stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <cstring>

#include <stdio.h>

using namespace std;

const int N=1e+5;

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

int memo[N][4];

int dp(int i,int t)

{

    if(i==n)

        return 0;

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

    if(~ret)

        return ret;

    ret=0;

    if(t!=0)

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

    if(t!=1)

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

    if(t!=2)

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

    return ret;





}

int main()

{

    memset(memo,-1,sizeof memo);

    scanf("%d",&n);

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

    {

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

    }

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

    return 0;

}


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



using namespace std;

int main(){

	int N;

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

	scanf("%d", &N);

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

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

	}

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

		int aa = a[i-1];

		int bb = b[i-1];

		int cc = c[i-1];

		a[i] = a[i] + max(bb, cc);

		b[i] = b[i] + max(aa, cc);

		c[i] = c[i] + max(bb, aa);

	}

	cout << max(a[N], max(b[N], c[N])) << endl;



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

using namespace std;



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

//#define first f

//#define second s



typedef  long long ull;

typedef long long ll;

ll const oo=1e18 ;



int const SZ= (int)1e5+5;

//const ll mod=(ll)1e9+7;

    

//int dp[SZ][SZ];

int arr[SZ][4];

int dp[SZ][4];

int n;

int solve(int r ,int prev ){



    if(r>=n){

        return 0;

    }

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

    if(prev!=-1 && ret !=-1){

        return ret;

    }

    int mx=0;

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

        if(i==prev) continue;

        mx=max(mx,arr[r][i]+solve(r+1,i));

    }

    return ret=mx;

}



int main() {

//#ifdef CLION

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

//    freopen("out.txt", "w", stdin);

//#endif

    

    cin>>n;

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

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

    }

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

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

    return 0;

}

 

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



using namespace std;

int main(){

	int N;

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

	scanf("%d", &N);

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

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

	}

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

		int aa = a[i-1];

		int bb = b[i-1];

		int cc = c[i-1];

		a[i] = a[i] + max(bb, cc);

		b[i] = b[i] + max(aa, cc);

		c[i] = c[i] + max(bb, aa);

	}

	cout << max(a[N], max(b[N], c[N])) << endl;



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

using namespace std;

int main(){

    int n;

    cin>>n;

    long long dp[100005][3];

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

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

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

        long long a,b,c;

        cin>>a>>b>>c;

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

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

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

    }

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

    cout<<ans<<'\n';

}


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



using namespace std;

int main(){

	int N;

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

	scanf("%d", &N);

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

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

	}

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

		int aa = a[i-1];

		int bb = b[i-1];

		int cc = c[i-1];

		a[i] = a[i] + max(bb, cc);

		b[i] = b[i] + max(aa, cc);

		c[i] = c[i] + max(bb, aa);

	}

	cout << max(a[N], max(b[N], c[N])) << endl;



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



using namespace std;



typedef long long ll;

const double eps=1e-6,pi=acos(-1);

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

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

int mem[N][5];



int solve(int i=0,int bk=0){

    if(i==n) return 0;

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

    if(~ret) return ret;

    if(bk!=1)

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

    if(bk!=2)

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

    if(bk!=3)

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

    return ret;

}



int main(){

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

    scanf("%d",&n);

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

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

    memset(mem,-1,sizeof mem);

    printf("%d",solve());

    return 0;

}


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



using namespace std;

int main(){

	int N;

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

	scanf("%d", &N);

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

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

	}

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

		int aa = a[i-1];

		int bb = b[i-1];

		int cc = c[i-1];

		a[i] = a[i] + max(bb, cc);

		b[i] = b[i] + max(aa, cc);

		c[i] = c[i] + max(bb, aa);

	}

	cout << max(a[N], max(b[N], c[N])) << endl;



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

#define lld         long long int

#define llf         long double

#define pb          push_back

#define mp          make_pair

#define IN          insert

#define loopN(n)    for(lld i=0;i<n;i++)

#define loop(p,n)   for(lld i=p;i<=n;i++)

#define rloop(p,n)  for(lld i=n;i>=p;i--)

#define loop2(p,n)  for(lld j=p;j<=n;j++)

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

#define F1          first

#define F2          second

#define INF         2e18

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

#define PI          2*acos(0.0)

#define ISO         ios::sync_with_stdio(false);cin.tie(0)

#define mem(a,b)    memset(a,b,sizeof(a))

#define case(z)     cout<<"Case "<<z<<": ";

using namespace std;

const lld mod=1e9+7;



lld on(lld m,lld p){return m | (1<<p);}

bool ison(lld m,lld p){return (bool)(m & (1<<p));}

lld flip(lld m,lld p){return m ^ (1<<p);}

lld allon(lld p){return (1<<p)-1;}

//______________________________________________________________________________________



lld n;

lld dp[100005][3];

lld a[100005][3];



lld fun(lld p, lld k)

{

    if(p>=n)return 0;

    if(dp[p][k]!=-1)

    {

        return dp[p][k];

    }

    lld ans=-INF;

    if(p==0)

    {

        loopN(3)

        {

            ans=max(ans,a[p][i]+fun(p+1,i));

        }

        return ans;

    }

    else

    {

        loopN(3)

        {

            if(i!=k)

            {

                ans=max(ans,a[p][i]+fun(p+1,i));

            }



        }



    }

    return dp[p][k]=ans;







}





int main()

{

    ISO;



    //lld t;cin>>t;while(t--)

    mem(dp,-1);

    cin>>n;

    loopN(n)loop2(0,2)cin>>a[i][j];

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





    return 0;

}






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



using namespace std;

int main(){

	int N;

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

	scanf("%d", &N);

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

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

	}

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

		int aa = a[i-1];

		int bb = b[i-1];

		int cc = c[i-1];

		a[i] = a[i] + max(bb, cc);

		b[i] = b[i] + max(aa, cc);

		c[i] = c[i] + max(bb, aa);

	}

	cout << max(a[N], max(b[N], c[N])) << endl;



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

     **author : _KMS_

     **created : 01-04-2020

**/

#include<bits/stdc++.h>

using namespace std;

const long long M =3e5+10,MOD=1e9+7;

typedef long long ll;

vector<int>v[M];

bool vis[M];

int dp[M][7];

int arr[10];

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    int t,n;

    cin>>n;

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

    {

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

      {

        cin>>arr[j];

       for(int k=1;k<=3;k++)if(j!=k)dp[i][j]=max(dp[i][j],dp[i-1][k]+arr[j]);

      }

    }



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

    return 0;

}

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

#define fr(i,a,n) for(ll i=a;i<n;i++)

#define YES cout<<"YES"<<endl

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

#define NO cout<<"NO"<<endl

#define pb(x) emplace_back(x)

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

#define vi vector<ll>

#define mi map<ll,ll>

#define pi pair<ll,ll>

#define what(x) cout<<#x<<" ="<<x<<endl;

using namespace std;

using ll =long long;

ll dp[100005][4];

vi a(100005),b(100005),c(100005);

ll n;

ll solve(ll taken,ll i,ll j)

{

    if(i>=n)return 0;

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



    if(taken!=1) dp[i][1]=a[i]+max(solve(1,i+1,2),solve(1,i+1,3));

    if(taken!=2)dp[i][2]=b[i]+max(solve(2,i+1,1),solve(2,i+1,3));

    if(taken!=3)dp[i][3]=c[i]+max(solve(3,i+1,1),solve(3,i+1,2));



    if(taken==1)return max({dp[i][2],dp[i][3]});

    if(taken==2)return max({dp[i][1],dp[i][3]});

    if(taken==3)return max({dp[i][2],dp[i][1]});

    else return max({dp[i][2],dp[i][1],dp[i][3]});

}







int main()

{

    memset(dp,-1,sizeof dp);

    cin>>n;

    fr(i,0,n)cin>>a[i]>>b[i]>>c[i];



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





   /* fr(i,1,4)

    {

        fr(j,0,n)cout<<dp[j][i]<<" ";

        cout<<endl;

    }

*/



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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



    for (int i = 0; i < 3; ++i) dp[1][i] = arr[1][i];



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

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



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


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

using namespace std;



typedef long long ll;

typedef vector<int> vi;



#define PB push_back

#define MP make_pair

#define endl '\n'

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

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



int arr[100000][3];

int n;

int dp[100000][3];

int rec(int row, int col)

{

    if(row == n-1)  return arr[n-1][col];

    if(dp[row][col]>0)

        return dp[row][col];

    else if(col==0)

        return dp[row][col]=arr[row][col]+max(rec(row+1,1),rec(row+1,2));

    else if(col==1)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,2));

    else if(col==2)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,1));

}



int main()

{

    optimize();



    cin>>n;

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

    {

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

            cin>>arr[i][j];

    }

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

    cout<<x;

    return 0;

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

using namespace std;



#define MAX_N 100005

int N, h[MAX_N][3], memo[MAX_N][3];



int main() {

  scanf("%i", &N);

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

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

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

	}

  }

  memset(memo, -1, sizeof memo);

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

  	memo[0][c] = h[0][c];

  }

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

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

  	  int &opt = memo[d][c];

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

  	    if (cc != c) {

  	      opt = max(opt, memo[d - 1][cc] + h[d][c]);

		  /*

  	      if (d == 1) {

  	        printf("%i %i %i %i\n", memo[d - 1][cc], h[d][c], cc, c);

		  }

		  */

		}

	  }

	}

  }

  /*

  puts("\ndebug");

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

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

  	  printf("%i ", memo[d][c]);

	}

	puts("");

  }

  puts("end-debug\n");

  */

  int ans = -1;

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

  	ans = max(ans, memo[N - 1][c]);

  }

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

  

}

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

using namespace std;



typedef long long ll;

typedef vector<int> vi;



#define PB push_back

#define MP make_pair

#define endl '\n'

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

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



int arr[100000][3];

int n;

int dp[100000][3];

int rec(int row, int col)

{

    if(row == n-1)  return arr[n-1][col];

    if(dp[row][col]>0)

        return dp[row][col];

    else if(col==0)

        return dp[row][col]=arr[row][col]+max(rec(row+1,1),rec(row+1,2));

    else if(col==1)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,2));

    else if(col==2)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,1));

}



int main()

{

    optimize();



    cin>>n;

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

    {

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

            cin>>arr[i][j];

    }

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

    cout<<x;

    return 0;

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

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

int main()

{

    int n,i,j,k;

    int a[100005][5];

    scanf("%d",&n);

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

    scanf("%d %d %d",&a[i][1],&a[i][2],&a[i][3]);

    int dp[100005][5];

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

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

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

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

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

    {

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

        {

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

            {

                if(k != j)

                {

                    if(dp[i][j] < dp[i - 1][k] + a[i][j])

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

using namespace std;



typedef long long ll;

typedef vector<int> vi;



#define PB push_back

#define MP make_pair

#define endl '\n'

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

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



int arr[100000][3];

int n;

int dp[100000][3];

int rec(int row, int col)

{

    if(row == n-1)  return arr[n-1][col];

    if(dp[row][col]>0)

        return dp[row][col];

    else if(col==0)

        return dp[row][col]=arr[row][col]+max(rec(row+1,1),rec(row+1,2));

    else if(col==1)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,2));

    else if(col==2)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,1));

}



int main()

{

    optimize();



    cin>>n;

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

    {

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

            cin>>arr[i][j];

    }

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

    cout<<x;

    return 0;

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



using namespace std;



vector<vector<int> > v;

int ans[100005][3];

queue<pair<int,pair<int,int> > >s;

int maior,a=0;



void dp(int i, int bloq, int sum) {

  if(ans[i-1][bloq]>sum)

    return;

  

  if (i>=v.size())

    maior = max(sum, maior);

  else {

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

      if (bloq != j) {



        if(ans[i][j]==-1) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }

        else if (ans[i][j]<sum+v[i][j]) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }



        //dp(i+1, j, sum+v[i][j]);

      }

    }

  }

}



int main () {

  int n;

  cin>>n;

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

    int a,b,c;

    cin>>a>>b>>c;

    v.push_back({a,b,c});

  }



  maior=0;

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

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

    s.push({v[0][i],{1,i}});

    //dp(1, i, v[0][i]);

  }



  while(!s.empty()) {

    pair<int,pair<int,int> > aux = s.front();

    dp(aux.second.first, aux.second.second, aux.first);

    s.pop();

  }



  cout<<maior<<endl;



}




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

using namespace std;



typedef long long ll;

typedef vector<int> vi;



#define PB push_back

#define MP make_pair

#define endl '\n'

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

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



int arr[100000][3];

int n;

int dp[100000][3];

int rec(int row, int col)

{

    if(row == n-1)  return arr[n-1][col];

    if(dp[row][col]>0)

        return dp[row][col];

    else if(col==0)

        return dp[row][col]=arr[row][col]+max(rec(row+1,1),rec(row+1,2));

    else if(col==1)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,2));

    else if(col==2)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,1));

}



int main()

{

    optimize();



    cin>>n;

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

    {

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

            cin>>arr[i][j];

    }

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

    cout<<x;

    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;



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

using namespace std;



typedef long long ll;

typedef vector<int> vi;



#define PB push_back

#define MP make_pair

#define endl '\n'

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

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



int arr[100000][3];

int n;

int dp[100000][3];

int rec(int row, int col)

{

    if(row == n-1)  return arr[n-1][col];

    if(dp[row][col]>0)

        return dp[row][col];

    else if(col==0)

        return dp[row][col]=arr[row][col]+max(rec(row+1,1),rec(row+1,2));

    else if(col==1)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,2));

    else if(col==2)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,1));

}



int main()

{

    optimize();



    cin>>n;

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

    {

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

            cin>>arr[i][j];

    }

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

    cout<<x;

    return 0;

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

using namespace std;

const int oo = 1e9;

int number;

const int nx = 1e5+5;

int ac[nx][3];

int dyn[3][nx];

int init(int a, int i){

	if(i == number) return 0;

	if(dyn[a][i] != -1) return dyn[a][i];

	int& res = dyn[a][i];

	

	if(a==0){

		res=max(res, init(1, i+1)+ac[i][0]);

		res=max(res, init(2, i+1)+ac[i][0]);

	}

	if(a==1){

		res=max(res, init(0, i+1)+ac[i][1]);

		res=max(res, init(2, i+1)+ac[i][1]);

	}

	if(a==2){

		res=max(res, init(0, i+1)+ac[i][2]);

		res=max(res, init(1, i+1)+ac[i][2]);

	}

	

	return res;

}

int main(){

	cin>>number;

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

	memset(dyn, -1, sizeof dyn);

	cout<<max(init(0,0),max(init(1,0),init(2,0)))<<"\n";

	return 0;

}




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

using namespace std;



typedef long long ll;

typedef vector<int> vi;



#define PB push_back

#define MP make_pair

#define endl '\n'

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

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



int arr[100000][3];

int n;

int dp[100000][3];

int rec(int row, int col)

{

    if(row == n-1)  return arr[n-1][col];

    if(dp[row][col]>0)

        return dp[row][col];

    else if(col==0)

        return dp[row][col]=arr[row][col]+max(rec(row+1,1),rec(row+1,2));

    else if(col==1)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,2));

    else if(col==2)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,1));

}



int main()

{

    optimize();



    cin>>n;

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

    {

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

            cin>>arr[i][j];

    }

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

    cout<<x;

    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;



int n;

const int nx = 1e5+5;

int ac[nx][3];

int dp[3][nx];

int go(int x, int i){

	if(i==n) return 0;

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

	int& ans = dp[x][i];

	if(x==0)

	{

		ans=max(ans, go(1, i+1)+ac[i][0]);

		ans=max(ans, go(2, i+1)+ac[i][0]);

	}

	if(x==1)

	{

		ans=max(ans, go(0, i+1)+ac[i][1]);

		ans=max(ans, go(2, i+1)+ac[i][1]);

	}

	if(x==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.1812073064058035x):
#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef vector<int> vi;



#define PB push_back

#define MP make_pair

#define endl '\n'

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

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



int arr[100000][3];

int n;

int dp[100000][3];

int rec(int row, int col)

{

    if(row == n-1)  return arr[n-1][col];

    if(dp[row][col]>0)

        return dp[row][col];

    else if(col==0)

        return dp[row][col]=arr[row][col]+max(rec(row+1,1),rec(row+1,2));

    else if(col==1)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,2));

    else if(col==2)

        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,1));

}



int main()

{

    optimize();



    cin>>n;

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

    {

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

            cin>>arr[i][j];

    }

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

    cout<<x;

    return 0;

}