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
124
125
126
127
128
129
130
#include <bits/stdc++.h>
using namespace std;

constexpr int TOO_BAD = 4;
constexpr int ALMOST_GOOD = 2;
constexpr int OVERFLOW = 1;

int is_almost_good(int a, int b, int c) {
  if ((a + b + 1) % 10 == c) {
    return ALMOST_GOOD;
  }
  else {
    return 0;
  }
}

int is_too_bad(int a, int b, int c) {
  if ((a+b) % 10 == c || (a+b+1) % 10 == c) {
    return 0;
  }
  else {
    return TOO_BAD;
  }
}

int is_overflow(int a, int b, int c) {
  if (a + b >= 10 || (a + b == 9 && c == 0)) {
    return OVERFLOW;
  }
  else {
    return 0;
  }
}

int get_info(char a, char b, char c) {
  int nA = a - '0';
  int nB = b - '0';
  int nC = c - '0';
  return is_almost_good(nA, nB, nC) ^ is_too_bad(nA, nB, nC) ^ is_overflow(nA, nB, nC);
}

long long get_comb(long long cnt) {
  return (cnt + 1) * cnt / 2;
}

long long solve(const vector<int>& arr, int a, int b) {
  // cerr << "[DEBUG] " << a << " " << b << "\n";
  long long res = 0;
  int l = a, r = a;
  bool shaping = false;
  int cnt = 0;
  for (r = l; r <= b; r++) {
    // cerr << "I AM " << r << " " << arr[r] << "\n";
    // cerr << "CURRENT " << cnt << " " << shaping << "\n";
    if ((!(arr[r] & ALMOST_GOOD)) && (!(arr[r] & OVERFLOW))) {
      // cerr << "CASE 1 " << arr[r] << endl;
      if (!shaping) {
        cnt++;
      }
      else {
        res += get_comb(cnt);
        shaping = false;
        cnt = 1;
      }
    }
    else if (!(arr[r] & ALMOST_GOOD) && (arr[r] & OVERFLOW)) {
      // cerr << "CASE 2" << endl;
      if (!shaping) {
        shaping = true;
      }
      else {
        res += get_comb(cnt);
        cnt = 0;
      }
    }
    else if ((arr[r] & ALMOST_GOOD) && !(arr[r] & OVERFLOW)) {
      // cerr << "CASE 3" << endl;
      if (!shaping) {
        res += get_comb(cnt);
        cnt = 0;
      }
      else {
        cnt++;
        shaping = false;
      }
    }
    else {
      // cerr << "CASE 4" << endl;
      if (!shaping) {
        res += get_comb(cnt);
        cnt = 0;
      }
      else {}
    }
  }
  res += get_comb(cnt);
  return res;
}



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

  string a, b, c;
  cin >> a >> b >> c;
  int n = a.size();

  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    arr[i] = get_info(a[n-i-1], b[n-i-1], c[n-i-1]);
  }
  long long res = 0;
  int l = 0;
  int r = 0;
  for (r = 0; r < n; r++) {
    if (arr[r] & TOO_BAD) {
      if (l < r) {
        res += solve(arr, l, r-1);
      }
      l = r + 1;
    }
  }
  if (l < r) {
    res += solve(arr, l, r-1);
  }

  cout << res << "\n";
}