1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,p,k) for(int i=(p); i<=(k); ++i)
#define FORL(i,p,k) for(long long i=(p); i<=(k); ++i)
#define RFOR(i,p,k) for(int i=(p); i>=(k); --i)
#define REP(i,k) FOR(i,0,(k)-1)
#define FORC(i,c,in) for(i; c; in)
#define FORPWK(pw,k,cond) for(int pw = 1, k = 1; cond; pw *= 2, ++k)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).end(), (x).begin()
#define siz(x) int((x).size())
#define f first
#define s second
#define v vector
#define pb push_back
#define eb emplace_back
#define C const
typedef long long ll;
typedef v<int> vi;
typedef C int ci;
typedef C ll cll;
typedef pair<int, int> pii;
template<typename T>
using V = vector<T>;

inline void solve(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    string a, b, c;
    cin >> a >> b >> c;
    int n = siz(a);

    ll wyn = 0, ile = 0, popr = -1;
    bool yes = 0;

    REP(i, n) {
        int x = a[i] - '0', y = b[i] - '0', z = c[i] - '0', s = x + y;
        int wej = -1, wyj = -1;

        if(s <= 8){
            if(z == s){
                wej = 0;
                wyj = 0;
				} 
            else if(z == s + 1){
                wej = 1;
                wyj = 0;
				} 
            else{
                wej = -1;
                wyj = -1;
				}
			} 
			else if(s == 9){
				if(z == 9){
					wej = 0;
					wyj = 0;
					}
				else if(z == 0){
					wej = 1;
					wyj = 1;
					} 
				else{
					wej = -1;
					wyj = -1;
					}
				}
				else{
					if(z == s - 10){
						wej = 0;
						wyj = 1;
						} 
					else if(z == s - 9){
						wej = 1;
						wyj = 1;
						} 
					else{
						wej = -1;
						wyj = -1;
						}
					}

        if(wej == -1){
            ile = 0;
            popr = -1;
            yes = 0;
			} 
			else{
            if(!yes){
                ile = 0;
				} 
				else{
					if(wyj == popr){
						} 
						else{
						ile = 0;
						}
				}

            if(wyj == 0){
                ++ile;
				} 
				else{
				}
            
            if(wej == 0){
                wyn += ile;
				} 
				else{
				}

            popr = wej;
            yes = 1;
        }
    }

    cout << wyn << "\n";
}

signed main(){
    int tt = 1;
    while(tt--) solve();
}