#include<bits/stdc++.h>
            #include <bitset>
            using namespace std;
            #define ll long long 
            #define ld long double
            #define MOD 1000000007
            #define mod9 1000000009
            #define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
            #define mp make_pair
            #define pb push_back
            #define ct ll t;cin>>t;while(t--)
            #define bi begin()
            #define ei end()
            #define fi first 
            #define se second  
            #define foe(i,a,b) for(ll i=a;i<b;i++)
    		#define sz(s) s.size() 
            #define mem(a,s) memset(a,s,sizeof(a))    
            bool isPrime(ll n) 
            { 
                // Corner case 
                if (n <= 1) 
                    return false; 
                
                // Check from 2 to n-1 
                for (ll i = 2; i*i <= n; i++) 
                    if (n % i == 0) 
                        return false; 
                
                return true; 
            }
            long long binpow(long long a, long long b) {
                long long res = 1;
                while (b > 0) {
                    if (b & 1)
                        res = (res%MOD) * (a%MOD);
                    a = (a%MOD) * (a%MOD);
                    b >>= 1;
                }
                return res%MOD;
            }
     
            // bool compare(const pair<ll,ll>&a,const pair<ll,ll>&b)
            // {
            //     return (a.se<b.se);
            // }
            ll lcm(ll a,ll b)
            {
                return(a*b)/__gcd(a,b);
            }
            // vector<ll>s;
            set<ll>s1;
            void SieveOfEratosthenes() 
            {  
                ll n=100005;
                bool prime[100005]={false};
                // s[0]=0;
                // s[1]=1;
                // s.pb(1);
                // t.insert(1);
                for (int p=2; p<=n; p++) 
                { 
                    
                   if(prime[p]==false)
                   {
                       for(ll j=p+p;j<=100005;j+=p)
                       {
                           prime[j]=true;
                       }    
                   }
                } 
                for(ll i=2;i<100005;i++)
                {
                    if(!prime[i])
                    {
                        // s.pb(i);
                        s1.insert(i);
                    }
                }
            } 
            void eea(ll a, ll b, ll & x, ll & y) {
            if (a == 0) {
                x = 0;
                y = 1;
                return ;
            }
            ll x1, y1;
            eea(b % a, a, x1, y1);
            x = y1 - (b / a) * x1;
            y = x1;
            return ;
        }
        ll modinverse(ll a,ll m)
        {
            ll x, y;
            eea(a, m, x, y);
            if (__gcd(a,m) != 1) {
            return -1;
            }
        else {
            x = (x % m + m) % m;
            cout << x << endl;
            return x;
        }
        }
            ll fact[1000007]={0};
            ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
            y=y>>1;x=(1ll*x*x)%MOD;} return res;}
            void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
            ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
            ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
                ll C(ll n, ll k) {
        ll res = 1;
        for (ll i = 1; i <= k; ++i)
            res = ((res) * (n - k + i) / i)%MOD;
        return (ll)(res + 0.01)%MOD;
    }
    const ll inf=(ll)1e18;
      ll dp[1005][1005];
          ll w[1005],v[1005];
          ll n,m;
      ll solve(ll i,ll w1)
      {
          if(w1<0)
          {
              return -1e9;
          }
          if(i>n)
          {
              return 0;
          }
         ll &ans = dp[i][w1];
        if(ans!=-1)
        {
            return ans;
        }
        ll t = max(solve(i+1,w1),v[i]+solve(i+1,w1-w[i])); 
        return ans=t;
      }
            int main()
            {
                fast
                // SieveOfEratosthenes();
               
            //    ct
    			 { 
                    ll n;
                    cin>>n;
                    ll dp[n][3];
                    foe(i,0,n)
                    {
                        cin>>dp[i][0]>>dp[i][1]>>dp[i][2];
                        if(i)
                        {
                            dp[i][0]+=max(dp[i-1][1],dp[i-1][2]);
                            dp[i][2]+=max(dp[i-1][1],dp[i-1][0]);
                            dp[i][1]+=max(dp[i-1][0],dp[i-1][2]);
                        }
                    }
                    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
                 }
            }
            

Measured memory_bytes: 2560