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

using namespace std;

#define vec vector
#define ll long long

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string a, b, c; cin >> a >> b >> c;

  int n = a.size();
  vec<int> a2(n);
  vec<int> b2(n);
  vec<int> c2(n);
  for (int i = 0; i < n; i++) {
    a2[i] = a[i] - '0';
    b2[i] = b[i] - '0';
    c2[i] = c[i] - '0';
  }

  ll cur = 0;
  int carry = 0;
  ll res = 0;
  for (int i = n - 1; i >= 0; i--) {
    if ((a2[i] + b2[i]) % 10 == c2[i] and carry == 0) {
      cur ++;
    } 
    else if ((a2[i] + b2[i] + carry) % 10 != c2[i]){
      if (carry) cur --;
      res += cur * (cur + 1) / 2;
      if ((a2[i] + b2[i]) % 10 == c2[i]) {
        cur = 1;
        carry = 0;
      } else {
        cur = 0;

      }
    }
    if ((a2[i] + b2[i] + carry) % 10 == c2[i]) {
      if (a2[i] + b2[i] + carry >= 10)
        carry = 1;
      else
        carry = 0;
    } else {
      carry  = 0;
    }
  }
  if (carry != 0) {
    cur --;
  }
  res += cur * (cur + 1) / 2;
  cout << res;
}