stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
//#include <bits/stdc++.h>

#include <algorithm>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cstring>

#include <vector>

#include <string>

#include <climits>

#include <map>

#include <set>

#include <stack>

#include <queue>

#include <deque>

#include <stdio.h>

//#define int long long

using namespace std;

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

#define endl '\n'

#define OnlineJudgec

#define F first

#define S second

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

#define clr(v,d ) memset(v, d, sizeof(v))

typedef long long ll;

typedef vector<int> vi;

void init()

{

    cin.tie(0);

    cin.sync_with_stdio(0);

    cout.tie(0);

    #ifdef OnlineJudge

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

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

    #endif

}

ll S(ll x){ll s = 0;while(x){s += x % 10;x /= 10;}return s;} /// sum of digits.

ll powe(ll a , ll n){if(n == 1)return a;return a * powe(a ,n-1);}

ll com(int n,int m){ll z = 1;for(int i = 0; i < m;i++){z = z * ( n - i) / (i + 1) ;}return z;}

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

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

int dr[] = {0,0,0,1,1,1,-1,-1,-1};

int dc[] ={-1,0,1,-1,0,1,-1,0,1};

/// <<------------------------------------------------------------------------------>>

const int mx = 100009;

int n , k;

int arr[mx][4];

int dp[mx][4];

int solve(int idx , int last)

{

     if(idx == n)return 0;

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

     if(~ret) return ret;

     int A = 0 ,B = 0 ,C = 0;

     if(last != 0)

        A = solve(idx+1 , 0) + arr[idx][0];

     if(last != 1)

        B = solve(idx+1 , 1) + arr[idx][1];

     if(last != 2)

        C = solve(idx+1 , 2) + arr[idx][2];

     return ret = max(A,max(B,C));

}

/// <<------------------------------------------------------------------------------>>

int main()

{

    init();

    cin >> n;

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

    {

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

    }

    clr(dp,-1);

    cout<<solve(0,3);

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm> 

#include<vector>

using namespace std;

int dp[100000][3];

int main()

{

	int n;

	cin>>n;

	int a[n][3];

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

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

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

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

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

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

	{

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

		{

			if(j>0)

			{

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

			}

			if(j<2)

			{

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

			}

			if(j==0)

			{

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

			}

			if(j==2)

			{

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

			}

		}

	}

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

	return 0;

 } 

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

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

int mem[N][3];



int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);



	cin >> n;



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

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

	}



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

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

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

				if (k == j) continue;

				mem[i][j] = max(mem[i][j], mem[i + 1][k] + c[i][k]);

			}

		}

	}



	int ans = 0;

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

		ans = max(ans, mem[0][i]);

	}



	cout << ans << '\n';



	return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#pragma comment(linker,"/STACK:102400000,102400000")

#include <iostream>

#include <cstdio>

#include <algorithm>

#include <vector>

#include <string>

#include <cstring>

#include <cctype>

#include <climits>

#include <cmath>

#include <set>

#include <map>

#include <sstream>

#include <queue>

#include <stack>

using namespace std;

int dp[100010][3];

int main(){

	int n,a,b,c,temp;

	scanf("%d",&n);

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

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

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

	}

	dp[n-1][0]=arr[n-1][0],dp[n-1][1]=arr[n-1][1],dp[n-1][2]=arr[n-1][2];

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

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

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

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

	}

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

	ans=max(ans,dp[0][0]);

	cout<<ans<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std ;

#define ll long long

inline int D(){

    int t ;

    scanf( "%d" , &t ) ;

    return t ;

}

inline ll LLD(){

    ll t ;

    scanf( "%lld" , &t ) ;

    return t ;

}

//################################################################

const int N=100009;

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

int mem[N][4];



int main() {

    n=D();

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

        a[i]=D(),b[i]=D(),c[i]=D();

    }

    mem[0][0]=a[0];

    mem[0][1]=b[0];

    mem[0][2]=c[0];

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

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

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

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

    }

    printf("%d",max(max(mem[n-1][0],mem[n-1][1]),mem[n-1][2]));



}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include <unordered_map>

#include <unordered_set>

#define endl '\n'

#define PI acos(-1)

typedef long long ll;

using namespace std;

struct ac{int a, b, c;} *x;

int n, **mem;

int jump(int i = 0, int last = 0)

{

    if(i == n)

        return 0;

    if(last != 1 && !~mem[i][0])

        mem[i][0] = x[i].a + jump(i + 1, 1);

    if(last != 2 && !~mem[i][1])

        mem[i][1] = x[i].b + jump(i + 1, 2);

    if(last != 3 && !~mem[i][2])

        mem[i][2] = x[i].c + jump(i + 1, 3);

    if(last == 1)

        return max(mem[i][1], mem[i][2]);

    else if(last == 2)

        return max(mem[i][0], mem[i][2]);

    else if(last == 3)

        return max(mem[i][0], mem[i][1]);

    else

        return max(mem[i][1], max(mem[i][0], mem[i][2]));

}

int main()

{

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

    #ifndef ONLINE_JUDGE

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

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

    #endif

    scanf("%d", &n);

    x = new ac[n];

    mem = new int*[n];

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

    {

        mem[i] = new int[3];

        mem[i][0] = mem[i][1] = mem[i][2] = -1;

    }

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

        scanf("%d %d %d", &(x[i].a), &(x[i].b), &(x[i].c));

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

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

#define x first

#define y second



vector<vector<int>> dp, arr;

int main() {

    fast;

    int n;

    cin>>n;

    arr.resize(n);

    dp.resize(n);

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

        arr[i].resize(3);

        dp[i].resize(3);

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

            cin>>arr[i][j];

            dp[i][j] = -1;

        }

    }

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

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

            if(i == n-1)

            {

                dp[i][j] = arr[i][j];

            } else{

                int temp, max = 0;

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

                    if(k == j)

                        continue;

                    temp = dp[i + 1][k];

                    if(temp > max)

                        max = temp;

                }

                dp[i][j] = max + arr[i][j];

            }

        }

    }

    sort(dp[0].begin(), dp[0].end());

    cout<<dp[0][2];

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



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

#define ll long long

#define pb push_back

#define endl '\n'

#define mod 1000000007

#define maxN 1e5

const int inf=0x3f3f3f3f;



int main() {

	Omar45

	int n; cin >> n;

    int a[n+3], b[n+3], c[n+3], dp[n-1][3], res=0;

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

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

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

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

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

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

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

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

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

            // last case //

            if (i==n-1) res = max(res, dp[i][j]);

        }

    }

    cout << res << endl;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>



#define ll long long



using namespace std;



int n;

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



ll build()

{

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

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

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

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

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

	{

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

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

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

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

	}

	return ans;

}



int main()

{

	cin >> n;

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

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

			cin >> arr[i][j];

	cout << build() << '\n';

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cmath>

#include <queue>

#include <set>

#include <string>

#include <vector>

#include <iomanip>

#include <algorithm>

#include <map>

#include <sstream>

using namespace std;

int dp[100000][5], a[100000], b[100000], c[100000];

int main()

{

    int n;

    cin >> n;

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

    {

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

    }

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

    dp[1][2] = b[1];

    dp[1][3] = c[1];

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

    {

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

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

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

    }

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

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define endl '\n'

using namespace std;

typedef long long ll;

const int c=1e5;

const ll mod=1e9+7;

/*bool p[1000];

void sieve(){

p[0]=p[1]=1;

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

    for(int j=i*i;j<=100;j+=i){

        p[j]=1;

    }

}

}*/

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int n;

    cin>>n;

    ll a[n+5]={},b[n+5]={},c[n+5]={};

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

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

    }

    ll dp[n][5]={};

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

    dp[0][2]=b[0];

    dp[0][3]=c[0];

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

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

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

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

    }

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

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



#define ll long long

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

#define pb push_back

const long double pi=3.141592654;

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

using namespace std;



const ll inf = 1e9 +5, mod = 1e9+7,N = 1e5+5;





int main()

{

	OSOS

	int n;

	cin>>n;

	int arr[N][3];

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

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

		{

			cin>>arr[i][ii];

		}





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

		{

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

			{

				int maxx = 0;

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

				{

					if(iii != ii)

					{

						maxx = max(arr[i-1][iii], maxx);

					}

				}

				arr[i][ii] += maxx;

			}

		}

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

}




// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream> 

#include <string>

#include <cmath> 

#include <algorithm>

using namespace std;

int main() {

	int n, a, b, c;

	cin >> n;

	int v[n + 1][3] = {0};

	cin >> a >> b >> c;

	v[1][0] = a;

	v[1][1] = b;

	v[1][2] = c;

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

		cin >> a >> b >> c;

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

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

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

	} 

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

	return 0; 

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using std::max;



#define MAXN 100003

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

int main(void)

{

    int i,N;

    scanf("%d",&N);

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

    {

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

    }

    d[0][0]=a[0][0];

    d[0][1]=a[0][1];

    d[0][2]=a[0][2];

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

    {

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

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

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

    }

    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/*

██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗

██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗

█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║

██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║

██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝

╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝

Believe in yourself ,( try and try and then try ), You can do it 

*/

#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

#include<unordered_map>

#define endl "\n"

#define Ceil(x,y) ((x+y-1)/y)

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

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

#define allr(s) s.rbegin(),s.rend()

#define rt(s) return cout<<s,0

#define watch(x) cout<<(#x)<<" = "<<x<<endl

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

#define OO 0x3f3f3f3f3f3f3f3fLL

const int oo = 0x3f3f3f3f, mod = 1e9 + 7;

using namespace std;

typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

//x = xDegrees*3.14159265 / 180;

//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);

//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));

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

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

void K_K(){

#ifndef ONLINE_JUDGE

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

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

#endif  !ONLINEJUDGE

	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}

ll gcd(ll a, ll b) {

	return b == 0 ? abs(a) : gcd(b, a % b);

}

ll lcm(ll a, ll b) {

	return a / gcd(a, b) * b;

}

int n;

vector<int>a, b, c;

int dp[100005][5];

int sol(int idx, int pre){

	if (idx == n)

		return 0;

	int& ret = dp[idx][pre];

	if (~ret)

		return ret;

	int ch1 = 0, ch2 = 0, ch3 = 0;

	if (pre != 1)

		ch1 = sol(idx + 1, 1) + a[idx];

	if (pre != 2)

		ch2 = sol(idx + 1, 2) + b[idx];

	if (pre != 3)

		ch3 = sol(idx + 1, 3) + c[idx];

	return ret = max({ ch1, ch2, ch3 });

}

int main(){

	K_K();

	cin >> n;

	a.resize(n);

	b.resize(n);

	c.resize(n);

	clr(dp, -1);

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

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

	cout << sol(0, 0);

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

int n;

int a[4][100005];

int f[100005][4];

int main()

{

	scanf("%d",&n);

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

	   scanf("%d%d%d",&a[1][i],&a[2][i],&a[3][i]);

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

	{

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

		{

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

			{

				if(j==k) continue;

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

			}

			//cout<<f[i][j]<<" ";

		}

		//cout<<endl;

	}

	int ans=0;

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

	   ans=max(ans,f[n][i]);

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

	return 0;

 } 

// Fastest known solution for this problem: