stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
/*我是萌新*/

#include<iostream>

#include<cmath>

#include<cstring>

#include<string>

#include<algorithm>

#include <iomanip> 

typedef long long LL;

const int mod = 1000000009;

using namespace std;

int main()

{

    std::ios::sync_with_stdio(false);

    std::cin.tie(0);

    int n;

    while (cin >> n)

    {

        int* p = new int[n + 1],ans=0,max1,min1;

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

            cin >> p[i];

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

        {

            max1 = max(p[i - 1], p[i + 1]);

            min1 = min(p[i - 1], p[i + 1]);

            if (p[i] > min1&& p[i] < max1)

                ans++;

        }

        cout << ans << '\n';

    }

}




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







int main()

{

	int num[100000],count =0, tc, i, k, l;

	

	scanf("%d", &tc);

	

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

	{

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

	} 

	

	for(i = 1; i <= tc-2; i++)

	{

		k = i + 1;

		l = i + 2;

		

		if(num[i] > num[k]  && num[k] > num[l])

		{

			count++;

		}

		else if(num[i] < num[k] && num[k] < num[l])

		{

			count++;

		}

	}

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

	

	return 0;

	

	

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

using namespace std;

#define mod 1e9+7

int main()

{

	int a[25];

	int n, sum = 0;

	cin >> n;

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

		cin >> a[i];

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

		if ((a[i] > a[i - 1] && a[i] < a[i + 1]) || (a[i] < a[i - 1] && a[i] > a[i + 1]))sum++;

	cout << sum;

}

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







int main()

{

	int num[100000],count =0, tc, i, k, l;

	

	scanf("%d", &tc);

	

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

	{

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

	} 

	

	for(i = 1; i <= tc-2; i++)

	{

		k = i + 1;

		l = i + 2;

		

		if(num[i] > num[k]  && num[k] > num[l])

		{

			count++;

		}

		else if(num[i] < num[k] && num[k] < num[l])

		{

			count++;

		}

	}

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

	

	return 0;

	

	

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

using namespace std;

#define fastIO ios::sync_with_stdio(0), cin.tie(0)

#define endl '\n'

#define ft first

#define sd second

#define pb push_back

#define pob pop_back()

#define pf push_front

#define pof pop_front()

typedef long long ll;

typedef pair<int,int> pii;

typedef pair<char,char> pcc;

typedef pair<long long,long long> pll;



int main() {

    fastIO;

    int n, rta = 0;

    cin >> n;

    int perm[n];

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

        cin >> perm[i];

    }

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

        vector<int> x;

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

            x.pb(perm[j]);

        }

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

        if(x[1] == perm[i]) rta++;

    }

    cout << rta << endl;

    return 0;

}




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







int main()

{

	int num[100000],count =0, tc, i, k, l;

	

	scanf("%d", &tc);

	

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

	{

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

	} 

	

	for(i = 1; i <= tc-2; i++)

	{

		k = i + 1;

		l = i + 2;

		

		if(num[i] > num[k]  && num[k] > num[l])

		{

			count++;

		}

		else if(num[i] < num[k] && num[k] < num[l])

		{

			count++;

		}

	}

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

	

	return 0;

	

	

}
// Slower C++ solution:
/*我是萌新*/

#include<iostream>

#include<cmath>

#include<cstring>

#include<string>

#include<algorithm>

#include <iomanip> 

typedef long long LL;

const int mod = 1000000009;

using namespace std;

int main()

{

    std::ios::sync_with_stdio(false);

    std::cin.tie(0);

    int n;

    while (cin >> n)

    {

        int* p = new int[n + 1],ans=0,max1,min1;

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

            cin >> p[i];

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

        {

            max1 = max(p[i - 1], p[i + 1]);

            min1 = min(p[i - 1], p[i + 1]);

            if (p[i] > min1&& p[i] < max1)

                ans++;

        }

        cout << ans << '\n';

    }

}




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



int main()

{



   int arr[1000],i,j,k,tc,cnt=0;



   scanf("%d",&tc);



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

   {



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



   }



   for(j=1;j<(tc-1);j++)

   {



    if((arr[j]>arr[j-1]&&arr[j]<arr[j+1])||(arr[j]<arr[j-1]&&arr[j]>arr[j+1]))

    {

        cnt++;

    }



   }



   printf("%d",cnt);



   return 0;

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

using namespace std;

#define mod 1e9+7

int main()

{

	int a[25];

	int n, sum = 0;

	cin >> n;

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

		cin >> a[i];

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

		if ((a[i] > a[i - 1] && a[i] < a[i + 1]) || (a[i] < a[i - 1] && a[i] > a[i + 1]))sum++;

	cout << sum;

}

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



int main()

{



   int arr[1000],i,j,k,tc,cnt=0;



   scanf("%d",&tc);



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

   {



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



   }



   for(j=1;j<(tc-1);j++)

   {



    if((arr[j]>arr[j-1]&&arr[j]<arr[j+1])||(arr[j]<arr[j-1]&&arr[j]>arr[j+1]))

    {

        cnt++;

    }



   }



   printf("%d",cnt);



   return 0;

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

using namespace std;

#define fastIO ios::sync_with_stdio(0), cin.tie(0)

#define endl '\n'

#define ft first

#define sd second

#define pb push_back

#define pob pop_back()

#define pf push_front

#define pof pop_front()

typedef long long ll;

typedef pair<int,int> pii;

typedef pair<char,char> pcc;

typedef pair<long long,long long> pll;



int main() {

    fastIO;

    int n, rta = 0;

    cin >> n;

    int perm[n];

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

        cin >> perm[i];

    }

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

        vector<int> x;

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

            x.pb(perm[j]);

        }

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

        if(x[1] == perm[i]) rta++;

    }

    cout << rta << endl;

    return 0;

}




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



int main()

{



   int arr[1000],i,j,k,tc,cnt=0;



   scanf("%d",&tc);



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

   {



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



   }



   for(j=1;j<(tc-1);j++)

   {



    if((arr[j]>arr[j-1]&&arr[j]<arr[j+1])||(arr[j]<arr[j-1]&&arr[j]>arr[j+1]))

    {

        cnt++;

    }



   }



   printf("%d",cnt);



   return 0;

}
// Slower C++ solution:


#include<stdio.h>

#include<iostream>

using namespace std;

int main()

{

    int a,count=0;

    cin>>a;

    int b[a];

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

        cin>>b[i];

    }

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

        if( (b[i]<b[i-1] && b[i]>b[i+1]) || (b[i]>b[i-1] && b[i]<b[i+1]) ){

            count++;

        }

    }

    cout<<count<<endl;



}


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



int main()

{



   int arr[1000],i,j,k,tc,cnt=0;



   scanf("%d",&tc);



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

   {



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



   }



   for(j=1;j<(tc-1);j++)

   {



    if((arr[j]>arr[j-1]&&arr[j]<arr[j+1])||(arr[j]<arr[j-1]&&arr[j]>arr[j+1]))

    {

        cnt++;

    }



   }



   printf("%d",cnt);



   return 0;

}
// Slower C++ solution:
#define _DEBUG

#include "bits/stdc++.h"

#define CHOOSE(a) CHOOSE2 a

#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x

#define debug_1(x1) cout<<#x1<<": "<<x1<<endl

#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl

#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl

#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl

#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl

#ifdef _DEBUG

#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#else

#define debug(...)

#endif

#define rep(index,num) for(int index=0;index<(int)num;index++)

#define rep1(index,num) for(int index=1;index<=(int)num;index++)

#define brep(index,num) for(int index=(int)num-1;index>=0;index--)

#define brep1(index,num) for(int index=(int)num;index>0;index--)

#define scan(argument) cin>>argument

#define prin(argument) cout<<argument<<endl

#define kaigyo cout<<endl

#define eps 1e-7

#define mp(a1,a2) make_pair(a1,a2)

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

#define rALL(a) (a).rbegin(),(a).rend()

typedef long long ll;

typedef long double ld;

using namespace std;

typedef pair<ll,ll> pll;

typedef pair<int,int> pint;

typedef vector<int> vint;

typedef vector<ll> vll;

typedef vector<pint> vpint;

typedef vector<pll> vpll;

ll INFl=(ll)1e+18+1;

int INF=1e+9+1;

int main(){

	int N;

	string S;

	scan(N>>S);

	int rnum=0;

	rep(i,N) if(S[i]=='R') rnum++;

	int ans=0;

	rep(i,rnum) if(S[i]=='W') ans++;

	prin(ans);

	return 0;

}


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

#define _USE_MATH_DEFINES

#include <math.h>

#include <vector>

#include <algorithm>



using namespace std;



int main(){

    long n;

    scanf("%ld", &n);

    char str[n+1];

    scanf("%s", str);

    

    long nCount = 0;

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

        if(str[i] == 'R'){

            nCount++;

        }

    }

    long nAns = 0;

    for(long i = 0; i < nCount; i++){

        if(str[i] == 'W'){

            nAns++;

        }

    }

  

    printf("%ld", nAns);

    return 0;

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

#include <algorithm>



using namespace std;



int c[6] = {1, 5, 10, 50, 100, 500};



int getNum(int t){

	int res = 0;

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

		res += t/c[i];

		t %= c[i];

	}

	return res;

}



int main(){

	int P, N[6];

	while(cin >> P, P){

		int end = 0;

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

			cin >> N[i];

			end += c[i]*N[i];

		}

		int ans = 10000000;

		for(int i=P;i<=end;i++){

			int cur = getNum(i-P);

			int l = i;

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

				int tmp = l/c[j];

				cur += min(N[j], tmp);

				l -= min(N[j], tmp)*c[j];

			}

			if(l != 0) continue;

			ans = min(ans, cur); 

		}

		cout << ans << endl;

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.355127412736114x):
// AOJ 1028 - ICPC: Ideal Coin Payment and Change (ツ妥ヲ5ツ嘉アツ療サツ習ツ嘉ッJ)



#include <iostream>

#include <algorithm>



using namespace std;



int c[6] = {1, 5, 10, 50, 100, 500};



int getNum(int t){

	int res = 0;

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

		res += t/c[i];

		t %= c[i];

	}

	return res;

}



int main(){

	int P, N[6];

	while(cin >> P, P){

		int end = 0;

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

			cin >> N[i];

			end += c[i]*N[i];

		}

		int ans = 10000000;

		for(int i=P;i<=min(P+500,end);i++){

			int cur = getNum(i-P);

			int l = i;

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

				int tmp = l/c[j];

				cur += min(N[j], tmp);

				l -= min(N[j], tmp)*c[j];

			}

			if(l != 0) continue;

			ans = min(ans, cur); 

		}

		cout << ans << endl;

	}

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

#include <string>

#include <algorithm>

#include <set>

#include <vector>

#include <cstring>

#include <climits>

#include <queue>

#include <map>

#include <sstream>

using namespace std;



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

#define rep(i,n) REP(i,0,n)

#define EPS 1e-9



const int coin[] = {1,5,10,50,100,500};

const int inf = 999999999;

int c[6],p;



int oturi(int x){

	int ret = 0;

	for(int i=5; i>=0 && x>0; i--){

		ret += (x/coin[i]);

		x -= (x/coin[i])*coin[i];

	}

	return ret;

}

int pay(int x){

	int ret = 0;

	for(int i=5; i>=0 && x>0; i--){

		ret += min(x/coin[i], c[i]);

		x -= min(x/coin[i],c[i]) * coin[i];

	}

	return x==0 ? ret : -1;

}

int main(){

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

		scanf("%d%d%d%d%d%d",c,c+1,c+2,c+3,c+4,c+5);

		int sum = 0;

		int ret = INT_MAX;

		

		rep(i,6)sum += coin[i]*c[i];

		

		for(int i=p; i<=sum; i++){

			int t = pay(i);

			if( t!=-1 ){

				ret = min(ret, t+oturi(i-p));

			}

		}

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

	}

	return 0;

}

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

#include <string>

#include <algorithm>

#include <set>

#include <vector>

#include <cstring>

#include <climits>

#include <queue>

#include <map>

#include <sstream>

using namespace std;



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

#define rep(i,n) REP(i,0,n)

#define EPS 1e-9



const int coin[] = {1,5,10,50,100,500};

const int inf = 999999999;

int c[6],p;



int oturi(int x){

	int ret = 0;

	for(int i=5; i>=0 && x>0; i--){

		ret += (x/coin[i]);

		x -= (x/coin[i])*coin[i];

	}

	return ret;

}

int pay(int x){

	int ret = 0;

	for(int i=5; i>=0 && x>0; i--){

		ret += min(x/coin[i], c[i]);

		x -= min(x/coin[i],c[i]) * coin[i];

	}

	return x==0 ? ret : -1;

}

int main(){

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

		scanf("%d%d%d%d%d%d",c,c+1,c+2,c+3,c+4,c+5);

		int sum = 0;

		int ret = INT_MAX;

		

		rep(i,6)sum += coin[i]*c[i];

		

		for(int i=p; i<=p+500; i++){

			int t = pay(i);

			if( t!=-1 ){

				ret = min(ret, t+oturi(i-p));

			}

		}

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

	}

	return 0;

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

using namespace std;

long long arr[100001][3] = {0};

int main()

{

    long long n;

    cin>>n;

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

    {

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

        {

            int a;

            cin>>a;

            arr[i][j] = a;

        }

    }

    long long dp[100001][3];

    memset(dp,0,sizeof dp);



    dp[0][0] = arr[0][0];

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

    dp[0][2] = arr[0][2];



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

    {

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

        {

            if(j==0)

            {

                dp[i][j] = arr[i][j] + max(dp[i-1][1],dp[i-1][2]);

            }



            if(j==1)

            {

                dp[i][j] = arr[i][j] + max(dp[i-1][0],dp[i-1][2]);   

            }



            if(j==2)

            {

                dp[i][j] = arr[i][j] + max(dp[i-1][0],dp[i-1][1]);

            }

        }

    }   

    long long ans = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

    cout<<ans<<endl;



    return 0;

}

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

using namespace std;

long long arr[100001][3] = {0};

int main()

{

    long long n;

    cin>>n;

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

    {

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

        {

            int a;

            cin>>a;

            arr[i][j] = a;

        }

    }

    long long dp[100001][3];



    dp[0][0] = arr[0][0];

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

    dp[0][2] = arr[0][2];



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

    {

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

        {

            if(j==0)

            {

                dp[i][j] = arr[i][j] + max(dp[i-1][1],dp[i-1][2]);

            }



            if(j==1)

            {

                dp[i][j] = arr[i][j] + max(dp[i-1][0],dp[i-1][2]);   

            }



            if(j==2)

            {

                dp[i][j] = arr[i][j] + max(dp[i-1][0],dp[i-1][1]);

            }

        }

    }   

    long long ans = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

    cout<<ans<<endl;



    return 0;

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

using namespace std;



long long w1,w2,hap=0,maxi,aa,bb,cc,N,i,j,k,a[100005][5];

long long M[100005][5];





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin>>N;

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

        for(j=0; j<4; j++)

            M[i][j]=0;



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

        cin>>a[i][0]>>a[i][1]>>a[i][2];

    M[N-1][0]=a[N-1][0];

    M[N-1][1]=a[N-1][1];

    M[N-1][2]=a[N-1][2];



    for(i=N-2; i>=0; i--)

    {

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

        {

            if(j==0)

            {

                w1=1;

                w2=2;

            }

            else if(j==1)

            {

                w1=0;

                w2=2;

            }

            else

            {

                w1=0;

                w2=1;

            }

        M[i][j]=a[i][j]+max(M[i+1][w1],M[i+1][w2]);

        }

    }

    aa=max(M[0][0],M[0][1]);

    aa=max(aa,M[0][2]);

    cout<<aa<<endl;

    return 0;

}






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

using namespace std;

#define INF 100005

#define maxx 1000000000000



int n;

long long a[INF][3];

long long mem[INF][3];



long long rec(int level,int pre)

{

    if(level==n) return 0;

    if(mem[level][pre]!=-1) return mem[level][pre];

    long long now=0;

    if(pre==0)

    {

        now=max(now,max(a[level][0]+rec(level+1,1),a[level][0]+rec(level+1,2)));

    }else

    if(pre==1)

    {

        now=max(now,max(a[level][1]+rec(level+1,0),a[level][1]+rec(level+1,2)));

    }else

    if(pre==2)

    {

        now=max(now,max(a[level][2]+rec(level+1,0),a[level][2]+rec(level+1,1)));

    }

    return mem[level][pre]=now;

}



int main()

{

    memset(mem,-1,sizeof(mem));

    scanf("%d",&n);

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

    {

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

    }

    long long ans=max(rec(0,0),max(rec(0,1),rec(0,2)));

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

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

using namespace std;



long long w1,w2,hap=0,maxi,aa,bb,cc,N,i,j,k,a[100005][5];

long long M[100005][5];





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin>>N;

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

        for(j=0; j<4; j++)

            M[i][j]=0;



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

        cin>>a[i][0]>>a[i][1]>>a[i][2];

    M[N-1][0]=a[N-1][0];

    M[N-1][1]=a[N-1][1];

    M[N-1][2]=a[N-1][2];



    for(i=N-2; i>=0; i--)

    {

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

        {

            if(j==0)

            {

                w1=1;

                w2=2;

            }

            else if(j==1)

            {

                w1=0;

                w2=2;

            }

            else

            {

                w1=0;

                w2=1;

            }

        M[i][j]=a[i][j]+max(M[i+1][w1],M[i+1][w2]);

        }

    }

    aa=max(M[0][0],M[0][1]);

    aa=max(aa,M[0][2]);

    cout<<aa<<endl;

    return 0;

}






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

using namespace std;



int main(){

    int n, i, j, k;

    scanf("%d",&n);

    int a[n+5], b[n+5], c[n+5];

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

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

    }

    int dp[n+5][3];

    memset(dp, 0, sizeof(dp));

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

        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];

        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];

        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];

    }

    int ans  = 0;

    ans = max(dp[n][0], dp[n][1]);

    ans = max(ans, dp[n][2]);

    printf("%d", ans);



    return 0;

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

using namespace std;

#define INF 100005

#define maxx 1000000000000



int n;

long long a[INF][3];

long long mem[INF][3];



long long rec(int level,int pre)

{

    if(level==n) return 0;

    if(mem[level][pre]!=-1) return mem[level][pre];

    long long now=0;

    if(pre==0)

    {

        now=max(now,max(a[level][0]+rec(level+1,1),a[level][0]+rec(level+1,2)));

    }else

    if(pre==1)

    {

        now=max(now,max(a[level][1]+rec(level+1,0),a[level][1]+rec(level+1,2)));

    }else

    if(pre==2)

    {

        now=max(now,max(a[level][2]+rec(level+1,0),a[level][2]+rec(level+1,1)));

    }

    return mem[level][pre]=now;

}



int main()

{

    memset(mem,-1,sizeof(mem));

    scanf("%d",&n);

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

    {

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

    }

    long long ans=max(rec(0,0),max(rec(0,1),rec(0,2)));

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

}


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

using namespace std;



int main(){

    int n, i, j, k;

    scanf("%d",&n);

    int a[n+5], b[n+5], c[n+5];

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

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

    }

    int dp[n+5][3];

    memset(dp, 0, sizeof(dp));

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

        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];

        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];

        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];

    }

    int ans  = 0;

    ans = max(dp[n][0], dp[n][1]);

    ans = max(ans, dp[n][2]);

    printf("%d", ans);



    return 0;

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

using namespace std;



long long w1,w2,hap=0,maxi,aa,bb,cc,N,i,j,k,a[100005][5];

long long M[100005][5];





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin>>N;

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

        for(j=0; j<4; j++)

            M[i][j]=0;



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

        cin>>a[i][0]>>a[i][1]>>a[i][2];

    M[N-1][0]=a[N-1][0];

    M[N-1][1]=a[N-1][1];

    M[N-1][2]=a[N-1][2];



    for(i=N-2; i>=0; i--)

    {

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

        {

            if(j==0)

            {

                w1=1;

                w2=2;

            }

            else if(j==1)

            {

                w1=0;

                w2=2;

            }

            else

            {

                w1=0;

                w2=1;

            }

        M[i][j]=a[i][j]+max(M[i+1][w1],M[i+1][w2]);

        }

    }

    aa=max(M[0][0],M[0][1]);

    aa=max(aa,M[0][2]);

    cout<<aa<<endl;

    return 0;

}






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

using namespace std;



int main()

{

    int i,n;

    cin>>n;

    int a[n+2], b[n+2], c[n+2], x=0, y=0, z=0, p, q, r;

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

    {

        cin>>a[i]>>b[i]>>c[i];

        if(i)

        {

            p=x,q=y,r=z;

            x=a[i]+max(q,r);

            y=b[i]+max(p,r);

            z=c[i]+max(q,p);

        }

        else

        {

            x=a[i], y=b[i], z=c[i];

        }

    }

    cout<<max(x, max(y, z))<<endl;

    return 0;

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

using namespace std;

#define INF 100005

#define maxx 1000000000000



int n;

long long a[INF][3];

long long mem[INF][3];



long long rec(int level,int pre)

{

    if(level==n) return 0;

    if(mem[level][pre]!=-1) return mem[level][pre];

    long long now=0;

    if(pre==0)

    {

        now=max(now,max(a[level][0]+rec(level+1,1),a[level][0]+rec(level+1,2)));

    }else

    if(pre==1)

    {

        now=max(now,max(a[level][1]+rec(level+1,0),a[level][1]+rec(level+1,2)));

    }else

    if(pre==2)

    {

        now=max(now,max(a[level][2]+rec(level+1,0),a[level][2]+rec(level+1,1)));

    }

    return mem[level][pre]=now;

}



int main()

{

    memset(mem,-1,sizeof(mem));

    scanf("%d",&n);

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

    {

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

    }

    long long ans=max(rec(0,0),max(rec(0,1),rec(0,2)));

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

}


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

using namespace std;



int main()

{

    int i,n;

    cin>>n;

    int a[n+2], b[n+2], c[n+2], x=0, y=0, z=0, p, q, r;

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

    {

        cin>>a[i]>>b[i]>>c[i];

        if(i)

        {

            p=x,q=y,r=z;

            x=a[i]+max(q,r);

            y=b[i]+max(p,r);

            z=c[i]+max(q,p);

        }

        else

        {

            x=a[i], y=b[i], z=c[i];

        }

    }

    cout<<max(x, max(y, z))<<endl;

    return 0;

}