#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define loop(i,n) sloop(0,i,n)
#define sloop(s, i, n) for(int i=(s);i<(n);i++)
#define rloop(i,n) rsloop(0,i,n)
#define rsloop(s,i,n) for(int i=(n);i-->(s);)
#define all(v) (v).begin(),(v).end()
#define nie {cout<<"No\n";return;}
#define tak {cout<<"Yes\n";return;}
#ifdef DEBUG
#define DBG cout << __LINE__ << endl;
#else
#define DBG
#endif
//int xses[8] = {-1,1,0,0,-1,1,1,-1};
//int yses[8] = {0,0,-1,1,-1,1,-1,1};
#define int ll
void solve()
{
string a,b,c;
cin>>a>>b>>c;
int n = a.size();
int r=0;
int c0=0,c1=0;
for(int i=n-1;i>=0;i--){
int d = (a[i]-'0')+(b[i]-'0')-(c[i]-'0');
c0++;
int nc0=0,nc1=0;
if(d==0)nc0+=c0;
else if(d==10)nc1+=c0;
if(d==-1)nc0+=c1;
else if(d==9)nc1+=c1;
c0=nc0;
c1=nc1;
r+=c0;
}
cout<<r<<'\n';
}
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
int t=1;
//cin>>t;
loop(i,t)
{
#ifdef DEBUG
if(t!=1)
{
cout<<"Test no. "<<i+1<<endl;
}
#endif
solve();
}
#ifdef DEBUG
cout << '\n';
#endif
return 0;
}
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 | #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define pii pair<int,int> #define vi vector<int> #define vpii vector<pii> #define loop(i,n) sloop(0,i,n) #define sloop(s, i, n) for(int i=(s);i<(n);i++) #define rloop(i,n) rsloop(0,i,n) #define rsloop(s,i,n) for(int i=(n);i-->(s);) #define all(v) (v).begin(),(v).end() #define nie {cout<<"No\n";return;} #define tak {cout<<"Yes\n";return;} #ifdef DEBUG #define DBG cout << __LINE__ << endl; #else #define DBG #endif //int xses[8] = {-1,1,0,0,-1,1,1,-1}; //int yses[8] = {0,0,-1,1,-1,1,-1,1}; #define int ll void solve() { string a,b,c; cin>>a>>b>>c; int n = a.size(); int r=0; int c0=0,c1=0; for(int i=n-1;i>=0;i--){ int d = (a[i]-'0')+(b[i]-'0')-(c[i]-'0'); c0++; int nc0=0,nc1=0; if(d==0)nc0+=c0; else if(d==10)nc1+=c0; if(d==-1)nc0+=c1; else if(d==9)nc1+=c1; c0=nc0; c1=nc1; r+=c0; } cout<<r<<'\n'; } signed main() { cin.tie(0); ios_base::sync_with_stdio(0); int t=1; //cin>>t; loop(i,t) { #ifdef DEBUG if(t!=1) { cout<<"Test no. "<<i+1<<endl; } #endif solve(); } #ifdef DEBUG cout << '\n'; #endif return 0; } |
English