Petya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given $$$n$$$ days from Petya's live and you have to determine what happened with his flower in the end.The flower grows as follows:   If the flower isn't watered for two days in a row, it dies.  If the flower is watered in the $$$i$$$-th day, it grows by $$$1$$$ centimeter.  If the flower is watered in the $$$i$$$-th and in the $$$(i-1)$$$-th day ($$$i > 1$$$), then it grows by $$$5$$$ centimeters instead of $$$1$$$.  If the flower is not watered in the $$$i$$$-th day, it does not grow. At the beginning of the $$$1$$$-st day the flower is $$$1$$$ centimeter tall. What is its height after $$$n$$$ days?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains the only integer $$$n$$$ ($$$1 \leq n \leq 100$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i = 0$$$ or $$$a_i = 1$$$). If $$$a_i = 1$$$, the flower is watered in the $$$i$$$-th day, otherwise it is not watered.

For each test case print a single integer $$$k$$$ — the flower's height after $$$n$$$ days, or $$$-1$$$, if the flower dies.

package main

import "fmt"

func solve() {
	var n int
	fmt.Scan(&n)

	var a [101]int
	for j := 0; j < n; j++ {
		fmt.Scan(&a[j]);
	}

	s := 1
	for j := 0; j < n; j++ {
		if j > 0 && a[j] == 0 && a[j - 1] == 0 {
			fmt.Println(-1);
			return;
		}
		if j > 0 && a[j] == 1 && a[j - 1] == 1 {
			s += 5
		} else {
			if a[j] == 1 {
				s++;
			}
		}
	}
	fmt.Println(s)
}

func main() {
	var t int

	fmt.Scan(&t)

	for i := 0; i < t; i++ {
	    solve()
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		nw, dead, p, hgt := false, false, 0, 1
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &p)
			if p == 0 && nw {
				dead = true
			}
			if p == 0 {
				nw = true
			} else {
				if j > 0 && !nw && p == 1 {
					hgt += 5
				} else if j == 0 && p == 1 || nw && p == 1 {
					hgt++
				}
				nw = false
			}
		}
		if dead {
			fmt.Fprintln(w, -1)
		} else {
			fmt.Fprintln(w, hgt)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int, a []int) int {
	b := 1
	for i := range a {
		if a[i] == 0 {
			if i > 0 && a[i-1] == 0 {
				return -1
			}
		} else if i > 0 && a[i-1] == 1 {
			b += 5
		} else {
			b++
		}
	}
	return b
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, a))
	}
}

package main

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

const MOD int64 = 1000000007

var n int

var a[]int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n)

		a = make([]int, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(read, &a[j])
		}

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() int {
	height := 1

	var prev = -1

	for i := 0; i < n; i++ {

		if prev == -1 {
			if a[i] == 1  {
				height++
			}

		} else {
			if prev == 1 {
				if a[i] == 1 {
					height += 5
				}
			} else if prev == 0 {

				if a[i] == 0 {
					return -1
				} else {
					height ++
				}
			}

		}

		prev = a[i]
	}

	return height

}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

/*
5
4
0 1 1 0
1
1
2
1 1
3
0 0 1
3
1 1 1
---
7
2
7
-1
12
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	bld := strings.Builder{}

	var t = 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		died := false
		ans := 1

		prev := 0

		for i := 0; i < n; i++ {
			var num int
			scanf("%d", &num)

			switch {
			case num == 1 && prev == 0:
				ans++
			case num == 1 && prev == 1:
				ans += 5
			case num == 0 && prev == 0 && i == 0:
				// do nothing
			case num == 0 && prev == 0:
				died = true
			}

			prev = num
		}
		scanf("\n")

		if died {
			ans = -1
		}

		fmt.Fprintln(&bld, ans)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	fst int
	snd int
}

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type CF1591A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1591A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1591A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1591A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1591A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1591A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1591A
Date: 12/12/21
User: epradere
URL: https://codeforces.com/contest/1591/problem/0
Problem: CF1591A
**/
func (in *CF1591A) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		size := 1
		live := true
		lastDay := 0
		for i := 0; i < n; i++ {
			day := in.NextInt()
			if day > 0 {
				size++
			}
			if i > 0 {
				if lastDay == 1 && day == 1 {
					size += 4
				}
				if day == 0 && lastDay == 0 {
					live = false
				}
			}
			lastDay = day
		}

		if !live {
			fmt.Println(-1)
		} else {
			fmt.Println(size)
		}

	}
}

func NewCF1591A(r *bufio.Reader) *CF1591A {
	return &CF1591A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1591A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		solve()
	}
}
func solve() {
	n := ReadInt()
	a := ReadInts(n)
	ans := 1
	for i := 0; i < n; i++ {
		if a[i] == 1 {
			if i > 0 && a[i-1] == 1 {
				ans += 5
			} else {
				ans++
			}
		} else {
			if i > 0 && a[i-1] == 0 {
				println(-1)
				return
			}
		}
	}
	println(ans)
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func ReadString() (s string) { fmt.Fscan(_r, &s); return }
func ReadInt() (i int)       { fmt.Fscan(_r, &i); return }
func ReadInts(n int) (a []int) {
	for ; n > 0; n-- {
		a = append(a, ReadInt())
	}
	return
}
func print(a ...interface{})   { fmt.Fprint(_w, a...) }
func println(a ...interface{}) { fmt.Fprintln(_w, a...) }
func prints(s []int)           { v := fmt.Sprint(s); println(v[1 : len(v)-1]) }

package main

import "fmt"

func main() {
	var t int

	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)

		var a [101]int
		for j := 0; j < n; j++ {
			fmt.Scan(&a[j]);
		}

		s := 1
		for j := 0; j < n; j++ {
			if j > 0 && a[j] == 0 && a[j - 1] == 0 {
				fmt.Println(-1);
				return;
			}
			if j > 0 && a[j] == 1 && a[j - 1] == 1 {
				s += 5
			} else {
				if a[j] == 1 {
					s++;
				}
			}
		}
		fmt.Println(s)
	}
}


Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor of all numbers from this segment was maximal possible. Help him with that.The xor operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java.

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.

Print a single integer — the required maximal xor of a segment of consecutive elements.

NoteIn the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one.The second sample contains only one optimal segment, which contains exactly one array element (element with index three).

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)
func main() {
	var n int
	ans:=0
	var a [110]int
	fmt.Scan(&n)
	input := bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	for i:=1;i<=n;i++ {
		input.Scan()
		bb,_:=strconv.Atoi(input.Text())
		a[i]=bb
		//fmt.Scan(&a[i])
	}
	k:=0
	for i:=1;i<=n;i++ {
		k=0
		for j:=i;j<=n;j++ {
			k^=a[j]
			if k>ans {
				ans=k
			}
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

func max(a, b int) int {
	if a>b {
		return a
	} else {
		return b
	}
}

func main() {
	var n, mx int
	fmt.Scan(&n)
	input := make([]int, n)
	for i:=0; i<n; i++ {
		fmt.Scan(&input[i])
		mx = max(input[i], mx)
	}
	for i:=0; i<n; i++ {
		for j:=i+1; j<n; j++ {
			cur := input[i]
			for k:=i+1; k<=j; k++ {
				cur = cur ^ input[k]
			}
			mx = max(cur, mx)
		}
	}
	fmt.Println(mx)
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = scanInt(scanner)
	}
	best := array[0]
	for i := 0; i < n; i++ {
		x := 0
		for j := i; j < n; j++ {
			x ^= array[j]
			if x > best {
				best = x
			}
		}
	}
	writer.WriteString(fmt.Sprintf("%d\n", best))
}

package main

import "fmt"

func main() {
    max := func(a,b int) int { if a > b { return a } else { return b } }
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ { fmt.Scan(&a[i]) }
    ans := 0
    for i := 0; i < n; i++ {
        tmp := 0
        for j := i; j < n ;j++ {
            tmp ^= a[j]
            ans = max(ans,tmp)
        }
    }
    fmt.Println(ans)
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = scanInt(scanner)
	}
	best := array[0]
	for i := 0; i < n; i++ {
		x := array[i]
		for j := i+1; j < n; j++ {
			x ^= array[j]
		}
		if x > best {
			best = x
		}
	}
	writer.WriteString(fmt.Sprintf("%d\n", best))
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = scanInt(scanner)
	}
	best := array[0]
	for i := 0; i < n; i++ {
		x := array[i]
		for j := i+1; j < n; j++ {
			x ^= array[j]
			if x > best {
				best = x
			}
		}
	}
	writer.WriteString(fmt.Sprintf("%d\n", best))
}

package main

import "fmt"

func main() {
    max := func(a,b int) int { if a > b { return a } else { return b } }
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ { fmt.Scan(&a[i]) }
    ans := 0
    for i := 0; i < n; i++ {
        tmp := a[i]
        for j := i+1; j < n ;j++ {
            tmp ^= a[j]
        }
        ans = max(ans,tmp)
    }
    fmt.Println(ans)
}

package main

import "fmt"

func main() {
    max := func(a,b int) int { if a > b { return a } else { return b } }
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ { fmt.Scan(&a[i]) }
    ans := 0
    for i := 0; i < n; i++ {
        tmp := a[i]
        for j := i+1; j < n ;j++ {
            tmp ^= a[j]
            ans = max(ans,tmp)
        }
    }
    fmt.Println(ans)
}