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

#include<cstdio>

#include<string>

using namespace std;

 int q,p,w[1000001],u[1000001],o;

 string a;

 int main()

 {

     cin>>a; 

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

     {

         if (a[i]=='C') 

         {

             p++;

             u[p]=i+1;

         } 

         else if (a[i]=='F')

         {

            q++;

             w[q]=i+1;

         }

     } 

     if (q>=1 && p>=1)

     {

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

     {

         for (int j=1;j<=q;j++)

         {

             if (u[i]<w[j])

             {

                 o=1;

             }

         }

     } 

     if (o==1) cout<<"Yes"<<endl; 

     else cout<<"No"<<endl;   

     }

     else cout<<"No"<<endl; 

     

 }  

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

#include<cstring>

char a[10010];//字符数组 

bool c, f;//标志变量 

int main() {

    scanf("%s", a);//读入字符串 

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

        if(a[i]=='C') c=true;//找到C后标记 

        if(a[i]=='F'&&c==true) f=true;//在找到C后再找到F时标记 

    }

    if(f==true) printf("Yes\n");//如果找到C和F输出Yes 

    else printf("No\n");//否则输出No 

    return 0;

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

using namespace std;

int main()

{

    string s;

    cin >> s;

    int c = s.find("C"); 

    int f = s.find("F", c);

    if(c >= s.length() || f >= s.length() || c > f)

        cout << "No" << endl;

    else

        cout << "Yes" << endl;

    return 0;

}

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

#include<cstring>

char a[10010];//字符数组 

bool c, f;//标志变量 

int main() {

    scanf("%s", a);//读入字符串 

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

        if(a[i]=='C') c=true;//找到C后标记 

        if(a[i]=='F'&&c==true) f=true;//在找到C后再找到F时标记 

    }

    if(f==true) printf("Yes\n");//如果找到C和F输出Yes 

    else printf("No\n");//否则输出No 

    return 0;

}
// Slower C++ solution:
// luogu-judger-enable-o2

#include<bits/stdc++.h>

using namespace std;

string c;

int main()

{

	cin>>c;

	int n=c.size();

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

	{

		if(c[i]=='C')

		{

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

			{

				if(c[j]=='F')

				{

					cout<<"Yes";

					return 0;

				}

			}

		}

	}

	cout<<"No";

	return 0;

}

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

#include<cstring>

char a[10010];//字符数组 

bool c, f;//标志变量 

int main() {

    scanf("%s", a);//读入字符串 

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

        if(a[i]=='C') c=true;//找到C后标记 

        if(a[i]=='F'&&c==true) f=true;//在找到C后再找到F时标记 

    }

    if(f==true) printf("Yes\n");//如果找到C和F输出Yes 

    else printf("No\n");//否则输出No 

    return 0;

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

using namespace std;

char a[266];

int main()

{

	int b=100;

	cin>>a;

	for(int i=0;i<strlen(a)&&b!=0;i++)

	{

		if(a[i]=='C'||b==10)

		{

			b=10;

			if(a[i]=='F'&&b==10)

				b=0;

		}

	}

	if(b==0)

		cout<<"Yes";

	else

		cout<<"No";	

}

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

#include<cstring>

char a[10010];//字符数组 

bool c, f;//标志变量 

int main() {

    scanf("%s", a);//读入字符串 

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

        if(a[i]=='C') c=true;//找到C后标记 

        if(a[i]=='F'&&c==true) f=true;//在找到C后再找到F时标记 

    }

    if(f==true) printf("Yes\n");//如果找到C和F输出Yes 

    else printf("No\n");//否则输出No 

    return 0;

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

#define pb push_back



using namespace std;



void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)

#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)

#define dbg_ok cerr<<"OK!\n"



typedef pair<int,int> pii;

typedef long long int ll;

typedef long double ld;



inline int two(int n) { return 1 << n; }

inline int test(int n, int pos) { return (bool) (n & two(pos)); }

inline void set_bit(int &n, int b) { n |= two(b); }

inline void unset_bit(int &n, int b) { n &= ~two(b); }

inline int last_bit(int n) { return n & (-n); }



const int DMAX = 1e5+10;



vector <int> vec;

vector <int> arb[DMAX];



char s[DMAX];



int V[DMAX];



int n;



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);



    int t,i,j,lg;



    cin>>s;

    lg=strlen(s);

    for(i=0;i<lg && s[i] != 'C';i++);

    if(i == lg){

       cout<<"No\n";

       return 0;

    }

    for(;i<lg && s[i] != 'F';i++);

    if(i == lg){

       cout<<"No\n";

       return 0;

    }

    cout<<"Yes\n";

    return 0;

}


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

#define NMAX 100005



using namespace std;



int i, ok1, ok2;



int main(){

    ios_base::sync_with_stdio(false);

    string sir;

    cin >> sir;

    for(i=0; i<sir.size(); ++i){

        if(sir[i] == 'C')

            ok1 = 1;

        if(sir[i] == 'F' && ok1 == 1){

            ok2 = 1;

            break;

            }

        }

    if(ok2 == 1)

        cout << "Yes\n";

        else

        cout << "No\n";

    return 0;

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

using namespace std;



typedef long long ll;

typedef pair<int,int> pii;

typedef pair<int,pii> ipii;

const int N = 1e5;





int find_par(int x, int *par){

	if(par[x] == x) return x;

	return par[x] = find_par(par[x],par);

}



int par[N+5];

int global_par[N+5];

vector<ipii> edge;



int n,q;

ll m;

int cnt[N+5];

int maksi[N+5];

bool pake[N+5];



int main(){

	memset(pake,0,sizeof(pake));

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

	int unused = n;

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

		int a,b,c;

		scanf("%d%d%d",&a,&b,&c);

		a++;

		b++;

		if(!pake[a]){

			unused--;

			pake[a]=1;

		}

		if(!pake[b]){

			unused--;

			pake[b]=1;

		}

		edge.push_back(make_pair(c,make_pair(a,b)));

	}

	unique(edge.begin(),edge.end());

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

	for(int i=1;i<=n;i++) par[i] = i,cnt[i]=1, global_par[i] = i;

	int valid = 1;

	int cnt2 = 0;

	ll gabung = n;

	

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

		if(edge[i].first == 0){

			int pa = find_par(edge[i].second.first,par);

			int pb = find_par(edge[i].second.second,par);

			if(pa != pb){

				par[pa] = pb;

				gabung--;

			}

		} else {

			if(m == n-1)valid = 0;

			int pa = find_par(edge[i].second.first,par);

			int pb = find_par(edge[i].second.second,par);

			if(pa == pb){

				valid = 0;

				break;

			}

			

		}

	}

	

	if(!valid){

		printf("No\n");

		return 0;

	}

	

	ll cnM = gabung * (gabung-3) / 2;

	if(m <= n+cnM) printf("Yes\n");

	else printf("No\n");

	return 0;

}

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

#define LL long long

using namespace std;

const int N=200010;

int n,m,k,fa[N],is[N],tot;

struct Q{

	int u,v,id;

	bool operator<(const Q&o)const{

		return id<o.id;

	}

}q[N];

int getfa(int x){

	return fa[x]==x?x:fa[x]=getfa(fa[x]);

}

int main(){

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

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

		scanf("%d%d%d",&q[i].u,&q[i].v,&q[i].id);

		q[i].u++,q[i].v++;

	}

	sort(q+1,q+k+1);

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

		fa[i]=i;

	}

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

		if(q[i].id==0){

			int u=getfa(q[i].u),v=getfa(q[i].v);

			if(u!=v)fa[u]=v,m--;

		}

		else{

			int u=getfa(q[i].u),v=getfa(q[i].v);

			if(u==v){

				puts("No");

				return 0;

			}

			is[u]=is[v]=1;

		}

	}

	bool flag=0;

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

		if(fa[i]==i){

			if(is[i]==0)flag=1;

			tot++;

		}

	}

	LL mi,mx;

	if(flag)mi=tot-1;

	else mi=tot;

	mx=(LL)tot*(tot-1)/2;

	if(mi<=m&&m<=mx)puts("Yes");

	else puts("No");

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

using namespace std;



typedef long long ll;

typedef pair<int,int> pii;

typedef pair<int,pii> ipii;

const int N = 1e5;





int find_par(int x, int *par){

	if(par[x] == x) return x;

	return par[x] = find_par(par[x],par);

}



int par[N+5];

int global_par[N+5];

vector<ipii> edge;



int n,q;

ll m;

int cnt[N+5];

int maksi[N+5];

bool pake[N+5];



int main(){

	memset(pake,0,sizeof(pake));

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

	int unused = n;

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

		int a,b,c;

		scanf("%d%d%d",&a,&b,&c);

		a++;

		b++;

		if(!pake[a]){

			unused--;

			pake[a]=1;

		}

		if(!pake[b]){

			unused--;

			pake[b]=1;

		}

		edge.push_back(make_pair(c,make_pair(a,b)));

	}

	unique(edge.begin(),edge.end());

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

	for(int i=1;i<=n;i++) par[i] = i,cnt[i]=1, global_par[i] = i;

	int valid = 1;

	int cnt2 = 0;

	ll gabung = n;

	

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

		if(edge[i].first == 0){

			int pa = find_par(edge[i].second.first,par);

			int pb = find_par(edge[i].second.second,par);

			if(pa != pb){

				par[pa] = pb;

				gabung--;

			}

		} else {

			if(m == n-1)valid = 0;

			int pa = find_par(edge[i].second.first,par);

			int pb = find_par(edge[i].second.second,par);

			if(pa == pb){

				valid = 0;

				break;

			}

			

		}

	}

	

	if(!valid){

		printf("No\n");

		return 0;

	}

	

	ll cnM = gabung * (gabung-3) / 2;

	if(m <= n+cnM) printf("Yes\n");

	else printf("No\n");

	return 0;

}

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

#define ll long long

using namespace std;

const int MAXN = 1e5 + 7;

int x[MAXN], y[MAXN], c[MAXN];

int f[MAXN], cnt0, cnt1, used;

int find(int x) {return x == f[x] ? f[x] : f[x] = find(f[x]);}

void unite(int x, int y)

{

    x = find(x), y = find(y);

    if (x != y) f[x] = y, cnt0--, used++;

}

int main()

{

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

    cnt0 = n; used = 0; cnt1 = 0;

    for (int i = 1; i <= n; i++) f[i] = i;

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

    {

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

        x[i]++; y[i]++;

        if (!c[i]) unite(x[i], y[i]);

        else 

        {

            cnt1++;

            if (m == n - 1) {puts("No"); return 0;}

        }

    }

    m -= used;

    if (!cnt1)

    {

        (m >= cnt0 - 1 && m <= (ll)cnt0 * (cnt0 - 1) / 2) ? puts("Yes") : puts("No");

        return 0;

    }

    else 

    {

        if (cnt0 == 2) {puts("No"); return 0;}

        for (int i = 1; i <= q; i++) if (c[i])

            if (find(x[i]) == find(y[i])) {puts("No"); return 0;}

        (m >= cnt0 && m <= (ll)cnt0 * (cnt0 - 1) / 2) ? puts("Yes") : puts("No");

    }

    return 0;

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

#include<cmath>

#include<algorithm>

#include<cstring>

#include<iostream>

using namespace std;

 

main()

{

	char x,y;

	scanf(" %c %c",&x,&y);

	if(x<y) printf("<\n");

	if(x>y) printf(">\n");

	if(x==y) printf("=\n");

		

	

}

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

#include <cmath>

using  namespace std;



int A=10,B=11,C=12,D=13,E=14,F=15;



int main()

{

	char X,Y;

	scanf("%c %c",&X,&Y);

	if(X > Y) printf(">\n");

	if(X < Y) printf("<\n");

	if(X == Y) printf("=\n");

	return 0;

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

using namespace std;

int main() {

    char ch[1];

    char s[1];

    scanf("%s",ch);

    scanf("%s",s);

    if(ch[0]>s[0]){

        cout<<">"<<endl;

    }

    else if(ch[0]<s[0])cout<<"<"<<endl;

    else cout<<"="<<endl;



}

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

int main()

{

	char a, b;

	scanf("%c %c", &a, &b);

	a == b ? puts("=") : (a < b ? puts("<") : puts(">"));

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

#include <algorithm>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cstring>

#include <climits>

#include <cctype>

#include <map>

#include <list>

#include <stack>

#include <queue>

#include <vector>

#include <set>

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

using namespace std;

const int INF=0x3f3f3f3f;

const double PI=acos(-1.0);

const double eps=1e-12;

const int MAX=100000+10;

const int EDGE=100000+10;//边的条数

typedef long long ll;

int main()

{

	ll n,x,i,a[MAX],t,ans;

	while(~scanf("%lld%lld",&n,&x))

	{

		mem(a,0);

		t=0;

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

		{

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

		}

		ans=0;

		if(a[0]>x)

		{

			t=a[0]-x;

			ans+=t;

			a[0]-=t;

		}

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

		{

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

			{

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

				ans+=t;

				a[i]-=t;

			}

		}

	//	if(a[n-2]+a[n-1]>x) ans+=a[n-2]+a[n-1]-x;

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

	}

	return 0;

}

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

#include<string.h>

#include<stdlib.h>

#include<algorithm>

#include<iostream>

#include<ctype.h>

#include<stack>

#include<queue>

#include <cmath>  

using namespace std;

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <string.h>

#include <algorithm>

using namespace std;

#define  inf 0x3fffffff 

int main()

{

	int i, n, x, a[110000];

	long long sum;

	while (cin>>n>>x)

	{

		sum = 0;

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

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

		if (a[1] > x)

		{

			sum += a[1] - x;

			a[1] = x;

		}

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

		{

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

			if (flag > 0)

			{

				sum += flag;

				a[i] -= flag;

			}

		}

		cout << sum << endl;

	}

	return 0;

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

using namespace std;

const int maxi=200010;

long long  a[maxi],n,x,sum,k,i;

int main()

{

    while (cin>>n>>x)

    {

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

             cin>>a[i];

          sum=0;

         if (a[0]>x)

         {

             sum+=a[0]-x;

             a[0]=x;

         }

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

         {

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

             if (k>0)

             {

                 sum+=k;

                 a[i]-=k;

             }

         }

         cout<<sum<<endl;

     }

     return 0;

}


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

int main()

{int a[100005];

 int n,x;

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

 {int i,j;

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

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

  long long sum=0;

  if(a[0]>x)

  {sum+=a[0]-x;

   a[0]=x;

  }

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

  {int temp=a[i]+a[i-1]-x;

   if(temp>0)

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

    sum+=temp;

   }

  }

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

 }

 return 0;

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

using namespace std;

long long a[100005];

int main()

{

	long long n,ans,nmax,num;

	cin>>n>>nmax;

	ans=0;

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

	{

		cin>>a[i];

	}

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

	{

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

		{

			num=a[i]+a[i+1]-nmax;

			ans+=(a[i]+a[i+1]-nmax);

			if(a[i+1]>=num)

			{

				a[i+1]-=num;

				

			}

			else

			{

				a[i+1]=0;

			}

		}

		

	 } 

	 cout<<ans<<endl;

	 return 0;

} 

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

int main()

{int a[100005];

 int n,x;

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

 {int i,j;

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

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

  long long sum=0;

  if(a[0]>x)

  {sum+=a[0]-x;

   a[0]=x;

  }

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

  {int temp=a[i]+a[i-1]-x;

   if(temp>0)

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

    sum+=temp;

   }

  }

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

 }

 return 0;

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

#define ll long long

using namespace std;



const int maxn = 1e5+10;

int a[maxn];

int main(){

  ll k,n,x,ans=0;

  cin>>n>>x;

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

    cin>>a[i];

  if(a[0]>x){

    ans=a[0]-x;

    a[0]=x;

  }

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

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

    if(k>0){

      ans+=k;

      a[i]-=k;

    }

  }

  cout<<ans<<endl;

  return 0;

}

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

int main()

{int a[100005];

 int n,x;

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

 {int i,j;

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

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

  long long sum=0;

  if(a[0]>x)

  {sum+=a[0]-x;

   a[0]=x;

  }

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

  {int temp=a[i]+a[i-1]-x;

   if(temp>0)

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

    sum+=temp;

   }

  }

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

 }

 return 0;

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

using namespace std;

int main()

{

    long long int n,x,t,s=0;

    long long int a[150000];

    cin>>n>>x;

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

    {

        cin>>a[i];

    }

    if(a[0]>x)  {s+=a[0]-x; a[0]=x;}

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

    {

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

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

        a[i]-=t;

        s+=t;

       }

    }

   cout<<s<<endl;

    return 0;

}

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

int main()

{int a[100005];

 int n,x;

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

 {int i,j;

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

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

  long long sum=0;

  if(a[0]>x)

  {sum+=a[0]-x;

   a[0]=x;

  }

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

  {int temp=a[i]+a[i-1]-x;

   if(temp>0)

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

    sum+=temp;

   }

  }

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

 }

 return 0;

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

#include <cstdio>

#include <algorithm>

#include <cstring>

#include <cctype>

#include <sstream>

#include <cmath>

using namespace std;

const int inf =0x3f3f3f3f;

typedef long long LL;

const int MAXN=100010;

int a[MAXN];

int main()

{

    LL n, x;

    while(~scanf("%lld %lld", &n, &x))

    {

        LL sum=0;

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

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

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

        {

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

            {

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

                sum+=t;

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

                    a[i+1]=0;

                else

                    a[i+1]-=t;

            }

        }

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

    }

    return 0;

}


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

int main()

{int a[100005];

 int n,x;

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

 {int i,j;

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

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

  long long sum=0;

  if(a[0]>x)

  {sum+=a[0]-x;

   a[0]=x;

  }

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

  {int temp=a[i]+a[i-1]-x;

   if(temp>0)

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

    sum+=temp;

   }

  }

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

 }

 return 0;

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

#include<algorithm>

#include<cstdio>

#include<cstring>

#include<vector>

#include<queue>

#include<map>

#include<cmath>

#define N 100009

using namespace std;

const int INF = 0x3f3f3f3f;

int a[N];



int main()

{

    int n, x;

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

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

    long long ans, now; ans = now = 0;

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

    {

        if(now + a[i] <= x) now = a[i];

        else ans += now + a[i] - x, now = a[i] - (now + a[i] - x);

    }

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

    return 0;

}


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

int main()

{int a[100005];

 int n,x;

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

 {int i,j;

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

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

  long long sum=0;

  if(a[0]>x)

  {sum+=a[0]-x;

   a[0]=x;

  }

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

  {int temp=a[i]+a[i-1]-x;

   if(temp>0)

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

    sum+=temp;

   }

  }

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

 }

 return 0;

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

#include<string.h>

#include<algorithm>

using namespace std;

int a[1000001];

main()

{

    int i,j;

    long long n,m,sum,p;

    long long a[100001];

    memset(a,0,sizeof(a));

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

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

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

    sum=0;

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

    {

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

        {

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

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

            p=a[i]+a[i+1]-m;

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

            //printf("%lld\n",a[i+1]);

            p=0;

        }

    }

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

}


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

int main()

{int a[100005];

 int n,x;

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

 {int i,j;

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

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

  long long sum=0;

  if(a[0]>x)

  {sum+=a[0]-x;

   a[0]=x;

  }

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

  {int temp=a[i]+a[i-1]-x;

   if(temp>0)

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

    sum+=temp;

   }

  }

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

 }

 return 0;

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

#include <algorithm>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cstring>

#include <climits>

#include <cctype>

#include <map>

#include <list>

#include <stack>

#include <queue>

#include <vector>

#include <set>

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

using namespace std;

const int INF=0x3f3f3f3f;

const double PI=acos(-1.0);

const double eps=1e-12;

const int MAX=100000+10;

const int EDGE=100000+10;//边的条数

typedef long long ll;

int main()

{

	ll n,x,i,a[MAX],t,ans;

	while(~scanf("%lld%lld",&n,&x))

	{

		mem(a,0);

		t=0;

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

		{

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

		}

		ans=0;

		if(a[0]>x)

		{

			t=a[0]-x;

			ans+=t;

			a[0]-=t;

		}

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

		{

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

			{

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

				ans+=t;

				a[i]-=t;

			}

		}

	//	if(a[n-2]+a[n-1]>x) ans+=a[n-2]+a[n-1]-x;

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

	}

	return 0;

}

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

int main()

{int a[100005];

 int n,x;

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

 {int i,j;

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

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

  long long sum=0;

  if(a[0]>x)

  {sum+=a[0]-x;

   a[0]=x;

  }

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

  {int temp=a[i]+a[i-1]-x;

   if(temp>0)

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

    sum+=temp;

   }

  }

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

 }

 return 0;

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

#include<string.h>

#include<stdlib.h>

#include<algorithm>

#include<iostream>

#include<ctype.h>

#include<stack>

#include<queue>

#include <cmath>  

using namespace std;

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <string.h>

#include <algorithm>

using namespace std;

#define  inf 0x3fffffff 

int main()

{

	int i, n, x, a[110000];

	long long sum;

	while (cin>>n>>x)

	{

		sum = 0;

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

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

		if (a[1] > x)

		{

			sum += a[1] - x;

			a[1] = x;

		}

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

		{

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

			if (flag > 0)

			{

				sum += flag;

				a[i] -= flag;

			}

		}

		cout << sum << endl;

	}

	return 0;

}

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

int main()

{int a[100005];

 int n,x;

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

 {int i,j;

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

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

  long long sum=0;

  if(a[0]>x)

  {sum+=a[0]-x;

   a[0]=x;

  }

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

  {int temp=a[i]+a[i-1]-x;

   if(temp>0)

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

    sum+=temp;

   }

  }

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

 }

 return 0;

}