stablegradients/pie-gem5-pairs huggingface dataset:
// 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: 26.5725774416907x):
#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

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

int main()

{

	scanf("%d",&n);

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

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

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

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

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

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

	}

	printf("%d\n",max(f[0][n],max(f[1][n],f[2][n])));

	return 0;

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

using namespace std;



int main()

{



    int dias;

    cin >> dias;

    int atividades[dias][3];

    int felicidadeDasAtividades[dias][3];



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

    {

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

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

    }



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

    {

        if (i == dias - 1)

        {

            felicidadeDasAtividades[i][0] = atividades[i][0];

            felicidadeDasAtividades[i][1] = atividades[i][1];

            felicidadeDasAtividades[i][2] = atividades[i][2];

        }

        else

        {

            if (felicidadeDasAtividades[i + 1][2] >= felicidadeDasAtividades[i + 1][1])

            {

                felicidadeDasAtividades[i][0] = atividades[i][0] + felicidadeDasAtividades[i + 1][2];

            }

            else

            {

                felicidadeDasAtividades[i][0] = atividades[i][0] + felicidadeDasAtividades[i + 1][1];

            }



            if (felicidadeDasAtividades[i + 1][2] >= felicidadeDasAtividades[i + 1][0])

            {

                felicidadeDasAtividades[i][1] = atividades[i][1] + felicidadeDasAtividades[i + 1][2];

            }

            else

            {

                felicidadeDasAtividades[i][1] = atividades[i][1] + felicidadeDasAtividades[i + 1][0];

            }



            if (felicidadeDasAtividades[i + 1][1] >= felicidadeDasAtividades[i + 1][0])

            {

                felicidadeDasAtividades[i][2] = atividades[i][2] + felicidadeDasAtividades[i + 1][1];

            }

            else

            {

                felicidadeDasAtividades[i][2] = atividades[i][2] + felicidadeDasAtividades[i + 1][0];

            }

        }



    }

    int melhorEscolha = 0;

    if (felicidadeDasAtividades[0][0] >= felicidadeDasAtividades[0][1] && felicidadeDasAtividades[0][0] >= felicidadeDasAtividades[0][2])

    {

        cout << felicidadeDasAtividades[0][0] << endl;

    }

    else if (felicidadeDasAtividades[0][1] >= felicidadeDasAtividades[0][0] && felicidadeDasAtividades[0][1] >= felicidadeDasAtividades[0][2])

    {

        cout << felicidadeDasAtividades[0][1] << endl;

    }

    else if (felicidadeDasAtividades[0][2] >= felicidadeDasAtividades[0][0] && felicidadeDasAtividades[0][2] >= felicidadeDasAtividades[0][1])

    {

        cout << felicidadeDasAtividades[0][2] << endl;

    }

}


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

#include <cstring>

#include <algorithm>

using namespace std;

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

int main()

{

	scanf("%d",&n);

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

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

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

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

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

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

	}

	printf("%d\n",max(f[0][n],max(f[1][n],f[2][n])));

	return 0;

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

}


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

#include <cstring>

#include <algorithm>

using namespace std;

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

int main()

{

	scanf("%d",&n);

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

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

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

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

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

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

	}

	printf("%d\n",max(f[0][n],max(f[1][n],f[2][n])));

	return 0;

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

}

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

#include <cstring>

#include <algorithm>

using namespace std;

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

int main()

{

	scanf("%d",&n);

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

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

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

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

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

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

	}

	printf("%d\n",max(f[0][n],max(f[1][n],f[2][n])));

	return 0;

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

}	 


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

#include <cstring>

#include <algorithm>

using namespace std;

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

int main()

{

	scanf("%d",&n);

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

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

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

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

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

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

	}

	printf("%d\n",max(f[0][n],max(f[1][n],f[2][n])));

	return 0;

}
// Slower C++ solution:
//by Top1

#include <bits/stdc++.h>

     

#define f first

#define s second

#define int long long

#define ld long double

#define ull unsigned long long

#define pii pair <int, int>

#define pll pair <long, long>

#define mp make_pair

#define pb push_back

#define pf push_front

#define pp pop_back

#define rev reverse

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

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

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

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

#define nxtp next_permutation

#define pvtp prev_permutation

#define KZ return 

#define x1 x21212121

#define y1 y21212121

#define sqr(x) x * x 

 

const int inf = INT_MAX;

const int mod = 1e9 + 7;

const int maxn = 6e5 + 111;

     

using namespace std;



int n, k, a[maxn], b[maxn], c[maxn], dp[5][maxn], q;



void solve(){    

	cin >> n;



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

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



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

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

	dp[3][1] = c[1];



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

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

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

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

	}



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

}



main(){

    boost;

	    

	q = 1;



	while (q--){

		solve();

	}

}

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

#include <cstring>

#include <algorithm>

using namespace std;

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

int main()

{

	scanf("%d",&n);

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

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

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

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

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

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

	}

	printf("%d\n",max(f[0][n],max(f[1][n],f[2][n])));

	return 0;

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



#define ll long long

#define f first

#define se second

#define pb push_back

#define mp make_pair

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

#define lb lower_bound

#define ub upper_bound

#define pii pair<int, int>



using namespace std;



const int N = 1e5 + 100, mod = 1e9, inf = 1e9 + 7;

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



ll bin_pow(int x, int y){

    if(y == 0)

        return 1;

    if(y == 1)

        return x;

    if(y % 2 == 0){

        ll z = bin_pow(x, y / 2);

        return (z * z) % mod;

    }

    return (bin_pow(x, y - 1) * x) % mod;

}





int main(){

    boost;

    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][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], dp[n][2], dp[n][3]});

    return 0;

}


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

#include <cstring>

#include <algorithm>

using namespace std;

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

int main()

{

	scanf("%d",&n);

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

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

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

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

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

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

	}

	printf("%d\n",max(f[0][n],max(f[1][n],f[2][n])));

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



using namespace std;



#define REP(i,a,b) for(ll i = a; i < b; i++)

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

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

#define endl '\n'



typedef long long ll;

typedef unsigned long long ull;

typedef pair<ll, ll> pii;

typedef pair<int, pii> tri;

typedef vector <vector <ll>> matrix;

typedef pair<string, string> pss;



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

const int MAX = (int)1e5 + 100;



const ll oo = 0x3f3f3f3f3f3f3f3f;



ll a[MAX][5];



ll dp[MAX][5];



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    int n; cin >> n;



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

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



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

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

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

                if(k == j) continue;

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

            }

        }

    }



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

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

}

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



using namespace std;



#define REP(i,a,b) for(ll i = a; i < b; i++)

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

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

#define endl '\n'



typedef long long ll;

typedef unsigned long long ull;

typedef pair<ll, ll> pii;

typedef pair<int, pii> tri;

typedef vector <vector <ll>> matrix;

typedef pair<string, string> pss;



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

const int MAX = (int)1e5 + 100;



const ll oo = 0x3f3f3f3f3f3f3f3f;



ll a[MAX][5];



ll dp[MAX][5];



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    int n; cin >> n;



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

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



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

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

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

                if(k == j) continue;

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

            }

        }

    }



    cout << max(dp[n][1], max(dp[n][2], dp[n][3])) << 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.056621908240088x):
#include <bits/stdc++.h>

 

#define ull unsigned long long

#define ll long long

#define pb push_back

#define mp make_pair

#define y1 my_y1

#define fi first

#define se second

#define lcm mylcm

 

using namespace std;

 

const ll mod = 998244353;

const ll inf = 2e9;

const int N = 1e5 + 5;



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



int main () {

	//freopen("a.out", "w", stdout);

    cin.tie(NULL);

	cout.tie(NULL);

	ios_base::sync_with_stdio(false);

	cin >> n;

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

		cin >> a >> b >> c;

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

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

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

	}

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

	return 0;

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

}

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

 

#define ull unsigned long long

#define ll long long

#define pb push_back

#define mp make_pair

#define y1 my_y1

#define fi first

#define se second

#define lcm mylcm

 

using namespace std;

 

const ll mod = 998244353;

const ll inf = 2e9;

const int N = 1e5 + 5;



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



int main () {

	//freopen("a.out", "w", stdout);

    cin.tie(NULL);

	cout.tie(NULL);

	ios_base::sync_with_stdio(false);

	cin >> n;

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

		cin >> a >> b >> c;

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

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

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

	}

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

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

using namespace std;

 

#define ll long long int



int main() {

    ll n;

    cin >> n;

    ll dp[n][3] = {};

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

        ll a, b, c;

        cin >> a >> b >> c;

        if(i == 0) {

            dp[i][0] = a;

            dp[i][1] = b;

            dp[i][2] = c;

        }

        else {

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

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

            dp[i][2] = c + 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;

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

}

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

using namespace std;

 

#define ll long long int



int main() {

    ll n;

    cin >> n;

    ll dp[n][3] = {};

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

        ll a, b, c;

        cin >> a >> b >> c;

        if(i == 0) {

            dp[i][0] = a;

            dp[i][1] = b;

            dp[i][2] = c;

        }

        else {

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

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

            dp[i][2] = c + 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 <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.053377981861269x):
#include <bits/stdc++.h>

/**

*   author: j o s e m a g o

*   date:

**/

using namespace std;

#pragma GCC optimize ("Ofast")

#define f first

#define s second

#define mp make_pair

#define lb lower_bound

#define ub upper_bound

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

#define mset(a,v) memset(a,v,sizeof(a))

#define pb push_back

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

#define rsz resize

#define ln "\n"



typedef double db;

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

const ld PI = 2*acos(0.0);

const int MOD = 1000000007;





int matriz[100009][3];

int dp[100009][3];







int main(){



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

  //freopen("input.out","w",stdout);



    ios_base::sync_with_stdio(0); cin.tie(0);





    int n;

    cin >> n;

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

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

            cin >> matriz[i][j];

        }

    }

    int m = 0;

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

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



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



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

                if(k != j){

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

                }

            }

            dp[i][j]+=m;

            dp[i][j]+= matriz[i][j];

            m = 0;

        }

    }



    int sol = 0;

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

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

    }

    cout<<sol;







    return 0;

}

/*

7

6 7 8

8 8 3

2 5 2

7 8 6

4 6 8

2 3 4

7 5 1







*/