stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int a[100000+5];

int b[100000+5];

int c[100000+5];



int main(int argc, char const *argv[])

{

	int N;

	while(cin >> N) {

		memset(a, 0, sizeof(a));

		memset(b, 0, sizeof(b));

		memset(c, 0, sizeof(c));

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

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

		}

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

			int tempa = a[i - 1];

			int tempb = b[i - 1];

			int tempc = c[i - 1];

			a[i] = a[i] + max(tempb, tempc);

			b[i] = b[i] + max(tempa, tempc);

			c[i] = c[i] + max(tempa, tempb);

		}

	    cout << max(a[N], max(b[N], c[N])) << endl;

    }

	return 0;

}

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

using namespace std;

#define debug(x) cerr<<#x<<" = "<<x<<endl;

typedef long long int ll;

int main(){

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int n;

    cin>>n;

    int arr[n];

    int arr2[n];

    int arr3[n];

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

        cin>>arr[i];

        cin>>arr2[i];

        cin>>arr3[i];



    }

    int ans[n];

    int ans2[n];

    int ans3[n];

    ans[0]=arr[0];

    ans2[0]=arr2[0];

    ans3[0]=arr3[0];

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

        ans[i]=arr[i]+max(ans2[i-1],ans3[i-1]);

        ans2[i]=arr2[i]+max(ans3[i-1],ans[i-1]);

        ans3[i]=arr3[i]+max(ans2[i-1],ans[i-1]);

    }

    int res=max({ans[n-1],ans2[n-1],ans3[n-1]});

    cout<<res<<"\n";

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

using namespace std;

#define ll long long

vector<vector<int>> vc;

int n;

int dp[100005][3];



int go(int i , int prev) {

	if (i >= n)

		return 0;

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

		return dp[i][prev];

	int res = -1;

	if (prev == 0)

		res = max(vc[i][1] + go(i + 1, 1), vc[i][2] + go(i + 1, 2));

	else if (prev == 1)

		res = max(vc[i][0] + go(i + 1, 0), vc[i][2] + go(i + 1, 2));

	else

		res = max(vc[i][1] + go(i + 1, 1), vc[i][0] + go(i + 1, 0));

	return dp[i][prev] = res;

}





int main()

{

	ios::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);

	cin >> n;

	int t = n;

	int x, y, z;

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

	while (t--) {

		cin >> x >> y >> z;

		// int one = max({x, y, z});

		// int three = min({x, y, z});

		// int two = x ^ y ^ z ^ one ^ three;



		vc.push_back({x, y, z});

	}

	cout << max({go(0, 0), go(0, 1), go(0, 2)}) << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.178200164533704x):


#include <bits/stdc++.h>

using namespace std;

#define ll long long

struct act

{

	int a, b, c;

};



int main()

{

	ios::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);



	int n;

	cin >> n;

	int dp[n][3];

	vector<act> vc(n + 1);

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

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

	dp[0][0] = vc[0].a;

	dp[0][1] = vc[0].b;

	dp[0][2] = vc[0].c;

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

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

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

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

	}

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

	return 0;

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

#include <ext/pb_ds/assoc_container.hpp>



#define INF 1000000021

#define MOD 1000000007

#define pb push_back

#define sqr(a) (a)*(a)

#define M(a, b) make_pair(a,b)

#define F first

#define S second

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

#define deb(x) cerr << #x << " = " << x << '\n'

#define N 222222



using namespace std;

using namespace __gnu_pbds;



typedef long double ld;

typedef long long ll;

typedef pair<int,int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;



const ld pi = 2 * acos(0.0);

template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}

template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}

template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}



//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};



ll a[N][4], dp[N][4];

int n;

ll f(int id, int pre)

{

	if(id > n)

		return 0;

	ll ans = dp[id][pre];

	if(ans != -1)

		return ans;

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

		if(i != pre)

			umax(ans, a[id][i] + f(id + 1, i));

	return dp[id][pre] = ans;

}



int main()

{

	memset(dp, -1, sizeof dp);

	cin >> n;

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

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

			cin >> a[i][j];

	cout << f(1, 0);

}

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

#include <ext/pb_ds/assoc_container.hpp>



#define INF 1000000021

#define MOD 1000000007

#define pb push_back

#define sqr(a) (a)*(a)

#define M(a, b) make_pair(a,b)

#define F first

#define S second

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

#define deb(x) cerr << #x << " = " << x << '\n'

#define N 222222



using namespace std;

using namespace __gnu_pbds;



typedef long double ld;

typedef long long ll;

typedef pair<int,int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;



const ld pi = 2 * acos(0.0);

template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}

template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}

template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}



//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};



ll dp[N][5];

int main()

{

	int n;

	cin >> n;

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

	{

		ll a, b, c;

		cin >> a >> b >> c;

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

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

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

	}

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









	











	getchar();

	getchar();

	return 0;

	//ios::sync_with_stdio(false);

	//cin.tie(0);

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

#include <algorithm>

#include <climits>

#define SIZE 100001

#define INF INT_MAX >> 1



using namespace std;



int dp[SIZE][3];



int main(void){

	int n; cin >> n;

	static int abc[SIZE][3];

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

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

	}



	fill(dp[0], dp[SIZE], 0);

	//配るDP

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

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

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

				if(from != to){

					dp[i+1][to] = max(dp[i+1][to], dp[i][from]+abc[i][to]);

				}

			}

		}

	}



	int ans = -1;

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

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

	}

	cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 2.182237690109281x):
#define _USE_MATH_DEFINES

#include <iostream>

#include <algorithm>

#include <queue>

#include <stack>

#include <deque>

#include <climits>

#include <string>

#include <vector>

#include <set>

#include <map>

#include <cmath>

#include <cstdio>

#include <cstdlib>

#include <cstring>

//#include <tuple>



#define INF INT_MAX>>1 

#define SIZE 100010

#define MOD 1000000007

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

#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)

#define ALL(obj) (obj).begin(), (obj).end()

#define LLPair pair<ll, ll>

#define vint vector<int>

#define vll vector<ll>

typedef long long ll;



using namespace std;



struct Point { int x, y; };

struct Edge { int from, to, cost; };

struct gNode { int from, to, cost; };

struct tNode { int value; int parent; vector<int> child; };



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

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



int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }

int lcm(int a, int b){ return a * b/ gcd(a, b); }

int extgcd(int a, int b, int& x, int& y){

	int d = a;

	if(b != 0){

		d = extgcd(b, a%b, y, x);

		y -= (a/b) * x;

	} else{

		x = 1; y = 0;

	}

	return d;

}

ll mod_pow(ll x, ll n){

	if(n == 0) return 1;

	ll res = mod_pow(x*x % MOD, n/2);

	if(n & 1) res = res * x % MOD;

	return res;

}



//int dp[SIZE][3];

#define A 0

#define B 1

#define C 2



int main(void){

	static int dp[SIZE][3];

	int n; cin >> n;

	vint a(n), b(n), c(n);

	rep(i, n){

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

	}



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

	dp[0][B] = b[0];

	dp[0][C] = c[0];



	rep2(i, 0, n-1){

		dp[i+1][A] = max(dp[i+1][A], dp[i][B] + a[i+1]);

		dp[i+1][A] = max(dp[i+1][A], dp[i][C] + a[i+1]);



		dp[i+1][B] = max(dp[i+1][B], dp[i][A] + b[i+1]);

		dp[i+1][B] = max(dp[i+1][B], dp[i][C] + b[i+1]);



		dp[i+1][C] = max(dp[i+1][C], dp[i][A] + c[i+1]);

		dp[i+1][C] = max(dp[i+1][C], dp[i][B] + c[i+1]);

	}



	int ans = 0;

	rep(i, 3){

		//cout << dp[n-1][i] << endl;

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

	}

	cout << ans << endl;

	return 0;

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

using namespace std;



const int N = 1e5 + 10;

int n;

int dp[N][3];

int a[N][3];

int solve(int r,int c){



    if(r > n-1)

        return 0;

        

    if(dp[r][c] != -1)  return dp[r][c];

    

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

        if(i != c)

            dp[r][c] = max(dp[r][c],solve(r+1,i)+a[r][i]);

    }

    

    return dp[r][c];    

} 

int main()

{

    cin>>n;

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

   

    

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

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

            cin>>a[i][j];

    int ans = -1;

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

    {

        ans = max(ans,solve(1,i) + a[0][i]);

    }

    

    cout<<ans<<endl;

    

    return 0;

    

}

    

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

#define int64_t int 



using namespace std;



int main(){

	

	int n;

	cin>>n;

	

	int a[n][3];

	int dp[n][3];

	

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

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

			cin>>a[i][j];

		}

	}

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

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

	}

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

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

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

		}

	}

	int ans = INT_MIN;

	

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

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

	}

	

	cout<<ans;

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

#include <string>

#include<iostream>

#include<vector>

#include <bits/stdc++.h>

#include <stdio.h>

#include <numeric>

#include<math.h>

#include <ctype.h>

#include <algorithm> // sort

#include <map> // pair

using namespace std;

#define nin(n) int n; cin >> n;

#define kin(k) int k; cin >> k;

const int INF = 1001001001;

int main(){

  int n;cin >> n;

  long long h[100010][3];

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

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

      int tmp;

      cin >> tmp;

      h[i][j]=tmp;

    }

  }

 long long dp[10010][3];

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

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

     dp[i][j]=0;

   }

 }

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

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

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

        if(j==k) continue;

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

      }

    }

  }

  long long res = 0;

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

      res=max(res, dp[n][j]);

    }

  

    cout << res << endl;

}

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

using namespace std;

#define nin(n) int n; cin >> n;

#define kin(k) int k; cin >> k;

 

int main() {

  int n; cin >> n;

  vector<int> a(n);

  vector<int> b(n);

  vector<int> c(n);

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

    cin >> a.at(i) >> b.at(i) >> c.at(i);

  }

  int dp[n+10][3]={};

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

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

  dp[0][2]=c[0];

  for(int i=1;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]));

      }

    }

  }

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

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

using namespace std;



const int MAX=100005;

vector<int> Sa(MAX,1000000005),Sb(MAX,1000000005),Sc(MAX,1000000005),A(MAX),B(MAX),C(MAX);

int N;



void DP(int u){

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

        Sa[i]=max(Sb[i-1],Sc[i-1])+A[i];

        Sb[i]=max(Sa[i-1],Sc[i-1])+B[i];

        Sc[i]=max(Sa[i-1],Sb[i-1])+C[i];

    }

    cout<<max(Sa[u],max(Sb[u],Sc[u]))<<endl;

}



int main(){

    

    cin>>N;

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

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

    }

    Sa[0]=0;Sb[0]=0;Sc[0]=0;

    DP(N);

}


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

using namespace std;



typedef long long ll;

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

const int mod=1000000007,INF=1<<30;



int main(){

    

    int N;cin>>N;

    vector<int> A(N),B(N),C(N);

    int dp[3][N+1];

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

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

    }

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

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

            dp[j][i]=-INF;

        }

    }

    dp[0][0]=A[0];dp[1][0]=B[0];dp[2][0]=C[0];

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

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

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

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

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

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

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

    }

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

    

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

using namespace std;

#define ll long long

int n , arr[100001][3]={},dp[100001][3];



int f(int i = 0 , int t = -1)

{

    if( i == n )

        return arr[n][t];

    if(i==0)

        return max({f(i+1,0),f(i+1,1),f(i+1,2)});

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

        return dp[i][t];

    if(t!=0)

        dp[i][t] = max(dp[i][t],f(i+1,0));

    if(t!=1)

        dp[i][t] = max(dp[i][t],f(i+1,1));

    if(t!=2)

        dp[i][t] = max(dp[i][t],f(i+1,2));

    return dp[i][t]+= arr[i][t];

}

int main()

{

    memset(dp,-1,sizeof dp);

    cin >> n;

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

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

    cout << f();

    return 0;

}

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

using namespace std;

#define ll long long

int main()

{

    int n, a[100000], b[100000], c[100000], dp[100000][3];

    scanf("%d", &n);

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

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

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

    dp[n-1][1] = b[n-1];

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

    for(int i=n-2; i>=0; --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];

    }

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

    return 0;

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

using namespace std;

#define ll long long

int n, a[100000], b[100000], c[100000], dp[100000][4];

int f(int i, int p)

{

    if( i == n )

        return 0;

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

        return dp[i][p];

    int mx = -1;

    if( p != 0 )

    {

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

    }

    if( p != 1 )

    {

        mx = max(mx , f(i+1, 1)+b[i]);

    }

    if( p != 2 )

    {

        mx = max(mx , f(i+1, 2)+c[i]);

    }

    return dp[i][p] = mx;



}

int main()

{

    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);

    cout << f(0, 3);

    return 0;

}

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

using namespace std;

#define ll long long

int main()

{

    int n, a[100000], b[100000], c[100000], dp[100000][3];

    scanf("%d", &n);

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

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

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

    dp[n-1][1] = b[n-1];

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

    for(int i=n-2; i>=0; --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];

    }

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

    return 0;

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

using namespace std;



#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)

#define rep(i, count) REP(i, 0, count)

#define ALLOF(c) (c).begin(), (c).end()



typedef long long ll;

typedef unsigned long long ull;



int N;

int a[100000 + 10] = {};

int b[100000 + 10] = {};

int c[100000 + 10] = {};



int main(void) {

    cin >> N;

    rep(i, N) {

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

    }



    int dp[100010][3] = {};

    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] = 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];

    }



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

    return 0;

}

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

using namespace std;



#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)

#define rep(i, count) REP(i, 0, count)

#define ALLOF(c) (c).begin(), (c).end()



using ll = long long;

using ull = unsigned long long;

using veci = vector<int>;

using vecll = vector<ll>;

using vecull = vector<ull>;



int main(void) {



    ll N;

    cin >> N;

    vector<vecll> abc(N + 1, vecll(3));



    REP(i, 1, N + 1) {

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

    }



    vector<vecll> dp(N + 1, vecll(3, 0));



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

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

            dp[i + 1][k] = max(dp[i + 1][k], dp[i][(k + 1) % 3] + abc[i + 1][k]);

            dp[i + 1][k] = max(dp[i + 1][k], dp[i][(k + 2) % 3] + abc[i + 1][k]);

        }

    }



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



    cout << ans << endl;



    return 0;

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

using namespace std;

#define ll long long 



#define F first

#define S second



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

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

const double EPS= 1e-8 ;

const double PI  = acos(-1.0);

#define inf INT_MAX

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }





struct hap{

	int a ; 

	int b ; 

	int c ; 

	

};

 int a[100005][3] ;   // dont ; 

 int n ;  

 int dp[100005][4] ;  



int sol ( int ind , int l ) 

{

	if (ind >= n ) return 0 ; 

	

	

	

	int &res = dp[ind][l]; 

	if ( res != -1 ) return res ; 

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

	{

		if ( l != i )

		{

			res = max (res, sol( ind+1 , i ) + a[ind][i]) ; 

			

		}

	}

	

	

	return res ; 

	

}









int main()

 {

 

 cin>>n ; 



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

 {

	 int x , y , z ; 

	 cin>>x >> y >> z ; 

	 a[i][0]= x ; 

	 a[i][1] = y ; 

	 a[i][2] = z ; 

	 

	 

 }

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

 

  

  int ans = sol ( 0 , 3 ) ; 

  cout<< ans << endl; 







 return 0 ;

}













 

 

 

 

 

 



 


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

using namespace std;

#define ll long long 



#define F first

#define S second



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

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

const double EPS= 1e-8 ;

const double PI  = acos(-1.0);

#define inf INT_MAX

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }











int main()

 {

 int n ; 

 cin>>n; 

 int a[n][3]  ;

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

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

	 cin>>a[i][j] ; 

 }

 

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

 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 )

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

 {

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

	 {

		 if (k!= j)

		 {

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

		 }

	 }

 }

 

 int ans = max ( { dp[n-1][0], dp[n-1][1], dp [n-1 ][2]}) ; 

 cout << ans << endl; 

 

  







 return 0 ;

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

#include <assert.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <string.h>

#include <cmath>

#include <algorithm>

#include <iomanip>

using namespace std;



const int N = 1e5 + 2;



int n, a[4][N];

long long dp[N][4];



long long calc(int i, int prv)

{

    if (i == n)

    {

        return 0;

    }

    long long &ret = dp[i][prv];

    if (ret != -1)

    {

        return ret;

    }

    ret = 0;

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

    {

        if (j != prv)

        {

            ret = max(ret, calc(i + 1, j) + a[j][i]);

        }

    }

    return ret;

}



int main()

{

    memset(dp, -1, sizeof dp);

    cin >> n;

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

    {

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

        {

            cin >> a[j][i];

        }

    }

    cout << calc(0, 0) << endl;

    return 0;

}

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

#include <assert.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <string.h>

#include <cmath>

#include <algorithm>

#include <iomanip>

#define ll long long

using namespace std;



const int N = 1e5 + 7;

const long long oo = 1e18L + 5;



int n, a[N][3];



int main() {

    cin >> n;

    vector<vector<ll>> dp(n + 2, vector<ll>(3, -oo));

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

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

            cin >> a[i][j];

        }

    }

    dp[0][0] = dp[0][1] = dp[0][2] = 0;

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

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

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

                if (k != j) {

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

                }

            }

        }

    }

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

    return 0;

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

#include <algorithm>

using namespace std;



int main(){

    int n, a[200000], b[200000], c[200000], dp[200000][5];

    cin >> n;

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

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

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

    }

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

}

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

using namespace std;

typedef long long ll;

const int MOD = 1e9+7;

const int INF = 2e9;



int n, abc[100005][3], dp[100005][3];



int main(){



    cin >> n;

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

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

            cin >> abc[i][j];

        }

    }

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

        dp[0][i] = abc[0][i];

    }

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

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

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

        }

    }

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

}