$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-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 \leq a_{i} \leq m$$$  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.

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$)  — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$)  — scores of the students.

NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$.

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"
	"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"
	"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() {
	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"
	"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() {
	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)
		}
	}
}


You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during $$$n$$$ consecutive days. During the $$$i$$$-th day you have to write exactly $$$a_i$$$ names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly $$$m$$$ names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from $$$1$$$ to $$$n$$$.

The first line of the input contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 10^9$$$) — the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ means the number of names you will write in the notebook during the $$$i$$$-th day.

Print exactly $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$, where $$$t_i$$$ is the number of times you will turn the page during the $$$i$$$-th day.

NoteIn the first example pages of the Death Note will look like this $$$[1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]$$$. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.

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 (
	"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 "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()
}


Cowboy Vlad has a birthday today! There are $$$n$$$ children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.Formally, let's number children from $$$1$$$ to $$$n$$$ in a circle order, that is, for every $$$i$$$ child with number $$$i$$$ will stand next to the child with number $$$i+1$$$, also the child with number $$$1$$$ stands next to the child with number $$$n$$$. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.

The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the number of the children who came to the cowboy Vlad's birthday. The second line contains integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) denoting heights of every child.

Print exactly $$$n$$$ integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child. If there are multiple possible answers, print any of them.

NoteIn the first example, the discomfort of the circle is equal to $$$1$$$, since the corresponding absolute differences are $$$1$$$, $$$1$$$, $$$1$$$ and $$$0$$$. Note, that sequences $$$[2, 3, 2, 1, 1]$$$ and $$$[3, 2, 1, 1, 2]$$$ form the same circles and differ only by the selection of the starting point.In the second example, the discomfort of the circle is equal to $$$20$$$, since the absolute difference of $$$10$$$ and $$$30$$$ is equal to $$$20$$$.

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
}

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 (
	"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
}

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], " ")
	}
}


Mahmoud was trying to solve the vertex cover problem on trees. The problem statement is:Given an undirected tree consisting of n nodes, find the minimum number of vertices that cover all the edges. Formally, we need to find a set of vertices such that for each edge (u, v) that belongs to the tree, either u is in the set, or v is in the set, or both are in the set. Mahmoud has found the following algorithm:  Root the tree at node 1.  Count the number of nodes at an even depth. Let it be evenCnt.  Count the number of nodes at an odd depth. Let it be oddCnt.  The answer is the minimum between evenCnt and oddCnt. The depth of a node in a tree is the number of edges in the shortest path between this node and the root. The depth of the root is 0.Ehab told Mahmoud that this algorithm is wrong, but he didn't believe because he had tested his algorithm against many trees and it worked, so Ehab asked you to find 2 trees consisting of n nodes. The algorithm should find an incorrect answer for the first tree and a correct answer for the second one.

The only line contains an integer n (2 ≤ n ≤ 105), the number of nodes in the desired trees.

The output should consist of 2 independent sections, each containing a tree. The algorithm should find an incorrect answer for the tree in the first section and a correct answer for the tree in the second. If a tree doesn't exist for some section, output "-1" (without quotes) for that section only. If the answer for a section exists, it should contain n - 1 lines, each containing 2 space-separated integers u and v (1 ≤ u, v ≤ n), which means that there's an undirected edge between node u and node v. If the given graph isn't a tree or it doesn't follow the format, you'll receive wrong answer verdict. If there are multiple answers, you can print any of them.

NoteIn the first sample, there is only 1 tree with 2 nodes (node 1 connected to node 2). The algorithm will produce a correct answer in it so we printed  - 1 in the first section, but notice that we printed this tree in the second section.In the second sample:In the first tree, the algorithm will find an answer with 4 nodes, while there exists an answer with 3 nodes like this:  In the second tree, the algorithm will find an answer with 3 nodes which is correct:

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()

	if N < 6 {
	  io.Println(-1)
	} else {
	  io.Println("1 2")
	  io.Println("2 3")
	  io.Println("2 4")
	  for i := 5; i <= N; i++ {
	    io.Println(1, i)
	  }
	}

	for i := 2; i <= N; i++ {
	  io.Println(1, i)
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()

	if N < 6 {
	  io.Println(-1)
	} else {
	  io.Println("1 2")
	  io.Println("2 3")
	  io.Println("1 2")
	  io.Println("2 4")
	  for i := 5; i <= N; i++ {
	    io.Println(1, i)
	  }
	}

	for i := 2; i <= N; i++ {
	  io.Println(1, i)
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.

The first line contains two integers, n and m (1 ≤ n ≤ 3000, 1 ≤ m ≤ 3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains n space-separated strings c1, c2, ..., cn — the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.

Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.

4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest

5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll

codeforces round letter round
hbnyiyc joll joll un joll

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"
	"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
	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))
}


You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.  Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.

The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.

In a single line print a real number — the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.

NoteThe second sample has been drawn on the picture above.

package main

import (
	"fmt"
	"math"
)

func dist(a, b [2]float64) float64 {
	return math.Sqrt(math.Pow(a[0]-b[0], 2) + math.Pow(a[1]-b[1], 2))
}

func rotate(xy [2]float64, a float64) [2]float64 {
	return [2]float64{xy[0]*math.Cos(a) - xy[1]*math.Sin(a), xy[0]*math.Sin(a) + xy[1]*math.Cos(a)}
}

func main() {
	var w, h, a float64
	fmt.Scan(&w, &h, &a)
	if w < h {
		w, h = h, w
	}
	if a > 90 {
		a = 180 - a
	}
	if a == 0 {
		fmt.Println(w*h)
		return
	}
	a = a / 180 * math.Pi
	if a <= math.Atan(h/w)*2 {
		// buvo x, y, po to x*cos(a) - y*sin(a), x*sin(a) + y*cos(a)
		lowerRight := [2]float64{w / 2, -h / 2}
		upperRight := [2]float64{w / 2, +h / 2}
		lowerRight2 := rotate(lowerRight, a)
		upperRight2 := rotate(upperRight, a)

		intersect := [2]float64{lowerRight2[0] - (lowerRight2[0]-upperRight2[0])*(upperRight[1]-lowerRight2[1])/(upperRight2[1]-lowerRight2[1]), h / 2}

		t1 := math.Pow(w/2-intersect[0], 2) / math.Tan(a) / 2

		t2 := math.Pow(dist(upperRight2, intersect), 2) / math.Tan(a) / 2

		fmt.Println(w*h - 2*(t1+t2))
	} else {
		lowerRight := [2]float64{w / 2, -h / 2}
		lowerLeft := [2]float64{-w / 2, -h / 2}
		lowerRight2 := rotate(lowerRight, a)
		lowerLeft2 := rotate(lowerLeft, a)

		intersect := [2]float64{lowerLeft2[0] + (lowerRight2[0]-lowerLeft2[0])*(h/2-lowerLeft2[1])/(lowerRight2[1]-lowerLeft2[1]), h / 2}

		triangle := h * h / math.Tan(a) / 2
		rectangle := h * (w/2 - intersect[0])

		fmt.Println(w*h - 2*(triangle+rectangle))
	}
}

package main

import (
	"fmt"
	"math"
)

func dist(a, b [2]float64) float64 {
	return math.Sqrt(math.Pow(a[0]-b[0], 2) + math.Pow(a[1]-b[1], 2))
}

func rotate(xy [2]float64, a float64) [2]float64 {
	return [2]float64{xy[0]*math.Cos(a) - xy[1]*math.Sin(a), xy[0]*math.Sin(a) + xy[1]*math.Cos(a)}
}

func main() {
	var w, h, a float64
	fmt.Scan(&w, &h, &a)
	if w < h {
		w, h = h, w
	}
	if a > 90 {
		a = 180 - a
	}
	a = a / 180 * math.Pi
	if a <= math.Atan(h/w)*2 {
		// buvo x, y, po to x*cos(a) - y*sin(a), x*sin(a) + y*cos(a)
		lowerRight := [2]float64{w / 2, -h / 2}
		upperRight := [2]float64{w / 2, +h / 2}
		lowerRight2 := rotate(lowerRight, a)
		upperRight2 := rotate(upperRight, a)

		intersect := [2]float64{lowerRight2[0] - (lowerRight2[0]-upperRight2[0])*(upperRight[1]-lowerRight2[1])/(upperRight2[1]-lowerRight2[1]), h / 2}

		t1 := math.Pow(w/2-intersect[0], 2) / math.Tan(a) / 2

		t2 := math.Pow(dist(upperRight2, intersect), 2) / math.Tan(a) / 2

		fmt.Println(w*h - 2*(t1+t2))
	} else {
		lowerRight := [2]float64{w / 2, -h / 2}
		lowerLeft := [2]float64{-w / 2, -h / 2}
		lowerRight2 := rotate(lowerRight, a)
		lowerLeft2 := rotate(lowerLeft, a)

		intersect := [2]float64{lowerLeft2[0] + (lowerRight2[0]-lowerLeft2[0])*(h/2-lowerLeft2[1])/(lowerRight2[1]-lowerLeft2[1]), h / 2}

		triangle := h * h / math.Tan(a) / 2
		rectangle := h * (w/2 - intersect[0])

		fmt.Println(w*h - 2*(triangle+rectangle))
	}
}


The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x1 < x2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that:   y' = ki * x' + bi, that is, point (x', y') belongs to the line number i;  y' = kj * x' + bj, that is, point (x', y') belongs to the line number j;  x1 < x' < x2, that is, point (x', y') lies inside the strip bounded by x1 < x2. You can't leave Anton in trouble, can you? Write a program that solves the given task.

The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x1 and x2 ( - 1 000 000 ≤ x1 < x2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines. The following n lines contain integers ki, bi ( - 1 000 000 ≤ ki, bi ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either ki ≠ kj, or bi ≠ bj.

Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).

NoteIn the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it.

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)
}


Andrew prefers taxi to other means of transport, but recently most taxi drivers have been acting inappropriately. In order to earn more money, taxi drivers started to drive in circles. Roads in Andrew's city are one-way, and people are not necessary able to travel from one part to another, but it pales in comparison to insidious taxi drivers.The mayor of the city decided to change the direction of certain roads so that the taxi drivers wouldn't be able to increase the cost of the trip endlessly. More formally, if the taxi driver is on a certain crossroads, they wouldn't be able to reach it again if he performs a nonzero trip. Traffic controllers are needed in order to change the direction the road goes. For every road it is known how many traffic controllers are needed to change the direction of the road to the opposite one. It is allowed to change the directions of roads one by one, meaning that each traffic controller can participate in reversing two or more roads.You need to calculate the minimum number of traffic controllers that you need to hire to perform the task and the list of the roads that need to be reversed.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 100\,000$$$, $$$1 \leq m \leq 100\,000$$$) — the number of crossroads and the number of roads in the city, respectively. Each of the following $$$m$$$ lines contain three integers $$$u_{i}$$$, $$$v_{i}$$$ and $$$c_{i}$$$ ($$$1 \leq u_{i}, v_{i} \leq n$$$, $$$1 \leq c_{i} \leq 10^9$$$, $$$u_{i} \ne v_{i}$$$) — the crossroads the road starts at, the crossroads the road ends at and the number of traffic controllers required to reverse this road.

In the first line output two integers the minimal amount of traffic controllers required to complete the task and amount of roads $$$k$$$ which should be reversed. $$$k$$$ should not be minimized. In the next line output $$$k$$$ integers separated by spaces — numbers of roads, the directions of which should be reversed. The roads are numerated from $$$1$$$ in the order they are written in the input. If there are many solutions, print any of them.

NoteThere are two simple cycles in the first example: $$$1 \rightarrow 5 \rightarrow 2 \rightarrow 1$$$ and $$$2 \rightarrow 3 \rightarrow 4 \rightarrow 5 \rightarrow 2$$$. One traffic controller can only reverse the road $$$2 \rightarrow 1$$$ and he can't destroy the second cycle by himself. Two traffic controllers can reverse roads $$$2 \rightarrow 1$$$ and $$$2 \rightarrow 3$$$ which would satisfy the condition.In the second example one traffic controller can't destroy the cycle $$$ 1 \rightarrow 3 \rightarrow 2 \rightarrow 1 $$$. With the help of three controllers we can, for example, reverse roads $$$1 \rightarrow 3$$$ ,$$$ 2 \rightarrow 4$$$, $$$1 \rightarrow 5$$$.

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

type edge struct {
	to, c, i int
}

var edges [][]edge

var ts int
var visited []int
var inStack []bool

func topoSort(c int) []int {
	ts++
	var topo []int
	var dfs func(int) bool
	dfs = func(v int) bool {
		visited[v] = ts
		inStack[v] = true
		defer func() { inStack[v] = false }()
		for _, e := range edges[v] {
			if e.c <= c {
				continue
			}
			if visited[e.to] == ts {
				if inStack[e.to] {
					return false
				}
				continue
			}
			if !dfs(e.to) {
				return false
			}
		}
		topo = append(topo, v)
		return true
	}
	for i := 1; i < len(edges); i++ {
		if visited[i] == ts {
			continue
		}
		if !dfs(i) {
			return nil
		}
	}
	return topo
}

func main() {
	var n, m int
	fmt.Fscan(in, &n, &m)
	edges = make([][]edge, n+1)
	visited = make([]int, n+1)
	inStack = make([]bool, n+1)
	for i := 1; i <= m; i++ {
		var u, v, c int
		fmt.Fscan(in, &u, &v, &c)
		edges[u] = append(edges[u], edge{v, c, i})
	}
	c := sort.Search(1e9+1, func(c int) bool {
		return topoSort(c) != nil
	})
	topo := topoSort(c)
	topoPos := make([]int, n+1)
	for i := range topo {
		topoPos[topo[i]] = i
	}
	var ans []int
	for v, es := range edges {
		for _, e := range es {
			if e.c <= c && topoPos[v] < topoPos[e.to] {
				ans = append(ans, e.i)
			}
		}
	}

	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	fmt.Fprintln(out, c, len(ans))
	for i := range ans {
		if i+1 == len(ans) {
			fmt.Fprintln(out, ans[i])
		} else {
			fmt.Fprint(out, ans[i], " ")
		}
	}
}

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

type edge struct {
	to, c, i int
}

var edges [][]edge

var stackPos []int
var stackSz, ts, curC int
var visited, reversed []int

func isEnough(c int) bool {
	curC = c
	ts++
	for i := 1; i < len(edges); i++ {
		if visited[i] == ts {
			continue
		}
		if !dfs(i) {
			return false
		}
	}
	return true
}

type saverT struct {
	stackPos, edge int
}

var saver []saverT

func dfs(v int) bool {
	visited[v] = ts
	stackPos[v] = stackSz
	stackSz++
	res := true
	for _, e := range edges[v] {
		if e.c <= curC {
			saver = append(saver, saverT{stackPos[v], e.i})
		}
		if visited[e.to] == ts {
			if stackPos[e.to] != -1 {
				if len(saver) == 0 || saver[len(saver)-1].stackPos < stackPos[e.to] {
					res = false
				} else {
					reversed[saver[len(saver)-1].edge] = ts
				}
			}
		} else {
			if !dfs(e.to) {
				res = false
			}
		}
		if e.c <= curC {
			saver = saver[:len(saver)-1]
		}
	}
	stackPos[v] = -1
	stackSz--
	return res
}

func main() {
	var n, m int
	fmt.Fscan(in, &n, &m)
	edges = make([][]edge, n+1)
	visited = make([]int, n+1)
	reversed = make([]int, n+1)
	stackPos = make([]int, n+1)
	for i := range stackPos {
		stackPos[i] = -1
	}
	for i := 1; i <= m; i++ {
		var u, v, c int
		fmt.Fscan(in, &u, &v, &c)
		edges[u] = append(edges[u], edge{v, c, i})
	}
	good := sort.Search(1e9+1, isEnough)
	isEnough(good)
	var ans []int
	for i := range reversed {
		if reversed[i] == ts {
			ans = append(ans, i)
		}
	}

	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	fmt.Fprintln(out, good, len(ans))
	for i := range ans {
		if i+1 == len(ans) {
			fmt.Fprintln(out, ans[i])
		} else {
			fmt.Fprint(out, ans[i], " ")
		}
	}
}