/** 	Author: Apoorva Mittal  **/
    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    #define endl "\n"
    #define nl "\n"
    #define vi vector<int>
    #define vvi vector<vector<int>>
    #define vii vector<pair<int, int>>
    #define rep(i, a, b) for (int i = a; i < b; i++)
    #define repD(i, a, b) for (int i = a; i >= b; i--)
    #define speed                     \
        ios_base::sync_with_stdio(0); \
        cin.tie(0);                   \
        cout.tie(0)
    #define init(i, k) memset(i, k, sizeof i)
    #define pb push_back
    #define pii pair<int, int>
    #define ff first
    #define ss second
    #define all(a) a.begin(), a.end()
    #define inp(a) rep(i, 0, a.size()) cin >> a[i];
    #define out(a)                               \
        cout << #a << ": "<<endl;                      \
        rep(i, 0, a.size()) cout << a[i] << " "; \
        cout << endl;
    #define out2d(a)                \
        cout << #a << ": " << endl; \
        rep(i, 0, a.size())         \
        {                           \
            rep(j, 0, a[0].size())  \
                    cout            \
                << a[i][j] << " ";  \
            cout << endl;           \
        }
    #define flush fflush(stdout);
    #define lb lower_bound
    #define ub upper_bound
    #define maxe *max_element
    #define mine *min_element
    #define umap unordered_map
    #define uset unordered_set
    #define mset multiset
    #define pqueue priority_queue
    #define precise(x) cout << fixed << showpoint << setprecision(x);
    #define setbit(x) __builtin_popcountll(x)
    #define gcd(a, b) __gcd(a, b)
    #define deb(x) cout << #x << " " << x << endl;
    #define Y "YES"
    #define N "NO"
    const int mod = 1e9 + 7;
    // ====== Useful functions begin ======
    inline int add(int a, int b) { return ((a % mod) + (b % mod)) % mod; }
    inline int sub(int a, int b) { return ((a % mod) - (b % mod) + mod) % mod; }
    inline int mul(int a, int b) { return ((a % mod) * (b % mod)) % mod; }
    // ====== Useful functions end ======
    const int inf = 1e18;
    const int maxn = 1e3 + 5;

    //--------------------------------------------------------------------------------------------------------------------------------

    //--------------------------------------------------------------------------------------------------------------------------------

    void solve()
    {
        int n;
        cin>>n;
        vector<array<int,3>>arr(n);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<3;j++)
            {
                cin>>arr[i][j];
            }
        }
        vector<array<int,3>>dp(n);
        dp[n-1] = arr[n-1];
        for(int i=n-2;i>=0;i--)
        {
            
            for(int j=0;j<3;j++)
            {
                int &ans = dp[i][j];
                ans=-1;
                for(int k=0;k<3;k++)
                {
                    if(k!=j)
                    {
                        ans = max(ans,dp[i+1][k] + arr[i][j]);
                    }
                }
            }
        }
        int ans = max({dp[0][0], dp[0][1],dp[0][2]});
        cout<<ans<<endl;
    }
    signed main()
    {
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);

        speed;
        int t = 1;
        // cin >> t;

        for (int tt = 1; tt <= t; tt++)
        {
            // cout<<"Case #"<<tt<<": ";
            solve();
        }
    }

Measured memory_bytes: 4992