package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

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

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	n := readi()
	s := make([][]byte, n)
	for i := range s {
		s[i] = readb()
	}

	c := make([]int, 26)
	for i := range s {
		j := int(s[i][0] - 'a')
		c[j]++
	}

	var ans int
	for _, v := range c {
		x := v / 2
		y := v - x
		ans += x * (x - 1) / 2
		ans += y * (y - 1) / 2
	}
	println(ans)

}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	cnt := make(map[uint8]int)
	for i := 0; i < n; i++ {
		scanner.Scan()
		t := scanner.Text()
		cnt[t[0]]++
	}
	ans := 0
	for _, value := range cnt {
		lhs := value / 2
		rhs := value - lhs
		ans += lhs * (lhs - 1) / 2
		ans += rhs * (rhs - 1) / 2
	}
	fmt.Print(ans)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, 26)

	for i := 0; i < n; i++ {
		s := ""
		fmt.Fscanf(in, "%s\n", &s)
		a[int(s[0])-'a']++
	}
	ans := 0
	for i := 0; i < 26; i++ {
		q1 := a[i] / 2
		q2 := a[i] - q1
		if q1 >= 2 {
			ans += (q1 * (q1 - 1)) / 2
		}
		if q2 >= 2 {
			ans += (q2 * (q2 - 1)) / 2
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
	return
}
func minstep(a, b byte) int {
	return min(int(a-b+26)%26, int(b-a+26)%26)
}

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

package main

import "fmt"

func main() {
    var n int
    var name string
    fmt.Scanln(&n)
    m := make(map[rune]int)
    for i := 0; i < n; i ++ {
        fmt.Scanln(&name)
        m[[]rune(name)[0]] ++
    }

    sum := 0
    for _, v := range m {
        if v == 1 || v == 2 {
            continue
        }

        if v == 3 {
            sum += 1
            continue
        }

        x := v / 2
        y := v - x
        sum += (x - 1) * x / 2
        sum += (y - 1) * y / 2
    }
    fmt.Println(sum)
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

func ReadInt() int {
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return n
}

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

func main() {
	scanner.Split(bufio.ScanWords)

	n := ReadInt()

	arr := make([]int, 26)
	for i := 0; i < n; i++ {
		str := ReadStr()
		arr[int(str[0]-'a')]++
	}

	ct := 0
	for _, c := range arr {
		if c > 0 {
			a := c / 2
			b := c/2 + c%2
			ct += a * (a - 1) / 2
			ct += b * (b - 1) / 2
		}
	}

	fmt.Println(ct)
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var s string
	mp := make(map[byte]int)

	fmt.Scanf("%d\n", &t)

	for ; t > 0; t-- {
		fmt.Scanf("%s\n", &s)
		mp[s[0]]++
	}

	cnt := 0

	for _, v := range mp {
		tmp := (v + 1) / 2
		cnt += (tmp * (tmp - 1)) / 2
		tmp = v / 2
		cnt += (tmp * (tmp - 1)) / 2
	}

	fmt.Print(cnt)
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var t, x int
	var starts [28]int
	for i := 0; i < 28; i++ {
		starts[i] = 0
	}
	var temp string
	fmt.Scanln(&temp)
	t, _ = strconv.Atoi(temp)
	for i := 0; i < t; i++ {
		fmt.Scanln(&temp)
		starts[temp[0]-'a']++
	}
	for i := 0; i < 28; i++ {
		pairs0 := starts[i] / 2
		pairs1 := (starts[i] + 1) / 2
		x += pairs0*(pairs0-1)/2 + pairs1*(pairs1-1)/2
	}
	fmt.Println(x)
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt() int  {
	scanner.Scan()
	n,err := strconv.Atoi(scanner.Text())
	if err != nil{
		panic(err)
	}
	return n

}
func main()  {
	n := ReadInt()
	a := make([]int,26)
	for i := 0; i < n ;i++{
		s := ReadStr()
		a[s[0] - 'a'] ++
	}
	var ans int
	for i := 0; i < 26 ;i ++{
		temp := a[i] / 2
		ans += (temp - 1) * (temp) / 2
		temp += a[i] % 2
		ans += (temp - 1) * temp / 2
	}
	fmt.Println(ans)

}

package main

import (
	"fmt"
	"math"
)

func f(n int) (int){
	return n*(n-1)/2;
}

func main(){
	var n int
	var a[1000] string
	fmt.Scanf("%d\n",&n)
	for i:=0;i<n;i++{
		fmt.Scanln(&a[i])
	}

	var cnt[26] int
	for i:=0;i<n;i++ {
		cnt[int(a[i][0])-int('a')]++
	}

	var res int
	for i:=0;i<26;i++{
		res += f(cnt[i]/2) + f(int(math.Ceil(float64(cnt[i])/2)))
	}

	fmt.Println(res)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt() int  {
	scanner.Scan()
	n,err := strconv.Atoi(scanner.Text())
	if err != nil{
		panic(err)
	}
	return n
}
func main()  {
		n := ReadInt()
		cnt := make([]int,30,30)
		for i := 0 ; i < n ;i ++{
			s := ReadStr();
			cnt[s[0] - 'a']++
		}
		var  ans int = 0
		for i := 0; i < 30 ;i ++{
			l := cnt[i] / 2;
			r := (cnt[i] - l)

		ans += ((l - 1) * l / 2)
		ans += ((r - 1) * r / 2)
		}

		fmt.Println(ans)

}

package main

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

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

	var n int
	fmt.Fscanf(in, "%d\n", &n)
	sts := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%s\n", &sts[i])
	}

	cnt := map[byte]int{}
	for i := 0; i < n; i++ {
		if _, ok := cnt[sts[i][0]]; !ok {
			cnt[sts[i][0]] = 0
		}
		cnt[sts[i][0]]++
	}

	var ans int
	for _, v := range cnt {
		ans += Combination(v/2, 2) + Combination((v-1)/2+1, 2)
	}

	fmt.Println(ans)
}

func Combination(n, r int) int {
	if n < r {
		return 0
	}
	if r == 0 || n == r {
		return 1
	}
	if r == 1 {
		return n
	}
	return Combination(n-1, r-1) + Combination(n-1, r)
}

package main

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

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

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

func main() {
        var n int
        var s string
        mp := make(map[uint8]int)
        scanf("%d\n", &n)
        for i:=0; i < n; i ++ {
                scanf("%s\n", &s)
                mp[s[0]]++
        }
        res := 0
        for _, v := range mp {
                first := v / 2
                second := v - first
                res += first * (first-1) / 2
                res += second * (second-1)/2
        }
        fmt.Println(res)
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var s string
	mp := make(map[byte]int)

	fmt.Scanf("%d\n", &t)

	for ; t > 0; t-- {
		fmt.Scanf("%s", &s)
		mp[s[0]]++
	}

	cnt := 0

	for _, v := range mp {
		tmp := (v + 1) / 2
		cnt += (tmp * (tmp - 1)) / 2

		tmp = v / 2
		cnt += (tmp * (tmp - 1)) / 2
	}

	fmt.Print(cnt)
}


package main

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

func minElemIndex(n int, a []int) int {
	minElem := a[0]
	minElemIndex := 0
	for i := 1; i < n; i++ {
		if a[i] < minElem {
			minElem = a[i]
			minElemIndex = i
		}
	}
	return minElemIndex
}

func Solve(n int, a []int) []int {
	for i := 0; i < n; i++ {
		if a[i] >= 0 {
			a[i] = -a[i] - 1
		}
	}
	minElemIndex := minElemIndex(n, a)
	if n%2 == 1 {
		a[minElemIndex] = -a[minElemIndex] - 1
	}
	return a
}

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

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

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

package main

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

func Solve(n int, a []int) []int {
	if n%2 == 0 {
		for i := 0; i < n; i++ {
			if a[i] >= 0 {
				a[i] = -a[i] - 1
			}
		}
		return a
	}
	negativeOneCount := 0
	maxPositive := 0
	maxPositiveIndex := 0
	for i := 0; i < n; i++ {
		if a[i] == -1 || a[i] == 0 {
			a[i] = -1
			negativeOneCount += 1
		} else if a[i] < 0 {
			a[i] = -a[i] - 1
		}
		if a[i] > maxPositive {
			maxPositive = a[i]
			maxPositiveIndex = i
		}
	}
	if negativeOneCount == n {
		a[0] = 0
		return a
	}
	for i := 0; i < n; i++ {
		if a[i] > 0 && i != maxPositiveIndex {
			a[i] = -a[i] - 1
		}
	}
	return a
}

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

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

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


package main

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

func solve(isHappyBoy []bool, isHappyGirl []bool, n int, m int) string {
	lcm := findLCM(n, m)

	for k := 0; k < 2; k++ {
		for i := 0; i <= lcm; i++ {
			if isHappyBoy[i%n] {
				isHappyGirl[i%m] = true
				continue
			}
			if isHappyGirl[i%m] {
				isHappyBoy[i%n] = true
			}
		}
	}

	for i := range isHappyBoy {
		if !isHappyBoy[i] {
			return "No"
		}
	}

	for i := range isHappyGirl {
		if !isHappyGirl[i] {
			return "No"
		}
	}

	return "Yes"
}

func findLCM(n int, m int) int {
	return n * m / findGCD(n, m)
}

func findGCD(n int, m int) int {
	remain, a, b := 0, m, n
	if n > m {
		a = n
		b = m
	}

	for b != 0 {
		remain = a % b
		a = b
		b = remain
	}

	return a
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m, b, g, id int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	isHappyBoy := make([]bool, n)
	isHappyGirl := make([]bool, m)

	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		fmt.Fscanf(r, "%d", &id)
		isHappyBoy[id] = true
	}
	fmt.Fscanln(r)

	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		fmt.Fscanf(r, "%d", &id)
		isHappyGirl[id] = true

	}
	fmt.Fscanln(r)

	fmt.Fprintf(os.Stdout, "%s\n", solve(isHappyBoy, isHappyGirl, n, m))
}

package main

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

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

	readint := func() int {
		sc.Scan()
		x, _ := strconv.Atoi(string(sc.Bytes()))
		return x
	}

	n := readint()
	m := readint()
	b := readint()

	B := make([]bool, n)
	G := make([]bool, m)

	for i := 0; i < b; i++ {
		B[readint()] = true
	}

	g := readint()
	for i := 0; i < g; i++ {
		G[readint()] = true
	}

	happy := b + g
	for i := 0; i < 1e6+6; i++ {
		if B[i%n] != G[i%m] {
			happy++
			if happy == n+m {
				fmt.Println("Yes")
				return
			}
			B[i%n] = true
			G[i%m] = true
		}
	}

	fmt.Println("No")
}

package main

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

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

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

	n, m := nextInt(), nextInt()
	b := nextInt()
	x := make([]bool, n)

	for i := 0; i < b; i++ {
		x[nextInt()] = true
	}

	g := nextInt()
	y := make([]bool, m)

	for i := 0; i < g; i++ {
		y[nextInt()] = true
	}

	i := 0

	for {
		// println(i, i%n, i%m)
		// println(x, y)

		if x[i%n] {
			y[i%m] = true
		}

		if y[i%m] {
			x[i%n] = true
		}

		if i > 0 && i%n == 0 && i%m == 0 {
			if notHappy(x) && notHappy(y) {
				println("No")
				return
			} else {
				println("Yes")
				return
			}

		}

		i++
	}
}

func notHappy(a []bool) bool {
	for i := 0; i < len(a); i++ {
		if !a[i] {
			return true
		}
	}

	return false
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

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

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

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

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

package main

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

var scanner *bufio.Scanner

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

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

  n, m := getI(), getI()
  boys := make([]bool, n)
  k := getI()
  count := k
  for i := 0; i < k; i++ {
    boys[getI()] = true
  }
  girls := make([]bool, m)
  k = getI()
  count += k
  for i := 0; i < k; i++ {
    girls[getI()] = true
  }
  for i := 0; i < 4*n*m; i++ {
    if boys[i%n] && !girls[i%m] {
      girls[i%m] = true
      count++
    } else if !boys[i%n] && girls[i%m] {
      boys[i%n] = true
      count++
    }
  }
  if count == n+m {
    writer.WriteString("Yes\n")
  } else {
    writer.WriteString("No\n")
  }
}

//https://codeforces.com/problemset/problem/516/E
//https://codeforces.com/problemset/problem/515/B
package main

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

func solve(boys []int, girls []int, n int, m int) string {
	d := findD(n, m)

	for i := 0; i < d*2; i++ {
		if girls[i%m] == 1 || boys[i%n] == 1 {
			girls[i%m] = 1
			boys[i%n] = 1
		}
	}

	for i := range boys {
		if boys[i] == 0 {
			return "No"

		}
	}

	for i := range girls {
		if girls[i] == 0 {
			return "No"
		}
	}

	return "Yes"
}

func findD(n int, m int) int {
	b, s := findMax(n, m)

	if b%s == 0 {
		return b
	}

	return b * s
}

func findMax(n int, m int) (int, int) {
	if n > m {
		return n, m
	}

	return m, n
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]int, m)
	boys := make([]int, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = 1
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = 1
	}

	fmt.Println(solve(boys, girls, n, m))
}

package main

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

func solve(boys []bool, girls []bool, n int, m int) string {
	cm := findLCM(n, m)

	//loop 2 times cuz some spots may not be update in first time yet(test case provided below)
	for i := 0; i < cm*2; i++ {
		if girls[i%m] || boys[i%n] {
			girls[i%m] = true
			boys[i%n] = true
		}
	}

	for i := range boys {
		if !boys[i] {
			return "No"
		}
	}

	for i := range girls {
		if !girls[i] {
			return "No"
		}
	}

	return "Yes"
}

func findLCM(n int, m int) int {
	gcd := findGCD(n, m)
	return n * m / gcd
}

func findGCD(n int, m int) int {
	for m > 0 {
		mod := n % m
		n = m
		m = mod
	}

	return n
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]bool, m)
	boys := make([]bool, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = true
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = true
	}

	fmt.Println(solve(boys, girls, n, m))
}

//https://codeforces.com/problemset/problem/516/E
//https://codeforces.com/problemset/problem/515/B
package main

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

func solve(boys []bool, girls []bool, n int, m int) string {
	cm := findLCM(n, m)

	//loop 2 times cuz some spot may not be update in first time yet
	for i := 0; i < cm*2; i++ {
		if girls[i%m] || boys[i%n] {
			girls[i%m] = true
			boys[i%n] = true
		}
	}

	for i := range boys {
		if !boys[i] {
			return "No"
		}
	}

	for i := range girls {
		if !girls[i] {
			return "No"
		}
	}

	return "Yes"
}

func findLCM(n int, m int) int {
	big, small := findMax(n, m)

	if big%small == 0 {
		return big
	}

	return big * small
}

func findMax(n int, m int) (int, int) {
	if n > m {
		return n, m
	}

	return m, n
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]bool, m)
	boys := make([]bool, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = true
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = true
	}

	fmt.Println(solve(boys, girls, n, m))
}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []Pair) []Pair {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i].first > arr[right].first {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

func sort2(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort2(arr[:left])
	sort2(arr[left+1:])
	return arr
}

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

func solution(reader io.Reader, writer io.Writer) {
	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	var k, v int
	b := make(map[int]bool)
	g := make(map[int]bool)

	fmt.Fscanf(reader, "%d", &k)
	for i := 0; i < k; i++ {
		fmt.Fscanf(reader, "%d", &v)
		b[v] = true
	}
	fmt.Fscanf(reader, "\n")

	fmt.Fscanf(reader, "%d", &k)
	for i := 0; i < k; i++ {
		fmt.Fscanf(reader, "%d", &v)
		g[v] = true
	}
	fmt.Fscanf(reader, "\n")
	for i := 0; i < 10000; i++ {
		if !(!g[i % m] && !b[i % n]) {
			g[i % m] = true
			b[i % n] = true
		}
	}
	if len(b) != n || len(g) != m {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

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

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

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

	n, m := nextInt(), nextInt()
	b := nextInt()
	x := make([]int, n)

	for i := 0; i < b; i++ {
		x[nextInt()] = 1
	}

	g := nextInt()
	y := make([]int, m)

	for i := 0; i < g; i++ {
		y[nextInt()] = 1
	}

	if b == 0 && g == 0 {
		println("No")
		return
	}

	if n > m {
		n, m = m, n
		x, y = y, x
	}

	if m%n == 0 {
		for i := range x {
			if x[i] == 0 && y[i] == 0 {
				println("No")
				return
			}
		}
	}

	println("Yes")
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

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

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

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

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

package main

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

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

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

	n, m := nextInt(), nextInt()
	b := nextInt()
	x := make([]bool, n)

	for i := 0; i < b; i++ {
		x[nextInt()] = true
	}

	g := nextInt()
	y := make([]bool, m)

	for i := 0; i < g; i++ {
		y[nextInt()] = true
	}

	if b == 0 && g == 0 {
		println("No")
		return
	}

	if n > m {
		n, m = m, n
		x, y = y, x
	}

	if m%n == 0 {
		for i := range y {
			if !x[i%n] && !y[i] {
				println("No")
				return
			}
		}
	}

	if (m%2==0 && n%2==0) || (m%2==1 && n%2==1) {
		if (!haveHappy(x, 0) && !haveHappy(y, 0)) || (!haveHappy(x, 1) && !haveHappy(y, 1)) {
			println("No")
			return
		}
	}

	println("Yes")
}

func haveHappy(a []bool, i int) bool {
	for ; i < len(a); i += 2 {
		if a[i] {
			return true
		}
	}

	return false
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

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

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

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

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

package main

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

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

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

	n, m := nextInt(), nextInt()
	b := nextInt()
	x := make([]int, n)

	for i := 0; i < b; i++ {
		x[nextInt()] = 1
	}

	g := nextInt()
	y := make([]int, m)

	for i := 0; i < g; i++ {
		y[nextInt()] = 1
	}

	if b == 0 && g == 0 {
		println("No")
		return
	}

	if n > m {
		n, m = m, n
		x, y = y, x
	}

	if m%n == 0 {
		for i := range y {
			if x[i%n] == 0 && y[i] == 0 {
				println("No")
				return
			}
		}
	}

	println("Yes")
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

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

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

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

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

//https://codeforces.com/problemset/problem/516/E
//https://codeforces.com/problemset/problem/515/B
package main

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

func solve(boys []int, girls []int, n int, m int) string {
	d := findD(n, m)

	for i := 0; i < d*2; i++ {
		if girls[i%m] == 1 || boys[i%n] == 1 {
			girls[i%m] = 1
			boys[i%n] = 1
		}
	}

	for i := range boys {
		if boys[i] == 0 {
			fmt.Println("b")

			return "No"

		}
	}

	for i := range girls {
		if girls[i] == 0 {
			fmt.Println("q")
			return "No"
		}
	}

	return "Yes"
}

func findD(n int, m int) int {
	b, s := findMax(n, m)

	if b%s == 0 {
		return b
	}

	return b * s
}

func findMax(n int, m int) (int, int) {
	if n > m {
		return n, m
	}

	return m, n
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]int, m)
	boys := make([]int, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = 1
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = 1
	}

	fmt.Println(solve(boys, girls, n, m))
}

//https://codeforces.com/problemset/problem/516/E
//https://codeforces.com/problemset/problem/515/B
package main

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

func solve(boys []int, girls []int, n int, m int) string {
	d := findD(n, m)

	for i := 0; i <= d*2; i++ {
		if girls[i%m] == 1 || boys[i%n] == 1 {
			girls[i%m] = 1
			boys[i%n] = 1
		}
	}

	for i := range boys {
		if boys[i] == 0 {
			fmt.Println("b")

			return "No"

		}
	}

	for i := range girls {
		if girls[i] == 0 {
			fmt.Println("q")
			return "No"
		}
	}

	return "Yes"
}

func findD(n int, m int) int {
	b, s := findMax(n, m)

	if b%s == 0 {
		return b
	}

	return b * s
}

func findMax(n int, m int) (int, int) {
	if n > m {
		return n, m
	}

	return m, n
}
func main() {
	r := bufio.NewReader(strings.NewReader(`100 50
	30 50 54 7 8 59 60 61 62 63 64 15 16 18 19 20 22 73 27 79 83 86 87 89 42 93 94 45 46 97 98
	20 1 2 3 5 6 17 21 24 25 26 28 30 31 32 34 35 38 40 41 49`))
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]int, m)
	boys := make([]int, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = 1
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = 1
	}

	fmt.Println(solve(boys, girls, n, m))
	fmt.Println(boys)
}

//https://codeforces.com/problemset/problem/516/E
//https://codeforces.com/problemset/problem/515/B
package main

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

func solve(boys []int, girls []int, n int, m int) string {
	d := findD(n, m)

	for i := 0; i < d; i++ {
		if girls[i%m] == 1 || boys[i%n] == 1 {
			girls[i%m] = 1
			boys[i%n] = 1
		}
	}

	for i := range boys {
		if boys[i] == 0 {
			return "No"
		}
	}

	for i := range girls {
		if girls[i] == 0 {
			return "No"
		}
	}

	return "Yes"
}

func findD(n int, m int) int {
	b, s := findMax(n, m)

	if b%s == 0 {
		return b
	}

	return b * s
}

func findMax(n int, m int) (int, int) {
	if n > m {
		return n, m
	}

	return m, n
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)
	girls := make([]int, m)
	boys := make([]int, n)

	var b int
	fmt.Fscanf(r, "%d", &b)
	for i := 0; i < b; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		boys[id] = 1
	}
	fmt.Fscanln(r)

	var g int
	fmt.Fscanf(r, "%d", &g)
	for i := 0; i < g; i++ {
		var id int
		fmt.Fscanf(r, "%d", &id)
		girls[id] = 1
	}

	fmt.Println(solve(boys, girls, n, m))
}


package main

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

type dormitory struct{
	firstRoom int64
	lastRoom  int64
}

func main() {

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

	var count, letters int
	var room int64

	fmt.Fscan(in, &count, &letters)

	dormitories := []dormitory{}

	for i := 0; i < count; i++ {
		var countRoom int64
		fmt.Fscan(in, &countRoom)

		each := dormitory{firstRoom: room + 1, lastRoom: countRoom + room}
		dormitories = append(dormitories, each)

		room += countRoom
	}

	for i := 0; i < letters; i++ {
		var letter int64
		fmt.Fscan(in, &letter)

		left, right := 0, count - 1

		for left <= right {
			middle := (left + right) / 2
			if dormitories[middle].firstRoom > letter {
				right = middle - 1
			} else if dormitories[middle].lastRoom < letter {
				left = middle + 1
			}
			if dormitories[middle].firstRoom <= letter && dormitories[middle].lastRoom >= letter {
				left = middle
				break
			}
		}

		fmt.Printf("%d %d\n", left + 1, letter + 1 - dormitories[left].firstRoom)
	}
}

package main

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

type obsh struct {
	Num  int
	Self  uint64
	Sum uint64
}

func main() {
	var line string
	var n int
	var tmp uint64
	var summ uint64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	obshagi := make([]obsh, n)
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseUint(v, 10, 64)
		summ += tmp
		obshagi[i] = obsh{i+1, tmp, summ}
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseUint(v, 10, 64)
		need := obshagi[binarySearch(tmp, &obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10),
			strconv.FormatUint(need.Self-(need.Sum-tmp), 10)}, " "))
		writer.WriteByte('\n')
		writer.Flush()
	}
}

func binarySearch(needle uint64, haystack *[]obsh) int64 {
	var low int64 = 0
	var high = int64(len(*haystack) - 1)
	for low <= high {
		median := (low + high) / 2
		if (*haystack)[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

type obsh struct {
	Num  int
	Self int64
	Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 64)
		summ += tmp
		obshagi[i].Self = tmp
		obshagi[i].Sum = summ
		obshagi[i].Num = i + 1
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 64)
		need := obshagi[binarySearch(tmp, obshagi)]
		fmt.Println(need.Num, need.Self-(need.Sum-tmp))
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {

	var low int64 = 0
	var high = int64(len(haystack)) - 1

	for low <= high {
		median := (low + high) / 2

		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}

	return low
}

package main

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

const (
	MaxN = 200005
)

var n, m int
var a, pre [MaxN]int64

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(inBuf, "%d", &a[i])
	}
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i - 1] + a[i]
	}
	fmt.Fscanf(inBuf, "\n")

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() } ()

	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscanf(inBuf, "%d", &tmp)
		ind := sort.Search(n, func(i int) bool {
			return pre[i] >= tmp
		})
		room := int64(0)
		if ind == 0 {
			room = tmp
		} else {
			room = tmp - pre[ind - 1]
		}
		fmt.Fprintf(outBuf, "%d %d\n", ind + 1, room)
	}
}

package main

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

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

	defer out.Flush()

	var n int
	var m int

	fmt.Fscan(in, &n, &m)

	a := make([]int64, n)
	b := make([]int64, m)
	s := make([]int64, n+1)

	s[0] = 0

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

	t := 0
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &b[i])
		b[i]--
		for s[t] <= b[i] {
			t++
		}
		t--
		fmt.Fprintln(out, t+1, b[i]-s[t]+1)
		//fmt.Printf("%d %d\n", t+1, b[i]-s[t]+1)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 2048*2048), 2048*2048)
	scanner.Split(bufio.ScanWords)

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

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

	a := make([]int64, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}

	cur := int64(0)
	total := int64(0)
	for i := 0; i < m; i++ {
		scanner.Scan()
		b, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		for b > total+a[cur] {
			total += a[cur]
			cur++
		}
		fmt.Println(cur+1, b-total)
	}
}

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([]int64, n+1)
	var t int64
	a[0] = 0
	for i := 1; i <= n; i++ {
		fmt.Fscan(in, &t)
		a[i] = a[i-1]+t
	}
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &t)
		l, r := 0, n
		for l < r {
			m := (l+r)/2
			if a[m] < t {
				l = m + 1
			} else {
				r = m
			}
		}
		fmt.Fprintln(out, l, t-a[l-1])
	}
}

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([]int64, n+1)
	var t int64
	a[0] = 0
	for i := 1; i <= n; i++ {
		fmt.Fscan(in, &t)
		a[i] = a[i-1]+t
	}
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &t)
		l, r := 1, n
		for l < r-1 {
			m := (l+r)/2
			if a[m] >= t {
				r = m
			} else {
				l = m
			}
		}
		if a[l] >= t {
			r = l
		}
		fmt.Fprintln(out, r, t-a[r-1])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int64) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int64(b&15)
		}
		return
	}

	n, m := int(r()), int(r())
	s := make([]int64, n+1)
	for i := 0; i < n; i++ {
		s[i+1] = s[i] + r()
	}
	for i := 1; m > 0; m-- {
		v := r()
		for ; s[i] < v; i++ {
		}
		Fprintln(out, i, v-s[i-1])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n, m int
	var v int64
	Fscan(in, &n, &m)
	s := make([]int64, n+1)
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		s[i+1] = s[i] + v
	}
	for i:=1;m>0;m-- {
		for Fscan(in, &v);s[i]<v;i++{}
		Fprintln(out, i,v-s[i-1])
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	z := readInt64Slice(reader, 2)
	zz := readInt64Slice(reader, int(z[0]))
	zzz := readInt64Slice(reader, int(z[1]))
	fmt.Println(zz, zzz)
}

func readOneInt64(r *bufio.Reader) (n int64) {
	bytes, _ := r.ReadBytes('\n')
	n, _ = strconv.ParseInt(string(bytes[:len(bytes)-2]), 10, 64)
	return
}

func readInt64Slice(r *bufio.Reader, n int) (slice []int64) {
	var bytes []byte
	slice = make([]int64, n)
	n--
	for i:=0;i<n;i++{
		bytes, _ = r.ReadBytes(' ')
		slice[i], _ = strconv.ParseInt(string(bytes[:len(bytes)-1]), 10, 64)
	}
	slice[n] = readOneInt64(r)
	return
}

package main

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

type obsh struct {
	Num  int
	Self int64
	Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		summ += tmp
		obshagi[i].Self = tmp
		obshagi[i].Sum = summ
		obshagi[i].Num = i + 1
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10), strconv.FormatInt(need.Self-(need.Sum-tmp), 10), "\n"}, " "))
	}
	writer.Flush()
}

func binarySearch(needle int64, haystack []obsh) int64 {
	var low int64 = 0
	var high = int64(len(haystack)) - 1
	for low <= high {
		median := (low + high) / 2
		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

type obsh struct {
	Num  int
	Self  uint64
	Sum uint64
}

func main() {
	var line string
	var n int
	var tmp uint64
	var summ uint64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	obshagi := make([]obsh, n)
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseUint(v, 10, 0)
		summ = summ + tmp
		obshagi[i] = obsh{i+1, tmp, summ}
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseUint(v, 10, 0)
		var a int
		if tmp<obshagi[0].Sum{
			a = 0
		} else {
			for i := 1; i < len(obshagi); i++ {
				if tmp>obshagi[i-1].Sum && tmp<=obshagi[i].Sum {
					a = i
					break
				}
			}
		}
		need := obshagi[a]
		writer.WriteString(strings.Join([]string{strconv.Itoa(need.Num),
		strconv.FormatUint(need.Self-(need.Sum-tmp), 10)}, " "))
		writer.WriteByte('\n')
		writer.Flush()
	}
}

package main

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

type obsh struct {
	Num  int
	Self, Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		summ += tmp
		obshagi[i] = obsh{i+1, tmp, summ}
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10),
		strconv.FormatInt(need.Self-(need.Sum-tmp), 10)}, " "))
		writer.WriteByte('\n')
		writer.Flush()
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {
	var low int64 = 0
	var high = int64(len(haystack)) - 1
	for low <= high {
		median := (low + high) / 2
		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

type obsh struct {
	Num  int
	Self int64
	Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		summ += tmp
		obshagi[i].Self = tmp
		obshagi[i].Sum = summ
		obshagi[i].Num = i + 1
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		fmt.Println(need.Num, need.Self-(need.Sum-tmp))
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {

	var low int64 = 0
	var high = int64(len(haystack)) - 1

	for low <= high {
		median := (low + high) / 2

		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}

	return low
}

package main

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

type obsh struct {
	Num  int
	Self  int64
	Sum uint64
}

func main() {
	var line string
	var n int
	var tmp int64
	var summ uint64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		summ += uint64(tmp)
		obshagi[i] = obsh{i+1, tmp, summ}
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10),
		strconv.FormatInt(int64(uint64(need.Self)-(need.Sum-uint64(tmp))), 10)}, " "))
		writer.WriteByte('\n')
		writer.Flush()
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {
	var low int64 = 0
	var high = int64(len(haystack)) - 1
	for low <= high {
		median := (low + high) / 2
		if haystack[median].Sum < uint64(needle) {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

type obsh struct {
	Num  int64
	Self int64
	Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		summ += tmp
		obshagi[i].Self = tmp
		obshagi[i].Sum = summ
		obshagi[i].Num = int64(i) + 1
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10),
		strconv.FormatInt(need.Self-(need.Sum-tmp), 10), "\n"}, " "))
		writer.Flush()
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {
	var low int64 = 0
	var high = int64(len(haystack)) - 1
	for low <= high {
		median := (low + high) / 2
		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

type obsh struct {
	Num  int
	Self, Sum  int64
}

func main() {
	var line string
	var n int
	var summ, tmp int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	obshagi := make([]obsh, n)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		tmp, err := strconv.ParseInt(v, 10, 0)
		if err != nil{
			fmt.Errorf("%v", err)
		}
		summ += tmp
		obshagi[i] = obsh{i+1, tmp, summ}
	}
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	for _, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 0)
		need := obshagi[binarySearch(tmp, obshagi)]
		writer.WriteString(strings.Join([]string{strconv.FormatInt(int64(need.Num), 10),
		strconv.FormatInt(need.Self-(need.Sum-tmp), 10)}, " "))
		writer.WriteByte('\n')
		writer.Flush()
	}
}

func binarySearch(needle int64, haystack []obsh) int64 {
	var low int64 = 0
	var high = int64(len(haystack)) - 1
	for low <= high {
		median := (low + high) / 2
		if haystack[median].Sum < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	return low
}

package main

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

const (
	MaxN = 200005
)

var n, m int
var a, pre [MaxN]int64

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(inBuf, "%d", &a[i])
	}
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i - 1] + a[i]
	}
	fmt.Println(pre[:n])
	fmt.Fscanf(inBuf, "\n")

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() } ()

	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscanf(inBuf, "%d", &tmp)
		ind := sort.Search(n, func(i int) bool {
			return pre[i] >= tmp
		})
		room := int64(0)
		if ind == 0 {
			room = tmp
		} else {
			room = tmp - pre[ind - 1]
		}
		fmt.Fprintf(outBuf, "%d %d\n", ind + 1, room)
	}
}

package main

import "fmt"

func main() {
	var n int
	var m int

	fmt.Scanf("%d %d", &n, &m)

	a := make([]int64, n)
	b := make([]int64, m)
	s := make([]int64, n+1)

	s[0] = 0

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

	t := 0
	for i := 0; i < m; i++ {
		fmt.Scanf("%d", &b[i])
		b[i]--
		for s[t] <= b[i] {
			t++
		}
		t--
		fmt.Printf("%d %d\n", t+1, b[i]-s[t]+1)
	}
}


package main

import (
	"fmt"
	"io/ioutil"
	"bytes"
	"os"
	"sort"
)

type Event struct {
	start, end int
}

type Events []Event

func (this Events) Len() int {
	return len(this)
}

func (this Events) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}

func (this Events) Less(i, j int) bool {
	return this[i].end < this[j].end
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	var events Events = make([]Event, 0, n)
	for i := 0;i < n;i ++ {
		var e Event
		fmt.Fscanf(reader, "%d %d\n", &e.start, &e.end)
		events = append(events, e)
	}
	sort.Sort(events)
	var minStart, ans int
	for i := n - 2;i >= 0;i -- {
		if i == n - 2 {
			minStart = events[i + 1].start
		} else if minStart > events[i + 1].start {
			minStart = events[i + 1].start
		}
		if minStart < events[i].start {
			ans ++
		}
	}
	fmt.Printf("%d", ans)
}

package main

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

var scanner *bufio.Scanner

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

type Span struct {
  Open, Close int
  Closed bool
  QueuePos int
}

type Event struct {
  Point int
  ForSpan *Span
  Opening, Closing bool
}
type Events []*Event
func (events Events) Len() int {
  return len(events)
}
func (events Events) Swap(i, j int) {
  events[i], events[j] = events[j], events[i]
}
func (events Events) Less(i, j int) bool {
  return events[i].Point < events[j].Point
}

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

  n := getI()
  spans := make([]*Span, n)
  events := make([]*Event, 2 * n)
  for i := 0; i < n; i++ {
    open, close := getI(), getI()
    spans[i] = &Span{ open, close, false, -1 }
    events[2 * i] = &Event{ open, spans[i], true, false }
    events[2 * i + 1] = &Event{ close, spans[i], false, true }
  }
  sort.Sort(Events(events))

  result := 0
  leftmost := 0
  queue := []*Span{}

  for _, event := range events {
    span := event.ForSpan
    if event.Opening {
      span.QueuePos = len(queue)
      queue = append(queue, span)
    } else {
      if queue[leftmost].Open < span.Open {
        result += 1
      }
      queue[span.QueuePos].Closed = true
      for leftmost < len(queue) && queue[leftmost].Closed {
        leftmost++
      }
    }
  }

  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

var scanner *bufio.Scanner

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

type Span struct {
  Open, Close int
}
type Spans []*Span
func (spans Spans) Len() int {
  return len(spans)
}
func (spans Spans) Swap(i, j int) {
  spans[i], spans[j] = spans[j], spans[i]
}
func (spans Spans) Less(i, j int) bool {
  return spans[i].Open < spans[j].Open
}

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

  n := getI()
  spans := make([]*Span, n)
  for i := 0; i < n; i++ {
    spans[i] = &Span{ getI(), getI() }
  }
  sort.Sort(Spans(spans))

  result := 0
  rightmost := spans[0].Close
  for i := 1; i < n; i++ {
    span := spans[i]
    if span.Close < rightmost {
      result++
    } else {
      rightmost = span.Close
    }
  }

  writer.WriteString(fmt.Sprintf("%d\n", result))
}


package main

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

func main() {

	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

	t := 0
	fmt.Fscan(f, &t)

	for t > 0 {

		x, y := 0, 0
		fmt.Fscan(f, &x, &y)
		x, y = solve(x, y)

		fmt.Fprintln(w, x, y)
		w.Flush()

		t--
	}

	// x, y := 6, 8
	// solve(x, y)
}

func solve(x, y int) (a int, b int) {

	num := x + y

	if num%2 == 0 {

		a, b = 0, num/2

		for !(a <= x && b <= y) {
			a++
			b--
		}

	} else {
		a, b = -1, -1
	}

	return
}

package main

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

var x, y int

var a []int
var b []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		a, b := solve()

		fmt.Println(a, b)
	}
}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() (int, int) {
	if (x + y) % 2 == 1  {
		return -1, -1
	}

	if x >= y {
		return (x + y) /2,  0
	}
	return 0, (x + y) /2
}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1612A
Date: 10/02/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1612/A
Problem: CF1612A
**/
func (in *CF1612A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		x, y := in.NextInt(), in.NextInt()
		if (x+y)%2 == 0 {
			div := (x + y) / 2
			a := int(math.Floor(float64(x) / 2.))
			b := int(math.Abs(float64(a) - float64(div)))
			fmt.Println(a, b)

		} else {
			fmt.Println("-1 -1")
		}
	}
}

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

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

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

	dist := func(x1, y1, x2, y2 int) int {
		return abs(x2-x1) + abs(y2-y1)
	}

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

		if (x+y)%2 != 0 {
			fmt.Fprintln(out, "-1 -1")
		} else {
			z := (x + y) / 2
			for i := 0; i <= z; i++ {
				if dist(z-i, i, x, y) == z {
					fmt.Fprintf(out, "%d %d\n", z-i, i)
					break
				}
			}
		}
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, x, y := 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &x, &y)
		if (x+y)%2 == 0 {
			o1, o2 := x%2 != 0, y%2 != 0
			if o1 && o2 {
				fmt.Fprintln(w, x>>1, (y>>1)+1)
			} else if o1 {
				fmt.Fprintln(w, x>>1, 1)
			} else if o2 {
				fmt.Fprintln(w, 1, y>>1)
			} else {
				fmt.Fprintln(w, x>>1, y>>1)
			}
		} else {
			fmt.Fprintln(w, "-1 -1")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import "fmt"

func solution(x, y int) (int, int) {
	if (x + y) % 2 == 1 { return -1, -1 }
	if x > y { return (x + y) / 2, 0 }
	return 0, (x + y) / 2
}

func main() {
	var t int
	fmt.Scanln(&t)
	var answers = make([][2]int, t)
	for i := range answers {
		var x, y int
		fmt.Scanln(&x, &y)
		answers[i][0], answers[i][1] = solution(x, y)
	}
	for _, ans := range answers {
		fmt.Println(ans[0], ans[1])
	}
}

package main

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

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

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

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

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

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

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

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

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

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

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

func DIVI(x []int) string {
	if len(x) == 1 {
		if x[0]%2 == 0 {
			return "NO"
		} else {
			return "YES"

		}
	} else {
		q := len(x)
		if DIVI(x[:q-1]) == "YES" {
			b := 0
			for j := 2; j < q+2; j++ {
				if x[q-1]%j != 0 {
					b = 1
					break
				}
			}
			if b == 1 {
				return "YES"
			} else {
				return "NO"

			}
		} else {
			return "NO"
		}
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {

		var x, y int
		fmt.Fscan(input, &x, &y)
		if (x+y)%2 == 1 {
			fmt.Println(-1)
			fmt.Println(-1)

		} else {
			if x%2 == 0 {
				fmt.Println(x / 2)
				fmt.Println(y / 2)
			} else {
				fmt.Println(x / 2)
				fmt.Println((y / 2) + 1)
			}
		}
	}
}

package main

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

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

func solve(x, y int) string {
	if (x+y)%2 == 1 {
		return "-1 -1"
	}
	h := (x + y) / 2
	if x > y {
		return fmt.Sprintf("%d %d", h, 0)
	} else {
		return fmt.Sprintf("%d %d", 0, h)
	}
}

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

package main
import."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var T, x, y int
	for Scan(&T); T > 0; T-- {
		Scan(&x, &y)
		if x&1 != y&1 {
			Println(-1, -1)
		} else {
			Println((x+1)/2, y/2)
		}
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)

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

func d(x, y, x1, y1 int) int {
	return abs(x,x1) + abs(y,y1)
}

func solve(){
	var x, y int
	fmt.Fscan(r, &x, &y)

	for cx := 0; cx <= 50; cx++ {
		for cy := 0; cy <= 50; cy++ {
			if d(0, 0, cx, cy) == d(cx, cy, x, y) {
				fmt.Println(cx, cy)
				return
			}
		}
	}

	fmt.Println(-1, -1)
}

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

package main

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

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

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

func solve() {
    var x, y int
    fmt.Fscan(input, &x, &y)
    if (x + y) % 2 == 1 {
        fmt.Fprintln(output, -1, -1)
        return
    }
    cx, cy := x / 2, y / 2
    if cx + cy != (x + y) /2 {cx++}

    fmt.Fprintln(output, cx, cy)
}

package main

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

func abs(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func main() {
	r := bufio.NewReader(os.Stdin)

	n := mustReadInt(r)
	for i := int64(0); i < n; i++ {
		nums := mustReadNNumbs(r, 3)
		n1, n2 := nums[0], nums[1]
		if (n1+n2)%2 == 1 {
			fmt.Println("-1 -1")
		} else {
			if n1%2 == 0 && n2%2 == 0 {
				fmt.Printf("%d %d\n", abs(n1/2), abs(n2/2))
			} else {
				dAB := n1 + n2
				if dAB/2 <= n1 {
					fmt.Printf("%d %d\n", abs(dAB/2), 0)
				} else {
					fmt.Printf("%d %d\n", n1, abs(dAB/2-n1))
				}
			}
		}
	}
}

func mustReadNNumbs(r *bufio.Reader, n int64) []int64 {
	nums := make([]int64, n)
	var err error
	for i, s := range strings.Split(mustReadLine(r), " ") {
		nums[i], err = strconv.ParseInt(s, 10, 64)
		checkError(err)
	}
	return nums
}

func mustReadInt(r *bufio.Reader) int64 {
	numb, err := strconv.ParseInt(mustReadLine(r), 10, 64)
	checkError(err)
	return numb
}

func mustReadLine(r *bufio.Reader) string {
	s, _, err := r.ReadLine()
	checkError(err)
	return string(s)
}

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

package main

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

func main() {

	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

	t := 0
	fmt.Fscan(f, &t)

	for t > 0 {

		x, y := 0, 0
		fmt.Fscan(f, &x, &y)
		x, y = solve(x, y)

		fmt.Fprintln(w, x, y)
		w.Flush()

		t--
	}

	// x, y := 6, 8
	// solve(x, y)
}

func solve(x, y int) (a int, b int) {

	num := x + y

	if num%2 == 0 {
		num /= 2
		a, b = 0, num
	} else {
		a, b = -1, -1
	}

	return
}

package main

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

var x, y int

var a []int
var b []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		a, b := solve()

		fmt.Println(a, b)
	}
}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() (int, int) {
	if (x + y) % 2 == 1 {
		return -1, -1
	}

	return 0, (x + y) /2
}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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


package main

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

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

func main() {
	defer out.Flush()

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var n int
		var x int64
		fmt.Fscan(in, &n, &x)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Ints(a)

		extra := 0
		i, j := 0, 1
		for i < n {
			xai := x * int64(a[i])
			if j < n && xai == int64(a[j]) {
				a[j] = -1
				i++
				j++
				continue
			}
			if j < n && xai > int64(a[j]) {
				j++
				continue
			}
			if a[i] == -1 {
				i++
				continue
			}
			extra++
			i++
		}
		fmt.Fprintln(out, extra)
	}
}

package main

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

/*
2
6 2
1 6 5 8 3 4
6 2
1 4 8 8 8 16
---
2 = cnt(2, 10)
2 = cnt(2, 16)
======
1
6 3
1 3 3 3 3 3
---
4
=======
1
4 1000000
1 1000000 1000000 1000001
---
2
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, x int64
	scanf("%d %d\n", &n, &x)

	nums := make([]int, n)
	numToCnt := make(map[int]int)

	for i := range nums {
		scanf("%d", &nums[i])

		numToCnt[nums[i]]++
	}
	scanf("\n")

	sort.Ints(nums)

	cnt := 0

	for _, lft := range nums {
		_, ok := numToCnt[lft]
		if !ok {
			continue
		}

		product := int64(lft) * x
		if product <= 1e9 {
			rgt := int(product)

			if _, ok := numToCnt[rgt]; ok {
				numToCnt[lft]--
				if numToCnt[lft] == 0 {
					delete(numToCnt, lft)
				}

				numToCnt[rgt]--
				if numToCnt[rgt] == 0 {
					delete(numToCnt, rgt)
				}
			} else {
				cnt++

				numToCnt[lft]--
				if numToCnt[lft] == 0 {
					delete(numToCnt, lft)
				}
			}
		} else {
			cnt++

			numToCnt[lft]--
			if numToCnt[lft] == 0 {
				delete(numToCnt, lft)
			}
		}
	}

	fmt.Fprintln(writer, cnt)
}

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

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

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int64) int64 {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) (max, idx int) {
	for i, num := range nums {
		if num > nums[idx] {
			idx = i
		}
	}

	return nums[idx], idx
}

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

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

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

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

	return true
}

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

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

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

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

package main

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

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

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

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		sort.Slice(arr, func(i, j int) bool {
			return arr[i] < arr[j]
		})
		m := make([]bool, n)
		c := n
		p := 1
		for i := 0; i < n; i++ {
			if m[i] {
				continue
			}

			for p < n && arr[p] <= arr[i]*x {
				if !m[p] && arr[p] == arr[i]*x {
					c -= 2
					m[p] = true
					break
				}
				p++
			}
		}
		fmt.Fprintln(out, c)
	}
}

package main

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

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

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

	c := 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		n, x := uint64(0), uint64(0)
		fmt.Fscan(in, &n, &x)
		arr := make([]uint64, n)
		mp := make(map[uint64]int)
		for i := uint64(0); i < n; i++ {
			fmt.Fscan(in, &arr[i])
			mp[arr[i]]++
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] > arr[j]
		})
		ans := 0
		for _, v := range arr {
			if mp[v] <= 0 {
				continue
			}
			if v%x != 0 {
				ans++
				mp[v]--
			} else if mp[v/x] <= 0 {
				ans++
				mp[v]--
			} else {
				mp[v]--
				mp[v/x]--
			}
		}
		fmt.Fprintln(out, ans)
	}
}

//nolint
package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

//}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

func Solve() {
	var n, tp, x int
	scan(&n, &x)
	count := make(map[int]int)
	for i := 1; i <= n; i++ {
		scan(&tp)
		count[tp]++
	}
	for _, k := range sortedKey(count) {
		if int64(k)*int64(x) > 1000_000_000 {
			continue
		}
		m := min(count[k*x], count[k])
		count[k*x] -= m
		count[k] -= m
	}
	sum := 0
	for _, v := range count {
		sum += v
	}
	fmt.Println(sum)
}

func sortedKey(m map[int]int) []int {
	sortedKey := make([]int, 0, len(m))
	for k := range m {
		sortedKey = append(sortedKey, k)
	}
	sort.Ints(sortedKey)
	return sortedKey
}

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

package main

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

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

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		sort.Ints(arr)
		m := make([]bool, n)
		c := n
		p := 1
		for i := 0; i < n; i++ {
			if m[i] {
				continue
			}

			for p < n && arr[p] <= arr[i]*x {
				if !m[p] && arr[p] == arr[i]*x {
					c -= 2
					m[p] = true
					break
				}
				p++
			}
		}
		fmt.Fprintln(out, c)
	}
}

package main

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

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

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

		m := make(map[int64]int)
		var c int
		for i := 0; i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			if x == 1 {
				if m[v] > 0 {
					m[v]--
					c--
				} else {
					m[v]++
					c++
				}
			} else {
				if m[v/x] > 0 {
					m[v/x]--
					c--
				} else if m[v*x] > 0 {
					m[v*x]--
					c--
				} else {
					m[v]++
					c++
				}
			}
		}

		fmt.Fprintln(out, c)
	}
}

package main

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

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

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

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

		m := make(map[int64]int64)
		for i := 0; i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)
			m[v]++
		}

		c := n
		for k, v := range m {
			if m[k/x] > 0 {
				d := min(v, m[k/x])
				c -= int(d * 2)
				v -= d
				m[k/x] -= d
			}

			if v > 0 && m[k*x] > 0 {
				d := min(v, m[k*x])
				c -= int(d * 2)
				v -= d
				m[k*x] -= d
			}

			m[k] = v
		}
		fmt.Fprintln(out, c)
	}
}

package main

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

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

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

		m := make(map[int64]int)
		var c int
		for i := 0; i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			if m[v/x] > 0 {
				m[v/x]--
				c--
			} else if m[v*x] > 0 {
				m[v*x]--
				c--
			} else {
				m[v]++
				c++
			}
		}

		fmt.Fprintln(out, c)
	}
}

package main

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

/*
2
6 2
1 6 5 8 3 4
6 2
1 4 8 8 8 16
---
2 = cnt(2, 10)
2 = cnt(2, 16)
======
1
6 3
1 3 3 3 3 3
---
4
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, x int64
	scanf("%d %d\n", &n, &x)

	nums := make([]int, n)
	numToCnt := make(map[int]int)

	for i := range nums {
		scanf("%d", &nums[i])

		numToCnt[nums[i]]++
	}
	scanf("\n")

	sort.Ints(nums)

	cnt := 0

	for _, lft := range nums {
		_, ok := numToCnt[lft]
		if !ok {
			continue
		}

		product := int64(lft) * x
		if product <= 1e9 {
			rgt := int(product)

			if _, ok := numToCnt[rgt]; ok {
				numToCnt[lft]--
				if numToCnt[lft] == 0 {
					delete(numToCnt, lft)
				}

				numToCnt[rgt]--
				if numToCnt[rgt] == 0 {
					delete(numToCnt, rgt)
				}
			} else {
				cnt++

				numToCnt[lft]--
				if numToCnt[lft] == 0 {
					delete(numToCnt, lft)
				}
			}
		} else {
			cnt++
		}
	}

	fmt.Fprintln(writer, cnt)
}

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

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

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int64) int64 {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) (max, idx int) {
	for i, num := range nums {
		if num > nums[idx] {
			idx = i
		}
	}

	return nums[idx], idx
}

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

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

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

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

	return true
}

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

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

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

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

//nolint
package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

//}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

func Solve() {
	var n, tp, x int
	scan(&n, &x)
	count := make(map[int]int)
	for i := 1; i <= n; i++ {
		scan(&tp)
		count[tp]++
	}
	for _, k := range sortedKey(count) {
		m := min(count[k*x], count[k])
		count[k*x] -= m
		count[k] -= m
	}
	sum := 0
	for _, v := range count {
		sum += v
	}
	fmt.Println(sum)
}

func sortedKey(m map[int]int) []int {
	sortedKey := make([]int, 0, len(m))
	for k := range m {
		sortedKey = append(sortedKey, k)
	}
	sort.Ints(sortedKey)
	return sortedKey
}

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


package main

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

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

	for i := 0; i < tc; i++ {
        n := readInt(in)
        arr := readArrInt64(in)
        parity := make([]int, n)
        countEven, countOdd := 0, 0
        for j, v := range arr {
            parity[j] = int(v % 2)
            if parity[j] == 0 {
                countEven++
            } else {
                countOdd++
            }
        }

        startZero := false
        if n % 2 == 1 {
            if  countEven == n/2 + 1 && countOdd == n/2 {
                startZero = true
            } else if countEven == n/2 && countOdd == n/2+1 {
                startZero = false
            } else {
                fmt.Println(-1)
                continue
            }
        } else {
            if  countEven != n/2 && countOdd != n/2 {
                fmt.Println(-1)
                continue
            }
            if parity[0] == 0 {
                startZero = true
            } else {
                startZero = false
            }
        }

        //last1 in correct position
        ans := 0
        if n % 2 == 1 {
            if startZero {
                ans = compAns(1, parity)
            } else {
                ans = compAns(0, parity)
            }
            fmt.Println(ans)
        } else {
            ans0 := compAns(1, parity)
            ans1 := compAns(0, parity)
            if ans0 < ans1 {
                fmt.Println(ans0)
            } else {
                fmt.Println(ans1)
            }
        }
	}
}

func compAns(last1 int, parity []int) int {
    ans := 0
    for i, p := range parity {
        if p == 1 {
            if i != last1 {
                ans += abs(i-last1)
            }
            last1 += 2
        }
    }
    return ans
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	return line
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

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

package main

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

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		c1, s0, s1 := 0, 0, 0
		for i, p := 0, 0; i < n; i++ {
			if Fscan(in, &v); v&1 > 0 {
				c1++
				s0 += abs(i - p)
				s1 += abs(i - (p ^ 1))
				p += 2
			}
		}
		if abs(n-c1*2) > 1 {
			Fprintln(out, -1)
		} else if n&1 == 0 {
			Fprintln(out, min(s0, s1))
		} else if c1*2 > n {
			Fprintln(out, s0)
		} else {
			Fprintln(out, s1)
		}
	}
}

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

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

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

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int

	fmt.Fscanf(r, "%d\n", &T)

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscanf(r, "%d\n", &n)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(r, "%d", &arr[i])
		}
		fmt.Fscanf(r, "\n")
		p := make([][]int, 2)

		for i := 0; i < n; i++ {
			p[arr[i]%2] = append(p[arr[i]%2], i)
		}

		res := -1
		for i := 0; i <= 1; i++ {
			c := make([][]int, 2)
			c[0] = p[0]
			c[1] = p[1]
			cur := 0
			for j := 0; j < n; j++ {
				x := (j + i) % 2

				//	fmt.Println(j, x, c[x])

				if len(c[x]) == 0 {
					cur = -1
					break
				}

				if c[x][0] > j {
					cur += c[x][0] - j
				}
				c[x] = c[x][1:]
			}

			if res == -1 || (cur < res && cur != -1) {
				res = cur
			}
		}

		fmt.Println(res)
	}
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

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

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

func cost(v []int, first int) int64 {
	res := int64(0)
	pos := 0
	for i, x := range v {
		if x%2 == first {
			res += int64(abs(int(i - pos)))
			pos += 2
		}
	}
	return res
}

func solve(v []int) int64 {
	count := make([]int, 2)
	for _, x := range v {
		count[x%2]++
	}

	diff := count[0] - count[1]
	switch {
	case abs(diff) > 1:
		return -1
	case diff == 0:
		return min(cost(v, 0), cost(v, 1))
	case diff > 0:
		return cost(v, 0)
	default:
		return cost(v, 1)
	}
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i++ {
		n := stdin.Int()
		v := stdin.Ints(n)
		fmt.Println(solve(v))
	}
}

package main

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

var (
	in = bufio.NewReader(os.Stdin)
)

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}
func solve() {
	var n int
	fmt.Fscan(in, &n)
	var arr = make([]int, n)
	var numberOfOne = 0
	var numberOfZero = 0
	for i := 0; i < n; i++ {
		var currentNumber int64
		fmt.Fscan(in, &currentNumber)
		arr[i] = int(currentNumber % 2)
		if arr[i] == 0 {
			numberOfZero++
		} else {
			numberOfOne++
		}
	}
	if math.Abs(float64(numberOfOne-numberOfZero)) > 1 {
		fmt.Println(-1)
		return
	}
	var ans int64 = math.MaxInt64

	//if we consider 1 at the starting
	var currentValue = 1
	var needEven = make([]int, n)
	var needOdd = make([]int, n)
	if numberOfZero > numberOfOne {
		calcNumberOfOperation(arr, 0, &needEven, &needOdd)
		evenCost := calcCost(needEven, needOdd)
		ans = int64(int(math.Min(float64(evenCost), float64(ans))))
	} else if numberOfOne > numberOfZero {
		calcNumberOfOperation(arr, currentValue, &needEven, &needOdd)
		oddCost := calcCost(needEven, needOdd)
		ans = int64(int(math.Min(float64(oddCost), float64(ans))))
	} else {
		calcNumberOfOperation(arr, 0, &needEven, &needOdd)
		evenCost := calcCost(needEven, needOdd)
		ans = int64(int(math.Min(float64(evenCost), float64(ans))))

		needEven = nil
		needOdd = nil

		calcNumberOfOperation(arr, currentValue, &needEven, &needOdd)
		oddCost := calcCost(needEven, needOdd)
		ans = int64(int(math.Min(float64(oddCost), float64(ans))))

	}

	fmt.Println(ans)

}

func calcCost(needEven []int, needOdd []int) int {
	sort.Ints(needOdd)
	sort.Ints(needEven)
	var evenStart = 0
	var oddStart = 0
	var tempAns = 0
	for evenStart < len(needEven) && oddStart < len(needOdd) {
		tempAns += int(math.Abs(float64(needEven[evenStart] - needOdd[oddStart])))
		evenStart++
		oddStart++
	}
	return tempAns
}

func calcNumberOfOperation(arr []int, currentValue int, needEven *[]int, needOdd *[]int) {
	for i := 0; i < len(arr); i++ {
		if arr[i] != currentValue {
			if currentValue == 0 {
				*needEven = append(*needEven, i)
			} else {
				*needOdd = append(*needOdd, i)
			}
		}
		if currentValue == 1 {
			currentValue = 0
		} else {
			currentValue = 1
		}
	}
}

//x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-TEMPLATE_STARTING-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-

type pair struct {
	a int64
	b int64
}

func sortPair(pairs []pair) {
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i].a < pairs[j].a
	})
}
func max(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

func (r runeSort) Len() int           { return len(r) }
func (r runeSort) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r runeSort) Less(i, j int) bool { return r[i] < r[j] }

package main

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

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

	for i := 0; i < tc; i++ {
        n := readInt(in)
        arr := readArrInt64(in)
        parity := make([]int, n)
        countEven, countOdd := 0, 0
        for j, v := range arr {
            parity[j] = int(v % 2)
            if parity[j] == 0 {
                countEven++
            } else {
                countOdd++
            }
        }

        startZero := false
        if n % 2 == 1 {
            if  countEven == n/2 + 1 && countOdd == n/2 {
                startZero = true
            } else if countEven == n/2 && countOdd == n/2+1 {
                startZero = false
            } else {
                fmt.Println(-1)
                continue
            }
        } else {
            if  countEven != n/2 && countOdd != n/2 {
                fmt.Println(-1)
                continue
            }
            if parity[0] == 0 {
                startZero = true
            } else {
                startZero = false
            }
        }

        //last1 in correct position
        last1 := 0
        ans := 0
        if startZero {
            last1 = 1
            for i, p := range parity {
                if p == 1 {
                    if i != last1 {
                        ans += abs(i-last1)
                    }
                    last1 += 2
                }
            }
        } else {
            last1 = 0
            for i, p := range parity {
                if p == 1 {
                    if i != last1 {
                        ans += abs(i-last1)
                    }
                    last1 += 2
                }
            }
        }
        fmt.Println(ans)
	}
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	return line
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

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


package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	nm := strings.Split(sc.Text(), " ")
	n, _ := strconv.Atoi(nm[0])
	m, _ := strconv.Atoi(nm[1])

	p := make([]int, n)
	sc.Scan()
	for i, pi := range strings.Split(sc.Text(), " ") {
		p[i], _ = strconv.Atoi(pi)
	}
	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < m; i++ {
		sc.Scan()
		lrx := strings.Split(sc.Text(), " ")
		l, _ := strconv.Atoi(lrx[0])
		r, _ := strconv.Atoi(lrx[1])
		x, _ := strconv.Atoi(lrx[2])
		l--
		r--
		x--
		j, c := l, 0
		for c <= x-l+1 && j <= r {
			if p[j] <= p[x] {
				c++
			}
			j++
		}
		if c == x-l+1 {
			fmt.Fprint(w, "\nYes")
		} else {
			fmt.Fprint(w, "\nNo")
		}
	}
	w.Flush()
}

func readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

package main

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

const (
	MaxN = 10009
)

var p [MaxN]int
var n, m int

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(buf, "%d", &p[i])
	}
	fmt.Fscanf(buf, "\n")
	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() }()
	for i := 0; i < m; i++ {
		var l, r, x int
		fmt.Fscanf(buf, "%d %d %d\n", &l, &r, &x)
		cnt := 0
		for j := l; j <= r; j++ {
			if p[x] > p[j] {
				cnt++
			}
		}
		if l + cnt == x {
			fmt.Fprintln(outBuf, "Yes")
		} else {
			fmt.Fprintln(outBuf, "No")
		}
	}
}

package main

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

func solve(s string) string {
	return s
}

func output(i int, ans string) {
	fmt.Printf("Case #%d: %s\n", i, ans)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 1000000), 1000000)

	scanner.Scan()
	x := strings.Split(scanner.Text(), " ")
	//a, _ := strconv.Atoi(x[0])
	b, _ := strconv.Atoi(x[1])

	scanner.Scan()
	numStrs := strings.Split(scanner.Text(), " ")
	num := make([]int, len(numStrs))
	for i := range num {
		num[i], _ = strconv.Atoi(numStrs[i])
	}
	for i := 0; i < b; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), " ")
		start, _ := strconv.Atoi(input[0])
		end, _ := strconv.Atoi(input[1])
		index, _ := strconv.Atoi(input[2])
		start -= 1
		index -= 1

		if index < start || index > end {
			fmt.Println("Yes")
		} else {
			lt := 0
			cmpv := num[index]
			for _, v := range num[start:end] {
				if v < cmpv {
					lt++
				}
			}
			//	fmt.Println(lt, index)
			if (lt + start) == index {
				fmt.Println("Yes")
			} else {
				fmt.Println("No")
			}
		}
	}
}

// Codeforces helper functions
// 20 Jan 18
// samadhi

package main

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

const debug = true

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

	m := gsli(reader)[1]
	p := gsli(reader)

	for i := 0; i < m; i++ {
		cur := gsli(reader)
		smaller := 0

		l := cur[0]
		r := cur[1]
		x := cur[2]

		for j := l - 1; j < r; j++ {
			if p[j] < p[x-1] {
				smaller++
			}
		}
		if smaller == x-l {
			yes()
		} else {
			no()
		}
	}

}

// Input helpers

// If you don't pass in a reference to the reader, and just instantiate a new
// one every time, it will work locally, with IO typed at human-speed, but not
// on Codeforces.

// Get Space-separated Line as Strings
//
// Example input:
// 1 test 382.0
// Example output:
// ["1", "test", "382.0"]

func gsls(reader *bufio.Reader) (arr []string) {
	// Get a full line
	input, _ := reader.ReadString('\n')

	//Strip newline and return chars, if any
	input = strings.TrimSuffix(input, "\n")
	input = strings.TrimSuffix(input, "\r")

	// Split at the spaces into an array
	arr = strings.Split(input, " ")

	return
}

// Get Space-separated Line as Integers
// Any non-valid integers will be 0
//
// Example input:
// test 1 12.3 -117
// Example output:
// [0, 1, 0, -117]

func gsli(reader *bufio.Reader) (arr []int) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.Atoi(e)
		arr = append(arr, cur)
	}

	return
}

// Get Space-separated Line as 64-bit Floats
// Any non-valid floats will be 0
//
// Example input:
// test 128.328 12 -11.0
// Example output:
// [0, 128.328, 12, -11]

func gslf(reader *bufio.Reader) (arr []float64) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.ParseFloat(e, 64)
		arr = append(arr, cur)
	}

	return
}

// String helpers

// Is Lowercase
// Given some string[i], return whether it is lower case or not.

func isl(b byte) bool {
	var r rune
	r = rune(b)
	return unicode.IsLower(r)
}

// Math helpers

// Positve Modulo
// Returns x mod y, but always positive

func posMod(x, y int) int {
	return (x%y + y) % y
}

// Max Int
// Returns the max of two ints

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

// Distance formule
// Calculates the distance to the origin

func dist(x, y float64) float64 {
	return math.Sqrt(math.Pow(x, 2) + math.Pow(y, 2))
}

// Output helpers

func yes() {
	fmt.Println("Yes")
}

func no() {
	fmt.Println("No")
}

// Debug helpers

// From https://groups.google.com/forum/#!topic/golang-nuts/Qlxs3V77nss

func dbg(s string, a ...interface{}) {
	if debug {
		fmt.Printf(s, a...)
	}
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}
	for i := 0; i < m; i++ {
		var l, r, x int
		fmt.Scan(&l, &r, &x)
		c := 0
		for _, z := range p[l-1 : r] {
			if z < p[x-1] {
				c++
			}
		}
		if l+c == x {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

const (
	MaxN = 10000
)

var p [MaxN]int
var n, m int

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(buf, "%d", &p[i])
	}
	fmt.Fscanf(buf, "\n")
	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() }()
	for i := 0; i < m; i++ {
		var l, r, x int
		fmt.Fscanf(buf, "%d %d %d\n", &l, &r, &x)
		cnt := 0
		for j := l; j <= r; j++ {
			if p[x] > p[j] {
				cnt++
			}
		}
		if l + cnt == x {
			fmt.Fprintln(outBuf, "YES")
		} else {
			fmt.Fprintln(outBuf, "NO")
		}
	}
}