package main import ( "bufio" "fmt" "os" "strconv" ) func g(n int) int { return n * (n + 1) / 2 } func main() { var sc = bufio.NewScanner(os.Stdin) sc.Split(bufio.ScanWords) sc.Scan() N, _ := strconv.Atoi(sc.Text()) A := make([]bool, N) for i := 0; i < N; i++ { sc.Scan() A[i] = sc.Text() == "1" } count := g(N) l := 0 for _, b := range A { if b { l++ } else if l > 0 { count -= g(l) l = 0 } } if l > 0 { count -= g(l) } fmt.Println(count) }