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

using namespace std;

int vacation(int a[][3],int n,int last,int i,int dp[100001][3]){

    if(i==n){return 0;    }

    if(dp[i][last]!=-1){return dp[i][last];}

    int r;

    if(i==0){

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

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

        

    }

    else {

        if(last==0){

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

        }

        else if(last==1){

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

        }

        else if(last==2){

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

        }

    }

    return dp[i][last];

}

int main() {

	int n;

	cin >> n;

	int a[n][3];

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

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

	} 

	int dp[100001][3];

	memset(dp,-1,sizeof dp);

	cout<<vacation(a,n,0,0,dp);

	return 0;

}

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

using namespace std;



int main() {

    int n;

    cin >> n;

    int a[n][3];

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

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

    }

    int dp[n][3]; 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]=max(dp[i-1][1],dp[i-1][2])+a[i][0];

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

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

    }

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

	return 0;

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

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

#define rep(i,n) repd(i,0,n)

typedef long long ll;

using namespace std;

const int MOD = 1000000007;

const int INF = 1010000000;

const double EPS = 1e-10;

const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 



int main(){

  int n, a[100000][3];cin>>n;

  rep(i,n)cin>>a[i][0]>>a[i][1]>>a[i][2];

  int dp[100000][3];rep(i,100000)rep(j,3)dp[i][j] = 0;

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

  repd(i,1,n){

    rep(j,3){

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

    }

  }

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

}




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

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

#define rep(i,n) repd(i,0,n)

#define int long long

typedef long long ll;

const int MOD = 1000000007;

const int INF = 1010000000;

const double EPS = 1e-10;

using namespace std;

const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 



signed main() {

  int n;cin>>n;

  int dp[110000][3];

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

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

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

  rep(i,n-1){

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

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

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

  }

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

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

using namespace std;

#define mp make_pair

#define pb push_back

#define emb emplace_back

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

#define N  99999

#define f first 

#define em emplace

#define s second

using lint=long long int;



typedef pair<int, int> pii;

typedef pair<double, double> pdd;

typedef vector<double> vd;

typedef vector<bool> vb;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<vvi> vvvi;

typedef vector<string> vs;



 

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

 

#define cins(s) string s; cin>>s;

#define cini(i) lint i; cin>>i;

#define cind(d) double d; cin>>d;

#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }

#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

#define z 1000000007 

const int INF=1e9+5;

   vector<vector<int>> v(100005);

 

void cleari(){

  for(int i=0;i<99999;i++) v[i].clear();

}

 void solve(){



   cleari();

    

   cini(n); 

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

   {

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

        { 

          int a;

           cin>>a; 

           v[i].pb(a);

        }

   }

   

  int m;

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

    

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

          m=0;

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

         if(j!=k)

         {

            m=max(v[i-1][k],m);

         }

       }

       v[i][j]+=m;



     }



  }



  int mx=max(v[n-1][0],v[n-1][1]);

      mx=max(v[n-1][2],mx);



      cout<<mx<<endl;





     



 }





 

 

int main()

{ 

  fast;

 /* #ifndef ONLINE_JUDGE

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

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

  #endif*/

  







  solve();

 }

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

using namespace std;

#define mp make_pair

#define pb push_back

#define emb emplace_back

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

#define N  99999

#define f first 

#define em emplace

#define s second

using lint=long long int;



typedef pair<int, int> pii;

typedef pair<double, double> pdd;

typedef vector<double> vd;

typedef vector<bool> vb;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<vvi> vvvi;

typedef vector<string> vs;



 

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

 

#define cins(s) string s; cin>>s;

#define cini(i) lint i; cin>>i;

#define cind(d) double d; cin>>d;

#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }

#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

#define z 1000000007 





void solve(){

  

  cini(n);

  vector<int>dp(3);





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

     vector<int>v(3);



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

           cin>>v[j];

            int m=0;

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



              if(j!=k){

                m=max(dp[k],m);

              }

           }

           v[j]+=m;

     }

    dp.clear();

    v.swap(dp);

  }

     

     int a=*max_element(dp.begin(),dp.end());

     cout<<a<<endl;









}

 

 

int main()

{ 

 

  







  solve();

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

using namespace std;

#define mp make_pair

#define pb push_back

#define emb emplace_back

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

#define N  99999

#define f first 

#define em emplace

#define s second

using lint=long long int;



typedef pair<int, int> pii;

typedef pair<double, double> pdd;

typedef vector<double> vd;

typedef vector<bool> vb;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<vvi> vvvi;

typedef vector<string> vs;



 

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

 

#define cins(s) string s; cin>>s;

#define cini(i) lint i; cin>>i;

#define cind(d) double d; cin>>d;

#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }

#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

#define z 1000000007 

const int INF=1e9+5;

   vector<vector<int>> v(100005);

 

void cleari(){

  for(int i=0;i<99999;i++) v[i].clear();

}

 void solve(){



   cleari();

    

   cini(n); 

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

   {

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

        { 

          int a;

           cin>>a; 

           v[i].pb(a);

        }

   }

   

  int m;

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

    

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

          m=0;

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

         if(j!=k)

         {

            m=max(v[i-1][k],m);

         }

       }

       v[i][j]+=m;



     }



  }



  int mx=max(v[n-1][0],v[n-1][1]);

      mx=max(v[n-1][2],mx);



      cout<<mx<<endl;





     



 }





 

 

int main()

{ 

  fast;

 /* #ifndef ONLINE_JUDGE

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

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

  #endif*/

  







  solve();

 }

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

using namespace std;

#define mp make_pair

#define pb push_back

#define emb emplace_back

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

#define N  99999

#define f first 

#define em emplace

#define s second

using lint=long long int;



typedef pair<int, int> pii;

typedef pair<double, double> pdd;

typedef vector<double> vd;

typedef vector<bool> vb;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<vvi> vvvi;

typedef vector<string> vs;



 

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

 

#define cins(s) string s; cin>>s;

#define cini(i) lint i; cin>>i;

#define cind(d) double d; cin>>d;

#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }

#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

#define z 1000000007 





void solve(){

  

  cini(n);

  vector<int>dp(3);





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

     vector<int>v(3);



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

           cin>>v[j];

            int m=0;

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



              if(j!=k){

                m=max(dp[k],m);

              }

           }

           v[j]+=m;

     }

    dp.clear();

    v.swap(dp);

  }

     

     int a=*max_element(dp.begin(),dp.end());

     cout<<a<<endl;









}

 

 

int main()

{ 

  fast;









  solve();

 }
// Slower C++ solution:


#include <bits/stdc++.h>



#define pb push_back

#define fst first

#define snd second

#define INF 0x7fffffff

#define INFLL 0x7FFFFFFFFFFFFFFF

#define lenA(ar) sizeof(ar)/sizeof(*ar)

#define lenrows(mat) sizeof(mat)/sizeof(*mat)

#define lencols(mat) sizeof(*mat)/sizeof(**mat)

#define fill(a,c) memset(&a, c, sizeof(a))

#define fore(i,x,y) for(ll i=x;i<y;i++)

#define foreI(i,x,y) for(ll i=x-1;i>=y;i--)

#define max2(a,b) max(a, b)

#define max3(a,b,c) max2(max2(a,b),c)

#define min2(a,b) min(a, b)

#define min3(a,b,c) min2(min2(a,b),c)

#define MOD 1000000009

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

#define rall(x) (x).rbegin(), (x).rend()

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



typedef long long ll;

typedef unsigned long long ull;



using namespace std;

ll arr[100010][3];

ll dp[100010][3];

int n;

ll solve(int i, int j){

    if(i==n-1) return arr[i][j];

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

    if(r>-1) return r;

    ll a = 0; ll b = 0;ll c = 0; ll act=arr[i][j];

    if(j!=0) a=solve(i+1, 0)+act;

    if(j!=1) b=solve(i+1, 1)+act;

    if(j!=2) c=solve(i+1, 2)+act;

   return r=max3(a,b,c);

}



int main() {

     

    cin>>n;

    arr[n][3];

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

    fore(i,0,n){

        fore(j,0,3){

            cin>>arr[i][j];

        }

    }



    cout<<max3(solve(0,0),solve(0,1),solve(0,2))<<"\n";



    return 0;

}






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



#define pb push_back

#define fst first

#define snd second

#define INF 0x7fffffff

#define INFLL 0x7FFFFFFFFFFFFFFF

#define lenA(ar) sizeof(ar)/sizeof(*ar)

#define fill(a,c) memset(&a, c, sizeof(a))

#define fore(i,x,y) for(ll i=x;i<y;i++)

#define foreI(i,x,y) for(ll i=x-1;i>=y;i--)

#define max3(a,b,c) max(max(a,b),c)

#define min3(a,b,c) min(min(a,b),c)

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

#define rall(x) (x).rbegin(), (x).rend()

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



typedef long long ll;

typedef unsigned long long ull;



using namespace std;



int main() {FIN;

   

    int n;cin>>n;

    int mat[n][3];

    ll dp[n][3]; fill(dp,0);

    fore(i,0,n){

        fore(j,0,3){

            cin>>mat[i][j];

        }

    }

    dp[0][0] = mat[0][0];

    dp[0][1] = mat[0][1];

    dp[0][2] = mat[0][2];

    fore(i,0,n-1){

        fore(j,0,3){

            fore(k,0,3){

                if(j!=k)

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

            }

        }

    }

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

    return 0;

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

#define INF 2147483647

#define inf 1000000007

#define SYOU(x) setprecision(x+1)

#define abs(x,y) (max(x,y)-min(x,y))

#define lol long long

#define mp make_pair

#define fi first

#define se second

using namespace std;

lol a,b;

lol w[111000],v[111000],q[111000];

lol mem[111000][5];

lol dp(int n,int m){

    if(n==a) return 0;

    if(mem[n][m]!=-1) return mem[n][m];

    if(m==0) return mem[n][m]=max(dp(n+1,1),dp(n+1,2))+w[n];

    if(m==1) return mem[n][m]=max(dp(n+1,0),dp(n+1,2))+v[n];

    return mem[n][m]=max(dp(n+1,0),dp(n+1,1))+q[n];

}

signed main(){

  cin.tie(0);

  ios::sync_with_stdio(false);

  lol c=1,d=1,e=0,f=0,g=0,h=0;

  string s;

  cin >>a;

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

      cin >>w[n]>>v[n]>>q[n];

  }

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

  cout <<max(dp(0,0),max(dp(0,1),dp(0,2)))<<'\n';

  return (0);

}


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

#define longinf 9223372036854775807LL

#define intinf 2147483647

#define inf 998244353

#define lol long long

#define in(n,s) insert(n,s)//ノート参照

#define SYOU(x) setprecision(x)

#define abs(x,y) (max(x,y)-min(x,y))

#define mp make_pair

#define fi first

#define se second

using namespace std;

lol a,b,c,d,e=0,g,h;

int i[111110][3];

lol dp[100011][3];

signed main(){

  cin.tie(0);

  ios::sync_with_stdio(false);

  cin >>a;

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

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

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

  }

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

  dp[0][1]=i[0][1];

  dp[0][2]=i[0][2];

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

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

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

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

  }

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

  return (0);

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

  #define endl "\n"

  #define ll long long int

  #define vi vector<int>

  #define vll vector<ll>

  #define vvi vector < vi >

  #define pii pair<int,int>

  #define pll pair<long long, long long>

  #define mod 1000000007

  #define inf 1000000000000000001;

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

  #define mp(x,y) make_pair(x,y)

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

  #define pb push_back

  #define f first

  #define se second

  

  using namespace std;

  ll arr[100005][3];

  ll dp[100005][3];



  ll func(ll x,ll y,ll n){

    if(x>=n)

      return 0;

    if(dp[x][y]!=-1 && y!=-1)

      return dp[x][y];



    ll sum1=0,sum2=0,sum3=0,sum=0;



    if(y!=0)

      sum1=arr[x][0]+func(x+1,0,n);

    

    if(y!=1)

      sum2=arr[x][1]+func(x+1,1,n);

    

    if(y!=2)

      sum3=arr[x][2]+func(x+1,2,n);

    

    sum=max({sum1,sum2,sum3});

    dp[x][y]=sum;



    return sum;

  }



  int main()

  {

    std::ios::sync_with_stdio(false);

    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;



    cin>>n;

    mem(arr,0);

    mem(dp,-1);



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

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

      {

        cin>>arr[i][j];

      }

    }



    cout<<func(0,-1,n);





    return 0;

  }

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

  #define endl "\n"

  #define ll long long int

  #define vi vector<int>

  #define vll vector<ll>

  #define vvi vector < vi >

  #define pii pair<int,int>

  #define pll pair<long long, long long>

  #define mod 1000000007

  #define inf 1000000000000000001;

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

  #define mp(x,y) make_pair(x,y)

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

  #define pb push_back

  #define f first

  #define se second

  

  using namespace std;

  int main()

  {

    std::ios::sync_with_stdio(false);

    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;



    cin>>n;



    ll arr[n+1][3],dp[n+1][3];

    mem(arr,0); mem(dp,0);



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

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

      {

        cin>>arr[i][j];

      }

    }



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

    {

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

      {

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

      }

    }



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



    return 0;

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

using namespace std;

using ll = long long;



template<class T>

void chmax(T &a, T b)

{

	if (a < b) a = b;

}



ll N;

constexpr ll DP_MAX = 100010;

ll dp[DP_MAX][3];

vector<ll> A, B, C;



int main(int argc, char **argv)

{

	cin >> N;

	A.resize(N), B.resize(N), C.resize(N);

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

	for (ll i = 0; i < DP_MAX; ++i)

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

			dp[i][j] = -(1ll<<50);

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



	for (ll i = 1; i <= N; ++i)

	{

		// chmax(dp[i+1][0], max(dp[i][1]+A[i], dp[i][2]+A[i]));

		// chmax(dp[i+1][1], max(dp[i][0]+B[i], dp[i][2]+B[i]));

		// chmax(dp[i+1][2], max(dp[i][0]+C[i], dp[i][1]+C[i]));

		chmax(dp[i][0], max(dp[i-1][1]+A[i-1], dp[i-1][2]+A[i-1]));

		chmax(dp[i][1], max(dp[i-1][0]+B[i-1], dp[i-1][2]+B[i-1]));

		chmax(dp[i][2], max(dp[i-1][0]+C[i-1], dp[i-1][1]+C[i-1]));

		

	}

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

}


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

using namespace std;

using ll = long long;



ll dp[100010][3];



int main(int argc, char **argv)

{

	ll N; cin >> N;

	vector<ll> A(N), B(N), C(N);

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



	for (ll i = 0; i < N; ++i)

	{

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

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

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

	}

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

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

#include <algorithm>

#include <cstring>

const int maxn = 3e5 + 5;

using namespace std;



int N;

int a[maxn][4];

int dp[maxn][4];

int main()

{

	scanf("%d", &N);

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

	{

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

		{

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

		}

	}

	memset(dp, 0, sizeof dp);

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

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

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

	{

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

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

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

	}

	int ans = 0;

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

		ans = max(dp[N][i], ans);

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

	return 0;	

}

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

using namespace std;



int dp[3][112345];

int mat[3][112345];



signed main()

{

    int n;

    cin >> n;



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

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



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

        dp[i][n] = 0;



    for(int i = n-1; i >= 0; --i)

    {

        dp[0][i] = max(mat[0][i] + dp[1][i+1],

                       mat[0][i] + dp[2][i+1]);



        dp[1][i] = max(mat[1][i] + dp[0][i+1],

                       mat[1][i] + dp[2][i+1]);



        dp[2][i] = max(mat[2][i] + dp[0][i+1],

                       mat[2][i] + dp[1][i+1]);

    }



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

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

#include <algorithm>

#include <cstring>

const int maxn = 3e5 + 5;

using namespace std;



int N;

int a[maxn][4];

int dp[maxn][4];

int main()

{

	scanf("%d", &N);

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

	{

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

		{

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

		}

	}

	memset(dp, 0, sizeof dp);

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

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

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

	{

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

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

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

	}

	int ans = 0;

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

		ans = max(dp[N][i], ans);

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

	return 0;	

}

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

using namespace std;

#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'

const int N = 1e5;

int A[N+7][5], mem[N+7][5];



int dp(int i, int j) {

	if(i==0) return 0;

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

	if(j==1) return mem[i][j] = A[i][j] + max(dp(i-1, 2), dp(i-1, 3));

	if(j==2) return mem[i][j] = A[i][j] + max(dp(i-1, 3), dp(i-1, 1));

	else return mem[i][j] = A[i][j] + max(dp(i-1, 1), dp(i-1, 2));

}

int main(){

	ios_base::sync_with_stdio(0);

	int a,b,n,T,cas=0;

	cin>>n;

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

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

	}

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

	int res = max(dp(n,1), max(dp(n,2), dp(n,3)));

	cout<<res<<endl;

	return 0;

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

#include <algorithm>

#include <cstring>

const int maxn = 3e5 + 5;

using namespace std;



int N;

int a[maxn][4];

int dp[maxn][4];

int main()

{

	scanf("%d", &N);

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

	{

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

		{

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

		}

	}

	memset(dp, 0, sizeof dp);

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

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

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

	{

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

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

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

	}

	int ans = 0;

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

		ans = max(dp[N][i], ans);

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

	return 0;	

}

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

using namespace std;

const int N = 1e5 + 100;

#define pb push_back

#define mp make_pair

#define f first

#define s second

#define ull unsigned long long

#define ll long long

#define pii pair <int,int>

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

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

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

#define pll pair <ll,ll>

const ll inf = 1e9 + 7;

const ll ll_inf = 1e17 + 100;   

const double pi = 3.14159265358979323;

inline void fr(){

    freopen("gcd.in", "r", stdin);

    freopen("gcd.out", "w", stdout);

}

void boost()

{

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);

}

 

ll binpow (ll a, ll n)

{

    ll res = 1;

    while (n) {

        if (n & 1)

        {

            res *= a;

            res %= inf;

        }

        a *= a;

        n >>= 1;

        a %= inf;

    }

    return res;

}

        

int n;

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

int dp[N][5];

 

main()	

{                                                                        

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

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

	}

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

}