let rec solve n =
    let rec _solve n a b c =
        if n <= 0
        then max a (max b c)
        else
            let (x, y, z) = Scanf.scanf " %d %d %d" (fun x y z -> (x, y, z)) in
            let a1 = x + max b c in
            let b1 = y + max c a in
            let c1 = z + max a b in
            _solve (n - 1) a1 b1 c1 in
    _solve n 0 0 0;;


let () =
    let n = Scanf.scanf "%d" (fun x -> x) in
    print_int (solve n);
    print_newline ();;
