stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

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; 

        if(a[i]=='F'&&c==true) f=true;

    }

    if(f==true) printf("Yes\n"); 

    else printf("No\n"); 

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

int main(){

	char c[5000];

	int x=0,i,j,l;

	scanf("%s",c);

	l=strlen(c);

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

		if(x==0&&c[i]=='C'){

			x++;

		}

		if(x==1&&c[i]=='F'){

			printf("Yes");

			return 0;

		}

	}

	printf("No");

	return 0;

}

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

#include<iostream>

using namespace std;

int main()

{

    string s;

    int f=0;

    getline(cin,s);

    for(int i=0;i<s.length();i++)

    {

        if(s[i]=='C'&&!f)f=1;

        if(s[i]=='F'&&f)f=2;

    }

    if(f==2)cout<<"Yes"<<endl;

    else cout<<"No"<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

int main(){

	char c[5000];

	int x=0,i,j,l;

	scanf("%s",c);

	l=strlen(c);

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

		if(x==0&&c[i]=='C'){

			x++;

		}

		if(x==1&&c[i]=='F'){

			printf("Yes");

			return 0;

		}

	}

	printf("No");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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++)//从0位开始循环

     {

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

         {

             p++;

             u[p]=i+1;

         }//判断是否发现C这个东西，并统计其位置

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

         {

            q++;

             w[q]=i+1;

         }

     }//判断是否发现F，同理 统计位置情况

     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;

             }

         }

     }//循环，找到C是否在F的前面

     if (o==1) cout<<"Yes"<<endl;//在前面则Yes

     else cout<<"No"<<endl;//否则No   

     }

     else cout<<"No"<<endl;//不存在两个数，直接No

     //以上为全部过程，希望能理解。

 }

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

int main(){

	char c[5000];

	int x=0,i,j,l;

	scanf("%s",c);

	l=strlen(c);

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

		if(x==0&&c[i]=='C'){

			x++;

		}

		if(x==1&&c[i]=='F'){

			printf("Yes");

			return 0;

		}

	}

	printf("No");

	return 0;

}

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

#include<cstdio>

using namespace std;

int main()

{

	string s;

	getline(cin,s);

//	cout<<s<<endl;

	int flag=0,len=s.length();

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

	{

		if(!flag)

		{

			if(s[i]=='C') flag=1;

		}

		if(flag==1)

		{

			if(s[i]=='F')

			{

				flag=2;

				break;

			}

		}

	}

	if(flag==2) cout<<"Yes";

	else cout<<"No";

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

int main(){

	char c[5000];

	int x=0,i,j,l;

	scanf("%s",c);

	l=strlen(c);

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

		if(x==0&&c[i]=='C'){

			x++;

		}

		if(x==1&&c[i]=='F'){

			printf("Yes");

			return 0;

		}

	}

	printf("No");

	return 0;

}

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

#include<cstdio>

#include<string>

using namespace std;

string s;

int main(){

    cin>>s;

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

        if(s[i]=='C'){

            for(int j=i+1;j<s.size();j++){

                if(s[j]=='F'){

                    cout<<"Yes";

                    return 0;

                }

            }

        }

    }

    cout<<"No";

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

int main(){

	char c[5000];

	int x=0,i,j,l;

	scanf("%s",c);

	l=strlen(c);

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

		if(x==0&&c[i]=='C'){

			x++;

		}

		if(x==1&&c[i]=='F'){

			printf("Yes");

			return 0;

		}

	}

	printf("No");

	return 0;

}

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

#include<iostream>

using namespace std;

char c[111];

int le,f;

int main()

{

    cin>>c;

    le=strlen(c);

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

    {

        if(c[i]=='C'&&f==0)

        f=1;

        if(c[i]=='F'&&f!=0)

        {

            cout<<"Yes"<<endl;

            return 0;

        }

    }

    cout<<"No"<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

int main(){

	char c[5000];

	int x=0,i,j,l;

	scanf("%s",c);

	l=strlen(c);

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

		if(x==0&&c[i]=='C'){

			x++;

		}

		if(x==1&&c[i]=='F'){

			printf("Yes");

			return 0;

		}

	}

	printf("No");

	return 0;

}

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

     

 }  

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

int main(){

	char c[5000];

	int x=0,i,j,l;

	scanf("%s",c);

	l=strlen(c);

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

		if(x==0&&c[i]=='C'){

			x++;

		}

		if(x==1&&c[i]=='F'){

			printf("Yes");

			return 0;

		}

	}

	printf("No");

	return 0;

}

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

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

int main(){

	char c[5000];

	int x=0,i,j,l;

	scanf("%s",c);

	l=strlen(c);

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

		if(x==0&&c[i]=='C'){

			x++;

		}

		if(x==1&&c[i]=='F'){

			printf("Yes");

			return 0;

		}

	}

	printf("No");

	return 0;

}

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

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

int main(){

	char c[5000];

	int x=0,i,j,l;

	scanf("%s",c);

	l=strlen(c);

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

		if(x==0&&c[i]=='C'){

			x++;

		}

		if(x==1&&c[i]=='F'){

			printf("Yes");

			return 0;

		}

	}

	printf("No");

	return 0;

}

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

}

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

#include<cstring>

using namespace std;

const int MAXN=10005;

char Str1[MAXN],Str2[MAXN];

int Len1,Len2;



int main(){

	scanf("%s",Str1);

	Len1=strlen(Str1);

	Str2[0]='C';

	Str2[1]='F';

	Len2=2;

	int j=0;

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

	if(Str1[i]==Str2[j]){

		j++;

		if(j==2){

			printf("Yes");

			return 0;

		}

	}

	

	printf("No");

	return 0;

	

}

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

}


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

}


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

}

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

}

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

		

	

}

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

}

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



}

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

int main()

{

	char a, b;

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

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

}

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

}

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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

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

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

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

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

}

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

}


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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

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

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

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

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

}

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

} 

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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

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

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

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

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

}

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

}

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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

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

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

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

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

}

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

}

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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

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

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

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

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

}

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

}


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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

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

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

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

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

}

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

}


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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

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

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

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

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

}

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

}


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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

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

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

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

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

}

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

}

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

long long  a,b,c,d,i,j,k,x,y,z,ans;

long long f[100005];

int main(){

	ans=0;

	f[0]=0;

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

	for (i=1;i<=a;i++) scanf("%lld",&f[i]);

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

		if (f[i]+f[i-1]>b){

			c=f[i]+f[i-1]-b;

			ans+=c;

			f[i]-=c;	

		}

	}

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

}

// Fastest known solution for this problem: