stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
// 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;

}

// Optimized solution to the same problem (faster):
// 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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

  }

}

// Optimized solution to the same problem (faster):
#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]);

  }

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <stdio.h>

#include <string>

#include <cstring>

#include <stdlib.h>

#include <math.h>

#include <algorithm>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <list>

#include <iterator>

#include <assert.h>

#pragma warning(disable:4996) 

 

typedef long long ll;

#define MIN(a, b) ((a)>(b)? (b): (a))

#define MAX(a, b) ((a)<(b)? (b): (a))

#define LINF 9223300000000000000

#define INF 2140000000

const long long MOD = 1000000007;

//const long long MOD = 998244353;



using namespace std;





void solve()

{

    int n, T;

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

    vector<int> a(n);

    int i;

    ll sum = 0;

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

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

        if (i > 0) sum += MIN(T, a[i] - a[i - 1]);

    }

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

    return;

}



int main(int argc, char* argv[])

{

#if 1

    solve();

#else

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

    while(T--) {

        solve();

    }

#endif

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <string>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <algorithm>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <list>

#include <iterator>

#include <cassert>

#include <numeric>

#include <functional>

#include <cassert>

//#include <numeric>

#pragma warning(disable:4996) 

 

typedef long long ll;

typedef unsigned long long ull;

#define MIN(a, b) ((a)>(b)? (b): (a))

#define MAX(a, b) ((a)<(b)? (b): (a))

#define LINF  9223300000000000000

#define LINF2 1223300000000000000

#define INF 2140000000

const long long MOD = 1000000007;

//const long long MOD = 998244353;



using namespace std;







void solve()

{

    int n, T;

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

    int i;

    int prev = -1;

    ll sum = 0;

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

        int tmp;

        scanf("%d", &tmp);

        if (i > 0) {

            if (tmp > prev + T) {

                sum += T;

            }

            else {

                sum += (tmp - prev);

            }

        }

        prev = tmp;

    }

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



    return;

}



int main(int argc, char* argv[])

{

#if 1

    solve();

#else

    int T;

    scanf("%d", &T);

    int t;

    for(t=0; t<T; t++) {

        //printf("Case #%d: ", t+1);

        solve();

    }

#endif

    return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<cmath>

#include<algorithm>

#include<iostream>

using namespace std;

int main(){

	long long n,T,t[200000];

	long long sum=0;

	cin>>n>>T;

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

		cin>>t[i];

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

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

			sum+=T;

		else

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

	}

	sum+=T;

	cout<<sum<<endl;

}








// Optimized solution to the same problem (faster):
#include<cstdio>

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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cmath>

#include<cstring>

#include<iostream>

#include<cstdlib>

#include<algorithm>

#include<map>

using namespace std;



int n, t;

int a[200005];

int main()

{

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

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

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

	long long sum = 0;

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

	{

		int ant = a[i] - a[i-1];

		if(ant < t) sum += ant;

		else sum += t;

	}

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

}


// Optimized solution to the same problem (faster):
#include<cstdio>

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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

int n,t,a[200005],l,r,j;

long long s;

int main()

{

	cin>>n>>t;

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

	{

		cin>>a[i];

	}



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

	{

	  if(i==n)s+=t;

	  else if(a[i+1]-a[i]<=t)s=s+a[i+1]-a[i];

	  else if(a[i+1]-a[i]>t)s+=t;

	}

	cout<<s;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
    #include<iostream>

    #include<cstring>

    #include<cstdio>

    #include<cstdlib>

    #include<algorithm>

    #include<map>

    #include<cmath>

    #include<cstdlib>

    using namespace std;

    const int M=200005;

long long int n,m,flag,sum;

int a[M];

int main()

{

   cin>>n>>m;

   cin>>a[1];

   sum=0;

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

   {

        cin>>a[i];

        if(a[i]-a[i-1]>=m)

            sum+=m;

        else if(a[i]-a[i-1]<m)

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

   }

   sum+=m;

   cout<<sum<<endl;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <stdio.h>

int main()

{

	int a[200005];

	int b[200005];

	int n, i, t;

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

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

	{

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

		b[i] = a[i] + t;

	}

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

	{

		if(b[i] > a[i + 1])

		{

			a[i + 1] = b[i];

		}

	}

	int sum = 0;

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

	{

		sum = sum + b[i] - a[i];

	}

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

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<cmath>

#include<map>

#include<iostream>

#include<algorithm>

using namespace std; 

int n,t;

int a[200005];



int main()

{

	cin>>n>>t;

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

	{

		cin>>a[i];

	}

	int ans=t;

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

	{

		int temp;

		temp=a[i]-a[i-1];

		if(temp>=t)

		   ans+=t;

		else

		   ans+=temp;

	}

	cout<<ans<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<cmath>

#include<iostream>

#include<algorithm>

using namespace std;

int main()

{

	long long int i,N,T,X = 0,t[200005];

	scanf("%lld %lld\n",&N,&T);

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

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

	if(N > 1)

	{

		for(i = 0;i < N - 1; i++)

		{

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

				X += T;

			else

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

		}

	}

		X += T;

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

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



typedef long long ll;



using namespace std;



int main() {

    ll n, t, prev;

    cin >> n >> t >> prev;

    ll now, cnt = t;

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

        cin >> now;

        if (now < prev + t) cnt += (now - prev);

        else cnt += t;

        prev = now;

    }

    cout << cnt << endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>



typedef long long ll;



using namespace std;



int main() {

    ll n, t, prev;

    scanf("%lld%lld%lld", &n, &t, &prev);

    ll now, cnt = t;

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

        scanf("%lld", &now);

        if (now < prev + t) cnt += (now - prev);

        else cnt += t;

        prev = now;

    }

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<string>

#include<queue>

#include<algorithm>

#include<iostream>

#include<cmath>

#include<map>

#include<set>

using namespace std;

int main()

{

	int N,T,A,B;

	while( scanf(" %d %d",&N,&T) != EOF ){

		scanf(" %d",&A);

		int sum = 0;

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

			scanf(" %d",&B);

			if( B - A > T )

				sum += T;

			else

				sum += (B - A);

			A = B;

		}

		sum += T;

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

	}

}

// Optimized solution to the same problem (faster):
#include<cstdio>

const int maxn = 2e6 + 5;

long long a[maxn];

int main(){

	int n ;

	long long m ;

	scanf("%d%lld",&n,&m);

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

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

		}

	long long sum = m;

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

		if(a[i] - a[i - 1] >= m)sum += m;

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

		}

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

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

using namespace std;



typedef long long ll;



const int N  = 200030;

ll t[N];



int main()

{

    int n,T;

    cin >> n >> T;

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

    {

        cin >> t[i];

    }



    ll sum = 0;

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

    {

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

        else sum += (t[i]-t[i-1]);

    }

    cout << sum+T << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

const int maxn = 2e6 + 5;

long long a[maxn];

int main(){

	int n ;

	long long m ;

	scanf("%d%lld",&n,&m);

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

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

		}

	long long sum = m;

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

		if(a[i] - a[i - 1] >= m)sum += m;

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

		}

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

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cmath>

#include<cstring>

#include<iostream>

#include<cstdlib>

#include<algorithm>

#include<map>

using namespace std;



int n, t;

int a[200005];

int main()

{

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

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

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

	long long sum = 0;

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

	{

		int ant = a[i] - a[i-1];

		if(ant < t) sum += ant;

		else sum += t;

	}

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

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<string>

#include<cstdlib>

#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 += T;

			else

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

		}

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

		return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<algorithm>

#include<cstring>

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

	int a[200005];

	long long sum = 0, n, i, t;

	scanf("%lld%lld",&n,&t);

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

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

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

	{

		if(i == 0&&n == 1)

		{

			sum = sum + t;

			continue;

		}

		if(i > 0)

		{

		    if((a[i]-a[i-1])>=t)

		    	sum += t;

     		else

	     		sum += (a[i]-a[i-1]);

	    }

	}

	if(i != 1)

	sum = sum + t;

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

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<string>

#include<cstdlib>

#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 += T;

			else

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

		}

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

		return 0;

}

// Fastest known solution for this problem: