There is an integer $$$n$$$ without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns.On her turn, Alice must swap any two digits of the integer that are on different positions. Bob on his turn always removes the last digit of the integer. The game ends when there is only one digit left.You have to find the smallest integer Alice can get in the end, if she plays optimally.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. The first and the only line of each test case contains the integer $$$n$$$ ($$$10 \le n \le 10^9$$$) — the integer for the game. $$$n$$$ does not have zeros in its decimal representation.

NoteIn the first test case Alice has to swap $$$1$$$ and $$$2$$$. After that Bob removes the last digit, $$$1$$$, so the answer is $$$2$$$.In the second test case Alice can swap $$$3$$$ and $$$1$$$: $$$312$$$. After that Bob deletes the last digit: $$$31$$$. Then Alice swaps $$$3$$$ and $$$1$$$: $$$13$$$ and Bob deletes $$$3$$$, so the answer is $$$1$$$.

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n uint64
	fmt.Sscanf(scanner.Text(), "%d", &n)

	for i := uint64(0); i < n; i++ {
		scanner.Scan()
		k := scanner.Text()

		if len(k) == 2 {
			fmt.Println(string(k[1]))
			continue
		}
		min := k[0]
		for i := 0; i < len(k); i++ {
			if k[i] < min {
				min = k[i]
			}
		}
		fmt.Println(string(min))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	// two digit number -- forced to take rightmost digit
	// three digit number -- can get left or right but not middle
	// four digit number -- can get any of the digits
	T := gi()
	for tt:=1;tt<=T;tt++ {
		s := gs(); ansarr := make([]byte,1)
		if len(s) == 2 {
			ansarr[0] = s[1]
		} else {
			ansarr[0] = s[0]
			for _,c := range s { if byte(c) < ansarr[0] { ansarr[0] = byte(c) } }
		}
		fmt.Fprintln(wrtr,string(ansarr))
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	defer w.Flush()
	var s string
	fmt.Fscan(r, &s)
	ans := s[0]
	if len(s) == 2 {
		fmt.Fprintln(w, string(s[1]))
	} else {
		for i := range s {
			ans = min(ans, s[i])
		}
		fmt.Fprintln(w, string(ans))
	}
}

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

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

package main

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

func A1() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		if n < 99 {
			Fprintln(out, n%10)
		} else {
			var min = 10
			for n > 0 {
				if n%10 < min {
					min = n % 10
				}
				n /= 10
			}
			Fprintln(out, min)
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A1() }

package main
import(
    "fmt"
    "bufio"
    "os"
    "strconv"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var word string
		fmt.Fscan(in,&word)
		if len(word) == 2 {
			fmt.Fprintln(out,string(word[1]))
		} else {
			smallest:=0
			for j:=0;j<len(word);j++{
				x,_:= strconv.Atoi(string(word[j]))
				if j==0{
					smallest=x
				} else {
					if x <= smallest {
						smallest=x
					}
				}
			}
			fmt.Fprintln(out,smallest)
		}
	}
}

// https://codeforces.com/problemset/problem/1684/A

// 1684A. Digit Minimization

// There is an integer n without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns.
// On her turn, Alice must swap any two digits of the integer that are on different positions. Bob on his turn always removes the last digit of the integer. The game ends when there is only one digit left.
// You have to find the smallest integer Alice can get in the end, if she plays optimally.

// Input
// The input consists of multiple test cases. The first line contains a single integer t (1≤t≤10^4) — the number of test cases. Description of the test cases follows.
// The first and the only line of each test case contains the integer n (10≤n≤10^9) — the integer for the game. n does not have zeros in its decimal representation.

// Output
// For each test case output a single integer — the smallest integer Alice can get in the end of the game.

// Example
// input
// 3
// 12
// 132
// 487456398
// output
// 2
// 1
// 3

// Note

// In the first test case Alice has to swap 1 and 2. After that Bob removes the last digit, 1, so the answer is 2.
// In the second test case Alice can swap 3 and 1: 312. After that Bob deletes the last digit: 31. Then Alice swaps 3 and 1: 13 and Bob deletes 3, so the answer is 1.

// Tutorial

// Let k be the length of n. Let ni be the i-th digit of n (1-indexation from the left).
//  • k=1
//    The game ends immediately so the answer is n itself.
//  • k=2
//    Alice should make the first move and she has to swap n1 and n2. After that Bob removes n1 and in the end there is only n2.
//  • k≥3
//    Alice can make swaps in such way that when there are only two digits left the second digit will be the maximal digit of n. Then she will make a swap and the maximal digit will be on the first position. The other one will be removed by Bob. This way she can always get the maximal digit of n in the end of the game.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c, i int
	var t uint
	var n string
	var ans byte

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

			if len(n) == 2 {
				ans = n[1]
			} else {
				ans = n[0]

				for i = 1; i < len(n); i++ {
					if ans > n[i] {
						ans = n[i]
					}
				}
			}

			fmt.Fprintln(writer, ans-'0')
		}
	}

	writer.Flush()
}

package main

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

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

func main() {

	var n int
	fmt.Fscan(in, &n)
	for 0 < n {
		n--
		solve()
	}
	defer out.Flush()
}

func solve() {
	var s string
	var min int64
	min = math.MaxInt64
	fmt.Fscan(in, &s)
	for i := 0; i < len(s); i++ {
		l, _ := strconv.ParseInt(string(s[i]), 0, 0)
		min = Min(min, l)
	}
	if len(s) == 2 {
		fmt.Fprintln(out, string(s[1]))
	} else {
		fmt.Fprintln(out, min)
	}
}

func Min(a int64, b int64) int64 {

	if a > b {
		return b
	}
	return a
}

package main

import "fmt"

func solve() {
	var n int64
	fmt.Scan(&n)
	if n < 100 {
		fmt.Println(n % 10)
		return
	}
	result := int64(9)
	for n > 0 {
		cur := n % 10
		n /= 10
		if cur < result {
			result = cur
		}
	}
	fmt.Println(result)
}

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1684A
Date: 21/05/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1684/A
Problem: CF1684A
**/
func (in *CF1684A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		ans := -1
		if len(str) == 2 {
			ans = int(str[len(str)-1]-'0')
		}else {
			for i:=0;i<len(str);i++{
				if ans == -1 {
					ans = int(str[i]-'0')
				}else if ans >  int(str[i]-'0'){
					ans = int(str[i]-'0')
				}
			}
		}
		fmt.Println(ans)
	}
}

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

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

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		s, _ := reader.ReadString('\n')
		if s[len(s)-1] == 10 {
			s = s[:len(s)-1]
		}
		if s[len(s)-1] == 13 {
			s = s[:len(s)-1]
		}

		sml := rune('9')
		for i := 0; i < len(s); i++ {
			if rune(s[i]) < sml {
				sml = rune(s[i])
			}
		}

		if len(s) > 2 {
			fmt.Println(string(sml))
		} else {
			fmt.Println(string(s[len(s)-1]))
		}
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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
}

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	for t := io.ReadInt(); t > 0; t-- {
		s := io.ReadString()
		if len(s) == 2 {
			fmt.Println(int(s[1] - byte('0')))
			continue
		}
		mn := 10
		for i := 0; i < len(s); i++ {
			mn = min(mn, int(s[i]-byte('0')))
		}
		fmt.Println(mn)
		//abc := io.ReadIntSlice(3)
		//fmt.Println(abc[0], abc[1], abc[0]+abc[2])
	}
}

package main

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

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

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

		x := s[len(s)-1]
		for i := 0; i < len(s)-1; i++ {
			if s[i] < x {
				x = s[i]
			}
		}

		if len(s) <= 2 {
			fmt.Fprintln(out, s[1]-'0')
		} else {
			fmt.Fprintln(out, x-'0')
		}
	}
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"os"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var s string
		Fscan(in, &s)
		if len(s) == 2 {
			Fprintln(out, s[1]-'0')
		} else {
			mi := '9'
			for _, ch := range s {
				if mi > ch {
					mi = ch
				}
			}
			Fprintln(out, mi-'0')
		}

	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n uint64
	fmt.Sscanf(scanner.Text(), "%d", &n)

	for i := uint64(0); i < n; i++ {
		scanner.Scan()
		k := scanner.Text()

		if len(k) == 2 {
			fmt.Println(string(k[1]))
			continue
		}
		if len(k) == 3 {
			if k[0] > k[1] {
				fmt.Println(string(k[1]))
			} else {
				fmt.Println(string(k[0]))
			}
			continue
		}
		min := k[0]
		for i := 0; i < len(k); i++ {
			if k[i] < min {
				min = k[i]
			}
		}
		fmt.Println(string(min))
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n uint64
	fmt.Sscanf(scanner.Text(), "%d", &n)

	for i := uint64(0); i < n; i++ {
		scanner.Scan()
		k := scanner.Text()
		if len(k) == 2 {
			fmt.Println(string(k[1]))
			continue
		}
		min := k[0]
		for i := 0; i < len(k)-1; i++ {
			if k[i] < min {
				min = k[i]
			}
		}
		fmt.Println(string(min))
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n uint64
	fmt.Sscanf(scanner.Text(), "%d", &n)

	for i := uint64(0); i < n; i++ {
		scanner.Scan()
		k := scanner.Text()
		if len(k) == 2 {
			fmt.Println(string(k[1]))
			continue
		}
		fmt.Println(">>>", k)
		min := k[0]
		for i := 0; i < len(k)-1; i++ {
			fmt.Printf("%d=%c,", i, k[i])
			if k[i] < min {
				min = k[i]
			}
		}
		fmt.Println(string(min))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	// two digit number -- forced to take rightmost digit
	// three digit number -- can get left or right but not middle
	// four digit number -- can get any of the digits
	T := gi()
	for tt:=1;tt<=T;tt++ {
		s := gs(); ans := "0"
		if len(s) == 2 {
			ans = s[1:2]
		} else if len(s) == 3 {
			ans = s[0:1]
			if s[2:3] < ans { ans = s[2:3] }
		} else {
			ans = "9"
			for i:=0;i<len(s);i++ {
				if s[i:i+1] < ans { ans = s[i:i+1] }
			}
		}
		fmt.Fprintln(wrtr,ans)
	}

}

package main

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

func A1() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	//Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		if n < 99 {
			Fprintln(out, n%10)
		} else {
			var min = 10
			for n > 0 {
				if n%10 < min {
					min = n % 10
				}
				n /= 10
			}
			Fprintln(out, min)
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A1() }


Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two intersections.  Initially anyone can pass any road for free. But since SlapsGiving is ahead of us, there will q consecutive events happen soon. There are two types of events:1. Government makes a new rule. A rule can be denoted by integers v, u and w. As the result of this action, the passing fee of all roads on the shortest path from u to v increases by w dollars. 2. Barney starts moving from some intersection v and goes to intersection u where there's a girl he wants to cuddle (using his fake name Lorenzo Von Matterhorn). He always uses the shortest path (visiting minimum number of intersections or roads) between two intersections.Government needs your calculations. For each time Barney goes to cuddle a girl, you need to tell the government how much money he should pay (sum of passing fee of all roads he passes).

The first line of input contains a single integer q (1 ≤ q ≤ 1 000). The next q lines contain the information about the events in chronological order. Each event is described in form 1 v u w if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest path from u to v by w dollars, or in form 2 v u if it's an event when Barnie goes to cuddle from the intersection v to the intersection u. 1 ≤ v, u ≤ 1018, v ≠ u, 1 ≤ w ≤ 109 states for every description line.

For each event of second type print the sum of passing fee of all roads Barney passes in this event, in one line. Print the answers in chronological order of corresponding events.

NoteIn the example testcase:Here are the intersections used:    Intersections on the path are 3, 1, 2 and 4.  Intersections on the path are 4, 2 and 1.  Intersections on the path are only 3 and 6.  Intersections on the path are 4, 2, 1 and 3. Passing fee of roads on the path are 32, 32 and 30 in order. So answer equals to 32 + 32 + 30 = 94.  Intersections on the path are 6, 3 and 1.  Intersections on the path are 3 and 7. Passing fee of the road between them is 0.  Intersections on the path are 2 and 4. Passing fee of the road between them is 32 (increased by 30 in the first event and by 2 in the second).

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 commonAncestor(a, b int64) int64 {
  ap := int64(1)
  for (ap << 1) <= a {
    ap <<= 1
  }
  bp := int64(1)
  for (bp << 1) <= b {
    bp <<= 1
  }
  x := int64(0)
  for ap != 0 && bp != 0 && ((a & ap == 0) == (b & bp == 0)) {
    x <<= 1
    if (a & ap != 0) {
      x |= 1
    }
    ap >>= 1
    bp >>= 1
  }
  return x
}

func intersectionSize(s, t *Segment) int64 {
  size := int64(0)
  y := commonAncestor(s.v, t.v)
  x := s.u
  if t.u > x {
    x = t.u
  }
  for y > x {
    size++
    y >>= 1
  }
  return size
}

type Segment struct {
  u, v int64
}

type Toll struct {
  segment *Segment
  cost int64
}

func makeSegments(a, b int64) []*Segment {
  x := commonAncestor(a, b)
  if x == a {
    return []*Segment{ &Segment{ a, b } }
  }
  if x == b {
    return []*Segment{ &Segment{ b, a } }
  }
  return []*Segment{ &Segment{ x, a }, &Segment{ x, b } }
}

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

  qNum := getI64()
  tolls := []*Toll{}
  for i := int64(0); i < qNum; i++ {
    q := getI64()
    segments := makeSegments(getI64(), getI64())
    if q == 1 {
      cost := getI64()
      for _, segment := range segments {
        tolls = append(tolls, &Toll{ segment, cost })
      }
    } else {
      cost := int64(0)
      for _, segment := range segments {
        for _, toll := range tolls {
          cost += intersectionSize(segment, toll.segment) * toll.cost
        }
      }
      writer.WriteString(fmt.Sprintf("%d\n", cost))
    }
  }
}

package main

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

func main() {
	q := getInt()
	m := map[int64]int64{}
	buf := &bytes.Buffer{}
	for i := 0; i < q; i++ {
		typ := getInt()
		v := getInt64()
		u := getInt64()
		switch typ {
		case 1:
			w := getInt64()
			for u != v {
				if u < v {
					u, v = v, u
				}
				m[u] += w
				u /= 2
			}
		case 2:
			var w int64
			for u != v {
				if u < v {
					u, v = v, u
				}
				w += m[u]
				u /= 2
			}
			fmt.Fprintf(buf, "%v\n", w)
		}
	}
	io.Copy(os.Stdout, buf)
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func getInt() int {
	globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x
}
func getInt64() int64 {
	globalInput.Scan()
	x, _ := strconv.ParseInt(globalInput.Text(), 10, 64)
	return x
}
func getIntOk() (int, bool) {
	ok := globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x, ok
}
func getNint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = getInt()
	}
	return v
}
func getVint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = getIntOk()
	}
	return ok
}
func getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
func getWordOk() (string, bool) {
	ok := globalInput.Scan()
	return globalInput.Text(), ok
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func minStr(a, b string) string {
	if a < b {
		return a
	}
	return b
}
func maxStr(a, b string) string {
	if a < b {
		return b
	}
	return a
}
func remin(a *int, b int) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax(a *int, b int) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func remin64(a *int64, b int64) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax64(a *int64, b int64) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func reminStr(a *string, b string) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remaxStr(a *string, b string) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}

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

type (
	FLess    func(i, j int) bool
	FSwap    func(i, j int)
	wrapSort struct {
		Length int
		FLess
		FSwap
	}
)

func (w *wrapSort) Len() int           { return w.Length }
func (w *wrapSort) Less(i, j int) bool { return w.FLess(i, j) }
func (w *wrapSort) Swap(i, j int)      { w.FSwap(i, j) }
func wsort(length int, fless func(i, j int) bool, fswap func(i, j int)) {
	sort.Sort(&wrapSort{length, fless, fswap})
}

package main

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

var fee map[int64]int64

func height(v int64) int {
	h := 0
	for x := int64(1); x <= v; x <<= 1 {
		h++
	}
	return h
}

func add(u int64, w int64) {
	_, found := fee[u]
	if found {
		fee[u] += w
	} else {
		fee[u] = w
	}
}

func get(u int64) int64 {
	f, found := fee[u]
	if found {
		return f
	}
	return 0
}

func update(u int64, v int64, w int64) {
	hu := height(u)
	hv := height(v)
	if hu < hv {
		u, v = v, u
		hu, hv = hv, hu
	}
	pu := u >> 1
	for hu > hv {
		add(u, w)
		u = pu
		pu = u >> 1
		hu--
	}
	pv := v >> 1
	for u != v {
		add(u, w)
		add(v, w)
		u = pu
		pu = u >> 1
		hu--
		v = pv
		pv = v >> 1
		hv--
	}
}

func query(u int64, v int64) int64 {
	sum := int64(0)
	hu := height(u)
	hv := height(v)
	if hu < hv {
		u, v = v, u
		hu, hv = hv, hu
	}
	pu := u >> 1
	for hu > hv {
		sum += get(u)
		u = pu
		pu = u >> 1
		hu--
	}
	pv := v >> 1
	for u != v {
		sum += get(u)
		sum += get(v)
		u = pu
		pu = u >> 1
		hu--
		v = pv
		pv = v >> 1
		hv--
	}
	return sum
}

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

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

	fee = make(map[int64]int64)

	q := readInt()
	for i := 0; i < q; i++ {
		cat := readInt()
		u := readInt64()
		v := readInt64()
		if cat == 1 {
			w := readInt64()
			update(u, v, w)
		} else {
			write(query(u, v))
		}
	}
}

// Input and Output
var in *bufio.Scanner
var out *bufio.Writer

func readString() string {
	in.Scan()
	return in.Text()
}

func readInt() int {
	in.Scan()
	val, _ := strconv.Atoi(in.Text())
	return val
}

func readInt64() int64 {
	in.Scan()
	val, _ := strconv.ParseInt(in.Text(), 10, 64)
	return val
}

func readFloat64() float64 {
	in.Scan()
	val, _ := strconv.ParseFloat(in.Text(), 64)
	return val
}

func write(args ...interface{}) {
	for i, e := range args {
		switch e.(type) {
		case string:
			out.WriteString(e.(string))
		case int:
			out.WriteString(strconv.Itoa(e.(int)))
		case int64:
			out.WriteString(strconv.FormatInt(e.(int64), 10))
		case float64:
			out.WriteString(strconv.FormatFloat(e.(float64), 'f', -1, 64))
		case []string:
			a := e.([]string)
			for j, x := range a {
				out.WriteString(x)
				if j+1 < len(a) {
					out.WriteByte(' ')
				}
			}
		case []int:
			a := e.([]int)
			for j, x := range a {
				out.WriteString(strconv.Itoa(x))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		case []int64:
			a := e.([]int64)
			for j, x := range a {
				out.WriteString(strconv.FormatInt(x, 10))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		case []float64:
			a := e.([]float64)
			for j, x := range a {
				out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		default:
			out.WriteString("###")
		}
		if i+1 < len(args) {
			out.WriteByte(' ')
		}
	}
	out.WriteByte('\n')
}

package main

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

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

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

	fee := make(map[int64]int64)

	q := readInt()
	for i := 0; i < q; i++ {
		cat := readInt()
		u := readInt64()
		v := readInt64()
		if cat == 1 {
			w := readInt64()
			for u != v {
				if u < v {
					u, v = v, u
				}
				fee[u] += w
				u >>= 1
			}
		} else {
			sum := int64(0)
			for u != v {
				if u < v {
					u, v = v, u
				}
				sum += fee[u]
				u >>= 1
			}
			write(sum)
		}
	}
}

// Input and Output
var in *bufio.Scanner
var out *bufio.Writer

func readString() string {
	in.Scan()
	return in.Text()
}

func readInt() int {
	in.Scan()
	val, _ := strconv.Atoi(in.Text())
	return val
}

func readInt64() int64 {
	in.Scan()
	val, _ := strconv.ParseInt(in.Text(), 10, 64)
	return val
}

func readFloat64() float64 {
	in.Scan()
	val, _ := strconv.ParseFloat(in.Text(), 64)
	return val
}

func write(args ...interface{}) {
	for i, e := range args {
		switch e.(type) {
		case string:
			out.WriteString(e.(string))
		case int:
			out.WriteString(strconv.Itoa(e.(int)))
		case int64:
			out.WriteString(strconv.FormatInt(e.(int64), 10))
		case float64:
			out.WriteString(strconv.FormatFloat(e.(float64), 'f', -1, 64))
		case []string:
			a := e.([]string)
			for j, x := range a {
				out.WriteString(x)
				if j+1 < len(a) {
					out.WriteByte(' ')
				}
			}
		case []int:
			a := e.([]int)
			for j, x := range a {
				out.WriteString(strconv.Itoa(x))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		case []int64:
			a := e.([]int64)
			for j, x := range a {
				out.WriteString(strconv.FormatInt(x, 10))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		case []float64:
			a := e.([]float64)
			for j, x := range a {
				out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		default:
			out.WriteString("###")
		}
		if i+1 < len(args) {
			out.WriteByte(' ')
		}
	}
	out.WriteByte('\n')
}


This is the easy version of the problem. In this version, $$$n \le 3000$$$, $$$x \ge y$$$ holds. You can make hacks only if both versions of the problem are solved.You are given two binary strings $$$a$$$ and $$$b$$$, both of length $$$n$$$. You can do the following operation any number of times (possibly zero).   Select two indices $$$l$$$ and $$$r$$$ ($$$l < r$$$).  Change $$$a_l$$$ to $$$(1 - a_l)$$$, and $$$a_r$$$ to $$$(1 - a_r)$$$.  If $$$l + 1 = r$$$, the cost of the operation is $$$x$$$. Otherwise, the cost is $$$y$$$. You have to find the minimum cost needed to make $$$a$$$ equal to $$$b$$$ or say there is no way to do so.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 600$$$) — the number of test cases. Each test case consists of three lines. The first line of each test case contains three integers $$$n$$$, $$$x$$$, and $$$y$$$ ($$$5 \le n \le 3000$$$, $$$1 \le y \le x \le 10^9$$$) — the length of the strings, and the costs per operation. The second line of each test case contains the string $$$a$$$ of length $$$n$$$. The string only consists of digits $$$0$$$ and $$$1$$$. The third line of each test case contains the string $$$b$$$ of length $$$n$$$. The string only consists of digits $$$0$$$ and $$$1$$$. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3000$$$.

For each test case, if there is no way to make $$$a$$$ equal to $$$b$$$, print $$$-1$$$. Otherwise, print the minimum cost needed to make $$$a$$$ equal to $$$b$$$.

NoteIn the first test case, selecting indices $$$2$$$ and $$$3$$$ costs $$$8$$$, which is the minimum possible cost.In the second test case, we cannot make $$$a$$$ equal to $$$b$$$ using any number of operations.In the third test case, we can perform the following operations:  Select indices $$$3$$$ and $$$6$$$. It costs $$$3$$$, and $$$a$$$ is 0101011 now.  Select indices $$$4$$$ and $$$6$$$. It costs $$$3$$$, and $$$a$$$ is 0100001 now. The total cost is $$$6$$$.In the fourth test case, we don't have to perform any operations.

package main

import (
	"fmt"
)

// https://codeforces.com/problemset/problem/1733/D1

func main() {
	var num int
	fmt.Scanf("%d\n", &num)
	for ; num > 0; num-- {
		var n int
		var x uint64
		var y uint64
		fmt.Scanf("%d %d %d\n", &n, &x, &y)
		var a string
		var b string
		fmt.Scanf("%s\n", &a)
		fmt.Scanf("%s\n", &b)

		var differ_count uint64
		differ_count = 0
		r := -1
		l := -1
		for i := 0; i < n; i++ {
			if a[i] != b[i] {
				differ_count++
				if l == -1 {
					l = i
				}
				r = i
			}
		}

		if differ_count%2 == 1 {
			fmt.Println(-1)
			continue
		}

		if differ_count == 2 {
			if l+1 == r {
				if (y * 2) < x {
					fmt.Println(y * 2)
				} else {
					fmt.Println(x)
				}
			} else {
				fmt.Println(y)
			}
			continue
		}

		fmt.Println(differ_count / 2 * y)
	}
}

package main

import (
	"fmt"
)

// https://codeforces.com/problemset/problem/1733/D1

func main() {
	var num int
	fmt.Scanf("%d\n", &num)
	for ; num > 0; num-- {
		var n int
		var x uint64
		var y uint64
		fmt.Scanf("%d %d %d\n", &n, &x, &y)
		var a string
		var b string
		fmt.Scanf("%s\n", &a)
		fmt.Scanf("%s\n", &b)

		var differ_count uint64
		differ_count = 0
		r := -1
		l := -1
		for i := 0; i < n; i++ {
			if a[i] != b[i] {
				differ_count++
				if l == -1 {
					l = i
				}
				r = i
			}
		}

		if differ_count%2 == 1 {
			fmt.Println(-1)
			continue
		}

		if differ_count == 2 {
			if l+1 == r {
				if (y * 2) < x {
					fmt.Println(y * 2)
				} else {
					fmt.Println(x)
				}
			} else {
				if (x * uint64(r-l)) < y {
					fmt.Println(x * uint64(r-l))
				} else {
					fmt.Println(y)
				}
			}
			continue
		}

		fmt.Println(differ_count / 2 * y)
	}
}

package main

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

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

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

		var n, x, y, flips, res int
		fmt.Fscan(r, &n, &x, &y)

		var a, b []byte
		fmt.Fscan(r, &a, &b)

		var adj bool
		for i := range a {
			if a[i] != b[i] {
				flips++

				if i < n-1 && a[i+1] != b[i+1] {
					adj = true
				}
			}
		}

		if flips % 2 == 1 {
			res = -1
		} else if n < 4 && adj {
			res = x
		} else if flips == 2 && adj {
			res = min(x, 2*y)
		} else {
			res = y * flips / 2
		}

		fmt.Fprintln(w, res)

	}

}

package main

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

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

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

		var n, x, y, flips, dis, res int
		fmt.Fscan(r, &n, &x, &y)

		var a, b []byte
		fmt.Fscan(r, &a, &b)

		var adj bool
		dis = n
		for i := range a {
			if a[i] != b[i] {
				flips++

				if i < n-1 && a[i+1] != b[i+1] {
					adj = true
					dis = min(dis, max(i, n-2-i))
				}
			}
		}

		if flips % 2 == 1 {
			res = -1
		} else if flips == 2 && adj {
			if n < 4 {
				res = x
			} else if dis < 2 {
				res = min(x, 3*y)
			} else {
				res = min(x, 2*y)
			}
		} else {
			res = y * flips / 2
		}

		fmt.Fprintln(w, res)

	}

}

package main

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

var a, b string

var diff [100005]bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)
	for cs := 0; cs < T; cs++ {
		var n int
		var x, y int
		fmt.Fscan(in, &n, &x, &y)
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		sum := 0
		flag := false
		for i := 0; i < n; i++ {
			diff[i] = (a[i] != b[i])
			if diff[i] {
				sum++
				if i > 0 && diff[i-1] {
					flag = true
				}
			}
		}
		if sum%2 == 1 {
			fmt.Fprintln(out, -1)
			continue
		}
		if sum == 2 && flag {
			if x > y*2 {
				fmt.Fprintln(out, y*2)
			} else {
				fmt.Fprintln(out, x)
			}
		} else {
			fmt.Fprintln(out, sum/2*y)
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	txt, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(strings.TrimSpace(txt))
	for ; t > 0; t-- {
		txt, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(txt), " ")
		n, _ := strconv.Atoi(arr[0])
		x, _ := strconv.Atoi(arr[1])
		y, _ := strconv.Atoi(arr[2])
		txt, _ = reader.ReadString('\n')
		a := strings.TrimSpace(txt)
		txt, _ = reader.ReadString('\n')
		b := strings.TrimSpace(txt)
		indexes := make([]int, 0)
		for i := 0; i < n; i++ {
			if a[i] != b[i] {
				indexes = append(indexes, i)
			}
		}
		ln := len(indexes)
		if ln%2 > 0 {
			fmt.Println(-1)
		} else if ln == 2 {
			if indexes[1]-indexes[0] == 1 {
				min := x
				if 2*y < min {
					min = 2 * y
				}
				fmt.Println(min)
			} else {
				fmt.Println(y)
			}
		} else {
			fmt.Println(ln / 2 * y)
		}
	}
}

package main

import (
	"fmt"
)

// https://codeforces.com/problemset/problem/1733/D1

func main() {
	var num int
	fmt.Scanf("%d\n", &num)
	for ; num > 0; num-- {
		var n int
		var x uint64
		var y uint64
		fmt.Scanf("%d %d %d\n", &n, &x, &y)
		var a string
		var b string
		fmt.Scanf("%s\n", &a)
		fmt.Scanf("%s\n", &b)

		var differ_count uint64
		differ_count = 0
		for r := 0; r < n; r++ {
			if a[r] != b[r] {
				differ_count++
			}
		}
		if differ_count%2 == 1 {
			fmt.Println(-1)
			continue
		}
		if differ_count == 2 {
			if (y * 2) < x {
				fmt.Println(y * 2)
			} else {
				fmt.Println(x)
			}
			continue
		}
		fmt.Println(differ_count / 2 * y)
	}
}

package main

import (
	"fmt"
)

// https://codeforces.com/problemset/problem/1733/D1

func main() {
	var num int
	fmt.Scanf("%d\n", &num)
	for ; num > 0; num-- {
		var n int
		var x int
		var y int
		fmt.Scanf("%d %d %d\n", &n, &x, &y)
		var a string
		var b string
		fmt.Scanf("%s\n", &a)
		fmt.Scanf("%s\n", &b)

		differ_count := 0
		for r := 0; r < n; r++ {
			if a[r] != b[r] {
				differ_count++
			}
		}
		if differ_count%2 == 1 {
			fmt.Println(-1)
			continue
		}
		if differ_count == 2 {
			if (y * 2) < x {
				fmt.Println(y * 2)
			} else {
				fmt.Println(x)
			}
			continue
		}
		fmt.Println(differ_count / 2 * y)
	}
}

package main

import (
	"fmt"
	"strings"
)

// https://codeforces.com/problemset/problem/1733/D1

func Run(length int, a []rune, b []rune, currentcost int, costx int, costy int, smallestcost int) int {
	if currentcost >= smallestcost {
		return smallestcost
	}
	for r := 0; r < length; r++ {
		for l := 0; l < r; l++ {
			tmpa := a
			if tmpa[r] == '0' {
				tmpa[r] = '1'
			} else {
				tmpa[r] = '0'
			}
			if tmpa[l] == '0' {
				tmpa[l] = '1'
			} else {
				tmpa[l] = '0'
			}
			newcost := currentcost
			if l == r-1 {
				newcost = currentcost + costx
			} else {
				newcost = currentcost + costy
			}
			if newcost >= smallestcost {
				continue
			}

			if strings.Compare(string(tmpa), string(b)) == 0 && newcost < smallestcost {
				smallestcost = newcost
				continue
			}
			smallestcost = Run(length, tmpa, b, newcost, costx, costy, smallestcost)
		}
	}
	return smallestcost
}

func main() {
	var num int
	fmt.Scanf("%d\n", &num)
	for ; num > 0; num-- {
		var n int
		var x int
		var y int
		fmt.Scanf("%d %d %d\n", &n, &x, &y)
		var a string
		var b string
		fmt.Scanf("%s\n", &a)
		fmt.Scanf("%s\n", &b)

		runea := []rune(a)
		runeb := []rune(b)
		differ_count := 0
		for r := 0; r < n; r++ {
			if runea[r] != runeb[r] {
				differ_count++
			}
		}
		if differ_count%2 == 1 {
			fmt.Println(-1)
			continue
		}

		smallest_change_count := differ_count / 2
		tmpa := runea
		tmpb := runeb
		smallest_cost := 0
		for ; smallest_change_count > 0; smallest_change_count-- {
			for r := 0; r < n; r++ {
				if tmpa[r] == tmpb[r] {
					continue
				}
				for l := 0; l < r; l++ {
					if tmpa[l] == tmpb[l] {
						continue
					}
					tmpa[r] = tmpb[r]
					tmpa[l] = tmpb[l]
					if l == r-1 {
						smallest_cost += x
					} else {
						smallest_cost += y
					}
				}
			}

		}
		smallest_cost = Run(n, runea, runeb, 0, x, y, smallest_cost)
		fmt.Println(smallest_cost)
	}
}

package main

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

var a, b string

var diff [100005]bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)
	for cs := 0; cs < T; cs++ {
		var n int
		var x, y int
		fmt.Fscan(in, &n, &x, &y)
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		sum := 0
		for i := 0; i < n; i++ {
			diff[i] = (a[i] != b[i])
			if diff[i] {
				sum++
			}
		}
		if sum%2 == 1 {
			fmt.Fprintln(out, -1)
			continue
		}
		if sum == 2 {
			if x > y*2 {
				fmt.Fprintln(out, y*2)
			} else {
				fmt.Fprintln(out, x)
			}
		} else {
			fmt.Fprintln(out, sum/2*y)
		}
	}
}


This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).In this problem you should guess an array a which is unknown for you. The only information you have initially is the length n of the array a.The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices i and j (the indices should be distinct). Then your program should read the response: the single integer equals to ai + aj.It is easy to prove that it is always possible to guess the array using at most n requests.Write a program that will guess the array a by making at most n requests.

NoteThe format of a test to make a hack is:  The first line contains an integer number n (3 ≤ n ≤ 5000) — the length of the array. The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — the elements of the array to guess.

package main

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

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

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

	var n, a, b, c, d int
	fmt.Fscanf(bufin, "%d\n", &n)
	x := make([]int, n+1)

	fmt.Fprintf(bufout, "? 1 2\n")
	bufout.Flush()
	fmt.Fscanf(bufin, "%d\n", &a)

	fmt.Fprintf(bufout, "? 2 3\n")
	bufout.Flush()
	fmt.Fscanf(bufin, "%d\n", &b)

	fmt.Fprintf(bufout, "? 3 1\n")
	bufout.Flush()
	fmt.Fscanf(bufin, "%d\n", &c)

	x[1] = (c - b + a) / 2
	x[2] = a - x[1]
	x[3] = b - x[2]
	for i := 4; i <= n; i++ {
		fmt.Fprintf(bufout, "? %d %d\n", i-1, i)
		bufout.Flush()
		fmt.Fscanf(bufin, "%d\n", &d)
		x[i] = d - x[i-1]
	}

	fmt.Fprintf(bufout, "!")
	for i := 1; i <= n; i++ {
		fmt.Fprintf(bufout, " %d", x[i])
	}
}

package main

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

var scanner *bufio.Scanner

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

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  n := getI()
  values := make([]int, n)
  fmt.Printf("? 1 2\n")
  fmt.Printf("? 2 3\n")
  fmt.Printf("? 1 3\n")
  x, y, z := getI(), getI(), getI()
  a := (x + z - y) / 2
  values[0] = a
  values[2] = z - a
  values[1] = y - values[2]
  for i := 3; i < n; i++ {
    fmt.Printf("? 1 %d\n", i + 1)
    values[i] = getI() - a
  }
  fmt.Printf("!")
  for _, x = range values {
    fmt.Printf(" %d", x)
  }
  fmt.Printf("\n")
}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, s12, s13, s23, s int
	Scan(&n)
	Println("? 1 2")
	Scan(&s12)
	Println("? 1 3")
	Scan(&s13)
	Println("? 2 3")
	Scan(&s23)

	a := make([]int, n)
	a[0] = (s12 + s13 - s23) / 2
	a[1] = s12 - a[0]
	a[2] = s13 - a[0]
	for i := 3; i < n; i++ {
		Println(Sprintf("? 1 %d", i+1))
		Scan(&s)
		a[i] = s - a[0]
	}
	Print("!")
	for _, v := range a {
		Print(" ", v)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol727C(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)

	var n, s12, s13, s23 int
	Fscan(in, &n)
	Fprintln(out, "? 1 2")
	out.Flush()
	Fscan(in, &s12)
	Fprintln(out, "? 1 3")
	out.Flush()
	Fscan(in, &s13)
	Fprintln(out, "? 2 3")
	out.Flush()
	Fscan(in, &s23)

	ans := make([]int, n)
	ans[0] = (s12 + s13 - s23) / 2
	ans[1] = s12 - ans[0]
	ans[2] = s13 - ans[0]
	for i := 3; i < n; i++ {
		Fprintln(out, Sprintf("? 1 %d", i+1))
		out.Flush()
		var sum int
		Fscan(in, &sum)
		ans[i] = sum - ans[0]
	}
	Fprint(out, "!")
	for _, v := range ans {
		Fprint(out, " ", v)
	}
	out.Flush()
}

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

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n int
	Scan(&n)
	a := make([]int, n)
	Println("? 2 3")
	Scan(&a[0])
	for i := 1; i < n; i++ {
		Println(Sprintf("? 1 %d", i+1))
		Scan(&a[i])
	}
	a[0] = (a[1] + a[2] - a[0]) / 2
	Print("! ", a[0])
	for _, v := range a[1:] {
		Print(" ", v-a[0])
	}
}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n int
	Scan(&n)
	a := make([]int, n)
	Println("? 1 2")
	Scan(&a[0])
	Println("? 1 3")
	Scan(&a[1])
	Println("? 2 3")
	Scan(&a[2])

	a[0] = (a[1] + a[2] - a[0]) / 2
	for i := 3; i < n; i++ {
		Println(Sprintf("? 1 %d", i+1))
		Scan(&a[i])
	}
	Print("! ", a[0])
	for _, v := range a[1:] {
		Print(" ", v-a[0])
	}
}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n int
	Scan(&n)
	a := make([]int, n)
	Println("? 1 2")
	Scan(&a[0])
	Println("? 1 3")
	Scan(&a[1])
	Println("? 2 3")
	Scan(&a[2])

	a[0] = (a[1] + a[2] - a[0]) / 2
	for i := 3; i < n; i++ {
		Println(Sprintf("? 1 %d", i+1))
		Scan(&a[i])
	}
	Print("!", a[0])
	for _, v := range a[1:] {
		Print(" ", v-a[0])
	}
}


Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1 / x seconds for the first character and 1 / y seconds for the second one). The i-th monster dies after he receives ai hits. Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit.

The first line contains three integers n,x,y (1 ≤ n ≤ 105, 1 ≤ x, y ≤ 106) — the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly. Next n lines contain integers ai (1 ≤ ai ≤ 109) — the number of hits needed do destroy the i-th monster.

Print n lines. In the i-th line print word "Vanya", if the last hit on the i-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time.

NoteIn the first sample Vanya makes the first hit at time 1 / 3, Vova makes the second hit at time 1 / 2, Vanya makes the third hit at time 2 / 3, and both boys make the fourth and fifth hit simultaneously at the time 1.In the second sample Vanya and Vova make the first and second hit simultaneously at time 1.

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func next() string {
	scanOne()
	return sc.Text()
}

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000) * int64(1000000000)
		for {
			d := c / 2
			h := hits(l + d)
			if h == a || d == 0 || h == a+1 && (l+d)%x == 0 && (l+d)%y == 0 {
				break
			}
			if h < a {
				l = l + d + 1
				c = c - d - 1
			} else {
				c = c - d
			}
		}
		return l + c/2
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		von := t / x * x
		van := t / y * y
		switch {
		case van > von:
			z = "Vanya"
		case von > van:
			z = "Vova"
		}
		fmt.Println(z)
	}
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// 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 nextInt64() int64 {
    ret, _ := strconv.ParseInt(next(), 10, 64)
    return ret
}

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

func gcd(a, b int64) int64 {
    for a > 0 && b > 0 {
        if a > b {
            a = a % b
        } else {
            b = b % a
        }
    }
    return a + b
}
func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    x := nextInt64()
    y := nextInt64()
    g := gcd(x, y)
    x /= g
    y /= g
    for i := 0; i < n; i++ {
        a := nextInt64() % (x + y)
        if x == y || a == 0 || a == x + y - 1 {
            fmt.Fprintln(out, "Both")
        } else {
            l := int64(1)
            r := x * y
            for l < r {
                m := l + (r - l) / 2
                va := m / y
                vo := m / x
                if va + vo < a {
                    l = m + 1
                } else {
                    r = m
                }
            }

            if r % y == 0 {
                fmt.Fprintln(out, "Vanya")
            } else {
                fmt.Fprintln(out, "Vova")
            }

        }
    }
}

package main

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

func scanInt(scanner *bufio.Scanner) int64 {
	scanner.Scan()
	x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, x, y := scanInt(scanner), scanInt(scanner), scanInt(scanner)
	for i := int64(0); i < n; i++ {
    points := scanInt(scanner)
    low, high := int64(0), int64(1) << 60
    for low != high {
      mid := (low+high)/2
      hits := mid / x + mid / y
      if hits < points {
        low = mid+1
      } else {
        high = mid
      }
      //writer.WriteString(fmt.Sprintf("low = %d, high = %d\n", low, high));
    }
    //writer.WriteString(fmt.Sprintf("low = %d\n", low))
    if (low % y == 0) {
      if (low % x == 0) {
        writer.WriteString("Both\n");
      } else {
        writer.WriteString("Vanya\n");
      }
    } else {
        writer.WriteString("Vova\n");
    }
	}
}

package main

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

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

var (
	n    int
	x, y int64
	a    []int64
)

func in() {
	read(&n, &x, &y)
	a = make([]int64, n)
	for i := 0; i < n; i++ {
		read(&a[i])
	}
}

func out() {
	defer output.Flush()
}

func run() {
	cd := gcd(x, y)
	x = x / cd
	y = y / cd
	for i := 0; i < n; i++ {
		hits := a[i] % (x + y)
		var winner rune
		if hits == 0 || hits == (x+y-1) {
			println("Both")
			continue
		} else {
			var p, q int64
			if x < y {
				p, q = x, y
			} else {
				p, q = y, x
			}
			for h := (hits*p)/(p+q) - 1; h <= (hits*p)/(p+q)+1; h++ {
				if h <= 0 {
					continue
				}
				if h*(p+q)/p == hits {
					if x < y {
						winner = 'x'
					} else {
						winner = 'y'
					}
					break
				}
			}
			if winner == 0 {
				if x < y {
					winner = 'y'
				} else {
					winner = 'x'
				}
			}
		}
		if winner == 'x' {
			println("Vanya")
		} else {
			println("Vova")
		}
	}
}

func gcd(a, b int64) int64 {
	if a < b {
		a, b = b, a
	}

	for b != 0 {
		a, b = b, a%b
	}
	return a
}

/** main **/
func main() {
	in()
	run()
	out()
}

func read(a ...interface{}) {
	_, err := fmt.Fscan(input, a...)
	if err != nil {
		println(err)
	}
}

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

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

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func next() string {
	scanOne()
	return sc.Text()
}

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000)
		for {
			m := l + c/2
			h := hits(m)
			if h == a || c == 0 {
				break
			}
			if h < a {
				l = m + 1
				c /= 2
			} else {
				c = c/2 + c%1
			}
		}
		return l + c/2
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		van := t / x * x
		von := t / y * y
		switch {
		case van > von:
			z = "Vova"
		case von > van:
			z = "Vanya"
		}
		fmt.Println(z)
	}
}

package main

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

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

var (
	n    int
	x, y int64
	a    []int64
)

func in() {
	read(&n, &x, &y)
	a = make([]int64, n)
	for i := 0; i < n; i++ {
		read(&a[i])
	}
}

func out() {
	defer output.Flush()
}

func run() {
	cd := gcd(x, y)
	x = x / cd
	y = y / cd
	for i := 0; i < n; i++ {
		hits := a[i] % (x + y)
		var winner rune
		if hits == 0 || hits == (x+y-1) {
			println("Both")
			continue
		} else {
			if x < y {
				if hits*x%(y+1) == 0 {
					winner = 'x'
				} else {
					winner = 'y'
				}
			} else {
				if hits*y%(x+1) == 0 {
					winner = 'y'
				} else {
					winner = 'x'
				}
			}
		}
		if winner == 'x' {
			println("Vanya")
		} else {
			println("Vova")
		}
	}
}

func gcd(a, b int64) int64 {
	if a < b {
		a, b = b, a
	}

	for b != 0 {
		a, b = b, a%b
	}
	return a
}

/** main **/
func main() {
	in()
	run()
	out()
}

func read(a ...interface{}) {
	_, err := fmt.Fscan(input, a...)
	if err != nil {
		println(err)
	}
}

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

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

package main

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

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

var (
	n    int
	x, y int64
	a    []int64
)

func in() {
	read(&n, &x, &y)
	a = make([]int64, n)
	for i := 0; i < n; i++ {
		read(&a[i])
	}
}

func out() {
	defer output.Flush()
}

func run() {
	cd := gcd(x, y)
	x = x / cd
	y = y / cd
	for i := 0; i < n; i++ {
		hits := a[i] % (x + y)
		var winner rune
		if hits == 0 || hits == (x+y-1) {
			println("Both")
			continue
		} else {
			if x < y {
				if hits%(y/x+1) == 0 {
					winner = 'x'
				} else {
					winner = 'y'
				}
			} else {
				if hits%(x/y+1) == 0 {
					winner = 'y'
				} else {
					winner = 'x'
				}
			}
		}
		if winner == 'x' {
			println("Vanya")
		} else {
			println("Vova")
		}
	}
}

func gcd(a, b int64) int64 {
	if a < b {
		a, b = b, a
	}

	for b != 0 {
		a, b = b, a%b
	}
	return a
}

/** main **/
func main() {
	in()
	run()
	out()
}

func read(a ...interface{}) {
	_, err := fmt.Fscan(input, a...)
	if err != nil {
		println(err)
	}
}

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

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

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func next() string {
	scanOne()
	return sc.Text()
}

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000) * int64(1000000000)
		for {
			d := c / 2
			h := hits(l + d)
			if h == a || d == 0 {
				break
			}
			if h < a {
				l = l + d + 1
				c = c - d - 1
			} else {
				c = c - d
			}
		}
		return l + c/2
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		von := t / x * x
		van := t / y * y
		switch {
		case van > von:
			z = "Vanya"
		case von > van:
			z = "Vova"
		}
		fmt.Println(z)
	}
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func next() string {
	scanOne()
	return sc.Text()
}

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()
	fmt.Println(x, y)

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000)
		for {
			m := l + c/2
			h := hits(m)
			if h == a || c == 0 {
				break
			}
			if h < a {
				l = m + 1
				c /= 2
			} else {
				c = c/2 + c%1
			}
		}
		return l + c/2
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		van := t / x * x
		von := t / y * y
		switch {
		case van > von:
			z = "Vanya"
		case von > van:
			z = "Vova"
		}
		fmt.Println(t, z)
	}
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func next() string {
	scanOne()
	return sc.Text()
}

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000) * int64(1000000000)
		for {
			c /= 2
			h := hits(l + c)
			if h == a || c == 0 {
				break
			}
			if h < a {
				l = l + c + 1
				c--
			}
		}
		return l + c
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		von := t / x * x
		van := t / y * y
		switch {
		case van > von:
			z = "Vanya"
		case von > van:
			z = "Vova"
		}
		fmt.Println(z)
	}
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

func nextInt() int {
	scanOne()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func next() string {
	scanOne()
	return sc.Text()
}

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000000000000)
		for {
			c /= 2
			h := hits(l + c)
			if h == a || c == 0 {
				break
			}
			if h < a {
				l = l + c + 1
				c--
			}
		}
		return l + c
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		von := t / x * x
		van := t / y * y
		switch {
		case van > von:
			z = "Vanya"
		case von > van:
			z = "Vona"
		}
		fmt.Println(z)
	}
}


This is an interactive problem.There are $$$n$$$ words in a text editor. The $$$i$$$-th word has length $$$l_i$$$ ($$$1 \leq l_i \leq 2000$$$). The array $$$l$$$ is hidden and only known by the grader. The text editor displays words in lines, splitting each two words in a line with at least one space. Note that a line does not have to end with a space. Let the height of the text editor refer to the number of lines used. For the given width, the text editor will display words in such a way that the height is minimized.More formally, suppose that the text editor has width $$$w$$$. Let $$$a$$$ be an array of length $$$k+1$$$ where $$$1=a_1 < a_2 < \ldots < a_{k+1}=n+1$$$. $$$a$$$ is a valid array if for all $$$1 \leq i \leq k$$$, $$$l_{a_i}+1+l_{a_i+1}+1+\ldots+1+l_{a_{i+1}-1} \leq w$$$. Then the height of the text editor is the minimum $$$k$$$ over all valid arrays.Note that if $$$w < \max(l_i)$$$, the text editor cannot display all the words properly and will crash, and the height of the text editor will be $$$0$$$ instead.You can ask $$$n+30$$$ queries. In one query, you provide a width $$$w$$$. Then, the grader will return the height $$$h_w$$$ of the text editor when its width is $$$w$$$.Find the minimum area of the text editor, which is the minimum value of $$$w \cdot h_w$$$ over all $$$w$$$ for which $$$h_w \neq 0$$$.The lengths are fixed in advance. In other words, the interactor is not adaptive.

The first and only line of input contains a single integer $$$n$$$ ($$$1 \leq n \leq 2000$$$)  — the number of words on the text editor. It is guaranteed that the hidden lengths $$$l_i$$$ satisfy $$$1 \leq l_i \leq 2000$$$.

NoteIn the first test case, the words are $$$\{\texttt{glory},\texttt{to},\texttt{ukraine},\texttt{and},\texttt{anton},\texttt{trygub}\}$$$, so $$$l=\{5,2,7,3,5,6\}$$$. If $$$w=1$$$, then the text editor is not able to display all words properly and will crash. The height of the text editor is $$$h_1=0$$$, so the grader will return $$$0$$$.If $$$w=9$$$, then a possible way that the words will be displayed on the text editor is:   $$$\texttt{glory__to}$$$  $$$\texttt{ukraine__}$$$  $$$\texttt{and_anton}$$$  $$$\texttt{__trygub_}$$$ The height of the text editor is $$$h_{9}=4$$$, so the grader will return $$$4$$$.If $$$w=16$$$, then a possible way that the words will be displayed on the text editor is:   $$$\texttt{glory_to_ukraine}$$$  $$$\texttt{and_anton_trygub}$$$ The height of the text editor is $$$h_{16}=2$$$, so the grader will return $$$2$$$.We have somehow figured out that the minimum area of the text editor is $$$32$$$, so we answer it.

package main

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

const MOD int64 = 1000000007

var n int

var a, b []int

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

	var h int

	lo := 1
	hi := int(1e9)

	var width int
	var area int

	for hi - lo > 1 {

		m := (lo + hi) >> 1

		fmt.Println("? ", m)
		fmt.Fscan(read, &h)

		if h == 0 {
			lo = m
		} else if h > 1 {
			lo = m
		} else {
			hi = m
		}
	}
	fmt.Println("? ", lo)
	fmt.Fscan(read, &h)

	if h == 1 {
		width = lo
	} else {
		width = hi
	}
	area = width

	for j := 2; j <= n; j++ {
		k := width / j

		fmt.Println("? ", k)
		fmt.Fscan(read, &h)

		if h == 0 {
			continue
		}

		if h*k < area {
			area = h * k
		}
	}

	fmt.Println("! ", area)

}

type pair struct {
	v int
	idx []int
}

//a b c d

//20 12 -- 4
//4  2  -- 4

func solve()  {

}

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

package main

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

const MOD int64 = 1000000007

var n int

var a, b []int

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

	var h int

	lo := 1
	hi := int(1e9)

	var width int
	var area int

	for hi - lo > 1 {

		m := (lo + hi) >> 1

		fmt.Println("? ", m)
		fmt.Fscan(read, &h)

		if h == 0 {
			lo = m
		} else if h > 1 {
			lo = m
		} else {
			hi = m
		}
	}
	fmt.Println("? ", lo)
	fmt.Fscan(read, &h)

	if h == 1 {
		width = lo
	} else {
		width = hi
	}
	area = width

	for j := 2; j <= n; j++ {
		k := width / j

		fmt.Println("? ", k)
		fmt.Fscan(read, &h)

		if h*k < area {
			area = h * k
		}
	}

	fmt.Println("! ", area)

}

type pair struct {
	v int
	idx []int
}

//a b c d

//20 12 -- 4
//4  2  -- 4

func solve()  {

}

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


T is a complete binary tree consisting of n vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two children). All leaves of a complete binary tree have the same depth (distance from the root). So n is a number such that n + 1 is a power of 2.In the picture you can see a complete binary tree with n = 15.  Vertices are numbered from 1 to n in a special recursive way: we recursively assign numbers to all vertices from the left subtree (if current vertex is not a leaf), then assign a number to the current vertex, and then recursively assign numbers to all vertices from the right subtree (if it exists). In the picture vertices are numbered exactly using this algorithm. It is clear that for each size of a complete binary tree exists exactly one way to give numbers to all vertices. This way of numbering is called symmetric.You have to write a program that for given n answers q queries to the tree.Each query consists of an integer number ui (1 ≤ ui ≤ n) and a string si, where ui is the number of vertex, and si represents the path starting from this vertex. String si doesn't contain any characters other than 'L', 'R' and 'U', which mean traverse to the left child, to the right child and to the parent, respectively. Characters from si have to be processed from left to right, considering that ui is the vertex where the path starts. If it's impossible to process a character (for example, to go to the left child of a leaf), then you have to skip it. The answer is the number of vertex where the path represented by si ends.For example, if ui = 4 and si = «UURL», then the answer is 10.

The first line contains two integer numbers n and q (1 ≤ n ≤ 1018, q ≥ 1). n is such that n + 1 is a power of 2. The next 2q lines represent queries; each query consists of two consecutive lines. The first of these two lines contains ui (1 ≤ ui ≤ n), the second contains non-empty string si. si doesn't contain any characters other than 'L', 'R' and 'U'. It is guaranteed that the sum of lengths of si (for each i such that 1 ≤ i ≤ q) doesn't exceed 105.

Print q numbers, i-th number must be the answer to the i-th query.

package main

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

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

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

type Query struct {
	startVertex int64
	path        string
}

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

	var n, q int64
	scanf("%d %d\n", &n, &q)
	var queries = make([]Query, q)
	for i := int64(0); i < q; i++ {
		var qi int64
		scanf("%d\n", &qi)
		var qPath string
		scanf("%s\n", &qPath)
		queries[i] = Query{qi, qPath}
	}

	answers := make([]int64, q)

	for i := int64(0); i < q; i++ {
		answers[i] = treeTraversal(n, queries[i])
	}

	for i := int64(0); i < q; i++ {
		printf("%v\n", answers[i])
	}
}

func treeTraversal(n int64, query Query) int64 {
	vertexNum := query.startVertex
	for _, direction :=range query.path{
		nextNum := int64(-1)
		switch direction {
		case 'U':
			nextNum = parent(vertexNum, n)
		case 'L':
			nextNum = left(vertexNum)
		case 'R':
			nextNum = right(vertexNum)
		}

		if nextNum != -1 {
			vertexNum = nextNum
		}
	}

	return vertexNum
}
//
//func qR(num int64, denum int64) (int64, int64){
//    return num/denum, num%denum
//}

func calcMax2PowK(x int64) int64{
	if x == 0 || x == 1{
		return 0
	}

	k := int64(1)
	num:=x
	denum := int64(2)
	remainder:= int64(0)

	for {
		remainder = num%denum
		num = num/denum
		if remainder != 0 || num == 0{
			break
		}
		k++
	}

	return k-1
}

func right(vertex int64) int64 {
	max2PowK := calcMax2PowK(vertex)
	if max2PowK == 0 {
		return vertex
	}
	return vertex + int64(math.Pow(2, float64(max2PowK-1)))
}

func left(vertex int64) int64 {
	max2PowK := calcMax2PowK(vertex)
	if max2PowK == 0 {
		return vertex
	}
	return vertex - int64(math.Pow(2, float64(max2PowK-1)))
}

func parent(vertex int64, vNum int64) int64 {
	max2PowK := calcMax2PowK(vertex)
	parentCandidate1 := vertex + int64(math.Pow(2, float64(max2PowK)))
	parentCandidate2 := vertex-int64(math.Pow(2, float64(max2PowK)))
	parent := parentCandidate2
	if parentCandidate1 % int64(math.Pow(2, float64(max2PowK)+1)) == 0 && parentCandidate1 % int64(math.Pow(2, float64(max2PowK+2))) != 0 {
		parent = parentCandidate1
	}

	if parent <= 0 || parent> vNum {
		parent=vertex
	}

	return parent
}


Permutation p is an ordered set of integers p1,  p2,  ...,  pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1,  p2,  ...,  pn.The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≤ i < n), that pi > pi + 1.You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k.

The single line contains two space-separated integers: n, k (1 ≤ n ≤ 105, 0 ≤ k < n) — the permutation length and the decreasing coefficient.

In a single line print n space-separated integers: p1, p2, ..., pn — the permutation of length n with decreasing coefficient k.  If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists.

package main
import (
	"fmt"
)
func main() {
	var n,k int
	fmt.Scan(&n,&k)
	for i:=n;i>n-k;i-- {
		fmt.Printf("%d ",i)
	}
	fmt.Print("1")
	for i:=2; i<=(n-k);i++ {
		fmt.Printf(" %d",i)
	}
	fmt.Println()
}

package main
import (
	"fmt"
)
func main() {
	var n,k int
	fmt.Scan(&n,&k)
	for i:=0;i<k;i++ {
		fmt.Printf("%d ",n-i)
	}
	fmt.Print("1")
	for i:=2; i<=(n-k);i++ {
		fmt.Printf(" %d",i)
	}
	fmt.Println()
}

package main

import (
	"fmt"
)

func main() {
	var n, k int
	if _, err := fmt.Scanf("%d %d\n", &n, &k); err != nil {
		return
	}

	p := make([]int, n*2)
	for i := 0; i < n; i++ {
		p[i] = i + 1
	}
	s1 := 0       // Inclusive
	s2 := 2*n - 1 // Exclusive

	for k > 0 {
		p[s2] = p[s1]
		s1++
		s2--
		k--
	}

	for i := s1; i < n; i++ {
		fmt.Printf("%d ", p[i])
	}
	for i := s2 + 1; i < 2*n; i++ {
		fmt.Printf("%d ", p[i])
	}
	fmt.Printf("\n")
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n,k int
    fmt.Scan(&n,&k)
    for ; k > 0; k-- {
        writer.WriteString(strconv.Itoa(n))
        n--
        if n != 0 { writer.WriteRune(' ') } else { writer.WriteRune('\n')}
    }
    for i := 1; i <= n; i++ {
        writer.WriteString(strconv.Itoa(i))
        if i != n { writer.WriteRune(' ') } else { writer.WriteRune('\n')}
    }
    writer.Flush()
}

package main

import (
	"bytes"
	"fmt"
	"strconv"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	var buffer bytes.Buffer
	for i := 0; i < k; i++ {
		buffer.WriteString(strconv.Itoa(n-i) + " ")
	}
	for i := 0; i < n-k; i++ {
		buffer.WriteString(strconv.Itoa(i+1) + " ")
	}

	fmt.Println(buffer.String())
}

package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = i + 1
	}

	for index, vl := range arr {
		if index < n-m-1 {
			fmt.Print(vl, " ")
		}
	}

	for i := n - 1; i >= n-m-1; i-- {
		fmt.Print(arr[i], " ")
	}
}

package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

	for i := 1; i < n-m; i++ {
		fmt.Printf("%d ", i)
	}

	for i := n; i >= n-m; i-- {
		fmt.Printf("%d ", i)
	}
}

package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = i + 1
	}

	for index, vl := range arr {
		if index < m {
			fmt.Print(vl, " ")
		}
	}

	for i := n - 1; i >= m; i-- {
		fmt.Print(arr[i], " ")
	}
}

package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

	for i := 1; i <= m; i++ {
		fmt.Printf("%d ", i)
	}

	for i := n; i >= m+1; i-- {
		fmt.Printf("%d ", i)
	}
}


This is an interactive problem.Homer likes arrays a lot and he wants to play a game with you. Homer has hidden from you a permutation $$$a_1, a_2, \dots, a_n$$$ of integers $$$1$$$ to $$$n$$$. You are asked to find any index $$$k$$$ ($$$1 \leq k \leq n$$$) which is a local minimum. For an array $$$a_1, a_2, \dots, a_n$$$, an index $$$i$$$ ($$$1 \leq i \leq n$$$) is said to be a local minimum if $$$a_i < \min\{a_{i-1},a_{i+1}\}$$$, where $$$a_0 = a_{n+1} = +\infty$$$. An array is said to be a permutation of integers $$$1$$$ to $$$n$$$, if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Initially, you are only given the value of $$$n$$$ without any other information about this permutation.At each interactive step, you are allowed to choose any $$$i$$$ ($$$1 \leq i \leq n$$$) and make a query with it. As a response, you will be given the value of $$$a_i$$$. You are asked to find any index $$$k$$$ which is a local minimum after at most $$$100$$$ queries.

NoteIn the example, the first line contains an integer $$$5$$$ indicating that the length of the array is $$$n = 5$$$.The example makes five "?" queries, after which we conclude that the array is $$$a = [3,2,1,4,5]$$$ and $$$k = 3$$$ is local minimum.

package main

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

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

	ask := func(i int) int {
		fmt.Printf("? %d\n", i)
		return readNum(reader)
	}

	n := readNum(reader)

	res := solve(n, ask)

	fmt.Printf("! %d\n", res)
}

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
}

// 不变性是在区间[l...r] 中间肯定存在局部最小值
func solve(n int, ask func(int) int) int {
	if n < 2 {
		return 1
	}
	// ask(i) = a[i]
	// ask(1) = a[1]
	// ask(n) = a[n]
	A := make([]int, n+1)

	cache := func(i int) int {
		if A[i] == 0 {
			A[i] = ask(i)
		}
		return A[i]
	}

	l, r := 1, n

	for l < r {
		mid := (l + r) / 2
		x := cache(mid)
		y := cache(mid + 1)
		if x > y {
			l = mid + 1
		} else {
			// x < y
			r = mid
		}
	}

	return r
}

package main
import ("fmt")
var n int

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

func query(a int) int{
  fmt.Println("? ", a)
  var x int
  fmt.Scan(&x)
  return x
}

func main(){
  fmt.Scan(&n)
  if n == 1 {
    fmt.Print("! ", 1)
    return
  }
  if n == 2 {
    var id int = 0; var mn int = 1e9
    var x int = query(1)
    if mn > x{
      mn = x
      id = 1
    }
    x = query(2)
    if mn > x{
      mn = x
      id = 2
    }
    fmt.Print("! ", id)
    return
  }
  var x1 int = query(1); var x2 int = query(2)
  var sl = x1 - x2
  if sl < 0 {
    fmt.Print("! ", 1)
    return
  }
  var l, r int
  l = 2; r = n
  for r - l > 0{
    var mid int = (l + r) / 2;
    var num = query(mid);
    if x1 > x2 && num > x2 {
      r = mid
      continue
    }
    var newsl = num - query(mid + 1)
    if newsl > 0 && sl > 0 {
      l = mid + 1
    } else {
      r = mid
    }
  }
  fmt.Print("! ", l)
}

package main

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

type (
	input struct{ n int }
	req   struct{ i int }
	resp  struct{ v int }
	guess struct{ ans int }
)

// github.com/EndlessCheng/codeforces-go
func CF1479A(in input, Q func(req) resp) (gs guess) {
	q := func(i int) int { return Q(req{i}).v }
	n := in.n
	if n == 1 || q(1) < q(2) {
		gs.ans = 1
		return
	}
	if q(n-1) > q(n) {
		gs.ans = n
		return
	}
	res := sort.Search(n, func(i int) bool {
		if i < 2 || gs.ans > 0 {
			return false
		}
		x, y, z := q(i-1), q(i), q(i+1)
		if x > y && y < z {
			gs.ans = i
			return false
		}
		return x < y && y < z
	})
	if gs.ans == 0 {
		gs.ans = res
	}
	return
}

func ioq79() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	Q := func(req req) (resp resp) {
		Fprintln(out, "?", req.i)
		out.Flush()
		Fscan(in, &resp.v)
		return
	}

	d := input{}
	Fscan(in, &d.n)
	gs := CF1479A(d, Q)
	Fprint(out, "! ", gs.ans)
	out.Flush()
}

func main() { ioq79() }

package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)

	left := 1
	right := n
	for left < right {
		mid := left + (right-left)/2
		var midLeft, midRight int
		fmt.Printf("? %d\n", mid)
		fmt.Scanln(&midLeft)
		fmt.Printf("? %d\n", mid+1)
		fmt.Scanln(&midRight)

		if midLeft < midRight {
			right = mid
		} else if midLeft > midRight {
			left = mid + 1
		} else {
			panic("impossible")
		}
	}
	fmt.Printf("! %d\n", left)
}

package main

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

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

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

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

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

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

func main() {
	l := 1
	r := sint()
	for l < r {
		m := (l + r) / 2
		resm := query(m)
		resmr := query(m + 1)
		if resm < resmr {
			r = m
			continue
		}
		l = m + 1
	}
	if l != r {
		panic("l != r")
	}
	printf("! %d\n", l)
	writer.Flush()
}

func query(i int) int {
	printf("? %d\n", i)
	writer.Flush()
	return sint()
}

package main

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

func main() {
	// defer writer.Flush()
	//RedirectInputToFile(reader, "input.txt")

	saved := make(map[int]int)
	var n, curr, next int
	scan(&n)

	l, r := 1, n
	for i := 0; i < 100; i++ {
		if l == r {
			fmt.Println("!", l)
			return
		}

		m := l + (r-l)/2

		if x, ok := saved[m]; ok {
			curr = x
		} else {
			fmt.Println("?", m)
			scan(&curr)
			saved[m] = curr
		}

		if x, ok := saved[m+1]; ok {
			next = x
		} else {
			fmt.Println("?", m+1)
			scan(&next)
			saved[m+1] = next
		}

		if curr < next {
			r = m
		} else {
			l = m + 1
		}
	}
}

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

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

func RedirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

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

	ask := func(i int) int {
		fmt.Printf("? %d\n", i)
		return readNum(reader)
	}

	n := readNum(reader)

	res := solve(n, ask)

	fmt.Printf("! %d\n", res)
}

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
}

// 不变性是在区间[l...r] 中间肯定存在局部最小值
func solve(n int, ask func(int) int) int {
	if n <= 2 {
		return 1
	}
	// ask(i) = a[i]
	// ask(1) = a[1]
	// ask(n) = a[n]
	A := make([]int, n+1)

	cache := func(i int) int {
		if A[i] > 0 {
			return A[i]
		}
		A[i] = ask(i)
		return A[i]
	}

	l, r := 1, n

	for l < r {
		mid := (l + r) / 2
		x := cache(mid)
		y := cache(mid + 1)
		if x > y {
			l = mid + 1
		} else {
			// x < y
			r = mid
		}
	}

	return r
}

package main

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

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

	ask := func(i int) int {
		fmt.Printf("? %d\n", i)
		return readNum(reader)
	}

	n := readNum(reader)

	res := solve(n, ask)

	fmt.Printf("! %d\n", res)
}

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
}

// 不变性是在区间[l...r] 中间肯定存在局部最小值
func solve(n int, ask func(int) int) int {
	if n <= 2 {
		return 1
	}
	// ask(i) = a[i]
	// ask(1) = a[1]
	// ask(n) = a[n]
	A := make([]int, n+1)

	cache := func(i int) int {
		if A[i] > 0 {
			return A[i]
		}
		A[i] = ask(i)
		return A[i]
	}

	l, r := 1, n

	for l+1 < r {
		mid := (l + r) / 2
		x := cache(mid)
		y := cache(mid + 1)
		if x > y {
			l = mid + 1
		} else {
			// x < y
			r = mid
		}
	}

	return r
}

package main
import ("fmt")
var n int

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

func query(a int) int{
  fmt.Println(a)
  var x int
  fmt.Scan(&x)
  return x
}

func main(){
  fmt.Scan(&n)
  if n == 1 {
    fmt.Print("! ", 1)
    return
  }
  if n == 2 {
    var id int = 0; var mn int = 1e9
    var x int = query(1)
    if mn > x{
      mn = x
      id = 1
    }
    x = query(2)
    if mn > x{
      mn = x
      id = 2
    }
    fmt.Print("! ", id)
    return
  }
  var x1 int = query(1); var x2 int = query(2)
  var sl = x1 - x2
  if sl < 0 {
    fmt.Print("! ", 1)
    return
  }
  var l, r int
  l = 2; r = n
  for r - l > 0{
    var mid int = (l + r) / 2;
    var num = query(mid);
    if x1 > x2 && num > x2 {
      r = mid
      continue
    }
    var newsl = num - query(mid + 1)
    if newsl > 0 && sl > 0 {
      l = mid + 1
    } else {
      r = mid
    }
  }
  fmt.Print("! ", l)
}

package main

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

type (
	input struct{ n int }
	req   struct{ i int }
	resp  struct{ v int }
	guess struct{ ans int }
)

// github.com/EndlessCheng/codeforces-go
func CF1479A(in input, Q func(req) resp) (gs guess) {
	q := func(i int) int { return Q(req{i}).v }
	n := in.n
	if n == 1 || q(1) < q(2) {
		gs.ans = 1
		return
	}
	if q(n-1) > q(n) {
		gs.ans = n
		return
	}
	res := sort.Search(n, func(i int) bool {
		if i < 2 || gs.ans > 0 {
			return false
		}
		x, y, z := q(i-1), q(i), q(i+1)
		if x > y && y < z {
			gs.ans = i
			return false
		}
		return x < y && y < z
	})
	if gs.ans == 0 {
		gs.ans = res
	}
	return
}

func ioq79() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	Q := func(req req) (resp resp) {
		Fprintln(out, "?", req.i)
		out.Flush()
		Fscan(in, &resp.v)
		return
	}

	d := input{}
	Fscan(in, &d.n)
	gs := CF1479A(d, Q)
	Fprint(out, "!", gs.ans)
	out.Flush()
}

func main() { ioq79() }