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

# define ll long long

# define fi first

# define se second



using namespace std ;



ll N, a, b, c, sum, pre;

ll vc[100001][3], dp[100001][3] ;

int main() {

    cin >> N ;

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

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

    }

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

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

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

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

    }

    cout << max( { vc[N-1][1], vc[N-1][2], vc[N-1][3] } ) << endl;

}


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

#include<algorithm>

using namespace std;

const int maxn = 100005;

int n;

int A[3];

int dp[3][maxn] = {0};

int a,b,c;



int main(){

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

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

	int t = 1;

	while(n--){

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

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

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

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

		t++;

	}

	int ans = max(dp[0][t-1],max(dp[1][t-1],dp[2][t-1]));

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

	return 0;

}
// Slower C++ solution:
//بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ

//لا إله إلا الله محمد رسول الله



#include <bits/stdc++.h>



#pragma GCC optimize("Ofast")



#define ll long long

#define pb push_back

#define fr first

#define sc second

#define in freopen("input.txt", "r" , stdin)

#define out freopen("snakes.out", "w", stdout)

using namespace std;



ll dp[100005][5];

ll n;

ll a[100005], b[100005], c[100005];

int main(){

    //in;

    //out;

    ios_base::sync_with_stdio(false);

    cin >> n;



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

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

    }



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

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

    dp[1][3] = c[1];



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

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

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

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

    }



    cout << max (dp[n][1], max (dp[n][2] , dp[n][3]));





}






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

#include<algorithm>

using namespace std;

const int maxn = 100005;

int n;

int A[3];

int dp[3][maxn] = {0};

int a,b,c;



int main(){

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

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

	int t = 1;

	while(n--){

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

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

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

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

		t++;

	}

	int ans = max(dp[0][t-1],max(dp[1][t-1],dp[2][t-1]));

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

	return 0;

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

#define maxn (int)(2e5)

#define INF 1<<30

#define i64 long long

#define pii pair<i64,i64>

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

#define LB(x,v) lower_bound(all(x), v) - x.begin()

#define fread() freopen("in.txt", "r", stdin);

using namespace std;



int mat[maxn+2][4], ans[maxn+2][4] , n;

const int k = 3;



void init(int n){

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

        ans[i][0] = ans[i][1] = ans[i][2] = -1;

}



int solve(int day, int option){

    if(day >= n) return 0;



    if(ans[day][option] != -1) return ans[day][option];



    int res = -1;

    for(int next_option = 0; next_option < k; next_option++) {

        if(next_option != option) res = max(res, mat[day][option] + solve(day + 1, next_option));

    }



    return ans[day][option] = res;

}



int main() {

    

    while(scanf("%d",&n)==1){

        init(n);

        

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

            for(int j = 0;j < k; j++) scanf("%d",&mat[i][j]);

        }



        int res = -1;

        for(int option = 0; option < k; option++) {

            res = max(res, solve(0, option));

        }



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

    }    

    return 0;

}

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

#include<algorithm>

using namespace std;

const int maxn = 100005;

int n;

int A[3];

int dp[3][maxn] = {0};

int a,b,c;



int main(){

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

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

	int t = 1;

	while(n--){

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

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

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

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

		t++;

	}

	int ans = max(dp[0][t-1],max(dp[1][t-1],dp[2][t-1]));

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

	return 0;

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

using namespace std;

 

int main() {

	int Ndays;

	scanf("%d", &Ndays);

	int a, b, c;

	int A = 0, B = 0, C = 0;

	while (Ndays--) {

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

		int AA = max(B, C) + a;

		int BB = max(A, C) + b;

		int CC = max(A, B) + c;

		A = AA, B = BB, C = CC;

	}

	printf("%d", max(max(A, B), C));

}

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

#include<algorithm>

using namespace std;

const int maxn = 100005;

int n;

int A[3];

int dp[3][maxn] = {0};

int a,b,c;



int main(){

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

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

	int t = 1;

	while(n--){

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

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

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

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

		t++;

	}

	int ans = max(dp[0][t-1],max(dp[1][t-1],dp[2][t-1]));

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

	return 0;

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

#include<algorithm>

#define MAXN 100003

using namespace std;

int dp[MAXN][3], n, a[MAXN][3];

int main()

{

	cin >> n;

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

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

	}

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

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

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

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

	{

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

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

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

	}

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

	return 0;

}


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

#include<algorithm>

using namespace std;

const int maxn = 100005;

int n;

int A[3];

int dp[3][maxn] = {0};

int a,b,c;



int main(){

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

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

	int t = 1;

	while(n--){

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

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

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

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

		t++;

	}

	int ans = max(dp[0][t-1],max(dp[1][t-1],dp[2][t-1]));

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

	return 0;

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

#define rep(i,n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;

const int inf = 1001001001;

 

int main(){

  int n;

  cin >> n;

  

  vector<vector<int>> h(n, vector<int>(3));

  rep(i,n){

    rep(j,3){

      cin >> h.at(i).at(j);

    }

  }

  vector<vector<int>> dvector(n, vector<int>(3,0));

  

  

  rep(i,n){

    

    if (i == 0){

      rep(l,3){dvector.at(0).at(l) = h.at(0).at(l);}

      continue;

    }

    

    rep(j,3){

      rep(k,3){

        

      if(k != j){

        dvector.at(i).at(j) = max(dvector.at(i).at(j), dvector.at(i-1).at(k)+h.at(i).at(j));

      }

      

      }

    }

  }

    

    int ans = 0;

    rep(i,3){

    ans = max(ans, dvector.at(n-1).at(i));

    }

    

    cout << ans << endl;

    

  }


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

#include<algorithm>

using namespace std;

const int maxn = 100005;

int n;

int A[3];

int dp[3][maxn] = {0};

int a,b,c;



int main(){

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

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

	int t = 1;

	while(n--){

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

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

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

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

		t++;

	}

	int ans = max(dp[0][t-1],max(dp[1][t-1],dp[2][t-1]));

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

	return 0;

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



#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

#define repd(i,x,n) for(int i=x;i<=n;i++)



using namespace std;

typedef long long ll;

inline void getInt(int* p);

const int maxn=1000010;

const int inf=0x3f3f3f3f;

ll n;

ll a[maxn];

ll b[maxn];

ll c[maxn];

ll dp[maxn][5];



int main()

{

    gbtb;

    cin>>n;

    repd(i,1,n)

    {

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

    }

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

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

    dp[1][3]=c[1];

    repd(i,2,n)

    {

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

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

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

    }

    cout<<max(dp[n][3],max(dp[n][1],dp[n][2]));

    return 0;

}



inline void getInt(int* p) {

    char ch;

    do {

        ch = getchar();

    } while (ch == ' ' || ch == '\n');

    if (ch == '-') {

        *p = -(getchar() - '0');

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 - ch + '0';

        }

    }

    else {

        *p = ch - '0';

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 + ch - '0';

        }

    }

}

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

#include<algorithm>

using namespace std;

const int maxn = 100005;

int n;

int A[3];

int dp[3][maxn] = {0};

int a,b,c;



int main(){

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

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

	int t = 1;

	while(n--){

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

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

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

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

		t++;

	}

	int ans = max(dp[0][t-1],max(dp[1][t-1],dp[2][t-1]));

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

	return 0;

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



using namespace std;



    const int n = 1e5+5;

    int num;

    int act[n][3];

    int dyn[3][n];

    

    int init(int a, int i){

        

    	if(i == num) return 0;

    	

    	if(dyn[a][i] != -1) return dyn[a][i];

    	int& res = dyn[a][i];

    	

    	if(a==0){

    	    

    		res=max(res, init(1, i+1)+act[i][0]);

    		res=max(res, init(2, i+1)+act[i][0]);

    	}

    	

    	if(a==1){

    	    

    		res=max(res, init(0, i+1)+act[i][1]);

    		res=max(res, init(2, i+1)+act[i][1]);

    	}

    	

    	if(a==2){

    	    

    		res=max(res, init(0, i+1)+act[i][2]);

    		res=max(res, init(1, i+1)+act[i][2]);

    	}

    	

    	

    	return res;

    }

    

    int main(){

        

    	cin>>num;

    	for(int i=0; i<num; i++) cin>>act[i][0]>>act[i][1]>>act[i][2];

    	memset(dyn, -1, sizeof dyn);

    	cout<<max(init(0,0),max(init(1,0),init(2,0)))<<"\n";

    	return 0;

    	

    }

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

#include<algorithm>

using namespace std;

const int maxn = 100005;

int n;

int A[3];

int dp[3][maxn] = {0};

int a,b,c;



int main(){

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

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

	int t = 1;

	while(n--){

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

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

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

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

		t++;

	}

	int ans = max(dp[0][t-1],max(dp[1][t-1],dp[2][t-1]));

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

	return 0;

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

#include<algorithm>

using namespace std;

const int maxn = 100005;

int n;

int A[3];

int dp[3][maxn] = {0};

int a,b,c;



int main(){

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

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

	int t = 1;

	while(n--){

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

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

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

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

		t++;

	}

	int ans = max(dp[0][t-1],max(dp[1][t-1],dp[2][t-1]));

	printf("%d\n", 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.054118223770879x):
#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;

}
// 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.39054112637575x):
#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;

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

#include<algorithm>

#include<cstring>

using namespace std;

const int maxn = 1e5 + 5;



int a[maxn][4];

int dp[maxn][4];//d[i][j] i day choose j thing 's max happy



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

		}

	}



	memset(dp, 0, sizeof dp);



	for(int i = 1 ; i <= 3 ; i++) dp[1][i] = a[1][i];



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

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

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

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

	}



	int ans = 0;

	for(int i = 1 ; i <= 3 ; i++)ans = max(dp[n][i],ans);

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

}

// Faster C++ solution for the same problem (measured speedup: 1.7876315485302299x):
#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;

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



using namespace std;



    const int n = 1e5+5;

    int num;

    int act[n][3];

    int dyn[3][n];

    

    int init(int a, int i){

        

    	if(i == num) return 0;

    	

    	if(dyn[a][i] != -1) return dyn[a][i];

    	int& res = dyn[a][i];

    	

    	if(a==0){

    	    

    		res=max(res, init(1, i+1)+act[i][0]);

    		res=max(res, init(2, i+1)+act[i][0]);

    	}

    	

    	if(a==1){

    	    

    		res=max(res, init(0, i+1)+act[i][1]);

    		res=max(res, init(2, i+1)+act[i][1]);

    	}

    	

    	if(a==2){

    	    

    		res=max(res, init(0, i+1)+act[i][2]);

    		res=max(res, init(1, i+1)+act[i][2]);

    	}

    	

    	

    	return res;

    }

    

    int main(){

        

    	cin>>num;

    	for(int i=0; i<num; i++) cin>>act[i][0]>>act[i][1]>>act[i][2];

    	memset(dyn, -1, sizeof dyn);

    	cout<<max(init(0,0),max(init(1,0),init(2,0)))<<"\n";

    	return 0;

    	

    }

// Faster C++ solution for the same problem (measured speedup: 2.2068668047743194x):
#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;

}
// 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.9512732955337468x):
#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;



}
// 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: 1.3090062527998816x):
#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;



}