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

using namespace std;



int m;

const int mx = 1e5+5;

int tasks[mx][3];

int diario[3][mx];

int cosa(int a, int i){

	if(i == m){

     return 0;

     }



	if(diario[a][i] != -1) {

        return diario[a][i];

    }

	int& ans = diario[a][i];



        if(a==0){

		ans=max(ans, cosa(1, i+1)+tasks[i][0]);

		ans=max(ans, cosa(2, i+1)+tasks[i][0]);

	}

        if(a==1){

		ans=max(ans, cosa(0, i+1)+tasks[i][1]);

		ans=max(ans, cosa(2, i+1)+tasks[i][1]);

        }

	if(a==2){

		ans=max(ans, cosa(0, i+1)+tasks[i][2]);

		ans=max(ans, cosa(1, i+1)+tasks[i][2]);

	}



	return ans;

}

int main(){

	cin>>m;

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

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

	}

	memset(diario, -1, sizeof diario);

	cout<<max(cosa(0,0),max(cosa(1,0),cosa(2,0)))<<"\n";

	return 0;

}


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

using namespace std;



#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void __f(const char* name, Arg1&& arg1) {

  cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f(const char* na, Arg1&& arg1, Args&&... args) {

  const char* c = strchr(na + 1, ',');

  cerr.write(na, c - na) << " : " << arg1 << " , ";

  __f(c + 1, args...);

}

#define endl "\n"

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

#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())

typedef long long LL;

typedef pair <int,int> pii;

const double pi = acos(-1.0);

const double eps = 1e-8;

const int mod = 1e9 + 7;

const int inf = 1e9;

const LL INF = 1e18;

const int N = 1e5 + 5;



LL a[ N ][ 5 ];

LL dp[ N ][5 ];



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0); cout.tie(0);

  #ifdef LOCAL

    freopen("input.txt", "r", stdin);

  #endif // LOCAL

  int n;

  cin >> n;

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

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

      cin >> a[i][j];

    }

  }

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

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

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

        if (j != k) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][k]);

      }

    }

  }

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

  return 0;

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;



int nn;

const int nxx = 1e5+5;

int acc[nxx][3];

int dpp[3][nxx];

int go(int aa, int ii)

{

	if(ii==nn) return 0;

	if(dpp[aa][ii] != -1) return dpp[aa][ii];

	int& ans = dpp[aa][ii];

	if(aa==0)

	{

		ans=max(ans, go(1, ii+1)+acc[ii][0]);

		ans=max(ans, go(2, ii+1)+acc[ii][0]);

	}

	if(aa==1)

	{

		ans=max(ans, go(0, ii+1)+acc[ii][1]);

		ans=max(ans, go(2, ii+1)+acc[ii][1]);

	}

	if(aa==2)

	{

		ans=max(ans, go(0, ii+1)+acc[ii][2]);

		ans=max(ans, go(1, ii+1)+acc[ii][2]);

	}



	return ans;



}

int main()

{

    cin>>nn;

    for(int ii=0; ii<nn; ii++) cin>>acc[ii][0]>>acc[ii][1]>>acc[ii][2];

    memset(dpp, -1, sizeof dpp);

    cout<<max(go(0,0), max(go(1,0),go(2,0)))<<"\n";

    return 0;

}

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

using namespace std;



#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void __f(const char* name, Arg1&& arg1) {

  cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f(const char* na, Arg1&& arg1, Args&&... args) {

  const char* c = strchr(na + 1, ',');

  cerr.write(na, c - na) << " : " << arg1 << " , ";

  __f(c + 1, args...);

}

#define endl "\n"

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

#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())

typedef long long LL;

typedef pair <int,int> pii;

const double pi = acos(-1.0);

const double eps = 1e-8;

const int mod = 1e9 + 7;

const int inf = 1e9;

const LL INF = 1e18;

const int N = 1e5 + 5;



LL a[ N ][ 5 ];

LL dp[ N ][5 ];



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0); cout.tie(0);

  #ifdef LOCAL

    freopen("input.txt", "r", stdin);

  #endif // LOCAL

  int n;

  cin >> n;

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

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

      cin >> a[i][j];

    }

  }

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

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

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

        if (j != k) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][k]);

      }

    }

  }

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

  return 0;

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;



int n;

const int nx = 1e5+5;

int ac[nx][3];

int dp[3][nx];

int go(int a, int i)

{

	if(i==n) return 0;

	if(dp[a][i] != -1) return dp[a][i];

	int& ans = dp[a][i];

	if(a==0)

	{

		ans=max(ans, go(1, i+1)+ac[i][0]);

		ans=max(ans, go(2, i+1)+ac[i][0]);

	}

	if(a==1)

	{

		ans=max(ans, go(0, i+1)+ac[i][1]);

		ans=max(ans, go(2, i+1)+ac[i][1]);

	}

	if(a==2)

	{

		ans=max(ans, go(0, i+1)+ac[i][2]);

		ans=max(ans, go(1, i+1)+ac[i][2]);

	}

	

	return ans;

	

}

int main()

{

    cin>>n;

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

    memset(dp, -1, sizeof dp);

    cout<<max(go(0,0), max(go(1,0),go(2,0)))<<"\n";

    return 0;

}

	

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

using namespace std;



#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void __f(const char* name, Arg1&& arg1) {

  cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f(const char* na, Arg1&& arg1, Args&&... args) {

  const char* c = strchr(na + 1, ',');

  cerr.write(na, c - na) << " : " << arg1 << " , ";

  __f(c + 1, args...);

}

#define endl "\n"

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

#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())

typedef long long LL;

typedef pair <int,int> pii;

const double pi = acos(-1.0);

const double eps = 1e-8;

const int mod = 1e9 + 7;

const int inf = 1e9;

const LL INF = 1e18;

const int N = 1e5 + 5;



LL a[ N ][ 5 ];

LL dp[ N ][5 ];



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0); cout.tie(0);

  #ifdef LOCAL

    freopen("input.txt", "r", stdin);

  #endif // LOCAL

  int n;

  cin >> n;

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

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

      cin >> a[i][j];

    }

  }

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

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

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

        if (j != k) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][k]);

      }

    }

  }

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

  return 0;

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

using namespace std;

int v[100009][3];

int dp[100009][3];

int n;

int vacation(int i, int j)

{

    if(i==n-1)

        return dp[i][j]=v[i][j];

    if(i>=n || j>=3)

        return 0;

    if(dp[i][j]!=-1)

        return dp[i][j];

    int temp = INT_MIN;

        if(j==0)

        {

             temp = max(vacation(i+1,j+1)+v[i][j],temp);

        temp = max(vacation(i+1,j+2)+v[i][j],temp);

 return dp[i][j]= temp;

        }

      else  if(j==1)

        {

             temp = max(vacation(i+1,0)+v[i][j],temp);

        temp = max(vacation(i+1,2)+v[i][j],temp);

 return dp[i][j]= temp;

        }

        else

        {

             temp = max(vacation(i+1,1)+v[i][j],temp);

        temp = max(vacation(i+1,0)+v[i][j],temp);

         return dp[i][j]= temp;

        }

}



int main()

{

    cin>>n;

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

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

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

    cout<<max(vacation(0,0),max(vacation(0,1),vacation(0,2)))<<endl;

}


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

using namespace std;



#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void __f(const char* name, Arg1&& arg1) {

  cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f(const char* na, Arg1&& arg1, Args&&... args) {

  const char* c = strchr(na + 1, ',');

  cerr.write(na, c - na) << " : " << arg1 << " , ";

  __f(c + 1, args...);

}

#define endl "\n"

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

#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())

typedef long long LL;

typedef pair <int,int> pii;

const double pi = acos(-1.0);

const double eps = 1e-8;

const int mod = 1e9 + 7;

const int inf = 1e9;

const LL INF = 1e18;

const int N = 1e5 + 5;



LL a[ N ][ 5 ];

LL dp[ N ][5 ];



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0); cout.tie(0);

  #ifdef LOCAL

    freopen("input.txt", "r", stdin);

  #endif // LOCAL

  int n;

  cin >> n;

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

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

      cin >> a[i][j];

    }

  }

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

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

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

        if (j != k) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][k]);

      }

    }

  }

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

  return 0;

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



using namespace std;

typedef long long ll;

typedef double dd;

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

#define endl "\n"

#define clr(n, r) memset(n,r,sizeof(n));



void fast() {

    cin.tie(0);

    cin.sync_with_stdio(0);

}

const int MAX=1e5+10;

int n,a[MAX],b[MAX],c[MAX],dp[MAX][3];

int ans(int i,int prev){

    if(i==n)return 0;

    int path1=0,path2=0,path3=0;

    int &ret=dp[i][prev];

    if(prev!=-1&&ret!=-1)return ret;

    if(prev!=0){

        path1=a[i]+ans(i+1,0);

    }

    if(prev!=1){

        path2=b[i]+ans(i+1,1);

    }

    if(prev!=2){

        path3=c[i]+ans(i+1,2);

    }

    return ret=max(path1,max(path2,path3));

}



int main() {

    fast();

    cin>>n;

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

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

    }

    clr(dp,-1);

    cout<<ans(0,-1);

}


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

using namespace std;



#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void __f(const char* name, Arg1&& arg1) {

  cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f(const char* na, Arg1&& arg1, Args&&... args) {

  const char* c = strchr(na + 1, ',');

  cerr.write(na, c - na) << " : " << arg1 << " , ";

  __f(c + 1, args...);

}

#define endl "\n"

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

#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())

typedef long long LL;

typedef pair <int,int> pii;

const double pi = acos(-1.0);

const double eps = 1e-8;

const int mod = 1e9 + 7;

const int inf = 1e9;

const LL INF = 1e18;

const int N = 1e5 + 5;



LL a[ N ][ 5 ];

LL dp[ N ][5 ];



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0); cout.tie(0);

  #ifdef LOCAL

    freopen("input.txt", "r", stdin);

  #endif // LOCAL

  int n;

  cin >> n;

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

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

      cin >> a[i][j];

    }

  }

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

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

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

        if (j != k) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][k]);

      }

    }

  }

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

  return 0;

}
// Slower C++ solution:
/*

** author:mahmoud magdy

*/

#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define endl "\n"



inline int D()

{

    int m ;

    cin>>m;

    return m ;

}

inline ll lD()

{

    ll m ;

    cin>>m;

    return m ;

}

inline double dD()

{

    double m;

    cin>>m;

    return m;

}

void fast()

{

    ios_base :: sync_with_stdio( 0 ) ;

    cin.tie( 0 ) ;

    cout.tie( 0 ) ;

}

int n;

ll a[100005],b[100005],c[100005];

ll dp[100005][5];

ll solve(int i,int prv){

 if(i==n)return 0;

 if(dp[i][prv]!=-1)return dp[i][prv];

 ll x=0;

 if(prv!=1){

 x=a[i]+solve(i+1,1);

 }

 ll y=0;

 if(prv!=2)

 y=b[i]+solve(i+1,2);

 ll z=0;

 if(prv!=3)

 z=c[i]+solve(i+1,3);

 return dp[i][prv]=max({x,y,z});

}

int main()

{

    memset(dp,-1,sizeof dp);

    fast();

    n=D();

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

        a[i]=D();b[i]=D();c[i]=D();

    }

    cout<<solve(0,10)<<endl;

}

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

using namespace std;



#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void __f(const char* name, Arg1&& arg1) {

  cerr << name << " : " << arg1 << "\n";

}

template <typename Arg1, typename... Args>

void __f(const char* na, Arg1&& arg1, Args&&... args) {

  const char* c = strchr(na + 1, ',');

  cerr.write(na, c - na) << " : " << arg1 << " , ";

  __f(c + 1, args...);

}

#define endl "\n"

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

#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())

typedef long long LL;

typedef pair <int,int> pii;

const double pi = acos(-1.0);

const double eps = 1e-8;

const int mod = 1e9 + 7;

const int inf = 1e9;

const LL INF = 1e18;

const int N = 1e5 + 5;



LL a[ N ][ 5 ];

LL dp[ N ][5 ];



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0); cout.tie(0);

  #ifdef LOCAL

    freopen("input.txt", "r", stdin);

  #endif // LOCAL

  int n;

  cin >> n;

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

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

      cin >> a[i][j];

    }

  }

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

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

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

        if (j != k) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][k]);

      }

    }

  }

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

  return 0;

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

using namespace std;



const int MaxN = 100005;



int n;

int f[MaxN][3], val[MaxN][3];



void upd(int &a, int b) {

	if (b > a) a = b;

}



int main() {

	scanf("%d", &n);

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

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

	}

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

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

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

				if (j == k) continue;

				upd(f[i][j], f[i - 1][k] + val[i][j]);

			}

		}

	}

	int Ans = 0;

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

			upd(Ans, f[n][j]);

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

	return 0;

}

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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 10;

int dp[maxn][3];

int abc[3];

int main()

{

	int n;

	while(~scanf("%d",&n)){

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

		dp[0][0] = abc[0];

		dp[0][1] = abc[1];

		dp[0][2] = abc[2];

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

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

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

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

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

		} 

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

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

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

	}

	return 0;

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

using namespace std;

 

#define mp make_pair

#define pb push_back

#define st first

#define nd second

#define lb lower_bound

#define ub upper_bound

 

typedef long long ll;

typedef long double ld;

typedef pair<int,int> pi;

typedef pair<ll,ll> pll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<pi> vpi;

typedef vector<pll> vpll;

 

const ll oo=1e18;

const int MOD=1000000007;

const int INF=1000000000;

const ld EPS=0.000000001;

 

int dp[100005][3],n,a,b,c;

 

signed main() {

    ios_base::sync_with_stdio(NULL);

    cin.tie(NULL);

    cout.tie(NULL);

    cin>>n;

    cin>>a>>b>>c;

    dp[1][0]=a;

    dp[1][1]=b;

    dp[1][2]=c;

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

        cin>>a>>b>>c;

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

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

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

    }

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

    return 0;

}

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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 10;

int dp[maxn][3];

int abc[3];

int main()

{

	int n;

	while(~scanf("%d",&n)){

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

		dp[0][0] = abc[0];

		dp[0][1] = abc[1];

		dp[0][2] = abc[2];

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

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

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

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

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

		} 

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

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

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

	}

	return 0;

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

using namespace std;

int x[100000][3];

int a[100001][3], mx=0;

int calc(int pos, int u)

{

	if(pos==-1) return 0;

	if(a[pos][u]==-1)

	{

		//if(pos==0) a[pos][u]=mx(x[pos][(u+1)%3],x[pos][(u+2)%3]);

		a[pos][u]=max(calc(pos-1, (u+1)%3)+x[pos][(u+1)%3],calc(pos-1, (u+2)%3)+x[pos][(u+2)%3]);

	}

	return a[pos][u];

}



int main() {

	int n;

	cin>>n;

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

	{

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

		{

			cin>>x[i][u];

		}

	}

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

	{

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

		{

			a[i][u]=-1;

		}

	}

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

	{

		if(mx<calc(n, i) ) mx=calc(n-1, i);

	}

	cout<<mx;

	return 0;

}

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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 10;

int dp[maxn][3];

int abc[3];

int main()

{

	int n;

	while(~scanf("%d",&n)){

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

		dp[0][0] = abc[0];

		dp[0][1] = abc[1];

		dp[0][2] = abc[2];

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

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

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

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

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

		} 

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

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

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

	}

	return 0;

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

#define LL long long

using namespace std;

const int N =1e6;



LL int dp[N][4], a[N], b[N], c[N];



int main(){

    int n;

    cin >> n;

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

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

    }

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

    dp[0][1] = b[0];

    dp[0][2] = c[0];

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

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

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

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

        //cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;

    }

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

    cout << ans << endl;

}


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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 10;

int dp[maxn][3];

int abc[3];

int main()

{

	int n;

	while(~scanf("%d",&n)){

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

		dp[0][0] = abc[0];

		dp[0][1] = abc[1];

		dp[0][2] = abc[2];

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

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

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

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

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

		} 

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

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

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

	}

	return 0;

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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 10;

int dp[maxn][3];

int abc[3];

int main()

{

	int n;

	while(~scanf("%d",&n)){

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

		dp[0][0] = abc[0];

		dp[0][1] = abc[1];

		dp[0][2] = abc[2];

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

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

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

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

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

		} 

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

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

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

	}

	return 0;

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

using namespace std;



int main(){



    int n, flag;

    long long ans = 0;



    cin >> n;

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

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

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

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

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

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

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

    }

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



    return 0;

}


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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 10;

int dp[maxn][3];

int abc[3];

int main()

{

	int n;

	while(~scanf("%d",&n)){

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

		dp[0][0] = abc[0];

		dp[0][1] = abc[1];

		dp[0][2] = abc[2];

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

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

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

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

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

		} 

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

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

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

	}

	return 0;

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

using namespace std;



typedef long long  int ll;



#define s(t) scanf("%I64d",&t)

#define s2(t,t1) scanf("%I64d%I64d",&t,&t1)





ll n,a[100005][3];

int main()

{

    cin>>n;

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

    {

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

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

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

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



    }

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







}


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

#include<algorithm>

using namespace std;

const int maxn = 1e5 + 10;

int dp[maxn][3];

int abc[3];

int main()

{

	int n;

	while(~scanf("%d",&n)){

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

		dp[0][0] = abc[0];

		dp[0][1] = abc[1];

		dp[0][2] = abc[2];

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

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

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

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

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

		} 

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

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

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

	}

	return 0;

 }