Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value.Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?You can assume that initially Vanya had infinitely many cards with each integer number from  - x to x.

The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.

Print a single number — the answer to the problem.

NoteIn the first sample, Vanya needs to find a single card with number -2.In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.

package main

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

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

//Wrong
func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, x := nextInt(), nextInt()
	sum := 0
	count := 0

	for i:=0; i<n; i++ {
		sum += nextInt()
	}

	count += abs(sum/x)

	if sum%x!=0 {
		count++
	}

	println(count)
}

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

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

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

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

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

package main
import (
	"fmt"
)
func main() {
	var n,m,t int
	s,a:=0,0
	fmt.Scan(&n,&m)
	for i:=0; i<n;i++ {
		fmt.Scan(&t)
		s += t
	}
	if s<0 {
		s= s*(-1)
	}
	if s%m==0 {
		a = s/m
	} else {a = s/m+1}
	fmt.Println(a)
}

package main

import "fmt"

func main() {
    var n,x,a int
    fmt.Scan(&n,&x)
    total := 0
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        total += a
    }
    if total < 0 { total = -total }
    if total == 0 {
        fmt.Println(0)
    } else if total <= x {
        fmt.Println(1)
    } else if total%x == 0 {
        fmt.Println(total/x)
    } else {
        fmt.Println((total/x) + 1)
    }
}

package main
import (
	"fmt"
)
func main() {
	var n,m,t int // membuat variabel n,m,dan t bertipe int
	s,a:=0,0   // membuat variabel s dan a yang kemudian diisi masing-masing nilai 0
	fmt.Scan(&n,&m)  // mengambil input
	for i:=0; i<n;i++ {  // looping sebanyak n kali
		fmt.Scan(&t)  // mengambil input ke 2
		s += t    // s ditambah dengan t
	}
	if s<0 {
		s= s*(-1)    // jika s kurang dari 0 maka s dikali dengan -1
	}
	if s%m==0 {
		a = s/m    // jika s dimodulo m sama dengan 0 maka a sama dengan s dibagi m
	} else {a = s/m+1}  // lainnya a sama dengan s dibagi m ditambah 1
	fmt.Println(a)   // mencetak output
}

/*********************************************************************************
*     File Name           :     A.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-10 23:29]
*     Last Modified       :     [2014-03-10 23:37]
*     Description         :
**********************************************************************************/

package main

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

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

    n, x := scanner.NextInt(), scanner.NextInt()
    sum := 0
    for i := 0; i < n; i++ {
        y := scanner.NextInt()
        sum += y
    }
    if sum < 0 {
        sum = -sum
    }
    ans := sum / x
    if sum%x != 0 {
        ans++
    }
    fmt.Println(ans)
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) NextInt() int {
    x, err := strconv.Atoi(self.Next())
    if err != nil {
        panic(err)
    }
    return x
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, x, tmp int

	fmt.Scan(&n, &x)

	sum := 0
	for i:=0; i<n; i++ {
		fmt.Scan(&tmp)
		sum += tmp
	}

	res := math.Ceil(math.Abs(float64(sum))/float64(x))

	fmt.Printf("%d", int(res))
}

package main

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

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

func main() {
    scanner.Split(bufio.ScanWords)
    n := scanner.NextInt()
    x := scanner.NextInt()
    total := 0
    for ; n > 0; n-- {
        t := scanner.NextInt()
        total += t
    }
    fmt.Printf("%d\n", (Abs(total)+x-1)/x)
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) NextInt() int {
    x, err := strconv.Atoi(self.Next())
    if err != nil {
        panic(err)
    }
    return x
}

func (self *Scanner) NextDouble() float64 {
    x, err := strconv.ParseFloat(self.Next(), 64)
    if err != nil {
        panic(err)
    }
    return x
}

package main

import "fmt"

func main() {
    var n,x,a int
    fmt.Scan(&n,&x)
    total := 0
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        total += a
    }
    if total < 0 { total = -total }
    if total <= x {
        fmt.Println(1)
    } else if total%x == 0 {
        fmt.Println(total/x)
    } else {
        fmt.Println((total/x) + 1)
    }
}


A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.

The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.

If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes). If the athlete can get from start to finish, print any way to do this in the following format:   print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;  print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.  All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.

package main

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

func main() {
	defer out.Flush()
	n := in.NextInt()
	m := in.NextInt()
	s := in.NextInt()
	d := in.NextInt()
	a := make([]int, n)
	for i := range a {
		a[i] = in.NextInt()
	}
	sort.Ints(a)
	ans := make([]Instruction, 0)
	ansExists := true
	x := 0
	for i := 0; i < n && ansExists; {
		runDist := a[i] - 1 - x
		if runDist < s {
			ansExists = false
			break
		}
		ans = append(ans, Instruction{"RUN", runDist})
		j := i
		for j+1 < n && a[j+1]-a[j]-2 < s {
			j++
		}
		jumpDist := 2 + a[j] - a[i]
		if jumpDist > d {
			ansExists = false
			break
		}
		ans = append(ans, Instruction{"JUMP", jumpDist})
		x = a[j] + 1
		i = j + 1
	}
	if x < m {
		ans = append(ans, Instruction{"RUN", m - x})
	}
	if !ansExists {
		fmt.Fprintln(out, "IMPOSSIBLE")
	} else {
		for _, i := range ans {
			fmt.Fprintln(out, i.action, i.distance)
		}
	}
}

type Instruction struct {
	action   string
	distance int
}

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

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	for len(r.buf) == 0 {
		var buf bytes.Buffer
		for {
			chunk, more, _ := r.r.ReadLine()
			buf.Write(chunk)
			if !more {
				break
			}
		}
		r.buf = buf.String()
	}
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	sign := 1
	if word[0] == '-' {
		sign = -1
		word = word[1:]
	}
	result := 0
	for i := 0; i < len(word); i++ {
		result = result*10 + int(word[i]) - '0'
	}
	result *= sign
	return result
}


YouKn0wWho has two even integers $$$x$$$ and $$$y$$$. Help him to find an integer $$$n$$$ such that $$$1 \le n \le 2 \cdot 10^{18}$$$ and $$$n \bmod x = y \bmod n$$$. Here, $$$a \bmod b$$$ denotes the remainder of $$$a$$$ after division by $$$b$$$. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)  — the number of test cases. The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$2 \le x, y \le 10^9$$$, both are even).

For each test case, print a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{18}$$$) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.

NoteIn the first test case, $$$4 \bmod 4 = 8 \bmod 4 = 0$$$.In the second test case, $$$10 \bmod 4 = 2 \bmod 10 = 2$$$.In the third test case, $$$420 \bmod 420 = 420 \bmod 420 = 0$$$.

package main

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

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

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

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

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		Д()
	}
}

func Д() {
	var x, y int64
	scan(&x, &y)
	var ans int64
	if x > y {
		ans = x + y
	} else if x == y {
		ans = x
	} else {
		ans = (y/x)*x + (y%x)/2
	}
	printf("%v\n", ans)
}

func solve() {
	var n int
	scan(&n)
	var g = make([][]int, n)
	for i := 0; i < n-1; i++ {
		var u, v int
		scan(&u, &v)
		u--
		v--
		g[u] = append(g[u], v)
		g[v] = append(g[v], u)
	}

	var (
		color     = make([]int, n)
		colorSize = [2]int{}
		bicolor   func(u, c int)
	)
	for i := range color {
		color[i] = -1
	}
	bicolor = func(u, c int) {
		if color[u] != -1 {
			return
		}
		color[u] = c
		colorSize[c]++
		for _, v := range g[u] {
			bicolor(v, c^1)
		}
	}
	bicolor(0, 0)

}

package main

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

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

	t := readInt(reader)

	for t > 0 {
		x, y := readTwoInt64(reader)
		if x > y {
			fmt.Fprintln(writer, x+y)
		} else {
			fmt.Fprintln(writer, y - y%x/2)
		}

		t--
	}

	writer.Flush()
}

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

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

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

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

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

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

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

	return value
}

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

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

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

	var ar []int

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

	return ar
}

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

	var ar []int64

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

	return ar
}

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

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

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

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

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

	return x
}

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

package main

import (
	"bufio"
	"fmt"
	"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 int64
		fmt.Fscan(input, &x, &y)

		if x > y {
			fmt.Println(x + y)
		}
		if x == y {
			fmt.Println(x)
		}
		if x < y {
			remain := (y % x) / 2
			fmt.Println(y - remain)

		}

	}
}

package main

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

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

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

	var c int
	Fscan(in, &c)
	for ; c > 0; c-- {
		var x uint64
		var y uint64
		Fscan(in, &x, &y)
		if x > y {
			Fprintln(out, x+y)
		} else {
			k := (y - y/x*x) / 2
			Fprintln(out, y/x*x+k)
		}
	}
}

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 u:=1;u<=t;u++{
		var x, y int64
		fmt.Fscan(in,&x,&y)
		if x>y{
			var ans int64
			ans = x + y
			fmt.Fprintln(out,ans)
		}else{
			var ans int64
			ans = y-(y%x)/2
			fmt.Fprintln(out,ans)
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1603B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, x, y int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x, &y)
		if x > y {
			Fprintln(out, x+y)
		} else {
			Fprintln(out, y-y%x/2)
		}
	}
}

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

package main

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

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

	var T, x, y int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x, &y)
		if x > y {
			Fprintln(out, x+y)
		} else {
			Fprintln(out, y-y%x/2)
		}
	}
}

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

package main

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

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

func main() {
	defer w.Flush()
	var t, x, y int64
	fmt.Fscan(r, &t)
	for t > 0 {
		t--
		fmt.Fscan(r, &x, &y)
		ans := (x + y) / 2
		ans = ans % x
		ans = y - ans
		if x > y {
			ans = x + y
		}
		fmt.Fprintln(w, ans)
	}
}

package main

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

func CF1603B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, x, y int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x, &y)
		if x > y {
			Fprintln(out, x+y)
		} else {
			Fprintln(out, y-y%x/2)
		}
	}
}

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

package main

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

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

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

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

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		Д()
	}
}

func Д() {
	var a, b int64
	scan(&a, &b)
	var ans int64
	if a > b {
		ans = a + b
	} else if a == b {
		ans = a
	} else {
		ans = (a + b) / 2
	}
	printf("%v\n", ans)
}

func solve() {
	var n int
	scan(&n)
	var g = make([][]int, n)
	for i := 0; i < n-1; i++ {
		var u, v int
		scan(&u, &v)
		u--
		v--
		g[u] = append(g[u], v)
		g[v] = append(g[v], u)
	}

	var (
		color     = make([]int, n)
		colorSize = [2]int{}
		bicolor   func(u, c int)
	)
	for i := range color {
		color[i] = -1
	}
	bicolor = func(u, c int) {
		if color[u] != -1 {
			return
		}
		color[u] = c
		colorSize[c]++
		for _, v := range g[u] {
			bicolor(v, c^1)
		}
	}
	bicolor(0, 0)

}

package main

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

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

	t := readInt(reader)

	for t > 0 {
		x, y := readTwoInt64(reader)
		if x > y {
			fmt.Fprintln(writer, x+y)
		} else if (x+y) % 2 == 0 {
			fmt.Fprintln(writer, (x+y)/2)
		} else {
			fmt.Fprintln(writer, (x+3*y)/4)
		}

		t--
	}

	writer.Flush()
}

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

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

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

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

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

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

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

	return value
}

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

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

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

	var ar []int

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

	return ar
}

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

	var ar []int64

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

	return ar
}

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

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

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

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

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

	return x
}

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

package main

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

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

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

	var c int
	Fscan(in, &c)
	for ; c > 0; c-- {
		var x uint64
		var y uint64
		Fscan(in, &x, &y)
		if 2*x == y {
			Fprintln(out, y)
		} else if 2*y == x {
			Fprintln(out, x*y)
		} else if x == y {
			Fprintln(out, x)
		} else if x > y {
			Fprintln(out, x+y)
		} else if 2*x > y {
			Fprintln(out, (x+y)/2)
		} else {
			for i := x + 1; i <= (x+y)/2; i++ {
				if i%x == y%i {
					Fprintln(out, i)
					break
				}
			}
		}
	}
}

package main

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

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

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

	var c int
	Fscan(in, &c)
	for ; c > 0; c-- {
		var x uint64
		var y uint64
		Fscan(in, &x, &y)
		if 2*x == y {
			Fprintln(out, y)
		} else if 2*y == x {
			Fprintln(out, y)
		} else if x == y {
			Fprintln(out, x)
		} else if x > y {
			Fprintln(out, x+y)
		} else if 2*x > y {
			Fprintln(out, (x+y)/2)
		} else {
			for i := x + 1; i <= (x+y)/2; i++ {
				if i%x == y%i {
					Fprintln(out, i)
					break
				}
			}
		}
	}
}

package main

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

func main() {
	A(os.Stdin, os.Stdout)
}
//
func A(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()

	var c int
	Fscan(in, &c)
	for ; c > 0; c-- {
		var x uint64
		var y uint64
		Fscan(in, &x, &y)
		if 2*x == y {
			Fprintln(out, y)
		} else if 2*y == x {
			Fprintln(out, x)
		} else if x == y {
			Fprintln(out, x)
		} else if x > y {
			Fprintln(out, x+y)
		} else if 2*x > y {
			Fprintln(out, (x+y)/2)
		} else {
			for i := x + 1; i <= (x+y)/2; i++ {
				if i%x == y%i {
					Fprintln(out, i)
					break
				}
			}
		}
	}
}

package main

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

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

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

	var c int
	Fscan(in, &c)
	for ; c > 0; c-- {
		var x uint64
		var y uint64
		Fscan(in, &x, &y)
		if 2*x == y {
			Fprintln(out, y)
		} else if 2*y == x {
			Fprintln(out, x)
		} else if x == y {
			Fprintln(out, x)
		} else if x > y {
			Fprintln(out, x+y)
		} else if 2*x > y {
			Fprintln(out, (x+y)/2)
		} else {
			for i := x + 1; i <= (x+y)/2; i++ {
				if i%x == y%i {
					Fprintln(out, i)
					break
				}
			}
		}
	}
}

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 u:=1;u<=t;u++{
		var x, y int
		fmt.Fscan(in,&x,&y)
		if x>y{
			var ans int
			ans = x + y
			fmt.Fprintln(out,ans)
		}else{
			var ans int
			ans = (x+y)/2
			fmt.Fprintln(out,ans)
		}
	}
}

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 u:=1;u<=t;u++{
		var x, y int64
		fmt.Fscan(in,&x,&y)
		if x>y{
			var ans int64
			ans = x + y
			fmt.Fprintln(out,ans)
		}else{
			var ans int64
			ans = (x+y)/2
			fmt.Fprintln(out,ans)
		}
	}
}

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 u:=1;u<=t;u++{
		var x, y int64
		fmt.Fscan(in,&x,&y)
		if x>y{
			fmt.Fprintln(out,x+y)
		}else{
			fmt.Fprintln(out,(x+y)/2)
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var x, y int64
		fmt.Fscan(in,&x,&y)
		if x<y{
			fmt.Fprintln(out,x+y)
		}else{
			fmt.Fprintln(out,(x+y)/2)
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriterSize(os.Stdout, 1024*1024)
	defer out.Flush()

	for i := 0; i < 1e6; i++ {
		Fprintln(out, int(1e9))
	}
}

package main

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

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

	for i := 0; i < 1e6; i++ {
		Fprintln(out, 0)
	}
}

package main

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

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

func main() {
	defer w.Flush()
	var t, x, y int64
	fmt.Fscan(r, &t)
	for t > 0 {
		t--
		fmt.Fscan(r, &x, &y)
		ans := (x + y) / 2
		if x > y {
			ans = y
		}
		fmt.Fprintln(w, ans)
	}
}

package main

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

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

func main() {
	defer w.Flush()
	var t, x, y int64
	fmt.Fscan(r, &t)
	for t > 0 {
		t--
		fmt.Fscan(r, x, y)
		ans := (x + y) / 2
		if x > y {
			ans = y
		}
		fmt.Fprintln(w, ans)
	}
}


Given the string $$$s$$$ of decimal digits (0-9) of length $$$n$$$.A substring is a sequence of consecutive characters of a string. The substring of this string is defined by a pair of indexes — with its left and right ends. So, each pair of indexes ($$$l, r$$$), where $$$1 \le l \le r \le n$$$, corresponds to a substring of the string $$$s$$$. We will define as $$$v(l,r)$$$ the numeric value of the corresponding substring (leading zeros are allowed in it).For example, if $$$n=7$$$, $$$s=$$$"1003004", then $$$v(1,3)=100$$$, $$$v(2,3)=0$$$ and $$$v(2,7)=3004$$$.You are given $$$n$$$, $$$s$$$ and an integer $$$w$$$ ($$$1 \le w < n$$$).You need to process $$$m$$$ queries, each of which is characterized by $$$3$$$ numbers $$$l_i, r_i, k_i$$$ ($$$1 \le l_i \le r_i \le n; 0 \le k_i \le 8$$$).The answer to the $$$i$$$th query is such a pair of substrings of length $$$w$$$ that if we denote them as $$$(L_1, L_1+w-1)$$$ and $$$(L_2, L_2+w-1)$$$, then:  $$$L_1 \ne L_2$$$, that is, the substrings are different;  the remainder of dividing a number $$$v(L_1, L_1+w-1) \cdot v(l_i, r_i) + v(L_2, L_2 + w - 1)$$$ by $$$9$$$ is equal to $$$k_i$$$. If there are many matching substring pairs, then find a pair where $$$L_1$$$ is as small as possible. If there are many matching pairs in this case, then minimize $$$L_2$$$.Note that the answer may not exist.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of input test cases. The first line of each test case contains a string $$$s$$$, which contains only the characters 0-9 and has a length $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$). The second line contains two integers $$$w, m$$$ ($$$1 \le w < n, 1 \le m \le 2 \cdot 10^5$$$), where $$$n$$$ — is the length of the given string $$$s$$$. The number $$$w$$$ denotes the lengths of the substrings being searched for, and $$$m$$$ is the number of queries to be processed. The following $$$m$$$ lines contain integers $$$l_i, r_i, k_i$$$ ($$$1 \le l_i \le r_i \le n$$$, $$$0 \le k_i \le 8$$$) — $$$i$$$th query parameters. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. It is also guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each request, print in a separate line:    left borders of the required substrings: $$$L_1$$$ and $$$L_2$$$; -1 -1 otherwise, if there is no solution.  If there are several solutions, minimize $$$L_1$$$ first, and minimize $$$L_2$$$ second.

NoteConsider the first test case of example inputs. In this test case $$$n=7$$$, $$$s=$$$"1003004", $$$w=4$$$ and one query $$$l_1=1$$$, $$$r_1=2$$$, $$$k_1=1$$$. Note that $$$v(1,2)=10$$$. We need to find a pair of substrings of length $$$4$$$ such that $$$v(L_1, L_1+3)\cdot10+v(L_2,L_2+3)$$$ has a remainder of $$$k_1=1$$$ when divided by $$$9$$$. The values $$$L_1=2, L_2=4$$$ actually satisfy all the requirements: $$$v(L_1, L_1+w-1)=v(2,5)=30$$$, $$$v(L_2, L_2+w-1)=v(4,7)=3004$$$. Indeed, $$$30\cdot10+3004=3304$$$, which has a remainder of $$$1$$$ when divided by $$$9$$$. It can be shown that $$$L_1=2$$$ is the minimum possible value, and $$$L_2=4$$$ is the minimum possible with $$$L_1=2$$$.

package main

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

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

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

		aa := make([]int, 10)
		for i := range aa {
			aa[i] = -1
		}
		bb := make([][]int, 10)
		digs := make([][10]int, len(s)+1)
		var x int
		for i := 0; i < w; i++ {
			digs[i+1] = digs[i]
			digs[i+1][s[i]-'0']++
			x += int(s[i] - '0')
			if x >= 9 {
				x -= 9
			}
		}
		aa[x] = 0
		bb[x] = append(bb[x], 0)
		for i := w; i < len(s); i++ {
			x -= int(s[i-w] - '0')
			if x < 0 {
				x += 9
			}
			digs[i+1] = digs[i]
			digs[i+1][s[i]-'0']++
			x += int(s[i] - '0')
			if x >= 9 {
				x -= 9
			}
			if aa[x] < 0 {
				aa[x] = i - w + 1
			}

			if len(bb[x]) < 2 {
				bb[x] = append(bb[x], i-w+1)
			}
		}

		mm := make([][][2]int, 10)
		for i := range mm {
			mm[i] = make([][2]int, 10)
		}

		for i := 0; i < m; i++ {
			var l, r, z int
			fmt.Fscan(in, &l, &r, &z)

			// This must be the slow section.
			var shift int
			for k := 1; k <= 9; k++ {
				shift += (digs[r][k] - digs[l-1][k]) * k
			}
			shift %= 9
			if mm[shift][z][1] > 0 {
				fmt.Fprintln(out, mm[shift][z][0], mm[shift][z][1])
				continue
			}

			a, b := math.MaxInt32, -1
			for j := 0; j < 10; j++ {
				if aa[j] < 0 {
					continue
				}

				x := (9 + z - (j*shift)%9) % 9
				if len(bb[x]) > 0 {
					if aa[j]+1 == bb[x][0]+1 {
						if len(bb[x]) > 1 && bb[x][0]+1 < a {
							a, b = bb[x][0]+1, bb[x][1]+1
						}
					} else {
						if aa[j]+1 < a {
							a, b = aa[j]+1, bb[x][0]+1
						}
					}
				}
			}

			if a == math.MaxInt32 {
				a = -1
			}
			mm[shift][z] = [2]int{a, b}
			fmt.Fprintln(out, a, b)
		}
	}
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

////////////////////////////////////////////////

func solve() {
	s := ReadString()
	n := len(s)

	w := ReadInt()
	m := ReadInt()

	ps := make([]int, n)
	ps[0] = int(s[0] - '0')
	for i := 1; i < n; i++ {
		ps[i] = (ps[i-1]*10 + int(s[i]-'0')) % 9
	}

	pw := make([]int, n+1)
	pw[0] = 1
	for i := 1; i <= n; i++ {
		pw[i] = (pw[i-1] * 10) % 9
	}

	get := func(l, r int) int {
		ans := ps[r-1]
		if l > 0 {
			ans -= ps[l-1] * pw[r-l]
		}
		return (ans%9 + 9) % 9
	}

	pos := make([]int, 9)
	for i, _ := range pos {
		pos[i] = -1
	}
	pos2 := make([]int, 9)
	copy(pos2, pos)

	for i := 0; i+w <= n; i++ {
		md := get(i, i+w)
		if pos[md] == -1 {
			pos[md] = i
		} else if pos2[md] == -1 {
			pos2[md] = i
		}
	}

	for i := 0; i < m; i++ {
		l := ReadInt()
		l--
		r := ReadInt()
		zal := ReadInt()

		cur := get(l, r)
		ansx := n
		ansy := n
		for x := 0; x < 9; x++ {
			if pos[x] == -1 {
				continue
			}
			if pos2[x] != -1 && (x*cur+x)%9 == zal {
				if pos[x] < ansx || (pos[x] == ansx && pos2[x] < ansy) {
					ansx, ansy = pos[x], pos2[x]
				}
			}
			for y := 0; y < 9; y++ {
				if x == y || pos[y] == -1 || (x*cur+y)%9 != zal {
					continue
				}

				if pos[x] < ansx || (pos[x] == ansx && pos[y] < ansy) {
					ansx, ansy = pos[x], pos[y]
				}
			}
		}
		if ansx == n {
			Println("-1 -1")
		} else {
			Println(ansx+1, ansy+1)
		}
	}
}

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

	t := 1
	t = ReadInt()

	for i := 0; i < t; i++ {
		solve()
	}
}

func ReadInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}

func ReadLong() int64 {
	var x int64
	fmt.Fscan(in, &x)
	return x
}

func ReadInts(n int) []int {
	a := make([]int, n)
	for i, _ := range a {
		a[i] = ReadInt()
	}
	return a
}

func ReadString() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}

func Print(a ...any) {
	fmt.Fprint(out, a...)
}

func Println(a ...any) {
	fmt.Fprintln(out, a...)
}

type IntPair struct {
	x int
	y int
}

func Iota(a []int, start int) {
	for i := 0; i < len(a); i++ {
		a[i] = start
		start++
	}
}

func NextPermutation(a []int) bool {
	n := len(a)
	pos := n - 2
	for ; pos >= 0; pos-- {
		if a[pos] < a[pos+1] {
			break
		}
	}
	if pos == -1 {
		return false
	}
	for i := n - 1; i >= 0; i-- {
		if a[i] > a[pos] {
			a[i], a[pos] = a[pos], a[i]
			Reverse(a[pos+1 : n])
			break
		}
	}
	return true
}

func Reverse(a []int) {
	n := len(a)
	for i := 0; i < n/2; i++ {
		a[i], a[n-i-1] = a[n-i-1], a[i]
	}
}

func RemoveIf(a []int, cond func(int) bool) []int {
	n := len(a)
	pos := 0
	for i := 0; i < n; i++ {
		if !cond(a[i]) {
			a[pos] = a[i]
			pos++
		}
	}
	return a[0:pos]
}

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

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

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

package main

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

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

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

		aa := make([]int, 10)
		for i := range aa {
			aa[i] = -1
		}
		bb := make([][]int, 10)
		digs := make([][10]int, len(s)+1)
		var x int
		for i := 0; i < w; i++ {
			digs[i+1] = digs[i]
			digs[i+1][s[i]-'0']++
			x += int(s[i] - '0')
			if x >= 9 {
				x -= 9
			}
		}
		aa[x] = 0
		bb[x] = append(bb[x], 0)
		for i := w; i < len(s); i++ {
			x -= int(s[i-w] - '0')
			if x < 0 {
				x += 9
			}
			digs[i+1] = digs[i]
			digs[i+1][s[i]-'0']++
			x += int(s[i] - '0')
			if x >= 9 {
				x -= 9
			}
			if aa[x] < 0 {
				aa[x] = i - w + 1
			}

			if len(bb[x]) < 2 {
				bb[x] = append(bb[x], i-w+1)
			}
		}

		mm := make([][][2]int, 10)
		for i := range mm {
			mm[i] = make([][2]int, 10)
		}
		for i := 0; i < m; i++ {
			var l, r, z int
			fmt.Fscan(in, &l, &r, &z)

			// This must be the slow section.
			var shift int
			for k := 1; k <= 9; k++ {
				shift += (digs[r][k] - digs[l-1][k]) * k
			}
			shift %= 9
			if mm[shift][z][1] > 0 {
				fmt.Fprintln(out, mm[shift][z][0], mm[shift][z][1])
				continue
			}

			a, b := math.MaxInt32, -1
			for j := 0; j < 10; j++ {
				if aa[j] < 0 {
					continue
				}

				x := (9 + z - (j*shift)%9) % 9
				// fmt.Println(i, j, (j*shift)%9, x, bb[x])
				if len(bb[x]) > 0 && (aa[j]+1 < a || bb[x][0]+1 < a) {
					if aa[j]+1 == bb[x][0]+1 {
						if len(bb[x]) > 1 {
							a, b = bb[x][0]+1, bb[x][1]+1
						}
					} else {
						a, b = aa[j]+1, bb[x][0]+1
					}
				}
			}

			if a == math.MaxInt32 {
				a = -1
			}
			mm[shift][z] = [2]int{a, b}
			fmt.Fprintln(out, a, b)
		}
	}
}

package main

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

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

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

		aa := make([]int, len(s)-w+1)
		bb := make([][2]int, 10)
		for i := range bb {
			bb[i] = [2]int{-1, -1}
		}
		var x int
		for i := 0; i < w; i++ {
			x += int(s[i] - '0')
		}
		aa[0] = x % 9
		bb[aa[0]][0] = 0
		for i := w; i < len(s); i++ {
			x += int(s[i]-'0') - int(s[i-w]-'0')
			d := i - w + 1
			aa[d] = x % 9
			if bb[aa[d]][0] < 0 {
				bb[aa[d]][0] = d
			} else if bb[aa[d]][1] < 0 {
				bb[aa[d]][1] = d
			}
		}

		for i := 0; i < m; i++ {
			var l, r, z int
			fmt.Fscan(in, &l, &r, &z)
			l--
			r--

			var shift int
			for i := l; i <= r; i++ {
				shift += int(s[i] - '0')
			}
			shift %= 9

			a, b := math.MaxInt32, -1
			cc := make([]bool, 10)
			for j := 0; j < len(aa); j++ {
				if cc[aa[j]] {
					continue
				}

				x := (9 + z - (aa[j]*shift)%9) % 9
				// fmt.Println(i, j, (aa[j]*shift)%9, x, bb[x])
				if bb[x][0] >= 0 {
					if j+1 == bb[x][0]+1 {
						if bb[x][1] > 0 {
							a, b = bb[x][0]+1, bb[x][1]+1
						}
					} else {
						a, b = j+1, bb[x][0]+1
					}
					break
				}
			}

			if a == math.MaxInt32 {
				a = -1
			}
			fmt.Fprintln(out, a, b)
		}
	}
}

package main

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

func min(a, b int) int {
	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 s string
		var w, m int
		fmt.Fscan(in, &s, &w, &m)

		aa := make([]int, len(s)-w+1)
		var x int
		for i := 0; i < w; i++ {
			x += int(s[i] - '0')
		}
		aa[0] = x % 9
		for i := w; i < len(s); i++ {
			x += int(s[i]-'0') - int(s[i-w]-'0')
			aa[i-w+1] = x % 9
		}

		for i := 0; i < m; i++ {
			var l, r, z int
			fmt.Fscan(in, &l, &r, &z)
			l--
			r--

			var shift int
			for i := l; i <= r; i++ {
				shift += int(s[i] - '0')
			}
			shift %= 9

			req := make([][]int, 10)
			for j := 0; j < 10; j++ {
				req[(j*shift)%9] = append(req[(j*shift)%9], j)
			}
			bb := make([]int, 10)
			for i := range bb {
				bb[i] = -1
			}
			bb[aa[0]] = 0 // keeps track of the indexes of last mod9 seen.
			a, b := math.MaxInt32, -1
			for j := 1; j < len(aa); j++ {
				x := (9 + z - aa[j]) % 9
				for _, v := range req[x] {
					if bb[v] >= 0 {
						a, b = min(a, bb[v]+1), j+1
					}
				}

				if a < math.MaxInt32 {
					break
				}
				if bb[aa[j]] < 0 {
					bb[aa[j]] = j
				}
			}

			if a == math.MaxInt32 {
				a = -1
			}
			fmt.Fprintln(out, a, b)
		}
	}
}


Connect the countless points with lines, till we reach the faraway yonder.There are n points on a coordinate plane, the i-th of which being (i, yi).Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set.

The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points. The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.

Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower).

NoteIn the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one.In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel.In the third example, it's impossible to satisfy both requirements at the same time.

package main

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

var a []int64

func isOnLine(start, end, p int) bool {
	return (a[p]-a[start])*int64(end-start) ==
		(int64(p)-int64(start))*(a[end]-a[start])
}

func isParallel(i, j, secondStart, secondEnd int) bool {
	left := int64(secondStart-secondEnd) * (a[i] - a[j])
	right := int64(i-j) * (a[secondStart] - a[secondEnd])
	return right == left
}

func checkAll(from, to int) bool {
	secondStart := -1
	secondEnd := -1
	for i := 0; i < len(a); i++ {
		if i != from && i != to {
			if isOnLine(from, to, i) {
				continue
			}
			if secondStart == -1 {
				secondStart = i
			} else if secondEnd == -1 {
				secondEnd = i
				if !isParallel(from, to, secondStart, secondEnd) {
					return false
				}
			} else if !isOnLine(secondStart, secondEnd, i) {
				return false
			}
		}
	}
	return true
}

func solve() {
	n := readInt()
	a = make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = readInt64()
	}

	fail := true
	for i := 1; i+1 < n; i++ {
		if !isOnLine(0, n-1, i) {
			fail = false
			break
		}
	}
	if fail {
		fmt.Println("No")
		return
	}
	for start := 0; start < 4; start++ {
		for end := start + 1; end < min(start+4, n); end++ {
			if checkAll(start, end) {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}

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

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

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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


You are given a connected undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. There are no self-loops or multiple edges in the given graph.You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the number of traversed edges).

The first line contains two integer numbers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$n - 1 \le m \le 2 \cdot 10^5$$$) — the number of vertices and edges, respectively. The following $$$m$$$ lines contain edges: edge $$$i$$$ is given as a pair of vertices $$$u_i$$$, $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \ne v_i$$$). There are no multiple edges in the given graph, i. e. for each pair ($$$u_i, v_i$$$) there are no other pairs ($$$u_i, v_i$$$) and ($$$v_i, u_i$$$) in the list of edges. It is also guaranteed that the given graph is connected (there is a path between any pair of vertex in the given graph).

If it is impossible to direct edges of the given graph in such a way that the obtained directed graph does not contain paths of length at least two, print "NO" in the first line. Otherwise print "YES" in the first line, and then print any suitable orientation of edges: a binary string (the string consisting only of '0' and '1') of length $$$m$$$. The $$$i$$$-th element of this string should be '0' if the $$$i$$$-th edge of the graph should be directed from $$$u_i$$$ to $$$v_i$$$, and '1' otherwise. Edges are numbered in the order they are given in the input.

NoteThe picture corresponding to the first example: And one of possible answers:

package main

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

type EdgeF struct {
	next *EdgeF
	u, v int
}

func addF(u, v int, mapp [][]int) {
	if len(mapp[u]) == 0 {
		mapp[u] = make([]int, 0)
	}
	mapp[u] = append(mapp[u], v)
}
func dfs(root int, color []int, mapp [][]int) bool {
	//fmt.Printf("root=%d\n",root)
	for _, next := range mapp[root] {
		if color[next] == 0 {
			if color[root] == 2 {
				color[next] = 1
			} else {
				color[next] = 2
			}
			if false==dfs(next,color,mapp){
				return false
			}
		} else if color[next] == color[root] {
			return false
		}
	}
	return true
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	edges := make([]EdgeF, m)
	mapp := make([][]int, n+1)
	for i := 0; i < m; i++ {
		fmt.Fscanf(buf, "%d %d\n", &edges[i].u, &edges[i].v)
		addF(edges[i].u, edges[i].v, mapp)
		addF(edges[i].v, edges[i].u, mapp)
	}
	color := make([]int,n+1)
	color[1] = 1
	if false == dfs(1,color,mapp){
		fmt.Printf("NO\n")
		return
	}
	fmt.Printf("YES\n")
	for i:=0;i < m;i++{
		fmt.Printf("%d",color[edges[i].u]-1)
	}
	fmt.Printf("\n")

}

package main

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

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

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

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

type edge struct {
	from, to  int
	visited   bool
	direction bool
}

func (e *edge) String() string {
	return fmt.Sprintf("%+v", *e)
}

type adjT struct {
	to int
	e  *edge
}

func (a adjT) String() string {
	return fmt.Sprintf("[%d: %v]", a.to, a.e)
}

func (a adjT) setDirection(dir bool) {
	if a.to == a.e.to {
		a.e.direction = dir
	} else {
		a.e.direction = !dir
	}
}

func (a adjT) direction() bool {
	if a.to == a.e.to {
		return a.e.direction
	}
	return !a.e.direction
}

var (
	n, m  int
	edges []*edge
	adj   [][]adjT
)

func dfs(v int, direction bool) bool {
	// Visit every edge going out from v and make its direction opposite to direction.
	for _, nex := range adj[v] {
		if nex.e.visited {
			// If outgoing edge already has a direction set, and it's not opposite, fail.
			if nex.direction() != !direction {
				return false
			}
			continue
		}

		nex.e.visited = true
		nex.setDirection(!direction)
		if !dfs(nex.to, !direction) {
			return false
		}
	}
	return true
}

func main() {
	defer writer.Flush()

	Scanf("%d %d\n", &n, &m)

	edges = make([]*edge, m+1)
	adj = make([][]adjT, n+1)
	for i := 1; i <= m; i++ {
		var e edge
		Scanf("%d %d\n", &e.from, &e.to)
		edges[i] = &e

		adj[e.from] = append(adj[e.from], adjT{e.to, &e})
		adj[e.to] = append(adj[e.to], adjT{e.from, &e})
	}

	for i := 1; i <= m; i++ {
		if edges[i].visited {
			continue
		}
		if !dfs(edges[i].from, false) {
			Printf("NO\n")
			return
		}
	}

	Printf("YES\n")
	for i := 1; i <= m; i++ {
		if edges[i].direction {
			Printf("1")
		} else {
			Printf("0")
		}
	}
}

package main

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

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

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

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

var (
	n, m     int
	edgeFrom []int
	adj      [][]int
	visited  []bool
	color    []bool
)

func dfs(v int, ccol bool) bool {
	visited[v] = true
	// Visit every edge going out from v and make its direction opposite to direction.
	for _, nex := range adj[v] {
		if visited[nex] {
			// If outgoing edge already has a direction set, and it's not opposite, fail.
			if ccol == color[nex] {
				return false
			}
			continue
		}

		color[nex] = !ccol
		if !dfs(nex, !ccol) {
			return false
		}
	}
	return true
}

func main() {
	defer writer.Flush()

	Scanf("%d %d\n", &n, &m)

	visited = make([]bool, n+1)
	color = make([]bool, n+1)
	adj = make([][]int, n+1)
	edgeFrom = make([]int, m+1)
	for i := 1; i <= m; i++ {
		var from, to int
		Scanf("%d %d\n", &from, &to)

		adj[from] = append(adj[from], to)
		adj[to] = append(adj[to], from)
		edgeFrom[i] = from
	}

	for i := 1; i <= n; i++ {
		if visited[i] {
			continue
		}
		if !dfs(i, false) {
			Printf("NO\n")
			return
		}
	}

	Printf("YES\n")
	for i := 1; i <= m; i++ {
		if color[edgeFrom[i]] {
			Printf("1")
		} else {
			Printf("0")
		}
	}
}

package main

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

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

	n, m := read(), read()
	g := make([][]int, n)
	type pair struct{ v, w int }
	edges := make([]pair, m)
	for i := 0; i < m; i++ {
		v, w := read()-1, read()-1
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
		edges[i] = pair{v, w}
	}

	colors := make([]int8, n)
	var f func(int, int8) bool
	f = func(v int, c int8) bool {
		colors[v] = c
		for _, w := range g[v] {
			if colors[w] == c {
				return false
			}
			if colors[w] == 0 {
				if !f(w, 3-c) {
					return false
				}
			}
		}
		return true
	}
	for i, c := range colors {
		if c == 0 && !f(i, 1) {
			Fprintln(out, "NO")
			return
		}
	}
	Fprintln(out, "YES")
	for _, e := range edges {
		Fprint(out, colors[e.v]-1)
	}
}

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

package main

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

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

	var n, m int
	fmt.Scanln(&n, &m)

	edges := make([][]int, n)
	for i := range edges {
		edges[i] = make([]int, 0)
	}

	conUs := make([]int, m)
	conVs := make([]int, m)
	for i := 0; i < m; i++ {
		var u, v int
		fmt.Fscanln(in, &u, &v)
		u--
		v--

		conUs[i] = u
		conVs[i] = v

		edges[u] = append(edges[u], v)
		edges[v] = append(edges[v], u)
	}

	colors := make([]int, n)
	visited := make([]bool, n)

	for i := 0; i < n; i++ {
		if colors[i] == 0 {
			colors[i] = 1
			next := make([]int, 1)
			next[0] = i

			for len(next) != 0 {
				cur := next[0]
				next = next[1:]

				if visited[cur] {
					continue
				}
				visited[cur] = true

				for _, con := range edges[cur] {
					if colors[con] == 0 {
						next = append(next, con)
						colors[con] = colors[cur] * -1
					} else if colors[con] * -1 != colors[cur] {
						fmt.Println("NO")
						return
					}
				}
			}
		}
	}
	fmt.Println("YES")
	for _, conU := range conUs {
		if colors[conU] == -1 {
			fmt.Print("0")
		} else {
			fmt.Print("1")
		}
	}
	fmt.Println()
}


You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.You know that you have $$$n$$$ bacteria in the Petri dish and size of the $$$i$$$-th bacteria is $$$a_i$$$. Also you know intergalactic positive integer constant $$$K$$$.The $$$i$$$-th bacteria can swallow the $$$j$$$-th bacteria if and only if $$$a_i > a_j$$$ and $$$a_i \le a_j + K$$$. The $$$j$$$-th bacteria disappear, but the $$$i$$$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $$$i$$$ can swallow any bacteria $$$j$$$ if $$$a_i > a_j$$$ and $$$a_i \le a_j + K$$$. The swallow operations go one after another.For example, the sequence of bacteria sizes $$$a=[101, 53, 42, 102, 101, 55, 54]$$$ and $$$K=1$$$. The one of possible sequences of swallows is: $$$[101, 53, 42, 102, \underline{101}, 55, 54]$$$ $$$\to$$$ $$$[101, \underline{53}, 42, 102, 55, 54]$$$ $$$\to$$$ $$$[\underline{101}, 42, 102, 55, 54]$$$ $$$\to$$$ $$$[42, 102, 55, \underline{54}]$$$ $$$\to$$$ $$$[42, 102, 55]$$$. In total there are $$$3$$$ bacteria remained in the Petri dish.Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope.

The first line contains two space separated positive integers $$$n$$$ and $$$K$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le K \le 10^6$$$) — number of bacteria and intergalactic constant $$$K$$$. The second line contains $$$n$$$ space separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — sizes of bacteria you have.

Print the only integer — minimal possible number of bacteria can remain.

NoteThe first example is clarified in the problem statement.In the second example an optimal possible sequence of swallows is: $$$[20, 15, 10, 15, \underline{20}, 25]$$$ $$$\to$$$ $$$[20, 15, 10, \underline{15}, 25]$$$ $$$\to$$$ $$$[20, 15, \underline{10}, 25]$$$ $$$\to$$$ $$$[20, \underline{15}, 25]$$$ $$$\to$$$ $$$[\underline{20}, 25]$$$ $$$\to$$$ $$$[25]$$$.In the third example no bacteria can swallow any other bacteria.

package main

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

func solve() {
	n := readInt()
	K := readInt()
	a := readIntArray(n)
	if n == 1 {
		fmt.Println(1)
		return
	}
	sort.Ints(a)
	cur := 0
	offset := 1
	ans := 0
	for offset < len(a) {
		if cur == offset || a[cur] == a[offset] {
			offset++
			continue
		}
		if a[cur] < a[offset] && a[cur]+K >= a[offset] {
			ans++
			cur++
		} else {
			cur++
		}
	}
	fmt.Println(n - ans)

}

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

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

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

package main

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

func main() {
	var n, K int

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

	var line string
	scanner := bufio.NewScanner(os.Stdin)

	buf := make([]byte, 0, 64*1024)
	scanner.Buffer(buf, 2048*1024)

	if scanner.Scan() {
		line = scanner.Text()
	}

	strList := strings.Split(line, " ")

	list := make([]int, n)
	count := make(map[int]int)

	for i := 0; i < n; i++ {
		list[i], _ = strconv.Atoi(strList[i])
		count[list[i]]++
	}

	sort.Ints(list)

	swallow := 0
	for i := 0; i < n-1; i++ {
		if list[i] < list[i+1] && list[i]+K >= list[i+1] {
			swallow += count[list[i]]
		}
	}

	fmt.Println(n - swallow)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, K int

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

	list := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&list[i])
	}

	sort.Ints(list)

	listK := make([]int, n)
	for i := 0; i < n; i++ {
		listK[i] = list[i] + K
	}

	swallow := 0
	for i := 0; i < n-1; i++ {
		if listK[i] >= list[i+1] {
			swallow++
		}
	}

	fmt.Println(len(list) - swallow)
}


A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 400$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of permutation. The second line of the test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the array $$$a$$$ represents the result of merging of some permutation $$$p$$$ with the same permutation $$$p$$$.

For each test case, print the answer: $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), representing the initial permutation. It is guaranteed that the answer exists and is unique.

package main

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

func main() {
	var t, n, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		ans := make([]int, 0)
		tmp := make(map[int]bool, 0)
		for j := 0; j < n*2; j++ {
			fmt.Fscan(in, &a)
			if !tmp[a] {
				tmp[a] = true
				ans = append(ans, a)
			}
		}
		for j := 0; j < n; j++ {
			fmt.Printf("%d ", ans[j])
		}
		fmt.Println()
	}
}

package main
// https://codeforces.com/contest/1380/submission/87050098
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type FastIn struct {
	scanner *bufio.Scanner
}

func MakeFastIn() (obj FastIn)  {
	obj = FastIn{}
	obj.scanner = bufio.NewScanner(os.Stdin)
	obj.scanner.Split(bufio.ScanWords)
	return
}

func (fi *FastIn) ReadText() string {
	fi.scanner.Scan()
	return fi.scanner.Text()
}

func (fi *FastIn) ReadInt() int {
	ret, err := strconv.Atoi(fi.ReadText())
	if err != nil {
		panic(err)
	}
	return ret
}

func (fi *FastIn) ReadInts(arr []int) {
	for i := 0; i < len(arr); i++ {
		arr[i] = fi.ReadInt()
	}
}
func Min (a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func (fi *FastIn) ReadInt64() int64 {
	ret, err := strconv.ParseInt(fi.ReadText(), 10, 64)
	if err != nil {
		panic(err)
	}
	return ret
}

var x,k,y int64

func GetCost(arr []int, left_b int, right_b int) (int64, bool) {
	any_gt := false
	max_bound := left_b
	if max_bound < right_b {
		max_bound = right_b
	}
	for _,v := range arr {
		if  v > max_bound {
			any_gt = true
		}
	}

	len := int64(len(arr))
	if any_gt {
		if len < k {
			return 0, false
		}
		return Min((len/k)*x+(len%k)*y,x+(len-k)*y), true
	} else {
		return Min((len/k)*x+(len%k)*y, len * y), true
	}
}

func main() {
	fin := MakeFastIn()
	T := fin.ReadInt()
	for ;T>0;T--{
		n := fin.ReadInt()
		a:= make([]int, 2*n)
		fin.ReadInts(a)

		vis:= make([]bool, n)
		for i:=0;i<2*n;i++{
			if vis[a[i]-1]{
				continue
			}
			fmt.Print(a[i]," ")
			vis[a[i]-1]=true
		}
		fmt.Print("\n")
	}
}

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-- {
		var n, a int
		fmt.Fscan(in, &n)
		d := make(map[int]bool)
		for i := 0; i < 2*n; i++ {
			fmt.Fscan(in, &a)
			if !d[a] {
				fmt.Fprint(out, a, " ")
			}
			d[a] = true
		}
		fmt.Fprintln(out)
	}
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.nextInt(); t > 0; t-- {
		n := io.nextInt()
		a := make([]int, 2*n)
		seen := make([]bool, n+1)
		for i := 0; i < 2*n; i++ {
			a[i] = io.nextInt()
			if !seen[a[i]] {
				io.print(a[i], " ")
				seen[a[i]] = true
			}
		}
		io.println()
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p []byte
}

func newFastIO(r io.Reader, w io.Writer) fastIO {
	return fastIO{bufio.NewReader(r), bufio.NewWriter(w), make([]byte, 1)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p)
	for !('0' <= f.p[0] && f.p[0] <= '9') {
		f.Read(f.p)
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p)
	}
	return n
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

// https://codeforces.com/contest/x/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input *bufio.Reader

func main() {
	var T int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n int
	fmt.Fscan(input, &n)
	ans := make([]int, 0)
	m := make([]int, 51)
	for i := 0; i < 2*n; i++ {
		var tmp int
		fmt.Fscan(input, &tmp)
		if m[tmp] == 0 {
			m[tmp]++
			ans = append(ans, tmp)
		}
	}
	for i := 0; i < len(ans); i++ {
		fmt.Print(ans[i], " ")
	}
	fmt.Println()
}

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

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 solve(p []int, length int) {
	m := make(map[int]bool)
	i := 0

	for _, v := range p {
		if m[v] == false {
			m[v] = true
			if i != 0 {
				printf(" ")
			}
			printf("%d", v)

			i++
		}
	}
	printf("\n")

}

func main() {
	defer writer.Flush()

	var testCases int
	scanf("%d\n", &testCases)
	for i := 0; i < testCases; i++ {
		var length int
		scanf("%d\n", &length)
		var lengthOfTestCase = length * 2
		var p = make([]int, lengthOfTestCase)
		for j := 0; j < lengthOfTestCase; j++ {
			if j < lengthOfTestCase-1 {
				scanf("%d ", &p[j])
			} else {
				scanf("%d\n", &p[j])
			}
		}
		solve(p, length)
	}
}

package main

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

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

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

	for t := input(); t > 0; t-- {
		n := input()
		index := 0

		arr := make([]int, n)

		for i := range arr {
			arr[i] = -1
		}

		for i:=0; i < 2*n; i++ {
			x := input()

			if arr[x-1] == -1 {
				arr[x-1] = index
				index++
			}
		}

		finarr := make([]int, n)

		for i := range arr {
			finarr[arr[i]] = i+1
		}

		for i := range finarr {
			fmt.Print(finarr[i], " ")
		}
		fmt.Print("\n")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		var p int
		a := make([]bool, n+1)
		for j := 0; j < 2*n; j++ {
			fmt.Fscan(in, &p)
			if !a[p] {
				a[p] = true
				fmt.Print(p, " ")
			}
		}
		fmt.Println()
	}
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		readLine(reader)
		line := readLine(reader)
		strs := strings.Split(string(line), " ")
		m := make(map[string]struct{})
		ss := ""
		for _, s:= range strs {
			if _, ok := m[s]; ok {
				continue
			}
			ss += s + " "
			m[s] = struct{}{}
		}
		fmt.Println(ss[:len(ss)-1])
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var n, count, x int
		var output = make(map[int]int)
		var out = make([]int, n)
		fmt.Scan(&n)
		for j := 0; j < (2 * n); j++ {
			fmt.Scan(&x)
			if _, ok := output[x]; !ok {
				output[x] = 1
				out = append(out, x)
				count++
			}
			if count > n {
				break
			}
		}
		for _, val := range out {
			fmt.Printf("%d ", val)
		}
		fmt.Println()
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1385B(_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)
		vis := make([]bool, n+1)
		for n *= 2; n > 0; n-- {
			Fscan(in, &v)
			if !vis[v] {
				vis[v] = true
				Fprint(out, v, " ")
			}
		}
		Fprintln(out)
	}
}

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

package main

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

var t int
var y [55]int

func null() {
	for i := 0; i < 53; i++ {
		y[i] = 0
	}
}

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

	fmt.Fscan(input, &t)

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

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

		for i := 0; i < (2 * n); i++ {
			if y[arr[i]] == 0 {
				fmt.Printf("%d ", arr[i])
				y[arr[i]]++
			}
		}

		fmt.Println()
	}
}

package main

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

func solve() {
	n := readInt()
	exists := make(map[int]bool)
	for i := 0; i < n*2; i++ {
		a := readInt()
		if _, ok := exists[a]; ok {
			continue
		}
		exists[a] = true
		fmt.Printf("%v ", a)
	}
}

func main() {
	k := readInt()
	for i := 0; i < k; i++ {
		solve()
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

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

func readInt() int {
	return int(readInt64())
}

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

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

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

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

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

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

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

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

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}

package main

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

func main() {
	defer writer.Flush()
	t := NextInt()
	for t > 0 {
		t--
		n := NextInt()
		used := make([]bool, n+1)
		for i := 0; i < 2*n; i++ {
			x := NextInt()
			if !used[x] {
				used[x] = true
				Print(x)
				Print(" ")
			}
		}
		Println("")
	}
}

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

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

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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

package main

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

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

func main() {
	defer out.Flush()
	var nTest int
	fmt.Fscanf(in, "%d\n", &nTest)
	for i := 0; i < nTest; i++ {
		solveCase()
	}
}
func solveCase() {
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]bool, n)
	for i := 0; i < 2*n; i++ {
		var x int
		fmt.Fscanf(in, "%d", &x)
		x--
		if !a[x] {
			a[x] = true
			fmt.Fprintf(out, "%d ", x+1)
		}
	}
	fmt.Fscanln(in)
	fmt.Fprint(out, "\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

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

	for _case := 1; _case <= T; _case++ {
		n := readInt()
		arr := readInts()
		ans := make([]int, n)
		used := make([]bool, n+1)

		for i,j := 0,0; i < n; i++ {
			for ; used[arr[j]]; j++ {}
			ans[i] = arr[j]
			used[arr[j]] = true
		}

		printInts(ans, " ")
		fmt.Println()
	}

	writer.Flush()
}

func readInts() []int {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

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

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

func printInts(arr []int, sep string) {
	n := len(arr)
	if n == 0 { panic("printInts empty") }
	fmt.Printf("%d", arr[0])
	for i := 1; i < n; i++ {
		fmt.Printf("%s%d", sep, arr[i])
	}
}

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 solve(p []int, length int) []int {
	m := make(map[int]bool)
	var r []int

	for _, v := range p {
		if m[v] == false {
			r = append(r, v)
			m[v] = true
		}
	}

	return r

}

func main() {
	defer writer.Flush()

	var testCases int
	scanf("%d\n", &testCases)
	for i := 0; i < testCases; i++ {
		var length int
		scanf("%d\n", &length)
		var lengthOfTestCase = length * 2
		var p = make([]int, lengthOfTestCase)
		for j := 0; j < lengthOfTestCase; j++ {
			if j < lengthOfTestCase-1 {
				scanf("%d ", &p[j])
			} else {
				scanf("%d\n", &p[j])
			}
		}
		r := solve(p, length)
		printf("%v\n", r)
	}
}


Do you know a story about the three musketeers? Anyway, you will learn about its origins now.Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.There are n warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers.Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions.

The first line contains two space-separated integers, n and m (3 ≤ n ≤ 4000, 0 ≤ m ≤ 4000) — respectively number of warriors and number of pairs of warriors knowing each other. i-th of the following m lines contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). Warriors ai and bi know each other. Each pair of warriors will be listed at most once.

If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).

NoteIn the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2.The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3.In the second sample there is no triple of warriors knowing each other.

package main

import "fmt"

var (
    g     = make([][]int, 4010)
    knows = make([][]bool, 4010)
    three = [3]int{0, 0, 0}
    ans   = -1
)

func dfs(idx, depth int) {
    three[depth] = idx
    if depth >= 2 {
        if knows[idx][three[0]] && idx != three[0] {
            rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
            if ans == -1 || ans > rec {
                ans = rec
            }
        }
        return
    }
    for _, x := range g[idx] {
        dfs(x, depth+1)
    }
}

func main() {
    n, m := 0, 0
    fmt.Scan(&n)
    fmt.Scan(&m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if g[a] == nil {
            g[a] = make([]int, 0)
            knows[a] = make([]bool, n+1)
        }
        if g[b] == nil {
            g[b] = make([]int, 0)
            knows[b] = make([]bool, n+1)
        }
        if knows[a][b] == false {
            g[a] = append(g[a], b)
            g[b] = append(g[b], a)
            knows[a][b] = true
            knows[b][a] = true
        }

    }
    for i := 1; i <= n; i++ {
        dfs(i, 0)
    }

    fmt.Println(ans)
}

package main

import "fmt"

var (
    g     = make([][]int, 4010)
    knows = map[int]map[int]bool{}
    three = [3]int{0, 0, 0}
    ans   = -1
)

func dfs(idx, depth int) {
    three[depth] = idx
    if depth >= 2 {
        if knows[idx][three[0]] && idx != three[0] {
            rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
            if ans == -1 || ans > rec {
                ans = rec
            }
        }
        return
    }
    for _, x := range g[idx] {
        dfs(x, depth+1)
    }
}

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if g[a] == nil {
            g[a] = make([]int, 0, n+1)
            knows[a] = make(map[int]bool)
        }
        if g[b] == nil {
            g[b] = make([]int, 0, n+1)
            knows[b] = make(map[int]bool)
        }
        if knows[a][b] == false {
            g[a] = append(g[a], b)
            g[b] = append(g[b], a)
            knows[a][b] = true
            knows[b][a] = true
        }

    }
    for i := 1; i <= n; i++ {
        dfs(i, 0)
    }

    fmt.Println(ans)
}

package main

import "fmt"

var (
    knows  = [4010][4010]bool{}
    degree = [4010]int{}
    ans    = 4010
)

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if knows[a][b] == false {
            knows[a][b] = true
            knows[b][a] = true
            degree[a]++
            degree[b]++
        }
    }

    for i := 1; i <= n; i++ {
        for j := i + 1; j <= n; j++ {
            if knows[i][j] {
                for k := j + 1; k <= n; k++ {
                    if knows[i][k] && knows[j][k] {
                        rec := degree[i] + degree[j] + degree[k] - 6
                        if ans > rec {
                            ans = rec
                        }
                    }
                }
            }
        }
    }
    if ans == 4010 {
        fmt.Println(-1)
    } else {
        fmt.Println(ans)
    }
}

package main

import "fmt"

var (
    g     = make([][]int, 4010)
    knows = [4010][4010]bool{}
    three = [3]int{0, 0, 0}
    ans   = -1
)

func dfs(idx, depth int) {
    three[depth] = idx
    if depth >= 2 {
        if knows[idx][three[0]] && idx != three[0] {
            rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
            if ans == -1 || ans > rec {
                ans = rec
            }
        }
        return
    }
    for _, x := range g[idx] {
        dfs(x, depth+1)
    }
}

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if g[a] == nil {
            g[a] = make([]int, 0, n+1)
        }
        if g[b] == nil {
            g[b] = make([]int, 0, n+1)
        }
        if knows[a][b] == false {
            g[a] = append(g[a], b)
            g[b] = append(g[b], a)
            knows[a][b] = true
            knows[b][a] = true
        }

    }
    for i := 1; i <= n; i++ {
        dfs(i, 0)
    }

    fmt.Println(ans)
}

package main

import "fmt"

var (
    knows  = [4010][4010]bool{}
    degree = [4010]int{}
    ans    = 4010
)

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        knows[a][b] = true
        knows[b][a] = true
        degree[a]++
        degree[b]++
    }

    for i := 1; i <= n; i++ {
        for j := i + 1; j <= n; j++ {
            if knows[i][j] {
                for k := j + 1; k <= n; k++ {
                    if knows[i][k] && knows[j][k] {
                        if ans > degree[i]+degree[j]+degree[k]-6 {
                            ans = degree[i] + degree[j] + degree[k] - 6
                        }
                    }
                }
            }
        }
    }
    if ans == 4010 {
        fmt.Println(-1)
    } else {
        fmt.Println(ans)
    }
}

package main

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

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

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

	n, m := nextInt(), nextInt()
	a, b := 0, 0
	pairs := make([][]bool, n+1)
	recogs := make([]int, n+1)
	minRecog := math.MaxInt32
	recog := 0

	for i := range pairs {
		pairs[i] = make([]bool, n+1)
	}

	for i := 0; i < m; i++ {
		a, b = nextInt(), nextInt()
		pairs[a][b] = true
		pairs[b][a] = true
		recogs[a]++
		recogs[b]++
	}
	// println(pairs)
	for i := 1; i < n+1; i++ {
		for j := i + 1; j < n+1; j++ {
			if pairs[i][j] {
				for k := j + 1; k < n+1; k++ {
					if pairs[i][k] && pairs[j][k] {
						recog = recogs[i] + recogs[j] + recogs[k] - 6
						// println(recog)
						if recog < minRecog {
							minRecog = recog
						}
					}
				}

			}
		}
	}

	if minRecog == math.MaxInt32 {
		println(-1)
	} else {
		println(minRecog)
	}
}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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 print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

import (
	"bufio"
	"fmt"
	"math"
	"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()
	a, b := 0, 0
	pairs := make([][]int, n+1)
	recogs := make([]int, n+1)
	minRecog := math.MaxInt32
	recog := 0

	for i := range pairs {
		pairs[i] = make([]int, n+1)
	}

	for i := 0; i < m; i++ {
		a, b = nextInt(), nextInt()
		pairs[a][b] = 1
		pairs[b][a] = 1
		recogs[a]++
		recogs[b]++
	}
	// println(pairs)
	for i := 1; i < n+1; i++ {
		for j := i + 1; j < n+1; j++ {
			if pairs[i][j] == 1 {
				for k := j + 1; k < n+1; k++ {
					if pairs[i][k] == 1 && pairs[j][k] == 1 {
						recog = recogs[i] + recogs[j] + recogs[k] - 6
						// println(recog)
						if recog < minRecog {
							minRecog = recog
						}
					}
				}

			}
		}
	}

	if minRecog == math.MaxInt32 {
		println(-1)
	} else {
		println(minRecog)
	}
}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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 print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

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

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

  n, m := getI(), getI()
  edges := make([][]int, m)
  neighbor := make([]map[int]bool, n + 1)
  for u := 1; u <= n; u++ {
    neighbor[u] = map[int]bool{}
  }
  for i := range edges {
    u, v := getI(), getI()
    edges[i] = []int{ u, v }
    neighbor[u][v] = true
    neighbor[v][u] = true
  }
  min_sum := -1

  for _, edge := range edges {
    u, v := edge[0], edge[1]
    for w := 1; w <= n; w++ {
      if neighbor[u][w] && neighbor[v][w] {
        sum := -6 + len(neighbor[u]) + len(neighbor[v]) + len(neighbor[w])
        if min_sum == -1 || sum < min_sum {
          min_sum = sum
        }
      }
    }
  }

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

package main

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

// Took from here: https://www.codementor.io/tucnak/using-golang-for-competitive-programming-h8lhvxzt3
var reader *bufio.Reader = bufio.NewReaderSize(os.Stdin, 10000000)
var writer *bufio.Writer = bufio.NewWriterSize(os.Stdout,10000000)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

var n, m int
var matrix [4001][4001]int
var warriors [4001]int

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

  scanf("%d %d\n", &n, &m)
  for i := 1; i <= m; i++ {
    var a, b int
    scanf("%d %d\n", &a, &b)
    matrix[a][b] = 1
    matrix[b][a] = 1
    warriors[a]++
    warriors[b]++
  }
  min := -1
  for i := 1; i <= n;  i++ {
    for j := 1; j <= n; j++ {
      if matrix[i][j] == 1 {
        for k := 1; k <= n; k++ {
          if matrix[j][k] == 1 && matrix[i][k] == 1 {
            sum := warriors[i] + warriors[j] + warriors[k]
            sum -= 6 // remove as contagens dos warriors escolhidos
            if sum < min || min == -1 {
              min = sum
            }
          }
        }
      }
    }
  }
  printf(strconv.Itoa(min))
}

package main

import "fmt"

var (
    g     = make([][]int, 4010)
    knows = [4010][4010]bool{}
    three = [3]int{0, 0, 0}
    ans   = -1
)

func dfs(idx, depth int) {
    three[depth] = idx
    if depth >= 2 {
        if knows[idx][three[0]] && idx != three[0] {
            rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
            if ans == -1 || ans > rec {
                ans = rec
            }
        }
        return
    }
    for _, x := range g[idx] {
        dfs(x, depth+1)
    }
}

func main() {
    n, m := 0, 0
    fmt.Scan(&n)
    fmt.Scan(&m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if g[a] == nil {
            g[a] = make([]int, 0)
        }
        if g[b] == nil {
            g[b] = make([]int, 0)
        }
        if knows[a][b] == false {
            g[a] = append(g[a], b)
            g[b] = append(g[b], a)
            knows[a][b] = true
            knows[b][a] = true
        }

    }
    for i := 1; i <= n; i++ {
        dfs(i, 0)
    }

    fmt.Println(ans)
}

package main

import "fmt"

var (
    g     = make([][]int, 4010)
    knows = [4010][4010]bool{}
    three = [3]int{0, 0, 0}
    ans   = -1
)

func dfs(idx, depth int) {
    three[depth] = idx
    if depth >= 2 {
        if knows[idx][three[0]] && idx != three[0] {
            rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
            if ans == -1 || ans > rec {
                ans = rec
            }
        }
        return
    }
    for _, x := range g[idx] {
        dfs(x, depth+1)
    }
}

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if g[a] == nil {
            g[a] = make([]int, 0)
        }
        if g[b] == nil {
            g[b] = make([]int, 0)
        }
        if knows[a][b] == false {
            g[a] = append(g[a], b)
            g[b] = append(g[b], a)
            knows[a][b] = true
            knows[b][a] = true
        }

    }
    for i := 1; i <= n; i++ {
        dfs(i, 0)
    }

    fmt.Println(ans)
}

package main

import (
    "fmt"
)

var (
    knows  = [4010][4010]bool{}
    degree = [4010]int{}
    ans    = 4010
)

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        knows[a][b] = true
        knows[b][a] = true
        degree[a]++
        degree[b]++
    }

    for i := 1; i <= n; i++ {
        for j := i + 1; j <= n; j++ {
            if knows[i][j] {
                for k := j + 1; k <= n; k++ {
                    if knows[i][k] && knows[j][k] {
                        if ans > degree[i]+degree[j]+degree[k] {
                            ans = degree[i] + degree[j] + degree[k]
                        }
                    }
                }
            }
        }
    }
    if ans == 4010 {
        fmt.Println(-1)
    } else {
        fmt.Println(ans - 6)
    }
}

package main

import "fmt"

var (
	g     = make([][]int, 4010)
	knows = map[int]map[int]bool{}
	three = [3]int{0, 0, 0}
	ans   = -1
)

func dfs(idx, depth int) {
	three[depth] = idx
	if depth >= 2 {
		if knows[idx][three[0]] && idx != three[0] {
			rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
			if ans == -1 || ans > rec {
				ans = rec
			}
		}
		return
	}
	for _, x := range g[idx] {
		dfs(x, depth+1)
	}
}

func main() {
	n, m := 0, 0
	fmt.Scan(&n, &m)
	for i := 0; i < m; i++ {
		a, b := 0, 0
		fmt.Scan(&a, &b)
		if g[a] == nil {
			g[a] = make([]int, 0)
			knows[a] = make(map[int]bool)
		}
		if g[b] == nil {
			g[b] = make([]int, 0)
			knows[b] = make(map[int]bool)
		}
		if knows[a][b] == false {
			g[a] = append(g[a], b)
			g[b] = append(g[b], a)
			knows[a][b] = true
			knows[b][a] = true
		}

	}
	for i := 1; i <= n; i++ {
		dfs(i, 0)
	}

	fmt.Println(ans)
}

package main

import "fmt"

var (
    knows  = [4010][4010]bool{}
    degree = [4010]int{}
    three  = [3]int{0, 0, 0}
    ans    = 4010
)

func main() {
    n, m := 0, 0
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        a, b := 0, 0
        fmt.Scan(&a, &b)
        if knows[a][b] == false {
            knows[a][b] = true
            knows[b][a] = true
            degree[a]++
            degree[b]++
        }
    }

    for i := 1; i <= n; i++ {
        for j := i + 1; j <= n; j++ {
            if knows[i][j] {
                for k := 1; k <= n; k++ {
                    if knows[i][k] && knows[j][k] {
                        rec := degree[i] + degree[j] + degree[k] - 6
                        if ans > rec {
                            ans = rec
                        }
                    }
                }
            }
        }
    }
    if ans == 4010 {
        fmt.Println(-1)
    } else {
        fmt.Println(ans)
    }
}

package main

import "fmt"

var (
	g     = make([][]int, 4010)
	knows = [4010][4010]bool{}
	three = [3]int{0, 0, 0}
	ans   = -1
)

func dfs(idx, depth int) {
	three[depth] = idx
	if depth >= 2 {
		if knows[idx][three[0]] && idx != three[0] {
			rec := len(g[three[0]]) + len(g[three[1]]) + len(g[three[2]]) - 6
			if ans == -1 || ans > rec {
				ans = rec
			}
		}
		return
	}
	for _, x := range g[idx] {
		dfs(x, depth+1)
	}
}

func main() {
	n, m := 0, 0
	fmt.Scanf("%d %d", &n, &m)
	for i := 0; i < m; i++ {
		a, b := 0, 0
		fmt.Scanf("%d %d", &a, &b)
		if g[a] == nil {
			g[a] = make([]int, 0)
		}
		if g[b] == nil {
			g[b] = make([]int, 0)
		}
		if knows[a][b] == false {
			g[a] = append(g[a], b)
			g[b] = append(g[b], a)
			knows[a][b] = true
			knows[b][a] = true
		}

	}
	for i := 1; i <= n; i++ {
		dfs(i, 0)
	}

	fmt.Println(ans)
}


It is the easy version of the problem. The only difference is that in this version $$$a_i \le 200$$$.You are given an array of $$$n$$$ integers $$$a_0, a_1, a_2, \ldots a_{n - 1}$$$. Bryap wants to find the longest beautiful subsequence in the array.An array $$$b = [b_0, b_1, \ldots, b_{m-1}]$$$, where $$$0 \le b_0 < b_1 < \ldots < b_{m - 1} < n$$$, is a subsequence of length $$$m$$$ of the array $$$a$$$.Subsequence $$$b = [b_0, b_1, \ldots, b_{m-1}]$$$ of length $$$m$$$ is called beautiful, if the following condition holds:   For any $$$p$$$ ($$$0 \le p < m - 1$$$) holds: $$$a_{b_p} \oplus b_{p+1} < a_{b_{p+1}} \oplus b_p$$$. Here $$$a \oplus b$$$ denotes the bitwise XOR of $$$a$$$ and $$$b$$$. For example, $$$2 \oplus 4 = 6$$$ and $$$3 \oplus 1=2$$$.Bryap is a simple person so he only wants to know the length of the longest such subsequence. Help Bryap and find the answer to his question.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_0,a_1,...,a_{n-1}$$$ ($$$0 \leq a_i \leq 200$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case print a single integer — the length of the longest beautiful subsequence.

NoteIn the first test case, we can pick the whole array as a beautiful subsequence because $$$1 \oplus 1 < 2 \oplus 0$$$.In the second test case, we can pick elements with indexes $$$1$$$, $$$2$$$ and $$$4$$$ (in $$$0$$$-indexation). For this elements holds: $$$2 \oplus 2 < 4 \oplus 1$$$ and $$$4 \oplus 4 < 1 \oplus 2$$$.

package main

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

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

func slove() {
	var n int
	fmt.Fscan(rr, &n)
	nums := make([]int, n)
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
	}
	dp := make([]int, n)
	ans := 0
	for i := range nums {
		dp[i] = max(dp[i], 1)
		for j:=1;j<256&&i+j<n;j++ {
			if nums[i]^(i+j) < nums[i+j]^i {
				dp[i+j] = max(dp[i+j], dp[i]+1)
			}
		}
		ans = max(ans, dp[i])
	}
	fmt.Fprintln(ww, ans)
}

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

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

package main

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

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

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(n, a)
		fmt.Fprintln(w, w1)
	}
}
func do(n int, a []int) int {
	d := make([]int, n)
	r := 0
	for i := range a {
		d[i] = 1
		k := i - 512
		if k < 0 {
			k = 0
		}
		for j := k; j < i; j++ {
			if a[j]^i < a[i]^j {
				if d[i] < d[j]+1 {
					d[i] = d[j] + 1
				}
			}
		}
		if r < d[i] {
			r = d[i]
		}
	}
	return r
}