stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#define __USE_MINGW_ANSI_STDIO

#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

#include <unordered_set>

#include <unordered_map>



using namespace std;



typedef long long ll;

typedef long long ull;

typedef pair<ll, ll> ii;



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

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

#define endl		"\n"

#define fx(n)		fixed<<setprecision(n)

#define mk			make_pair	



void File()

{

#ifndef ONLINE_JUDGE

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

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

#endif

#ifdef ONLINE_JUDGE

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

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

#endif

}

void fast()

{

	ios::sync_with_stdio(NULL);

	cout.tie(NULL);

	cin.tie(NULL);

	//File();

}

const double pi = 2 * acos(0.0);

const ll oo = 0x3f3f3f3f;

const int MOD = 1e9 + 7;

const int nn = 1e5 + 15;

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

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



int n, k;

vector<pair<int, pair<int, int>>>v;

ll dp[nn][4];

ll solve(int idx, int last)

{

	if (idx >= n)

		return 0;

	ll &ret = dp[idx][last];

	if (~ret)

		return ret;

	ret = 0;

	if (last != 1)

		ret = max(ret, solve(idx + 1, 1) + v[idx].first);



	if (last != 2)

		ret = max(ret, solve(idx + 1, 2) + v[idx].second.first);



	if (last != 3)

		ret = max(ret, solve(idx + 1, 3) + v[idx].second.second);



	return ret;

}

int main()

{

	fast();

	cin >> n;

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

	{

		int x, y, z;

		cin >> x >> y >> z;

		v.push_back(mk(x, mk(y, z)));

	}

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

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

	return 0;

}

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

using namespace std;

 

#define MOD (1000000007)

#define f first

#define s second

#define pb(x) push_back(x)

#define mp(x,y) make_pair(x,y)

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

#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

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

#define forr(i,a,b) for(int i = (a); i > (b); i--)

#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

typedef long long int ll;

#define ld long double

const int N = 2e5+30;

//https://codeforces.com/problemset/page/2?tags=1700-1700

 

 

void solve(){

   int n;

   cin>>n;

   int hap[n+3][5];

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

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

       cin>>hap[i][j];

     }

   }

   ll dp[n+3][4];

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

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

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

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

         if(k!=j){

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

         }

       }

     }

   }

   cout<<*max_element(dp[n]+1,dp[n]+3)<<'\n';

}

 

 

int main(){

 	ios_base::sync_with_stdio(false);

  cin.tie(NULL);

	int T;

  //cin >> T;

  //cout<<prs.size()<<'\n';

	 T = 1;

  //visited[1]=1;

	while(T--){

		solve();

	}

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

#define ull unsigned long long

#define ll long long

#define pb push_back

#define endl '\n'

#define line cout<<"----------------------"<<endl

#define mp make_pair

#define mod 1000000007

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)

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

#define fileout freopen("output.txt","w",stdout)

using namespace std;

const ll  mx=300009;

struct edge

{

    ll  a,b,c;

};

vector<edge> v;

ll  dp[100009][4];

ll  call(ll  ind, ll  pre)

{

    if(ind==v.size()) return 0;

    ll  &ret=dp[ind][pre];

    if(ret!=-1) return ret;

    ret=0;

    ll  a=0,b=0,c=0;

    auto x=v[ind];

        if(pre==1)

        {

            a=x.b+call(ind+1,2);

            b=x.c+call(ind+1,3);

        }

        else if(pre==2)

        {

            a=x.a+call(ind+1,1);

            b=x.c+call(ind+1,3);

        }

        else if(pre==3)

        {

            a=x.a+call(ind+1,1);

            b=x.b+call(ind+1,2);

        }

        else

        {

            a=x.a+call(ind+1,1);

            b=x.b+call(ind+1,2);

            c=x.c+call(ind+1,3);

        }

    return ret=max(a,max(b,c));

}

int  main()

{

    ll  n ;

    cin>>n;

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

    {

        ll  a,b,c; cin>>a>>b>>c;

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

    }

    memset(dp,-1,sizeof dp);

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







}


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

using namespace std;

 

#define MOD (1000000007)

#define f first

#define s second

#define pb(x) push_back(x)

#define mp(x,y) make_pair(x,y)

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

#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

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

#define forr(i,a,b) for(int i = (a); i > (b); i--)

#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

typedef long long int ll;

#define ld long double

const int N = 2e5+30;

//https://codeforces.com/problemset/page/2?tags=1700-1700

 

 

void solve(){

   int n;

   cin>>n;

   int hap[n+3][5];

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

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

       cin>>hap[i][j];

     }

   }

   ll dp[n+3][4];

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

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

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

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

         if(k!=j){

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

         }

       }

     }

   }

   cout<<*max_element(dp[n]+1,dp[n]+3)<<'\n';

}

 

 

int main(){

 	ios_base::sync_with_stdio(false);

  cin.tie(NULL);

	int T;

  //cin >> T;

  //cout<<prs.size()<<'\n';

	 T = 1;

  //visited[1]=1;

	while(T--){

		solve();

	}

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

#define ll long long

using namespace std;



ll n;

std::vector<ll> ara[100010];

ll dp[100010][4];



ll fnc(ll idx,ll last){

  if(idx == n) return 0;

  if(dp[idx][last] != -1) return dp[idx][last];



  ll res1 = - (1<<25);

  ll res2 = - (1<<25);

  ll res3 = - (1<<25);



  if(last == 0){

    res1 = max(res1,ara[idx][0] + fnc(idx+1,1));

    res2 = max(res2,ara[idx][1] + fnc(idx+1,2));

    res3 = max(res3,ara[idx][2] + fnc(idx+1,3));

  }else if(last == 1){

    res2 = max(res2,ara[idx][1] + fnc(idx+1,2));

    res3 = max(res3,ara[idx][2] + fnc(idx+1,3));

  }else if(last == 2){

    res1 = max(res1,ara[idx][0] + fnc(idx+1,1));

    res3 = max(res3,ara[idx][2] + fnc(idx+1,3));

  }else if(last == 3){

    res1 = max(res1,ara[idx][0] + fnc(idx+1,1));

    res2 = max(res2,ara[idx][1] + fnc(idx+1,2));

  }

  dp[idx][last] = max(res1, max(res2,res3));

  return dp[idx][last];

}



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

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

  cin >> n;

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

    int a,b,c;

    cin >> a >> b >> c;

    ara[i].push_back(a);

    ara[i].push_back(b);

    ara[i].push_back(c);

  }



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

  return 0;

}


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

using namespace std;

 

#define MOD (1000000007)

#define f first

#define s second

#define pb(x) push_back(x)

#define mp(x,y) make_pair(x,y)

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

#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

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

#define forr(i,a,b) for(int i = (a); i > (b); i--)

#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

typedef long long int ll;

#define ld long double

const int N = 2e5+30;

//https://codeforces.com/problemset/page/2?tags=1700-1700

 

 

void solve(){

   int n;

   cin>>n;

   int hap[n+3][5];

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

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

       cin>>hap[i][j];

     }

   }

   ll dp[n+3][4];

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

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

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

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

         if(k!=j){

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

         }

       }

     }

   }

   cout<<*max_element(dp[n]+1,dp[n]+3)<<'\n';

}

 

 

int main(){

 	ios_base::sync_with_stdio(false);

  cin.tie(NULL);

	int T;

  //cin >> T;

  //cout<<prs.size()<<'\n';

	 T = 1;

  //visited[1]=1;

	while(T--){

		solve();

	}

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



using namespace std;

typedef long long int lli;



lli n, a[100005], b[100005], c[100005];



lli dp[100005][4];



lli solve(lli i, lli last){

    if(i == n) return dp[i][last] = 0;

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

    lli ans1, ans2, ans3;

    ans1 = ans2 = ans3 = LONG_LONG_MIN;

    if(last != 1) ans1 = a[i] + solve(i+1, 1);

    if(last != 2) ans2 = b[i] + solve(i+1, 2);

    if(last != 3) ans3 = c[i] + solve(i+1, 3);



    return dp[i][last] = max(ans1, max(ans2, ans3));

}





int main(){

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

    int T=1, cs=1;

    //scanf("%d", &T);

    while(T--){

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

        scanf("%lld", &n);

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

            scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);

        }

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



    }



    return 0;

}

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

using namespace std;

 

#define MOD (1000000007)

#define f first

#define s second

#define pb(x) push_back(x)

#define mp(x,y) make_pair(x,y)

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

#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

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

#define forr(i,a,b) for(int i = (a); i > (b); i--)

#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

typedef long long int ll;

#define ld long double

const int N = 2e5+30;

//https://codeforces.com/problemset/page/2?tags=1700-1700

 

 

void solve(){

   int n;

   cin>>n;

   int hap[n+3][5];

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

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

       cin>>hap[i][j];

     }

   }

   ll dp[n+3][4];

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

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

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

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

         if(k!=j){

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

         }

       }

     }

   }

   cout<<*max_element(dp[n]+1,dp[n]+3)<<'\n';

}

 

 

int main(){

 	ios_base::sync_with_stdio(false);

  cin.tie(NULL);

	int T;

  //cin >> T;

  //cout<<prs.size()<<'\n';

	 T = 1;

  //visited[1]=1;

	while(T--){

		solve();

	}

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

#include <cstring>

#include <stdio.h>

using namespace std;

const int N=1e+5;

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

int memo[N][4];

int dp(int i,int t)

{

    if(i==n)

        return 0;

    int &ret=memo[i][t];

    if(~ret)

        return ret;

    ret=0;

    if(t!=0)

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

    if(t!=1)

        ret=max(ret,dp(i+1,1)+b[i]);

    if(t!=2)

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

    return ret;





}

int main()

{

    memset(memo,-1,sizeof memo);

    scanf("%d",&n);

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

    {

         scanf("%d %d %d",a+i,b+i,c+i);

    }

    printf("%d\n",dp(0,3));

    return 0;

}


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

using namespace std;

 

#define MOD (1000000007)

#define f first

#define s second

#define pb(x) push_back(x)

#define mp(x,y) make_pair(x,y)

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

#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

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

#define forr(i,a,b) for(int i = (a); i > (b); i--)

#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

typedef long long int ll;

#define ld long double

const int N = 2e5+30;

//https://codeforces.com/problemset/page/2?tags=1700-1700

 

 

void solve(){

   int n;

   cin>>n;

   int hap[n+3][5];

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

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

       cin>>hap[i][j];

     }

   }

   ll dp[n+3][4];

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

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

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

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

         if(k!=j){

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

         }

       }

     }

   }

   cout<<*max_element(dp[n]+1,dp[n]+3)<<'\n';

}

 

 

int main(){

 	ios_base::sync_with_stdio(false);

  cin.tie(NULL);

	int T;

  //cin >> T;

  //cout<<prs.size()<<'\n';

	 T = 1;

  //visited[1]=1;

	while(T--){

		solve();

	}

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

using namespace std;



#define clr(arr,val) memset(arr,val ,sizeof arr)

//#define first f

//#define second s



typedef  long long ull;

typedef long long ll;

ll const oo=1e18 ;



int const SZ= (int)1e5+5;

//const ll mod=(ll)1e9+7;

    

//int dp[SZ][SZ];

int arr[SZ][4];

int dp[SZ][4];

int n;

int solve(int r ,int prev ){



    if(r>=n){

        return 0;

    }

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

    if(prev!=-1 && ret !=-1){

        return ret;

    }

    int mx=0;

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

        if(i==prev) continue;

        mx=max(mx,arr[r][i]+solve(r+1,i));

    }

    return ret=mx;

}



int main() {

//#ifdef CLION

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

//    freopen("out.txt", "w", stdin);

//#endif

    

    cin>>n;

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

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

    }

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

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

    return 0;

}

 

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

using namespace std;

 

#define MOD (1000000007)

#define f first

#define s second

#define pb(x) push_back(x)

#define mp(x,y) make_pair(x,y)

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

#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

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

#define forr(i,a,b) for(int i = (a); i > (b); i--)

#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

typedef long long int ll;

#define ld long double

const int N = 2e5+30;

//https://codeforces.com/problemset/page/2?tags=1700-1700

 

 

void solve(){

   int n;

   cin>>n;

   int hap[n+3][5];

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

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

       cin>>hap[i][j];

     }

   }

   ll dp[n+3][4];

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

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

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

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

         if(k!=j){

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

         }

       }

     }

   }

   cout<<*max_element(dp[n]+1,dp[n]+3)<<'\n';

}

 

 

int main(){

 	ios_base::sync_with_stdio(false);

  cin.tie(NULL);

	int T;

  //cin >> T;

  //cout<<prs.size()<<'\n';

	 T = 1;

  //visited[1]=1;

	while(T--){

		solve();

	}

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

using namespace std;

int main(){

    int n;

    cin>>n;

    long long dp[100005][3];

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

    dp[0][0]=0;

    dp[0][1]=0;

    dp[0][2]=0;

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

        long long a,b,c;

        cin>>a>>b>>c;

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

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

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

    }

    long long ans=max(dp[n][0], max(dp[n][1], dp[n][2]));

    cout<<ans<<'\n';

}


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

using namespace std;

 

#define MOD (1000000007)

#define f first

#define s second

#define pb(x) push_back(x)

#define mp(x,y) make_pair(x,y)

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

#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

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

#define forr(i,a,b) for(int i = (a); i > (b); i--)

#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

typedef long long int ll;

#define ld long double

const int N = 2e5+30;

//https://codeforces.com/problemset/page/2?tags=1700-1700

 

 

void solve(){

   int n;

   cin>>n;

   int hap[n+3][5];

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

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

       cin>>hap[i][j];

     }

   }

   ll dp[n+3][4];

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

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

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

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

         if(k!=j){

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

         }

       }

     }

   }

   cout<<*max_element(dp[n]+1,dp[n]+3)<<'\n';

}

 

 

int main(){

 	ios_base::sync_with_stdio(false);

  cin.tie(NULL);

	int T;

  //cin >> T;

  //cout<<prs.size()<<'\n';

	 T = 1;

  //visited[1]=1;

	while(T--){

		solve();

	}

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



using namespace std;



typedef long long ll;

const double eps=1e-6,pi=acos(-1);

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

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

int mem[N][5];



int solve(int i=0,int bk=0){

    if(i==n) return 0;

    int &ret=mem[i][bk];

    if(~ret) return ret;

    if(bk!=1)

        ret=max(ret,solve(i+1,1)+a[i]);

    if(bk!=2)

        ret=max(ret,solve(i+1,2)+b[i]);

    if(bk!=3)

        ret=max(ret,solve(i+1,3)+c[i]);

    return ret;

}



int main(){

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

    scanf("%d",&n);

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

        scanf("%d%d%d",a+i,b+i,c+i);

    memset(mem,-1,sizeof mem);

    printf("%d",solve());

    return 0;

}


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

using namespace std;

 

#define MOD (1000000007)

#define f first

#define s second

#define pb(x) push_back(x)

#define mp(x,y) make_pair(x,y)

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

#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

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

#define forr(i,a,b) for(int i = (a); i > (b); i--)

#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

typedef long long int ll;

#define ld long double

const int N = 2e5+30;

//https://codeforces.com/problemset/page/2?tags=1700-1700

 

 

void solve(){

   int n;

   cin>>n;

   int hap[n+3][5];

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

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

       cin>>hap[i][j];

     }

   }

   ll dp[n+3][4];

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

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

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

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

         if(k!=j){

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

         }

       }

     }

   }

   cout<<*max_element(dp[n]+1,dp[n]+3)<<'\n';

}

 

 

int main(){

 	ios_base::sync_with_stdio(false);

  cin.tie(NULL);

	int T;

  //cin >> T;

  //cout<<prs.size()<<'\n';

	 T = 1;

  //visited[1]=1;

	while(T--){

		solve();

	}

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

#define lld         long long int

#define llf         long double

#define pb          push_back

#define mp          make_pair

#define IN          insert

#define loopN(n)    for(lld i=0;i<n;i++)

#define loop(p,n)   for(lld i=p;i<=n;i++)

#define rloop(p,n)  for(lld i=n;i>=p;i--)

#define loop2(p,n)  for(lld j=p;j<=n;j++)

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

#define F1          first

#define F2          second

#define INF         2e18

#define FILE        freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define PI          2*acos(0.0)

#define ISO         ios::sync_with_stdio(false);cin.tie(0)

#define mem(a,b)    memset(a,b,sizeof(a))

#define case(z)     cout<<"Case "<<z<<": ";

using namespace std;

const lld mod=1e9+7;



lld on(lld m,lld p){return m | (1<<p);}

bool ison(lld m,lld p){return (bool)(m & (1<<p));}

lld flip(lld m,lld p){return m ^ (1<<p);}

lld allon(lld p){return (1<<p)-1;}

//______________________________________________________________________________________



lld n;

lld dp[100005][3];

lld a[100005][3];



lld fun(lld p, lld k)

{

    if(p>=n)return 0;

    if(dp[p][k]!=-1)

    {

        return dp[p][k];

    }

    lld ans=-INF;

    if(p==0)

    {

        loopN(3)

        {

            ans=max(ans,a[p][i]+fun(p+1,i));

        }

        return ans;

    }

    else

    {

        loopN(3)

        {

            if(i!=k)

            {

                ans=max(ans,a[p][i]+fun(p+1,i));

            }



        }



    }

    return dp[p][k]=ans;







}





int main()

{

    ISO;



    //lld t;cin>>t;while(t--)

    mem(dp,-1);

    cin>>n;

    loopN(n)loop2(0,2)cin>>a[i][j];

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





    return 0;

}






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

using namespace std;

 

#define MOD (1000000007)

#define f first

#define s second

#define pb(x) push_back(x)

#define mp(x,y) make_pair(x,y)

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

#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

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

#define forr(i,a,b) for(int i = (a); i > (b); i--)

#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

typedef long long int ll;

#define ld long double

const int N = 2e5+30;

//https://codeforces.com/problemset/page/2?tags=1700-1700

 

 

void solve(){

   int n;

   cin>>n;

   int hap[n+3][5];

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

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

       cin>>hap[i][j];

     }

   }

   ll dp[n+3][4];

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

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

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

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

         if(k!=j){

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

         }

       }

     }

   }

   cout<<*max_element(dp[n]+1,dp[n]+3)<<'\n';

}

 

 

int main(){

 	ios_base::sync_with_stdio(false);

  cin.tie(NULL);

	int T;

  //cin >> T;

  //cout<<prs.size()<<'\n';

	 T = 1;

  //visited[1]=1;

	while(T--){

		solve();

	}

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



using namespace std;

int main(){

	int N;

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

	scanf("%d", &N);

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

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

	}

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

		int aa = a[i-1];

		int bb = b[i-1];

		int cc = c[i-1];

		a[i] = a[i] + max(bb, cc);

		b[i] = b[i] + max(aa, cc);

		c[i] = c[i] + max(bb, aa);

	}

	cout << max(a[N], max(b[N], c[N])) << endl;



}