stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



const int N = 1e5+5;



int n;

int a[N][3];

int mem[N][3];



int go(int idx , int lst){

    if(idx == n + 1)

        return 0;

    if(~mem[idx][lst])

        return mem[idx][lst];

    int best = 0;

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

        if(idx == 1 || lst != i){

            best = max(best , go(idx + 1 , i) + a[idx][i]);

        }

    }

    return mem[idx][lst] = best;

}



int main(){

    scanf("%d" , &n);

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

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

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

        }

    }

    memset(mem , -1 , sizeof mem);

    printf("%d\n" , go(1 , 0));

}


// Faster C++ solution for the same problem (measured speedup: 2.1630834065564266x):
																//  SMOKE SHISHA PLAY FIFA  // 

#include<bits/stdc++.h>

using namespace std;



typedef long long int ll;

typedef long double ld;



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

#define pll pair<ll,ll>

#define MP make_pair

#define ff first

#define ss second

#define PB push_back

#define mod 1000000007

#define lp(i,start,end) for(ll i=start;i<=end;i++) 

#define deb1(a) cout<<#a<<" = "<<(a)<<endl;

#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;

#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;





ll modu(ll a, ll b)

{

	ll ans =1;

	while(b>0)

	{

		if(b&1)

		ans = (ans*a)%mod;

		b/=2;

		a = (a*a)%mod;

	}

	return ans;

}



int main()

{

	fastio

	ll t=1;

	//cin >> t;

	while(t--)

	{

		ll n;

		cin>>n;

		ll a[n+1],b[n+1],c[n+1],dp[3][n];

		lp(i,1,n)

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

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

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

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

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

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

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

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

    }

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

	}

	return 0;	

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

//const int mod = 1e9+9;

/*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }

*ll lcm(ll x, ll y){return x*(y/gcd(x,y));}

*void exEuclid(int a, int b){

	if(b==0){x = 1; y=0; d=a; return ;}

	exEuclid(b, a%b);

	int x1 = y;

	int y1 = x-(a/b)*y;

	x = x1; 100000

	y = y1;

} 

* */

//===========================================================//

int n;

const int nx = 1e5+5;

int ac[nx][3];

int dp[3][nx];

int go(int a, int i){

	if(i == n) return 0;

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

	int& ans = dp[a][i];

	

	if(a==0){

		ans=max(ans, go(1, i+1)+ac[i][0]);

		ans=max(ans, go(2, i+1)+ac[i][0]);

	}

	if(a==1){

		ans=max(ans, go(0, i+1)+ac[i][1]);

		ans=max(ans, go(2, i+1)+ac[i][1]);

	}

	if(a==2){

		ans=max(ans, go(0, i+1)+ac[i][2]);

		ans=max(ans, go(1, i+1)+ac[i][2]);

	}

	

	return ans;

}

int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.1814788400709015x):
																//  SMOKE SHISHA PLAY FIFA  // 

#include<bits/stdc++.h>

using namespace std;



typedef long long int ll;

typedef long double ld;



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

#define pll pair<ll,ll>

#define MP make_pair

#define ff first

#define ss second

#define PB push_back

#define mod 1000000007

#define lp(i,start,end) for(ll i=start;i<=end;i++) 

#define deb1(a) cout<<#a<<" = "<<(a)<<endl;

#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;

#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;





ll modu(ll a, ll b)

{

	ll ans =1;

	while(b>0)

	{

		if(b&1)

		ans = (ans*a)%mod;

		b/=2;

		a = (a*a)%mod;

	}

	return ans;

}



int main()

{

	fastio

	ll t=1;

	//cin >> t;

	while(t--)

	{

		ll n;

		cin>>n;

		ll a[n+1],b[n+1],c[n+1],dp[3][n];

		lp(i,1,n)

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

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

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

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

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

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

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

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

    }

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

	}

	return 0;	

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

using namespace std;



int m;

const int mx = 1e5+5;

int tasks[mx][3];

int diario[3][mx];

int cosa(int a, int i){

	if(i == m){

     return 0;

     }



	if(diario[a][i] != -1) {

        return diario[a][i];

    }

	int& ans = diario[a][i];



        if(a==0){

		ans=max(ans, cosa(1, i+1)+tasks[i][0]);

		ans=max(ans, cosa(2, i+1)+tasks[i][0]);

	}

        if(a==1){

		ans=max(ans, cosa(0, i+1)+tasks[i][1]);

		ans=max(ans, cosa(2, i+1)+tasks[i][1]);

        }

	if(a==2){

		ans=max(ans, cosa(0, i+1)+tasks[i][2]);

		ans=max(ans, cosa(1, i+1)+tasks[i][2]);

	}



	return ans;

}

int main(){

	cin>>m;

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

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

	}

	memset(diario, -1, sizeof diario);

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

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.1815048376623114x):
																//  SMOKE SHISHA PLAY FIFA  // 

#include<bits/stdc++.h>

using namespace std;



typedef long long int ll;

typedef long double ld;



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

#define pll pair<ll,ll>

#define MP make_pair

#define ff first

#define ss second

#define PB push_back

#define mod 1000000007

#define lp(i,start,end) for(ll i=start;i<=end;i++) 

#define deb1(a) cout<<#a<<" = "<<(a)<<endl;

#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;

#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;





ll modu(ll a, ll b)

{

	ll ans =1;

	while(b>0)

	{

		if(b&1)

		ans = (ans*a)%mod;

		b/=2;

		a = (a*a)%mod;

	}

	return ans;

}



int main()

{

	fastio

	ll t=1;

	//cin >> t;

	while(t--)

	{

		ll n;

		cin>>n;

		ll a[n+1],b[n+1],c[n+1],dp[3][n];

		lp(i,1,n)

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

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

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

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

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

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

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

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

    }

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

	}

	return 0;	

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;



int nn;

const int nxx = 1e5+5;

int acc[nxx][3];

int dpp[3][nxx];

int go(int aa, int ii)

{

	if(ii==nn) return 0;

	if(dpp[aa][ii] != -1) return dpp[aa][ii];

	int& ans = dpp[aa][ii];

	if(aa==0)

	{

		ans=max(ans, go(1, ii+1)+acc[ii][0]);

		ans=max(ans, go(2, ii+1)+acc[ii][0]);

	}

	if(aa==1)

	{

		ans=max(ans, go(0, ii+1)+acc[ii][1]);

		ans=max(ans, go(2, ii+1)+acc[ii][1]);

	}

	if(aa==2)

	{

		ans=max(ans, go(0, ii+1)+acc[ii][2]);

		ans=max(ans, go(1, ii+1)+acc[ii][2]);

	}



	return ans;



}

int main()

{

    cin>>nn;

    for(int ii=0; ii<nn; ii++) cin>>acc[ii][0]>>acc[ii][1]>>acc[ii][2];

    memset(dpp, -1, sizeof dpp);

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.181502646869374x):
																//  SMOKE SHISHA PLAY FIFA  // 

#include<bits/stdc++.h>

using namespace std;



typedef long long int ll;

typedef long double ld;



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

#define pll pair<ll,ll>

#define MP make_pair

#define ff first

#define ss second

#define PB push_back

#define mod 1000000007

#define lp(i,start,end) for(ll i=start;i<=end;i++) 

#define deb1(a) cout<<#a<<" = "<<(a)<<endl;

#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;

#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;





ll modu(ll a, ll b)

{

	ll ans =1;

	while(b>0)

	{

		if(b&1)

		ans = (ans*a)%mod;

		b/=2;

		a = (a*a)%mod;

	}

	return ans;

}



int main()

{

	fastio

	ll t=1;

	//cin >> t;

	while(t--)

	{

		ll n;

		cin>>n;

		ll a[n+1],b[n+1],c[n+1],dp[3][n];

		lp(i,1,n)

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

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

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

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

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

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

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

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

    }

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

	}

	return 0;	

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;



int n;

const int nx = 1e5+5;

int ac[nx][3];

int dp[3][nx];

int go(int a, int i)

{

	if(i==n) return 0;

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

	int& ans = dp[a][i];

	if(a==0)

	{

		ans=max(ans, go(1, i+1)+ac[i][0]);

		ans=max(ans, go(2, i+1)+ac[i][0]);

	}

	if(a==1)

	{

		ans=max(ans, go(0, i+1)+ac[i][1]);

		ans=max(ans, go(2, i+1)+ac[i][1]);

	}

	if(a==2)

	{

		ans=max(ans, go(0, i+1)+ac[i][2]);

		ans=max(ans, go(1, i+1)+ac[i][2]);

	}

	

	return ans;

	

}

int main()

{

    cin>>n;

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

    memset(dp, -1, sizeof dp);

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

    return 0;

}

	

// Faster C++ solution for the same problem (measured speedup: 2.1814788400709015x):
																//  SMOKE SHISHA PLAY FIFA  // 

#include<bits/stdc++.h>

using namespace std;



typedef long long int ll;

typedef long double ld;



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

#define pll pair<ll,ll>

#define MP make_pair

#define ff first

#define ss second

#define PB push_back

#define mod 1000000007

#define lp(i,start,end) for(ll i=start;i<=end;i++) 

#define deb1(a) cout<<#a<<" = "<<(a)<<endl;

#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;

#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;





ll modu(ll a, ll b)

{

	ll ans =1;

	while(b>0)

	{

		if(b&1)

		ans = (ans*a)%mod;

		b/=2;

		a = (a*a)%mod;

	}

	return ans;

}



int main()

{

	fastio

	ll t=1;

	//cin >> t;

	while(t--)

	{

		ll n;

		cin>>n;

		ll a[n+1],b[n+1],c[n+1],dp[3][n];

		lp(i,1,n)

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

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

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

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

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

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

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

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

    }

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

	}

	return 0;	

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

using namespace std;

int v[100009][3];

int dp[100009][3];

int n;

int vacation(int i, int j)

{

    if(i==n-1)

        return dp[i][j]=v[i][j];

    if(i>=n || j>=3)

        return 0;

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

        return dp[i][j];

    int temp = INT_MIN;

        if(j==0)

        {

             temp = max(vacation(i+1,j+1)+v[i][j],temp);

        temp = max(vacation(i+1,j+2)+v[i][j],temp);

 return dp[i][j]= temp;

        }

      else  if(j==1)

        {

             temp = max(vacation(i+1,0)+v[i][j],temp);

        temp = max(vacation(i+1,2)+v[i][j],temp);

 return dp[i][j]= temp;

        }

        else

        {

             temp = max(vacation(i+1,1)+v[i][j],temp);

        temp = max(vacation(i+1,0)+v[i][j],temp);

         return dp[i][j]= temp;

        }

}



int main()

{

    cin>>n;

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

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

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

    cout<<max(vacation(0,0),max(vacation(0,1),vacation(0,2)))<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 2.18159935278029x):
																//  SMOKE SHISHA PLAY FIFA  // 

#include<bits/stdc++.h>

using namespace std;



typedef long long int ll;

typedef long double ld;



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

#define pll pair<ll,ll>

#define MP make_pair

#define ff first

#define ss second

#define PB push_back

#define mod 1000000007

#define lp(i,start,end) for(ll i=start;i<=end;i++) 

#define deb1(a) cout<<#a<<" = "<<(a)<<endl;

#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;

#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;





ll modu(ll a, ll b)

{

	ll ans =1;

	while(b>0)

	{

		if(b&1)

		ans = (ans*a)%mod;

		b/=2;

		a = (a*a)%mod;

	}

	return ans;

}



int main()

{

	fastio

	ll t=1;

	//cin >> t;

	while(t--)

	{

		ll n;

		cin>>n;

		ll a[n+1],b[n+1],c[n+1],dp[3][n];

		lp(i,1,n)

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

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

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

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

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

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

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

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

    }

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

	}

	return 0;	

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



using namespace std;

typedef long long ll;

typedef double dd;

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

#define endl "\n"

#define clr(n, r) memset(n,r,sizeof(n));



void fast() {

    cin.tie(0);

    cin.sync_with_stdio(0);

}

const int MAX=1e5+10;

int n,a[MAX],b[MAX],c[MAX],dp[MAX][3];

int ans(int i,int prev){

    if(i==n)return 0;

    int path1=0,path2=0,path3=0;

    int &ret=dp[i][prev];

    if(prev!=-1&&ret!=-1)return ret;

    if(prev!=0){

        path1=a[i]+ans(i+1,0);

    }

    if(prev!=1){

        path2=b[i]+ans(i+1,1);

    }

    if(prev!=2){

        path3=c[i]+ans(i+1,2);

    }

    return ret=max(path1,max(path2,path3));

}



int main() {

    fast();

    cin>>n;

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

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

    }

    clr(dp,-1);

    cout<<ans(0,-1);

}


// Faster C++ solution for the same problem (measured speedup: 2.1917886816243257x):
																//  SMOKE SHISHA PLAY FIFA  // 

#include<bits/stdc++.h>

using namespace std;



typedef long long int ll;

typedef long double ld;



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

#define pll pair<ll,ll>

#define MP make_pair

#define ff first

#define ss second

#define PB push_back

#define mod 1000000007

#define lp(i,start,end) for(ll i=start;i<=end;i++) 

#define deb1(a) cout<<#a<<" = "<<(a)<<endl;

#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;

#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;





ll modu(ll a, ll b)

{

	ll ans =1;

	while(b>0)

	{

		if(b&1)

		ans = (ans*a)%mod;

		b/=2;

		a = (a*a)%mod;

	}

	return ans;

}



int main()

{

	fastio

	ll t=1;

	//cin >> t;

	while(t--)

	{

		ll n;

		cin>>n;

		ll a[n+1],b[n+1],c[n+1],dp[3][n];

		lp(i,1,n)

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

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

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

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

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

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

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

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

    }

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

	}

	return 0;	

}
// Slower C++ solution:
/*

** author:mahmoud magdy

*/

#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define endl "\n"



inline int D()

{

    int m ;

    cin>>m;

    return m ;

}

inline ll lD()

{

    ll m ;

    cin>>m;

    return m ;

}

inline double dD()

{

    double m;

    cin>>m;

    return m;

}

void fast()

{

    ios_base :: sync_with_stdio( 0 ) ;

    cin.tie( 0 ) ;

    cout.tie( 0 ) ;

}

int n;

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

ll dp[100005][5];

ll solve(int i,int prv){

 if(i==n)return 0;

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

 ll x=0;

 if(prv!=1){

 x=a[i]+solve(i+1,1);

 }

 ll y=0;

 if(prv!=2)

 y=b[i]+solve(i+1,2);

 ll z=0;

 if(prv!=3)

 z=c[i]+solve(i+1,3);

 return dp[i][prv]=max({x,y,z});

}

int main()

{

    memset(dp,-1,sizeof dp);

    fast();

    n=D();

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

        a[i]=D();b[i]=D();c[i]=D();

    }

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

}

// Faster C++ solution for the same problem (measured speedup: 5.04164574875471x):
																//  SMOKE SHISHA PLAY FIFA  // 

#include<bits/stdc++.h>

using namespace std;



typedef long long int ll;

typedef long double ld;



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

#define pll pair<ll,ll>

#define MP make_pair

#define ff first

#define ss second

#define PB push_back

#define mod 1000000007

#define lp(i,start,end) for(ll i=start;i<=end;i++) 

#define deb1(a) cout<<#a<<" = "<<(a)<<endl;

#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;

#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;





ll modu(ll a, ll b)

{

	ll ans =1;

	while(b>0)

	{

		if(b&1)

		ans = (ans*a)%mod;

		b/=2;

		a = (a*a)%mod;

	}

	return ans;

}



int main()

{

	fastio

	ll t=1;

	//cin >> t;

	while(t--)

	{

		ll n;

		cin>>n;

		ll a[n+1],b[n+1],c[n+1],dp[3][n];

		lp(i,1,n)

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

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

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

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

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

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

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

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

    }

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

	}

	return 0;	

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

#include <queue>

#include <string>

#include <map>

#include <stdio.h>

#include <iomanip>

#include <math.h>

#include <vector>

#include <stack>

#include <algorithm>

#include <string.h>

#include <set>

#include <cstdlib>

#include <iostream>

#include <bits/stdc++.h>

#define pii pair<int,int> 

#define ll long long int 

#define sl(n) scanf("%lld",&n)

#define s(n) scanf("%d",&n)

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

#define fo(i,n) for(int i=1;i<=n;++i)

#define fnm(n,m) for(ll i=n;i<m+1;++i)

#define pb push_back

#define pf printf

#define F first

#define S second

#define srt(v) sort(v.begin(),v.end());

#define srtc(v,cmp) sort(v.begin(),v.end(),cmp);

#define srta(v,n) sort(v,v+n);

const ll LL_INF=0x3f3f3f3f3f3f;

const ll MOD=1073741824;





using namespace std;





int T;

int d,arr[100005][5];

int dp[100005][5];



int gen(int i,int prev){ // swim:0, bugs:1, homework:2

    if(i == d)return 0;

    int &ret = dp[i][prev];

    if(~ret)return ret;

    ret = gen(i+1,(prev+1)%3)+arr[i][(prev+1)%3];

    ret = max( ret , gen(i+1,(prev+2)%3)+arr[i][(prev+2)%3]);

    if(!i)ret = max( ret , gen(i+1,(prev)%3)+arr[i][(prev)%3]);

    return ret;

}



int main(){

    // pf("\t\t\t***************************************************************************\n\n");

    // pf("\t\t\t***************************************************************************\n\n");

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

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

    memset(dp,-1,sizeof dp);

    s(d);

    f(i,d){

        s(arr[i][0]);

        s(arr[i][1]);

        s(arr[i][2]);

    }

    pf("%d\n",gen(0,0));



    return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 2.9531835406626925x):
																//  SMOKE SHISHA PLAY FIFA  // 

#include<bits/stdc++.h>

using namespace std;



typedef long long int ll;

typedef long double ld;



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

#define pll pair<ll,ll>

#define MP make_pair

#define ff first

#define ss second

#define PB push_back

#define mod 1000000007

#define lp(i,start,end) for(ll i=start;i<=end;i++) 

#define deb1(a) cout<<#a<<" = "<<(a)<<endl;

#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;

#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;





ll modu(ll a, ll b)

{

	ll ans =1;

	while(b>0)

	{

		if(b&1)

		ans = (ans*a)%mod;

		b/=2;

		a = (a*a)%mod;

	}

	return ans;

}



int main()

{

	fastio

	ll t=1;

	//cin >> t;

	while(t--)

	{

		ll n;

		cin>>n;

		ll a[n+1],b[n+1],c[n+1],dp[3][n];

		lp(i,1,n)

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

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

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

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

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

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

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

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

    }

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

	}

	return 0;	

}
// Slower C++ solution:


#include <bits/stdc++.h>

using namespace  std;



int N;

const int SIZE = 100005;

int mem [SIZE][4];

int arr [SIZE][3];





int dp (int i, int activ) {

  

  if (i == N) return 0;

  



 if (mem[i][activ] != -1) return mem[i][activ];  

  

  int ret = -1; 



  if (activ != 0) {

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

  }



  if (activ != 1) {

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

    

  }



  if (activ != 2) {

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

    

  }



  return  mem[i][activ] = ret;

}



int main (){ 



  cin  >> N ;

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

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

  }



  memset(mem, -1, sizeof mem);

  





  cout << dp(0,3);



}

// Faster C++ solution for the same problem (measured speedup: 2.5717491494069082x):
																//  SMOKE SHISHA PLAY FIFA  // 

#include<bits/stdc++.h>

using namespace std;



typedef long long int ll;

typedef long double ld;



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

#define pll pair<ll,ll>

#define MP make_pair

#define ff first

#define ss second

#define PB push_back

#define mod 1000000007

#define lp(i,start,end) for(ll i=start;i<=end;i++) 

#define deb1(a) cout<<#a<<" = "<<(a)<<endl;

#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;

#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;





ll modu(ll a, ll b)

{

	ll ans =1;

	while(b>0)

	{

		if(b&1)

		ans = (ans*a)%mod;

		b/=2;

		a = (a*a)%mod;

	}

	return ans;

}



int main()

{

	fastio

	ll t=1;

	//cin >> t;

	while(t--)

	{

		ll n;

		cin>>n;

		ll a[n+1],b[n+1],c[n+1],dp[3][n];

		lp(i,1,n)

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

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

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

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

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

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

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

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

    }

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

	}

	return 0;	

}