stablegradients/pie-gem5-pairs huggingface dataset:
// 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.459266690834695x):
#include<bits/stdc++.h>

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

#define mp make_pair

using namespace std;



using ll = long long;

using ii = pair<int, int>;

const int INF = (int)10e9;

int dp[3][100005];



int main() {

    std::ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    int N;

    cin>>N;

    vector<int> a(N), b(N), c(N);

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

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

    }



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

    dp[1][0] = b[0];

    dp[2][0] = c[0];

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

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

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

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

    }

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

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

#define mp make_pair

using namespace std;



using ll = long long;

using ii = pair<int, int>;

const int INF = (int)10e9;

int dp[3][100005];



int main() {

    std::ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    int N;

    cin>>N;

    vector<int> a(N), b(N), c(N);

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

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

    }



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

    dp[1][0] = b[0];

    dp[2][0] = c[0];

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

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

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

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

    }

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

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

#define mp make_pair

using namespace std;



using ll = long long;

using ii = pair<int, int>;

const int INF = (int)10e9;

int dp[3][100005];



int main() {

    std::ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    int N;

    cin>>N;

    vector<int> a(N), b(N), c(N);

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

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

    }



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

    dp[1][0] = b[0];

    dp[2][0] = c[0];

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

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

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

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

    }

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

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

#define mp make_pair

using namespace std;



using ll = long long;

using ii = pair<int, int>;

const int INF = (int)10e9;

int dp[3][100005];



int main() {

    std::ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    int N;

    cin>>N;

    vector<int> a(N), b(N), c(N);

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

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

    }



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

    dp[1][0] = b[0];

    dp[2][0] = c[0];

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

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

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

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

    }

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



    return 0;

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;



int n;

const int nx = 1e5+5;

int ac[nx][3];

int dp[3][nx];



int go(int a, int i){

	if(i == n) return 0;

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

	int& ans = dp[a][i];

	

	if(a==0){

		ans=max(ans, go(1, i+1)+ac[i][0]);

		ans=max(ans, go(2, i+1)+ac[i][0]);

	}

	if(a==1){

		ans=max(ans, go(0, i+1)+ac[i][1]);

		ans=max(ans, go(2, i+1)+ac[i][1]);

	}

	if(a==2){

		ans=max(ans, go(0, i+1)+ac[i][2]);

		ans=max(ans, go(1, i+1)+ac[i][2]);

	}

	

	return ans;

}



int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<max(go(0,0),max(go(1,0),go(2,0)))<<"\n";

	return 0;

}


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

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

#define mp make_pair

using namespace std;



using ll = long long;

using ii = pair<int, int>;

const int INF = (int)10e9;

int dp[3][100005];



int main() {

    std::ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    int N;

    cin>>N;

    vector<int> a(N), b(N), c(N);

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

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

    }



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

    dp[1][0] = b[0];

    dp[2][0] = c[0];

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

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

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

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

    }

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

using namespace std;

const int oo = 1e9;

int number;

const int nx = 1e5+5;

int ac[nx][3];

int dyn[3][nx];

int init(int a, int i){

	if(i == number) return 0;

	if(dyn[a][i] != -1) return dyn[a][i];

	int& res = dyn[a][i];

	

	if(a==0){

		res=max(res, init(1, i+1)+ac[i][0]);

		res=max(res, init(2, i+1)+ac[i][0]);

	}

	if(a==1){

		res=max(res, init(0, i+1)+ac[i][1]);

		res=max(res, init(2, i+1)+ac[i][1]);

	}

	if(a==2){

		res=max(res, init(0, i+1)+ac[i][2]);

		res=max(res, init(1, i+1)+ac[i][2]);

	}

	

	return res;

}

int main(){

	cin>>number;

	for(int i=0; i<number; i++) cin>>ac[i][0]>>ac[i][1]>>ac[i][2];

	memset(dyn, -1, sizeof dyn);

	cout<<max(init(0,0),max(init(1,0),init(2,0)))<<"\n";

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

    

using namespace std;

     

int main(){  

    int n;

    cin >> n;

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

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

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

            cin >> h[i][j];

        }

    }

 

    vector<array<long long,3>> dp(n);

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

        dp[0][j] = h[0][j];

    }

    

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

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

            dp[i][j] = 0;

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

                if (j == k) continue;

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

            }

        }

    }

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

    

using namespace std;

     

int main(){  

    int n;

    cin >> n;

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

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

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

            cin >> h[i][j];

        }

    }

 

    vector<array<long long,3>> dp(n);

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

        dp[0][j] = h[0][j];

    }

    

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

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

            dp[i][j] = 0;

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

                if (j == k) continue;

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

            }

        }

    }

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

    

using namespace std;

     

int main(){  

    int n;

    cin >> n;

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

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

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

            cin >> h[i][j];

        }

    }

 

    vector<array<long long,3>> dp(n);

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

        dp[0][j] = h[0][j];

    }

    

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

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

            dp[i][j] = 0;

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

                if (j == k) continue;

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

            }

        }

    }

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

    

using namespace std;

     

int main(){  

    int n;

    cin >> n;

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

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

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

            cin >> h[i][j];

        }

    }

 

    vector<array<long long,3>> dp(n);

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

        dp[0][j] = h[0][j];

    }

    

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

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

            dp[i][j] = 0;

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

                if (j == k) continue;

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

            }

        }

    }

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

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;



int n;

const int nx = 1e5+5;

int ac[nx][3];

int dp[3][nx];



int go(int a, int i){

	if(i == n) return 0;

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

	int& ans = dp[a][i];

	

	if(a==0){

		ans=max(ans, go(1, i+1)+ac[i][0]);

		ans=max(ans, go(2, i+1)+ac[i][0]);

	}

	if(a==1){

		ans=max(ans, go(0, i+1)+ac[i][1]);

		ans=max(ans, go(2, i+1)+ac[i][1]);

	}

	if(a==2){

		ans=max(ans, go(0, i+1)+ac[i][2]);

		ans=max(ans, go(1, i+1)+ac[i][2]);

	}

	

	return ans;

}



int main(){

	cin>>n;

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

	memset(dp, -1, sizeof dp);

	cout<<max(go(0,0),max(go(1,0),go(2,0)))<<"\n";

	return 0;

}


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

    

using namespace std;

     

int main(){  

    int n;

    cin >> n;

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

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

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

            cin >> h[i][j];

        }

    }

 

    vector<array<long long,3>> dp(n);

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

        dp[0][j] = h[0][j];

    }

    

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

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

            dp[i][j] = 0;

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

                if (j == k) continue;

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

            }

        }

    }

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

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

using namespace std;

const int oo = 1e9;

int number;

const int nx = 1e5+5;

int ac[nx][3];

int dyn[3][nx];

int init(int a, int i){

	if(i == number) return 0;

	if(dyn[a][i] != -1) return dyn[a][i];

	int& res = dyn[a][i];

	

	if(a==0){

		res=max(res, init(1, i+1)+ac[i][0]);

		res=max(res, init(2, i+1)+ac[i][0]);

	}

	if(a==1){

		res=max(res, init(0, i+1)+ac[i][1]);

		res=max(res, init(2, i+1)+ac[i][1]);

	}

	if(a==2){

		res=max(res, init(0, i+1)+ac[i][2]);

		res=max(res, init(1, i+1)+ac[i][2]);

	}

	

	return res;

}

int main(){

	cin>>number;

	for(int i=0; i<number; i++) cin>>ac[i][0]>>ac[i][1]>>ac[i][2];

	memset(dyn, -1, sizeof dyn);

	cout<<max(init(0,0),max(init(1,0),init(2,0)))<<"\n";

	return 0;

}




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

    

using namespace std;

     

int main(){  

    int n;

    cin >> n;

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

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

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

            cin >> h[i][j];

        }

    }

 

    vector<array<long long,3>> dp(n);

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

        dp[0][j] = h[0][j];

    }

    

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

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

            dp[i][j] = 0;

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

                if (j == k) continue;

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

            }

        }

    }

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

using namespace std;

typedef long long ll;

typedef long long int lli;

typedef long double ld;

const int oo = 1e9;



int n;

const int nx = 1e5+5;

int ac[nx][3];

int dp[3][nx];

int go(int x, int i){

	if(i==n) return 0;

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

	int& ans = dp[x][i];

	if(x==0)

	{

		ans=max(ans, go(1, i+1)+ac[i][0]);

		ans=max(ans, go(2, i+1)+ac[i][0]);

	}

	if(x==1)

	{

		ans=max(ans, go(0, i+1)+ac[i][1]);

		ans=max(ans, go(2, i+1)+ac[i][1]);

	}

	if(x==2)

	{

		ans=max(ans, go(0, i+1)+ac[i][2]);

		ans=max(ans, go(1, i+1)+ac[i][2]);

	}

	

	return ans;

	

}

int main(){

    cin>>n;

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

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

    }

    memset(dp, -1, sizeof dp);

    cout<<max(go(0,0), max(go(1,0),go(2,0)))<<"\n";

    return 0;

}