stablegradients/pie-gem5-pairs huggingface dataset:
// 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: 11.46250674875082x):
#include<stdio.h>

#include<stdlib.h>



#define get(a, i, j) *((*(a+i))+j)





typedef long long ll;



//long long **mem, **util, N;

ll mem[100001][3], util[100001][3], N;



ll dp(ll d, ll u);



int main()

{

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



    ll i, max, temp_util;



    //util = (ll**) malloc(N * sizeof(ll*));

    //mem = (ll**) malloc(N * sizeof(ll*));



    scanf("%lld", &N);



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

        //*(util+i) = (ll*) malloc(3 * sizeof(ll));

        //*(mem+i) = (ll*) calloc(3, sizeof(ll));



        scanf("%lld%lld%lld", &get(util, i, 0), &get(util, i, 1), &get(util, i, 2));

    }





    //printf("%lld\n", dp(0, 0));

    max = 0;

    temp_util = 0;



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

        //printf("calling dp(const 0, %lld)\n", i);

        temp_util = dp(0, i);

        if (max < temp_util) max = temp_util;

    }



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



    return 0;

}





ll dp(ll d, ll u)

{

    //printf("inside dp with d = %lld, u = %lld\n", d, u);

    if (d == N-1) {

        //printf("returning %lld without setting\n\n", get(util, d, u));

        return get(util, d, u);

    }



    if(get(mem, d, u) > 0) {

        //printf("returning %lld without setting\n\n", get(util, d, u));

        return get(mem, d, u);

    }



    ll i, max, temp_util;



    max = 0;

    temp_util = 0;

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

        if(i!=u) temp_util = dp(d+1, i);

        if(temp_util>max) max = temp_util;

    }



    //printf("setting value in mem[%lld][%lld] = %lld (%lld)\n\n", d, u, get(util, d, u)+max, get(util, d, u));

    return get(mem, d, u) = get(util, d, u) + max;

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

using namespace std;

#define endl '\n'



const int N = 1e5;



int dp[N+5][4];

int arr[N+5][4];



int main(){



	ios_base::sync_with_stdio(0);

	int n; cin >>n;

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

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

	}



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

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

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

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

	}	



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

	return 0;

}

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

#include<stdlib.h>



#define get(a, i, j) *((*(a+i))+j)





typedef long long ll;



//long long **mem, **util, N;

ll mem[100001][3], util[100001][3], N;



ll dp(ll d, ll u);



int main()

{

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



    ll i, max, temp_util;



    //util = (ll**) malloc(N * sizeof(ll*));

    //mem = (ll**) malloc(N * sizeof(ll*));



    scanf("%lld", &N);



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

        //*(util+i) = (ll*) malloc(3 * sizeof(ll));

        //*(mem+i) = (ll*) calloc(3, sizeof(ll));



        scanf("%lld%lld%lld", &get(util, i, 0), &get(util, i, 1), &get(util, i, 2));

    }





    //printf("%lld\n", dp(0, 0));

    max = 0;

    temp_util = 0;



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

        //printf("calling dp(const 0, %lld)\n", i);

        temp_util = dp(0, i);

        if (max < temp_util) max = temp_util;

    }



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



    return 0;

}





ll dp(ll d, ll u)

{

    //printf("inside dp with d = %lld, u = %lld\n", d, u);

    if (d == N-1) {

        //printf("returning %lld without setting\n\n", get(util, d, u));

        return get(util, d, u);

    }



    if(get(mem, d, u) > 0) {

        //printf("returning %lld without setting\n\n", get(util, d, u));

        return get(mem, d, u);

    }



    ll i, max, temp_util;



    max = 0;

    temp_util = 0;

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

        if(i!=u) temp_util = dp(d+1, i);

        if(temp_util>max) max = temp_util;

    }



    //printf("setting value in mem[%lld][%lld] = %lld (%lld)\n\n", d, u, get(util, d, u)+max, get(util, d, u));

    return get(mem, d, u) = get(util, d, u) + max;

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



#define fi first

#define se second

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

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

#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)

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

#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)

#define pb push_back

#define el '\n'

#define d(x) cout<< #x<< " " << x<<el

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



using namespace std;



typedef long long ll;

typedef pair<int,int> ii;

typedef pair<char,int> pci;

typedef tuple<int, int, int> tiii;

typedef pair<ll,ll> pll;

typedef vector<int> vi;



const int MAXN = 1e5+200;



int dp[MAXN][3];



int main(){

    ios_base::sync_with_stdio(false);

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

    int n;

    cin>> n;



    int op[n][3];

    forn(i,n) cin>> op[i][0]>> op[i][1]>> op[i][2];

    forn(i,3) dp[0][i]= op[0][i];



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

        forn(j,3){

            dp[i][j]= max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + op[i][j];

        }

    }

    --n;

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

}




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

#include<stdlib.h>



#define get(a, i, j) *((*(a+i))+j)





typedef long long ll;



//long long **mem, **util, N;

ll mem[100001][3], util[100001][3], N;



ll dp(ll d, ll u);



int main()

{

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



    ll i, max, temp_util;



    //util = (ll**) malloc(N * sizeof(ll*));

    //mem = (ll**) malloc(N * sizeof(ll*));



    scanf("%lld", &N);



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

        //*(util+i) = (ll*) malloc(3 * sizeof(ll));

        //*(mem+i) = (ll*) calloc(3, sizeof(ll));



        scanf("%lld%lld%lld", &get(util, i, 0), &get(util, i, 1), &get(util, i, 2));

    }





    //printf("%lld\n", dp(0, 0));

    max = 0;

    temp_util = 0;



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

        //printf("calling dp(const 0, %lld)\n", i);

        temp_util = dp(0, i);

        if (max < temp_util) max = temp_util;

    }



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



    return 0;

}





ll dp(ll d, ll u)

{

    //printf("inside dp with d = %lld, u = %lld\n", d, u);

    if (d == N-1) {

        //printf("returning %lld without setting\n\n", get(util, d, u));

        return get(util, d, u);

    }



    if(get(mem, d, u) > 0) {

        //printf("returning %lld without setting\n\n", get(util, d, u));

        return get(mem, d, u);

    }



    ll i, max, temp_util;



    max = 0;

    temp_util = 0;

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

        if(i!=u) temp_util = dp(d+1, i);

        if(temp_util>max) max = temp_util;

    }



    //printf("setting value in mem[%lld][%lld] = %lld (%lld)\n\n", d, u, get(util, d, u)+max, get(util, d, u));

    return get(mem, d, u) = get(util, d, u) + max;

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

using namespace std;

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

#include<stdlib.h>



#define get(a, i, j) *((*(a+i))+j)





typedef long long ll;



//long long **mem, **util, N;

ll mem[100001][3], util[100001][3], N;



ll dp(ll d, ll u);



int main()

{

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



    ll i, max, temp_util;



    //util = (ll**) malloc(N * sizeof(ll*));

    //mem = (ll**) malloc(N * sizeof(ll*));



    scanf("%lld", &N);



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

        //*(util+i) = (ll*) malloc(3 * sizeof(ll));

        //*(mem+i) = (ll*) calloc(3, sizeof(ll));



        scanf("%lld%lld%lld", &get(util, i, 0), &get(util, i, 1), &get(util, i, 2));

    }





    //printf("%lld\n", dp(0, 0));

    max = 0;

    temp_util = 0;



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

        //printf("calling dp(const 0, %lld)\n", i);

        temp_util = dp(0, i);

        if (max < temp_util) max = temp_util;

    }



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



    return 0;

}





ll dp(ll d, ll u)

{

    //printf("inside dp with d = %lld, u = %lld\n", d, u);

    if (d == N-1) {

        //printf("returning %lld without setting\n\n", get(util, d, u));

        return get(util, d, u);

    }



    if(get(mem, d, u) > 0) {

        //printf("returning %lld without setting\n\n", get(util, d, u));

        return get(mem, d, u);

    }



    ll i, max, temp_util;



    max = 0;

    temp_util = 0;

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

        if(i!=u) temp_util = dp(d+1, i);

        if(temp_util>max) max = temp_util;

    }



    //printf("setting value in mem[%lld][%lld] = %lld (%lld)\n\n", d, u, get(util, d, u)+max, get(util, d, u));

    return get(mem, d, u) = get(util, d, u) + max;

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

#include<cmath>

using namespace std;



int dp[100000][3]; 

//dp[i][j]表示第i天玩第j项活动，从第一天到第i天累计获得第最大第快乐值

int a[100000][3];

//a[i][3]保存第i天，三项每项获得第快乐值



int main(){

    int n,lage;

    cin>>n;

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

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

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

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

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

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

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

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

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

    }

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

    lage=max(lage,dp[n-1][2]);

    cout<<lage<<endl;

    return 0;

}

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

#include<stdlib.h>



#define get(a, i, j) *((*(a+i))+j)





typedef long long ll;



//long long **mem, **util, N;

ll mem[100001][3], util[100001][3], N;



ll dp(ll d, ll u);



int main()

{

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



    ll i, max, temp_util;



    //util = (ll**) malloc(N * sizeof(ll*));

    //mem = (ll**) malloc(N * sizeof(ll*));



    scanf("%lld", &N);



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

        //*(util+i) = (ll*) malloc(3 * sizeof(ll));

        //*(mem+i) = (ll*) calloc(3, sizeof(ll));



        scanf("%lld%lld%lld", &get(util, i, 0), &get(util, i, 1), &get(util, i, 2));

    }





    //printf("%lld\n", dp(0, 0));

    max = 0;

    temp_util = 0;



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

        //printf("calling dp(const 0, %lld)\n", i);

        temp_util = dp(0, i);

        if (max < temp_util) max = temp_util;

    }



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



    return 0;

}





ll dp(ll d, ll u)

{

    //printf("inside dp with d = %lld, u = %lld\n", d, u);

    if (d == N-1) {

        //printf("returning %lld without setting\n\n", get(util, d, u));

        return get(util, d, u);

    }



    if(get(mem, d, u) > 0) {

        //printf("returning %lld without setting\n\n", get(util, d, u));

        return get(mem, d, u);

    }



    ll i, max, temp_util;



    max = 0;

    temp_util = 0;

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

        if(i!=u) temp_util = dp(d+1, i);

        if(temp_util>max) max = temp_util;

    }



    //printf("setting value in mem[%lld][%lld] = %lld (%lld)\n\n", d, u, get(util, d, u)+max, get(util, d, u));

    return get(mem, d, u) = get(util, d, u) + max;

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

#include<algorithm>



using namespace std;



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

int f[110000][3];

int main()

{

    int n;



    cin>>n;



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

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

    f[1][0] = max(b[1],c[1]);

    f[1][1] = max(a[1],c[1]);

    f[1][2] = max(a[1],b[1]);

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

    {

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

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

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

    }

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

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

    cout<<ans;

}   

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

{

	int n;

	cin >> n;



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



	for(auto &cur : h)

		cin >> cur[0] >> cur[1] >> cur[2];



	dp[0] = h[0];



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

	{

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

		{

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

			{

				if(k == j)

					continue;



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

			}

		}

	}



	cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.273070685623848x):
#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 dp[100005][5],a[100005][5];

int main()

{

    int i,j,n;

    cin>>n;

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

    {

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

        {

            cin>>a[i][j];

        }

    }

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

    {

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

        {

            if(i==0)

            {

                dp[i][j]=a[i][j];

            }

            else if(j==0)

            {

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

            }

            else if(j==1)

            {

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

            }

            else if(j==2)

            {

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

            }

        }

    }

    n--;

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

    return 0;

}




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

using namespace std;

ll n,a[100009],b[100009],c[100009],dp[100009][5];

int main (){

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n;

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

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

	}

	for (int i=n; i>=1; i--){

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

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

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

	}

	ll jwb=0;

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

		jwb=max(jwb,dp[1][i]);

	}

	cout << jwb << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.268426799314544x):
#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 ar[100010][5],n;

int dp[100010][5];



int call(int i,int f)

{



    if(i==n)

        return 0;



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

        return dp[i][f];



    int ans=0;



    if(f==0)

        ans+=max(ar[i][1]+call(i+1,1),ar[i][2]+call(i+1,2));



    else if(f==1)

        ans+=max(ar[i][0]+call(i+1,0),ar[i][2]+call(i+1,2));

    else

        ans+=max(ar[i][1]+call(i+1,1),ar[i][0]+call(i+1,0));



        dp[i][f]=ans;

        return ans;



}



int main()

{



    cin>>n;



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

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



    memset(dp,-1,sizeof dp);



    int ans=max(max(call(0,0),call(0,1)),call(0,2));



    cout<<ans<<endl;



}


// Faster C++ solution for the same problem (measured speedup: 15.64110630648925x):
#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 h[3][100005], a[100005], b[100005], c[100005];



int main(){



    int n; cin >> n;

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

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

    }



    h[0][1] = a[1];

    h[1][1] = b[1];

    h[2][1] = c[1];



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

        h[0][i] = max({h[0][i - 2] + a[i], h[1][i-1] + a[i], h[2][i-1] + a[i]});

        h[1][i] = max({h[1][i - 2] + b[i], h[0][i-1] + b[i], h[2][i-1] + b[i]});

        h[2][i] = max({h[2][i - 2] + c[i], h[0][i-1] + c[i], h[1][i-1] + c[i]});

    }



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

    return 0;

}




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

#include <string>

#include <cstdlib>

using namespace std;



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

#define WRITE               freopen("out.txt", "w", stdout)



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

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

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



#define CLR(a)              memset(a, 0, sizeof(a))

#define SET(a)              memset(a, -1, sizeof(a))



#define PI                  acos(-1.0)



#define pb                  push_back

#define mp                  make_pair

#define SORT(v)             sort(v.begin(), v.end())

#define REV(v)              reverse(v.begin(), v.end())

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

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

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

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

#define LOOP(i, x, y)       for(int i=x; i<=y; i++)

#define fastIO()            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);





typedef long long              LL;

typedef unsigned long long     ULL;

typedef vector<int>            VI;

typedef pair<int, int>         PII;

typedef pair<string, int>      PSI;

typedef pair<char, int>        PCI;



const int MAX = 100005;

const LL LMAX = 12158598925;

const double eps = 1e-9;

const int INF = 0x3f3f3f3f;



int dx[] = {-1, 0, 1, 0};

int dy[] = {0, 1, 0, -1};

int kx[] = {1, 1, 2, 2, -1, -1, -2, -2};

int ky[] = {2, -2, 1, -1, 2, -2, 1, -1};



int n, w;

int arr[MAX][3];

LL dp[MAX][3];







int main()

{

//    READ;

//    WRITE;

    si(n);



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

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

            si(arr[i][j]);

    }



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



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

//        cout << "FOR: " << i << ":\n";

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

            LL mx = INT_MIN;

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

                if(q == j) continue;



                mx = max(mx, dp[i-1][q]);

            }



            dp[i][j] = arr[i][j] + mx;

//              cout << " max: " << mx << " arr: " << arr[i][j] << " dp: " << dp[i][j] << endl;

        }

//        cout << endl;

    }



//    cout << endl;

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

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

//            cout << dp[i][j] << " ";

//        }

//        cout << endl;

//    }



    LL ans = INT_MIN;

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



    cout << ans << endl;

    return 0;

}


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

}