Consider all binary strings of length $$$m$$$ ($$$1 \le m \le 60$$$). A binary string is a string that consists of the characters 0 and 1 only. For example, 0110 is a binary string, and 012aba is not. Obviously, there are exactly $$$2^m$$$ such strings in total.The string $$$s$$$ is lexicographically smaller than the string $$$t$$$ (both have the same length $$$m$$$) if in the first position $$$i$$$ from the left in which they differ, we have $$$s[i] < t[i]$$$. This is exactly the way strings are compared in dictionaries and in most modern programming languages when comparing them in a standard way. For example, the string 01011 is lexicographically smaller than the string 01100, because the first two characters are the same, and the third character in the first string is less than that in the second.We remove from this set $$$n$$$ ($$$1 \le n \le \min(2^m-1, 100)$$$) distinct binary strings $$$a_1, a_2, \ldots, a_n$$$, each of length $$$m$$$. Thus, the set will have $$$k=2^m-n$$$ strings. Sort all strings of the resulting set in lexicographical ascending order (as in the dictionary).We number all the strings after sorting from $$$0$$$ to $$$k-1$$$. Print the string whose index is $$$\lfloor \frac{k-1}{2} \rfloor$$$ (such an element is called median), where $$$\lfloor x \rfloor$$$ is the rounding of the number down to the nearest integer.For example, if $$$n=3$$$, $$$m=3$$$ and $$$a=[$$$010, 111, 001$$$]$$$, then after removing the strings $$$a_i$$$ and sorting, the result will take the form: $$$[$$$000, 011, 100, 101, 110$$$]$$$. Thus, the desired median is 100.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then, $$$t$$$ test cases follow. The first line of each test case contains integers $$$n$$$ ($$$1 \le n \le \min(2^m-1, 100)$$$) and $$$m$$$ ($$$1 \le m \le 60$$$), where $$$n$$$ is the number of strings to remove, and $$$m$$$ is the length of binary strings. The next $$$n$$$ lines contain $$$a_1, a_2, \ldots, a_n$$$ — distinct binary strings of length $$$m$$$. The total length of all given binary strings in all test cases in one test does not exceed $$$10^5$$$.

Print $$$t$$$ answers to the test cases. For each test case, print a string of length $$$m$$$ — the median of the sorted sequence of remaining strings in the corresponding test case.

NoteThe first test case is explained in the statement.In the second test case, the result after removing strings and sorting is $$$[$$$001, 010, 101, 110$$$]$$$. Therefore, the desired median is 010.

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	search := func(n int64, f func(int64) bool) int64 {
		i, j := int64(0), n
		for i < j {
			h := (i + j) >> 1
			if f(h) {
				j = h
			} else {
				i = h + 1
			}
		}
		return i
	}

	var t, n, m int64
	var s string
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &s)
			a[i], _ = strconv.ParseInt(s, 2, 64)
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		k := 1<<m - n
		midId := (k - 1) / 2
		ans := search(1<<m, func(x int64) bool {
			cnt := x
			for _, v := range a {
				if v <= x {
					cnt--
				}
			}
			return cnt >= midId
		})
		Fprintf(out, "%0*b\n", m, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	search := func(n int64, f func(int64) bool) int64 {
		i, j := int64(0), n
		for i < j {
			h := (i + j) >> 1
			if f(h) {
				j = h
			} else {
				i = h + 1
			}
		}
		return i
	}

	var t, n, m int64
	var s string
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &s)
			a[i], _ = strconv.ParseInt(s, 2, 64)
		}
		mid := (1<<m - n - 1) / 2
		ans := search(1<<m, func(x int64) bool {
			cnt := x
			for _, v := range a {
				if v <= x {
					cnt--
				}
			}
			return cnt >= mid
		})
		Fprintf(out, "%0*b\n", m, ans)
	}
}

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

package main

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)
	for i := rd(); i > 0; i-- {
		n, m := rdll(), rdll()
		a := make([]int64, n)
		for i := range a {
			s := rds()
			a[i], _ = strconv.ParseInt(s, 2, 64)
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		target := ((1 << m) - n - 1) / 2
		var l, r int64 = 0, (1 << m) - 1
		for l <= r {
			mid := (l + r) >> 1
			cnt := 0
			for _, it := range a {
				if it < mid {
					cnt++
				}
			}
			if mid-int64(cnt) <= target {
				l = mid + 1
			} else {
				r = mid - 1
			}
		}
		Fprintf(out, "%0*b\n", m, r)
	}

}

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 rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}

package main

import (
	"fmt"
)

func get_count(x int64, A [] int64) int64 {
	ret := x
	for _, v := range A {
		if v < x {
			ret--
		}
	}
	return ret
}

func main(){
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n, m int
		fmt.Scan(&n, &m)
		A := make([]int64, n)
		for i := 0; i < n; i++ {
			var s string
			fmt.Scan(&s)
			for j := 0; j < m; j++ {
				A[i] = (A[i] << 1) + int64(s[j] - '0')
			}
		}
		var tot int64 = 1
		tot = (tot << m) - 1
		target := (tot - int64(n)) >> 1
		var s int64 = 0
		e := tot
		for s < e {
			mid := s + ((e-s) >> 1)
			if(get_count(mid, A) >= target)  {
				e = mid
			} else {
				s = mid + 1
			}
		}
		for {
			is_in := false
			for _, v := range A {
				if v == s {
					is_in = true
					break
				}
			}
			if !is_in {
				break
			}
			s++
		}
		res := make([]rune, m)
		for i := 0; i < m; i++ {
			b := (s >> (m-1-i)) & 1
			if b == 1 {
				res[i] = '1'
			} else {
				res[i] = '0'
			}
		}
		fmt.Println(string(res))
	}

}

package main

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)
	for i := rd(); i > 0; i-- {
		n, m := rdll(), rdll()
		a := make([]int64, n)
		for i := range a {
			var s string
			Fscan(in, &s)
			a[i], _ = strconv.ParseInt(s, 2, 64)
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		target := ((1 << m) - n - 1) / 2
		var l, r int64 = 0, (1 << m) - 1
		for l <= r {
			mid := (l + r) >> 1
			cnt := 0
			for _, it := range a {
				if it < mid {
					cnt++
				}
			}
			if mid-int64(cnt) <= target {
				l = mid + 1
			} else {
				r = mid - 1
			}
		}
		Fprintf(out, "%0*b\n", m, r)
	}

}

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 rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}


Sometimes it is not easy to come to an agreement in a bargain. Right now Sasha and Vova can't come to an agreement: Sasha names a price as high as possible, then Vova wants to remove as many digits from the price as possible. In more details, Sasha names some integer price $$$n$$$, Vova removes a non-empty substring of (consecutive) digits from the price, the remaining digits close the gap, and the resulting integer is the price.For example, is Sasha names $$$1213121$$$, Vova can remove the substring $$$1312$$$, and the result is $$$121$$$.It is allowed for result to contain leading zeros. If Vova removes all digits, the price is considered to be $$$0$$$.Sasha wants to come up with some constraints so that Vova can't just remove all digits, but he needs some arguments supporting the constraints. To start with, he wants to compute the sum of all possible resulting prices after Vova's move.Help Sasha to compute this sum. Since the answer can be very large, print it modulo $$$10^9 + 7$$$.

The first and only line contains a single integer $$$n$$$ ($$$1 \le n < 10^{10^5}$$$).

In the only line print the required sum modulo $$$10^9 + 7$$$.

package main

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

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

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

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

const mod = 1000000007

func Add(a, b int64) int64 {
	return (a + b) % mod
}

func Mult(a, b int64) int64 {
	return (a * b) % mod
}

func solve() {
	arr := []byte(next())

	var res int64

	var ways int64
	var pow int64 = 1

	for i := len(arr) - 1; i >= 0; i-- {
		res = Add(res, Mult(int64(i)*int64(i+1)/2, Mult(int64(arr[i]-'0'), pow)))
		res = Add(res, Mult(ways, int64(arr[i]-'0')))
		ways = Add(ways, Mult(int64(len(arr)-i), pow))
		pow = Mult(pow, 10)
	}

	printf("%d\n", res)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	// for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
	// printf("Case #%d:\n", i)
	solve()
	// }

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	const mod int64 = 1e9 + 7
	var d string
	Fscan(bufio.NewReader(os.Stdin), &d)
	var s, k, t, n int64 = 0, 0, 1, int64(len(d))
	for i := n - 1; i >= 0; i-- {
		s += int64(d[i]&15) * (i*(i+1)/2%mod*t%mod + k)
		k = (k + (n-i)*t) % mod
		t = t * 10 % mod
	}
	Print(s % mod)
}

package main

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

var reader = bufio.NewReader(os.Stdin)

var mod int64 = 1e9 + 7

func main() {
	var s string
	fmt.Fscan(reader, &s)

	var arr []int
	for _, c := range s {
		arr = append(arr, int(c-'0'))
	}

	n := len(arr)

	var total int64 = 0
	var tenPow int64 = 1
	var tenTotal int64 = 0
	var multiple int64 = 1
	for i := n - 1; i >= 0; i-- {
		// left combinations
		total = add(total, mul(int64(arr[i]), mul(nc2(int64(i)), tenPow)))

		// right combinations
		total = add(total, mul(int64(arr[i]), tenTotal))

		tenTotal = add(tenTotal, mul(tenPow, multiple))
		tenPow = mul(tenPow, 10)
		multiple = add(multiple, 1)
	}

	fmt.Println(total)
}

func add(a, b int64) int64 {
	return ((a+b)%mod + mod) % mod
}

func mul(a, b int64) int64 {
	return ((a*b)%mod + mod) % mod
}

func nc2(n int64) int64 {
	return add(n*(n+1)/2, 0)
}


Orac is studying number theory, and he is interested in the properties of divisors.For two positive integers $$$a$$$ and $$$b$$$, $$$a$$$ is a divisor of $$$b$$$ if and only if there exists an integer $$$c$$$, such that $$$a\cdot c=b$$$.For $$$n \ge 2$$$, we will denote as $$$f(n)$$$ the smallest positive divisor of $$$n$$$, except $$$1$$$.For example, $$$f(7)=7,f(10)=2,f(35)=5$$$.For the fixed integer $$$n$$$, Orac decided to add $$$f(n)$$$ to $$$n$$$. For example, if he had an integer $$$n=5$$$, the new value of $$$n$$$ will be equal to $$$10$$$. And if he had an integer $$$n=6$$$, $$$n$$$ will be changed to $$$8$$$.Orac loved it so much, so he decided to repeat this operation several times.Now, for two positive integers $$$n$$$ and $$$k$$$, Orac asked you to add $$$f(n)$$$ to $$$n$$$ exactly $$$k$$$ times (note that $$$n$$$ will change after each operation, so $$$f(n)$$$ may change too) and tell him the final value of $$$n$$$.For example, if Orac gives you $$$n=5$$$ and $$$k=2$$$, at first you should add $$$f(5)=5$$$ to $$$n=5$$$, so your new value of $$$n$$$ will be equal to $$$n=10$$$, after that, you should add $$$f(10)=2$$$ to $$$10$$$, so your new (and the final!) value of $$$n$$$ will be equal to $$$12$$$.Orac may ask you these queries many times.

The first line of the input is a single integer $$$t\ (1\le t\le 100)$$$: the number of times that Orac will ask you. Each of the next $$$t$$$ lines contains two positive integers $$$n,k\ (2\le n\le 10^6, 1\le k\le 10^9)$$$, corresponding to a query by Orac. It is guaranteed that the total sum of $$$n$$$ is at most $$$10^6$$$.

Print $$$t$$$ lines, the $$$i$$$-th of them should contain the final value of $$$n$$$ in the $$$i$$$-th query by Orac.

NoteIn the first query, $$$n=5$$$ and $$$k=1$$$. The divisors of $$$5$$$ are $$$1$$$ and $$$5$$$, the smallest one except $$$1$$$ is $$$5$$$. Therefore, the only operation adds $$$f(5)=5$$$ to $$$5$$$, and the result is $$$10$$$.In the second query, $$$n=8$$$ and $$$k=2$$$. The divisors of $$$8$$$ are $$$1,2,4,8$$$, where the smallest one except $$$1$$$ is $$$2$$$, then after one operation $$$8$$$ turns into $$$8+(f(8)=2)=10$$$. The divisors of $$$10$$$ are $$$1,2,5,10$$$, where the smallest one except $$$1$$$ is $$$2$$$, therefore the answer is $$$10+(f(10)=2)=12$$$.In the third query, $$$n$$$ is changed as follows: $$$3 \to 6 \to 8 \to 10 \to 12$$$.

package main

import (
	"fmt"
)

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	if n&1 == 0 {
		fmt.Println(n + 2*k)
	} else {
		for i := 2; i <= n; i++ {
			if n%i == 0 {
				n += i
				break
			}
		}
		k--
		fmt.Println(n + 2*k)
	}

}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

import "fmt"

func main() {

	var t int

	fmt.Scan(&t)
	for ;t > 0; t-- {

		var n,k int;

		fmt.Scan( &n, &k )

		if (n % 2 == 1) {

			i := 2

			for ; i < n/2; i++ {
				if n % i == 0 {
					break
				}
			}

			if n % i == 0 {
				n += i + 2 * ( k - 1 )
			} else {
				n += n + 2 * ( k - 1 )
			}

		} else {
			n += 2 * k
		}

		fmt.Print(n, "\n" )
	}
}

package main

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

type Scan struct {
	f *os.File
	in *bufio.Reader
	out *bufio.Writer
}

func setup() *Scan {
	r := &Scan{ f: nil }

	inputFile := os.Getenv("INPUT_FILE")
	if inputFile != "" {
		var err error
		if r.f, err = os.Open(inputFile); err == nil {
			os.Stdin = r.f
		}
	}
	r.in = bufio.NewReader(os.Stdin)
	r.out = bufio.NewWriter(os.Stdout)

	return r
}

func (r *Scan) close() {
	if r.f != nil {
		r.f.Close()
	}
	r.out.Flush()
}

func (r *Scan) readString() string {
	var x string
	fmt.Fscan(r.in, &x)
	return x
}

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

func (r *Scan) readLongInt() int64 {
	x, err := strconv.ParseInt(r.readString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return x
}

func (r *Scan) strings(refs ... *string) {
	for _, ref := range refs {
		*ref = r.readString()
	}
}

func (r *Scan) ints(refs ... *int) {
	for _, ref := range refs {
		*ref = r.readInt()
	}
}

func (r *Scan) longInts(refs ... *int64) {
	for _, ref := range refs {
		*ref = r.readLongInt()
	}
}

func (r *Scan) print(s string) {
	fmt.Fprintf(r.out, "%s", s)
}

func smallestDivisor(x int64) int64 {
	for i := int64(2); i <= x*x; i++ {
		if x%i == 0 {
			return i
		}
	}
	return x
}

func main() {
	scan := setup()

	var t int
	var n, k int64

	scan.ints(&t)
	for tc := 0; tc < t; tc++ {
		scan.longInts(&n, &k)

		ans := n
		div := smallestDivisor(n)
		ans = n + div
		k--;
		if k > 0 {
			ans += 2 * k;
		}
		scan.print(fmt.Sprintf("%d\n", ans))
	}

	scan.close()
}

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

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var n, k int
	fmt.Fscan(input, &n, &k)

	minp := n
	for i := 2; i*i <= n; i++ {
		if n % i == 0 {
			minp = i
			break
		}
	}

	fmt.Println(2 * (k - 1) + (minp + n))
}

package main

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

func main()  {

	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		nks := scanner.Text()

		ps := strings.Fields(nks)

		n, err := strconv.Atoi(ps[0])

		if err != nil {
			panic(err)
		}

		k, err := strconv.Atoi(ps[1])

		if err != nil {
			panic(err)
		}

		ans := solve1(int64(n), int64(k))

		fmt.Println(ans)
	}
}

func solve1(n, k int64 ) int64 {

	if n % 2 == 0 {
		return 2 * k + n
	}

	var i int64
	for i = 2 ; i <= n ; i++ {
		if n % i == 0 {
			break
		}
	}

	n += i

	return 2 * (k - 1) + n
}

/*
URL:
https://codeforces.com/contest/1350/problem/0
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, k int64
)

func main() {
	t = ReadInt()

	for i := 0; i < t; i++ {
		n, k = ReadInt64_2()
		solve(n, k)
	}
}

func solve(n, k int64) {
	tmp := divisor(int(n))
	sort.Sort(sort.IntSlice(tmp))

	D := []int64{}
	for i := 0; i < len(tmp); i++ {
		D = append(D, int64(tmp[i]))
	}

	ans := n
	ans += D[1]

	ans += (k - 1) * 2
	fmt.Println(ans)
}

// 約数の列挙: O(sqrt(n))
func divisor(n int) []int {
	res := []int{}

	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i != (n / i) {
				res = append(res, (n / i))
			}
		}
	}

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, k := ScanInt64(), ScanInt()

		for kk := k; kk > 0; kk-- {
			divisor := f(n)
			if divisor%2 == 0 {
				n += int64(kk << 1)
				break
			} else {
				n += divisor
			}
		}
		P(n)
	}

	close(O)
	oWg.Wait()
}

func f(n int64) int64 {
	if n%2 == 0 {
		return 2
	}
	sqr := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqr; i += 2 {
		if n%int64(i) == 0 {
			return int64(i)
		}
	}
	return n
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

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

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

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

package main

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

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

	var t int
	var n, k int64

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n, &k)

		minDivisor := getMinDivisor(n)

		fmt.Fprintln(w, n+minDivisor+2*(k-1))
	}
}

func getMinDivisor(n int64) int64 {
	if n%2 == 0 {
		return 2
	}

	var i int64
	for i = 3; i*i <= n; i += 2 {
		if n%i == 0 {
			return i
		}
	}

	return n
}

package main

import (
	"fmt"
)

func solve(n, k int64) int64 {
	if k == 0 {
		return n
	} else if n % 2 == 0 {
		return n + k*2
	} else {
		return solve(n+f(n), k-1)
	}
}

func f(n int64) int64{
	for i := int64(2); i*i <= n; i++ {
		if n % i == 0 {
			return i
		}
	}
	return n
}

func main() {
	var T int
	var n, k int64
	fmt.Scanf("%d\n", &T)
	for kase := 1; kase <= T; kase++ {
		fmt.Scanf("%d%d\n", &n, &k)
		fmt.Printf("%v\n", solve(n, k))
	}
}

package main

import "fmt"

func main() {
	n := int(1e6) * 2
	data := make([]int, n+1)
	for i := 2; i <= n; i++ {
		if data[i] != 0 {
			continue
		}
		data[i] = i
		if i > n/i {
			continue
		}
		for j := i * i; j <= n; j += i {
			if data[j] == 0 {
				data[j] = i
			}
		}
	}

	var t int
	fmt.Scan(&t)

	for ; t > 0; t-- {
		var n, k int
		fmt.Scan(&n, &k)
		ans := int64(n)
		ans += int64(data[n])
		k--
		if k > 0 {
			ans += int64(2 * k)
		}
		fmt.Println(ans)
	}
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextUInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

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

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

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

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

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n, k := reader.NextInt64(), reader.NextInt64()
		writer.Printf("%d\n", sol(n, k))
	}
}

func sol(n, k int64) int64 {
	for ; k > 0; k-- {
		for i := int64(2); i <= n; i++ {
			if n % i == 0 {
				if i == 2 {
					return n + k*2
				}
				n += i
				break
			}
		}
	}
	return n
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, k := ScanInt64(), ScanInt()

		for kk := k; kk > 0; kk-- {
			divisor := f(n)
			if divisor%2 == 0 {
				n += int64(math.Pow(2, float64(kk)))
				break
			} else {
				n += divisor
			}
		}
		P(n)
	}

	close(O)
	oWg.Wait()
}

func f(n int64) int64 {
	if n%2 == 0 {
		return 2
	}
	sqr := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqr; i += 2 {
		if n%int64(i) == 0 {
			return int64(i)
		}
	}
	return n
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

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

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

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

package main

import (
	"fmt"
)

func solve(n, k int64) int64 {
	if k == 0 {
		return n
	} else if n % 2 == 0 {
		return n + k*2
	} else {
		return solve(n+f(n), k-1)
	}
}

func f(n int64) int64{
	for i := int64(2); i*i <= n; i++ {
		if n % i == 0 {
			return i
		}
	}
	return n
}

func main() {
	var T int
	var n, k int64
	fmt.Scanf("%v", &T)
	for kase := 1; kase <= T; kase++ {
		fmt.Scanf("%d%d", &n, &k)
		fmt.Printf("%v\n", solve(n, k))
	}
}


The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.The city of Tomsk can be represented as point on the plane with coordinates (0; 0). The city is surrounded with n other locations, the i-th one has coordinates (xi, yi) with the population of ki people. You can widen the city boundaries to a circle of radius r. In such case all locations inside the circle and on its border are included into the city.Your goal is to write a program that will determine the minimum radius r, to which is necessary to expand the boundaries of Tomsk, so that it becomes a megacity.

The first line of the input contains two integers n and s (1 ≤ n ≤ 103; 1 ≤ s < 106) — the number of locatons around Tomsk city and the population of the city. Then n lines follow. The i-th line contains three integers — the xi and yi coordinate values of the i-th location and the number ki of people in it (1 ≤ ki < 106). Each coordinate is an integer and doesn't exceed 104 in its absolute value. It is guaranteed that no two locations are at the same point and no location is at point (0; 0).

In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity. The answer is considered correct if the absolute or relative error don't exceed 10 - 6.

package main

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

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

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

	n, s := nextInt(), nextInt()

	radius := make([]float64, n)
	numberOfPeoples := make([]int, n)
	var a, b float64

	for i:=0; i<n; i++ {
		a, b = nextFloat(), nextFloat()
		radius[i] = math.Sqrt(a*a + b*b)
		numberOfPeoples[i] = nextInt()
	}

	minIndex := 0
	for {
		minIndex = min(radius)

		if minIndex == -1 {
			println(-1)
			return
		}
		// println(minIndex)
		s += numberOfPeoples[minIndex]

		if s >= 1000000 {
			break
		}
		radius[minIndex] = 0
	}

	println(radius[minIndex])
}

func min(a []float64) (index int) {
	for a[index] == 0 {
		index++

		if index >= len(a) {
			return -1
		}
	}

	for i:=index+1; i<len(a); i++ {
		if a[i]!=0 && a[i]<a[index] {
			index = i
		}
	}

	if a[index] == 0 {
		return -1
	}

	return
}

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

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

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

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

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

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

//https://codeforces.com/problemset/problem/424/B
//http://bigocoder.com/courses/BLUE20/BLUE20_LEC13/BLUE_L13P03/statement
package main

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

type city struct {
	r int
	p int
}

func solve(cities []city, population int) int {
	for i := range cities {
		population += cities[i].p
		if population >= 1000000 {
			return cities[i].r
		}
	}

	return -1
}

func calculateRadius(x int, y int) int {
	//formula : sqt((x1-x0)2 + (y1-y0)2)
	return x*x + y*y
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, population, x, y, p int
	fmt.Fscanf(r, "%d %d\n", &n, &population)
	cities := make([]city, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d %d %d\n", &x, &y, &p)
		cities[i] = city{calculateRadius(x, y), p}
	}

	sort.Slice(cities, func(i, j int) bool { return cities[i].r < cities[j].r })

	result := solve(cities, population)

	if result == -1 {
		fmt.Fprintf(os.Stdout, "%d\n", result)
	} else {
		fmt.Fprintf(os.Stdout, "%.7f\n", math.Sqrt(float64(result)))
	}
}

package main

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

const MEGACITY int64 = 1000000

type Pair struct {
	X      int
	Y      int
	K      int64
	Radius float64
}

type Pairs []*Pair

func (p Pairs) Len() int {
	return len(p)
}

func (p Pairs) Less(i, j int) bool {
	return p[i].Radius < p[j].Radius
}

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

func (p Pair) Dist() float64 {
	return math.Sqrt(float64(p.X*p.X + p.Y*p.Y))
}

func abs(x, y int64) int64 {
	if x > y {
		return x - y
	}
	return y - x
}

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

	var n int
	var s int64
	fmt.Fscanf(reader, "%d %d\n", &n, &s)
	pairs := make([]*Pair, 0)
	for i := 1; i <= n; i++ {
		p := Pair{}
		fmt.Fscanf(reader, "%d %d %d\n", &p.X, &p.Y, &p.K)
		p.Radius = p.Dist()
		pairs = append(pairs, &p)
	}
	sort.Sort(Pairs(pairs))
	sum := s
	for _, p := range pairs {
		sum = sum + p.K
		p.K = sum
		//fmt.Fprintln(writer, p.X, p.Y, p.K, p.Radius)
	}
	var min int64
	min = math.MaxInt64
	idx := -1
	for i := 0; i < n; i++ {
		if pairs[i].K >= MEGACITY {
			if min > pairs[i].K {
				min = pairs[i].K
				idx = i
			}
		}
	}
	if idx >= 0 && idx < n {
		fmt.Fprintf(writer, "%.7f\n", pairs[idx].Radius)
	} else {
		fmt.Fprintf(writer, "-1\n")
	}
}

package main

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

const MEGACITY = 1000000

type Pair struct {
	X      int
	Y      int
	K      int
	Radius float64
}

type Pairs []*Pair

func (p Pairs) Len() int {
	return len(p)
}

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

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

func (p Pair) Dist() float64 {
	return math.Sqrt(float64(p.X*p.X + p.Y*p.Y))
}

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

	var n, s int
	fmt.Fscanf(reader, "%d %d\n", &n, &s)
	pairs := make([]*Pair, 0)
	for i := 1; i <= n; i++ {
		p := Pair{}
		fmt.Fscanf(reader, "%d %d %d\n", &p.X, &p.Y, &p.K)
		pairs = append(pairs, &p)
	}
	sort.Sort(Pairs(pairs))
	dist := s
	for _, p := range pairs {
		p.Radius = p.Dist()
		dist = dist + p.K
		p.K = dist
	}
	low := 0
	high := n - 1
	mid := -1
	for low <= high {
		mid = (low + high) >> 1
		p := pairs[mid]
		if p.K < MEGACITY {
			low = mid + 1
		} else if p.K > MEGACITY {
			high = mid - 1
		} else {
			break
		}
	}
	if mid >= 0 && mid < n {
		p := pairs[mid]
		if p.K >= MEGACITY {
			fmt.Fprintf(writer, "%.7f\n", p.Radius)
		} else {
			fmt.Fprintf(writer, "-1\n")
		}
	} else {
		fmt.Fprintf(writer, "-1\n")
	}
}

package main

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

const MEGACITY = 1000000

type Pair struct {
	X      int
	Y      int
	K      int
	Radius float64
}

type Pairs []*Pair

func (p Pairs) Len() int {
	return len(p)
}

func (p Pairs) Less(i, j int) bool {
	return p[i].Dist() < p[j].Dist()
}

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

func (p Pair) Dist() float64 {
	return math.Sqrt(float64(p.X*p.X + p.Y*p.Y))
}

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

	var n, s int
	fmt.Fscanf(reader, "%d %d\n", &n, &s)
	pairs := make([]*Pair, 0)
	for i := 1; i <= n; i++ {
		p := Pair{}
		fmt.Fscanf(reader, "%d %d %d\n", &p.X, &p.Y, &p.K)
		pairs = append(pairs, &p)
	}
	sort.Sort(Pairs(pairs))
	dist := s
	for _, p := range pairs {
		p.Radius = p.Dist()
		dist = dist + p.K
		p.K = dist
		//fmt.Fprintln(writer, p.X, p.Y, p.K, p.Radius)
	}
	low := 0
	high := n - 1
	mid := -1
	for low <= high {
		mid = (low + high) >> 1
		p := pairs[mid]
		//fmt.Println(p.X, p.Y, p.K, p.Radius)
		if p.K < MEGACITY {
			low = mid + 1
		} else if p.K > MEGACITY {
			high = mid - 1
		} else {
			break
		}
	}
	if mid >= 0 && mid < n {
		p := pairs[mid]
		//fmt.Println("mid is ", p.X, p.Y, p.K, p.Radius)
		if p.K >= MEGACITY {
			fmt.Fprintf(writer, "%.7f\n", p.Radius)
		} else {
			fmt.Fprintf(writer, "-1\n")
		}
	} else {
		fmt.Fprintf(writer, "-1\n")
	}
}


The only difference between this problem and D1 is that you don't have to provide the way to construct the answer in D1, but you have to do it in this problem.There's a table of $$$n \times m$$$ cells ($$$n$$$ rows and $$$m$$$ columns). The value of $$$n \cdot m$$$ is even.A domino is a figure that consists of two cells having a common side. It may be horizontal (one of the cells is to the right of the other) or vertical (one of the cells is above the other).You need to place $$$\frac{nm}{2}$$$ dominoes on the table so that exactly $$$k$$$ of them are horizontal and all the other dominoes are vertical. The dominoes cannot overlap and must fill the whole table.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of a single line. The line contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1 \le n,m \le 100$$$, $$$0 \le k \le \frac{nm}{2}$$$, $$$n \cdot m$$$ is even) — the count of rows, columns and horizontal dominoes, respectively.

For each test case:   print "NO" if it's not possible to place the dominoes on the table in the described way;  otherwise, print "YES" on a separate line, then print $$$n$$$ lines so that each of them contains $$$m$$$ lowercase letters of the Latin alphabet — the layout of the dominoes on the table. Each cell of the table must be marked by the letter so that for every two cells having a common side, they are marked by the same letters if and only if they are occupied by the same domino. I.e. both cells of the same domino must be marked with the same letter, but two dominoes that share a side must be marked with different letters. If there are multiple solutions, print any of them.

YES
accx
aegx
bega
bdda
YES
aha
aha
YES
zz
aa
zz
NO
YES
aaza
bbza
NO
YES
bbaabbaabbaabbaay
ddccddccddccddccy
NO

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

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

	var T, n, m, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		ans := make([][]byte, n)
		for i := range ans {
			ans[i] = make([]byte, m)
		}
		if n&1 > 0 {
			k -= m / 2
			if k < 0 {
				Fprintln(out, "NO")
				continue
			}
			for j := 1; j < m; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[n-1][j-1] = c
				ans[n-1][j] = c
			}
		} else if m&1 > 0 {
			if k > m/2*n {
				Fprintln(out, "NO")
				continue
			}
			for i := 1; i < n; i += 2 {
				c := 'f' ^ byte(i/2&1)
				ans[i-1][m-1] = c
				ans[i][m-1] = c
			}
		}
		if k&1 > 0 {
			Fprintln(out, "NO")
			continue
		}
		for i := 1; i < n; i += 2 {
			for j := 1; j < m; j += 2 {
				if k > 0 {
					k -= 2
					c := 'b' ^ byte(j/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c
					ans[i][j-1] = c ^ 1
					ans[i][j] = c ^ 1
				} else {
					c := 'd' ^ byte(i/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c ^ 1
					ans[i][j-1] = c
					ans[i][j] = c ^ 1
				}
			}
		}
		Fprintln(out, "YES")
		for _, r := range ans {
			Fprintf(out, "%s\n", r)
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var ans [][]byte
	solve := func(Case int) (_b bool) {
		var n, m, k int
		Fscan(in, &n, &m, &k)

		ans = make([][]byte, n)
		for i := range ans {
			ans[i] = make([]byte, m)
		}

		mx := 0
		base := 0
		if m&1 == 0 {
			mx = n * m / 2

			if n&1 == 0 {

			} else {
				base = m / 2
			}

			if k < base {
				return false
			}
			if (k-base)&1 > 0 {
				return false
			}

		} else { // m&1==1 && n&1==0
			mx = n*m/2 - n/2
			if k > mx {
				return false
			}
			if k&1 > 0 {
				return false
			}

		}
		kk := k
		_ = kk

		if base > 0 {
			for j := 1; j < m && k > 0; j += 2 {
				i := 0
				if (i+j/2)&1 == 0 {
					ans[i][j-1] = 'a'
					ans[i][j] = 'a'
				} else {
					ans[i][j-1] = 'b'
					ans[i][j] = 'b'
				}

				k--
			}
		}

		for j := 1; j < m && k > 0; j += 2 {
			i := 0
			if base > 0 {
				i = 1
			}
			for ; i < n && k > 0; i++ {
				if (i+j/2)&1 == 0 {
					ans[i][j-1] = 'a'
					ans[i][j] = 'a'
				} else {
					ans[i][j-1] = 'b'
					ans[i][j] = 'b'
				}

				k--
			}
		}

		for j := 0; j < m; j++ {
			i := 0
			for ; i < n && ans[i][j] > 0; i++ {
			}
			for ; i < n; i += 2 {
				if (i/2+j)&1 == 0 {
					ans[i][j] = 'c'
					ans[i+1][j] = 'c'
				} else {
					ans[i][j] = 'd'
					ans[i+1][j] = 'd'
				}
			}
		}

		return true
	}

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

		if solve(Case) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
			continue
		}

		for _, r := range ans {
			Fprintln(out, string(r))
		}
	}

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

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

package main

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

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

	var T, n, m, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		ans := make([][]byte, n)
		for i := 0; i < n; i++ {
			ans[i] = make([]byte, m)
		}
		if n&1 > 0 {
			k -= m / 2
			if k < 0 {
				Fprintln(out, "NO")
				continue
			}
			for j := 0; j < m; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[n-1][j] = c
				ans[n-1][j+1] = c
			}
		} else if m&1 > 0 {
			if k > m/2*n {
				Fprintln(out, "NO")
				continue
			}
			for j := 0; j < n; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[j][m-1] = c
				ans[j+1][m-1] = c
			}
		}
		if k&1 > 0 {
			Fprintln(out, "NO")
			continue
		}
		for i := 1; i < n; i += 2 {
			for j := 1; j < m; j += 2 {
				if k > 0 {
					k -= 2
					c := 'b' ^ byte(j/2&1)
					ans[i][j-1] = c
					ans[i][j] = c
					ans[i-1][j-1] = c ^ 1
					ans[i-1][j] = c ^ 1
				} else {
					c := 'd' ^ byte(i/2&1)
					ans[i][j-1] = c
					ans[i][j] = c ^ 1
					ans[i-1][j-1] = c
					ans[i-1][j] = c ^ 1
				}
			}
		}
		Fprintln(out, "YES")
		for i := 0; i < n; i++ {
			Fprintf(out, "%s\n", ans[i])
		}
	}
}

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

package main

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

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

	var T, n, m, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		ans := make([][]byte, n)
		for i := range ans {
			ans[i] = make([]byte, m)
		}
		if n&1 > 0 {
			k -= m / 2
			if k < 0 || k&1 > 0 {
				Fprintln(out, "NO")
				continue
			}
			for j := 1; j < m; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[n-1][j-1] = c
				ans[n-1][j] = c
			}
		} else if m&1 > 0 {
			if k > m/2*n || k&1 > 0 {
				Fprintln(out, "NO")
				continue
			}
			for i := 1; i < n; i += 2 {
				c := 'f' ^ byte(i/2&1)
				ans[i-1][m-1] = c
				ans[i][m-1] = c
			}
		}
		for i := 1; i < n; i += 2 {
			for j := 1; j < m; j += 2 {
				if k > 0 {
					k -= 2
					c := 'b' ^ byte(j/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c
					ans[i][j-1] = c ^ 1
					ans[i][j] = c ^ 1
				} else {
					c := 'd' ^ byte(i/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c ^ 1
					ans[i][j-1] = c
					ans[i][j] = c ^ 1
				}
			}
		}
		Fprintln(out, "YES")
		for _, r := range ans {
			Fprintf(out, "%s\n", r)
		}
	}
}

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

package main

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

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

	var T, n, m, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		ans := make([][]byte, n)
		for i := range ans {
			ans[i] = make([]byte, m)
		}
		if n&1 > 0 {
			k -= m / 2
			if k < 0 || k&1 > 0 {
				Fprintln(out, "NO")
				continue
			}
			for j := 1; j < m; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[n-1][j-1] = c
				ans[n-1][j] = c
			}
		} else if m&1 > 0 {
			if k > m/2*n {
				Fprintln(out, "NO")
				continue
			}
			for i := 1; i < n; i += 2 {
				c := 'f' ^ byte(i/2&1)
				ans[i-1][m-1] = c
				ans[i][m-1] = c
			}
		}
		for i := 1; i < n; i += 2 {
			for j := 1; j < m; j += 2 {
				if k > 0 {
					k--
					c := 'b' ^ byte(j/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c
					ans[i][j-1] = c ^ 1
					ans[i][j] = c ^ 1
				} else {
					c := 'd' ^ byte(i/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c ^ 1
					ans[i][j-1] = c
					ans[i][j] = c ^ 1
				}
			}
		}
		Fprintln(out, "YES")
		for _, r := range ans {
			Fprintf(out, "%s\n", r)
		}
	}
}

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

package main

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

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

	var T, n, m, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		ans := make([][]byte, n)
		for i := 0; i < n; i++ {
			ans[i] = make([]byte, m)
		}
		if n&1 > 0 {
			k -= m / 2
			if k < 0 {
				Fprintln(out, "NO")
				continue
			}
			for j := 0; j < m; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[n-1][j] = c
				ans[n-1][j+1] = c
			}
		} else if m&1 > 0 {
			if k > m/2*n {
				Fprintln(out, "NO")
				continue
			}
			for j := 0; j < n; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[j][m-1] = c
				ans[j+1][m-1] = c
			}
		}
		if k&1 > 0 {
			Fprintln(out, "NO")
			continue
		}
		for i := 1; i < n; i += 2 {
			for j := 1; j < m; j += 2 {
				if k > 0 {
					k -= 2
					c := 'b' ^ byte(j/2&1)
					ans[i][j-1] = c
					ans[i][j] = c
					ans[i-1][j-1] = c ^ 1
					ans[i-1][j] = c ^ 1
				} else {
					c := 'd' ^ byte(j/2&1)
					ans[i][j-1] = c
					ans[i][j] = c
					ans[i-1][j-1] = c ^ 1
					ans[i-1][j] = c ^ 1
				}
			}
		}
		Fprintln(out, "YES")
		for i := 0; i < n; i++ {
			Fprintf(out, "%s/n", ans[i])
		}
	}
}

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


You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix a is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.

The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.

Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.

package main

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

func main() {
	const maxn = 5010
	var (
		n, m int
		a    [maxn][maxn]int
	)
	fmt.Scanf("%d %d\n", &n, &m)
	scan := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scan.Scan()
		s := scan.Text()
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[j][i] = d
		}
	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := make([]int, m+1)
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[j][i]]++
			if maxw < a[j][i] {
				maxw = a[j][i]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	const maxn = 5010
	var (
		n, m int
		a    [maxn][maxn]int
	)
	fmt.Scanf("%d %d\n", &n, &m)
	scan := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scan.Scan()
		s := scan.Text()
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[i][j] = d
		}
	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := [maxn + 1]int{}
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[i][j]]++
			if maxw < a[i][j] {
				maxw = a[i][j]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	const maxn = 5010
	var (
		n, m int
		a    [maxn][maxn]int
	)
	fmt.Scanf("%d %d\n", &n, &m)
	scan := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scan.Scan()
		s := scan.Text()
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[i][j] = d
		}
	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := make([]int, m+1)
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[i][j]]++
			if maxw < a[i][j] {
				maxw = a[i][j]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	const maxn = 5010
	var n, m int
	fmt.Scan(&n, &m)
	a := make([][]int, m+1)
	for i := range a {
		a[i] = make([]int, n+1)
	}
	scan := bufio.NewScanner(os.Stdin)
	scan.Scan()
	for i := 0; i < n; i++ {
		scan.Scan()
		s := scan.Text()
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[j][i] = d
		}
	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := make([]int, m+1)
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[j][i]]++
			if maxw < a[j][i] {
				maxw = a[j][i]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	const maxn = 5010
	var (
		n, m int
		a    [maxn][maxn]int
	)
	fmt.Scanf("%d %d\n", &n, &m)
	scan := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scan.Scan()
		s := scan.Text()
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[i][j] = d
		}
	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	bucket := make([]int, maxn+1)
	for j := 0; j < m; j++ {
		for i := 0; i <= m; i++ {
			bucket[i] = 0
		}
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[i][j]]++
			if maxw < a[i][j] {
				maxw = a[i][j]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	const maxn = 5010
	var (
		n, m int
		a [maxn][maxn]int
	)
	fmt.Scanf("%d %d\n", &n, &m)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < n; i++ {
		s, _ := reader.ReadString('\n')
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[i][j] = d
		}
	}
//	for i := 0; i < n; i++ {
//		for j := 0; j < m; j++ {
//			fmt.Print(a[i][j], " ")
//		}
//		fmt.Println()
//	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := [maxn+1]int{}
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[i][j]]++
			if maxw < a[i][j] {
				maxw = a[i][j]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	const maxn = 5010
	var (
		n, m int
		a [maxn][maxn]int
	)
	fmt.Scanf("%d %d", &n, &m)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scanf("%s", &s)
		d := 0
		for j := 0; j < m; j++ {
			if j < len(s) && s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[i][j] = d
		}
	}
//	for i := 0; i < n; i++ {
//		for j := 0; j < m; j++ {
//			fmt.Print(a[i][j], " ")
//		}
//		fmt.Println()
//	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := [maxn+1]int{}
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[i][j]]++
			if maxw < a[i][j] {
				maxw = a[i][j]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}