stablegradients/pie-gem5-pairs huggingface dataset:
// 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.189247521666298x):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

struct actv{

ll f,s,t;

};

int main(){

    ll n;

    cin>>n;

    vector < actv > v,dp;

    v.resize(n);

    dp.resize(n);

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

        cin>>v[i].f>>v[i].s>>v[i].t;

        dp[i].f=dp[i].s=dp[i].t=0;

    }

    dp[0].f=v[0].f;

    dp[0].t=v[0].t;

    dp[0].s=v[0].s;

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

        dp[i].f=v[i].f+max(dp[i-1].s,dp[i-1].t);

        dp[i].s=v[i].s+max(dp[i-1].f,dp[i-1].t);

        dp[i].t=v[i].t+max(dp[i-1].s,dp[i-1].f);

    }

    cout<<max(max(dp[n-1].f,dp[n-1].s),dp[n-1].t);

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.1892453230977105x):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

struct actv{

ll f,s,t;

};

int main(){

    ll n;

    cin>>n;

    vector < actv > v,dp;

    v.resize(n);

    dp.resize(n);

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

        cin>>v[i].f>>v[i].s>>v[i].t;

        dp[i].f=dp[i].s=dp[i].t=0;

    }

    dp[0].f=v[0].f;

    dp[0].t=v[0].t;

    dp[0].s=v[0].s;

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

        dp[i].f=v[i].f+max(dp[i-1].s,dp[i-1].t);

        dp[i].s=v[i].s+max(dp[i-1].f,dp[i-1].t);

        dp[i].t=v[i].t+max(dp[i-1].s,dp[i-1].f);

    }

    cout<<max(max(dp[n-1].f,dp[n-1].s),dp[n-1].t);

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.1892214318031993x):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

struct actv{

ll f,s,t;

};

int main(){

    ll n;

    cin>>n;

    vector < actv > v,dp;

    v.resize(n);

    dp.resize(n);

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

        cin>>v[i].f>>v[i].s>>v[i].t;

        dp[i].f=dp[i].s=dp[i].t=0;

    }

    dp[0].f=v[0].f;

    dp[0].t=v[0].t;

    dp[0].s=v[0].s;

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

        dp[i].f=v[i].f+max(dp[i-1].s,dp[i-1].t);

        dp[i].s=v[i].s+max(dp[i-1].f,dp[i-1].t);

        dp[i].t=v[i].t+max(dp[i-1].s,dp[i-1].f);

    }

    cout<<max(max(dp[n-1].f,dp[n-1].s),dp[n-1].t);

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.189342372241104x):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

struct actv{

ll f,s,t;

};

int main(){

    ll n;

    cin>>n;

    vector < actv > v,dp;

    v.resize(n);

    dp.resize(n);

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

        cin>>v[i].f>>v[i].s>>v[i].t;

        dp[i].f=dp[i].s=dp[i].t=0;

    }

    dp[0].f=v[0].f;

    dp[0].t=v[0].t;

    dp[0].s=v[0].s;

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

        dp[i].f=v[i].f+max(dp[i-1].s,dp[i-1].t);

        dp[i].s=v[i].s+max(dp[i-1].f,dp[i-1].t);

        dp[i].t=v[i].t+max(dp[i-1].s,dp[i-1].f);

    }

    cout<<max(max(dp[n-1].f,dp[n-1].s),dp[n-1].t);

return 0;

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

#include <algorithm>

#include <cstring>

const int maxn = 3e5 + 5;

using namespace std;



int N;

int a[maxn][4];

int dp[maxn][4];

int main()

{

	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] + a[i][1], dp[i - 1][3] + a[i][1]);

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

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

	}

	int ans = 0;

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

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

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

	return 0;	

}

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

using namespace std;

typedef long long ll;



ll arr[100005][3];

ll dp[100005][3];





int main(){

    ll n;

    cin>>n;

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

        cin>>arr[i][0];

        cin>>arr[i][1];

        cin>>arr[i][2];

    }

    dp[0][0]=arr[0][0];

    dp[0][1]=arr[0][1];

    dp[0][2]=arr[0][2];

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

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

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

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

    }

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

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

using namespace std;

#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'

const int N = 1e5;

int A[N+7][5], mem[N+7][5];



int dp(int i, int j) {

	if(i==0) return 0;

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

	if(j==1) return mem[i][j] = A[i][j] + max(dp(i-1, 2), dp(i-1, 3));

	if(j==2) return mem[i][j] = A[i][j] + max(dp(i-1, 3), dp(i-1, 1));

	else return mem[i][j] = A[i][j] + max(dp(i-1, 1), dp(i-1, 2));

}

int main(){

	ios_base::sync_with_stdio(0);

	int a,b,n,T,cas=0;

	cin>>n;

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

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

	}

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

	int res = max(dp(n,1), max(dp(n,2), dp(n,3)));

	cout<<res<<endl;

	return 0;

}

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

using namespace std;

typedef long long ll;



ll arr[100005][3];

ll dp[100005][3];





int main(){

    ll n;

    cin>>n;

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

        cin>>arr[i][0];

        cin>>arr[i][1];

        cin>>arr[i][2];

    }

    dp[0][0]=arr[0][0];

    dp[0][1]=arr[0][1];

    dp[0][2]=arr[0][2];

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

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

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

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

    }

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

}
// 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.192874250711476x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll arr[100005][3];

ll dp[100005][3];





int main(){

    ll n;

    cin>>n;

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

        cin>>arr[i][0];

        cin>>arr[i][1];

        cin>>arr[i][2];

    }

    dp[0][0]=arr[0][0];

    dp[0][1]=arr[0][1];

    dp[0][2]=arr[0][2];

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

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

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

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

    }

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

}
// 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.2115230334455567x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll arr[100005][3];

ll dp[100005][3];





int main(){

    ll n;

    cin>>n;

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

        cin>>arr[i][0];

        cin>>arr[i][1];

        cin>>arr[i][2];

    }

    dp[0][0]=arr[0][0];

    dp[0][1]=arr[0][1];

    dp[0][2]=arr[0][2];

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

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

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

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

    }

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

}
// 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.2115493890861257x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll arr[100005][3];

ll dp[100005][3];





int main(){

    ll n;

    cin>>n;

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

        cin>>arr[i][0];

        cin>>arr[i][1];

        cin>>arr[i][2];

    }

    dp[0][0]=arr[0][0];

    dp[0][1]=arr[0][1];

    dp[0][2]=arr[0][2];

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

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

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

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

    }

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

}
// 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.2115471681207173x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll arr[100005][3];

ll dp[100005][3];





int main(){

    ll n;

    cin>>n;

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

        cin>>arr[i][0];

        cin>>arr[i][1];

        cin>>arr[i][2];

    }

    dp[0][0]=arr[0][0];

    dp[0][1]=arr[0][1];

    dp[0][2]=arr[0][2];

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

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

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

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

    }

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

}
// 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.2115230334455567x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll arr[100005][3];

ll dp[100005][3];





int main(){

    ll n;

    cin>>n;

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

        cin>>arr[i][0];

        cin>>arr[i][1];

        cin>>arr[i][2];

    }

    dp[0][0]=arr[0][0];

    dp[0][1]=arr[0][1];

    dp[0][2]=arr[0][2];

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

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

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

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

    }

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

}
// 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.2116452059038636x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



ll arr[100005][3];

ll dp[100005][3];





int main(){

    ll n;

    cin>>n;

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

        cin>>arr[i][0];

        cin>>arr[i][1];

        cin>>arr[i][2];

    }

    dp[0][0]=arr[0][0];

    dp[0][1]=arr[0][1];

    dp[0][2]=arr[0][2];

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

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

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

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

    }

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

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

#include <algorithm>

#include <cstring>

const int maxn = 3e5 + 5;

using namespace std;



int N;

int a[maxn][4];

int dp[maxn][4];

int main()

{

	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] + a[i][1], dp[i - 1][3] + a[i][1]);

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

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

	}

	int ans = 0;

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

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

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

	return 0;	

}

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



using namespace std;



#define ll long long

#define PI acos(-1.0)



int main()

{

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

	

	scanf("%lld", &t);

	for(int i = 1; i <= t; i++) scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);

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

	{

		a[i] = a[i] + max(b[i-1],c[i-1]);

		b[i] = b[i] + max(a[i-1],c[i-1]);

		c[i] = c[i] + max(a[i-1],b[i-1]);

	}

	printf("%lld\n",max(a[t],max(b[t],c[t])));

	return 0;

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

using namespace std;

#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'

const int N = 1e5;

int A[N+7][5], mem[N+7][5];



int dp(int i, int j) {

	if(i==0) return 0;

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

	if(j==1) return mem[i][j] = A[i][j] + max(dp(i-1, 2), dp(i-1, 3));

	if(j==2) return mem[i][j] = A[i][j] + max(dp(i-1, 3), dp(i-1, 1));

	else return mem[i][j] = A[i][j] + max(dp(i-1, 1), dp(i-1, 2));

}

int main(){

	ios_base::sync_with_stdio(0);

	int a,b,n,T,cas=0;

	cin>>n;

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

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

	}

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

	int res = max(dp(n,1), max(dp(n,2), dp(n,3)));

	cout<<res<<endl;

	return 0;

}

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



using namespace std;



#define ll long long

#define PI acos(-1.0)



int main()

{

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

	

	scanf("%lld", &t);

	for(int i = 1; i <= t; i++) scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);

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

	{

		a[i] = a[i] + max(b[i-1],c[i-1]);

		b[i] = b[i] + max(a[i-1],c[i-1]);

		c[i] = c[i] + max(a[i-1],b[i-1]);

	}

	printf("%lld\n",max(a[t],max(b[t],c[t])));

	return 0;

}
// 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.104480785864278x):
#include <bits/stdc++.h>



using namespace std;



#define ll long long

#define PI acos(-1.0)



int main()

{

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

	

	scanf("%lld", &t);

	for(int i = 1; i <= t; i++) scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);

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

	{

		a[i] = a[i] + max(b[i-1],c[i-1]);

		b[i] = b[i] + max(a[i-1],c[i-1]);

		c[i] = c[i] + max(a[i-1],b[i-1]);

	}

	printf("%lld\n",max(a[t],max(b[t],c[t])));

	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.122377847189567x):
#include <bits/stdc++.h>



using namespace std;



#define ll long long

#define PI acos(-1.0)



int main()

{

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

	

	scanf("%lld", &t);

	for(int i = 1; i <= t; i++) scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);

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

	{

		a[i] = a[i] + max(b[i-1],c[i-1]);

		b[i] = b[i] + max(a[i-1],c[i-1]);

		c[i] = c[i] + max(a[i-1],b[i-1]);

	}

	printf("%lld\n",max(a[t],max(b[t],c[t])));

	return 0;

}