stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#define _CRT_SECURE_NO_WARINGS

#include <iostream>

#include <iomanip>

#include <map>

#include <cmath>

#include <algorithm>

#include <string>

#include <vector>

#include <queue>

#include <set>

#include <deque>

#include <stack>

#include <bitset>

#include <fstream>

#include <map>

#include <unordered_map>



using namespace std;

typedef int me;

typedef long long ll;

typedef unsigned long long ull;



#define andrew ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define endl '\n'

#define sz(v) (int)(v.size())

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

#define PI 3.1415926535

#define sin(i) (long double)sin(i *PI / 180.0)

#define cos(i) (long double)cos(i * PI/ 180.0)



ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }

ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }



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

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

int id8[] = { 0, 1, 2, 3, 4, 5, 6, 7 };

struct happ

{

    int a, b, c;

};

int n;

vector<happ>v;

ll mem[100005][4];

ll solve(int i, int last)

{

    if (i == n+1)

        return 0;



    ll& ret = mem[i][last];

    

    if (ret != -1)

        return ret;



    if (last != 1)

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

    if (last != 2)

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

    if (last != 3)

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



    return ret;

}

int main()

{

    andrew;

    cin >> n;

    v.resize(n + 1);



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

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



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

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

            mem[i][j] = -1;



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







}


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

using namespace std;

#define ll long long

#define m 100005

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

int main()

{

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

  }

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

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



template <typename T>

using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;

typedef complex<double> point;



#define X real()

#define Y imag()

#define angle(a) (atan2((a).imag(), (a).real()))

#define vec(a, b) ((b) - (a))

#define same(p1, p2) (dp(vec(p1, p2), vec(p1, p2)) < EPS)

#define dp(a, b) ((conj(a) * (b)).real())

#define cp(a, b) ((conj(a) * (b)).imag())

#define length(a) (hypot((a).imag(), (a).real()))

#define normalize(a) (a) / length(a)

#define rotateO(p, ang) ((p)*exp(point(0, ang)))

#define rotateA(p, ang, about) (rotateO(vec(about, p), ang) + about)

#define reflectO(v, m) (conj((v) / (m)) * (m))

#define clr(a, b) memset(a, b, sizeof(a));



const ll N = 100005;

const int MOD = 1e9 + 7;

const double EPS = 1e-7;

const double PI = acos(-1.0);



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

ll memo[N][4];



ll solve(ll i, ll j)

{

	if(i == n)

		return 0;



	ll& ret = memo[i][j];



	if(~ret)

		return ret;



	ret = 0;



	if(j != 0)

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

	if(j != 1)

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

	if(j != 2)

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

	return ret;

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL), cout.tie(NULL);

    clr(memo, -1);

    cin >> n;

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

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

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

}

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



using namespace std;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;



const ll N = 100005;

const ll INF = 1e9;

const int MOD = 1e9 + 7;

const double EPS = 1e-7;

const double PI = acos(-1.0);



struct E {

    ll a, b, c;

} arr[N];



ll n, dp[N][3];



int main() {

    ios::sync_with_stdio(false);

    cin.tie(NULL), cout.tie(NULL);

    cin >> n;

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

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

    

    dp[0][0] = arr[0].a;

    dp[0][1] = arr[0].b;

    dp[0][2] = arr[0].c;



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

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

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

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

    }

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

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



template <typename T>

using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;

typedef complex<double> point;



#define X real()

#define Y imag()

#define angle(a) (atan2((a).imag(), (a).real()))

#define vec(a, b) ((b) - (a))

#define same(p1, p2) (dp(vec(p1, p2), vec(p1, p2)) < EPS)

#define dp(a, b) ((conj(a) * (b)).real())

#define cp(a, b) ((conj(a) * (b)).imag())

#define length(a) (hypot((a).imag(), (a).real()))

#define normalize(a) (a) / length(a)

#define rotateO(p, ang) ((p)*exp(point(0, ang)))

#define rotateA(p, ang, about) (rotateO(vec(about, p), ang) + about)

#define reflectO(v, m) (conj((v) / (m)) * (m))

#define clr(a, b) memset(a, b, sizeof(a));



const ll N = 100005;

const int MOD = 1e9 + 7;

const double EPS = 1e-7;

const double PI = acos(-1.0);



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

ll memo[N][4];



ll solve(ll i, ll j)

{

	if(i == n)

		return 0;



	ll& ret = memo[i][j];



	if(~ret)

		return ret;



	ret = 0;



	if(j != 0)

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

	if(j != 1)

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

	if(j != 2)

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

	return ret;

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL), cout.tie(NULL);

    clr(memo, -1);

    cin >> n;

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

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

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

}

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



using namespace std;



typedef long long ll;

typedef pair<ll, ll> pll;

typedef pair<int, int> pii;



#define endl "\n"



const ll INF = 1e15;

const int MOD = 1e9 + 7;

const double EPS = 1e-9;

const double PI = acos(-1.0);



mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());



const int N = 1e5 + 5;



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



int main() {

    ios::sync_with_stdio(false);

    cin.tie(NULL), cout.tie(NULL);



    cin >> n;



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

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



    for (int i = 1; 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];

    }



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

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

using namespace std;



int n, a[100005][3], dp[100005][3];



int solve(int i, int j)

{

    if (i == n)

        return 0;

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

        return dp[i][j];

    int c = 0;

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

        if (k != j)

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

    return dp[i][j] = c;

}



int main()

{

    memset(dp, -1, sizeof dp);

    cin >> n;

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

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

        cin >> a[i][j];

    cout << solve(0, 4);

    return 0;

}

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

using namespace std;



#define VIC ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);

#define wtf(s) freopen((s), "w", stdout)

#define rff(s) freopen((s), "r", stdin)

#define pi (2 * acos(0))

typedef long double ld;

typedef long long ll;

typedef complex<ld> point;

#define endl '\n'

#define matrix vector<vector<ll>>

#define EPS 1e-9

#define X real()

#define Y imag()

#define vec(a, b) ((b) - (a))

#define dot(a, b) ((conj(a) * (b)).real())

#define cross(a, b) ((conj(a) *(b)).imag())

#define lengthsqr(v) (dot(v, v))

#define length(v) ((ld)hypot((v).Y, (v).X))

#define same(a, b) (lengthsqr(vec(a, b)) < EPS)



const int N = 1e5 + 5, inf = 1e9 + 5;

const ll mod = 1e9 + 7;



int dp[N][3], a[N][3];



int main()

{

    VIC

    int n;

    cin >> n;

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

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

            cin >> a[i][j];

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

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

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

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

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

            {

                if (j == k)

                    continue;

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

            }

    int ans = 0;

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

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

    cout << ans;

    return 0;

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

using namespace std;



int dp[100001][4];



int n;

void fillarray()

{

	int i,j;

	for(i=0;i<=100000;i++)

	{

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

		dp[i][j] = -1;

	}

}

int solve(int a[] , int b[], int c[],  int i , int last)

{

	if(i == n)

	return 0;



	

	if(dp[i][last] >= 0)

	return dp[i][last];

	

	int val = 0;

	

	if(last != 1)

	val = max(val ,  a[i] + solve(a , b , c, i + 1 , 1));

	

	if(last != 2)

	val = max( val , b[i] + solve(a ,b ,c  , i + 1 , 2));

	

	if(last != 3)

	val = max( val ,c[i] + solve(a , b , c , i + 1 , 3));

	

	dp[i][last] = val;

	return val;

}

main()

{

	cin>>n;

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

	int i,j;

	

	fillarray();

	

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

	{

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

	}

	

	cout<<solve(a , b , c, 0,0);

	

}

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

#include<vector>

#include<limits.h>

#define ll long long

using namespace std;

int main()

{

	int n;

	cin>>n;

	

	

	int i,j,k;

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

	

	int dp[n][3];

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

	{

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

	}

	

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

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

	dp[0][2] = c[0];

	

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

	{

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

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

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

	}

	

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

	

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

using namespace std;



int dp[100001][4];



int n;

void fillarray()

{

	int i,j;

	for(i=0;i<=100000;i++)

	{

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

		dp[i][j] = -1;

	}

}

int solve(int a[] , int b[], int c[],  int i , int last)

{

	if(i == n)

	return 0;



	

	if(dp[i][last] >= 0)

	return dp[i][last];

	

	int val = 0;

	

	if(last != 1)

	val = max(val ,  a[i] + solve(a , b , c, i + 1 , 1));

	

	if(last != 2)

	val = max( val , b[i] + solve(a ,b ,c  , i + 1 , 2));

	

	if(last != 3)

	val = max( val ,c[i] + solve(a , b , c , i + 1 , 3));

	

	dp[i][last] = val;

	return val;

}

main()

{

	cin>>n;

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

	int i,j;

	

	fillarray();

	

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

	{

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

	}

	

	cout<<solve(a , b , c, 0,0);

	

}

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

#include<vector>

#include<algorithm>

#include<map>

#include<math.h>



#define long long ll



using namespace std;



main()

{

	int n,k;

	cin>>n;

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

	

	int i,j;

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

	{

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

	}

	

	int dp[n][3];

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

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

	dp[0][2] = c[0];

	

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

	{

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

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

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

	}

	

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

	

	

	

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

using namespace std;



const int MAXN = 1e5+5;

const int INF = 1e9+7;

int dp[MAXN][4],a[MAXN][4];

// dp[i][j] ==> The maximum we can get if we do [1..i] and do type j activity on day i



int main()

{

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

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

            dp[i][j] = INF;

        }

    }

    int n;cin >> n;

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

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

            cin >> a[i][j];

        }

    }

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

        // Choose Swimming

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

    }

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

}


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

using namespace std;



const int MAXN = 1e5+5;

int dp[MAXN][3],a[MAXN][3];



int main()

{

    int n;cin >> n;

    vector<int> dp(3);



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

        vector<int> new_dp(3);

        vector<int> c(3);

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

            cin >> c[j];

        }

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

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

                if(i==j) continue;

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

            }

            new_dp[i] += c[i];

        }

        dp = new_dp;

    }



    int maxs=0;

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

        maxs = max(maxs,dp[i]);

    }

    cout << maxs;

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

using namespace std;



const int MAXN = 1e5+5;

const int INF = 1e9+7;

int dp[MAXN][4],a[MAXN][4];

// dp[i][j] ==> The maximum we can get if we do [1..i] and do type j activity on day i



int main()

{

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

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

            dp[i][j] = INF;

        }

    }

    int n;cin >> n;

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

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

            cin >> a[i][j];

        }

    }

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

        // Choose Swimming

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

    }

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

}


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

using namespace std;



const int MAXN = 3e5+5;

const int INF = 1e9+7;

#define ll long long

#define pb push_back

#define endl '\n'

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

#define F first

#define S second



ll poww(ll a, ll b, ll md) {

    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));

}



ll MOD(ll a){

    return ((a%INF)+INF)%INF;

}



ll inv(ll a){

    return poww(a,INF-2,INF);

}



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



int main()

{

    fast_io;

    //cout << fixed << setprecision(15);



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

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

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

    }

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

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

#include <stdio.h>

#include <vector>

#include <string>

#include <set>

#include <queue>

#include <cmath>

#include <map>

#include <algorithm>

#include <stack>

#include <cstring>

 

#define ll long long

#define MP make_pair

#define PB push_back

#define P push

#define f first

#define se second

#define S size()

#define B begin()

#define E end()

#define rB rbegin()

#define rE rend()

#define PI acos(-1)



 

const int N = 1e5 + 100;

const int M = 1e6 + 100;

const ll oo = 1e18;

 

ll n, m, k, t, q, h, a, b, d, c, e, w, x, y, z;

using namespace std;





int ai[N], bi[N], ci[N], dp[N][3];





int calc(int n, int las) {



	if(n == m) return 0;



	int &r = dp[n][max(las, 0)];



	if(r != -1) return r;





	int x = -1, y = -1, f = -1;



	if(las != 0){

		x = calc(n + 1, 0) + ai[n];

	}

	if(las != 1){

		y = calc(n + 1, 1) + bi[n];

	}

	if(las != 2){

		f = calc(n + 1, 2) + ci[n];

	}



	return r = max({x, y, f});

}





int main() {



	memset(dp, -1, sizeof dp);



	cin >> m;

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

		cin >> ai[i] >> bi[i] >> ci[i];

	}

	

	cout << calc(0, -1);







    

    return 0;

}






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

#include <stdio.h>

#include <vector>

#include <string>

#include <set>

#include <queue>

#include <cmath>

#include <map>

#include <algorithm>

#include <stack>

#include <cstring>

 

#define ll long long

#define MP make_pair

#define PB push_back

#define P push

#define f first

#define se second

#define S size()

#define B begin()

#define E end()

#define rB rbegin()

#define rE rend()

#define PI acos(-1)



 

const int N = 1e5 + 100;

const int M = 1e6 + 100;

const ll oo = 1e18;

 

ll n, m, k, t, q, h, a, b, d, c, e, w, x, y, z;

using namespace std;





int ai[N], bi[N], ci[N], dp[N][3];









int main() {



	cin >> n;

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

		cin >> ai[i] >> bi[i] >> ci[i];

	}







	

	dp[0][0] = ai[0], dp[0][1] = bi[0], dp[0][2] = ci[0];





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

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



			if(j == 0){

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

			}

			if(j == 1){

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

			}

			if(j == 2){

				dp[i][j] = max(dp[i - 1][0] + ci[i], dp[i - 1][1] + ci[i]);

			}

			

		}

	}





	



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

    

    return 0;

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

#include <stdio.h>

#include <vector>

#include <string>

#include <set>

#include <queue>

#include <cmath>

#include <map>

#include <algorithm>

#include <stack>

#include <cstring>

 

#define ll long long

#define MP make_pair

#define PB push_back

#define P push

#define f first

#define se second

#define S size()

#define B begin()

#define E end()

#define rB rbegin()

#define rE rend()

#define PI acos(-1)



 

const int N = 1e5 + 100;

const int M = 1e6 + 100;

const ll oo = 1e18;

 

ll n, m, k, t, q, h, a, b, d, c, e, w, x, y, z;

using namespace std;





int ai[N], bi[N], ci[N], dp[N][3];





int calc(int n, int las) {



	if(n == m) return 0;



	int &r = dp[n][max(las, 0)];



	if(r != -1) return r;





	int x = -1, y = -1, f = -1;



	if(las != 0){

		x = calc(n + 1, 0) + ai[n];

	}

	if(las != 1){

		y = calc(n + 1, 1) + bi[n];

	}

	if(las != 2){

		f = calc(n + 1, 2) + ci[n];

	}



	return r = max({x, y, f});

}





int main() {



	memset(dp, -1, sizeof dp);



	cin >> m;

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

		cin >> ai[i] >> bi[i] >> ci[i];

	}

	

	cout << calc(0, -1);







    

    return 0;

}






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

#include <stdio.h>

#include <vector>

#include <string>

#include <set>

#include <queue>

#include <cmath>

#include <map>

#include <algorithm>

#include <stack>

#include <cstring>

 

#define ll long long

#define MP make_pair

#define PB push_back

#define P push

#define f first

#define se second

#define S size()

#define B begin()

#define E end()

#define rB rbegin()

#define rE rend()

#define PI acos(-1)

 

 

const int N = 1e5 + 100;

const int M = 1e6 + 100;

const ll oo = 1e18;

 

ll n, m, k, t, q, h, a, b, d, c, e, w, x, y, z;

using namespace std;



int ai[N][3];

ll dp[N][3];



int main() {

 

	cin >> n;



	vector <int> v(n);



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

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

	}



	dp[0][0] = ai[0][0];

	dp[0][1] = ai[0][1];

	dp[0][2] = ai[0][2];



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

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

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

		}

	}





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





 

    return 0;

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



using namespace std;



typedef long long ll;

typedef vector <int> vi;

typedef vector <ll> vl;

typedef pair <ll, ll> dl;

typedef pair <int, int> ii;

typedef vector <ii> vii;

typedef vector <vi> graph;



int n;

ll mat[100010][3];

ll dp[100010][3];



ll solve(int r, int c) {

	if (r == n - 1) {

		return mat[r][c];

	}

	if (dp[r][c] != -1) return dp[r][c];

	ll temp, mayor = -1;

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

	{

		if (i == c) continue;

		temp = solve(r + 1, i);

		mayor = temp > mayor ? temp : mayor;

	}

	return dp[r][c] = mat[r][c] + mayor;

}



int main() {

    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);



	cin >> n;

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

	{

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

		{

			cin >> mat[i][j];

		}

	}

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

	{

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

		{

			dp[i][j] = -1;

		}

	}

	ll temp, mayor = -1;

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

	{

		temp = solve(0, i);

		mayor = temp > mayor ? temp : mayor;

	}

	cout << mayor << "\n";

    return 0;

}


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



using namespace std;



typedef long long ll;

typedef vector <int> vi;

typedef vector <ll> vl;

typedef pair <ll, ll> dl;

typedef pair <int, int> ii;

typedef vector <ii> vii;

typedef vector <vi> graph;



int n;

ll mat[100010][3];



/*ll solve(int r, int c) {

	if (r == n - 1) {

		return mat[r][c];

	}

	if (dp[r][c] != -1) return dp[r][c];

	ll temp, mayor = -1;

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

	{

		if (i == c) continue;

		temp = solve(r + 1, i);

		mayor = temp > mayor ? temp : mayor;

	}

	return dp[r][c] = mat[r][c] + mayor;

}*/



int main() {

    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);



	cin >> n;

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

	{

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

		{

			cin >> mat[i][j];

		}

	}

	vector <long long> arr1(3), arr2(3);

	arr1[0] = mat[0][0];

	arr1[1] = mat[0][1];

	arr1[2] = mat[0][2];

	arr2 = arr1;

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

	{

		arr2[0] = mat[i][0] + max(arr1[1], arr1[2]);

		arr2[1] = mat[i][1] + max(arr1[0], arr1[2]);

		arr2[2] = mat[i][2] + max(arr1[1], arr1[0]);

		if (i < n - 1) arr1.swap(arr2);

	}

	ll mayor = max(arr2[0], max(arr2[1], arr2[2]));

	cout << mayor << "\n";

    return 0;

}