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

using namespace std;

#define ll long long



const ll INF= 1LL << 60;



//入力

ll N;

ll K;

ll a[100010][3];

//dp

ll dp[100010][3];





void chmin(ll& a, ll b){

  if(a>b){

    a=b;

  }

}





void chmax(ll& a, ll b){

  if(a<b){

    a=b;

  }

}



int main(){

  cin >> N;

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

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

      cin>>a[i][j]; 

    }

  }



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

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

          dp[i][j]=0;

    } 

  }

  

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

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

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

        if(j==k) continue;

      	chmax(dp[i+1][k],dp[i][j]+a[i][k]);

      }

    }

  }

  

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

    chmax(dp[N][0],dp[N][i]);

  }

  cout << dp[N][0] << endl;

}

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



using namespace std;



#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)

#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)

#define REP(i,n) rep(i,0,n)

#define REP2(i,n) rep2(i,0,n)

#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)

#define ll long long

#define ull unsigned long long

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

#define en '\n'

template <class T> using vec = vector<T>;

template <class T> using vvec = vector<vec<T>>;

typedef pair<ll, ll> P;

constexpr long long INF = 1LL << 60;

constexpr int INF_INT = 1 << 25;

constexpr long long MOD = (ll) 1e9 + 7;

typedef vector<ll> Array;

typedef vector<Array> Matrix;

constexpr int loose = 0;

constexpr int tight = 1;





template<class T> inline bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}

template<class T> inline bool chmax(T& a, T b) {

    if (a < b) {

        a = b;

        return true;

    }

    return false;

}



struct Edge {

	ll to, cap, rev;

	Edge(ll _to, ll _cap, ll _rev) {

	to = _to; cap = _cap; rev = _rev;

	}

};

typedef vector<Edge> Edges;

typedef vector<Edges> Graph;



void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {

	G[from].push_back(Edge(to, cap, (ll)G[to].size()));

	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));

}



void solve(){

	ll n;

	cin>>n;

	Matrix a(n,Array(3));

	REP(i,n) cin>>a[i][0]>>a[i][1]>>a[i][2];



	Matrix dp(n+1,Array(3,0));//iこまでみて、最後にjした

	REP(i,n){

		REP(j,3){

			REP(k,3){

				if(j==k) continue;

				chmax(dp[i+1][k],dp[i][j]+a[i][k]);

			}

		}		

	}

	ll ans=0;

	REP(i,3) chmax(ans,dp[n][i]);

	cout<< ans<<en;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    solve();

    return 0;

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

    // typedef __int128 int128;

    // typedef __float128 float128;

     

    using namespace std;

    using namespace rel_ops;

    typedef long long ll;

    typedef long double ld;

    typedef complex<ld> pt;

    typedef vector<pt> pol;

    typedef vector<ll> vi;

    typedef vector<vi> vvi;

    typedef vector<vvi> vvvi;

    typedef vector<ld> vd;

    typedef vector<vd> vvd;

    typedef pair<ll, ll> pii;

    typedef vector<pii> vpii;

    #define pb push_back

     

     

    int main(){

     

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

     

      ll N;

      cin >> N;

     

     

      ll abc[100010][4];

     

      ll f[100010][4];

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

        cin >> abc[i][1] >> abc[i][2] >> abc[i][3];

        if(i == 1) f[i][1] = abc[i][1], f[i][2] = abc[i][2], f[i][3] = abc[i][3];

        else f[i][1] = max(abc[i][1] + f[i-1][2], abc[i][1] + f[i-1][3]),

               f[i][2] = max(abc[i][2] + f[i-1][1], abc[i][2] + f[i-1][3]),

               f[i][3] = max(abc[i][3] + f[i-1][1], abc[i][3] + f[i-1][2]);

      }

     

      cout << max(max(f[N][1], f[N][2]), f[N][3]) << endl;

     

     

    }

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

using namespace std;



#define ll  int

#define intmax INT_MAX

#define pi 3.14159265358979323846

#define ff first 

#define ss second

#define pb push_back

#define watch(x) cerr<<(#x)<<"  "<<x<<"\n";

const int MOD=998244353;

const int MAXN = 3e5+4;

int dp[MAXN][3],a[MAXN][3];



int main(){	

ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int n; cin>>n;

for(int i=1;i<=n;i++) for(int j=0;j<3;j++) cin>>a[i][j];





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

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

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

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

}



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





return 0;

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

#define sf1(n) scanf("%d",&n)

#define sf2(n,q) scanf("%d %d",&n,&q)

#define f first

#define ss second

#define pb push_back

#define lli long long

#define mem(ar,false) memset(ar,false,sizeof(ar))

#define mpr make_pair

#define endl "\n"

#define mod 1000000007

#define inf 9000000000000000000LL

using namespace std;



int ar[200005][5];

int n,k;

int dp[100005][5];

int func(int i,int j)

{



    if(i==n+1)

        return 0;

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

        return dp[i][j];

    int ret = INT_MIN;



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

    {

        if(k==j)

            continue;

       ret = max(ret,ar[i][k]+func(i+1,k));

    }

    return dp[i][j] = ret;

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    mem(dp,-1);

    cin >> n ;

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

        cin >> ar[i][1] >> ar[i][2] >> ar[i][3];



     int ans = func(1,0);

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

    {

        int ret = INT_MAX;

        for(int j=1;j<=k;j++)

        {

            if(i-j>=0)

                ret = min(ret,dp[i-j]+abs(ar[i]-ar[i-j]));

        }

        dp[i] = ret;

    }*/



    cout << ans << endl;

    return 0;



}


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

#define sf1(n) scanf("%d",&n)

#define sf2(n,q) scanf("%d %d",&n,&q)

#define f first

#define ss second

#define pb push_back

#define lli long long

#define mem(ar,false) memset(ar,false,sizeof(ar))

#define mpr make_pair

#define endl "\n"

#define mod 1000000007

#define inf 9000000000000000000LL

using namespace std;



int ar[200005][5];

int n,k;

int dp[100005][5];

int func(int i,int j)

{



    if(i==n+1)

        return 0;

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

        return dp[i][j];

    int ret = INT_MIN;



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

    {

        if(k==j)

            continue;

       ret = max(ret,ar[i][k]+func(i+1,k));

    }

    return dp[i][j] = ret;

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

   // mem(dp,-1);

    cin >> n ;

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

        cin >> ar[i][1] >> ar[i][2] >> ar[i][3];





     //int ans = func(1,0);

     int j=0;

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

    {

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

        dp[i][1] = max(dp[i][1],dp[i-1][3]+ar[i][1]);

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

        dp[i][2] = max(dp[i][2],dp[i-1][3]+ar[i][2]);

        dp[i][3] = max(dp[i][3],dp[i-1][1]+ar[i][3]);

        dp[i][3] = max(dp[i][3],dp[i-1][2]+ar[i][3]);

    }



    cout << max(dp[n][1],max(dp[n][2],dp[n][3])) << endl;

    return 0;



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

using namespace std;

//vector<vector<long long int> > dp(100001,vector<long long int>(4));

long long int dp[100001][4];

long long int n;

long long int gen(int i,int p,vector<vector<long long int> >&arr)

{

    long long int ans=INT_MIN;

    if(i>=n)

        return 0;

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

        return dp[i][p];

    if(p==0)

    {

        ans=max(ans,arr[i][1]+gen(i+1,1,arr));

        ans=max(ans,arr[i][2]+gen(i+1,2,arr));

    }

    else if(p==1)

    {

        ans=max(ans,arr[i][0]+gen(i+1,0,arr));

        ans=max(ans,arr[i][2]+gen(i+1,2,arr));

    }

    else if(p==2)

    {

       ans=max(ans,arr[i][0]+gen(i+1,0,arr));

       ans=max(ans,arr[i][1]+gen(i+1,1,arr));



    }

    else{

        ans=max(ans,arr[i][0]+gen(i+1,0,arr));

        ans=max(ans,arr[i][1]+gen(i+1,1,arr));

        ans=max(ans,arr[i][2]+gen(i+1,2,arr));

    }

    return dp[i][p]=ans;



}

int main()

{

    //int n;

    cin>>n;

    vector<vector<long long int>> arr(n,vector<long long int>(3));

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

    {

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

        {

            cin>>arr[i][j];

        }

    }

    //input part has been done

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



    long long ans=gen(0,3,arr);

    cout<<ans;



}


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

using namespace std;

long long int dp[100001][3];

int main()

{

    int n;

    cin>>n;

    vector<vector<int>>arr(n,vector<int>(3));

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

    {

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

    }

    //input part has been done

    //now initialization for day 1

    dp[1][0]=arr[0][0];

    dp[1][1]=arr[0][1];

    dp[1][2]=arr[0][2];

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

    {

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



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



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

    }

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

    cout<<ans<<endl;

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

#include <vector>

#include <algorithm>

#include <array>

#include <cstring>



using namespace std;



const int INF = 1e9 + 7;



int n;

int happy[100000][3];

long long dp[100000][4];



long long dfs(int now, int before){

    if(now == n) return 0;

    if(~dp[now][before]) return dp[now][before];

    long long res = 0;

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

        if(before == i) continue;

        res = max(res, happy[now][i] + dfs(now + 1, i));

    }

    return dp[now][before] = res;

}



int main(){

    cin >> n;

    memset(dp, -1, sizeof dp);

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

        for(auto&& j : happy[i]){

            cin >> j;

        }

    }

    cout << dfs(0, 3) << "\n";

}

// Faster C++ solution for the same problem (measured speedup: 1.615757301228464x):
#include <iostream>

#include <vector>

#include <algorithm>

#include <array>

#include <cstring>



using namespace std;



const int INF = 1e9 + 7;



int n;

vector<array<int, 3>> happy;

int dp[100000][4];



int dfs(int now, int before){

    if(now == n) return 0;

    if(~dp[now][before]) return dp[now][before];

    int res = 0;

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

        if(before == i) continue;

        res = max(res, happy[now][i] + dfs(now + 1, i));

    }

    return dp[now][before] = res;

}



int main(){

    cin >> n;

    happy.resize(n);

    memset(dp, -1, sizeof dp);

    for(auto&& i : happy){

        for(auto&& j : i){

            cin >> j;

        }

    }

    cout << dfs(0, 3) << "\n";

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



using namespace std;

typedef long long int ll;



#define p(V) for(int iiv=0;iiv<V.size();iiv++) cout<<V[iiv]<<" ";

#define mp make_pair

#define pb push_back

#define graph vector<vector<int> >

#define pf first

#define ps second

#define pq priority_queue

const int N = 2e5;

const int l = 18;

const double pi = acos(-1);

struct d{

    int a , b , c;

    d(){

        a=b=c=0;

    }

};

int dp[N][4];

int n;

vector<d> day;

int calc(int idx,int back){

    if(idx==n) return 0;

    int &dp = ::dp[idx][back];

    if(dp!=-1) return dp;

    if(back!=0) dp=max(dp,day[idx].a+calc(idx+1,0));

    if(back!=1) dp=max(dp,day[idx].b+calc(idx+1,1));

    if(back!=2) dp=max(dp,day[idx].c+calc(idx+1,2));

    return dp;

}

int main(){   

    memset(dp,-1,sizeof dp);

    cin >> n;

    day.resize(n);

    for(int i=0;i<n;i++) cin>>day[i].a>>day[i].b>>day[i].c;

    cout<<calc(0,3);

    return 0;

}


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



using namespace std;

typedef long long int ll;



#define p(V) for(int iiv=0;iiv<V.size();iiv++) cout<<V[iiv]<<" ";

#define mp make_pair

#define pb push_back

#define graph vector<vector<int> >

#define pf first

#define ps second

#define pq priority_queue

const int N = 2e5;

const int l = 18;

const double pi = acos(-1);

struct d{

    int a , b , c;

    d(){

        a=b=c=0;

    }

};

int dp[N][3];

int n;

vector<d> day;

int main(){   

    cin >> n;

    day.resize(n);

    for(int i=0;i<n;i++) cin>>day[i].a>>day[i].b>>day[i].c;

    dp[n-1][0] = day[n-1].a;

    dp[n-1][1] = day[n-1].b;

    dp[n-1][2] = day[n-1].c;

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

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

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

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

    }

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

    return 0;

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

using namespace         std;

#define                 int long long

#define                 pb push_back

#define                 mp make_pair

#define st(arr,a)       memset(arr,a,sizeof arr)

#define                 nl cout<<endl

#define                 real signed

#define                 endl '\n'              

#define bitcount(x)     __builtin_popcountll(x)

const int MOD = 1000000007ll;

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

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



int tot = 100500;

int n,dp[100500][3],arr[100500][3];





int ans(int ind,int cur)

{

   if(ind==n+1)return 0;

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



   dp[ind][cur]=-MOD*MOD;



   forn(j,0,2)

   {

       if(j==cur)continue;

       dp[ind][cur]=max(dp[ind][cur],arr[ind][j]+ans(ind+1,j));

   }

   return dp[ind][cur];





}







signed main() 

{

	ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cin>>n;

    st(dp,-1);



    forn(i,1,n)

        forn(j,0,2) 

            cin>>arr[i][j];

    

    cout<<max(ans(1,0),max(ans(1,1),ans(1,2)));





    



     

     









     return 0;



}



//       g++ -g c2.cpp ; ./a.exe

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

using namespace         std;

#define                 int long long

#define                 pb push_back

#define                 mp make_pair

#define st(arr,a)       memset(arr,a,sizeof arr)

#define                 nl cout<<endl

#define                 real signed

#define                 endl '\n'              

#define bitcount(x)     __builtin_popcountll(x)

const int MOD = 1000000007ll;

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

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

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

#define pi pair<int,int>

#define X first

#define Y second

#define N 1014159

#define  vi vector<int>

#define  v  vector



int n;

int A[4][N];

int dp[N][5];



void solve()

{

    cin>>n;

    forn(i,1,n)

    {

        cin>>A[1][i]>>A[2][i]>>A[3][i];;

    }

    

    forn(i,1,n)

    {

        forn(j,1,3)

        {

           forn(k,1,3)

            {

                if(k == j)continue;

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

            }

        }    

    }



    int x = 0;

    forn(i,1,3)x = max(x,dp[n][i]);

    cout<<x;

    

}





signed main() 

{

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

    int t = 1;

    //cin>>t;

    while(t--)

    {

        solve();

    }







    return 0;



}



//       g++ -g c.cpp ; ./a.exe
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n;

vector <int> sw(100005);

vector <int> bg(100005);

vector <int> hw(100005);

int dp[100005][3];

int solve(int i, int t){

    if(i>n){

        return 0;

    }

    if(dp[i][t]!=-1){

        return dp[i][t];

    }

    int q = 0;

    if(t==1){

        q = sw[i]+ max(solve(i+1,2), solve(i+1, 3));

    }

    else if(t==2){

         q = bg[i]+ max(solve(i+1,1), solve(i+1, 3));

    }

    else{

         q = hw[i]+ max(solve(i+1,2), solve(i+1, 1));

    }

    dp[i][t] = q;

    return q;

}

void initialize(){

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

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

            dp[i][j]=-1;

        }

    }

}

int main(){

    initialize();

    cin>>n;

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

        cin>>sw[i]>>bg[i]>>hw[i];

    }

    int ans = solve(1,1);

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

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

    cout<<ans<<endl;

}


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

using namespace std;

vector <int> dp;

int main(){

	int n;

  	cin>>n;

  	vector <vector<int> >  v(n, vector <int> (3));

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

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

	}

	vector <vector <int> > dp(n+1, vector <int> (3, 0));

	dp[0][0] = v[0][0];

	dp[0][1] = v[0][1];

	dp[0][2] = v[0][2];

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

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

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

				if(j==k) continue;

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

			}

		}

	}

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

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

using namespace std;

typedef long long int ll;

const int MAX=1e5+10;

int N,A[MAX],B[MAX],C[MAX],dp[MAX][3];

int solve(int idx,int pr)

{

    if(idx>N)return 0;

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

    int res=0;

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

        if(i==pr)continue;

        int val=0;

        if(i==1)val=A[idx];

        if(i==2)val=B[idx];

        if(i==3)val=C[idx];

        res = max(res,solve(idx+1,i)+val);

    }

    return dp[idx][pr]=res;

}

int  main ()

{

    memset(dp,-1,sizeof dp);

    cin >> N;

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

        cin >> A[i] >> B[i] >> C[i];

    }

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

    return 0;

}






// Faster C++ solution for the same problem (measured speedup: 1.590906211542436x):
#include <cstdio>

#include <cstdint>

#include <cinttypes>

#include <cstring>

#include <algorithm>



using i32 = std::int_fast32_t;



const int MaxN = 100001;



int A[MaxN][3], dp[MaxN][3];



signed main(signed argc, char **argv) {

	i32 n;

	std::scanf("%" SCNdFAST32, &n);

	

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

		std::scanf("%" SCNdFAST32 "%" SCNdFAST32 "%" SCNdFAST32, A[i], A[i] + 1, A[i] + 2);

	}

	

	memset(dp, 0, sizeof dp);

	

	dp[0][0] = A[0][0];

	dp[0][1] = A[0][1];

	dp[0][2] = A[0][2];

	

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

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

			for (i32 a = 0; a < 3; ++ a) {

				if (a == j) {

					continue;

				}

				dp[i][j] = std::max(dp[i][j], dp[i - 1][a] + A[i][j]);

			}

		}

	}

	

	std::printf("%" PRIdFAST32, std::max(dp[n - 1][0], std::max(dp[n - 1][1], dp[n - 1][2])));

	return 0;

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

using namespace std;

#define print printf("==================\n")

#define ll long long

#define pi acos(-1.0)

#define eps 1e-16

#define max3(a,b,c) max(a,max(b,c))

const ll INF = 1 << 30;

typedef pair<ll, ll  > payar;

typedef struct

{

    ll  x, y;

} point;

priority_queue<payar, vector<payar>,  greater<payar> > pq; ///accending

vector< pair<ll,payar  > > vpp;

vector < payar >  vp;



ll n ;

int ara[100005][4];

ll dp[100005][4];

ll cal(int day, int itm)

{

    if(day>n)

    {

        return 0;

    }



    if(dp[day][itm]!=-1)

        return dp[day][itm];

    ll maxi = -1;

    if(day==1)

    {

   return   maxi = dp[day][itm]=max3( cal(day+1,1)+ara[day][1], cal(day+1,2)+ara[day][2], cal(day+1,3)+ara[day][3] );



    }

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

    {

            if(i==itm)

                continue;

            maxi=max( cal(day+1,i)+ara[day][i],maxi);





    }

    return dp[day][itm]=maxi;

}



int main()

{



    cin>>n;

    memset(dp,-1,sizeof dp);

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

    {

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

        {

            cin>>ara[i][j];

        }

    }

    cout<<cal(1,1);







    return  0 ;

}


// Faster C++ solution for the same problem (measured speedup: 3.038173961795961x):
#include <cstdio>

#include <cstdint>

#include <cinttypes>

#include <cstring>

#include <algorithm>



using i32 = std::int_fast32_t;



const int MaxN = 100001;



int A[MaxN][3], dp[MaxN][3];



signed main(signed argc, char **argv) {

	i32 n;

	std::scanf("%" SCNdFAST32, &n);

	

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

		std::scanf("%" SCNdFAST32 "%" SCNdFAST32 "%" SCNdFAST32, A[i], A[i] + 1, A[i] + 2);

	}

	

	memset(dp, 0, sizeof dp);

	

	dp[0][0] = A[0][0];

	dp[0][1] = A[0][1];

	dp[0][2] = A[0][2];

	

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

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

			for (i32 a = 0; a < 3; ++ a) {

				if (a == j) {

					continue;

				}

				dp[i][j] = std::max(dp[i][j], dp[i - 1][a] + A[i][j]);

			}

		}

	}

	

	std::printf("%" PRIdFAST32, std::max(dp[n - 1][0], std::max(dp[n - 1][1], dp[n - 1][2])));

	return 0;

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

using namespace std;

typedef long long int ll;

const int MAX=1e5+10;

int N,A[MAX],B[MAX],C[MAX],dp[MAX][3];

int solve(int idx,int pr)

{

    if(idx>N)return 0;

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

    int res=0;

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

        if(i==pr)continue;

        int val=0;

        if(i==1)val=A[idx];

        if(i==2)val=B[idx];

        if(i==3)val=C[idx];

        res = max(res,solve(idx+1,i)+val);

    }

    return dp[idx][pr]=res;

}

int  main ()

{

    memset(dp,-1,sizeof dp);

    cin >> N;

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

        cin >> A[i] >> B[i] >> C[i];

    }

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

    return 0;

}






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

#define ll long long

using namespace std;

ll n,a[100009][4],dp[100009][4],k;

int main(){

    cin >> n;

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

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

    }

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

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

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

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

    }//ashsijk

    cout << max(max(dp[n][1],dp[n][2]),dp[n][3]) << endl;

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

using namespace std;

#define print printf("==================\n")

#define ll long long

#define pi acos(-1.0)

#define eps 1e-16

#define max3(a,b,c) max(a,max(b,c))

const ll INF = 1 << 30;

typedef pair<ll, ll  > payar;

typedef struct

{

    ll  x, y;

} point;

priority_queue<payar, vector<payar>,  greater<payar> > pq; ///accending

vector< pair<ll,payar  > > vpp;

vector < payar >  vp;



ll n ;

int ara[100005][4];

ll dp[100005][4];

ll cal(int day, int itm)

{

    if(day>n)

    {

        return 0;

    }



    if(dp[day][itm]!=-1)

        return dp[day][itm];

    ll maxi = -1;

    if(day==1)

    {

   return   maxi = dp[day][itm]=max3( cal(day+1,1)+ara[day][1], cal(day+1,2)+ara[day][2], cal(day+1,3)+ara[day][3] );



    }

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

    {

            if(i==itm)

                continue;

            maxi=max( cal(day+1,i)+ara[day][i],maxi);





    }

    return dp[day][itm]=maxi;

}



int main()

{



    cin>>n;

    memset(dp,-1,sizeof dp);

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

    {

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

        {

            cin>>ara[i][j];

        }

    }

    cout<<cal(1,1);







    return  0 ;

}


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

#define ll long long

using namespace std;

ll n,a[100009][4],dp[100009][4],k;

int main(){

    cin >> n;

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

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

    }

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

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

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

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

    }//ashsijk

    cout << max(max(dp[n][1],dp[n][2]),dp[n][3]) << endl;

}