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

#define ull unsigned long long

#define ll long long

#define pb push_back

#define endl '\n'

#define line cout<<"----------------------"<<endl

#define mp make_pair

#define mod 1000000007

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

#define filein freopen("input.txt","r",stdin)

#define fileout freopen("output.txt","w",stdout)

using namespace std;

const ll  mx=300009;

struct edge

{

    ll  a,b,c;

};

vector<edge> v;

ll  dp[100009][4];

ll  call(ll  ind, ll  pre)

{

    if(ind==v.size()) return 0;

    ll  &ret=dp[ind][pre];

    if(ret!=-1) return ret;

    ret=0;

    ll  a=0,b=0,c=0;

    auto x=v[ind];

        if(pre==1)

        {

            a=x.b+call(ind+1,2);

            b=x.c+call(ind+1,3);

        }

        else if(pre==2)

        {

            a=x.a+call(ind+1,1);

            b=x.c+call(ind+1,3);

        }

        else if(pre==3)

        {

            a=x.a+call(ind+1,1);

            b=x.b+call(ind+1,2);

        }

        else

        {

            a=x.a+call(ind+1,1);

            b=x.b+call(ind+1,2);

            c=x.c+call(ind+1,3);

        }

    return ret=max(a,max(b,c));

}

int  main()

{

    ll  n ;

    cin>>n;

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

    {

        ll  a,b,c; cin>>a>>b>>c;

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

    }

    memset(dp,-1,sizeof dp);

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







}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

#define ll long long

using namespace std;



ll n;

std::vector<ll> ara[100010];

ll dp[100010][4];



ll fnc(ll idx,ll last){

  if(idx == n) return 0;

  if(dp[idx][last] != -1) return dp[idx][last];



  ll res1 = - (1<<25);

  ll res2 = - (1<<25);

  ll res3 = - (1<<25);



  if(last == 0){

    res1 = max(res1,ara[idx][0] + fnc(idx+1,1));

    res2 = max(res2,ara[idx][1] + fnc(idx+1,2));

    res3 = max(res3,ara[idx][2] + fnc(idx+1,3));

  }else if(last == 1){

    res2 = max(res2,ara[idx][1] + fnc(idx+1,2));

    res3 = max(res3,ara[idx][2] + fnc(idx+1,3));

  }else if(last == 2){

    res1 = max(res1,ara[idx][0] + fnc(idx+1,1));

    res3 = max(res3,ara[idx][2] + fnc(idx+1,3));

  }else if(last == 3){

    res1 = max(res1,ara[idx][0] + fnc(idx+1,1));

    res2 = max(res2,ara[idx][1] + fnc(idx+1,2));

  }

  dp[idx][last] = max(res1, max(res2,res3));

  return dp[idx][last];

}



int main(int argc, char const *argv[]) {

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

  cin >> n;

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

    int a,b,c;

    cin >> a >> b >> c;

    ara[i].push_back(a);

    ara[i].push_back(b);

    ara[i].push_back(c);

  }



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

  return 0;

}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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



using namespace std;

typedef long long int lli;



lli n, a[100005], b[100005], c[100005];



lli dp[100005][4];



lli solve(lli i, lli last){

    if(i == n) return dp[i][last] = 0;

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

    lli ans1, ans2, ans3;

    ans1 = ans2 = ans3 = LONG_LONG_MIN;

    if(last != 1) ans1 = a[i] + solve(i+1, 1);

    if(last != 2) ans2 = b[i] + solve(i+1, 2);

    if(last != 3) ans3 = c[i] + solve(i+1, 3);



    return dp[i][last] = max(ans1, max(ans2, ans3));

}





int main(){

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

    int T=1, cs=1;

    //scanf("%d", &T);

    while(T--){

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

        scanf("%lld", &n);

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

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

        }

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



    }



    return 0;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

#include<algorithm>

using namespace std;

int dp[100010][3];

int a[100010][3];

int main()

{

    int n;

    cin >> n;

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

    {

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

    }

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

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

    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][0], dp[i-1][2]);

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

    }

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

    return 0;

}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

#include<algorithm>

#include<vector>

using namespace std;

struct day{

	int a;

	int b;

	int c;

};

int main () {

	int n;

    cin>>n;

    day dp[n];

    cin>>dp[0].a>>dp[0].b>>dp[0].c;

	int a1,b1,c1 ;

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

    	cin>>a1>>b1>>c1;

    	dp[i].a=max((dp[i-1].b),dp[i-1].c)+a1;

    	dp[i].b=max((dp[i-1].a),dp[i-1].c)+b1;

    	dp[i].c=max((dp[i-1].b),(dp[i-1].a))+c1;

	}

	int ma=0;

	cout<<max(dp[n-1].a,max(dp[n-1].b,dp[n-1].c));

	return 0;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

#define ll long long

using namespace std;

const int maxn = 1e5+5;

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



int main(){

	int n; cin >> n;

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

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

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

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

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

	}

	int ans;

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

	cout << ans << endl;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

using namespace std;

const int maxn = 1e5+10;

int dp[maxn][4];

int main()

{

    int n;

    cin>>n;

    int ans =0;

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

    {

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

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

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

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

        ans = max(dp[i][1],max(dp[i][2],dp[i][3]));

    }

    cout<<ans<<endl;

}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

using namespace std;

const int N = 2e5 ;

int dpA[N], dpB[N] , dpC[N] ,a[N] , b[N] , c[N],n;

int main()

{

    cin >> n ;

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

    dpA[0] = a[0] ;

    dpB[0] = b[0] ;

    dpC[0] = c[0] ;

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

        dpA[i] = max(dpB[i-1],dpC[i-1])+a[i] ;

        dpB[i] = max(dpA[i-1],dpC[i-1])+b[i] ;

        dpC[i] = max(dpB[i-1],dpA[i-1])+c[i] ;

    }

    cout << max(dpA[n-1],max(dpB[n-1],dpC[n-1]));

}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

#include <vector>

#include <string>

#include <cmath>

#include <set>

#include <stdio.h>

#include <algorithm>

#include <map>

#include <queue>

#include <unordered_map>

#define ll long long

#define pii pair <int, int>

#define pll pair <long long, long long>

#define plxy pair <long long, pll>

#define INT_MAX 1e18

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

using namespace std;

using namespace std;

const int mod=1e9+7;

const int N=1e5+5;

ll ans[N][3];

int main()

{

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

     cin>>n;

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

     {

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

     }

     ans[0][0]=a[0];

     ans[0][1]=b[0];

     ans[0][2]=c[0];

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

     {

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

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

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

     }

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

    return 0;

}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

#define ll long long

using namespace std;



int main()

{

    int n;

    cin>>n;

    int a[n+5],b[n+5],c[n+5];



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

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

    int dp[3][n+5];

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

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

    dp[2][1]=c[1];

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

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

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

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

    }

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

    return 0;

}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

#include <bitset>

using namespace std;

#define ll long long

#define mod 1000000009



int arr[100005][3];

ll sol[100005][3];



int main()

{

    ios_base::sync_with_stdio(false);    cin.tie(NULL);



    ll n; cin >> n;

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

        for(ll ii=0; ii<3; ii++){

            cin >> arr[i][ii];

        }

    }

    sol[0][0] = arr[0][0];

    sol[0][1] = arr[0][1];

    sol[0][2] = arr[0][2];



    ll maxi = max(arr[0][0],max(arr[0][1],arr[0][2]));

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

        for(ll ii=0; ii<3; ii++){

            maxi = 0;

            for(ll x=0; x<3; x++){

                if(x == ii) continue;



                maxi = max(maxi,arr[i][ii] + sol[i-1][x]);

            }

            sol[i][ii] = maxi;

        }

    }









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







    return 0;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)

#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)

#include<bits/stdc++.h>

typedef long long ll;

using namespace std;

const ll oo=1e15;

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

char A='a',B='b',C='c';

map<pair<int,char>,ll>calc;

ll vacation(int day,char last){

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

    if(calc[{day,last}])

        return calc[{day,last}];

    ll maxi=0;

    if(last!=A)

        maxi=max(maxi,a[day]+vacation(day+1,A));

    if(last!=B)

        maxi=max(maxi,b[day]+vacation(day+1,B));

    if(last!=C)

        maxi=max(maxi,c[day]+vacation(day+1,C));

    calc[{day,last}]=maxi;

    return maxi;

}

int main()

{

    scanf("%d",&n);

    f(i,1,n+1)

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

    cout<<vacation(1,'Z')<<'\n';

    return 0;

}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
//Author: Fuadul Hasan(fuadul202@gmail.com)

//BSMRSTU,Gopalganj

#include<bits/stdc++.h>

using namespace std;int tc = 1;

#define happy ios::sync_with_stdio(false);

#define coding  cin.tie(0);

#define mp make_pair

#define ll long long

#define Pi atan(1)*4

#define pb  push_back

#define vpr vector<pr> 

#define pr pair<int, int> 

#define vi std::vector<int>

#define vll std::vector<ll>

#define YES printf("YES\n");

#define NO printf("NO\n");

#define Yes printf("Yes\n");

#define No printf("No\n");

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

#define point(x) setprecision(x)

#define Test printf("Case %d: ",tc++);

#define Unique(c) (c).resize(unique(all(c))-(c).begin())



const int M = 1e9 + 7;

const ll  Inf = (ll)2e18 + 5;

const int N   = 2e5 + 5;

ll dp1[N],dp2[N],dp3[N];

int solve() 

{

	//happy coding



	int n;

	cin>>n;

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

		int a,b,c;

		cin>>a>>b>>c;

		dp1[i] = max(dp2[i-1]+a,dp3[i-1]+a);

		dp2[i] = max(dp1[i-1]+b,dp3[i-1]+b);

		dp3[i] = max(dp1[i-1]+c,dp2[i-1]+c);

	}

	int x = max(dp1[n],max(dp2[n],dp3[n]));

	cout<<x<<endl;

	return 0;

}

int main(){

	int test = 1;

	//scanf("%d", &test);

	while (test--)solve();return 0;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

#include<cmath>

#include<iostream>

#define maxn 100005

using namespace std;



int main(void)

{

    int N;

    cin >> N;

    int a[maxn][3];

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

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

    }

    int dp[N+1][3];

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

        dp[0][i] = 0;

    }

    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]) + a[i][j];

        }

    }

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

    return 0;

}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

using namespace std;

int main(){

    int n;

    cin >> n;

    vector<int>a(n + 3), b(n + 3), c(n + 3);

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

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

    }

    int dp[n + 3][4];

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

    }

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

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

    cout << mx;

    return 0;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


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

using namespace std;



#define ll long long

#define ull unsigned ll



#define vi vector <int>

#define ii pair <int, int>

#define vii vector <ii>

#define INFLL 9e18

#define INF 2e9

#define EPS 1e-9

#define pb push_back

#define emp emplace_back

#define PI acos(-1.0)

#define endl "\n"

#define mp make_pair

#define DEBUG 0





int main ()



{

    #define int ll

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    //cout.tie(NULL);



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

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

    

    int n;

    cin >> n;

    int activity[n][3];

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

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

            cin >> activity[i][j];

        }

    }



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

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

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

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

    }



    int ans = 0;

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

        ans = max(ans, activity[n-1][i]);

    }



    cout << ans << endl;

       

    return 0;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

    scanf("%d%d%d",&da[0][i],&da[1][i],&da[2][i]);

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}


// Fastest known solution for this problem: