stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:


#include<bits/stdc++.h>

using namespace std;



#define MAX 100000



int dp[MAX+5][4];

int val[MAX+5][4];

int n;



void initialize()

{

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

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

            dp[i][j] = -1;

}



int vacation(int i, int j)

{

    if(i<=0) return 0;



  /*  if(i==1)

    {

        return val[i][j];

    }

*/

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



    int mx = INT_MIN;



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

    {

        if(j==k) continue;



        mx = max(mx, vacation(i-1, k)+ val[i][j]);

    }





    dp[i][j] = mx;



    return mx;

}



int main()

{

    initialize();



    cin>>n;

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

    {

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

            cin>>val[i][j];

    }



    int retVal1 = vacation(n, 1);



    initialize();



    int retVal2 = vacation(n, 2);



    initialize();



    int retVal3 = vacation(n, 3);



    cout<<max({retVal1, retVal2, retVal3})<<endl;



    return 0;

}


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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

using namespace std;



#define fr(i,n) _back

#define pb	push_back

#define eb	emplace_back

#define mk	make_pair

#define fi	first

#define se	second

#define endl	'\n'



typedef long long ll;

typedef pair<int,int> ii;

typedef vector<ii> vii;

const int INF = 0x3f3f3f3f;

const double PI = acos(-1.0);

int dp[2][3];



int main() {

    ios_base::sync_with_stdio(false);

    int n; cin >> n;

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

        for(int j = 0; j  < 3; j++) cin >> dp[1][j];

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

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

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

        for(int j = 0; j < 3; j++) dp[0][j] = dp[1][j];

    }

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

    return 0;

}


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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

using namespace std;

int arr[100010][5];

int dp[100010][5];



int vac(int a, int b){

	if(a == 0) return 0;

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

	

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

		if(i != b){

			dp[a][b] = max(dp[a][b], vac(a - 1,i) + arr[a][i]);

		}

	}

	

	return dp[a][b];

}



int main (){

	memset(dp,-1,sizeof dp);

	int n;

	cin >> n;

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

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

	}

	

	

	int ans = 0;

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

		ans = max(ans , vac(n - 1, i) + arr[n][i]);

	}

	

	cout << ans << endl;

	

}

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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

using namespace std;

int n,a[100010][5],dp[100010][5];



int main()

{

	scanf("%d",&n);

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

	{

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

	}

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

	{

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

	}

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

	{

	//	printf("%d. ",i);

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

		{

			dp[i][j] = -1;

			for(int k=0;k<3;k++)

			{

			//	printf("%d %d : %d %d\n",i,j,dp[i-1][j]+a[i][k],a[i][k]);

				if(j!=k)

				{

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

				}

			}

			//printf("%d ",dp[i][j]);

		}

		//printf("\n");

	}

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

	return 0;

}

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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

#include<iostream>

#include<algorithm>

#include<queue>

#define inf 0x3f3f3f3f

using namespace std;

typedef long long LL;

const int maxn = 1e5+5;



int a[maxn],b[maxn],c[maxn],dp[maxn][3];



int main(){

	int n;

	scanf("%d",&n);

	int m;

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

	dp[1][0] = a[1]; dp[1][1] = b[1]; dp[1][2] = c[1];

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

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

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

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

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

		}

	}

	m = max(dp[n][0], dp[n][1]);

	m = max(m, dp[n][2]);

	printf("%d",m);

}

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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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



using namespace std;



int main() {

    vector<vector<int>> anpan;

    int n, k = -1;

    cin >> n;

    vector<int> zerad = {0};

        anpan.push_back(zerad);

        anpan.push_back(zerad);

        anpan.push_back(zerad);



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

        int a, b, c;

        cin >> a >> b >> c;

        anpan[0].push_back(max(anpan[1][i], anpan[2][i]) + a);

        anpan[1].push_back(max(anpan[0][i], anpan[2][i]) + b);

        anpan[2].push_back(max(anpan[0][i], anpan[1][i]) + c);

    }

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

}

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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

using namespace std;



int felicidade(int n){

    int a[n+1],b[n+1],c[n+1];

    

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

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

    }



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

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

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

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

    }



    if(a[n]>=b[n] and a[n]>=c[n]){

        return a[n];

    } else if(b[n]>=a[n] and b[n]>=c[n]){

        return b[n];

    }else if(c[n]>=a[n] and c[n]>=b[n]){

        return c[n];

    }

    

    return 0;

}



int main() {

    int n;



    cin >> n;



    cout << felicidade(n) << endl;

}

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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

#include <algorithm>

using namespace std;



int main(){

	int n;

	int result;

	int x = 0, y = 0, z = 0;

	

	scanf("%d", &n);

	

	int m[n+1][3];

	

	m[0][0] = m[0][1] = m[0][2] = 0;

	

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

		if(i > 0){

			scanf("%d", &x);

			scanf("%d", &y);

			scanf("%d", &z);

			

			//Caso não possa escolher a atividade a

			m[i][0] = max(m[i - 1][1], m[i - 1][2]) + x;

			//Caso não possa escolher a atividade b

			m[i][1] = max(m[i - 1][0], m[i - 1][2]) + y;

			//Caso não possa escolher a atividade c

			m[i][2] = max(m[i - 1][1], m[i - 1][0]) + z;

		}

	}

	

	result = max(max(m[n][0], m[n][1]), m[n][2]);

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

}

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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

#define ll long long

#define ull unsigned ll

#define ld long double

#define pll pair<ll, ll>

#define pii pair<int, int>

#define f first

#define se second

#define pb push_back

#define ft fflush(stdout)

 

 

using namespace std;

 

 

const int N = 2e5 + 123;

const int PLS = 3e5 + 123;

const int mod = 1e9 + 7;

const ll inf = 1e16;





ll n, a[N], c[N], b[N], dp[N][3];





int main() {

    ios_base::sync_with_stdio(NULL);

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

    cin >> n;

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

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

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

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

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

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

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

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

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

    }

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

}

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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

#include<iostream>

using namespace std;

const int MAXN = 100010;

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

int main()

{

	scanf("%d",&n);

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

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

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

	{

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

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

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

	}

	int ans = max(f[n][0], max(f[n][1], f[n][2]));

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

	return 0;

}

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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

using namespace std;

#define INF INT_MAX

#define N 100005

#define K 3

int n, k;

int arr[N][K];

int dp[N][K];

int solve(int idx, int last_k){

    int res;

    if(idx == n)

        return 0;

    if(~last_k && ~dp[idx][last_k])

        return dp[idx][last_k];

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

        if(last_k != i){

            dp[idx][last_k] = max(dp[idx][last_k], arr[idx][i]+solve(idx+1, i));

        }

    }

    return dp[idx][last_k];

}

int main()

{

    cin >> n;

    memset(dp, -1, sizeof(dp[0][0]) * N * K);

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

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

            cin >> arr[i][j];

    cout << solve(0, -1);

    return 0;

}




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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

typedef long long ll;

using namespace std;

const int N = 2e5+10 , M = 5e5+10, OO = 0x3f3f3f3f ,  MOD = 1e9+7;

const double EPS = 1e-3;

#define M_PI 3.14159265358979323846

#define clr(arr,val) memset(arr , val , sizeof (arr))

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

#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)

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

#define pb push_back

#define F first

#define S second

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

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

typedef pair <int,int> pii ;

typedef vector < pii > vii ;

typedef vector < int > vi;

int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction

//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

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

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







int n,x;

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

ll dp[N][4];





ll solve(int idx, int preC){ //preColour = (1 : a) -- (2 : b) -- (3 : c) -- (0 : invalid)



    if(idx == n) return 0;



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

    if(~ret) return ret;



    ret = -OO;

    if(preC != 1) ret = max(ret, solve(idx+1 , 1)+a[idx]);

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

    if(preC != 3) ret = max(ret, solve(idx+1 , 3)+c[idx]);



    return ret;



}







int main(){





    //ios_base::sync_with_stdio(0);

    //cin.tie(0);cout.tie(0);





    scanf("%d",&n);

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

        scanf("%d %d %d",a+i,b+i,c+i);



    memset(dp, -1 , sizeof dp);

    ll ans = solve(0 , 0);

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







    return 0;

}


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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

using namespace std;

int f[100010][4];

const int e=110000;

int a[e][4];

int main(){

	int n;

	cin>>n;

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

	{

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

	}

	f[1][1]=a[1][1];

	f[1][2]=a[1][2];

	f[1][3]=a[1][3];

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

	{

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

		{

			int t1,t2;

			if(j==1){t1=2;t2=3;}

			else if(j==2){t1=1;t2=3;}

			else{t1=1;t2=2;}

			f[i][j]=max(f[i-1][t1],f[i-1][t2])+a[i][j];

		}

	}

	int ans=-1;

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

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

	cout<<ans;

	return 0;

}






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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

#include <algorithm>

#include <cmath>

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <iomanip>

#include <string>

#include <set>

#include <vector>

#include <queue>

#include <stack>

#include <map>

using namespace std;

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

#define fore(i, a, n) for (long long i = a; i < n; i++)

#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)

#define si(a) scanf("%d", &a)

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

#define sii(a, b) scanf("%d%d", &a, &b)

#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)

#define sll(a, b) scanf("%lld%lld", &a, &b)

#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

#define debug(a) cout << a << endl

#define pr(a) printf("%d ",a)

#define endl '\n'

#define pi acos(-1.0)

#define tr t[root]

#define lson t[root << 1]

#define rson t[root << 1 | 1]

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

#define ull unsigned long long

const double eps = 1e-8;

inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }

typedef long long ll;

const int inf=0x3f3f3f3f;

const int MAXN = 1e5 + 10;

int n,a[MAXN],b[MAXN],c[MAXN];

ll dp[MAXN][3];

int main()

{

	si(n);

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

	{

		siii(a[i],b[i],c[i]);

	}

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

	{

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

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

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

	}

	ll ans=max(dp[n][0],max(dp[n][1],dp[n][2]));

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

 } 

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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

#include <cstring>

using namespace std;

const int maxn=1e5+5;

const int inf=0x3f3f3f3f;

int dp[maxn][4];

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

int main()

{

   int n;

   cin>>n;

   memset(dp,0,sizeof(dp));

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

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

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

   }

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

   return 0;

}


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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

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

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <vector>



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

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

#define pii pair<int,int>

#define pll pair<long long ,long long>

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

#define MS0(X) memset((X), 0, sizeof((X)))

#define MSC0(X) memset((X), '\0', sizeof((X)))

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define gg(x) getInt(&x)



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

#include<algorithm>

using namespace std;

int n, a, b, c;

int dp[3][2];//一维：3个项目的选择   二维：切换今天 和 昨天  今天i=0  昨天  1-i  i = i-1



int main(){

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

	scanf("%d", &n);

	int i = 0;

	while(n--){

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

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

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

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

		i = 1-i;

	}

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

	return 0;

}