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

using namespace std;

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

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

typedef long long ll;

typedef unsigned long long ull;

#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++)

#define forn(i, n) forr(i, 0, n)

#define pb push_back

#define mp make_pair

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

#define DBG(x) cerr << #x << " = " << (x) << endl

#define MOD 1000000007

#define MAXN 100005

ll dp[MAXN][3];

void solve(vector< vector<ll> > &a, int n)

{

    forn(i,MAXN)

    {

        forn(j,3)

        {

            dp[i][j]=(pow(10,9)+5)*(ll)(-1);

        }

    }

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

    forr(i,1,n)

    {

        forn(j,3)

        {

            forn(k,3)

            {

                if(j==k)

                {

                    continue;

                }

                else dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);

            }

        }

 

    }

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

}

 

int main() {

    FIN;

    int n;

    cin >> n;

    vector< vector<ll> > arreglo(n);

    forn(i,n) arreglo[i].resize(3);

    forn(i,n)

    {

        forn(j,3) cin >> arreglo[i][j];

    }

    solve(arreglo, n);

    return 0;

}

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



typedef   long long  int ll;

typedef  long double ld;

typedef std::vector<ll> vi;

typedef std::vector<std::vector<ll> > vv;



#define MOD 1000000007

#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);

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

#define mp make_pair

#define pb(x) push_back(x)

#define fi first

#define se second

#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" ";cout<<endl;

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

#define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];

#define ms(a,val) memset(a,val,sizeof(a))

using namespace std;



const int N = 1e5 + 5;





void solve(){

            ll i,j,n,m,k;

            

            

            cin>>n;

            ll dp[n][3];

            ms(dp,0);

            ll a[n][3];

            fo(i,0,n)

            {fo(j,0,3)

				cin>>a[i][j];

			}

			fo(i,0,3)

			dp[0][i] = a[0][i];//,dp[1] = a[1],dp[2]  =a[2];

			fo(i,1,n)

			{

				fo(j,0,3)

				{

					//dp[i][j] = INT_MAX;

					fo(k,0,3)

					{

						if(j^k)

						 dp[i][j] = max(dp[i][j],dp[i-1][k] + a[i][j]);

					 }

				 }

			 }

			 ll minn =  INT_MIN;

			 fo(i,0,3)

			  minn = max(minn,dp[n-1][i]);

			  cout<<minn<<endl;

            

    

            

						            



















}



int main()

{

    IO;

      ll t=1;

      //cin>>t;





      while(t--)

      {



          solve();

      }

    return 0;

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

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define ll long long

using namespace std;

const int N = 100010;

int dp[N][3];

int main(){

    fast;

	int n, i, a, b, c;

	cin >> n;

	memset(dp, 0, sizeof dp);

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

		cin >> a >> b >> c;

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

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

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

	}

	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << "\n";

	return 0;

}


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



typedef   long long  int ll;

typedef  long double ld;

typedef std::vector<ll> vi;

typedef std::vector<std::vector<ll> > vv;



#define MOD 1000000007

#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);

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

#define mp make_pair

#define pb(x) push_back(x)

#define fi first

#define se second

#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" ";cout<<endl;

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

#define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];

#define ms(a,val) memset(a,val,sizeof(a))

using namespace std;



const int N = 1e5 + 5;





void solve(){

            ll i,j,n,m,k;

            

            

            cin>>n;

            ll dp[n][3];

            ms(dp,0);

            ll a[n][3];

            fo(i,0,n)

            {fo(j,0,3)

				cin>>a[i][j];

			}

			fo(i,0,3)

			dp[0][i] = a[0][i];//,dp[1] = a[1],dp[2]  =a[2];

			fo(i,1,n)

			{

				fo(j,0,3)

				{

					//dp[i][j] = INT_MAX;

					fo(k,0,3)

					{

						if(j^k)

						 dp[i][j] = max(dp[i][j],dp[i-1][k] + a[i][j]);

					 }

				 }

			 }

			 ll minn =  INT_MIN;

			 fo(i,0,3)

			  minn = max(minn,dp[n-1][i]);

			  cout<<minn<<endl;

            

    

            

						            



















}



int main()

{

    IO;

      ll t=1;

      //cin>>t;





      while(t--)

      {



          solve();

      }

    return 0;

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

using namespace std;

#define tpl  tuple<int, int, int>

#define mt   make_tuple

#define LIM  100000





int n, dp[LIM+5][4], vis[LIM+5][4];

vector<tpl> v;



int f(int pos, int k){

    if(pos >= n) return 0;

    if(vis[pos][k]) return dp[pos][k];

    vis[pos][k] = 1;

    int ans;

    if(k == 0) ans = get<0>(v[pos]) + max(f(pos+1, 1), f(pos+1, 2));

    else if(k == 1) ans = get<1>(v[pos]) + max(f(pos+1, 0), f(pos+1, 2));

    else ans = get<2>(v[pos]) + max(f(pos+1, 0), f(pos+1, 1));



    return dp[pos][k] = ans;

}



int main(){

    scanf("%d", &n);

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

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

        v.push_back(mt(a, b, c));

    }

    int ans = f(0, 0);

    memset(dp, 0, sizeof dp);

    memset(vis, 0, sizeof vis);

    ans = max(ans, f(0, 1));

    memset(dp, 0, sizeof dp);

    memset(vis, 0, sizeof vis);

    ans = max(ans, f(0, 2));



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

}


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



typedef   long long  int ll;

typedef  long double ld;

typedef std::vector<ll> vi;

typedef std::vector<std::vector<ll> > vv;



#define MOD 1000000007

#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);

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

#define mp make_pair

#define pb(x) push_back(x)

#define fi first

#define se second

#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" ";cout<<endl;

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

#define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];

#define ms(a,val) memset(a,val,sizeof(a))

using namespace std;



const int N = 1e5 + 5;





void solve(){

            ll i,j,n,m,k;

            

            

            cin>>n;

            ll dp[n][3];

            ms(dp,0);

            ll a[n][3];

            fo(i,0,n)

            {fo(j,0,3)

				cin>>a[i][j];

			}

			fo(i,0,3)

			dp[0][i] = a[0][i];//,dp[1] = a[1],dp[2]  =a[2];

			fo(i,1,n)

			{

				fo(j,0,3)

				{

					//dp[i][j] = INT_MAX;

					fo(k,0,3)

					{

						if(j^k)

						 dp[i][j] = max(dp[i][j],dp[i-1][k] + a[i][j]);

					 }

				 }

			 }

			 ll minn =  INT_MIN;

			 fo(i,0,3)

			  minn = max(minn,dp[n-1][i]);

			  cout<<minn<<endl;

            

    

            

						            



















}



int main()

{

    IO;

      ll t=1;

      //cin>>t;





      while(t--)

      {



          solve();

      }

    return 0;

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

#define ll long long

#define endl "\n"

#define shalaby ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);cerr.tie(0);

#define mod 100000000

using namespace std;



inline int D()

{

    int t;

    scanf("%d",&t);

    return t;

}

inline ll llD()

{

    ll t;

    scanf("%lld",&t);

    return t;

}

const int Max=1e5+8;

const int OO=-1e6;

int xt[4]= {1,0,0,-1};

int yt[4]= {0,1,-1,0};

////////////////////////////////////////////////////////////////////////////////////



ll mem[100005][5],a[100005],b[100005],c[100005],n,m;

bool valid(int x,int y)

{

    return x>-1 && y>-1 && x<n && y<m;

}

void init()

{

    memset(mem,-1,sizeof mem);

}

/////////////////////////////////////////////////////////////////////

ll solve(int i=0, int k=3)

{

    if(i==n)

        return 0;

    ll &ret=mem[i][k];

    if(~ret)return ret;

    ret =0;

    if(k!=0)

        ret=max(ret,solve(i+1,0)+a[i]);



    if(k!=1)

        ret=max(ret,solve(i+1,1)+b[i]);

    if(k!=2)

        ret=max(ret,solve(i+1,2)+c[i]);

    return ret;

}



int main()

{

    init();

    int T=1;

///   T=D();

    while(T-->0)

    {

        cin >> n ;

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

        {

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

        }

        cout << solve();

    }

}


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



typedef   long long  int ll;

typedef  long double ld;

typedef std::vector<ll> vi;

typedef std::vector<std::vector<ll> > vv;



#define MOD 1000000007

#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);

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

#define mp make_pair

#define pb(x) push_back(x)

#define fi first

#define se second

#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" ";cout<<endl;

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

#define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];

#define ms(a,val) memset(a,val,sizeof(a))

using namespace std;



const int N = 1e5 + 5;





void solve(){

            ll i,j,n,m,k;

            

            

            cin>>n;

            ll dp[n][3];

            ms(dp,0);

            ll a[n][3];

            fo(i,0,n)

            {fo(j,0,3)

				cin>>a[i][j];

			}

			fo(i,0,3)

			dp[0][i] = a[0][i];//,dp[1] = a[1],dp[2]  =a[2];

			fo(i,1,n)

			{

				fo(j,0,3)

				{

					//dp[i][j] = INT_MAX;

					fo(k,0,3)

					{

						if(j^k)

						 dp[i][j] = max(dp[i][j],dp[i-1][k] + a[i][j]);

					 }

				 }

			 }

			 ll minn =  INT_MIN;

			 fo(i,0,3)

			  minn = max(minn,dp[n-1][i]);

			  cout<<minn<<endl;

            

    

            

						            



















}



int main()

{

    IO;

      ll t=1;

      //cin>>t;





      while(t--)

      {



          solve();

      }

    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: 4.995197954270166x):
#include <iostream>

#include <vector>

using namespace std;

int main(){

    int a;

    while(cin>>a){

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

        vector<vector<int>> num(a,vector<int> (3,0));

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

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

                cin>>num[i][j];

            }

        }

        dp[0][0]=num[0][0];

        dp[0][1]=num[0][1];

        dp[0][2]=num[0][2];

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

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

                if(j==0){

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

                }

                else if(j==1){

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

                }

                else if(j==2){

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

                }

            }

        }

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

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

    }

}
// 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.3510146277711605x):
#include <iostream>

#include <vector>

using namespace std;

int main(){

    int a;

    while(cin>>a){

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

        vector<vector<int>> num(a,vector<int> (3,0));

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

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

                cin>>num[i][j];

            }

        }

        dp[0][0]=num[0][0];

        dp[0][1]=num[0][1];

        dp[0][2]=num[0][2];

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

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

                if(j==0){

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

                }

                else if(j==1){

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

                }

                else if(j==2){

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

                }

            }

        }

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

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

    }

}
// 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.7667915665701732x):
#include <iostream>

#include <vector>

using namespace std;

int main(){

    int a;

    while(cin>>a){

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

        vector<vector<int>> num(a,vector<int> (3,0));

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

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

                cin>>num[i][j];

            }

        }

        dp[0][0]=num[0][0];

        dp[0][1]=num[0][1];

        dp[0][2]=num[0][2];

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

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

                if(j==0){

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

                }

                else if(j==1){

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

                }

                else if(j==2){

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

                }

            }

        }

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

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

    }

}
// 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.1811394313468604x):
#include <iostream>

#include <vector>

using namespace std;

int main(){

    int a;

    while(cin>>a){

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

        vector<vector<int>> num(a,vector<int> (3,0));

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

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

                cin>>num[i][j];

            }

        }

        dp[0][0]=num[0][0];

        dp[0][1]=num[0][1];

        dp[0][2]=num[0][2];

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

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

                if(j==0){

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

                }

                else if(j==1){

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

                }

                else if(j==2){

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

                }

            }

        }

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

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

    }

}
// 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: 2.559968388694517x):
#include <iostream>

#include <vector>

using namespace std;

int main(){

    int a;

    while(cin>>a){

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

        vector<vector<int>> num(a,vector<int> (3,0));

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

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

                cin>>num[i][j];

            }

        }

        dp[0][0]=num[0][0];

        dp[0][1]=num[0][1];

        dp[0][2]=num[0][2];

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

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

                if(j==0){

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

                }

                else if(j==1){

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

                }

                else if(j==2){

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

                }

            }

        }

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

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

    }

}
// 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: 4.177322599764243x):
#include <iostream>

#include <vector>

using namespace std;

int main(){

    int a;

    while(cin>>a){

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

        vector<vector<int>> num(a,vector<int> (3,0));

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

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

                cin>>num[i][j];

            }

        }

        dp[0][0]=num[0][0];

        dp[0][1]=num[0][1];

        dp[0][2]=num[0][2];

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

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

                if(j==0){

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

                }

                else if(j==1){

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

                }

                else if(j==2){

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

                }

            }

        }

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

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

    }

}