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

using namespace std;



int ar[100010][5],n;

int dp[100010][5];



int call(int i,int f)

{



    if(i==n)

        return 0;



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

        return dp[i][f];



    int ans=0;



    if(f==0)

        ans+=max(ar[i][1]+call(i+1,1),ar[i][2]+call(i+1,2));



    else if(f==1)

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

    else

        ans+=max(ar[i][1]+call(i+1,1),ar[i][0]+call(i+1,0));



        dp[i][f]=ans;

        return ans;



}



int main()

{



    cin>>n;



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

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



    memset(dp,-1,sizeof dp);



    int ans=max(max(call(0,0),call(0,1)),call(0,2));



    cout<<ans<<endl;



}


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

using namespace std;



int felicidade(int n){

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

    

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

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

    }



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

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

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

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

    }



    if(a[n]>=b[n] and a[n]>=c[n]){

        return a[n];

    } else if(b[n]>=a[n] and b[n]>=c[n]){

        return b[n];

    }else if(c[n]>=a[n] and c[n]>=b[n]){

        return c[n];

    }

    

    return 0;

}



int main() {

    int n;



    cin >> n;



    cout << felicidade(n) << endl;

}
// Slower C++ solution:


#include<bits/stdc++.h>

using namespace std;



#define MAX 100000



int dp[MAX+5][4];

int val[MAX+5][4];

int n;



void initialize()

{

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

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

            dp[i][j] = -1;

}



int vacation(int i, int j)

{

    if(i<=0) return 0;



  /*  if(i==1)

    {

        return val[i][j];

    }

*/

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



    int mx = INT_MIN;



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

    {

        if(j==k) continue;



        mx = max(mx, vacation(i-1, k)+ val[i][j]);

    }





    dp[i][j] = mx;



    return mx;

}



int main()

{

    initialize();



    cin>>n;

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

    {

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

            cin>>val[i][j];

    }



    int retVal1 = vacation(n, 1);



    initialize();



    int retVal2 = vacation(n, 2);



    initialize();



    int retVal3 = vacation(n, 3);



    cout<<max({retVal1, retVal2, retVal3})<<endl;



    return 0;

}


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

using namespace std;



int felicidade(int n){

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

    

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

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

    }



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

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

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

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

    }



    if(a[n]>=b[n] and a[n]>=c[n]){

        return a[n];

    } else if(b[n]>=a[n] and b[n]>=c[n]){

        return b[n];

    }else if(c[n]>=a[n] and c[n]>=b[n]){

        return c[n];

    }

    

    return 0;

}



int main() {

    int n;



    cin >> n;



    cout << felicidade(n) << endl;

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

using namespace std;

int arr[100010][5];

int dp[100010][5];



int vac(int a, int b){

	if(a == 0) return 0;

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

	

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

		if(i != b){

			dp[a][b] = max(dp[a][b], vac(a - 1,i) + arr[a][i]);

		}

	}

	

	return dp[a][b];

}



int main (){

	memset(dp,-1,sizeof dp);

	int n;

	cin >> n;

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

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

	}

	

	

	int ans = 0;

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

		ans = max(ans , vac(n - 1, i) + arr[n][i]);

	}

	

	cout << ans << endl;

	

}

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

using namespace std;



int felicidade(int n){

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

    

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

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

    }



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

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

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

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

    }



    if(a[n]>=b[n] and a[n]>=c[n]){

        return a[n];

    } else if(b[n]>=a[n] and b[n]>=c[n]){

        return b[n];

    }else if(c[n]>=a[n] and c[n]>=b[n]){

        return c[n];

    }

    

    return 0;

}



int main() {

    int n;



    cin >> n;



    cout << felicidade(n) << endl;

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

using namespace std;



int ar[100010][5],n;

int dp[100010][5];



int call(int i,int f)

{



    if(i==n)

        return 0;



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

        return dp[i][f];



    int ans=0;



    if(f==0)

        ans+=max(ar[i][1]+call(i+1,1),ar[i][2]+call(i+1,2));



    else if(f==1)

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

    else

        ans+=max(ar[i][1]+call(i+1,1),ar[i][0]+call(i+1,0));



        dp[i][f]=ans;

        return ans;



}



int main()

{



    cin>>n;



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

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



    memset(dp,-1,sizeof dp);



    int ans=max(max(call(0,0),call(0,1)),call(0,2));



    cout<<ans<<endl;



}


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

#include <algorithm>

using namespace std;



int main(){

	int n;

	int result;

	int x = 0, y = 0, z = 0;

	

	scanf("%d", &n);

	

	int m[n+1][3];

	

	m[0][0] = m[0][1] = m[0][2] = 0;

	

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

		if(i > 0){

			scanf("%d", &x);

			scanf("%d", &y);

			scanf("%d", &z);

			

			//Caso não possa escolher a atividade a

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

			//Caso não possa escolher a atividade b

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

			//Caso não possa escolher a atividade c

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

		}

	}

	

	result = max(max(m[n][0], m[n][1]), m[n][2]);

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

}
// Slower C++ solution:


#include<bits/stdc++.h>

using namespace std;



#define MAX 100000



int dp[MAX+5][4];

int val[MAX+5][4];

int n;



void initialize()

{

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

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

            dp[i][j] = -1;

}



int vacation(int i, int j)

{

    if(i<=0) return 0;



  /*  if(i==1)

    {

        return val[i][j];

    }

*/

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



    int mx = INT_MIN;



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

    {

        if(j==k) continue;



        mx = max(mx, vacation(i-1, k)+ val[i][j]);

    }





    dp[i][j] = mx;



    return mx;

}



int main()

{

    initialize();



    cin>>n;

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

    {

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

            cin>>val[i][j];

    }



    int retVal1 = vacation(n, 1);



    initialize();



    int retVal2 = vacation(n, 2);



    initialize();



    int retVal3 = vacation(n, 3);



    cout<<max({retVal1, retVal2, retVal3})<<endl;



    return 0;

}


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

#include <algorithm>

using namespace std;



int main(){

	int n;

	int result;

	int x = 0, y = 0, z = 0;

	

	scanf("%d", &n);

	

	int m[n+1][3];

	

	m[0][0] = m[0][1] = m[0][2] = 0;

	

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

		if(i > 0){

			scanf("%d", &x);

			scanf("%d", &y);

			scanf("%d", &z);

			

			//Caso não possa escolher a atividade a

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

			//Caso não possa escolher a atividade b

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

			//Caso não possa escolher a atividade c

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

		}

	}

	

	result = max(max(m[n][0], m[n][1]), m[n][2]);

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

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

using namespace std;

int arr[100010][5];

int dp[100010][5];



int vac(int a, int b){

	if(a == 0) return 0;

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

	

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

		if(i != b){

			dp[a][b] = max(dp[a][b], vac(a - 1,i) + arr[a][i]);

		}

	}

	

	return dp[a][b];

}



int main (){

	memset(dp,-1,sizeof dp);

	int n;

	cin >> n;

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

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

	}

	

	

	int ans = 0;

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

		ans = max(ans , vac(n - 1, i) + arr[n][i]);

	}

	

	cout << ans << endl;

	

}

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

#include <algorithm>

using namespace std;



int main(){

	int n;

	int result;

	int x = 0, y = 0, z = 0;

	

	scanf("%d", &n);

	

	int m[n+1][3];

	

	m[0][0] = m[0][1] = m[0][2] = 0;

	

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

		if(i > 0){

			scanf("%d", &x);

			scanf("%d", &y);

			scanf("%d", &z);

			

			//Caso não possa escolher a atividade a

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

			//Caso não possa escolher a atividade b

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

			//Caso não possa escolher a atividade c

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

		}

	}

	

	result = max(max(m[n][0], m[n][1]), m[n][2]);

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

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

using namespace std;



int ar[100010][5],n;

int dp[100010][5];



int call(int i,int f)

{



    if(i==n)

        return 0;



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

        return dp[i][f];



    int ans=0;



    if(f==0)

        ans+=max(ar[i][1]+call(i+1,1),ar[i][2]+call(i+1,2));



    else if(f==1)

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

    else

        ans+=max(ar[i][1]+call(i+1,1),ar[i][0]+call(i+1,0));



        dp[i][f]=ans;

        return ans;



}



int main()

{



    cin>>n;



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

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



    memset(dp,-1,sizeof dp);



    int ans=max(max(call(0,0),call(0,1)),call(0,2));



    cout<<ans<<endl;



}


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

#define ll long long

#define ull unsigned ll

#define ld long double

#define pll pair<ll, ll>

#define pii pair<int, int>

#define f first

#define se second

#define pb push_back

#define ft fflush(stdout)

 

 

using namespace std;

 

 

const int N = 2e5 + 123;

const int PLS = 3e5 + 123;

const int mod = 1e9 + 7;

const ll inf = 1e16;





ll n, a[N], c[N], b[N], dp[N][3];





int main() {

    ios_base::sync_with_stdio(NULL);

    cin.tie(NULL); cout.tie(NULL);

    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 = 2; i <= n; i++) {

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

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

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

    }

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

}
// Slower C++ solution:


#include<bits/stdc++.h>

using namespace std;



#define MAX 100000



int dp[MAX+5][4];

int val[MAX+5][4];

int n;



void initialize()

{

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

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

            dp[i][j] = -1;

}



int vacation(int i, int j)

{

    if(i<=0) return 0;



  /*  if(i==1)

    {

        return val[i][j];

    }

*/

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



    int mx = INT_MIN;



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

    {

        if(j==k) continue;



        mx = max(mx, vacation(i-1, k)+ val[i][j]);

    }





    dp[i][j] = mx;



    return mx;

}



int main()

{

    initialize();



    cin>>n;

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

    {

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

            cin>>val[i][j];

    }



    int retVal1 = vacation(n, 1);



    initialize();



    int retVal2 = vacation(n, 2);



    initialize();



    int retVal3 = vacation(n, 3);



    cout<<max({retVal1, retVal2, retVal3})<<endl;



    return 0;

}


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

#define ll long long

#define ull unsigned ll

#define ld long double

#define pll pair<ll, ll>

#define pii pair<int, int>

#define f first

#define se second

#define pb push_back

#define ft fflush(stdout)

 

 

using namespace std;

 

 

const int N = 2e5 + 123;

const int PLS = 3e5 + 123;

const int mod = 1e9 + 7;

const ll inf = 1e16;





ll n, a[N], c[N], b[N], dp[N][3];





int main() {

    ios_base::sync_with_stdio(NULL);

    cin.tie(NULL); cout.tie(NULL);

    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 = 2; i <= n; i++) {

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

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

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

    }

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

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

using namespace std;

int arr[100010][5];

int dp[100010][5];



int vac(int a, int b){

	if(a == 0) return 0;

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

	

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

		if(i != b){

			dp[a][b] = max(dp[a][b], vac(a - 1,i) + arr[a][i]);

		}

	}

	

	return dp[a][b];

}



int main (){

	memset(dp,-1,sizeof dp);

	int n;

	cin >> n;

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

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

	}

	

	

	int ans = 0;

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

		ans = max(ans , vac(n - 1, i) + arr[n][i]);

	}

	

	cout << ans << endl;

	

}

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

#define ll long long

#define ull unsigned ll

#define ld long double

#define pll pair<ll, ll>

#define pii pair<int, int>

#define f first

#define se second

#define pb push_back

#define ft fflush(stdout)

 

 

using namespace std;

 

 

const int N = 2e5 + 123;

const int PLS = 3e5 + 123;

const int mod = 1e9 + 7;

const ll inf = 1e16;





ll n, a[N], c[N], b[N], dp[N][3];





int main() {

    ios_base::sync_with_stdio(NULL);

    cin.tie(NULL); cout.tie(NULL);

    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 = 2; i <= n; i++) {

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

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

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

    }

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

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

#include<algorithm>



using namespace std;



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

int f[110000][3];

int main()

{

    int n;



    cin>>n;



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

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

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

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

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

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

    {

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

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

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

    }

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

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

    cout<<ans;

}   

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

int n;

int hap[100002][3]={};

int max(int a,int b)

{

	return a>b? a:b;

}

int main()

{

	scanf("%d",&n);

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

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

		{

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

			hap[i][j]+=max(hap[i-1][(j+1)%3],hap[i-1][(j+2)%3]);

		}

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

	return 0;

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



using namespace std;





int main()

{

	int n;

	cin >> n;



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



	for(auto &cur : h)

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



	dp[0] = h[0];



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

	{

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

		{

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

			{

				if(k == j)

					continue;



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

			}

		}

	}



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

}

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

int n;

int hap[100002][3]={};

int max(int a,int b)

{

	return a>b? a:b;

}

int main()

{

	scanf("%d",&n);

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

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

		{

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

			hap[i][j]+=max(hap[i-1][(j+1)%3],hap[i-1][(j+2)%3]);

		}

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

	return 0;

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

using namespace std;

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

int main()

{

    int i,j,n;

    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)

            {

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

            }

            else if(j==0)

            {

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

            }

            else if(j==1)

            {

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

            }

            else if(j==2)

            {

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

            }

        }

    }

    n--;

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

    return 0;

}




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

int n;

int hap[100002][3]={};

int max(int a,int b)

{

	return a>b? a:b;

}

int main()

{

	scanf("%d",&n);

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

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

		{

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

			hap[i][j]+=max(hap[i-1][(j+1)%3],hap[i-1][(j+2)%3]);

		}

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

	return 0;

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

#define ll long long

#define ull unsigned long long

using namespace std;

ll n,a[100009],b[100009],c[100009],dp[100009][5];

int main (){

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n;

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

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

	}

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

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

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

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

	}

	ll jwb=0;

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

		jwb=max(jwb,dp[1][i]);

	}

	cout << jwb << endl;

}

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

int n;

int hap[100002][3]={};

int max(int a,int b)

{

	return a>b? a:b;

}

int main()

{

	scanf("%d",&n);

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

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

		{

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

			hap[i][j]+=max(hap[i-1][(j+1)%3],hap[i-1][(j+2)%3]);

		}

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

	return 0;

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

using namespace std;



int ar[100010][5],n;

int dp[100010][5];



int call(int i,int f)

{



    if(i==n)

        return 0;



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

        return dp[i][f];



    int ans=0;



    if(f==0)

        ans+=max(ar[i][1]+call(i+1,1),ar[i][2]+call(i+1,2));



    else if(f==1)

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

    else

        ans+=max(ar[i][1]+call(i+1,1),ar[i][0]+call(i+1,0));



        dp[i][f]=ans;

        return ans;



}



int main()

{



    cin>>n;



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

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



    memset(dp,-1,sizeof dp);



    int ans=max(max(call(0,0),call(0,1)),call(0,2));



    cout<<ans<<endl;



}


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

int n;

int hap[100002][3]={};

int max(int a,int b)

{

	return a>b? a:b;

}

int main()

{

	scanf("%d",&n);

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

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

		{

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

			hap[i][j]+=max(hap[i-1][(j+1)%3],hap[i-1][(j+2)%3]);

		}

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

	return 0;

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

using namespace std;



int h[3][100005], a[100005], b[100005], c[100005];



int main(){



    int n; cin >> n;

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

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

    }



    h[0][1] = a[1];

    h[1][1] = b[1];

    h[2][1] = c[1];



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

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

        h[1][i] = max({h[1][i - 2] + b[i], h[0][i-1] + b[i], h[2][i-1] + b[i]});

        h[2][i] = max({h[2][i - 2] + c[i], h[0][i-1] + c[i], h[1][i-1] + c[i]});

    }



    cout << max({h[0][n], h[1][n], h[2][n]}) << endl;

    return 0;

}




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

int n;

int hap[100002][3]={};

int max(int a,int b)

{

	return a>b? a:b;

}

int main()

{

	scanf("%d",&n);

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

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

		{

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

			hap[i][j]+=max(hap[i-1][(j+1)%3],hap[i-1][(j+2)%3]);

		}

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

	return 0;

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

#include <string>

#include <cstdlib>

using namespace std;



#define READ                freopen("in.txt", "r", stdin)

#define WRITE               freopen("out.txt", "w", stdout)



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

#define sii(a,b)            scanf("%d %d", &a, &b)

#define siii(a,b,c)         scanf("%d %d %d", &a, &b, &c)



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

#define SET(a)              memset(a, -1, sizeof(a))



#define PI                  acos(-1.0)



#define pb                  push_back

#define mp                  make_pair

#define SORT(v)             sort(v.begin(), v.end())

#define REV(v)              reverse(v.begin(), v.end())

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

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

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

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

#define LOOP(i, x, y)       for(int i=x; i<=y; i++)

#define fastIO()            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);





typedef long long              LL;

typedef unsigned long long     ULL;

typedef vector<int>            VI;

typedef pair<int, int>         PII;

typedef pair<string, int>      PSI;

typedef pair<char, int>        PCI;



const int MAX = 100005;

const LL LMAX = 12158598925;

const double eps = 1e-9;

const int INF = 0x3f3f3f3f;



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

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

int kx[] = {1, 1, 2, 2, -1, -1, -2, -2};

int ky[] = {2, -2, 1, -1, 2, -2, 1, -1};



int n, w;

int arr[MAX][3];

LL dp[MAX][3];







int main()

{

//    READ;

//    WRITE;

    si(n);



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

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

            si(arr[i][j]);

    }



    for(int j=0; j<3; j++) dp[1][j] = arr[1][j];



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

//        cout << "FOR: " << i << ":\n";

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

            LL mx = INT_MIN;

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

                if(q == j) continue;



                mx = max(mx, dp[i-1][q]);

            }



            dp[i][j] = arr[i][j] + mx;

//              cout << " max: " << mx << " arr: " << arr[i][j] << " dp: " << dp[i][j] << endl;

        }

//        cout << endl;

    }



//    cout << endl;

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

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

//            cout << dp[i][j] << " ";

//        }

//        cout << endl;

//    }



    LL ans = INT_MIN;

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



    cout << ans << endl;

    return 0;

}


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

int n;

int hap[100002][3]={};

int max(int a,int b)

{

	return a>b? a:b;

}

int main()

{

	scanf("%d",&n);

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

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

		{

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

			hap[i][j]+=max(hap[i-1][(j+1)%3],hap[i-1][(j+2)%3]);

		}

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

	return 0;

}