//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<class T>
using vec = vector<T>;
template<typename T>
bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#ifdef KoRoVa
#define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define DEBUG while (false)
#define LOG(...)
#endif
const int max_n = -1, inf = 1000111222;
struct num {
static const int MA = 1e9 + 7, MB = 1e9 + 9;
int a, b;
num() : a(0), b(0) { }
num( int x ) : a(x), b(x) { }
num( int a, int b ) : a(a), b(b) { }
num operator + ( const num &x ) const { return num((a + x.a) % MA, (b + x.b) % MB); }
num operator - ( const num &x ) const { return num((a + MA - x.a) % MA, (b + MB - x.b) % MB); }
num operator * ( int x ) const { return num(((ll)a * x) % MA, ((ll)b * x) % MB); }
num operator * ( const num &x ) const { return num(((ll)a * x.a) % MA, ((ll)b * x.b) % MB); }
bool operator == ( const num &x ) const { return a == x.a && b == x.b; }
bool operator != ( const num &x ) const { return !(a == x.a && b == x.b); }
bool operator < (const num &x) const {
return pii{a, b} < pii{x.a, x.b};
}
};
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
string a, b, c;
cin >> a >> b >> c;
int n = len(a);
ll ans = 0;
map <num, int> cnt;
++cnt[num{0, 0}];
num h = 0, st = 1;
for (int i = n - 1; i >= 0; i--) {
int A = a[i] - '0';
int B = b[i] - '0';
int C = c[i] - '0';
h = h + st * A + st * B - st * C;
ans += cnt[h]++;
st = st * 10;
}
cout << ans << '\n';
}
/*
KoRoVa!
*/
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 | //#pragma GCC optimize("Ofast", "unroll-loops") //#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4") #include <bits/stdc++.h> #define all(a) a.begin(),a.end() #define len(a) (int)(a.size()) #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef long double ld; template<class T> using vec = vector<T>; template<typename T> bool umin(T &a, T b) { if (b < a) { a = b; return true; } return false; } template<typename T> bool umax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #ifdef KoRoVa #define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false) #define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); } #else #define DEBUG while (false) #define LOG(...) #endif const int max_n = -1, inf = 1000111222; struct num { static const int MA = 1e9 + 7, MB = 1e9 + 9; int a, b; num() : a(0), b(0) { } num( int x ) : a(x), b(x) { } num( int a, int b ) : a(a), b(b) { } num operator + ( const num &x ) const { return num((a + x.a) % MA, (b + x.b) % MB); } num operator - ( const num &x ) const { return num((a + MA - x.a) % MA, (b + MB - x.b) % MB); } num operator * ( int x ) const { return num(((ll)a * x) % MA, ((ll)b * x) % MB); } num operator * ( const num &x ) const { return num(((ll)a * x.a) % MA, ((ll)b * x.b) % MB); } bool operator == ( const num &x ) const { return a == x.a && b == x.b; } bool operator != ( const num &x ) const { return !(a == x.a && b == x.b); } bool operator < (const num &x) const { return pii{a, b} < pii{x.a, x.b}; } }; int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); string a, b, c; cin >> a >> b >> c; int n = len(a); ll ans = 0; map <num, int> cnt; ++cnt[num{0, 0}]; num h = 0, st = 1; for (int i = n - 1; i >= 0; i--) { int A = a[i] - '0'; int B = b[i] - '0'; int C = c[i] - '0'; h = h + st * A + st * B - st * C; ans += cnt[h]++; st = st * 10; } cout << ans << '\n'; } /* KoRoVa! */ |
English