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

#include <cstring>

#include <iostream>

#include <algorithm>

#define ll long long

using namespace std;

#define N 100005

#define mod 1000000007

int n, m, x[N];

struct Matrix

{

	int A[3][3];

	Matrix(){memset(A, 0, sizeof A);}

	Matrix operator * (const Matrix &b)const

	{

		Matrix c;

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

			for (int k = 0; k < 3; k++)

				for (int j = 0; j < 3; j++)

					c.A[i][j] = (c.A[i][j] + (ll)A[i][k] * b.A[k][j]) % mod;

		return c;

	}

	void Init()

	{

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

			for (int j = 0; j < 3; j++)

				A[i][j]=1;

		A[0][1] = A[2][1] = A[2][2]=2;

		A[1][0] = 0;

	}

}ans, now, oth, mat, one;

void Pow(int k)

{

	now = one;

	mat.Init();

	while (k)

	{

		if (k & 1)

			now = now * mat;

		mat = mat * mat;

		k >>= 1;

	}

}

int main()

{

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

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

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

	x[++m] = n;

	oth.Init();

	oth.A[2][1] = oth.A[2][0] = 0;

	oth.A[2][2] = 1;

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

		one.A[i][i] = 1;

	ans.A[0][0] = 1;

	Pow(x[1]);

	ans = ans * now;

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

		{

			ans = ans * oth;

			Pow(x[i + 1] - x[i] - 1);

			ans = ans * now;

		}

	printf("%d\n", ans.A[0][2]);

}


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

#include <assert.h>



typedef long long LL;



const int MAXM = 1e5, MOD = 1e9 + 7;

int n, m;



inline int add ( int a, const int b ) { return ( a += b ) < MOD ? a : a - MOD; }

inline int mul ( LL a, const int b ) { return ( a *= b ) < MOD ? a : a % MOD; }



inline int rint () {

	int x = 0; char s = getchar ();

	for ( ; s < '0' || '9' < s; s = getchar () );

	for ( ; '0' <= s && s <= '9'; s = getchar () ) x = x * 10 + ( s ^ '0' );

	return x;

}



struct Matrix {

	int n, m, mat[3][3];

	Matrix (): n ( 0 ), m ( 0 ), mat {} {}

	Matrix ( const int tn, const int tm ): n ( tn ), m ( tm ), mat {} {}

	inline int* operator [] ( const int key ) { return mat[key]; }

	inline Matrix operator * ( Matrix t ) {

		assert ( m == t.n );

		Matrix ret ( n, t.m );

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

			for ( int k = 0; k < m; ++ k ) {

				for ( int j = 0; j < t.m; ++ j ) {

					ret[i][j] = add ( ret[i][j], mul ( mat[i][k], t[k][j] ) );

				}

			}

		}

		return ret;

	}

};



inline Matrix qkpow ( Matrix a, int b ) {

	Matrix ret ( a.n, a.m );

	for ( int i = 0; i < ret.n; ++ i ) ret[i][i] = 1;

	for ( ; b; a = a * a, b >>= 1 ) if ( b & 1 ) ret = ret * a;

	return ret;

}



Matrix I ( 3, 1 ), A ( 3, 3 ), B ( 3, 3 );



inline void init () {

	I[0][0] = 1;

	A[0][0] = 1;

	A[1][0] = 2, A[1][1] = 1;

	A[2][0] = A[2][1] = A[2][2] = 1;

	B = A, ++ B[0][0], ++ B[0][1], ++ B[0][2];

}



int main () {

	init ();

	n = rint (), m = rint ();

	int las = 0;

	for ( int i = 1, x; i <= m; ++ i ) {

		x = rint ();

		I = A * qkpow ( B, x - las - 1 ) * I;

		las = x;

	}

	

	I = A * qkpow ( B, n - las - 1 ) * I;

	printf ( "%d\n", I[2][0] );

	return 0;

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

#include<cstring>

#include<cstdio>

#define LL long long

using namespace std;

int n,m;

const int N=100010,mod=1e9+7;

int a[N];

struct ju

{

	LL v[3][3];

	ju(){memset(v,0,sizeof(v));}

	friend ju operator *(const ju &a,const ju &b)

	{

		ju c;

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

			for(int j=0;j<=2;++j)

				for(int k=0;k<=2;++k)

					(c.v[i][j]+=a.v[i][k]*b.v[k][j])%=mod;

		return c;

	}

}A,B,Ans;

ju ksm(ju a,LL b)

{

	ju res;res.v[0][0]=res.v[1][1]=res.v[2][2]=1;

	for(;b;b>>=1,a=a*a)

		if(b&1)res=res*a;

	return res;

}

signed main()

{

	cin>>n>>m;

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

	A.v[0][0]=A.v[1][0]=A.v[1][2]=2;

	A.v[0][1]=A.v[0][2]=A.v[1][1]=A.v[2][0]=A.v[2][2]=1;

	

	B.v[0][0]=B.v[0][1]=B.v[0][2]=B.v[1][1]=B.v[2][2]=1;

	B.v[1][2]=2;

	

	Ans.v[0][0]=1;

	for(int i=1;i<=m;++i)Ans=Ans*ksm(A,a[i]-a[i-1]-1)*B;

	Ans=Ans*ksm(A,n-a[m]);

	cout<<Ans.v[0][2];

	return 0;

}

/*

3 1 

2



13



5 2

2 3



66



10 9

1 2 3 4 5 6 7 8 9



100

*/

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

#include <assert.h>



typedef long long LL;



const int MAXM = 1e5, MOD = 1e9 + 7;

int n, m;



inline int add ( int a, const int b ) { return ( a += b ) < MOD ? a : a - MOD; }

inline int mul ( LL a, const int b ) { return ( a *= b ) < MOD ? a : a % MOD; }



inline int rint () {

	int x = 0; char s = getchar ();

	for ( ; s < '0' || '9' < s; s = getchar () );

	for ( ; '0' <= s && s <= '9'; s = getchar () ) x = x * 10 + ( s ^ '0' );

	return x;

}



struct Matrix {

	int n, m, mat[3][3];

	Matrix (): n ( 0 ), m ( 0 ), mat {} {}

	Matrix ( const int tn, const int tm ): n ( tn ), m ( tm ), mat {} {}

	inline int* operator [] ( const int key ) { return mat[key]; }

	inline Matrix operator * ( Matrix t ) {

		assert ( m == t.n );

		Matrix ret ( n, t.m );

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

			for ( int k = 0; k < m; ++ k ) {

				for ( int j = 0; j < t.m; ++ j ) {

					ret[i][j] = add ( ret[i][j], mul ( mat[i][k], t[k][j] ) );

				}

			}

		}

		return ret;

	}

};



inline Matrix qkpow ( Matrix a, int b ) {

	Matrix ret ( a.n, a.m );

	for ( int i = 0; i < ret.n; ++ i ) ret[i][i] = 1;

	for ( ; b; a = a * a, b >>= 1 ) if ( b & 1 ) ret = ret * a;

	return ret;

}



Matrix I ( 3, 1 ), A ( 3, 3 ), B ( 3, 3 );



inline void init () {

	I[0][0] = 1;

	A[0][0] = 1;

	A[1][0] = 2, A[1][1] = 1;

	A[2][0] = A[2][1] = A[2][2] = 1;

	B = A, ++ B[0][0], ++ B[0][1], ++ B[0][2];

}



int main () {

	init ();

	n = rint (), m = rint ();

	int las = 0;

	for ( int i = 1, x; i <= m; ++ i ) {

		x = rint ();

		I = A * qkpow ( B, x - las - 1 ) * I;

		las = x;

	}

	

	I = A * qkpow ( B, n - las - 1 ) * I;

	printf ( "%d\n", I[2][0] );

	return 0;

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

using namespace std;



//#define int long long

#define DBG 0

#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}

#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}

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

#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)

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

static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;

static const int MOD = (int)(1e9 + 7);



//????????????

class Dice {

private:

	map<char, string> mp;

public:

	//string d = "UFRLBD";

	string d = "RENSWL";

	vector<int> v; //UFRLBD:123456

	Dice() {

		init();

		v.resize(6);

	};

	Dice(vector<int> v) :v(v) {

		init();

	};

	void init(){

		mp[d[0]] = "2354";

		mp[d[1]] = "1463";

		mp[d[2]] = "1265";

		mp[d[3]] = "1562";

		mp[d[4]] = "1364";

		mp[d[5]] = "2453";

	}

	void input() { rep(i, 0, 6) { cin >> v[i]; } }

	void roll(char c) { roll(mp[c]); }

	void roll(string s) {

		int tmp = v[s[0] - '1'];

		rep(i, 1, s.size())v[s[i - 1] - '1'] = v[s[i] - '1'];

		v[s[s.size() - 1] - '1'] = tmp;

	}

	bool operator==(const Dice &D)const { return v == D.v; }

};



signed main() {

	int n; cin >> n;

	vector<Dice> D(n); rep(i, 0, n) { D[i].input(); }

	rep(i, 0, n) {

		rep(j, i + 1, n) {

			rep(k, 0, 1000) {

				if (D[i] == D[j]) {

					cout << "No" << endl;

					return 0;

				}

				D[j].roll( D[j].d[rand() % 6] );

			}

		}

	}

	cout << "Yes" << endl;

	return 0;

}

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

using namespace std;



//#define int long long

#define DBG 0

#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}

#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}

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

#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)

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

static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;

static const int MOD = (int)(1e9 + 7);



//????????????

class Dice {

private:

	map<char, string> mp;

public:

	//string d = "UFRLBD";

	string d = "RENSWL";

	vector<int> v; //UFRLBD:123456

	Dice() {

		init();

		v.resize(6);

	};

	Dice(vector<int> v) :v(v) {

		init();

	};

	void init(){

		mp[d[0]] = "2354";

		mp[d[1]] = "1463";

		mp[d[2]] = "1265";

		mp[d[3]] = "1562";

		mp[d[4]] = "1364";

		mp[d[5]] = "2453";

	}

	void input() { rep(i, 0, 6) { cin >> v[i]; } }

	void roll(char c) { roll(mp[c]); }

	void roll(string s) {

		int tmp = v[s[0] - '1'];

		rep(i, 1, s.size())v[s[i - 1] - '1'] = v[s[i] - '1'];

		v[s[s.size() - 1] - '1'] = tmp;

	}

	bool operator==(const Dice &D)const { return v == D.v; }

};



signed main() {

	int n; cin >> n;

	vector<Dice> D(n); rep(i, 0, n) { D[i].input(); }

	rep(i, 0, n) {

		rep(j, i + 1, n) {

			rep(k, 0, 100) {

				if (D[i] == D[j]) {

					cout << "No" << endl;

					return 0;

				}

				D[j].roll( D[j].d[rand() % 6] );

			}

		}

	}

	cout << "Yes" << endl;

	return 0;

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

using namespace std;



//#define int long long

#define DBG 0

#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}

#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}

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

#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)

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

static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;

static const int MOD = (int)(1e9 + 7);



//????????????

class Dice {

private:

	map<char, string> mp;

public:

	//string d = "UFRLBD";

	string d = "RENSWL";

	vector<int> v; //UFRLBD:123456

	Dice() {

		init();

		v.resize(6);

	};

	Dice(vector<int> v) :v(v) {

		init();

	};

	void init(){

		mp[d[0]] = "2354";

		mp[d[1]] = "1463";

		mp[d[2]] = "1265";

		mp[d[3]] = "1562";

		mp[d[4]] = "1364";

		mp[d[5]] = "2453";

	}

	void input() { rep(i, 0, 6) { cin >> v[i]; } }

	void roll(char c) { roll(mp[c]); }

	void roll(string s) {

		int tmp = v[s[0] - '1'];

		rep(i, 1, s.size())v[s[i - 1] - '1'] = v[s[i] - '1'];

		v[s[s.size() - 1] - '1'] = tmp;

	}

	bool operator==(const Dice &D)const { return v == D.v; }

};



signed main() {

	int n; cin >> n;

	vector<Dice> D(n); rep(i, 0, n) { D[i].input(); }

	rep(i, 0, n) {

		rep(j, i + 1, n) {

			rep(k, 0, 1000) {

				if (D[i] == D[j]) {

					cout << "No" << endl;

					return 0;

				}

				D[j].roll( D[j].d[rand() % 6] );

			}

		}

	}

	cout << "Yes" << endl;

	return 0;

}

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

using namespace std;



//#define int long long

#define DBG 0

#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}

#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}

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

#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)

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

static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;

static const int MOD = (int)(1e9 + 7);



//????????????

class Dice {

private:

	map<char, string> mp;

public:

	//string d = "UFRLBD";

	string d = "RENSWL";

	vector<int> v; //UFRLBD:123456

	Dice() {

		init();

		v.resize(6);

	};

	Dice(vector<int> v) :v(v) {

		init();

	};

	void init(){

		mp[d[0]] = "2354";

		mp[d[1]] = "1463";

		mp[d[2]] = "1265";

		mp[d[3]] = "1562";

		mp[d[4]] = "1364";

		mp[d[5]] = "2453";

	}

	void input() { rep(i, 0, 6) { cin >> v[i]; } }

	void roll(char c) { roll(mp[c]); }

	void roll(string s) {

		int tmp = v[s[0] - '1'];

		rep(i, 1, s.size())v[s[i - 1] - '1'] = v[s[i] - '1'];

		v[s[s.size() - 1] - '1'] = tmp;

	}

	bool operator==(const Dice &D)const { return v == D.v; }

};



signed main() {

	int n; cin >> n;

	vector<Dice> D(n); rep(i, 0, n) { D[i].input(); }

	rep(i, 0, n) {

		rep(j, i + 1, n) {

			rep(k, 0, 30) {

				if (D[i] == D[j]) {

					cout << "No" << endl;

					return 0;

				}

				D[j].roll( D[j].d[rand() % 6] );

			}

		}

	}

	cout << "Yes" << endl;

	return 0;

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

#include <vector>

#include <limits>

using namespace std;



inline int f(int n)

{

  return max(0, min(255, n));

}



int main()

{

  int N, M;

  while (cin >> N >> M && N != 0) {

    vector<int> cs(M);

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

      cin >> cs[i];

    }

    vector<int> xs(N);

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

      cin >> xs[i];

    }



    vector<vector<int> > dp(N+1, vector<int>(256, 100000000));

    dp[0][128] = 0;

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

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

        for (int k = 0; k < M; k++) {

          const int y = f(j+cs[k]);

          dp[i+1][y] = min(dp[i+1][y], dp[i][j] + (xs[i]-y)*(xs[i]-y));

        }

      }

    }

    int ans = numeric_limits<int>::max();

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

      ans = min(ans, dp[N][i]);

    }

    cout << ans << endl;

  }

  return 0;

}

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

#include <vector>

#include <algorithm>

using namespace std;



int sqr(int x) { return x*x; }



int main()

{

  int N, M;

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

    vector<int> cs(M);

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

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

    }



    static long long dp[20000+1][256];

    static const long long INF = 1LL<<50;

    fill_n(dp[0], 256, INF);

    dp[0][128] = 0;

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

      int x;

      scanf("%d", &x);

      fill_n(dp[i], 256, INF);

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

        for (int k = 0; k < M; k++) {

          int y = j + cs[k];

          if (y < 0) {

            y = 0;

          } else if (y > 255) {

            y = 255;

          }

          dp[i][y] = min(dp[i][y], dp[i-1][j] + sqr(y - x));

        }

      }

    }

    printf("%lld\n", *min_element(dp[N], dp[N]+256));

  }

  return 0;

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

#include <cmath>

#include <algorithm>

#include <bits/stdc++.h>

const int maxn = 1e5 + 10;

using namespace std;

int main()

{

    int n, x;

    long long a[maxn] = {0};

    cin >> n >> x;

    long long  count = 0;

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

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

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

    {

        if (a[i] > x)

        {

            count += (a[i] - x);

            a[i] = x;

        }

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

        {

            count += (a[i+1] + a[i] - x);

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

        }

    }

    cout << count << endl;

    return 0;

}

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

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

using namespace std;



typedef long long ll;

typedef pair<int,int> ii;

typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;



int main() {

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

	int N,x; cin>>N>>x;

	vector<int> a(N);

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

		cin>>a[i];

	ll ret=0;

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

		if(a[i-1]+a[i]<=x)

			continue;

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

		ret+=cur;

		a[i]-=min(a[i],cur);

	}

	cout<<ret<<"\n";

	return 0;

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

#include <cmath>

#include <algorithm>

#include <bits/stdc++.h>

const int maxn = 1e5 + 10;

using namespace std;

int main()

{

    int n, x;

    long long a[maxn] = {0};

    cin >> n >> x;

    long long  count = 0;

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

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

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

    {

        if (a[i] > x)

        {

            count += (a[i] - x);

            a[i] = x;

        }

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

        {

            count += (a[i+1] + a[i] - x);

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

        }

    }

    cout << count << endl;

    return 0;

}

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

using namespace std;

int main(){

	int n,x; 

	cin>>n>>x;

	vector<int>a(n);

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

		cin>>a[i];

	long long ret=0;

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

		if(a[i-1]+a[i]>x){

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

			ret+=diff;

			if(a[i]<diff){

				diff-=a[i];

				a[i]=0;

				a[i-1]-=diff;

			}

			else{

				a[i]-=diff;

			}

		}

	}

	cout<<ret<<endl;

	return 0;

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

#include <cmath>

#include <algorithm>

#include <bits/stdc++.h>

const int maxn = 1e5 + 10;

using namespace std;

int main()

{

    int n, x;

    long long a[maxn] = {0};

    cin >> n >> x;

    long long  count = 0;

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

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

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

    {

        if (a[i] > x)

        {

            count += (a[i] - x);

            a[i] = x;

        }

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

        {

            count += (a[i+1] + a[i] - x);

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

        }

    }

    cout << count << endl;

    return 0;

}

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

#include<algorithm>

#include<string>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/rope>

using namespace __gnu_cxx;

using namespace __gnu_pbds;

using namespace std;



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

#define pi acos(-1.0)



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

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

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

#define pf(a) printf("%lld\n",a)



#define stll(a) stoll(a,nullptr,10)

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

#define PII pair<ll,ll>

#define MP(a,b) make_pair(a,b)

#define pb(a) push_back(a)

#define EL printf("\n")

#define ff first

#define ss second

#define rev(a) reverse(all(a))





#define mem(ar,val) memset(ar,val,sizeof(ar))

#define ssort(ar) sort(ar.begin(),ar.end())

#define csort(ar,comp) sort(ar.begin(),ar.end(),comp)



#define bug1(a) cerr<<"test "<<a<<endl;

#define bug2(a,b) cerr<<"test "<<a<<" "<<b<<endl;

#define bug3(a,b,c) cerr<<"test "<<a<<" "<<b<<" "<<c<<endl;

#define bug4(a,b,c,d) cerr<<"test "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;



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

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



/// unordered_map<int,int>mp;

/// mp.reserve(1024);

/// mp.max_load_factor(0.25);



/// pbds

/// *find_by_order(k) - return k th largest element.. 0 based

/// order_of_key(k) - number of items strictly smaller than k



///  priority_queue <ll, vector<ll>, greater<ll> >



/*

struct HASH{

  size_t operator()(const pair<int,int>&x)const{

    return (size_t) x.first * 37U + (size_t) x.second;

  }

};

*/



typedef long long ll;

typedef unsigned long long ull;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;





ll ar[100005];

int main()

{

    ll n,x,mx;

    cin>>n>>x;

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

        cin>>ar[i];



    ll ans =0;

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

    {

        mx = ar[i]+ar[i+1];

        if(mx<=x)continue;

        ans+=min(ar[i+1],mx-x);

        ar[i+1]-=min(ar[i+1],mx-x);;

        mx=ar[i]+ar[i+1];

        if(mx<=x)continue;

        ans+=min(ar[i],mx-x);

        ar[i]-=min(ar[i],mx-x);

    }

    if(ar[n]>x)

        ans+=ar[n]-x;

    cout<<ans<<endl;

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

#include <cmath>

#include <algorithm>

#include <bits/stdc++.h>

const int maxn = 1e5 + 10;

using namespace std;

int main()

{

    int n, x;

    long long a[maxn] = {0};

    cin >> n >> x;

    long long  count = 0;

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

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

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

    {

        if (a[i] > x)

        {

            count += (a[i] - x);

            a[i] = x;

        }

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

        {

            count += (a[i+1] + a[i] - x);

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

        }

    }

    cout << count << endl;

    return 0;

}

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

using namespace std;

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

#define int long long

#define ll long long

#define vi vector<int>

#define pii pair<int,int>

#define F first

#define S second

#define pb push_back

#define forn(b) for(int i = 0; i < b; i++)

#define rforn(b) for(int i = b - 1 ;i >= 0; i--)

#define It(m) for(auto it = m.begin(); it != m.end(); it++)

#define N 500500

#define PI 3.14159265358979323846264338327950L

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

    

const ll mod = (ll)1e9 + 7;

    

signed main(){

    speed;

    int n, k; cin >> n >> k;

    vi v(n);

    forn(n) cin >> v[i];

    int ans = 0;

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

        if(v[i] > k) {

            ans += v[i] - k;

            v[i] = k;

        }

        if(v[i] + v[i + 1] > k) {

            ans += (v[i] + v[i + 1]) - k;

            v[i + 1] = k - v[i];

        }

    }

    cout << ans;

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

#include <cmath>

#include <algorithm>

#include <bits/stdc++.h>

const int maxn = 1e5 + 10;

using namespace std;

int main()

{

    int n, x;

    long long a[maxn] = {0};

    cin >> n >> x;

    long long  count = 0;

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

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

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

    {

        if (a[i] > x)

        {

            count += (a[i] - x);

            a[i] = x;

        }

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

        {

            count += (a[i+1] + a[i] - x);

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

        }

    }

    cout << count << endl;

    return 0;

}

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

using namespace std;



int main() {

	long long n, k;

	cin >> n >> k;

	vector<long long> a(n + 1);

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

		cin >> a[i];

	}

	vector<long long> dp(n + 1);

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

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

		dp[i] = dp[i - 1];

		if (x > k) {

			long long dx = x - k;

			dp[i] += dx;

			if (a[i] >= dx) {

				a[i] -= dx;

			} 

			else {

				a[i] = 0;

			}

		}

	} 

	cout << dp[n];

	return 0;

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

#include <cmath>

#include <algorithm>

#include <bits/stdc++.h>

const int maxn = 1e5 + 10;

using namespace std;

int main()

{

    int n, x;

    long long a[maxn] = {0};

    cin >> n >> x;

    long long  count = 0;

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

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

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

    {

        if (a[i] > x)

        {

            count += (a[i] - x);

            a[i] = x;

        }

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

        {

            count += (a[i+1] + a[i] - x);

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

        }

    }

    cout << count << endl;

    return 0;

}

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

#define ll long long

#define ull unsigned long long

#define pii pair<int,int>

#define piii pair<int,pii>

#define pll pair<ll,ll>

#define plii pair<ll,pii>

#define vi vector<int>

#define ff first

#define ss second

#define mp make_pair

#define pb push_back

#define SORT(x) sort(x.begin(), x.end())

#define GSORT(x) sort(x.begin(), x.end(), greater<int>())

#define mx 100001

#define eps 0.00000000001

#define mod 1000000007

#define pi acos(-1)

#define inf 100000000

#define loop(i,b,n) for(int i=b;i<n;++i)

#define rev_loop(i,b,n) for(int i=b;i>=n;--i)

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

using namespace std;

int main()

{

    fio;

    ll n,x;

    cin>>n>>x;

    vector<ll> v1;

    ll a1,ans=0;

    loop(i,0,n)

    {

        cin>>a1;

        v1.pb(a1);

    }

    if(v1[0]>x)

    {

        ans+=v1[0]-x;

        v1[0]=x;

    }

    loop(i,1,n)

    {

        if(v1[i]+v1[i-1]>x)

        {

            ans+=(v1[i]+v1[i-1]-x);

            v1[i] -=(v1[i]+v1[i-1]-x);

        }

    }

    cout<<ans<<endl;

    return 0;

}