stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
//       Author: Mostafa Mounir Shehab

 

#include <bits/stdc++.h>

using namespace std;

 

#define PI  3.14159265  // PI = acos(-1)

#define EPS (1e-10)

#define endl "\n"

#define SZ(v) (int)(v.size())

typedef long long ll;

typedef long double ld;

//template <class Type>

 

 

void Fast(){

	std::ios_base::sync_with_stdio(0);

	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);

}

 

inline int D(){

	int t;

	scanf("%d",&t);

	return t;

}

inline ll llD(){

	ll t;

	scanf("%lld",&t);

	return t;

}

 

 

ll MOD=1e9 + 7; 

const int N=1e5 + 5,M=50 + 1;

int arr[N][4];

ll dp[N][4];

ll OO=1e12; 

 

ll n,m,k,cnt,SU,idx,len,MN,MX;

ll l,r,mid;

ll a,b,c,d;



ll Solve(int idx,int row){

	

		

	if(idx == n)

		return 0;

	

	ll &ret = dp[idx][row];

	if(~ret)

		return ret;

	

	ret = -OO;

	

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

		if(row != i)

			ret = max(ret,arr[idx][i] + Solve(idx+1,i));

	

	return ret;

}







 

 

int main(){

	

	memset(dp, -1 ,sizeof dp);

	cin>>n;

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

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



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

	



	





}

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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

#define loopOne(i, n)   for(int i = 1 ; i <= n; ++i)

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int a[N], b[N], c[N], n, memo[N][4];



int Solve(int idx, int prev){

    // 0 for a, 1 for b, 2 for c

    if(idx == n)    return 0;

    if(memo[idx][prev] != -1)   return memo[idx][prev];



    int res = -OO;

    if(prev == 0){  // The previous one was 'A'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), c[idx] + Solve(idx+1, 2));

    }else if(prev == 1){  // The previous one was 'b'

        memo[idx][prev] = max(a[idx] + Solve(idx+1, 0), c[idx] + Solve(idx+1, 2));

    }else if(prev == 2){  // The previous one was 'c'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), a[idx] + Solve(idx+1, 0));

    }else{

        memo[idx][prev] = max(max(a[idx] + Solve(idx+1, 0), b[idx] + Solve(idx+1, 1)), c[idx] + Solve(idx+1, 2));

    }

    return memo[idx][prev];

}

int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0, 3));

    return 0;

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

#include <unordered_map>

#define stop(x) {cout<<x<<endl;exit(0);}

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

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

#define endl '\n'

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

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

typedef long long ll;

using namespace std;



void file() {

    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE

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

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

#endif

}





ll n;

ll mem[100004][4];

vector < vector < int > > v;



ll solve(int idx , int last) {

    if (idx == n)return 0;



    ll& ret = mem[idx][last];

    if (~ret)return ret;

    ret = 0;

    if (last != 0)ret = max(ret, solve(idx + 1, 0) + v[idx][0]);

    if (last != 1)ret = max(ret, solve(idx + 1, 1) + v[idx][1]);

    if (last != 2)ret = max(ret, solve(idx + 1, 2) + v[idx][2]);

    return ret;

}



int main() {

    //file();



    memset(mem, -1, sizeof mem);

    cin >> n;

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

    for (auto& e : v)

        for (auto& f : e)

            cin >> f;



    cout << solve(0,3) << endl;



}

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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

#define loopOne(i, n)   for(int i = 1 ; i <= n; ++i)

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int a[N], b[N], c[N], n, memo[N][4];



int Solve(int idx, int prev){

    // 0 for a, 1 for b, 2 for c

    if(idx == n)    return 0;

    if(memo[idx][prev] != -1)   return memo[idx][prev];



    int res = -OO;

    if(prev == 0){  // The previous one was 'A'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), c[idx] + Solve(idx+1, 2));

    }else if(prev == 1){  // The previous one was 'b'

        memo[idx][prev] = max(a[idx] + Solve(idx+1, 0), c[idx] + Solve(idx+1, 2));

    }else if(prev == 2){  // The previous one was 'c'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), a[idx] + Solve(idx+1, 0));

    }else{

        memo[idx][prev] = max(max(a[idx] + Solve(idx+1, 0), b[idx] + Solve(idx+1, 1)), c[idx] + Solve(idx+1, 2));

    }

    return memo[idx][prev];

}

int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0, 3));

    return 0;

}
// Slower C++ solution:
/******

author :- Mahmoud Tarek.

*******/



#include<bits/stdc++.h>



using namespace std ;



#define rg register

#define dbg(v) cerr << #v << " " << v ;

typedef long long ll ;



int n;

struct doW{

int w[5] ;

};



vector<doW> a ;

int mem[100002][6] ;



int solve(int i, int ch){

if(i == n) return 0 ;

int & ret = mem[i][ch] ;

if(~ret) return ret ;

ret = 0 ;

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

    if(ch != j){

        ret = max(ret, a[i].w[j] + solve(i + 1, j)) ;

    }

}

return ret ;

}



int main() {

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

    cin >> n ;

    a.resize(n) ;

    memset(mem, -1, sizeof mem) ;

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

        for(int j = 2 ; j <= 4 ; j++) cin >> a[i].w[j] ;

    }

    cout << solve(0, 1) ;



}



/*

  Empty set of troubles.

*/


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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

#define loopOne(i, n)   for(int i = 1 ; i <= n; ++i)

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int a[N], b[N], c[N], n, memo[N][4];



int Solve(int idx, int prev){

    // 0 for a, 1 for b, 2 for c

    if(idx == n)    return 0;

    if(memo[idx][prev] != -1)   return memo[idx][prev];



    int res = -OO;

    if(prev == 0){  // The previous one was 'A'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), c[idx] + Solve(idx+1, 2));

    }else if(prev == 1){  // The previous one was 'b'

        memo[idx][prev] = max(a[idx] + Solve(idx+1, 0), c[idx] + Solve(idx+1, 2));

    }else if(prev == 2){  // The previous one was 'c'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), a[idx] + Solve(idx+1, 0));

    }else{

        memo[idx][prev] = max(max(a[idx] + Solve(idx+1, 0), b[idx] + Solve(idx+1, 1)), c[idx] + Solve(idx+1, 2));

    }

    return memo[idx][prev];

}

int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0, 3));

    return 0;

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

using namespace std;



const int N=1e5+30;

typedef long long ll;

int n;

int a[N],b[N],c[N];

ll dp[N][5];

ll solve(int i,int last){

    if(i==n)return 0;

    int path1=-1 ,path2=-1,path3=-1;

    ll &ret=dp[i][last];

    if(~ret)return ret;

    if(last!=1){

        path1=a[i]+solve(i+1,1);

    }

    if(last!=2){

        path2=b[i]+solve(i+1,2);

    }

    if(last!=3){

        path3=c[i]+solve(i+1,3);

    }

    return ret=max(path1,max(path2,path3));



}

int main()

{

    memset(dp,-1,sizeof dp);

    cin>>n;

    for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];

    cout<<solve(0,4);



}




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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

#define loopOne(i, n)   for(int i = 1 ; i <= n; ++i)

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int a[N], b[N], c[N], n, memo[N][4];



int Solve(int idx, int prev){

    // 0 for a, 1 for b, 2 for c

    if(idx == n)    return 0;

    if(memo[idx][prev] != -1)   return memo[idx][prev];



    int res = -OO;

    if(prev == 0){  // The previous one was 'A'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), c[idx] + Solve(idx+1, 2));

    }else if(prev == 1){  // The previous one was 'b'

        memo[idx][prev] = max(a[idx] + Solve(idx+1, 0), c[idx] + Solve(idx+1, 2));

    }else if(prev == 2){  // The previous one was 'c'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), a[idx] + Solve(idx+1, 0));

    }else{

        memo[idx][prev] = max(max(a[idx] + Solve(idx+1, 0), b[idx] + Solve(idx+1, 1)), c[idx] + Solve(idx+1, 2));

    }

    return memo[idx][prev];

}

int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0, 3));

    return 0;

}
// Slower C++ solution:
/* MaTb3aa */

#include<bits/stdc++.h>

#define ll long long

using namespace std;

int n;

const int N = 100005;

vector<int>v;

ll dp[100005][4];

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

ll solve(int i,int lst) {

	if (i == n)return 0;

	ll& ret = dp[i][lst];

	if (~ret)return ret;

	if (lst != 1)ret = max(ret, solve(i + 1, 1) + A[i]);

	if (lst != 2)ret = max(ret, solve(i + 1, 2) + B[i]);

	if (lst != 3)ret = max(ret, solve(i + 1, 3) + C[i]);

	return ret;

}

int main() {

	cin >> n;

	for (int i = 0; i < n; i++)cin >> A[i] >> B[i] >> C[i];

	memset(dp, -1, sizeof dp);

	cout << solve(0, 0);

	

		 

}

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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

#define loopOne(i, n)   for(int i = 1 ; i <= n; ++i)

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int a[N], b[N], c[N], n, memo[N][4];



int Solve(int idx, int prev){

    // 0 for a, 1 for b, 2 for c

    if(idx == n)    return 0;

    if(memo[idx][prev] != -1)   return memo[idx][prev];



    int res = -OO;

    if(prev == 0){  // The previous one was 'A'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), c[idx] + Solve(idx+1, 2));

    }else if(prev == 1){  // The previous one was 'b'

        memo[idx][prev] = max(a[idx] + Solve(idx+1, 0), c[idx] + Solve(idx+1, 2));

    }else if(prev == 2){  // The previous one was 'c'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), a[idx] + Solve(idx+1, 0));

    }else{

        memo[idx][prev] = max(max(a[idx] + Solve(idx+1, 0), b[idx] + Solve(idx+1, 1)), c[idx] + Solve(idx+1, 2));

    }

    return memo[idx][prev];

}

int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0, 3));

    return 0;

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

#include<bits/stdc++.h>

using namespace std;



typedef long long ll;



int n;

int a[100005][4];

ll dp[100005][4];



ll solve(int d,int l){

    if(d==n+1) return 0;

    if(dp[d][l]!=-1) return dp[d][l];

    ll ret=0;

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

        if(i!=l){

            ret=max(ret, solve(d+1,i)+a[d][i]);

        }

    }

    return dp[d][l]=ret;



}





int main()

{

    cin>>n;

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

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

            cin>>a[i][j];

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

    cout<<solve(1,-1);



    return 0;

}


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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

#define loopOne(i, n)   for(int i = 1 ; i <= n; ++i)

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int a[N], b[N], c[N], n, memo[N][4];



int Solve(int idx, int prev){

    // 0 for a, 1 for b, 2 for c

    if(idx == n)    return 0;

    if(memo[idx][prev] != -1)   return memo[idx][prev];



    int res = -OO;

    if(prev == 0){  // The previous one was 'A'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), c[idx] + Solve(idx+1, 2));

    }else if(prev == 1){  // The previous one was 'b'

        memo[idx][prev] = max(a[idx] + Solve(idx+1, 0), c[idx] + Solve(idx+1, 2));

    }else if(prev == 2){  // The previous one was 'c'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), a[idx] + Solve(idx+1, 0));

    }else{

        memo[idx][prev] = max(max(a[idx] + Solve(idx+1, 0), b[idx] + Solve(idx+1, 1)), c[idx] + Solve(idx+1, 2));

    }

    return memo[idx][prev];

}

int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0, 3));

    return 0;

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

#define inf INFINITY

#define file freopen( "input.txt" , "r" , stdin) ; freopen( "output.txt" , "w" , stdout) ;

#define Gamed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define _3102_ main()

#define endl '\n'

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

using namespace std;

const int N = 1e5 + 100;

const ll MX = 1e9;

const ll mod = 1e9 + 7;

const double eps = 1e-9 ;



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



ll solve( int i , int j ){

	if ( i < 0 ) return 0 ;

	ll &ret = dp[i][j] ;

	if ( ret != -1) return ret ;

	if ( j == 0 ){

		return ret = a[i] + max ( solve(i-1 , 1), solve(i-1,2) ) ;

	}

	else if ( j == 1 ){

		return ret = b[i] + max ( solve(i-1 , 0), solve(i-1,2) ) ;

	}

	return ret = c[i] + max ( solve(i-1 , 1), solve(i-1,0) ) ;

}



int _3102_{

	Gamed

	cin >> n ;

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

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

	}

	memset ( dp , -1 , sizeof dp);

	dp[0][0] = a[0] , dp[0][1] = b[0] , dp[0][2] = c[0] ;

	cout << max ( solve ( n - 1 , 1) , max ( solve ( n -1 , 0 ) , solve ( n - 1 , 2 ))) << endl ;

	return 0;

}


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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

#define loopOne(i, n)   for(int i = 1 ; i <= n; ++i)

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int a[N], b[N], c[N], n, memo[N][4];



int Solve(int idx, int prev){

    // 0 for a, 1 for b, 2 for c

    if(idx == n)    return 0;

    if(memo[idx][prev] != -1)   return memo[idx][prev];



    int res = -OO;

    if(prev == 0){  // The previous one was 'A'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), c[idx] + Solve(idx+1, 2));

    }else if(prev == 1){  // The previous one was 'b'

        memo[idx][prev] = max(a[idx] + Solve(idx+1, 0), c[idx] + Solve(idx+1, 2));

    }else if(prev == 2){  // The previous one was 'c'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), a[idx] + Solve(idx+1, 0));

    }else{

        memo[idx][prev] = max(max(a[idx] + Solve(idx+1, 0), b[idx] + Solve(idx+1, 1)), c[idx] + Solve(idx+1, 2));

    }

    return memo[idx][prev];

}

int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0, 3));

    return 0;

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

using namespace std;

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

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

typedef long long ll;

typedef unsigned long long ull;

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

#define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++)

#define forn(i, n) forr(i, 0, n)

#define pb push_back

#define mp make_pair

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

#define DBG(x) cerr << #x << " = " << (x) << endl

#define MOD 1000000007

#define MAXN 100005

ll dp[MAXN][3];

void solve(vector< vector<ll> > &a, int n)

{

    forn(i,MAXN)

    {

        forn(j,3)

        {

            dp[i][j]=(pow(10,9)+5)*(ll)(-1);

        }

    }

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

    forr(i,1,n)

    {

        forn(j,3)

        {

            forn(k,3)

            {

                if(j==k)

                {

                    continue;

                }

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

            }

        }

 

    }

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

}

 

int main() {

    FIN;

    int n;

    cin >> n;

    vector< vector<ll> > arreglo(n);

    forn(i,n) arreglo[i].resize(3);

    forn(i,n)

    {

        forn(j,3) cin >> arreglo[i][j];

    }

    solve(arreglo, n);

    return 0;

}

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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

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

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

#define loopOne(i, n)   for(int i = 1 ; i <= n; ++i)

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



int a[N], b[N], c[N], n, memo[N][4];



int Solve(int idx, int prev){

    // 0 for a, 1 for b, 2 for c

    if(idx == n)    return 0;

    if(memo[idx][prev] != -1)   return memo[idx][prev];



    int res = -OO;

    if(prev == 0){  // The previous one was 'A'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), c[idx] + Solve(idx+1, 2));

    }else if(prev == 1){  // The previous one was 'b'

        memo[idx][prev] = max(a[idx] + Solve(idx+1, 0), c[idx] + Solve(idx+1, 2));

    }else if(prev == 2){  // The previous one was 'c'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), a[idx] + Solve(idx+1, 0));

    }else{

        memo[idx][prev] = max(max(a[idx] + Solve(idx+1, 0), b[idx] + Solve(idx+1, 1)), c[idx] + Solve(idx+1, 2));

    }

    return memo[idx][prev];

}

int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0, 3));

    return 0;

}