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

using namespace std;



typedef long double LD;

typedef long long ll;

typedef map<int,int> mii;

typedef pair<int,int> pii;

typedef vector<pii> vpii;



#define pb              push_back

#define mp              make_pair

#define F               first

#define S               second

#define mod             1000000007

#define INF             2147483647

#define Endl            "\n"

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

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

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

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

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

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



const int MAXN = 1000005;

const int SQRTN = 1003;

const int LOGN = 22;

const double PI=acos(-1);

const int sz=1e5+9;



int strtoint(string str){

    stringstream ss(str);

    int x = 0;

    ss >> x ;

    return x ;

}

string intostr(int x){

    stringstream ss;

    ss << x;

    string str = ss.str();

    return str;

}

void rem(string &s, const string &c) {

	auto pos = s.find(c);

	if (pos == string::npos) {

		cout << -1 << endl;

		exit(0);

	}

	s.erase(0, pos + 1);

}

void println (int n){

    cout<<n<<"\n";

}

void printvec(vector <int> &a){

    for (int i=0;i<a.size();i++){

        cout<<a[i]<<" ";

    }

    cout<<"\n";

}



void printgraph(vector <int> g[],int e){

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

        cout<<i<<" --> ";

        for (int j=0;j<g[i].size();j++){

            cout<<g[i][j]<<" ";

        }

        cout<<"\n";

    }

}



void printmap (map <int,int> &mymap){

    for (auto itr = mymap.begin(); itr != mymap.end(); ++itr) {

        cout << '\t' << itr->first

             << '\t' << itr->second << '\n';

    }

    cout << "\n";

}



int a[100005][4], dp[100005][4];

int N;



int rec(int pos, int type){



    if(pos>N) return 0;



    if(dp[pos][type]!=-1) return dp[pos][type];



    int ret = -1;

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

        if(i!=type)

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



    return dp[pos][type] = ret;

}





void solve(){

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

    int i,j;

    cin>>N;

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

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

            cin>>a[i][j];





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



    //printvec(v);

}





int main(){

    //FasterIO;



    solve();

    return 0;

}

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

typedef long long ll;

using namespace std;

ll dpa[100005],dpb[100005],dpc[100005];



int main()

{

  ll n;

  cin>>n;

  ll a[n],b[n],c[n];

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

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

  }

  dpa[n-1]=a[n-1];

  dpb[n-1]=b[n-1];

  dpc[n-1]=c[n-1];

  for(int i=n-2;i>=0;i-- ){

   dpa[i]=a[i]+max(dpb[i+1],dpc[i+1]);

   dpb[i]=b[i]+max(dpa[i+1],dpc[i+1]);

   dpc[i]=c[i]+max(dpb[i+1],dpa[i+1]);

  }

  cout<<max(dpa[0],max(dpb[0],dpc[0]));

    return 0;

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

#define inf INFINITY

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

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

#define _3102_ main()

#define endl '\n'

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

using namespace std;

const int N = 1e5 + 100;

const ll MX = 1e9;

const ll mod = 1e9 + 7;

const double eps = 1e-9 ;



ll n, a[N] , b[N] , c[N], dp[N][3] ;



ll solve( int i , int j ){

	if ( i < 0 ) return 0 ;

	ll &ret = dp[i][j] ;

	if ( ret != -1) return ret ;

	if ( j == 0 ){

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

	}

	else if ( j == 1 ){

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

	}

	return ret = c[i] + max ( solve(i-1 , 1), solve(i-1,0) ) ;

}



int _3102_{

	Gamed

	cin >> n ;

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

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

	}

	memset ( dp , -1 , sizeof dp);

	dp[0][0] = a[0] , dp[0][1] = b[0] , dp[0][2] = c[0] ;

	cout << max ( solve ( n - 1 , 1) , max ( solve ( n -1 , 0 ) , solve ( n - 1 , 2 ))) << endl ;

	return 0;

}


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

typedef long long ll;

using namespace std;

ll dpa[100005],dpb[100005],dpc[100005];



int main()

{

  ll n;

  cin>>n;

  ll a[n],b[n],c[n];

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

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

  }

  dpa[n-1]=a[n-1];

  dpb[n-1]=b[n-1];

  dpc[n-1]=c[n-1];

  for(int i=n-2;i>=0;i-- ){

   dpa[i]=a[i]+max(dpb[i+1],dpc[i+1]);

   dpb[i]=b[i]+max(dpa[i+1],dpc[i+1]);

   dpc[i]=c[i]+max(dpb[i+1],dpa[i+1]);

  }

  cout<<max(dpa[0],max(dpb[0],dpc[0]));

    return 0;

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

using namespace std;

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

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

typedef long long ll;

typedef unsigned long long ull;

#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++)

#define forn(i, n) forr(i, 0, n)

#define pb push_back

#define mp make_pair

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

#define DBG(x) cerr << #x << " = " << (x) << endl

#define MOD 1000000007

#define MAXN 100005

ll dp[MAXN][3];

void solve(vector< vector<ll> > &a, int n)

{

    forn(i,MAXN)

    {

        forn(j,3)

        {

            dp[i][j]=(pow(10,9)+5)*(ll)(-1);

        }

    }

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

    forr(i,1,n)

    {

        forn(j,3)

        {

            forn(k,3)

            {

                if(j==k)

                {

                    continue;

                }

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

            }

        }

 

    }

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

}

 

int main() {

    FIN;

    int n;

    cin >> n;

    vector< vector<ll> > arreglo(n);

    forn(i,n) arreglo[i].resize(3);

    forn(i,n)

    {

        forn(j,3) cin >> arreglo[i][j];

    }

    solve(arreglo, n);

    return 0;

}

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

typedef long long ll;

using namespace std;

ll dpa[100005],dpb[100005],dpc[100005];



int main()

{

  ll n;

  cin>>n;

  ll a[n],b[n],c[n];

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

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

  }

  dpa[n-1]=a[n-1];

  dpb[n-1]=b[n-1];

  dpc[n-1]=c[n-1];

  for(int i=n-2;i>=0;i-- ){

   dpa[i]=a[i]+max(dpb[i+1],dpc[i+1]);

   dpb[i]=b[i]+max(dpa[i+1],dpc[i+1]);

   dpc[i]=c[i]+max(dpb[i+1],dpa[i+1]);

  }

  cout<<max(dpa[0],max(dpb[0],dpc[0]));

    return 0;

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

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

#define ll long long

using namespace std;

const int N = 100010;

int dp[N][3];

int main(){

    fast;

	int n, i, a, b, c;

	cin >> n;

	memset(dp, 0, sizeof dp);

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

		cin >> a >> b >> c;

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

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

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

	}

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

	return 0;

}


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

typedef long long ll;

using namespace std;

ll dpa[100005],dpb[100005],dpc[100005];



int main()

{

  ll n;

  cin>>n;

  ll a[n],b[n],c[n];

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

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

  }

  dpa[n-1]=a[n-1];

  dpb[n-1]=b[n-1];

  dpc[n-1]=c[n-1];

  for(int i=n-2;i>=0;i-- ){

   dpa[i]=a[i]+max(dpb[i+1],dpc[i+1]);

   dpb[i]=b[i]+max(dpa[i+1],dpc[i+1]);

   dpc[i]=c[i]+max(dpb[i+1],dpa[i+1]);

  }

  cout<<max(dpa[0],max(dpb[0],dpc[0]));

    return 0;

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

using namespace std;

#define tpl  tuple<int, int, int>

#define mt   make_tuple

#define LIM  100000





int n, dp[LIM+5][4], vis[LIM+5][4];

vector<tpl> v;



int f(int pos, int k){

    if(pos >= n) return 0;

    if(vis[pos][k]) return dp[pos][k];

    vis[pos][k] = 1;

    int ans;

    if(k == 0) ans = get<0>(v[pos]) + max(f(pos+1, 1), f(pos+1, 2));

    else if(k == 1) ans = get<1>(v[pos]) + max(f(pos+1, 0), f(pos+1, 2));

    else ans = get<2>(v[pos]) + max(f(pos+1, 0), f(pos+1, 1));



    return dp[pos][k] = ans;

}



int main(){

    scanf("%d", &n);

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

        int a, b, c; scanf("%d %d %d", &a, &b, &c);

        v.push_back(mt(a, b, c));

    }

    int ans = f(0, 0);

    memset(dp, 0, sizeof dp);

    memset(vis, 0, sizeof vis);

    ans = max(ans, f(0, 1));

    memset(dp, 0, sizeof dp);

    memset(vis, 0, sizeof vis);

    ans = max(ans, f(0, 2));



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

}


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

typedef long long ll;

using namespace std;

ll dpa[100005],dpb[100005],dpc[100005];



int main()

{

  ll n;

  cin>>n;

  ll a[n],b[n],c[n];

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

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

  }

  dpa[n-1]=a[n-1];

  dpb[n-1]=b[n-1];

  dpc[n-1]=c[n-1];

  for(int i=n-2;i>=0;i-- ){

   dpa[i]=a[i]+max(dpb[i+1],dpc[i+1]);

   dpb[i]=b[i]+max(dpa[i+1],dpc[i+1]);

   dpc[i]=c[i]+max(dpb[i+1],dpa[i+1]);

  }

  cout<<max(dpa[0],max(dpb[0],dpc[0]));

    return 0;

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

#define ll long long

#define endl "\n"

#define shalaby ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);cerr.tie(0);

#define mod 100000000

using namespace std;



inline int D()

{

    int t;

    scanf("%d",&t);

    return t;

}

inline ll llD()

{

    ll t;

    scanf("%lld",&t);

    return t;

}

const int Max=1e5+8;

const int OO=-1e6;

int xt[4]= {1,0,0,-1};

int yt[4]= {0,1,-1,0};

////////////////////////////////////////////////////////////////////////////////////



ll mem[100005][5],a[100005],b[100005],c[100005],n,m;

bool valid(int x,int y)

{

    return x>-1 && y>-1 && x<n && y<m;

}

void init()

{

    memset(mem,-1,sizeof mem);

}

/////////////////////////////////////////////////////////////////////

ll solve(int i=0, int k=3)

{

    if(i==n)

        return 0;

    ll &ret=mem[i][k];

    if(~ret)return ret;

    ret =0;

    if(k!=0)

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



    if(k!=1)

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

    if(k!=2)

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

    return ret;

}



int main()

{

    init();

    int T=1;

///   T=D();

    while(T-->0)

    {

        cin >> n ;

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

        {

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

        }

        cout << solve();

    }

}


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

typedef long long ll;

using namespace std;

ll dpa[100005],dpb[100005],dpc[100005];



int main()

{

  ll n;

  cin>>n;

  ll a[n],b[n],c[n];

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

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

  }

  dpa[n-1]=a[n-1];

  dpb[n-1]=b[n-1];

  dpc[n-1]=c[n-1];

  for(int i=n-2;i>=0;i-- ){

   dpa[i]=a[i]+max(dpb[i+1],dpc[i+1]);

   dpb[i]=b[i]+max(dpa[i+1],dpc[i+1]);

   dpc[i]=c[i]+max(dpb[i+1],dpa[i+1]);

  }

  cout<<max(dpa[0],max(dpb[0],dpc[0]));

    return 0;

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



#define pb push_back

#define mp make_pair



using namespace std;



typedef vector<int> vi;

typedef pair<int, int> ii;

typedef vector<ii> vii;

typedef unsigned long long ull;

typedef long long ll;





int DP[100005][3];

int V[100005][3];

bool ok[100005][3];

int N;



int dp(int i, int m) {

    if (ok[i][m]) {

        return DP[i][m];

    }

    

    if (i == N+1) {

        return 0;

    } else {

        int res = 0;

        if (m == 0) {

            res = max(dp(i+1, 1) + V[i][1], dp(i+1, 2) + V[i][2]);

        } else if (m == 1) {

            res = max(dp(i+1, 0) + V[i][0], dp(i+1, 2) + V[i][2]);

        } else {

            res = max(dp(i+1, 0) + V[i][0], dp(i+1, 1) + V[i][1]);

        }

        

        ok[i][m] = true;

        DP[i][m] = res;

        return DP[i][m];

    }

}



int main() {

    std::ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

    

    cin >> N;

    

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

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

    }

    

    int res = 0;

    res = dp(1, 1);

    memset(DP, 0, sizeof(DP));

    memset(ok, 0, sizeof(ok));

    res = max(res, dp(1, 2));

    memset(DP, 0, sizeof(DP));

    memset(ok, 0, sizeof(ok));

    res = max(res, dp(1, 3));

    

    cout << res << endl;

    

	return 0;

}

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

typedef long long ll;

using namespace std;

ll dpa[100005],dpb[100005],dpc[100005];



int main()

{

  ll n;

  cin>>n;

  ll a[n],b[n],c[n];

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

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

  }

  dpa[n-1]=a[n-1];

  dpb[n-1]=b[n-1];

  dpc[n-1]=c[n-1];

  for(int i=n-2;i>=0;i-- ){

   dpa[i]=a[i]+max(dpb[i+1],dpc[i+1]);

   dpb[i]=b[i]+max(dpa[i+1],dpc[i+1]);

   dpc[i]=c[i]+max(dpb[i+1],dpa[i+1]);

  }

  cout<<max(dpa[0],max(dpb[0],dpc[0]));

    return 0;

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

#include <queue>

#include <set>

#include <list>

#include <deque>

#include <vector>

#include <map>

#include <utility>

#include <algorithm>

#include <cmath>

#include <cstdio>

#include <string>

#include <iterator>

#define ll long long

#define pb push_back

#define pf push_front

#define ppb pop_back

#define ppf pop_front

#define powr(x,n,p) for(int axy=0 ; axy<p ; axy++){x=x*n;}

#define YES printf("YES\n")

#define Yes printf("Yes\n")

#define yes printf("yes\n")

#define NO printf("NO\n")

#define No printf("No\n")

#define no printf("no\n")

#define nl printf("\n")

#define fr0(n,q) for(q=0 ; q<n ; q++)

#define fr1(n,q) for(q=1 ; q<=n ; q++)

#define mp make_pair

#define scl(x) scanf("%lld",&x)

#define sci(x) scanf("%d",&x)

#define lst(x) x[x.size()-1]

#define llst(x) x[x.size()-2]

#define md 1000000007

#define check(x,y) (x&(1<<y))

#define set(x,y) x=x|(1<<y)

using namespace std;

int n;

int arr[100005][3],dp[100005][3];

int solve(int i, int j){

    if(i>n) return 0;

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

    int ret;

    if(j==0) ret=max(arr[i][j]+solve(i+1,1),arr[i][j]+solve(i+1,2));

    else if(j==1) ret=max(arr[i][j]+solve(i+1,0),arr[i][j]+solve(i+1,2));

    else ret=max(arr[i][j]+solve(i+1,0),arr[i][j]+solve(i+1,1));

    return dp[i][j]=ret;

}

int main()

{

        sci(n);

        int i,j;

        fr0(100005,i){

            fr0(3,j) dp[i][j]=-1;

        }

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

            for(j=0 ; j<3 ; j++) sci(arr[i][j]);

        }

        int ans=max(solve(1,0),solve(1,1));

        ans=max(ans,solve(1,2));

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

    return 0;

}

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

typedef long long ll;

using namespace std;

ll dpa[100005],dpb[100005],dpc[100005];



int main()

{

  ll n;

  cin>>n;

  ll a[n],b[n],c[n];

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

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

  }

  dpa[n-1]=a[n-1];

  dpb[n-1]=b[n-1];

  dpc[n-1]=c[n-1];

  for(int i=n-2;i>=0;i-- ){

   dpa[i]=a[i]+max(dpb[i+1],dpc[i+1]);

   dpb[i]=b[i]+max(dpa[i+1],dpc[i+1]);

   dpc[i]=c[i]+max(dpb[i+1],dpa[i+1]);

  }

  cout<<max(dpa[0],max(dpb[0],dpc[0]));

    return 0;

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

using namespace std;

int a[100001][3];

int dp[100001][3];

int n;



int func(int ind, int flag) {



	if (ind == n) return 0;



	if (dp[ind][flag] != -1) return dp[ind][flag];



	int maxi = 0;

	if (flag == 0) {

		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));

		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));

		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));

	}

	else if (flag == 1) {

		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));

		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));

	}

	else if (flag == 2) {

		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));

		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));

	}

	else {

		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));

		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));

	}



	return dp[ind][flag] = maxi;

}



int main() {



	cin >> n;

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

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

			cin >> a[i][j];

		}

	}



	memset(dp, -1, sizeof dp);



	cout << func(0, 0);



	return 0;

}


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

typedef long long ll;

using namespace std;

ll dpa[100005],dpb[100005],dpc[100005];



int main()

{

  ll n;

  cin>>n;

  ll a[n],b[n],c[n];

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

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

  }

  dpa[n-1]=a[n-1];

  dpb[n-1]=b[n-1];

  dpc[n-1]=c[n-1];

  for(int i=n-2;i>=0;i-- ){

   dpa[i]=a[i]+max(dpb[i+1],dpc[i+1]);

   dpb[i]=b[i]+max(dpa[i+1],dpc[i+1]);

   dpc[i]=c[i]+max(dpb[i+1],dpa[i+1]);

  }

  cout<<max(dpa[0],max(dpb[0],dpc[0]));

    return 0;

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

using namespace std;



long long w1,w2,hap=0,maxi,aa,bb,cc,N,i,j,k,a[100005][5];

long long M[100005][5];





int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin>>N;

    for(i=0; i<100003; i++)

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

            M[i][j]=0;



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

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

    M[N-1][0]=a[N-1][0];

    M[N-1][1]=a[N-1][1];

    M[N-1][2]=a[N-1][2];



    for(i=N-2; i>=0; i--)

    {

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

        {

            if(j==0)

            {

                w1=1;

                w2=2;

            }

            else if(j==1)

            {

                w1=0;

                w2=2;

            }

            else

            {

                w1=0;

                w2=1;

            }

        M[i][j]=a[i][j]+max(M[i+1][w1],M[i+1][w2]);

        }

    }

    aa=max(M[0][0],M[0][1]);

    aa=max(aa,M[0][2]);

    cout<<aa<<endl;

    return 0;

}






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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

#define loop(i, n)      for(int i = 0 ; i < n ; ++i)

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

#define loopOne(i, n)   for(int i = 1 ; i <= n; ++i)

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



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



int Solve(int idx, int prev){

    // 0 for a, 1 for b, 2 for c

    if(idx == n)    return 0;

    if(memo[idx][prev] != -1)   return memo[idx][prev];



    int res = -OO;

    if(prev == 0){  // The previous one was 'A'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), c[idx] + Solve(idx+1, 2));

    }else if(prev == 1){  // The previous one was 'b'

        memo[idx][prev] = max(a[idx] + Solve(idx+1, 0), c[idx] + Solve(idx+1, 2));

    }else if(prev == 2){  // The previous one was 'c'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), a[idx] + Solve(idx+1, 0));

    }else{

        memo[idx][prev] = max(max(a[idx] + Solve(idx+1, 0), b[idx] + Solve(idx+1, 1)), c[idx] + Solve(idx+1, 2));

    }

    return memo[idx][prev];

}

int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0, 3));

    return 0;

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

using namespace std;

#define INF 100005

#define maxx 1000000000000



int n;

long long a[INF][3];

long long mem[INF][3];



long long rec(int level,int pre)

{

    if(level==n) return 0;

    if(mem[level][pre]!=-1) return mem[level][pre];

    long long now=0;

    if(pre==0)

    {

        now=max(now,max(a[level][0]+rec(level+1,1),a[level][0]+rec(level+1,2)));

    }else

    if(pre==1)

    {

        now=max(now,max(a[level][1]+rec(level+1,0),a[level][1]+rec(level+1,2)));

    }else

    if(pre==2)

    {

        now=max(now,max(a[level][2]+rec(level+1,0),a[level][2]+rec(level+1,1)));

    }

    return mem[level][pre]=now;

}



int main()

{

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

    scanf("%d",&n);

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

    {

        scanf("%lld%lld%lld",&a[i][0],&a[i][1],&a[i][2]);

    }

    long long ans=max(rec(0,0),max(rec(0,1),rec(0,2)));

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

}


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

using namespace std;



#define ll long long

#define mp make_pair

#define pb push_back

#define loop(i, n)      for(int i = 0 ; i < n ; ++i)

#define rloop(i, n)     for(int i = int(n)-1 ; i >= 0 ; --i)

#define loopOne(i, n)   for(int i = 1 ; i <= n; ++i)

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

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



void GO(){

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}

const ll N = 1e5+100, OO = 1e9;

int mx = -OO, mn = OO;

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

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



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



int Solve(int idx, int prev){

    // 0 for a, 1 for b, 2 for c

    if(idx == n)    return 0;

    if(memo[idx][prev] != -1)   return memo[idx][prev];



    int res = -OO;

    if(prev == 0){  // The previous one was 'A'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), c[idx] + Solve(idx+1, 2));

    }else if(prev == 1){  // The previous one was 'b'

        memo[idx][prev] = max(a[idx] + Solve(idx+1, 0), c[idx] + Solve(idx+1, 2));

    }else if(prev == 2){  // The previous one was 'c'

        memo[idx][prev] = max(b[idx] + Solve(idx+1, 1), a[idx] + Solve(idx+1, 0));

    }else{

        memo[idx][prev] = max(max(a[idx] + Solve(idx+1, 0), b[idx] + Solve(idx+1, 1)), c[idx] + Solve(idx+1, 2));

    }

    return memo[idx][prev];

}

int main() {

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

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

    GO();

    scanf("%d", &n);

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

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

    }

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

    printf("%d", Solve(0, 3));

    return 0;

}