package main

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

func sum(a []int) int {
	ret := 0
	for _, v := range a {
		ret += v
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	x, y, a, b, c := nextInt(), nextInt(), nextInt(), nextInt(), nextInt()
	p, q, r := nextInts(a), nextInts(b), nextInts(c)
	sort.Sort(sort.IntSlice(p))
	sort.Sort(sort.IntSlice(q))
	sort.Sort(sort.IntSlice(r))

	p = p[a-x:]
	q = q[b-y:]

	for i, j, k := 0, 0, c-1; (i < x || j < y) && k >= 0; k-- {
		if i < x && j < y && p[i] < q[j] && p[i] < r[k] {
			// pの要素が最小
			p[i] = r[k]
			i++
		} else if i < x && j < y && p[i] > q[j] && q[j] < r[k] {
			// qの要素が最小
			q[j] = r[k]
			j++
		} else if i < x && p[i] < r[k] {
			p[i] = r[k]
			i++
		} else if j < y && q[j] < r[k] {
			q[j] = r[k]
			j++
		} else {
			break
		}
	}

	ans := sum(p) + sum(q)

	puts(ans)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

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

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

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

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


package main

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

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

func main() {
	X := readInt()
	Y := readInt()
	A := readInt()
	B := readInt()
	C := readInt()

	p := make([]int, A+1)
	q := make([]int, B+1)
	r := make([]int, C+1)

	for i := 0; i < A; i++ {
		p[i+1] = readInt()
	}
	for i := 0; i < B; i++ {
		q[i+1] = readInt()
	}
	for i := 0; i < C; i++ {
		r[i+1] = readInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(p)))
	sort.Sort(sort.Reverse(sort.IntSlice(q)))
	sort.Sort(sort.Reverse(sort.IntSlice(r)))

	for i := 0; i < A-1; i++ {
		p[i+1] += p[i]
	}
	for i := 0; i < B-1; i++ {
		q[i+1] += q[i]
	}
	for i := 0; i < C-1; i++ {
		r[i+1] += r[i]
	}

	result := 0
	for i := max(0, X-C); i <= X; i++ {
		j := 0
		ok := max(0, Y-(C-(X-i)))
		if ok != Y {
			ng := Y
			for ng-ok != 1 {
				m := ok + (ng-ok)/2
				t0 := 0
				t1 := 0
				if m != 0 {
					t0 += q[m-1]
				}
				k := (X - i) + (Y - m)
				if k != 0 {
					t0 += r[k-1]
				}
				t1 += q[m]
				k = (X - i) + (Y - (m + 1))
				if k != 0 {
					t1 += r[k-1]
				}
				if t0 <= t1 {
					ok = m
				} else {
					ng = m
				}
			}
			j = ok + 1
		} else {
			j = Y
		}

		t := 0
		if i != 0 {
			t += p[i-1]
		}
		if j != 0 {
			t += q[j-1]
		}
		k := (X - i) + (Y - j)
		if k != 0 {
			t += r[k-1]
		}
		result = max(result, t)
	}

	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

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

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


package main

import (
	"fmt"
	"sort"
)

func main() {
	var x, y, a, b, c int
	fmt.Scan(&x, &y, &a, &b, &c)
	apples := make([]apple, 0, a+b+c)
	for a > 0 {
		a--
		var d int64
		fmt.Scan(&d)
		apples = append(apples, apple{d, 1})
	}
	sort.Sort(byDel(apples))
	apples = apples[:x]
	for b > 0 {
		b--
		var d int64
		fmt.Scan(&d)
		apples = append(apples, apple{d, 2})
	}
	sort.Sort(byDel(apples[x:]))
	apples = apples[:x+y]
	for c > 0 {
		c--
		var d int64
		fmt.Scan(&d)
		apples = append(apples, apple{d, 0})
	}
	if c > x+y {
		sort.Sort(byDel(apples[x+y:]))
		apples = apples[:x+x+y+y]
	}
	sort.Sort(byDel(apples))
	eaten := 0
	var total int64
	for _, a := range apples {
		switch a.color {
		case 0:
			eaten++
			total += a.del
		case 1:
			if x > 0 {
				x--
				total += a.del
			}
		case 2:
			if y > 0 {
				y--
				total += a.del
			}
		}
		if eaten == x+y {
			break
		}
	}
	fmt.Printf("%d\n", total)
}

type apple struct {
	del   int64
	color int
}

type byDel []apple

func (a byDel) Len() int           { return len(a) }
func (a byDel) Less(i, j int) bool { return a[i].del > a[j].del }
func (a byDel) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }


package main

import (
	"fmt"
	"sort"
)

func main() {
	var x, y, a, b, c, ans int
	fmt.Scan(&x)
	fmt.Scan(&y)
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	p := make([]int, a)
	q := make([]int, b)
	r := make([]int, c)
	for i := 0; i < a; i++ {
		fmt.Scan(&p[i])
	}
	for i := 0; i < b; i++ {
		fmt.Scan(&q[i])
	}
	for i := 0; i < c; i++ {
		fmt.Scan(&r[i])
	}

	sort.Ints(p)
	sort.Ints(q)
	sort.Ints(r)

	for i := 0; i < x; i++ {
		if p[len(p)-1] > r[len(r)-1] {
			ans += p[len(p)-1]
			p = p[:len(p)-1]
		} else {
			ans += r[len(r)-1]
			r = r[:len(r)-1]
		}
	}
	for i := 0; i < y; i++ {
		if q[len(q)-1] > r[len(r)-1] {
			ans += q[len(q)-1]
			q = q[:len(q)-1]
		} else {
			ans += r[len(r)-1]
			r = r[:len(r)-1]
		}
	}
	fmt.Println(ans)
}


package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

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

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	X, Y, A, B, C := sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()
	P := sc.nextIntSlice(A)
	Q := sc.nextIntSlice(B)
	R := sc.nextIntSlice(C)
	sort.Sort(sort.Reverse(sort.IntSlice(P)))
	sort.Sort(sort.Reverse(sort.IntSlice(Q)))
	sort.Sort(sort.Reverse(sort.IntSlice(R)))
	arr := []int{}
	for i := 0; i < X; i++ {
		arr = append(arr, P[i])
	}
	//fmt.Fprintln(wtr, "after P", arr)
	for i := 0; i < Y; i++ {
		arr = append(arr, Q[i])
	}
	sort.Ints(arr)
	//fmt.Fprintln(wtr, arr)
	idx := 0
	for i := 0; i < len(arr); i++ {
		if arr[i] < R[idx] {
			arr[i] = R[idx]
			idx++
			if idx == C {
				break
			}
		} else {
			break
		}
	}
	ans := 0
	for i := 0; i < len(arr); i++ {
		ans += arr[i]
	}

	fmt.Fprintln(wtr, ans)
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var A, B, C float64
	fmt.Scan(&A, &B, &C)
	if C-A-B > 0 && 4*A*B < math.Pow(C-A-B, 2) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Score : 300 points

Problem Statement

Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?

Constraints

1 \leq a, b, c \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a \ b \ c

Output

If \sqrt{a} + \sqrt{b} < \sqrt{c}, print Yes; otherwise, print No.

Sample Input 1

2 3 9

Sample Output 1

No

\sqrt{2} + \sqrt{3} < \sqrt{9} does not hold.

Sample Input 2

2 3 10

Sample Output 2

Yes

\sqrt{2} + \sqrt{3} < \sqrt{10} holds.


package main

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

/* sort */
type pair struct {
	index  int64
	p1, p2 interface{}
}
type pairs []pair

func (slice pairs) Len() int {
	return len(slice)
}

func (slice pairs) Less(i, j int) bool {
	return slice[i].index < slice[j].index
}

func (slice pairs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

/* sort */
type Int64Slice []int64

func (slice Int64Slice) Len() int {
	return len(slice)
}

func (slice Int64Slice) Less(i, j int) bool {
	return slice[i] < slice[j]
}

func (slice Int64Slice) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}
func Int64s(a []int64)                    { sort.Sort(Int64Slice(a)) }
func Int64sSliceAreSorted(a []int64) bool { return sort.IsSorted(Int64Slice(a)) }

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
	INF            = 1e8
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
	di      = []int64{-1, 0, 1, 0}
	dj      = []int64{0, -1, 0, 1}
	di8     = []int64{-1, -1, 0, 1, 1, 1, 0, -1}
	dj8     = []int64{0, -1, -1, -1, 0, 1, 1, 1}
)

func main() {
	buf := make([]byte, initialBufSize)
	scanner.Buffer(buf, maxBufSize)
	scanner.Split(bufio.ScanWords)
	a, b, c := readInt(), readInt(), readInt()
	d := c - a - b
	if d > 0 && d*d > 4*a*b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

/*==========================================
 *             Library
 *==========================================*/
func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}
func doubleAry(h int64, w int64, init int64) (res [][]int64) {
	res = make([][]int64, h)
	for i := int64(0); i < h; i++ {
		res[i] = make([]int64, w)
		for j := int64(0); j < w; j++ {
			res[i][j] = init
		}
	}
	return
}

func aryEq(a []int64, b []int64) bool {
	return reflect.DeepEqual(a, b)
}

func clone(n []int64) (r []int64) {
	r = make([]int64, len(n))
	for i := 0; i < len(n); i++ {
		r[i] = n[i]
	}
	return
}
func write(s string) {
	writer.WriteString(s)
}

func print() {
	writer.Flush()
}

// scanner.Split(bufio.ScanWords) をコメントアウトしないと使用不可
func readLine() (s string) {
	if scanner.Scan() {
		s = scanner.Text()
	}
	return s
}

func readInt() (read int64) {
	scanner.Scan()
	read, err := strconv.ParseInt(scanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return
}

func readFloat() (read float64) {
	scanner.Scan()
	read, err := strconv.ParseFloat(scanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return
}

func readRunes() (read []rune) {
	scanner.Scan()
	for _, v := range scanner.Text() {
		read = append(read, v)
	}
	return
}

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

func readStrings() (read []string) {
	scanner.Scan()
	for _, v := range scanner.Text() {
		read = append(read, string(v))
	}
	return
}

func s2i(s string) int64 {
	var intVal, e = strconv.ParseInt(s, 10, 64)
	if e != nil {
		panic(e)
	}
	return intVal
}

func i2s(i int64) string {
	var strVal = strconv.FormatInt(i, 10)
	return strVal
}

func s2f(s string) float64 {
	var floatVal, e = strconv.ParseFloat(s, 64)
	if e != nil {
		panic(e)
	}
	return floatVal
}

func abs(i int64) int64 {
	return int64(math.Abs(float64(i)))
}

func max(a ...int64) int64 {
	ans := int64(0)
	for i, v := range a {
		if i == 0 {
			ans = v
		}
		if ans < v {
			ans = v
		}
	}
	return ans
}
func min(a ...int64) int64 {
	ans := int64(0)
	for i, v := range a {
		if i == 0 {
			ans = v
		}
		if ans > v {
			ans = v
		}
	}
	return ans
}

func sum(i []int64) int64 {
	sum := int64(0)
	for _, val := range i {
		sum += val
	}
	return sum
}

func split(s string) []string {
	return strings.Fields(s)
}

func strAry2intAry(strs []string) []int64 {
	var ret = make([]int64, 0, len(strs))
	for _, str := range strs {
		var intVal = s2i(str)
		ret = append(ret, intVal)
	}
	return ret
}

func intAry2strAry(nums []int64) []string {
	var ret = make([]string, 0, len(nums))
	for _, num := range nums {
		var strVal = i2s(num)
		ret = append(ret, strVal)
	}
	return ret
}

func ary2str(strs []string) string {
	return strings.Join(strs, " ")
}

func reverse(res []int64) []int64 {
	for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
		res[i], res[j] = res[j], res[i]
	}
	return res
}
func reverseStr(res []string) []string {
	for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
		res[i], res[j] = res[j], res[i]
	}
	return res
}

func ini(res []int, init int) {
	if len(res) == 0 {
		return
	}
	res[0] = init
	for i := 0; i < len(res); i++ {
		copy(res[i:], res[:i])
	}
}

//
// func regexpExample() {
//     // Your code here!
//     var str = "13:20"
//     r := regexp.MustCompile(`(\d+):(\d+)`)
//     fmt.Println(r.FindStringSubmatch(str))
// }

// type Country struct {
//     gold int
//     silver int
//     blonze int
// }

// // 複数ソートのサンプル
// func stableSortExample() []Country{
//     var country = []Country {
//         {gold:1, silver:2, blonze:3},
//         {gold:1, silver:2, blonze:3},
//         {gold:1, silver:3, blonze:2},
//         {gold:1, silver:3, blonze:3},
//     }
//     sort.SliceStable(country, func(i, j int) bool { return country[i].blonze > country[j].blonze })
//     sort.SliceStable(country, func(i, j int) bool { return country[i].silver > country[j].silver })
//     sort.SliceStable(country, func(i, j int) bool { return country[i].gold > country[j].gold })
//     return country
// }


package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)

	// if (c-a-b)*(c-a-b) > 4*a*b {
	if (c - a - b) > 2*int(math.Sqrt(float64(a*b))) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var (
		a float64
		b float64
		c float64
	)
	fmt.Scan(&a, &b, &c)

	if c+2*math.Sqrt(a*b) > a+b {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}


package main

import (
	"fmt"
)

func main() {
	var a, b, c float64
	fmt.Scan(&a, &b, &c)

	x := c - a - b
	if x > 0 && 4*a*b < x*x {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


package main

import (
	"fmt"
)

func main() {
	var a, b, c int64

	fmt.Scan(&a, &b, &c)

	d := c - a - b
	if d < 0 {
		fmt.Println("No")
		return
	}

	if d*d > 4*a*b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

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

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	a, b, c := sc.nextInt(), sc.nextInt(), sc.nextInt()
	if c-a-b > 0 && 4*a*b < pow(c-a-b, 2) {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
}


package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"math"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

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

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	a, b, c := sc.nextFloat(), sc.nextFloat(), sc.nextFloat()
	if c-a-b > 0 && 4*a*b < math.Pow(c-a-b, 2) {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
}


package main

import (
	"fmt"
  "math"
)

// inspired by https://tour.golang.org/flowcontrol/8
// https://gist.github.com/alenbasic/108417acbff63d765f9da5e036fc018b
// https://gist.github.com/abesto/3476594

// func Sqrt(loop int, seed, square float64) float64 {
//
// 	x := seed
// 	for i := 0; i < loop; i++ {
// 		x = x - ((x*x)-square)/(2*x)
// 	}
// 	return x
//
// }
const DELTA = 0.0000000000001
const INITIAL_Z = 100.0

func Sqrt(x float64) (z float64) {
    z = INITIAL_Z

    step := func() float64 {
    	return z - (z*z - x) / (2 * z)
    }

    for zz := step(); math.Abs(zz - z) > DELTA
    {
    	z = zz
	zz = step()
    }
    return
}

func main() {
  var a,b,c float64
  fmt.Scan(&a)
  fmt.Scan(&b)
  fmt.Scan(&c)

  ra := Sqrt(a)
  rb := Sqrt(b)
  rc := Sqrt(c)
  left := ra+rb

  if left < rc {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}


package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt64(scanner)
	b := getNextInt64(scanner)
	c := getNextInt64(scanner)

	if c-(a+b) >= 0 {
		if 4*a*b < (c-(a+b))*(c-(a+b)) {
			fmt.Fprintln(writer, "Yes")
			return
		}
		fmt.Fprintln(writer, "No")
		return
	}
	if 4*a*b > (c-(a+b))*(c-(a+b)) {
		fmt.Fprintln(writer, "Yes")
		return
	}
	fmt.Fprintln(writer, "No")
}


package main

import "fmt"
import "math"

func Sum(values []float64) float64 {
	var partials []float64
	for _, x := range values {
		i := 0
		for _, y := range partials {
			if math.Abs(x) < math.Abs(y) {
				tmp := x
				x = y
				y = tmp
			}
			hi := x + y
			lo := y - (hi - x)
			if lo != 0.0 {
				partials[i] = lo
				i++
			}
			x = hi
		}
		if i < len(partials) {
			partials[i] = x
			partials = partials[0 : i+1]
		} else {
			partials = append(partials, x)
		}
	}
	var result float64
	for _, x := range partials {
		result += x
	}
	return result
}

func main() {
	var a, b, c float64
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)

	ar := make([]float64, 2, 2)
	ar[0] = math.Sqrt(a)
	ar[1] = math.Sqrt(b)

	res := Sum(ar) < math.Sqrt(c)

	if res {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


package main

import "fmt"
import "math"

func main() {
	var a, b, c float64
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)

	left := (a + b - c) / -2
	right := math.Sqrt(a*b)

	// fmt.Println(left)
	// fmt.Println(right)

	res := left > right

	if res {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


package main

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

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

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

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

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

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	a := nextFloat64()
	b := nextFloat64()
	c := nextFloat64()
	if math.Pow((math.Sqrt(a)+math.Sqrt(b)), 2.0) < c {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}


package main

import (
	"fmt"
	"math"
)

func solution(a, b, c int) string {
	if math.Sqrt(float64(a))+math.Sqrt(float64(b)) < math.Sqrt(float64(c)) {
		return "Yes"
	}
	return "No"
}

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	fmt.Println(solution(a, b, c))
}


package main

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

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Simple math functions

const (
	// big prime
	MOD = 1000000007
	INF = math.MaxInt64
)

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

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

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

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

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

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

func pow(p, q int) int {
    return int(math.Pow(float64(p), float64(q)))
}

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

func lcm(a,b int) int{
  return a * b / gcd(a, b)
}

func isInteger(x float64) bool {
    return math.Floor(x) == x
}

// lower_bound
func bisectLeft(a []int, x int) int {
    return sort.SearchInts(a, x)
}

// upper_bound
func bisectRight(a []int, x int) int {
    return sort.Search(len(a), func(i int) bool { return a[i] > x })
}

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

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

func main() {
  defer Flush()

  a,b,c := readi(), readi(), readi()

  if a + b < c{
	  println("Yes")
  } else {
	  println("No")
  }
}


package main

import (
	"fmt"
	"math"
)

func main() {

	var a, b, c float64
	fmt.Scan(&a, &b, &c)

	sum := math.Sqrt(a) + math.Sqrt(b)

	if sum < math.Sqrt(c) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c float64
	fmt.Scan(&a, &b, &c)

	if math.Sqrt(a)+math.Sqrt(b)-math.Sqrt(c) < 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	answer := compareSqrt(a, b, c)
	if answer {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func compareSqrt(a, b, c int) bool {
	return 4*a*b < (c*c + a*a + b*b - 2*c*a - 2*c*b + 2*a*b)
}


package main

import (
	"fmt"
)

func main() {
	var a, b, c int64
	fmt.Scanf("%d %d %d", &a, &b, &c)
	if c*c-2*c*(a+b)+(a-b)*(a-b) > 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c float64
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)

	if math.Sqrt(a)+math.Sqrt(b) < math.Sqrt(c) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


package main

import (
	"fmt"
	"math"
)

func main() {
	var (
		a, b, c float64
	)

	fmt.Scan(&a, &b, &c)

	if math.Sqrt(a) + math.Sqrt(b) < math.Sqrt(c) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


package main

import "fmt"

var a, b, c int

func main() {
	fmt.Scan(&a, &b, &c)
	if c-a-b <= 0 {
		fmt.Println("No")
		return
	}

	n := c*c + (a+b)*(a+b) - 4*a*b - 2*c*(a+b)

	if n > 0 {
		fmt.Println("Yes")

	} else {

		fmt.Println("No")
	}
}


package main

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

func main() {

	a := nextInt64()
	b := nextInt64()
	c := nextInt64()

	d := c - a - b
	if d >= 0 && 4*a*b < d*d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
	a := nextInt()
	b := nextInt()
	c := nextInt()
	if math.Sqrt(float64(a))+math.Sqrt(float64(b)) < math.Sqrt(float64(c)) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


package main

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

func main() {
	sc := NewScanner()
	A, B, C := sc.NextFloat(), sc.NextFloat(), sc.NextFloat()
	ans := math.Sqrt(A)+math.Sqrt(B) < math.Sqrt(C)
	if ans {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

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) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 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, K, V int
	fmt.Scan(&N)
	fmt.Scan(&M)
	l := make([]int, N)
	m := make(map[int]int, N)
	for i := 0; i < M; i++ {
	    fmt.Scan(&K)
		fmt.Scan(&V)
		m[K - 1] = m[K - 1] + 1
		if l[K-1] == 0 {
			l[K-1] = V
		} else if l[K-1] != V {
			fmt.Println(-1)
			return
		}
	}
	if N == 1 {
		fmt.Println(l[0])
	} else if l[0] == 0 && m[0] >= 1 {
		fmt.Println(-1)
		return
	} else if l[0] == 0 {
		l[0] = 1
		for _, v := range l {
			fmt.Print(v)
		}
	} else {
		for _, v := range l {
			fmt.Print(v)
		}
	}
}

Score : 300 points

Problem Statement

If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1.

The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)

The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)

Constraints

All values in input are integers.

1 \leq N \leq 3

0 \leq M \leq 5

1 \leq s_i \leq N

0 \leq c_i \leq 9

Input

Input is given from Standard Input in the following format:

N M
s_1 c_1
\vdots
s_M c_M

Output

Print the answer.

Sample Input 1

3 3
1 7
3 2
1 7

Sample Output 1

702

702 satisfies the conditions - its 1-st and 3-rd digits are 7 and 2, respectively - while no non-negative integer less than 702 satisfies them.

Sample Input 2

3 2
2 1
2 3

Sample Output 2

-1

Sample Input 3

3 1
1 0

Sample Output 3

-1


package main

import (
	"fmt"
)

func main() {

	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	s := make([]int, M)
	c := make([]int, M)
	number := make([]int, N)
	for i := 0; i < N; i++ {
		number[i] = -1
	}

	var flag int = 0
	for i := 0; i < M; i++ {
		fmt.Scanf("%d %d", &s[i], &c[i])
		if number[s[i]-1] == -1 {
			number[s[i]-1] = c[i]
		} else if number[s[i]-1] != -1 && number[s[i]-1] != c[i] {
			flag = 1
		}
	}

	if N > 1 {
		if number[0] == 0 {
			flag = 1
		} else if number[0] == -1 {
			number[0] = 1
		}

		for i := 1; i < N; i++ {
			if number[i] == -1 {
				number[i] = 0
			}
		}
	} else if N == 1 {
		if number[0] == -1 {
			number[0] = 0
		}
	}

	if flag == 1 {
		fmt.Println("-1")
	} else {
		for i := 0; i < N; i++ {
			fmt.Printf("%d", number[i])
		}
		fmt.Printf("\n")
	}
}


package main

import (
	"fmt"
	"math"
	"strconv"
)

type (
	Inn struct {
		index int
		value int
	}
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	in := []Inn{}
	for i := 0; i < m; i++ {
		ind := 0
		val := 0
		fmt.Scan(&ind, &val)
		if ind == 1 && val == 0 {
			fmt.Println(-1)
			return
		}
		in = append(in, Inn{
			index: ind,
			value: val,
		})
	}

	for i := int(math.Pow(10, float64(n-1))); i < int(math.Pow(10, float64(n))); i++ {
		temp := strconv.Itoa(i)
		for j, v := range in {
			if string(temp[v.index-1]) != strconv.Itoa(v.value) {
				break
			}
			if j == len(in)-1 {
				fmt.Println(i)
				return
			}
		}
	}
	fmt.Println(-1)
}


package main

import (
	"fmt"
	"math"
)

type (
	In struct {
		index int
		value int
	}
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	in := []In{}
	for i := 0; i < m; i++ {
		ind := 0
		val := 0
		fmt.Scan(&ind, &val)
		if ind == 1 && val == 0 {
			fmt.Println(-1)
			return
		}
		in = append(in, In{
			index: ind,
			value: val,
		})
	}

	ans := []In{}
	for i := 0; i < m; i++ {
		if !notIn(in[i].index, in[i].value, ans) {
			fmt.Println(-1)
			return
		}
		if !iin(in[i].index, in[i].value, ans) {
			ans = append(ans, in[i])
		}
	}

	fmt.Println(calc(n, ans))
}

func calc(n int, in []In) int {
	ans := 0
	for _, v := range in {
		ans += int(math.Pow(10, float64(n-v.index)) * float64(v.value))
	}
	return ans
}

func notIn(ind, val int, ans []In) bool {
	for _, v := range ans {
		if v.index == ind && v.value != val {
			return false
		}
	}
	return true
}

func iin(ind, val int, ans []In) bool {
	for _, v := range ans {
		if v.index == ind && v.value == val {
			return true
		}
	}
	return false
}


package main

import (
	"fmt"
	"strconv"
	"strings"
)

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

	s := make(map[int]int, m)

	tmpk, tmpv := 0, 0
	for i := 0; i < m; i++ {
		fmt.Scan(&tmpk,&tmpv)
		if s[tmpk] != 0 && s[tmpk] != tmpv {
			fmt.Println(-1)
			return
		} else {
			s[tmpk] = tmpv
		}
	}
	//fmt.Println(s)

	ans := make([]string, n)

	for i := 0; i < n; i++{
		if s[i+1] == 0 {
			ans[i] = "0"
		} else {
			ans[i] = strconv.Itoa(s[i+1])
		}
	}

	if ans[0] == "0" {
		fmt.Println(-1)
		return
	}

	fmt.Println(strings.Join(ans,""))
}


package main

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

func main() {
	var first, sc = mirLine(2)
	var N, _ int = first[0], first[1]

	var c []int = make([]int, 5)
	var check []bool = make([]bool, 5)

	for _, l := range sc {
		if check[l[0]-1] && c[l[0]-1] != l[1] {
			fmt.Printf("%d", -1)
			return
		}

		c[l[0]-1] = l[1]
		check[l[0]-1] = true
	}

	for i, ch := range check {
		if !ch {
			if i == 0 && N > 1 {
				c[0] = 1
			} else {
				c[i] = 0
			}
		}
	}

	if c[0] == 0 && N > 1 {
		fmt.Printf("%d", -1)
		return
	}

	for i := 0; i < N; i++ {
		fmt.Printf("%d", c[i])
	}
	return
}

//minf returns min{a, b}(a, b: float64)
func minf(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//mini returns min{a, b} (a, b: int)
func mini(a, b int) int {
	if a > b {
		return b
	}
	return a
}

//paw paw returns f^num
func paw(f float64, num int) float64 {
	var result float64 = 1
	for i := 0; num > i; i++ {
		result *= f
	}
	return result
}

//StrStdin Read standard input data
func StrStdin(line int) [][]string {
	var stringInput [][]string
	scanner := bufio.NewScanner(os.Stdin)

	for i := 0; i < line; i++ {
		scanner.Scan()
		if s := scanner.Text(); s != "" {
			stringInput = append(stringInput, strings.Split(strings.TrimSpace((scanner.Text())), " "))
		} else {
			break
		}
	}

	return stringInput
}

//rLine Read all standard input data
func rLine(line int) [][]string {
	var rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	var buf = make([]byte, 0, 1000000)
	var stringInput [][]string

	for i := 0; i < line; {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			stringInput = append(stringInput, strings.Split(strings.TrimSpace((string(buf))), " "))
			buf = []byte{}
			i++
		}
	}
	return stringInput
}

//irLine Read Standard input data and convert into integer
func irLine(i int) [][]int {
	return alitoas(rLine(i))
}

//mtrLine Read multi-line standard input data
// put the location of data of the number of lines in a first line
//ex:
// 3 5
// 1 2
// 2 3
// 3 5
// you have to put 1, where the number 3 put in the first line
func mrLine(line int) (first []int, other [][]string) {
	var rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	var buf = make([]byte, 0, 1000000)
	var Input []string
	var stringInput [][]string

	{
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			Input = strings.Split(strings.TrimSpace((string(buf))), " ")
			buf = []byte{}
		}
	}

	first = itoas(Input)

	for i := 0; i < first[line-1]; {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			stringInput = append(stringInput, strings.Split(strings.TrimSpace((string(buf))), " "))
			buf = []byte{}
			i++
		}
	}
	return first, stringInput
}

//mirLine  Read multi-line standard input data and convert into integer data
// put the location of data of the number of lines in a first line
//ex:
// 3 5
// 1 2
// 2 3
// 3 5
// you have to put 1, where the number 3 put in the first line
func mirLine(line int) (first []int, other [][]int) {
	var f, o = mrLine(line)
	return f, alitoas(o)
}

//itoa converts string to integer
func itoa(s string) int {
	var i, _ = strconv.Atoi(s)
	return i
}

//itoas converts string slice to integer slice
func itoas(S []string) []int {
	var result = make([]int, len(S))
	for i, s := range S {
		result[i] = itoa(s)
	}
	return result
}

//alitoas converts string 2 dimention slice to intger one
func alitoas(S [][]string) [][]int {
	var result = make([][]int, len(S))
	for i, s := range S {
		result[i] = itoas(s)
	}
	return result
}

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

func gcd3(a, b, c int) int {
	return gcd(gcd(a, b), c)
}


package main

import (
	"fmt"
	"strconv"
)

func main() {
	var N, M, f, t int
	fmt.Scan(&N, &M)
	s := make([]int, M)
	c := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&s[i], &c[i])
	}
	if N == 1 {
		f, t = 0, 10
	} else if N == 2 {
		f, t = 10, 100
	} else {
		f, t = 100, 1000
	}
	for i := f; i < t; i++ {
		if calc(i, s, c) {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(-1)

}
func calc(n int, s, c []int) bool {
	w := strconv.Itoa(n)
	for i := 0; i < len(s); i++ {
		s, _ := strconv.Atoi(string(w[s[i]-1]))
		if s != c[i] {
			return false
		}
	}
	return true
}


package main

import (
	"fmt"
	"strconv"
)

func main() {

	GuessTheNumber()

}

func GuessTheNumber() {

	var N, M int

	fmt.Scan(&N, &M)

	s := make([]int, M)
	c := make([]int, M)

	for i := 0; i < M; i++ {

		fmt.Scan(&s[i], &c[i])
	}

	result := make([]int, N)

	keta := 0
	number := 0

	for i := 0; i < M; i++ {

		keta = s[i]
		number = c[i]

		if s[i]<N{

		if result[keta-1] == 0 {

			result[keta-1] = number

		} else {

			if result[keta-1] == number {

			} else {

				fmt.Println(-1)
				return
			}
		}

		}else
		{

			fmt.Println(-1)
			return
		}

	}

	var stresult string

	for _, x := range result {

		stresult += strconv.Itoa(x)
	}

	var check string

	for j := 0; j < 1000; j++ {

		check = strconv.Itoa(j)

		if check == stresult {

			fmt.Println(stresult)
			return

		}

	}

	fmt.Println(-1)

}


package main

import (
	"fmt"
	"os"
)

func main() {
	var N, M int
	var s [6]int
	var c [6]int
	var r [6]int

	res := 0

	fmt.Scan(&N, &M)
	for i := 0; i < N; i++ {
		r[i] = 10
	}
	for i := 0; i < M; i++ {
		fmt.Scan(&s[i], &c[i])
		if r[N-s[i]] > c[i] {
			r[N-s[i]] = c[i]
		}
	}
	if r[N-1] == 0 {
		fmt.Printf("-1\n")
		fmt.Printf("B\n")
		os.Exit(0)
	}
	for i := 0; i < N; i++ {
		if i == N-1 && N > 1 && r[i] == 10 {
			r[i] = 1
		} else if r[i] == 10 {
			r[i] = 0
		}
	}
	power := 1
	for i := 0; i < N; i++ {
		res += power * r[i]
		power *= 10
	}

	// fmt.Printf("%v\n", M)
	// fmt.Printf("%v\n", s)
	// fmt.Printf("%v\n", c)

	fmt.Printf("%d\n", res)
}


package main

import (
	"fmt"
	"os"
)

func main() {
	var N, M int
	var s [6]int
	var c [6]int
	var r [6]int

	res := 0

	fmt.Scan(&N, &M)
	for i := 0; i < N; i++ {
		r[i] = 10
	}
	if N > 1 && M == 0 {
		fmt.Printf("-1\n")
		// fmt.Printf("C\n")
		os.Exit(0)
	}
	for i := 0; i < M; i++ {
		fmt.Scan(&s[i], &c[i])
		if r[N-s[i]] > c[i] {
			r[N-s[i]] = c[i]
		}
	}
	if r[N-1] == 0 {
		fmt.Printf("-1\n")
		// fmt.Printf("B\n")
		os.Exit(0)
	}
	for i := 0; i < N; i++ {
		if r[i] == 10 {
			r[i] = 0
		}
	}
	power := 1
	for i := 0; i < N; i++ {
		res += power * r[i]
		power *= 10
	}

	// fmt.Printf("%v\n", M)
	// fmt.Printf("%v\n", s)
	// fmt.Printf("%v\n", c)

	fmt.Printf("%d\n", res)
}


package main

import (
	"fmt"
)

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

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

	var s, c int
	duplicatedDefinition := false
	for i := 0; i < m; i++ {
		fmt.Scanf("%d %d", &s, &c)
		if num[s-1] != -1 && num[s-1] != c {
			duplicatedDefinition = true
		}
		num[s-1] = c
	}
	if duplicatedDefinition {
		fmt.Println(-1)
		return
	}
	if (num[0] == 0 && n == 1) || (num[0] == -1 && n == 1) {
		fmt.Println(0)
		return
	} else if num[0] == 0 {
		fmt.Println(-1)
		return
	}

	answer := ""
	for i, val := range num {
		if val == -1 {
			if i == 0 {
				val = 1
			} else {
				val = 0
			}
		}
		answer += fmt.Sprintf("%d", val)
	}

	fmt.Println(answer)

}


package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var sc [5][2]int
	var n, m int
	var ans [3]int
	fmt.Fscan(r, &n)

	if n < 1 {
		fmt.Println("-1")
		return
	}
	if m < 0 {
		fmt.Println("-1")
		return
	}
	if m > 5 {
		fmt.Println("-1")
		return
	}
	fmt.Fscan(r, &m)
	for i := 0; i < m; i++ {
		fmt.Fscan(r, &sc[i][0], &sc[i][1])
	}
	if n > 3 {
		fmt.Println("-1")
		return
	}

	var l3 []int
	var l2 []int
	var l1 []int
	for _, k := range sc {
		if k[0] == 3 {
			l3 = append(l3, k[1])
		}
		if k[0] == 2 {
			l2 = append(l2, k[1])
		}
		if k[0] == 1 {
			l1 = append(l1, k[1])
		}
		if k[1] < 0 {
			fmt.Println("-1")
			return
		}
		if k[1] >= 10 {
			fmt.Println("-1")
			return
		}
	}

	hoge1 := removeDuplicate1(l3)
	if len(hoge1) > 1 {
		fmt.Println("-1")
		return
	}
	sort.Sort(sort.IntSlice(hoge1))
	if len(hoge1) < 1 {
		hoge1 = append(hoge1, 0)
	}

	hoge2 := removeDuplicate1(l2)
	if len(hoge2) > 1 {
		fmt.Println("-1")
		return
	}
	sort.Sort(sort.IntSlice(hoge2))
	if len(hoge2) < 1 {
		hoge2 = append(hoge2, 0)
	}

	hoge3 := removeDuplicate1(l1)
	if len(hoge3) > 1 {
		fmt.Println("-1")
		return
	}
	sort.Sort(sort.IntSlice(hoge3))
	if len(hoge3) < 1 {
		hoge3 = append(hoge3, 0)
	}

	if n == 3 {
		ans[2] = hoge3[0] * 100
		ans[1] = hoge2[0] * 10
		ans[0] = hoge1[0]
	}

	if n == 2 {
		ans[1] = hoge2[0] * 10
		ans[0] = hoge1[0]
	}

	if n == 1 {
		ans[0] = hoge1[0]
	}

	if n == 3 {
		if ans[2] == 0 {
			fmt.Println("-1")
			return
		}
		fmt.Println(ans[2] + ans[1] + ans[0])
		return
	}
	if n == 2 {
		if ans[1] == 0 {
			fmt.Println("-1")
			return
		}
		fmt.Println(ans[1] + ans[0])
		return
	}
	if n == 1 {
		fmt.Println(ans[0])
		return
	}
}

func removeDuplicate1(args []int) []int {
	results := make([]int, 0, len(args))
	encountered := map[int]bool{}
	for i := 0; i < len(args); i++ {
		if !encountered[args[i]] {
			encountered[args[i]] = true
			results = append(results, args[i])
		}
	}
	return results
}


package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func main() {
	solve(NewScanner())
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

type rule struct {
	s int
	c int
}

func solve(s *Scanner) {
	wtr := bufio.NewWriter(os.Stdout)

	N, M := s.nextInt(), s.nextInt()

	ss := make([]int, M)
	cs := make([]int, M)

	for k := 0; k < M; k++ {
		ss[k], cs[k] = s.nextInt(), s.nextInt()
	}

	ansArray := make([]int, N)

	for i := 1; i <= N; i++ {
		ansArray[i-1] = 0
		tmps := 10
		tmpc := 10
		for j := 0; j < M; j++ {
			if ss[j] == i {
				ansArray[i-1] = cs[j]
				if tmps == ss[j] && tmpc != cs[j] {
					fmt.Fprintln(wtr, "-1")
					wtr.Flush()
					return
				}
				tmps = ss[j]
				tmpc = cs[j]
			}
		}
	}

	if M == 0 {
		if N == 1 {
			fmt.Fprintln(wtr, "0")
			wtr.Flush()
			return
		}

		ansArray[0] = 1
	}

	if ansArray[0] == 0 {
		fmt.Fprintln(wtr, "-1")
		wtr.Flush()
		return
	}

	ans := ""
	for i := 0; i < len(ansArray); i++ {
		ans += strconv.Itoa(ansArray[i])
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func main() {
	solve(NewScanner())
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

type rule struct {
	s int
	c int
}

func solve(s *Scanner) {
	wtr := bufio.NewWriter(os.Stdout)

	N, M := s.nextInt(), s.nextInt()

	ss := make([]int, M)
	cs := make([]int, M)

	for k := 0; k < M; k++ {
		ss[k], cs[k] = s.nextInt(), s.nextInt()
	}

	ansArray := make([]int, N)

	for i := 1; i <= N; i++ {
		ansArray[i-1] = 0
		tmp := 10
		for j := 0; j < M; j++ {
			if ss[j] == i {
				if cs[j] < tmp {
					ansArray[i-1] = cs[j]
				}
				tmp = cs[j]
			}
		}
	}

	if M == 0 {
		if N == 1 {
			fmt.Fprintln(wtr, "0")
			wtr.Flush()
			return
		}

		ansArray[0] = 1
	}

	if ansArray[0] == 0 {
		fmt.Fprintln(wtr, "-1")
		wtr.Flush()
		return
	}

	ans := ""
	for i := 0; i < len(ansArray); i++ {
		ans += strconv.Itoa(ansArray[i])
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


package main

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

var sc = bufio.NewScanner(os.Stdin)
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()

	num := make(map[int]int, n)
	for i := 0; i<m; i++ {
		s, c := nextInt(), nextInt()
		if v, ok := num[s]; ok {
			if v != c {
				fmt.Println("-1")
				return
			}
		}
		num[s] = c
	}

	if v, ok := num[n]; ok {
		if v == 0 && len(num) == 1{
			fmt.Println(0)
			return
		}
	}
	if v, ok := num[1]; ok {
		if v == 0 {
			fmt.Println("-1")
			return
		}
	}
	if len(num) == 1 {
		fmt.Println(0)
		return
	}

	for i := 1; i<=n; i++ {
		if v, ok := num[i]; ok {
			fmt.Print(v)
			continue
		}

		if i == 1 {
			fmt.Print(1)
			continue
		}
		fmt.Print(0)
	}
}


package main

import (
        "fmt"
        "strconv"
)

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

        t := make([]int, N, N)
        for i := range t {
                t[i] = -1
        }

        ret := true
        ans := ""
        for i := 0; i < M; i++ {
                var s, c int
                fmt.Scanf("%d %d\n", &s, &c)
                if t[s-1] == -1 {
                        t[s-1] = c
                        continue
                }
                if t[s-1] != c {
                        ret = false
                }
        }
        if !ret {
                fmt.Println(-1)
                return
        }
        for i := range t {
                if ans == "" && t[i] == -1 {
                        ans = "1"
                        continue
                }
                if t[i] == -1 {
                        ans += "0"
                } else {
                        ans += strconv.Itoa(t[i])
                }
        }
        if ans[:1] == "0" && ans != "0" {
                fmt.Println(-1)
                return
        }
        if len(ans) != N {
                fmt.Println(-1)
                return
        }
        a, _ := strconv.Atoi(ans)
        fmt.Println(a)

}


package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextLineValue() int {
  sc.Scan()
  return getInt(sc.Text())
}

func nextLineValues() []int {
  sc.Scan()
  return getIntArray(sc.Text())
}

func getInt(s string) int {
  v, _ := strconv.Atoi(s)
  return v
}

func getIntArray(s string) []int {
  var v []int
  valstr := strings.Split(s, " ")
  for _, c := range valstr {
    va, _ := strconv.Atoi(c)
    v = append(v, va)
  }
  return v
}

func digitTotal(v int) int {
  total := 0
  d := strings.Split(strconv.Itoa(v), "")
  for _, c := range d {
    dv, _ := strconv.Atoi(c)
    total += dv
  }
  return total
}

func sortDesc(v *[]int) {
  sort.Sort(sort.Reverse(sort.IntSlice(*v)))
}

func removeDupIntSlice(values *[]int) []int {
  m := make(map[int]bool)
  uniq := []int{}
  for _, v := range *values {
    if !m[v] {
      uniq = append(uniq, v)
      m[v] = true
    }
  }
  return uniq
}

func main() {
  nm := nextLineValues()

  answerString := make([]string, nm[0])
  for i:=0; i<nm[0]; i++ {
    answerString[i] = "*"
  }

  for i:=0; i<nm[1]; i++ {
    sc := nextLineValues()
    vstr := strconv.Itoa(sc[1])

    if answerString[sc[0]-1] != "*" && answerString[sc[0]-1] != vstr {
      fmt.Println("-1")
      return
    }
    answerString[sc[0]-1] = vstr
  }

  if len(answerString) > 1 && answerString[0] == "*" {
    answerString[0] = "1"
  } else if len(answerString) == 1 && answerString[0] == "*" {
    answerString[0] = "0"
  }

  for i:=1; i<nm[0]; i++ {
    if answerString[i] == "*" {
      answerString[i] = "0"
    }
  }

  if len(answerString) > 1 && answerString[0] == "0" {
    fmt.Println("-1")
    return
  }

  fmt.Println(strings.Join(answerString, ""))
}


package main

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

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

	charNumber := make([]byte, n)
	var s, c int
	duplicatedDefinition := false
	zeroSpecifiedAt := 99
	for i := 0; i < m; i++ {
		fmt.Scanf("%d %d", &s, &c)
		newNumber := byte(c + 48)
		if charNumber[s-1] != 0 && charNumber[s-1] != newNumber {
			duplicatedDefinition = true
		}
		charNumber[s-1] = newNumber
		if c == 0 && zeroSpecifiedAt > s {
			zeroSpecifiedAt = s
		}
	}
	if m == 1 && charNumber[0] == 48 {
		fmt.Println(0)
		return
	}
	if duplicatedDefinition {
		fmt.Println(-1)
		os.Exit(0)
	}
	if zeroSpecifiedAt == 1 {
		fmt.Println(-1)
		return
	} else if zeroSpecifiedAt > 1 && zeroSpecifiedAt != 99 {
		needToSetOneAtTop := true
		for i := zeroSpecifiedAt - 1; i >= 0; i-- {
			if charNumber[i] != 0 {
				needToSetOneAtTop = false
				break
			}
		}
		if needToSetOneAtTop {
			charNumber[0] = 1 + 48
		}
	}
	for i := 0; i < n; i++ {
		if charNumber[i] == 0 {
			charNumber[i] = 48 // set zero
		}
	}
	if charNumber[0] == 48 {
		charNumber[0] = 49 // head of digit cannot be zero
	}

	strNumber := string(charNumber)

	answer, err := strconv.ParseInt(strNumber, 10, 64)

	if err == nil && countDigit(answer) == n {
		fmt.Println(answer)
	} else {
		fmt.Println(-1)
	}
}

func countDigit(n int64) int {
	cnt := 1
	for n/10 > 0 {
		n = n / 10
		cnt++
	}
	return cnt
}


package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	nums := make([]int, n)
	var s, c int
	var flag, flag2 bool
	for i := 0; i < m; i++ {
		fmt.Scanf("%d %d", &s, &c)
		if s == 1 && c == 0 {
			flag = true
		}
		if nums[s-1] == 0 || nums[s-1] == c {
			nums[s-1] = c
		} else {
			flag2 = true
		}
	}
	if flag {
		fmt.Print("1")
		for i := 1; i < n; i++ {
			fmt.Print("0")
		}
		return
	}
	if flag2 {
		fmt.Println("-1")
		return
	}
	if m == 0 {
		if n == 1 {
			fmt.Println("0")
			return
		}
		fmt.Print("1")
		for i := 1; i < n; i++ {
			fmt.Print("0")
		}
		return
	}
	if n > 2 && nums[0] == 0 {
		fmt.Println("-1")
		return
	}
	for i := 0; i < n; i++ {
		fmt.Print(nums[i])
	}
}


package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	M := nextInt()
	conditions := make([]int, N)
	nums := make([]int, N)
	for i := 0; i < M; i++ {
		s := nextInt() - 1
		c := nextInt()
		if conditions[s] == 1 && nums[s] != c {
			fmt.Println(-1)
			return
		}
		nums[s] = c
		conditions[s] = 1
		// fmt.Println(nums)
	}
	ans := nums[0]*100 + nums[1]*10 + nums[2]
	if nums[0] == 0 {
		fmt.Println(-1)
	} else if ans >= 0 {
		fmt.Println(ans)
	} else {
		fmt.Println(-1)
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


package main

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

var sc = bufio.NewScanner(os.Stdin)
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()

	num := make(map[int]int, n)
	for i := 0; i<m; i++ {
		s, c := nextInt(), nextInt()
		if v, ok := num[s]; ok {
			if v != c {
				fmt.Println("-1")
				return
			}
		}
		num[s] = c
	}

	sum := 0
	for _, v := range num{
		sum += v
	}
	if sum == 0 {
		fmt.Println("-1")
		return
	}

	for i := 1; i<=n; i++ {
		if v, ok := num[i]; ok {
			fmt.Print(v)
			continue
		}
		fmt.Print(0)
	}
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

func main() {
	n, m := readInt(), readInt()
	nums := make(map[int]int)
	var key, val int
	for i := 1; i <= m; i++ {
		key = readInt()
		val = readInt()
		if key == 1 && val == 0 {
			fmt.Println(-1)
			return
		}
		if v, ok := nums[key]; ok && v != val {
			fmt.Println(-1)
			return
		}
		nums[key] = val
	}
	for i := 1; i <= n; i++ {
		if v, ok := nums[i]; ok {
			fmt.Print(v)
			continue
		}
		if i == 1 {
			fmt.Print(1)
		} else {
			fmt.Print(0)
		}
	}
	fmt.Println()
}


package main

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

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

type SC struct {
	s int
	c int
	N int
}

func (sc *SC) check(n int) bool {
	switch sc.N {
	case 1:
		return n == sc.c
	case 2:
		switch sc.s {
		case 1:
			return n/10 == sc.c
		case 2:
			return n%10 == sc.c
		}
	case 3:
		switch sc.s {
		case 1:
			return n/100 == sc.c
		case 2:
			return (n%100)/10 == sc.c
		case 3:
			return n%10 == sc.c
		}
	}
	return false
}

func main() {
	N, M := readInt2()
	var start, end int
	switch N {
	case 1:
		start = 0
		end = 9
	case 2:
		start = 10
		end = 99
	case 3:
		start = 100
		end = 999
	}

	sc := make([]SC, M)
	for i := 0; i < M; i++ {
		s, c := readInt2()
		sc[i] = SC{s: s, c: c, N: N}
	}

	for n := start; n <= end; n++ {
		isFulfill := true
		for i := 0; i < M; i++ {
			if !sc[i].check(n) {
				isFulfill = false
				break
			}
		}
		if isFulfill {
			fmt.Println(n)
			return
		}
	}
	fmt.Println(-1)

}

//func main() {
//	N, M := readInt2()
//
//	var str string
//	for i := 0; i < N; i++ {
//		str += "a"
//	}
//
//	for i := 0; i < M; i++ {
//		s, c := readInt2()
//		target := string(str[s-1])
//		if target == "a" || target == strconv.Itoa(c) {
//			str = str[:s-1] + strconv.Itoa(c) + str[s:]
//		} else {
//			fmt.Println(-1)
//			return
//		}
//	}
//
//	str = strings.Replace(str, "a", "0", -1)
//
//	if N != 1 && string(str[0]) == "0" {
//		fmt.Println(-1)
//		return
//	}
//	result, _ := strconv.Atoi(str)
//	fmt.Println(result)
//}


package main

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

var s []int
var c []int

func checkDigits(num int) int {
	if num == 0 {
		return 1
	}

	digits := 0
	for num > 0 {
		num /= 10
		digits++
	}

	return digits
}

var dic map[int]int

func main() {
	var n, m int

	n = readInt()
	m = readInt()
	dic = make(map[int]int, 0)

	s = make([]int, m)
	c = make([]int, m)
	min, max := math.MaxInt64, 0
	for i := 0; i < m; i++ {
		s[i] = readInt()
		c[i] = readInt()
		dic[s[i]] = c[i]
		if s[i] > max {
			max = s[i]
		}
		if s[i] < min {
			min = s[i]
		}
		//fmt.Printf("s[%d] = %d, c[%d] = %d\n", i, s[i], i, c[i])
	}

	//fmt.Printf("n = %d, m = %d\n", n, m)
	/*
		for k, v := range dic {
			fmt.Printf("dic[%d] = %d\n", k, v)
		}
	*/
	if n == max {
		resStr := make([]rune, max)
		for i := 1; i <= max; i++ {
			if _, exist := dic[i]; exist {
				resStr[i-1] = rune(dic[i] + '0')
			} else {
				resStr[i-1] = '0'
			}
		}

		fmt.Println(string(resStr))

	} else {
		fmt.Println(-1)

	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

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

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


package main

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

var sc = bufio.NewScanner(os.Stdin)
func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func main() {
  sc.Split(bufio.ScanWords)
  n := nextInt()
  m := nextInt()
  if m == 0 {
    fmt.Println(int(math.Pow(10, float64(n-1))))
    return
  }
  var cex map[int]bool = map[int]bool{}
  var cs map[int]int = map[int]int{}
  for i := 0; i < m; i++ {
    s := nextInt()
    c := nextInt()
    if n != 1 && s == 1 && c == 0 {
      fmt.Println(-1)
      return
    }
    if cex[s] && cs[s] != c {
      fmt.Println(-1)
      return
    }
    cex[s] = true
    cs[s] = c
  }
  ans := 0
  min := 5
  for s, c := range cs {
    if s < min {
      min = s
    }
    ans += c * int(math.Pow(10, float64(n - s)))
  }
  if n != 1 && cs[min] == 0 {
    fmt.Println(-1)
    return
  }
  if min != 1 {
    ans += int(math.Pow(10, float64(n-1)))
  }
  fmt.Println(ans)
}


package main

import "fmt"

func main(){
	var n,m int;
	fmt.Scan(&n,&m)
	s := make([]int,m)
	c := make([]int,m)
	var temp_s,temp_c int
	ans := true
	for i := 0 ; i < m ; i++ {
		fmt.Scan(&temp_s,&temp_c)
		for j := 0; j < i ; j++ {
			if temp_s == s[j] && temp_c != c[j] {
				ans = false
				break
			}
		}
		if ans == true {
			s[i] = temp_s
			c[i] = temp_c
		} else {
			break
		}
	}
	if ans {
		if n == 1 {
			for j := 0 ; j < m ; j++ {
				if s[j] == 1 {
					fmt.Print(c[j])
					break
				}
			}
		} else if n == 2{
			one := -1
			ten := -1
			for j := 0 ; j < m ; j++ {
				if s[j] == 1 {
					ten = c[j]
				} else if s[j] == 2 {
					one = c[j]
				}
			}
			if ten == 0 {
				fmt.Println("-1")
			} else if ten > 0 {
				if one == -1 {
					fmt.Println(ten*10)
				} else {
					fmt.Println(ten*10 + one)
				}
			} else {
				if one == -1 {
					fmt.Println("10")
				} else {
					fmt.Println(10+one)
				}
			}
		} else {
			one := -1
			ten := -1
			hun := -1
			for j := 0 ; j < m ; j++ {
				if s[j] == 1 {
					hun = c[j]
				} else if s[j] == 2 {
					ten = c[j]
				} else if s[j] == 3 {
					one = c[j]
				}
			}
//fmt.Println(hun,ten,one)
			if hun == 0 {
				fmt.Println("-1")
			} else if hun > 0 {
				if ten != -1 {
					if one != -1 {
						fmt.Println(hun*100+ten*10+one)
					} else {
						fmt.Println(hun*100+ten*10)
					}
				} else {
					if one != -1 {
						fmt.Println(hun*100+one)
					} else {
						fmt.Println(hun*100)
					}
				}
			} else {
				if ten != -1 {
					if one != -1 {
						fmt.Println(100+ten*10+one)
					} else {
						fmt.Println(100+ten*10)
					}
				} else {
					if one != -1 {
						fmt.Println(100+one)
					} else {
						fmt.Println("100")
					}
				}
			}
		}
	} else {
		fmt.Println("-1")
	}
}


package main

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

func main() {
	io := NewIo()
	defer io.Flush()

	n, m := io.Int(), io.Int()

	if n == 1 && m == 0 {
		fmt.Println(0)
		return
	}

	type input struct {
		s, c int
	}

	inputs := make([]input, m)

	dupCheck := map[int]int{}

	for i := 0; i < m; i++ {
		s := io.Int()
		c := io.Int()

		if v, ok := dupCheck[s]; ok && v != c {
			fmt.Println(-1)
			return
		}
		dupCheck[s] = c
		inputs[i] = input{
			s: s - 1,
			c: c,
		}
	}

	nums := make([]int, n)
	for i := 0; i < n; i++ {
		nums[i] = -1
	}

	for _, i := range inputs {
		nums[i.s] = i.c
	}

	ansStr := ""
	firstNum := false
	for _, n := range nums {
		if firstNum {
			if n != -1 {
				ansStr += strconv.Itoa(n)
			} else {
				ansStr += "0"
			}
			continue
		}

		if !firstNum {
			firstNum = true
			if n != -1 {
				ansStr += strconv.Itoa(n)
				firstNum = true
			} else {
				ansStr += "1"
			}
		}
	}
	ans, _ := strconv.Atoi(ansStr)

	if ans == 0 && n == 1 {
		fmt.Println(0)
		return
	}

	if float64(ans) < math.Pow(10, float64(n-1)) {
		fmt.Println(-1)
		return
	}
	fmt.Println(ansStr)

}

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

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

func (io *Io) Float() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

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

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

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

func Pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func Min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func Max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func SortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func SortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

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

func LCM(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / GCD(a, b)
}

func CumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}

func BisectLeft(nums []int, left, right int, target int) int {
	if left == right {
		if nums[left] == target {
			return left
		} else if nums[left] < target {
			return left + 1
		} else {
			return left
		}
	}

	mid := (left + right) / 2
	if nums[mid] == target {
		return mid
	}

	if nums[mid] > target {
		return BisectLeft(nums, left, mid, target)
	} else if nums[mid] < target {
		return BisectLeft(nums, mid+1, right, target)
	}
	return 0
}

func Permutations(nums []int) [][]int {
	n := len(nums)
	if n == 0 {
		return [][]int{}
	}
	ans := [][]int{}

	for _, n := range nums {
		rest := remove(nums, n)
		lists := Permutations(rest)
		if len(lists) == 0 {
			lists = [][]int{nil}
		}

		for i := 0; i < len(lists); i++ {
			lists[i] = append(lists[i], n)
			ans = append(ans, lists[i])
		}
	}
	return ans
}

func remove(nums []int, target int) []int {
	result := []int{}
	for i := 0; i < len(nums); i++ {
		if nums[i] != target {
			result = append(result, nums[i])
		}
	}
	return result
}

func PowerSet(nums []int) [][]int {
	size := Pow(2, len(nums))
	result := make([][]int, size)

	idx := 0
	result[idx] = []int{}
	idx++

	for _, n := range nums {
		max := idx
		for i := 0; i < max; i++ {
			result[idx] = copyAndAppend(result[i], n)
			idx++
		}
	}

	return result
}

func copyAndAppend(nums []int, n int) []int {
	dst := make([]int, len(nums)+1)
	copy(dst, nums)
	dst[len(nums)] = n
	return dst
}

func Combination(nums []int, k int) [][]int {
	size := len(nums)
	result := make([][]int, CombinationCount(int64(len(nums)), int64(k), 10e9))
	bi := (1 << uint(k)) - 1
	max := 1 << uint(size)
	idx := 0

	for bi < max {
		flags := bi
		s := []int{}
		for _, n := range nums {
			if flags%2 != 0 {
				s = append(s, n)
			}
			flags /= 2
		}
		result[idx] = s
		idx++
		bi = Combination2NextIndex(bi)
	}
	return result
}

func Combination2NextIndex(n int) int {
	smallest := n & -n
	ripple := n + smallest
	newSmallest := ripple & -ripple
	ones := ((newSmallest / smallest) >> 1) - 1
	return ripple | ones
}

// CombinationCount はnCmを計算する関数。メモ化を使って計算量を削減する。
func CombinationCount(n, m, maxInput int64) int64 {
	memo := map[int64]map[int64]int64{}
	for i := int64(1); i <= maxInput*maxInput; i++ {
		memo[int64(i)] = map[int64]int64{}
	}
	return combinationCount(n, m, memo)
}
func combinationCount(n, m int64, memo map[int64]map[int64]int64) int64 {
	if n == m || m == 0 {
		return 1
	}

	left, lOK := memo[n-1][m-1]
	right, rOK := memo[n-1][m]

	if lOK && rOK {
		return left + right
	}

	if lOK {
		right = combinationCount(n-1, m, memo)
		memo[n-1][m] = right
		return left + right
	}

	if rOK {
		left = combinationCount(n-1, m-1, memo)
		memo[n-1][m-1] = left
		return left + right
	}

	left = combinationCount(n-1, m-1, memo)
	right = combinationCount(n-1, m, memo)
	memo[n-1][m-1] = left
	memo[n-1][m] = right
	return left + right
}

func Fact(n int) int {
	if n == 0 {
		return 1
	} else {
		return n * Fact(n-1)
	}
}

func Divisors(n int) []int {
	divisors := map[int]bool{}
	for i := 1; i < int(math.Sqrt(float64(n)))+1; i++ {
		if n%i == 0 {
			divisors[i] = true
			//divisors = append(divisors, i)
			if i != n {
				divisors[n/i] = true
				//divisors = append(divisors, n/i)
			}
		}

	}
	ans := []int{}
	for k := range divisors {
		ans = append(ans, k)
	}
	return ans
}


package main

import (
	"fmt"
)

func main() {

	var N, M int
	fmt.Scanf("%d %d\n", &N, &M)
	r := make([]int, N)
	for i := 0; i < N; i ++ {
		if i == 0 {
			r[0] = 1
		} else {
			r[i] = 0
		}
	}
	var re string
	cache := map[int]int{}
	for i := 0; i < M; i ++ {
		var j, n int
		fmt.Scanf("%d %d\n", &j, &n)
		if j == 1 && n == 0 {
			re = "-1"
			break
		}
		if num, exists := cache[j]; exists && num != n {
			re = "-1"
			break
		}
		r[j-1] = n
		cache[j] = n
	}
	if re != "-1" {
		for _, n := range r {
			re += fmt.Sprint(n)
		}
	}
	fmt.Println(re)
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, m := scanInt(), scanInt()
	xs := make([]int, n)
	for i := range xs {
		xs[i] = -1
	}

	for i := 0; i < m; i++ {
		s, c := scanInt(), scanInt()
		if xs[s-1] != -1 && xs[s-1] != c {
			fmt.Println(-1)
			return
		}
		xs[s-1] = c
	}

	ans := ""
	for i := range xs {
		if xs[i] == -1 {
			ans = ans + "0"
		} else {
			ans = ans + strconv.Itoa(xs[i])
		}
	}
	zero := true
	for i := n - 1; i >= 0; i-- {
		if ans[i] != '0' {
			zero = false
		} else if zero {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(ans)
}


package main

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

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

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()

	c := make([]int, n)
	for i := 0; i < n; i++ {
		c[i] = -1
	}
	for i := 0; i < m; i++ {
		s := scanInt()-1
		num := scanInt()

		if c[s] == -1 {
			c[s] = num
		} else {
			if c[s] != num {
				fmt.Fprintln(wr, -1)
				return
			}
		}
	}

	ans := 0
	d := 100
	for i := 0; i < n; i++ {
		if ans == 0 && c[i] == 0 {
			fmt.Fprintln(wr, -1)
			return
		}

		if c[i] == -1 {
			d /= 10
			continue
		}

		ans += d*c[i]
		d /= 10
	}

	fmt.Fprintln(wr, ans)

}


package main

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

func solution(n, k int, nums []int) int {
	l := (n * (n - 1)) / 2

	var stack = make([][]int, 3)
	for i := range nums {
		switch {
		case nums[i] < 0:
			stack[0] = append(stack[0], nums[i])
		case nums[i] == 0:
			stack[1] = append(stack[1], nums[i])
		case nums[i] > 0:
			stack[2] = append(stack[2], nums[i])
		}
	}
	nn := len(stack[0])
	pn := len(stack[2])
	nns := pn * nn
	pns := (pn*(pn-1))/2 + (nn*(nn-1))/2
	zns := l - (nns + pns)

	var ans int
	switch {
	case k <= nns:
		memo := make([]int, nns)
		for _, n := range stack[0] {
			for _, p := range stack[2] {
				memo = append(memo, n*p)
			}
		}
		sort.Ints(memo)
		ans = memo[k-1]

	case k > nns && k <= nns+zns:
		ans = 0
	case k > nns+zns:
		memo := make([]int, 0, pns)
		for i := 0; i < nn; i++ {
			for j := i + 1; j < nn; j++ {
				memo = append(memo, stack[0][i]*stack[0][j])
			}
		}
		for i := 0; i < pn; i++ {
			for j := i + 1; j < pn; j++ {
				memo = append(memo, stack[2][i]*stack[2][j])
			}
		}
		sort.Ints(memo)
		ans = memo[k-1-(nns+zns)]
	}
	return ans
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	reader := bufio.NewReaderSize(os.Stdin, 2*1e6)
	str, _, _ := reader.ReadLine()
	nums := make([]int, n)
	for i, s := range strings.Split(string(str), " ") {
		nums[i], _ = strconv.Atoi(s)
	}

	fmt.Println(solution(n, k, nums))
}

Score: 400 points

Problem Statement

We have N integers A_1, A_2, ..., A_N.

There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list?

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq K \leq \frac{N(N-1)}{2}

-10^9 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.

Sample Input 1

4 3
3 3 -4 -2

Sample Output 1

-6

There are six ways to form a pair. The products of those pairs are 9, -12, -6, -12, -6, 8.

Sorting those numbers in ascending order, we have -12, -12, -6, -6, 8, 9. The third number in this list is -6.

Sample Input 2

10 40
5 4 3 2 -1 0 0 0 0 0

Sample Output 2

6

Sample Input 3

30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0

Sample Output 3

448283280358331064


package main
import (
  "fmt"
  "sort"
)
func main() {
  var n,k,x,y,z,c int
  fmt.Scan(&n,&k)
  a := make([]int,n)
  for i:=0;i<n;i++ { fmt.Scan(&a[i]) }
  sort.Ints(a)
  b := make([]int,n)
  for i:=0;i<n;i++ { b[i] = a[n-i-1] }
  x,z = -1e18,1e18
  for z-x > 1 {
    y = (x+z)/2
    c = 0
    for i:=0;i<n;i++ {
      t := a[i+1:]
      if a[i] < 0 { t = b[:n-i-1] }
      l,r := -1,len(t)
      for r-l > 1 {
        m := (l+r)/2
        if a[i]*t[m] < y { l = m } else { r = m }
      }
      c += r
    }
    if c < k { x = y } else { z = y }
  }
  fmt.Println(x)
}


package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}

func Search(A []int, x int) int {
  N := len(A)
  if x < A[0] { return 0 }
  if A[N - 1] <= x { return N }
  lex, gtx := 0, N - 1
  for 1 < gtx - lex {
    med := (gtx + lex) / 2
    if x < A[med] {
      gtx = med
    } else {
      lex = med
    }
  }
  return lex + 1
}

func Count(A []int, x int) int {
  N := len(A)
  cnt := 0
  for i, a := range A {
    if a == 0 {
      if 0 <= x { cnt += N - i - 1 }
    } else if 0 < a {
      k := x / a
      if x < 0 && x % a != 0 { k-- }
      cnt += MaxInt(Search(A, k) - i - 1, 0)
    } else {
      k := x / a
      if 0 < x || x % a == 0 { k-- }
      cnt += MaxInt(N - MaxInt(Search(A, k), i + 1), 0)
    }
  }
  return cnt
}

func Solve() {
  var N, K int
  NextInt(&N, &K)
  var A []int
  NextIntVec(&A)
  sort.Ints(A)
  M := MaxInt(A[0] * A[0], A[N - 1] * A[N - 1])
  m := MinInt(A[0] * A[0], A[0] * A[N - 1], A[N - 1] * A[N - 1]) - 1
  for 1 < M - m {
    med := (M + m) / 2
    if Count(A, med) < K {
      m = med
    } else {
      M = med
    }
  }
  Write(M)
  return
}

func main() {
  Solve()
  Output()
}


package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}

func Search(A []int, x int) int {
  N := len(A)
  if x < A[0] { return 0 }
  if A[N - 1] <= x { return N }
  lex, gtx := 0, N - 1
  for 1 < gtx - lex {
    med := (gtx + lex) / 2
    if x < A[med] {
      gtx = med
    } else {
      lex = med
    }
  }
  return lex + 1
}

func Count(A []int, x int) int {
  N := len(A)
  cnt := 0
  for i, a := range A {
    if a == 0 {
      if 0 <= x { cnt += N - i - 1 }
    } else if 0 < a {
      k := x / a
      if x < 0 && x % a != 0 { k-- }
      cnt += MaxInt(Search(A, k) - i - 1, 0)
    } else {
      k := x / a
      if x % a == 0 { k-- }
      cnt += MaxInt(N - MaxInt(Search(A, k), i + 1), 0)
    }
  }
  return cnt
}

func Solve() {
  var N, K int
  NextInt(&N, &K)
  var A []int
  NextIntVec(&A)
  sort.Ints(A)
  M := MaxInt(A[0] * A[0], A[N - 1] * A[N - 1])
  m := MinInt(A[0] * A[0], A[0] * A[N - 1], A[N - 1] * A[N - 1]) - 1
  for 1 < M - m {
    med := (M + m) / 2
    if Count(A, med) < K {
      m = med
    } else {
      M = med
    }
  }
  Write(M)
  return
}

func main() {
  Solve()
  Output()
}


package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}

func Search(A []int, x int) int {
  N := len(A)
  if x < A[0] { return 0 }
  if A[N - 1] <= x { return N }
  lex, gtx := 0, N - 1
  for 1 < gtx - lex {
    med := (gtx + lex) / 2
    if x < A[med] {
      gtx = med
    } else {
      lex = med
    }
  }
  return lex + 1
}

func Count(A []int, x int) int {
  N := len(A)
  cnt := 0
  for i, a := range A {
    if a == 0 {
      if 0 <= x { cnt += N - i - 1 }
    } else if 0 < a {
      k := x / a
      if x < 0 && x % a != 0 { k-- }
      cnt += MaxInt(Search(A, k) - i - 1, 0)
    } else {
      k := x / a
      if x <= 0 {
        if x % a == 0 { k-- }
      } else {
        if x % a != 0 { k-- }
      }
      cnt += MaxInt(N - MaxInt(Search(A, k), i + 1), 0)
    }
  }
  return cnt
}

func Solve() {
  var N, K int
  NextInt(&N, &K)
  var A []int
  NextIntVec(&A)
  sort.Ints(A)
  M := MaxInt(A[0] * A[0], A[N - 1] * A[N - 1])
  m := MinInt(A[0] * A[0], A[0] * A[N - 1], A[N - 1] * A[N - 1]) - 1
  for 1 < M - m {
    med := (M + m) / 2
    if Count(A, med) < K {
      m = med
    } else {
      M = med
    }
  }
  Write(M)
  return
}

func main() {
  Solve()
  Output()
}


package main

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

func main() {

	var Nstr string
	sc1 := bufio.NewScanner(os.Stdin)

	if sc1.Scan() {
		Nstr = sc1.Text()
	}

	N, _ := strconv.Atoi(strings.Split(Nstr, " ")[0])
	K, _ := strconv.Atoi(strings.Split(Nstr, " ")[1])

	var cardStr string
	sc := bufio.NewScanner(os.Stdin)
	if sc.Scan() {
		cardStr = sc.Text()
	}

	Ntotal := (N * (N - 1) / 2) + 1

	var total []int
	total = make([]int, Ntotal, Ntotal)

	cardArray := strings.Split(cardStr, " ")

	// var tmpInt []int
	// tmpInt = make([]int, N, N)
	// for i, valueStr := range cardArray {
	// 	value, _ := strconv.Atoi(valueStr)
	// 	tmpInt[i] = value
	// }

	cnt := 1
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			value1, _ := strconv.Atoi(cardArray[i])
			value2, _ := strconv.Atoi(cardArray[j])
			total[cnt] = value1 * value2
			cnt++
		}
	}

	sort.Sort(sort.IntSlice(total))

	fmt.Println(total[K])

}


package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	var base int
	var count int

	fmt.Scan(&n, &k)

	a := make([]int, n)
	result := make([]int, n*(n-1)/2)

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

	for i := 0; i < n-1; i++ {
		base = a[i]
		for j := i + 1; j < n; j++ {
			result[count] = base * a[j]
			count++
		}
	}

	sort.Sort(sort.IntSlice(result))
	fmt.Println(result[k-1])
}


package main

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

func main() {

	var Nstr string
	sc1 := bufio.NewScanner(os.Stdin)

	if sc1.Scan() {
		Nstr = sc1.Text()
	}

	N, _ := strconv.Atoi(strings.Split(Nstr, " ")[0])
	K, _ := strconv.Atoi(strings.Split(Nstr, " ")[1])

	var cardStr string
	sc := bufio.NewScanner(os.Stdin)
	if sc.Scan() {
		cardStr = sc.Text()
	}

	Ntotal := N * (N - 1) / 2
	var tmpInt []int
	tmpInt = make([]int, N, N)

	var total []int
	total = make([]int, Ntotal, Ntotal)

	cardArray := strings.Split(cardStr, " ")

	for i, valueStr := range cardArray {
		value, _ := strconv.Atoi(valueStr)
		tmpInt[i] = value
	}

	var cnt int
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			total[cnt] = tmpInt[i] * tmpInt[j]
			cnt++
		}
	}

	sort.Sort(sort.IntSlice(total))

	fmt.Println(total[K-1])

}


package main

import (
	"fmt"
	"sort"
)

func main(){
	var k,n int
	fmt.Scan(&n,&k)
	a := make([]int,n)
	p := n*(n-1)/2
	pro := make([]int,p)
	for i := 0 ; i < n ; i++ {
		fmt.Scan(&a[i])
	}
	//fmt.Println(a)
	c := 0
	for i := 0 ; i < n-1; i++ {
		for j := i+1 ; j < n ; j++ {
			pro[c] = a[i] * a[j]
			c++
		}
	}
	sort.Ints(pro)
	fmt.Println(pro[k-1])
}


package main

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

func run() int {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)
	an := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &an[i])
	}

	list := make([]int, (len(an)*(len(an)-1))/2)
	idx := 0
	for i := 0; i < len(an); i++ {
		for j := i + 1; j < len(an); j++ {
			list[idx] = an[i] * an[j]
			idx++
		}
	}

  sort.Ints(list)

	fmt.Println(list[k-1])

	return 0
}

func main() {
	os.Exit(run())
}


package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if a <= 9 && b <= 9 {
		fmt.Println(a * b)
	} else {
		fmt.Println(-1)
	}
}

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

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

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

Score : 100 points

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.

Given are two integers A and B.

If Takahashi can calculate A \times B, print the result; if he cannot, print -1 instead.

Constraints

1 \leq A \leq 20

1 \leq B \leq 20

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

If Takahashi can calculate A \times B, print the result; if he cannot, print -1.

Sample Input 1

2 5

Sample Output 1

10

2 \times 5 = 10.

Sample Input 2

5 10

Sample Output 2

-1

5\times 10 = 50, but Takahashi cannot do this calculation, so print -1 instead.

Sample Input 3

9 9

Sample Output 3

81


package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
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 asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := getInt(), getInt()
	if a < 10 && b < 10 {
		out(a * b)
		return
	}
	out(-1)
}


package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	if a <= 9 && b <= 9 {
		fmt.Println(a * b)
	} else {
		fmt.Println(-1)
	}
}


package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if (1 <= a && a <= 9) && (1 <= b && b <= 9) {
		fmt.Println(a * b)
	} else {
		fmt.Println(-1)
	}
}


package main

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

//=====I/O=====

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

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

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

	a, b := scanInt(), scanInt()

	if a < 10 && b < 10 {
		fmt.Println(a*b)
	} else {
		fmt.Println(-1)
	}
}


package main

import (
	"fmt"
)

func main() {
	var a,b int
	fmt.Scan(&a, &b)
	if a >= 10 || b >= 10 {
		fmt.Println(-1)
	} else {
		fmt.Println(a*b)
	}
}


package main

import (
  "fmt"
)

func main() {
  var A, B int
  fmt.Scan(&A, &B)

  if A < 10 && B < 10 {
    fmt.Println(A * B)
  } else {
    fmt.Println(-1)
  }
}


package main

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

func main() {
  scanner := bufio.NewScanner(os.Stdin)
  scanner.Scan()
  stdInput := scanner.Text()
  valueList := strings.Split(stdInput, " ")
  a, _ := strconv.Atoi(valueList[0])
  b, _ := strconv.Atoi(valueList[1])

  if 0 < a && a < 10 && 0 < b && b < 10 {
    fmt.Println(a * b)
  } else {
    fmt.Println("-1")
  }
}


package main

import (
	"fmt"
)

// main is ...
func main() {
	var a, b int
	fmt.Scan(&a, &b)

	isValid := isValid(a) && isValid(b)
	if isValid {
		fmt.Print(a * b)
		return

	}

	fmt.Print(-1)
}

func isValid(a int) bool {
	return 0 <= a && a < 10
}