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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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

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

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

using namespace std;

typedef long long ll;

const int inf = 1001001001;

 

int main(){

  int n;

  cin >> n;

  

  vector<vector<int>> h(n, vector<int>(3));

  rep(i,n){

    rep(j,3){

      cin >> h.at(i).at(j);

    }

  }

  vector<vector<int>> dvector(n, vector<int>(3,0));

  

  

  rep(i,n){

    

    if (i == 0){

      rep(l,3){dvector.at(0).at(l) = h.at(0).at(l);}

      continue;

    }

    

    rep(j,3){

      rep(k,3){

        

      if(k != j){

        dvector.at(i).at(j) = max(dvector.at(i).at(j), dvector.at(i-1).at(k)+h.at(i).at(j));

      }

      

      }

    }

  }

    

    int ans = 0;

    rep(i,3){

    ans = max(ans, dvector.at(n-1).at(i));

    }

    

    cout << ans << endl;

    

  }


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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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

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



#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

#define repd(i,x,n) for(int i=x;i<=n;i++)



using namespace std;

typedef long long ll;

inline void getInt(int* p);

const int maxn=1000010;

const int inf=0x3f3f3f3f;

ll n;

ll a[maxn];

ll b[maxn];

ll c[maxn];

ll dp[maxn][5];



int main()

{

    gbtb;

    cin>>n;

    repd(i,1,n)

    {

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

    }

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

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

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

    repd(i,2,n)

    {

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

    return 0;

}



inline void getInt(int* p) {

    char ch;

    do {

        ch = getchar();

    } while (ch == ' ' || ch == '\n');

    if (ch == '-') {

        *p = -(getchar() - '0');

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 - ch + '0';

        }

    }

    else {

        *p = ch - '0';

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 + ch - '0';

        }

    }

}

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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]);

    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

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

}