stablegradients/pie-gem5-pairs huggingface dataset:
// 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.5928479391490686x):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

ll a[100009],b[100009],c[100009];

int dp[100009][3];

int main() {

    ios::sync_with_stdio(false);

    int n;cin>>n;

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

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

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

    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(max(dp[n][0],dp[n][1]),dp[n][2])<<endl;

    return 0;

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

using namespace std;

typedef long long ll;



ll arr[100009][3];

int dp[100009][2][2][2];



long long VAC1(int n,int a, int b, int c)

{



    if(!n && a) return arr[n][0];

    else if(!n && b) return arr[n][1];

    else if(!n && c) return arr[n][2];

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



    else

    {



        ll x,y,z;

        if(a)

        {

            x = VAC1(n-1,0,1,0)+arr[n][0];

            y = VAC1(n-1,0,0,1)+arr[n][0];



        }



        else if(b)

        {

            x = VAC1(n-1,1,0,0)+arr[n][1];

            y = VAC1(n-1,0,0,1)+arr[n][1];

        }



        else if(c)

        {

            x = VAC1(n-1,1,0,0)+arr[n][2];

            y = VAC1(n-1,0,1,0)+arr[n][2];

        }



        dp[n][a][b][c] = max(x,y);;

        return dp[n][a][b][c];





    }

}



int main()

{

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

    int n;

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

    cin >> n;

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

    {

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

        {

            cin >> arr[i][j];

        }

    }

    ll res = VAC1(n-1,1,0,0);

    res= max(res, VAC1(n-1,0,1,0));

    res = max(res,VAC1(n-1,0,0,1));



    cout << res << endl;

}


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

using namespace std;

#define ll long long

ll a[100009],b[100009],c[100009];

int dp[100009][3];

int main() {

    ios::sync_with_stdio(false);

    int n;cin>>n;

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

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

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

    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(max(dp[n][0],dp[n][1]),dp[n][2])<<endl;

    return 0;

}
// 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.214458374291133x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

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

#include <limits.h>

#include <algorithm>  

#include <numeric>

 

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

using namespace std;

 

#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define endl '\n'

using ll = long long;

 

const int precision = 3;

const int modulo =  1000000007; // 10^9 + 7

const ll lmodulo =  1000000007; // 10^9 + 7

 

const double EPS = 1e-9;

const ll inf = 1e18;



void solve () {

	int n; cin >> n;

	vector<vector<int>> days(n, vector<int>(3));

	for (auto &it : days) {

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

	}



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

	dp[0] = days[0];



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

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

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

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

	}



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

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

	cout << ret << endl;

}



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(nullptr);

  cout.tie(nullptr);

  cout.precision(precision);

  cout.setf(ios_base::fixed);

  solve();

  return 0;

}




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

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

	printf("%d\n",max(d[n-1][0],max(d[n-1][1],d[n-1][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: 18.423060951850196x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
#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;

}


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

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
#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

***/


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

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
#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);

} 

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

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
#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;

}

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

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

}
// 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: 11.400201228605978x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

}
// 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: 11.819106540502117x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
#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;

}

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

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
// Problem B - Vacation - MATA52

#include <iostream>

#include<bits/stdc++.h>



using namespace std;



int main() {

    int days;

    int max_a = -1, max_b = -1, max_c = -1, max_happiness = -1;

    int a_ant = 0, b_ant = 0, c_ant = 0, a, b, c;

    

    cin >> days;

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

        cin >> a >> b >> c;     // read activities 

        int today_a = max(b_ant + a, c_ant + a);     // activity a with others

        max_a = max(today_a, max_a);                 // max of activities a

        max_happiness = max(max_a, max_happiness);   // max Taro happiness

        

        int today_b = max(a_ant + b, c_ant + b);    // activity b with others

        max_b = max(today_b, max_b);                // max of activities b

        max_happiness = max(max_b, max_happiness);  // max Taro happiness

        

        int today_c = max(b_ant + c, a_ant + c);    // activity c with others

        max_c = max(today_c, max_c);                // max of activities c

        max_happiness = max(max_c, max_happiness);  // max Taro happiness

        

        // update activities of yesterday with the choices of today

        a_ant = today_a;

        b_ant = today_b;

        c_ant = today_c;

    }

    // print max happiness obtained

    cout << max_happiness << endl;

}

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

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

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



using namespace std;



int vacation(int table_of_happiness[][3], int j, int r[][4], int nxt){

	if(j==-1){

		return 0;

	}

	if(r[j][nxt] >= 0){

		return r[j][nxt];

	}

	else{

		int t[3];

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

			if(nxt != i)

				t[i] = vacation(table_of_happiness, j-1, r, i) + table_of_happiness[j][i];

		int best=0;

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

			if(nxt != i && t[i] > best){

				best = t[i];

			}

		}

		r[j][nxt] = best;

		return r[j][nxt];

	}

}



int main(){

	int N;

	scanf("%d", &N);

	int table_of_happiness[N][3];

	int r[N][4];

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

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

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

		}

	}



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

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

			r[i][j] = -1;

		}

	}



	r[N-1][3] = vacation(table_of_happiness, N-1, r, 3);



	printf("%d\n", r[N-1][3]);

}

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

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

}