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
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <deque>
#include <map>
#include <queue>
#include <climits>
using namespace std;
using ll=long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s1, s2, s3;
    cin >> s1;
    cin >> s2;
    cin >> s3;
    int length = s1.size();
    int x=0;
    bool search=false;
    ll wynik=0;
    ll dodanie=0;
    for(int y=1; y<=length; y++){
        if(int(s1[y-1])-int('0')+int(s2[y-1])-int('0')==int(s3[y-1])-int('0')){
            if(search){
                search=false;
                dodanie=0;
            }
            wynik+=++dodanie;
            //cout<<1<<'\n';
        }
        else if(int(s1[y-1])-int('0')+int(s2[y-1])-int('0')==int(s3[y-1])-int('0')+10){
            if(search){
                wynik+=++dodanie;
                search=false;
            }
            else{
                x=y;
                dodanie=0;
            }
            //cout<<2<<'\n';
        }
        else if(int(s1[y-1])-int('0')+int(s2[y-1])-int('0')==int(s3[y-1])-int('0')+9){
            if(search){}
            else{
                x=y;
                dodanie=0;
            }
            //cout<<3<<'\n';
        }
        else if(int(s1[y-1])-int('0')+int(s2[y-1])-int('0')==int(s3[y-1])-int('0')-1){
            if(search){
                x=y-1;
                dodanie=0;
            }
            search=true;
            //cout<<4<<'\n';
        }
        else{
            search=false;
            dodanie=0;
            //cout<<5<<'\n';
        }

    }
    cout << wynik << '\n';
    return 0;
}