let step (am, bm, cm) (a, b, c) =
    let am' = a + max bm cm in
    let bm' = b + max am cm in
    let cm' = c + max am bm in
    (am', bm', cm')

let () =
    let n = Scanf.scanf "%d " (fun n -> n) in
    let rec loop n (am, bm, cm) =
        if n = 0 then max am (max bm cm)
        else
            Scanf.scanf "%d %d %d " @@ fun a b c ->
                loop (n - 1) (step (am, bm, cm) (a, b, c))
    in Printf.printf "%d\n" (loop n (0, 0, 0))
