stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

  

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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

***/


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

} 

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



vector<vector<int> > v;

int ans[100005][3];

queue<pair<int,pair<int,int> > >s;

int maior,a=0;



void dp(int i, int bloq, int sum) {

  if(ans[i-1][bloq]>sum)

    return;

  

  if (i>=v.size())

    maior = max(sum, maior);

  else {

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

      if (bloq != j) {



        if(ans[i][j]==-1) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }

        else if (ans[i][j]<sum+v[i][j]) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }



        //dp(i+1, j, sum+v[i][j]);

      }

    }

  }

}



int main () {

  int n;

  cin>>n;

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

    int a,b,c;

    cin>>a>>b>>c;

    v.push_back({a,b,c});

  }



  maior=0;

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

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

    s.push({v[0][i],{1,i}});

    //dp(1, i, v[0][i]);

  }



  while(!s.empty()) {

    pair<int,pair<int,int> > aux = s.front();

    dp(aux.second.first, aux.second.second, aux.first);

    s.pop();

  }



  cout<<maior<<endl;



}




// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;



int n;

const int nx = 1e5+5;

int ac[nx][3];

int dp[3][nx];



int go(int a, int i){

	if(i == n) return 0;

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

	int& ans = dp[a][i];

	

	if(a==0){

		ans=max(ans, go(1, i+1)+ac[i][0]);

		ans=max(ans, go(2, i+1)+ac[i][0]);

	}

	if(a==1){

		ans=max(ans, go(0, i+1)+ac[i][1]);

		ans=max(ans, go(2, i+1)+ac[i][1]);

	}

	if(a==2){

		ans=max(ans, go(0, i+1)+ac[i][2]);

		ans=max(ans, go(1, i+1)+ac[i][2]);

	}

	

	return ans;

}



int main(){

	cin>>n;

	for(int i=0; i<n; i++) cin>>ac[i][0]>>ac[i][1]>>ac[i][2];

	memset(dp, -1, sizeof dp);

	cout<<max(go(0,0),max(go(1,0),go(2,0)))<<"\n";

	return 0;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

const int oo = 1e9;

int number;

const int nx = 1e5+5;

int ac[nx][3];

int dyn[3][nx];

int init(int a, int i){

	if(i == number) return 0;

	if(dyn[a][i] != -1) return dyn[a][i];

	int& res = dyn[a][i];

	

	if(a==0){

		res=max(res, init(1, i+1)+ac[i][0]);

		res=max(res, init(2, i+1)+ac[i][0]);

	}

	if(a==1){

		res=max(res, init(0, i+1)+ac[i][1]);

		res=max(res, init(2, i+1)+ac[i][1]);

	}

	if(a==2){

		res=max(res, init(0, i+1)+ac[i][2]);

		res=max(res, init(1, i+1)+ac[i][2]);

	}

	

	return res;

}

int main(){

	cin>>number;

	for(int i=0; i<number; i++) cin>>ac[i][0]>>ac[i][1]>>ac[i][2];

	memset(dyn, -1, sizeof dyn);

	cout<<max(init(0,0),max(init(1,0),init(2,0)))<<"\n";

	return 0;

}




// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem: