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
#include <bits/stdc++.h>

using namespace std;

#define endl "\n"
#define ll long long

#define SIZE 500500

void solve() {
  string a, b, c;
  cin >> a >> b >> c;
  int n = a.length();

  for(int i = 0; i < n; i++) {
    a[i] -= '0';
    b[i] -= '0';
    c[i] -= '0';
  }

  bool carry = false;
  bool prev_carry = false;
  ll ans = 0;
  int counter = 0;

  for(int i = n-1; i >=0; i--) {
    int sum = a[i] + b[i] + (carry ? 1 : 0);
    prev_carry = carry;
    carry = sum >= 10;
    sum %= 10;

    if(sum == c[i]) {
      if(!carry) counter ++;
    } else {
      if(prev_carry && sum - 1 == c[i]) {
        ++i;
      }
      ans += counter*(counter + 1) / 2;
      counter = 0;
      carry = false;
    }
  }

  ans += counter*(counter + 1) / 2;

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  //cin >> t;
  while (t--) {
    solve();
  }
}