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

#include <algorithm>



const int maxn = 1e5+7;



int n;

int a[maxn][3];

int dp[maxn][3];



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

	std::cin >> n;

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

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

			std::cin >> a[i][j];

		}

	}

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

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

	}

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

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

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

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

	}

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

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

using namespace std;

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

#define ll long long

#define fastIO cout << fixed << setprecision(9), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

double const EPS = 1e-9, PI = acos(-1);

const int N = 1e5 + 9, M = 5e2 + 9, OO = 1e9 + 7, MOD = 1e9 + 9;

const ll inf = 1e18;



ll dp[N][3], happ[N][3];



int main() {

  fastIO;

#ifdef LOCAL

  freopen("input.in", "rt", stdin);

#endif



  int n;

  cin >> n;

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

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

      cin >> happ[i][j];



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

    dp[0][i] = happ[0][i];



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

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

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

        if(k == prv) continue;

        dp[i][k] = max(dp[i][k], dp[i-1][prv] + happ[i][k]);

      }

    }

  }



  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][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.3473394935117358x):
#include<bits/stdc++.h>

using namespace std;

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

#define ll long long

#define fastIO cout << fixed << setprecision(9), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

double const EPS = 1e-9, PI = acos(-1);

const int N = 1e5 + 9, M = 5e2 + 9, OO = 1e9 + 7, MOD = 1e9 + 9;

const ll inf = 1e18;



ll dp[N][3], happ[N][3];



int main() {

  fastIO;

#ifdef LOCAL

  freopen("input.in", "rt", stdin);

#endif



  int n;

  cin >> n;

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

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

      cin >> happ[i][j];



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

    dp[0][i] = happ[0][i];



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

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

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

        if(k == prv) continue;

        dp[i][k] = max(dp[i][k], dp[i-1][prv] + happ[i][k]);

      }

    }

  }



  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][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.7648538859161549x):
#include<bits/stdc++.h>

using namespace std;

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

#define ll long long

#define fastIO cout << fixed << setprecision(9), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

double const EPS = 1e-9, PI = acos(-1);

const int N = 1e5 + 9, M = 5e2 + 9, OO = 1e9 + 7, MOD = 1e9 + 9;

const ll inf = 1e18;



ll dp[N][3], happ[N][3];



int main() {

  fastIO;

#ifdef LOCAL

  freopen("input.in", "rt", stdin);

#endif



  int n;

  cin >> n;

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

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

      cin >> happ[i][j];



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

    dp[0][i] = happ[0][i];



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

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

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

        if(k == prv) continue;

        dp[i][k] = max(dp[i][k], dp[i-1][prv] + happ[i][k]);

      }

    }

  }



  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][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.053109168692075x):
#include<iostream>

#include<algorithm>

using namespace std;

int a[100005][4];

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

int main()

{

	int n;

	cin>>n;

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

		cin>>a[i][0]>>a[i][1]>>a[i][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][1],dp[i-1][0])+a[i][2];

	}

	int ans=-1;

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

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

	cout<<ans<<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.389864204588014x):
#include<iostream>

#include<algorithm>

using namespace std;

int a[100005][4];

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

int main()

{

	int n;

	cin>>n;

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

		cin>>a[i][0]>>a[i][1]>>a[i][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][1],dp[i-1][0])+a[i][2];

	}

	int ans=-1;

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

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

	cout<<ans<<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.7872746477587773x):
#include<iostream>

#include<algorithm>

using namespace std;

int a[100005][4];

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

int main()

{

	int n;

	cin>>n;

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

		cin>>a[i][0]>>a[i][1]>>a[i][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][1],dp[i-1][0])+a[i][2];

	}

	int ans=-1;

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

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

	cout<<ans<<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.049532566788641x):
#include <bits/stdc++.h>

using namespace std;

int n;

long long f[100005] , s[100005] , th[100005];

long long mem[100005][4];

long long sol(){

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

		mem[i][0] = mem[0][i] = 0;

	}

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

		mem[i][1] = max(mem[i-1][3] + f[i] , mem[i-1][2] +f[i]);

		mem[i][2] = max(mem[i-1][1] + s[i] , mem[i-1][3] + s[i]);

		mem[i][3] = max(mem[i-1][2] + th[i] , mem[i-1][1] +th[i]);

	}

	return max(mem[n][1] , max(mem[n][2],mem[n][3]));

}

int main()

{

	cin>>n;

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

		cin>>f[i]>>s[i]>>th[i];

	}

	cout<<sol();

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

using namespace std;

int n;

long long f[100005] , s[100005] , th[100005];

long long mem[100005][4];

long long sol(){

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

		mem[i][0] = mem[0][i] = 0;

	}

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

		mem[i][1] = max(mem[i-1][3] + f[i] , mem[i-1][2] +f[i]);

		mem[i][2] = max(mem[i-1][1] + s[i] , mem[i-1][3] + s[i]);

		mem[i][3] = max(mem[i-1][2] + th[i] , mem[i-1][1] +th[i]);

	}

	return max(mem[n][1] , max(mem[n][2],mem[n][3]));

}

int main()

{

	cin>>n;

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

		cin>>f[i]>>s[i]>>th[i];

	}

	cout<<sol();

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

using namespace std;

int n;

long long f[100005] , s[100005] , th[100005];

long long mem[100005][4];

long long sol(){

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

		mem[i][0] = mem[0][i] = 0;

	}

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

		mem[i][1] = max(mem[i-1][3] + f[i] , mem[i-1][2] +f[i]);

		mem[i][2] = max(mem[i-1][1] + s[i] , mem[i-1][3] + s[i]);

		mem[i][3] = max(mem[i-1][2] + th[i] , mem[i-1][1] +th[i]);

	}

	return max(mem[n][1] , max(mem[n][2],mem[n][3]));

}

int main()

{

	cin>>n;

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

		cin>>f[i]>>s[i]>>th[i];

	}

	cout<<sol();

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

# define ll long long

# define fi first

# define se second



using namespace std ;



ll N, a, b, c, sum, pre;

ll vc[100001][3], dp[100001][3] ;

int main() {

    cin >> N ;

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

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

    }

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

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

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

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

    }

    cout << max( { vc[N-1][1], vc[N-1][2], vc[N-1][3] } ) << endl;

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

# define ll long long

# define fi first

# define se second



using namespace std ;



ll N, a, b, c, sum, pre;

ll vc[100001][3], dp[100001][3] ;

int main() {

    cin >> N ;

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

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

    }

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

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

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

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

    }

    cout << max( { vc[N-1][1], vc[N-1][2], vc[N-1][3] } ) << endl;

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

# define ll long long

# define fi first

# define se second



using namespace std ;



ll N, a, b, c, sum, pre;

ll vc[100001][3], dp[100001][3] ;

int main() {

    cin >> N ;

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

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

    }

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

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

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

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

    }

    cout << max( { vc[N-1][1], vc[N-1][2], vc[N-1][3] } ) << endl;

}
// 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.002911541162934x):
//بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ

//لا إله إلا الله محمد رسول الله



#include <bits/stdc++.h>



#pragma GCC optimize("Ofast")



#define ll long long

#define pb push_back

#define fr first

#define sc second

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

#define out freopen("snakes.out", "w", stdout)

using namespace std;



ll dp[100005][5];

ll n;

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

int main(){

    //in;

    //out;

    ios_base::sync_with_stdio(false);

    cin >> n;



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

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

    }



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

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

    dp[1][3] = c[1];



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

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

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

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

    }



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





}