stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 32.18164147344293x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 4.500056019762914x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 4.549201792488534x):
#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;

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

THE WHITE WOLF

NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/



#include<bits/stdc++.h>

using namespace std;



#define io ios_base::sync_with_stdio(false)

#define ll long long

#define ull unsigned long long

#define vi vector<int>

#define vll vector<long long>

#define pb push_back

#define mod  10000007

#define pii pair<int, int>

#define PI 2*acos(0.0)

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





int main()

{

    io;

    int n;

    cin>>n;

    ll dp[n+1][3];

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

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

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

        {

            ll ma = 0;

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

            {

                if(a == j)

                    continue;

                ma = max(ma, dp[i-1][a]);

            }

            dp[i][j] += ma;

        }

    }

    ll ans = 0;

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

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

    cout<<ans;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.5515191241225414x):
#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;

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

#include<iostream>

using namespace std;

#define pii pair<int,int>

#define ll long long

#define pb push_back

#define fi first

#define se second

#define mp make_pair

#define gap ' '

#define abs(x) ((x)>0?(x):-(x))

#define INF 1e18

#define mod  10000007

int main()

{

 ios::sync_with_stdio(0);

    cin.tie(0);

    int n;

    cin>>n;

    vector<int> v[n];

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

    {

        int x,y,z;

        cin>>x>>y>>z;

        v[i].pb(x);

        v[i].pb(y);

        v[i].pb(z);

    }

    int dp[n+1][3];

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

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

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

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

    {

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

        {

            dp[i][j]=0;

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

            {

                if(j==k) continue;

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

            }

        }

    }

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

}


// Faster C++ solution for the same problem (measured speedup: 4.559548784717198x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 18.87165453703086x):
#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;

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

using namespace std;

#define vb __int128

#define ll long long

#define ld long double

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

#define stoink stack<ll>

#define vec vector <ll>

#define vg vector<vector<ll> >

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

#define pa pair<ll,ll>

#define mp make_pair

#define pb push_back

#define ff first

#define ss second

#define pre 0.00000000000000000001

#define inf 1000000000000

#define mod 998244353

vg arr;

ll n;

vg dp;

ll func(ll ind,ll act) {

	if(dp[ind][act]!=-1)

		return dp[ind][act];

	if(ind == n - 1)

		return arr[ind][act];

	ll i;

	ll res = -1;

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

		if(i == act)

			continue;

		res = max(res,arr[ind][act] + func(ind + 1,i));

	}

	return dp[ind][act] = res;

}

int main()

{	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);

	cin >> n;

	ll i,j;

	arr.assign(n,vector<ll>(3,0));

	dp.assign(n,vector<ll>(3,-1));

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

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

			cin >> arr[i][j];

	}

	ll res = -1;

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

		res = max(res,func(0,i));

	}

	cout << res;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.594215014653388x):
#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;

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

using namespace std;



typedef long long int ll;

typedef pair<int,int> pi;

priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap



ll mini(ll a,ll b){	return a<b?a:b;}

ll maxi(ll a,ll b){	return a>b?a:b;}

ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}

ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    int n;

    cin>>n;



    vector<int> tot(3,0);

    vector<int> vals(3,0);



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

        vector<int> cur(3,0);

        for(int j=0;j<3;++j)    cin>>vals[j];

        

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

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

                if(i!=j){

                    cur[j] = max(cur[j], tot[i] + vals[j]);

                }

            }

        }



        tot = cur;

    }



    cout<<max(tot[0], max(tot[1], tot[2]))<<"\n";



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.594467981124025x):
#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;

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

#define MAX 100005

using namespace std;



int n;

int d[3][MAX];

long long dp[3][MAX];

long long m;



int main(){

    cin>>n;

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

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

            cin>>d[j][i];

    }

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

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

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

                if(k!=j)dp[j][i] = max(dp[k][i-1]+d[j][i], dp[j][i]);

                m = max(dp[j][i], m);

            }

    }

    cout<<m<<"\n";

    return 0;

}

/*

3

10 40 70

20 50 80

30 60 90

*/


// Faster C++ solution for the same problem (measured speedup: 4.498982372758021x):
#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;

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

using namespace std;



#define ll long long int

#define oo 1L<<60;



int N;

int happiness [100005][3];

ll memo [100005][3];



ll costo(){

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

	memo[0][i] = happiness[0][i];

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

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

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

	return max(max(memo[N-1][0], memo[N-1][1]), memo[N-1][2]);

}



int main() {

	cin>>N;

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

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

	cout<<costo()<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.493844567304108x):
#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;

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

using namespace std;

#define MAXN 100000

#define INF 2000000000

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

int dpa[MAXN+1],dpb[MAXN+1],dpc[MAXN+1];

int n,k;

int main() {

	int i;

	int j;

	scanf("%d",&n,&k);

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

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

	}

	dpa[n]=dpb[n]=dpc[n]=0;

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

		dpa[i]=a[i]+max(dpb[i+1],dpc[i+1]);

		dpb[i]=b[i]+max(dpa[i+1],dpc[i+1]);

		dpc[i]=c[i]+max(dpa[i+1],dpb[i+1]);

	}

	printf("%d\n",max(dpa[0], max(dpb[0], dpc[0])));

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.469254068174036x):
#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;

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



using namespace std;



int choose(const int &day, const int &last_activity, const int activities[][3], const int &n, int memo[][4]){

    int ans;

    if(day == n){

        ans = 0;

    }

    else{

        if(memo[day][last_activity] != -1){

            ans = memo[day][last_activity];

        }

        else if(last_activity == 0){

            ans = memo[day][0] = max(activities[day][0] + choose(day + 1, 1, activities, n, memo), max(activities[day][1] + choose(day + 1, 2, activities, n, memo), activities[day][2] + choose(day + 1, 3, activities, n, memo)));

        }

        else if(last_activity == 1){

            ans = memo[day][1] = max(activities[day][1] + choose(day + 1, 2, activities, n, memo), activities[day][2] + choose(day + 1, 3, activities, n, memo));

        }

        else if(last_activity == 2){

            ans = memo[day][2] = max(activities[day][0] + choose(day + 1, 1, activities, n, memo), activities[day][2] + choose(day + 1, 3, activities, n, memo));

        }

        else{

            ans = memo[day][3] = max(activities[day][0] + choose(day + 1, 1, activities, n, memo), activities[day][1] + choose(day + 1, 2, activities, n, memo));

        }

    }

    return ans;

}



int solve(const int activities[][3], const int &n, int memo[][4]){

    return choose(0, 0, activities, n, memo);

}



int main(){

    int n;

    while(scanf("%d", &n) != EOF){

        int activities[n][3], memo[n][4];

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

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

            memo[i][0] = -1; memo[i][1] = -1; memo[i][2] = -1; memo[i][3] = -1;

        }

        printf("%d\n", solve(activities, n, memo));

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.476037451837919x):
#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;

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



using namespace std;



typedef long long lint;

const lint N = 1e5+100;

lint n, happiness[N][3], abc[N][3];



int main(){

#ifdef LOCAL

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

#endif



	scanf("%lld", &n);



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

		scanf("%lld %lld %lld", &abc[i][0], &abc[i][1], &abc[i][2]);

	}



	happiness[0][0] = abc[0][0]; happiness[0][1] = abc[0][1]; happiness[0][2] = abc[0][2];



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

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

			if (j==2) happiness[i][j] = max(happiness[i-1][0] + abc[i][j], happiness[i-1][1] + abc[i][j]);

			else if (j==1) happiness[i][j] = max(happiness[i-1][0] + abc[i][j], happiness[i-1][2] + abc[i][j]);

			else happiness[i][j] = max(happiness[i-1][1] + abc[i][j], happiness[i-1][2] + abc[i][j]);

		}

	}

	

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



	return 0; 

}

// Faster C++ solution for the same problem (measured speedup: 4.434127438020951x):
#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;

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

#include<vector>

#include<map>

using namespace std;

vector<vector<int>>niv;

vector<vector<int>>dat;

string k;

int m(int n,int r){

    if(n>=niv.size())return 0;

    if(dat[n][r]!=0)return dat[n][r];

    dat[n][r]=0;

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

        if(i!=r){

            int l=m(n+1,i);

           dat[n][r]=max(dat[n][r],l+niv[n][r]);

        }

    }

    return dat[n][r];

}



int main(){

    int a,aux;

    cin>>a;

    dat=vector<vector<int>>(a+1,vector<int>(4,0));

    vector<int> aux2(4,0);

    niv.push_back(aux2);

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

        aux2.clear();

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

            cin>>aux;

            aux2.push_back(aux);

        }

        niv.push_back(aux2);

    }

    cout<<m(0,3)<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.55987870161607x):
#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;

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

#define IO ios::sync_with_stdio(0), cin.tie(0)

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 5;

const int inf = ~0u >> 1;

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

int h[maxn][5];

int d[maxn][5];

int main() {

    IO;

    int n;

    cin >> n;

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

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

    }

    d[1][1] = h[1][1];

    d[1][2] = h[1][2];

    d[1][3] = h[1][3];

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

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

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

                if (j != k) d[i][j] = max(d[i - 1][k] + h[i][j], d[i][j]);

        }

    }

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.548867695658278x):
#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;

}