stablegradients/pie-gem5-pairs huggingface dataset:
// 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.121600541213189x):
#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;



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.263285559827857x):
#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>

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.199635596843309x):
#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 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.125651268251946x):
#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 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.250467499096941x):
#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<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.126377112870422x):
#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 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.403655448284349x):
#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;

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.188207210382435x):
#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 <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.529058312618911x):
#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;

}