#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long
#define M 1000000007
#define MAX 100005
int A[MAX], tree[4 * MAX];
int power(int x, int p)
{
    if (p == 0)
        return 1;
    int y = power(x, p / 2);
    y *= y;
    y %= M;
    if (p % 2 == 0)
        return y;
    y *= x;
    y %= M;
    return y;
}
bool prime[10000001];
void sieveFunction(int maxLimit)
{
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = false;
    for (int i = 2; i <= maxLimit; i++)
    {
        if (prime[i])
        {
            for (int j = 2 * i; j < maxLimit; j += i)
                prime[j] = false;
        }
    }
}
void build(int node, int start, int end)
{
    if (start == end)
        //Leaf node will have a single element
        tree[node] = start;
    else
    {
        int mid = (start + end) / 2;
        //Recurse on the left child
        build(2 * node, start, mid);
        //Recurse on the right child
        build(2 * node + 1, mid + 1, end);
        // Internal node will have the sum of both of its children
        tree[node] = tree[2 * node] + tree[2 * node + 1];
    }
}
void update(int node, int start, int end, int idx, int val)
{
    if (start == end)
    {
        //Leaf Node
        A[idx] = val;
        tree[node] += val;
    }
    else
    {
        int mid = (start - end) / 2 + end;
        if (start <= idx && idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update(2 * node, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update(2 * node + 1, mid + 1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = tree[2 * node] + tree[2 * node + 1];
    }
}
int query(int node, int start, int end, int l, int r)
{
    if (r < start || l > end)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if (l <= start && end <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query(2 * node, start, mid, l, r);
    int p2 = query(2 * node + 1, mid + 1, end, l, r);
    return p1 + p2;
}
//Longest Sum Contiguous Subarray (Kadane's Algorithm)
int maxSubArraySum(int a[], int start, int end)
{
    int max_so_far = 0, max_ending_here = 0;
    for (int i = start; i < end; i++)
    {
        max_ending_here = max_ending_here + a[i];
        if (max_ending_here < 0)
            max_ending_here = 0;
        /* Do not compare for all elements. Compare only
when max_ending_here > 0
*/
        else if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;
    }
    return max_so_far;
}
int findMin(int a[], int b[], int c[], int n)
{
    int cost[n][3];
    cost[0][0] = max(b[0], c[0]);
    cost[0][1] = max(a[0], c[0]);
    cost[0][2] = max(a[0], b[0]);

    for (int i = 1; i < n; i++)
    {
        cost[i][0] = max(c[i] + cost[i - 1][2], b[i] + cost[i - 1][1]);
        cost[i][1] = max(a[i] + cost[i - 1][0], c[i] + cost[i - 1][2]);
        cost[i][2] = max(a[i] + cost[i - 1][0], b[i] + cost[i - 1][1]);
    }
    return max(max(cost[n - 1][0], cost[n - 1][1]), cost[n - 1][2]);
}

signed main()
{

    rootdada;
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    rep(i, 0, n)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    cout << findMin(a, b, c, n) << endl;
}

Measured memory_bytes: 4992