stablegradients/pie-gem5-pairs huggingface dataset:
// 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;

//const int mod = 1e9+9;

/*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }

*ll lcm(ll x, ll y){return x*(y/gcd(x,y));}

*void exEuclid(int a, int b){

	if(b==0){x = 1; y=0; d=a; return ;}

	exEuclid(b, a%b);

	int x1=y;

	int y1=x-(a/b)*y;

	x=x1; 100000

	y=y1;

} 

* */

//===========================================================//

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.1762232289037007x):
/* BISMILLAHIR RAHMANIR RAHIM */

#include<bits/stdc++.h>

using namespace std;

#define ll        long long

#define ull       unsigned long long

#define sd(x)     scanf("%lf", &x)

#define l0(i,n)   for(ll i=0; i<n; i++)

#define MAX       100005

#define maxn 	  200005

#define pb 		  push_back

#define mk 		  make_pair

#define endl	  "\n"

#define INF 	  1000000000

#define MOD		  1000000007

#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "





int main()

{

	int n;

	cin >> n;

	vector<int> hap[n+5];

	vector<int> dp[n+5];

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

	{

		int a,b,c;

		cin >> a >> b >> c;

		hap[i].pb(a);

		hap[i].pb(b);

		hap[i].pb(c);

		dp[i].pb(0);

		dp[i].pb(0);

		dp[i].pb(0);

	}

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

	dp[0][0] = hap[0][0];

	dp[0][1] = hap[0][1];

	dp[0][2] = hap[0][2];

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

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

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

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

	}

	int ans = *max_element(dp[n-1].begin(),dp[n-1].end());

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

//	{

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

//	}

	cout << ans << endl;

	return 0;

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

using namespace std;

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.176201254222485x):
/* BISMILLAHIR RAHMANIR RAHIM */

#include<bits/stdc++.h>

using namespace std;

#define ll        long long

#define ull       unsigned long long

#define sd(x)     scanf("%lf", &x)

#define l0(i,n)   for(ll i=0; i<n; i++)

#define MAX       100005

#define maxn 	  200005

#define pb 		  push_back

#define mk 		  make_pair

#define endl	  "\n"

#define INF 	  1000000000

#define MOD		  1000000007

#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "





int main()

{

	int n;

	cin >> n;

	vector<int> hap[n+5];

	vector<int> dp[n+5];

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

	{

		int a,b,c;

		cin >> a >> b >> c;

		hap[i].pb(a);

		hap[i].pb(b);

		hap[i].pb(c);

		dp[i].pb(0);

		dp[i].pb(0);

		dp[i].pb(0);

	}

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

	dp[0][0] = hap[0][0];

	dp[0][1] = hap[0][1];

	dp[0][2] = hap[0][2];

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

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

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

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

	}

	int ans = *max_element(dp[n-1].begin(),dp[n-1].end());

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

//	{

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

//	}

	cout << ans << endl;

	return 0;

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

using namespace std;



int const N=1e5+5, M=1e9+7, OO = 0x3f3f3f3f;



int n;

int arr[3][N];



int mem[N][4];

int solve(int i, int last)

{

    if(i==n)

        return 0;

    if(mem[i][last]!=-1)

        return mem[i][last];

    int op1= (last!=1) ? solve(i+1, 1)+arr[0][i] : 0;

    int op2= (last!=2) ? solve(i+1, 2)+arr[1][i] : 0;

    int op3= (last!=3) ? solve(i+1, 3)+arr[2][i] : 0;

    return mem[i][last]=max(op1,max(op2,op3));

}





int main()

{

//    freopen("input.txt","rt",stdin);

//    freopen("output.txt","wt",stdout);

    scanf("%d",&n);

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

        scanf("%d %d %d",arr[0]+i,arr[1]+i,arr[2]+i);

    memset(mem, -1, sizeof mem);

    printf("%d\n",solve(0,0));







    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.550326208617673x):
/* BISMILLAHIR RAHMANIR RAHIM */

#include<bits/stdc++.h>

using namespace std;

#define ll        long long

#define ull       unsigned long long

#define sd(x)     scanf("%lf", &x)

#define l0(i,n)   for(ll i=0; i<n; i++)

#define MAX       100005

#define maxn 	  200005

#define pb 		  push_back

#define mk 		  make_pair

#define endl	  "\n"

#define INF 	  1000000000

#define MOD		  1000000007

#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "





int main()

{

	int n;

	cin >> n;

	vector<int> hap[n+5];

	vector<int> dp[n+5];

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

	{

		int a,b,c;

		cin >> a >> b >> c;

		hap[i].pb(a);

		hap[i].pb(b);

		hap[i].pb(c);

		dp[i].pb(0);

		dp[i].pb(0);

		dp[i].pb(0);

	}

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

	dp[0][0] = hap[0][0];

	dp[0][1] = hap[0][1];

	dp[0][2] = hap[0][2];

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

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

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

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

	}

	int ans = *max_element(dp[n-1].begin(),dp[n-1].end());

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

//	{

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

//	}

	cout << ans << endl;

	return 0;

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

using namespace std;

#define ALL(x) begin(x),end(x)

typedef long long ll;

int OO = 0x3f3f3f3f;



int n;

int a[100005];

int b[100005];

int c[100005];

int mem[100005][3];



int solve(int x, int k)

{

    int op1, op2, op3;

    if(x == n)

        return 0;



    if(mem[x][k] != -1)

        return mem[x][k];



    op1 = op2 = op3 = 0;

    if(k != 1)

        op1 = solve(x+1, 1)+a[x];

    if(k != 2)

        op2 = solve(x+1, 2)+b[x];

    if(k != 3)

        op3 = solve(x+1, 3)+c[x];



    return mem[x][k] = max(op1, max(op2, op3));

}



int main()

{

    memset(mem, -1, sizeof mem);

    cin >> n;

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

    {

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

    }

    cout << solve(0, 0) << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.178021478522634x):
/* BISMILLAHIR RAHMANIR RAHIM */

#include<bits/stdc++.h>

using namespace std;

#define ll        long long

#define ull       unsigned long long

#define sd(x)     scanf("%lf", &x)

#define l0(i,n)   for(ll i=0; i<n; i++)

#define MAX       100005

#define maxn 	  200005

#define pb 		  push_back

#define mk 		  make_pair

#define endl	  "\n"

#define INF 	  1000000000

#define MOD		  1000000007

#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "





int main()

{

	int n;

	cin >> n;

	vector<int> hap[n+5];

	vector<int> dp[n+5];

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

	{

		int a,b,c;

		cin >> a >> b >> c;

		hap[i].pb(a);

		hap[i].pb(b);

		hap[i].pb(c);

		dp[i].pb(0);

		dp[i].pb(0);

		dp[i].pb(0);

	}

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

	dp[0][0] = hap[0][0];

	dp[0][1] = hap[0][1];

	dp[0][2] = hap[0][2];

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

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

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

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

	}

	int ans = *max_element(dp[n-1].begin(),dp[n-1].end());

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

//	{

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

//	}

	cout << ans << endl;

	return 0;

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



using namespace std;



const int N = 1e5 + 9, OO = 0x3f3f3f3f;



int n, points[N][3], dp[N][4];



int solve(int i, int prev){

    if(i == n)  return 0;



    int &ret = dp[i][prev];

    if(~ret)    return ret;



    ret = 0;

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

        if(prev != j)   ret = max(ret, points[i][j] + solve(i + 1, j));





    return ret;

}



int main(){



    cin >> n;

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

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



    memset(dp, -1, sizeof dp);



    cout << solve(0, 3);

}


// Faster C++ solution for the same problem (measured speedup: 2.5652922402621394x):
/* BISMILLAHIR RAHMANIR RAHIM */

#include<bits/stdc++.h>

using namespace std;

#define ll        long long

#define ull       unsigned long long

#define sd(x)     scanf("%lf", &x)

#define l0(i,n)   for(ll i=0; i<n; i++)

#define MAX       100005

#define maxn 	  200005

#define pb 		  push_back

#define mk 		  make_pair

#define endl	  "\n"

#define INF 	  1000000000

#define MOD		  1000000007

#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "





int main()

{

	int n;

	cin >> n;

	vector<int> hap[n+5];

	vector<int> dp[n+5];

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

	{

		int a,b,c;

		cin >> a >> b >> c;

		hap[i].pb(a);

		hap[i].pb(b);

		hap[i].pb(c);

		dp[i].pb(0);

		dp[i].pb(0);

		dp[i].pb(0);

	}

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

	dp[0][0] = hap[0][0];

	dp[0][1] = hap[0][1];

	dp[0][2] = hap[0][2];

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

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

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

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

	}

	int ans = *max_element(dp[n-1].begin(),dp[n-1].end());

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

//	{

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

//	}

	cout << ans << endl;

	return 0;

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

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

#define     FasterIO        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define     bug(a,b)        cout<<a<<"\t"<<b<<"\n";

#define     Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";

#define     watch(a)        cout<<fixed<<setprecision(a)

#define     lp(i,a,b)       for(int i=a;i<b;i++)

#define     Endl            "\n";

#define     tab             "\t"

#define     reset(a,b)      memset(a,b,sizeof(a));

#define     sf(a)           scanf(" %d", &a);

#define     srt(a)          sort(a.begin(),a.end());

#define     pi              2*acos(0.0)

#define     inf             INT_MAX

const int sz=1e5+9;

int n,x,arr[sz][3],dp[sz][3];



int clac(int i,int ignore ,int value){

    if(i>n)return value;

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

    int ret=0;

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

        if(j==ignore)

            continue;

        ret=max(ret,value+clac(i+1,j,arr[i][j]));

    }

    return dp[i][ignore]=ret;

}



void solve(){

    cin>>n;

    reset(dp,-1);

    //cout<<dp[2][0]<<tab<<dp[2][1]<<tab<<dp[2][2]<<endl;

    lp(i,1,n+1)cin>>arr[i][0]>>arr[i][1]>>arr[i][2];

    int ans1=clac(2,0,arr[1][0]);

    //cout<<dp[2][0]<<tab<<dp[2][1]<<tab<<dp[2][2]<<endl;

    int ans2=clac(2,1,arr[1][1]);

    int ans3=clac(2,2,arr[1][2]);

    //cout<<ans1<<tab<<ans2<<tab<<ans3<<endl;

    //int ans=max(ans1,(max(ans2,ans3)));

   // bug(ans1,1);

    cout<<max(ans1,(max(ans2,ans3)))<<"\n";

}



int main(){

    //FasterIO;

    #ifndef ONLINE_JUDGE

       //freopen("1.txt","r",stdin);

    #endif

    // int t;

    //cin>>t;

    //while(t--)

        solve();

}


// Faster C++ solution for the same problem (measured speedup: 2.174955849915159x):
/* BISMILLAHIR RAHMANIR RAHIM */

#include<bits/stdc++.h>

using namespace std;

#define ll        long long

#define ull       unsigned long long

#define sd(x)     scanf("%lf", &x)

#define l0(i,n)   for(ll i=0; i<n; i++)

#define MAX       100005

#define maxn 	  200005

#define pb 		  push_back

#define mk 		  make_pair

#define endl	  "\n"

#define INF 	  1000000000

#define MOD		  1000000007

#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "





int main()

{

	int n;

	cin >> n;

	vector<int> hap[n+5];

	vector<int> dp[n+5];

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

	{

		int a,b,c;

		cin >> a >> b >> c;

		hap[i].pb(a);

		hap[i].pb(b);

		hap[i].pb(c);

		dp[i].pb(0);

		dp[i].pb(0);

		dp[i].pb(0);

	}

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

	dp[0][0] = hap[0][0];

	dp[0][1] = hap[0][1];

	dp[0][2] = hap[0][2];

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

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

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

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

	}

	int ans = *max_element(dp[n-1].begin(),dp[n-1].end());

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

//	{

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

//	}

	cout << ans << endl;

	return 0;

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

using namespace std;



#define ll long long

#define size 100001



int a[size];

int b[size];

int c[size];

int dp[size][4];



int max_sum(int n, int p)

{

    if(n <= 0)

        return 0;

    if(n > 0 && dp[n][p] != -1)

        return dp[n][p];

    int ans = INT_MIN;

    if(p != 0)

    {

        ans = max(ans,a[n]+max_sum(n-1,0));

    }

    if(p != 1)

    {

        ans = max(ans,b[n]+max_sum(n-1,1));

    }

    if(p != 2)

    {

        ans = max(ans,c[n]+max_sum(n-1,2));

    }



    return dp[n][p] = ans;

}







int main()

{

  //OJ;

  int t = 1;

  //cin>>t;

  while(t--){

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

  int n;

  cin>>n;



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

  {

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

  }

  cout<<max_sum(n,3)<<endl;

  }

   return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.5744951055711423x):
/* BISMILLAHIR RAHMANIR RAHIM */

#include<bits/stdc++.h>

using namespace std;

#define ll        long long

#define ull       unsigned long long

#define sd(x)     scanf("%lf", &x)

#define l0(i,n)   for(ll i=0; i<n; i++)

#define MAX       100005

#define maxn 	  200005

#define pb 		  push_back

#define mk 		  make_pair

#define endl	  "\n"

#define INF 	  1000000000

#define MOD		  1000000007

#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "





int main()

{

	int n;

	cin >> n;

	vector<int> hap[n+5];

	vector<int> dp[n+5];

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

	{

		int a,b,c;

		cin >> a >> b >> c;

		hap[i].pb(a);

		hap[i].pb(b);

		hap[i].pb(c);

		dp[i].pb(0);

		dp[i].pb(0);

		dp[i].pb(0);

	}

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

	dp[0][0] = hap[0][0];

	dp[0][1] = hap[0][1];

	dp[0][2] = hap[0][2];

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

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

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

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

	}

	int ans = *max_element(dp[n-1].begin(),dp[n-1].end());

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

//	{

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

//	}

	cout << ans << endl;

	return 0;

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





using namespace std;



vector<vector<int>> vec(100007);

int n;



long long meme[100007][5];





long long solve(int index, int flag){

    if(index==n){

        return 0;

    }

    

    long long &res = meme[index][flag]; 

    

    if(res != -1){

        return res;

    }

    res = 0;

    

    if(flag!=0){

        res = max(res,vec[index][0]+solve(index+1,0));

    }

    if(flag!=1){

        res =  max(res,vec[index][1]+solve(index+1,1));

    }

    if(flag!=2){

        res =  max(res,vec[index][2]+solve(index+1,2));

    }

    return res;

}



int main(){

    cin>>n;

    int num1,num2,num3;

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

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

        cin>>num1>>num2>>num3;

        vec[i].push_back(num1);

        vec[i].push_back(num2);

        vec[i].push_back(num3);

    }

    long long sol = solve(0,3);

    cout<<sol<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 7.942134412707321x):
/* BISMILLAHIR RAHMANIR RAHIM */

#include<bits/stdc++.h>

using namespace std;

#define ll        long long

#define ull       unsigned long long

#define sd(x)     scanf("%lf", &x)

#define l0(i,n)   for(ll i=0; i<n; i++)

#define MAX       100005

#define maxn 	  200005

#define pb 		  push_back

#define mk 		  make_pair

#define endl	  "\n"

#define INF 	  1000000000

#define MOD		  1000000007

#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "





int main()

{

	int n;

	cin >> n;

	vector<int> hap[n+5];

	vector<int> dp[n+5];

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

	{

		int a,b,c;

		cin >> a >> b >> c;

		hap[i].pb(a);

		hap[i].pb(b);

		hap[i].pb(c);

		dp[i].pb(0);

		dp[i].pb(0);

		dp[i].pb(0);

	}

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

	dp[0][0] = hap[0][0];

	dp[0][1] = hap[0][1];

	dp[0][2] = hap[0][2];

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

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

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

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

	}

	int ans = *max_element(dp[n-1].begin(),dp[n-1].end());

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

//	{

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

//	}

	cout << ans << endl;

	return 0;

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

#define inf 1000000007

#define N 100007

using namespace std;



int a[N];

int b[N];

int c[N];

int n;

long long mem[N][3];



long long dp(int i, int j)

{

    if(i >= n)

        return 0;

    if(mem[i][j] != -1)

        return mem[i][j];

    long long ans = 0;

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

    {

        if(k == 0 && k != j)

        {

            long long val = a[i] + dp(i + 1, k);

            ans = max(ans, val);

        }

        if(k == 1 && k != j)

        {

            long long val = b[i] + dp(i + 1, k);

            ans = max(ans, val);

        }

        if(k == 2 && k != j)

        {

            long long val = c[i] + dp(i + 1, k);

            ans = max(ans, val);

        }

    }

    mem[i][j] = ans;

    return ans;

}



int main()

{

    //freopen("input.txt", "r", stdin);

    //freopen("output.txt", "w", stdout);

    cin >> n;

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

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

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

    long long val1 = dp(0, 0);

    long long val2 = dp(0, 1);

    long long val3 = dp(0, 2);

    long long ans = max(val1, val2);

    ans = max(ans, val3);

    cout << ans << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.3528693139253587x):
/* BISMILLAHIR RAHMANIR RAHIM */

#include<bits/stdc++.h>

using namespace std;

#define ll        long long

#define ull       unsigned long long

#define sd(x)     scanf("%lf", &x)

#define l0(i,n)   for(ll i=0; i<n; i++)

#define MAX       100005

#define maxn 	  200005

#define pb 		  push_back

#define mk 		  make_pair

#define endl	  "\n"

#define INF 	  1000000000

#define MOD		  1000000007

#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "





int main()

{

	int n;

	cin >> n;

	vector<int> hap[n+5];

	vector<int> dp[n+5];

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

	{

		int a,b,c;

		cin >> a >> b >> c;

		hap[i].pb(a);

		hap[i].pb(b);

		hap[i].pb(c);

		dp[i].pb(0);

		dp[i].pb(0);

		dp[i].pb(0);

	}

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

	dp[0][0] = hap[0][0];

	dp[0][1] = hap[0][1];

	dp[0][2] = hap[0][2];

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

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

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

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

	}

	int ans = *max_element(dp[n-1].begin(),dp[n-1].end());

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

//	{

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

//	}

	cout << ans << endl;

	return 0;

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

using namespace std;

using ll = long long;

using ii = pair<int, int>;

using iii = pair<ii, int>;

#define vt vector

#define pq priority_queue

#define pb push_back

#define pf push_front

#define mp make_pair

#define fi first

#define se second

#define __lcm(a, b) a * b / __gcd(a, b)

const int MOD = 1e9 + 7;

const int INF = 2e9;

const int N = 1e5 + 5;



int n;

int a[N], b[N], c[N];

int dp[N][5];



int f(int idx, int now) {

    if(idx == n) return 0;

    int &sol = dp[idx][now];

    if(sol != -1) return sol;

    if(now == 0) {

        sol = max(f(idx + 1, 1) + a[idx + 1], 

              max(f(idx + 1, 2) + b[idx + 1], 

                  f(idx + 1, 3) + c[idx + 1]));

    } else if(now == 1) {

        sol = max(f(idx + 1, 2) + b[idx + 1],

                  f(idx + 1, 3) + c[idx + 1]);

    } else if(now == 2) {

        sol = max(f(idx + 1, 1) + a[idx + 1],

                  f(idx + 1, 3) + c[idx + 1]);

    } else {

        sol = max(f(idx + 1, 1) + a[idx + 1],

                  f(idx + 1, 2) + b[idx + 1]);

    }

    return sol;

}



void solve() {

    cin >> n;

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

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

    }

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

    cout << f(0, 0) << "\n";

}



int main() {

 

    ios_base::sync_with_stdio(0);

    cin.tie(0); cout.tie(0);

    

    solve();

    

}

// Faster C++ solution for the same problem (measured speedup: 2.9739525454119144x):
/* BISMILLAHIR RAHMANIR RAHIM */

#include<bits/stdc++.h>

using namespace std;

#define ll        long long

#define ull       unsigned long long

#define sd(x)     scanf("%lf", &x)

#define l0(i,n)   for(ll i=0; i<n; i++)

#define MAX       100005

#define maxn 	  200005

#define pb 		  push_back

#define mk 		  make_pair

#define endl	  "\n"

#define INF 	  1000000000

#define MOD		  1000000007

#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "





int main()

{

	int n;

	cin >> n;

	vector<int> hap[n+5];

	vector<int> dp[n+5];

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

	{

		int a,b,c;

		cin >> a >> b >> c;

		hap[i].pb(a);

		hap[i].pb(b);

		hap[i].pb(c);

		dp[i].pb(0);

		dp[i].pb(0);

		dp[i].pb(0);

	}

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

	dp[0][0] = hap[0][0];

	dp[0][1] = hap[0][1];

	dp[0][2] = hap[0][2];

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

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

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

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

	}

	int ans = *max_element(dp[n-1].begin(),dp[n-1].end());

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

//	{

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

//	}

	cout << ans << endl;

	return 0;

}