Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties:  the upper half of matrix c (rows with numbers from 1 to x) exactly matches b;  the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain?

The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a.

In the single line, print the answer to the problem — the minimum number of rows of matrix b.

NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, m int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	m, _ = strconv.Atoi(r.Text())
	var a [101][101]int
	for i:=0; i<n; i++ {
		for j:=0; j<m; j++ {
			r.Scan()
			a[i][j], _ = strconv.Atoi(r.Text())
		}
	}
	ans := n
	nn := n
	ii := 0
	for nn % 2 == 0 {
		ii = nn - 1
		nn = nn / 2
		for i:=0; i<nn; i++ {
			for j:=0; j<m; j++ {
				if a[i][j] != a[ii][j] {
					w.WriteString(strconv.Itoa(ans)+"\n")
					w.Flush()
					return
				}
			}
			ii -= 1
		}
		ans = nn
	}
	w.WriteString(strconv.Itoa(ans)+"\n")
	w.Flush()
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()

	a := make([][]int, n)

	for i:=0; i<n; i++ {
		a[i] = make([]int, m)
		for j:=0; j<m; j++ {
			a[i][j] = nextInt()
		}
	}

	// if n==1 {
	// 	println(0)
	// 	return
	// }

	// if n % 2 == 0 && !isMirroring(a, n) {
	// 	println(0)
	// 	return
	// }

	for i:=n; i>0; i /= 2 {
		if i % 2 == 1 {
			println(i)
			return
		}

		if !isMirroring(a, i) {
			println(i)
			return
		}
	}
}

func isMirroring(a [][]int, n int) bool {
	for i, j := 0, n-1; i<j; i, j = i+1, j-1 {
		for col:=0; col<len(a[i]); col++ {
			if a[i][col] != a[j][col] {
				return false
			}
		}
	}
	return true
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	//"sort"
)

func main() {
	var n,m,i,j,t,r int
	var a [110][110]int
	input := bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	fmt.Scan(&n,&m)
	for i=0;i<n;i++ {
		for j=0;j<m;j++ {
			input.Scan()
			aa,_:=strconv.Atoi(input.Text())
			a[i][j]=aa
		}
	}
	r=n
	for ;(r/2)!=0 && r%2==0; {
		t=0
		for i=0;i<r/2;i++ {
			for j=0;j<m;j++ {
				if a[i][j]!=a[r-1-i][j] {
					t=1
				}
			}
		}
		if t==1 {
			break
		}
		r/=2
	}
	out := bufio.NewWriter(os.Stdout)
	out.WriteString(strconv.Itoa(r))
	out.Flush()
}

package main

import "fmt"

func main() {
    var n,m int
    var a [105][105]int
    fmt.Scan(&n,&m)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            fmt.Scan(&a[i][j])
        }
    }
    ans := n
    for (ans > 1) && (ans%2 == 0) {
        ok := true
        for i := 0; (i < ans/2) && ok; i++ {
            for j := 0; j < m; j++ {
                if a[i][j] != a[ans-i-1][j] {
                    ok = false
                    break
                }
            }
        }
        if !ok { break } else { ans /= 2 }
    }
    fmt.Println(ans)
}

// 426B
package main

import (
	"fmt"
)

func main() {
	var n, m int
	var xy [100][100]int
	flag := true
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Scan(&xy[i][j])
		}
	}
	for n%2 == 0 && flag == true {
		flag = true
		for i := 0; i < n/2; i++ {
			for j := 0; j < m; j++ {
				if xy[i][j] == xy[n-1-i][j] {
					continue
				}
				flag = false
				break
			}
			if flag == false {
				break
			}
		}
		if flag == true {
			n = n / 2
		}
	}
	fmt.Println(n)
}

// 426B-mic
package main

import (
	"fmt"
)

func main() {
	var a [107][107]int
	f := true
	var n, m int
	fmt.Scan(&n, &m)
	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			fmt.Scan(&a[i][j])
		}
	}
	for n%2 == 0 {
		b := n / 2
		for i := 1; i <= b; i++ {
			for j := 1; j <= m; j++ {
				if a[n+1-i][j] != a[i][j] {
					f = false
					break
				}
			}
		}
		if !f {
			break
		} else {
			n /= 2
		}
	}
	fmt.Println(n)
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()

	a := make([][]int, n)

	for i:=0; i<n; i++ {
		a[i] = make([]int, m)
		for j:=0; j<m; j++ {
			a[i][j] = nextInt()
		}
	}

	if n==1 {
		println(0)
		return
	}

	// if n % 2 == 0 && !isMirroring(a, n) {
	// 	println(0)
	// 	return
	// }

	for i:=n; i>0; i /= 2 {
		if i % 2 == 1 {
			println(i)
			return
		}

		if !isMirroring(a, i) {
			println(i)
			return
		}
	}
}

func isMirroring(a [][]int, n int) bool {
	for i, j := 0, n-1; i<j; i, j = i+1, j-1 {
		for col:=0; col<len(a[i]); col++ {
			if a[i][col] != a[j][col] {
				return false
			}
		}
	}
	return true
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()

	a := make([][]int, n)

	for i:=0; i<n; i++ {
		a[i] = make([]int, m)
		for j:=0; j<m; j++ {
			a[i][j] = nextInt()
		}
	}

	if n==1 {
		println(0)
		return
	}

	if n % 2 == 0 && !isMirroring(a, n) {
		println(0)
		return
	}

	for i:=n; i>0; i /= 2 {
		if i % 2 == 1 {
			println(i)
			return
		}

		if !isMirroring(a, i) {
			println(i)
			return
		}
	}
}

func isMirroring(a [][]int, n int) bool {
	for i, j := 0, n-1; i<j; i, j = i+1, j-1 {
		for col:=0; col<len(a[i]); col++ {
			if a[i][col] != a[j][col] {
				return false
			}
		}
	}
	return true
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()

	a := make([][]int, n)

	for i:=0; i<n; i++ {
		a[i] = make([]int, m)
		for j:=0; j<m; j++ {
			a[i][j] = nextInt()
		}
	}

	if n==1 || !isMirroring(a, n) {
		println(0)
		return
	}

	for i:=n; i>0; i /= 2 {
		if i % 2 == 1 {
			println(i)
			return
		}

		if !isMirroring(a, i) {
			println(i)
			return
		}
	}
}

func isMirroring(a [][]int, n int) bool {
	for i, j := 0, n-1; i<j; i, j = i+1, j-1 {
		for col:=0; col<len(a[i]); col++ {
			if a[i][col] != a[j][col] {
				return false
			}
		}
	}
	return true
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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


Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge uv there is at least one endpoint of it in this set, i.e.  or  (or both).Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.They have agreed to give you their graph and you need to find two disjoint subsets of its vertices A and B, such that both A and B are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).

The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — the number of vertices and the number of edges in the prize graph, respectively. Each of the next m lines contains a pair of integers ui and vi (1  ≤  ui,  vi  ≤  n), denoting an undirected edge between ui and vi. It's guaranteed the graph won't contain any self-loops or multiple edges.

If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer k denoting the number of vertices in that vertex cover, and the second line contains k integers — the indices of vertices. Note that because of m ≥ 1, vertex cover cannot be empty.

NoteIn the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).In the second sample, there is no way to satisfy both Pari and Arya.

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}

var (
  visited []int
  covers [][]int
  children [][]int
  infeasible bool
)

func descend(u, whichSet int) {
  if visited[u] != -1 {
    if visited[u] != whichSet {
      infeasible = true
    }
    return
  }
  visited[u] = whichSet
  covers[whichSet] = append(covers[whichSet], u)
  for _, v := range children[u] {
    descend(v, whichSet ^ 1)
  }
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, m := getI(), getI()
  children = make([][]int, n + 1)
  for i := 0; i < m; i++ {
    u, v := getI(), getI()
    children[u] = append(children[u], v)
    children[v] = append(children[v], u)
  }
  visited = make([]int, n + 1)
  for u := 1; u <= n; u++ {
    visited[u] = -1
  }
  covers = make([][]int, 2)
  for u := 1; u <= n; u++ {
    if visited[u] == -1 {
      descend(u, 0)
    }
  }

  if infeasible {
    writer.WriteString("-1\n")
    return
  }
  for _, cover := range covers {
    writer.WriteString(fmt.Sprintf("%d\n%d", len(cover), cover[0]))
    for i := 1; i < len(cover); i++ {
      writer.WriteString(fmt.Sprintf(" %d", cover[i]))
    }
    writer.WriteString("\n")
  }
}

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

var (
  visited []int
  covers [][]int
  children [][]int
  infeasible bool
)

func descend(u, v, whichSet int) {
  //fmt.Printf("%d %d %d\n", u, v, whichSet)
  if visited[v] != -1 {
    //fmt.Printf("  visited[%d]: %d, whichSet: %d\n", v, visited[v], whichSet)
    if visited[v] != whichSet {
      infeasible = true
      //fmt.Printf("  infeasible\n")
    }
    return
  }
  visited[v] = whichSet
  covers[whichSet] = append(covers[whichSet], v)
  for _, w := range children[v] {
    if w == u {
      continue
    }
    descend(v, w, whichSet ^ 1)
  }
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, m := getI(), getI()
  children = make([][]int, n + 1)
  for i := 0; i < m; i++ {
    u, v := getI(), getI()
    children[u] = append(children[u], v)
    children[v] = append(children[v], u)
  }
  visited = make([]int, n + 1)
  for u := 1; u <= n; u++ {
    visited[u] = -1
  }
  covers = make([][]int, 2)
  for u := 1; u <= n; u++ {
    if visited[u] == -1 {
      descend(-1, u, 0)
    }
  }

  if infeasible {
    writer.WriteString("-1\n")
    return
  }
  for _, cover := range covers {
    writer.WriteString(fmt.Sprintf("%d\n%d", len(cover), cover[0]))
    for i := 1; i < len(cover); i++ {
      writer.WriteString(fmt.Sprintf(" %d", cover[i]))
    }
    writer.WriteString("\n")
  }
}

package main

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

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
	adj     []*Vertex
	color   []bool
	visited []bool
)

type Vertex struct {
	to []int
}

func ReadInt() int {
	scanner.Scan()
	v, _ := strconv.Atoi(scanner.Text())
	return v
}

func dfs(u, fa int) bool {
	visited[u] = true
	if adj[u] == nil {
		return true
	}
	for i := 0; i < len(adj[u].to); i++ {
		v := adj[u].to[i]
		if visited[v] {
			if color[v] == color[u] {
				return false
			}
			continue
		}
		color[v] = !color[u]
		if !dfs(v, u) {
			return false
		}
	}
	return true
}

func main() {
	scanner.Split(bufio.ScanWords)
	defer writer.Flush()
	n, m := ReadInt(), ReadInt()
	adj = make([]*Vertex, n, n)
	color = make([]bool, n, n)
	visited = make([]bool, n, n)
	for i := 0; i < m; i++ {
		a, b := ReadInt(), ReadInt()
		a--
		b--
		if adj[a] == nil {
			adj[a] = &Vertex{
				to: make([]int, 0),
			}
		}
		if adj[b] == nil {
			adj[b] = &Vertex{
				to: make([]int, 0),
			}
		}
		adj[a].to = append(adj[a].to, b)
		adj[b].to = append(adj[b].to, a)
	}
	var is bool = true
	for i := 0; i < n; i++ {
		if !visited[i] {
			color[i] = true
			if !dfs(i, -1) {
				is = false
				break
			}
		}
	}
	if !is {
		writer.WriteString("-1\n")
		return
	}
	r, b := make([]int, 0, n), make([]int, 0, n)
	for i := 0; i < n; i++ {
		if color[i] {
			r = append(r, i)
		} else {
			b = append(b, i)
		}
	}
	l := fmt.Sprintf("%d", len(r))
	writer.WriteString(l + "\n")
	for i := 0; i < len(r); i++ {
		writer.WriteString(strconv.Itoa(r[i]+1) + " ")
	}
	writer.WriteString("\n")
	l = fmt.Sprintf("%d", len(b))
	writer.WriteString(l + "\n")
	for i := 0; i < len(b); i++ {
		writer.WriteString(strconv.Itoa(b[i]+1) + " ")
	}
	writer.WriteString("\n")
}

package main

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

func isIn(s []int64, e int64) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

type node struct {
	id    int64
	links []int64
	owner int
}

func assignNode(nodes []node, n int64, o int) (retnodes []node, err error) {
	if (nodes[n].owner != 0) && (nodes[n].owner != o) {
		return nil, errors.New("")
	}
	if nodes[n].owner == o {
		return nodes, nil
	}

	nodes[n].owner = o
	for _, i := range nodes[n].links {
		newo := 2
		if o == 2 {
			newo = 1
		}
		var err error
		nodes, err = assignNode(nodes, i, newo)
		if err != nil {
			return nil, errors.New("")
		}
	}
	return nodes, nil
}

func main() {
	var i int64
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	n, _ := strconv.ParseInt(s[0], 10, 64)
	m, _ := strconv.ParseInt(s[1], 10, 64)

	nodes := []node{node{0, []int64{}, 0}}
	for i = 1; i <= n; i++ {
		newnode := node{i, []int64{}, 0}
		nodes = append(nodes, newnode)
	}
	for i = 0; i < m; i++ {
		scanner.Scan()
		s := strings.Split(scanner.Text(), " ")
		e1, _ := strconv.ParseInt(s[0], 10, 64)
		e2, _ := strconv.ParseInt(s[1], 10, 64)
		nodes[e1].links = append(nodes[e1].links, e2)
		nodes[e2].links = append(nodes[e2].links, e1)
	}
	for i = 0; i < n; i++ {
		if nodes[i].owner == 0 && len(nodes[i].links) > 0 {
			var err error
			nodes, err = assignNode(nodes, i, 1)
			if err != nil {
				fmt.Println("-1")
				return
			}
		}
	}
	p := []int64{}
	a := []int64{}
	for i = 1; i <= n; i++ {
		if nodes[i].owner == 1 {
			p = append(p, i)
		}
		if nodes[i].owner == 2 {
			a = append(a, i)
		}
	}
	fmt.Printf("%d\n", len(p))
	for _, i := range p {
		fmt.Printf("%d ", i)
	}
	fmt.Println()
	fmt.Printf("%d\n", len(a))
	for _, i := range a {
		fmt.Printf("%d ", i)
	}
	fmt.Println()

}

package main

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

// 邻接表
const MAXN = 1e5 + 1
var G [MAXN][]int

var n,m int
var color [MAXN]int

func readGraph()  {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 1; i <= m; i++ {
		scanner.Scan()
		f, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		s, _ := strconv.Atoi(scanner.Text())
		G[f] = append(G[f], s)
		G[s] = append(G[s], f)
	}

}

// current node v has color c
func dfs(v int, c int)  bool{

	color[v] = c
	for i:=0; i < len(G[v]); i++ {
		if color[G[v][i]] == 0 {
			if !dfs(G[v][i],3-c) {return false} //dfs, whether or not feasible
		}else { //already has color
			if color[G[v][i]] != 3-c{return  false} //conflict
		}
	}
	return true
}

func main()  {
	fmt.Scan(&n,&m)
	readGraph()
	for i := 1; i <= n; i++ {
		if color[i] == 0 {
			if !dfs(i,1){
				fmt.Println(-1)
				return
			}
		}
	}
	var res [3][]int
	for i := 1; i <= n; i++ {
		res[color[i]] = append(res[color[i]],i)
	}

	for j := 1; j <= 2; j++ {
		fmt.Println(len(res[j]))
		for i := 0; i < len(res[j]); i++ {
			fmt.Printf("%d ",res[j][i])
		}
		fmt.Println()
	}
}

package main

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

const (
	RED   = 1
	GREEN = 2
)

type Graph struct {
	Visited     map[int]bool
	Color       map[int]int
	Edges       map[int][]int
	IsBipartite bool
	Sets        map[int][]int
}

func explore(g *Graph, u int) {
	g.Visited[u] = true
	if _, ok := g.Color[u]; !ok {
		g.Color[u] = RED
	}
	g.Sets[g.Color[u]] = append(g.Sets[g.Color[u]], u)
	if edges, ok := g.Edges[u]; ok {
		for _, v := range edges {
			if _, ok := g.Visited[v]; !ok {
				if g.Color[u] == RED {
					g.Color[v] = GREEN
				} else {
					g.Color[v] = RED
				}
				explore(g, v)
			} else {
				if g.Color[v] == g.Color[u] {
					g.IsBipartite = false
				}
			}
		}
	}
}

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

	g := Graph{Visited: make(map[int]bool), Color: make(map[int]int), Edges: make(map[int][]int), Sets: make(map[int][]int), IsBipartite: true}
	g.Sets[RED] = make([]int, 0)
	g.Sets[GREEN] = make([]int, 0)

	var n, m, u, v int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	for i := 1; i <= m; i++ {
		fmt.Fscanf(reader, "%d %d\n", &u, &v)
		if _, ok := g.Edges[u]; !ok {
			g.Edges[u] = make([]int, 0)
		}
		if _, ok := g.Edges[v]; !ok {
			g.Edges[v] = make([]int, 0)
		}
		g.Edges[u] = append(g.Edges[u], v)
		g.Edges[v] = append(g.Edges[v], u)
	}
	for p, _ := range g.Edges {
		if _, ok := g.Visited[p]; !ok {
			explore(&g, p)
		}
	}
	if g.IsBipartite == true {
		for _, vertices := range g.Sets {
			size := len(vertices)
			fmt.Fprintf(writer, "%d\n", size)
			for idx, vertex := range vertices {
				if idx == size-1 {
					fmt.Fprintf(writer, "%d\n", vertex)
				} else {
					fmt.Fprintf(writer, "%d ", vertex)
				}
			}
		}
	} else {
		fmt.Fprintf(writer, "%d\n", -1)
	}
}

package main

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

const (
	RED   = 1
	GREEN = 2
)

type Graph struct {
	Visited     map[int]bool
	Color       map[int]int
	Edges       map[int][]int
	IsBipartite bool
	Sets        map[int][]int
}

func explore(g *Graph, u int) {
	g.Visited[u] = true
	if _, ok := g.Color[u]; !ok {
		g.Color[u] = RED
	}
	g.Sets[g.Color[u]] = append(g.Sets[g.Color[u]], u)
	if edges, ok := g.Edges[u]; ok {
		for _, v := range edges {
			if _, ok := g.Visited[v]; !ok {
				if g.Color[u] == RED {
					g.Color[v] = GREEN
				} else {
					g.Color[v] = RED
				}
				explore(g, v)
			} else {
				if g.Color[v] == g.Color[u] {
					g.IsBipartite = false
				}
			}
		}
	}
}

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

	g := Graph{Visited: make(map[int]bool), Color: make(map[int]int), Edges: make(map[int][]int), Sets: make(map[int][]int), IsBipartite: true}
	g.Sets[RED] = make([]int, 0)
	g.Sets[GREEN] = make([]int, 0)

	var n, m, u, v int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	for i := 1; i <= m; i++ {
		fmt.Fscanf(reader, "%d %d\n", &u, &v)
		if _, ok := g.Edges[u]; !ok {
			g.Edges[u] = make([]int, 0)
		}
		if _, ok := g.Edges[v]; !ok {
			g.Edges[v] = make([]int, 0)
		}
		g.Edges[u] = append(g.Edges[u], v)
		g.Edges[v] = append(g.Edges[v], u)
	}
	for p, _ := range g.Edges {
		if _, ok := g.Visited[p]; !ok {
			explore(&g, p)
		}
	}
	if g.IsBipartite {
		for _, vertices := range g.Sets {
			size := len(vertices)
			fmt.Fprintf(writer, "%d\n", size)
			for idx, vertex := range vertices {
				if idx == size-1 {
					fmt.Fprintf(writer, "%d\n", vertex)
				} else {
					fmt.Fprintf(writer, "%d ", vertex)
				}
			}
		}
	} else {
		fmt.Fprintf(writer, "%d\n", -1)
	}
}

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

var (
  visited []int
  covers [][]int
  children [][]int
  infeasible bool
)

func descend(u, v, whichSet, depth int) {
  //fmt.Printf("%d %d %d %d\n", u, v, whichSet, depth)
  if visited[v] != -1 {
    //fmt.Printf("  visited[%d]: %d, whichSet: %d\n", v, visited[v], whichSet)
    if visited[v] != whichSet && depth % 2 == 1 {
      infeasible = true
      //fmt.Printf("  infeasible\n")
    }
    return
  }
  visited[v] = whichSet
  covers[whichSet] = append(covers[whichSet], v)
  for _, w := range children[v] {
    if w == u {
      continue
    }
    descend(v, w, whichSet ^ 1, depth + 1)
  }
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, m := getI(), getI()
  children = make([][]int, n + 1)
  for i := 0; i < m; i++ {
    u, v := getI(), getI()
    children[u] = append(children[u], v)
    children[v] = append(children[v], u)
  }
  visited = make([]int, n + 1)
  for u := 1; u <= n; u++ {
    visited[u] = -1
  }
  covers = make([][]int, 2)
  for u := 1; u <= n; u++ {
    descend(-1, u, 0, 0)
  }

  if infeasible {
    writer.WriteString("-1\n")
    return
  }
  for _, cover := range covers {
    writer.WriteString(fmt.Sprintf("%d\n%d", len(cover), cover[0]))
    for i := 1; i < len(cover); i++ {
      writer.WriteString(fmt.Sprintf(" %d", cover[i]))
    }
    writer.WriteString("\n")
  }
}


There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 ≤ i < n + m) such that positions with indexes i and i + 1 contain children of different genders (position i has a girl and position i + 1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line.

The single line of the input contains two integers n and m (1 ≤ n, m ≤ 100), separated by a space.

Print a line of n + m characters. Print on the i-th position of the line character "B", if the i-th position of your arrangement should have a boy and "G", if it should have a girl.  Of course, the number of characters "B" should equal n and the number of characters "G" should equal m. If there are multiple optimal solutions, print any of them.

NoteIn the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal.

package main

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

func main() {
    input, _ := os.Open("input.txt")
    defer input.Close()
    scanner := bufio.NewScanner(input)
    scanner.Split(bufio.ScanWords)
    output, _ := os.Create("output.txt")
    defer output.Close()
    writer := bufio.NewWriter(output)

    scanner.Scan()
    n, _ := strconv.Atoi(scanner.Text())
    scanner.Scan()
    m, _ := strconv.Atoi(scanner.Text())
    if n > m {
        for (n > 0) && (m > 0) { writer.WriteString("BG"); n--; m--; }
        for (n > 0) { writer.WriteString("B"); n--; }
    } else {
        for (n > 0) && (m > 0) { writer.WriteString("GB"); n--; m--; }
        for (m > 0) { writer.WriteString("G"); m--; }
    }
    writer.WriteString("\n")
    writer.Flush()
}

package main

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

var fi, _ = os.Open("input.txt")
var fo, _ = os.Create("output.txt")

var in = bufio.NewScanner(fi)
var out = bufio.NewWriter(fo)

func main() {

	defer out.Flush()
	in.Split(bufio.ScanWords)

	var n, m int = NextInt(), NextInt()
	if n >= m {
		for i := 0; i < m; i++ {
			fmt.Fprint(out, "BG")
		}
		for i := 0; i < n - m; i++ {
			fmt.Fprint(out, "B")
		}
	}else {
		for i := 0; i < n; i++ {
			fmt.Fprint(out, "GB")
		}
		for i := 0; i < m - n; i++ {
			fmt.Fprint(out, "G")
		}
	}
	fmt.Fprintln(out)
}

func Max(x, y int) int {
	if x < y {
		return y
	}
	return x
}

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

func Next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

func NextInt() int{
	ret, _ := strconv.Atoi(Next())
	return ret
}

package main

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

var file, _ = os.Open("input.txt")
var outfile, _ = os.Create("output.txt")
var in = bufio.NewScanner(file)
var out = bufio.NewWriter(outfile)

// var in = bufio.NewScanner(os.Stdin)
// var out = bufio.NewWriter(os.Stdout)

func next() string {
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

func nextInt() int {
    ret, _ := strconv.Atoi(next())
    return ret
}

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    m := nextInt()
    if n > m {
        for i := 0; i < m; i++ {
            out.WriteString("BG");
        }
        for i := 0; i < n - m; i++ {
            out.WriteString("B");
        }
    } else {
        for i := 0; i < n; i++ {
            out.WriteString("GB");
        }
        for i := 0; i < m - n; i++ {
            out.WriteString("G");
        }

    }
}

// Author: sighduck
// URL: https://codeforces.com/contest/253/problem/A

package main

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

func Solve(b int, g int) string {
	if b < g {
		return strings.Repeat("GB", b) + strings.Repeat("G", g-b)
	}
	return strings.Repeat("BG", g) + strings.Repeat("B", b-g)
}

func main() {
	inputFile, _ := os.Open("input.txt")
	outputFile, _ := os.Create("output.txt")
	reader := bufio.NewReader(inputFile)
	writer := bufio.NewWriter(outputFile)
	defer writer.Flush()

	var b, g int
	fmt.Fscanf(reader, "%d %d\n", &b, &g)
	fmt.Fprintf(writer, "%s\n", Solve(b, g))
}

package main
import (
	//"fmt"
	"bufio"
	"os"
	"strconv"
)
func main() {
	var m,n int
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	input.Scan()
	out := bufio.NewWriter(os.Stdout)
	aa,_:= strconv.Atoi(input.Text())
	n=aa
	input.Scan()
	bb,_:= strconv.Atoi(input.Text())
	m=bb
	//fmt.Scan(&n,&m)
	if n>=m {
		for i:=0;i<m;i++ {
			out.WriteString("BG")
		}
		out.Flush()
		for i:=0;i<n-m;i++ {
			out.WriteRune('B')
		}
		out.Flush()
	} else {
		for i:=0;i<n;i++ {
			out.WriteString("GB")
		}
		out.Flush()
		for i:=0;i<m-n;i++ {
			out.WriteRune('G')
		}
		out.Flush()
	}
}

package main

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

func main() {
    input, _ := os.Open("input.txt")
    defer input.Close()
    scanner := bufio.NewScanner(input)
    scanner.Split(bufio.ScanWords)
    output, _ := os.Create("output.txt")
    defer output.Close()
    writer := bufio.NewWriter(output)
    scanner.Scan()
    n, _ := strconv.Atoi(scanner.Text())
    scanner.Scan()
    m, _ := strconv.Atoi(scanner.Text())
    for (n > 0) && (m > 0) { writer.WriteString("BG"); n--; m--; }
    for (n > 0) { writer.WriteString("B"); n--; }
    for (m > 0) { writer.WriteString("G"); m--; }
    writer.WriteRune('\n')
    writer.Flush()
}

package main

import "fmt"

func main() {
    var n,m int
    fmt.Scan(&n,&m)
    for (n > 0) && (m > 0) { fmt.Print("BG"); n--; m--; }
    for (n > 0) { fmt.Print("B"); n--; }
    for (m > 0) { fmt.Print("G"); m--; }
    fmt.Println()
}

package main

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

func main() {
    input, _ := os.Open("input.txt")
    defer input.Close()
    scanner := bufio.NewScanner(input)
    scanner.Split(bufio.ScanWords)
    output, _ := os.Create("output.txt")
    defer output.Close()
    writer := bufio.NewWriter(output)

    scanner.Scan()
    n, _ := strconv.Atoi(scanner.Text())
    scanner.Scan()
    m, _ := strconv.Atoi(scanner.Text())
    for (n > 0) && (m > 0) { writer.WriteString("BG"); n--; m--; }
    for (n > 0) { writer.WriteString("B"); n--; }
    for (m > 0) { writer.WriteString("G"); m--; }
    writer.WriteString("\n")
    writer.Flush()
}

package main

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

func main() {
    input, _ := os.Open("input.txt")
    defer input.Close()
    scanner := bufio.NewScanner(input)
    scanner.Split(bufio.ScanWords)
    output, _ := os.Create("output.txt")
    defer output.Close()
    writer := bufio.NewWriter(output)

    scanner.Scan()
    n, _ := strconv.Atoi(scanner.Text())
    scanner.Scan()
    m, _ := strconv.Atoi(scanner.Text())
    for (n > 0) && (m > 0) { writer.WriteString("GB"); n--; m--; }
    for (n > 0) { writer.WriteString("B"); n--; }
    for (m > 0) { writer.WriteString("G"); m--; }
    writer.WriteString("\n")
    writer.Flush()
}


There are $$$n$$$ water tanks in a row, $$$i$$$-th of them contains $$$a_i$$$ liters of water. The tanks are numbered from $$$1$$$ to $$$n$$$ from left to right.You can perform the following operation: choose some subsegment $$$[l, r]$$$ ($$$1\le l \le r \le n$$$), and redistribute water in tanks $$$l, l+1, \dots, r$$$ evenly. In other words, replace each of $$$a_l, a_{l+1}, \dots, a_r$$$ by $$$\frac{a_l + a_{l+1} + \dots + a_r}{r-l+1}$$$. For example, if for volumes $$$[1, 3, 6, 7]$$$ you choose $$$l = 2, r = 3$$$, new volumes of water will be $$$[1, 4.5, 4.5, 7]$$$. You can perform this operation any number of times.What is the lexicographically smallest sequence of volumes of water that you can achieve?As a reminder:A sequence $$$a$$$ is lexicographically smaller than a sequence $$$b$$$ of the same length if and only if the following holds: in the first (leftmost) position where $$$a$$$ and $$$b$$$ differ, the sequence $$$a$$$ has a smaller element than the corresponding element in $$$b$$$.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the number of water tanks. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — initial volumes of water in the water tanks, in liters. Because of large input, reading input as doubles is not recommended.

Print the lexicographically smallest sequence you can get. In the $$$i$$$-th line print the final volume of water in the $$$i$$$-th tank. Your answer is considered correct if the absolute or relative error of each $$$a_i$$$ does not exceed $$$10^{-9}$$$. Formally, let your answer be $$$a_1, a_2, \dots, a_n$$$, and the jury's answer be $$$b_1, b_2, \dots, b_n$$$. Your answer is accepted if and only if $$$\frac{|a_i - b_i|}{\max{(1, |b_i|)}} \le 10^{-9}$$$ for each $$$i$$$.

NoteIn the first sample, you can get the sequence by applying the operation for subsegment $$$[1, 3]$$$.In the second sample, you can't get any lexicographically smaller sequence.

package main

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

type vec struct{ x, y int64 }

func (a vec) sub(b vec) vec   { return vec{a.x - b.x, a.y - b.y} }
func (a vec) det(b vec) int64 { return a.x*b.y - a.y*b.x }

// github.com/EndlessCheng/codeforces-go
func CF1299C(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n := read()
	s := make([]int64, n+1)
	ps := make([]vec, 1, n+1)
	for i := 1; i <= n; i++ {
		s[i] = s[i-1] + int64(read())
		p := vec{int64(i), s[i]}
		for {
			sz := len(ps)
			if sz <= 1 || ps[sz-1].sub(ps[sz-2]).det(p.sub(ps[sz-1])) > 0 {
				break
			}
			ps = ps[:sz-1]
		}
		ps = append(ps, p)
	}
	sz := len(ps)
	for i := 1; i < sz; i++ {
		a, b := ps[i-1], ps[i]
		l := b.x - a.x
		avg := float64(b.y-a.y) / float64(l)
		for ; l > 0; l-- {
			Fprintf(out, "%.9f\n", avg)
		}
	}
}

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

package main

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

type vec struct{ x, y int64 }

func (a vec) sub(b vec) vec   { return vec{a.x - b.x, a.y - b.y} }
func (a vec) det(b vec) int64 { return a.x*b.y - a.y*b.x }

// github.com/EndlessCheng/codeforces-go
func CF1299C(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n := read()
	s := make([]int64, n+1)
	ps := make([]vec, 1, n+1)
	for i := 1; i <= n; i++ {
		s[i] = s[i-1] + int64(read())
		p := vec{int64(i), s[i]}
		for {
			sz := len(ps)
			if sz <= 1 || ps[sz-1].sub(ps[sz-2]).det(p.sub(ps[sz-1])) > 0 {
				break
			}
			ps = ps[:sz-1]
		}
		ps = append(ps, p)
	}
	for i := 1; i < len(ps); i++ {
		a, b := ps[i-1], ps[i]
		l := b.x - a.x
		avg := float64(b.y-a.y) / float64(l)
		for ; l > 0; l-- {
			Fprintf(out, "%.9f\n", avg)
		}
	}
}

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

package main

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

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

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

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	avg := make([]float64, 0, n)
	count := make([]int, 0, n)
	for i := len(a) - 1; i >= 0; i-- {
		sum := float64(a[i])
		cc := 1
		best := float64(a[i])
		for len(avg) > 0 {
			m := len(avg) - 1
			x := (sum + avg[m]*float64(count[m])) / float64(cc+count[m])
			if x >= best {
				break
			}
			sum += avg[m] * float64(count[m])
			cc += count[m]
			avg = avg[:m]
			count = count[:m]
			best = x
		}
		avg = append(avg, best)
		count = append(count, cc)
	}

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

	for i := len(avg) - 1; i >= 0; i-- {
		for j := 0; j < count[i]; j++ {
			fmt.Fprintf(writer, "%.10f\n", avg[i])
		}
	}
}

package main

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

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

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

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	avg := make([]float64, 0, n)
	count := make([]int, 0, n)
	for i := len(a) - 1; i >= 0; i-- {
		sum := float64(a[i])
		cc := 1
		best := float64(a[i])
		for len(avg) > 0 {
			m := len(avg) - 1
			x := (sum + avg[m]*float64(count[m])) / float64(cc+count[m])
			if x >= best {
				break
			}
			sum += avg[m] * float64(count[m])
			cc += count[m]
			avg = avg[:m]
			count = count[:m]
			best = x
		}
		avg = append(avg, best)
		count = append(count, cc)
	}

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

	for i := len(avg) - 1; i >= 0; i-- {
		for j := 0; j < count[i]; j++ {
			fmt.Fprintf(writer, "%f\n", avg[i])
		}
	}
}


A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence (or, shortly, an RBS) is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example:  bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)");  bracket sequences ")(", "(" and ")" are not. There was an RBS. Some brackets have been replaced with question marks. Is it true that there is a unique way to replace question marks with brackets, so that the resulting sequence is an RBS?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of testcases. The only line of each testcase contains an RBS with some brackets replaced with question marks. Each character is either '(', ')' or '?'. At least one RBS can be recovered from the given sequence. The total length of the sequences over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print "YES" if the way to replace question marks with brackets, so that the resulting sequence is an RBS, is unique. If there is more than one way, then print "NO".

NoteIn the first testcase, the only possible original RBS is "(())".In the second testcase, there are multiple ways to recover an RBS.In the third and the fourth testcases, the only possible original RBS is "()".In the fifth testcase, the original RBS can be either "((()()))" or "(())()()".

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var s string
	fmt.Fscan(rr, &s)
	l, r, q := 0, 0, 0
	for i := range s {
		if s[i] == '(' {
			l++
		} else if s[i] == ')' {
			r++
		} else {
			q++
		}
	}
	nl, nr := 0, 0
	if l - r > 0 {
		nr = l - r
		nl += (q-nr)/2
		nr += (q-nr)/2
	} else {
		nl = r - l
		nr += (q-nl)/2
		nl += (q-nl)/2
	}
	ori_nr := nr
	if nl == 0 || nr == 0 {
		fmt.Fprintln(ww, "YES")
		return
	}
	cnt := 0
	for i := range s {
		if s[i] == '(' {
			cnt++
		} else if s[i] == ')' {
			cnt--
			if cnt <= 1 && nl == 0 && nr == ori_nr {
				fmt.Fprintln(ww, "YES")
				return
			}
		} else if s[i] == '?' {
			if nl > 0 {
				nl--
				if nl == 0 && cnt == 0 {
					fmt.Fprintln(ww, "YES")
					return
				}
				cnt++

			} else {
				nr--
				cnt--
			}
		}
	}
	fmt.Fprintln(ww, "NO")
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func sol() bool {
	s := myio.ReadBytes()
	l, r, q := 0, 0, 0
	// myio.Println(string(s))
	for _, c := range s {
		if c == '(' {
			l++
		} else if c == ')' {
			r++
		} else {
			q++
		}
	}
	nl := (l+r+q)/2 - l
	nr := (l+r+q)/2 - r
	u, ct := 0, 0
	// myio.Println(l, r, q, nl, nr)
	if nl == 0 || nr == 0 {
		return true
	}

	for _, c := range s {
		if c == '(' {
			u++
		} else if c == ')' {
			u--
		} else {
			ct++
			if ct < nl {
				u++
			} else if ct == nl {
				u--
			} else if ct == nl+1 {
				u++
			} else {
				u--
			}
		}
		if u < 0 {
			return true
		}
	}
	return false
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		if sol() {
			myio.Println("YES")
		} else {
			myio.Println("NO")
		}
	}
}

package main

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

func check(a []rune) bool {
    	check := 0
    	other := 0
    	for i := range a {
    		switch {
    		case a[i] == '(':
    			check++
    		case a[i] == ')':
    			check--
    		default:
    			other++
    		}
    	}
    	//Thx YT.
    	open  := (other - check) / 2
    	close := (other + check) / 2
    	if open == 0 || close == 0 {
    		return true
    	}
    	new_replace := []rune(new_str(open, close))
	i := 0
	for j, _ := range a {
		switch a[j] {
		case '?':
			a[j] = new_replace[i]
			i++
		}
	}
    	check = 0
    	for _, j := range a {
    		switch j {
    		case '(':
    			check++
    		default:
    			check--
    		}
    		if check < 0 { return true }
    	}
    	return false
}

func new_str(open, close int) string {
    	var new_string string
    	for i := 1; i < open; i++ {
    		new_string += "("
    	}
    	new_string += ")("
    	for i := 1; i < close; i++ {
    		new_string += ")"
    	}
    	return new_string
}

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

    	fmt.Fscan(reader, &testcase)
    	for testcase > 0 {
    		var a string
    		fmt.Fscan(reader, &a)
    		if check([]rune(a)) {
    			fmt.Fprintln(writer, "YES")
    		} else {
    			fmt.Fprintln(writer, "NO")
    		}
    		testcase--
    	}
}

package main

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

func main() {
	CF1709C(os.Stdin, os.Stdout)
}
func CF1709C(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

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

		num, p := 0, 0
		for i := 0; i < len(s); i++ {
			switch s[i] {
			case '(':
				num++
			case ')':
				num--
			case '?':
				p++
			}
			if num+p == 1 {
				num = 1
				p = 0
			}
		}

		if num == p {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
}

package main

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

var _, _, _ = main, rw, do

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

func rw(in io.Reader, out io.Writer) {
	var t int
	fmt.Fscan(in, &t)
	for ti := 0; ti < t; ti++ {
		var s string
		fmt.Fscan(in, &s)
		w1 := do(s)
		fmt.Fprintln(out, w1)
	}
}

func do(s string) string {
	b := []byte(s)
	l := len(b) / 2
	for _, c := range b {
		if c == '(' {
			l--
		}
	}
	var x, y int
	for i, c := range b {
		if c == '?' {
			l--
			b[i] = '('
			if l < 0 {
				b[i] = ')'
			}
			if l == 0 {
				x = i
			}
			if l == -1 {
				y = i
			}
		}
	}
	if y <= x {
		return "YES"
	}
	b[x], b[y] = b[y], b[x]
	l = 0
	for _, c := range b {
		if c == '(' {
			l++
		} else {
			l--
		}
		if l < 0 {
			return "YES"
		}
	}
	return "NO"
}

package main

import (
	"bufio"
	"math"
	"os"
	"strconv"
)

func solve() {
	k, x := 0, 0
	for _, c := range gets() {
		switch c {
		case '(':
			k++
		case ')':
			k--
		case '?':
			x++
		}
		if k+x == 1 {
			k, x = 1, 0
		}
	}
	yn(k == x)
}

const (
	once       = false
	maxBufSize = 10000000
)

var (
	splitFunc = bufio.ScanLines
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(splitFunc)
	in.Buffer(make([]byte, maxBufSize), maxBufSize)

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	t := get()
	for t > 0 {
		solve()
		t--
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func geta1(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get() - 1
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func get64a1(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64() - 1
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func line() {
	putc('\n')
}

func space() {
	putc(' ')
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES\n")
}

func no() {
	puts("NO\n")
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

type IntType interface {
	int | int64
}

type Type interface {
	IntType | float64
}

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

func fabs(x float64) float64 {
	return math.Abs(x)
}

func max1[T Type](x T, y T) T {
	if x > y {
		return x
	}
	return y
}

func max[T Type](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = max1(r, x)
	}
	return r
}

func maxa[T Type](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] <= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func min1[T Type](x T, y T) T {
	if x < y {
		return x
	}
	return y
}

func min[T Type](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = min1(r, x)
	}
	return r
}

func mina[T Type](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] >= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func L(i int) int64 {
	return int64(i)
}

func F(i int) float64 {
	return float64(i)
}

func ints(n int, val int) (a []int) {
	a = make([]int, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func int64s(n int, val int64) (a []int64) {
	a = make([]int64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func floats(n int, val float64) (a []float64) {
	a = make([]float64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

const heapBase = 4

func children(i int) (int, int) {
	start := heapBase * i
	return start + 1, start + (1 + heapBase)
}

func parent(i int) int {
	return (i - 1) / heapBase
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		s := readString(reader)
		res := solve(s)
		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

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
}

func solve(s string) bool {
	n := len(s)
	if n%2 == 1 {
		return false
	}
	cnt := make([]int, 3)

	for i := 0; i < n; i++ {
		if s[i] == '(' {
			cnt[0]++
		} else if s[i] == ')' {
			cnt[1]++
		} else {
			cnt[2]++
		}
	}

	// open = close = n / 2
	if cnt[0] > n/2 || cnt[1] > n/2 {
		return false
	}

	if cnt[2] == 0 {
		return cnt[0] == cnt[1]
	}

	// cnt[0] + x = n / 2
	x := n/2 - cnt[0]

	buf := []byte(s)
	a, b := -1, -1
	for i := 0; i < n; i++ {
		if buf[i] == '?' {
			if x > 0 {
				buf[i] = '('
				x--
				a = i
			} else {
				if b < 0 {
					b = i
				}
				buf[i] = ')'
			}
		}
	}
	var open int
	for i := 0; i < n; i++ {
		if buf[i] == '(' {
			open++
		} else {
			open--
		}
		if open < 0 {
			return false
		}
	}

	if open != 0 {
		return false
	}
	// a, b
	if a < 0 || b < 0 {
		// can't change
		return true
	}

	// a < b
	buf[a], buf[b] = buf[b], buf[a]

	for i := 0; i < n; i++ {
		if buf[i] == '(' {
			open++
		} else {
			open--
		}
		if open < 0 {
			return true
		}
	}

	return open != 0
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func test(s string) bool {
	n := len(s)
	prefix := make([]int, n+1)
	for i:=n-1;i>=0;i-- {
		prefix[i] = prefix[i+1]
		if s[i] == ')' {
			prefix[i]++
		} else if s[i] == '(' {
			prefix[i]--
		} else {
			prefix[i]--
		}
	}
	base := 0
	cnt := 0
	bias := 0
	ans := false
	for i := range s {
		//fmt.Fprintln(ww, cnt, bias, base, string(s[i:i+1]))
		if s[i] == '(' {
			base++
		} else if s[i] == ')' {
			base--
			if cnt - 2 + bias + base < 0 || cnt - 2 + bias + base - prefix[i+1] < 0 {
				bias += cnt
				cnt = 0
				ans = false
			}
		} else {
			cnt++
			if cnt - 2 + bias + base < 0 || cnt - 2 + bias + base - prefix[i+1] < 0 {
				bias += cnt
				cnt = 0
				ans = false
			} else if cnt >= 2 {
				ans = true
			}
		}
	}
	return ans
}

func slove() {
	var s string
	fmt.Fscan(rr, &s)
	n := len(s)
	ss := make([]byte, n)
	for i := range s {
		if s[i] == '(' {
			ss[n-i-1] = ')'
		} else if s[i] == ')' {
			ss[n-i-1] = '('
		} else {
			ss[n-i-1] = '?'
		}
	}
	if test(s) && test(string(ss)) {
		fmt.Fprintln(ww, "NO")
	} else {
		fmt.Fprintln(ww, "YES")
	}
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func test(s string) bool {
	n := len(s)
	prefix := make([]int, n+1)
	for i:=n-1;i>=0;i-- {
		prefix[i] = prefix[i+1]
		if s[i] == ')' {
			prefix[i]++
		} else if s[i] == '(' {
			prefix[i]--
		} else {
			prefix[i]--
		}
	}
	base := 0
	cnt := 0
	bias := 0
	for i := range s {
		//fmt.Fprintln(ww, cnt, bias, base, string(s[i:i+1]))
		if s[i] == '(' {
			base++
		} else if s[i] == ')' {
			base--
			if cnt - 2 + bias + base < 0 || cnt - 2 + bias + base - prefix[i+1] < 0 {
				bias += cnt
				cnt = 0
			}
		} else {
			cnt++
			if cnt - 2 + bias + base < 0 || cnt - 2 + bias + base - prefix[i+1] < 0 {
				bias += cnt
				cnt = 0
			} else if cnt >= 2 {
				return true
			}
		}
	}
	return false
}

func slove() {
	var s string
	fmt.Fscan(rr, &s)
	n := len(s)
	ss := make([]byte, n)
	for i := range s {
		if s[i] == '(' {
			ss[n-i-1] = ')'
		} else if s[i] == ')' {
			ss[n-i-1] = '('
		} else {
			ss[n-i-1] = '?'
		}
	}
	if test(s) && test(string(ss)) {
		fmt.Fprintln(ww, "NO")
	} else {
		fmt.Fprintln(ww, "YES")
	}
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var s string
	fmt.Fscan(rr, &s)
	n := len(s)
	prefix := make([]int, n+1)
	for i:=n-1;i>=0;i-- {
		prefix[i] = prefix[i+1]
		if s[i] == ')' {
			prefix[i]++
		} else if s[i] == '(' {
			prefix[i]--
		} else {
			prefix[i]--
		}
	}
	base := 0
	cnt := 0
	bias := 0
	for i := range s {
		//fmt.Fprintln(ww, cnt, bias, base, string(s[i:i+1]))
		if s[i] == '(' {
			base++
		} else if s[i] == ')' {
			base--
			if cnt - 2 + bias + base < 0 || cnt - 2 + bias + base - prefix[i+1] < 0 {
				bias += cnt
				cnt = 0
			}
		} else {
			cnt++
			if cnt - 2 + bias + base < 0 || cnt - 2 + bias + base - prefix[i+1] < 0 {
				bias += cnt
				cnt = 0
			} else if cnt >= 2 {
				fmt.Fprintln(ww, "NO")
				return
			}
		}
	}
	fmt.Fprintln(ww, "YES")
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var s string
	fmt.Fscan(rr, &s)
	n := len(s)
	prefix := make([]int, n+1)
	for i := range s {
		prefix[i+1] = prefix[i]
		if s[i] == ')' {
			prefix[i+1]++
		} else if s[i] == '(' {
			prefix[i+1]--
		} else {
			prefix[i+1]--
		}
	}
	base := 0
	cnt := 0
	bias := 0
	for i := range s {
		if s[i] == '(' {
			base++
		} else if s[i] == ')' {
			base--
		} else {
			cnt++
			if cnt - 2 + bias + base < 0 || cnt - 2 + bias + base - prefix[i] < 0 {
				bias += cnt
				cnt = 0
			} else if cnt >= 2 {
				fmt.Fprintln(ww, "NO")
				return
			}
		}
	}
	fmt.Fprintln(ww, "YES")
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func sol() bool {
	s := myio.ReadBytes()
	l, r, q := 0, 0, 0
	// myio.Println(string(s))
	for _, c := range s {
		if c == '(' {
			l++
		} else if c == ')' {
			r++
		} else {
			q++
		}
	}
	nl := (l+r+q)/2 - l
	nr := (l+r+q)/2 - r
	u, ct := 0, 0
	// myio.Println(l, r, q, nl, nr)
	if nl == 0 || nr == 0 {
		return true
	}

	for _, c := range s {
		if c == '(' {
			u++
		} else if c == ')' {
			u--
		} else {
			ct++
			if ct < nl {
				u++
			} else if ct == nl {
				if u == 0 {
					return true
				} else {
					return false
				}
			}
		}
	}
	return false
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		if sol() {
			myio.Println("YES")
		} else {
			myio.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func sol() bool {
	s := myio.ReadBytes()
	l, r, q := 0, 0, 0
	// myio.Println(string(s))
	for _, c := range s {
		if c == '(' {
			l++
		} else if c == ')' {
			r++
		} else {
			q++
		}
	}
	nl := (l+r+q)/2 - l
	nr := (l+r+q)/2 - r
	u, ct := 0, 0
	// myio.Println(l, r, q, nl, nr)
	if nl == 0 || nr == 0 {
		return true
	}

	for _, c := range s {
		if c == '{' {
			u++
		} else if c == '}' {
			u--
		} else {
			ct++
			if ct < nl {
				u++
			} else if ct == nl {
				if u == 0 {
					return true
				} else {
					return false
				}
			}
		}
	}
	return false
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		if sol() {
			myio.Println("YES")
		} else {
			myio.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	"math"
	"os"
	"strconv"
)

func solve() {
	k, x := 0, 0
	for c := range gets() {
		switch c {
		case '(':
			k++
		case ')':
			k--
		case '?':
			x++
		}
		if 1-k == x {
			x = 0
			k = 1
		}
	}
	yn(k == x)
}

const (
	once       = false
	maxBufSize = 10000000
)

var (
	splitFunc = bufio.ScanLines
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(splitFunc)
	in.Buffer(make([]byte, maxBufSize), maxBufSize)

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	t := get()
	for t > 0 {
		solve()
		t--
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func geta1(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get() - 1
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func get64a1(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64() - 1
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func line() {
	putc('\n')
}

func space() {
	putc(' ')
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES\n")
}

func no() {
	puts("NO\n")
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

type IntTp interface {
	int | int64
}

type Tp interface {
	IntTp | float64
}

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

func fabs(x float64) float64 {
	return math.Abs(x)
}

func max1[T Tp](x T, y T) T {
	if x > y {
		return x
	}
	return y
}

func max[T Tp](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = max1(r, x)
	}
	return r
}

func maxa[T Tp](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] <= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func min1[T Tp](x T, y T) T {
	if x < y {
		return x
	}
	return y
}

func min[T Tp](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = min1(r, x)
	}
	return r
}

func mina[T Tp](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] >= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func L(i int) int64 {
	return int64(i)
}

func F(i int) float64 {
	return float64(i)
}

func ints(n int, val int) (a []int) {
	a = make([]int, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func int64s(n int, val int64) (a []int64) {
	a = make([]int64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func floats(n int, val float64) (a []float64) {
	a = make([]float64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

const heapBase = 4

func children(i int) (int, int) {
	start := heapBase * i
	return start + 1, start + (1 + heapBase)
}

func parent(i int) int {
	return (i - 1) / heapBase
}


The grasshopper is located on the numeric axis at the point with coordinate $$$x_0$$$.Having nothing else to do he starts jumping between integer points on the axis. Making a jump from a point with coordinate $$$x$$$ with a distance $$$d$$$ to the left moves the grasshopper to a point with a coordinate $$$x - d$$$, while jumping to the right moves him to a point with a coordinate $$$x + d$$$.The grasshopper is very fond of positive integers, so for each integer $$$i$$$ starting with $$$1$$$ the following holds: exactly $$$i$$$ minutes after the start he makes a jump with a distance of exactly $$$i$$$. So, in the first minutes he jumps by $$$1$$$, then by $$$2$$$, and so on.The direction of a jump is determined as follows: if the point where the grasshopper was before the jump has an even coordinate, the grasshopper jumps to the left, otherwise he jumps to the right.For example, if after $$$18$$$ consecutive jumps he arrives at the point with a coordinate $$$7$$$, he will jump by a distance of $$$19$$$ to the right, since $$$7$$$ is an odd number, and will end up at a point $$$7 + 19 = 26$$$. Since $$$26$$$ is an even number, the next jump the grasshopper will make to the left by a distance of $$$20$$$, and it will move him to the point $$$26 - 20 = 6$$$.Find exactly which point the grasshopper will be at after exactly $$$n$$$ jumps.

The first line of input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Each of the following $$$t$$$ lines contains two integers $$$x_0$$$ ($$$-10^{14} \leq x_0 \leq 10^{14}$$$) and $$$n$$$ ($$$0 \leq n \leq 10^{14}$$$) — the coordinate of the grasshopper's initial position and the number of jumps.

Print exactly $$$t$$$ lines. On the $$$i$$$-th line print one integer — the answer to the $$$i$$$-th test case — the coordinate of the point the grasshopper will be at after making $$$n$$$ jumps from the point $$$x_0$$$.

NoteThe first two test cases in the example correspond to the first two jumps from the point $$$x_0 = 0$$$. Since $$$0$$$ is an even number, the first jump of length $$$1$$$ is made to the left, and the grasshopper ends up at the point $$$0 - 1 = -1$$$.Then, since $$$-1$$$ is an odd number, a jump of length $$$2$$$ is made to the right, bringing the grasshopper to the point with coordinate $$$-1 + 2 = 1$$$.

// 00
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var x, n int64
		fmt.Fscan(reader, &x, &n)
		if n%4 == 0 {
			fmt.Println(x)
		} else {
			ex := ((n - 1) / 4) * 4
			ex++
			if (n-1)%4 == 1 {
				ex -= n
			} else if (n-1)%4 == 2 {
				ex -= n
				ex -= n - 1
			} else if (n-1)%4 == 3 {
				ex -= n - 2
			}
			if x%2 == 0 {
				ex = x - ex
			} else {
				ex += x
			}
			fmt.Println(ex)
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var x0, n int64
		fmt.Scan(&x0, &n)
		if x0%2 == 0 {
			switch n % 4 {
			case 0:
				fmt.Println(x0)
			case 1:
				fmt.Println(x0 - n)
			case 2:
				fmt.Println(x0 + 1)
			default:
				fmt.Println(x0 + n + 1)
			}
		} else {
			switch n % 4 {
			case 0:
				fmt.Println(x0)
			case 1:
				fmt.Println(x0 + n)
			case 2:
				fmt.Println(x0 - 1)
			default:
				fmt.Println(x0 - n - 1)
			}
		}
	}
}

package main

import "fmt"

const (
	T_MIN = 1
	T_MAX = int64(1e4)
	X_MIN = int64(-1e14)
	X_MAX = int64(1e14)
	N_MIN = 0
	N_MAX = int64(1e14)
)

func evenCase(x, n int64) int64 {
	n4 := n % 4
	switch n4 {
	case 0:
		return x
	case 1:
		return x - n
	case 2:
		return x + 1
	case 3:
		return x + n + 1
	}
	return 0
}

func oddCase(x, n int64) int64 {
	n4 := n % 4
	switch n4 {
	case 0:
		return x
	case 1:
		return x + n
	case 2:
		return x - 1
	case 3:
		return x - n - 1
	}
	return 0
}

func main() {
	var t int
	fmt.Scanf("%v\n", &t)
	for i := 0; i < t; i++ {
		var x, n int64
		fmt.Scanf("%v %v\n", &x, &n)
		if x&1 == 0 {
			fmt.Println(evenCase(x, n))
		} else {
			fmt.Println(oddCase(x, n))
		}
	}
}

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var x, n int64
    fmt.Fscan(input, &x, &n)
    if n == 0 {
        fmt.Fprintln(output, x)
        return
    }
    ans := int64(0)
    if x & 1 == 1 {
        c := (n - 1) / 4
        ans = 1 + c * 4
        rem := (n - 1) % 4
        if rem == 3 {
            ans += n - (n - 1) - (n - 2)
        }
        if rem == 2 {
            ans += - n - (n - 1)
        }
        if rem == 1 {
            ans -= n
        }
    } else {
        c := (n - 1) / 4
        ans = -1 - c * 4
        rem := (n - 1) % 4
        if rem == 3 {
            ans += -n + n - 1 + n - 2
        }
        if rem == 2 {
            ans += n + n - 1
        }
        if rem == 1 {
            ans += n
        }
    }
    fmt.Fprintln(output, x + ans)
}

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

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

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

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
}

package main
import (
    "bufio"
    "fmt"
    "os"
)
//+1 -2 -3 +4
type ll int64
var scan = fmt.Fscan
var println = fmt.Fprintln
//var print = fmt.Fprint

var in *bufio.Reader
var out *bufio.Writer
func init(){
    in = bufio.NewReader(os.Stdin)
    out = bufio.NewWriter(os.Stdout)
}

func main(){
	defer out.Flush()
	var t int; scan(in,&t)
	for ;t>0;t-- {
		var a, b ll
		scan(in,&a,&b)
		c := ((b>>2)<<2)
		p := -1
		if(a%2==1 || a%2 == -1) {p = -p}
		for i,j:=c+1,1;i<=b;i,j=i+1,j+1{
			if(j%2==0) {p = -p}
			a += ll(i) * ll(p)
		}

		println(out,a)
	}
}

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 x, n int64
		fmt.Fscan(in, &x, &n)

		var d int64
		switch n % 4 {
		case 0:
			d = 0
		case 1:
			d = -n
		case 2:
			d = 1
		case 3:
			d = n + 1
		}

		if x%2 == 0 {
			fmt.Fprintln(out, x+d)
		} else {
			fmt.Fprintln(out, x-d)
		}
	}
}

package main

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

/*
9
100 0
100 1
100 2
100 3
100 4
100 5
100 6
100 7
100 8
---
100
99
101
104
100
95
101
108
100
======
1
0 2
---
1
*/

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

	bld := strings.Builder{}

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

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

		start := n/4*4 + 1
		x := x0

		for i := start; i <= n; i++ {
			if x%2 != 0 {
				x += i
			} else {
				x -= i
			}
		}

		fmt.Fprintln(&bld, x)
	}

	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 {
	x int64
	y int64
}

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 {
	num = abs(num)

	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"
)

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

func solve(x, n int64) int64 {
	d := n + 1
	if n%4 == 0 {
		d = 0
	} else if n%4 == 1 {
		d = -n
	} else if n%4 == 2 {
		d = 1
	}
	if x%2 == 0 {
		return x + d
	}
	return x - d
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &x, &n)
		fmt.Println(solve(x, n))
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)
	for t > 0 {
		t--
		var x,n int64
		fmt.Scanln(&x,&n)
		if n%4==0{
			fmt.Println(x)
			continue
		}else{
			var i int64 = (n%4)
			n-=n%4
			n++
			for i>0{
				i--
				if x%2==0{
					x-=n
				}else{
					x+=n
				}
				n++
			}
		}
		fmt.Println(x)
	}
}

package main

import (
	"fmt"
)

func scan(p ...interface{}) {
	fmt.Scan(p...)
}

func proc() int64 {
	var x, n int64
	scan(&x, &n)
	i := n
	if n == 0 {
		return x
	}
	if x&1 == 0 {
		x--
	} else {
		x++
	}
	n--
	if n == 0 {
		return x
	}
	b := n / 4
	n %= 4
	if x&1 == 0 {
		x += b * 4
	} else {
		x -= b * 4
	}
	for n = i - n + 1; n <= i; n++ {
		if x&1 == 0 {
			x -= n
		} else {
			x += n
		}
	}
	return x
}

func main() {
	var t int
	scan(&t)
	for i := 0; i < t; i++ {
		fmt.Println(proc())
	}
}

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 {
		x0, n := readTwoInt64(reader)

		s := sum(1, (n+3)/4) + sum(0, n/4+1) - sum(2, (n+2)/4) - sum(3, (n+1)/4)

		if x0 % 2 == 0 {
			x0 -= s
		} else {
			x0 += s
		}

		fmt.Fprintln(writer, x0)
		t--
	}

	writer.Flush()
}

func sum(a1 int64, n int64) int64 {
	return (2*a1 + (n-1)*4)*n/2
}

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]
}

// 00
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var x, n int64
		fmt.Fscan(reader, &x, &n)
		if n == 0 || n == 4 {
			fmt.Println(x)
		} else {
			ex := ((n - 1) / 4) * 4
			ex++
			if (n-1)%4 == 1 {
				ex -= n
			} else if (n-1)%4 == 2 {
				ex -= n
				ex -= n - 1
			} else if (n-1)%4 == 3 {
				ex -= n - 2
			}
			if x%2 == 0 {
				ex = x - ex
			} else {
				ex += x
			}
			fmt.Println(ex)
		}

	}
}

// 00
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var x, n int64
		fmt.Fscan(reader, &x, &n)
		if n == 0 {
			fmt.Println(x)
		} else {
			ex := ((n - 1) / 4) * 4
			ex++
			if (n-1)%4 == 1 {
				ex -= n
			} else if (n-1)%4 == 2 {
				ex -= n
				ex -= n - 1
			} else if (n-1)%4 == 3 {
				ex -= n - 2
			}
			if x%2 == 0 {
				ex = x - ex
			} else {
				ex += x
			}
			fmt.Println(ex)
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var x0, n int
		fmt.Scan(&x0, &n)
		if x0%2 == 0 {
			switch n % 4 {
			case 0:
				fmt.Println(x0)
			case 1:
				fmt.Println(x0 - n)
			case 2:
				fmt.Println(x0 + 1)
			default:
				fmt.Println(x0 + n + 1)
			}
		} else {
			switch n % 4 {
			case 0:
				fmt.Println(x0)
			case 1:
				fmt.Println(x0 + n)
			case 2:
				fmt.Println(x0 - 1)
			default:
				fmt.Println(x0 - n - 1)
			}
		}
	}
}

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var x, n int64
    fmt.Fscan(input, &x, &n)
    if n == 0 {
        fmt.Fprintln(output, x)
        return
    }
    ans := int64(0)
    if x & 1 == 1 {
        c := (n - 1) / 4
        ans = 1 + c * 4
        rem := (n - 1) % 4
        if rem == 3 {
            ans = n - (n - 1) - (n - 2)
        }
        if rem == 2 {
            ans += - n - (n - 1)
        }
        if rem == 1 {
            ans -= n
        }
    } else {
        c := (n - 1) / 4
        ans = -1 - c * 4
        rem := (n - 1) % 4
        if rem == 3 {
            ans += -n + n - 1 + n - 2
        }
        if rem == 2 {
            ans += n + n - 1
        }
        if rem == 1 {
            ans += n
        }
    }
    fmt.Fprintln(output, x + ans)
}

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

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

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

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
}


You are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something!You have $$$n$$$ tickets to sell. The price of the $$$i$$$-th ticket is $$$p_i$$$. As a teller, you have a possibility to select the order in which the tickets will be sold (i.e. a permutation of the tickets). You know that the cinema participates in two ecological restoration programs applying them to the order you chose:  The $$$x\%$$$ of the price of each the $$$a$$$-th sold ticket ($$$a$$$-th, $$$2a$$$-th, $$$3a$$$-th and so on) in the order you chose is aimed for research and spreading of renewable energy sources.  The $$$y\%$$$ of the price of each the $$$b$$$-th sold ticket ($$$b$$$-th, $$$2b$$$-th, $$$3b$$$-th and so on) in the order you chose is aimed for pollution abatement. If the ticket is in both programs then the $$$(x + y) \%$$$ are used for environmental activities. Also, it's known that all prices are multiples of $$$100$$$, so there is no need in any rounding.For example, if you'd like to sell tickets with prices $$$[400, 100, 300, 200]$$$ and the cinema pays $$$10\%$$$ of each $$$2$$$-nd sold ticket and $$$20\%$$$ of each $$$3$$$-rd sold ticket, then arranging them in order $$$[100, 200, 300, 400]$$$ will lead to contribution equal to $$$100 \cdot 0 + 200 \cdot 0.1 + 300 \cdot 0.2 + 400 \cdot 0.1 = 120$$$. But arranging them in order $$$[100, 300, 400, 200]$$$ will lead to $$$100 \cdot 0 + 300 \cdot 0.1 + 400 \cdot 0.2 + 200 \cdot 0.1 = 130$$$.Nature can't wait, so you decided to change the order of tickets in such a way, so that the total contribution to programs will reach at least $$$k$$$ in minimum number of sold tickets. Or say that it's impossible to do so. In other words, find the minimum number of tickets which are needed to be sold in order to earn at least $$$k$$$.

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of independent queries. Each query consists of $$$5$$$ lines. The first line of each query contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of tickets. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$100 \le p_i \le 10^9$$$, $$$p_i \bmod 100 = 0$$$) — the corresponding prices of tickets. The third line contains two integers $$$x$$$ and $$$a$$$ ($$$1 \le x \le 100$$$, $$$x + y \le 100$$$, $$$1 \le a \le n$$$) — the parameters of the first program. The fourth line contains two integers $$$y$$$ and $$$b$$$ ($$$1 \le y \le 100$$$, $$$x + y \le 100$$$, $$$1 \le b \le n$$$) — the parameters of the second program. The fifth line contains single integer $$$k$$$ ($$$1 \le k \le 10^{14}$$$) — the required total contribution. It's guaranteed that the total number of tickets per test doesn't exceed $$$2 \cdot 10^5$$$.

Print $$$q$$$ integers — one per query.  For each query, print the minimum number of tickets you need to sell to make the total ecological contribution of at least $$$k$$$ if you can sell tickets in any order. If the total contribution can not be achieved selling all the tickets, print $$$-1$$$.

NoteIn the first query the total contribution is equal to $$$50 + 49 = 99 < 100$$$, so it's impossible to gather enough money.In the second query you can rearrange tickets in a following way: $$$[100, 100, 200, 200, 100, 200, 100, 100]$$$ and the total contribution from the first $$$6$$$ tickets is equal to $$$100 \cdot 0 + 100 \cdot 0.1 + 200 \cdot 0.15 + 200 \cdot 0.1 + 100 \cdot 0 + 200 \cdot 0.25 = 10 + 30 + 20 + 50 = 110$$$.In the third query the full price of each ticket goes to the environmental activities.In the fourth query you can rearrange tickets as $$$[100, 200, 100, 100, 100]$$$ and the total contribution from the first $$$4$$$ tickets is $$$100 \cdot 0 + 200 \cdot 0.31 + 100 \cdot 0 + 100 \cdot 0.31 = 62 + 31 = 93$$$.

package main

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

const debug = false

var in = bufio.NewReader(os.Stdin)
var n, x, a, y, b int
var k int64

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

func can(p []int32, m int) bool {
	nab := int(int64(m) / (int64(a / gcd(a, b)) * int64(b)))
	na := m/a - nab
	nb := m/b - nab
	if debug {
		log.Println(m, nab, na, nb)
	}
	var kk int64
	i := 0
	for ; nab > 0 && i < m; nab-- {
		kk += int64(p[i]) * int64(x+y)
		i++
	}
	for ; na > 0 && i < m; na-- {
		kk += int64(p[i]) * int64(x)
		i++
	}
	for ; nb > 0 && i < m; nb-- {
		kk += int64(p[i]) * int64(y)
		i++
	}
	return kk >= k
}

func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	var q int
	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		fmt.Fscan(in, &n)
		p := make([]int32, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &p[i])
			p[i] /= 100
		}
		fmt.Fscan(in, &x, &a, &y, &b, &k)
		sort.Slice(p, func(i, j int) bool { return p[i] > p[j] })
		if x < y {
			x, y = y, x
			a, b = b, a
		}
		lo := 1
		hi := n
		for lo < hi {
			mid := (lo + hi) / 2
			if can(p, mid) {
				hi = mid
			} else {
				lo = mid + 1
			}
		}
		if !can(p, lo) {
			lo = -1
		}
		fmt.Println(lo)
	}
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of `strconv.Atoi()`.
// If `strconv.Atoi()` returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		// str := strconv.FormatInt(A[i], 10)  // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var q int

func main() {
	q = ReadInt()

	for i := 0; i < q; i++ {
		n := ReadInt()
		P := ReadIntSlice(n)
		for j := 0; j < n; j++ {
			P[j] /= 100
		}
		x, a := ReadInt2()
		y, b := ReadInt2()
		k := ReadInt64()

		sort.Sort(sort.Reverse(sort.IntSlice(P)))
		percents := make([]int, n)
		for j := 0; j < n; j++ {
			if (j+1)%a == 0 && (j+1)%b == 0 {
				percents[j] = x + y
			} else if (j+1)%a == 0 {
				percents[j] = x
			} else if (j+1)%b == 0 {
				percents[j] = y
			}
		}
		// fmt.Println(percents)

		// m は中央を意味する何らかの値
		isOK := func(m int) bool {
			tmp := make([]int, m)
			for h := 0; h < m; h++ {
				tmp[h] = percents[h]
			}
			sort.Sort(sort.Reverse(sort.IntSlice(tmp)))

			val := int64(0)
			for h := 0; h < m; h++ {
				val += int64(tmp[h]) * int64(P[h])
			}

			if val >= k {
				return true
			}
			return false
		}

		ng, ok := -1, n
		for int(math.Abs(float64(ok-ng))) > 1 {
			mid := (ok + ng) / 2
			if isOK(mid) {
				ok = mid
			} else {
				ng = mid
			}
		}

		if isOK(ok) {
			fmt.Println(ok)
		} else {
			fmt.Println(-1)
		}
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

package main

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

const debug = false

var in = bufio.NewReader(os.Stdin)
var n, x, a, y, b int
var k int64

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

func can(p []int32, m int) bool {
	nab := m / ((a * b) / gcd(a, b))
	na := m/a - nab
	nb := m/b - nab
	if debug {
		log.Println(m, nab, na, nb)
	}
	var kk int64
	i := 0
	for ; nab > 0 && i < m; nab-- {
		kk += int64(p[i]) * int64(x+y)
		i++
	}
	for ; na > 0 && i < m; na-- {
		kk += int64(p[i]) * int64(x)
		i++
	}
	for ; nb > 0 && i < m; nb-- {
		kk += int64(p[i]) * int64(y)
		i++
	}
	return kk >= k
}

func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	var q int
	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		fmt.Fscan(in, &n)
		p := make([]int32, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &p[i])
			p[i] /= 100
		}
		fmt.Fscan(in, &x, &a, &y, &b, &k)
		sort.Slice(p, func(i, j int) bool { return p[i] > p[j] })
		if x < y {
			x, y = y, x
			a, b = b, a
		}
		lo := 1
		hi := n
		for lo < hi {
			mid := (lo + hi) / 2
			if can(p, mid) {
				hi = mid
			} else {
				lo = mid + 1
			}
		}
		if !can(p, lo) {
			lo = -1
		}
		fmt.Println(lo)
	}
}

package main

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

const debug = false

var in = bufio.NewReader(os.Stdin)
var n, x, a, y, b int
var k int64

func can(p []int32, m int) bool {
	nab := m / (a * b)
	na := m/a - nab
	nb := m/b - nab
	if debug {
		log.Println(m, nab, na, nb)
	}
	var kk int64 = 0
	i := 0
	for ; nab > 0 && i < m; nab-- {
		kk += int64(p[i]) * int64(x+y)
		i++
	}
	for ; na > 0 && i < m; na-- {
		kk += int64(p[i]) * int64(x)
		i++
	}
	for ; nb > 0 && i < m; nb-- {
		kk += int64(p[i]) * int64(y)
		i++
	}
	return kk >= k
}

func main() {
	if debug {
		log.SetFlags(log.LstdFlags | log.Lshortfile)
	}
	var q int
	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		fmt.Fscan(in, &n)
		p := make([]int32, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &p[i])
			p[i] /= 100
		}
		fmt.Fscan(in, &x, &a, &y, &b, &k)
		sort.Slice(p, func(i, j int) bool { return p[i] > p[j] })
		if x < y {
			x, y = y, x
			a, b = b, a
		}
		lo := 1
		hi := n
		for lo < hi {
			mid := (lo + hi) / 2
			if can(p, mid) {
				hi = mid
			} else {
				lo = mid + 1
			}
		}
		if !can(p, lo) {
			lo = -1
		}
		fmt.Println(lo)
	}
}