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

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	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: 11.556245115519044x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	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: 5.272101743272674x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	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: 5.143871190104854x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	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: 5.279840340306349x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	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: 5.216688612942173x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	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: 5.202939535256729x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	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: 5.270189257465696x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	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: 5.1695545888397865x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	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: 5.272068045046374x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	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: 5.271593882381137x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	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: 5.21311599688889x):
#include <cstdio>

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

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

#include <iostream>

#include<vector>

#include<algorithm>

using namespace std;

	vector<int> p[3];

int main(){

	int n,t1,t2,t3;

	cin>>n;

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

		scanf("%d %d %d",&t1,&t2,&t3);

		p[0].push_back(t1);

		p[1].push_back(t2);

		p[2].push_back(t3);

	}

	int a[3],b[3];

	b[0]=a[0]=p[0][0];

	b[1]=a[1]=p[1][0];

	b[2]=a[2]=p[2][0];

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

		a[0]=p[0][i]+max(b[1],b[2]);

		a[1]=p[1][i]+max(b[0],b[2]);

		a[2]=p[2][i]+max(b[0],b[1]);

		b[0]=a[0];b[1]=a[1];b[2]=a[2];

	}

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

	return 0;

}


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

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

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

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

using namespace std;

int n,a[1000010],b[1000010], c[1000010],dp[1000010][5];

int main()

{

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

    return 0;

}

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

#include <algorithm>

using std::max;

const int maxn = 100003;

int d[maxn][3],a[maxn][3];

int main() {

	int i,n;

    scanf("%d", &n);

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

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

    }

    d[0][0] = a[0][0];

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

	d[0][2] = a[0][2];

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

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

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

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

	}

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

	return 0;

}