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

#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: 4.454412558210661x):
#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 ll long long

#define ull unsigned long long

#define mst(a, b) memset((a), (b), sizeof(a))

#define mp(a, b) make_pair(a, b)

#define pi acos(-1)

#define pii pair<int, int>

#define pb push_back

const int INF = 0x3f3f3f3f;

const double eps = 1e-10;

const int maxn = 1e5 + 107;

const int maxm = 5e5 + 10;

int s[maxn][3];

int dp[maxn][3];

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int n;

    cin >> n;

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

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

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

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

    {

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

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

        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+s[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.549375340262849x):
#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;

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: 9.917551622431684x):
#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;



const int nmax =100010;



int act[3];

int dp[nmax][3];



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    int n;cin>>n;

    int a=0 , b=0 ,c=0;

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

    {

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

        dp[i][0]=max(b + act[0], c + act[0]);

        dp[i][1]=max(a + act[1], c + act[1]);

        dp[i][2]=max(a + act[2], b + act[2]);

        a = dp[i][0];

        b = dp[i][1];

        c = dp[i][2];

    }

    int sol = max({ dp[n][0],dp[n][1],dp[n][2] });

    cout<<sol;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.5439016891053114x):
#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 dp[100007][5], a[100007][5];



int main() {

	int n;

	cin >> n;

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

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

	}  

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

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

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

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

		dp[i][0] = 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 - 1][0], dp[n - 1][1], dp[n - 1][2] } );

}

// Faster C++ solution for the same problem (measured speedup: 4.489179453794102x):
#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 forn(i, n) for (int i = 0; i < int(n); ++i)

#define for1(i, n) for (int i = 1; i <= int(n); ++i)

#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)

#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)

#define pb push_back

#define eb emplace_back

#define ms(a, x) memset(a, x, sizeof(a))

#define F first

#define S second

#define endl '\n'

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

#define de2(x,y) cout<<#x<<" = "<<(x) <<' '<< #y<<" = "<<y<<endl;



using namespace std;



typedef long long ll;

typedef pair<int, int> pii;

const int INF = 0x3f3f3f3f;

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());



const int N=1e5+5;

int a[N][3];

int dp[N][4];

int n;

int dfs(int x,int la){

	if(x==n+1) return 0;

	if(dp[x][la]) return dp[x][la];

	int res=0;

	forn(i,3){

		if(i==la) continue;

		res=max(res,a[x][i]+dfs(x+1,i));

	}

	return dp[x][la]=res;

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

	cin>>n;

	for1(i,n){

		forn(j,3) cin>>a[i][j];

	}

	cout<<dfs(1,4);

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 4.58202049275239x):
#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 <bits/stdc++.h>



using namespace std;

int a[100005][5], p[100005][5];



int main()

{

    int n, i, j;

    cin>>n;

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

    {

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

        {

            cin>>a[i][j];

        }

    }

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

    {

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

        {

            if(i==0)

            {

                p[i][j]=a[i][j];

            }

            else if(j==0)

            {

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

            }

            else if(j==1)

            {

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

            }

            else if(j==2)

            {

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

            }

        }

    }

    n--;

    cout<<max(p[n][0],max(p[n][1],p[n][2]))<<"\n";



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.4980465766653435x):
#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 all(v) v.begin(), v.end()

#define mp make_pair

using namespace std;



using ll = long long;

using ii = pair<int, int>;

const int INF = (int)10e9;

int dp[3][100005];



int main() {

    std::ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    int N;

    cin>>N;

    vector<int> a(N), b(N), c(N);

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

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

    }



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

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

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

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

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

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

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

    }

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



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.592849789526811x):
#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;

const int oo = 1e9;

int number;

const int nx = 1e5+5;

int ac[nx][3];

int dyn[3][nx];

int init(int a, int i){

	if(i == number) return 0;

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

	int& res = dyn[a][i];

	

	if(a==0){

		res=max(res, init(1, i+1)+ac[i][0]);

		res=max(res, init(2, i+1)+ac[i][0]);

	}

	if(a==1){

		res=max(res, init(0, i+1)+ac[i][1]);

		res=max(res, init(2, i+1)+ac[i][1]);

	}

	if(a==2){

		res=max(res, init(0, i+1)+ac[i][2]);

		res=max(res, init(1, i+1)+ac[i][2]);

	}

	

	return res;

}

int main(){

	cin>>number;

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

	memset(dyn, -1, sizeof dyn);

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

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 9.917659854126844x):
#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(){  

    int n;

    cin >> n;

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

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

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

            cin >> h[i][j];

        }

    }

 

    vector<array<long long,3>> dp(n);

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

        dp[0][j] = h[0][j];

    }

    

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

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

            dp[i][j] = 0;

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

                if (j == k) continue;

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

            }

        }

    }

    return cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << '\n',0; 

}

// Faster C++ solution for the same problem (measured speedup: 4.53718936427498x):
#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;

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 x, int i){

	if(i==n) return 0;

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

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

	if(x==0)

	{

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

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

	}

	if(x==1)

	{

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

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

	}

	if(x==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: 9.917551622431684x):
#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;

typedef long long ll;



ll arr[100009][3];

int dp[100009][2][2][2];



long long VAC1(int n,int a, int b, int c)

{



    if(!n && a) return arr[n][0];

    else if(!n && b) return arr[n][1];

    else if(!n && c) return arr[n][2];

    else if(dp[n][a][b][c]!=-1)return dp[n][a][b][c];



    else

    {



        ll x,y,z;

        if(a)

        {

            x = VAC1(n-1,0,1,0)+arr[n][0];

            y = VAC1(n-1,0,0,1)+arr[n][0];



        }



        else if(b)

        {

            x = VAC1(n-1,1,0,0)+arr[n][1];

            y = VAC1(n-1,0,0,1)+arr[n][1];

        }



        else if(c)

        {

            x = VAC1(n-1,1,0,0)+arr[n][2];

            y = VAC1(n-1,0,1,0)+arr[n][2];

        }



        dp[n][a][b][c] = max(x,y);;

        return dp[n][a][b][c];





    }

}



int main()

{

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

    int n;

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

    cin >> n;

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

    {

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

        {

            cin >> arr[i][j];

        }

    }

    ll res = VAC1(n-1,1,0,0);

    res= max(res, VAC1(n-1,0,1,0));

    res = max(res,VAC1(n-1,0,0,1));



    cout << res << endl;

}


// Faster C++ solution for the same problem (measured speedup: 18.95818077875793x):
#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 ll long long

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

int dp[100009][3];

int main() {

    ios::sync_with_stdio(false);

    int n;cin>>n;

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

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

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

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

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

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

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

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

    }

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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 9.974519163081487x):
#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<algorithm>

using namespace std;

int dp[100010][3];

int a[100010][3];

int main()

{

    int n;

    cin >> n;

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

    {

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

    }

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

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

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

    {

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

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

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

    }

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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.495455292080272x):
#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<algorithm>

#include<vector>

using namespace std;

struct day{

	int a;

	int b;

	int c;

};

int main () {

	int n;

    cin>>n;

    day dp[n];

    cin>>dp[0].a>>dp[0].b>>dp[0].c;

	int a1,b1,c1 ;

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

    	cin>>a1>>b1>>c1;

    	dp[i].a=max((dp[i-1].b),dp[i-1].c)+a1;

    	dp[i].b=max((dp[i-1].a),dp[i-1].c)+b1;

    	dp[i].c=max((dp[i-1].b),(dp[i-1].a))+c1;

	}

	int ma=0;

	cout<<max(dp[n-1].a,max(dp[n-1].b,dp[n-1].c));

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.488377155035255x):
#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;

const int mx=100010;

int arr[mx][3],n;

int dp[mx][3];

int f(int pos,int ty){

	if(pos==n)return 0;

	int &ans=dp[pos][ty];

	if(ans^-1)return ans;

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

		if(ty^i){

			ans=max(ans,f(pos+1,i)+arr[pos][i]);

		}

	}

	return ans;

}



int main(int argc, char const *argv[])

{

	memset(dp,-1,sizeof dp);

	cin>>n;

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

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

			cin>>arr[i][j];

		}

	}

	cout<<max({f(0,0),f(0,1),f(0,2)})<<endl;



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 9.924386269170986x):
#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;

}