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

#define ll long long

using namespace std;



ll arr[100007][3];

ll dp[100007][3];

bool vis[100007][3];

int n;



ll rec( int i, int prev  )

{

    if(i>=n)

        return 0;

    if(vis[i][prev])

        return dp[i][prev];



    ll ans= 0;

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

    {

        if(prev==j)

            continue;

        ans= max( ans, arr[i][j]+rec(i+1,j) );

    }



    vis[i][prev]= 1;



    return dp[i][prev]= ans;

}



int main()

{

    cin>>n;



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

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

            cin>>arr[i][j];



    cout<< rec( 0, -1 ) <<endl;

}


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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

#include <algorithm>



using namespace std;



int main() {

	int n;

	cin >> n;

	int activities[n][3];

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

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

			cin >> activities[i][j];

		}

	}



	int escolhaA = 0, escolhaB = 0, escolhaC = 0;

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

		int auxA = escolhaA, auxB = escolhaB, auxC = escolhaC;

		escolhaA = max(auxB,auxC) + activities[i][0];

		escolhaB = max(auxA,auxC) + activities[i][1];

		escolhaC = max(auxA,auxB) + activities[i][2];

	}



	cout << max(escolhaA,max(escolhaB,escolhaC)) << endl;

}

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

#include<algorithm>

#include<cstring>

using namespace std;

const int maxn = 1e5 + 5;



int a[maxn][4];

int dp[maxn][4];//d[i][j] i day choose j thing 's max happy



int main(){

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

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

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

	}



	int ans = 0;

	for(int i = 1 ; i <= 3 ; i++)ans = max(dp[n][i],ans);

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

}

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

#include <algorithm>



using namespace std;



int main(void) {

    int n;



    cin >> n;



    int tasks[n][3];

    int points[n][3];



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

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

    }



    points[0][0] = tasks[0][0];

    points[0][1] = tasks[0][1];

    points[0][2] = tasks[0][2];



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

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

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

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

    }



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



    return 0;

}


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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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



using namespace std;

const int N = (int)(1e5 + 123);

const int INF = (int)(1e9 + 7);



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

int dp[N][3];

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[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] , max(dp[n][1] , dp[n][2]));

	return 0;

}

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

 

#define mp make_pair

#define pb push_back

#define f first

#define s second

#define ll long long

#define int ll

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

#define forev(i, b, a) for(int i = (b); i >= (a); --i)

#define VAR(v, i) __typeof( i) v=(i)

#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)

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

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

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

 

using namespace std;

 

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

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

 

#define inf mod

 

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;   

typedef vector<ll> Vll;               

typedef vector<pair<int, int> > vpii;

typedef vector<pair<ll, ll> > vpll;

 

int n, dp[maxn][4], k;

int a[maxn][4];

main () {

	cin >> n;

	forn(i, 1, n)

		forn(j, 0, 2){

			cin >> a[i][j];

			if(i == 1) dp[i][j] = a[i][j];

		}

	forn(i, 2, n){

		forn(t1, 0, 2)

			forn(t2, 0, 2)

				if(t1 != t2)

					dp[i][t1] = max(dp[i][t1], dp[i - 1][t2] + a[i][t1]);

	}

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

}

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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



using namespace std;

 

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

 

#define nl '\n'

 

#define y1 aza_ibagaliev

 

#define f first

#define s second

	

#define ed end()

#define bg begin()

#define rbg rbegin()

 

#define rv reverse

#define mp make_pair

#define pb push_back

#define ppb pop_back

#define ppf pop_front

 

#define sz size()

#define all(x) x.bg, x.ed

 

#define pll pair < ll, ll >

#define pii pair < int, int >

 

#define sqr(x) ((x) * 1ll * (x))

#define sqrd(x) ((x) * 1.0 * (x))

 

#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

 

#define rnl cout << "----------------------------------------" << nl

 

#define bit __builtin_popcount

 

inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}

        	

const int ppr = 257;

const ll INF = 2e18;

const int inf = 2e9;

const int mod = 1e9 + 7;

const int N = 1e5 + 123;

const ld pi = 3.1741592653589793238462643;

 

const int dx[] = {1, 0, -1, 0};

const int dy[] = {0, 1, 0, -1};



int n, x[5][N], dp[5][N];



main() {             	

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

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



//	srand(time(NULL));



	scanf("%d", &n);



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

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

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



		if(i == 1) {

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

				dp[j][i] = x[j][i];

		} else {

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

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

					if(a != b) dp[a][i] = max(dp[a][i], dp[b][i - 1] + x[a][i]);

		}

	}



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



    return 0;                                        

}

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

#include <iomanip>

#include <cmath>

#include <cstdio>

#include <cstring>

#include <ctime>

#include <string>

#include <stdio.h>

#include <set>

#include <map>

#include <algorithm>

#include <queue>

#include <vector>

#define ll long long

#define pb push_back

#define mp make_pair

#define f first

#define s second



using namespace std;



const int inf = 1e9 + 7;

const long long INF = 1e18 + 7;

const int maxn = 2e5 + 7;



int n, dp[maxn][4];

pair < pair < int, int >, int > a[maxn];



int main(){

	ios_base::sync_with_stdio(NULL);

	cin.tie(0);

	cout.tie(0);

	cin >> n;

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

		cin >> a[i].f.f >> a[i].f.s >> a[i].s;

	dp[1][1] = a[1].f.f;

	dp[1][2] = a[1].f.s;

	dp[1][3] = a[1].s;

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

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

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

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

	}

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

	return 0;

} 

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

#include<cstdio>

using namespace std;

const int N=100010;

int a[N][4],f[N][4];

int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d%d%d",&a[i][1],&a[i][2],&a[i][3]);

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

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

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

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

			}

		}

	}

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

} 

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

#include<cstdio>

using namespace std;

int a[100001],b[100001],c[100001],n,dp[100001][3];

int main(){

	scanf("%d",&n);

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

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

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

	}

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

	return 0;

}

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

#include <algorithm>



const int maxn = 1e5+7;



int n;

int a[maxn][3];

int dp[maxn][3];



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

	std::cin >> n;

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

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

			std::cin >> a[i][j];

		}

	}

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

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

	}

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

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

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

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

	}

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

}

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

using namespace std;

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

#define ll long long

#define fastIO cout << fixed << setprecision(9), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

double const EPS = 1e-9, PI = acos(-1);

const int N = 1e5 + 9, M = 5e2 + 9, OO = 1e9 + 7, MOD = 1e9 + 9;

const ll inf = 1e18;



ll dp[N][3], happ[N][3];



int main() {

  fastIO;

#ifdef LOCAL

  freopen("input.in", "rt", stdin);

#endif



  int n;

  cin >> n;

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

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

      cin >> happ[i][j];



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

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



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

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

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

        if(k == prv) continue;

        dp[i][k] = max(dp[i][k], dp[i-1][prv] + happ[i][k]);

      }

    }

  }



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

  return 0;

}


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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

#include<algorithm>

using namespace std;

int a[100005][4];

int dp[100005][3]={0};

int main()

{

	int n;

	cin>>n;

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

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

	

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

	{

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

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

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

	}

	int ans=-1;

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

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

	cout<<ans<<endl;

	return 0;

}

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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

using namespace std;

int n;

long long f[100005] , s[100005] , th[100005];

long long mem[100005][4];

long long sol(){

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

		mem[i][0] = mem[0][i] = 0;

	}

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

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

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

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

	}

	return max(mem[n][1] , max(mem[n][2],mem[n][3]));

}

int main()

{

	cin>>n;

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

		cin>>f[i]>>s[i]>>th[i];

	}

	cout<<sol();

	return 0;

}




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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

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

# define ll long long

# define fi first

# define se second



using namespace std ;



ll N, a, b, c, sum, pre;

ll vc[100001][3], dp[100001][3] ;

int main() {

    cin >> N ;

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

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

    }

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

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

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

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

    }

    cout << max( { vc[N-1][1], vc[N-1][2], vc[N-1][3] } ) << endl;

}


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

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

}
// Slower C++ solution:
//بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ

//لا إله إلا الله محمد رسول الله



#include <bits/stdc++.h>



#pragma GCC optimize("Ofast")



#define ll long long

#define pb push_back

#define fr first

#define sc second

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

#define out freopen("snakes.out", "w", stdout)

using namespace std;



ll dp[100005][5];

ll n;

ll a[100005], b[100005], c[100005];

int main(){

    //in;

    //out;

    ios_base::sync_with_stdio(false);

    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.252152874972055x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int dp[100001][3]={0};//第i天选了第j种

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

int main(){

    int n;

    scanf("%d",&n);

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

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

    }

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

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

    }

    int ans = 0;

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

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

    }

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

}