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

using namespace std;



int main()  {

    int n;

    cin>>n;

    int a[n];

    

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

        cin>>a[i];

        }

    int c=0;

    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]))

            c++;

        }

        cout<<c;

}

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

int main()

{

    int num,i,j,k,big=-1,avg,max,total=0,count[50];

    scanf("%d",&max);

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

    {

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

    }

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

    {

        if(count[i]>count[i-1] && count[i]<count[i+1])

        {

            total++;

        }

        else if(count[i]<count[i-1] && count[i]>count[i+1])

        {

            total++;

        }

    }

    printf("%d",total);

    return 0;

}


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

#include <vector>



using namespace std;



using std::vector;



int main()

{

    int n;

    cin >> n;



    vector<int> numbers(n);



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

    {

        cin >> numbers[i];

    }



    int count = 0;

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

    {

        if((numbers[i] < numbers[i+1] && numbers[i+1] < numbers[i+2]) || (numbers[i] > numbers[i+1] && numbers[i+1] > numbers[i+2]))

        {

            count++;

        }

    }



    cout << count << endl;





    return 0;

}

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

int main()

{

    int num,i,j,k,big=-1,avg,max,total=0,count[50];

    scanf("%d",&max);

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

    {

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

    }

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

    {

        if(count[i]>count[i-1] && count[i]<count[i+1])

        {

            total++;

        }

        else if(count[i]<count[i-1] && count[i]>count[i+1])

        {

            total++;

        }

    }

    printf("%d",total);

    return 0;

}


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

using namespace std;

void debug() {cout<<endl;}

template<typename T,typename... Args>

void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}

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

#define SZ(x) int(x.size())

#define pb push_back

#define F first

#define S second

#define endl "\n"

typedef long long ll;

typedef pair<int, int> pii;



int main() {

    ios::sync_with_stdio(0); cin.tie(0);

    int n;

    cin >> n;

    int v[n];

    forn(i, 0, n) {

        cin >> v[i];

    }

    int ans = 0;

    forn(i, 1, n-1) {

        int aux[3] = {v[i-1], v[i], v[i+1]};

        sort(aux, aux+3);

        if (v[i] == aux[1]) ans++;

    }

    cout << ans << endl;

}


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

int main()

{

    int num,i,j,k,big=-1,avg,max,total=0,count[50];

    scanf("%d",&max);

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

    {

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

    }

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

    {

        if(count[i]>count[i-1] && count[i]<count[i+1])

        {

            total++;

        }

        else if(count[i]<count[i-1] && count[i]>count[i+1])

        {

            total++;

        }

    }

    printf("%d",total);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/*我是萌新*/

#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';

    }

}




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

}


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

}

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

}


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

}




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

}


// Fastest known solution for this problem:
// Original C++ solution (slower):


#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;



}


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

}


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

}


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

}


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

	}

}

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

	}

}

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

}

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

}

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

}

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

}

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

}






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

#include <algorithm>

using std::max;



int main(void)

{

    int dp[2][3],a[3],i,N;

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

    printf("%d\n",max(max(dp[i][0],dp[i][1]),dp[i][2]));

    return 0;

}

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

}


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

#include <algorithm>

using std::max;



int main(void)

{

    int dp[2][3],a[3],i,N;

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

    printf("%d\n",max(max(dp[i][0],dp[i][1]),dp[i][2]));

    return 0;

}

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

using namespace std;

const int MAX_n=1e5+10;

int n;

int a[MAX_n],b[MAX_n],c[MAX_n];

int dp[MAX_n][3];

int main()

{

    cin>>n;

    for(int i=1;i<=n;i++)    cin>>a[i]>>b[i]>>c[i];

    dp[1][0]=max(b[1],c[1]);

    dp[1][1]=max(a[1],c[1]);

    dp[1][2]=max(a[1],b[1]);

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

    {

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

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

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

    }

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

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

    cout<<ans;

    return 0;

}

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

#include <algorithm>

using std::max;



int main(void)

{

    int dp[2][3],a[3],i,N;

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

    printf("%d\n",max(max(dp[i][0],dp[i][1]),dp[i][2]));

    return 0;

}

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

#include <vector>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <set>

#include <tuple>

#include <functional>

#include <map>

#include <unordered_map>

#include <queue>

#include <tuple>



using namespace std;



#define endl '\n'



using ull = unsigned long int;

using ll = long long;



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(nullptr);

  const int precision = 13;

  cout.precision(precision);

  cout.setf(ios_base::fixed);



  int n; cin >> n;

  vector<vector<int>> dp(2, vector<int>(3, 0));



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

    int a, b, c; cin >> a >> b >> c;

    int cur = i%2;

    int prev = (i-1)%2;

    dp[cur][0] = a + max(dp[prev][1], dp[prev][2]);

    dp[cur][1] = b + max(dp[prev][0], dp[prev][2]);

    dp[cur][2] = c + max(dp[prev][0], dp[prev][1]);

  }



  cout << *max_element(dp[n%2].begin(), dp[n%2].end()) << endl;





  return 0;

}


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

#include <algorithm>

using std::max;



int main(void)

{

    int dp[2][3],a[3],i,N;

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

    printf("%d\n",max(max(dp[i][0],dp[i][1]),dp[i][2]));

    return 0;

}

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

}


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

#include <algorithm>

using std::max;



int main(void)

{

    int dp[2][3],a[3],i,N;

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

    printf("%d\n",max(max(dp[i][0],dp[i][1]),dp[i][2]));

    return 0;

}

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

}


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

#include <algorithm>

using std::max;



int main(void)

{

    int dp[2][3],a[3],i,N;

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

    printf("%d\n",max(max(dp[i][0],dp[i][1]),dp[i][2]));

    return 0;

}

// Fastest known solution for this problem: