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

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.22177116718636x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.213013572683432x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.209759393771277x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.162775074632459x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.279579659662675x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.18827423065556x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.148455123138409x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.2174477031190225x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.286258892812586x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.219944545533715x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.2236418508487x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.215470976790657x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}
// 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.272319813387954x):
#include <cstdio>

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

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

#define maxn (int)(2e5)

#define INF 1<<30

#define i64 long long

#define pii pair<i64,i64>

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

#define LB(x,v) lower_bound(all(x), v) - x.begin()

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

using namespace std;



int mat[maxn+2][4], ans[maxn+2][4] , n;

const int k = 3;



void init(int n){

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

        ans[i][0] = ans[i][1] = ans[i][2] = -1;

}



int solve(int day, int option){

    if(day >= n) return 0;



    if(ans[day][option] != -1) return ans[day][option];



    int res = -1;

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

        if(next_option != option) res = max(res, mat[day][option] + solve(day + 1, next_option));

    }



    return ans[day][option] = res;

}



int main() {

    

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

        init(n);

        

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

            for(int j = 0;j < k; j++) scanf("%d",&mat[i][j]);

        }



        int res = -1;

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

            res = max(res, solve(0, option));

        }



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

    }    

    return 0;

}

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

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

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

using namespace std;

 

int main() {

	int Ndays;

	scanf("%d", &Ndays);

	int a, b, c;

	int A = 0, B = 0, C = 0;

	while (Ndays--) {

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

		int AA = max(B, C) + a;

		int BB = max(A, C) + b;

		int CC = max(A, B) + c;

		A = AA, B = BB, C = CC;

	}

	printf("%d", max(max(A, B), C));

}

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

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

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

#include<algorithm>

#define MAXN 100003

using namespace std;

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

int main()

{

	cin >> n;

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

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

	}

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

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

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

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

	{

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

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

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

	}

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

	return 0;

}


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

#include <algorithm>

using std::max;



int main(void)

{

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

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

}