package main

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

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

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

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

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

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

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

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

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		var num uint64
		s, _ := reader.ReadBytes('\n')
		readUint64(s, 0, &num)

		fmt.Println(solve(num))
	}
}

const N = 64

var dp []uint64

func init() {
	dp = make([]uint64, N)
	dp[0] = 1

	for i := 1; i < N; i++ {
		dp[i] = (dp[i-1] << 1) + uint64(i+1)
	}
}

func solve(num uint64) uint64 {
	var res uint64

	for i := N - 1; i > 0; i-- {
		if (num>>i)&1 == 1 {
			res += dp[i-1] + uint64(i+1)
		}
	}

	if num&1 == 1 {
		res++
	}

	return res
}

package main

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var n int64
	fmt.Fscan(input, &n)
	ans := int64(0)
	g := int64(2)
	n++
	for k := n / g; k > 0; k = n / g {

		ans += 2*k - 1
		r := n % g
		if r > 0 {ans++}
		if r > g>>1 {ans++}
		g <<= 1
	}
	r := n % g
	if r > g>>1 {ans++}
	fmt.Println(ans)
}

package main

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

func main() {
	t := int(nextInt())
	for i := 0; i < t; i++ {
		fmt.Println(solve(nextInt()))
	}
}

func solve(n int64) int64 {
	var answer int64
	for n > 0 {
		answer += n
		n /= 2
	}
	return answer
}

var sc = bufio.NewScanner(os.Stdin)

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

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

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

/*
URL:
https://codeforces.com/contest/1362/problem/C
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

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

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int
	n int64

	dp [100]int64
)

func main() {
	dp[0] = 1
	for i := int64(1); i <= 60; i++ {
		var d int64
		d = 1 << uint(i)
		dp[i] = dp[i-1] + d
	}
	// PrintfDebug("%v\n", dp)

	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt64()

		solve()
	}
}

func solve() {
	// for i := int64(1); i <= n; i++ {
	// 	PrintfDebug("%v\n", calcDiff(i, i-1))
	// }
	// PrintfDebug("\n")

	// for i := 0; i <= int(n); i++ {
	// 	PrintfDebug("%2d: %s\n", i, string(ZeroPaddingRuneSlice(i, 10)))
	// }
	// PrintfDebug("\n")

	// sum := int64(0)
	// for i := int64(1); i <= n; i++ {
	// 	sum += calcDiff(i, i-1)
	// 	if PopCount(i) == 1 {
	// 		PrintfDebug("%2d: %d\n", i, sum)
	// 	}
	// }
	// PrintfDebug("\n")

	ans := int64(0)
	for i := 0; i <= 60; i++ {
		if NthBit(n, i) == 1 {
			ans += dp[i]
		}
	}
	fmt.Println(ans)
}

func calcDiff(a, b int64) int64 {
	res := int64(0)

	for i := 0; i < 61; i++ {
		if NthBit(a, i) != NthBit(b, i) {
			res++
		}
	}

	return res
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num int64, nth int) int64 {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num int64, nth int) int64 {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num int64, nth int) int64 {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int64) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

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

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

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

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

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

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

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

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

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

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

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

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

	return string(res)
}

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

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

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

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import "fmt"

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

	for t := 0; t < nTest; t++ {
		var x, res int64
		fmt.Scan(&x)

		for i := 0; x != 0; i++ {
			if x%2 != 0 {
				res += (1 << (i + 1)) - 1
			}

			x /= 2
		}

		fmt.Println(res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"math/big"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	defer out.Flush()
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt64()

		c := &big.Int{}
		for n > 0 {
			c = c.Add(c, big.NewInt(n))
			n /= 2
		}
		P(c.String())
	}

}

func length(n int64) int {
	i := 0
	for n > 0 {
		i++
		n = n >> 1
	}
	return i
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

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

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

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

/*********************** Utils int64 ***********************/
func MnMx64(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 Mn64(args ...int64) int64 { mn, _ := MnMx64(args...); return mn }
func Mx64(args ...int64) int64 { _, mx := MnMx64(args...); return mx }
func LCM64(a, b int64) int64   { return a / GCD64(a, b) * b }
func GCD64(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD64(b%a, a)
}
func SortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func Abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

/*********************** Utils int ***********************/
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
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%v\n", &t)
	for now := 0; now < t;now++{
		var n, ans int64
		fmt.Fscanf(in, "%v\n", &n)
		for n > 0 {
			ans += n
			n /= 2
		}
		fmt.Fprintln(out, ans)
	}
	return
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Buffer([]byte{}, 10000000)
	inn.Split(bufio.ScanWords)

	for tt := rd(); tt > 0; tt-- {
		n := rdll()
		Fprintln(out, solve(n))
	}
}

func solve(n int64) int64 {
	if n == 1 {
		return 1
	}
	return solve(n/2) + n
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.Atoi(string(data))
	return x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.ParseInt(string(data), 10, 64)
	return x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}

package main

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

func getUnfairness(n int64) int64 {
	var res int64
	for d := int64(1); d <= n; d *= 2 {
		res += n / d
	}
	return res
}

func main() {
	defer out.Flush()

	var t int
	for scan(&t); t > 0; t-- {
		var n int64
		scan(&n)
		println(getUnfairness(n))
	}
}

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func println(a ...interface{}) {
	fmt.Fprintln(out, a...)
}


package main

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

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

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

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

		var p1, p2 int
		z := make([]int, n+m)
		f := true
		for p1 < n && p2 < m {
			if a[p1] <= b[p2] {
				z[p1+p2] = a[p1]
				p1++
			} else {
				z[p1+p2] = b[p2]
				p2++
			}

			if z[p1+p2-1] == 0 {
				k++
			} else if z[p1+p2-1] > k {
				f = false
				break
			}
		}

		for p1 < n {
			z[p1+p2] = a[p1]
			if a[p1] == 0 {
				k++
			} else if a[p1] > k {
				f = false
				break
			}
			p1++
		}

		for p2 < m {
			z[p1+p2] = b[p2]
			if b[p2] == 0 {
				k++
			} else if b[p2] > k {
				f = false
				break
			}
			p2++
		}

		if !f {
			fmt.Fprintln(out, -1)
		} else {
			for _, v := range z {
				fmt.Fprintf(out, "%d ", v)
			}
			fmt.Fprintln(out)
		}
	}
}

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		mono, poly, ans := make([]int, n), make([]int, m), make([]int,n+m)

		for i, _ := range mono {
			Fscan(in, &mono[i])
		}
		for i, _ := range poly {
			Fscan(in, &poly[i])
		}

		left, right, ans := 0, 0, []int{}
		for left < n || right < m {
			flag := false
			if left < n {
				if mono[left] == 0 {
					ans = append(ans, mono[left])
					left++; k++
					flag = true

				} else if mono[left] <= k {
					ans = append(ans, mono[left])
					left++; flag = true

				}
			}
			if right < m {
				if poly[right] == 0 {
					ans = append(ans, poly[right])
					right++; k++; flag = true

				} else if poly[right] <= k {
					ans = append(ans, poly[right])
					right++; flag = true

				}
			}
			if !flag {
				goto error
			}
		}
		for _, val := range ans {
			Fprint(out, val, " ")
		}
		Fprintln(out)
		continue
		error:
			Fprintln(out, -1)
	}

}

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		mono, poly, ans := make([]int, n), make([]int, m), make([]int,n+m)

		for i := 0; i < n; i++ {
			Fscan(in, &mono[i])
		}
		for i := 0; i < m; i++ {
			Fscan(in, &poly[i])
		}

		left, right, ans := 0, 0, []int{}
		for left < n || right < m {
			flag := false
			if left < n {
				if mono[left] == 0 {
					ans = append(ans, mono[left])
					left++; k++
					flag = true

				} else if mono[left] <= k {
					ans = append(ans, mono[left])
					left++; flag = true

				}
			}
			if right < m {
				if poly[right] == 0 {
					ans = append(ans, poly[right])
					right++; k++; flag = true

				} else if poly[right] <= k {
					ans = append(ans, poly[right])
					right++; flag = true

				}
			}
			if !flag {
				goto error
			}
		}
		for _, val := range ans {
			Fprint(out, val, " ")
		}
		Fprintln(out)
		continue
		error:
			Fprintln(out, -1)
	}

}

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		mono, poly, ans := make([]int, n), make([]int, m), make([]int,n+m)

		for i := 0; i < n; i++ {
			Fscan(in, &mono[i])
		}
		for i := 0; i < m; i++ {
			Fscan(in, &poly[i])
		}

		left, right, curr := 0, 0, 0
		for left < n && right < m {
			flag := false
			if mono[left] == 0 {
				ans[curr] = 0
				left++; curr++; k++

			} else if mono[left] <= k {
				ans[curr] = mono[left]
				curr++; left++;

			} else {
				flag = true
			}
			if poly[right] == 0 {
				ans[curr] = 0
				curr++; right++; k++

			} else if poly[right] <= k {
				ans[curr] = poly[right]
				curr++; right++

			} else if flag {
				goto error
			}
		}

		for i := left; i < n; i++ {
			if mono[i] == 0 {
				ans[curr] = mono[i]
				curr++; k++

			} else if mono[i] <= k {
				ans[curr] = mono[i]
				curr++

			} else {
				goto error
			}
		}

		for i := right; i < m; i++ {
			if poly[i] == 0 {
				ans[curr] = poly[i]
				curr++; k++

			} else if poly[i] <= k {
				ans[curr] = poly[i]
				curr++

			} else {
				goto error
			}
		}
		for _, val := range ans {
			Fprint(out, val, " ")
		}
		goto routine
	error:
		Fprintln(out, -1)
		continue
	routine:
		Fprintln(out)
	}

}

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		mono, poly, ans := make([]int, n), make([]int, m), make([]int,n+m)

		for i := 0; i < n; i++ {
			Fscan(in, &mono[i])
		}
		for i := 0; i < m; i++ {
			Fscan(in, &poly[i])
		}

		solve := func() {
			left, right, curr := 0, 0, 0
			for left < n || right < m {
				flag := false
				if left < n {
					if mono[left] == 0 {
						ans[curr], flag = 0, true
						left++; curr++; k++

					} else if mono[left] <= k {
						ans[curr], flag = mono[left], true
						curr++; left++
					}
				}
				if right < m {
					if poly[right] == 0 {
						ans[curr], flag = 0, true
						curr++; right++; k++

					} else if poly[right] <= k {
						ans[curr], flag = poly[right], true
						curr++; right++;
					}
				}
				if !flag {
					Fprintln(out, -1)
					return
				}
			}
			for _, val := range ans {
				Fprint(out, val, " ")
			}
			Fprintln(out)
		}
		solve()
	}

}

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

package main

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

const N int = 300 + 10

var a, b [N]int
var ans [N * 2]int
var len, sum int

func check(arr *[N]int, idx *int, length *int) bool {
	change := false
	for *idx <= *length {
		if arr[*idx] == 0 {
			sum++
			ans[sum] = arr[*idx]
			len++
			*idx++
			change = true
		} else if arr[*idx] > len {
			break
		} else {
			sum++
			ans[sum] = arr[*idx]
			*idx++
		}
	}
	return change
}

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

	solve := func(Case int) {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}
		for i := 1; i <= m; i++ {
			Fscan(in, &b[i])
		}

		ia, ib := 1, 1
		len, sum = k, 0
		for {
			if !check(&a, &ia, &n) && !check(&b, &ib, &m) {
				break
			}
		}

		if ia <= n || ib <= m {
			Fprintln(out, -1)
		} else {
			for i := 1; i < sum; i++ {
				Fprint(out, ans[i], " ")
			}
			Fprintln(out, ans[sum])
		}

	}

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

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

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var caseNum int
	fmt.Fscan(r, &caseNum)
	for c := 0; c < caseNum; c++ {
		var k, n, m int
		fmt.Fscan(r, &k, &n, &m)
		opeMono, opePoly := make([]int, n), make([]int, m)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &opeMono[i])
		}
		for i := 0; i < m; i++ {
			fmt.Fscan(r, &opePoly[i])
		}
		solve1547C(k, opeMono, opePoly)
	}
}
func solve1547C(k int, opeMono, opePoly []int) {
	n, m := len(opeMono), len(opePoly)
	p1, p2, p3 := 0, 0, 0
	ope := make([]int, n+m)
	for p1 < n || p2 < m {
		var isAppend bool = false
		for p1 < n && (opeMono[p1] == 0 || opeMono[p1] <= k) {
			isAppend = true
			ope[p3] = opeMono[p1]
			p3++
			if opeMono[p1] == 0 {
				k++
			}
			p1++
		}
		for p2 < m && (opePoly[p2] == 0 || opePoly[p2] <= k) {
			isAppend = true
			ope[p3] = opePoly[p2]
			p3++
			if opePoly[p2] == 0 {
				k++
			}
			p2++
		}
		if !isAppend {
			fmt.Println("-1")
			return
		}
	}
	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < len(ope); i++ {
		fmt.Fprint(w, ope[i], " ")
	}
	fmt.Fprintln(w)
	w.Flush()
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var caseNum int
	fmt.Fscan(r, &caseNum)
	for c := 0; c < caseNum; c++ {
		var k, n, m int
		fmt.Fscan(r, &k, &n, &m)
		opeMono, opePoly := make([]int, n), make([]int, m)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &opeMono[i])
		}
		for i := 0; i < m; i++ {
			fmt.Fscan(r, &opePoly[i])
		}
		solve1547C(k, opeMono, opePoly)
	}
}
func solve1547C(k int, opeMono, opePoly []int) {
	n, m := len(opeMono), len(opePoly)
	p1, p2 := 0, 0
	ope:=[]int{}
	for p1 < n || p2 < m {
		var isAppend bool = false
		for p1 < n && (opeMono[p1] == 0 || opeMono[p1] <= k) {
			isAppend = true
			ope=append(ope,opeMono[p1])
			if opeMono[p1] == 0 {
				k++
			}
			p1++
		}
		for p2 < m && (opePoly[p2] == 0 || opePoly[p2] <= k) {
			isAppend = true
			ope=append(ope,opePoly[p2])
			if opePoly[p2] == 0 {
				k++
			}
			p2++
		}
		if !isAppend {
			fmt.Println("-1")
			return
		}
	}
	for i := 0; i < len(ope); i++ {
		fmt.Printf("%d ", ope[i])
	}
	fmt.Printf("\n")
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var caseNum int
	fmt.Fscan(r, &caseNum)
	for c := 0; c < caseNum; c++ {
		var k, n, m int
		fmt.Fscan(r, &k, &n, &m)
		opeMono, opePoly := make([]int, n), make([]int, m)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &opeMono[i])
		}
		for i := 0; i < m; i++ {
			fmt.Fscan(r, &opePoly[i])
		}
		solve1547C(k, opeMono, opePoly)
	}
}
func solve1547C(k int, opeMono, opePoly []int) {
	n, m := len(opeMono), len(opePoly)
	p1, p2, p3 := 0, 0, 0
	ope := make([]int, n+m)
	for p1 < n || p2 < m {
		var isAppend bool = false
		for p1 < n && (opeMono[p1] == 0 || opeMono[p1] <= k) {
			isAppend = true
			ope[p3] = opeMono[p1]
			p3++
			if opeMono[p1] == 0 {
				k++
			}
			p1++
		}
		for p2 < m && (opePoly[p2] == 0 || opePoly[p2] <= k) {
			isAppend = true
			ope[p3] = opePoly[p2]
			p3++
			if opePoly[p2] == 0 {
				k++
			}
			p2++
		}
		if !isAppend {
			fmt.Println("-1")
			return
		}
	}
	for i := 0; i < len(ope); i++ {
		fmt.Printf("%d ", ope[i])
	}
	fmt.Printf("\n")
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadInts() (int, int, int) {
	var a, b, c int
	fmt.Fscanf(io.in, "%d %d %d\n", &a, &b, &c)
	return a, b, c
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	some: for t := io.ReadInt(); t > 0; t-- {
		io.ReadString()
		k, n, m := io.ReadInts()
		a := io.ReadIntSlice(n)
		b := io.ReadIntSlice(m)

		i, j := 0, 0
		ans := ""
		for {
			if i < n && a[i] <= k {
				if a[i] == 0 {
					k++
				}
				ans += strconv.Itoa(a[i]) + " "
				i++
			} else if j < m && b[j] <= k {
				if b[j] == 0 {
					k++
				}
				ans += strconv.Itoa(b[j]) + " "
				j++
			} else if i == n && j == m {
				io.Println(ans)
				break
			} else {
				io.Println(-1)
				continue some
			}
		}
	}
}

package main

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

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

	var tcs int
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var k, n, m int
		_, _ = fmt.Fscan(in, &k, &n, &m)

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

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

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

		ans := make([]int, 0, n+m)

		i, j := 0, 0
		for i < n || j < m {
			if j == m {
				if a[i] == 0 {
					k++
				}

				if a[i] > k {
					break
				}

				ans = append(ans, a[i])
				i++
				continue
			}

			if i == n {
				if b[j] == 0 {
					k++
				}

				if b[j] > k {
					break
				}

				ans = append(ans, b[j])
				j++
				continue
			}

			if a[i] < b[j] {
				if a[i] == 0 {
					k++
				}

				if a[i] > k {
					break
				}

				ans = append(ans, a[i])
				i++
			} else {
				if b[j] == 0 {
					k++
				}

				if b[j] > k {
					break
				}

				ans = append(ans, b[j])
				j++
			}
		}

		if len(ans) == n+m {
			for _, v := range ans {
				_, _ = fmt.Fprintf(out, "%d ", v)
			}

			_, _ = fmt.Fprintln(out)
		} else {
			_, _ = fmt.Fprintln(out, "-1")
		}
	}

	_ = out.Flush()
}

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

	return n
}

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

	return b
}

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

	return b
}

package main

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

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

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

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

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

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		k := sint64()
		n := sint64()
		m := sint64()
		a := sint64s(n)
		b := sint64s(m)
		res := sol(k, n, m, a, b)
		if res == nil {
			printf("-1\n")
		} else {
			for _, r := range res {
				printf("%d ", r)
			}
			printf("\n")
		}
	}
}

func sol(k, n, m int64, a, b []int64) []int64 {
	ai, bi := int64(0), int64(0)
	ret := []int64{}
	for ai < n && bi < m {
		if a[ai] == 0 {
			ret = append(ret, a[ai])
			ai++
			k++
			continue
		}
		if b[bi] == 0 {
			ret = append(ret, b[bi])
			bi++
			k++
			continue
		}
		if a[ai] < b[bi] {
			if a[ai] > k {
				return nil
			}
			ret = append(ret, a[ai])
			ai++
		} else {
			if b[bi] > k {
				return nil
			}
			ret = append(ret, b[bi])
			bi++
		}
	}

	for ai < n {
		if a[ai] == 0 {
			ret = append(ret, a[ai])
			ai++
			k++
			continue
		}
		if a[ai] > k {
			return nil
		}
		ret = append(ret, a[ai])
		ai++
	}

	for bi < m {
		if b[bi] == 0 {
			ret = append(ret, b[bi])
			bi++
			k++
			continue
		}
		if b[bi] > k {
			return nil
		}
		ret = append(ret, b[bi])
		bi++
	}

	return ret
}

package main

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

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

	solve := func(Case int) {
		var cur, n, m int
		Fscan(in, &cur, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int, m)
		for i := range b {
			Fscan(in, &b[i])
		}

		ans :=[]int{}
		i,j := 0,0
		for i<n||j<m {
			ok := false
			if i < n {
				if a[i] == 0 {
					cur++
					ok=true
					ans = append(ans, a[i])
					i++
				} else {
					if a[i] <= cur {
						ok=true
						ans = append(ans, a[i])
						i++
					}
				}
			}
			if j < m {
				if b[j] == 0 {
					cur++
					ok=true
					ans = append(ans, b[j])
					j++
				} else {
					if b[j] <= cur {
						ok=true
						ans = append(ans, b[j])
						j++
					}
				}
			}
			if !ok {
				Fprintln(out, -1)
				return
			}
		}
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

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

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

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		mono, poly, ans := make([]int, n), make([]int, m), make([]int,n+m)

		for i := 0; i < n; i++ {
			Fscan(in, &mono[i])
		}
		for i := 0; i < m; i++ {
			Fscan(in, &poly[i])
		}

		left, right, curr := 0, 0, 0
		for left < n && right < m {
			flag := false
			if mono[left] == 0 {
				ans[curr] = 0
				left++; curr++; k++

			} else if mono[left] <= k {
				ans[curr] = mono[left]
				curr++; left++;

			} else {
				flag = true
			}
			if poly[right] == 0 {
				ans[curr] = 0
				curr++; right++; k++

			} else if poly[right] <= k {
				ans[curr] = poly[right]
				curr++; right++

			} else if flag {
				goto error
			}
		}

		for i := left; i < n; i++ {
			if mono[i] == 0 {
				ans[curr] = mono[i]
				curr++

			} else if mono[i] <= k {
				ans[curr] = mono[i]
				curr++

			} else {
				goto error
			}
		}

		for i := right; i < m; i++ {
			if poly[i] == 0 {
				ans[curr] = poly[i]
				curr++

			} else if poly[i] <= k {
				ans[curr] = poly[i]
				curr++

			} else {
				goto error
			}
		}
		for _, val := range ans {
			Fprint(out, val, " ")
		}
		goto routine
		error:
			Fprintln(out, -1)
			continue
		routine:
			Fprintln(out)
	}

}

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

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

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

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

package main

import (
	"fmt"
)

const N int = 300 + 10

var a, b [N]int
var ans [N * 2]int
var len, sum int

func solve(arr *[N]int, idx *int, length *int) bool {
	change := false
	for *idx <= *length {
		if arr[*idx] == 0 {
			sum++
			ans[sum] = arr[*idx]
			len++
			*idx++
			change = true
		} else if arr[*idx] > len {
			break
		} else {
			sum++
			ans[sum] = arr[*idx]
			*idx++
		}
	}
	return change
}

func main() {
	T := 0
	fmt.Scanf("%d\n", &T)
	for ; T > 0; T-- {
		var k, n, m int
		fmt.Scanf("\n%d%d%d\n", &k, &n, &m)
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i])
		}
		fmt.Scanf("\n")
		for i := 1; i <= m; i++ {
			fmt.Scanf("%d", &b[i])
		}
		fmt.Scanf("\n")

		ia, ib := 1, 1
		len, sum = k, 0
		for {
			if !solve(&a, &ia, &n) && !solve(&b, &ib, &m) {
				break
			}
		}

		if ia <= n || ib <= m {
			fmt.Println(-1)
		} else {
			for i := 1; i < sum; i++ {
				fmt.Printf("%d ", a[i])
			}
			fmt.Println(a[sum])
		}
	}
}

package main

import (
	"fmt"
)

const N int = 300 + 10

var a, b [N]int
var ans [N * 3]int
var len int

func solve(arr *[N]int, idx *int, length *int) bool {
	change := false
	for *idx <= *length {
		if arr[*idx] == 0 {
			len++
			*idx++
			change = true
		} else if arr[*idx] > len {
			break
		} else {
			ans[1] = a[*idx]
			*idx++
		}
	}
	return change
}

func main() {
	T := 0
	fmt.Scanf("%d\n", &T)
	for ; T > 0; T-- {
		var k, n, m int
		fmt.Scanf("\n%d%d%d\n", &k, &n, &m)
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i])
		}
		fmt.Scanf("\n")
		for i := 1; i <= m; i++ {
			fmt.Scanf("%d", &b[i])
		}
		fmt.Scanf("\n")

		ia, ib := 1, 1
		len = k
		for {
			if !solve(&a, &ia, &n) && !solve(&b, &ib, &m) {
				break
			}
		}

		if ia <= n || ib <= m {
			fmt.Println(-1)
		} else {
			for i := 1; i < len; i++ {
				fmt.Printf("%d ", a[i])
			}
			fmt.Println(a[len])
		}
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadInts() (int, int, int) {
	var a, b, c int
	fmt.Fscanf(io.in, "%d %d %d\n", &a, &b, &c)
	return a, b, c
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	some: for t := io.ReadInt(); t > 0; t-- {
		io.ReadString()
		k, n, m := io.ReadInts()
		a := io.ReadIntSlice(n)
		b := io.ReadIntSlice(m)

		i, j := 0, 0
		ans := ""
		for {
			if i < n && a[i] <= k {
				if a[i] == 0 {
					k++
				}
				ans += strconv.Itoa(a[i])
				i++
			} else if j < m && b[j] <= k {
				if b[j] == 0 {
					k++
				}
				ans += strconv.Itoa(b[j])
				j++
			} else if i == n && j == m {
				io.Println(ans)
				break
			} else {
				io.Println(-1)
				continue some
			}
		}
	}
}


package main

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

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

	s := io.Next()
	n := len(s)
	mn := int(1e9)

	for i := 0; i < n; i++ {
		a := int(s[i] - 'a')
		mn = min(mn, a)
		if mn < a {
			io.Println("Ann")
		} else {
			io.Println("Mike")
		}
	}
}

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

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

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

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

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

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

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

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

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

/* solution */

func solve() {

	s := read()

	min := 'z'
	for _, c := range s {
		if min < c {
			print("Ann")
		} else {
			print("Mike")
			min = c
		}
	}

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

func main() {
	defer Flush()

	s := readb()
	for _, v := range solve(s) {
		if v == 0 {
			println("Ann")
		} else {
			println("Mike")
		}
	}

}

func solve(s []byte) []int {
	n := len(s)
	a := make([]int, n)
	for i := range a {
		a[i] = int(s[i] - 'a')
	}

	res := make([]int, n)
	minv := 27
	for k, v := range a {
		if v <= minv {
			res[k] = 1
			minv = v
		} else {
			res[k] = 0
		}
	}

	return res
}

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

// 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[:len(b):len(b)]
}

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

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(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...)
}

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// 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 minf(a, b float64) float64 {
	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 maxf(a, b float64) float64 {
	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
}

func absf(a float64) float64 {
	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)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1220/problem/C

package main

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

func createSmallestLetterExistsArray(s string) []bool {
	smallerLetterExists := make([]bool, len(s))
	smallestLetter := string(s[0])
	for i := 1; i < len(s); i++ {
		l := string(s[i])
		if smallestLetter < l {
			smallerLetterExists[i] = true
		}
		if l < smallestLetter {
			smallestLetter = l
		}
	}
	return smallerLetterExists
}

func Solve(s string) []string {
	winners := make([]string, len(s))
	for i, annWins := range createSmallestLetterExistsArray(s) {
		if annWins {
			winners[i] = "Ann"
		} else {
			winners[i] = "Mike"
		}
	}
	return winners
}

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

	var s string
	fmt.Fscanf(reader, "%s\n", &s)

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

// Author: sighduck
// URL: https://codeforces.com/contest/1220/problem/C

package main

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

func Solve(s string) []string {
	winners := make([]string, len(s))
	minLetter := "z"
	for i, si := range s {
		currentLetter := string(si)
		if minLetter < currentLetter {
			winners[i] = "Ann"
		} else {
			winners[i] = "Mike"
			minLetter = currentLetter
		}
	}
	return winners
}

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

	var s string
	fmt.Fscanf(reader, "%s\n", &s)

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


package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	// scan first line
	sc.Scan()
	//mn := getArrInt(sc.Text())
	// scan second line
	sc.Scan()
	games := getArrInt(sc.Text())
	// scan third line
	sc.Scan()
	wallet := getArrInt(sc.Text())

	boughtGames := 0
	billIdx := 0
	for _, game := range games {
		currentBill := wallet[billIdx]
		if currentBill >= game {
			boughtGames++
			billIdx++
			// catch condition where there are much more games than bill
			if billIdx >= len(wallet) {
				break
			}
		}
	}
	fmt.Println(boughtGames)
}

func getArrInt(arrStr string) (arr []int) {
	tokens := strings.Split(arrStr, " ")
	for _, token := range tokens {
		x, _ := strconv.Atoi(token)
		arr = append(arr, x)
	}
	return
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() int {
	var ch byte
	var err error
	for {
		ch, err = reader.ReadByte()
		if err != nil {
			return 0
		}
		if unicode.IsDigit(rune(ch)) {
			break
		}
	}
	result := int(ch & 0xf)
	for {
		ch, err = reader.ReadByte()
		if err != nil || !unicode.IsDigit(rune(ch)) {
			return result
		}
		result = result*10 + int(ch&0xf)
	}
	return result
}

const M int = 1005

var (
	n, m, ans int
	c, a [M]int
)

func main() {
	n, m = readInt(), readInt()
	for i := 0; i < n; i++ {
		c[i] = readInt()
	}
	for i := 0; i < m; i++ {
		a[i] = readInt()
	}
	cl, al := c[:n], a[:m]
	for ; len(cl)!=0 && len(al)!=0; {
		if al[0] >= cl[0] {
			ans += 1
			cl = cl[1:]
			al = al[1:]
		} else {
			cl = cl[1:]
		}
	}
	fmt.Println(ans)
	return
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	c := make([]int, n)
	a := make([]int, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&a[i])
	}
	var result, i, j int
	for i < n && j < m {
		if c[i] <= a[j] {
			result++
			i++
			j++
		} else {
			i++
		}
	}
	fmt.Println(result)
}

package main
import "fmt"
func main() {
  var hehe int
  var n, m int
  fmt.Scanf("%d", &n)
  fmt.Scanf("%d", &m)
  fmt.Scanf("%d", &hehe)
  var c []int
  var a []int

  for i:=0; i<n; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    c = append(c, tmp)
  }
  fmt.Scanf("%d", &hehe)
  for i:=0; i<m; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    a = append(a, tmp)
  }
  fmt.Scanf("%d", &hehe)

  aindex := 0
  cindex := 0
  counter := 0
  for cindex<n && aindex<m {
    if c[cindex] <= a[aindex] {
      cindex++
      aindex++
      counter++
    } else {
      cindex++
    }
  }
  fmt.Println(counter)
}

package main

import (
	"bufio"
	"os"
)

func main() {
	defer out.Flush()

	n,m := readInt(),readInt()

	c:=make([]int,n)
	for i:=range c {
		c[i]=readInt()
	}
	ans:=0
	for i,j:=0,0;i<m;i++ {
		x := readInt()
		for j<n && c[j]>x { j++ }
		if j==n {
			break
		}
		ans++
		j++
	}
	writeInt(ans)
	out.WriteByte('\n')
}

var in, out = io()

func io() (*bufio.Scanner, *bufio.Writer) {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	return in, bufio.NewWriter(os.Stdout)
}

func readInt() int {
	if !in.Scan() {
		panic("Input error")
	}

	b := in.Bytes()

	x := int(0)

	for _, v := range b {
		x = x*10 + int(v-'0')
	}

	return x
}

const (
	INTLEN = 22
)

func writeInt(x int) {
	var neg bool
	if x < 0 {
		neg = true
		x = -x
	}

	var b [INTLEN + 1]byte //negative
	i := INTLEN+1
	for x >= 10 {
		q := x / 10
		i--
		b[i] = byte(x-q*10) + '0'
		x = q
	}
	i--
	b[i] = byte(x) + '0'

	if neg {
		i--
		b[i] = '-'
	}
	out.Write(b[i:])
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	c := make([]int, n)
	a := make([]int, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&a[i])
	}
	var result, j int
	for i := 0; i < n && j < m; i++ {
		if c[i] <= a[j] {
			result++
			j++
		}
	}
	fmt.Println(result)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var c, a []int
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		c = append(c, t)
	}
	for i := 0; i < m; i++ {
		var t int
		fmt.Scan(&t)
		a = append(a, t)
	}
	ret := 0
	for i, j := 0, 0; i < n && j < m; {
		if c[i] <= a[j] {
			ret++
			i++
			j++
		} else {
			i++
		}
	}
	fmt.Println(ret)
}

package main

import (
	"fmt"
)
const (
	maxn = 1000 + 10
)
func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var c, a [maxn]int
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&a[i])
	}
	ret := 0
	for i, j := 0, 0; i < n && j < m; {
		if c[i] <= a[j] {
			ret++
			i++
			j++
		} else {
			i++
		}
	}
	fmt.Println(ret)
}

package main

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

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()
	c := sc.NextIntArray()
	a := sc.NextIntArray()

	p := 0
	ans := 0
	for i := 0; i < N && p < M; i++ {
		if c[i] <= a[p] {
			p++
			ans++
		}
	}
	fmt.Println(ans)

}

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

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var c, a []int
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		c = append(c, t)
	}

	for i := 0; i < m; i++ {
		var t int
		fmt.Scan(&t)
		a = append(a, t)
	}
	fmt.Println(n, m, c, a)
	ret := 0
	for i, j := 0, 0; i < n && j < m; {
		fmt.Println(i, j, ret, c[i], a[j])
		if c[i] <= a[j] {
			ret++
			i++
			j++
		} else {
			i++
		}
	}
	fmt.Println(ret)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var c, a []int
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		c = append(c, t)
	}
	for i := 0; i < m; i++ {
		var t int
		fmt.Scan(&t)
		a = append(a, t)
	}
	ret := 0
	for i, j := 0, 0; i < n && j < m; {
		if c[i] <= a[j] {
			ret++
			i++
			j++
		} else {
			j++
		}
	}
	fmt.Println(ret)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() int {
	var ch byte
	var err error
	for {
		ch, err = reader.ReadByte()
		if err != nil {
			return 0
		}
		if unicode.IsDigit(rune(ch)) {
			break
		}
	}
	result := int(ch & 0xf)
	for {
		ch, err = reader.ReadByte()
		if err != nil || !unicode.IsDigit(rune(ch)) {
			return result
		}
		result = result*10 + int(ch&0xf)
	}
	return result
}

const M int = 1005

var (
	n, m, ans int
	c, a [M]int
)

func main() {
	n, m = readInt(), readInt()
	for i := 0; i < n; i++ {
		c[i] = readInt()
	}
	for i := 0; i < m; i++ {
		a[i] = readInt()
	}
	cl, al := c[:n], a[:m]
	for ; len(cl)!=0 && len(al)!=0; {
		if al[0] >= cl[0] {
			ans += 1
			cl = cl[1:]
			al = al[1:]
		} else {
			al = al[1:]
		}
	}
	fmt.Println(ans)
	return
}

package main
import "fmt"
func main() {
  var n, m int
  fmt.Scanf("%d %d", &n, &m)
  var c []int
  var a []int

  for i:=0; i<n; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    c = append(c, tmp)
  }
  for i:=0; i<m; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    a = append(a, tmp)
  }

  aindex := 0
  cindex := 0
  counter := 0
  for cindex<n && aindex<m {
    if c[cindex] <= a[aindex] {
      cindex++
      aindex++
      counter++
    } else {
      cindex++
    }
  }
  fmt.Println(counter)
}

package main
import "fmt"
func main() {
  var n, m int
  fmt.Scanf("%d %d", &n, &m)
  var c []int
  var a []int

  for i:=0; i<n; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    c = append(c, tmp)
  }
  for i:=0; i<m; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    a = append(a, tmp)
  }

  aindex := 0
  cindex := 0
  counter := 0
  fmt.Println(a)
  fmt.Println(c)
  for cindex<n && aindex<m {
    if c[cindex] <= a[aindex] {
      cindex++
      aindex++
      counter++
    } else {
      cindex++
    }
  }
  fmt.Println(counter)
}

package main

import (
	"bufio"
	"os"
)

func main() {
	defer out.Flush()

	n,m := readInt(),readInt()

	c:=make([]int,n)
	for i:=range c {
		c[i]=readInt()
	}
	ans:=0
	for i,j:=0,0;i<m;i++ {
		x := readInt()
		for j<n && c[j]>x { j++ }
		if j==n {
			break
		}
		ans++
		j++
	}
	writeInt(ans)
	out.WriteByte('\n')
}

var in, out = io()

func io() (*bufio.Scanner, *bufio.Writer) {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	return in, bufio.NewWriter(os.Stdout)
}

func readInt() int {
	if !in.Scan() {
		panic("Input error")
	}

	b := in.Bytes()

	x := int(0)

	for _, v := range b {
		x = x*10 + int(v-'0')
	}

	return x
}

const (
	INTLEN = 22
)

func writeInt(x int) {
	var neg bool
	if x < 0 {
		neg = true
		x = -x
	}

	var b [INTLEN + 1]byte //negative
	i := INTLEN
	for x >= 10 {
		q := x / 10
		i--
		b[i] = byte(x-q*10) + '0'
		x = q
	}
	i--
	b[i] = byte(x) + '0'

	if neg {
		i--
		b[i] = '-'
	}
	out.Write(b[i:])
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func getN(v int) int {
	v = v & -v
	t := 0
	for (v & 32767) != 0 {
		v <<= 1
		t++
	}
	return t
}

func sol() {
	z := ri()
	r := 30
	for i := 0; i < 30; i++ {
		t := i + getN(z+i)
		if r > t {
			r = t
		}
	}
	fmt.Print(r, " ")
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

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

const M uint64 = 32768

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

	f := [32770]uint64{}
	for i := range f {
		f[i] = 1e10
	}
	f[0] = 0
	f[32768] = 0
	que := []uint64{32768}
	for len(que) > 0 {
		top := que[0]
		que = que[1:]
		//v+1
		if top != 0 && f[top]+1 < f[top-1] {
			f[top-1] = f[top] + 1
			que = append(que, top-1)
		}
		//v*2
		if k := top / 2; top%2 == 0 && f[top]+1 < f[k] {
			f[k] = f[top] + 1
			que = append(que, k)
		}
		if k := (top + M) / 2; k%2 == 0 && k/2 <= 32768 && f[top]+1 < f[k] {
			f[k] = f[top] + 1
			que = append(que, k)
		}
	}
	var c int
	var n int
	Fscan(in, &c)
	for i := 1; i <= c; i++ {
		Fscan(in, &n)
		Fprintf(out, "%d%s", f[n], " ")
	}
}

package main

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

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

	var n int
	fmt.Fscan(in, &n)

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

		min := 32768 - v
		for j := 0; j < 16; j++ {
			if v+j == 0 {
				min = 0
				break
			}

			trail := 16 - bits.TrailingZeros(uint(v+j)) + j - 1
			if trail < min {
				min = trail
			}
		}
		fmt.Fprintf(out, "%d ", min)
	}
	fmt.Fprintln(out)
}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n int
		fmt.Fscan(r, &n)

		res := 15
		for i := 0; i < 14; i++ {
			for j := 0; i + j < res; j++ {
				if ( (n+i)*(1<<j) ) % 32768 == 0 {
					res = i + j
				}
			}
		}
		fmt.Fprintf(w, "%d ", res)
	}
	fmt.Fprintln(w, "")
}

package main

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

/*
type deque interface {
	emplace(n int)
	top() int
	bottom() int
	popback() int
	popfront() int
	empty() bool
}
*/
type deque struct {
	q []int
}

func (q *deque) emplace(n int) {
	(*q).q = append((*q).q, n)
}

func (q deque) empty() bool {
	return len(q.q) == 0
}

func (q deque) top() int {
	if q.empty() {
		panic("top() performed on empty deque")
	}
	return q.q[len(q.q)-1]
}

func (q *deque) popback() int {
	if q.empty() {
		panic("popback() performed on empty deque")
	}
	res := (*q).top()
	(*q).q = (*q).q[:len((*q).q)-1]
	return res
}

func (q deque) bottom() int {
	if q.empty() {
		panic("bottom() performed on empty deque")
	}
	return q.q[0]
}

func (q *deque) popfront() int {
	if q.empty() {
		panic("popfront() performed on empty deque")
	}
	res := (*q).bottom()
	(*q).q = (*q).q[1:]
	return res
}

func right(n int) int {
	if n % 2 == 1 { return 0 }
	return n/2
}

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

	N := 32768

	vis := make([]bool, N)
	dis := make([]int, N)

	q := deque{ make([]int, 0, N+7) }
	q.emplace(0)
	vis[0] = true

	for ! q.empty() {
		nd := q.popfront()
		for _, nxt := range []int{ (N+nd-1)%N, right(nd), right(N+nd) } {
			if !vis[nxt] {
				vis[nxt] = true
				dis[nxt] = dis[nd] + 1
				q.emplace(nxt)
			}
		}
	}

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n int
		fmt.Fscan(r, &n)
		fmt.Fprintf(w, "%d ", dis[n])
	}
	fmt.Fprintln(w, "")

}

package main

import (
	"fmt"
	"math"
)

var step [32769]int64
var MOD int64 = 32768

func initStep() {
	for i := int64(0); i < MOD; i++ {
		step[i] = math.MaxInt
	}
	var queue []int64
	queue = append(queue, MOD)
	ct := 1000000
	for len(queue) > 0 && ct > 0 {
		now := queue[0]
		queue = queue[1:]
		if now%2 == 0 {
			next1 := now / 2
			if step[next1] == math.MaxInt {
				step[next1] = step[now] + 1
				queue = append(queue, next1)
			}
		}
		if (now+MOD)%2 == 0 {
			next2 := (now + MOD) / 2
			if step[next2] == math.MaxInt {
				step[next2] = step[now] + 1
				queue = append(queue, next2)
			}
		}
		if now-1 >= 0 {
			next3 := now - 1
			if step[next3] == math.MaxInt {
				step[next3] = step[now] + 1
				queue = append(queue, next3)
			}
		}

	}
	step[0] = 0
}

func main() {
	initStep()
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])

		fmt.Println(step[a[i]])
	}
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}
func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}
func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

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

func main() {
	ip := bufio.NewReader(os.Stdin)
	_ = readInt(ip)
	a := readArrInt(ip)
	for i := range a {
		fuck(a[i])
	}

}

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

func fuck(a int) {
	if a == 0 {
		fmt.Print(0, " ")
		return
	}
	res := int(1e9)
	tmp := 0
	for a <= 32768 {
		cnt := 0
		p := a
		for p%2 == 0 {
			cnt++
			p >>= 1
		}

		res = min(res, 15-cnt+tmp)
		tmp += lb(a)
		a += lb(a)
	}

	fmt.Print(res, " ")
}

func lb(x int) int {
	return x & -x
}

package main

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

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

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

	var T int
	var x int
	mod := 32768

	dp := make([]int, mod+1)
	st := []int{32768}
	dp[32768] = 0
	for len(st) > 0 {
		ns := []int{}
		for _, v := range st {
			pre := v - 1
			if pre > 0 && dp[pre] == 0 {
				dp[pre] = dp[v] + 1
				ns = append(ns, pre)
			}

			if v%2 == 0 {
				d := v/2
				if dp[d] == 0 {
					dp[d] = dp[v]+1
					ns = append(ns,d)
				}

				div := ((v + mod) / 2) % mod
				if dp[div] == 0 {
					dp[div] = dp[v] + 1
					ns = append(ns, div)
				}
			}
		}
		st = ns
	}
	dp[0] = 0
	//Println(dp[mod/2])
	//Println(dp[mod/4])

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x)

		Fprintln(out, dp[x])
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

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

	var n, v int
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &v)
		if v == 0 {
			Fprint(out, "0 ")
			continue
		}
		ans := 15
		for i := 0; i < 15; i++ {
			ans = min(ans, i+15-bits.TrailingZeros(uint(v+i)))
		}
		Fprint(out, ans, " ")
	}
}

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

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

package main

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

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

	const mx = 32768
	g := [mx][]int{}
	for w := range g {
		v := (w + 1) % mx
		g[v] = append(g[v], w)
		v = w * 2 % mx
		g[v] = append(g[v], w)
	}
	dis := [mx]int{-1}
	q := []int{0}
	for k := 1; len(q) > 0; k++ {
		tmp := q
		q = nil
		for _, v := range tmp {
			for _, w := range g[v] {
				if dis[w] == 0 {
					dis[w] = k
					q = append(q, w)
				}
			}
		}
	}
	dis[0] = 0

	var n, v int
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &v)
		Fprint(out, dis[v], " ")
	}
}

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

package main

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

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

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

func main() {
	defer out.Flush()

	N := 32768
	count := make([]int, N+1)
	for i := 0; i < len(count); i++ {
		count[i] = -1
	}
	count[N] = 0
	count[0] = 0

	stack := make([][]int, 0)
	stack = append(stack, []int{N, 0})
	index := 0
	for index < len(stack) {
		s, l := stack[index][0], stack[index][1]
		index++

		if s > 0 {
			if s%2 == 0 {
				{
					s := s / 2
					if count[s] == -1 {
						count[s] = l + 1
						stack = append(stack, []int{s, l + 1})
					}
				}
				{
					s := (s + N) / 2
					if count[s] == -1 {
						count[s] = l + 1
						stack = append(stack, []int{s, l + 1})
					}
				}
			}
			s = s - 1
			if count[s] == -1 {
				count[s] = l + 1
				stack = append(stack, []int{s, l + 1})
			}
		}

	}

	// fmt.Fprintln(out, count)

	var n int
	fmt.Fscan(in, &n)

	a := make([]int64, n)

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

	for i := 0; i < len(a); i++ {
		fmt.Fprint(out, count[a[i]], " ")
	}
}

package main

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

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

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

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

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

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

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

const C = 32768

func main() {
	defer writer.Flush()
	n := _int()
	for i := 0; i < n; i++ {
		printf("%d ", sol(_int()))
	}
}

func sol(i int) int {
	res := 16
	for add := 0; add <= 15; add++ {
		curr := 1
		for mul := 0; mul <= 15; mul++ {
			if ((i+add)*curr)%C == 0 {
				res = min(res, add+mul)
			}
			curr *= 2
		}
	}
	return res
}

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

package main

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

func solve(a []uint64) []uint64 {
	getPow := func(d uint64) uint64 {
		i := uint64(0)
		for d%2 == 0 && d > 1 {
			d = d >> 1
			i++
		}

		return i
	}

	getMin := func(n uint64) uint64 {
		max := 15 - getPow(n)
		res := max

		for i := uint64(0); i <= max; i++ {
			t := (n + i) % 32768
			r := i
			if t > 0 {
				r += 15 - getPow(t)
			}
			if r < res {
				res = r
			}
		}

		return uint64(res)
	}

	for i, n := range a {
		a[i] = getMin(n % 32768)
	}

	return a
}

func main() {
	toInt := func(buf []byte) uint64 {
		var n uint64
		for _, v := range buf {
			n = n*10 + uint64(v-'0')
		}
		return n
	}

	var n uint64

	fmt.Scan(&n)
	b := make([]uint64, n)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := range b {
		scanner.Scan()
		b[i] = toInt(scanner.Bytes())
	}

	a := solve(b)
	for _, x := range a {
		fmt.Print(x, " ")
	}
	fmt.Println()
}

package main

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	dp := make([]int, 32769)
	dp[0] = 0

	var cal func(i int, visited map[int]bool) int
	cal = func(i int, visited map[int]bool) int {
		if i == 0 || i == 32768 {
			return 0
		}
		if dp[i] > 0 {
			return dp[i]
		}
		if visited[i] {
			return 32768 - i
		}
		visited[i] = true
		a, b := (i*2)%32768, (i+1)%32768
		ans := min(cal(a, visited), cal(b, visited)) + 1
		dp[i] = ans
		return ans
	}
	for ii := 0; ii < t; ii++ {
		m := 0
		fmt.Fscan(in, &m)
		ans := 15
		for i := 0; i <= 15; i++ {
			temp := i
			a := (m + i) % 32768
			for a != 0 {
				a = a * 2
				a %= 32768
				temp++
			}
			//fmt.Println(i, ans)
			if temp < ans {
				ans = temp
			}
		}
		fmt.Fprint(out, ans)
		if ii == t-1 {
			fmt.Fprintln(out)
		} else {
			fmt.Fprint(out, " ")
		}
	}
}

package main

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

/*
1
19
*/

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

	for i := 0; i < n; i++ {
		var num int
		scanf("%d", &num)

		minCnt := 32768 - num

		for j := 0; j < 16; j++ {
			cnt := j
			rem := num + j
			for rem != 0 {
				rem = 2 * rem % 32768
				cnt++
			}

			minCnt = min(minCnt, cnt)
		}

		fmt.Fprintf(writer, "%d ", minCnt)
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

import (
	"bufio"
	"container/list"
	. "fmt"
	"os"
)

const (
	INF = 3e5 + 10
	MOD = 32768
)

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

	var n int
	Fscan(in, &n)

	dp := make([]int, MOD)
	vis := make([]bool, MOD)

	queue := list.New()

	queue.PushBack(0)
	vis[0] = true

	for queue.Len() > 0 {
		newQueue := list.New()
		for e := queue.Front(); e != nil; e = e.Next() {
			x := e.Value.(int)
			if vis[(x+MOD-1)%MOD] == false {
				dp[(x+MOD-1)%MOD] = dp[x] + 1
				newQueue.PushBack((x + MOD - 1) % MOD)
				vis[(x+MOD-1)%MOD] = true

			}
			if x%2 == 0 && vis[x>>1] == false {
				dp[x>>1] = dp[x] + 1
				newQueue.PushBack(x >> 1)
				vis[x>>1] = true
			}

			if x%2 == 0 && vis[(x+MOD)>>1] == false {
				dp[(x+MOD)>>1] = dp[x] + 1
				newQueue.PushBack((x + MOD) >> 1)
				vis[(x+MOD)>>1] = true
			}
		}
		queue = newQueue
	}

	for i := 0; i < n; i++ {
		var x int
		Fscan(in, &x)
		Fprint(out, dp[x], " ")
	}

}

package main

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

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

const M uint64 = 32768

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

	f := [32770]uint64{}
	for i := range f {
		f[i] = 1e10
	}
	f[0] = 0
	que := []uint64{32768}
	for len(que) > 0 {
		top := que[0]
		que = que[1:]
		//v+1
		if top != 0 && f[top]+1 < f[top-1] {
			f[top-1] = f[top] + 1
			que = append(que, top-1)
		}
		//v*2
		if k := top / 2; top%2 == 0 && f[top]+1 < f[k] {
			f[k] = f[top] + 1
			que = append(que, k)
		}
		if k := (top + M) / 2; k%2 == 0 && k/2 <= 32768 && f[top]+1 < f[k] {
			f[k] = f[top] + 1
			que = append(que, k)
		}
	}
	var c int
	var n int
	Fscan(in, &c)
	for i := 1; i <= c; i++ {
		Fscan(in, &n)
		Fprintf(out, "%d%s", f[n], " ")
	}
}

package main

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

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

const M uint64 = 32768

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

	f := [32769]uint64{}
	for i := range f {
		f[i] = 1e10
	}
	f[32768] = 0
	que := []uint64{32768}
	for len(que) > 0 {
		top := que[0]
		que = que[1:]
		//v+1
		if top != 0 && f[top]+1 < f[top-1] {
			f[top-1] = f[top] + 1
			que = append(que, top-1)
		}
		//v*2
		if k := top / 2; top%2 == 0 && f[top]+1 < f[k] {
			f[k] = f[top] + 1
			que = append(que, k)
		}
		if k := (top + M) / 2; k%2 == 0 && k/2 <= 32768 && f[top]+1 < f[k] {
			f[k] = f[top] + 1
			que = append(que, k)
		}
	}
	var c int
	var n int
	Fscan(in, &c)
	for i := 1; i <= c; i++ {
		Fscan(in, &n)
		if i == 18833 {
			Println("this", n)
		}
		Fprintf(out, "%d%s", f[n], " ")
	}
}

package main

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

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

const M uint64 = 32768

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

	f := [32769]uint64{}
	for i := range f {
		f[i] = 1e10
	}
	f[32768] = 0
	que := []uint64{32768}
	for len(que) > 0 {
		top := que[0]
		que = que[1:]
		//v+1
		if top != 0 && f[top]+1 < f[top-1] {
			f[top-1] = f[top] + 1
			que = append(que, top-1)
		}
		//v*2
		if k := top / 2; top%2 == 0 && f[top]+1 < f[k] {
			f[k] = f[top] + 1
			que = append(que, k)
		}
		if k := (top + M) / 2; k%2 == 0 && k/2 <= 32768 && f[top]+1 < f[k] {
			f[k] = f[top] + 1
			que = append(que, k)
		}
	}
	var c int
	var n int
	Fscan(in, &c)
	for ; c > 0; c-- {
		Fscan(in, &n)
		Fprintf(out, "%d%s", f[n], " ")
	}
}

package main

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

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

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

	var c int
	Fscan(in, &c)
	for ; c > 0; c-- {
		vis := make(map[uint64]bool)
		var n uint64
		Fscan(in, &n)
		Println(n)
		que := []uint64{n}
		step := 0
		for {
			k := len(que)
			for i := 0; i < k; i++ {
				cur := que[0]
				que = que[1:]
				if cur == 0 {
					Fprint(out, step, " ")
					goto h1
				}
				if vis[cur] {
					continue
				} else {
					vis[cur] = true
				}
				que = append(que, (cur+1)%32768)
				que = append(que, (cur * 2 % 32768))
			}
			step++
		}
	h1:
	}
}

package main

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

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

	var n int
	fmt.Fscan(in, &n)

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

		var c int
		if v%2 != 0 {
			c++
			v++
		}

		var z int
		if v > 0 {
			z = 16 - bits.TrailingZeros(uint(v)) - 1
			if 32768-v < z {
				z = 32768 - v
			}
		}
		if z+c == 0 {
			z = 1
		}
		fmt.Fprintf(out, "%d ", z+c)
	}
	fmt.Fprintln(out)
}

package main

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

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

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

	var n int
	fmt.Fscan(in, &n)

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

		trail := func(n int64) int64 {
			if n <= 0 {
				return 0
			}

			var c int64
			for n%32768 != 0 {
				c++
				n *= 2
			}
			return c
		}

		c := min(32768-v, trail(v), trail(v+1)+1)
		if c == 0 {
			c = 1
		}
		fmt.Fprintf(out, "%d ", c)
	}
	fmt.Fprintln(out)
}

package main

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

func min(a int, rest ...int) int {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

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

	var n int
	fmt.Fscan(in, &n)

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

		trail := func(n int) int {
			if n <= 0 {
				return 0
			}

			var c int
			for n%32768 != 0 {
				c++
				n *= 2
			}
			return c
		}

		c := min(32768-v, trail(v), trail(v+1)+1)
		if c == 0 {
			c = 1
		}
		fmt.Fprintf(out, "%d ", c)
	}
	fmt.Fprintln(out)
}

package main

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

func min(a int, rest ...int) int {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

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

	var n int
	fmt.Fscan(in, &n)

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

		trail := func(n int) int {
			if n <= 0 {
				return 0
			}

			var c int
			for n%32768 != 0 {
				c++
				n *= 2
			}
			return c
		}

		c := min(32768-v, trail(v), trail(v+1)+1)
		fmt.Fprintf(out, "%d ", c)
	}
	fmt.Fprintln(out)
}

package main

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

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

	var n int
	fmt.Fscan(in, &n)

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

		t := v
		var c int
		if v%2 != 0 {
			c++
			v++
		}

		for v%32768 != 0 {
			c++
			v *= 2
		}

		if 32768-t < c {
			c = 32768 - t
		}

		fmt.Fprintf(out, "%d ", c)
	}
	fmt.Fprintln(out)
}

package main

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

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

	var n int
	fmt.Fscan(in, &n)

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

		var c int
		if v%2 != 0 {
			c++
			v++
		}

		var z int
		if v > 0 {
			z = 16 - bits.TrailingZeros(uint(v)) - 1
			if 32768-v < z {
				z = 32768 - v
			}
		}
		fmt.Fprintf(out, "%d ", z+c)
	}
	fmt.Fprintln(out)
}

package main

import (
	"fmt"
	"math"
)

var step [32769]int64
var MOD int64 = 32768

func initStep() {
	for i := int64(0); i < MOD; i++ {
		step[i] = math.MaxInt
	}
	var queue []int64
	queue = append(queue, MOD)
	ct := 102768
	for len(queue) > 0 && ct > 0 {
		now := queue[0]
		queue = queue[1:]
		if now%2 == 0 {
			next1 := now / 2
			if step[next1] == math.MaxInt {
				step[next1] = step[now] + 1
				queue = append(queue, next1)
			}
		}
		if (now+MOD)%2 == 0 {
			next2 := (now + MOD) / 2
			if step[next2] == math.MaxInt {
				step[next2] = step[now] + 1
				queue = append(queue, next2)
			}
		}
		if now-1 >= 0 {
			next3 := now - 1
			if step[next3] == math.MaxInt {
				step[next3] = step[now] + 1
				queue = append(queue, next3)
			}
		}

	}

}

func main() {
	initStep()
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])

		fmt.Println(step[a[i]])
	}
}

package main

import (
	"fmt"
	"math"
)

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

var step [32769]int
var MOD int = 32768

func initStep() {
	for i := 0; i < MOD; i++ {
		step[i] = math.MaxInt
	}
	var queue []int
	queue = append(queue, MOD)
	ct := 102768
	for len(queue) > 0 && ct > 0 {
		now := queue[0]
		queue = queue[1:]
		if now%2 == 0 {
			next1 := now / 2
			if step[next1] == math.MaxInt {
				step[next1] = step[now] + 1
				queue = append(queue, next1)
			}
		}
		if (now+MOD)%2 == 0 {
			next2 := (now + MOD) / 2
			if step[next2] == math.MaxInt {
				step[next2] = step[now] + 1
				queue = append(queue, next2)
			}
		}
		if now-1 > 0 {
			next3 := now - 1
			if step[next3] == math.MaxInt {
				step[next3] = step[now] + 1
				queue = append(queue, next3)
			}
		}

	}

}

func main() {
	initStep()
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])

		fmt.Println(step[a[i]])
	}
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}
func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}
func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

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

func main() {
	ip := bufio.NewReader(os.Stdin)
	_ = readInt(ip)
	a := readArrInt(ip)
	ans := 0
	for i := range a {
		if a[i]==0{
			fmt.Print(0, " ")
			continue
		}
		ans = 0
		tmp := 0
		if a[i]%2 == 1 {
			ans++
			a[i]++
		}
		p := a[i]
		for p%2 == 0 {
			p >>= 1
			tmp++
		}
		ans += min(15-tmp, 32768-a[i])
		fmt.Print(ans, " ")
	}

}

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

package main

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

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

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

	var T int
	var x int
	mod := 32768

	dp := make([]int, mod+1)
	st := []int{32768}
	dp[32768] = 0
	for len(st) > 0 {
		ns := []int{}
		for _, v := range st {
			pre := v - 1
			if pre > 0 && dp[pre] == 0 {
				dp[pre] = dp[v] + 1
				ns = append(ns, pre)
			}

			if v%2 == 0 {
				d := v/2
				if dp[d] == 0 {
					dp[d] = dp[v]+1
					ns = append(ns,d)
				}

				div := ((v + mod) / 2) % mod
				if dp[div] == 0 {
					dp[div] = dp[v] + 1
					ns = append(ns, div)
				}
			}
		}
		st = ns
	}
	//Println(dp[mod/2])
	//Println(dp[mod/4])

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x)

		Fprintln(out, dp[x])
	}
}

package main

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

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

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

func main() {
	defer out.Flush()

	N := 32768
	count := make([]int, N+1)
	for i := 0; i < len(count); i++ {
		count[i] = -1
	}
	count[N] = 0

	stack := make([][]int, 0)
	stack = append(stack, []int{N, 0})
	index := 0
	for index < len(stack) {
		s, l := stack[index][0], stack[index][1]
		index++

		if s > 0 {
			if s%2 == 0 {
				{
					s := s / 2
					if count[s] == -1 {
						count[s] = l + 1
						stack = append(stack, []int{s, l + 1})
					}
				}
				{
					s := (s + N) / 2
					if count[s] == -1 {
						count[s] = l + 1
						stack = append(stack, []int{s, l + 1})
					}
				}
			}
			s = s - 1
			if count[s] == -1 {
				count[s] = l + 1
				stack = append(stack, []int{s, l + 1})
			}
		}

	}

	// fmt.Fprintln(out, count)

	var n int
	fmt.Fscan(in, &n)

	a := make([]int64, n)

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

	for i := 0; i < len(a); i++ {
		fmt.Fprint(out, count[a[i]], " ")
	}
}


package main

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

func (io *IO) Solve_() bool {
	n, k := io.Int64(), io.Int64()
	if k%3 != 0 {
		return n%3 != 0
	}
	if n%(k+1) == k {
		return true
	}
	if (n%(k+1))%3 == 0 {
		return false
	}
	return true
}

func (io *IO) Solve() {
	t := io.Int()
	for i := 0; i < t; i++ {
		if io.Solve_() {
			io.Print("Alice\n")
		} else {
			io.Print("Bob\n")
		}
	}
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int64() (n int64) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int64(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func (io *IO) UInt() (n uint) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + uint(v-'0')
	}
	return
}

func (io *IO) Bytes() (s []byte) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	s = make([]byte, len(buf))
	copy(s, buf)
	return
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) UIntArray(n int) (arr []uint) {
	arr = make([]uint, n)
	for i := 0; i < n; i++ {
		arr[i] = io.UInt()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

func (io *IO) setBuffer() {
	io.scanner.Buffer(make([]byte, 4096), 512*1024)
}

package main

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

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

	var t, n, k int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		if k%3 == 0 {
			n %= k + 1
			if n == k {
				Fprintln(out, "Alice")
				continue
			}
		}
		if n%3 != 0 {
			Fprintln(out, "Alice")
		} else {
			Fprintln(out, "Bob")
		}
	}
}

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


package main
import (
	"fmt"
)

func main() {
	var a,g,h,j,k,i,mi,in int
	fmt.Scan(&a,&k)
	d:=make([]int,1000)
	f:=make([]int,1000)
	for i=0;i<k;i++ {
		fmt.Scan(&d[i])
		f[i]=d[i]
	}
	for i=0;i<a;i++ {
		mi=10000
		in=-1
		for j=0;j<k;j++ {
			if d[j]<mi && d[j]>0 {
				mi=d[j]
				in=j
			}
		}
		if in==-1 {
			break
		}
		g+=d[in]
		d[in]--
	}
	for i=0;i<a;i++ {
		mi=0
		in=-1
		for j=0;j<k;j++ {
			if f[j]>mi && f[j]>0 {
				mi=f[j]
				in=j
			}
		}
		if in==-1 {
			break
		}
		h+=f[in]
		f[in]--

	}
	fmt.Print(h," ",g)
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

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

	n, m := scanInt(scanner), scanInt(scanner)
	minPlanes, maxPlanes := make([]int, m), make([]int, m)
	for i := 0; i < m; i++ {
		minPlanes[i] = scanInt(scanner)
		maxPlanes[i] = minPlanes[i]
	}
	minCost, maxCost := 0, 0
	nonzero := 0
	for i := 0; i < n; i++ {
		sort.Ints(minPlanes)
		for minPlanes[nonzero] == 0 {
			nonzero++
		}
		minCost += minPlanes[nonzero]
		minPlanes[nonzero]--
		sort.Ints(maxPlanes)
		maxCost += maxPlanes[m-1]
		maxPlanes[m-1]--
	}
	writer.WriteString(fmt.Sprintf("%d %d\n", maxCost, minCost))
}

package main

import "fmt"

func main() {
    var n,m,a int
    var cnt [1001]int
    fmt.Scan(&n,&m)
    for i := 0; i < m; i++ {
        fmt.Scan(&a)
        cnt[a]++
    }
    min, n_min := 0, n
    for i := 1; (i <= 1000) && (n_min > 0); i++ {
        for j := 0; (j < cnt[i]) && (n_min > 0); j++ {
            total := (i*(i+1))/2
            if n_min < i {
                d := i-n_min
                total -= (d*(d+1))/2
            }
            n_min -= i
            min += total
        }
    }
    max, n_max := 0, n
    for i := 1000; (i >= 1) && (n_max > 0); {
        if cnt[i] != 0 {
            max += i
            n_max -= 1
            cnt[i-1]++
            cnt[i]--
        } else {
            i--
        }
    }
    fmt.Println(max,min)
}

package main

import "fmt"

func main() {
    var n,m,a int						// membuat variabel n,m,a dengan jenis int
    var cnt [1001]int					// membuat variabel cnt[1001] dengan jenis int
    fmt.Scan(&n,&m)						// mengambil input
    for i := 0; i < m; i++ {			// looping 1
        fmt.Scan(&a)					// mengambil input kedua
        cnt[a]++						// cnt[a] ditambah terus
    }
    min, n_min := 0, n					// membuat variabel min dan n_min kemudian diisi dengan 0 dan n
    for i := 1; (i <= 1000) && (n_min > 0); i++ {  // looping ke 2
        for j := 0; (j < cnt[i]) && (n_min > 0); j++ {  // looping ke 3
            total := (i*(i+1))/2		// membuat variabel total dan diisi dengan hasil dari (i*(i+1))/2
            if n_min < i {				// if n_min lebih kecil dari i
                d := i-n_min			// maka buat variabel d dan diisi dengan hasil dari i-n_min
                total -= (d*(d+1))/2   // total dikurang (d*(d+1))/2
            }
            n_min -= i				// n_min dikurang i
            min += total			// min ditambah total
        }
    }
    max, n_max := 0, n					// membuat variabel max dan n_max dan diisi dengan 0 dan n
    for i := 1000; (i >= 1) && (n_max > 0); { // looping ke empat
        if cnt[i] != 0 {				// if cnt[i] tidak sama dengan 0
            max += i					// maka max ditambah i
            n_max -= 1					// n_max dikurang 1
            cnt[i-1]++					// cnt [i-1] ditambah terus
            cnt[i]--					// cnt[i] dikurang terus
        } else {						// lainnya
            i--							// i dikurang terus
        }
    }
    fmt.Println(max,min)				// cetak hasil max dan min
}

// 218B-mic
package main

import (
    "fmt"
)

func main() {
    var n, m, r1, r2 int
    var a1, a2 [1005]int
    fmt.Scan(&n, &m)
    for i := 0; i < m; i++ {
        fmt.Scan(&a1[i])
        a2[i] = a1[i]
    }

    for i := 0; i < n; i++ {
        max := -1
        min := 1005
        mi_ind := -1
        ma_ind := -1
        for j := 0; j < m; j++ {
            if a1[j] > max {
                max = a1[j]
                ma_ind = j
            }
            if a2[j] < min && a2[j] > 0 {
                min = a2[j]
                mi_ind = j
            }
        }
        r1 += max
        r2 += min

        a1[ma_ind]--
        a2[mi_ind]--
    }
    fmt.Print(r1)
    fmt.Print(" ")
    fmt.Print(r2)
    fmt.Println()
}

package main

import "fmt"

func main() {
    var n,m,a int
    var cnt [1001]int
    fmt.Scan(&n,&m)
    for i := 0; i < m; i++ {
        fmt.Scan(&a)
        cnt[a]++
    }
    min, n_min := 0, n
    for i := 1; (i <= 1000) && (n_min > 0); i++ {
        for j := 0; j < cnt[i]; j++ {
            total := (i*(i+1))/2
            if n_min < i {
                d := i-n_min
                total -= (d*(d+1))/2
            }
            n_min -= i
            min += total
        }
    }
    max, n_max := 0, n
    for i := 1000; (i >= 1) && (n_max > 0); {
        if cnt[i] != 0 {
            max += i
            n_max -= 1
            cnt[i-1]++
            cnt[i]--
        } else {
            i--
        }
    }
    fmt.Println(max,min)
}