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



#define  ll         long long

#define  llu        unsigned long long

#define  mod        1000000007

#define  pi         ((2.0)*acos(0.0))

#define  pb         push_back

#define  pf         push_front

#define  eb         emplace_back

#define  mp         make_pair

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

#define  X          first

#define  Y          second



/*loop*/

#define  fr(i,m,n)   for(ll i=m;i<n;++i)



/*output shortcuts*/

#define  nl         "\n"

#define  Yes        cout<<"Yes\n"

#define  yes        cout<<"yes\n"

#define  YES        cout<<"YES\n"

#define  No         cout<<"No\n"

#define  no         cout<<"no\n"

#define  NO         cout<<"NO\n"



using namespace std;

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll n;

    cin>>n;

    ll a[n][3];



    fr(i,0,n)

        fr(j,0,3)

            cin>>a[i][j];



    //ll r=1;

    ll dp[n][3]={-1};



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

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

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



    fr(r,1,n)

    {

    for(ll i=0;i<3 && r<n; i++)  // cur_row

    {

        for(ll j=0;j<3;j++) // pre_row

        {

            if(j==i)

                continue;

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

        }

    }

    }



    /*cout<<nl<<nl;

    fr(i,0,n)

        {

            fr(j,0,3)

            {cout<<dp[i][j]<<" ";}

            cout<<nl;

        }

    */

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



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



#define  ll         long long

#define  llu        unsigned long long

#define  mod        1000000007

#define  pi         ((2.0)*acos(0.0))

#define  pb         push_back

#define  pf         push_front

#define  eb         emplace_back

#define  mp         make_pair

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

#define  X          first

#define  Y          second



/*loop*/

#define  fr(i,m,n)   for(ll i=m;i<n;++i)



/*output shortcuts*/

#define  nl         "\n"

#define  Yes        cout<<"Yes\n"

#define  yes        cout<<"yes\n"

#define  YES        cout<<"YES\n"

#define  No         cout<<"No\n"

#define  no         cout<<"no\n"

#define  NO         cout<<"NO\n"



using namespace std;

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll n;

    cin>>n;

    ll a[n][3];



    fr(i,0,n)

        fr(j,0,3)

            cin>>a[i][j];



    //ll r=1;

    ll dp[n][3]={-1};



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

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

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



    fr(r,1,n)

    {

    for(ll i=0;i<3 && r<n; i++)  // cur_row

    {

        for(ll j=0;j<3;j++) // pre_row

        {

            if(j==i)

                continue;

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

        }

    }

    }



    /*cout<<nl<<nl;

    fr(i,0,n)

        {

            fr(j,0,3)

            {cout<<dp[i][j]<<" ";}

            cout<<nl;

        }

    */

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



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



#define  ll         long long

#define  llu        unsigned long long

#define  mod        1000000007

#define  pi         ((2.0)*acos(0.0))

#define  pb         push_back

#define  pf         push_front

#define  eb         emplace_back

#define  mp         make_pair

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

#define  X          first

#define  Y          second



/*loop*/

#define  fr(i,m,n)   for(ll i=m;i<n;++i)



/*output shortcuts*/

#define  nl         "\n"

#define  Yes        cout<<"Yes\n"

#define  yes        cout<<"yes\n"

#define  YES        cout<<"YES\n"

#define  No         cout<<"No\n"

#define  no         cout<<"no\n"

#define  NO         cout<<"NO\n"



using namespace std;

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll n;

    cin>>n;

    ll a[n][3];



    fr(i,0,n)

        fr(j,0,3)

            cin>>a[i][j];



    //ll r=1;

    ll dp[n][3]={-1};



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

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

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



    fr(r,1,n)

    {

    for(ll i=0;i<3 && r<n; i++)  // cur_row

    {

        for(ll j=0;j<3;j++) // pre_row

        {

            if(j==i)

                continue;

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

        }

    }

    }



    /*cout<<nl<<nl;

    fr(i,0,n)

        {

            fr(j,0,3)

            {cout<<dp[i][j]<<" ";}

            cout<<nl;

        }

    */

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



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



#define  ll         long long

#define  llu        unsigned long long

#define  mod        1000000007

#define  pi         ((2.0)*acos(0.0))

#define  pb         push_back

#define  pf         push_front

#define  eb         emplace_back

#define  mp         make_pair

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

#define  X          first

#define  Y          second



/*loop*/

#define  fr(i,m,n)   for(ll i=m;i<n;++i)



/*output shortcuts*/

#define  nl         "\n"

#define  Yes        cout<<"Yes\n"

#define  yes        cout<<"yes\n"

#define  YES        cout<<"YES\n"

#define  No         cout<<"No\n"

#define  no         cout<<"no\n"

#define  NO         cout<<"NO\n"



using namespace std;

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll n;

    cin>>n;

    ll a[n][3];



    fr(i,0,n)

        fr(j,0,3)

            cin>>a[i][j];



    //ll r=1;

    ll dp[n][3]={-1};



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

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

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



    fr(r,1,n)

    {

    for(ll i=0;i<3 && r<n; i++)  // cur_row

    {

        for(ll j=0;j<3;j++) // pre_row

        {

            if(j==i)

                continue;

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

        }

    }

    }



    /*cout<<nl<<nl;

    fr(i,0,n)

        {

            fr(j,0,3)

            {cout<<dp[i][j]<<" ";}

            cout<<nl;

        }

    */

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



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



#define  ll         long long

#define  llu        unsigned long long

#define  mod        1000000007

#define  pi         ((2.0)*acos(0.0))

#define  pb         push_back

#define  pf         push_front

#define  eb         emplace_back

#define  mp         make_pair

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

#define  X          first

#define  Y          second



/*loop*/

#define  fr(i,m,n)   for(ll i=m;i<n;++i)



/*output shortcuts*/

#define  nl         "\n"

#define  Yes        cout<<"Yes\n"

#define  yes        cout<<"yes\n"

#define  YES        cout<<"YES\n"

#define  No         cout<<"No\n"

#define  no         cout<<"no\n"

#define  NO         cout<<"NO\n"



using namespace std;

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll n;

    cin>>n;

    ll a[n][3];



    fr(i,0,n)

        fr(j,0,3)

            cin>>a[i][j];



    //ll r=1;

    ll dp[n][3]={-1};



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

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

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



    fr(r,1,n)

    {

    for(ll i=0;i<3 && r<n; i++)  // cur_row

    {

        for(ll j=0;j<3;j++) // pre_row

        {

            if(j==i)

                continue;

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

        }

    }

    }



    /*cout<<nl<<nl;

    fr(i,0,n)

        {

            fr(j,0,3)

            {cout<<dp[i][j]<<" ";}

            cout<<nl;

        }

    */

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



return 0;

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

using namespace std;

int a[100000+5];

int b[100000+5];

int c[100000+5];



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

{

	int N;

	while(cin >> N) {

		memset(a, 0, sizeof(a));

		memset(b, 0, sizeof(b));

		memset(c, 0, sizeof(c));

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

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

		}

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

			int tempa = a[i - 1];

			int tempb = b[i - 1];

			int tempc = c[i - 1];

			a[i] = a[i] + max(tempb, tempc);

			b[i] = b[i] + max(tempa, tempc);

			c[i] = c[i] + max(tempa, tempb);

		}

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

    }

	return 0;

}

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



#define  ll         long long

#define  llu        unsigned long long

#define  mod        1000000007

#define  pi         ((2.0)*acos(0.0))

#define  pb         push_back

#define  pf         push_front

#define  eb         emplace_back

#define  mp         make_pair

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

#define  X          first

#define  Y          second



/*loop*/

#define  fr(i,m,n)   for(ll i=m;i<n;++i)



/*output shortcuts*/

#define  nl         "\n"

#define  Yes        cout<<"Yes\n"

#define  yes        cout<<"yes\n"

#define  YES        cout<<"YES\n"

#define  No         cout<<"No\n"

#define  no         cout<<"no\n"

#define  NO         cout<<"NO\n"



using namespace std;

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll n;

    cin>>n;

    ll a[n][3];



    fr(i,0,n)

        fr(j,0,3)

            cin>>a[i][j];



    //ll r=1;

    ll dp[n][3]={-1};



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

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

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



    fr(r,1,n)

    {

    for(ll i=0;i<3 && r<n; i++)  // cur_row

    {

        for(ll j=0;j<3;j++) // pre_row

        {

            if(j==i)

                continue;

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

        }

    }

    }



    /*cout<<nl<<nl;

    fr(i,0,n)

        {

            fr(j,0,3)

            {cout<<dp[i][j]<<" ";}

            cout<<nl;

        }

    */

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



return 0;

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

using namespace std;



int ar[100010][5],n;

int dp[100010][5];



int call(int i,int f)

{



    if(i==n)

        return 0;



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

        return dp[i][f];



    int ans=0;



    if(f==0)

        ans+=max(ar[i][1]+call(i+1,1),ar[i][2]+call(i+1,2));



    else if(f==1)

        ans+=max(ar[i][0]+call(i+1,0),ar[i][2]+call(i+1,2));

    else

        ans+=max(ar[i][1]+call(i+1,1),ar[i][0]+call(i+1,0));



        dp[i][f]=ans;

        return ans;



}



int main()

{



    cin>>n;



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

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



    memset(dp,-1,sizeof dp);



    int ans=max(max(call(0,0),call(0,1)),call(0,2));



    cout<<ans<<endl;



}


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

using namespace std;

#define debug(x) cerr<<#x<<" = "<<x<<endl;

typedef long long int ll;

int main(){

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int n;

    cin>>n;

    int arr[n];

    int arr2[n];

    int arr3[n];

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

        cin>>arr[i];

        cin>>arr2[i];

        cin>>arr3[i];



    }

    int ans[n];

    int ans2[n];

    int ans3[n];

    ans[0]=arr[0];

    ans2[0]=arr2[0];

    ans3[0]=arr3[0];

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

        ans[i]=arr[i]+max(ans2[i-1],ans3[i-1]);

        ans2[i]=arr2[i]+max(ans3[i-1],ans[i-1]);

        ans3[i]=arr3[i]+max(ans2[i-1],ans[i-1]);

    }

    int res=max({ans[n-1],ans2[n-1],ans3[n-1]});

    cout<<res<<"\n";

}
// Slower C++ solution:


#include<bits/stdc++.h>

using namespace std;



#define MAX 100000



int dp[MAX+5][4];

int val[MAX+5][4];

int n;



void initialize()

{

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

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

            dp[i][j] = -1;

}



int vacation(int i, int j)

{

    if(i<=0) return 0;



  /*  if(i==1)

    {

        return val[i][j];

    }

*/

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



    int mx = INT_MIN;



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

    {

        if(j==k) continue;



        mx = max(mx, vacation(i-1, k)+ val[i][j]);

    }





    dp[i][j] = mx;



    return mx;

}



int main()

{

    initialize();



    cin>>n;

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

    {

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

            cin>>val[i][j];

    }



    int retVal1 = vacation(n, 1);



    initialize();



    int retVal2 = vacation(n, 2);



    initialize();



    int retVal3 = vacation(n, 3);



    cout<<max({retVal1, retVal2, retVal3})<<endl;



    return 0;

}


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

using namespace std;

#define debug(x) cerr<<#x<<" = "<<x<<endl;

typedef long long int ll;

int main(){

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int n;

    cin>>n;

    int arr[n];

    int arr2[n];

    int arr3[n];

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

        cin>>arr[i];

        cin>>arr2[i];

        cin>>arr3[i];



    }

    int ans[n];

    int ans2[n];

    int ans3[n];

    ans[0]=arr[0];

    ans2[0]=arr2[0];

    ans3[0]=arr3[0];

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

        ans[i]=arr[i]+max(ans2[i-1],ans3[i-1]);

        ans2[i]=arr2[i]+max(ans3[i-1],ans[i-1]);

        ans3[i]=arr3[i]+max(ans2[i-1],ans[i-1]);

    }

    int res=max({ans[n-1],ans2[n-1],ans3[n-1]});

    cout<<res<<"\n";

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

using namespace std;

int arr[100010][5];

int dp[100010][5];



int vac(int a, int b){

	if(a == 0) return 0;

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

	

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

		if(i != b){

			dp[a][b] = max(dp[a][b], vac(a - 1,i) + arr[a][i]);

		}

	}

	

	return dp[a][b];

}



int main (){

	memset(dp,-1,sizeof dp);

	int n;

	cin >> n;

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

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

	}

	

	

	int ans = 0;

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

		ans = max(ans , vac(n - 1, i) + arr[n][i]);

	}

	

	cout << ans << endl;

	

}

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

using namespace std;

#define debug(x) cerr<<#x<<" = "<<x<<endl;

typedef long long int ll;

int main(){

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int n;

    cin>>n;

    int arr[n];

    int arr2[n];

    int arr3[n];

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

        cin>>arr[i];

        cin>>arr2[i];

        cin>>arr3[i];



    }

    int ans[n];

    int ans2[n];

    int ans3[n];

    ans[0]=arr[0];

    ans2[0]=arr2[0];

    ans3[0]=arr3[0];

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

        ans[i]=arr[i]+max(ans2[i-1],ans3[i-1]);

        ans2[i]=arr2[i]+max(ans3[i-1],ans[i-1]);

        ans3[i]=arr3[i]+max(ans2[i-1],ans[i-1]);

    }

    int res=max({ans[n-1],ans2[n-1],ans3[n-1]});

    cout<<res<<"\n";

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

using namespace std;

#define INF INT_MAX

#define N 100005

#define K 3

int n, k;

int arr[N][K];

int dp[N][K];

int solve(int idx, int last_k){

    int res;

    if(idx == n)

        return 0;

    if(~last_k && ~dp[idx][last_k])

        return dp[idx][last_k];

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

        if(last_k != i){

            dp[idx][last_k] = max(dp[idx][last_k], arr[idx][i]+solve(idx+1, i));

        }

    }

    return dp[idx][last_k];

}

int main()

{

    cin >> n;

    memset(dp, -1, sizeof(dp[0][0]) * N * K);

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

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

            cin >> arr[i][j];

    cout << solve(0, -1);

    return 0;

}




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

using namespace std;

#define debug(x) cerr<<#x<<" = "<<x<<endl;

typedef long long int ll;

int main(){

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int n;

    cin>>n;

    int arr[n];

    int arr2[n];

    int arr3[n];

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

        cin>>arr[i];

        cin>>arr2[i];

        cin>>arr3[i];



    }

    int ans[n];

    int ans2[n];

    int ans3[n];

    ans[0]=arr[0];

    ans2[0]=arr2[0];

    ans3[0]=arr3[0];

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

        ans[i]=arr[i]+max(ans2[i-1],ans3[i-1]);

        ans2[i]=arr2[i]+max(ans3[i-1],ans[i-1]);

        ans3[i]=arr3[i]+max(ans2[i-1],ans[i-1]);

    }

    int res=max({ans[n-1],ans2[n-1],ans3[n-1]});

    cout<<res<<"\n";

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

typedef long long ll;

using namespace std;

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

const double EPS = 1e-3;

#define M_PI 3.14159265358979323846

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

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

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

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

#define pb push_back

#define F first

#define S second

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

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

typedef pair <int,int> pii ;

typedef vector < pii > vii ;

typedef vector < int > vi;

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

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

//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

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

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







int n,x;

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

ll dp[N][4];





ll solve(int idx, int preC){ //preColour = (1 : a) -- (2 : b) -- (3 : c) -- (0 : invalid)



    if(idx == n) return 0;



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

    if(~ret) return ret;



    ret = -OO;

    if(preC != 1) ret = max(ret, solve(idx+1 , 1)+a[idx]);

    if(preC != 2) ret = max(ret, solve(idx+1 , 2)+b[idx]);

    if(preC != 3) ret = max(ret, solve(idx+1 , 3)+c[idx]);



    return ret;



}







int main(){





    //ios_base::sync_with_stdio(0);

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





    scanf("%d",&n);

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

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



    memset(dp, -1 , sizeof dp);

    ll ans = solve(0 , 0);

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







    return 0;

}


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

using namespace std;

#define debug(x) cerr<<#x<<" = "<<x<<endl;

typedef long long int ll;

int main(){

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int n;

    cin>>n;

    int arr[n];

    int arr2[n];

    int arr3[n];

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

        cin>>arr[i];

        cin>>arr2[i];

        cin>>arr3[i];



    }

    int ans[n];

    int ans2[n];

    int ans3[n];

    ans[0]=arr[0];

    ans2[0]=arr2[0];

    ans3[0]=arr3[0];

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

        ans[i]=arr[i]+max(ans2[i-1],ans3[i-1]);

        ans2[i]=arr2[i]+max(ans3[i-1],ans[i-1]);

        ans3[i]=arr3[i]+max(ans2[i-1],ans[i-1]);

    }

    int res=max({ans[n-1],ans2[n-1],ans3[n-1]});

    cout<<res<<"\n";

}