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

using namespace std;

int arr[100010][5];

int dp[100010][5];



int vac(int a, int b){

	if(a == 0) return 0;

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

	

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

		if(i != b){

			dp[a][b] = max(dp[a][b], vac(a - 1,i) + arr[a][i]);

		}

	}

	

	return dp[a][b];

}



int main (){

	memset(dp,-1,sizeof dp);

	int n;

	cin >> n;

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

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

	}

	

	

	int ans = 0;

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

		ans = max(ans , vac(n - 1, i) + arr[n][i]);

	}

	

	cout << ans << endl;

	

}

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

using namespace std;

#define endl '\n'



const int N = 1e5;



int dp[N+5][4];

int arr[N+5][4];



int main(){



	ios_base::sync_with_stdio(0);

	int n; cin >>n;

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

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

	}



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

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

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

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

	}	



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

	return 0;

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

using namespace std;

#define INF INT_MAX

#define N 100005

#define K 3

int n, k;

int arr[N][K];

int dp[N][K];

int solve(int idx, int last_k){

    int res;

    if(idx == n)

        return 0;

    if(~last_k && ~dp[idx][last_k])

        return dp[idx][last_k];

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

        if(last_k != i){

            dp[idx][last_k] = max(dp[idx][last_k], arr[idx][i]+solve(idx+1, i));

        }

    }

    return dp[idx][last_k];

}

int main()

{

    cin >> n;

    memset(dp, -1, sizeof(dp[0][0]) * N * K);

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

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

            cin >> arr[i][j];

    cout << solve(0, -1);

    return 0;

}




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

using namespace std;

#define endl '\n'



const int N = 1e5;



int dp[N+5][4];

int arr[N+5][4];



int main(){



	ios_base::sync_with_stdio(0);

	int n; cin >>n;

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

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

	}



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

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

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

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

	}	



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

	return 0;

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

typedef long long ll;

using namespace std;

const int N = 2e5+10 , M = 5e5+10, OO = 0x3f3f3f3f ,  MOD = 1e9+7;

const double EPS = 1e-3;

#define M_PI 3.14159265358979323846

#define clr(arr,val) memset(arr , val , sizeof (arr))

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

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

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

#define pb push_back

#define F first

#define S second

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

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

typedef pair <int,int> pii ;

typedef vector < pii > vii ;

typedef vector < int > vi;

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

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction

//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

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

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







int n,x;

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

ll dp[N][4];





ll solve(int idx, int preC){ //preColour = (1 : a) -- (2 : b) -- (3 : c) -- (0 : invalid)



    if(idx == n) return 0;



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

    if(~ret) return ret;



    ret = -OO;

    if(preC != 1) ret = max(ret, solve(idx+1 , 1)+a[idx]);

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

    if(preC != 3) ret = max(ret, solve(idx+1 , 3)+c[idx]);



    return ret;



}







int main(){





    //ios_base::sync_with_stdio(0);

    //cin.tie(0);cout.tie(0);





    scanf("%d",&n);

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

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



    memset(dp, -1 , sizeof dp);

    ll ans = solve(0 , 0);

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







    return 0;

}


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

using namespace std;

#define endl '\n'



const int N = 1e5;



int dp[N+5][4];

int arr[N+5][4];



int main(){



	ios_base::sync_with_stdio(0);

	int n; cin >>n;

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

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

	}



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

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

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

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

	}	



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

	return 0;

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

#include <cstring>

using namespace std;

const int maxn=1e5+5;

const int inf=0x3f3f3f3f;

int dp[maxn][4];

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

int main()

{

   int n;

   cin>>n;

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

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

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

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

   }

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

   return 0;

}


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

using namespace std;

#define endl '\n'



const int N = 1e5;



int dp[N+5][4];

int arr[N+5][4];



int main(){



	ios_base::sync_with_stdio(0);

	int n; cin >>n;

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

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

	}



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

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

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

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

	}	



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

	return 0;

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

//const int mod = 1e9+9;

/*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }

*ll lcm(ll x, ll y){return x*(y/gcd(x,y));}

*void exEuclid(int a, int b){

	if(b==0){x = 1; y=0; d=a; return ;}

	exEuclid(b, a%b);

	int x1=y;

	int y1=x-(a/b)*y;

	x=x1; 100000

	y=y1;

} 

* */

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

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;

}


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

using namespace std;

#define endl '\n'



const int N = 1e5;



int dp[N+5][4];

int arr[N+5][4];



int main(){



	ios_base::sync_with_stdio(0);

	int n; cin >>n;

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

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

	}



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

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

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

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

	}	



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

	return 0;

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

using namespace std;



int ar[100010][5],n;

int dp[100010][5];



int call(int i,int f)

{



    if(i==n)

        return 0;



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

        return dp[i][f];



    int ans=0;



    if(f==0)

        ans+=max(ar[i][1]+call(i+1,1),ar[i][2]+call(i+1,2));



    else if(f==1)

        ans+=max(ar[i][0]+call(i+1,0),ar[i][2]+call(i+1,2));

    else

        ans+=max(ar[i][1]+call(i+1,1),ar[i][0]+call(i+1,0));



        dp[i][f]=ans;

        return ans;



}



int main()

{



    cin>>n;



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

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



    memset(dp,-1,sizeof dp);



    int ans=max(max(call(0,0),call(0,1)),call(0,2));



    cout<<ans<<endl;



}


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



#define fi first

#define se second

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

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

#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)

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

#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)

#define pb push_back

#define el '\n'

#define d(x) cout<< #x<< " " << x<<el

#define ri(n) scanf("%d",&n)



using namespace std;



typedef long long ll;

typedef pair<int,int> ii;

typedef pair<char,int> pci;

typedef tuple<int, int, int> tiii;

typedef pair<ll,ll> pll;

typedef vector<int> vi;



const int MAXN = 1e5+200;



int dp[MAXN][3];



int main(){

    ios_base::sync_with_stdio(false);

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

    int n;

    cin>> n;



    int op[n][3];

    forn(i,n) cin>> op[i][0]>> op[i][1]>> op[i][2];

    forn(i,3) dp[0][i]= op[0][i];



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

        forn(j,3){

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

        }

    }

    --n;

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

}
// Slower C++ solution:


#include<bits/stdc++.h>

using namespace std;



#define MAX 100000



int dp[MAX+5][4];

int val[MAX+5][4];

int n;



void initialize()

{

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

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

            dp[i][j] = -1;

}



int vacation(int i, int j)

{

    if(i<=0) return 0;



  /*  if(i==1)

    {

        return val[i][j];

    }

*/

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



    int mx = INT_MIN;



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

    {

        if(j==k) continue;



        mx = max(mx, vacation(i-1, k)+ val[i][j]);

    }





    dp[i][j] = mx;



    return mx;

}



int main()

{

    initialize();



    cin>>n;

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

    {

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

            cin>>val[i][j];

    }



    int retVal1 = vacation(n, 1);



    initialize();



    int retVal2 = vacation(n, 2);



    initialize();



    int retVal3 = vacation(n, 3);



    cout<<max({retVal1, retVal2, retVal3})<<endl;



    return 0;

}


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



#define fi first

#define se second

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

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

#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)

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

#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)

#define pb push_back

#define el '\n'

#define d(x) cout<< #x<< " " << x<<el

#define ri(n) scanf("%d",&n)



using namespace std;



typedef long long ll;

typedef pair<int,int> ii;

typedef pair<char,int> pci;

typedef tuple<int, int, int> tiii;

typedef pair<ll,ll> pll;

typedef vector<int> vi;



const int MAXN = 1e5+200;



int dp[MAXN][3];



int main(){

    ios_base::sync_with_stdio(false);

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

    int n;

    cin>> n;



    int op[n][3];

    forn(i,n) cin>> op[i][0]>> op[i][1]>> op[i][2];

    forn(i,3) dp[0][i]= op[0][i];



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

        forn(j,3){

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

        }

    }

    --n;

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

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

using namespace std;

int arr[100010][5];

int dp[100010][5];



int vac(int a, int b){

	if(a == 0) return 0;

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

	

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

		if(i != b){

			dp[a][b] = max(dp[a][b], vac(a - 1,i) + arr[a][i]);

		}

	}

	

	return dp[a][b];

}



int main (){

	memset(dp,-1,sizeof dp);

	int n;

	cin >> n;

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

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

	}

	

	

	int ans = 0;

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

		ans = max(ans , vac(n - 1, i) + arr[n][i]);

	}

	

	cout << ans << endl;

	

}

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



#define fi first

#define se second

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

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

#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)

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

#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)

#define pb push_back

#define el '\n'

#define d(x) cout<< #x<< " " << x<<el

#define ri(n) scanf("%d",&n)



using namespace std;



typedef long long ll;

typedef pair<int,int> ii;

typedef pair<char,int> pci;

typedef tuple<int, int, int> tiii;

typedef pair<ll,ll> pll;

typedef vector<int> vi;



const int MAXN = 1e5+200;



int dp[MAXN][3];



int main(){

    ios_base::sync_with_stdio(false);

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

    int n;

    cin>> n;



    int op[n][3];

    forn(i,n) cin>> op[i][0]>> op[i][1]>> op[i][2];

    forn(i,3) dp[0][i]= op[0][i];



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

        forn(j,3){

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

        }

    }

    --n;

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

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

using namespace std;

#define INF INT_MAX

#define N 100005

#define K 3

int n, k;

int arr[N][K];

int dp[N][K];

int solve(int idx, int last_k){

    int res;

    if(idx == n)

        return 0;

    if(~last_k && ~dp[idx][last_k])

        return dp[idx][last_k];

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

        if(last_k != i){

            dp[idx][last_k] = max(dp[idx][last_k], arr[idx][i]+solve(idx+1, i));

        }

    }

    return dp[idx][last_k];

}

int main()

{

    cin >> n;

    memset(dp, -1, sizeof(dp[0][0]) * N * K);

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

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

            cin >> arr[i][j];

    cout << solve(0, -1);

    return 0;

}




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



#define fi first

#define se second

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

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

#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)

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

#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)

#define pb push_back

#define el '\n'

#define d(x) cout<< #x<< " " << x<<el

#define ri(n) scanf("%d",&n)



using namespace std;



typedef long long ll;

typedef pair<int,int> ii;

typedef pair<char,int> pci;

typedef tuple<int, int, int> tiii;

typedef pair<ll,ll> pll;

typedef vector<int> vi;



const int MAXN = 1e5+200;



int dp[MAXN][3];



int main(){

    ios_base::sync_with_stdio(false);

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

    int n;

    cin>> n;



    int op[n][3];

    forn(i,n) cin>> op[i][0]>> op[i][1]>> op[i][2];

    forn(i,3) dp[0][i]= op[0][i];



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

        forn(j,3){

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

        }

    }

    --n;

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

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

typedef long long ll;

using namespace std;

const int N = 2e5+10 , M = 5e5+10, OO = 0x3f3f3f3f ,  MOD = 1e9+7;

const double EPS = 1e-3;

#define M_PI 3.14159265358979323846

#define clr(arr,val) memset(arr , val , sizeof (arr))

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

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

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

#define pb push_back

#define F first

#define S second

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

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

typedef pair <int,int> pii ;

typedef vector < pii > vii ;

typedef vector < int > vi;

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

//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction

//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

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

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







int n,x;

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

ll dp[N][4];





ll solve(int idx, int preC){ //preColour = (1 : a) -- (2 : b) -- (3 : c) -- (0 : invalid)



    if(idx == n) return 0;



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

    if(~ret) return ret;



    ret = -OO;

    if(preC != 1) ret = max(ret, solve(idx+1 , 1)+a[idx]);

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

    if(preC != 3) ret = max(ret, solve(idx+1 , 3)+c[idx]);



    return ret;



}







int main(){





    //ios_base::sync_with_stdio(0);

    //cin.tie(0);cout.tie(0);





    scanf("%d",&n);

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

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



    memset(dp, -1 , sizeof dp);

    ll ans = solve(0 , 0);

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







    return 0;

}


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



#define fi first

#define se second

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

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

#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)

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

#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)

#define pb push_back

#define el '\n'

#define d(x) cout<< #x<< " " << x<<el

#define ri(n) scanf("%d",&n)



using namespace std;



typedef long long ll;

typedef pair<int,int> ii;

typedef pair<char,int> pci;

typedef tuple<int, int, int> tiii;

typedef pair<ll,ll> pll;

typedef vector<int> vi;



const int MAXN = 1e5+200;



int dp[MAXN][3];



int main(){

    ios_base::sync_with_stdio(false);

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

    int n;

    cin>> n;



    int op[n][3];

    forn(i,n) cin>> op[i][0]>> op[i][1]>> op[i][2];

    forn(i,3) dp[0][i]= op[0][i];



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

        forn(j,3){

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

        }

    }

    --n;

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

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

#include <cstring>

using namespace std;

const int maxn=1e5+5;

const int inf=0x3f3f3f3f;

int dp[maxn][4];

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

int main()

{

   int n;

   cin>>n;

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

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

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

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

   }

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

   return 0;

}


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



#define fi first

#define se second

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

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

#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)

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

#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)

#define pb push_back

#define el '\n'

#define d(x) cout<< #x<< " " << x<<el

#define ri(n) scanf("%d",&n)



using namespace std;



typedef long long ll;

typedef pair<int,int> ii;

typedef pair<char,int> pci;

typedef tuple<int, int, int> tiii;

typedef pair<ll,ll> pll;

typedef vector<int> vi;



const int MAXN = 1e5+200;



int dp[MAXN][3];



int main(){

    ios_base::sync_with_stdio(false);

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

    int n;

    cin>> n;



    int op[n][3];

    forn(i,n) cin>> op[i][0]>> op[i][1]>> op[i][2];

    forn(i,3) dp[0][i]= op[0][i];



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

        forn(j,3){

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

        }

    }

    --n;

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

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;

//const int mod = 1e9+9;

/*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }

*ll lcm(ll x, ll y){return x*(y/gcd(x,y));}

*void exEuclid(int a, int b){

	if(b==0){x = 1; y=0; d=a; return ;}

	exEuclid(b, a%b);

	int x1=y;

	int y1=x-(a/b)*y;

	x=x1; 100000

	y=y1;

} 

* */

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

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;

}


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



#define fi first

#define se second

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

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

#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)

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

#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)

#define pb push_back

#define el '\n'

#define d(x) cout<< #x<< " " << x<<el

#define ri(n) scanf("%d",&n)



using namespace std;



typedef long long ll;

typedef pair<int,int> ii;

typedef pair<char,int> pci;

typedef tuple<int, int, int> tiii;

typedef pair<ll,ll> pll;

typedef vector<int> vi;



const int MAXN = 1e5+200;



int dp[MAXN][3];



int main(){

    ios_base::sync_with_stdio(false);

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

    int n;

    cin>> n;



    int op[n][3];

    forn(i,n) cin>> op[i][0]>> op[i][1]>> op[i][2];

    forn(i,3) dp[0][i]= op[0][i];



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

        forn(j,3){

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

        }

    }

    --n;

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

}