open Scanf open Printf let readint () = scanf " %d" (fun x -> x) let readstr () = scanf " %s" (fun x -> x) let readint2 () = scanf " %d %d" (fun x y -> x, y) let stoa s = Array.init (String.length s) (String.get s) let atos a = String.init (Array.length a) (Array.get a) let inf = max_int / 4 let min3 x y z = min x (min y z) let f (x, y, z) (c, d) = let x' = c + min3 (x + c) (y + c + d) (z + d) in let y' = c + min x (y + d) in let z' = c + min3 (x + c) (y + c + d) (z + d) in x', y', z' let () = let n = readint () in let _, _, ans = Array.init n (fun _ -> readint2 ()) |> Array.fold_left f (0, inf, inf) in printf "%d\n" ans