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

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

int n,m,x;

const int maxn = 1e5+10;

long long gcd(long long a, long long b){

    return a == 0 ? b : gcd(b % a, a);

}

long long a[maxn],b[maxn];

int main(){

    long long i,j,k;

    long long ans;

    long long now;

    long long comm;

    while(~scanf("%d",&n)){

        ans = 0;

        now = 0;

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

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

        }

        

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

            a[i] += ans;

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

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

                    break;

                }

            }

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

            ans += comm;

        }

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

    }

    

}

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

using namespace std;

const int maxn=1e5+10;

#define LL long long

LL n,ans;

LL a[maxn],b[maxn];

int main()

{

	LL i,j;

    scanf("%d",&n);

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

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

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

	{

		a[i] += ans;

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

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

				break;

		LL comm = j*b[i] - a[i];

		ans += comm;

	}

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

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

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

int n,m,x;

const int maxn = 1e5+10;

long long a[maxn],b[maxn];

int main(){

    long long i,j,k;

    long long ans;

    long long now;

    long long comm;

    scanf("%d",&n);

        ans = 0;

        now = 0;

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

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

        }

        

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

            a[i] += ans;

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

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

                    break;

                }

            }

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

            ans += comm;

        }

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

    

    

}

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

using namespace std;

const int maxn=1e5+10;

#define LL long long

LL n,ans;

LL a[maxn],b[maxn];

int main()

{

	LL i,j;

    scanf("%d",&n);

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

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

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

	{

		a[i] += ans;

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

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

				break;

		LL comm = j*b[i] - a[i];

		ans += comm;

	}

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

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

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

int n,m,x;

const int maxn = 1e5+10;

long long gcd(long long a, long long b){

    return a == 0 ? b : gcd(b % a, a);

}

long long a[maxn],b[maxn];

int main(){

    long long i,j,k;

    long long ans;

    long long now;

    long long comm;

    while(~scanf("%d",&n)){

        ans = 0;

        now = 0;

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

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

        }

        

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

            a[i] += ans;

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

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

                    break;

                }

            }

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

            ans += comm;

        }

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

    }

    

}

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

using namespace std;

const int maxn=1e5+10;

#define LL long long

LL n,ans;

LL a[maxn],b[maxn];

int main()

{

	LL j;

    scanf("%d",&n);

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

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

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

	{

		a[i] += ans;

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

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

				break;

		LL comm = j*b[i] - a[i];

		ans += comm;

	}

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

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

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

int n,m,x;

const int maxn = 1e5+10;

long long a[maxn],b[maxn];

int main(){

    long long i,j,k;

    long long ans;

    long long now;

    long long comm;

    scanf("%d",&n);

        ans = 0;

        now = 0;

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

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

        }

        

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

            a[i] += ans;

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

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

                    break;

                }

            }

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

            ans += comm;

        }

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

    

    

}

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

using namespace std;

const int maxn=1e5+10;

#define LL long long

LL n,ans;

LL a[maxn],b[maxn];

int main()

{

	LL j;

    scanf("%d",&n);

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

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

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

	{

		a[i] += ans;

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

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

				break;

		LL comm = j*b[i] - a[i];

		ans += comm;

	}

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

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

#include <cstring>

#include <algorithm>

#include <iostream>

using namespace std;



typedef long long ll;

const int maxn = 100000;



int n;

long long a[maxn], b[maxn];



int main(void) {

	cin >> n;

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

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

	}

	long long add = 0;

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

		a[i] += add;

		if(a[i] % b[i]) {

			add += b[i] - a[i] % b[i];

		}

	}

	cout << add << endl;

	return 0;

}

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

#include <cstring>

#include <algorithm>

using namespace std;

typedef long long li;



const int maxn = 1e5;

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



int main(void) {

  scanf("%d", &n);

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

    scanf("%d%d", a + i, b + i);

  }

  li ans = 0;

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

    li cur = a[i] + ans;

    li tar = (cur + b[i] - 1) / b[i] * b[i];

    ans += tar - cur;

  }

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

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



using namespace std;



int main()

{

    //freopen("04.txt","r",stdin);

    int mod,n,i,a[100001]={0},b[100001]={0};

    long long tim[100001]={0};

    long long mul,done=0;

    cin>>n;

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

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

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

    {

        mod=a[i]%b[i];

        if(mod)

            tim[i]=b[i]-mod;

    }

    for(i=n-2;i>=0;i--)

    {

        if(tim[i]>=tim[i+1])

            continue;

        mul=(tim[i+1]-tim[i])/b[i];

        tim[i]+=mul*b[i];

        if(tim[i]<tim[i+1])

            tim[i]+=b[i];

    }

    done=tim[n-1];

    for(i=n-2;i>=0;i--)

    {

        done+=(long long)(tim[i]-tim[i+1]);

    }

    cout<<done;

    return 0;

}


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

//#include <ext/pb_ds/assoc_container.hpp>

//using namespace __gnu_pbds;

using namespace std;

typedef long long ll;

//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;

template<class T1, class T2>

ostream &operator <<(ostream &os, pair<T1,T2>&p);

template <class T>

ostream &operator <<(ostream &os, vector<T>&v);

template <class T>

ostream &operator <<(ostream &os, set<T>&v);

#define debug(a) cerr<<#a<<" --> "<<(a)<<endl;

#define fastInput ios_base::sync_with_stdio(false);cin.tie(0)

#define INPUT freopen("input.txt","r",stdin)

#define OUTPUT freopen("output.txt","w",stdout)

#define ERROR  1e-9

#define pi (2*acos(0))

const ll mod = 998244353;

const int N = 2e5 +5;



void SOLVE(int cas)

{

    ll n;

    scanf("%lld",&n);

    vector< pair<ll,ll> >pii(n);

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

    {

        scanf("%lld %lld",&pii[i].first,&pii[i].second);

    }

    ll now =0;

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

    {

        ll ff = pii[i].first + now;

        ll ss = pii[i].second;

        if(ff%ss ==0)

            continue;

        ll d = ff/ss;

        d++;

        now+= ss*d - ff;

    }

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



















}





/*





*/







int main()

{

    //INPUT;

    //OUTPUT;

    int t=1,cas=0;

    //scanf("%d",&t);

    while(t--)

    {

        SOLVE(++cas);

    }



    return 0;

}







//os.order_of_key(v): returns how many elements strictly less than v

//os.find_by_order()



template<class T1, class T2>

ostream &operator <<(ostream &os, pair<T1,T2>&p)

{

    os<<"{"<<p.first<<", "<<p.second<<"} ";

    return os;

}

template <class T>

ostream &operator <<(ostream &os, vector<T>&v)

{

    os<<"[ ";

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

    {

        os<<v[i]<<" " ;

    }

    os<<" ]";

    return os;

}



template <class T>

ostream &operator <<(ostream &os, set<T>&v)

{

    os<<"[ ";

    for(T i:v)

    {

        os<<i<<" ";

    }

    os<<" ]";

    return os;

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



using namespace std;



int main()

{

    //freopen("04.txt","r",stdin);

    int mod,n,i,a[100001]={0},b[100001]={0};

    long long tim[100001]={0};

    long long mul,done=0;

    cin>>n;

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

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

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

    {

        mod=a[i]%b[i];

        if(mod)

            tim[i]=b[i]-mod;

    }

    for(i=n-2;i>=0;i--)

    {

        if(tim[i]>=tim[i+1])

            continue;

        mul=(tim[i+1]-tim[i])/b[i];

        tim[i]+=mul*b[i];

        if(tim[i]<tim[i+1])

            tim[i]+=b[i];

    }

    done=tim[n-1];

    for(i=n-2;i>=0;i--)

    {

        done+=(long long)(tim[i]-tim[i+1]);

    }

    cout<<done;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.5772438451234225x):
///****In the name of ALLAH, most Gracious, most Compassionate****//



#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair <int, int> pii;



#define ALL(a) a.begin(), a.end()

#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)

#define IN freopen("input.txt","r+",stdin)

#define OUT freopen("output.txt","w+",stdout)



#define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl

#define NL cout<<endl



template < class T1,class T2>

ostream &operator <<(ostream &os,const pair < T1,T2 > &p)

{

    os<<"{"<<p.first<<","<<p.second<<"}";

    return os;

}



const int N=3e5+5;

const int oo=1e9+7;



ll a[N];

ll b[N];



ll incr(ll x,ll y)

{

    if(x%y)

    return y- x%y;

    return 0;

}



int32_t main()

{

    FastIO;

    int n;

    cin>>n;

    ll add = 0;

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

    {

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

    }

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

    {

        a[i]+=add;

        add+=incr(a[i],b[i]);

    }

    cout<<add<<"\n";

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



using namespace std;



int main()

{

    //freopen("04.txt","r",stdin);

    int mod,n,i,a[100001]={0},b[100001]={0};

    long long tim[100001]={0};

    long long mul,done=0;

    cin>>n;

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

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

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

    {

        mod=a[i]%b[i];

        if(mod)

            tim[i]=b[i]-mod;

    }

    for(i=n-2;i>=0;i--)

    {

        if(tim[i]>=tim[i+1])

            continue;

        mul=(tim[i+1]-tim[i])/b[i];

        tim[i]+=mul*b[i];

        if(tim[i]<tim[i+1])

            tim[i]+=b[i];

    }

    done=tim[n-1];

    for(i=n-2;i>=0;i--)

    {

        done+=(long long)(tim[i]-tim[i+1]);

    }

    cout<<done;

    return 0;

}


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

using namespace std;

using ll = long long;



void solve() {

    int N;

    cin >> N;

    vector<ll> a(N),b(N);

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

    ll cnt=0;

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

        a[i]+=cnt;

        cnt+=(a[i]+b[i]-1)/b[i]*b[i]-a[i];

    }

    cout << cnt << "\n"; 

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    solve();

    return 0;

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



using namespace std;



int main()

{

    //freopen("04.txt","r",stdin);

    int mod,n,i,a[100001]={0},b[100001]={0};

    long long tim[100001]={0};

    long long mul,done=0;

    cin>>n;

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

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

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

    {

        mod=a[i]%b[i];

        if(mod)

            tim[i]=b[i]-mod;

    }

    for(i=n-2;i>=0;i--)

    {

        if(tim[i]>=tim[i+1])

            continue;

        mul=(tim[i+1]-tim[i])/b[i];

        tim[i]+=mul*b[i];

        if(tim[i]<tim[i+1])

            tim[i]+=b[i];

    }

    done=tim[n-1];

    for(i=n-2;i>=0;i--)

    {

        done+=(long long)(tim[i]-tim[i+1]);

    }

    cout<<done;

    return 0;

}


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

using namespace std;

#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;

typedef long long ll;

typedef double db;



#define mem(a,x) memset(a,x,sizeof(a))

#define pb push_back

#define ff first

#define ss second

#define mk make_pair

#define pi pair<int,int>

#define vi vector<int>

#define pL pair<ll,ll>

#define vL vector<ll>

#define vp vector<pi>

#define vpL vector<pL>



const int MX=1000000;

const ll inf=1e9;

const ll mod=998244353;





ll a[MX], b[MX];



int main()

{



    FasterIO;





    int n;



    cin>>n;



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



    ll sm=0;



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

    {

        ll x=a[i], y=b[i];

        ll rem=(x+sm)%y;

        if(rem) sm+=(y-rem);

    }



    cout<<sm<<endl;



    return 0;

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



using namespace std;



int main()

{

    //freopen("04.txt","r",stdin);

    int mod,n,i,a[100001]={0},b[100001]={0};

    long long tim[100001]={0};

    long long mul,done=0;

    cin>>n;

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

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

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

    {

        mod=a[i]%b[i];

        if(mod)

            tim[i]=b[i]-mod;

    }

    for(i=n-2;i>=0;i--)

    {

        if(tim[i]>=tim[i+1])

            continue;

        mul=(tim[i+1]-tim[i])/b[i];

        tim[i]+=mul*b[i];

        if(tim[i]<tim[i+1])

            tim[i]+=b[i];

    }

    done=tim[n-1];

    for(i=n-2;i>=0;i--)

    {

        done+=(long long)(tim[i]-tim[i+1]);

    }

    cout<<done;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.587081089057236x):
/*

Nahid Hossain

Jahangirnagar University

Roll:54

*/

#include<bits/stdc++.h>

#include<string.h>

#define ll long long

#define pf printf

#define sf scanf

#define ff first

#define ss second

#define clr clear()

#define sz size()

#define pb push_back

#define mk make_pair

#define pi acos(-1)

#define inf 2000000000000000000

#define mod 1000000007

#define ull unsigned long long int

#define f(i,k,n) for(i=k;i<n;i++)

#define fr(i,n,k) for(i=n;i>=k;i--)

#define ent(a) scanf("%lld",&a)

#define ent2(a,b) scanf("%lld%lld",&a,&b)

#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

#define mem(a) memset(a,0,sizeof(a))

#define vec(v,s) vector<ll>v[s]

#define arr(a,s) ll a[s];

//knight and king//

int dr[]= {2,2,-2,-2,1,-1,1,-1};

int dc[]= {1,-1,1,-1,2,2,-2,-2};

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

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

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

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

////////////////////////////

using namespace std;

#define ma 500005



ll a[ma],b[ma];



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    ll n,i,j,x,k;

    while(cin>>n)

    {



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

        {

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

        }

        ll s=0;

        ll ans=0;

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

        {

            ll r=(a[i]+s)%b[i];

            if(r==0)continue;

            r=b[i]-r;

            s+=r;

            ans+=r;

        }

        cout<<ans<<endl;



    }

    return 0;

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

using namespace std;

const int maxn = 2e5+10;

typedef long long ll;

ll n, a[maxn];

ll f(ll x){

	ll sum = 0;

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

		sum += abs(a[i]-(x+i));

	return sum;

}

int main() {

	cin>>n;

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

		cin>>a[i];

	ll l = -1e9, r = 1e9, ans = -1;

	while(l < r-1){

		ll mid = (l+r)>>1;

		ll mmid = (r+mid)>>1;

		if(f(mid) < f(mmid)) r = mmid;

		else l = mid;

	}

	ans = f(l) > f(r)? r:l;

	cout<<f(ans)<<endl;

	return 0;

}

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

#include <algorithm>



using namespace std;

typedef long long lli;



const lli inf=1e18;

int n;

lli arr[200001];

int main() {

	scanf("%d",&n);

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

		scanf("%lld",arr+i);

		arr[i]-=i;

	}

	sort(arr+1,arr+n+1);



	lli val=arr[1],sum=0,mx=inf;

	for(int i=1;i<=n;i++) arr[i]-=val,sum+=arr[i];



	mx=sum;

	for(int i=2;i<=n;i++) {

		sum+=(i-1)*(arr[i]-arr[i-1])- (n-i+1)*(arr[i]-arr[i-1]);

		mx=min(mx,sum);

	}

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



	return 0;

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

using namespace std;

const int maxn = 2e5+10;

typedef long long ll;

ll n, a[maxn];

ll f(ll x){

	ll sum = 0;

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

		sum += abs(a[i]-(x+i));

	return sum;

}

int main() {

	cin>>n;

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

		cin>>a[i];

	ll l = -1e9, r = 1e9, ans = -1;

	while(l < r-1){

		ll mid = (l+r)>>1;

		ll mmid = (r+mid)>>1;

		if(f(mid) < f(mmid)) r = mmid;

		else l = mid;

	}

	ans = f(l) > f(r)? r:l;

	cout<<f(ans)<<endl;

	return 0;

}

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

#include<algorithm>

using namespace std;

long long n,a[200005],cnt,f;

int main(){

	scanf("%lld",&n);

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

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

		a[i]-=i;

	}

	sort(a+1,a+n+1);

	if(n%2==1)f=a[(n+1)/2];

	else f=a[n/2];

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

		cnt+=abs(a[i]-f);

	printf("%lld",cnt);

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

using namespace std;

const int maxn = 2e5+10;

typedef long long ll;

ll n, a[maxn];

ll f(ll x){

	ll sum = 0;

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

		sum += abs(a[i]-(x+i));

	return sum;

}

int main() {

	cin>>n;

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

		cin>>a[i];

	ll l = -1e9, r = 1e9, ans = -1;

	while(l < r-1){

		ll mid = (l+r)>>1;

		ll mmid = (r+mid)>>1;

		if(f(mid) < f(mmid)) r = mmid;

		else l = mid;

	}

	ans = f(l) > f(r)? r:l;

	cout<<f(ans)<<endl;

	return 0;

}

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

#include<algorithm>

using namespace std;

int N,a[1000001];

int main(){

	scanf("%d",&N);

	for(int i=1;i<=N;++i) scanf("%d",a+i), a[i]-=i;

	sort(a+1,a+N+1);

	int X=a[N+1>>1];

	long long Ans=0;

	for(int i=1;i<=N;++i) Ans+=X-a[i]<0?a[i]-X:X-a[i];

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

	return 0;

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

#include<algorithm>

#include<string>

using namespace std;

typedef long long ll;

int n;

ll ans, b;

ll a[200005];

ll f(ll x) { return x > 0 ? x : -x; }

int main()

{

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

	cin >> n;

	for (int i = 1; i <= n; i++)cin >> a[i], a[i] -= i;

	sort(a + 1, a + n + 1);

	b = a[(n + 1) / 2];

	for (int i = 1; i <= n; i++)ans += f(a[i] - b);

	cout << ans;

	return 0;

}

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

#include<algorithm>

using namespace std;

int N,a[1000001];

int main(){

	scanf("%d",&N);

	for(int i=1;i<=N;++i) scanf("%d",a+i), a[i]-=i;

	sort(a+1,a+N+1);

	int X=a[N+1>>1];

	long long Ans=0;

	for(int i=1;i<=N;++i) Ans+=X-a[i]<0?a[i]-X:X-a[i];

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

	return 0;

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

#include<vector>

#include<algorithm>

using namespace std;

int main(){

	long long int a,b,i,d,res=0;

	

	cin>>a;

	vector<int> c(a);

	for(i=0;i<a;i++){

		cin>>c[i];

		c[i]-=i;

	}

	sort(c.begin(),c.end());

	b=c[a/2];

	for(i=0;i<a;i++)res+=abs(c[i]-b);

	cout<<res;

}

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

#include<algorithm>

using namespace std;

int N,a[1000001];

int main(){

	scanf("%d",&N);

	for(int i=1;i<=N;++i) scanf("%d",a+i), a[i]-=i;

	sort(a+1,a+N+1);

	int X=a[N+1>>1];

	long long Ans=0;

	for(int i=1;i<=N;++i) Ans+=X-a[i]<0?a[i]-X:X-a[i];

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

	return 0;

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

using namespace std;

const int maxn = 2e5+10;

typedef long long ll;

ll n, a[maxn];

ll f(ll x){

	ll sum = 0;

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

		sum += abs(a[i]-(x+i));

	return sum;

}

int main() {

	cin>>n;

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

		cin>>a[i];

	ll l = -1e9, r = 1e9, ans = -1;

	while(l < r-1){

		ll mid = (l+r)>>1;

		ll mmid = (r+mid)>>1;

		if(f(mid) < f(mmid)) r = mmid;

		else l = mid;

	}

	ans = f(l) > f(r)? r:l;

	cout<<f(ans)<<endl;

	return 0;

}

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

#include<algorithm>

int n,a[200001];

long long sum=0;

int Abs(int a){return a>0?a:-a;}

using namespace std;

int main(){

	scanf("%d",&n);

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

		scanf("%d",&a[i]);a[i]-=i;

	}

	sort(a,a+n);

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

		sum+=1ll*Abs(a[i]-a[n/2]);

	}

	printf("%lld",sum);

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

#include<algorithm>

#include<string>

using namespace std;

typedef long long ll;

int n;

ll ans, b;

ll a[200005];

ll f(ll x) { return x > 0 ? x : -x; }

int main()

{

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

	cin >> n;

	for (int i = 1; i <= n; i++)cin >> a[i], a[i] -= i;

	sort(a + 1, a + n + 1);

	b = a[(n + 1) / 2];

	for (int i = 1; i <= n; i++)ans += f(a[i] - b);

	cout << ans;

	return 0;

}

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

#include<algorithm>

int n,a[200001];

long long sum=0;

int Abs(int a){return a>0?a:-a;}

using namespace std;

int main(){

	scanf("%d",&n);

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

		scanf("%d",&a[i]);a[i]-=i;

	}

	sort(a,a+n);

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

		sum+=1ll*Abs(a[i]-a[n/2]);

	}

	printf("%lld",sum);

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

#include<vector>

#include<algorithm>

using namespace std;

int main(){

	long long int a,b,i,d,res=0;

	

	cin>>a;

	vector<int> c(a);

	for(i=0;i<a;i++){

		cin>>c[i];

		c[i]-=i;

	}

	sort(c.begin(),c.end());

	b=c[a/2];

	for(i=0;i<a;i++)res+=abs(c[i]-b);

	cout<<res;

}

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

#include<algorithm>

int n,a[200001];

long long sum=0;

int Abs(int a){return a>0?a:-a;}

using namespace std;

int main(){

	scanf("%d",&n);

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

		scanf("%d",&a[i]);a[i]-=i;

	}

	sort(a,a+n);

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

		sum+=1ll*Abs(a[i]-a[n/2]);

	}

	printf("%lld",sum);

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

#include<cstdio>

#include<algorithm>

using namespace std;

#define Min(_A,_B) ((_A)<(_B)?(_A):(_B))

#define Abs(_A) ((_A)>0?(_A):(-(_A)))

#define INF 0x3f3f3f3f



int n;

int a[200005];

void init(){

    scanf("%lld",&n);

    long long sm=0,b;

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

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

        a[i]-=i;

    }

    sort(a+1,a+1+n);

    if(n&1){

        b=a[(n>>1)+1];

    }else{

        b=(a[(n>>1)]+a[(n>>1)+1])>>1;

    }

    long long ans=0;

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

        ans+=Abs(a[i]-b);

    }

    printf("%lld",ans);

}

int main(){

    init();

    return 0;

}

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

#include<algorithm>

int n,a[200001];

long long sum=0;

int Abs(int a){return a>0?a:-a;}

using namespace std;

int main(){

	scanf("%d",&n);

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

		scanf("%d",&a[i]);a[i]-=i;

	}

	sort(a,a+n);

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

		sum+=1ll*Abs(a[i]-a[n/2]);

	}

	printf("%lld",sum);

}