stablegradients/pie-gem5-pairs huggingface dataset:
// 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.210386965382637x):
#include <stdio.h>

using namespace std;

#define MAX(a,b) (a>b?a:b)

#define MOD(a) (a>0?a:-(a))



int main(){

  int ndias;

  scanf("%d",&ndias);

  int ativ[ndias][3] , maxfor[ndias][3];

  for (size_t i = 0; i < ndias; i++) {

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

  }

  // for (size_t i = 0; i < ndias; i++) {

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

  //     printf("%d ",ativ[i][j]);

  //   }

  //   printf("\n");

  // }

  maxfor[0][0] = ativ[0][0];

  maxfor[0][1] = ativ[0][1];

  maxfor[0][2] = ativ[0][2];

  for (size_t i = 1; i < ndias; i++) {

    maxfor[i][0] = ativ[i][0] + MAX(maxfor[i-1][1],maxfor[i-1][2]);

    maxfor[i][1] = ativ[i][1] + MAX(maxfor[i-1][0],maxfor[i-1][2]);

    maxfor[i][2] = ativ[i][2] + MAX(maxfor[i-1][0],maxfor[i-1][1]);

  }

  // for (size_t i = 0; i < ndias; i++) {

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

  //     printf("%d ",maxfor[i][j]);

  //   }

  //   printf("\n");

  // }

  printf("%d\n", MAX( MAX(maxfor[ndias-1][0],maxfor[ndias-1][1]) , maxfor[ndias-1][2] ) );

}
// 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.30989055686854x):
#include <stdio.h>

using namespace std;

#define MAX(a,b) (a>b?a:b)

#define MOD(a) (a>0?a:-(a))



int main(){

  int ndias;

  scanf("%d",&ndias);

  int ativ[ndias][3] , maxfor[ndias][3];

  for (size_t i = 0; i < ndias; i++) {

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

  }

  // for (size_t i = 0; i < ndias; i++) {

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

  //     printf("%d ",ativ[i][j]);

  //   }

  //   printf("\n");

  // }

  maxfor[0][0] = ativ[0][0];

  maxfor[0][1] = ativ[0][1];

  maxfor[0][2] = ativ[0][2];

  for (size_t i = 1; i < ndias; i++) {

    maxfor[i][0] = ativ[i][0] + MAX(maxfor[i-1][1],maxfor[i-1][2]);

    maxfor[i][1] = ativ[i][1] + MAX(maxfor[i-1][0],maxfor[i-1][2]);

    maxfor[i][2] = ativ[i][2] + MAX(maxfor[i-1][0],maxfor[i-1][1]);

  }

  // for (size_t i = 0; i < ndias; i++) {

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

  //     printf("%d ",maxfor[i][j]);

  //   }

  //   printf("\n");

  // }

  printf("%d\n", MAX( MAX(maxfor[ndias-1][0],maxfor[ndias-1][1]) , maxfor[ndias-1][2] ) );

}
// 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: 5.051341546495469x):
#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;

}
// 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: 3.3886784001631596x):
#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;

}
// 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: 1.7866494433087365x):
#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;

}
// 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: 5.059827540315207x):
#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;

}
// 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: 3.3943712054696658x):
#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;

}
// 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: 1.789650922419662x):
#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;

}
// 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: 5.062988067095105x):
#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]));

}
// 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: 3.396491436052689x):
#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]));

}
// 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: 1.7907687944463089x):
#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]));

}
// 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: 5.109064265205935x):
#include <bits/stdc++.h> 



using namespace std;

 

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

 

#define nl '\n'

 

#define y1 aza_ibagaliev

 

#define f first

#define s second

	

#define ed end()

#define bg begin()

#define rbg rbegin()

 

#define rv reverse

#define mp make_pair

#define pb push_back

#define ppb pop_back

#define ppf pop_front

 

#define sz size()

#define all(x) x.bg, x.ed

 

#define pll pair < ll, ll >

#define pii pair < int, int >

 

#define sqr(x) ((x) * 1ll * (x))

#define sqrd(x) ((x) * 1.0 * (x))

 

#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

 

#define rnl cout << "----------------------------------------" << nl

 

#define bit __builtin_popcount

 

inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}

        	

const int ppr = 257;

const ll INF = 2e18;

const int inf = 2e9;

const int mod = 1e9 + 7;

const int N = 1e5 + 123;

const ld pi = 3.1741592653589793238462643;

 

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

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



int n, x[5][N], dp[5][N];



main() {             	

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

//  freopen(".out", "w", stdout);



//	srand(time(NULL));



	scanf("%d", &n);



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

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

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



		if(i == 1) {

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

				dp[j][i] = x[j][i];

		} else {

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

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

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

		}

	}



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



    return 0;                                        

}