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
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

long long out = 0;

void push(long long &l) {
   out += (l * (l + 1)) / 2;
   l = 0;
}

void comp(string &s) {
   if ((int)s.length() == 0) return;
   char state = 'b';
   long long l = 0;

   // cerr << s << '\n';
   for (char c : s) {
      if (state == 'b') {
         if (c == 'a') l++;
         if (c == 'b') state = 'e';
         if (c == 'm') push(l);
         if (c == 'e') push(l);
      }
      else {
         if (c == 'a') { push(l); state = 'b'; l++; }
         if (c == 'b') { push(l); state = 'e'; }
         if (c == 'm') { ; }
         if (c == 'e') { l++; state = 'b'; }
      }
      // cerr << c << ' ' << out << ' ' << state << ' ' << l << endl;
   }
   push(l);
   s.clear();
}

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);

   string s1, s2, s3;
   cin >> s1 >> s2 >> s3;
   int n = (int)s1.size();

   vector<char> type(n + 2, 'n');
   for (int i = 1; i <= n; i++) {
      int a = s1[i-1] - '0';
      int b = s2[i-1] - '0';
      int c = s3[i-1] - '0';
      if (a + b == c) type[i] = 'a';
      else if (a + b + 1 == c) type[i] = 'b';
      else if (a + b == c + 10) type[i] = 'e';
      else if (a + b + 1 == c + 10) type[i] = 'm';
   }

   string toComp;
   for (int i = 1; i <= n + 1; i++) {
      if (type[i] == 'n') { comp(toComp); continue; }
      toComp.push_back(type[i]);
   }

   cout << out << endl;

   return 0;
}