Problem:
Score : 100 points

Problem Statement

Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.

The vacation consists of N days.
For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:

A: Swim in the sea. Gain a_i points of happiness.

B: Catch bugs in the mountains. Gain b_i points of happiness.

C: Do homework at home. Gain c_i points of happiness.

As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.

Find the maximum possible total points of happiness that Taro gains.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq a_i, b_i, c_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N

Output

Print the maximum possible total points of happiness that Taro gains.

Sample Input 1

3
10 40 70
20 50 80
30 60 90

Sample Output 1

210

If Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210 points of happiness.

Sample Input 2

1
100 10 1

Sample Output 2

100

Sample Input 3

7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1

Sample Output 3

46

Taro should do activities in the order C, A, B, A, C, B, A.

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

#define nl                  "\n"
#define ll                  long long
#define ull                 unsigned long long
#define pb                  push_back
#define SIZE(a)             (int)a.size()
#define SORT(v)             sort(v.begin(),v.end())
#define RSORT(v)            sort(v.rbegin(),v.rend())
#define REV(v)              reverse(v.begin(),v.end())
#define ff                  first
#define ss                  second
#define sq(a)               ((a)*(a))
#define For(i,a,b)          for(i=a;i<=b;i++)
#define Rof(i,a,b)          for(i=a;i>=b;i--)
#define Rep(i,b)            for(i=0;i<b;i++)
#define MOD                 1000000007
#define PI                  acos(-1.0)
#define eps                 1e-9
#define Linf                2e18
#define inf                 1<<30
#define MX5                 100005
#define MX6                 1000006
#define MX3                 1005
#define GCD(a,b)            __gcd(a,b)
#define Abs(a)              abs(a)
#define input(a,b)          scanf("%lld%lld",&a,&b)
#define in1(a)              scanf("%lld",&a)
#define output(a)           printf("%lld\n",a);
#define mem(a)              memset(a,-1,sizeof(a)) // complexity O(n)
#define clr(a)              memset(a,0,sizeof (a))
#define mk                  make_pair
#define pLL                 pair<ll,ll>
#define invcos(a)           (acos(a)*(180/3.14159265))
#define rtan(a)             (tan(a*3.14159265/180.0))
#define pip                 printf("pip")
#define Case(x)             printf("Case %lld: ",x)
#define timelimit           1.0*clock()/CLOCKS_PER_SEC
#define pc_one              __builtin_popcount
#define pcl_one             __builtin_popcountl
#define pcll_one            __builtin_popcountll
#define parity              __builtin_parity
#define parityl             __builtin_parityl
#define parityll            __builtin_parityll
#define infile              freopen("input.txt","r",stdin)
#define outfile             freopen("output.txt","w",stdout)
#define debug(x)            cerr << #x << " is " << x << endl
#define fast                ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//const ll Linf=2e18;
///4direction ->        int del_x[]={-1,0,1,0},del_y[]={0,1,0,-1};
///8direction ->        int del_x[]={-1,0,1,0,1,-1,-1,1},del_y[]={0,1,0,-1,-1,-1,1,1};


#include <bits/stdc++.h>
#include <iomanip>
using namespace std;

ll bigmod(ll n, ll p) {if (p == 0) return 1; if (p == 1)return (n + MOD) % MOD; if (p % 2)return (bigmod(n, p - 1) * n + MOD) % MOD; else {ll x = bigmod(n, p / 2); return (x * x + MOD) % MOD;}}
ll modinverse(ll n) {return bigmod(n, MOD - 2) % MOD;}
bool check_2s_power(ll a) {return (pcll_one(a) == 1 ? true : false);}


/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

ll dp[MX5][3];

int main()
{
    ll n,i,j,k,a;
    in1(n);
    For(i,1,n)
    {
        Rep(j,3)
        {
            in1(dp[i][j]);
        }
    }
    ll ans=0;
    For(i,1,n)
    {
        Rep(j,3)
        {
            ll maxi=0;
            For(k,1,2)
            {
                a=(j+k)%3;
                maxi=max(maxi,dp[i-1][a]);
            }
            dp[i][j]+=maxi;
            ans=max(ans,dp[i][j]);
        }
    }
    output(ans);
}