stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)

#define rep(i, count) REP(i, 0, count)

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



typedef long long ll;

typedef unsigned long long ull;



int N;

int a[100000 + 10] = {};

int b[100000 + 10] = {};

int c[100000 + 10] = {};



int main(void) {

    cin >> N;

    rep(i, N) {

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

    }



    int dp[100010][3] = {};

    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])) << endl;;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)

#define rep(i, count) REP(i, 0, count)

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



using ll = long long;

using ull = unsigned long long;

using veci = vector<int>;

using vecll = vector<ll>;

using vecull = vector<ull>;



int main(void) {



    ll N;

    cin >> N;

    vector<vecll> abc(N + 1, vecll(3));



    REP(i, 1, N + 1) {

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

    }



    vector<vecll> dp(N + 1, vecll(3, 0));



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

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

            dp[i + 1][k] = max(dp[i + 1][k], dp[i][(k + 1) % 3] + abc[i + 1][k]);

            dp[i + 1][k] = max(dp[i + 1][k], dp[i][(k + 2) % 3] + abc[i + 1][k]);

        }

    }



    ll ans = max(dp[N][0], max(dp[N][1], dp[N][2]));



    cout << ans << endl;



    return 0;

}


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

using namespace std;

#define ll long long 



#define F first

#define S second



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

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

const double EPS= 1e-8 ;

const double PI  = acos(-1.0);

#define inf INT_MAX

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }





struct hap{

	int a ; 

	int b ; 

	int c ; 

	

};

 int a[100005][3] ;   // dont ; 

 int n ;  

 int dp[100005][4] ;  



int sol ( int ind , int l ) 

{

	if (ind >= n ) return 0 ; 

	

	

	

	int &res = dp[ind][l]; 

	if ( res != -1 ) return res ; 

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

	{

		if ( l != i )

		{

			res = max (res, sol( ind+1 , i ) + a[ind][i]) ; 

			

		}

	}

	

	

	return res ; 

	

}









int main()

 {

 

 cin>>n ; 



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

 {

	 int x , y , z ; 

	 cin>>x >> y >> z ; 

	 a[i][0]= x ; 

	 a[i][1] = y ; 

	 a[i][2] = z ; 

	 

	 

 }

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

 

  

  int ans = sol ( 0 , 3 ) ; 

  cout<< ans << endl; 







 return 0 ;

}













 

 

 

 

 

 



 


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

#define ll long long 



#define F first

#define S second



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

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

const double EPS= 1e-8 ;

const double PI  = acos(-1.0);

#define inf INT_MAX

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }











int main()

 {

 int n ; 

 cin>>n; 

 int a[n][3]  ;

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

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

	 cin>>a[i][j] ; 

 }

 

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

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

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

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

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

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

 {

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

	 {

		 if (k!= j)

		 {

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

		 }

	 }

 }

 

 int ans = max ( { dp[n-1][0], dp[n-1][1], dp [n-1 ][2]}) ; 

 cout << ans << endl; 

 

  







 return 0 ;

}













 

 

 

 

 

 



 


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <assert.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <string.h>

#include <cmath>

#include <algorithm>

#include <iomanip>

using namespace std;



const int N = 1e5 + 2;



int n, a[4][N];

long long dp[N][4];



long long calc(int i, int prv)

{

    if (i == n)

    {

        return 0;

    }

    long long &ret = dp[i][prv];

    if (ret != -1)

    {

        return ret;

    }

    ret = 0;

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

    {

        if (j != prv)

        {

            ret = max(ret, calc(i + 1, j) + a[j][i]);

        }

    }

    return ret;

}



int main()

{

    memset(dp, -1, sizeof dp);

    cin >> n;

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

    {

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

        {

            cin >> a[j][i];

        }

    }

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

    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <assert.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <string.h>

#include <cmath>

#include <algorithm>

#include <iomanip>

#define ll long long

using namespace std;



const int N = 1e5 + 7;

const long long oo = 1e18L + 5;



int n, a[N][3];



int main() {

    cin >> n;

    vector<vector<ll>> dp(n + 2, vector<ll>(3, -oo));

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

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

            cin >> a[i][j];

        }

    }

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

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

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

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

                if (k != j) {

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

                }

            }

        }

    }

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

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

using namespace std;



int main(){

    int n, a[200000], b[200000], c[200000], dp[200000][5];

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

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

    }

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

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD = 1e9+7;

const int INF = 2e9;



int n, abc[100005][3], dp[100005][3];



int main(){



    cin >> n;

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

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

            cin >> abc[i][j];

        }

    }

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

        dp[0][i] = abc[0][i];

    }

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

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

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

        }

    }

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

}

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



using namespace std;

typedef long long ll;



ll n,arr[100005][5],mem[100005][5];



ll dp(int pos, int last){

    if(pos==n)return 0;

    if(mem[pos][last]!=-1)return mem[pos][last];

    ll res=0;

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

        if(i!=last)res=max(res,dp(pos+1,i)+arr[pos][i]);

    }

    return mem[pos][last]=res;

}



int main(){

    ios_base::sync_with_stdio(0);

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

    cin>>n;

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

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

    }

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

    cout<<dp(0,3);

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;



ll n,arr[100005][5],dp[100005][5];



int main(){

    ios_base::sync_with_stdio(0);

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

    cin>>n;

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

    dp[0][0]=arr[0][0];dp[0][1]=arr[0][1];dp[0][2]=arr[0][2];

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

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

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

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

    }

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

}

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

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

#define debug(x)   cerr<<#x<<": "<<x<<endl;

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

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

#define endl       '\n'

#define MAX        1000000

typedef long long int ll;

using namespace std;



const ll mod = 1e9+7;





int n ;

vector<tuple<int,int,int>>arr;



int dp[100005][4];





int recur(int ind , int pre) {

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



    if(dp[ind][pre] != -1)return dp[ind][pre];



    int used_a =  0 , used_b = 0 ,  used_c = 0;

    if(pre!=1)

        used_a = get<0>(arr[ind]) + recur(ind + 1 , 1);

    if(pre!=2)

        used_b = get<1>(arr[ind]) + recur(ind + 1 , 2);

    if(pre!=3)

        used_c = get<2>(arr[ind]) + recur(ind + 1 , 3);

    return dp[ind][pre] = max({used_a , used_b , used_c});

}







void solve(){

    cin >>n;

    arr.resize(n + 1);

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



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



    cout<<recur(1,0)<<endl; 

    return;

}











int main(){

    fastio

    int test=1;

    while(test--)

        solve();

    return 0;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

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

typedef long long int ll;

using namespace std;



const ll     mod = 1e9+7;

const double eps = 1e-9;





int n;

const int N=1e5+10;

int a[N][3],dp[N][4];



int rec(int ind,int p) {

    if(ind==n)

        return 0;

    int &cur=dp[ind][p+1];

    if(cur!=-1)return cur;

    int ans=0;

    ans=max({ans,(p!=0)*(a[ind][0]+rec(ind+1,0)),(p!=1)*(a[ind][1]+rec(ind+1,1)),(p!=2)*(a[ind][2]+rec(ind+1,2))});

    return cur=ans;

}



void solve(){

    cin >> n;

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

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

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

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

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

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

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

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

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

    }

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

}





int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    int t=1;

    while(t--)

        solve();

    return  0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
//This is not my solution

#include<bits/stdc++.h>

using namespace std;

#define ll long long int

const int N=1e5+5;

const int inf=0x3f3f3f3f;

ll dp[3][N]={inf},v[3][N],k,n;



ll check(int index);





int main(){

    ios_base::sync_with_stdio(false);

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

ll i,j,m;

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



    cin>>n;

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

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

    for(auto it:{0,1,2})

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

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

        for(auto it:{0,1,2}){

            for(auto iit:{0,1,2}){

                if(it!=iit)

                    dp[it][i]=max(dp[it][i],v[it][i]+dp[iit][i-1]);

            }

        }

    }

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

    // for(auto it:{0,1,2})

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

    //         cout<<dp[it][i]<<" \n"[i==n-1];

    return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

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

typedef long long int ll;

using namespace std;



const ll     mod = 1e9+7;

const double eps = 1e-9;





int n;

const int N=1e5+10;

int a[N][3],dp[N][4];



int rec(int ind,int p) {

    if(ind==n)

        return 0;

    int &cur=dp[ind][p+1];

    if(cur!=-1)return cur;

    int ans=0;

    ans=max({ans,(p!=0)*(a[ind][0]+rec(ind+1,0)),(p!=1)*(a[ind][1]+rec(ind+1,1)),(p!=2)*(a[ind][2]+rec(ind+1,2))});

    return cur=ans;

}



void solve(){

    cin >> n;

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

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

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

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

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

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

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

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

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

    }

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

}





int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    int t=1;

    while(t--)

        solve();

    return  0;

}


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

#include <ext/pb_ds/assoc_container.hpp>

#define F first

#define S second

#define PB push_back

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

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

using namespace __gnu_pbds;

using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pi;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;



const int OO = 1e9+7;

const int MOD = 1e9+7;

const int N = 1e5+7;



int mem[N][5];

int n;

int a[5][N];



int dp(int i,int t)

{

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

    if (ret != -1) return ret;

    if (i == n) return 0;

    ret = 0;

    REP(j,0,2)

    {

        if (j == t) continue;

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

    }

    return ret;

}



int main()

{

    //ios::sync_with_stdio(0);

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

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

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



    memset(mem,-1,sizeof mem);

    scanf("%d",&n);

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

    printf("%d\n",dp(0,3));



    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#define F first

#define S second

#define PB push_back

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

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

using namespace __gnu_pbds;

using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pi;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;



const int OO = 1e9+7;

const int MOD = 1e9+7;

const int N = 1e5+7;



ll dp[N][5];

int n;

ll a[N][5];





int main()

{

    //ios::sync_with_stdio(0);

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

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

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



    scanf("%d",&n);

    REP(i,0,n-1) scanf("%lld %lld %lld",&a[i][0], &a[i][1], &a[i][2]);



    REP(j,0,2) dp[0][j] = a[0][j];



    REP(i,1,n-1)

    {

        REP(j,0,2)

        {

            REP(k,0,2)

            {

                if (k==j) continue;

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

            }

        }

    }

    ll ans = 0;

    REP(i,0,2) ans = max(ans,dp[n-1][i]);

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



    return 0;

}


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

using namespace std;

const int N = 1e5 + 1;

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

int calc(int i , int op){

    if(i == n)

        return 0;

    int &ret = dp[i][op];

    if(ret != -1)

        return ret;

    ret = 0;

    if(op != 0){

        ret = max(ret , calc(i + 1 , 0) + a[i]);}

    if(op != 1)

        ret = max(ret , calc(i + 1 , 1) + b[i]);

    if(op != 2)

        ret = max(ret , calc(i + 1 , 2) + c[i]);

    return ret;

    }

int main(){

    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);

    cout<<calc(0,3);

    return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int N = 1e5 + 1;

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

int main(){

    scanf("%d", &n );

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

        scanf("%d%d%d", &a[i] , &b[i] , &c[i]);

    }

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

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

    dp[0][2] = c[0];

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

    }

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

    return 0;

}

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

using namespace std;

//vector<int> is passed by &

#define maxholidays 100000



int dp[maxholidays][3];

vector<vector<int>> joy;



int getMostJoyToDay(int D, int A)

{

	if(dp[D][A]!=-1)

		return dp[D][A];



	if(D==0)

		return joy[D][A];



	if(A==0)

		return dp[D][A] = joy[D][A] + max( getMostJoyToDay(D-1,1) , getMostJoyToDay(D-1,2) );

	else if(A==1)

		return dp[D][A] = joy[D][A] + max( getMostJoyToDay(D-1,0) , getMostJoyToDay(D-1,2) );

	else //(A==2)

		return dp[D][A] = joy[D][A] + max( getMostJoyToDay(D-1,0) , getMostJoyToDay(D-1,1) );

}





int main()

{

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

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

			dp[i][j]=-1;



	int n;	

	cin >> n ;

	int t;

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

	{

		vector<int> x;

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

		{

			cin >> t;

			x.push_back(t);

		}

		joy.push_back(x);

	}

	int a = getMostJoyToDay(n-1,0);

	int b = getMostJoyToDay(n-1,1);

	int c = getMostJoyToDay(n-1,2);

	cout << max(max(a,b),c) <<endl;



	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

//ask the right questions.		



int main() 

{

	int n,x;

	cin >> n;

	vector<vector<int>> v;

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

	{

		vector<int> p;

		cin >> x;

		p.push_back(x);

		cin >> x;

		p.push_back(x);

		cin >> x;

		p.push_back(x);

		v.push_back(p);

	}



	//max fun on day n obtainable if activity j=0,1,2 is done on that day 

	int dp[n+1][3];

	

	//trivial case:

	dp[0][0]=0;

	dp[0][1]=0;

	dp[0][2]=0;



	//base case:

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

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

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



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

	{

		//TIP: on ith day you could have done any of the 3 activites only, 

		//this fixes the activity done on prev day

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

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

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

	}

	

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

	ans = max(ans, dp[n][2]);

	cout << ans <<endl; 

	return 0;

	

}

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

#define ll long long int

#define mp make_pair

#define pb push_back

#define ff first 

#define ss second

#define mod 1000000007

#define lim 100005

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

using namespace std;



int main()

{

	int i,j,n,k,t,a[lim],b[lim],c[lim],dp[lim][3] = {};

	cin>>n;

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

	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];

	}

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

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define ull uint64_t

#define ll long long int

#define pb push_back

#define mp make_pair

#define ff first

#define ss second

#define mx5 100005

#define mx6 1000005

#define mod 1000000007

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

using namespace std;



int main() {

    nfs

    int i, j, n, fa, fb, fc, a, b, c;

    fa = fb = fc = 0;

    cin >> n;

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

        cin >> a >> b >> c;

        tie(fa, fb, fc) = make_tuple(a + max(fb, fc), b + max(fa, fc), c + max(fa, fb));

    }

    cout << max({fa, fb, fc});

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <stdio.h>

#include <vector>

#include <string>

#include <set>

#include <queue>

#include <cmath>

#include <map>

#include <algorithm>

#include <stack>

#include <cstring>



#define ll long long

#define MP make_pair

#define PB push_back

#define P push

#define f first

#define se second

#define S size()

#define B begin()

#define E end()

#define PI acos(-1)

#define fscan1(n)  scanf("%d",&(n));

#define fscan2(n,m)  scanf("%d %d",&(n),&(m));

#define fscan3(n,m,k)  scanf("%d %d %d",&(n),&(m),&(k));



const int N = 1e5 + 100;

const int M = 2e5 + 100;

const ll oo = 1e18;



int n, m, k, t, q, h, a, b, c, x, y, z;

using namespace std;



int ar[N][3];

int dp[N][3];





int rec(int ind, int act){

	if(ind == n)return 0;



	int &ret = dp[ind][act];



	if(ret != -1)return ret;



	return ret = max(rec(ind + 1, (act + 1) % 3),rec(ind + 1, (act + 2) % 3)) + ar[ind][act];

}





int main(){

	

	cin >> n;

	memset(dp, -1, sizeof dp);

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

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

	}

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



	cout << ans << endl;

	



	return 0;

 }






// Optimized solution to the same problem (faster):
#include <iostream>

#include <stdio.h>

#include <vector>

#include <string>

#include <set>

#include <queue>

#include <cmath>

#include <map>

#include <algorithm>

#include <stack>

#include <cstring>



#define ll long long

#define MP make_pair

#define PB push_back

#define P push

#define f first

#define se second

#define S size()

#define B begin()

#define E end()

#define PI acos(-1)

#define fscan1(n)  scanf("%d",&(n));

#define fscan2(n,m)  scanf("%d %d",&(n),&(m));

#define fscan3(n,m,k)  scanf("%d %d %d",&(n),&(m),&(k));



const int N = 1e5 + 100;

const int M = 2e5 + 100;

const ll oo = 1e18;



int n, m, k, t, q, h, a, b, c, x, y, z;

using namespace std;



int ar[N][3];

int dp[N][3];





int main(){

	

	cin >> n;

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

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

	}

	

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

		if( i == 0){

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

			continue;

		}

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

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

		}

	}



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



	return 0;

 }






// Fastest known solution for this problem: