let rec f l p n = if p + 3 < List.length l then let a = (l.[p+0] + l.[p+2]) let c = (l.[p+0] + l.[p+3]) let b = (l.[p+1] + l.[p+3]) let d = List.max [a;b;c] let e = if d = a || d = c then 0 else 1 f l (p+2+e) (n+l.[p+e]) elif p + 2 < List.length l then n + (max (l.[p] + l.[p+2]) l.[p+1]) elif p + 1 < List.length l then n + (max l.[p] l.[p+1]) elif p < List.length l then n + l.[p] else n stdin.ReadLine() |> ignore let l = stdin.ReadLine().Split([|' '|]) |> Seq.map (int) |> Seq.toList f l 0 0 |> (printfn "%d")