stablegradients/pie-gem5-pairs huggingface dataset:
// 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.2043800995134384x):
#include <bits/stdc++.h>



using namespace std;



const int maxn = 100001;



int value[maxn][3];

int dp[maxn][3];



int main() {

    int N;

    while (cin >> N) {

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

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

        }

        dp[0][0] = value[0][0];

        dp[0][1] = value[0][1];

        dp[0][2] = value[0][2];

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

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

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

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

        }

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

    }

    return 0;

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

using namespace std;

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;

}

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



using namespace std;



const int maxn = 100001;



int value[maxn][3];

int dp[maxn][3];



int main() {

    int N;

    while (cin >> N) {

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

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

        }

        dp[0][0] = value[0][0];

        dp[0][1] = value[0][1];

        dp[0][2] = value[0][2];

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

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

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

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

        }

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

    }

    return 0;

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

using namespace std;



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



int n;

int arr[3][N];



int mem[N][4];

int solve(int i, int last)

{

    if(i==n)

        return 0;

    if(mem[i][last]!=-1)

        return mem[i][last];

    int op1= (last!=1) ? solve(i+1, 1)+arr[0][i] : 0;

    int op2= (last!=2) ? solve(i+1, 2)+arr[1][i] : 0;

    int op3= (last!=3) ? solve(i+1, 3)+arr[2][i] : 0;

    return mem[i][last]=max(op1,max(op2,op3));

}





int main()

{

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

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

    scanf("%d",&n);

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

        scanf("%d %d %d",arr[0]+i,arr[1]+i,arr[2]+i);

    memset(mem, -1, sizeof mem);

    printf("%d\n",solve(0,0));







    return 0;

}


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



using namespace std;



const int maxn = 100001;



int value[maxn][3];

int dp[maxn][3];



int main() {

    int N;

    while (cin >> N) {

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

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

        }

        dp[0][0] = value[0][0];

        dp[0][1] = value[0][1];

        dp[0][2] = value[0][2];

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

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

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

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

        }

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

    }

    return 0;

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

using namespace std;

#define ALL(x) begin(x),end(x)

typedef long long ll;

int OO = 0x3f3f3f3f;



int n;

int a[100005];

int b[100005];

int c[100005];

int mem[100005][3];



int solve(int x, int k)

{

    int op1, op2, op3;

    if(x == n)

        return 0;



    if(mem[x][k] != -1)

        return mem[x][k];



    op1 = op2 = op3 = 0;

    if(k != 1)

        op1 = solve(x+1, 1)+a[x];

    if(k != 2)

        op2 = solve(x+1, 2)+b[x];

    if(k != 3)

        op3 = solve(x+1, 3)+c[x];



    return mem[x][k] = max(op1, max(op2, op3));

}



int main()

{

    memset(mem, -1, sizeof mem);

    cin >> n;

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

    {

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

    }

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

    return 0;

}


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



using namespace std;



const int maxn = 100001;



int value[maxn][3];

int dp[maxn][3];



int main() {

    int N;

    while (cin >> N) {

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

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

        }

        dp[0][0] = value[0][0];

        dp[0][1] = value[0][1];

        dp[0][2] = value[0][2];

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

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

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

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

        }

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

    }

    return 0;

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



using namespace std;



const int N = 1e5 + 9, OO = 0x3f3f3f3f;



int n, points[N][3], dp[N][4];



int solve(int i, int prev){

    if(i == n)  return 0;



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

    if(~ret)    return ret;



    ret = 0;

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

        if(prev != j)   ret = max(ret, points[i][j] + solve(i + 1, j));





    return ret;

}



int main(){



    cin >> n;

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

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



    memset(dp, -1, sizeof dp);



    cout << solve(0, 3);

}


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



using namespace std;



const int maxn = 100001;



int value[maxn][3];

int dp[maxn][3];



int main() {

    int N;

    while (cin >> N) {

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

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

        }

        dp[0][0] = value[0][0];

        dp[0][1] = value[0][1];

        dp[0][2] = value[0][2];

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

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

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

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

        }

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

    }

    return 0;

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

#include <algorithm>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cstring>

#include <vector>

#include <string>

#include <climits>

#include <map>

#include <set>

#include <stack>

#include <queue>

#include <deque>

#include <stdio.h>

//#define int long long

using namespace std;

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

#define endl '\n'

#define OnlineJudgec

#define F first

#define S second

#define  precision(n)  cout << fixed << setprecision(n)

#define clr(v,d ) memset(v, d, sizeof(v))

typedef long long ll;

typedef vector<int> vi;

void init()

{

    cin.tie(0);

    cin.sync_with_stdio(0);

    cout.tie(0);

    #ifdef OnlineJudge

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

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

    #endif

}

ll S(ll x){ll s = 0;while(x){s += x % 10;x /= 10;}return s;} /// sum of digits.

ll powe(ll a , ll n){if(n == 1)return a;return a * powe(a ,n-1);}

ll com(int n,int m){ll z = 1;for(int i = 0; i < m;i++){z = z * ( n - i) / (i + 1) ;}return z;}

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

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

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

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

/// <<------------------------------------------------------------------------------>>

const int mx = 100009;

int n , k;

int arr[mx][4];

int dp[mx][4];

int solve(int idx , int last)

{

     if(idx == n)return 0;

     int &ret = dp[idx][last];

     if(~ret) return ret;

     int A = 0 ,B = 0 ,C = 0;

     if(last != 0)

        A = solve(idx+1 , 0) + arr[idx][0];

     if(last != 1)

        B = solve(idx+1 , 1) + arr[idx][1];

     if(last != 2)

        C = solve(idx+1 , 2) + arr[idx][2];

     return ret = max(A,max(B,C));

}

/// <<------------------------------------------------------------------------------>>

int main()

{

    init();

    cin >> n;

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

    {

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

    }

    clr(dp,-1);

    cout<<solve(0,3);

}


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



using namespace std;



const int maxn = 100001;



int value[maxn][3];

int dp[maxn][3];



int main() {

    int N;

    while (cin >> N) {

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

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

        }

        dp[0][0] = value[0][0];

        dp[0][1] = value[0][1];

        dp[0][2] = value[0][2];

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

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

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

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

        }

        cout << max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])) << 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: 3.042756634690067x):
#include<bits/stdc++.h>

using namespace std;

 

#define             ll  long long

#define            ull  unsigned long long

#define            P_B  push_back

#define            M_P  make_pair

#define         DBG(x)  printf("%s %d\n", #x, x)

#define       DBGLL(x)  printf("%s %lld\n", #x, x)

#define         SCI(x)  scanf("%d",&x)

#define         SCD(x)  scanf("%lf",&x)

#define         SCS(x)  scanf("%s",x)

#define         CLR(x)  memset(x, 0, sizeof(x))

#define        CLRN(x)  memset(x, -1, sizeof(x))

#define        SCLL(x)  scanf("%lld", &x)

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

#define  FORR(i, m, n)  for(int i = m; i < n; i++)

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

#define  SCI3(m, n, o)  scanf("%d%d%d",&m, &n, &o)

#define     SCD2(m, n)  scanf("%lf%lf",&m,&n)

#define  SCD3(m, n, o)  scanf("%lf%lf%lf",&m,&n,&o)

#define    SCLL2(m, n)  scanf("%lld%lld", &m, &n)

#define SCLL3(m, n, o)  scanf("%lld%lld%lld",&m, &n, &o)

#define             vi  vector<int>

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

#define            vll  vector<pair<ll, ll> >

#define            Mod  998244353

#define            INF  1000000000

 



int a[100005][4];

int n;



int main()

{

	SCI(n);

	FOR(i, n)

		FOR(j, 3)

			SCI(a[i][j]);

	FORR(i, 1, n){

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

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

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

	}

	printf("%d\n", max(a[n-1][0], max(a[n-1][1] , a[n-1][2])));    

}
// 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.6785449192928854x):
#include<bits/stdc++.h>

using namespace std;

 

#define             ll  long long

#define            ull  unsigned long long

#define            P_B  push_back

#define            M_P  make_pair

#define         DBG(x)  printf("%s %d\n", #x, x)

#define       DBGLL(x)  printf("%s %lld\n", #x, x)

#define         SCI(x)  scanf("%d",&x)

#define         SCD(x)  scanf("%lf",&x)

#define         SCS(x)  scanf("%s",x)

#define         CLR(x)  memset(x, 0, sizeof(x))

#define        CLRN(x)  memset(x, -1, sizeof(x))

#define        SCLL(x)  scanf("%lld", &x)

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

#define  FORR(i, m, n)  for(int i = m; i < n; i++)

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

#define  SCI3(m, n, o)  scanf("%d%d%d",&m, &n, &o)

#define     SCD2(m, n)  scanf("%lf%lf",&m,&n)

#define  SCD3(m, n, o)  scanf("%lf%lf%lf",&m,&n,&o)

#define    SCLL2(m, n)  scanf("%lld%lld", &m, &n)

#define SCLL3(m, n, o)  scanf("%lld%lld%lld",&m, &n, &o)

#define             vi  vector<int>

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

#define            vll  vector<pair<ll, ll> >

#define            Mod  998244353

#define            INF  1000000000

 



int a[100005][4];

int n;



int main()

{

	SCI(n);

	FOR(i, n)

		FOR(j, 3)

			SCI(a[i][j]);

	FORR(i, 1, n){

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

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

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

	}

	printf("%d\n", max(a[n-1][0], max(a[n-1][1] , a[n-1][2])));    

}
// 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: 3.045619488135452x):
#include<bits/stdc++.h>

using namespace std;

 

#define             ll  long long

#define            ull  unsigned long long

#define            P_B  push_back

#define            M_P  make_pair

#define         DBG(x)  printf("%s %d\n", #x, x)

#define       DBGLL(x)  printf("%s %lld\n", #x, x)

#define         SCI(x)  scanf("%d",&x)

#define         SCD(x)  scanf("%lf",&x)

#define         SCS(x)  scanf("%s",x)

#define         CLR(x)  memset(x, 0, sizeof(x))

#define        CLRN(x)  memset(x, -1, sizeof(x))

#define        SCLL(x)  scanf("%lld", &x)

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

#define  FORR(i, m, n)  for(int i = m; i < n; i++)

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

#define  SCI3(m, n, o)  scanf("%d%d%d",&m, &n, &o)

#define     SCD2(m, n)  scanf("%lf%lf",&m,&n)

#define  SCD3(m, n, o)  scanf("%lf%lf%lf",&m,&n,&o)

#define    SCLL2(m, n)  scanf("%lld%lld", &m, &n)

#define SCLL3(m, n, o)  scanf("%lld%lld%lld",&m, &n, &o)

#define             vi  vector<int>

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

#define            vll  vector<pair<ll, ll> >

#define            Mod  998244353

#define            INF  1000000000

 



int a[100005][4];

int n;



int main()

{

	SCI(n);

	FOR(i, n)

		FOR(j, 3)

			SCI(a[i][j]);

	FORR(i, 1, n){

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

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

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

	}

	printf("%d\n", max(a[n-1][0], max(a[n-1][1] , a[n-1][2])));    

}
// 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.2249329430616562x):
#include<bits/stdc++.h>

using namespace std;

 

#define             ll  long long

#define            ull  unsigned long long

#define            P_B  push_back

#define            M_P  make_pair

#define         DBG(x)  printf("%s %d\n", #x, x)

#define       DBGLL(x)  printf("%s %lld\n", #x, x)

#define         SCI(x)  scanf("%d",&x)

#define         SCD(x)  scanf("%lf",&x)

#define         SCS(x)  scanf("%s",x)

#define         CLR(x)  memset(x, 0, sizeof(x))

#define        CLRN(x)  memset(x, -1, sizeof(x))

#define        SCLL(x)  scanf("%lld", &x)

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

#define  FORR(i, m, n)  for(int i = m; i < n; i++)

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

#define  SCI3(m, n, o)  scanf("%d%d%d",&m, &n, &o)

#define     SCD2(m, n)  scanf("%lf%lf",&m,&n)

#define  SCD3(m, n, o)  scanf("%lf%lf%lf",&m,&n,&o)

#define    SCLL2(m, n)  scanf("%lld%lld", &m, &n)

#define SCLL3(m, n, o)  scanf("%lld%lld%lld",&m, &n, &o)

#define             vi  vector<int>

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

#define            vll  vector<pair<ll, ll> >

#define            Mod  998244353

#define            INF  1000000000

 



int a[100005][4];

int n;



int main()

{

	SCI(n);

	FOR(i, n)

		FOR(j, 3)

			SCI(a[i][j]);

	FORR(i, 1, n){

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

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

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

	}

	printf("%d\n", max(a[n-1][0], max(a[n-1][1] , a[n-1][2])));    

}
// 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.639613908439913x):
#include<bits/stdc++.h>

using namespace std;

 

#define             ll  long long

#define            ull  unsigned long long

#define            P_B  push_back

#define            M_P  make_pair

#define         DBG(x)  printf("%s %d\n", #x, x)

#define       DBGLL(x)  printf("%s %lld\n", #x, x)

#define         SCI(x)  scanf("%d",&x)

#define         SCD(x)  scanf("%lf",&x)

#define         SCS(x)  scanf("%s",x)

#define         CLR(x)  memset(x, 0, sizeof(x))

#define        CLRN(x)  memset(x, -1, sizeof(x))

#define        SCLL(x)  scanf("%lld", &x)

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

#define  FORR(i, m, n)  for(int i = m; i < n; i++)

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

#define  SCI3(m, n, o)  scanf("%d%d%d",&m, &n, &o)

#define     SCD2(m, n)  scanf("%lf%lf",&m,&n)

#define  SCD3(m, n, o)  scanf("%lf%lf%lf",&m,&n,&o)

#define    SCLL2(m, n)  scanf("%lld%lld", &m, &n)

#define SCLL3(m, n, o)  scanf("%lld%lld%lld",&m, &n, &o)

#define             vi  vector<int>

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

#define            vll  vector<pair<ll, ll> >

#define            Mod  998244353

#define            INF  1000000000

 



int a[100005][4];

int n;



int main()

{

	SCI(n);

	FOR(i, n)

		FOR(j, 3)

			SCI(a[i][j]);

	FORR(i, 1, n){

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

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

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

	}

	printf("%d\n", max(a[n-1][0], max(a[n-1][1] , a[n-1][2])));    

}