stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
// 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;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

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

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

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

#include <cmath>



using namespace std;



int escolhas(int dia, int k);



int n_dias;



int atividades[100001][3];



int pontos[100001][3];



int main(){

    cin >> n_dias;



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

        cin >> atividades[i][1];

        cin >> atividades[i][2];

        cin >> atividades[i][3];

    }



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

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

            pontos[i][j] = -1;

        }

    }



    int felicidade = escolhas(1, -1);



    cout << felicidade << endl;



    return 0;

}



int escolhas(int dia, int k){

    if(dia == n_dias + 1){

        return 0;

    }



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

        if(i != k){

            if(pontos[dia][i] == -1){

                pontos[dia][i] = atividades[dia][i] + escolhas(dia + 1, i);

            }

        }

    }



    int maximo = 0;



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

        if(i != k){

            if(pontos[dia][i] > maximo){

                maximo = pontos[dia][i];

            }

        }

    }



    return maximo;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

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



using namespace std;



vector<vector<int> > v;

int ans[100005][3];

queue<pair<int,pair<int,int> > >s;

int maior,a=0;



void dp(int i, int bloq, int sum) {

  if(ans[i-1][bloq]>sum)

    return;

  

  if (i>=v.size())

    maior = max(sum, maior);

  else {

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

      if (bloq != j) {



        if(ans[i][j]==-1) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }

        else if (ans[i][j]<sum+v[i][j]) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }



        //dp(i+1, j, sum+v[i][j]);

      }

    }

  }

}



int main () {

  int n;

  cin>>n;

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

    int a,b,c;

    cin>>a>>b>>c;

    v.push_back({a,b,c});

  }



  maior=0;

  memset(ans, -1, sizeof(ans));

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

    s.push({v[0][i],{1,i}});

    //dp(1, i, v[0][i]);

  }



  while(!s.empty()) {

    pair<int,pair<int,int> > aux = s.front();

    dp(aux.second.first, aux.second.second, aux.first);

    s.pop();

  }



  cout<<maior<<endl;



}




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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

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



using namespace std;



#define INF (1ll << 62)

#define pb push_back

#define ii pair<int,int>

#define OK cerr <<"OK"<< endl

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

#define ff first

#define ss second

#define int long long

#define tt tuple<int, int, int>

#define endl '\n'



int dp[200000][3];

int mat[200000][3];





signed main () {

  

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);



  int n;



  cin >> n;



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

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

  		cin >> mat[i][j];

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

  			if(j == k)

  				continue;

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

  		}

  	}

  }



  cout << *max_element(dp[n], dp[n] + 3) << endl;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

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

#include<iostream>

#include<algorithm>

#include<cmath>

using namespace std;



const int maxn = 1e5 + 5;

int dp[maxn][4];

int day[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",&day[i][j]);

		}

	}



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

		dp[1][i] = day[1][i];

	}



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

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

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

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

	}



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



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



	return 0;

}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

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

#define ll long long

#define ld long double

#define ull unsigned ll

#define ioi exit(0);

 

#define f first

#define s second

 

#define inf (int)1e9 + 7

 

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

 

#define mp(x,y) make_pair(x,y)

 

#define lb(x) lower_bound(x)

#define ub(x) upper_bound(x)

 

#define pb push_back

#define ppb pop_back

 

#define bitcoin __builtin_popcount

 

#define endl "\n"

 

#define in(x) insert(x)

 

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

 

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

 

#define pw2(x) (1ll<<x) //2^x

 

#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)

 

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

 

#define UpdateRandom srand (time(NULL));

 

using namespace std;

 

const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;



int n;

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

int dp[N][10];



int main(){

		

	NFS

	

	cin >> n;

	

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

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

	}

	

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

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

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

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

	}

	

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



	ioi

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}
// Slower C++ solution:
/***************************************************************

Esse é um problema parecido com o problema da mochila.

Usando o código do exercício anterior

***************************************************************/

#include <bits/stdc++.h>



using namespace std;



int main(){

    int n=0, q=0;



    cin >> n;

    

    int matrix[n][3], resp[n][3];

    

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

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

            cin >> matrix[i][j];

            resp[i][j]=-1;

        }

    }



    resp[0][0]=matrix[0][0];

    resp[0][1]=matrix[0][1];

    resp[0][2]=matrix[0][2];

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

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

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

                    if (j==k){

                        continue;

                    }else{

                    

                    q=max(resp[i+1][k], resp[i][j]+matrix[i+1][k]);

                    }

                    // cout << "k: " << k << " j: " << j << endl;

                resp[i+1][k]=q;

                }

                // cout << "To no j" << endl;

        }

        // cout << "To no i" << endl;

    }

    

    

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

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

    //         cout << resp[i][j] << " ";  

    //     }

    //     cout << endl;

    // }



    //Não funciona, tem que imprimir o valor máximo na n-linha

    //cout << resp[n-1][2] << endl;

    int resposta=0;

    if(resp[n-1][0] >=resp[n-1][1] && resp[n-1][0] >=resp[n-1][2]){

        resposta = resp[n-1][0];

    }else if(resp[n-1][1] >=resp[n-1][0] && resp[n-1][1] >=resp[n-1][2]){

        resposta = resp[n-1][1];

    }else if(resp[n-1][2] >=resp[n-1][0] && resp[n-1][2] >=resp[n-1][1]){

        resposta = resp[n-1][2];

    }

    cout << resposta << endl;

    



}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

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



#define pb push_back

#define se second

#define fi first



using namespace std;



long long n, a[(int)1e5 + 7][3], d[(int)1e5 + 7][3];



int main(){

    cin >> n;

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

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

    d[1][1] = a[1][1];

    d[1][2] = a[1][2];

    d[1][3] = a[1][3];

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

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

            for(int h = 1; h <= 3; h++)

                if(h != j)

                    d[i][j] = max(d[i][j], d[i - 1][h] + a[i][j]);

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

}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

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



using namespace std;



#define ff first

#define ss second

#define int long long

#define pii pair<int,int>

#define mp make_pair



signed main(){

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	int n,i,j;

	cin>>n;

	pii dx[3] = {mp(1,2),mp(0,2),mp(0,1)};

	int mat[n][3],memo[n][3];

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

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

			cin>>mat[i][j];

		}

	}

	for(i=0;i<3;i++)memo[0][i]=mat[0][i];

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

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

			memo[i][j]=max(memo[i-1][dx[j].ff],memo[i-1][dx[j].ss])+mat[i][j];

		}	

	}

	int maior=-1;

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

		if(memo[n-1][i]>maior)maior=memo[n-1][i];

	}	



	cout<<maior<<endl;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

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

#define ll long long

using namespace std;

ll n,a[100010],b[100010],c[100010],dp[100010][3],ans=0;

inline int read(){

     int x=0,f=1;char ch=getchar();

     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

     while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}

     return x*f;

 }

int main ( )

{

	n=read();

	for(int i=1;i<=n;i++) a[i]=read(),b[i]=read(),c[i]=read();

	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]=std::max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);

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

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

	}

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

	cout<<ans;

	return 0;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}
// Slower C++ solution:
//#pragma GCC target("avx2")

//#pragma GCC optimize("O3")

   

//#include <x86intrin.h>

#include <bits/stdc++.h>   

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace __gnu_pbds;

using namespace std;



template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

     

#define F first

#define S second           

#define lb lower_bound               

#define ub upper_bound

#define pb push_back

#define pf push_front    

#define ppb pop_back

#define mp make_pair                                     

#define bpp __builtin_popcountll                                                                                        

#define sqr(x) ((x) * (x)) 

#define al 0x3F3F3F3F

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

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

#define in insert

#define ppf pop_front

#define endl '\n'

//#define int long long

 

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

typedef pair <int, int> pii;

 

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

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

const ll inf = (ll)1e18 + 1;



const double pi = acos (-1.0);

const double eps = 1e-7;                  

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

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



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



inline void boost () {                    

   ios_base :: sync_with_stdio (NULL);

   cin.tie (NULL), cout.tie (NULL);          

}                                                     



inline void Solve () {

   cin >> n;

   for (int i = 1; i <= n; i ++) cin >> a[i][1] >> a[i][2] >> a[i][3];

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

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

   }                                              

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

      

     

}



main () {                                       

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

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

   boost ();

   int tt = 1;

   //cin >> tt;   

   while (tt --) {

      Solve ();

   }                                               

   return 0;      

}

                          

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

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

using namespace std;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    long long n;

    cin >> n;

    long long a[n + 1][3], dp[n + 1][3];

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

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

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

    }

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

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

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

    for(long long i = 2; 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][0], dp[i - 1][1]) + a[i][2];

    }

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

    return 0;

}


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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

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

#include<cstdio>

using namespace std;

typedef struct day{

    int a,b,c;

}D;

int Max(int a,int b){

    return a>b?a:b;

}

int MM(D d){

    int m=d.a>d.b?d.a:d.b;

    return d.c>m?d.c:m;

}

int main()

{

    int n;

    D t,dp[2];

    cin>>n;

    dp[0].a=dp[0].b=dp[0].c=0;

    while(n--){

        cin>>t.a>>t.b>>t.c;

        dp[1].a=t.a+Max(dp[0].b,dp[0].c);

        dp[1].b=t.b+Max(dp[0].a,dp[0].c);

        dp[1].c=t.c+Max(dp[0].a,dp[0].b);

        dp[0]=dp[1];

    }

    cout<<MM(dp[1])<<endl;

    return 0;

}

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

#include<algorithm>

int main(){

  int j=1,x,da[3][100001],fun[3][2];

  scanf("%d",&x);

  fun[0][0] = fun[1][0] = fun[2][0] = 0;

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

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

    fun[0][j] = std::max(fun[1][j^1],fun[2][j^1]) + da[0][i];

    fun[1][j] = std::max(fun[0][j^1],fun[2][j^1]) + da[1][i];

    fun[2][j] = std::max(fun[1][j^1],fun[0][j^1]) + da[2][i];

    j^=1;

  }

  j^=1;

  printf("%d\n",std::max(std::max(fun[0][j],fun[1][j]),fun[2][j]));

  

  return 0;

}