stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

const int maxn = 2e5;



char s[maxn + 5];

char t[maxn + 5];

char a[maxn + 5];

char b[maxn + 5];

bool flag;



int main(){

	memset(a, '#', sizeof(a));

	memset(b, '#', sizeof(b));

	scanf("%s", s);

	scanf("%s", t);

	int len = strlen(s);

	for(int i = 0; i <= len - 1; i++){

		if(a[s[i] - 'a'] == '#' || a[s[i] - 'a'] == t[i]){

			a[s[i] - 'a'] = t[i];

		}

		else flag = 1;

		if(b[t[i] - 'a'] == '#' || b[t[i] - 'a'] == s[i]){

			b[t[i] - 'a'] = s[i];

		}

		else flag = 1;

		if(flag){

			printf("No\n");

			return 0;

		}

	}

	printf("Yes\n");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.36744857563926x):
#include <bits/stdc++.h>



#define vi vector<int>

#define ii pair<int,int>

#define vii vector<pair<int,int>>



typedef long long ll;

typedef unsigned long long ull;



#define pb push_back

#define mp make_pair

#define fi first

#define se second



using namespace std;



string s,t;

map<char, char> m;

bool mapped[256];



int main (void) {

    ios_base::sync_with_stdio(false);



    cin >> s >> t;

    int length = s.length();

    for (int i = 0; i < length; i++) {

        if (m.count(s[i]) == 0) {

            m[s[i]] = t[i];

            if (mapped[t[i]]) {

                cout << "No" << endl;

                return 0;

            }

            mapped[t[i]] = true;

        } else {

            if (t[i] != m[s[i]]) {

                cout << "No" << endl;

                return 0;

            }

        }

//        printf("%c %c %c\n", s[i], t[i], m[s[i]]);

    }



    cout << "Yes" << endl;



    return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

const int maxn = 2e5;



char s[maxn + 5];

char t[maxn + 5];

char a[maxn + 5];

char b[maxn + 5];

bool flag;



int main(){

	memset(a, '#', sizeof(a));

	memset(b, '#', sizeof(b));

	scanf("%s", s);

	scanf("%s", t);

	int len = strlen(s);

	for(int i = 0; i <= len - 1; i++){

		if(a[s[i] - 'a'] == '#' || a[s[i] - 'a'] == t[i]){

			a[s[i] - 'a'] = t[i];

		}

		else flag = 1;

		if(b[t[i] - 'a'] == '#' || b[t[i] - 'a'] == s[i]){

			b[t[i] - 'a'] = s[i];

		}

		else flag = 1;

		if(flag){

			printf("No\n");

			return 0;

		}

	}

	printf("Yes\n");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4107911736231635x):
#include <iostream>

#include <sstream>

#include <algorithm>

#include <cstdio>

#include <math.h>

#include <set>

#include <map>

#include <queue>

#include <string>

#include <string.h>

#include <bitset>

#define REP(i,a,n) for(int i=a;i<=n;++i)

#define PER(i,a,n) for(int i=n;i>=a;--i)

#define hr putchar(10)

#define pb push_back

#define lc (o<<1)

#define rc (lc|1)

#define mid ((l+r)>>1)

#define ls lc,l,mid

#define rs rc,mid+1,r

#define x first

#define y second

#define io std::ios::sync_with_stdio(false)

#define endl '\n'

#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})

using namespace std;

typedef long long ll;

typedef pair<int,int> pii;

const int P = 1e9+7, INF = 0x3f3f3f3f;

ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}

ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}

inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}

//head







const int N = 1e6+10;

char s[N],t[N];

int f[222],n,cnt;

void solve(int x, int y) {

	REP(i,1,cnt) {

		if (s[i]==x) s[i]=y;

		else if (s[i]==y) s[i]=x;

	}

}



int main() {

	scanf("%s%s", s+1, t+1);

	n = strlen(s+1);

	REP(i,1,n) {

		if (f[s[i]]&&f[s[i]]!=t[i]) return puts("No"),0;

		f[s[i]] = t[i];

	}

	REP(i,'a','z') if (f[i]) { 

		s[++cnt]=i;

		t[cnt]=f[i];

	}

	REP(i,1,cnt) if (s[i]!=t[i]) solve(s[i],t[i]);

	REP(i,1,cnt) if (s[i]!=t[i]) return puts("No"),0;

	puts("Yes");

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

const int maxn = 2e5;



char s[maxn + 5];

char t[maxn + 5];

char a[maxn + 5];

char b[maxn + 5];

bool flag;



int main(){

	memset(a, '#', sizeof(a));

	memset(b, '#', sizeof(b));

	scanf("%s", s);

	scanf("%s", t);

	int len = strlen(s);

	for(int i = 0; i <= len - 1; i++){

		if(a[s[i] - 'a'] == '#' || a[s[i] - 'a'] == t[i]){

			a[s[i] - 'a'] = t[i];

		}

		else flag = 1;

		if(b[t[i] - 'a'] == '#' || b[t[i] - 'a'] == s[i]){

			b[t[i] - 'a'] = s[i];

		}

		else flag = 1;

		if(flag){

			printf("No\n");

			return 0;

		}

	}

	printf("Yes\n");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3566377932838438x):
#include<bits/stdc++.h>

using namespace std;

#define LL long long int

#define DL double

#define MLL map<LL,LL>::iterator

#define MSL map<string,L>::iterator

#define MLS map<LL,string>::iterator

#define MSS map<string,string>::iterator

#define MCL map<char,LL>::iterator

#define SL set<LL>::iterator

#define SS set<string>::iterator sl

#define G getline

#define SZ size()

#define IN insert

#define C clear()

#define B begin()

#define F front()

#define T top()

#define E end()

#define EM empty()

#define V vector

#define Q queue

#define DQ deque

#define PQ priority_queue

#define ST stack

#define FI first

#define SE second

#define PI acos(-1)

#define PS push

#define PP pop()

#define PSF push_front

#define PSB push_back

#define PPF pop_front()

#define PPB pop_back()

#define U (LL)0

#define endl "\n"

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

map<char,LL>u,v;

int main()

{

    FAST;

    LL n,m,i,j,k,p,q,o,l,s,t,z;

    string a,b;

    cin>>a>>b;

    k=1;

    for(i=0; a[i]; i++)

    {

        if(u[a[i]]==0 || u[a[i]]==b[i]-'0')

        {

            u[a[i]]=b[i]-'0';

        }

        else

        {

            k=0;

            break;

        }

        if(v[b[i]]==0 || v[b[i]]==a[i]-'0')

        {

            v[b[i]]=a[i]-'0';

        }

        else

        {

            k=0;

            break;

        }

    }

    if(k==0)

    {

        cout<<"No"<<endl;

    }

    else

    {

        cout<<"Yes"<<endl;

    }





    return 0;



}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+7;

int num[maxn];

int main()

{

    string stra;

    string strb;

    cin>>stra>>strb;

    int len=stra.size();

    memset(num,-1,sizeof(num));

    for(int i=0;i<len;i++)

    {

        if(num[stra[i]]==-1)

        {

            num[stra[i]]=strb[i];

        }

        else

        {

            if(num[stra[i]]!=strb[i])

            {

                cout<<"No"<<endl;

                return 0;

            }

        }

    }

    memset(num,-1,sizeof(num));

    for(int i=0;i<len;i++)

    {

        if(num[strb[i]]==-1)

        {

            num[strb[i]]=stra[i];

        }

        else

        {

            if(num[strb[i]]!=stra[i])

            {

                cout<<"No"<<endl;

                return 0;

            }

        }

    }

    cout<<"Yes"<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3975456740790382x):
#include<bits/stdc++.h>

using namespace std;

#define LL long long int

#define DL double

#define MLL map<LL,LL>::iterator

#define MSL map<string,L>::iterator

#define MLS map<LL,string>::iterator

#define MSS map<string,string>::iterator

#define MCL map<char,LL>::iterator

#define SL set<LL>::iterator

#define SS set<string>::iterator sl

#define G getline

#define SZ size()

#define IN insert

#define C clear()

#define B begin()

#define F front()

#define T top()

#define E end()

#define EM empty()

#define V vector

#define Q queue

#define DQ deque

#define PQ priority_queue

#define ST stack

#define FI first

#define SE second

#define PI acos(-1)

#define PS push

#define PP pop()

#define PSF push_front

#define PSB push_back

#define PPF pop_front()

#define PPB pop_back()

#define U (LL)0

#define endl "\n"

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

map<char,LL>u,v;

int main()

{

    FAST;

    LL n,m,i,j,k,p,q,o,l,s,t,z;

    string a,b;

    cin>>a>>b;

    k=1;

    for(i=0; a[i]; i++)

    {

        if(u[a[i]]==0 || u[a[i]]==b[i]-'0')

        {

            u[a[i]]=b[i]-'0';

        }

        else

        {

            k=0;

            break;

        }

        if(v[b[i]]==0 || v[b[i]]==a[i]-'0')

        {

            v[b[i]]=a[i]-'0';

        }

        else

        {

            k=0;

            break;

        }

    }

    if(k==0)

    {

        cout<<"No"<<endl;

    }

    else

    {

        cout<<"Yes"<<endl;

    }





    return 0;



}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

const int maxn = 2e5;



char s[maxn + 5];

char t[maxn + 5];

char a[maxn + 5];

char b[maxn + 5];

bool flag;



int main(){

	memset(a, '#', sizeof(a));

	memset(b, '#', sizeof(b));

	scanf("%s", s);

	scanf("%s", t);

	int len = strlen(s);

	for(int i = 0; i <= len - 1; i++){

		if(a[s[i] - 'a'] == '#' || a[s[i] - 'a'] == t[i]){

			a[s[i] - 'a'] = t[i];

		}

		else flag = 1;

		if(b[t[i] - 'a'] == '#' || b[t[i] - 'a'] == s[i]){

			b[t[i] - 'a'] = s[i];

		}

		else flag = 1;

		if(flag){

			printf("No\n");

			return 0;

		}

	}

	printf("Yes\n");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.371116363353341x):
#include <bits/stdc++.h>

using namespace std;

int main()

{

    int a,b,c,d,e,f,g,h,j,i;

 int k,sum=0,tc;

 

    string s,s1;

    cin>>s>>s1;

    map<char, int> m, m1;

    string ans = "Yes";

    for( i=0; i<s.size(); i++)

    {

        m[s[i]]++;

        m1[s1[i]]++;

        if(m[s[i]] != m1[s1[i]])

        {

            ans = "No";

            break;

        }

    }

    cout<<ans<<endl;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+7;

int num[maxn];

int main()

{

    string stra;

    string strb;

    cin>>stra>>strb;

    int len=stra.size();

    memset(num,-1,sizeof(num));

    for(int i=0;i<len;i++)

    {

        if(num[stra[i]]==-1)

        {

            num[stra[i]]=strb[i];

        }

        else

        {

            if(num[stra[i]]!=strb[i])

            {

                cout<<"No"<<endl;

                return 0;

            }

        }

    }

    memset(num,-1,sizeof(num));

    for(int i=0;i<len;i++)

    {

        if(num[strb[i]]==-1)

        {

            num[strb[i]]=stra[i];

        }

        else

        {

            if(num[strb[i]]!=stra[i])

            {

                cout<<"No"<<endl;

                return 0;

            }

        }

    }

    cout<<"Yes"<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4124608290803573x):
#include <bits/stdc++.h>

using namespace std;

int main()

{

    int a,b,c,d,e,f,g,h,j,i;

 int k,sum=0,tc;

 

    string s,s1;

    cin>>s>>s1;

    map<char, int> m, m1;

    string ans = "Yes";

    for( i=0; i<s.size(); i++)

    {

        m[s[i]]++;

        m1[s1[i]]++;

        if(m[s[i]] != m1[s1[i]])

        {

            ans = "No";

            break;

        }

    }

    cout<<ans<<endl;

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

const int maxn = 2e5;



char s[maxn + 5];

char t[maxn + 5];

char a[maxn + 5];

char b[maxn + 5];

bool flag;



int main(){

	memset(a, '#', sizeof(a));

	memset(b, '#', sizeof(b));

	scanf("%s", s);

	scanf("%s", t);

	int len = strlen(s);

	for(int i = 0; i <= len - 1; i++){

		if(a[s[i] - 'a'] == '#' || a[s[i] - 'a'] == t[i]){

			a[s[i] - 'a'] = t[i];

		}

		else flag = 1;

		if(b[t[i] - 'a'] == '#' || b[t[i] - 'a'] == s[i]){

			b[t[i] - 'a'] = s[i];

		}

		else flag = 1;

		if(flag){

			printf("No\n");

			return 0;

		}

	}

	printf("Yes\n");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3947910235933536x):
#include<bits/stdc++.h>

using namespace std;

int fr1[150];

int fr2[130];

int main()

{

   string s,t;

   cin>>s>>t;int y=1;

   map<char,int> mp;

   for(int i=0;i<s.size();i++)

   {

       fr1[s[i]]++;

       fr2[t[i]]++;

       if(fr1[s[i]]!=fr2[t[i]])

       {

           y=0;

           break;

       }

   }

   if(y==0)

    cout<<"No\n";

    else

        cout<<"Yes\n";



}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+7;

int num[maxn];

int main()

{

    string stra;

    string strb;

    cin>>stra>>strb;

    int len=stra.size();

    memset(num,-1,sizeof(num));

    for(int i=0;i<len;i++)

    {

        if(num[stra[i]]==-1)

        {

            num[stra[i]]=strb[i];

        }

        else

        {

            if(num[stra[i]]!=strb[i])

            {

                cout<<"No"<<endl;

                return 0;

            }

        }

    }

    memset(num,-1,sizeof(num));

    for(int i=0;i<len;i++)

    {

        if(num[strb[i]]==-1)

        {

            num[strb[i]]=stra[i];

        }

        else

        {

            if(num[strb[i]]!=stra[i])

            {

                cout<<"No"<<endl;

                return 0;

            }

        }

    }

    cout<<"Yes"<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4368493719674256x):
#include<bits/stdc++.h>

using namespace std;

int fr1[150];

int fr2[130];

int main()

{

   string s,t;

   cin>>s>>t;int y=1;

   map<char,int> mp;

   for(int i=0;i<s.size();i++)

   {

       fr1[s[i]]++;

       fr2[t[i]]++;

       if(fr1[s[i]]!=fr2[t[i]])

       {

           y=0;

           break;

       }

   }

   if(y==0)

    cout<<"No\n";

    else

        cout<<"Yes\n";



}
// Slower C++ solution:
#include<iostream>

#include<stdlib.h>

#include<string>

using namespace std;

int cnt[30],ans[30],alpha_cnt;//alphabetの個数をカウント

int check_s[300010],check_t[300010];

int main(){

    string s,t;

    cin>>s>>t;

    for(int i=0;i<s.length();i++){

        ans[t[i]-'a']++;

        cnt[s[i]-'a']++;

    }

    for(int i=0;i<26;i++){

        if(cnt[i]!=0)alpha_cnt++;

        check_s[cnt[i]]++;

        check_t[ans[i]]++;

    }

    bool flag=true;

    for(int i=1;i<300001;i++){

        if(check_s[i]!=check_t[i]){

            flag=false;

            break;

        }

    }

   if(flag)cout<<"Yes"<<endl;

   else cout<<"No"<<endl;



    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.2143036832283451x):
#include<iostream>

#include<stdlib.h>

#include<string>

#include<vector>

using namespace std;

int main(){

    string s,t;

    cin>>s>>t;

    int a,b;

    vector<int>start(26,-114514),end(26,-114514);

    for(int i=0;i<s.length();i++){

        a=s[i]-'a';

        b=t[i]-'a';

        if(start[a]!=-114514||end[b]!=-114514){

            if(start[a]!=b||end[b]!=a){

                cout<<"No"<<endl;

                return 0;

            }

        }

        else{

            start[a]=b;

            end[b]=a;

        }

    }

    cout<<"Yes"<<endl;



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define fbo find_by_order

#define ook order_of_key



typedef long long ll;

typedef pair<ll,ll> ii;

typedef vector<int> vi;

typedef long double ld; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

typedef set<int>::iterator sit;

typedef map<int,int>::iterator mit;

typedef vector<int>::iterator vit;



ll a[100001];

ll b[100001];



ll getmin(ll a, ll b)

{

	if(a%b==0) return 0;

	return (((a+b-1)/b)*b - a);

}

int main()

{

	ios_base::sync_with_stdio(0); cin.tie(0);

	int n; cin>>n;

	for(int i = 0; i<n;i++)

	{

		cin>>a[i]>>b[i];

	}

	ll sum = 0;

	for(int i = n - 1; i >= 0; i--)

	{

		a[i]+=sum;

		sum+=getmin(a[i],b[i]);

	}

	cout<<sum<<'\n';

}


// Faster C++ solution for the same problem (measured speedup: 5.2924110807315845x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

long long n,a[100002],b[100002],ans;

int main()

{

	scanf("%lld",&n);

	for(int i=1;i<=n;i++)

		scanf("%lld%lld",&a[i],&b[i]);

	long long t;

	for(long long i=n;i>=1;i--)

	{

		a[i]+=ans;

		long long j;

		for(j=a[i]/b[i];;j++)

			if(j*b[i]>=a[i])

				break;

		t=j*b[i]-a[i];

		ans+=t;

	}

	printf("%lld",ans);

}
// Slower C++ solution:
#include <iostream>

#include <cstring>

#include <vector>

using namespace std;

const int NICO = 100000 + 10;

typedef long long Long;

Long a[NICO], b[NICO], n;

int main()

{

    cin >> n;

    for(int i=1;i<=n;i++)

    {

        cin >> a[i] >> b[i];

    }

    Long tmp = 0;

    for(int i=n;i>=1;i--)

    {

        a[i] += tmp;

        tmp += (b[i] - a[i]%b[i]) % b[i];

    }

    cout << tmp << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.204251423528519x):
#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

#include <vector>

#include <string>

#include <map>

#include <set>

#include <cassert>

using namespace std;

#define rep(i,a,n) for (int i=a;i<n;i++)

#define per(i,a,n) for (int i=n-1;i>=a;i--)

#define pb push_back

#define mp make_pair

#define all(x) (x).begin(),(x).end()

#define fi first

#define se second

#define SZ(x) ((int)(x).size())

typedef vector<int> VI;

typedef long long ll;

typedef pair<int,int> PII;

const ll mod=1000000007;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

// head



const int N=101000;

int n;

ll a[N],b[N],x;

int main() {

	scanf("%d",&n);

	rep(i,0,n) scanf("%lld%lld",a+i,b+i);

	per(i,0,n) {

		a[i]+=x;

		a[i]%=b[i];

		if (a[i]!=0) x+=b[i]-a[i];

	}

	printf("%lld\n",x);

}
// Slower C++ solution:
#include <iostream>

#include <cstring>

#include <vector>

using namespace std;

const int NICO = 100000 + 10;

typedef long long Long;

Long a[NICO], b[NICO], n;

int main()

{

    cin >> n;

    for(int i=1;i<=n;i++)

    {

        cin >> a[i] >> b[i];

    }

    Long tmp = 0;

    for(int i=n;i>=1;i--)

    {

        a[i] += tmp;

        tmp += (b[i] - a[i]%b[i]) % b[i];

    }

    cout << tmp << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.213938642185446x):
#include<cstdio>



#define MAXN 100000

int N;

long long A[MAXN+5],B[MAXN+5];



int main(){

    scanf("%d",&N);

    for(int i=1;i<=N;i++)

        scanf("%lld%lld",&A[i],&B[i]);

    long long Ans=0;

    for(int i=N;i>=1;i--){

        A[i]+=Ans;

        Ans+=(B[i]-(A[i]%B[i]))%B[i];

    }

    printf("%lld",Ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const size_t MAX_N = (size_t) 1e5 + 5;

ll a[MAX_N], b[MAX_N];

int main() {

    int n;

    cin >> n;

    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

    ll res = 0;

    for (int i = n - 1; i + 1; i--) 

        res += (b[i] - (a[i] + res) % b[i]) % b[i];

    cout << res;

}

// Faster C++ solution for the same problem (measured speedup: 5.220014388456341x):
#include<cstdio>



#define MAXN 100000

int N;

long long A[MAXN+5],B[MAXN+5];



int main(){

    scanf("%d",&N);

    for(int i=1;i<=N;i++)

        scanf("%lld%lld",&A[i],&B[i]);

    long long Ans=0;

    for(int i=N;i>=1;i--){

        A[i]+=Ans;

        Ans+=(B[i]-(A[i]%B[i]))%B[i];

    }

    printf("%lld",Ans);

}
// Slower C++ solution:
/*  ***  In The Name of God ... ***  */

#include <bits/stdc++.h>



using namespace std ;

 

typedef long long ll ;

typedef long double ld ;





#define int long long

#define all(v) v.begin() , v.end()



template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}

template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}



const int N = ( int ) 1e5 + 10 ;



int n , a [ N ] , b [ N ] ;



int32_t main()                     

{

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin >> n ;

	for ( int i = 0 ; i < n ; ++ i )

		cin >> a [ i ] >> b [ i ] ;

	int added = 0 , res = 0 ;

	for ( int i = n - 1 ; i >= 0 ; -- i ) {

		a [ i ] += added ;

		if ( a [ i ] % b [ i ] == 0 ) continue ; 

		int reach = a [ i ] + ( b [ i ] - ( a [ i ] % b [ i ] ) ) ;

		added += reach - a [ i ] ; 

	}

	cout << added << endl ; 

}


// Faster C++ solution for the same problem (measured speedup: 5.275902933457601x):
#include<cstdio>



#define MAXN 100000

int N;

long long A[MAXN+5],B[MAXN+5];



int main(){

    scanf("%d",&N);

    for(int i=1;i<=N;i++)

        scanf("%lld%lld",&A[i],&B[i]);

    long long Ans=0;

    for(int i=N;i>=1;i--){

        A[i]+=Ans;

        Ans+=(B[i]-(A[i]%B[i]))%B[i];

    }

    printf("%lld",Ans);

}
// Slower C++ solution:
#include <iostream>

#include <iomanip>

#include <cstdio>

#include <string>

#include <cstring>

#include <deque>

#include <list>

#include <queue>

#include <stack>

#include <vector>

#include <utility>

#include <algorithm>

#include <map>

#include <set>

#include <complex>

#include <cmath>

#include <limits>

#include <climits>

#include <ctime>

#include <cassert>

using namespace std;



#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)

#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)

#define all(v) begin(v), end(v)

#define pb(a) push_back(a)

#define fr first

#define sc second

#define INF 2000000000

#define int long long int



#define X real()

#define Y imag()

#define EPS (1e-10)

#define EQ(a,b) (abs((a) - (b)) < EPS)

#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )

#define LE(n, m) ((n) < (m) + EPS)

#define LEQ(n, m) ((n) <= (m) + EPS)

#define GE(n, m) ((n) + EPS > (m))

#define GEQ(n, m) ((n) + EPS >= (m))



typedef vector<int> VI;

typedef vector<VI> MAT;

typedef pair<int, int> pii;

typedef long long ll;



typedef complex<double> P;

typedef pair<P, P> L;

typedef pair<P, double> C;



int dy[]={0, 0, 1, -1};

int dx[]={1, -1, 0, 0};

int const MOD = 1000000007;



namespace std {

    bool operator<(const P& a, const P& b) {

        return a.X != b.X ? a.X < b.X : a.Y < b.Y;

    }

}



signed main() {

    int n; cin >> n;

    ll a[100010], b[100010];

    rep(i,0,n) {

        cin >> a[i] >> b[i];

    }

    ll ans = 0;

    repr(i,n-1,0) {

        ll k;

        a[i] += ans;

        if(a[i] == 0) k = 0;

        else if(a[i] < b[i]) k = b[i] - a[i];

        else {

            if(a[i] % b[i] == 0) k = 0;

            else k = b[i] - (a[i] % b[i]);

        }

        // printf("k = %lld\n", k);

        ans += k;

    }

    cout << ans << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.404181207859709x):
#include <cstdio>

using namespace std;



long long int A[100010], B[100010];

int main() {

    int N; scanf("%d", &N);

    for(int i=0; i<N; i++) {

        scanf("%lld%lld", &A[i], &B[i]);

    }



    long long int ofs = 0;

    for(int i=N-1; i>=0; i--) {

        A[i] += ofs;

        if(A[i] == 0) continue;

        if(A[i] <= B[i]) ofs += B[i] - A[i];

        else {

            long long int mo = A[i] % B[i];

            ofs += (B[i] - mo) % B[i];

        }

    }

    printf("%lld\n", ofs);

    return 0;

}