package main

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

type node struct {
	val int64
	typ int //0 for 1 add
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	s := ""
	fmt.Fscanf(in, "%s\n", &s)

	for i := 0; i < 10; i++ {
		for j := 0; j < 10; j++ {
			a := make([][]int, 10)
			for k := 0; k < 10; k++ {
				a[k] = make([]int, 10)
				for q := 0; q < 10; q++ {
					a[k][q] = cal(i, j, k, q)
				}
			}
			ans := 0
			for k := 1; k < len(s); k++ {
				from := int(s[k-1] - '0')
				to := int(s[k] - '0')
				if a[from][to] == -1 {
					ans = -1
					break
				}
				ans += a[from][to]
			}
			if ans == -1 {
				fmt.Fprintf(out, "%d", -1)
			} else {
				fmt.Fprintf(out, "%d", ans-len(s)+1)
			}
			if j < 9 {
				fmt.Fprintf(out, " ")
			}
		}
		fmt.Fprintf(out, "\n")
	}
	return
}

func cal(a, b, x, y int) int {
	// x -> y with a and b
	ans := -1
	for i := 0; i < 10; i++ {
		for j := 0; j < 10; j++ {
			if i+j == 0 {
				continue
			}
			if (i*a+j*b+x)%10 == y {
				if ans == -1 {
					ans = i + j
				} else {
					if i+j < ans {
						ans = i + j
					}
				}
			}
		}
	}
	return ans
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1202B(_r io.Reader, _w io.Writer) {
	s, _ := ioutil.ReadAll(_r)
	s = bytes.TrimSpace(s)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	cnts := [10]int{}
	for i, c := range s[1:] {
		cnts[(c-s[i]+10)%10]++
	}
	ans := [10][10]int{}
	for x := range ans {
	loop:
		for y := range ans {
			ops := [10]int{}
			for i := range ops {
				ops[i] = 99
			}
			for i := 0; i < 10; i++ {
				for j := 0; j < 10; j++ {
					if i == 0 && j == 0 {
						continue
					}
					if v := (i*x + j*y) % 10; i+j < ops[v] {
						ops[v] = i + j
					}
				}
			}
			for i, op := range ops {
				if op == 99 && cnts[i] > 0 {
					ans[x][y] = -1
					continue loop
				}
				ans[x][y] += (op - 1) * cnts[i]
			}
		}
	}
	for _, ai := range ans {
		for _, v := range ai {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

/* solution */

const inf = 1000000000

var d [][][]int

func solve() {

	d = make([][][]int, 100)

	// step 1 (initialize)

	for c := 0; c < 100; c++ {

		d[c] = make([][]int, 10)

		for x := 0; x < 10; x++ {

			d[c][x] = make([]int, 10)

			for y := 0; y < 10; y++ {
				d[c][x][y] = inf
			}

			for y := 0; y < 10; y++ {

				if y < x {
					d[c][x][y] = d[c][y][x]
					continue
				}

				if c == 0 {
					d[c][x][y] = 0
					continue
				}

				cd := gcd(x, y)
				if cd == 0 {
					d[c][x][y] = inf
					continue
				}

				diff := c
				for diff < 100 && diff%cd != 0 {
					diff *= 10
				}

				if diff >= 100 {
					d[c][x][y] = inf
				} else {
					if c-x < 0 && c-y < 0 {
						d[c][x][y] = inf
					} else if c-x < 0 {
						d[c][x][y] = d[c-y][x][y] + 1
					} else if c-y < 0 {
						d[c][x][y] = d[c-x][x][y] + 1
					} else {
						if d[c-y][x][y] > d[c-x][x][y] {
							d[c][x][y] = d[c-x][x][y] + 1
						} else {
							d[c][x][y] = d[c-y][x][y] + 1
						}
					}
				}

			}

		}

	}

	// step 2 (compress)

	for c := 0; c < 10; c++ {
		diff := c
		skip := 0
		if diff == 0 {
			diff = 10
			skip = 1
		}
		for x := 0; x < 10; x++ {
			for y := 0; y < 10; y++ {
				min := d[diff][x][y]
				for j := 1; j < 10-skip; j++ {
					if d[diff+10*j][x][y] < min {
						min = d[diff+10*j][x][y]
					}
				}
				d[c][x][y] = min
			}
		}
	}

	// step 3 (output)

	s := read()

	matrix := make([][]int, 10)

	for x := 0; x < 10; x++ {

		matrix[x] = make([]int, 10)

		for y := 0; y < 10; y++ {

			ans := 0

			if y < x {

				ans = matrix[y][x]

			} else {

				cur := int(s[0] - '0')
				for i := 1; ans < inf && i < len(s); i++ {

					next := int(s[i] - '0')
					diff := (next - cur + 10) % 10

					ans += d[diff][x][y]

					cur = next

				}

				matrix[x][y] = ans

			}

			if ans >= inf {
				printInt(-1)
			} else {
				printInt(ans - len(s) + 1)
			}

		}

		println("")

	}

}

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

/* stubs */

func main() {

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

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

	reader = bufio.NewScanner(f)

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

	reader.Split(bufio.ScanWords)

	solve()

}

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

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

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

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

func println(s string) {
	if len(s) > 0 {
		writer.WriteString(s)
	}
	writer.WriteString("\n")
}

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

func printLnInt(i int) {
	println(strconv.Itoa(i))
}

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

package main

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

/* solution */

const inf = 1000000

var d [][][]int

func solve() {

	d = make([][][]int, 100)

	for c := 0; c < 100; c++ {

		d[c] = make([][]int, 10)

		for x := 0; x < 10; x++ {

			d[c][x] = make([]int, 10)

			for y := 0; y < 10; y++ {
				d[c][x][y] = inf
			}

			for y := 0; y < 10; y++ {

				if c == 0 {
					d[c][x][y] = 0
					continue
				}

				cd := gcd(x, y)
				if cd == 0 {
					d[c][x][y] = inf
					continue
				}

				diff := c
				for diff < 100 && diff%cd != 0 {
					diff *= 10
				}

				if diff >= 100 {
					d[c][x][y] = inf
				} else {
					if c-x < 0 && c-y < 0 {
						d[c][x][y] = inf
					} else if c-x < 0 {
						d[c][x][y] = d[c-y][x][y] + 1
					} else if c-y < 0 {
						d[c][x][y] = d[c-x][x][y] + 1
					} else {
						if d[c-y][x][y] > d[c-x][x][y] {
							d[c][x][y] = d[c-x][x][y] + 1
						} else {
							d[c][x][y] = d[c-y][x][y] + 1
						}
					}
				}

			}

		}

	}

	s := read()

	for x := 0; x < 10; x++ {

		for y := 0; y < 10; y++ {

			ans := int64(0)

			cur := int(s[0] - '0')
			for i := 1; ans < inf && i < len(s); i++ {

				next := int(s[i] - '0')
				diff := (next - cur + 10) % 10

				// corner case
				skip := 0
				if diff == 0 {
					diff = 10
					skip = 1
				}

				min := d[diff][x][y]
				for j := 1; j < 10-skip; j++ {
					if d[diff+10*j][x][y] < min {
						min = d[diff+10*j][x][y]
					}
				}

				ans += int64(min)

				cur = next

			}

			if ans >= inf {
				printInt(-1)
			} else {
				printInt64(ans - int64(len(s)+1))
			}

		}

		println("")

	}

}

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

/* stubs */

func main() {

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

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

	reader = bufio.NewScanner(f)

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

	reader.Split(bufio.ScanWords)

	solve()

}

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

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

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

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

func println(s string) {
	if len(s) > 0 {
		writer.WriteString(s)
	}
	writer.WriteString("\n")
}

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

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

func printLnInt(i int) {
	println(strconv.Itoa(i))
}

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

package main

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

/* solution */

const inf = 1000000

var d [][][]int

func solve() {

	d = make([][][]int, 100)

	for c := 0; c < 100; c++ {

		d[c] = make([][]int, 10)

		for x := 0; x < 10; x++ {

			d[c][x] = make([]int, 10)

			for y := 0; y < 10; y++ {
				d[c][x][y] = inf
			}

			for y := 0; y < 10; y++ {

				if c == 0 {
					d[c][x][y] = 0
					continue
				}

				cd := gcd(x, y)
				if cd == 0 {
					d[c][x][y] = inf
					continue
				}

				diff := c
				for diff < 100 && diff%cd != 0 {
					diff *= 10
				}

				if diff >= 100 {
					d[c][x][y] = inf
				} else {
					if c-x < 0 && c-y < 0 {
						d[c][x][y] = inf
					} else if c-x < 0 {
						d[c][x][y] = d[c-y][x][y] + 1
					} else if c-y < 0 {
						d[c][x][y] = d[c-x][x][y] + 1
					} else {
						if d[c-y][x][y] > d[c-x][x][y] {
							d[c][x][y] = d[c-x][x][y] + 1
						} else {
							d[c][x][y] = d[c-y][x][y] + 1
						}
					}
				}

			}

		}

	}

	s := read()

	for x := 0; x < 10; x++ {

		for y := 0; y < 10; y++ {

			ans := int64(0)

			cur := int(s[0] - '0')
			for i := 1; ans < inf && i < len(s); i++ {

				next := int(s[i] - '0')
				diff := (next - cur + 10) % 10

				// corner case
				skip := 0
				if diff == 0 {
					diff = 10
					skip = 1
				}

				min := d[diff][x][y]
				for j := 1; j < 10-skip; j++ {
					if d[diff+10*j][x][y] < min {
						min = d[diff+10*j][x][y]
					}
				}

				ans += int64(min)

				cur = next

			}

			if ans >= inf {
				printInt(-1)
			} else {
				printInt64(ans - int64(len(s)-1))
			}

		}

		println("")

	}

}

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

/* stubs */

func main() {

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

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

	reader = bufio.NewScanner(f)

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

	reader.Split(bufio.ScanWords)

	solve()

}

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

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

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

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

func println(s string) {
	if len(s) > 0 {
		writer.WriteString(s)
	}
	writer.WriteString("\n")
}

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

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

func printLnInt(i int) {
	println(strconv.Itoa(i))
}

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

package main

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

/* solution */

const inf = 36000000

var d [][][]int

func solve() {

	d = make([][][]int, 100)

	// step 1 (initialize)

	for c := 0; c < 100; c++ {

		d[c] = make([][]int, 10)

		for x := 0; x < 10; x++ {

			d[c][x] = make([]int, 10)

			for y := 0; y < 10; y++ {
				d[c][x][y] = inf
			}

			for y := 0; y < 10; y++ {

				if y < x {
					d[c][x][y] = d[c][y][x]
					continue
				}

				if c == 0 {
					d[c][x][y] = 0
					continue
				}

				cd := gcd(x, y)
				if cd == 0 {
					d[c][x][y] = inf
					continue
				}

				diff := c
				for diff < 100 && diff%cd != 0 {
					diff *= 10
				}

				if diff >= 100 {
					d[c][x][y] = inf
				} else {
					if c-x < 0 && c-y < 0 {
						d[c][x][y] = inf
					} else if c-x < 0 {
						d[c][x][y] = d[c-y][x][y] + 1
					} else if c-y < 0 {
						d[c][x][y] = d[c-x][x][y] + 1
					} else {
						if d[c-y][x][y] > d[c-x][x][y] {
							d[c][x][y] = d[c-x][x][y] + 1
						} else {
							d[c][x][y] = d[c-y][x][y] + 1
						}
					}
				}

			}

		}

	}

	// step 2 (compress)

	for c := 0; c < 10; c++ {
		diff := c
		skip := 0
		if diff == 0 {
			diff = 10
			skip = 1
		}
		for x := 0; x < 10; x++ {
			for y := 0; y < 10; y++ {
				min := d[diff][x][y]
				for j := 1; j < 10-skip; j++ {
					if d[diff+10*j][x][y] < min {
						min = d[diff+10*j][x][y]
					}
				}
				d[c][x][y] = min
			}
		}
	}

	// step 3 (output)

	s := read()

	matrix := make([][]int, 10)

	for x := 0; x < 10; x++ {

		matrix[x] = make([]int, 10)

		for y := 0; y < 10; y++ {

			ans := 0

			if y < x {

				ans = matrix[y][x]

			} else {

				cur := int(s[0] - '0')
				for i := 1; ans < inf && i < len(s); i++ {

					next := int(s[i] - '0')
					diff := (next - cur + 10) % 10

					ans += d[diff][x][y]

					cur = next

				}

				matrix[x][y] = ans

			}

			if ans >= inf {
				printInt(-1)
			} else {
				printInt(ans - len(s) + 1)
			}

		}

		println("")

	}

}

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

/* stubs */

func main() {

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

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

	reader = bufio.NewScanner(f)

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

	reader.Split(bufio.ScanWords)

	solve()

}

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

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

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

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

func println(s string) {
	if len(s) > 0 {
		writer.WriteString(s)
	}
	writer.WriteString("\n")
}

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

func printLnInt(i int) {
	println(strconv.Itoa(i))
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1202B(_r io.Reader, _w io.Writer) {
	s, _ := ioutil.ReadAll(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	cnts := [10]int{}
	for i, c := range s[1:] {
		cnts[(c-s[i]+10)%10]++
	}
	ans := [10][10]int{}
	for x := range ans {
	loop:
		for y := range ans {
			ops := [10]int{}
			for i := range ops {
				ops[i] = 99
			}
			for i := 0; i < 10; i++ {
				for j := 0; j < 10; j++ {
					if i == 0 && j == 0 {
						continue
					}
					if v := (i*x + j*y) % 10; i+j < ops[v] {
						ops[v] = i + j
					}
				}
			}
			for i, op := range ops {
				if op == 99 && cnts[i] > 0 {
					ans[x][y] = -1
					continue loop
				}
				ans[x][y] += (op - 1) * cnts[i]
			}
		}
	}
	for _, ai := range ans {
		for _, v := range ai {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1202B(_r io.Reader, _w io.Writer) {
	s, _ := ioutil.ReadAll(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	Fprintln(out, s, len(s))

	cnts := [10]int{}
	for i, c := range s[1:] {
		cnts[(c-s[i]+10)%10]++
	}
	ans := [10][10]int{}
	for x := range ans {
	loop:
		for y := range ans {
			ops := [10]int{}
			for i := range ops {
				ops[i] = 99
			}
			for i := 0; i < 10; i++ {
				for j := 0; j < 10; j++ {
					if i == 0 && j == 0 {
						continue
					}
					if v := (i*x + j*y) % 10; i+j < ops[v] {
						ops[v] = i + j
					}
				}
			}
			for i, op := range ops {
				if op == 99 && cnts[i] > 0 {
					ans[x][y] = -1
					continue loop
				}
				ans[x][y] += (op - 1) * cnts[i]
			}
		}
	}
	for _, ai := range ans {
		for _, v := range ai {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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


package main

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

const (
	MaxIterations = 200005
)

var n, t int
var a []int
var counts map[int]int
var numElementsPerIteration [MaxIterations]int
var elemCount [MaxIterations]map[int]int
var maxPossibleIterations int

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &t)
	a = make([]int, n)
	counts = make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(inBuf, "%d", &a[i])
		counts[a[i]]++
	}

	for elem := range counts {
		for iterations := 1; iterations <= counts[elem]; iterations++ {
			if iterations > maxPossibleIterations {
				maxPossibleIterations = iterations
			}
			if elemCount[iterations] == nil {
				elemCount[iterations] = make(map[int]int)
			}
			count := counts[elem] / iterations
			elemCount[iterations][elem] = count
			numElementsPerIteration[iterations] += count
		}
	}

	r := make([]int, 0)
	for i := maxPossibleIterations; i >= 1; i-- {
		if numElementsPerIteration[i] >= t {
			for element := range elemCount[i] {
				for count := 0; count < elemCount[i][element]; count++ {
					if len(r) < t {
						r = append(r, element)
					} else {
						break
					}
				}
				if len(r) == t {
					break
				}
			}
		}
	}

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() } ()
	for i := 0; i < t; i++ {
		fmt.Fprintf(outBuf, "%d ", r[i])
	}
}

package main

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

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

	var n, k int
	Fscan(in, &n, &k)
	cnt := make([]int, 2e5+1)
	for i := 0; i < n; i++ {
		var v int
		Fscan(in, &v)
		cnt[v]++
	}

	times := sort.Search(n/k+1, func(times int) bool {
		if times <= 1 {
			return false
		}
		// 不能删除 times 次
		left := k
		for _, c := range cnt {
			left -= c / times
			if left <= 0 {
				return false
			}
		}
		return true
	})
	times--
	for v, c := range cnt {
		for c /= times; c > 0; c-- {
			Fprint(out, v, " ")
			k--
			if k == 0 {
				return
			}
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1077D(reader io.Reader, writer io.Writer) {
	type bsFunc func(int) bool
	reverse := func(f bsFunc) bsFunc {
		return func(i int) bool {
			return !f(i)
		}
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n, k int
	Fscan(in, &n, &k)
	cnt := make([]int, 2e5+1)
	for i := 0; i < n; i++ {
		var v int
		Fscan(in, &v)
		cnt[v]++
	}

	times := sort.Search(n/k+1, reverse(func(times int) bool {
		// return true if we can cut out `times` times
		if times <= 1 {
			return true
		}
		left := k
		for _, c := range cnt {
			left -= c / times
			if left <= 0 {
				return true
			}
		}
		return false
	}))
	times--
	for v, c := range cnt {
		for c /= times; c > 0; c-- {
			Fprint(out, v, " ")
			k--
			if k == 0 {
				return
			}
		}
	}
}

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

package main

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

const (
	MaxIterations = 200005
)

var n, t int
var a []int
var counts map[int]int
var numElementsPerIteration [MaxIterations]int
var elemCount [MaxIterations]map[int]int
var maxPossibleIterations int

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &t)
	a = make([]int, n)
	counts = make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(inBuf, "%d", &a[i])
		counts[a[i]]++
	}

	for elem := range counts {
		//for count := counts[elem]; count >= 1; count-- {
		//	iterations := counts[elem] / count
		//	if iterations > maxPossibleIterations {
		//		maxPossibleIterations = iterations
		//	}
		//	if elemCount[iterations] == nil {
		//		elemCount[iterations] = make(map[int]int)
		//	}
		//	if _, ok := elemCount[iterations][elem]; !ok {
		//		elemCount[iterations][elem] = count
		//		numElementsPerIteration[iterations] += count
		//	}
		//}
		for iterations := 1; iterations <= counts[elem]; iterations++ {
			if iterations > maxPossibleIterations {
				maxPossibleIterations = iterations
			}
			if elemCount[iterations] == nil {
				elemCount[iterations] = make(map[int]int)
			}
			count := counts[elem] / iterations
			elemCount[iterations][elem] = count
			numElementsPerIteration[iterations] += count
		}
	}

	r := make([]int, 0)
	for i := maxPossibleIterations; i >= 1; i-- {
		if numElementsPerIteration[i] >= t {
			for element := range elemCount[i] {
				for count := 0; count < elemCount[i][element]; count++ {
					if len(r) < t {
						r = append(r, element)
					} else {
						break
					}
				}
				if len(r) == t {
					break
				}
			}
		}
	}

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() } ()
	for i := 0; i < t; i++ {
		fmt.Fprintf(outBuf, "%d ", r[i])
	}
}

package main

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

const (
	MaxIterations = 200005
)

type pair struct {
	elem, count int
}

var n, t int
var a []int
var counts map[int]int
var numElementsPerIteration [MaxIterations]int
var elemCount [MaxIterations]map[int]int
var maxPossibleIterations int

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &t)
	a = make([]int, n)
	counts = make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(inBuf, "%d", &a[i])
		counts[a[i]]++
	}

	for elem := range counts {
		for count := 1; count <= counts[elem]; count++ {
			iterations := counts[elem] / count
			if iterations > maxPossibleIterations {
				maxPossibleIterations = iterations
			}
			if elemCount[iterations] == nil {
				elemCount[iterations] = make(map[int]int)
			}
			if _, ok := elemCount[iterations][elem]; !ok {
				elemCount[iterations][elem] = count
				numElementsPerIteration[iterations] += count
			}
		}
	}

	r := make([]int, 0)
	for i := maxPossibleIterations; i >= 1; i-- {
		if numElementsPerIteration[i] >= t {
			for element := range elemCount[i] {
				for count := 0; count < elemCount[i][element]; count++ {
					if len(r) < t {
						r = append(r, element)
					} else {
						break
					}
				}
				if len(r) == t {
					break
				}
			}
		}
	}

	if len(r) == 0 {
		r = a
	}

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() } ()
	for i := 0; i < t; i++ {
		fmt.Fprintf(outBuf, "%d ", r[i])
	}
}

package main

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

const (
	MaxIterations = 200005
)

type pair struct {
	elem, count int
}

var n, t int
var a []int
var counts map[int]int
var numElementsPerIteration [MaxIterations]int
var elemCount [MaxIterations]map[int]int
var maxPossibleIterations int

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &t)
	a = make([]int, n)
	counts = make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(inBuf, "%d", &a[i])
		counts[a[i]]++
	}

	for elem := range counts {
		for count := counts[elem]; count >= 1; count-- {
			iterations := counts[elem] / count
			if iterations > maxPossibleIterations {
				maxPossibleIterations = iterations
			}
			if elemCount[iterations] == nil {
				elemCount[iterations] = make(map[int]int)
			}
			if _, ok := elemCount[iterations][elem]; !ok {
				elemCount[iterations][elem] = count
				numElementsPerIteration[iterations] += count
			}
		}
		for i := counts[elem] / 2 + 1; i <= counts[elem]; i++ {
			if elemCount[i] == nil {
				elemCount[i] = make(map[int]int)
			}
			if _, ok := elemCount[i][elem]; !ok {
				elemCount[i][elem] = 1
				numElementsPerIteration[i] += 1
			}
		}
	}

	r := make([]int, 0)

	for i := maxPossibleIterations; i >= 1; i-- {
		if numElementsPerIteration[i] >= t {
			for element := range elemCount[i] {
				for count := 0; count < elemCount[i][element]; count++ {
					if len(r) < t {
						r = append(r, element)
					} else {
						break
					}
				}
				if len(r) == t {
					break
				}
			}
		}
	}

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() } ()
	for i := 0; i < t; i++ {
		fmt.Fprintf(outBuf, "%d ", r[i])
	}
}

package main

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

const (
	MaxIterations = 200005
)

type pair struct {
	elem, count int
}

var n, t int
var a []int
var counts map[int]int
var numElementsPerIteration [MaxIterations]int
var elemCount [MaxIterations]map[int]int
var maxPossibleIterations int

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &t)
	a = make([]int, n)
	counts = make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(inBuf, "%d", &a[i])
		counts[a[i]]++
	}

	for elem := range counts {
		for count := 1; count <= counts[elem]; count++ {
			iterations := counts[elem] / count
			if iterations > maxPossibleIterations {
				maxPossibleIterations = iterations
			}
			if elemCount[iterations] == nil {
				elemCount[iterations] = make(map[int]int)
			}
			if _, ok := elemCount[iterations][elem]; !ok {
				elemCount[iterations][elem] = count
				numElementsPerIteration[iterations] += count
			}
		}
	}

	r := make([]int, 0)
	for i := maxPossibleIterations; i >= 1; i-- {
		if numElementsPerIteration[i] >= t {
			for element := range elemCount[i] {
				for count := 0; count < elemCount[i][element]; count++ {
					if len(r) < t {
						r = append(r, element)
					} else {
						break
					}
				}
				if len(r) == t {
					break
				}
			}
		}
	}

	if len(r) == 0 {
		r = a
	}

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() } ()
	fmt.Print(len(r))
	for i := 0; i < t; i++ {
		fmt.Fprintf(outBuf, "%d ", r[i])
	}
}

package main

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

const (
	MaxIterations = 200005
)

type pair struct {
	elem, count int
}

var n, t int
var a []int
var counts map[int]int
var numElementsPerIteration [MaxIterations]int
var elemCount [MaxIterations]map[int]int
var maxPossibleIterations int

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &t)
	a = make([]int, n)
	counts = make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(inBuf, "%d", &a[i])
		counts[a[i]]++
	}

	for elem := range counts {
		for count := counts[elem]; count >= 1; count-- {
			iterations := counts[elem] / count
			if iterations > maxPossibleIterations {
				maxPossibleIterations = iterations
			}
			if elemCount[iterations] == nil {
				elemCount[iterations] = make(map[int]int)
			}
			if _, ok := elemCount[iterations][elem]; !ok {
				elemCount[iterations][elem] = count
				numElementsPerIteration[iterations] += count
			}
		}
	}

	r := make([]int, 0)
	for i := maxPossibleIterations; i >= 1; i-- {
		if numElementsPerIteration[i] >= t {
			for element := range elemCount[i] {
				for count := 0; count < elemCount[i][element]; count++ {
					if len(r) < t {
						r = append(r, element)
					} else {
						break
					}
				}
				if len(r) == t {
					break
				}
			}
		}
	}

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() } ()
	for i := 0; i < t; i++ {
		fmt.Fprintf(outBuf, "%d ", r[i])
	}
}


package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(0)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		a, b, c := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &a, &b, &c)
		if a+b >= c-1 && a+c >= b-1 && b+c >= a-1 {
			fmt.Fprintf(out, "YES\n")
		} else {
			fmt.Fprintf(out, "NO\n")
		}
	}
	return
}

package main

import (
	"fmt"
)

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

func maxx(a, b, c int64) int64 {
	if t := max(a, b); t >= c {
		return t
	}

	return c
}

func main() {
	var a, b, c, n int64
	fmt.Scan(&n)
	for i := int64(0); i < n; i++ {
		fmt.Scan(&a, &b, &c)
		t := a + b + c
		t2 := maxx(a, b, c)
		println(t, t2, t-t2-t2)
		if t2 <= t-t2 {
			fmt.Println("Yes")
		} else if t2+t2-t == int64(1) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func newYear(t int) int {
	for t > 0 {
		n := 3
		a := make([]int, n)
		for j := 0; j < n; j++{
			fmt.Scan(&a[j])
		}
		sort.Sort(sort.IntSlice(a))
		if a[2] <= (a[0] + a[1] + 1) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
		t--
	}
	return 0
}

func main() {
	var t int
	fmt.Scan(&t)
	newYear(t)
}

package main

import (
	"fmt"
	"sort"
)

func sol(r,g,b int)bool {
	arr:=[]int{r,g,b}
	sort.Ints(arr)
	if arr[0]+arr[1]+1>=arr[2]{
		return true
	}
	return false
}
func main(){
	t:=0
	fmt.Scanf("%d\n",&t)
	for ;t>0;t--{
		r,g,b:=0,0,0
		fmt.Scanf("%d %d %d\n",&r,&g,&b)
		ans:=sol(r,g,b)
		if ans{
			fmt.Println("Yes")
		} else{
			fmt.Println("No")
		}
	}
}

package main

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

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

	testCount := 0
	fmt.Fscanf(in, "%d\n", &testCount)

	for i := 0; i < testCount; i++ {
		r, g, b := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &r, &g, &b)

		//if (r < 0 || g < 0 || b < 0) {
		//	fmt.Println("No")
		//}
		//
		//if (r == 1 && g == 0 && b == 0) {
		//	fmt.Println("Yes")
		//}
		//
		//if (r == 0 && g == 1 && b == 0) {
		//	fmt.Println("Yes")
		//}
		//if (r == 0 && g == 0 && b == 1) {
		//	fmt.Println("Yes")
		//}

		arr := []int{r, g, b}
		sort.Ints(arr)
		if arr[0]+arr[1] >= arr[2]-1 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

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

func countWays(p, q, r, last int64) int64 {

	if (p < 0 || q < 0 || r < 0) {
		return 0
	}

	if (p == 1 && q == 0 && r == 0 && last == 0) {
		return 1
	}

	if (p == 0 && q == 1 && r == 0 && last == 1) {
		return 1
	}
	if (p == 0 && q == 0 && r == 1 && last == 2) {
		return 1
	}
	if (last == 0) {
		return countWays(p-1, q, r, 1) + countWays(p-1, q, r, 2)
	}

	if (last == 1) {
		return countWays(p, q-1, r, 0) +
			countWays(p, q-1, r, 2)
	}
	if (last == 2) {
		return countWays(p, q, r-1, 0) + countWays(p, q, r-1, 1)
	}

	return 0
}

func countUtil(p, q, r int64) int64 {
	return countWays(p, q, r, 0) + countWays(p, q, r, 1) + countWays(p, q, r, 2)
}
*/

package main

import (
	. "fmt"
)

func main() {
	var n int
	Scan(&n)

	output := ""
	for i := 0; i < n; i++ {
		var r, g, b int
		Scan(&r, &g, &b)

		if b > g { b, g = g, b }
		if g > r { g, r = r, g }
		if b > g { b, g = g, b }

		if r - g - b <= 1 {
			output += "Yes\n"
		} else {
			output += "No\n"
		}
	}

	Println(output)
}

package main
import (
	"bufio"
	"fmt"
	"os"
	"strings"
)
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	ans := make([]string, n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Fscan(r, &a, &b, &c)
		if a + b >= c - 1 && b + c >= a - 1 && c + a >= b - 1 {
			ans[i] = "YES"
		} else {
			ans[i] = "NO"
		}
	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

import (
	"fmt"
)

func maxx(a, b, c int64) int64 {
	if a >= b && a >= c {
		return a
	} else if b >= a && b >= c {
		return b
	}

	return c
}

func main() {
	var a, b, c, n int64
	fmt.Scan(&n)
	for i := int64(0); i < n; i++ {
		fmt.Scan(&a, &b, &c)
		t := a + b + c
		t2 := maxx(a, b, c)
		if t2 <= t-t2 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

import (
	"fmt"
)

func maxx(a, b, c int) int {
	if a >= b && a >= c {
		return a
	} else if b >= a && b >= c {
		return b
	}

	return c
}

func main() {
	var a, b, c, n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a, &b, &c)
		t := a + b + c
		t2 := maxx(a, b, c)
		if t2 <= t-t2 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

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

	testCount := 0
	fmt.Fscanf(in, "%d\n", &testCount)

	for i := 0; i < testCount; i++ {
		r, g, b := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &r, &g, &b)

		if (r < 0 || g < 0 || b < 0) {
			fmt.Println("No")
		}

		if (r == 1 && g == 0 && b == 0) {
			fmt.Println("Yes")
		}

		if (r == 0 && g == 1 && b == 0) {
			fmt.Println("Yes")
		}
		if (r == 0 && g == 0 && b == 1) {
			fmt.Println("Yes")
		}

		arr := []int{r, g, b}
		sort.Ints(arr)

		if arr[0]+arr[1] >= arr[2] {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

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

	testCount := 0
	fmt.Fscanf(in, "%d\n", &testCount)

	for i := 0; i < testCount; i++ {
		r, g, b := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &r, &g, &b)

		//if (r < 0 || g < 0 || b < 0) {
		//	fmt.Println("No")
		//}
		//
		//if (r == 1 && g == 0 && b == 0) {
		//	fmt.Println("Yes")
		//}
		//
		//if (r == 0 && g == 1 && b == 0) {
		//	fmt.Println("Yes")
		//}
		//if (r == 0 && g == 0 && b == 1) {
		//	fmt.Println("Yes")
		//}

		arr := []int{r, g, b}
		sort.Ints(arr)

		if arr[0]+arr[1] >= arr[2] {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

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

	testCount := 0
	fmt.Fscanf(in, "%d\n", &testCount)

	for i := 0; i < testCount; i++ {
		r, g, b := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &r, &g, &b)

		//if (r < 0 || g < 0 || b < 0) {
		//	fmt.Println("No")
		//}
		//
		//if (r == 1 && g == 0 && b == 0) {
		//	fmt.Println("Yes")
		//}
		//
		//if (r == 0 && g == 1 && b == 0) {
		//	fmt.Println("Yes")
		//}
		//if (r == 0 && g == 0 && b == 1) {
		//	fmt.Println("Yes")
		//}

		arr := []int{r, g, b}
		sort.Ints(arr)
		fmt.Println(arr)
		if arr[0]+arr[1] >= arr[2]-1 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

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

func countWays(p, q, r, last int64) int64 {

	if (p < 0 || q < 0 || r < 0) {
		return 0
	}

	if (p == 1 && q == 0 && r == 0 && last == 0) {
		return 1
	}

	if (p == 0 && q == 1 && r == 0 && last == 1) {
		return 1
	}
	if (p == 0 && q == 0 && r == 1 && last == 2) {
		return 1
	}
	if (last == 0) {
		return countWays(p-1, q, r, 1) + countWays(p-1, q, r, 2)
	}

	if (last == 1) {
		return countWays(p, q-1, r, 0) +
			countWays(p, q-1, r, 2)
	}
	if (last == 2) {
		return countWays(p, q, r-1, 0) + countWays(p, q, r-1, 1)
	}

	return 0
}

func countUtil(p, q, r int64) int64 {
	return countWays(p, q, r, 0) + countWays(p, q, r, 1) + countWays(p, q, r, 2)
}
*/

package main

import (
	. "fmt"
)

func main() {
	var n int
	Scan(&n)

	output := ""
	for i := 0; i < n; i++ {
		var r, g, b int
		Scan(&r, &g, &b)

		if r + g < b || g + b < r || r + b < g {
			output += "No\n"
		} else {
			output += "Yes\n"
		}
	}

	Println(output)
}

package main
import (
	"bufio"
	"fmt"
	"os"
	"strings"
)
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	ans := make([]string, n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Fscan(r, &a, &b, &c)
		if a + b >= c && b + c >= a && c + a >= b {
			ans[i] = "YES"
		} else {
			ans[i] = "NO"
		}
	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(0)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		a, b, c := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &a, &b, &c)
		if a+b >= c && a+c >= b && b+c >= a {
			fmt.Fprintf(out, "YES\n")
		} else {
			fmt.Fprintf(out, "NO\n")

		}
	}
	return
}


package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

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

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

	for i := 0; i < n; i++ {
		fmt.Fscanf(bufin, "%d\n", &a[i])
		if m < a[i] {
			m = a[i]
		}
	}

	cnt := make([]int, m+1)
	for i := 0; i < n; i++ {
		cnt[a[i]]++
	}

	dp := make([]int, m+1)
	for x := 1; x <= m; x++ {
		dp[x] = dp[x-1] + cnt[x]
	}

	res := int64(0)
	for x := 1; x <= m; x++ {
		if cnt[x] > 0 {
			sum := int64(0)
			for y := x; y <= m; y += x {
				if y+x-1 < m {
					sum += int64(y) * int64(dp[y+x-1]-dp[y-1])
				} else {
					sum += int64(y) * int64(dp[m]-dp[y-1])
				}
			}
			if res < sum {
				res = sum
			}
		}
	}

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

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n, a int
	fmt.Fscanf(bufin, "%d\n", &n)

	cnt := make([]int, 200001)
	m := 0

	for i := 0; i < n; i++ {
		fmt.Fscanf(bufin, "%d\n", &a)
		cnt[a]++
		if m < a {
			m = a
		}
	}

	dp := make([]int, m+1)
	for x := 1; x <= m; x++ {
		dp[x] = dp[x-1] + cnt[x]
	}

	res := int64(0)
	for x := 1; x <= m; x++ {
		if cnt[x] > 0 {
			sum := int64(0)
			for y := x; y <= m; y += x {
				if y+x-1 < m {
					sum += int64(y) * int64(dp[y+x-1]-dp[y-1])
				} else {
					sum += int64(y) * int64(dp[m]-dp[y-1])
				}
			}
			if res < sum {
				res = sum
			}
		}
	}

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

package main

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

func solve() {
    n := readInt()
    a, mx := readInt64Array(n), int64(200009)

    c := make([]int64, 2*mx)
    for _, v := range a {
        c[v]++
    }
    for i := range c {
        if i > 0 {
            c[i] += c[i-1]
        }
    }

    mem := make([]int64, mx)
    for x := int64(1); x < mx; x++ {
        for k := int64(2); k*x < 2*mx; k++ {
            mem[x] += (c[k*x-1] - c[(k-1)*x-1]) * (k-1)*x
        }
    }

    ans := int64(0)
    for _, x := range a {
        if mem[x] > ans {
            ans = mem[x]
        }
    }
    fmt.Println(ans)
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// Math

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

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

// Sort

type Ints64 []int64

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

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

// http://codeforces.com/contest/731/problem/F
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

const (
	MOD = 1e9 + 7
)

type (

)

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

	return b
}

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

	return b
}

func main () {
	var (
		n int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n)
	cnt := make([]int, 200001)
	sum := make([]int, 200001)

	maxa := 0
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscan(input, &tmp)
		cnt[tmp]++
		if maxa < tmp {
			maxa = tmp
		}
	}

	// Solve
	for i := 1; i <= maxa; i++ {
		sum[i] = sum[i - 1] + cnt[i]
	}

	maxs := int64(0)
	for i := 1; i <= maxa; i++ {
		if cnt[i] > 0 {

			total := int64(0)

			for j := i; j <= maxa; j += i {
				total += (int64(sum[min(maxa, j + i - 1)] - sum[j - 1]) * int64(j))
			}

			maxs = max(maxs, total)
		}
	}

	fmt.Println(maxs)

	/*
	// Primitive solution
	sort.Ints(a)
	maxs := int64(0)

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

		sum := int64(a[i])
		for j := i + 1; j < n; j++ {
			sum += int64(a[j] - a[j] % a[i])
		}

		maxs = max(sum, maxs)
	}

	fmt.Println(maxs)*/
}

package main

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

func solve() {
    n := readInt()
    a, mx := readInt64Array(n), int64(200009)

    c := make([]int64, 2*mx)
    for _, v := range a {
        c[v]++
    }
    for i := range c {
        if i > 0 {
            c[i] += c[i-1]
        }
    }

    mem := make([]int64, mx)
    for x := int64(1); x < mx; x++ {
        for k := int64(2); k*x < mx; k++ {
            mem[x] += (c[k*x-1] - c[(k-1)*x-1]) * (k-1)*x
        }
    }

    ans := int64(0)
    for _, x := range a {
        if mem[x] > ans {
            ans = mem[x]
        }
    }
    fmt.Println(ans)
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// Math

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

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

// Sort

type Ints64 []int64

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

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

func solve() {
    n := readInt()
    a, mx := readInt64Array(n), int64(400009)

    c := make([]int64, mx)
    for _, v := range a {
        c[int(v)]++
    }
    for i := range c {
        if i > 0 {
            c[i] += c[i-1]
        }
    }

    ans := int64(0)
    for _, x := range a {
        cur := int64(0)
        for k := int64(2); k*x < mx; k++ {
            cur += c[k*x-1] - c[(k-1)*x-1] * (k-1)*x
        }
        if cur > ans {
            ans = cur
        }
    }
    fmt.Println(ans)
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// Math

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

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

// Sort

type Ints64 []int64

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

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/


package main

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

var nTest, n int
var s string

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &n, &s)
		first1ID := -1
		last0ID := -1

		for i := 0; i < n; i++ {
			if s[i] == '1' && first1ID == -1 {
				first1ID = i
			}

			if s[i] == '0' {
				last0ID = i
			}
		}

		if last0ID == -1 {
			for i := 0; i < n; i++ {
				fmt.Fprint(out, 1)
			}
		} else if first1ID == -1 {
			for i := 0; i < n; i++ {
				fmt.Fprint(out, 0)
			}
		} else {
			for i := 0; i < first1ID; i++ {
				fmt.Fprint(out, 0)
			}
			if first1ID < last0ID {
				fmt.Fprint(out, 0)
			}
			for i := n - 1; i > last0ID; i-- {
				fmt.Fprint(out, 1)
			}
		}

		fmt.Fprintln(out)
	}

	out.Flush()
}

package main

import (
  . "fmt"
)

var t int
func main() {
  Scan(&t)
  for tc := 0; tc < t; tc++ {
  	var n int
  	var bs []byte
    Scan(&n)
    Scan(&bs)
    bef := make([]byte, 0)
    aft := make([]byte, 0)
    i := 0
    for ;i < n; i++ {
        if bs[i] == '0' {
            bef = append(bef, 0)
        } else {
            break
        }
    }
    j := n-1
    for ;i <= j; j-- {
        if bs[j] == '1' {
            aft = append(aft, 1)
        } else {
            break
        }
    }
    if i <= j {
        bef = append(bef, 0)
    }
    for k := range bef {
        Print(bef[k])
    }
    for k := range aft {
        Print(aft[k])
    }
    Println()

  }
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		s, _ := reader.ReadBytes('\n')
		fmt.Println(solve(n, s))
	}
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, s []byte) string {
	var i int

	for i < n && s[i] == '0' {
		i++
	}
	if i == n {
		return string(s[:i])
	}
	// s[i] == '1'
	var j = n - 1
	for j >= 0 && s[j] == '1' {
		j--
	}
	// s[j] == '0'
	if j < i {
		return string(s[:n])
	}

	for j < n {
		s[i] = s[j]
		i++
		j++
	}
	return string(s[:i])
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 1024*1024)
	scanner.Split(bufio.ScanWords)

	input := func() int {
		scanner.Scan()
		i, _ := strconv.Atoi(scanner.Text())
		return i
	}

	var t, n int
	var s string

	t = input()

	for ; t > 0; t-- {
		n = input()

		scanner.Scan()
		s = scanner.Text()

		len := 0
		prev := -1
		count := 0
		for i := n - 1; i >= 0; i-- {
			if s[i] == '0' {
				count++
				prev = 0
			} else {
				if prev == -1 {
					len++
				} else if prev == 0 {
					count = 1
				}
			}
		}

		for i := 0; i < count; i++ {
			fmt.Print("0")
		}

		for i := 0; i < len; i++ {
			fmt.Print("1")
		}
		fmt.Print("\n")
	}

}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		ns := readLine(reader)
		str := readLine(reader)
		n, _ := strconv.ParseInt(string(ns), 10, 64)

		if str[0] == '0' {
			zero1 := int64(0)
			for i := int64(1); i < n; i++ {
				if str[i] != '0' {
					break
				}
				zero1 = i
			}
			lastone := n
			for i:=n-1;i>zero1;i-- {
				if str[i] == '0' {
					break
				}
				lastone = i
			}
			if zero1 == n-1 {
				fmt.Println(string(str))
			} else if lastone == n {
				fmt.Println(string(str[:zero1+1])+"0")
			} else if zero1 == lastone - 1{
				fmt.Println(string(str[:zero1+1])+string(str[lastone:]))
			} else {
				fmt.Println(string(str[:zero1+1])+"0"+string(str[lastone:]))
			}
		} else {
			tailone := n
			for i:=n-1;i>=0;i-- {
				if str[i] == '0' {
					break
				}
				tailone = i
			}
			if tailone == 0 {
				fmt.Println(string(str))
			} else if tailone == n {
				fmt.Println("0")
			} else {
				fmt.Println("0"+string(str[tailone:]))
			}
		}
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

/*
URL:
https://codeforces.com/contest/1369/problem/B
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n int
	S []rune
)

func main() {
	t = ReadInt()

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

		solve()
	}
}

func solve() {
	// 一種類だけの場合を除去
	comp, _ := RunLengthEncoding(S)
	if len(comp) == 1 {
		fmt.Println(string(S))
		return
	}

	var l1, r0 int
	for i := 0; i < n; i++ {
		if S[i] == '1' {
			l1 = i
			break
		}
	}
	for i := n - 1; i >= 0; i-- {
		if S[i] == '0' {
			r0 = i
			break
		}
	}

	if r0 < l1 {
		fmt.Println(string(S))
		return
	}

	// PrintfDebug("jikken: %v\n", string(S[:0]))

	ans := []rune{}
	if l1 >= 0 {
		ans = append(ans, S[:l1]...)
	}
	ans = append(ans, '0')
	if r0+1 < n {
		ans = append(ans, S[r0+1:]...)
	}
	fmt.Println(string(ans))
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []rune) ([]rune, []int) {
	runes := []rune{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []rune, L []int) []rune {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []rune{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[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"
	"io"
	"os"
)

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

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var T int
	con.Scan(&T)
	for testcase := 0; testcase < T; testcase++ {
		var n int
		var s string
		con.Scan(&n, &s)
		ok := true
		for ok {
			ok = false
			for i := len(s) - 1; i >= 0; i-- {
				if s[i] == '0' {
					j := i - 1
					for j >= 0 && s[j] == '0' {
						j--
					}
					if j >= 0 {
						s = s[:j] + s[i:]
						ok = true
					}
					break
				}
			}
		}
		con.Println(s)
	}
	return nil
}

package main

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

var nTest, n int
var s string

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &n, &s)
		first1ID := -1
		last0ID := -1

		for i := 0; i < n; i++ {
			if s[i] == '1' && first1ID == -1 {
				first1ID = i
			}

			if s[i] == '0' {
				last0ID = i
			}
		}

		for i := 0; i < first1ID; i++ {
			fmt.Fprint(out, 0)
		}

		if first1ID != -1 && last0ID != -1 && first1ID < last0ID {
			fmt.Fprint(out, 0)
		}

		if last0ID != -1 {
			for i := n - 1; i > last0ID; i-- {
				fmt.Fprint(out, 1)
			}
		} else {
			for i := 0; i < n; i++ {
				fmt.Fprint(out, 1)
			}
		}

		fmt.Fprintln(out)
	}

	out.Flush()
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF827B(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var n, k int
	Fscan(bufio.NewReader(in), &n, &k)
	l, r := (n-1)/k, (n-1)%k
	Fprintln(out, 2*l+min(r, 2))
	c := k + 2
	for i := 1; i <= k; i++ {
		ll := l
		if i > r {
			ll--
		}
		Fprintln(out, k+1, i)
		if ll > 0 {
			Fprintln(out, i, c)
			c++
		}
		for j := 1; j < ll; j++ {
			Fprintln(out, c-1, c)
			c++
		}
	}
}

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

package main

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

func Init() {
}

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

	what := make([]int, K)
	for i := 0; i < K; i++ {
	  what[i] = 1
	}

	sz := 0
	var sb bytes.Buffer
	for i := 2; i <= N; i++ {
	  idx := (i - 2) % K
	  if idx <= 1 {
	    sz++
	  }
	  sb.WriteString(fmt.Sprintf("%d %d\n", what[idx], i))
	  what[idx] = i
	}
	io.Println(sz)
	io.Println(sb.String())
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827B(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var n, k int
	Fscan(bufio.NewReader(in), &n, &k)
	l, r := (n-1)/k, (n-1)%k
	Fprintln(out, 2*l+min(r, 2))
	c := k + 2
	for i := 1; i <= k; i++ {
		for j := 0; j < l-1; j++ {
			Fprintln(out, k+1, c+j)
			c++
		}
		Fprintln(out, c-1, i)
	}
	for i := 1; i <= r; i++ {
		Fprintln(out, i, c)
		c++
	}
}

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


package main

import "fmt"

func main() {
    var k,d int
    fmt.Scan(&k,&d)
    if (d == 0) && (k != 1) {
        fmt.Println("No solution")
    } else {
        fmt.Print(d)
        for i := 1; i < k; i++ { fmt.Print(0) }
        fmt.Println()
    }
}

package main
import (
	"fmt"
	//"sort"
	//"unicode/utf8"
)
func main() {
	var n,m int
	fmt.Scan(&n,&m)
	if m==0 {
		if n==1 {
			fmt.Println("0")
		} else {
			fmt.Println("No solution")
		}
	} else {
		fmt.Print(m)
		n--
		for ; n!=0;n-- {
			fmt.Print("0")
		}
	}
}

// hey project main.go
package main

import (
    "fmt"
)

func main() {
    var x, y int
    fmt.Scan(&x, &y)

    if y == 0 && x > 1 {
        fmt.Printf("No solution\n")
        return
    }
    fmt.Print(y)
    if y != 0 {
        for i := 0; i < x-1; i++ {
            fmt.Printf("0")
        }
    }
}

// 355A-mic
package main

import (
    "fmt"
)

func main() {
    var k, l int
    fmt.Scan(&k, &l)
    if k == 0 || (k > 1 && l == 0) {
        fmt.Println("No solution")
    } else {
        fmt.Print(l)
        for i := 1; i < k; i++ {
            fmt.Print("0")
        }
        fmt.Println()
    }
}

// Steve Phillips / elimisteve
// 2013.10.13

package main

import (
	"fmt"
	"strconv"
)

const (
	NO_SOLUTION = "No solution"
)

func main() {
	// for _, num := range []int64{4098, 5881, 36172, 0} {
	// 	fmt.Printf("digitalRoot(%6d) == %d\n", num, digitalRoot(num))
	// }

	// `The first line contains two integers k and d
	// (1 ≤ k ≤ 1000; 0 ≤ d ≤ 9)`
	var k, d int64

	// `...find the number consisting of exactly k digits (the leading
	// zeroes are not allowed), with digital root equal to d, or else
	// state that such number does not exist.`

	// So, find num s.t. len(num) == k, and digitalRoot(num) == d
	fmt.Scanf("%d %d", &k, &d)

	//
	// Handle "small" corner cases
	//

	// 1, _ -> _
	if k == 1 {
		fmt.Printf("%d\n", d)
		return
	}
	// KNOWN: 1 < k

	if k > 1 && d == 0 {
		fmt.Println(NO_SOLUTION)
		return
	}

	// If number of digits (k) > their sum (d), => 1s followed by 0s
	if k >= d {
		fmt.Printf("%s%s\n", ones(d), zeroes(k-d))
		return
	}
	// KNOWN: k < d

	// => KNOWN: 1 < k < d

	fmt.Printf("%s%v\n", ones(k-1), (d%10 - (k-1)) % 10)
}

func parseInt(s string) int64 {
	num, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		panic(err)
	}
	return num
}

func digitalRoot(num int64) int64 {
	// total := sumDigits(num)
	// if total < 10 {
	// 	return total
	// }
	return sumDigits(sumDigits(sumDigits(sumDigits(num))))
}

// func digitalRoot(num int64) int64 {
// 	total := sumDigits(num)
// 	if total < 10 {
// 		return total
// 	}
// 	return sumDigits(total)
// }

func sumDigits(num int64) int64 {
	var total int64
	str := strconv.FormatInt(num, 10)
	for i, _ := range str {
		total += parseInt(str[i:i+1])
	}
	return total
}

func ones(n int64) string {
	return repeat("1", n)
}

func zeroes(n int64) string {
	return repeat("0", n)
}

func repeat(s string, times int64) string {
	str := ""
	for i := int64(0); i < times; i++ {
		str += s
	}
	return str
}

package main
import (
	"fmt"
	//"sort"
	//"unicode/utf8"
)
func main() {
	var n,m int
	fmt.Scan(&n,&m)
	if m==0 {
		if n==1 {
			fmt.Println("0")
		} else {
			fmt.Println("No Solution")
		}
	} else {
		fmt.Print(m)
		n--
		for ; n!=0;n-- {
			fmt.Print("0")
		}
	}
}

package main

import "fmt"

func main() {
    var k,d int
    fmt.Scan(&k,&d)
    if (d == 0) && (k != 1) {
        d = 55
        k--
    }
    fmt.Print(d)
    for i := 1; i < k; i++ { fmt.Print(0) }
    fmt.Println()
}

// hey project main.go
package main

import (
    "fmt"
)

func main() {
    var x, y int
    fmt.Scan(&x, &y)
    fmt.Print(y)
    if y == 0 && x > 1 {
        fmt.Printf("No solution\n")
        return
    }
    if y != 0 {
        for i := 0; i < x-1; i++ {
            fmt.Printf("0")
        }
    }
}

// hey project main.go
package main

import (
    "fmt"
)

func main() {
    var x, y int
    fmt.Scan(&x, &y)
    fmt.Print(y)
    if y != 0 {
        for i := 0; i < x-1; i++ {
            fmt.Printf("0")
        }
    }
}

// hey project main.go
package main

import (
    "fmt"
)

func main() {
    var x, y int
    fmt.Scan(&x, &y)
    fmt.Print(y)
    for i := 0; i < x-1; i++ {
        fmt.Printf("0")
    }
}


/*
URL:
https://codeforces.com/contest/1395/problem/B
*/

package main

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

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

var (
	n, m   int
	sx, sy int

	visited [][]bool
	ans     [][]int
)

func main() {
	n, m = ReadInt2()
	sy, sx = ReadInt2() // x <==> y
	sy--
	sx--

	visited = [][]bool{}
	for i := 0; i < n; i++ {
		row := make([]bool, m)
		visited = append(visited, row)
	}
	PrintfDebug("n, m, sy, sx: %d, %d, %d, %d\n", n, m, sy, sx)

	ans = [][]int{}

	cy, cx := sy, sx
	add(cy, cx)

	for cx-1 >= 0 {
		cx--
		add(cy, cx)
	}
	for cy-1 >= 0 {
		cy--
		add(cy, cx)
	}

	for cx < m {
		// 下へ
		for cy+1 < n {
			cy++
			if !visited[cy][cx] {
				add(cy, cx)
			}
		}

		// 右へ行けないなら終わり
		if cx+1 >= m {
			break
		}
		cx++
		if !visited[cy][cx] {
			add(cy, cx)
		}

		// 上へ
		for cy-1 >= 0 {
			cy--
			if !visited[cy][cx] {
				add(cy, cx)
			}
		}

		// 右へ行けないなら終わり
		if cx+1 >= m {
			break
		}
		cx++
		if !visited[cy][cx] {
			add(cy, cx)
		}
	}

	if len(ans) != n*m {
		// fmt.Println("aaa")
		panic("aaa")
	}
	for _, p := range ans {
		fmt.Println(p[0], p[1])
	}
}

func add(y, x int) {
	visited[y][x] = true
	ans = append(ans, []int{y + 1, x + 1})
}

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	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
)

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

/********** bufio setting **********/

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

/********** 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...)

/*********** Input ***********/

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

/*********** Output ***********/

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

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

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

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

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

package main

import "fmt"

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

	b := make([][]bool, n+1)

	for i := range b {
		b[i] = make([]bool, m+1)
	}

	var start bool = true

	b[x][y] = true

	fmt.Println(x, y)

	count := 0
	for count < m*n-1 {
		if start == true {
			for i := 1; i <= n; i++ {
				if !b[i][y] {
					fmt.Println(i, y)
					b[i][y] = true
					count++
				}
			}
			start = false
		} else {
			for i := n; i >= 1; i-- {
				if !b[i][y] {
					fmt.Println(i, y)
					b[i][y] = true
					count++
				}
			}
			start = true
		}

		y--
		if y == 0 {
			y = m
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n, m, x, y int // x - row, y - col
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &m)
	fmt.Fscan(in, &x)
	fmt.Fscan(in, &y)

	fmt.Println(x, y)
	fmt.Println(1, y)

	direction := true
	for i := 1; i <= n; i++ {
		if direction {
			for j := 1; j <= m; j++ {
				if i == 1 && j == y {
					continue
				}
				if i == x && j == y {
					continue
				}
				fmt.Println(i, j)
			}
			direction = false
		} else if !direction {
			for j := m; j >= 1; j-- {
				if i == 1 && j == y {
					continue
				}
				if i == x && j == y {
					continue
				}
				fmt.Println(i, j)
			}
			direction = true
		}
	}
}

package main

import "fmt"

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

	sign := "+"

	b := make([][]bool, n+1)

	for i := range b {
		b[i] = make([]bool, m+1)
	}

	count := 0
	for count < m*n {
		if !b[x][y] {
			fmt.Println(x, y)
			b[x][y] = true
			count++
		}

		if sign == "+" {
			x++
		} else {
			x--
		}

		if x == n+1 {
			y = y + 1
			x = n
			sign = "-"
		} else if x == 0 {
			y = y + 1
			x = 1
			sign = "+"
		}

		if y > m {
			y = 1
		}
	}
}

package main

import "fmt"

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

	sign := "+"
	for i := 0; i < m*n; i++ {
		fmt.Println(x, y)

		if sign == "+" {
			x++
		} else {
			x--
		}

		if x == n+1 {
			y = y + 1
			x = n
			sign = "-"
		} else if x == 0 {
			y = y + 1
			x = 1
			sign = "+"
		}

		if y > m {
			y = 1
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n, m, x, y int // x - row, y - col
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &m)
	fmt.Fscan(in, &x)
	fmt.Fscan(in, &y)

	fmt.Println(x, y)
	fmt.Println(1, y)

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if i == 1 && j == y {
				continue
			}
			if i == x && j == y {
				continue
			}
			fmt.Println(i, j)
		}
	}
}


package main

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

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

	const mx int = 1e6
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	core := func(x int) int {
		c := 1
		for x > 1 {
			p := lpf[x]
			e := 1
			for x /= p; lpf[x] == p; x /= p {
				e ^= 1
			}
			if e > 0 {
				c *= p
			}
		}
		return c
	}

	var T, n, v, q int
	var w int64
	for Fscan(in, &T); T > 0; T-- {
		cnt := map[int]int{}
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &v)
			cnt[core(v)]++
		}
		mx, c1 := 0, cnt[1]
		for v, c := range cnt {
			if c > mx {
				mx = c
			}
			if v > 1 && c&1 == 0 {
				c1 += c
			}
		}
		if mx > c1 {
			c1 = mx
		}
		for Fscan(in, &q); q > 0; q-- {
			if Fscan(in, &w); w > 0 {
				Fprintln(out, c1)
			} else {
				Fprintln(out, mx)
			}
		}
	}
}

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

package main

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

var primes = make([]int64, 0)

func sieve(n int64) {
	var i int64
	var isPrime = make([]bool, n+1)
	for i = 2; i <= n; i++ {
		isPrime[i] = true
	}
	for i = 2; i*i <= n; i++ {
		if !isPrime[i] {
			continue
		}
		for j := i * i; j <= n; j += i {
			isPrime[j] = false
		}
	}
	for i = 1; i <= n; i++ {
		if isPrime[i] {
			primes = append(primes, i)
		}
	}
}

func compress(x int64) int64 {
	var n, res int64 = x, 1
	for i := 0; i < len(primes) && primes[i]*primes[i] <= n; i++ {
		p := primes[i]
		c := 0
		for x%p == 0 {
			x /= p
			c++
		}
		if c%2 == 1 {
			res *= p
		}
	}
	return res * x
}

func solve(a, w []int64) {
	var max1, max2 int64 = -1e9, -1e9

	beforeFirst := make(map[int64]int64)
	for _, x := range a {
		y := compress(x)
		beforeFirst[y]++
		if max1 < beforeFirst[y] {
			max1 = beforeFirst[y]
		}
	}

	afterFirst := make(map[int64]int64)
	for k, v := range beforeFirst {
		if k == 1 || v%2 == 0 {
			afterFirst[1] += v
			if max2 < afterFirst[1] {
				max2 = afterFirst[1]
			}
		} else {
			afterFirst[k] += v
			if max2 < afterFirst[k] {
				max2 = afterFirst[k]
			}
		}
	}

	for _, q := range w {
		v := max1
		if q > 0 {
			v = max2
		}
		printf("%d\n", v)
	}
}

func main() {
	//RedirectInputToFile(reader, "input.txt")

	sieve(1e6)
	t := 1
	scan(&t)

	for T := 0; T < t; T++ {
		var (
			n, q int64
			a, w []int64
		)

		scan(&n)
		a = make([]int64, n)
		for i := range a {
			scan(&a[i])
		}

		scan(&q)
		w = make([]int64, q)
		for i := range w {
			scan(&w[i])
		}

		solve(a, w)
	}

	writer.Flush()
}

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

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

func RedirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

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

	const mx int = 1e6
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	core := func(x int) int {
		c := 1
		for x > 1 {
			p := lpf[x]
			e := 1
			for x /= p; lpf[x] == p; x /= p {
				e ^= 1
			}
			if e > 0 {
				c *= p
			}
		}
		return c
	}

	var T, n, v, q int
	var w int64
	for Fscan(in, &T); T > 0; T-- {
		cnt := map[int]int{}
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &v)
			cnt[core(v)]++
		}
		maxC, c1 := 0, cnt[1]
		for v, c := range cnt {
			maxC = max(maxC, c)
			if v > 1 && c&1 == 0 {
				c1 += c
			}
		}
		for Fscan(in, &q); q > 0; q-- {
			if Fscan(in, &w); w == 0 {
				Fprintln(out, maxC)
			} else {
				Fprintln(out, max(maxC, c1))
			}
		}
	}
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	const N int = 1e6
	lpf := [N + 1]int{1: 1}//定义长度为1e6 + 1的数组, lpf[1]设为1
	//lpf为最大质因数的缩写
	for i := 2; i <= N; i++ {
		if lpf[i] == 0 {
			for j := i; j <= N; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	core := func(x int) int {
		c := 1
		for x > 1 {
			p := lpf[x]
			e := 1
			for x /= p; lpf[x] == p; x /= p {
				e ^= 1
			}
			if e == 1 {
				c *= p
			}
		}
		return c
	}
	var t, n, q int
	var w int64
	for Fscan(in, &t); t > 0; t-- {
		cnt := map[int]int{}
		for Fscan(in, &n); n > 0; n-- {
			var la int
			Fscan(in, &la)
			cnt[core(la)] ++
		}
		max_0, max_1 := 0, cnt[1]
		for v, c := range cnt {
			max_0 = max(max_0, c)
			if v > 1 && c & 1 == 0 {
				max_1 += c
			}
		}
		for Fscan(in, &q); q > 0 ; q-- {
			if Fscan(in, &w); w == 0 {
				Fprintln(out, max_0)
			} else {
				Fprintln(out, max(max_0, max_1))
			}
		}
	}
}

func max(x int, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

package main

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

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

func sieve() []int {
	res := make([]int, 0)
	np := make([]bool, 1000)

	for i := 2; i < 1000; i++ {
		if !np[i] {
			res = append(res, i)
			for j := i * i; j < 1000; j += i {
				np[j] = true
			}
		}
	}
	// fmt.Println(res)
	return res
}

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		solve()
	}
}

func solve() {
	var a, n, m int
	var w int64
	s := make(map[int]int)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a)
		a = foo(a)
		s[a]++
	}
	// fmt.Fprintln(out, s)
	var mx, sum int
	for val, sz := range s {
		if sz > mx {
			mx = sz
		}
		if val == 1 || sz%2 == 0 {
			sum += sz
		}
	}
	if mx > sum {
		sum = mx
	}

	fmt.Fscan(in, &m)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &w)
		if w == 0 {
			fmt.Fprintln(out, mx)
		} else {
			fmt.Fprintln(out, sum)
		}
	}
}

func foo(a int) int {
	for _, p := range primes {
		if p > a {
			break
		}
		ok := false
		for a%p == 0 {
			ok = !ok
			a /= p
		}
		if ok {
			a = a * p
		}
	}
	// fmt.Println(a)
	return a
}

package main

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

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

func sieve() []int {
	res := make([]int, 0)
	np := make([]bool, 1000)

	for i := 2; i < 1000; i++ {
		if !np[i] {
			res = append(res, i)
			for j := i * i; j < 1000; j += i {
				np[j] = true
			}
		}
	}
	// fmt.Println(res)
	return res
}

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		solve()
	}
}

func solve() {
	var a, n, m int
	s := make(map[int]int)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a)
		a = foo(a)
		s[a]++
	}
	// fmt.Fprintln(out, s)
	var mx, sum int
	sum = s[1]
	for val, sz := range s {
		if sz > mx {
			mx = sz
		}
		if val > 1 && sz%2 == 0 {
			sum += sz
		}
	}
	if mx > sum {
		sum = mx
	}

	fmt.Fscan(in, &m)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &a)
		if a == 0 {
			fmt.Fprintln(out, mx)
		} else {
			fmt.Fprintln(out, sum)
		}
	}
}

func foo(a int) int {
	for _, p := range primes {
		if p > a {
			break
		}
		ok := false
		for a%p == 0 {
			ok = !ok
			a /= p
		}
		if ok {
			a = a * p
		}
	}
	// fmt.Println(a)
	return a
}

package main

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

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

func sieve() []int {
	res := make([]int, 0)
	np := make([]bool, 1000)

	for i := 2; i < 1000; i++ {
		if !np[i] {
			res = append(res, i)
			for j := i * i; j < 1000; j += i {
				np[j] = true
			}
		}
	}
	// fmt.Println(res)
	return res
}

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		solve()
	}
}

func solve() {
	var a, n, m int
	s := make(map[int]int)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a)
		a = foo(a)
		s[a]++
	}
	// fmt.Fprintln(out, s)
	var mx, sum int
	for val, sz := range s {
		if sz > mx {
			mx = sz
		}
		if val > 1 && sz%2 == 0 {
			sum += sz
		}
	}
	if mx > sum {
		sum = mx
	}

	fmt.Fscan(in, &m)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &a)
		if a == 0 {
			fmt.Fprintln(out, mx)
		} else {
			fmt.Fprintln(out, sum)
		}
	}
}

func foo(a int) int {
	for _, p := range primes {
		if p > a {
			break
		}
		ok := false
		for a%p == 0 {
			ok = !ok
			a /= p
		}
		if ok {
			a = a * p
		}
	}
	// fmt.Println(a)
	return a
}

package main

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

var (
	in     = bufio.NewReader(os.Stdin)
	out    = bufio.NewWriter(os.Stdout)
	primes = sieve()
	pp     = make([]int, 1000001)
)

func bar(x, y int) int {
	res := 0
	for x%y == 0 {
		res++
		x /= y
	}
	return res
}

func sieve() []int {
	res := make([]int, 0)
	np := make([]bool, 1000001)

	for i := 1; i <= 1000000; i++ {
		pp[i] = 1
	}

	for i := 2; i <= 1000000; i++ {
		if !np[i] {
			res = append(res, i)
			for j := i; j <= 1000000; j += i {
				np[j] = true
				if bar(j, i)%2 == 1 {
					pp[j] *= i
				}
			}
		}
	}
	// fmt.Println(res, len(res))
	return res
}

func main() {
	defer out.Flush()

	// return

	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		solve()
	}
}

func solve() {
	var a, n, m int
	s := make(map[int]int)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a)
		a = pp[a]
		s[a]++
	}
	var mx, sum int
	for val, sz := range s {
		if sz > mx {
			mx = sz
		}
		if val == 1 || sz%2 == 0 {
			sum += sz
		}
	}
	if mx > sum {
		sum = mx
	}

	fmt.Fscan(in, &m)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &a)
		if a == 0 {
			fmt.Fprintln(out, mx)
		} else {
			fmt.Fprintln(out, sum)
		}
	}
}

func foo(a int) int {
	for _, p := range primes {
		if p > a {
			break
		}
		ok := false
		for a%p == 0 {
			ok = !ok
			a /= p
		}
		if ok {
			a = a * p
		}
	}
	// fmt.Println(a)
	return a
}

package main

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

var (
	in     = bufio.NewReader(os.Stdin)
	out    = bufio.NewWriter(os.Stdout)
	primes = sieve()
	pp     = make([]int, 1000001)
)

func bar(x, y int) int {
	res := 0
	for x%y == 0 {
		res++
		x /= y
	}
	return res
}

func sieve() []int {
	res := make([]int, 0)
	np := make([]bool, 1000000)

	for i := 1; i <= 1000000; i++ {
		pp[i] = 1
	}

	for i := 2; i < 1000000; i++ {
		if !np[i] {
			res = append(res, i)
			for j := i; j < 1000000; j += i {
				np[j] = true
				if bar(j, i)%2 == 1 {
					pp[j] *= i
				}
			}
		}
	}
	// fmt.Println(res, len(res))
	return res
}

func main() {
	defer out.Flush()

	// return

	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		solve()
	}
}

func solve() {
	var a, n, m int
	s := make(map[int]int)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a)
		a = pp[a]
		s[a]++
	}
	var mx, sum int
	for val, sz := range s {
		if sz > mx {
			mx = sz
		}
		if val == 1 || sz%2 == 0 {
			sum += sz
		}
	}
	if mx > sum {
		sum = mx
	}

	fmt.Fscan(in, &m)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &a)
		if a == 0 {
			fmt.Fprintln(out, mx)
		} else {
			fmt.Fprintln(out, sum)
		}
	}
}

func foo(a int) int {
	for _, p := range primes {
		if p > a {
			break
		}
		ok := false
		for a%p == 0 {
			ok = !ok
			a /= p
		}
		if ok {
			a = a * p
		}
	}
	// fmt.Println(a)
	return a
}

package main

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

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

func sieve() []int {
	res := make([]int, 0)
	np := make([]bool, 1000)

	for i := 2; i < 1000; i++ {
		if !np[i] {
			res = append(res, i)
			for j := i * i; j < 1000; j += i {
				np[j] = true
			}
		}
	}
	return res
}

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		solve()
	}
}

func solve() {
	var a, n, m int
	s := make(map[int]int)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a)
		a = foo(a)
		s[a]++
	}
	var mx, sum int
	for val, sz := range s {
		if sz > mx {
			mx = sz
		}
		if val == 1 || sz%2 == 0 {
			sum += sz
		}
	}
	if mx > sum {
		sum = mx
	}

	fmt.Fscan(in, &m)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &a)
		if a == 0 {
			fmt.Fprintln(out, mx)
		} else {
			fmt.Fprintln(out, sum)
		}
	}
}

func foo(a int) int {
	for _, p := range primes {
		if p > a {
			break
		}
		ok := false
		for a%p == 0 {
			ok = !ok
			a /= p
		}
		if ok {
			a = a * p
		}
	}
	return a
}

package main

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

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

	const mx int = 1e6
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	core := func(x int) int {
		c := 1
		for x > 1 {
			p := lpf[x]
			e := 1
			for x /= p; lpf[x] == p; x /= p {
				e ^= 1
			}
			if e > 0 {
				c *= p
			}
		}
		return c
	}

	var T, n, v, q int
	var w int64
	for Fscan(in, &T); T > 0; T-- {
		cnt := map[int]int{}
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &v)
			cnt[core(v)]++
		}
		mx, c1 := 0, cnt[1]
		for _, c := range cnt {
			if c > mx {
				mx = c
			}
			if c&1 == 0 {
				c1 += c
			}
		}
		if mx > c1 {
			c1 = mx
		}
		for Fscan(in, &q); q > 0; q-- {
			if Fscan(in, &w); w > 0 {
				Fprintln(out, c1)
			} else {
				Fprintln(out, mx)
			}
		}
	}
}

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

package main

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

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

	const mx int = 1e6
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	core := func(x int) int {
		c := 1
		for x > 1 {
			p := lpf[x]
			e := 1
			for x /= p; lpf[x] == p; x /= p {
				e ^= 1
			}
			if e > 0 {
				c *= p
			}
		}
		return c
	}

	var T, n, v, q int
	var w int64
	for Fscan(in, &T); T > 0; T-- {
		cnt := map[int]int{}
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &v)
			cnt[core(v)]++
		}
		mx, c1 := 0, cnt[1]
		for _, c := range cnt {
			if c > mx {
				mx = c
			}
			if c&1 == 0 {
				c1 += c
			}
		}
		for Fscan(in, &q); q > 0; q-- {
			if Fscan(in, &w); w > 0 {
				Fprintln(out, c1)
			} else {
				Fprintln(out, mx)
			}
		}
	}
}

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

package main

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

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

	const mx int = 1e6
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	core := func(x int) int {
		c := 1
		for x > 1 {
			p := lpf[x]
			e := 1
			for x /= p; lpf[x] == p; x /= p {
				e ^= 1
			}
			if e > 0 {
				c *= p
			}
		}
		return c
	}

	var T, n, v, q int
	var w int64
	for Fscan(in, &T); T > 0; T-- {
		c1 := 0
		cnt := map[int]int{}
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &v)
			if v == 1 {
				c1++
			} else {
				cnt[core(v)]++
			}
		}
		mx := c1
		for _, c := range cnt {
			if c > mx {
				mx = c
			}
			if c&1 == 0 {
				c1 += c
			}
		}
		for Fscan(in, &q); q > 0; q-- {
			Fscan(in, &w)
			if w > 0 {
				Fprintln(out, c1)
			} else {
				Fprintln(out, mx)
			}
		}
	}
}

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

package main

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

var primes = make([]int64, 0)

func sieve(n int64) {
	var i int64
	var isPrime = make([]bool, n+1)
	for i = 2; i <= n; i++ {
		isPrime[i] = true
	}
	for i = 2; i*i <= n; i++ {
		if !isPrime[i] {
			continue
		}
		for j := i * i; j <= n; j += i {
			isPrime[j] = false
		}
	}
	for i = 1; i <= n; i++ {
		if isPrime[i] {
			primes = append(primes, i)
		}
	}
}

func compress(x int64) int64 {
	var res int64 = 1
	for i := 0; i < len(primes) && x > 1; i++ {
		p := primes[i]
		c := 0
		for x%p == 0 {
			x /= p
			c++
		}
		if c%2 == 1 {
			res *= p
		}
	}
	return res
}

func solve(a, w []int64) {
	var max1, max2 int64 = -1e9, -1e9

	beforeFirst := make(map[int64]int64)
	for _, x := range a {
		y := compress(x)
		beforeFirst[y]++
		if max1 < beforeFirst[y] {
			max1 = beforeFirst[y]
		}
	}

	afterFirst := make(map[int64]int64)
	for k, v := range beforeFirst {
		if k == 1 || v%2 == 0 {
			afterFirst[1] += v
			if max2 < afterFirst[1] {
				max2 = afterFirst[1]
			}
		} else {
			afterFirst[k] += v
			if max2 < afterFirst[k] {
				max2 = afterFirst[k]
			}
		}
	}

	for q := range w {
		v := max1
		if q > 0 {
			v = max2
		}
		printf("%d\n", v)
	}
}

func main() {
	//RedirectInputToFile(reader, "input.txt")

	sieve(1e6)
	t := 1
	scan(&t)

	for T := 0; T < t; T++ {
		var (
			n, q int64
			a, w []int64
		)

		scan(&n)
		a = make([]int64, n)
		for i := range a {
			scan(&a[i])
		}

		scan(&q)
		w = make([]int64, q)
		for i := range w {
			scan(&w[i])
		}

		solve(a, w)
	}

	writer.Flush()
}

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

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

func RedirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

var primes = make([]int64, 0)

func sieve(n int64) {
	var i int64
	var isPrime = make([]bool, n+1)
	for i = 2; i <= n; i++ {
		isPrime[i] = true
	}
	for i = 2; i*i <= n; i++ {
		if !isPrime[i] {
			continue
		}
		for j := i * i; j <= n; j += i {
			isPrime[j] = false
		}
	}
	for i = 1; i <= n; i++ {
		if isPrime[i] {
			primes = append(primes, i)
		}
	}
}

func compress(x int64) int64 {
	var res int64 = 1
	for i := 0; i < len(primes) && x > 1; i++ {
		p := primes[i]
		c := 0
		for x%p == 0 {
			x /= p
			c++
		}
		if c%2 == 1 {
			res *= p
		}
	}
	return res
}

func solve(a []int64, q, w int64) {
	var max1, max2 int64 = -1e9, -1e9

	beforeFirst := make(map[int64]int64)
	for _, x := range a {
		y := compress(x)
		beforeFirst[y]++
		if max1 < beforeFirst[y] {
			max1 = beforeFirst[y]
		}
	}

	afterFirst := make(map[int64]int64)
	for k, v := range beforeFirst {
		if k == 1 || v%2 == 0 {
			afterFirst[1] += v
			if max2 < afterFirst[1] {
				max2 = afterFirst[1]
			}
		} else {
			afterFirst[k] += v
			if max2 < afterFirst[k] {
				max2 = afterFirst[k]
			}
		}
	}

	for i := int64(0); i < q; i++ {
		v := max1
		if w > 0 {
			v = max2
		}
		printf("%d\n", v)
	}
}

func main() {
	//RedirectInputToFile(reader, "input.txt")

	sieve(1e6)
	t := 1
	scan(&t)

	for T := 0; T < t; T++ {
		var (
			n, q, w int64
			a       []int64
		)
		scan(&n)
		a = make([]int64, n)
		for i := range a {
			scan(&a[i])
		}
		scan(&q, &w)
		solve(a, q, w)
	}

	writer.Flush()
}

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

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

func RedirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}