package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for t > 0 {
		t--
		var n, k int
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &n, &k)
		numbers := make([]int, n)
		sum := 0
		scanner.Scan()
		for i, m := range strings.Fields(scanner.Text()) {
			numbers[i], _ = strconv.Atoi(m)
			sum += numbers[i]
		}
		sort.Ints(numbers)
		i, j := n-k-1, n-1
		for k > 0 {
			k--
			sum += numbers[i] / numbers[j]
			sum -= numbers[i] + numbers[j]
			i--
			j--
		}
		fmt.Println(sum)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1618D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		s := 0
		for _, v := range a[:n-k*2] {
			s += v
		}
		for i := n - k; i < n; i++ {
			s += a[i-k] / a[i]
		}
		Fprintln(out, s)
	}
}

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

package main

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

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

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

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

		sort.Ints(nums)
		var sum int
		for i := 0; i < k; i++ {
			sum += nums[n-i-k-1] / nums[n-i-1]
		}

		for i := 0; i < n-k-k; i++ {
			sum += nums[i]
		}
		fmt.Fprintln(out, sum)
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, k, p := 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &k)
		o, sum := []int{}, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &p)
			o = append(o, p)
		}
		sort.Ints(o)
		for j := 0; j < k; j++ {
			sum += o[n-k-j-1] / o[n-j-1]
		}
		for j := 0; j < n-(2*k); j++ {
			sum += o[j]
		}
		fmt.Fprintln(w, sum)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var T, n, k int
	Fscan(reader, &T)
	for cas := 1; cas <= T; cas++ {
		Fscan(reader, &n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(reader, &a[i])
		}
		sort.Ints(a)
		ans := 0
		for i := 1; i <= k; i++ {
			ans += a[n-i-k] / a[n-i]
		}
		for i := 0; i < n-k-k; i++ {
			ans += a[i]
		}
		Fprintln(writer, ans)
	}
}

package main

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

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

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

func main() {
	var T, n, k int
	Scan(&T)
	for cas := 1; cas <= T; cas++ {
		Scan(&n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Scan(&a[i])
		}
		sort.Ints(a)
		ans := 0
		for i := 1; i <= k; i++ {
			ans += a[n-i-k] / a[n-i]
		}
		for i := 0; i < n-k-k; i++ {
			ans += a[i]
		}
		Println(ans)
	}
}

package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)
func insertionSort(a []int) {
	var n = len(a)
	for i:=0; i<n; i++ {
		j:=i
		for j>0 {
			if a[j-1]>a[j] {
				a[j-1], a[j] = a[j], a[j-1]
			}
			j--
		}
	}
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	tests, _ := strconv.Atoi(scanner.Text())

	for i := 1; i <= tests; i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		a := make([]int, n, n)
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < n; i++ {
			scanner.Scan()
			a[i], _ = strconv.Atoi(scanner.Text())
		}
		//fmt.Println(a)
		insertionSort(a)
		//fmt.Println(a)
		//fmt.Println()
		sum := 0
		for i := n - 2*k; i < n-k; i++ {
			sum += a[i] / a[i+k]
		}
		for i := 0; i < n-2*k; i++ {
			sum += a[i]
		}
		fmt.Println(sum)
	}
}

package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)
func insertionSort(a []int) {
	var n = len(a)
	for i:=0; i<n; i++ {
		j:=i
		for j>0 {
			if a[j-1]>a[j] {
				a[j-1], a[j] = a[j], a[j-1]
			}
			j--
		}
	}
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	tests, _ := strconv.Atoi(scanner.Text())

	for i := 1; i <= tests; i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		a := make([]int, n, n)
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < n; i++ {
			scanner.Scan()
			a[i], _ = strconv.Atoi(scanner.Text())
		}
		insertionSort(a)
		sum := 0
		for i := n - 2*k; i < n-k; i++ {
			sum += a[i] / a[i+k]
		}
		for i := 0; i < k; i++ {
			sum += a[i]
		}
		fmt.Println(sum)
	}
}


package main

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

// 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 MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	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 {
	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 LITTLE(x int) int64 {
	var answer int64
	answer = answer + int64((x*x*x*x-x*x)/4) + int64(x*x*(x-1)*(x-1)/8) - int64(x*(x-1)*(x+x+1)*(x+x-1)/12)
	return answer
}

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
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

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

		Even := make([]int, 0)
		Odd := make([]int, 0)

		for i := 1; i < n+1; i++ {
			var m int
			fmt.Fscan(input, &m)
			if m%2 == 0 {
				Even = append(Even, m)
			} else {
				Odd = append(Odd, m)
			}
		}
		var Answer int
		q := len(Even)
		q1 := len(Odd)

		Answer = int(q*(q-1)/2) + q*q1

		sort.Ints(Odd)

		for i := q1 - 1; i > 0; i-- {
			for j := i - 1; j > -1; j-- {
				if GCD(int64(Odd[i]), int64(Odd[j])) > 1 {
					Answer++
				}
			}
		}
		fmt.Println(Answer)

	}

}

package main

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

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

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

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

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

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

		m := make([]int, n)
		var pos int
		for i := n - 1; i >= 0; i-- {
			if arr[i]%2 == 0 {
				m[pos] = arr[i]
				pos++
			}
		}

		for i := n - 1; i >= 0; i-- {
			if arr[i]%2 != 0 {
				m[pos] = arr[i]
				pos++
			}
		}

		var c int
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if gcd(m[i], 2*m[j]) > 1 {
					c++
				}
			}
		}
		fmt.Fprintln(out, c)
	}
}

package main

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

/*
1
33
27 49 32 95 100 20 58 39 92 30 67 89 58 81 100 66 73 29 75 81 70 55 18 28 7 35 98 52 30 11 69 48 84
*/

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

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

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

		a := make([]int, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		for i, j := 0, n-1; i < j; {
			if a[i]%2 == 0 {
				i++
				continue
			}

			if a[j]%2 != 0 {
				j--
				continue
			}

			a[i], a[j] = a[j], a[i]
		}

		cnt := 0

		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if (gcd(a[i], 2*a[j])) > 1 {
					cnt++
				}
			}
		}

		fmt.Fprintln(writer, cnt)
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()
	Test:= io.NextInt()
	for i := 0; i < Test; i++ {
		n := io.NextInt()
		var ans int64=0
		arr:=make([]int,n)
		var odd []int
		var even []int
		for i:=0 ; i < n ; i++{
		    x:=io.NextInt()
		    arr[i]=x
		    if(x%2==1){
		        odd=append(odd,x)
		    }else{
		        even=append(even,x)
		    }
		}
		var c int64=int64(len(odd))
		var d int64=int64(len(even))
		var cc int=len(odd)
		ans+=c*d
		ans+=(d*(d-1))/2
		for i:=0 ; i < cc; i++{
		    for j:=i+1 ; j < cc; j++{
		        if(GCD(odd[i],odd[j])>1){
		            ans+=1
		        }
		    }
		}
		io.Println(ans)
	}
}
func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}
func min(i,j int64)int64{
    if(i>j){
        return j
    }
    return i
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

// 00
package main

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

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, curr int
		fmt.Fscan(reader, &n)
		odds := make([]int, 0)
		o := 0
		e := 0
		ans := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &curr)
			if curr%2 == 0 {
				e++
			} else {
				o++
				odds = append(odds, curr)
			}
		}
		ans += o * e
		ans += (e * (e - 1)) / 2
		for i := 0; i < len(odds); i++ {
			for j := i + 1; j < len(odds); j++ {
				if gcd(odds[i], odds[j]) > 1 {
					ans++
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

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

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

func gcd(x, y int) int {
	if y > x {
		return gcd(y, x)
	}
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func solve(n int, a []int) int {
	var (
		x    []int
		c, r int
	)
	for _, v := range a {
		if v%2 == 1 {
			x = append(x, v)
		} else {
			c++
		}
	}
	r = n*c - c*(c+1)/2
	for i := 0; i < len(x); i++ {
		for j := i + 1; j < len(x); j++ {
			if gcd(x[i], x[j]) > 1 {
				r++
			}
		}
	}
	return r
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, a))
	}
}

package main

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

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	solve := func() {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i]&1 == 0
		})
		c := 0
		for l, v := range a {
			for r := l + 1; r < len(a); r++ {
				w := a[r]
				if gcd(v, w*2) > 1 {
					c++
				}
			}
		}
		Fprintln(out, c)
	}
	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve()
	}
}

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

package main

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

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

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i, _ := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i]%2 < a[j]%2 })
		c := 0
		for i, u := range a {
			for j := i + 1; j < len(a); j++ {
				v := a[j]
				if gcd(u, 2*v) > 1 {
					c++
				}
			}
		}
		fmt.Fprintln(out, c)

	}
}

func max(x, y int64) int64 {
	if x < y {
		return y
	}
	return x
}

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

package main

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

)

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(){

		var n int

		fmt.Fscan(in , &n)

		arr  := make([]int,n)

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

		}

		count := 0

		arr = ArrayReorder(arr)

		for i := 0 ; i < n ; i++{
			for j := i+1 ; j < len(arr);j++{

				if GCD(arr[i] , 2 * arr[j]) > 1{
						count++
				}

			}
		}

		fmt.Fprintln(out , count)
	}

	T := 1

	fmt.Fscan(in ,&T)

	for o := 0 ; o < T ; o++{
		solve()
	}
}

func ArrayReorder(arr []int)[]int{

 sort.Slice(arr , func(a , b int) bool{

 	return arr[a] & 1 == 0   // even and odd sort
 })
 	return arr
}

func GCD(a , b int)int{

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

	return b
}

func main(){

	run(os.Stdin , os.Stdout)
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i]&1 == 0
		})
		c:=0
		for l, v := range a {
			for r := l + 1; r < len(a); r++ {
				w := a[r]
				if gcd(v,w*2) > 1 {
					c++
				}
			}
		}
		Fprintln(out, c)
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

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

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

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

package main

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

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

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

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

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

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

		var c int
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if gcd(arr[i], 2*arr[j]) > 1 {
					c++
				}
			}
		}
		fmt.Fprintln(out, c)
	}
}

package main

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

/*

 */

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

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

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

		a := make([]int, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		for i, j := 0, n-1; i < j; i++ {
			for j >= 0 && a[j]%2 != 0 {
				j--
			}

			if j < 0 {
				break
			}

			if a[i]%2 != 0 {
				a[i], a[j] = a[j], a[i]
			}
		}

		cnt := 0

		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if (gcd(a[i], 2*a[j])) > 1 {
					cnt++
				}
			}
		}

		fmt.Fprintln(writer, cnt)
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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


// 109A-mic
package main

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

func main() {
    z := bufio.NewWriter(os.Stdout)
    var f, s, i, n int
    fmt.Scan(&n)
    for n > 0 {
        if n%7 != 0 {
            n -= 4
            f++

        } else {
            s += n / 7
            n = 0
        }
    }
    if n < 0 {
        fmt.Println("-1")
        return
    }
    for i = 0; i < f; i++ {
        z.WriteRune('4')
        z.Flush()
    }
    for i = 0; i < s; i++ {
        z.WriteRune('7')
        z.Flush()
    }
    fmt.Println()
}

//https://codeforces.com/contest/110/problem/C

package main

import (
	"bytes"
	"fmt"
)

func main() {
	var n int
	_, err := fmt.Scan(&n)
	if err != nil {
		fmt.Println(err)
	} else {
		sliceResult := findComposedLuckyNumbers(n)
		fmt.Print(sliceResult)
	}
}

func findComposedLuckyNumbers(x int) string {
	if x%4 == 0 {
		xIn4 := x / 4
		return buildNumberSequence(xIn4, 0)
	}

	if x%7 == 0 {
		xIn7 := x / 7
		return buildNumberSequence(0, xIn7)
	}

	xIn7 := 0
	for x > 7 {
		x -= 7
		xIn7++
		if x%4 == 0 {
			xIn4 := x / 4
			return buildNumberSequence(xIn4, xIn7)
		}
	}
	return "-1"
}

func buildNumberSequence(xIn4 int, xIn7 int) string {
	for xIn4 >= 7 {
		xIn7 += 4
		xIn4 -= 7
	}

	var result bytes.Buffer

	i := 0
	for ; i < xIn4; i++ {
		result.WriteString("4")
	}

	for ; i < xIn4+xIn7; i++ {
		result.WriteString("7")
	}

	return result.String()
}

package main
import (
	"fmt"
	"bufio"
	"os"
	//"strconv"
)
func main() {
	var n,x int
	out := bufio.NewWriter(os.Stdout)
	fmt.Scan(&n)
	flag:=false
	for s:=0;s<=n;s+=4 {
		x=n-s
		if x%7==0 {
			flag=true
			for i:=s/4;i>0;i-- {
				out.WriteRune('4')
			}
			for k:=x/7;k>0;k-- {
				out.WriteRune('7')
			}
			break
		}
	}
	if flag==false {
		out.WriteString("-1")
	}
	out.Flush()
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    n7 := n/7
    n %= 7
    for (n7 > 0) && (n%4 != 0) {
        n7--
        n += 7
    }
    if n%4 == 0 {
        n4 := n/4
        for ; n4 > 0; n4-- { writer.WriteRune('4') }
        for ; n7 > 0; n7-- { writer.WriteRune('7') }
    } else {
        writer.WriteString("-1")
    }
    writer.WriteRune('\n')
    writer.Flush()
}

package main
import (
	"fmt"
	"bufio"
	"os"
	//"strconv"
)
func main() {
	var n,x int
	out := bufio.NewWriter(os.Stdout)
	fmt.Scan(&n)
	flag:=false
	for s:=0;s<=n;s+=4 {
		x=n-s
		if x%7==0 {
			flag=true
			for i:=s/4;i>0;i-- {
				out.WriteRune('4')
			}
			for k:=x/7;k>0;k-- {
				out.WriteRune('7')
			}
		}
	}
	if flag==false {
		out.WriteString("-1")
	}
	out.Flush()
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    if (n%4)%7 == 0 {
        n4, n7 := n/4, (n%4)/7
        for ; n4 > 0; n4-- { writer.WriteRune('4') }
        for ; n7 > 0; n7-- { writer.WriteRune('7') }
    } else if (n%7)%4 == 0 {
        n4, n7 := (n%7)/4, n/7
        for ; n4 > 0; n4-- { writer.WriteRune('4') }
        for ; n7 > 0; n7-- { writer.WriteRune('7') }
    } else {
        writer.WriteString("-1")
    }
    writer.WriteRune('\n')
    writer.Flush()
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    if (n%4)%7 == 0 {
        n4, n7 := n/4, (n%4)/7
        n7 += (n4/7)*4
        n4 %= 7
        for ; n4 > 0; n4-- { writer.WriteRune('4') }
        for ; n7 > 0; n7-- { writer.WriteRune('7') }
    } else if (n%7)%4 == 0 {
        n4, n7 := (n%7)/4, n/7
        for ; n4 > 0; n4-- { writer.WriteRune('4') }
        for ; n7 > 0; n7-- { writer.WriteRune('7') }
    } else {
        writer.WriteString("-1")
    }
    writer.WriteRune('\n')
    writer.Flush()
}

// 109A-mic
package main

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

func main() {
    z := bufio.NewWriter(os.Stdout)
    var f, s, i, n int
    fmt.Scan(&n)
    for n > 0 {
        if n%7 == 1 {
            n -= 4
            f++
        } else {
            s += n / 7
            n = 0
        }
    }
    if n < 0 {
        fmt.Println("-1")
        return
    }
    for i = 0; i < f; i++ {
        z.WriteRune('4')
    }
    for i = 0; i < s; i++ {
        z.WriteRune('7')
    }
    fmt.Println()
}

package main

import (
	"fmt"
)

func main() {
	var n int
	_, err := fmt.Scan(&n)
	if err != nil {
		fmt.Println(err)
	} else {
		sliceResult := findLuckyNumbers(n)
		for i := 0; i < len(sliceResult); i++ {
			fmt.Print(sliceResult[i])
		}
	}
}

func findLuckyNumbers(x int) []int {
	//Number formed by sums of n-seq of 4's AND s-seq of 7's
	slice4 := []int{}
	slice7 := []int{}
	for {
		slice4 = genNextSequenceValue(slice4, 4, 7)
		digitsSum := sumDigits(slice4)
		if int64(x) == digitsSum {
			return slice4
		}
		if digitsSum > int64(x) {
			break
		}
	}

	for {
		slice7 = genNextSequenceValue(slice7, 7, 4)
		digitsSum := sumDigits(slice7)
		if int64(x) == digitsSum {
			return slice7
		}
		if digitsSum > int64(x) {
			return []int{-1}
		}
	}
}

func genNextSequenceValue(sliceNumber []int, prefix int, suffix int) []int {
	sliceNumberLen := len(sliceNumber)
	if sliceNumberLen == 0 {
		return []int{prefix}
	}
	lastItem := sliceNumber[sliceNumberLen-1]
	if lastItem == prefix {
		sliceNumber[sliceNumberLen-1] = suffix
	} else {
		sliceNumber[sliceNumberLen-1] = prefix
		sliceNumber = append(sliceNumber, prefix)
	}
	return sliceNumber
}

func sumDigits(sliceNumber []int) (sum int64) {
	sliceSize := len(sliceNumber)
	for i := 0; i < sliceSize; i++ {
		sum += int64(sliceNumber[i])
	}
	return sum
}


package main

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

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

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

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

func main() {
	var t int
	scanf("%d\n", &t)
	for t > 0 {
		var n, m int
		scanf("%d %d\n", &n, &m)
		sum, a := 0, 0
		for i := 0; i < n; i++ {
			scanf("%d", &a)
			sum += a
		}
		if sum > m {
			sum = m
		}
		printf("%d\n", sum)
		scanf("\n")
		t--
	}
	writer.Flush()
}

package main

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

func readInts(scanner *bufio.Scanner, n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		t := scanner.Text()
		x, _ := strconv.Atoi(t)
		ret[i] = x
	}
	return ret
}

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

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	for i := 0; i < cases; i++ {
		a := readInts(scanner, 2)
		n, m := a[0], a[1]

		sum := 0
		a = readInts(scanner, n)
		for i := 0; i < n; i++ {
			sum += a[i]
		}
		if sum > m {
			fmt.Println(m)
		} else {
			fmt.Println(sum)
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		sum := 0
		tmp := 0
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &tmp)
			sum += tmp
		}
		fmt.Fscanf(in, "\n")
		if sum > m {
			sum = m
		}
		fmt.Fprintf(out, "%d\n", sum)
	}
	return
}

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

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 10010)

	T := NextInt()
	a := make([]int, 20000)

	for t := 0; t < T; t++ {
		n := NextInt()
		m := NextInt()
		var sum int
		for i := 0; i < n; i++ {
			a[i] = NextInt()
			sum += a[i]
		}
		if sum > m {
			sum = m
		}
		fmt.Fprintln(out, sum)
	}
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		arrs := strings.Split(string(line), " ")
		n, _ := strconv.ParseInt(arrs[0], 10, 64)
		m, _ := strconv.ParseInt(arrs[1], 10, 64)
		line = readLine(reader)
		arrs = strings.Split(string(line), " ")
		sum := int64(0)
		for i := int64(0); i < n; i++ {
			x, _ := strconv.ParseInt(arrs[i], 10, 64)
			sum += x
		}
		if sum >= m {
			fmt.Println(m)
		} else {
			fmt.Println(sum)
		}
	}
}

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 (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	for testcases := readInt(); testcases > 0; testcases-- {
		n, m := readInt(), readInt()
		a := readarray(n)

		total := int64(0)
		for i := 0; i < n; i++ {
			total += a[i]
		}
		x := minimum(total, int64(m))
		fmt.Println(x)
	}
}

var in *bufio.Scanner
func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
}

func ScanWord() string { in.Scan(); return in.Text() }
func readInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func min_max(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func minimum(args ...int64) int64 { mn, _ := min_max(args...); return mn }
func readarray(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		a := ScanInt64Slice(n)

		sum := int64(0)
		for i := 0; i < n; i++ {
			sum += a[i]
		}
		P(Mn(sum, int64(m)))
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

var a[2000] int
func main() {
	for t:=ReadInt();t>0;t-- {
		var sum int =0
		n:=ReadInt()
		m:=ReadInt()
		for i:=1;i<=n;i++ {
			a[i] = ReadInt();
			sum += a[i]
		}
		if sum>=m {
			fmt.Println(m)
		} else {
			fmt.Println(sum)
		}
	}
}

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

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

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

func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.ParseInt(intStr, 10, 32)
	return int(i)
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

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

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

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

package main

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

func main() {

	for t := scanInt(); t > 0; t-- {
		n, m := scanInt(), scanInt()
		givenArray := scanIntSlice(n)
		sum := 0
		for i := 0; i < n; i ++{
			sum += givenArray[i]
		}

		fmt.Println(min(sum, m))
	}

	close(channelType)
	oWg.Wait()
}

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

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if (a == 0) {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}
func min(args ...int) int { mn, _ := MnMx(args...); return mn }
func max(args ...int) int { _, mx := MnMx(args...); return mx }
func MnMx(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}

package main

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

func main() {
	var t, n, m, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &m)
		sum := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			sum += a
		}
		fmt.Println(min(sum, m))
	}
}

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

// A. Grade Allocation
/*
𝑛 students are taking an exam. The highest possible score at this exam is 𝑚. Let 𝑎𝑖 be the score of the 𝑖-th student. You have access to the school database which stores the results of all students.

You can change each student's score as long as the following conditions are satisfied:

    All scores are integers
    0≤𝑎𝑖≤𝑚
   	The average score of the class doesn't change.

You are student 1 and you would like to maximize your own score.

Find the highest possible score you can assign to yourself such that all conditions are satisfied.

Input
Each test contains multiple test cases.

The first line contains the number of test cases 𝑡 (1≤𝑡≤200). The description of the test cases follows.

The first line of each test case contains two integers 𝑛 and 𝑚 (1≤𝑛≤103, 1≤𝑚≤105)  — the number of students and the highest possible score respectively.

The second line of each testcase contains 𝑛 integers 𝑎1,𝑎2,…,𝑎𝑛 (0≤𝑎𝑖≤𝑚)  — scores of the students.

Output
For each testcase, output one integer  — the highest possible score you can assign to yourself such that both conditions are satisfied._

Example
Input
2
4 10
1 2 3 4
4 5
1 2 3 4

Output
10
5

Note
In the first case, 𝑎=[1,2,3,4], with average of 2.5. You can change array 𝑎 to [10,0,0,0]. Average remains 2.5, and all conditions are satisfied.

In the second case, 0≤𝑎𝑖≤5. You can change 𝑎 to [5,1,1,3]. You cannot increase 𝑎1 further as it will violate condition 0≤𝑎𝑖≤𝑚.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(strings.TrimSpace(input1))

	for ; t > 0; t-- {
		input2, _ := reader.ReadString('\n')
		arr1 := strings.Split(strings.TrimSpace(input2), " ")
		n, _ := strconv.Atoi(arr1[0])
		m, _ := strconv.Atoi(arr1[1])

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

		s := 0
		for i := 0; i < n; i++ {
			j, _ := strconv.Atoi(arr2[i])
			s += j

			if s > m {
				s = m
				break
			}
		}
		fmt.Println(s)

	}
}

package main

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

func main() {

	t := ScanInt()
	for ; t > 0; t-- {
		n := ScanInt()
		m := ScanInt64()
		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			arr[i] = ScanInt64()
		}
		m -= arr[0]
		for i := 1; i < n; i++ {
			min := Minimum(arr[i], m)
			m -= min
			arr[0] += min
		}
		fmt.Println(arr[0])

	}
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args []int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args []int64) int64 { mn, _ := MnMx(args); return mn }
func Mx(args []int64) int64 { _, mx := MnMx(args); return mx }
func LCM(a, b int64) int64  { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}
func MinimumMaximum(a, b int64) (int64, int64) {
	if a < b {
		return a, b
	}
	return b, a

}
func Minimum(a, b int64) int64 {
	min, _ := MinimumMaximum(a, b)
	return min

}
func Maximum(a, b int64) int64 {
	_, max := MinimumMaximum(a, b)
	return max

}

package main

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

func main() {
	t := scanInt()
	for ; t > 0; t-- {
		n , m := scanInt(), scanInt()
		arr := scanIntSlice(n)
		total := 0
		for _, value := range arr {
			total += value
		}
		_, _ = printFmt(min(total, m))
	}
}
/*********************** I/O ***********************/

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if a == 0 {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}
func min(args ...int) int { mn, _ := MnMx(args...); return mn }
func max(args ...int) int { _, mx := MnMx(args...); return mx }
func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}

package main

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

func main() {
	var t, n, m, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &m)
		sum := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			sum += a
			fmt.Println(min(sum, m))
		}
	}
}

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 scanf(f string, a ...interface{}) {
	fmt.Fscanf(reader, f, a...)
}

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

func main() {
	var t int
	scanf("%d\n", &t)
	for t > 0 {
		var n, m int
		scanf("%d %d\n", &n, &m)
		sum, a := 0, 0
		for i := 0; i < n; i++ {
			scanf("%d ", &a)
			sum += a
		}
		if sum > m {
			sum = m
		}
		printf("%d\n", sum)
		t--
	}
	writer.Flush()
}

package main

import (
	"fmt"
)

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

	for i := 0; i < cases; i++ {
		var n, m int
		fmt.Scan(&n, &m)
		sum := 0
		for i := 0; i < n; i++ {
			var x int
			fmt.Scan(&x)
			sum += x
		}
		if sum > m {
			fmt.Println(m)
		} else {
			fmt.Println(m)
		}
	}
}


package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	A := sc.NextIntArray()

	P := K
	ans := make([]int, N)
	for i, v := range A {
		if P > v {
			P -= v
			ans[i] = 0
		} else {
			T := P - v
			ans[i] += -(T / K) + 1
			T %= K
			P = T + ((-T/K)+1)*K
		}
	}

	PrintI(ans...)
}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	rdr := bufio.NewReader(os.Stdin)
	var n, m, a, s int
	var t []string
	fmt.Fscan(rdr, &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscan(rdr, &a)
		s += a
		t = append(t, strconv.Itoa(s/m))
		s %= m
	}
	fmt.Println(strings.Join(t, " "))
}

package main

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

func main() {
	rdr := bufio.NewReader(os.Stdin)
	wrt := bufio.NewWriter(os.Stdout)
	var n, m, a, s int
	var t []string
	fmt.Fscan(rdr, &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscan(rdr, &a)
		s += a
		t = append(t, strconv.Itoa(s/m))
		s %= m
	}
	fmt.Fprint(wrt, strings.Join(t, " "))
	wrt.Flush()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var n int
	var m, x int64
	fmt.Fscan(in, &n, &m)
	var sum int64 = 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		sum += x
		fmt.Fprint(out, sum / m - (sum - x) / m, " ")
	}
	out.Flush()
}

package main

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

func main() {

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

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

	var sum int
	for i := 0; i < n; i++ {
		var a int
		fmt.Fscanf(in, "%d ", &a)
		sum += a
		fmt.Fprintf(out, "%d ", sum / m)
		sum %= m
	}

}

package main

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

func main() {
	var n, m int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

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

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

	pos := 1
	for i := 1; i <= n; i++ {
		scanner.Scan()
		a[i], _ = strconv.Atoi(scanner.Text())

		count := (int)(a[i] / m)
		if (a[i] % m) >= (m - pos + 1) {
			count++
		}
		if i > 1 {
			fmt.Printf(" %d", count)
		} else {
			fmt.Printf("%d", count)
		}
		pos = (pos + a[i]) % m
		if pos == 0 {
			pos = m
		}
	}
	fmt.Println()
}

package main

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

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

	var n, l,a int
	Fscan(in, &n, &l)

	sum := 0
	var ans []interface{}
	for n>0{
		n--
		Fscan(in, &a)

		sum+=a
		ans = append(ans, sum/l)
		sum%=l
	}
	Fprintln(out, ans...)
}

package main

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

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

	var n, l, a int
	Fscan(in, &n, &l)

	sum := 0
	var ans []int
	for n > 0 {
		n--
		Fscan(in, &a)

		sum += a
		ans = append(ans, sum/l)
		sum %= l
	}

	for _, a := range ans {
		Fprint(out, a, " ")
	}
}

package main

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

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

	var n, l, a int
	Fscan(in, &n, &l)

	sum := 0
	ans := make([]int, 0, n)
	for n > 0 {
		n--
		Fscan(in, &a)

		sum += a
		ans = append(ans, sum/l)
		sum %= l
	}

	for _, a := range ans {
		Fprint(out, a, " ")
	}
}

package main

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

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	defer Flush()

	n := readi()
	m := readll()
	t := make([]int64, n)
	for i := range t {
		t[i] = readll()
	}
	cur := int64(0)
	sp := ""
	for _, v := range t {
		p := int64(0)
		cur += v
		p += cur / m
		cur = cur % m
		printf("%s%d", sp, p)
		sp = " "
	}
	println()

}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"

func main() {
	var n, m int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	line := scanner.Text()
	elems := strings.Split(line, " ")
	n, _ = strconv.Atoi(elems[0])
	m, _ = strconv.Atoi(elems[1])
	//fmt.Scanf("%d%d", &n, &m)
	a := make([]int, n+1)

	//scanner.Scan()
	//line = scanner.Text()
	//elems = strings.Split(line, " ")
	pos := 1
	for i:=1; i<=n; i++ {
		//fmt.Println()
		//fmt.Println(i, pos)
		fmt.Scan(&a[i])
		//a[i], _ = strconv.Atoi(elems[i-1])
		count := (int)(a[i] / m)
		if (a[i] % m) >= (m-pos+1) {
			count++
		}
		if i>1 {
			fmt.Printf(" %d", count)
		} else {
			fmt.Printf("%d", count)
		}
		pos = (pos + a[i]) % m
		if pos == 0 {
			pos = m
		}
	}
	fmt.Println()
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d%d", &n, &m)
	a := make([]int, n+1)

	pos := 1
	for i := 1; i <= n; i++ {
		//fmt.Println()
		//fmt.Println(i, pos)
		fmt.Scanf("%d", &a[i])
		count := (int)(a[i] / m)
		if (a[i] % m) >= (m - pos + 1) {
			count++
		}
		if i > 1 {
			fmt.Printf(" %d", count)
		} else {
			fmt.Printf("%d", count)
		}
		pos = (pos + a[i]) % m
		if pos == 0 {
			pos = m
		}
	}
	fmt.Println()
}

/*package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"

func main() {
	var n, m int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	line := scanner.Text()
	elems := strings.Split(line, " ")
	n, _ = strconv.Atoi(elems[0])
	m, _ = strconv.Atoi(elems[1])
	strconv.
	//fmt.Scan(&n, &m)
	a := make([]int, n+1)

	scanner.Scan()
	line = scanner.Text()
	index := 0
	length := len(line)
	pos := 1
	for i:=1; i<=n; i++ {
		//fmt.Println()
		//fmt.Println(i, pos)
		//fmt.Scan(&a[i])
		//a[i], _ = strconv.Atoi(elems[i-1])
		bytearray := []byte{}
		for index < length && line[index] == ' ' {
			index++
		}
		for index < length && line[index] != ' ' {
			bytearray = append(bytearray, line[index])
			index++
		}
		//fmt.Println(i)
		a[i], _ = strconv.Atoi(string(bytearray))
		//xxx, _ := binary.ReadVarint(buf)
		//a[i] = int(xxx)
		//fmt.Println(a[i])

		count := (int)(a[i] / m)
		if (a[i] % m) >= (m-pos+1) {
			count++
		}
		if i>1 {
			fmt.Printf(" %d", count)
		} else {
			fmt.Printf("%d", count)
		}
		pos = (pos + a[i]) % m
		if pos == 0 {
			pos = m
		}
	}
	fmt.Println()
}*/

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d%d", &n, &m)
	a := make([]int, n+1)

	pos := 1
	for i:=1; i<=n; i++ {
		//fmt.Println()
		//fmt.Println(i, pos)
		fmt.Scanf("%d", &a[i])
		count := (int)(a[i] / m)
		if (a[i] % m) >= (m-pos+1) {
			count++
		}
		if i>1 {
			fmt.Printf(" %d", count)
		} else {
			fmt.Printf("%d", count)
		}
		pos = (pos + a[i]) % m
		if pos == 0 {
			pos = m
		}
	}
	fmt.Println()
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"

func main() {
	var n, m int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	line := scanner.Text()
	elems := strings.Split(line, " ")
	n, _ = strconv.Atoi(elems[0])
	m, _ = strconv.Atoi(elems[1])
	//fmt.Scan(&n, &m)
	a := make([]int, n+1)

	scanner.Scan()
	line = scanner.Text()
	index := 0
	length := len(line)
	pos := 1
	for i:=1; i<=n; i++ {
		//fmt.Println()
		//fmt.Println(i, pos)
		//fmt.Scan(&a[i])
		//a[i], _ = strconv.Atoi(elems[i-1])
		bytearray := []byte{}
		for index < length && line[index] == ' ' {
			index++
		}
		for index < length && line[index] != ' ' {
			bytearray = append(bytearray, line[index])
			index++
		}
		//fmt.Println(i)
		a[i], _ = strconv.Atoi(string(bytearray))
		//xxx, _ := binary.ReadVarint(buf)
		//a[i] = int(xxx)
		//fmt.Println(a[i])

		count := (int)(a[i] / m)
		if (a[i] % m) >= (m-pos+1) {
			count++
		}
		if i>1 {
			fmt.Printf(" %d", count)
		} else {
			fmt.Printf("%d", count)
		}
		pos = (pos + a[i]) % m
		if pos == 0 {
			pos = m
		}
	}
	fmt.Println()
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"

func main() {
	var n, m int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	line := scanner.Text()
	elems := strings.Split(line, " ")
	n, _ = strconv.Atoi(elems[0])
	m, _ = strconv.Atoi(elems[1])
	//fmt.Scan(&n, &m)
	a := make([]int, n+1)

	scanner.Scan()
	line = scanner.Text()
	index := 0
	length := len(line)
	pos := 1
	for i:=1; i<=n; i++ {
		//fmt.Println()
		//fmt.Println(i, pos)
		//fmt.Scan(&a[i])
		//a[i], _ = strconv.Atoi(elems[i-1])
		bytearray := []byte{}
		for index < length && line[index] != ' ' {
			bytearray = append(bytearray, line[index])
			index++
		}
		index++
		//fmt.Println(i)
		a[i], _ = strconv.Atoi(string(bytearray))
		//xxx, _ := binary.ReadVarint(buf)
		//a[i] = int(xxx)
		//fmt.Println(a[i])

		count := (int)(a[i] / m)
		if (a[i] % m) >= (m-pos+1) {
			count++
		}
		if i>1 {
			fmt.Printf(" %d", count)
		} else {
			fmt.Printf("%d", count)
		}
		pos = (pos + a[i]) % m
		if pos == 0 {
			pos = m
		}
	}
	fmt.Println()
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d%d", &n, &m)
	a := make([]int, n+1)

	pos := 1
	for i:=1; i<=n; i++ {
		//fmt.Println()
		//fmt.Println(i, pos)
		fmt.Scanf("%d", &a[i])
		count := (int)(a[i] / m)
		if (a[i] % m) >= (m-pos+1) {
			count++
		}
		if i>1 {
			fmt.Printf(" %d", count)
		} else {
			fmt.Printf("%d", count)
		}
		pos = (pos + a[i]) % m
		if pos == 0 {
			pos = m
		}
	}
	//fmt.Println()
}


package main

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

func main() {
	// imulateInput()

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

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

	sort.Ints(heights)
	res := make([]string, n)
	i := 0
	j := n - 1
	for index, h := range heights {
		hStr := strconv.Itoa(h)
		if index%2 == 0 {
			res[i] = hStr
			i++
		} else {
			res[j] = hStr
			j--
		}
	}
	fmt.Println(strings.Join(res, " "))
}

func imulateInput() {
	file, err := os.OpenFile("input.txt", os.O_RDWR, 0644)
	if err != nil {
		panic(err)
	}
	os.Stdin = file
}

package main

import (
	"fmt"
	"sort"
)

var n int

func max(i, j int) int {
	if i > j {
		return i
	} else {
		return j
	}
}

func abs(i, j int) int {
	if i > j {
		return i - j
	} else {
		return j - i
	}
}

func check(a []int, diff int) bool {
	dp := make([][]bool, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				dp[i][t] = dp[i][t] || a[t] - a[j] <= diff
				dp[t][j] = dp[t][j] || a[t] - a[i] <= diff
			}
		}
	}

	if n == 2 {
		return true
	}

	for i := 0; i + 2 < n; i++ {
		if dp[i][n - 2] && a[n - 1] - a[i] <= diff && a[n - 1] - a[n - 2] <= diff {
			return true
		}
	}

	return false
}

func find_ans(a []int, diff int) []int {
	dp := make([][]bool, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				dp[i][t] = dp[i][t] || a[t] - a[j] <= diff
				dp[t][j] = dp[t][j] || a[t] - a[i] <= diff
			}
		}
	}

	other_index, index := -1, n - 2
	for i := 0; i + 2 < n; i++ {
		if dp[i][n - 2] && a[n - 1] - a[i] <= diff && a[n - 1] - a[n - 2] <= diff {
			other_index = i
		}
	}

	if n == 2 {
		return a
	}

	if other_index == -1 {
		panic("oiwejfew")
	}

	var res []int = make([]int, n)

	res[0], res[1], res[2] = a[other_index], a[n - 1], a[index]

	i, j := n - 1, 3

	var kt []bool = make([]bool, n)
	kt[index], kt[other_index] = true, true
	kt[n - 1] = true

	for t := n - 1; t >= 0; t-- {
		if kt[t] {
			continue
		}
		check_one := abs(a[index], a[t]) <= diff && index > t && dp[other_index][t]
		check_two := other_index > t && abs(a[other_index], a[t]) <= diff && dp[t][index]

		if (check_one && check_two && index > other_index) || !check_two {
			res[j] = a[t]
			j++
			index = t
		} else {
			res[i] = a[t]
			i--
			other_index = t
		}

		kt[t] = true
	}

	return res
}

func main() {
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range(a) {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	var low, high int = 0, 1000000000
	res := -1
	for low <= high {
		mid := (low + high) >> 1
		if check(a, mid) {
			res = mid
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	ans := find_ans(a, res)
	for i := range(ans) {
		fmt.Print(ans[i], " ")
	}
}

package main

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

type SA []int

func (s SA) Len() int {
	return len(s)
}

func (s SA) Swap(a, b int) {
	tmp := s[a]
	s[a] = s[b]
	s[b] = tmp
}
func (s SA) Less(i, j int) bool {
	if s[i] < s[j] {
		return true
	}
	return false
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	mat := make(SA, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &mat[i])
	}
	sort.Sort(mat)
	for i := 0; i < n; i += 2 {
		if i == 0{
			fmt.Printf("%d", mat[i])
		}else{
			fmt.Printf(" %d", mat[i])
		}

	}
	s := n - 1
	if (n & 1) == 1 {
		s--
	}
	for s > 0 {
		fmt.Printf(" %d", mat[s])
		s -= 2
	}
	fmt.Printf("\n")
}

/**
0 0
0 1
3
UDD
 */

package main

import (
	"fmt"
	"sort"
)

var n int

func max(i, j int) int {
	if i > j {
		return i
	} else {
		return j
	}
}

func abs(i, j int) int {
	if i > j {
		return i - j
	} else {
		return j - i
	}
}

func check(a []int, diff int) bool {
	dp := make([][]bool, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				dp[i][t] = dp[i][t] || a[t] - a[j] <= diff
				dp[t][j] = dp[t][j] || a[t] - a[i] <= diff
			}
		}
	}

	if n == 2 {
		return true
	}

	for i := 0; i + 2 < n; i++ {
		if dp[i][n - 2] && a[n - 1] - a[i] <= diff && a[n - 1] - a[n - 2] <= diff {
			return true
		}
	}

	return false
}

type trace struct  {
	other int
	here int
}

func find_ans(a []int, diff int) []int {
	dp := make([][]bool, n)
	traces := make([][]trace, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
		traces[i] = make([]trace, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				if a[t] - a[j] <= diff {
					dp[i][t] = true
					traces[i][t] = trace{ i, j }
				}
				if a[t] - a[i] <= diff {
					dp[t][j] = true
					traces[t][j] = trace { i, j }
				}
			}
		}
	}

	other_index, index := 0, n - 2
	for i := 0; i + 2 < n; i++ {
		if dp[i][n - 2] && a[n - 1] - a[i] <= diff && a[n - 1] - a[n - 2] <= diff {
			other_index = i
		}
	}

	if n == 2 {
		return a
	}

	var res []int = make([]int, n)

	res[0], res[1], res[2] = a[other_index], a[n - 1], a[index]

	i, j := n - 1, 3

	var kt []bool = make([]bool, n)
	for i := range(kt) {
		kt[i] = true
	}
	kt[index], kt[other_index] = false, false
	kt[n - 1] = false

	for t := n - 1; t >= 0; t-- {
		if !kt[t] {
			continue
		}
		if abs(a[index], a[t]) <= diff && dp[other_index][t] {
			res[j] = a[t]
			j++
			index = t
		} else {
			res[i] = a[t]
			i--
			other_index = t
		}

		kt[t] = false
	}

	return res
}

func main() {
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range(a) {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	var low, high int = 0, 1000000000
	res := -1
	for low <= high {
		mid := (low + high) >> 1
		if check(a, mid) {
			res = mid
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	ans := find_ans(a, res)
	for i := range(ans) {
		fmt.Print(ans[i], " ")
	}
}

package main

import (
	"fmt"
	"sort"
)

var n int

func max(i, j int) int {
	if i > j {
		return i
	} else {
		return j
	}
}

func abs(i, j int) int {
	if i > j {
		return i - j
	} else {
		return j - i
	}
}

func check(a []int, diff int) bool {
	dp := make([][]bool, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				dp[i][t] = dp[i][t] || a[t] - a[j] <= diff
				dp[t][j] = dp[t][j] || a[t] - a[i] <= diff
			}
		}
	}

	if n == 2 {
		return true
	}

	for i := 0; i + 2 < n; i++ {
		if dp[i][n - 2] && a[n - 1] - a[i] <= diff && a[n - 1] - a[n - 2] <= diff {
			return true
		}
	}

	return false
}

func find_ans(a []int, diff int) []int {
	dp := make([][]bool, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				if a[t] - a[j] <= diff {
					dp[i][t] = true
				}
				if a[t] - a[i] <= diff {
					dp[t][j] = true
				}
			}
		}
	}

	other_index, index := -1, n - 2
	for i := 0; i + 2 < n; i++ {
		if dp[i][n - 2] && a[n - 1] - a[i] <= diff && a[n - 1] - a[n - 2] <= diff {
			other_index = i
		}
	}

	if n == 2 {
		return a
	}

	if other_index == -1 {
		panic("oiwejfew")
	}

	var res []int = make([]int, n)

	res[0], res[1], res[2] = a[other_index], a[n - 1], a[index]

	i, j := n - 1, 3

	var kt []bool = make([]bool, n)
	for i := range(kt) {
		kt[i] = true
	}
	kt[index], kt[other_index] = false, false
	kt[n - 1] = false

	for t := n - 1; t >= 0; t-- {
		if !kt[t] {
			continue
		}
		if abs(a[index], a[t]) <= diff && index > t && dp[other_index][t] {
			res[j] = a[t]
			j++
			index = t
		} else {
			res[i] = a[t]
			i--
			other_index = t
		}

		kt[t] = false
	}

	return res
}

func main() {
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range(a) {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	var low, high int = 0, 1000000000
	res := -1
	for low <= high {
		mid := (low + high) >> 1
		if check(a, mid) {
			res = mid
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	ans := find_ans(a, res)
	for i := range(ans) {
		fmt.Print(ans[i], " ")
	}
}

package main

import (
	"fmt"
	"sort"
)

var n int

func max(i, j int) int {
	if i > j {
		return i
	} else {
		return j
	}
}

func abs(i, j int) int {
	if i > j {
		return i - j
	} else {
		return j - i
	}
}

func check(a []int, diff int) bool {
	dp := make([][]bool, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				dp[i][t] = dp[i][t] || a[t] - a[j] <= diff
				dp[t][j] = dp[t][j] || a[t] - a[i] <= diff
			}
		}
	}

	if n == 2 {
		return true
	}

	for i := 0; i + 2 < n; i++ {
		if dp[i][n - 2] && a[n - 1] - a[i] <= diff && a[n - 1] - a[n - 2] <= diff {
			return true
		}
	}

	return false
}

func find_ans(a []int, diff int) []int {
	dp := make([][]bool, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				dp[i][t] = dp[i][t] || a[t] - a[j] <= diff
				dp[t][j] = dp[t][j] || a[t] - a[i] <= diff
			}
		}
	}

	other_index, index := -1, n - 2
	for i := 0; i + 2 < n; i++ {
		if dp[i][n - 2] && a[n - 1] - a[i] <= diff && a[n - 1] - a[n - 2] <= diff {
			other_index = i
		}
	}

	if n == 2 {
		return a
	}

	if other_index == -1 {
		panic("oiwejfew")
	}

	var res []int = make([]int, n)

	res[0], res[1], res[2] = a[other_index], a[n - 1], a[index]

	i, j := n - 1, 3

	var kt []bool = make([]bool, n)
	kt[index], kt[other_index] = true, true
	kt[n - 1] = true

	for t := n - 1; t >= 0; t-- {
		if kt[t] {
			continue
		}
		check_one := abs(a[index], a[t]) <= diff && index > t && dp[other_index][t]
		check_two := other_index > t && abs(a[other_index], a[t]) <= diff && dp[t][index]

		if (check_one && check_two && index > other_index) || !check_two {
			res[j] = a[t]
			j++
			index = t
		} else {
			res[i] = a[t]
			i--
			other_index = t
		}

		kt[t] = true
	}

	return res
}

func main() {
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range(a) {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	var low, high int = 0, 1000000000
	res := -1
	for low <= high {
		mid := (low + high) >> 1
		if check(a, mid) {
			res = mid
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	fmt.Println(res)

	ans := find_ans(a, res)
	for i := range(ans) {
		fmt.Print(ans[i], " ")
	}
}

package main

import (
	"fmt"
	"sort"
)

var n int

func max(i, j int) int {
	if i > j {
		return i
	} else {
		return j
	}
}

func abs(i, j int) int {
	if i > j {
		return i - j
	} else {
		return j - i
	}
}

func check(a []int, diff int) bool {
	dp := make([][]bool, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				dp[i][t] = dp[i][t] || a[t] - a[j] <= diff
				dp[t][j] = dp[t][j] || a[t] - a[i] <= diff
			}
		}
	}

	for i := 0; i + 1 < n; i++ {
		if dp[i][n - 1] && a[n - 1] - a[i] <= diff {
			return true
		}
	}

	return false
}

type trace struct  {
	other int
	here int
}

func find_ans(a []int, diff int) []int {
	dp := make([][]bool, n)
	traces := make([][]trace, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
		traces[i] = make([]trace, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				if a[t] - a[j] <= diff {
					dp[i][t] = true
					traces[i][t] = trace{ i, j }
				}
				if a[t] - a[i] <= diff {
					dp[t][j] = true
					traces[t][j] = trace { i, j }
				}
			}
		}
	}

	other_index, index := 0, n - 1
	for i := 0; i + 1 < n; i++ {
		if dp[i][n - 1] && a[n - 1] - a[i] <= diff {
			other_index = i
		}
	}

	var res []int = make([]int, n)
	res[1], res[0] = a[other_index], a[index]
	i, j := n - 1, 2

	var kt []bool = make([]bool, n)
	for i := range(kt) {
		kt[i] = true
	}
	kt[index], kt[other_index] = false, false

	for t := n - 1; t >= 0; t-- {
		if !kt[t] {
			continue
		}
		if abs(a[index], a[t]) <= diff && dp[other_index][t] {
			res[i] = a[t]
			i--
			other_index = t
		} else {
			res[j] = a[t]
			j++
			index = t
		}

		kt[t] = false
	}

	return res
}

func main() {
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range(a) {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	var low, high int = 0, 1000000000
	res := -1
	for low <= high {
		mid := (low + high) >> 1
		if check(a, mid) {
			res = mid
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	ans := find_ans(a, res)
	for i := range(ans) {
		fmt.Print(ans[i], " ")
	}
}

package main

import (
	"fmt"
	"sort"
)

var n int

func max(i, j int) int {
	if i > j {
		return i
	} else {
		return j
	}
}

func abs(i, j int) int {
	if i > j {
		return i - j
	} else {
		return j - i
	}
}

func check(a []int, diff int) bool {
	dp := make([][]bool, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				dp[i][t] = dp[i][t] || a[t] - a[j] <= diff
				dp[t][j] = dp[t][j] || a[t] - a[i] <= diff
			}
		}
	}

	if n == 2 {
		return true
	}

	for i := 0; i + 2 < n; i++ {
		if dp[i][n - 2] && a[n - 1] - a[i] <= diff && a[n - 1] - a[n - 2] <= diff {
			return true
		}
	}

	return false
}

func find_ans(a []int, diff int) []int {
	dp := make([][]bool, n)
	for i := range(dp) {
		dp[i] = make([]bool, n)
	}

	dp[0][0] = true
	for i := 0; i + 1 < n; i++ {
		for j := 0; j + 1 < n; j++ {
			if dp[i][j] {
				t := max(i, j) + 1
				if a[t] - a[j] <= diff {
					dp[i][t] = true
				}
				if a[t] - a[i] <= diff {
					dp[t][j] = true
				}
			}
		}
	}

	other_index, index := -1, n - 2
	for i := 0; i + 2 < n; i++ {
		if dp[i][n - 2] && a[n - 1] - a[i] <= diff && a[n - 1] - a[n - 2] <= diff {
			other_index = i
		}
	}

	if n == 2 {
		return a
	}

	if other_index == -1 {
		panic("oiwejfew")
	}

	var res []int = make([]int, n)

	res[0], res[1], res[2] = a[other_index], a[n - 1], a[index]

	i, j := n - 1, 3

	var kt []bool = make([]bool, n)
	for i := range(kt) {
		kt[i] = true
	}
	kt[index], kt[other_index] = false, false
	kt[n - 1] = false

	for t := n - 1; t >= 0; t-- {
		if !kt[t] {
			continue
		}
		if abs(a[index], a[t]) <= diff && index >= t && dp[other_index][t] {
			res[j] = a[t]
			j++
			index = t
		} else {
			res[i] = a[t]
			i--
			other_index = t
		}

		kt[t] = false
	}

	return res
}

func main() {
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range(a) {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	var low, high int = 0, 1000000000
	res := -1
	for low <= high {
		mid := (low + high) >> 1
		if check(a, mid) {
			res = mid
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	ans := find_ans(a, res)
	for i := range(ans) {
		fmt.Print(ans[i], " ")
	}
}


package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"strings"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func ReadString() string {
	scanner.Scan()
	return scanner.Text()
}

func PrintInts(ints ...int) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		writer.WriteByte(' ')
	}
}
func PrintStrings(strs ...string) {
	for _, value := range strs {
		writer.WriteString(value)
		writer.WriteByte(' ')
	}
}

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	n,m := ReadInt32(),ReadInt32()
	d := make(map[string]string)
	for i := 0; i< m;i++ {
		a,b := ReadString(),ReadString()
		if len(a)> len(b) {
			d[a] = b
			d[b] = b
		} else {
			d[a] = a
			d[b] = a
		}
	}
	s := make([]string,n)
	for i :=0;i<n;i++ {
		s[i] = d[ReadString()]
	}
	fmt.Println(strings.Join(s," "))
}

package main

import (
    "fmt"
    //"strings"
)

func main() {
    var n,m int = 0,0
    var a,b string
    s:=""
    ma:=make(map[string]string, 3005)
    fmt.Scan(&n, &m)
    for i:=0;i<m;i++{
        fmt.Scan(&a, &b)
        ma[a]=b
    }
    for key, value := range ma {
        if len(key)<=len(value){
             ma[key]=key
        }
    }
    for i:=0;i<n;i++{
        fmt.Scan(&s)
        fmt.Print(ma[s]+" ")
    }
    fmt.Print("\n")
}

package main

import (
    "fmt"
    //"strings"
)

func main() {
    var n,m int = 0,0
    var a,b [3100]string
    s:=""
    ma:=make(map[string]string, 3100)
    fmt.Scan(&n, &m)
    for i:=0;i<m;i++{
        fmt.Scan(&a[i], &b[i])
    }
    for i:=0;i<m;i++{
        if len(a[i])<=len(b[i]){
             ma[a[i]]=a[i]
        } else {
            ma[a[i]]=b[i]
        }
    }
    for i:=0;i<n;i++{
        fmt.Scan(&s)
        fmt.Print(ma[s]+" ")
    }
    fmt.Print("\n")
}

package main

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

    dict := make(map[string] string)
    for i := 0; i < m; i++ {
        var sa, sb string
        fmt.Scan(&sa, &sb)
        if len(sb) < len(sa) {
            dict[sa] = sb
        } else {
            dict[sa] = sa
        }
    }

    for i := 0; i < n; i++ {
        var tmp string
        fmt.Scan(&tmp)
        fmt.Print(dict[tmp])
        if i != n {
            fmt.Print(" ")
        }
    }
    fmt.Println()
}

package main

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

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

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

	n, m := nextInt(), nextInt()
	languages := make(map[string]string)

	for i := 0; i < m; i++ {
		languages[next()] = next()
	}

	for ; n > 0; n-- {
		word := next()

		if len(word) <= len(languages[word]) {
			println(word)
		} else {
			println(languages[word])
		}
	}
}

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

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

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

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

package main

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

func main() {
	var n, m int
	fmt.Scanf("%d %d \n", &n, &m)
	obj := make(map[string]string)

	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < m; i++ {
		scanner.Scan()
		line := scanner.Text()
		list := strings.Split(line, " ")
		key := list[0]
		value := list[1]
		if len(value) >= len(key) {
			value = key
		}
		obj[key] = value
	}
	scanner.Scan()
	line := scanner.Text()
	list := strings.Split(line, " ")
	for index, value := range list {
		list[index] = obj[value]
	}
	fmt.Println(strings.Join(list, " "))
}

package main

import (
	"bytes"
	"fmt"
)

var (
	n       int
	m       int
	dict    map[string]string
	lecture []string
	result  string
)

func in() {
	dict = make(map[string]string)

	fmt.Scanf("%d %d\n", &n, &m)
	for i := 0; i < m; i++ {
		var lang1, lang2 string
		fmt.Scan(&lang1)
		fmt.Scan(&lang2)
		if len(lang2) < len(lang1) {
			dict[lang1] = lang2
		}
	}

	lecture = make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&lecture[i])
	}
}

func out() {
	fmt.Println(result)
}

func run() {
	var buffer bytes.Buffer
	for i, word := range lecture {
		if i > 0 {
			buffer.WriteString(" ")
		}
		if v, ok := dict[word]; ok {
			buffer.WriteString(v)
		} else {
			buffer.WriteString(word)
		}
	}
	result = buffer.String()
}

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

package main

import (
	"fmt"
)

func main() {
	var n, m int
	var a, b string
	d := make(map[string]string)

	fmt.Scan(&n, &m)

	for i := 0; i < m; i++ {
		fmt.Scan(&a, &b)
		if len(a) > len(b) {
			d[a] = b
		} else {
			d[a] = a
		}
	}

	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		fmt.Print(d[a])
		if i < n-1 {
			fmt.Print(" ")
		} else {
			fmt.Println()
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var m, n int
	fmt.Fscanln(reader, &m, &n)
	//fmt.Println(m, n)
	lecture := make(map[string]string, 2*n)
	for i := 0; i < n; i++ {
		var a, b string
		fmt.Fscanln(reader, &a, &b)
		//fmt.Println(a, b)
		if len(a) <= len(b) {
			lecture[a] = a
			lecture[b] = a
		} else {
			lecture[a] = b
			lecture[b] = b
		}
	}
	//fmt.Println(lecture)
	note := make([]string, m)
	for i := 0; i < m; i++ {
		fmt.Fscan(reader, &note[i])
	}
	fmt.Fscanln(reader)
	//fmt.Println(note)
	for i := 0; i < m-1; i++ {
		fmt.Print(lecture[note[i]], " ")
	}
	fmt.Println(lecture[note[m-1]])
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	dict := make(map[string]string)
	for i := 0; i < m; i++ {
		var l1, l2 string
		fmt.Scan(&l1, &l2)
		s := l1
		if len(l2) < len(l1) {
			s = l2
		}
		dict[l1] = s
		dict[l2] = s
	}
	for i := 0; i < n; i++ {
		var w string
		fmt.Scan(&w)
		fmt.Print(dict[w])
		if i < n-1 {
			fmt.Print(" ")
		}
	}
	fmt.Println()
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	dic := make(map[string]string)
	for i := 0; i < m; i++ {
		var a, b string
		fmt.Scan(&a, &b)
		if len(b) < len(a) {
			dic[a] = b
		} else {
			dic[a] = a
		}
	}

	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(dic[s])
	}
	fmt.Println()
}

package main

import (
	"fmt"
	"strings"
)

type WordData struct {
	word     string
	position int
}

type Storage map[string]WordData

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

	words := make(Storage)

	var langOne string
	var langTwo string

	for i := 0; i < m; i++ {
		fmt.Scanln(&langOne, &langTwo)
		a := WordData{word: langOne, position: 1}
		b := WordData{word: langTwo, position: 2}
		words[a.word] = b
		words[b.word] = a
	}
	var translate string
	output := ""
	for i := 0; i < n; i++ {
		fmt.Scanf("%s", &translate)
		temp1 := words[translate]
		if len(temp1.word) > len(words[temp1.word].word) {
			output = output + " " + words[temp1.word].word
		} else if len(temp1.word) == len(words[temp1.word].word) {
			if temp1.position == 1 {
				output = output + " " + temp1.word
			} else {
				output = output + " " + words[temp1.word].word
			}
		} else {
			output = output + " " + temp1.word
		}
	}
	fmt.Printf("%s", strings.TrimSpace(output))
}

package main

import (
    "fmt"
    )

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

    mm := make(map[string]string)
    for i := 0; i < m; i++ {
        var org, dst string
        fmt.Scan(&org)
        fmt.Scan(&dst)
        mm[org] = dst
    }

    result := ""
    for i := 0; i < n; i++ {
        var str string
        fmt.Scan(&str)
        if len(mm[str]) < len(str) {
            result += mm[str]
        } else {
            result += str
        }
        if i != n-1 {
            result += " "
        }
    }

    fmt.Println(result)
}

package main

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

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

type WordInfo struct {
	Word string
	IsFirst bool
}

func main() {

	reader := bufio.NewReader(os.Stdin)
	line, _ := Readln(reader)

	var nLectureWords, nDictionaryWords int
	fmt.Sscanf(line, "%d %d\n", &nLectureWords, &nDictionaryWords)

	dict := make(map[string]WordInfo)
	for i := 0; i < nDictionaryWords; i++ {

		line, _ := Readln(reader)
		var word1, word2 string
		fmt.Sscanf(line, "%s %s\n", &word1, &word2)
		dict[word1] = WordInfo{Word:word2, IsFirst: false}
		dict[word2] = WordInfo{Word:word1, IsFirst: true}
	}

	line, _ = Readln(reader)
	lectureWords := strings.Split(line, " ")
	sep := ""
	for i := 0; i < nLectureWords; i++ {
		word1 := lectureWords[i]
		word2Info := dict[word1]

		fmt.Print(sep)

		if len(word1) < len(word2Info.Word){
			fmt.Print(word1)
		} else if len(word1) == len(word2Info.Word) {
			if word2Info.IsFirst {
				fmt.Print(word2Info.Word)
			} else {
				fmt.Print(word1)
			}
		} else {
			fmt.Print(word2Info.Word)
		}

		if i == 0 {
			sep = " "
		}
	}
}

package main

import (
	"fmt"
	// "math"
	// "sort"
	// "strings"

)

func main() {
	var lecture, count int
	fmt.Scan(&lecture, &count)

	words := make(map[string]string)
	for i := 0; i < count; i++ {
		var x, y string
		fmt.Scan(&x, &y)

		if len(x) > len(y) {
			words[x] = y
		} else {
			words[x] = x
		}
	}

	for i := 0; i < lecture; i++ {
		var x string
		fmt.Scan(&x)

		fmt.Printf("%s ", words[x])
	}
}

package main

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

func main() {
	reader := NewStdReader(os.Stdin)
	n, m := reader.ReadInt(), reader.ReadInt()

	dict := map[string]string{}

	for i := 0; i < m; i++ {
		c, a := reader.ReadText(), reader.ReadText()
		if len(c) > len(a) {
			dict[c] = a
		}
	}

	for i := 0; i < n; i++ {
		if i > 0 {
			fmt.Print(" ")
		}
		c := reader.ReadText()
		if a, ok := dict[c]; ok {
			fmt.Print(a)
		} else {
			fmt.Print(c)
		}
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadText() string {

	buf := bytes.NewBuffer(nil)

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b == ' ' || b == '\t' || b == '\r' || b == '\n' {
			if buf.Len() > 0 {
				break
			}
		} else {
			buf.WriteByte(b)
		}
	}

	return buf.String()
}

package main

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

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

func solution() {
	n, m := next_int(), next_int()
	_m := make(map[string]string)

	for i := 0; i < m; i++ {
		_m[next()] = next()
	}

	var res string
	for i := 0; i < n; i++ {
		s := next()
		if len(s) <= len(_m[s]) {
			res += s
		} else {
			res += _m[s]
		}

		if i < n-1 {
			res += " "
		}
	}
	println(res)
}

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

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

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

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

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

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

package main

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

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

func solution() {
	n, m := next_int(), next_int()
	_m := make(map[string]string)

	for i := 0; i < m; i++ {
		_m[next()] = next()
	}
	for i := 0; i < n; i++ {
		s := next()
		if len(s) <= len(_m[s]) {
			println(s)
		} else {
			println(_m[s])
		}
	}
}

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

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

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

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

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

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

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, m int
	fmt.Scanln(&n, &m)
	words := make(map[string]string)

	var langOne string
	var langTwo string

	for i := 0; i < m; i++ {
		fmt.Scanln(&langOne, &langTwo)
		words[langOne] = langTwo
		words[langTwo] = langOne
	}
	var translate string
	output := ""
	for i := 0; i < n; i++ {
		fmt.Scanf("%s", &translate)
		temp1 := words[translate]
		if len(temp1) > len(words[temp1]) {
			output = output + " " + words[temp1]
		} else {
			output = output + " " + temp1
		}
	}
	fmt.Printf("%s", strings.TrimSpace(output))
}


package main
import (
	"os"
	"bufio"
	"fmt"
	"strconv"
	"strings"
	"sort"
)
type (
	A struct {
		y1,y2 int64
	}
)
var (
	n int
	a []A
)

type ASlice []A
func (a ASlice) Len() int           { return len(a) }
func (a ASlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ASlice) Less(i, j int) bool {
	if a[i].y1 != a[j].y1 {
		return a[i].y1 < a[j].y1
	} else {
		return a[i].y2 < a[j].y2
	}
}

func input(f *os.File) {
	var (
		s string
		blank_pos int
		k,b int
		x1,x2 int
		y1,y2 int64
	)

	fmt.Fscanf(f,"%d\n", &n)
	a=make([]A,n)

	fmt.Fscanf(f,"%d %d\n", &x1, &x2)

	scanner := bufio.NewScanner(f)
	for i:=0; i<n; i++ {
		if !scanner.Scan() { panic("input") }
		s=scanner.Text()
		blank_pos=strings.IndexByte(s,' ')
		k,_=strconv.Atoi(s[:blank_pos])
		b,_=strconv.Atoi(s[blank_pos+1:])
		y1=int64(k) * int64(x1) + int64(b)
		y2=int64(k) * int64(x2) + int64(b)
		a[i] = A{y1,y2}
	}
}

func sorta() {
	sort.Sort(ASlice(a))
}

func find() bool {
	for i:=0; i<n-1; i++ {
		if a[i].y2 > a[i+1].y2 {
			return true
		}
	}
	return false
}

func task(f *os.File) bool {
	input(f)
	sorta()
	found:=find()
	return found
}

func output(found bool) {
	if found {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func main() {
	output(task(os.Stdin))
}

package main

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

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

	var n, x1, x2, k, b int64
	Fscan(in, &n, &x1, &x2)
	type pair struct{ l, r int64 }
	ps := make([]pair, n)
	for i := range ps {
		Fscan(in, &k, &b)
		ps[i].l = k*x1 + b
		ps[i].r = k*x2 + b
	}
	sort.Slice(ps, func(i, j int) bool {
		a, b := ps[i], ps[j]
		return a.l < b.l || a.l == b.l && a.r < b.r
	})
	for i, p := range ps[:n-1] {
		if p.r > ps[i+1].r {
			Fprint(out, "YES")
			return
		}
	}
	Fprint(out, "NO")
}

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

package main
import (
	"os"
	"bufio"
	"fmt"
	"strconv"
	"strings"
	"sort"
)
type (
	A struct {
		y1,y2 int
	}
)
var (
	n int
	a []A
)

type ASlice []A
func (a ASlice) Len() int           { return len(a) }
func (a ASlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ASlice) Less(i, j int) bool {
	if a[i].y1 != a[j].y1 {
		return a[i].y1 < a[j].y1
	} else {
		return a[i].y2 < a[j].y2
	}
}

func input(f *os.File) {
	var (
		s string
		blank_pos int
		k,b int
		x1,x2 int
		y1,y2 int
	)

	fmt.Fscanf(f,"%d\n", &n)
	a=make([]A,n)

	fmt.Fscanf(f,"%d %d\n", &x1, &x2)

	scanner := bufio.NewScanner(f)
	for i:=0; i<n; i++ {
		if !scanner.Scan() { panic("input") }
		s=scanner.Text()
		blank_pos=strings.IndexByte(s,' ')
		k,_=strconv.Atoi(s[:blank_pos])
		b,_=strconv.Atoi(s[blank_pos+1:])
		y1=k*x1 + b
		y2=k*x2 + b
		a[i] = A{y1,y2}
	}
}

func sorta() {
	sort.Sort(ASlice(a))
}

func find() bool {
	for i:=0; i<n-1; i++ {
		if a[i].y2 > a[i+1].y2 {
			return true
		}
	}
	return false
}

func task(f *os.File) bool {
	input(f)
	sorta()
	found:=find()
	return found
}

func output(found bool) {
	if found {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func main() {
	output(task(os.Stdin))
}

package main

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

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

	var n, x1, x2, k, b int
	Fscan(in, &n, &x1, &x2)
	type pair struct{ l, r int }
	ps := make([]pair, n)
	for i := range ps {
		Fscan(in, &k, &b)
		ps[i].l = k*x1 + b
		ps[i].r = k*x2 + b
	}
	sort.Slice(ps, func(i, j int) bool {
		a, b := ps[i], ps[j]
		return a.l < b.l || a.l == b.l && a.r < b.r
	})
	for i, p := range ps[:n-1] {
		if p.r > ps[i+1].r {
			Fprint(out, "YES")
			return
		}
	}
	Fprint(out, "NO")
}

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