You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters.

Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$.

NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer.

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func checkDiverce(s string) string {
	if len(s) < 2 {
		return ""
	}
	for index, char := range s[1:] {
		// if previous char != current, return previous+current
		if s[index] != byte(char) {
			return fmt.Sprintf("%c%c", s[index], char)
		}
	}
	return ""
}

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()

	// var a, b int
	var input string
	var n int
	scanf("%d\n", &n)
	scanf("%s", &input)
	if answer := checkDiverce(input); answer != "" {
		printf("YES\n%s\n", answer)
	} else {
		printf("NO\n")
	}
}

package main

import (
    "fmt"
    "os"
)

func main() {
    var s string
    var d int
    fmt.Scanf("%d\n%s", &d, &s)
    for i := range s {
        if i == 0 {
            continue
        }
        if s[i] != s[i - 1] {
            fmt.Println("YES")
            fmt.Print(string(s[i-1]), string(s[i]))
            os.Exit(0)
        }
    }
    fmt.Print("NO")
}

package main

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

func isDiffrentSubString(str string) bool {
	return str[0] != str[1];
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	scanner.Scan();
	str := scanner.Text()

	resultSubstring := ""

	if len(str) > 1 {
		for i:=0; i + 2 <= len(str); i++{
			substring := str[i:i+2]
			if isDiffrentSubString(substring){
				resultSubstring = substring
				break
			}
		}
	}

	if resultSubstring == "" {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		fmt.Println(resultSubstring)
	}
}

package main

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

func main() {

	sc := bufio.NewReader(os.Stdin)
	var c int
	var s string
	fmt.Fscanf(sc,"%d\n%s",&c,&s)
	l := len(s)

	for i:= 1;i<l;i++ {
		if(s[i-1] != s[i]) {
			fmt.Println("Yes")
			fmt.Printf("%c%c",s[i-1],s[i])
			os.Exit(0)
		}
	}
	fmt.Println("No")
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	S := io.NextLine()

	for i := 1; i < N; i++ {
		if S[i-1] != S[i] {
			io.Println("YES")
			io.Println(S[i-1 : i+1])
			return
		}
	}
	io.Println("NO")
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func main() {
	readLine()
	line := readLine()
	isDiverse := false
	for i := 0; i < (len(line) - 1); i++ {
		if line[i] != line[i+1] {
			fmt.Println("YES")
			fmt.Println(line[i : i+2])
			isDiverse = true
			break
		}
	}
	if !isDiverse {
		fmt.Println("NO")
	}
}

var scanner = bufio.NewScanner(os.Stdin)

func readLine() string {
	scanner.Scan()
	return scanner.Text()
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	s := scanner.Text()

	for i := 0; i < n-1; i++ {
		if s[i] != s[i+1] {
			fmt.Println("YES")
			fmt.Println(string(s[i]) + string(s[i+1]))
			return
		}
	}

	fmt.Println("NO")
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func checkDiverce(s string) string {
	if len(s) <= 2 {
		return ""
	}
	for index, char := range s[1:] {
		// if previous char != current, return previous+current
		// printf("%c\n", s[index])
		if s[index] != byte(char) {
			return fmt.Sprintf("%c%c", s[index], char)
		}
	}
	return ""
}

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()

	// var a, b int
	var input string
	scanf("%s", &input)
	if answer := checkDiverce(input); answer != "" {
		printf("YES\n%s\n", answer)
	} else {
		printf("NO\n")
	}
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func checkDiverce(s string) string {
	if len(s) <= 2 {
		return ""
	}
	for index, char := range s[1:] {
		// if previous char != current, return previous+current
		// printf("%c\n", s[index])
		if s[index] != byte(char) {
			return fmt.Sprintf("%c%c", s[index], char)
		}
	}
	return ""
}

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()

	// var a, b int
	var input string
	var n int
	scanf("%d\n", &n)
	scanf("%s", &input)
	if answer := checkDiverce(input); answer != "" {
		printf("YES\n%s\n", answer)
	} else {
		printf("NO\n")
	}
}

package main

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

func isDiffrentSubString(str string) bool {
	return str[0] != str[1] && str[0] != str[2] && str[1] != str[2]
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	scanner.Scan();
	str := scanner.Text()

	resultSubstring := ""

	if len(str) > 2 {
		for i:=0; i + 3 <= len(str); i++{
			substring := str[i:i+3]
			if isDiffrentSubString(substring){
				resultSubstring = substring
				break
			}
		}
	}

	if resultSubstring == "" {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		fmt.Println(resultSubstring)
	}
}

package main

import ("fmt";"os")

func main() {
	var c int
	var s string
	fmt.Scan(&c)
	fmt.Scanln(&s)
	l := len(s)

	for i:= 1;i<l;i++ {
		if(s[i-1] != s[i]) {
			fmt.Println("Yes")
			fmt.Printf("%c%c",s[i-1],s[i])
			os.Exit(0)
		}
	}
	fmt.Println("No")
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	S := io.NextLine()

	for i := range S {
		freq := make(map[byte]int)
		for j := i; j < N; j++ {
			freq[S[j]]++
			if diverse(freq, j-i+1) {
				io.Println("YES")
				io.Println(S[i : j+1])
				return
			}
		}
	}
	io.Println("NO")
}

func diverse(freq map[byte]int, w int) bool {
	for _, v := range freq {
		if (v << 1) >= w {
			return false
		}
	}
	return true
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can :  Press the ' + ' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes x + k. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes k + 1. This button can only be pressed when x is a perfect square, i.e. x = m2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the game — he wants to reach level n + 1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the ' + ' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level n + 1, but not necessarily a sequence minimizing the number of presses.

The first and only line of the input contains a single integer n (1 ≤ n ≤ 100 000), denoting that ZS the Coder wants to reach level n + 1.

Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the ' + ' button before pressing the '' button at level i.  Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.

NoteIn the first sample case:On the first level, ZS the Coder pressed the ' + ' button 14 times (and the number on screen is initially 2), so the number became 2 + 14·1 = 16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 16 times, so the number becomes 4 + 16·2 = 36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the ' + ' button 46 times, so the number becomes 6 + 46·3 = 144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the ' + ' button 10 times on the third level before levelling up does not work, because the number becomes 6 + 10·3 = 36, and when the '' button is pressed, the number becomes  and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the ' + ' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2 + 999999999999999998·1 = 1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 44500000000 times, so the number becomes 109 + 44500000000·2 = 9·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.

package main

import "fmt"
import "bufio"
import "os"

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n, a, x, k int64
	fmt.Fscanf(bufin, "%d\n", &n)

	a = 2
	for k = 1; k <= n; k++ {
		x = k*(k+1)*(k+1) - a/k
		a = k * (k + 1)
		fmt.Fprintf(bufout, "%d\n", x)
	}
}

package main

import "fmt"
import "bufio"
import "os"

var bufin *bufio.Reader
var bufout *bufio.Writer

var p []int64
var np int

func sqr(x int64) int64 {
	return x * x
}

func multiple(k int64) (int64, int64) {
	ret := int64(1)
	m := int64(1)

	for i := 0; i < np && sqr(p[i]) <= k; i++ {
		cnt := 0
		for k%p[i] == 0 {
			cnt++
			k /= p[i]
		}
		if (cnt > 0) && (cnt%2 == 1) {
			ret *= p[i]
			cnt++
		}
		cnt /= 2
		for j := 0; j < cnt; j++ {
			m *= p[i]
		}
	}

	if k > 1 {
		ret *= k
		m *= k
	}

	return ret, m
}

func find(a int64, k int64) (int64, int64) {
	_, m := multiple(k)
	b := m * (k + 1)
	x := m*m/k*(k+1)*(k+1) - a/k
	return x, b
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	n := 100002
	prime := make([]bool, n+1)
	for i := 0; i <= n; i++ {
		prime[i] = true
	}
	prime[0] = false
	prime[1] = false
	for i := 2; i*i <= n; i++ {
		if prime[i] {
			for j := i * i; j <= n; j += i {
				prime[j] = false
			}
		}
	}

	for i := 2; i < n; i++ {
		if prime[i] {
			p = append(p, int64(i))
		}
	}
	np = len(p)

	res := make([]int64, n+1)
	var k, a, x int64

	a = 2
	for k = 1; k <= int64(n); k++ {
		x, a = find(a, k)
		res[k] = x
	}

	fmt.Fscanf(bufin, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fprintf(bufout, "%d\n", res[i])
	}
}

package main

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

func gcd(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int64) int64 {
	return (a / gcd(a, b)) * b
}

func main() {
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int64
	fmt.Scan(&n)

	var x int64 = 2
	var k int64 = 1
	for k <= n {
		lcm := lcm(k, k+1)
		ans := (lcm/k)*lcm - (x / k)
		writer.WriteString(strconv.FormatInt(ans, 10))
		writer.WriteByte('\n')
		x = lcm
		k++
	}
}

package main

import "fmt"

func main() {
    var n, m, y, k int64
    fmt.Scan(&n)
    m = 2
    for k = 1; k <= n; k++ {
        y = (k+1)*(k+1)*k - m
        m = k
        fmt.Println(y)
    }
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/715/A

package main

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

func Solve(n int64) []int64 {
	ans := make([]int64, n)
	x := int64(2)
	for i := int64(1); i <= n; i++ {
		ans[i-1] = i*(i+1)*(i+1) - x/i
		x = i * (i + 1)
	}
	return ans
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int64
	fmt.Fscanf(reader, "%d\n", &n)

	for _, elem := range Solve(n) {
		fmt.Fprintf(writer, "%d\n", elem)
	}
}

package main

import "fmt"
import "bufio"
import "os"

var bufin *bufio.Reader
var bufout *bufio.Writer

var p []int64
var np int

func sqr(x int64) int64 {
	return x * x
}

func multiple(k int64) (int64, int64) {
	ret := int64(1)
	m := int64(1)

	for i := 0; i < np && sqr(p[i]) <= k; i++ {
		cnt := 0
		for k%p[i] == 0 {
			cnt++
			k /= p[i]
		}
		if (cnt > 0) && (cnt%2 == 1) {
			ret *= p[i]
			cnt++
		}
		cnt /= 2
		for j := 0; j < cnt; j++ {
			m *= p[i]
		}
	}

	if k > 1 {
		ret *= k
		m *= k
	}

	return ret, m
}

func find(a int64, k int64) (int64, int64) {
	_, m := multiple(k)
	b := m * (k + 1)
	x := b/k*b - a/k
	return x, b
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	n := 100002
	prime := make([]bool, n+1)
	for i := 0; i <= n; i++ {
		prime[i] = true
	}
	prime[0] = false
	prime[1] = false
	for i := 2; i*i <= n; i++ {
		if prime[i] {
			for j := i * i; j <= n; j += i {
				prime[j] = false
			}
		}
	}

	for i := 2; i < n; i++ {
		if prime[i] {
			p = append(p, int64(i))
		}
	}
	np = len(p)

	res := make([]int64, n+1)
	var k, a, x int64

	a = 2
	for k = 1; k <= int64(n); k++ {
		x, a = find(a, k)
		res[k] = x
	}

	fmt.Fscanf(bufin, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fprintf(bufout, "%d\n", res[i])
	}
}


Arkady owns a non-decreasing array $$$a_1, a_2, \ldots, a_n$$$. You are jealous of its beauty and want to destroy this property. You have a so-called XOR-gun that you can use one or more times.In one step you can select two consecutive elements of the array, let's say $$$x$$$ and $$$y$$$, remove them from the array and insert the integer $$$x \oplus y$$$ on their place, where $$$\oplus$$$ denotes the bitwise XOR operation. Note that the length of the array decreases by one after the operation. You can't perform this operation when the length of the array reaches one.For example, if the array is $$$[2, 5, 6, 8]$$$, you can select $$$5$$$ and $$$6$$$ and replace them with $$$5 \oplus 6 = 3$$$. The array becomes $$$[2, 3, 8]$$$.You want the array no longer be non-decreasing. What is the minimum number of steps needed? If the array stays non-decreasing no matter what you do, print $$$-1$$$.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the initial length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that $$$a_i \le a_{i + 1}$$$ for all $$$1 \le i < n$$$.

Print a single integer — the minimum number of steps needed. If there is no solution, print $$$-1$$$.

NoteIn the first example you can select $$$2$$$ and $$$5$$$ and the array becomes $$$[7, 6, 8]$$$.In the second example you can only obtain arrays $$$[1, 1]$$$, $$$[3, 3]$$$ and $$$[0]$$$ which are all non-decreasing.In the third example you can select $$$1$$$ and $$$2$$$ and the array becomes $$$[3, 4, 6, 20]$$$. Then you can, for example, select $$$3$$$ and $$$4$$$ and the array becomes $$$[7, 6, 20]$$$, which is no longer non-decreasing.

package main

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

func main() {
	defer _w.Flush()
	n := ReadInt()
	a := ReadInts(n)
	println(solve(n, a))
}

const Inf = 1 << 29

func solve(n int, a []int) int {
	if n > 100 {
		return 1
	}
	ans := Inf
	for i := 0; i < n-1; i++ {
		x := 0
		for l := i; l >= 0; l-- {
			x ^= a[l]
			y := 0
			for r := i + 1; r < n; r++ {
				y ^= a[r]
				if x > y {
					ans = Min(ans, r-l-1)
					break
				}
			}
		}
	}
	if ans == Inf {
		return -1
	}
	return ans
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

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

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func printInts(a ...int)                { s := fmt.Sprint(a); println(s[1 : len(s)-1]) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	defer _w.Flush()
	n := ReadInt()
	a := ReadInts(n)
	println(solve(n, a))
}

const Inf = 1 << 29

func solve(n int, a []int) int {
	// l := make([]int, n+1)
	// r := make([]int, n+1)
	// for i := 0; i < n; i++ {
	// 	l[i+1] = l[i] ^ a[i]
	// }
	// for i := n-1; i >= 0; i-- {
	// 	r[i] = r[i+1] ^ a[i]
	// }
	//
	// for i := 0; i < n-1; i++ {
	// 	if a[i]
	// }

	ans := Inf
	{
		r := 0
		sum := 0
		for l := 0; l < n-1; l++ {
			for r < n-1 && sum^a[r] <= a[r+1] {
				sum ^= a[r]
				r++
			}
			if r < n-1 && sum^a[r] > a[r+1] {
				ans = Min(ans, r-l)
			}
			if l == r {
				r++
			} else {
				sum ^= a[l]
			}
		}
	}

	i := 0
	j := n - 1
	for i < j {
		a[i], a[j] = a[j], a[i]
		i++
		j--
	}
	{
		r := 0
		sum := 0
		for l := 0; l < n-1; l++ {
			for r < n-1 && sum^a[r] >= a[r+1] {
				sum ^= a[r]
				r++
			}
			if r < n-1 && sum^a[r] < a[r+1] {
				ans = Min(ans, r-l)
			}
			if l == r {
				r++
			} else {
				sum ^= a[l]
			}
		}
	}

	if ans == Inf {
		return -1
	} else {
		return ans
	}
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

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

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func printInts(a ...int)                { s := fmt.Sprint(a); println(s[1 : len(s)-1]) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}


We get more and more news about DDoS-attacks of popular websites.Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds $$$100 \cdot t$$$, where $$$t$$$ — the number of seconds in this time segment. Arseny knows statistics on the number of requests per second since the server is booted. He knows the sequence $$$r_1, r_2, \dots, r_n$$$, where $$$r_i$$$ — the number of requests in the $$$i$$$-th second after boot. Determine the length of the longest continuous period of time, which Arseny considers to be a DDoS-attack. A seeking time period should not go beyond the boundaries of the segment $$$[1, n]$$$.

The first line contains $$$n$$$ ($$$1 \le n \le 5000$$$) — number of seconds since server has been booted. The second line contains sequence of integers $$$r_1, r_2, \dots, r_n$$$ ($$$0 \le r_i \le 5000$$$), $$$r_i$$$ — number of requests in the $$$i$$$-th second.

Print the only integer number — the length of the longest time period which is considered to be a DDoS-attack by Arseny. If it doesn't exist print 0.

// Brute force. Too slow
package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func read_int_array(array_length int) []int {
    input_array := make([]int, array_length)
    for i := 0; i < array_length; i++ {
        fmt.Fscan(reader, &input_array[i])
    }
    return input_array
}

func main() {
    var n int
    fmt.Fscanln(reader, &n)

    input_array := read_int_array(n)
    res := 0
    for i:=0; i < n; i++ {
        sum := 0
        num_elems := 1
        for j := i; j < n; j++ {
            sum += input_array[j]
            if sum > 100 * num_elems {
                if num_elems > res {
                    res = num_elems
                }
            }
            num_elems++
        }
    }
    fmt.Println(res)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	Fscan(in, &n)

	arr := make([]int, n)
	for i := range arr {
		Fscan(in, &arr[i])
	}
	ans := 0
	for i := 0; i < n; i++ {
		sum, cnt := 0, 1
		for j := i; j < n; j++ {
			sum += arr[j]
			if sum > 100*cnt {
				if cnt > ans {
					ans = cnt
				}
			}
			cnt++
		}
	}
	Print(ans)
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. Friends asked you to make the greatest common divisor (GCD) of all numbers in the array equal to $$$1$$$. In one operation, you can do the following: Select an arbitrary index in the array $$$1 \leq i \leq n$$$; Make $$$a_i = \gcd(a_i, i)$$$, where $$$\gcd(x, y)$$$ denotes the GCD of integers $$$x$$$ and $$$y$$$. The cost of such an operation is $$$n - i + 1$$$.You need to find the minimum total cost of operations we need to perform so that the GCD of the all array numbers becomes equal to $$$1$$$.

Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 5\,000$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 20$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.

For each test case, output a single integer — the minimum total cost of operations that will need to be performed so that the GCD of all numbers in the array becomes equal to $$$1$$$. We can show that it's always possible to do so.

NoteIn the first test case, the GCD of the entire array is already equal to $$$1$$$, so there is no need to perform operations.In the second test case, select $$$i = 1$$$. After this operation, $$$a_1 = \gcd(2, 1) = 1$$$. The cost of this operation is $$$1$$$.In the third test case, you can select $$$i = 1$$$, after that the array $$$a$$$ will be equal to $$$[1, 4]$$$. The GCD of this array is $$$1$$$, and the total cost is $$$2$$$.In the fourth test case, you can select $$$i = 2$$$, after that the array $$$a$$$ will be equal to $$$[3, 2, 9]$$$. The GCD of this array is $$$1$$$, and the total cost is $$$2$$$.In the sixth test case, you can select $$$i = 4$$$ and $$$i = 5$$$, after that the array $$$a$$$ will be equal to $$$[120, 60, 80, 4, 5]$$$. The GCD of this array is $$$1$$$, and the total cost is $$$3$$$.

package main

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

func gcd(a, b int) int {
	if b == 0 { return a }
	return gcd(b, a%b)
}

func min(a, b int) int {
	if a < b { return a }
	return b
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, cgcd, cost int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			if i == 0 { cgcd = a[i] }
			fmt.Fscan(r, &a[i])
			cgcd = gcd(cgcd, a[i])
		}

		sa_cost := int(1e14)
		for i, v := range a {
			if gcd(cgcd, gcd(v, i+1)) == 1 {
				sa_cost = min(sa_cost, n-i)
			}
		}

		for i := n-1; i >= 0 && cgcd != 1; i-- {
			if gcd(i+1, a[i]) != cgcd && a[i] != i+1 {
				cost += n-i
				a[i] = gcd(i+1, a[i])
				cgcd = gcd(cgcd, gcd(a[i], i+1))
			}
		}
		fmt.Fprintln(w, min(sa_cost, cost))
	}

}

package main

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

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("WITHIN") == "TEMPTATION" }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("REMEMBER_YOU_AS_LONG_AS_I_CAN"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		iost.Writer.Flush()
	}()
	solve()
}
func solve() {
	t := iost.GetNextInt()
	for i := 0; i < t; i++ {
		testcase()
	}
}
func testcase() {
	n := iost.GetNextInt()
	aa := make([]int, n)
	g := 0
	for i := 0; i < n; i++ {
		aa[i] = iost.GetNextInt()
		g = gcd(g, aa[i])
	}
	if g == 1 {
		iost.Println(0)
		return
	}
	ans := 3
	for i := 0; i < n; i++ {
		g = 0
		for j := 0; j < n; j++ {
			if i == j {
				g = gcd(g, gcd(aa[j], j+1))
				continue
			}
			g = gcd(g, aa[j])
		}
		if g == 1 {
			ans = min(ans, n-i)
		}
	}
	iost.Println(ans)
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min(a, b int) int { return -max(-a, -b) }
func abs(a int) int    { return max(a, -a) }

func gcd(m, n int) int {
	if n == 0 {
		return m
	}
	return gcd(n, m%n)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer func(w *bufio.Writer) {
		err := w.Flush()
		if err != nil {
			log.Fatal(err)
		}
	}(w)

	var n, t, g, g1 int
	_, err := fmt.Fscan(r, &t)
	if err != nil {
		return
	}
	for i := 1; i <= t; i++ {

		_, err = fmt.Fscan(r, &n)
		if err != nil {
			return
		}

		x := make([]int, n+1)
		for j := 1; j <= n; j++ {
			_, err = fmt.Fscan(r, &x[j])
			if err != nil {
				return
			}
		}
		g = 0
		for j := 1; j <= n; j++ {
			g = gcd(x[j], g)
		}

		if g == 1 {
			_, err = fmt.Fprintln(w, "0")
			if err != nil {
				return
			}
			continue
		}

		if n == 1 {
			_, err = fmt.Fprintln(w, "1")
			if err != nil {
				return
			}
			continue
		}
		g1 = gcd(x[n], n)
		if gcd(g1, g) == 1 {
			_, err = fmt.Fprintln(w, 1)
			if err != nil {
				return
			}
			continue
		}
		g1 = gcd(x[n-1], n-1)
		if gcd(g1, g) == 1 {
			_, err = fmt.Fprintln(w, 2)
			if err != nil {
				return
			}
			continue
		}

		_, err = fmt.Fprintln(w, "3")
		if err != nil {
			return
		}

	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		a := readArrayInt64(reader)

		var g = a[0]
		for i := 1; i < n; i++ {
			g = gcd(a[i], g)
		}

		if g == 1 {
			fmt.Fprintln(writer, 0)
		} else {
			var (
				gi  int64
				sum int
				gg  = g
			)
			for i := n - 1; i >= 0; i-- {
				gi = gcd(a[i], int64(i+1))
				if gcd(gg, gi) == 1 {
					sum = n - i
					break
				} else {
					sum += n - i
					g = gcd(g, gi)
					if g == 1 {
						break
					}
				}
			}
			fmt.Fprintln(writer, sum)
		}

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

func gcd(x, y int64) int64 {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x * y / gcd(x, y)
}

package main

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

const cf = true

type pair struct {
	begin int
	end   int
}

type val struct {
	ind      int
	val      int
	haveZero bool
}

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	gcd := -1
	for i := range arr {
		fmt.Fscan(in, &arr[i])
		if gcd == -1 {
			gcd = arr[i]
		} else {
			gcd = GCD(gcd, arr[i])
		}
	}
	if gcd == 1 {
		fmt.Fprintln(out, 0)
		return
	}
	for i := n; i >= max(1, n-1); i-- {
		if GCD(gcd, i) == 1 {
			fmt.Fprintln(out, n-i+1)
			return
		}
	}
	fmt.Fprintln(out, 3)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func _int() int {
	s := _string()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func _int64() int64 {
	s := _string()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		n := _int()
		a := make([]int, n)
		for i := range a {
			a[i] = _int()
		}
		printf("%d\n", sol(n, a))
	}
}

func sol(n int, a []int) int {
	g := a[0]
	for i := range a {
		g = gcd(g, a[i])
	}
	if g == 1 {
		return 0
	}
	ret := 3
	for i := range a {
		// printf("g=%d\n", g)
		if gcd(g, i+1) == 1 {
			// printf("%d\n", i+1)
			ret = min(ret, n-(i+1)+1)
		}
	}
	return ret
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	if a < 0 {
		a *= -1
	}
	return a
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	f := func(a []int) int {
		g := 0
		for _, v := range a {
			g = gcd(g, v)
		}
		return g
	}

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}
		if f(a) == 1 {
			Fprintln(out, 0)
			return
		}
		ans := int(1e9)
		for i := 1; i <= n; i++ {
			b := append([]int{}, a...)
			b[i] = gcd(b[i], i)
			if f(b) == 1 {
				ans = min(ans, n-i+1)
			}
		}
		for i := 1; i < n; i++ {
			b := append([]int{}, a...)
			b[i] = gcd(b[i], i)
			b[i+1] = gcd(b[i+1], i+1)
			if f(b) == 1 {
				ans = min(ans, n-i+1 + n-(i+1)+1)
			}
		}
		Fprintln(out, ans)
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

	leftData, _ := ioutil.ReadAll(in)
	if s := strings.TrimSpace(string(leftData)); s != "" {
		panic("有未读入的数据：\n" + s)
	}

}

func main() { run(os.Stdin, os.Stdout) }

func gcd(a, b int) int {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

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

package main

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

func gcd(a, b int) int {
	if b == 0 { return a }
	return gcd(b, a%b)
}

func gcd_arr(a []int) int {
	var cgcd int
	for i, v := range a {
		if i == 0 { cgcd = v }
		cgcd = gcd(cgcd, v)
	}
	return cgcd
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, cgcd, cost int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		cgcd = gcd_arr(a)

		for i := n-1; i >= 0 && cgcd != 1; i-- {
			if gcd(i+1, a[i]) != cgcd && a[i] != i+1 {
				cost += n-i
				a[i] = gcd(i+1, a[i])
				cgcd = gcd_arr(a)
			}
		}
		fmt.Fprintln(w, cost)
	}

}

package main

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

func gcd(a, b int) int {
	if b == 0 { return a }
	return gcd(b, a%b)
}

func min(a, b int) int {
	if a < b { return a }
	return b
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, cgcd, cost int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			if i == 0 { cgcd = a[i] }
			fmt.Fscan(r, &a[i])
			cgcd = gcd(cgcd, a[i])
		}

		for i := n-1; i >= 0 && cgcd != 1; i-- {
			if gcd(i+1, a[i]) != cgcd {
				cost += n-i
				cgcd = gcd(cgcd, gcd(i+1, a[i]))
			}
		}
		fmt.Fprintln(w, cost)
	}

}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		a := readArrayInt64(reader)

		var g = a[0]
		for i := 1; i < n; i++ {
			g = gcd(a[i], g)
		}

		if g == 1 {
			fmt.Fprintln(writer, 0)
		} else {
			var (
				gi  int64
				sum int
			)
			for i := n - 1; i >= 0; i-- {
				gi = gcd(a[i], int64(i+1))
				if g == gi {
					continue
				}

				sum += n - i
				g = gcd(g, gi)
				if g == 1 {
					break
				}
			}
			fmt.Fprintln(writer, sum)
		}

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

func gcd(x, y int64) int64 {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x * y / gcd(x, y)
}


You are given an array $$$a$$$ of $$$n$$$ ($$$n \geq 2$$$) positive integers and an integer $$$p$$$. Consider an undirected weighted graph of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$ for which the edges between the vertices $$$i$$$ and $$$j$$$ ($$$i<j$$$) are added in the following manner:  If $$$gcd(a_i, a_{i+1}, a_{i+2}, \dots, a_{j}) = min(a_i, a_{i+1}, a_{i+2}, \dots, a_j)$$$, then there is an edge of weight $$$min(a_i, a_{i+1}, a_{i+2}, \dots, a_j)$$$ between $$$i$$$ and $$$j$$$.  If $$$i+1=j$$$, then there is an edge of weight $$$p$$$ between $$$i$$$ and $$$j$$$. Here $$$gcd(x, y, \ldots)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$, $$$y$$$, ....Note that there could be multiple edges between $$$i$$$ and $$$j$$$ if both of the above conditions are true, and if both the conditions fail for $$$i$$$ and $$$j$$$, then there is no edge between these vertices.The goal is to find the weight of the minimum spanning tree of this graph.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) and $$$p$$$ ($$$1 \leq p \leq 10^9$$$) — the number of nodes and the parameter $$$p$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, a_3, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Output $$$t$$$ lines. For each test case print the weight of the corresponding graph.

NoteHere are the graphs for the four test cases of the example (the edges of a possible MST of the graphs are marked pink):For test case 1  For test case 2  For test case 3  For test case 4

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
type uf struct {
	fa []int
}

func newUnionFind(n int) uf {
	fa := make([]int, n)
	for i := range fa {
		fa[i] = i
	}
	return uf{fa}
}

func (u uf) find(x int) int {
	if u.fa[x] != x {
		u.fa[x] = u.find(u.fa[x])
	}
	return u.fa[x]
}

func (u uf) merge(from, to int) (isNewMerge bool) {
	x, y := u.find(from), u.find(to)
	if x == y {
		return false
	}
	u.fa[x] = y
	return true
}

func (u uf) same(x, y int) bool { return u.find(x) == u.find(y) }

func (u uf) countRoots(l, r int) (cnt int) {
	for i := l; i <= r; i++ {
		if u.find(i) == i {
			cnt++
		}
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) {
		var n, lim int
		Fscan(in, &n, &lim)
		ans := int64(0)

		type pair struct{ v, i int }
		a := make([]pair, n)
		b := make([]int, n)
		for i := range a {
			Fscan(in, &a[i].v)
			a[i].i = i
			b[i] = a[i].v
		}
		sort.Slice(a, func(i, j int) bool { return a[i].v < a[j].v })

		u := newUnionFind(n)
		for _, p := range a {
			if p.v >= lim {
				break
			}
			for j := p.i - 1; j >= 0 && b[j] >= p.v && b[j]%p.v == 0 && !u.same(j, p.i); j-- {
				u.merge(j, p.i)
				ans += int64(p.v)
			}
			for j := p.i + 1; j < n && b[j] >= p.v && b[j]%p.v == 0 && !u.same(j, p.i); j++ {
				u.merge(j, p.i)
				ans += int64(p.v)
			}
		}

		for i := 1; i < n; i++ {
			if !u.same(i-1, i) {
				ans += int64(lim)
			}
		}
		Fprintln(out, ans)
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

func main() { run(os.Stdin, os.Stdout) }


There is a deck of $$$n$$$ cards. The $$$i$$$-th card has a number $$$a_i$$$ on the front and a number $$$b_i$$$ on the back. Every integer between $$$1$$$ and $$$2n$$$ appears exactly once on the cards.A deck is called sorted if the front values are in increasing order and the back values are in decreasing order. That is, if $$$a_i< a_{i+1}$$$ and $$$b_i> b_{i+1}$$$ for all $$$1\le i<n$$$.To flip a card $$$i$$$ means swapping the values of $$$a_i$$$ and $$$b_i$$$. You must flip some subset of cards (possibly, none), then put all the cards in any order you like. What is the minimum number of cards you must flip in order to sort the deck?

The first line contains a single integer $$$n$$$ ($$$1\le n\le 2\cdot 10^5$$$) — the number of cards. The next $$$n$$$ lines describe the cards. The $$$i$$$-th of these lines contains two integers $$$a_i, b_i$$$ ($$$1\le a_i, b_i\le 2n$$$). Every integer between $$$1$$$ and $$$2n$$$ appears exactly once.

If it is impossible to sort the deck, output "-1". Otherwise, output the minimum number of flips required to sort the deck.

NoteIn the first test case, we flip the cards $$$(1, 9)$$$ and $$$(2, 7)$$$. The deck is then ordered $$$(3,10), (5,8), (6,4), (7,2), (9,1)$$$. It is sorted because $$$3<5<6<7<9$$$ and $$$10>8>4>2>1$$$.In the second test case, it is impossible to sort the deck.

package main

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

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

	n := readNum(reader)
	P := make([][]int, n)
	for i := 0; i < n; i++ {
		P[i] = readNNums(reader, 2)
	}
	res := solve(n, P)
	fmt.Println(res)
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const INF = 1 << 30

func solve(n int, P [][]int) int {
	f := make([]int, n+1)
	c := make([]int, n+1)
	for i := 0; i < n; i++ {
		a := P[i][0]
		b := P[i][1]
		var cost int
		if a > b {
			a, b = b, a
			cost = 1
		}
		if a > n {
			return -1
		}
		f[a] = b
		c[a] = cost
	}

	suf_max := make([]int, n+2)
	suf_max[n+1] = -1
	for i := n; i > 0; i-- {
		suf_max[i] = max(suf_max[i+1], f[i])
	}

	prev_min := INF
	var cost0, cost1 int
	var ans int
	seq0 := NewQueue(n)
	seq1 := NewQueue(n)

	for i := 1; i <= n; i++ {
		prev_min = min(prev_min, f[i])
		if seq0.IsEmpty() || f[seq0.Back()] > f[i] {
			seq0.Push(i)
			cost0 += c[i]
		} else if seq1.IsEmpty() || f[seq1.Back()] > f[i] {
			seq1.Push(i)
			cost1 += c[i]
		} else {
			return -1
		}

		if prev_min > suf_max[i+1] {
			s0 := seq0.Size()
			s1 := seq1.Size()
			ans += min(cost0+s1-cost1, cost1+s0-cost0)
			cost0 = 0
			cost1 = 0
			seq0.Reset()
			seq1.Reset()
		}
	}
	return ans
}

type Queue struct {
	arr   []int
	front int
	end   int
}

func NewQueue(n int) *Queue {
	q := new(Queue)
	q.arr = make([]int, n)
	q.front = 0
	q.end = 0
	return q
}

func (q *Queue) Size() int {
	return q.end - q.front
}

func (q *Queue) IsEmpty() bool {
	return q.front == q.end
}

func (q *Queue) Back() int {
	return q.arr[q.end-1]
}

func (q *Queue) Push(v int) {
	q.arr[q.end] = v
	q.end++
}

func (q *Queue) Reset() {
	q.front = 0
	q.end = 0
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}


Luntik came out for a morning stroll and found an array $$$a$$$ of length $$$n$$$. He calculated the sum $$$s$$$ of the elements of the array ($$$s= \sum_{i=1}^{n} a_i$$$). Luntik calls a subsequence of the array $$$a$$$ nearly full if the sum of the numbers in that subsequence is equal to $$$s-1$$$.Luntik really wants to know the number of nearly full subsequences of the array $$$a$$$. But he needs to come home so he asks you to solve that problem!A sequence $$$x$$$ is a subsequence of a sequence $$$y$$$ if $$$x$$$ can be obtained from $$$y$$$ by deletion of several (possibly, zero or all) elements.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The next $$$2 \cdot t$$$ lines contain descriptions of test cases. The description of each test case consists of two lines. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 60$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$.

NoteIn the first test case, $$$s=1+2+3+4+5=15$$$, only $$$(2,3,4,5)$$$ is a nearly full subsequence among all subsequences, the sum in it is equal to $$$2+3+4+5=14=15-1$$$.In the second test case, there are no nearly full subsequences.In the third test case, $$$s=1+0=1$$$, the nearly full subsequences are $$$(0)$$$ and $$$()$$$ (the sum of an empty subsequence is $$$0$$$).

package main

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

func main() {
	CF1582B(os.Stdin, os.Stdout)
}

func CF1582B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, val int64
		fmt.Fscan(r, &n)
		a, b := int64(0), int64(0)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &val)
			if val == 0 {
				a++
			} else if val == 1 {
				b++
			}
		}
		fmt.Fprintln(w, (1<<a)*b)
	}
}

package main

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

func main() {
	CF1582B(os.Stdin, os.Stdout)
}

func CF1582B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, val int64
		fmt.Fscan(r, &n)
		a, b := int64(1), int64(0)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &val)
			if val == 0 {
				a *= 2
			} else if val == 1 {
				b++
			}
		}

		fmt.Fprintln(w, a*b)

	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for j:=0; j<t; j++{
		var n, k, s int64
		fmt.Scan(&n)
		for i := 0; i < int(n); i++ {
			var x int64
			fmt.Scan(&x)
			if x == 1 {
				k++
			}

			if x == 0 {
				s++
			}

		}

		if s > 0 {
			s = 1 << s
			k = s * k
		}

		fmt.Println(k)
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var n, k, s int64
		fmt.Scan(&n)
		for i := 0; i < int(n); i++ {
			var x int64
			fmt.Scan(&x)
			if x == 1 {
				k++
			}

			if x == 0 {
				s++
			}

		}

		if s > 0 {
			s = 1 << s
			k = s * k
		}

		fmt.Println(k)
	}
}

package main

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

func Pow(x, n int) int64 {
	return int64(math.Pow(float64(x), float64(n)))
}

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)
		z, o := 0, 0
		for j := 0; j < n; j++ {
			p := 0
			fmt.Fscan(f, &p)
			if p == 1 {
				o++
			}
			if p == 0 {
				z++
			}
		}
		if z == 0 {
			fmt.Fprintln(w, o)
		} else {
			fmt.Fprintln(w, Pow(2, z)*int64(o))
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		readInt(reader)
		a := readArrayInt64(reader)

		cnt0 := 0
		cnt1 := 0
		for _, v := range a {
			if v == 0 {
				cnt0++
			} else if v == 1 {
				cnt1++
			}
		}

		ans := int64(cnt1)*int64(math.Pow(2, float64(cnt0)))
		fmt.Fprintln(writer, ans)

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

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

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		var z, o int64
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v == 0 {
				z++
			} else if v == 1 {
				o++
			}
		}

		if z > 0 && o > 0 {
			fmt.Fprintln(out, 2<<(z-1)*o)
		} else {
			fmt.Fprintln(out, o)
		}
	}
}

package main

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

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

func solve(n int, a []int64) int64 {
	var (
		sum, p int64
		q      int
	)
	for _, x := range a {
		sum += x
		if x == 1 {
			p++
		}
		if x == 0 {
			q++
		}
	}
	return p << q
}

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

package main

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

/*
14
5
1 2 3 4 5
2
1000 1000
2
1 0
5
3 0 2 1 1
5
2 1 0 3 0
1
1
2
1 1
3
1 1 1
4
3 2 1 1
3
1 0 0
3
2 1 1
4
2 1 1 1
5
2 1 1 1 0
6
2 1 1 1 0 0
---
1
0
2
4
4
1
2
3
2
4
2
3
6
12
======
1
60
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

---

*/

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

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

	bld := strings.Builder{}

	for k := 0; k < t; k++ {
		var n int
		scanf("%d\n", &n)

		zeroCnt := 0
		oneCnt := 0

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

			if a == 0 {
				zeroCnt++
			}

			if a == 1 {
				oneCnt++
			}
		}
		scanf("\n")

		var ans uint64

		if oneCnt > 0 {
			ans = uint64(oneCnt)
			if zeroCnt > 0 {
				ans = uint64(oneCnt) * uint64(math.Pow(2, float64(zeroCnt)))
			}
		}

		fmt.Fprintf(&bld, "%d\n", 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, 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
}

package main

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

var n int

var a []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n)

		a = make([]int, n)

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

		ans := solve()

		fmt.Println(ans)
	}
}

func solve() int64 {
	var s int
	for i := 0; i < n; i++ {
		s += a[i]
	}

	var c int64
	var z int

	for i := 0; i < n; i++ {
		if a[i] == 1 {
			c++
		}
		if a[i] == 0 {
			z++
		}
	}

	return c * int64(1 << uint(z))
}

// https://codeforces.com/problemset/problem/1582/B

// 1582B - Luntik and Subsequences

// Luntik came out for a morning stroll and found an array a of length n. He calculated the sum s of the elements of the array (s=∑ni=1ai). Luntik calls a subsequence of the array a nearly full if the sum of the numbers in that subsequence is equal to s−1.
// Luntik really wants to know the number of nearly full subsequences of the array a. But he needs to come home so he asks you to solve that problem!
// A sequence x is a subsequence of a sequence y if x can be obtained from y by deletion of several (possibly, zero or all) elements.

// Input
// The first line contains a single integer t (1≤t≤1000) — the number of test cases. The next 2⋅t lines contain descriptions of test cases. The description of each test case consists of two lines.
// The first line of each test case contains a single integer n (1≤n≤60) — the length of the array.
// The second line contains n integers a1,a2,…,an (0≤ai≤109) — the elements of the array a.

// Output
// For each test case print the number of nearly full subsequences of the array.

// Example
// input
// 5
// 5
// 1 2 3 4 5
// 2
// 1000 1000
// 2
// 1 0
// 5
// 3 0 2 1 1
// 5
// 2 1 0 3 0
// output
// 1
// 0
// 2
// 4
// 4

// Note

// In the first test case, s=1+2+3+4+5=15, only (2,3,4,5) is a nearly full subsequence among all subsequences, the sum in it is equal to 2+3+4+5=14=15−1.
// In the second test case, there are no nearly full subsequences.
// In the third test case, s=1+0=1, the nearly full subsequences are (0) and () (the sum of an empty subsequence is 0).

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, n, a uint
	var cnt_0, cnt_1 uint64

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			cnt_0, cnt_1 = 0, 0

			for fmt.Fscan(reader, &n); n > 0; n-- {
				fmt.Fscan(reader, &a)

				if a == 0 {
					cnt_0++
				} else if a == 1 {
					cnt_1++
				}
			}

			fmt.Fprintln(writer, (1<<cnt_0)*cnt_1)
		}
	}

	writer.Flush()
}

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, curr int
		fmt.Fscan(reader, &n)
		zeros := 0
		ones := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &curr)
			if curr == 0 {
				zeros++
			}
			if curr == 1 {
				ones++
			}
		}
		ans := int64(ones)
		for zeros > 0 {
			ans = ans * 2
			zeros--
		}
		fmt.Println(ans)

	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}
func solve() {
	arr := []int{}
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		arr = append(arr, a)
	}
	var ans int64
	for _, v := range arr {
		if v == 1 {
			ans++
		}
	}
	for _, v := range arr {
		if v == 0 {
			ans = ans * 2
		}
	}
	fmt.Println(ans)
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"time"
)

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		ARR := make([]int, n)
		var zero int64 = 1
		ones := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARR[i])
			if ARR[i] == 0 {
				zero = zero * 2
			}
			if ARR[i] == 1 {
				ones++
			}
		}
		q := int64(ones) * zero
		fmt.Println(q)

	}

}

package main

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

func main() {
	CF1582B(os.Stdin, os.Stdout)
}

func CF1582B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, val int64
		fmt.Fscan(r, &n)
		a, b := int64(0), int64(0)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &val)
			if val == 0 {
				a++
			} else if val == 1 {
				b++
			}
		}
		fmt.Fprintln(w, a*b)
	}
}

package main

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

func main() {
	CF1582B(os.Stdin, os.Stdout)
}

func CF1582B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, val int64
		fmt.Fscan(r, &n)
		a, b := 1, 0
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &val)
			if val == 0 {
				a *= 2
			} else if val == 1 {
				b++
			}
		}

		if b == 0 {
			fmt.Fprintln(w, 0)
		} else {
			fmt.Fprintln(w, a*b)
		}

	}
}

package main

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

func main() {
	CF1582B(os.Stdin, os.Stdout)
}

func CF1582B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, val int64
		fmt.Fscan(r, &n)
		a, b := 0, 0
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &val)
			if val == 0 {
				a++
			} else if val == 1 {
				b++
			}
		}

		if b == 0 {
			fmt.Fprintln(w, 0)
		} else {
			fmt.Fprintln(w, a*b*b)
		}

	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var n, k, s int
		fmt.Scan(&n)
		for i := 0; i < n; i++ {
			var x int64
			fmt.Scan(&x)
			if x == 1 {
				k++
			}

			if x == 0 {
				s++
			}

		}

		if s > 0 {
			s = (1 + s) * s / 2
			k += s * k
		}

		fmt.Println(k)
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var n, k, s int
		fmt.Scan(&n)
		for i := 0; i < n; i++ {
			var x int64
			fmt.Scan(&x)
			if x == 1 {
				k++
			}

			if x == 0 {
				s++
			}

		}

		if s > 0 {
			k += s * k
		}

		fmt.Println(k)
	}
}

package main

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

func Pow(x, n int) int {
	return int(math.Pow(float64(x), float64(n)))
}

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)
		z, o := 0, 0
		for j := 0; j < n; j++ {
			p := 0
			fmt.Fscan(f, &p)
			if p == 1 {
				o++
			}
			if p == 0 {
				z++
			}
		}
		if z == 0 {
			fmt.Fprintln(w, o)
		} else {
			fmt.Fprintln(w, Pow(2, z)*o)
		}
	}
	w.Flush()
}

func main() {
	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)
		z, o := 0, 0
		for j := 0; j < n; j++ {
			p := 0
			fmt.Fscan(f, &p)
			if p == 1 {
				o++
			}
			if p == 0 {
				z++
			}
		}
		if z == 0 {
			fmt.Fprintln(w, o)
		} else {
			fmt.Fprintln(w, 2*z*o)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		readInt(reader)
		a := readArrayInt64(reader)

		cnt0 := 0
		cnt1 := 0
		for _, v := range a {
			if v == 0 {
				cnt0++
			} else if v == 1 {
				cnt1++
			}
		}

		ans := cnt1*(1 + (1+cnt0)*cnt0/2)
		fmt.Fprintln(writer, ans)

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		readInt(reader)
		a := readArrayInt64(reader)

		cnt0 := 0
		cnt1 := 0
		for _, v := range a {
			if v == 0 {
				cnt0++
			} else if v == 1 {
				cnt1++
			}
		}

		if cnt0 == 0 && cnt1 > 0 {
			fmt.Fprintln(writer, cnt1)
		} else {
			fmt.Fprintln(writer, 2*cnt1*cnt0)
		}

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

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

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		var z, o int64
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v == 0 {
				z++
			} else if v == 1 {
				o++
			}
		}

		if z > 0 && o > 0 {
			fmt.Fprintln(out, 2<<(z-1)*o)
		} else if z > 0 {
			fmt.Fprintln(out, 2<<(z-1))
		} else {
			fmt.Fprintln(out, o)
		}
	}
}

package main

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

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

func solve(n int, a []int64) int64 {
	var (
		sum, p int64
		q      int
	)
	for _, x := range a {
		sum += x
		if x == 1 {
			p++
		}
		if x == 0 {
			q++
		}
	}
	if sum == 1 {
		return p<<q + 1
	}
	return p << q
}

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

package main

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

/*
14
5
1 2 3 4 5
2
1000 1000
2
1 0
5
3 0 2 1 1
5
2 1 0 3 0
1
1
2
1 1
3
1 1 1
4
3 2 1 1
3
1 0 0
3
2 1 1
4
2 1 1 1
5
2 1 1 1 0
6
2 1 1 1 0 0
---
1
0
2
4
4
1
2
3
2
4
2
3
6
12
*/

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

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

	bld := strings.Builder{}

	for k := 0; k < t; k++ {
		var n int
		scanf("%d\n", &n)

		zeroCnt := 0
		oneCnt := 0

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

			if a == 0 {
				zeroCnt++
			}

			if a == 1 {
				oneCnt++
			}
		}
		scanf("\n")

		ans := 0

		if oneCnt > 0 {
			ans = oneCnt
			if zeroCnt > 0 {
				ans = oneCnt * int(math.Pow(2, float64(zeroCnt)))
			}
		}

		fmt.Fprintf(&bld, "%d\n", 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, 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
}

package main

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

var n int

var a []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n)

		a = make([]int, n)

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

		ans := solve()

		fmt.Println(ans)
	}
}

func solve() int {
	var s int
	for i := 0; i < n; i++ {
		s += a[i]
	}

	var c int
	var z int

	for i := 0; i < n; i++ {
		if a[i] == 1 {
			c++
		}
		if a[i] == 0 {
			z++
		}
	}

	return c * (1 << uint(z))
}