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

#include <iostream>

using namespace std;



int t;

int arr[100000+100][4] ;

long long dp[100000+100][4];



long long solve(int r ,int col=4)

{

    if(r>=t)

        return 0;

    long long &ret=dp[r][col] ;

    if(ret)

        return ret;

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

    {

        if(i==col) continue;

        ret=max(ret,arr[r][i]+solve(r+1,i));

    }

     

    return  ret;

}

int main()

{

     //freopen("input.txt", "rt", stdin);

    // freopen("output.txt", "wt", stdout);

    

    cin>>t;

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

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

    printf("%lld\n",solve(0));

    return 0;

}

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

#include <algorithm>

#include <vector>

using namespace std;

 

int n,dp[100005][5],a[100005][5],k; 

int main(){

	scanf("%d",&n);

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

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

	}

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

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

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

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

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

	}

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

	return 0;

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



using namespace std;



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

int memo[100007][4];

int n; 



int solve(int p, int last) {

    if(p == n) return 0;

    int & st = memo[p][last];

    if(st == -1) {

        st = max({

            last != 1? solve(p+1, 1) + a[p] : 0,

            last != 2? solve(p+1, 2) + b[p] : 0,

            last != 3? solve(p+1, 3) + c[p] : 0

        });

    }

    return st;

}

int main() {

    memset(memo, -1, sizeof memo);

    cin >> n;

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

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

    }



    cout << solve(0, 0);

}

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

#include <algorithm>

#include <vector>

using namespace std;

 

int n,dp[100005][5],a[100005][5],k; 

int main(){

	scanf("%d",&n);

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

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

	}

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

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

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

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

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

	}

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

	return 0;

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

using namespace std;

const int maxn=100010;

int dp[maxn][3]={0};

int A[maxn][3];

int main(){

	int n;

	scanf("%d",&n); 

	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]=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];

		

	}

	int temp=dp[n-1][0];

	if(temp<dp[n-1][1])	temp=dp[n-1][1];

	if(temp<dp[n-1][2])	temp=dp[n-1][2];

	printf("%d",temp);

	return 0;

}

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

#include <algorithm>

#include <vector>

using namespace std;

 

int n,dp[100005][5],a[100005][5],k; 

int main(){

	scanf("%d",&n);

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

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

	}

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

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

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

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

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

	}

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

	return 0;

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

#define inf 1200000

using namespace std;

int main()

{

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

    int n;

    int dp[110001][3];

    cin>>n;

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

    {

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



    }





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

    {

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

        {

            if(i==0)

            {

                if(j==0)

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

                else if(j==1)

                    dp[i][j]=b[i];

                else

                    dp[i][j]=c[i];

            }

            else

            {

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

                {

                    if(j==k)

                        continue;

                     if(j==0)

                    {

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



                    }



                    else if(j==1)

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

                    else

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



                }

            }

        }

    }



   int r=0;

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



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



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



   cout<<r;



}


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

#include <algorithm>

#include <vector>

using namespace std;

 

int n,dp[100005][5],a[100005][5],k; 

int main(){

	scanf("%d",&n);

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

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

	}

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

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

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

#define rep(i,a,n) for (int i=a;i<n;i++)

#define per(i,a,n) for (int i=n-1;i>=a;i--)

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

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

#define clr(v, d) memset(v, d, sizeof(v))

#define fi first

#define se second

#define pp push_back

#define pb pop_back

#define pi 3.141592654

#define MOD 1000000007 

#define cons1 1e12

#define cons2 1e6

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int, int> pa;

typedef unsigned long long int ull;

typedef double long dl;

const int N = 1e5+9,oo=1e9;

int n,k;

int v[N][3], ans[N][4];

int sol(int i,int l) {

	if (i == n)

		return 0;

	int mx = INT_MIN;

	if (!ans[i][l]) {

		if (l != 0)

			mx = max(mx, v[i][0] + sol(i + 1, 0));

		if (l != 1)

			mx = max(mx, v[i][1] + sol(i + 1, 1));

		if (l != 2)

			mx = max(mx, v[i][2] + sol(i + 1, 2));

		ans[i][l] = mx;

	}



	return ans[i][l];

	

}

void solve() {

	cin >> n;

	rep(i, 0, n)

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

	cout << sol(0,3) << endl;

	

}

int main() {

	ios::sync_with_stdio(0);

	cin.tie(NULL);

	cout.tie(NULL);

	int t = 1;

	//cin >> t;

	while (t--)

		solve();



#ifndef ONLINE_JUDGE

	- system("pause");

#endif



}

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

#include <algorithm>

#include <vector>

using namespace std;

 

int n,dp[100005][5],a[100005][5],k; 

int main(){

	scanf("%d",&n);

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

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

	}

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

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

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

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

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

	}

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

	return 0;

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



using namespace std;



int n;

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

bool found[100001][3];

long long int dp[100001][3];



long long int m(long long int a, long long int b){

    return ((a > b) ? a : b);

}



long long int f(int now, int k){

    if (now == n){

        if (k == 0){

            return max(b[now], c[now]);

        } else if (k == 1){

            return max(a[now], c[now]);

        } else if (k == 2) {

            return max(b[now], c[now]);

        } else {

            return max(a[now], max(b[now], c[now]));

        }

    } else {

        if (found[now][k]){

            return dp[now][k];

        } else {

            if (k == 0){

                dp[now][k] = m(b[now] + f(now+1, 1), c[now] + f(now+1, 2));

            } else if (k == 1){

                dp[now][k] = m(a[now] + f(now+1, 0), c[now] + f(now+1, 2));

            } else if (k == 2){

                dp[now][k] = m(b[now] + f(now+1, 1), a[now] + f(now+1, 0));

            } else {

                dp[now][k] = m(a[now] + f(now+1, 0), m(b[now] + f(now+1, 1), c[now] + f(now+1, 2)));

            }

            found[now][k] = true;

            return dp[now][k];

        }

    }

}



int main(){

    cin >> n;

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

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

    }

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

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

    dp[1][2] = c[1];

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

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

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

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

    }

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

}


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

#include <algorithm>

#include <vector>

using namespace std;

 

int n,dp[100005][5],a[100005][5],k; 

int main(){

	scanf("%d",&n);

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

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

	}

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

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

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

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

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

	}

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

	return 0;

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

#include<iostream>

#include<algorithm>

#include<iomanip>

#include<string>

#include<cmath>

#include<vector>

#include<set>

#include<queue>

#include<stack>

#include<fstream>

#include<map>

#include<bitset>

#include<unordered_map>

#include<cstring>

#include<cctype>

using namespace std;

#define  ll long long

#define  ull unsigned long long

#define  ul unsigned long

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

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

#define pb(s) push_back(s);

#define format(n) fixed<<setprecision(n)

#define finl "\n"

#define Mohammed_Atef_Hassan fast();

#define mod 1000000007

#define INF LLONG_MAX

#define PI acos(-1)

#define clr(dp,n) memset(dp,n,sizeof dp)

#define ex(n) return cout<<n<<finl,0;

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

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

ll fix_mod(ll x, ll y)

{

	return (y + x % y) % y;

}

void fast() {

	std::ios_base::sync_with_stdio(false);

	cin.tie(nullptr); cout.tie(nullptr);





}

int n;

vector<vector<ll>>v;

ll mem[(int)1e5 + 10][5];

ll solve(int i, int c)

{

	if (i == n)return 0;

	ll& ret = mem[i][c];

	if (~ret)return ret;

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

	{

		if (k == c)continue;

		ret = max(ret, solve(i+1, k) + v[i][k]);

	}

	return ret;

}

int main()

{

	Mohammed_Atef_Hassan

		cin >> n;

	v = vector<vector<ll>>(n + 1, vector<ll>(3));

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

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

	clr(mem, -1);

	ex(solve(0, 4));

}

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

#include <algorithm>

#include <vector>

using namespace std;

 

int n,dp[100005][5],a[100005][5],k; 

int main(){

	scanf("%d",&n);

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

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

	}

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

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

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

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

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

	}

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

	return 0;

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

#include<string>

#include<cmath>

#include<algorithm>

#include<vector>

#include<map>

#include<stack>

#include<queue>

using namespace std;

#define MAXN 100001

int dp[MAXN*3];

int main(){

	int N;

	cin>>N;

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

		cin>>dp[i];

	}

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

	for(int i=3;i<N*3;i++){

		if(i%3==0){

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

		}else if(i%3==1){

			dp[i]=dp[i]+max(dp[i-4],dp[i-2]);

		}else{

			dp[i]=dp[i]+max(dp[i-4],dp[i-5]);

		}

	}

	int x;

	if(dp[3*N-1]>=dp[3*N-2]){

		x=dp[3*N-1];

	}else{

		x=dp[3*N-2];

	}

   cout<<(x>dp[3*N-3]?x:dp[3*N-3]);

   return 0;

} 

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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 MAX 100005

#define pb push_back

#define mp make_pair

#define pii pair<long long,long long>

#define read(a) scanf("%d",&a)

#define p1(a) cout<<"Check "<<a<<endl;

#define p2(a,b) cout<<"Check "<<a<<' '<<b<<endl;

#define p3(a,b,c) cout<<"Check "<<a<<' '<<b<<' '<<c<<endl;

#define fo(i,n) for(i=0;i<n;i++)

#define ll long long

#define clr(a) memset(a,0,sizeof(a))

#define MOD 10000000000

#define INF 10000000000000;



using namespace std;



int main()

{

    int n,m;

    cin>>n;

    int ar[n+5][4];

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

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

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

        }

    }

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

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

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

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

    }

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



    return 0;

}




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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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 sz 100105

using namespace std;

ll dp[sz][10];

void solve(ll n , ll i){

   if(i<n){

        ll mx;

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

            mx = 0;

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

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

            dp[i][j] += mx;

        }

        solve(n,i+1);

   }

}



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll i , j , n , k , res = 0;

    cin>>n;

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

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

            cin>>dp[i][j];

    }

    solve(n,1);

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

        res = max(res,dp[n-1][j]);

    cout<<res<<endl;

    return 0;

}






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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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;

struct actv{

ll f,s,t;

};

int main(){

    ll n;

    cin>>n;

    vector < actv > v,dp;

    v.resize(n);

    dp.resize(n);

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

        cin>>v[i].f>>v[i].s>>v[i].t;

        dp[i].f=dp[i].s=dp[i].t=0;

    }

    dp[0].f=v[0].f;

    dp[0].t=v[0].t;

    dp[0].s=v[0].s;

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

        dp[i].f=v[i].f+max(dp[i-1].s,dp[i-1].t);

        dp[i].s=v[i].s+max(dp[i-1].f,dp[i-1].t);

        dp[i].t=v[i].t+max(dp[i-1].s,dp[i-1].f);

    }

    cout<<max(max(dp[n-1].f,dp[n-1].s),dp[n-1].t);

return 0;

}


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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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;

typedef long long ll;



ll arr[100005][3];

ll dp[100005][3];





int main(){

    ll n;

    cin>>n;

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

        cin>>arr[i][0];

        cin>>arr[i][1];

        cin>>arr[i][2];

    }

    dp[0][0]=arr[0][0];

    dp[0][1]=arr[0][1];

    dp[0][2]=arr[0][2];

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

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

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

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

    }

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

}


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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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 ll long long

#define PI acos(-1.0)



int main()

{

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

	

	scanf("%lld", &t);

	for(int i = 1; i <= t; i++) scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);

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

	{

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

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

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

	}

	printf("%lld\n",max(a[t],max(b[t],c[t])));

	return 0;

}


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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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 mat[100002][3], dp[100002][3];





int main() {

  int n;

  cin >> n;

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

    for (int j = 0; j < 3; ++j) cin >> mat[i][j];



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



  vector<vector<int>> now {{1, 2}, {0, 2}, {0, 1}};



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

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

      for (auto el: now[col]) {

        dp[pos][col] = max(dp[pos][col], mat[pos][col] + dp[pos - 1][el]);

      }

    }

  }



  int res = 0;

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

  cout << res << endl;  

  return 0;

}

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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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;

#define mx 100009

ll ar[mx][4];

ll br[mx][4];

ll n;



ll dp(){

    br[n][1]=ar[n][1];

    br[n][2]=ar[n][2];

    br[n][3]=ar[n][3];

    for(ll i=n-1;i>=1;i--){

        br[i][1]=ar[i][1]+max(br[i+1][2],br[i+1][3]);

        br[i][2]=ar[i][2]+max(br[i+1][1],br[i+1][3]);

        br[i][3]=ar[i][3]+max(br[i+1][1],br[i+1][2]);

    }

    return max(br[1][1],max(br[1][2],br[1][3]));

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

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

    //freopen("output.txt", "w", stdout);



    //ll n;

    cin>>n;

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

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

            cin>>ar[i][j];

        }

    }

    cout<<dp()<<endl;

    return 0;

}


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

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

    for(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(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;

}