stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



int dp[3];



int main(){

    int n,a,b,c,x,y,z;

    cin>>n;



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

        cin>>a>>b>>c;

        if(i==0){

            dp[0]=a;

            dp[1]=b;

            dp[2]=c;

            continue;

        }



        x=dp[0];

        y=dp[1];

        z=dp[2];



        dp[0]=a+max(y,z);

        dp[1]=b+max(x,z);

        dp[2]=c+max(x,y);







    }



    cout<<max(dp[0],max(dp[1],dp[2]))<<endl;





    return 0;







}


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

#include <algorithm>

using namespace std;



int a[100000][3],dp[100000][3];



int main()

{

	int n,i,j;

	scanf("%d",&n);

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

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

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

	}

	dp[0][0]=a[0][0];

	dp[0][1]=a[0][1];

	dp[0][2]=a[0][2];

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

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

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

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

	}

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

	return 0;

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

#include<cstdio>

#include<cstring> 

#include<string>

#include<map>

#include<vector>

#include<cmath>

#include<string>

#include<algorithm>

using namespace std;

int dp[100000][3];

int main()

{

	  int a,b,c,d;

	  cin>>a;

	  dp[0][0]=0;

	  dp[0][1]=0;

	  dp[0][2]=0;

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

	  {

	  	cin>>b;

	  	cin>>c;

	  	cin>>d;	 

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

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

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

	  }	  

	  cout<<max(max(dp[a][0],dp[a][1]),dp[a][2])<<endl;

	  return 0;

}

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

#include <algorithm>

using namespace std;



int a[100000][3],dp[100000][3];



int main()

{

	int n,i,j;

	scanf("%d",&n);

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

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

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

	}

	dp[0][0]=a[0][0];

	dp[0][1]=a[0][1];

	dp[0][2]=a[0][2];

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

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

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

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

	}

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

	return 0;

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

#include <string.h>

#define MAXN 100003



int array_a[MAXN][3];

int array_d[MAXN][3];



int max(int a,int b){

	return a>b? a:b;

}



int main(){

	memset(array_a,-1,sizeof(int)*MAXN*3);

	memset(array_d,-1,sizeof(int)*MAXN*3);

	int N;

	scanf("%d",&N);



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

		scanf("%d %d %d",&array_a[i][0],&array_a[i][1],&array_a[i][2]);

	}



	array_d[0][0]=array_a[0][0];

	array_d[0][1]=array_a[0][1];

	array_d[0][2]=array_a[0][2];

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

		array_d[i][0]=array_a[i][0]+max(array_d[i-1][1],array_d[i-1][2]);

		array_d[i][1]=array_a[i][1]+max(array_d[i-1][0],array_d[i-1][2]);

		array_d[i][2]=array_a[i][2]+max(array_d[i-1][0],array_d[i-1][1]);

	}

	printf("%d",max(array_d[N-1][0],max(array_d[N-1][1],array_d[N-1][2])));

	return 0;



}

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

#include <algorithm>

using namespace std;



int a[100000][3],dp[100000][3];



int main()

{

	int n,i,j;

	scanf("%d",&n);

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

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

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

	}

	dp[0][0]=a[0][0];

	dp[0][1]=a[0][1];

	dp[0][2]=a[0][2];

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

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

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

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

	}

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

	return 0;

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

#include<string>

#include<cmath>

#include<algorithm>

#include<vector>

#include<map>

#include<stack>

#include<queue>

using namespace std;

#define MAXN 100001

int dp[MAXN*3];

int main(){

	int N;

	cin>>N;

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

		cin>>dp[i];

	}

	//dp[i]对应与本次选择i%3(A,B,C)的最大值，等于前面不选择i%3的最大值加上选择i%3的值

	for(int i=3;i<N*3;i++){

		if(i%3==0){

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

		}else if(i%3==1){

			dp[i]=dp[i]+max(dp[i-4],dp[i-2]);

		}else{

			dp[i]=dp[i]+max(dp[i-4],dp[i-5]);

		}

	}

	int x;

	if(dp[3*N-1]>=dp[3*N-2]){

		x=dp[3*N-1];

	}else{

		x=dp[3*N-2];

	}

   cout<<(x>dp[3*N-3]?x:dp[3*N-3]);

   return 0;

} 

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

#include <algorithm>

using namespace std;



int a[100000][3],dp[100000][3];



int main()

{

	int n,i,j;

	scanf("%d",&n);

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

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

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

	}

	dp[0][0]=a[0][0];

	dp[0][1]=a[0][1];

	dp[0][2]=a[0][2];

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

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

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

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

	}

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

	return 0;

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

#include<cstring>

#include<vector>

#include<stack>

#include<cstdio>

using namespace std;

int main()

{

	int n,a,b,c,flag=1,ans=0;

	int x[2][3];

	scanf("%d",&n);

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

	{

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

		if(i==0)

		{

			x[i][0]=a;

		    x[i][1]=b;

		    x[i][2]=c;

		    continue;

		}

		x[flag][0]=a+max(x[1-flag][1],x[1-flag][2]);

		x[flag][1]=b+max(x[1-flag][2],x[1-flag][0]);

		x[flag][2]=c+max(x[1-flag][1],x[1-flag][0]);

		flag=1-flag;

	}

	ans=max(x[1-flag][0],max(x[1-flag][1],x[1-flag][2]));

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

	return 0;

}


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

#include <algorithm>

using namespace std;



int a[100000][3],dp[100000][3];



int main()

{

	int n,i,j;

	scanf("%d",&n);

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

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

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

	}

	dp[0][0]=a[0][0];

	dp[0][1]=a[0][1];

	dp[0][2]=a[0][2];

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

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
//       Author: Mostafa Mounir Shehab

 

#include <bits/stdc++.h>

using namespace std;

 

#define PI  3.14159265  // PI = acos(-1)

#define EPS (1e-10)

#define endl "\n"

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

typedef long long ll;

typedef long double ld;

//template <class Type>

 

 

void Fast(){

	std::ios_base::sync_with_stdio(0);

	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);

}

 

inline int D(){

	int t;

	scanf("%d",&t);

	return t;

}

inline ll llD(){

	ll t;

	scanf("%lld",&t);

	return t;

}

 

 

ll MOD=1e9 + 7; 

const int N=1e5 + 5,M=50 + 1;

int arr[N][4];

ll dp[N][4];

ll OO=1e12; 

 

ll n,m,k,cnt,SU,idx,len,MN,MX;

ll l,r,mid;

ll a,b,c,d;



ll Solve(int idx,int row){

	

		

	if(idx == n)

		return 0;

	

	ll &ret = dp[idx][row];

	if(~ret)

		return ret;

	

	ret = -OO;

	

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

		if(row != i)

			ret = max(ret,arr[idx][i] + Solve(idx+1,i));

	

	return ret;

}







 

 

int main(){

	

	memset(dp, -1 ,sizeof dp);

	cin>>n;

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

		cin>>arr[i][1]>>arr[i][2]>>arr[i][3];



	cout<<Solve(0,0)<<endl;

	



	





}

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

#include <algorithm>

using namespace std;



int a[100000][3],dp[100000][3];



int main()

{

	int n,i,j;

	scanf("%d",&n);

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

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

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

	}

	dp[0][0]=a[0][0];

	dp[0][1]=a[0][1];

	dp[0][2]=a[0][2];

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

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

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

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

	}

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

	return 0;

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

#include <bits/stdc++.h>

#include <unordered_map>

#define stop(x) {cout<<x<<endl;exit(0);}

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

#define szz(s) int(s.size())

#define endl '\n'

int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

typedef long long ll;

using namespace std;



void file() {

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

#ifndef ONLINE_JUDGE

    if (freopen("input.txt", "r", stdin));

    if (freopen("output.txt", "w", stdout));

#endif

}





ll n;

ll mem[100004][4];

vector < vector < int > > v;



ll solve(int idx , int last) {

    if (idx == n)return 0;



    ll& ret = mem[idx][last];

    if (~ret)return ret;

    ret = 0;

    if (last != 0)ret = max(ret, solve(idx + 1, 0) + v[idx][0]);

    if (last != 1)ret = max(ret, solve(idx + 1, 1) + v[idx][1]);

    if (last != 2)ret = max(ret, solve(idx + 1, 2) + v[idx][2]);

    return ret;

}



int main() {

    //file();



    memset(mem, -1, sizeof mem);

    cin >> n;

    v = vector < vector < int > >(n, vector < int >(3));

    for (auto& e : v)

        for (auto& f : e)

            cin >> f;



    cout << solve(0,3) << endl;



}

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

#include <algorithm>

using namespace std;



int a[100000][3],dp[100000][3];



int main()

{

	int n,i,j;

	scanf("%d",&n);

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

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

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

	}

	dp[0][0]=a[0][0];

	dp[0][1]=a[0][1];

	dp[0][2]=a[0][2];

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

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
/******

author :- Mahmoud Tarek.

*******/



#include<bits/stdc++.h>



using namespace std ;



#define rg register

#define dbg(v) cerr << #v << " " << v ;

typedef long long ll ;



int n;

struct doW{

int w[5] ;

};



vector<doW> a ;

int mem[100002][6] ;



int solve(int i, int ch){

if(i == n) return 0 ;

int & ret = mem[i][ch] ;

if(~ret) return ret ;

ret = 0 ;

for(int j = 2 ; j <= 4 ; j++){

    if(ch != j){

        ret = max(ret, a[i].w[j] + solve(i + 1, j)) ;

    }

}

return ret ;

}



int main() {

//  freopen("in.txt", "r", stdin) ;

    cin >> n ;

    a.resize(n) ;

    memset(mem, -1, sizeof mem) ;

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

        for(int j = 2 ; j <= 4 ; j++) cin >> a[i].w[j] ;

    }

    cout << solve(0, 1) ;



}



/*

  Empty set of troubles.

*/


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

#include <algorithm>

using namespace std;



int a[100000][3],dp[100000][3];



int main()

{

	int n,i,j;

	scanf("%d",&n);

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

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

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

	}

	dp[0][0]=a[0][0];

	dp[0][1]=a[0][1];

	dp[0][2]=a[0][2];

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

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
#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;

}

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

    dp[1][0] = a[1];

    dp[1][1] = b[1];

    dp[1][2] = c[1];

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

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

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

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

    }

    int ans = 0;

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

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

    }

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

}
// Slower C++ solution:
#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;

}


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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

    dp[1][0] = a[1];

    dp[1][1] = b[1];

    dp[1][2] = c[1];

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

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

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

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

    }

    int ans = 0;

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

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

    }

    printf("%d\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: 26.27605623414978x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

    dp[1][0] = a[1];

    dp[1][1] = b[1];

    dp[1][2] = c[1];

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

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

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

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

    }

    int ans = 0;

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

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

    }

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

}
// 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: 17.627219102598797x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

    dp[1][0] = a[1];

    dp[1][1] = b[1];

    dp[1][2] = c[1];

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

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

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

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

    }

    int ans = 0;

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

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

    }

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

}
// Slower C++ solution:
#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;

}


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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

    dp[1][0] = a[1];

    dp[1][1] = b[1];

    dp[1][2] = c[1];

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

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

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

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

    }

    int ans = 0;

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

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

    }

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

}
// Slower C++ solution:
#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;

}


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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

    dp[1][0] = a[1];

    dp[1][1] = b[1];

    dp[1][2] = c[1];

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

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

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

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

    }

    int ans = 0;

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

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

    }

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

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

using namespace std;

#define ll long long

#define MX 100005



const ll INF = 1e12;



int A[MX][4];

ll dp[MX][4];



ll recur(int i, int j){

    if (i == 1) return dp[i][j] = A[i][j];

    if (dp[i][j] != -1) return dp[i][j];



    ll mx = 0;

    for (int x = 1; x <= 3; x++){

        if (x != j) mx = max(mx, recur(i-1, x));

    }

    return dp[i][j] = (mx + A[i][j]);

}



int main()

{

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

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

        for (int j = 1; j <= 3; j++){

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

            dp[i][j] = -1;

        }

    }



    ll ans = 0;

    for (int j = 1; j <= 3; j++){

        ans = max(ans, recur(n, j));

    }



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



    return 0;

}


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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

    dp[1][0] = a[1];

    dp[1][1] = b[1];

    dp[1][2] = c[1];

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

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

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

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

    }

    int ans = 0;

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

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

    }

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

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

using namespace std;



#define pb push_back

#define mp make_pair

#define fi first

#define se second

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

#define rall(x) (x).rbegin(), (x).rend()

#define MAX 1000000

//3

typedef long long ll;

typedef pair<int,int> pii;

priority_queue< int > pq;

priority_queue< int , vector<int> , greater<int> > rpq;

set<int>s;

set <int > :: iterator itr; 

vector<int> vec[1001];

int r,n,m,inp,tc;

int arr[1000007]= {};

map<int , int> mymap;





int main()

{

	int n;

	int arr[3];

	int dp[3];

	cin>>n;

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

		cin>>arr[0]>>arr[1]>>arr[2];

		if(i == 0 ) {

			dp[0] = arr[0];

			dp[1] = arr[1];

			dp[2] = arr[2];

		}

		else{

			int a = dp[0];

			int b = dp[1];

			int c = dp[2];

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

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

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

		}

		//cout<<dp[0]<<" "<<dp[1]<<" "<<dp[2]<<endl;

	}

	cout<<max(max(dp[0],dp[1]),dp[2])<<endl;

    return 0;

}



//65 900 17 13

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

    dp[1][0] = a[1];

    dp[1][1] = b[1];

    dp[1][2] = c[1];

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

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

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

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

    }

    int ans = 0;

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

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

    }

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

}