stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<string>

#include<cstdio>

#include<algorithm>

#include<cstdlib>

#include<cmath>

#include<vector>

#include<utility>

#include<queue>

#include<stack>

#include<set>

#include<map>

#include<unordered_set>

#include<bitset>

using namespace std;

//#define MODE 1

#ifdef MODE

#define DEB(X) cout<< #X <<": "<<X<<" ";

#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";

#define END cout<<endl;

#else

#define DEB(X) {}

#define ARDEB(i,X) {}

#define END {}

#endif

typedef long long int ll;

#define int long long

typedef pair<int,int> P;

struct edge{int to,cost;};

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

const int INF=100000000000000000;



int N,A[100010],B[100010],C[100010];

int dp[100010][3];



int DP(int a,int k){

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

	int res=0,res2=0,res3=0;

	if(a==N){

		return 0;

	}

	DEB(k)END

	while(0);

	if(k==0){

		res2=DP(a+1,1)+B[a+1];

		res3=DP(a+1,2)+C[a+1];

	}

	else if(k==1){

		res=DP(a+1,0)+A[a+1];

		res3=DP(a+1,2)+C[a+1];

	}

	else if(k==2){

		res=DP(a+1,0)+A[a+1];

		res2=DP(a+1,1)+B[a+1];

	}

	return dp[a][k]=max({res,res2,res3});

}



signed main(){

	cin>>N;

	REP(i,N){

		cin>>A[i]>>B[i]>>C[i];

	}

	REP(i,100010)REP(j,3){

		dp[i][j]=-1;

	}

	cout<<max({DP(0,0)+A[0],DP(0,1)+B[0],DP(0,2)+C[0]})<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.399787251112544x):
#include<iostream>

#include<string>

#include<cstdio>

#include<algorithm>

#include<cstdlib>

#include<cmath>

#include<vector>

#include<utility>

#include<queue>

#include<stack>

#include<set>

#include<map>

#include<unordered_set>

#include<unordered_map>

#include<bitset>

#include<iomanip>

#include<list>

#include<deque>

using namespace std;

//#define MODE 1

#ifdef MODE

#define DEB(X) cout<< #X <<": "<<X<<" ";

#define END cout<<endl;

#else

#define DEB(X) {}

#define END {}

#endif

typedef long long ll;

#define int ll

#define uset unordered_set

#define umap unordered_map

typedef std::pair<int,int> P;

struct edge{int to,cost;};

const int INF=100000000000000000;

const int INF2=9223372036854775807;

const int MOD=1000000007;

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

#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))

#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))

#define MAX(X,Y) (*max_element(X,Y))

#define MIN(X,Y) (*min_element(X,Y))

#define NP(X,Y) next_permutation(X,Y)

#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;

int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}

int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}

int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}



int N;

int A[100010],B[100010],C[100010];

int dp[100010];

int dp2[100010];

int dp3[100010];



signed main(){

	cin>>N;

	REP(i,N){

		cin>>A[i]>>B[i]>>C[i];

	}

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

		dp[i]=max(dp2[i-1],dp3[i-1])+A[i];

		dp2[i]=max(dp[i-1],dp3[i-1])+B[i];

		dp3[i]=max(dp[i-1],dp2[i-1])+C[i];

	}

	cout<<max(dp[N-1],max(dp2[N-1],dp3[N-1]))<<endl;

	return 0;

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



#define F first

#define S second

#define PB push_back



using namespace std;



typedef long long ll;



int n;

ll a[100005][5];

ll memo[100005][5];



ll dp(int pos, int last){

	if(pos >= n) return 0;

	if(memo[pos][last] != -1)	return memo[pos][last];

	

	ll mmax = -1;

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

		if(i == last)	continue;

		mmax = max(mmax, a[pos][i] + dp(pos+1, i));

	}

	return memo[pos][last] = mmax;

}



int main(){

	

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);



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



	cin >> n;

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

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

			cin >> a[i][j];

		}

	}



	cout << dp(0, 4);



	return 0;

}

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



#define F first

#define S second

#define PB push_back



using namespace std;



typedef long long ll;



int main(){

	

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);



	int n;

	cin >> n;

	int a[n][3];

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

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

	}



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

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

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

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

	}



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



	return 0;

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



#define F first

#define S second

#define PB push_back



using namespace std;



typedef long long ll;



int n;

ll a[100005][5];

ll memo[100005][5];



ll dp(int pos, int last){

	if(pos >= n) return 0;

	if(memo[pos][last] != -1)	return memo[pos][last];

	

	ll mmax = -1;

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

		if(i == last)	continue;

		mmax = max(mmax, a[pos][i] + dp(pos+1, i));

	}

	return memo[pos][last] = mmax;

}



int main(){

	

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);



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



	cin >> n;

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

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

			cin >> a[i][j];

		}

	}



	cout << dp(0, 4);



	return 0;

}

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



#define F first

#define S second

#define PB push_back



using namespace std;



typedef long long ll;



int main(){

	

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);



	int n;

	cin >> n;

	int a[2][3];

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

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

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

		

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

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

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



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

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

		a[0][2] = a[1][2];

	}



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



	return 0;

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



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



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

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



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


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

using namespace std;

int main()

{

    int n, i, j, k;

    scanf("%d",&n);

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

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

    {

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

    }

    int dp[n+5][3];

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

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

    {

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

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

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

    }

    int ans = 0;

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

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

    cout << ans << "\n";

    return 0;

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



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



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

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



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


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

#include<stdio.h>

#include<vector>

#pragma GCC optimize(2)

typedef long long ll;

typedef unsigned long long ull;

const int mod=1000;

const int maxn=1e5+5;

const ll INF=100000000000005;

using namespace std;

ll n,m,p;

ll qpow(ll a,ll b){ll ans=1;while(b){if(b&1) ans=(ans*a)%mod;b/=2;a=(a*a)%mod;}return ans;}

struct node{

    ll a,b,c;

}save[maxn];

ll dp[maxn][4];

int main()

{

    scanf("%lld",&n);

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

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

    {

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

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

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

    }

    ll res=0;

    for(int i=1;i<=3;i++) res=max(dp[n][i],res);

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

    return 0;

}

/***

10 4

40 10 20 70 80 10 20 70 80 60

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



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



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

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



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


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



using namespace std;

int main(){

	long long n,ans=0;

	scanf("%lld", &n);

	long long a[n+5],b[n+5],c[n+5],check[n+5][4];

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

	scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);

	memset(check,0,sizeof(check));

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

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

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

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

	}

	ans=max(check[n][1], check[n][2]);

	ans=max(ans,check[n][3]);

	printf("%lld", ans);

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



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



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

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



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.5986425752155826x):
#include<set>

#include<map>

#include<cmath>

#include<ctime>

#include<queue>

#include<stack>

#include<cstdio>

#include<string>

#include<vector>

#include<random>

#include<cstdlib>

#include<cstring>

#include<iomanip>

#include<iostream>

#include<algorithm>

#include<unordered_map>

#define endl "\n"

#define fi first

#define se second

#define db double

#define gcd __gcd

#define pb push_back

#define mp make_pair

#define lowbit(x) (x & (-x))

#define PII  pair<int, int> 

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

#define debug(x) cout << #x << " = " << x << endl

#define rep(i, a, b) for(__typeof(b) i = a; i <= (b); i++)

#define Rep(i, a, b) for(__typeof(a) i = a; i >= (b); i--)

#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

template<class T> inline T qmin(T a, T b) { return a < b ? a : b; }

template<class T> inline T qmax(T a, T b) { return a > b ? a : b; }

typedef long long ll;

typedef unsigned long long ull;

const db eps = 1e-9;

const db PI = acos(-1);

const int inf = 0x3f3f3f3f;

const int mod = (int)1e9 + 7;

const int maxn = (int)1e5 + 5;//remember to modify it, No RE or MLE

const ll INF = 0x3f3f3f3f3f3f3f3f;

using namespace std;

ll qpow(ll x, ll y) { ll ret = 1; for( ; y; y >>= 1, x = (x * x) % mod) if(y & 1) ret = (ret * x) % mod; return ret; }



inline int read(){

	char ch = getchar();

	int x = 0, f = 1;

	while(ch < '0' || ch > '9'){

		if(ch == '-') f = -1;

		ch = getchar();

	}

	while('0' <= ch && ch <= '9'){

		x = x * 10 + ch - '0';

		ch = getchar();

	}

	return x * f;

}



int n;

int val[3][maxn];

int dp[maxn][3];



int main()

{

	n = read();

	rep(i, 1, n) rep(j, 0, 2) val[j][i] = read();

	rep(i, 1, n){

		rep(j, 0, 2){

			rep(k, 0, 2){

				if(k == j) continue;

				dp[i][j] = qmax(dp[i][j], dp[i-1][k] + val[j][i]);

			}

		}

	}

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

	return 0;

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



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



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

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



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


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

using namespace std;



#define MAX_N 100005

int N, h[MAX_N][3], memo[MAX_N][3];



int main() {

  scanf("%i", &N);

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

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

  	  scanf("%i", &h[d][c]);

	}

  }

  memset(memo, -1, sizeof memo);

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

  	memo[0][c] = h[0][c];

  }

  for (int d = 1; d < N; d++) {

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

  	  int &opt = memo[d][c];

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

  	    if (cc != c) {

  	      opt = max(opt, memo[d - 1][cc] + h[d][c]);

		  /*

  	      if (d == 1) {

  	        printf("%i %i %i %i\n", memo[d - 1][cc], h[d][c], cc, c);

		  }

		  */

		}

	  }

	}

  }

  /*

  puts("\ndebug");

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

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

  	  printf("%i ", memo[d][c]);

	}

	puts("");

  }

  puts("end-debug\n");

  */

  int ans = -1;

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

  	ans = max(ans, memo[N - 1][c]);

  }

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

  

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



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



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

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



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.5587524225048164x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

int main()

{

    int n,i,j,k;

    int a[100005][5];

    scanf("%d",&n);

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

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

    int dp[100005][5];

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

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

    dp[1][2] = a[1][2];

    dp[1][3] = a[1][3];

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

    {

        for(j = 1;j < 4;j++)

        {

            for(k = 1;k < 4;k++)

            {

                if(k != j)

                {

                    if(dp[i][j] < dp[i - 1][k] + a[i][j])

                    dp[i][j] = dp[i - 1][k] + a[i][j];

                }

            }

        }

    }

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

    return 0;

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



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



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

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



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.4906970697341917x):
#include<iostream>

#include<vector>

using namespace std;

int main(){

  int n;

  cin>>n;

  vector<vector<int>>task;

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

    task.push_back({0});

  

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

    int a;

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

      cin>>a;

      if(j==0)task[0].push_back(max(task[1][i],task[2][i])+a);

      if(j==1)task[1].push_back(max(task[0][i],task[2][i])+a);

      if(j==2)task[2].push_back(max(task[1][i],task[0][i])+a);

    }

  }

  cout<< max(task[0][task[0].size()-1],max(task[1][task[1].size()-1],task[2][task[2].size()-1]))<<endl;

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

using namespace std;



#define MAX_N 100005

int N, h[MAX_N][3], memo[MAX_N][3];



int main() {

  scanf("%i", &N);

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

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

  	  scanf("%i", &h[d][c]);

	}

  }

  memset(memo, -1, sizeof memo);

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

  	memo[0][c] = h[0][c];

  }

  for (int d = 1; d < N; d++) {

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

  	  int &opt = memo[d][c];

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

  	    if (cc != c) {

  	      opt = max(opt, memo[d - 1][cc] + h[d][c]);

		  /*

  	      if (d == 1) {

  	        printf("%i %i %i %i\n", memo[d - 1][cc], h[d][c], cc, c);

		  }

		  */

		}

	  }

	}

  }

  /*

  puts("\ndebug");

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

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

  	  printf("%i ", memo[d][c]);

	}

	puts("");

  }

  puts("end-debug\n");

  */

  int ans = -1;

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

  	ans = max(ans, memo[N - 1][c]);

  }

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

  

}

// Faster C++ solution for the same problem (measured speedup: 2.1600454521146504x):
#include<iostream>

#include<vector>

using namespace std;

int main(){

  int n;

  cin>>n;

  vector<vector<int>>task;

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

    task.push_back({0});

  

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

    int a;

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

      cin>>a;

      if(j==0)task[0].push_back(max(task[1][i],task[2][i])+a);

      if(j==1)task[1].push_back(max(task[0][i],task[2][i])+a);

      if(j==2)task[2].push_back(max(task[1][i],task[0][i])+a);

    }

  }

  cout<< max(task[0][task[0].size()-1],max(task[1][task[1].size()-1],task[2][task[2].size()-1]))<<endl;

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

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

int main()

{

    int n,i,j,k;

    int a[100005][5];

    scanf("%d",&n);

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

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

    int dp[100005][5];

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

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

    dp[1][2] = a[1][2];

    dp[1][3] = a[1][3];

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

    {

        for(j = 1;j < 4;j++)

        {

            for(k = 1;k < 4;k++)

            {

                if(k != j)

                {

                    if(dp[i][j] < dp[i - 1][k] + a[i][j])

                    dp[i][j] = dp[i - 1][k] + a[i][j];

                }

            }

        }

    }

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.239417254040166x):
#include<iostream>

#include<vector>

using namespace std;

int main(){

  int n;

  cin>>n;

  vector<vector<int>>task;

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

    task.push_back({0});

  

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

    int a;

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

      cin>>a;

      if(j==0)task[0].push_back(max(task[1][i],task[2][i])+a);

      if(j==1)task[1].push_back(max(task[0][i],task[2][i])+a);

      if(j==2)task[2].push_back(max(task[1][i],task[0][i])+a);

    }

  }

  cout<< max(task[0][task[0].size()-1],max(task[1][task[1].size()-1],task[2][task[2].size()-1]))<<endl;

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

#include <cmath>

#include <cstring>

using namespace std;

const int maxn=1e5+1;

int n;

int a[maxn][4];

int f[maxn][4];



int main(){

	cin>>n;

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

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

			cin>>a[i][j];

		}

	}

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

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

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

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

				if (k==j) continue;

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

			}

		}

	}

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

//		for(int j=1..3) {

//			

//			for(int k=1..3) {

//				if (k==j) continue;

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

//			} 

//		} 

	

//	}

	int max=-1;

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

		if (f[n-1][i]>max) max=f[n-1][i];

	}

	cout<<max<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.204619591248211x):
#include<cstdio>

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 5;

int dp[maxn][5] , a[maxn][4];

int main(){

	int n;

	scanf("%d",&n);

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

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

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

		}

	}

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

	}

	int ans = 0;

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

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

}