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

using namespace std;

#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'

const int N = 1e6;

const int inf = 1e9;



int main(){

	ios_base::sync_with_stdio(0);

	int a,b,n,k,T,cas=0;

	cin>>n;

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

	for(vector<int> &x: A) {

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

	}

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

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

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

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

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

	}

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

	return 0;

}

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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>



using namespace std;



int main(){

	

	int N;

	cin >> N;

	

	int A[N] = {}, B[N] = {}, C[N] = {};

	

	int custo[N][3] = {};

	

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

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

	}

	

	

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

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

			if(i == 0){

				switch(j){

					case 0: custo[i][j] = A[i]; break; 

					case 1:	custo[i][j] = B[i]; break;

					case 2: custo[i][j] = C[i]; break;

				}

			}

			else{

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

					if(j == k) continue;

					switch(j){

						case 0: custo[i][j] = max(custo[i][j], custo[i-1][k] + A[i]);break;

						case 1:	custo[i][j] = max(custo[i][j], custo[i-1][k] + B[i]);break;

						case 2: custo[i][j] = max(custo[i][j], custo[i-1][k] + C[i]);break;

					}

				}

				

			}

		

		}

	}

	

	int maximo = 0;

	

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

		if(custo[N-1][i] > maximo)

			maximo = custo[N-1][i];

	}

	cout<< maximo << endl;

	return 0;

}

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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 <iostream>

using namespace std;



int main() {

  long long n;



  cin>>n;



  long long A[n],B[n],C[n];

  long long agendaDP[n][3];



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

    agendaDP[0][i] = 0;

  }



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

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

  }



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

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

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

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

  }



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



}


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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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 f first

#define s second

#define ll long long

#define ld long double

#define pii pair <int,int>

#define pll pair <ll,ll>

#define pil pair <int,ll>

#define pli pair <ll,int>

#define ull unsigned long long

#define pdd pair <double,double>

#define pb push_back

#define mp make_pair

#define puu pair<ull,ull>

#define pvv pair<vector<int>, vector<int> >

#define _bp __builtin_popcount

#define ptt pair <Tree*,Tree*>

#define all(v) v.begin(),v.end();

const long double pi = acos(-1);

void boos()

{

     ios_base :: sync_with_stdio(false);

     cin.tie(0);

     cout.tie(0);

}

void file()

{

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

   freopen(".out","w",stdout);

}

const ll INF = 1e9 + 7;

const ll INF1 = 998244353;

const ll LLINF = (ll)1e18;

const int  INTmx = (int)1e9;

const int N = 2e5 + 100;

ll dp[N][3];

ll a[N];

ll b[N];

ll c[N];

int main()

{

    //file();

    boos();

    int n;

    cin >> n;

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

    {

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

    }

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

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

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

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

    {

        dp[i][0] = 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]));

}

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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>                                           

 

#define int long long

//#pragma GCC optimize("Ofast")

//#pragma comment(linker, "/stack:200000000")

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

 

 

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

#define forev(i, b, a) for(int i = (b); i >= (a); --i)

#define forn(i, a, b) for(int i = (a); i <= (b); ++i)

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

#define sz(s) (int)s.size()

#define pb push_back

#define ppb pop_back

#define mp make_pair

#define s second

#define f first

 

 

using namespace std;

 

 

typedef pair < long long, long long > pll;    

typedef pair < int, int > pii;

typedef unsigned long long ull;         

typedef vector < pii > vpii;

typedef vector < int > vi;

typedef long double ldb; 

typedef long long ll;  

typedef double db;                         

 

 

const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;

const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);

const int inf = 1e9, N = 2e5 + 48, mod = 1e9 + 7;

const db eps = 1e-12, pi = 3.14159265359;

const ll INF = 1e18;





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



main () {

	cin >> n;

	forn (i, 1, n) {

		cin >> a >> b >> c;

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

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

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

	}





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

} 

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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:
//#pragma GCC target ("avx2,sse2")

//#pragma GCC optimization ("Ofast")

//#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



#define ordered_set tree <pair <ll, int>, null_type, less <pair <ll, int> >, rb_tree_tag, tree_order_statistics_node_update>

#define ll long long

#define ull unsigned long long

#define db long double

#define pb push_back

#define pf push_front

#define ppb pop_back

#define ppf pop_front

#define fi first

#define se second

#define mp make_pair

#define up_b upper_bound

#define low_b lower_bound

#define sz(x) (int)(x).size()

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

#define endl "\n"



#define left fsdsdfoisf

#define sum dpsdfioppsf

#define assign xcvjlkdjfio

#define trie fksdfkjkfnjuiv

#define next sidlfjsfkl

#define merge sdfksdkfsldf



#define int long long



using namespace std;



void dout() {

    cerr << endl;

}

template <typename Head, typename... Tail>

void dout(Head H, Tail... T) {

    cerr << H << ' ';

    dout(T...);

}



//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair <int, int> pii;



const int N = 1e5 + 7;

int n, c[3][N], dp[3][N];



void solve(int tc) {

    // check for (int i = 0; i < n; j++)

    cin >> n;

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

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

            cin >> c[j][i];

        }

    }

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

        dp[i][1] = c[i][1];

    }

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

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

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

        }

    }

    int res = 0;

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

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

    }

    cout << res;

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

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

//    freopen("output.txt", "w", stdout);

    int tc = 1;

//    cin >> tc;

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

        solve(i);

//        cleanup();

    }

}


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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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;



typedef signed long long ll;

const int MX = 1e5 + 5;

const int INF = 1e9 + 5;

int n, A[MX][3], dp[MX][4];



int solve(int pos, int prev) {

    if(pos >= n) return 0;

    if(dp[pos][prev] != -1) return dp[pos][prev];

    int ans = 0;

    if(prev == 1) 

        ans = max(ans, max(A[pos][1] + solve(pos + 1, 2), A[pos][2] + solve(pos + 1, 3)));

    else if(prev == 2) 

        ans = max(ans, max(A[pos][0] + solve(pos + 1, 1), A[pos][2] + solve(pos + 1, 3)));

    else if(prev == 3) 

        ans = max(ans, max(A[pos][1] + solve(pos + 1, 2), A[pos][0] + solve(pos + 1, 1)));

    else

        ans = max(A[pos][0] + solve(pos + 1, 1), max(A[pos][1] + solve(pos + 1, 2), A[pos][2] + solve(pos + 1, 3)));

    return dp[pos][prev] = ans;

}



int main() {

    scanf("%d", &n);



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

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

    }

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

    int ans = solve(0, 0);

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

    return 0;

}

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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 ll long long int

#define tc(t) int t;cin >> t; while(t--)

#define pb push_back

#define fi first

#define se second

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

#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";

#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

 

int main() {_

    ll n;

    cin >> n;

    ll dp[n][3] = {};

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

        ll a, b, c;

        cin >> a >> b >> c;

        if(i == 0) {

            dp[i][0] = a;

            dp[i][1] = b;

            dp[i][2] = c;

        }

        else {

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

}

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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;

const int Max= 1e5+10;

long long dp[Max][4];

long long a[Max][4];

int main()

{

	int n;

	scanf("%d",&n);

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

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

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

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

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

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

	{

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

		{

			if(j==1)

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

			else if(j==2)

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

			else

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

		}

	}

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

	return 0;

} 

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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>

#include <math.h>

using namespace std;

int main()

{

    int n;

    cin >> n;

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

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

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

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

    int i;

    dp[0][0] = v[0][0];

    dp[0][1] = v[0][1];

    dp[0][2] = v[0][2];

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

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

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

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

    }

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

    return 0;

}

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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;

typedef long long ll;

const int inf=0x3f3f3f3f;

const int N=2e5+5;

int a[N],b[N],c[N],dp[N][3],n,k;

int main(){

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

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

		}	

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

	return 0;

} 

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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 <algorithm>

#include <cmath>

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <iomanip>

#include <string>

#include <set>

#include <vector>

#include <queue>

#include <stack>

using namespace std;

#define ms(a, x) memset(a, x, sizeof(a))

#define fore(i, a, n) for (long long i = a; i < n; i++)

#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)

#define si(a) scanf("%d", &a)

#define sii(a, b) scanf("%d%d", &a, &b)

#define debug(a) cout << a << endl

#define endl '\n'

#define pi acos(-1.0)

#define tr t[root]

#define lson t[root << 1]

#define rson t[root << 1 | 1]

#define IO ios::sync_with_stdio(false), cin.tie(0)

const double eps = 1e-8;

inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }

typedef long long ll;

const int inf = 0x3f3f3f3f;

const int maxn=100005;



//=================================================

int a[maxn][4];

int dp[maxn][4];

int n,k;

void init() {

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

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

            a[i][j]=0;

            dp[i][j]=0;

        }

    }

}

int main()

{

    IO;

    cin>>n;

    init();

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

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

            cin>>a[i][j];

        }

    }

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

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

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

                if(j!=k)

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

            }

        }

    }

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



    return 0;

}

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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;

typedef long long ll;

const int inf=0x3f3f3f3f;

const int maxn=2e5+5;

int a[maxn][5];

int dp[maxn][5];

int main(){

	int n;

	cin>>n;

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

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

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

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

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

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

		{

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

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

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

		}

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

	return 0;

} 

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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;

const int N=100005;

int a[N][4],dp[N][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<=n;i++)

	{

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

		{

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

			{

				if(j==k)

					continue;

				dp[i][j]=max(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: 5.141815986628406x):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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;

}