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

using namespace std;



#define MAX_N 100005

int N, h[MAX_N][3], memo[MAX_N][3];



int main() {

  scanf("%i", &N);

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

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

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

	}

  }

  memset(memo, -1, sizeof memo);

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

  	memo[0][c] = h[0][c];

  }

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

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

  	  int &opt = memo[d][c];

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

  	    if (cc != c) {

  	      opt = max(opt, memo[d - 1][cc] + h[d][c]);

		  /*

  	      if (d == 1) {

  	        printf("%i %i %i %i\n", memo[d - 1][cc], h[d][c], cc, c);

		  }

		  */

		}

	  }

	}

  }

  /*

  puts("\ndebug");

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

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

  	  printf("%i ", memo[d][c]);

	}

	puts("");

  }

  puts("end-debug\n");

  */

  int ans = -1;

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

  	ans = max(ans, memo[N - 1][c]);

  }

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

  

}

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



#define pb push_back

#define se second

#define fi first



using namespace std;



long long n, a[(int)1e5 + 7][3], d[(int)1e5 + 7][3];



int main(){

    cin >> n;

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

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

    d[1][1] = a[1][1];

    d[1][2] = a[1][2];

    d[1][3] = a[1][3];

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

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

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

                if(h != j)

                    d[i][j] = max(d[i][j], d[i - 1][h] + a[i][j]);

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

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

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

int main()

{

    int n,i,j,k;

    int a[100005][5];

    scanf("%d",&n);

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

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

    int dp[100005][5];

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

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

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

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

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

    {

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

        {

            for(k = 1;k < 4;k++)

            {

                if(k != j)

                {

                    if(dp[i][j] < dp[i - 1][k] + a[i][j])

                    dp[i][j] = dp[i - 1][k] + a[i][j];

                }

            }

        }

    }

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

    return 0;

}

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



#define pb push_back

#define se second

#define fi first



using namespace std;



long long n, a[(int)1e5 + 7][3], d[(int)1e5 + 7][3];



int main(){

    cin >> n;

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

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

    d[1][1] = a[1][1];

    d[1][2] = a[1][2];

    d[1][3] = a[1][3];

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

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

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

                if(h != j)

                    d[i][j] = max(d[i][j], d[i - 1][h] + a[i][j]);

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

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



using namespace std;



vector<vector<int> > v;

int ans[100005][3];

queue<pair<int,pair<int,int> > >s;

int maior,a=0;



void dp(int i, int bloq, int sum) {

  if(ans[i-1][bloq]>sum)

    return;

  

  if (i>=v.size())

    maior = max(sum, maior);

  else {

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

      if (bloq != j) {



        if(ans[i][j]==-1) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }

        else if (ans[i][j]<sum+v[i][j]) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }



        //dp(i+1, j, sum+v[i][j]);

      }

    }

  }

}



int main () {

  int n;

  cin>>n;

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

    int a,b,c;

    cin>>a>>b>>c;

    v.push_back({a,b,c});

  }



  maior=0;

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

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

    s.push({v[0][i],{1,i}});

    //dp(1, i, v[0][i]);

  }



  while(!s.empty()) {

    pair<int,pair<int,int> > aux = s.front();

    dp(aux.second.first, aux.second.second, aux.first);

    s.pop();

  }



  cout<<maior<<endl;



}




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



#define pb push_back

#define se second

#define fi first



using namespace std;



long long n, a[(int)1e5 + 7][3], d[(int)1e5 + 7][3];



int main(){

    cin >> n;

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

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

    d[1][1] = a[1][1];

    d[1][2] = a[1][2];

    d[1][3] = a[1][3];

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

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

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

                if(h != j)

                    d[i][j] = max(d[i][j], d[i - 1][h] + a[i][j]);

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

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



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



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

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



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


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



using namespace std;



#define ff first

#define ss second

#define int long long

#define pii pair<int,int>

#define mp make_pair



signed main(){

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	int n,i,j;

	cin>>n;

	pii dx[3] = {mp(1,2),mp(0,2),mp(0,1)};

	int mat[n][3],memo[n][3];

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

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

			cin>>mat[i][j];

		}

	}

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

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

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

			memo[i][j]=max(memo[i-1][dx[j].ff],memo[i-1][dx[j].ss])+mat[i][j];

		}	

	}

	int maior=-1;

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

		if(memo[n-1][i]>maior)maior=memo[n-1][i];

	}	



	cout<<maior<<endl;

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

using namespace std;



#define MAX_N 100005

int N, h[MAX_N][3], memo[MAX_N][3];



int main() {

  scanf("%i", &N);

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

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

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

	}

  }

  memset(memo, -1, sizeof memo);

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

  	memo[0][c] = h[0][c];

  }

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

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

  	  int &opt = memo[d][c];

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

  	    if (cc != c) {

  	      opt = max(opt, memo[d - 1][cc] + h[d][c]);

		  /*

  	      if (d == 1) {

  	        printf("%i %i %i %i\n", memo[d - 1][cc], h[d][c], cc, c);

		  }

		  */

		}

	  }

	}

  }

  /*

  puts("\ndebug");

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

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

  	  printf("%i ", memo[d][c]);

	}

	puts("");

  }

  puts("end-debug\n");

  */

  int ans = -1;

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

  	ans = max(ans, memo[N - 1][c]);

  }

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

  

}

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



using namespace std;



#define ff first

#define ss second

#define int long long

#define pii pair<int,int>

#define mp make_pair



signed main(){

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	int n,i,j;

	cin>>n;

	pii dx[3] = {mp(1,2),mp(0,2),mp(0,1)};

	int mat[n][3],memo[n][3];

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

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

			cin>>mat[i][j];

		}

	}

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

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

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

			memo[i][j]=max(memo[i-1][dx[j].ff],memo[i-1][dx[j].ss])+mat[i][j];

		}	

	}

	int maior=-1;

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

		if(memo[n-1][i]>maior)maior=memo[n-1][i];

	}	



	cout<<maior<<endl;

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

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

int main()

{

    int n,i,j,k;

    int a[100005][5];

    scanf("%d",&n);

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

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

    int dp[100005][5];

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

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

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

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

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

    {

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

        {

            for(k = 1;k < 4;k++)

            {

                if(k != j)

                {

                    if(dp[i][j] < dp[i - 1][k] + a[i][j])

                    dp[i][j] = dp[i - 1][k] + a[i][j];

                }

            }

        }

    }

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

    return 0;

}

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



using namespace std;



#define ff first

#define ss second

#define int long long

#define pii pair<int,int>

#define mp make_pair



signed main(){

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	int n,i,j;

	cin>>n;

	pii dx[3] = {mp(1,2),mp(0,2),mp(0,1)};

	int mat[n][3],memo[n][3];

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

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

			cin>>mat[i][j];

		}

	}

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

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

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

			memo[i][j]=max(memo[i-1][dx[j].ff],memo[i-1][dx[j].ss])+mat[i][j];

		}	

	}

	int maior=-1;

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

		if(memo[n-1][i]>maior)maior=memo[n-1][i];

	}	



	cout<<maior<<endl;

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



using namespace std;



vector<vector<int> > v;

int ans[100005][3];

queue<pair<int,pair<int,int> > >s;

int maior,a=0;



void dp(int i, int bloq, int sum) {

  if(ans[i-1][bloq]>sum)

    return;

  

  if (i>=v.size())

    maior = max(sum, maior);

  else {

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

      if (bloq != j) {



        if(ans[i][j]==-1) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }

        else if (ans[i][j]<sum+v[i][j]) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }



        //dp(i+1, j, sum+v[i][j]);

      }

    }

  }

}



int main () {

  int n;

  cin>>n;

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

    int a,b,c;

    cin>>a>>b>>c;

    v.push_back({a,b,c});

  }



  maior=0;

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

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

    s.push({v[0][i],{1,i}});

    //dp(1, i, v[0][i]);

  }



  while(!s.empty()) {

    pair<int,pair<int,int> > aux = s.front();

    dp(aux.second.first, aux.second.second, aux.first);

    s.pop();

  }



  cout<<maior<<endl;



}




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



using namespace std;



#define ff first

#define ss second

#define int long long

#define pii pair<int,int>

#define mp make_pair



signed main(){

	ios_base::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	int n,i,j;

	cin>>n;

	pii dx[3] = {mp(1,2),mp(0,2),mp(0,1)};

	int mat[n][3],memo[n][3];

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

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

			cin>>mat[i][j];

		}

	}

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

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

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

			memo[i][j]=max(memo[i-1][dx[j].ff],memo[i-1][dx[j].ss])+mat[i][j];

		}	

	}

	int maior=-1;

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

		if(memo[n-1][i]>maior)maior=memo[n-1][i];

	}	



	cout<<maior<<endl;

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



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



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

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



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


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

#define ll long long

using namespace std;

ll n,a[100010],b[100010],c[100010],dp[100010][3],ans=0;

inline int read(){

     int x=0,f=1;char ch=getchar();

     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

     while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}

     return x*f;

 }

int main ( )

{

	n=read();

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

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

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

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

	}

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

	cout<<ans;

	return 0;

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

using namespace std;



#define MAX_N 100005

int N, h[MAX_N][3], memo[MAX_N][3];



int main() {

  scanf("%i", &N);

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

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

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

	}

  }

  memset(memo, -1, sizeof memo);

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

  	memo[0][c] = h[0][c];

  }

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

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

  	  int &opt = memo[d][c];

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

  	    if (cc != c) {

  	      opt = max(opt, memo[d - 1][cc] + h[d][c]);

		  /*

  	      if (d == 1) {

  	        printf("%i %i %i %i\n", memo[d - 1][cc], h[d][c], cc, c);

		  }

		  */

		}

	  }

	}

  }

  /*

  puts("\ndebug");

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

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

  	  printf("%i ", memo[d][c]);

	}

	puts("");

  }

  puts("end-debug\n");

  */

  int ans = -1;

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

  	ans = max(ans, memo[N - 1][c]);

  }

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

  

}

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

#define ll long long

using namespace std;

ll n,a[100010],b[100010],c[100010],dp[100010][3],ans=0;

inline int read(){

     int x=0,f=1;char ch=getchar();

     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

     while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}

     return x*f;

 }

int main ( )

{

	n=read();

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

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

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

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

	}

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

	cout<<ans;

	return 0;

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

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

int main()

{

    int n,i,j,k;

    int a[100005][5];

    scanf("%d",&n);

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

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

    int dp[100005][5];

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

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

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

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

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

    {

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

        {

            for(k = 1;k < 4;k++)

            {

                if(k != j)

                {

                    if(dp[i][j] < dp[i - 1][k] + a[i][j])

                    dp[i][j] = dp[i - 1][k] + a[i][j];

                }

            }

        }

    }

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

    return 0;

}

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

#define ll long long

using namespace std;

ll n,a[100010],b[100010],c[100010],dp[100010][3],ans=0;

inline int read(){

     int x=0,f=1;char ch=getchar();

     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

     while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}

     return x*f;

 }

int main ( )

{

	n=read();

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

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

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

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

	}

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

	cout<<ans;

	return 0;

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



using namespace std;



vector<vector<int> > v;

int ans[100005][3];

queue<pair<int,pair<int,int> > >s;

int maior,a=0;



void dp(int i, int bloq, int sum) {

  if(ans[i-1][bloq]>sum)

    return;

  

  if (i>=v.size())

    maior = max(sum, maior);

  else {

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

      if (bloq != j) {



        if(ans[i][j]==-1) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }

        else if (ans[i][j]<sum+v[i][j]) {

          ans[i][j] = sum+v[i][j];

          s.push({sum+v[i][j],{i+1,j}});

        }



        //dp(i+1, j, sum+v[i][j]);

      }

    }

  }

}



int main () {

  int n;

  cin>>n;

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

    int a,b,c;

    cin>>a>>b>>c;

    v.push_back({a,b,c});

  }



  maior=0;

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

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

    s.push({v[0][i],{1,i}});

    //dp(1, i, v[0][i]);

  }



  while(!s.empty()) {

    pair<int,pair<int,int> > aux = s.front();

    dp(aux.second.first, aux.second.second, aux.first);

    s.pop();

  }



  cout<<maior<<endl;



}




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

#define ll long long

using namespace std;

ll n,a[100010],b[100010],c[100010],dp[100010][3],ans=0;

inline int read(){

     int x=0,f=1;char ch=getchar();

     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

     while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}

     return x*f;

 }

int main ( )

{

	n=read();

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

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

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

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

	}

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

	cout<<ans;

	return 0;

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

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

int main()

{

    int n,i,j,k;

    int a[100005][5];

    scanf("%d",&n);

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

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

    int dp[100005][5];

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

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

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

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

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

    {

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

        {

            for(k = 1;k < 4;k++)

            {

                if(k != j)

                {

                    if(dp[i][j] < dp[i - 1][k] + a[i][j])

                    dp[i][j] = dp[i - 1][k] + a[i][j];

                }

            }

        }

    }

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.2418349762399843x):
//#pragma GCC target("avx2")

//#pragma GCC optimize("O3")

   

//#include <x86intrin.h>

#include <bits/stdc++.h>   

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace __gnu_pbds;

using namespace std;



template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

     

#define F first

#define S second           

#define lb lower_bound               

#define ub upper_bound

#define pb push_back

#define pf push_front    

#define ppb pop_back

#define mp make_pair                                     

#define bpp __builtin_popcountll                                                                                        

#define sqr(x) ((x) * (x)) 

#define al 0x3F3F3F3F

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

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

#define in insert

#define ppf pop_front

#define endl '\n'

//#define int long long

 

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

typedef pair <int, int> pii;

 

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

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

const ll inf = (ll)1e18 + 1;



const double pi = acos (-1.0);

const double eps = 1e-7;                  

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

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



int n, a[N][4], dp[N][4];



inline void boost () {                    

   ios_base :: sync_with_stdio (NULL);

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

}                                                     



inline void Solve () {

   cin >> n;

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

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

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

   }                                              

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

      

     

}



main () {                                       

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

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

   boost ();

   int tt = 1;

   //cin >> tt;   

   while (tt --) {

      Solve ();

   }                                               

   return 0;      

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

using namespace std;



int n;

int dp[100100][4];

vector<int> arr[100100];



int main() {

    cin >> n;

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

        int k;

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

            cin >> k;

            arr[i].push_back(k);

        }

    }



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



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

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



            if ( j == 0 ) 

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][1], dp[pos - 1][2]);

            

            else if ( j == 1 )

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



            else

                dp[pos][j] = arr[pos][j] + max(dp[pos - 1][0], dp[pos - 1][1]);

        }

    }



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

    return 0;

}


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

using namespace std;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    long long n;

    cin >> n;

    long long a[n + 1][3], dp[n + 1][3];

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

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

        dp[i][0] = dp[i][1] = dp[i][2] = 0;

    }

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

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

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

    for(long long i = 2; 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];

    }

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

    return 0;

}