let mcm p n =
  let m = Array.make_matrix (n + 1) (n + 1) max_int in
  let rec init i =
    if i <= n then begin
      m.(i).(i) <- 0;
      init (i + 1)
    end in
  init 1;
  let rec doit = function
    | (l, _) when l > n -> m.(1).(n)
    | (l, i) when i > n - l + 1 -> doit (l + 1, 1)
    | (l, i) ->
      let j = i + l - 1 in
      let rec aux k =
        if k < j then begin
          m.(i).(j) <- min m.(i).(j) (m.(i).(k) + m.(k+1).(j) + p.(i-1)*p.(k)*p.(j));
          aux (k + 1)
        end in
      aux i;
      doit (l, i + 1) in
  doit (2, 1)


let () =
  let n = read_int () in
  let p = Array.make (n + 1) 0 in
  let rec read i =
    if i < n then begin
      let (r, c) = Scanf.scanf "%d %d\n" (fun r c -> (r, c)) in
      p.(i) <- r; p.(i+1) <- c;
      read (i + 1)
    end in
  read 0;
  Printf.printf "%d\n" (mcm p n)