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

#include <limits.h>

#include <algorithm>  

#include <numeric>

 

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

using namespace std;

 

#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define endl '\n'

using ll = long long;

 

const int precision = 3;

const int modulo =  1000000007; // 10^9 + 7

const ll lmodulo =  1000000007; // 10^9 + 7

 

const double EPS = 1e-9;

const ll inf = 1e18;



void solve () {

	int n; cin >> n;

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

	for (auto &it : days) {

		cin >> it[0] >> it[1] >> it[2];

	}



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

	dp[0] = days[0];



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

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

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

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

	}



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

	ret = max(ret, dp[n - 1][2]);

	cout << ret << endl;

}



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(nullptr);

  cout.tie(nullptr);

  cout.precision(precision);

  cout.setf(ios_base::fixed);

  solve();

  return 0;

}




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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 5;

int dp[maxn][5] , a[maxn][4];

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

		}

	}

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

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



    for (int i = 0; i < 3; ++i) dp[1][i] = arr[1][i];



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][2]);



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 5;

int dp[maxn][5] , a[maxn][4];

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

		}

	}

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

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

using namespace std;

int main()

{

    int n, i, j, k;

    scanf("%d",&n);

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

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

    {

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

    }

    int dp[n+5][3];

    memset(dp, 0, sizeof(dp));

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

    }

    int ans = 0;

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

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

    cout << ans << "\n";

    return 0;

}


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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 5;

int dp[maxn][5] , a[maxn][4];

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

		}

	}

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

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

#include<stdio.h>

#include<vector>

#pragma GCC optimize(2)

typedef long long ll;

typedef unsigned long long ull;

const int mod=1000;

const int maxn=1e5+5;

const ll INF=100000000000005;

using namespace std;

ll n,m,p;

ll qpow(ll a,ll b){ll ans=1;while(b){if(b&1) ans=(ans*a)%mod;b/=2;a=(a*a)%mod;}return ans;}

struct node{

    ll a,b,c;

}save[maxn];

ll dp[maxn][4];

int main()

{

    scanf("%lld",&n);

    for(int i=1;i<=n;i++) scanf("%lld%lld%lld",&save[i].a,&save[i].b,&save[i].c);

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

    {

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

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

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

    }

    ll res=0;

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

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

    return 0;

}

/***

10 4

40 10 20 70 80 10 20 70 80 60

***/


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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 5;

int dp[maxn][5] , a[maxn][4];

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

		}

	}

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

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



using namespace std;

int main(){

	long long n,ans=0;

	scanf("%lld", &n);

	long long a[n+5],b[n+5],c[n+5],check[n+5][4];

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

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

	memset(check,0,sizeof(check));

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

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

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

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

	}

	ans=max(check[n][1], check[n][2]);

	ans=max(ans,check[n][3]);

	printf("%lld", ans);

} 

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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 5;

int dp[maxn][5] , a[maxn][4];

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

		}

	}

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

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

#include<map>

#include<cmath>

#include<ctime>

#include<queue>

#include<stack>

#include<cstdio>

#include<string>

#include<vector>

#include<random>

#include<cstdlib>

#include<cstring>

#include<iomanip>

#include<iostream>

#include<algorithm>

#include<unordered_map>

#define endl "\n"

#define fi first

#define se second

#define db double

#define gcd __gcd

#define pb push_back

#define mp make_pair

#define lowbit(x) (x & (-x))

#define PII  pair<int, int> 

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

#define debug(x) cout << #x << " = " << x << endl

#define rep(i, a, b) for(__typeof(b) i = a; i <= (b); i++)

#define Rep(i, a, b) for(__typeof(a) i = a; i >= (b); i--)

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

template<class T> inline T qmin(T a, T b) { return a < b ? a : b; }

template<class T> inline T qmax(T a, T b) { return a > b ? a : b; }

typedef long long ll;

typedef unsigned long long ull;

const db eps = 1e-9;

const db PI = acos(-1);

const int inf = 0x3f3f3f3f;

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

const int maxn = (int)1e5 + 5;//remember to modify it, No RE or MLE

const ll INF = 0x3f3f3f3f3f3f3f3f;

using namespace std;

ll qpow(ll x, ll y) { ll ret = 1; for( ; y; y >>= 1, x = (x * x) % mod) if(y & 1) ret = (ret * x) % mod; return ret; }



inline int read(){

	char ch = getchar();

	int x = 0, f = 1;

	while(ch < '0' || ch > '9'){

		if(ch == '-') f = -1;

		ch = getchar();

	}

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

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

		ch = getchar();

	}

	return x * f;

}



int n;

int val[3][maxn];

int dp[maxn][3];



int main()

{

	n = read();

	rep(i, 1, n) rep(j, 0, 2) val[j][i] = read();

	rep(i, 1, n){

		rep(j, 0, 2){

			rep(k, 0, 2){

				if(k == j) continue;

				dp[i][j] = qmax(dp[i][j], dp[i-1][k] + val[j][i]);

			}

		}

	}

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

	return 0;

}

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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 5;

int dp[maxn][5] , a[maxn][4];

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

		}

	}

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

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

using namespace std;



#define MAX_N 100005

int N, h[MAX_N][3], memo[MAX_N][3];



int main() {

  scanf("%i", &N);

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

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

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

	}

  }

  memset(memo, -1, sizeof memo);

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

  	memo[0][c] = h[0][c];

  }

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

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

  	  int &opt = memo[d][c];

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

  	    if (cc != c) {

  	      opt = max(opt, memo[d - 1][cc] + h[d][c]);

		  /*

  	      if (d == 1) {

  	        printf("%i %i %i %i\n", memo[d - 1][cc], h[d][c], cc, c);

		  }

		  */

		}

	  }

	}

  }

  /*

  puts("\ndebug");

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

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

  	  printf("%i ", memo[d][c]);

	}

	puts("");

  }

  puts("end-debug\n");

  */

  int ans = -1;

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

  	ans = max(ans, memo[N - 1][c]);

  }

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

  

}

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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 5;

int dp[maxn][5] , a[maxn][4];

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

		}

	}

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

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

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

int main()

{

    int n,i,j,k;

    int a[100005][5];

    scanf("%d",&n);

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

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

    int dp[100005][5];

    memset(dp,0,sizeof(dp));

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

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

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

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

    {

        for(j = 1;j < 4;j++)

        {

            for(k = 1;k < 4;k++)

            {

                if(k != j)

                {

                    if(dp[i][j] < dp[i - 1][k] + a[i][j])

                    dp[i][j] = dp[i - 1][k] + a[i][j];

                }

            }

        }

    }

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

    return 0;

}

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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 5;

int dp[maxn][5] , a[maxn][4];

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

		}

	}

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

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

#include<vector>

using namespace std;

int main(){

  int n;

  cin>>n;

  vector<vector<int>>task;

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

    task.push_back({0});

  

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

    int a;

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

      cin>>a;

      if(j==0)task[0].push_back(max(task[1][i],task[2][i])+a);

      if(j==1)task[1].push_back(max(task[0][i],task[2][i])+a);

      if(j==2)task[2].push_back(max(task[1][i],task[0][i])+a);

    }

  }

  cout<< max(task[0][task[0].size()-1],max(task[1][task[1].size()-1],task[2][task[2].size()-1]))<<endl;

}

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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 5;

int dp[maxn][5] , a[maxn][4];

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

		}

	}

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

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



    for (int i = 0; i < 3; ++i) dp[1][i] = arr[1][i];



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][2]);



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.5338037136180054x):
// Problem B - Vacation - MATA52

#include <iostream>

#include<bits/stdc++.h>



using namespace std;



int main() {

    int days;

    int max_a = -1, max_b = -1, max_c = -1, max_happiness = -1;

    int a_ant = 0, b_ant = 0, c_ant = 0, a, b, c;

    

    cin >> days;

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

        cin >> a >> b >> c;     // read activities 

        int today_a = max(b_ant + a, c_ant + a);     // activity a with others

        max_a = max(today_a, max_a);                 // max of activities a

        max_happiness = max(max_a, max_happiness);   // max Taro happiness

        

        int today_b = max(a_ant + b, c_ant + b);    // activity b with others

        max_b = max(today_b, max_b);                // max of activities b

        max_happiness = max(max_b, max_happiness);  // max Taro happiness

        

        int today_c = max(b_ant + c, a_ant + c);    // activity c with others

        max_c = max(today_c, max_c);                // max of activities c

        max_happiness = max(max_c, max_happiness);  // max Taro happiness

        

        // update activities of yesterday with the choices of today

        a_ant = today_a;

        b_ant = today_b;

        c_ant = today_c;

    }

    // print max happiness obtained

    cout << max_happiness << endl;

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

using namespace std;



#define MAX_N 100005

int N, h[MAX_N][3], memo[MAX_N][3];



int main() {

  scanf("%i", &N);

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

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

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

	}

  }

  memset(memo, -1, sizeof memo);

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

  	memo[0][c] = h[0][c];

  }

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

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

  	  int &opt = memo[d][c];

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

  	    if (cc != c) {

  	      opt = max(opt, memo[d - 1][cc] + h[d][c]);

		  /*

  	      if (d == 1) {

  	        printf("%i %i %i %i\n", memo[d - 1][cc], h[d][c], cc, c);

		  }

		  */

		}

	  }

	}

  }

  /*

  puts("\ndebug");

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

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

  	  printf("%i ", memo[d][c]);

	}

	puts("");

  }

  puts("end-debug\n");

  */

  int ans = -1;

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

  	ans = max(ans, memo[N - 1][c]);

  }

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

  

}

// Faster C++ solution for the same problem (measured speedup: 2.186719869349099x):
// Problem B - Vacation - MATA52

#include <iostream>

#include<bits/stdc++.h>



using namespace std;



int main() {

    int days;

    int max_a = -1, max_b = -1, max_c = -1, max_happiness = -1;

    int a_ant = 0, b_ant = 0, c_ant = 0, a, b, c;

    

    cin >> days;

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

        cin >> a >> b >> c;     // read activities 

        int today_a = max(b_ant + a, c_ant + a);     // activity a with others

        max_a = max(today_a, max_a);                 // max of activities a

        max_happiness = max(max_a, max_happiness);   // max Taro happiness

        

        int today_b = max(a_ant + b, c_ant + b);    // activity b with others

        max_b = max(today_b, max_b);                // max of activities b

        max_happiness = max(max_b, max_happiness);  // max Taro happiness

        

        int today_c = max(b_ant + c, a_ant + c);    // activity c with others

        max_c = max(today_c, max_c);                // max of activities c

        max_happiness = max(max_c, max_happiness);  // max Taro happiness

        

        // update activities of yesterday with the choices of today

        a_ant = today_a;

        b_ant = today_b;

        c_ant = today_c;

    }

    // print max happiness obtained

    cout << max_happiness << endl;

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

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

int main()

{

    int n,i,j,k;

    int a[100005][5];

    scanf("%d",&n);

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

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

    int dp[100005][5];

    memset(dp,0,sizeof(dp));

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

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

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

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

    {

        for(j = 1;j < 4;j++)

        {

            for(k = 1;k < 4;k++)

            {

                if(k != j)

                {

                    if(dp[i][j] < dp[i - 1][k] + a[i][j])

                    dp[i][j] = dp[i - 1][k] + a[i][j];

                }

            }

        }

    }

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.2670718342425453x):
// Problem B - Vacation - MATA52

#include <iostream>

#include<bits/stdc++.h>



using namespace std;



int main() {

    int days;

    int max_a = -1, max_b = -1, max_c = -1, max_happiness = -1;

    int a_ant = 0, b_ant = 0, c_ant = 0, a, b, c;

    

    cin >> days;

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

        cin >> a >> b >> c;     // read activities 

        int today_a = max(b_ant + a, c_ant + a);     // activity a with others

        max_a = max(today_a, max_a);                 // max of activities a

        max_happiness = max(max_a, max_happiness);   // max Taro happiness

        

        int today_b = max(a_ant + b, c_ant + b);    // activity b with others

        max_b = max(today_b, max_b);                // max of activities b

        max_happiness = max(max_b, max_happiness);  // max Taro happiness

        

        int today_c = max(b_ant + c, a_ant + c);    // activity c with others

        max_c = max(today_c, max_c);                // max of activities c

        max_happiness = max(max_c, max_happiness);  // max Taro happiness

        

        // update activities of yesterday with the choices of today

        a_ant = today_a;

        b_ant = today_b;

        c_ant = today_c;

    }

    // print max happiness obtained

    cout << max_happiness << endl;

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



    for (int i = 0; i < 3; ++i) dp[1][i] = arr[1][i];



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][2]);



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


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



using namespace std;



int vacation(int table_of_happiness[][3], int j, int r[][4], int nxt){

	if(j==-1){

		return 0;

	}

	if(r[j][nxt] >= 0){

		return r[j][nxt];

	}

	else{

		int t[3];

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

			if(nxt != i)

				t[i] = vacation(table_of_happiness, j-1, r, i) + table_of_happiness[j][i];

		int best=0;

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

			if(nxt != i && t[i] > best){

				best = t[i];

			}

		}

		r[j][nxt] = best;

		return r[j][nxt];

	}

}



int main(){

	int N;

	scanf("%d", &N);

	int table_of_happiness[N][3];

	int r[N][4];

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

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

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

		}

	}



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

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

			r[i][j] = -1;

		}

	}



	r[N-1][3] = vacation(table_of_happiness, N-1, r, 3);



	printf("%d\n", r[N-1][3]);

}