You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces.  Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$:   if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$;  if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$;  if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$;  if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower).

6
10 5
RRRRRRRRRRUUUUU
1 1
UDDDRLLL
-3 -5
LDLDLDDDR
1 2
LLLLUU
3 -2
RDULRLLDR
-1 6
RUDURUUUUR

NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces.

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
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 x,y int
		fmt.Fscan(in,&x,&y)
		var directions string
		fmt.Fscan(in,&directions)
		counter:=0
		if x > 0 {
			if strings.Count(directions,"R") >= x {
				counter++
			}
		}
		if x < 0 {
			if strings.Count(directions,"L") >= abs(x) {
				counter++
			}
		}
		if y > 0 {
			if strings.Count(directions,"U") >= y {
				counter++
			}
		}
		if y < 0 {
			if strings.Count(directions,"D") >= abs(y) {
				counter++
			}
		}
		if x == 0 {
			counter++
		}
		if y == 0 {
			counter++
		}
		if counter == 2 {
			fmt.Fprintln(out,"YES")
		} else {
			fmt.Fprintln(out,"NO")
		}
	}
}
func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer  out.Flush()
	cases:=0
	Fscan(in,&cases)
	for ;cases>0;cases-- {
		px,py:=0,0
		Fscan(in,&px,&py)
		var str string
		left,right,top,down:=0,0,0,0
		Fscan(in,&str)
		for i:=0;i<len(str);i++ {
			if str[i] == 'U' {
				top = top + 1
			}else if str[i] == 'D' {
				down = down - 1
			}else if str[i] == 'L' {
				left = left - 1
			}else if str[i] == 'R' {
				right = right + 1
			}
		}
		if px>=left && px <=right && py >= down && py <= top  {
			Fprintln(out,"YES")
		}else {
			Fprintln(out,"NO")
		}
	}

}

package main

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

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

func (in *CF1481A) 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 *CF1481A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
 Run solve the problem CF1481A
 Date: 26/05/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1481/A
 Problem: CF1481A
**/
func (in *CF1481A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		px := in.NextInt()
		py := in.NextInt()
		chain := in.NextString()

		data := map[uint8]int{}
		ws1, ws2 := false, false
		for i := 0; i < len(chain); i++ {
			val, ok := data[chain[i]]
			if !ok {
				data[chain[i]] = 0
			}
			data[chain[i]] = val + 1
		}

		U, _ := data['U']
		D, _ := data['D']
		R, _ := data['R']
		L, _ := data['L']

		if px < 0 && L >= -px  {
			ws1 = true
		}
		if px >= 0 && R >= px {
			ws1 = true
		}

		if py < 0 && D >= -py  {
			ws2 = true
		}
		if py >= 0 && U >= py {
			ws2 = true
		}

		if ws1 && ws2 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}

}

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

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

package main

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

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

func main() {
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n, m int
		fmt.Fscan(in, &n, &m)
		var s string
		fmt.Fscan(in, &s)
		var a [4]int
		for i := 0; i < len(s); i++ {
			if s[i] == 'R' {
				a[0]++
			}
			if s[i] == 'L' {
				a[1]--
			}
			if s[i] == 'U' {
				a[2]++
			}
			if s[i] == 'D' {
				a[3]--
			}
		}
		if a[1] <= n && n <= a[0] && a[3] <= m && m <= a[2] {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
	out.Flush()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, x, y, S := 0, 0, 0, ""
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &x, &y, &S)
		u, d, r, l := 0, 0, 0, 0
		U, D, R, L := strings.Count(S, "U"), strings.Count(S, "D"), strings.Count(S, "R"), strings.Count(S, "L")
		if x > 0 {
			r = x
		}
		if x < 0 {
			l = x
		}
		if y > 0 {
			u = y
		}
		if y < 0 {
			d = y
		}
		if u > 0 && U < u || d < 0 && D < -d || r > 0 && R < r || l < 0 && L < -l {
			fmt.Fprintln(w, "NO")
		} else {
			fmt.Fprintln(w, "YES")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

	for t > 0 {
		t--
		var x, y int
		fmt.Fscan(reader, &x, &y)

		str := ""
		fmt.Fscan(reader, &str)

		u, d, l, r := 0, 0, 0, 0
		for _, c := range str {
			if c == 'U' {
				u++
			}
			if c == 'D' {
				d++
			}
			if c == 'R' {
				r++
			}
			if c == 'L' {
				l++
			}
		}

		if -l <= x && x <= r && -d <= y && y <= u {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		px, py := scanInt(), scanInt()
		s := ScanString()
		count := map[rune]int{}

		for _, r := range s {
			count[r]++
		}

		x := count['R'] - count['L']
		y := count['U'] - count['D']

		if count['R'] >= x-px && count['L'] >= px-x && count['U'] >= y-py && count['D'] >= py-y {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t, x, y int
	var s string
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		data := make([]int, 4)
		fmt.Fscan(in, &x, &y, &s)
		for _, v := range s {
			data[getIdx(v)]++
		}
		if abs(x) <= data[getXY(x)] && abs(y) <= data[getUD(y)] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func getUD(y int) int {
	if y > 0 {
		return 0
	}
	return 2
}
func getXY(x int) int {
	if x > 0 {
		return 1
	}
	return 3
}
func getIdx(r rune) int {
	switch r {
	case 'U':
		return 0
	case 'R':
		return 1
	case 'D':
		return 2
	case 'L':
		return 3
	}
	return 0
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	t := getI()
	forEach(t, func(i int64) {
		x, y := getI(), getI()
		orders := getS()
		ordersMap := make(map[byte]int64)
		forEach(int64(len(orders)), func(j int64) {
			ordersMap[orders[j]]++
		})

		yValid := y == 0 || (y > 0 && ordersMap['U'] >= y) || (y < 0 && ordersMap['D'] >= abs(y))
		xValid := x == 0 || (x > 0 && ordersMap['R'] >= x) || (x < 0 && ordersMap['L'] >= abs(x))
		if yValid && xValid {
			out("YES")
		} else {
			out("NO")
		}
	})
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

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

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func sortInts(data []int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func joinInts(s []int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, px, py, fx, fy, L, R, U, D int
	var order string
	c := "YES"
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &px)
		Fscan(in, &py)
		Fscan(in, &order)
		for _, v := range order {
			if v == 'U' {
				U++
			} else if v == 'D' {
				D++
			} else if v == 'L' {
				L++
			} else if v == 'R' {
				R++
			}
		}
		fx = R - L
		fy = U - D
		if fx > px {
			if R < fx-px {
				c = "NO"
			}
		} else if fx < px {
			if L < (px - fx) {
				c = "NO"
			}
		}
		if fy > py {
			if U < fy-py {
				c = "NO"
			}
		} else if py > fy {
			if D < py-fy {
				c = "NO"
			}
		}
		Fprintln(out, c)
		L, R, U, D = 0, 0, 0, 0
		c = "YES"
	}
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		px, py := readTwoNums(reader)
		S, _ := reader.ReadString('\n')
		res := solve(px, py, S)
		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(px, py int, s string) bool {
	var a, b, c, d int
	for i := 0; i < len(s); i++ {
		if s[i] == 'U' {
			a++
		} else if s[i] == 'D' {
			b--
		} else if s[i] == 'L' {
			c--
		} else if s[i] == 'R' {
			d++
		}
	}
	return a >= py && py >= b && c <= px && px <= d
}

package main

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

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

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

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

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

		}
		return initial
	}
}

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

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var px int
		var py int
		fmt.Fscan(input, &px)
		fmt.Fscan(input, &py)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)

		var U int
		var D int
		var R int
		var L int
		for i := 0; i < len(STRING); i++ {
			if string(STRING[i]) == "U" {
				U = U + 1
			}
			if string(STRING[i]) == "D" {
				D = D + 1
			}
			if string(STRING[i]) == "R" {
				R = R + 1
			}
			if string(STRING[i]) == "L" {
				L = L + 1
			}

		}

		if px > R || py > U {
			fmt.Println("NO")
		} else {
			if px < 0 && -px > L {
				fmt.Println("NO")
			} else {
				if py < 0 && -py > D {
					fmt.Println("NO")
				} else {
					fmt.Println("YES")
				}
			}
		}
	}
}

package main

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

func main() {

	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var px, py int
		var s string
		_, _ = fmt.Fscan(in, &px, &py)
		_, _ = fmt.Fscan(in, &s)

		count := make(map[rune]int)
		for _, c := range s {
			count[c]++
		}

		var xPossible, yPossible bool
		if px > 0 {
			xPossible = px <= count['R']
		} else {
			xPossible = (-px) <= count['L']
		}

		if py > 0 {
			yPossible = py <= count['U']
		} else {
			yPossible = (-py) <= count['D']
		}

		if xPossible && yPossible {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

	var t, x, y int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &x, &y)
		fmt.Fscan(in, &s)
		u, d, l, r := 0, 0, 0, 0
		for i := range s {
			if s[i] == 'U' {
				u++
			}
			if s[i] == 'D' {
				d++
			}
			if s[i] == 'L' {
				l++
			}
			if s[i] == 'R' {
				r++
			}
		}
		if y > 0 && u < y ||
			y < 0 && d < -y ||
			x > 0 && r < x ||
			x < 0 && l < -x {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) bool {
		var x, y int
		var s string
		Fscan(in, &x, &y, &s)
		if x < 0 && strings.Count(s, "L") < -x || strings.Count(s, "R") < x {
			return false
		}
		if y < 0 && strings.Count(s, "D") < -y || strings.Count(s, "U") < y {
			return false
		}
		return true
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		Fprintln(out, map[bool]string{true: "YES", false: "NO"}[solve(Case)])
	}

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

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

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
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 x,y int
		fmt.Fscan(in,&x,&y)
		var directions string
		fmt.Fscan(in,&directions)
		counter:=0
		if x >= 0 {
			if strings.Count(directions,"R") >= x {
				counter++
			}
		}
		if x <= 0 {
			if strings.Count(directions,"L") >= abs(x) {
				counter++
			}
		}
		if y >= 0 {
			if strings.Count(directions,"U") >= y {
				counter++
			}
		}
		if y <= 0 {
			if strings.Count(directions,"D") >= abs(y) {
				counter++
			}
		}
		if counter >= 2 {
			fmt.Fprintln(out,"YES")
		} else {
			fmt.Fprintln(out,"NO")
		}
	}
}
func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
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 x,y int
		fmt.Fscan(in,&x,&y)
		var directions string
		fmt.Fscan(in,&directions)
		counter:=0
		if x >= 0 {
			if strings.Count(directions,"R") >= x {
				counter++
			}
		}
		if x <= 0 {
			if strings.Count(directions,"L") >= abs(x) {
				counter++
			}
		}
		if y >= 0 {
			if strings.Count(directions,"U") >= y {
				counter++
			}
		}
		if y <= 0 {
			if strings.Count(directions,"D") >= abs(y) {
				counter++
			}
		}
		if counter == 2 {
			fmt.Fprintln(out,"YES")
		} else {
			fmt.Fprintln(out,"NO")
		}
	}
}
func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}

package main

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

func main() {
	cases:=0
	fmt.Scanf("%d",&cases)
	for ;cases>0;cases-- {
		px,py:=0,0
		fmt.Scanf("%d %d",&px,&py)
		var str string
		left,right,top,down:=0,0,0,0
		fmt.Scanf("%s",&str)
		for i:=0;i<len(str);i++ {
			if str[i] == 'U' {
				top = top + 1
			}else if str[i] == 'D' {
				down = down - 1
			}else if str[i] == 'L' {
				left = left - 1
			}else if str[i] == 'R' {
				right = right + 1
			}
		}
		if px>=left && px <=right && py >= down && py <= top  {
			fmt.Println("YES")
		}else {
			fmt.Println("NO")
		}
		f := bufio.NewWriter(os.Stdout)
		f.Flush()
	}
}

package main

import "fmt"

func main() {
	cases:=0
	fmt.Scanf("%d",&cases)
	for ;cases>0;cases-- {
		px,py:=0,0
		fmt.Scanf("%d %d",&px,&py)
		var str string
		left,right,top,down:=0,0,0,0
		fmt.Scanf("%s",&str)
		for i:=0;i<len(str);i++ {
			if str[i] == 'U' {
				top = top + 1
			}else if str[i] == 'D' {
				down = down - 1
			}else if str[i] == 'L' {
				left = left - 1
			}else if str[i] == 'R' {
				right = right + 1
			}
		}
		if px>=left && px <=right && py >= down && py <= top  {
			fmt.Println("YES")
		}else {
			fmt.Println("NO")
		}
	}

}

package main

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

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

func (in *CF1481A) 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 *CF1481A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
 Run solve the problem CF1481A
 Date: 26/05/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1481/A
 Problem: CF1481A
**/
func (in *CF1481A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		px := in.NextInt()
		py := in.NextInt()
		chain := in.NextString()
		moves := map[uint8][]int{
			'U': {0, 1},
			'D': {0, -1},
			'R': {1, 0},
			'L': {-1, 0},
		}
		x, y := 0, 0
		ws1, ws2 := false, false
		for i := 0; i < len(chain); i++ {
			x += moves[chain[i]][0]
			y += moves[chain[i]][1]
			if x == px {
				ws1 = true
			}
			if y == py {
				ws2 = true
			}
		}

		if ws1 && ws2 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}

}

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

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

package main

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

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

func main() {
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n, m int
		fmt.Fscan(in, &n, &m)
		var s string
		fmt.Fscan(in, &s)
		var a [4]int
		for i := 0; i < len(s); i++ {
			if s[i] == 'R' {
				a[0]++
			}
			if s[i] == 'L' {
				a[1]--
			}
			if s[i] == 'U' {
				a[2]++
			}
			if s[i] == 'D' {
				a[3]--
			}
		}
		fmt.Println(a)
		if a[1] <= n && n <= a[0] && a[3] <= m && m <= a[2] {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
	out.Flush()
}


n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins k games in a row. This player becomes the winner.For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.

The first line contains two integers: n and k (2 ≤ n ≤ 500, 2 ≤ k ≤ 1012) — the number of people and the number of wins. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ai are distinct.

Output a single integer — power of the winner.

NoteGames in the second sample:3 plays with 1. 3 wins. 1 goes to the end of the line.3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.

package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data[deque.begin:deque.end])
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data[deque.begin:deque.end])

	}
}

func main() {
	var (
		n  int
		k0 int64
	)
	fmt.Scanf("%d %d\n", &n, &k0)

	if debug {
		fmt.Println(n, k0)
	}

	k := int(math.Min(float64(k0), float64(n-1)))

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

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(25000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 1
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

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

func solve() {
	n := readInt()
	k := readInt64()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}
	if a[0] < a[1] {
		a[0], a[1] = a[1], a[0]
	}
	wins := int64(0)
	for i := 1; i < n; i++ {
		if a[i-1] > a[i] {
			a[i-1], a[i] = a[i], a[i-1]
			wins++
		} else {
			wins = 1
		}
		if wins == k {
			fmt.Println(a[i])
			return
		}
	}
	fmt.Println(a[len(a)-1])
}

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

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

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

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	K := io.NextLong()
	A := io.NextIntArray(N)

	best := A[0]
	winner := A[0]
	consec := 0
	for i := 1; i < N; i++ {
		if winner > A[i] {
			consec++
			if int64(consec) >= K {
				io.Println(winner)
				return
			}
		} else {
			consec = 1
			best = A[i]
			winner = A[i]
		}
	}
	io.Println(best)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

import (
	"fmt"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	return element
}

func (deque *Deque) Push(element int) {
	fmt.Println(deque.data)

	deque.data[deque.end] = element
	deque.end++
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	//k = int(math.Min(float64(k), float64(n-1)))

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

	players := NewDeque(10)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	k = int(math.Min(float64(k), float64(n-1)))

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

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if opponent < current {
			players.Push(opponent)

			amount += 1
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	fmt.Println("Push", deque.data, deque.begin, deque.end)
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	//k = int(math.Min(float64(k), float64(n-1)))

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

	fmt.Println(a)

	players := NewDeque(10)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	fmt.Println("Push", deque.data, deque.begin, deque.end)
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	//k = int(math.Min(float64(k), float64(n-1)))

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

	players := NewDeque(10)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	k = int(math.Min(float64(k), float64(n-1)))

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

	players := NewDeque(1000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount += 1
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data, deque.begin, deque.end)

	}
}

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	k = int(math.Min(float64(k), float64(n-1)))

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

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	//fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	//fmt.Println("Push", deque.data, deque.begin, deque.end)
}

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	k = int(math.Min(float64(k), float64(n-1)))

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

	//fmt.Println(a)

	players := NewDeque(30000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		//fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data, deque.begin, deque.end)

	}
}

func main() {
	var (
		n  int
		k0 int64
	)
	fmt.Scanf("%d %d\n", &n, &k0)

	if debug {
		fmt.Println(n, k0)
	}

	k := int(math.Min(float64(k0), float64(n-1)))

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

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	//k = int(math.Min(float64(k), float64(n-1)))

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

	players := NewDeque(1000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	//k = int(math.Min(float64(k), float64(n-1)))

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

	players := NewDeque(1000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if opponent < current {
			players.Push(opponent)

			amount += 1
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data, deque.begin, deque.end)

	}
}

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	if debug {
		fmt.Println(n, k)
	}

	k = int(math.Min(float64(k), float64(n-1)))

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

	if n == 4 && a[1] == 4 {
		fmt.Println(n, k)
	}

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data, deque.begin, deque.end)

	}
}

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	if debug {
		fmt.Println(n, k)
	}

	k = int(math.Min(float64(k), float64(n-1)))

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

	if n == 4 && a[0] == 4 {
		fmt.Println(n, k)
	}

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data, deque.begin, deque.end)

	}
}

func main() {
	var (
		n  int
		k0 int64
	)
	fmt.Scanf("%d %d\n", &n, &k0)

	if debug {
		fmt.Println(n, k0)
	}

	k := int(math.Min(float64(k0), float64(n-1)))

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

	if n == 4 && a[1] == 4 {
		fmt.Println(n, k)
	}

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	K := io.NextLong()
	A := io.NextIntArray(N)

	best := A[0]
	winner := A[0]
	consec := 0
	for i := 1; i < N; i++ {
		if winner > A[i] {
			consec++
			if int64(consec) >= K {
				io.Println(winner)
				return
			}
		} else {
			consec = 0
			best = A[i]
			winner = A[i]
		}
	}
	io.Println(best)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


Petya has an array $$$a$$$ consisting of $$$n$$$ integers. He has learned partial sums recently, and now he can calculate the sum of elements on any segment of the array really fast. The segment is a non-empty sequence of elements standing one next to another in the array.Now he wonders what is the number of segments in his array with the sum less than $$$t$$$. Help Petya to calculate this number.More formally, you are required to calculate the number of pairs $$$l, r$$$ ($$$l \le r$$$) such that $$$a_l + a_{l+1} + \dots + a_{r-1} + a_r < t$$$.

The first line contains two integers $$$n$$$ and $$$t$$$ ($$$1 \le n \le 200\,000, |t| \le 2\cdot10^{14}$$$). The second line contains a sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$|a_{i}| \le 10^{9}$$$) — the description of Petya's array. Note that there might be negative, zero and positive elements.

Print the number of segments in Petya's array with the sum of elements less than $$$t$$$.

NoteIn the first example the following segments have sum less than $$$4$$$:  $$$[2, 2]$$$, sum of elements is $$$-1$$$  $$$[2, 3]$$$, sum of elements is $$$2$$$  $$$[3, 3]$$$, sum of elements is $$$3$$$  $$$[4, 5]$$$, sum of elements is $$$3$$$  $$$[5, 5]$$$, sum of elements is $$$-1$$$

package main

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

const (
	INF = 1234567890987654321
)

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	T := io.NextLong()
	A := io.NextLongArray(N)

	S := make([]int64, N)
	S[0] = A[0]
	for i := 1; i < N; i++ {
		S[i] = S[i-1] + A[i]
	}

	var cnt int64
	atrs := &AVLTreeRangeSum{}
	atrs.Increment(0, 1)
	for _, v := range S {
		add := int64(atrs.GetRange(avlKey(v-T+1), INF))
		cnt += add
		atrs.Increment(avlKey(v), 1)
	}
	io.Println(cnt)
}

// +-----------------------+
// | FILL IN THIS SECTION! |
// +-----------------------+

type avlKey int64
type avlValue int64

func (k avlKey) compare(other avlKey) int {
	if k < other {
		return -1
	} else if k > other {
		return 1
	}
	return 0
}

func (v avlValue) combine(other avlValue) avlValue {
	return v + other
}

func (v avlValue) uncombine(other avlValue) avlValue {
	return v - other
}

func avlDefaultValue() avlValue {
	return 0
}

// =========================

type AVLTreeRangeSum struct {
	root *avlTreeNode
}

func (atrs *AVLTreeRangeSum) Insert(k avlKey, v avlValue) {
	if atrs.tryCreateRoot(k, v) {
		return
	}
	path := atrs.root.getRootToLeafPath(k)
	path[len(path)-1].val = v
	updatePath(path)
	atrs.root = atrs.root.balance()
}

func (atrs *AVLTreeRangeSum) Increment(k avlKey, v avlValue) {
	if atrs.tryCreateRoot(k, v) {
		return
	}
	path := atrs.root.getRootToLeafPath(k)
	path[len(path)-1].val += v
	updatePath(path)
	atrs.root = atrs.root.balance()
}

func (atrs *AVLTreeRangeSum) Get(k avlKey) avlValue {
	curr := atrs.root
	for curr != nil {
		c := k.compare(curr.key)
		if c == 0 {
			return curr.val
		}
		if c < 0 {
			curr = curr.left
		} else {
			curr = curr.right
		}
	}
	return avlDefaultValue()
}

func (atrs *AVLTreeRangeSum) GetRange(lo, hi avlKey) avlValue {
	return atrs.root.getRangeLT(hi).uncombine(atrs.root.getRangeLT(lo))
}

func (atrs *AVLTreeRangeSum) tryCreateRoot(k avlKey, v avlValue) bool {
	if atrs.root == nil {
		atrs.root = &avlTreeNode{
			key: k,
			val: v,
			sum: v,
			ht:  1,
		}
		return true
	}
	return false
}

type avlTreeNode struct {
	key   avlKey
	val   avlValue
	sum   avlValue
	ht    int
	left  *avlTreeNode
	right *avlTreeNode
}

func (atn *avlTreeNode) getRangeLT(k avlKey) avlValue {
	curr := atn
	ans := avlDefaultValue()
	for curr != nil {
		if k.compare(curr.key) <= 0 {
			curr = curr.left
		} else {
			ans = ans.combine(curr.val).combine(curr.left.getSum())
			curr = curr.right
		}
	}
	return ans
}

func (atn *avlTreeNode) getRootToLeafPath(k avlKey) []*avlTreeNode {
	curr := atn
	lst := []*avlTreeNode{curr}
	for k.compare(curr.key) != 0 {
		if k.compare(curr.key) < 0 {
			curr.left = curr.left.getOrCreate(k)
			curr = curr.left
		} else {
			curr.right = curr.right.getOrCreate(k)
			curr = curr.right
		}
		lst = append(lst, curr)
	}
	return lst
}

func (atn *avlTreeNode) update() {
	atn.ht = 1 + Max(atn.left.getHeight()+atn.right.getHeight())
	atn.sum = atn.val + atn.left.getSum() + atn.right.getSum()
}

func (atn *avlTreeNode) getHeight() int {
	if atn == nil {
		return 0
	}
	return atn.ht
}

func (atn *avlTreeNode) getSum() avlValue {
	if atn == nil {
		return avlDefaultValue()
	}
	return atn.sum
}

func (atn *avlTreeNode) getOrCreate(k avlKey) *avlTreeNode {
	if atn == nil {
		return &avlTreeNode{
			key: k,
		}
	}
	return atn
}

func (atn *avlTreeNode) balance() *avlTreeNode {
	if atn == nil {
		return nil
	}
	bf := atn.getBalanceFactor()
	if bf > 1 {
		return atn.rotateRight()
	} else if bf < -1 {
		return atn.rotateLeft()
	} else {
		return atn
	}
}

func (atn *avlTreeNode) rotateRight() *avlTreeNode {
	pivot := atn.left
	atn.left = pivot.right
	pivot.right = atn
	atn.update()
	pivot.update()
	return pivot
}

func (atn *avlTreeNode) rotateLeft() *avlTreeNode {
	pivot := atn.right
	atn.right = pivot.left
	pivot.left = atn
	atn.update()
	pivot.update()
	return pivot
}

func (atn *avlTreeNode) getBalanceFactor() int {
	return atn.left.getHeight() - atn.right.getHeight()
}

func updatePath(path []*avlTreeNode) {
	for i := len(path) - 1; i >= 0; i-- {
		path[i].left = path[i].left.balance()
		path[i].right = path[i].right.balance()
		path[i].update()
	}
}

func Max(args ...int) int {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

const (
	INF = 1234567890987654321
)

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	T := io.NextLong()
	A := io.NextLongArray(N)

	S := make([]int64, N)
	S[0] = A[0]
	for i := 1; i < N; i++ {
		S[i] = S[i-1] + A[i]
	}

	// fmt.Println("S =", S)

	var cnt int64
	atrs := &AVLTreeRangeSum{}
	atrs.Increment(0, 1)
	// printo(atrs.root)
	// fmt.Println()
	for _, v := range S {
		add := int64(atrs.GetRange(avlKey(v-T+1), INF))
		// fmt.Printf("v = %d, lb = %d, add = %d\n", v, v-T+1, add)
		// fmt.Printf("  below lb: %d\n", atrs.root.getRangeLT(avlKey(v-T+1)))
		// fmt.Printf("  below rb: %d\n", atrs.root.getRangeLT(INF))
		cnt += add
		atrs.Increment(avlKey(v), 1)
		// printo(atrs.root)
		// fmt.Println()
	}
	io.Println(cnt)
}

func printo(node *avlTreeNode) {
	if node == nil {
		fmt.Print("[]")
		return
	}
	fmt.Printf("[ (%d: %d, sum = %d, ht = %d) -> ", node.key, node.val, node.sum, node.ht)
	printo(node.left)
	fmt.Print(" | ")
	printo(node.right)
	fmt.Print(" ]")
}

// +-----------------------+
// | FILL IN THIS SECTION! |
// +-----------------------+

type avlKey int64
type avlValue int64

func (k avlKey) compare(other avlKey) int {
	if k < other {
		return -1
	} else if k > other {
		return 1
	}
	return 0
}

func (v avlValue) combine(other avlValue) avlValue {
	return v + other
}

func (v avlValue) uncombine(other avlValue) avlValue {
	return v - other
}

func avlDefaultValue() avlValue {
	return 0
}

// =========================

type AVLTreeRangeSum struct {
	root *avlTreeNode
}

func (atrs *AVLTreeRangeSum) Insert(k avlKey, v avlValue) {
	if atrs.tryCreateRoot(k, v) {
		return
	}
	path := atrs.root.getRootToLeafPath(k)
	path[len(path)-1].val = v
	updatePath(path)
	atrs.root = atrs.root.balance()
}

func (atrs *AVLTreeRangeSum) Increment(k avlKey, v avlValue) {
	if atrs.tryCreateRoot(k, v) {
		return
	}
	path := atrs.root.getRootToLeafPath(k)
	path[len(path)-1].val += v
	updatePath(path)
	atrs.root = atrs.root.balance()
}

func (atrs *AVLTreeRangeSum) Get(k avlKey) avlValue {
	curr := atrs.root
	for curr != nil {
		c := k.compare(curr.key)
		if c == 0 {
			return curr.val
		}
		if c < 0 {
			curr = curr.left
		} else {
			curr = curr.right
		}
	}
	return avlDefaultValue()
}

func (atrs *AVLTreeRangeSum) GetRange(lo, hi avlKey) avlValue {
	return atrs.root.getRangeLT(hi).uncombine(atrs.root.getRangeLT(lo))
}

func (atrs *AVLTreeRangeSum) tryCreateRoot(k avlKey, v avlValue) bool {
	if atrs.root == nil {
		atrs.root = &avlTreeNode{
			key: k,
			val: v,
			sum: v,
			ht:  1,
		}
		return true
	}
	return false
}

type avlTreeNode struct {
	key   avlKey
	val   avlValue
	sum   avlValue
	ht    int
	left  *avlTreeNode
	right *avlTreeNode
}

func (atn *avlTreeNode) getRangeLT(k avlKey) avlValue {
	curr := atn
	ans := avlDefaultValue()
	for curr != nil {
		if k.compare(curr.key) <= 0 {
			curr = curr.left
		} else {
			ans = ans.combine(curr.val).combine(curr.left.getSum())
			curr = curr.right
		}
	}
	return ans
}

func (atn *avlTreeNode) getRootToLeafPath(k avlKey) []*avlTreeNode {
	curr := atn
	lst := []*avlTreeNode{curr}
	for k.compare(curr.key) != 0 {
		if k.compare(curr.key) < 0 {
			curr.left = curr.left.getOrCreate(k)
			curr = curr.left
		} else {
			curr.right = curr.right.getOrCreate(k)
			curr = curr.right
		}
		lst = append(lst, curr)
	}
	return lst
}

func (atn *avlTreeNode) update() {
	atn.ht = 1 + Max(atn.left.getHeight()+atn.right.getHeight())
	atn.sum = atn.val + atn.left.getSum() + atn.right.getSum()
}

func (atn *avlTreeNode) getHeight() int {
	if atn == nil {
		return 0
	}
	return atn.ht
}

func (atn *avlTreeNode) getSum() avlValue {
	if atn == nil {
		return avlDefaultValue()
	}
	return atn.sum
}

func (atn *avlTreeNode) getOrCreate(k avlKey) *avlTreeNode {
	if atn == nil {
		return &avlTreeNode{
			key: k,
		}
	}
	return atn
}

func (atn *avlTreeNode) balance() *avlTreeNode {
	if atn == nil {
		return nil
	}
	bf := atn.getBalanceFactor()
	if bf > 1 {
		return atn.rotateRight()
	} else if bf < -1 {
		return atn.rotateLeft()
	} else {
		return atn
	}
}

func (atn *avlTreeNode) rotateRight() *avlTreeNode {
	pivot := atn.left
	atn.left = pivot.right
	pivot.right = atn
	atn.update()
	pivot.update()
	return pivot
}

func (atn *avlTreeNode) rotateLeft() *avlTreeNode {
	pivot := atn.right
	atn.right = pivot.left
	pivot.left = atn
	atn.update()
	pivot.update()
	return pivot
}

func (atn *avlTreeNode) getBalanceFactor() int {
	return atn.left.getHeight() - atn.right.getHeight()
}

func updatePath(path []*avlTreeNode) {
	for i := len(path) - 1; i >= 0; i-- {
		path[i].left = path[i].left.balance()
		path[i].right = path[i].right.balance()
		path[i].update()
	}
}

func Max(args ...int) int {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

const (
	Min = -(1<<62)
	MaxN = 200005
)

var n int
var t int64
var a [MaxN]int64
var pre [MaxN]int64
var c []int64
var tree [MaxN]int64

func update(ind int) {
	for ;ind < MaxN; ind += ind & -ind {
		tree[ind]++
	}
}

func query(ind int) int64 {
	s := int64(0)
	for ;ind > 0; ind -= ind & -ind {
		s += tree[ind]
	}
	return s
}

func makeCoords() {
	c = make([]int64, 0)
	c = append(c, Min)
	c = append(c, pre[0])
	for i := 1; i <= n; i++ {
		if c[len(c) - 1] != pre[i] {
			c = append(c, pre[i])
		}
	}
}

func search(l []int64, val int64) int {
	return sort.Search(len(l), func(ind int) bool {
		return l[ind] >= val
	})
}

func upperBound(l []int64, val int64) int {
	return sort.Search(len(l), func(ind int) bool {
		return l[ind] > val
	})
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d\n", &n, &t)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
	}
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i-1] + a[i]
	}
	sort.Slice(pre[:n+1], func(i, j int) bool {
		return pre[i] < pre[j]
	})
	makeCoords()
	update(search(c, 0))

	ans := int64(0)
	s := int64(0)
	for i := 0; i < n; i++ {
		s += a[i]
		smaller := upperBound(c, s - t) - 1
		ans += int64(i + 1) - query(smaller)
		update(search(c, s))
	}
	fmt.Println(ans)
}


Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.There are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.Let's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".The year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.For example, if $$$n = 3, m = 4, s = $$${"a", "b", "c"}, $$$t =$$$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat.  You are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system?

The first line contains two integers $$$n, m$$$ ($$$1 \le n, m \le 20$$$). The next line contains $$$n$$$ strings $$$s_1, s_2, \ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. The next line contains $$$m$$$ strings $$$t_1, t_2, \ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$. Among the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different). The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2\,020$$$). In the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \le y \le 10^9$$$) is given, denoting the year we want to know the name for.

Print $$$q$$$ lines. For each line, print the name of the year as per the rule described above.

NoteThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal.

package main

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

func main() {
	var n, m, q, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n, &m)
	s := make([]string, n)
	t := make([]string, m)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &s[i])
	}
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &t[i])
	}
	fmt.Fscan(in, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(in, &a)
		fmt.Println(s[(a-1)%n] + t[(a-1)%m])
	}
}

// A. New Year and Naming
/*
Happy new year! The year 2020 is also known as Year Gyeongja
(경자년, gyeongja-nyeon) in Korea. Where did the name come from?
Let's briefly look at the Gapja system, which is traditionally used in Korea to
name the years.

There are two sequences of 𝑛 strings 𝑠1,𝑠2,𝑠3,…,𝑠𝑛 and 𝑚 strings 𝑡1,𝑡2,𝑡3,…,𝑡𝑚.
These strings contain only lowercase letters.
There might be duplicates among these strings.

Let's call a concatenation of strings 𝑥 and 𝑦 as the string that is
obtained by writing down strings 𝑥 and 𝑦 one right after another without
changing the order. For example, the concatenation of the strings "code" and
"forces" is the string "codeforces".

The year 1 has a name which is the concatenation of the two strings 𝑠1 and 𝑡1.
When the year increases by one, we concatenate the next two strings in order
from each of the respective sequences. If the string that is currently being
used is at the end of its sequence, we go back to the first string
in that sequence.

For example, if 𝑛=3,𝑚=4,𝑠={"a", "b", "c"}, 𝑡= {"d", "e", "f", "g"},
the following table denotes the resulting year names.
Note that the names of the years may repeat.

You are given two sequences of strings of size 𝑛 and 𝑚 and also 𝑞 queries.
For each query, you will be given the current year.
Could you find the name corresponding to the given year,
according to the Gapja system?

Input
The first line contains two integers 𝑛,𝑚(1≤𝑛,𝑚≤20).

The next line contains 𝑛 strings 𝑠1,𝑠2,…,𝑠𝑛. Each string contains only
lowercase letters, and they are separated by spaces.
The length of each string is at least 1 and at most 10.

The next line contains 𝑚 strings 𝑡1,𝑡2,…,𝑡𝑚. Each string contains only
lowercase letters, and they are separated by spaces.
The length of each string is at least 1 and at most 10.

Among the given 𝑛+𝑚 strings may be duplicates
(that is, they are not necessarily all different).

The next line contains a single integer 𝑞 (1≤𝑞≤2020).

In the next 𝑞 lines, an integer 𝑦 (1≤𝑦≤109) is given,
denoting the year we want to know the name for.

Output
Print 𝑞 lines. For each line, print the name of the year as
per the rule described above.

Example
Input
10 12
sin im gye gap eul byeong jeong mu gi gyeong
yu sul hae ja chuk in myo jin sa o mi sin
14
1
2
3
4
10
11
12
13
73
2016
2017
2018
2019
2020

Output
sinyu
imsul
gyehae
gapja
gyeongo
sinmi
imsin
gyeyu
gyeyu
byeongsin
jeongyu
musul
gihae
gyeongja

Note
The first example denotes the actual names used in the Gapja system.
These strings usually are either a number or the name of some animal.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _, _ := reader.ReadLine()
	inputArr := strings.Split(string(input1), " ")
	n, _ := strconv.Atoi(inputArr[0])
	m, _ := strconv.Atoi(inputArr[1])

	input2, _ := reader.ReadString('\n')
	s := strings.Split(strings.TrimSpace(input2), " ")

	input3, _ := reader.ReadString('\n')
	t := strings.Split(strings.TrimSpace(input3), " ")

	input4, _ := reader.ReadString('\n')
	q, _ := strconv.Atoi(strings.TrimSpace(input4))

	for ; q > 0; q-- {
		j, k := 0, 0

		input5, _ := reader.ReadString('\n')
		year, _ := strconv.Atoi(strings.TrimSpace(input5))

		if year%n == 0 {
			j = n
		} else {
			j = year % n
		}
		if year%m == 0 {
			k = m
		} else {
			k = year % m
		}
		fmt.Printf("%v%v\n", s[j-1], t[k-1])
	}
}

package main

import "fmt"

func main() {
	var n, m, q, y int
	buf1 := make([]string, 20, 20)
	buf2 := make([]string, 20, 20)
	var str string
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		fmt.Scan(&str)
		buf1[i] = str
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&str)
		buf2[i] = str
	}
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		fmt.Scan(&y)
		fmt.Println(buf1[(y-1)%n] + buf2[(y-1)%m])
	}
}

package main

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

func scanStrings(r *bufio.Reader, n int, s []string) {
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &s[i])
	}
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	var n, m, q int
	fmt.Fscan(r, &n, &m)
	s := make([]string, n)
	t := make([]string, m)
	scanStrings(r, n, s)
	scanStrings(r, m, t)
	fmt.Fscan(r, &q)
	for i := 0; i < q; i++ {
		var y int
		fmt.Fscan(r, &y)
		fmt.Fprint(w, s[(y-1)%n ], t[(y-1)%m], "\n")
	}
	w.Flush()
}

package main

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

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	n, m := readInt2()
	s := readStringArray(n)
	t := readStringArray(m)
	q := readInt()
	years := readIntArray(q)

	for _, y := range years {
		l := s[(y-1)%len(s)]
		r := t[(y-1)%len(t)]
		fmt.Printf("%s%s\n", l, r)
	}
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

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

//str := PrintlnInts(X...)

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

func main() {
	n, m := ReadInt2()
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	t := make([]string, m)
	for i := 0; i < m; i++ {
		t[i] = ReadString()
	}
	for q := ReadInt(); q > 0; q-- {
		y := ReadInt()
		y--
		fmt.Println(s[y%n] + t[y%m])
	}
}

/*********** Math ***********/
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

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

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

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

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

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

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

func readInt_64() int64 {
	return readIntNbits(64)
}

func ReadInt2_64() (int64, int64) {
	return readInt_64(), readInt_64()
}

func ReadInt3_64() (int64, int64, int64) {
	return readInt_64(), readInt_64(), readInt_64()
}

func readInt() int {
	return int(readIntNbits(32))
}

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

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

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

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

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

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

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

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

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

	return string(res)
}

package main

import (
	"fmt"
	"strings"
)

func main(){
	var n, m, q, k int
	fmt.Scan(&n, &m)
	s := make([]string, 0, n)
	t := make([]string, 0, m)
	var word string
	for i:= 0; i < n; i++ {
		fmt.Scan(&word)
		s = append(s, word)
	}
	for i:= 0; i < m; i++ {
		fmt.Scan(&word)
		t = append(t, word)
	}
	fmt.Scan(&q)
	result := make([]string, 0, q)
	for i:= 0; i < q; i++ {
		fmt.Scan(&k)
		result = append(result, s[(k - 1) % n] + t[(k - 1) % m])
	}
	fmt.Println(strings.Join(result, "\n"))
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var i, n, m, q, year int64
	fmt.Fscanln(reader, &n, &m)
	s := make([]string, n)
	t := make([]string, m)
	for ; i < n; i++ {
		if i == n-1 {
			fmt.Fscanf(reader, "%s\n", &s[i])
		} else {
			fmt.Fscanf(reader, "%s", &s[i])
		}
	}
	for i = 0; i < m; i++ {
		if i == m-1 {
			fmt.Fscanf(reader, "%s\n", &t[i])
		} else {
			fmt.Fscanf(reader, "%s", &t[i])
		}
	}
	fmt.Fscanln(reader, &q)
	for ; q > 0; q-- {
		fmt.Fscanln(reader, &year)
		sindex := year % n
		if sindex == 0 {
			sindex = n
		}
		sindex -= 1
		tindex := year % m
		if tindex == 0 {
			tindex = m
		}
		tindex -= 1
		fmt.Fprintln(writer, s[sindex]+t[tindex])
	}
}

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	const mod int = 1e9 + 7

	var n,m int
	Fscan(in, &n, &m)
	a1 := make([]string, n)
	for i := range a1 {
		Fscan(in, &a1[i])
	}
	a2 := make([]string, m)
	for i := range a2 {
		Fscan(in, &a2[i])
	}
	var q int
	Fscan(in, &q)
	for ;q>0;q-- {
		var  y int
		Fscan(in, &y)
		y--
		Fprintln(out, a1[y%n]+a2[y%m])
	}
}

func main() {
	solve(os.Stdin, os.Stdout)
	//in, _ := os.Open("input.txt")
	//out, _ := os.Open("output.txt")
	//solve(in, out)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func ifElseI(cond bool, a, b int) int {
	if cond {
		return a
	}
	return b
}
func ifElseS(cond bool, a, b string) string {
	if cond {
		return a
	}
	return b
}

package main

import (
	"fmt"
)

func main() {
	var n, m, q, year int
	fmt.Scan(&n, &m)
	firstParts := make([]string, n)
	secondParts := make([]string, m)
	for i := range firstParts {
		fmt.Scan(&firstParts[i])
	}
	for i := range secondParts {
		fmt.Scan(&secondParts[i])
	}
	fmt.Scan(&q)
	answers := make([]string, q)
	for i := 0; i < q; i++ {
		fmt.Scan(&year)
		year--
		answers[i] = firstParts[year%n] + secondParts[year%m]
	}
	for _, answer := range answers {
		fmt.Println(answer)
	}
}

package main

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

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

	// input
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)

	s := []string{}
	t := []string{}

	line := ""
	line, _ = in.ReadString('\n')
	line = strings.TrimSpace(line)
	s = strings.Split(line, " ")

	line = ""
	line, _ = in.ReadString('\n')
	line = strings.TrimSpace(line)
	t = strings.Split(line, " ")

	q := 0
	fmt.Fscanf(in, "%d\n", &q)

	for i := 0; i < q; i++ {
		year := 0
		fmt.Fscanf(in, "%d\n", &year)
		year--

		sIdx := year % n
		tIdx := year % m
		fmt.Fprintln(out, s[sIdx]+t[tIdx])
	}
}

package main

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

func main() {
	n, m := ReadInt(), ReadInt()
	s, t := ReadStringSlice(n), ReadStringSlice(m)

	q := ReadInt()
	for j := 0; j < q; j++ {
		yr := ReadInt()
		yr--
		out <- (s[ yr%n] + t[yr%m])
	}

	close(out)
	outWg.Wait()
}

/*********************** utility ***********************/

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	// set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

		for line := range out {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.Atoi(intStr)
	return i
}

func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i], _ = strconv.Atoi(ReadString())
	}
	return arr
}

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

func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}

package main

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

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

	inputList := strings.Split(scanner.Text(), " ")

	n, _ := strconv.Atoi(inputList[0])
	m, _ := strconv.Atoi(inputList[1])

	nList := make(map[int]string, n+1)
	mList := make(map[int]string, m+1)

	var index int
	var element string

	scanner.Scan()
	for index, element = range strings.Split(scanner.Text(), " ") {
		nList[index+1] = element
	}

	scanner.Scan()
	for index, element = range strings.Split(scanner.Text(), " ") {
		mList[index+1] = element
	}

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

	var quest, remN, remM int
	for i := 0; i < q; i++ {
		scanner.Scan()
		quest, _ = strconv.Atoi(scanner.Text())

		remN = quest % n
		if remN == 0 {
			remN = n
		}

		remM = quest % m
		if remM == 0 {
			remM = m
		}

		fmt.Println(nList[remN] + mList[remM])
	}
}

// 10 12
// sin im gye gap eul byeong jeong mu gi gyeong
// yu sul hae ja chuk in myo jin sa o mi sin
// 14
// 1
// 2
// 3
// 4
// 10
// 11
// 12
// 13
// 73
// 2016
// 2017
// 2018
// 2019
// 2020

package main

import (
	"fmt"
)

func main() {
	var n, m, q, year int
	fmt.Scan(&n, &m)
	var s []string = make([]string, n)
	var t []string = make([]string, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&t[i])
	}
	fmt.Scan(&q)
	for q != 0 {
		fmt.Scan(&year)
		i := (year % n) - 1
		j := (year % m) - 1
		if i < 0 {
			i = n + i
		}
		if j < 0 {
			j = m + j
		}
		fmt.Printf("%s%s\n", s[i], t[j])
		q--
	}

}

package main

import "fmt"

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

    var ns []string
    for i := 0; i < n; i++ {
        var s string
        fmt.Scan(&s)
        ns = append(ns, s)
    }
    var ms []string
    for i := 0; i < m; i++ {
        var s string
        fmt.Scan(&s)
        ms = append(ms, s)
    }
    var q int
    fmt.Scan(&q)
    for i := 0; i < q; i++ {
        var y int
        fmt.Scan(&y)

        pn := (y-1) % n
        pm := (y-1) % m

        fmt.Println(ns[pn]+ms[pm])
    }
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var s, t int
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &t)
	p1 := make([]string, s)
	p2 := make([]string, t)
	for i:=0; i<s; i++ {fmt.Fscan(in, &p1[i])}
	for i:=0; i<t; i++ {fmt.Fscan(in, &p2[i])}
	lp1, lp2 := len(p1), len(p2)
	q := 0
	fmt.Fscan(in, &q)
	for ; q>0; q-- {
		y := 0
		fmt.Fscan(in, &y)
		pre, suf := lp1, lp2
		if y % lp1 != 0 {pre = y % lp1}
		if y % lp2 != 0 {suf = y % lp2}
		fmt.Fprint(out, p1[pre-1]+p2[suf-1]+"\n")
	}
}

package main

import (
    "fmt"
)

func main() {
    var(
        n int
        m int
        q int
        x int
        a [22]string
        b [22]string
    )
    fmt.Scanf("%d %d\n",&n, &m)
    for i:=0 ; i<n ; i++{
        fmt.Scanf("%s", &a[i])
    }
    fmt.Scanf("%s",&a[21])
    for i:=0 ; i<m ; i++{
        fmt.Scanf("%s", &b[i])
    }
    fmt.Scanf("%s",&a[21])
    fmt.Scanf("%d\n",&q);
    for i:=0 ; i<q ; i++{
        fmt.Scanf("%d\n", &x)
        x--
        fmt.Println(a[x%n]+b[x%m])
    }
}

package main

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

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

  var n, m int
  fmt.Fscan(in, &n, &m)
  a := make([]string, n)
  b := make([]string, m)

  for i := 0; i < n; i++ {
    fmt.Fscan(in, &a[i])
  }
  for i := 0; i < m; i++ {
    fmt.Fscan(in, &b[i])
  }

  var q int
  fmt.Fscan(in, &q)
  for i := 0; i < q; i++ {
    var x int
    fmt.Fscan(in, &x)

    fmt.Fprintln(out, a[(x - 1)%n] + b[(x - 1)%m]);
  }
}

package main

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

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

	var n, m, q, y int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	arr1 := make([]string, n)
	arr2 := make([]string, m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%s", &arr1[i])
	}
	fmt.Fscanf(reader, "\n")
	for i := 0; i < m; i++ {
		fmt.Fscanf(reader, "%s", &arr2[i])
	}
	fmt.Fscanf(reader, "\n")
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 1; i <= q; i++ {
		fmt.Fscanf(reader, "%d\n", &y)
		r1 := y % n
		r2 := y % m
		var idx1, idx2 int
		if r1 == 0 {
			idx1 = n - 1
		} else {
			idx1 = r1 - 1
		}
		if r2 == 0 {
			idx2 = m - 1
		} else {
			idx2 = r2 - 1
		}
		fmt.Fprintf(writer, "%s%s\n", arr1[idx1], arr2[idx2])
	}
}

package main

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

type WordScanner struct {
	*bufio.Scanner
}

func NewWordScanner() *WordScanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &WordScanner{Scanner: s}
}

func (s *WordScanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *WordScanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *WordScanner) NextString() string {
	s.Scan()
	return s.Text()
}

func elapsed(t time.Time) {
	fmt.Println(time.Since(t))
}

func sol(s, t []string, y int) string {
	y -= 1
	return s[y%len(s)] + t[y%len(t)]
}

func main() {
	wscn := NewWordScanner()
	n := wscn.NextInt()
	m := wscn.NextInt()
	s := []string{}
	t := []string{}
	for ; n > 0; n-- {
		s = append(s, wscn.NextString())
	}
	for ; m > 0; m-- {
		t = append(t, wscn.NextString())
	}
	q := wscn.NextInt()
	for ; q > 0; q-- {
		y := wscn.NextInt()
		fmt.Println(sol(s, t, y))
	}
}

package main

import "fmt"

func main() {
	var n, m, q, y int
	buf1 := make([]string, 20, 20)
	buf2 := make([]string, 20, 20)
	var str string
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		fmt.Scan(&str)
		buf1[i] = str
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&str)
		buf2[i] = str
	}
	fmt.Println(buf1, buf2)
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		fmt.Scan(&y)
		fmt.Println(buf1[(y-1)%n] + buf2[(y-1)%m])
	}
}

// 10 12
// sin im gye gap eul byeong jeong mu gi gyeong
// yu sul hae ja chuk in myo jin sa o mi sin
// 14
// 1
// 2
// 3
// 4
// 10
// 11
// 12
// 13
// 73
// 2016
// 2017
// 2018
// 2019
// 2020

package main

import (
	"fmt"
)

func main() {
	var n, m, q, year int
	fmt.Scan(&n, &m)
	var s []string = make([]string, n)
	var t []string = make([]string, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&t[i])
	}
	fmt.Scan(&q)
	for q != 0 {
		fmt.Scan(&year)
		i := (year % n) - 1
		j := (year % m) - 1
		fmt.Println(i, j)
		if i < 0 {
			i = n + i
		}
		if j < 0 {
			j = m + j
		}
		fmt.Printf("%s%s\n", s[i], t[j])
		q--
	}

}


You have been offered a job in a company developing a large social network. Your first task is connected with searching profiles that most probably belong to the same user.The social network contains n registered profiles, numbered from 1 to n. Some pairs there are friends (the "friendship" relationship is mutual, that is, if i is friends with j, then j is also friends with i). Let's say that profiles i and j (i ≠ j) are doubles, if for any profile k (k ≠ i, k ≠ j) one of the two statements is true: either k is friends with i and j, or k isn't friends with either of them. Also, i and j can be friends or not be friends.Your task is to count the number of different unordered pairs (i, j), such that the profiles i and j are doubles. Note that the pairs are unordered, that is, pairs (a, b) and (b, a) are considered identical.

The first line contains two space-separated integers n and m (1 ≤ n ≤ 106, 0 ≤ m ≤ 106), — the number of profiles and the number of pairs of friends, correspondingly.  Next m lines contains descriptions of pairs of friends in the format "v u", where v and u (1 ≤ v, u ≤ n, v ≠ u) are numbers of profiles that are friends with each other. It is guaranteed that each unordered pair of friends occurs no more than once and no profile is friends with itself.

Print the single integer — the number of unordered pairs of profiles that are doubles.  Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the %I64d specificator.

NoteIn the first and second sample any two profiles are doubles.In the third sample the doubles are pairs of profiles (1, 3) and (2, 4).

package main

// http://codeforces.com/problemset/problem/154/C

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

const mx = 1000000

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

	mtable [mx]uint64
	// pri    = uint64(15932464337171)
	pri = uint64(1004271249911446763)
	// 9223372036854775807 maxint
)

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

func main() {
	var n, m uint64
	Scanf("%d %d\n", &n, &m)
	defer writer.Flush()
	Dprint("n=%d, m=%d", n, m)

	// init multipl. table
	mtable[0] = 1
	for i := 1; i < mx; i++ {
		mtable[i] = (mtable[i-1] * 3) % pri
	}

	hashes := make([]uint64, n*2) // hashes[i] is hash of ith
	for i := uint64(0); i < n; i++ {
		hashes[n+i] = mtable[i]
	}

	for i := uint64(0); i < m; i++ {
		var v, u uint64
		Scanf("%d %d\n", &v, &u)
		v--
		u--
		hashes[v] += mtable[u]
		hashes[v] %= pri
		hashes[u] += mtable[v]
		hashes[u] %= pri

		hashes[n+v] += mtable[u]
		hashes[n+v] %= pri
		hashes[n+u] += mtable[v]
		hashes[n+u] %= pri
	}

	sort.Slice(hashes, func(i, j int) bool {
		return hashes[i] < hashes[j]
	})

	dups := uint64(0)
	rSize := uint64(1)
	for i := 1; i < len(hashes); i++ {
		if hashes[i] == hashes[i-1] {
			rSize++
		} else {
			dups += rSize * (rSize - 1) / 2
			rSize = 1
		}
	}
	if rSize != 1 {
		dups += rSize * (rSize - 1) / 2
	}
	// Dprint("%v", hashes)
	Printf("%d", dups)
}

package main

// http://codeforces.com/problemset/problem/154/C

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

const mx = 1000000

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

	mtable [mx]int64
	pri    = int64(15932464337171)
)

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

func main() {
	var n, m int64
	Scanf("%d %d\n", &n, &m)
	defer writer.Flush()
	Dprint("n=%d, m=%d", n, m)

	// init multipl. table
	mtable[0] = 1
	for i := 1; i < mx; i++ {
		mtable[i] = (mtable[i-1] * 3) % pri
	}

	hashes := make([]int64, n*2) // hashes[i] is hash of ith
	for i := int64(0); i < n; i++ {
		hashes[n+i] = mtable[i]
	}

	for i := int64(0); i < m; i++ {
		var v, u int64
		Scanf("%d %d\n", &v, &u)
		v--
		u--
		hashes[v] += mtable[u]
		hashes[v] %= pri
		hashes[u] += mtable[v]
		hashes[u] %= pri

		hashes[n+v] += mtable[u]
		hashes[n+v] %= pri
		hashes[n+u] += mtable[v]
		hashes[n+u] %= pri
	}

	sort.Slice(hashes, func(i, j int) bool {
		return hashes[i] < hashes[j]
	})

	dups := 0
	rSize := 1
	for i := 1; i < len(hashes); i++ {
		if hashes[i] == hashes[i-1] {
			rSize++
		} else {
			dups += rSize * (rSize - 1) / 2
			rSize = 1
		}
	}
	if rSize != 1 {
		dups += rSize * (rSize - 1) / 2
	}
	// Dprint("%v", hashes)
	Printf("%d", dups)
}

package main

// http://codeforces.com/problemset/problem/154/C

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

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

	mtable [1000000]int64
	pri    = int64(15932464337171)
)

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

func main() {
	var n, m int64
	Scanf("%d %d\n", &n, &m)
	defer writer.Flush()

	// init multipl. table
	mtable[0] = 1
	for i := 1; i < 1000000; i++ {
		mtable[i] = (mtable[i-1] * 3) % pri
	}

	hashes := make([]int64, n) // hashes[i] is hash of ith
	for i := int64(0); i < m; i++ {
		hashes[i] = mtable[i]
	}
	for i := int64(0); i < m; i++ {
		var v, u int64
		Scanf("%d %d\n", &v, &u)
		v--
		u--
		hashes[v] += mtable[u]
		hashes[v] %= pri
		hashes[u] += mtable[v]
		hashes[u] %= pri
	}

	sort.Slice(hashes, func(i, j int) bool {
		return hashes[i] < hashes[j]
	})

	dups := 0
	fstDup := true
	for i := 1; i < len(hashes); i++ {
		if hashes[i] == hashes[i-1] {
			// Found duplicate.
			if fstDup {
				dups++
				fstDup = false
			}
			dups++
		} else {
			fstDup = true
		}
	}
	Dprint("%v", hashes)
	Printf("%d", dups)
}

package main

// http://codeforces.com/problemset/problem/154/C

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

const mx = 1000000

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

	mtable [mx]uint64
	pri    = uint64(15932464337171)
	// 9223372036854775807 maxint
)

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

func main() {
	var n, m uint64
	Scanf("%d %d\n", &n, &m)
	defer writer.Flush()
	Dprint("n=%d, m=%d", n, m)

	// init multipl. table
	mtable[0] = 1
	for i := 1; i < mx; i++ {
		mtable[i] = (mtable[i-1] * 3) % pri
	}

	hashes := make([]uint64, n*2) // hashes[i] is hash of ith
	for i := uint64(0); i < n; i++ {
		hashes[n+i] = mtable[i]
	}

	for i := uint64(0); i < m; i++ {
		var v, u uint64
		Scanf("%d %d\n", &v, &u)
		v--
		u--
		hashes[v] += mtable[u]
		hashes[v] %= pri
		hashes[u] += mtable[v]
		hashes[u] %= pri

		hashes[n+v] += mtable[u]
		hashes[n+v] %= pri
		hashes[n+u] += mtable[v]
		hashes[n+u] %= pri
	}

	sort.Slice(hashes, func(i, j int) bool {
		return hashes[i] < hashes[j]
	})

	dups := uint64(0)
	rSize := uint64(1)
	for i := 1; i < len(hashes); i++ {
		if hashes[i] == hashes[i-1] {
			rSize++
		} else {
			dups += rSize * (rSize - 1) / 2
			rSize = 1
		}
	}
	if rSize != 1 {
		dups += rSize * (rSize - 1) / 2
	}
	// Dprint("%v", hashes)
	Printf("%d", dups)
}

package main

// http://codeforces.com/problemset/problem/154/C

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

const mx = 1000000

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

	mtable [mx]int64
	pri    = int64(15932464337171)
	// 9223372036854775807 maxint
)

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

func main() {
	var n, m int64
	Scanf("%d %d\n", &n, &m)
	defer writer.Flush()
	Dprint("n=%d, m=%d", n, m)

	// init multipl. table
	mtable[0] = 1
	for i := 1; i < mx; i++ {
		mtable[i] = (mtable[i-1] * 3) % pri
	}

	hashes := make([]int64, n*2) // hashes[i] is hash of ith
	for i := int64(0); i < n; i++ {
		hashes[n+i] = mtable[i]
	}

	for i := int64(0); i < m; i++ {
		var v, u int64
		Scanf("%d %d\n", &v, &u)
		v--
		u--
		hashes[v] += mtable[u]
		hashes[v] %= pri
		hashes[u] += mtable[v]
		hashes[u] %= pri

		hashes[n+v] += mtable[u]
		hashes[n+v] %= pri
		hashes[n+u] += mtable[v]
		hashes[n+u] %= pri
	}

	sort.Slice(hashes, func(i, j int) bool {
		return hashes[i] < hashes[j]
	})

	dups := uint64(0)
	rSize := uint64(1)
	for i := 1; i < len(hashes); i++ {
		if hashes[i] == hashes[i-1] {
			rSize++
		} else {
			dups += rSize * (rSize - 1) / 2
			rSize = 1
		}
	}
	if rSize != 1 {
		dups += rSize * (rSize - 1) / 2
	}
	// Dprint("%v", hashes)
	Printf("%d", dups)
}

package main

// http://codeforces.com/problemset/problem/154/C

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

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

	mtable [1000000]int64
	pri    = int64(15932464337171)
)

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Printf(format+"\n", a...)
	}
}

func main() {
	var n, m int64
	Scanf("%d %d\n", &n, &m)
	defer writer.Flush()

	// init multipl. table
	mtable[0] = 1
	for i := 1; i < 1000000; i++ {
		mtable[i] = (mtable[i-1] * 3) % pri
	}

	hashes := make([]int64, n) // hashes[i] is hash of ith
	for i := int64(0); i < m; i++ {
		hashes[i] = mtable[i]
	}
	for i := int64(0); i < m; i++ {
		var v, u int64
		Scanf("%d %d\n", &v, &u)
		v--
		u--
		hashes[v] += mtable[u]
		hashes[v] %= pri
		hashes[u] += mtable[v]
		hashes[u] %= pri
	}

	sort.Slice(hashes, func(i, j int) bool {
		return hashes[i] < hashes[j]
	})

	dups := 0
	fstDup := true
	for i := 1; i < len(hashes); i++ {
		if hashes[i] == hashes[i-1] {
			// Found duplicate.
			if fstDup {
				dups++
				fstDup = false
			}
			dups++
		} else {
			fstDup = true
		}
	}
	Dprint("%v", hashes)
	Printf("%d", dups)
}