stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

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

#define srep(i,s,t) for(int i = s; i < t; ++i)

#define drep(i,n) for(int i = (n)-1; i >= 0; --i)

using namespace std;

typedef long long int ll;

typedef pair<int,int> P;

#define yn {puts("Yes");}else{puts("No");}

#define MAX_N 200005



#define ch() getchar()

#define pc(x) putchar(x)

template<typename T>inline void read(T&x){

	int f;char c;

	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;

	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;

}



int main() {

    int x[MAX_N] = {}, y[MAX_N] = {};

    int n, q;

    // scanf("%d%d", &n,&q);

    read(n); read(q);

    ll ans = (ll)(n-2)*(n-2);

    srep(i,2,n){

        x[i] = n;

        y[i] = n;

    }

    int xx = n;

    int yy = n;

    while(q--){

        int t, z;

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

        read(t), read(z);

        if(t == 1){

            if(z < xx){

                ans -= yy - 2;

                srep(i,z+1,xx) x[i] = yy;

                xx = z;

            }else{

                ans -= x[z] - 2;

            }

        }else{

            if(z < yy){

                ans -= xx - 2;

                srep(i,z+1,yy) y[i] = xx;

                yy = z;

            }else{

                ans -= y[z] - 2;

            }

        }

    }

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

    return 0;

}






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

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

#define srep(i,s,t) for(int i = s; i < t; ++i)

#define drep(i,n) for(int i = (n)-1; i >= 0; --i)

using namespace std;

typedef long long int ll;

typedef pair<int,int> P;

#define yn {puts("Yes");}else{puts("No");}

#define MAX_N 200005



#define ch() getchar()

#define pc(x) putchar(x)

template<typename T>inline void read(T&x){

	int f;char c;

	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;

	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;

}



int x[MAX_N], y[MAX_N];



int main() {

    int n, q;

    read(n); read(q);

    ll ans = (ll)(n-2)*(n-2);

    int xx = n;

    int yy = n;

    while(q--){

        int t, z;

        read(t), read(z);

        if(t == 1){

            if(z < xx){

                ans -= yy - 2;

                srep(i,z+1,xx) x[i] = yy;

                xx = z;

            }else{

                ans -= x[z] - 2;

            }

        }else{

            if(z < yy){

                ans -= xx - 2;

                srep(i,z+1,yy) y[i] = xx;

                yy = z;

            }else{

                ans -= y[z] - 2;

            }

        }

    }

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

    return 0;

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

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

#define srep(i,s,t) for(int i = s; i < t; ++i)

#define drep(i,n) for(int i = (n)-1; i >= 0; --i)

using namespace std;

typedef long long int ll;

typedef pair<int,int> P;

#define yn {puts("Yes");}else{puts("No");}

#define MAX_N 200005



#define ch() getchar()

#define pc(x) putchar(x)

template<typename T>inline void read(T&x){

	int f;char c;

	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;

	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;

}



int main() {

    int x[MAX_N] = {}, y[MAX_N] = {};

    int n, q;

    // scanf("%d%d", &n,&q);

    read(n); read(q);

    ll ans = (ll)(n-2)*(n-2);

    /*

    srep(i,2,n){

        x[i] = n;

        y[i] = n;

    }

    */

    int xx = n;

    int yy = n;

    while(q--){

        int t, z;

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

        read(t), read(z);

        if(t == 1){

            if(z < xx){

                ans -= yy - 2;

                srep(i,z+1,xx) x[i] = yy;

                xx = z;

            }else{

                ans -= x[z] - 2;

            }

        }else{

            if(z < yy){

                ans -= xx - 2;

                srep(i,z+1,yy) y[i] = xx;

                yy = z;

            }else{

                ans -= y[z] - 2;

            }

        }

    }

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

    return 0;

}






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

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

#define srep(i,s,t) for(int i = s; i < t; ++i)

#define drep(i,n) for(int i = (n)-1; i >= 0; --i)

using namespace std;

typedef long long int ll;

typedef pair<int,int> P;

#define yn {puts("Yes");}else{puts("No");}

#define MAX_N 200005



#define ch() getchar()

#define pc(x) putchar(x)

template<typename T>inline void read(T&x){

	int f;char c;

	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;

	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;

}



int x[MAX_N], y[MAX_N];



int main() {

    int n, q;

    read(n); read(q);

    ll ans = (ll)(n-2)*(n-2);

    int xx = n;

    int yy = n;

    while(q--){

        int t, z;

        read(t), read(z);

        if(t == 1){

            if(z < xx){

                ans -= yy - 2;

                srep(i,z+1,xx) x[i] = yy;

                xx = z;

            }else{

                ans -= x[z] - 2;

            }

        }else{

            if(z < yy){

                ans -= xx - 2;

                srep(i,z+1,yy) y[i] = xx;

                yy = z;

            }else{

                ans -= y[z] - 2;

            }

        }

    }

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

    return 0;

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

using namespace std;

#define ll long long

const int maxn = 2e5 + 5;

int minTA[maxn] , minPA[maxn];

int minTB[maxn] , minPB[maxn];

int lowbit (int x) {return x & -x;}

void modify (int x , int c , int n , int minn[]){

    while (x <= n){

        minn[x] = min (minn[x] , c);

        x += lowbit(x);

    }

}

int ask (int x , int n , int minn[]){

    int ans = 1e9;

    while (x){

        ans = min (ans , minn[x]);

        x -= lowbit(x);

    }

    return ans;

}

int main()

{

    ios::sync_with_stdio(false);

    ll n , q; cin >> n >> q;

    // 初始化

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

        minTA[i] = minTB[i] = minPA[i] = minPB[i] = 1e9;

    }

    ll ans = (n - 2) * (n - 2);

    for (int g = 1 ; g <= q ; g++){

        int op , x; cin >> op >> x;

        if (op == 1){

            int res = ask(x , n , minTA);

            if (res == 1e9) res = g - 1;

            int res2 =  minPB[res];

            if (res2 == 1e9) ans -= n - 2;

            else ans -= res2 - 2;

            modify( x , g , n , minTA );

            minPA[g] = x;

        }else {

            int res = ask(x , n , minTB);

            if (res == 1e9) res = g - 1;

            int res2 =  minPA[res];

            if (res2 == 1e9) ans -= n - 2;

            else ans -= res2 - 2;

            modify( x , g , n , minTB );

            minPB[g] = x;

        }

        minPB[g] = min (minPB[g] , minPB[g - 1]);

        minPA[g] = min (minPA[g] , minPA[g - 1]);

    }

    cout << ans << endl;

    return 0;

}


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

using namespace std;

#define ll long long

const int maxn = 2e5 + 5;

int l[maxn] , h[maxn];

int main()

{

    ios::sync_with_stdio(false);

    ll n , q; cin >> n >> q;

    ll ans = (n - 2) * (n - 2) , maxl = n , maxh = n;

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

        l[i] = n;

        h[i] = n;

    }

    while (q--){

        int op , x; cin >> op >> x;

        if (op == 1){

            if (x < maxl){

                for (int i = x ; i <= maxl - 1 ; i++) l[i] = maxh;

                maxl = x;

            }

            ans -= l[x] - 2;

        }else {

            if (x < maxh){

                for (int i = x ; i <= maxh - 1 ; i++) h[i] = maxl;

                maxh = x;

            }

            ans -= h[x] - 2;

        }

    }

    cout << ans << endl;

    return 0;

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

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

#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)

#define ALL(x) begin(x),end(x)

#define PB push_back

using namespace std;

typedef int64_t LL;

typedef vector<int> VI;

typedef pair<int,int> PII;



template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }

template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }

template<class T> using MaxHeap = priority_queue<T>;

template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {

    sort(begin(v),end(v),f);

    v.resize(unique(begin(v),end(v))-begin(v));

}



const int N=55,MOD=1e9+7;

LL dp[N][N][N*N]; // dp(i,j,k): i之前保留j個空格分數為k



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    int n,k;

    cin >> n >> k;

    dp[0][0][0]=1;

    REP(i,n) REP(j,n+1) REP(k,n*n) {

        // i-i

        dp[i+1][j][k+j*2]+=dp[i][j][k]; dp[i+1][j][k+j*2]%=MOD;

        // i-x i-x

        dp[i+1][j+1][k+(j+1)*2]+=dp[i][j][k]; dp[i+1][j+1][k+(j+1)*2]%=MOD;

        // i-j i-x

        dp[i+1][j][k+j*2]+=dp[i][j][k]*j*2; dp[i+1][j][k+j*2]%=MOD;

        // i-j i-j

        dp[i+1][j-1][k+(j-1)*2]+=dp[i][j][k]*j*j; dp[i+1][j-1][k+(j-1)*2]%=MOD;

    }



    cout << dp[n][0][k] << '\n';

    return 0;

}


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

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

#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)

#define ALL(x) begin(x),end(x)

#define PB push_back

using namespace std;

typedef int64_t LL;

typedef vector<int> VI;

typedef pair<int,int> PII;



template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }

template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }

template<class T> using MaxHeap = priority_queue<T>;

template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {

    sort(begin(v),end(v),f);

    v.resize(unique(begin(v),end(v))-begin(v));

}



const int N=55,MOD=1e9+7;

LL dp[N][N][N*N]; // dp(i,j,k): i之前保留j個空格分數為k



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    int n,K;

    cin >> n >> K;

    dp[0][0][0]=1;

    REP(i,n) REP1(j,0,i) REP1(k,0,K) {

        // i-i

        dp[i+1][j][k+j*2]+=dp[i][j][k]; dp[i+1][j][k+j*2]%=MOD;

        // i-x i-x

        dp[i+1][j+1][k+(j+1)*2]+=dp[i][j][k]; dp[i+1][j+1][k+(j+1)*2]%=MOD;

        // i-j i-x

        dp[i+1][j][k+j*2]+=dp[i][j][k]*j*2; dp[i+1][j][k+j*2]%=MOD;

        // i-j i-j

        if ( j ) {

            dp[i+1][j-1][k+(j-1)*2]+=dp[i][j][k]*j*j; dp[i+1][j-1][k+(j-1)*2]%=MOD;

        }

    }



    cout << dp[n][0][K] << '\n';

    return 0;

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

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

#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)

#define ALL(x) begin(x),end(x)

#define PB push_back

using namespace std;

typedef int64_t LL;

typedef vector<int> VI;

typedef pair<int,int> PII;



template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }

template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }

template<class T> using MaxHeap = priority_queue<T>;

template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {

    sort(begin(v),end(v),f);

    v.resize(unique(begin(v),end(v))-begin(v));

}



const int N=55,MOD=1e9+7;

LL dp[N][N][N*N]; // dp(i,j,k): i之前保留j個空格分數為k



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    int n,k;

    cin >> n >> k;

    dp[0][0][0]=1;

    REP(i,n) REP(j,n+1) REP(k,n*n) {

        // i-i

        dp[i+1][j][k+j*2]+=dp[i][j][k]; dp[i+1][j][k+j*2]%=MOD;

        // i-x i-x

        dp[i+1][j+1][k+(j+1)*2]+=dp[i][j][k]; dp[i+1][j+1][k+(j+1)*2]%=MOD;

        // i-j i-x

        dp[i+1][j][k+j*2]+=dp[i][j][k]*j*2; dp[i+1][j][k+j*2]%=MOD;

        // i-j i-j

        dp[i+1][j-1][k+(j-1)*2]+=dp[i][j][k]*j*j; dp[i+1][j-1][k+(j-1)*2]%=MOD;

    }



    cout << dp[n][0][k] << '\n';

    return 0;

}


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

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

#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)

#define ALL(x) begin(x),end(x)

#define PB push_back

using namespace std;

typedef int64_t LL;

typedef vector<int> VI;

typedef pair<int,int> PII;



template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }

template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }

template<class T> using MaxHeap = priority_queue<T>;

template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {

    sort(begin(v),end(v),f);

    v.resize(unique(begin(v),end(v))-begin(v));

}



const int N=51,MOD=1e9+7;

LL dp[N][N][N*N]; // dp(i,j,k): i之前,保留j個,分數為k



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    int n,K;

    cin >> n >> K;

    dp[0][0][0]=1;

    REP(i,n) REP1(j,0,i) REP1(k,0,K) {

        // i-i

        dp[i+1][j][k+j*2]+=dp[i][j][k]; dp[i+1][j][k+j*2]%=MOD;

        // i-x i-x

        dp[i+1][j+1][k+(j+1)*2]+=dp[i][j][k]; dp[i+1][j+1][k+(j+1)*2]%=MOD;

        // i-j i-x

        dp[i+1][j][k+j*2]+=dp[i][j][k]*j*2; dp[i+1][j][k+j*2]%=MOD;

        // i-j i-j

        if ( j ) {

            dp[i+1][j-1][k+(j-1)*2]+=dp[i][j][k]*j*j; dp[i+1][j-1][k+(j-1)*2]%=MOD;

        }

    }



    cout << dp[n][0][K] << '\n';

    return 0;

}
// Slower C++ solution:
// Why am I so dumb? :c

#include <bits/stdc++.h>



#define pb push_back

#define mp make_pair



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



#define fi first

#define se second



using namespace std;



typedef long long ll;



const int MAXN = 50 + 5;



int a[MAXN], b[MAXN];



ll pw[MAXN];



ll ans;



int n;



void pre() {

    pw[0] = 1;



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

        pw[i] = (pw[i - 1] << 1);

    }

}



bool bit(ll m, int ps) {

    return m & pw[ps];

}



bool check(set<int> S) {

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

        ll m = pw[a[i]];



        for (auto it = S.rbegin(); it != S.rend(); ++it) {

            int x = *it;



            for (int p = 1; p <= 50; ++p) {

                if (bit(m, p)) {

                    m |= pw[p % x];

                }

            }

        }



        if (!bit(m, b[i])) {

            return 0;

        }

    }



    return 1;

}



void solve() {

    scanf("%d", &n);



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

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

    }



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

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

    }



    set<int> S;



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

        S.insert(i);

    }



    if (!check(S)) {

        printf("-1\n");

        return;

    }



    for (int cur = 50; cur > 0; --cur) {

        S.erase(cur);



        if (!check(S)) {

            S.insert(cur);

        }

    }



    for (int x : S) {

        ans += pw[x];

    }



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

}



int main() {

    int tt = 1;



    pre();



    while (tt--) {

        solve();

    }



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1976618318839785x):
// Why am I so dumb? :c

#include<bits/stdc++.h>



#define pb push_back

#define mp make_pair



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



#define fi first

#define se second



using namespace std;



typedef long long ll;



int a[55], b[55];



int n;



bool bit(ll x, int p) {

	return x & (1ll << p);

}



bool check(ll m) {

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

		ll cur = (1ll << a[i]);



		for (int j = 50; j > 0; --j) {

			if (bit(m, j)) {

				for (int p = 0; p < j; ++p) {

					if (!bit(cur, p)) {

						for (int nx = p + j; nx <= 50; nx += j) {

							if (bit(cur, nx)) {

								cur |= (1ll << p);

								break;

							}

						}

					}

				}                

			}			

		}



		if (!bit(cur, b[i])) {

			return 0;

		}

	}	



	return 1;

}



void solve() {

	scanf("%d", &n);



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

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

	}



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

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

	}



	ll mask = (1ll << 51) - 2ll;



	if (!check(mask)) {

		printf("-1\n");

		return;

	}



	for (int i = 50; i > 0; --i) {

		mask -= (1ll << i);



		if (!check(mask)) {

			mask += (1ll << i);

		}

	}



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

}



int main() {

    int tt = 1;



    while (tt--) {

        solve();

    }



    return 0;

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

#include <algorithm>

using namespace std;



long long d[10],v[10];



void compute(int n){

    for(int i = 2 ; i <= min(d[n],v[n]) ; i++){

        if(d[n]%i==0||v[n]%i==0){

            while(d[n]%i==0&&v[n]%i==0){

                d[n] /= i;

                v[n] /= i;

            }

        }

    }

}



int main(){

    int n;

    

    while(cin >>n,n){

        long long a,b;

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

            cin >> d[i] >> v[i];

            compute(i);

        }

        

        a = (d[0]*d[1])/__gcd(d[0],d[1]);

        b = __gcd(v[0],v[1]);

        

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

            a = (a*d[i])/__gcd(a,d[i]);

            b = __gcd(b,v[i]);

        }



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

            cout << a*v[i]/(b*d[i]) << endl;

        }

    }

    

    return 0;

}

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

#include <cmath>

#include <algorithm>



using namespace std;



#define MAX 10

typedef long long ll;



ll d[MAX],v[MAX];



ll gcd(ll a,ll b){

  return __gcd(a,b);

}



ll lcm(ll a,ll b){

  return a * b / gcd(a,b);

}



int main(){

  int n;



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

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

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

      ll a = gcd(d[i],v[i]);

      d[i] /= a;

      v[i] /= a;

    }       

    

    ll T = d[0],V = v[0];

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

      T = lcm(T,d[i]);

      V = gcd(V,v[i]);

    }

    

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

      ll div = T / d[i];

      printf("%lld\n" ,div*v[i]/V);

    }

  }

  

  return 0;

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

using namespace std;



typedef long long ll;



ll gcd(ll a,ll b){

  return (!b)?a:gcd(b,a%b);

}



int main(){

  int n;

  ll d[10],v[10],t[10];



  for(;;){

    cin >> n;

    if(!n)break;



    for(int i=0;i<n;i++)cin >> d[i] >> v[i];

    t[0] = 1;

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

      t[i] = t[i-1]*d[i-1]*v[i];

      for(int j=0;j<i;j++)t[j] *= d[i]*v[i-1];

      ll T = t[0];

      for(int j=1;j<=i;j++)T = gcd(T,t[j]);

      for(int j=0;j<=i;j++)t[j]/=T;

    }



    for(int i=0;i<n;i++)cout << t[i] << endl;

  }

}

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

using namespace std;

typedef long long ll;



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



int main(){

  int n,i,j;

  ll d[10],v[10],t[10];



  for(;;){

    scanf("%d",&n);

    if(!n)break;



    for(i=0;i<n;i++)scanf("%lld %lld",&d[i],&v[i]);

    t[0] = 1;

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

      t[i] = t[i-1]*d[i-1]*v[i];

      for(j=0;j<i;j++)t[j] *= d[i]*v[i-1];

      ll T = t[0];

      for(j=1;j<=i;j++)T = gcd(T,t[j]);

      for(j=0;j<=i;j++)t[j]/=T;

    }



    for(i=0;i<n;i++)printf("%lld\n",t[i]);

  }

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

#include<cstring>

#include<iostream>

using namespace std;

typedef long long LL;

int main(){

	LL n,T;

	cin>>n>>T;

	LL t,temp;

	cin>>t;

	temp=t;

	LL sum=n*T;

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

		cin>>t;

		t=t-temp;

		temp=temp+t;

		if(t<T) sum-=T-t;

	}

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

return 0;

}


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

#include<cstdlib>

#include<cstring>

#include<queue>

#include<algorithm>

#include<cmath>

#include<map>

#include<set>

using namespace std;

const int Max= 2e5;

long long t[Max+1];

int main()

{

	int n,T,sum;

	scanf("%d%d",&n,&T);

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

	{

		scanf("%d",&t[i]);

	}

	sum=T;

	if(n>1)

	{

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

		{

			if(t[i+1]-t[i]>=T)

				sum=sum+T;

			

			else 

				sum=sum+t[i+1]-t[i];

		

}

		printf("%d\n",sum);

}

if(n==1){

	printf("%d\n",T);

}

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

#include<cstdlib>

#include<cstring>

#include<string>

#include<iostream>

#include<cmath>

#include<algorithm>

using namespace std;

const int MaxN = 2e5;

long long a[MaxN + 5];

int N;

long long T, x;



int main()

{

	long long flag = 0;

	scanf("%d %lld", &N, &T);

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

	{

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

	}

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

	{

		if(a[i] <= T)

		{

			flag = a[i];

			x = a[i];

		}

		else if(a[i] - a[i - 1] > T) x = x + T;

		else x = x + a[i] - a[i - 1];

	}

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

	return 0;

}

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

#include<cstdlib>

#include<cstring>

#include<queue>

#include<algorithm>

#include<cmath>

#include<map>

#include<set>

using namespace std;

const int Max= 2e5;

long long t[Max+1];

int main()

{

	int n,T,sum;

	scanf("%d%d",&n,&T);

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

	{

		scanf("%d",&t[i]);

	}

	sum=T;

	if(n>1)

	{

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

		{

			if(t[i+1]-t[i]>=T)

				sum=sum+T;

			

			else 

				sum=sum+t[i+1]-t[i];

		

}

		printf("%d\n",sum);

}

if(n==1){

	printf("%d\n",T);

}

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

#include<cstdlib>

#include<cmath>

#include<iostream>

#include<algorithm>

#include<map>

#include<cstring>

#include<string>

using namespace std;

typedef long long LL;

const int  MaxN = 200000;



int tim[MaxN + 10];

int main()

{

	int N, T, sum = 0;

	cin >> N >> T;

	for(int i = 1;i <= N;i++) cin >> tim[i];

	if(N == 1) cout << T << endl;

	else{

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

			int t = tim[i] - tim[i-1];

			if(t < T) sum += t;

			else sum += T;

		}

		sum += T;

		cout << sum << endl;

	}

	return 0;

}

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

#include<cstdlib>

#include<cstring>

#include<queue>

#include<algorithm>

#include<cmath>

#include<map>

#include<set>

using namespace std;

const int Max= 2e5;

long long t[Max+1];

int main()

{

	int n,T,sum;

	scanf("%d%d",&n,&T);

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

	{

		scanf("%d",&t[i]);

	}

	sum=T;

	if(n>1)

	{

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

		{

			if(t[i+1]-t[i]>=T)

				sum=sum+T;

			

			else 

				sum=sum+t[i+1]-t[i];

		

}

		printf("%d\n",sum);

}

if(n==1){

	printf("%d\n",T);

}

}