let n = stdin.ReadLine() |> int let a = stdin.ReadLine().Split() let mutable x = 0L let mutable result = 0L for i = 0 to n - 1 do if a.[i] = "1" then x <- x + 1L else result <- result + int64 (n - i) * (x + 1L) x <- 0L result |> printfn "%d"