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

#define x first

#define y second

#define pii pair<int,int>

#define ll long long

#define pll pair<ll,ll>

#define mp make_pair

#define pb push_back

#define pf push_front

#define popb pop_back

#define popf pop_front

#define xmod 100000007

using namespace std;



int n,m,dp[100005][5],a[100005][5],ans;

int main (){

	ios::sync_with_stdio(false);

	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++){

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

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

				if (j != k)

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

			}

			dp[i][j]+=a[i][j];

		}

	}

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

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

	}

	cout << ans << "\n";

    return 0;

}

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

#include <algorithm>

using std::max;



int main(void)

{

    int dp[2][3],a[3],i,N;

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

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

using namespace std;

const int maxv=1000010;

typedef long long ll;

ll n;

ll a[maxv];

ll b[maxv];

ll c[maxv];

ll ans[maxv][3];



int main()

{



    cin>>n;





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

    {

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

    }



    ans[0][0]=a[0];

    ans[0][1]=b[0];

    ans[0][2]=c[0];

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

    {

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

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

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





    }

    ll result=max(ans[n-1][2],max(ans[n-1][0],ans[n-1][1]));

    cout<<result;



    return 0;



}


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

#include <algorithm>

using std::max;



int main(void)

{

    int dp[2][3],a[3],i,N;

    i=0; 

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

 

    scanf("%d",&N);

    while(N--)

    {

        scanf("%d%d%d",a,a+1,a+2);

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

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

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

        i=1-i;

    }

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

    return 0;

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

using namespace std;

const int MAX_n=1e5+10;

int n;

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

int dp[MAX_n][3];

int main()

{

    cin>>n;

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

    dp[1][0]=max(b[1],c[1]);

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

    dp[1][2]=max(a[1],b[1]);

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

    {

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

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

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

    }

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

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

    cout<<ans;

    return 0;

}

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

#include <vector>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <set>

#include <tuple>

#include <functional>

#include <map>

#include <unordered_map>

#include <queue>

#include <tuple>



using namespace std;



#define endl '\n'



using ull = unsigned long int;

using ll = long long;



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(nullptr);

  const int precision = 13;

  cout.precision(precision);

  cout.setf(ios_base::fixed);



  int n; cin >> n;

  vector<vector<int>> dp(2, vector<int>(3, 0));



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

    int a, b, c; cin >> a >> b >> c;

    int cur = i%2;

    int prev = (i-1)%2;

    dp[cur][0] = a + max(dp[prev][1], dp[prev][2]);

    dp[cur][1] = b + max(dp[prev][0], dp[prev][2]);

    dp[cur][2] = c + max(dp[prev][0], dp[prev][1]);

  }



  cout << *max_element(dp[n%2].begin(), dp[n%2].end()) << endl;





  return 0;

}


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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

using namespace std;



long long w1,w2,hap=0,maxi,aa,bb,cc,N,i,j,k,a[100005][5];

long long M[100005][5];





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin>>N;

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

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

            M[i][j]=0;



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

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

    M[N-1][0]=a[N-1][0];

    M[N-1][1]=a[N-1][1];

    M[N-1][2]=a[N-1][2];



    for(i=N-2; i>=0; i--)

    {

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

        {

            if(j==0)

            {

                w1=1;

                w2=2;

            }

            else if(j==1)

            {

                w1=0;

                w2=2;

            }

            else

            {

                w1=0;

                w2=1;

            }

        M[i][j]=a[i][j]+max(M[i+1][w1],M[i+1][w2]);

        }

    }

    aa=max(M[0][0],M[0][1]);

    aa=max(aa,M[0][2]);

    cout<<aa<<endl;

    return 0;

}






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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

using namespace std;

#define INF 100005

#define maxx 1000000000000



int n;

long long a[INF][3];

long long mem[INF][3];



long long rec(int level,int pre)

{

    if(level==n) return 0;

    if(mem[level][pre]!=-1) return mem[level][pre];

    long long now=0;

    if(pre==0)

    {

        now=max(now,max(a[level][0]+rec(level+1,1),a[level][0]+rec(level+1,2)));

    }else

    if(pre==1)

    {

        now=max(now,max(a[level][1]+rec(level+1,0),a[level][1]+rec(level+1,2)));

    }else

    if(pre==2)

    {

        now=max(now,max(a[level][2]+rec(level+1,0),a[level][2]+rec(level+1,1)));

    }

    return mem[level][pre]=now;

}



int main()

{

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

    scanf("%d",&n);

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

    {

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

    }

    long long ans=max(rec(0,0),max(rec(0,1),rec(0,2)));

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

}


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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

using namespace std;



int main(){

    int n, i, j, k;

    scanf("%d",&n);

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

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

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

    }

    int dp[n+5][3];

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

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

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

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

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

    }

    int ans  = 0;

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

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

    printf("%d", ans);



    return 0;

}


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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

using namespace std;



int main()

{

    int i,n;

    cin>>n;

    int a[n+2], b[n+2], c[n+2], x=0, y=0, z=0, p, q, r;

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

    {

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

        if(i)

        {

            p=x,q=y,r=z;

            x=a[i]+max(q,r);

            y=b[i]+max(p,r);

            z=c[i]+max(q,p);

        }

        else

        {

            x=a[i], y=b[i], z=c[i];

        }

    }

    cout<<max(x, max(y, z))<<endl;

    return 0;

}


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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

using namespace std;

#define ll long long

#define MX 100005



const ll INF = 1e12;



int A[MX][4];

ll dp[MX][4];



ll recur(int i, int j){

    if (i == 1) return dp[i][j] = A[i][j];

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



    ll mx = 0;

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

        if (x != j) mx = max(mx, recur(i-1, x));

    }

    return dp[i][j] = (mx + A[i][j]);

}



int main()

{

    int n; scanf("%d", &n);

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

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

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

            dp[i][j] = -1;

        }

    }



    ll ans = 0;

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

        ans = max(ans, recur(n, j));

    }



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



    return 0;

}


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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

using namespace std;



#define pb push_back

#define mp make_pair

#define fi first

#define se second

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

#define rall(x) (x).rbegin(), (x).rend()

#define MAX 1000000

//3

typedef long long ll;

typedef pair<int,int> pii;

priority_queue< int > pq;

priority_queue< int , vector<int> , greater<int> > rpq;

set<int>s;

set <int > :: iterator itr; 

vector<int> vec[1001];

int r,n,m,inp,tc;

int arr[1000007]= {};

map<int , int> mymap;





int main()

{

	int n;

	int arr[3];

	int dp[3];

	cin>>n;

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

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

		if(i == 0 ) {

			dp[0] = arr[0];

			dp[1] = arr[1];

			dp[2] = arr[2];

		}

		else{

			int a = dp[0];

			int b = dp[1];

			int c = dp[2];

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

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

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

		}

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

	}

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

    return 0;

}



//65 900 17 13

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

#define ll long long

using namespace std;



ll arr[100007][3];

ll dp[100007][3];

bool vis[100007][3];

int n;



ll rec( int i, int prev  )

{

    if(i>=n)

        return 0;

    if(vis[i][prev])

        return dp[i][prev];



    ll ans= 0;

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

    {

        if(prev==j)

            continue;

        ans= max( ans, arr[i][j]+rec(i+1,j) );

    }



    vis[i][prev]= 1;



    return dp[i][prev]= ans;

}



int main()

{

    cin>>n;



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

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

            cin>>arr[i][j];



    cout<< rec( 0, -1 ) <<endl;

}


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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

#include <algorithm>



using namespace std;



int main() {

	int n;

	cin >> n;

	int activities[n][3];

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

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

			cin >> activities[i][j];

		}

	}



	int escolhaA = 0, escolhaB = 0, escolhaC = 0;

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

		int auxA = escolhaA, auxB = escolhaB, auxC = escolhaC;

		escolhaA = max(auxB,auxC) + activities[i][0];

		escolhaB = max(auxA,auxC) + activities[i][1];

		escolhaC = max(auxA,auxB) + activities[i][2];

	}



	cout << max(escolhaA,max(escolhaB,escolhaC)) << endl;

}

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

#include<algorithm>

#include<cstring>

using namespace std;

const int maxn = 1e5 + 5;



int a[maxn][4];

int dp[maxn][4];//d[i][j] i day choose j thing 's max happy



int main(){

	int n;scanf("%d",&n);

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

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

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

		}

	}



	memset(dp, 0, sizeof dp);



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



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

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

	}



	int ans = 0;

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

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

}

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

#include <algorithm>



using namespace std;



int main(void) {

    int n;



    cin >> n;



    int tasks[n][3];

    int points[n][3];



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

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

    }



    points[0][0] = tasks[0][0];

    points[0][1] = tasks[0][1];

    points[0][2] = tasks[0][2];



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

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

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

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

    }



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



    return 0;

}


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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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



using namespace std;

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

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



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

int dp[N][3];

int main() {

	int n;

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

	return 0;

}

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

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

 

#define mp make_pair

#define pb push_back

#define f first

#define s second

#define ll long long

#define int ll

#define forn(i, a, b) for(int i = (a); i <= (b); ++i)

#define forev(i, b, a) for(int i = (b); i >= (a); --i)

#define VAR(v, i) __typeof( i) v=(i)

#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)

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

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

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

 

using namespace std;

 

const int maxn = (int)1e5 + 100;

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

 

#define inf mod

 

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;   

typedef vector<ll> Vll;               

typedef vector<pair<int, int> > vpii;

typedef vector<pair<ll, ll> > vpll;

 

int n, dp[maxn][4], k;

int a[maxn][4];

main () {

	cin >> n;

	forn(i, 1, n)

		forn(j, 0, 2){

			cin >> a[i][j];

			if(i == 1) dp[i][j] = a[i][j];

		}

	forn(i, 2, n){

		forn(t1, 0, 2)

			forn(t2, 0, 2)

				if(t1 != t2)

					dp[i][t1] = max(dp[i][t1], dp[i - 1][t2] + a[i][t1]);

	}

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

}

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



int max(int a, int b)

{

    return a > b ? a : b;

}



int main()

{

    int n;

    scanf("%d", &n);

    int a[n][3];

    int dp[n][3];

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

    {

        scanf("%d %d %d", &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] = 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][0], dp[i - 1][1]);

    }

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

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

}