← Home
For problem statement at 0-999/400-499/460-469/465/problemB.txt this is a correct solution, but verifier at 0-999/400-499/460-469/465/verifierB.go ends with All tests passed can you fix the verifier? package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(in, &n)

	unread := 0
	groups := 0
	prev := 0

	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(in, &x)
		if x == 1 {
			unread++
			if prev == 0 {
				groups++
			}
		}
		prev = x
	}

	if unread == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(unread + groups - 1)
	}
}