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.1625719816369076x):
#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;

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

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

}
// 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.533982547644212x):
#include <iostream>

#include<cstdio>

using namespace std;

typedef struct day{

    int a,b,c;

}D;

int Max(int a,int b){

    return a>b?a:b;

}

int MM(D d){

    int m=d.a>d.b?d.a:d.b;

    return d.c>m?d.c:m;

}

int main()

{

    int n;

    D t,dp[2];

    cin>>n;

    dp[0].a=dp[0].b=dp[0].c=0;

    while(n--){

        cin>>t.a>>t.b>>t.c;

        dp[1].a=t.a+Max(dp[0].b,dp[0].c);

        dp[1].b=t.b+Max(dp[0].a,dp[0].c);

        dp[1].c=t.c+Max(dp[0].a,dp[0].b);

        dp[0]=dp[1];

    }

    cout<<MM(dp[1])<<endl;

    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.186830531952377x):
#include <iostream>

#include<cstdio>

using namespace std;

typedef struct day{

    int a,b,c;

}D;

int Max(int a,int b){

    return a>b?a:b;

}

int MM(D d){

    int m=d.a>d.b?d.a:d.b;

    return d.c>m?d.c:m;

}

int main()

{

    int n;

    D t,dp[2];

    cin>>n;

    dp[0].a=dp[0].b=dp[0].c=0;

    while(n--){

        cin>>t.a>>t.b>>t.c;

        dp[1].a=t.a+Max(dp[0].b,dp[0].c);

        dp[1].b=t.b+Max(dp[0].a,dp[0].c);

        dp[1].c=t.c+Max(dp[0].a,dp[0].b);

        dp[0]=dp[1];

    }

    cout<<MM(dp[1])<<endl;

    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.267186563190918x):
#include <iostream>

#include<cstdio>

using namespace std;

typedef struct day{

    int a,b,c;

}D;

int Max(int a,int b){

    return a>b?a:b;

}

int MM(D d){

    int m=d.a>d.b?d.a:d.b;

    return d.c>m?d.c:m;

}

int main()

{

    int n;

    D t,dp[2];

    cin>>n;

    dp[0].a=dp[0].b=dp[0].c=0;

    while(n--){

        cin>>t.a>>t.b>>t.c;

        dp[1].a=t.a+Max(dp[0].b,dp[0].c);

        dp[1].b=t.b+Max(dp[0].a,dp[0].c);

        dp[1].c=t.c+Max(dp[0].a,dp[0].b);

        dp[0]=dp[1];

    }

    cout<<MM(dp[1])<<endl;

    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.216763471677139x):
#include <iostream>

#include<cstdio>

using namespace std;

typedef struct day{

    int a,b,c;

}D;

int Max(int a,int b){

    return a>b?a:b;

}

int MM(D d){

    int m=d.a>d.b?d.a:d.b;

    return d.c>m?d.c:m;

}

int main()

{

    int n;

    D t,dp[2];

    cin>>n;

    dp[0].a=dp[0].b=dp[0].c=0;

    while(n--){

        cin>>t.a>>t.b>>t.c;

        dp[1].a=t.a+Max(dp[0].b,dp[0].c);

        dp[1].b=t.b+Max(dp[0].a,dp[0].c);

        dp[1].c=t.c+Max(dp[0].a,dp[0].b);

        dp[0]=dp[1];

    }

    cout<<MM(dp[1])<<endl;

    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.523425737458343x):
#include <cstdio>

#include <iostream>

#include<vector>

#include<algorithm>

using namespace std;

	vector<int> p[3];

int main(){

	int n,t1,t2,t3;

	cin>>n;

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

		scanf("%d %d %d",&t1,&t2,&t3);

		p[0].push_back(t1);

		p[1].push_back(t2);

		p[2].push_back(t3);

	}

	int a[3],b[3];

	b[0]=a[0]=p[0][0];

	b[1]=a[1]=p[1][0];

	b[2]=a[2]=p[2][0];

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

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

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

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

		b[0]=a[0];b[1]=a[1];b[2]=a[2];

	}

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

	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.1802979714421746x):
#include <cstdio>

#include <iostream>

#include<vector>

#include<algorithm>

using namespace std;

	vector<int> p[3];

int main(){

	int n,t1,t2,t3;

	cin>>n;

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

		scanf("%d %d %d",&t1,&t2,&t3);

		p[0].push_back(t1);

		p[1].push_back(t2);

		p[2].push_back(t3);

	}

	int a[3],b[3];

	b[0]=a[0]=p[0][0];

	b[1]=a[1]=p[1][0];

	b[2]=a[2]=p[2][0];

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

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

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

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

		b[0]=a[0];b[1]=a[1];b[2]=a[2];

	}

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

	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.260413960926791x):
#include <cstdio>

#include <iostream>

#include<vector>

#include<algorithm>

using namespace std;

	vector<int> p[3];

int main(){

	int n,t1,t2,t3;

	cin>>n;

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

		scanf("%d %d %d",&t1,&t2,&t3);

		p[0].push_back(t1);

		p[1].push_back(t2);

		p[2].push_back(t3);

	}

	int a[3],b[3];

	b[0]=a[0]=p[0][0];

	b[1]=a[1]=p[1][0];

	b[2]=a[2]=p[2][0];

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

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

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

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

		b[0]=a[0];b[1]=a[1];b[2]=a[2];

	}

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

	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.210141494663397x):
#include <cstdio>

#include <iostream>

#include<vector>

#include<algorithm>

using namespace std;

	vector<int> p[3];

int main(){

	int n,t1,t2,t3;

	cin>>n;

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

		scanf("%d %d %d",&t1,&t2,&t3);

		p[0].push_back(t1);

		p[1].push_back(t2);

		p[2].push_back(t3);

	}

	int a[3],b[3];

	b[0]=a[0]=p[0][0];

	b[1]=a[1]=p[1][0];

	b[2]=a[2]=p[2][0];

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

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

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

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

		b[0]=a[0];b[1]=a[1];b[2]=a[2];

	}

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

	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.5667761091485897x):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

using namespace std;

int n,a[1000010],b[1000010], c[1000010],dp[1000010][5];

int main()

{

    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][3],max(dp[n][1],dp[n][2]));

    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.207123207590245x):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

using namespace std;

int n,a[1000010],b[1000010], c[1000010],dp[1000010][5];

int main()

{

    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][3],max(dp[n][1],dp[n][2]));

    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.2882249019488334x):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

using namespace std;

int n,a[1000010],b[1000010], c[1000010],dp[1000010][5];

int main()

{

    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][3],max(dp[n][1],dp[n][2]));

    return 0;

}