You have a statistic of price changes for one product represented as an array of $$$n$$$ positive integers $$$p_0, p_1, \dots, p_{n - 1}$$$, where $$$p_0$$$ is the initial price of the product and $$$p_i$$$ is how the price was increased during the $$$i$$$-th month.Using these price changes you are asked to calculate the inflation coefficients for each month as the ratio of current price increase $$$p_i$$$ to the price at the start of this month $$$(p_0 + p_1 + \dots + p_{i - 1})$$$.Your boss said you clearly that the inflation coefficients must not exceed $$$k$$$ %, so you decided to increase some values $$$p_i$$$ in such a way, that all $$$p_i$$$ remain integers and the inflation coefficients for each month don't exceed $$$k$$$ %.You know, that the bigger changes — the more obvious cheating. That's why you need to minimize the total sum of changes.What's the minimum total sum of changes you need to make all inflation coefficients not more than $$$k$$$ %?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 100$$$; $$$1 \le k \le 100$$$) — the length of array $$$p$$$ and coefficient $$$k$$$. The second line of each test case contains $$$n$$$ integers $$$p_0, p_1, \dots, p_{n - 1}$$$ ($$$1 \le p_i \le 10^9$$$) — the array $$$p$$$.

For each test case, print the minimum total sum of changes you need to make all inflation coefficients not more than $$$k$$$ %.

NoteIn the first test case, you can, for example, increase $$$p_0$$$ by $$$50$$$ and $$$p_1$$$ by $$$49$$$ and get array $$$[20150, 50, 202, 202]$$$. Then you get the next inflation coefficients:   $$$\frac{50}{20150} \le \frac{1}{100}$$$;  $$$\frac{202}{20150 + 50} \le \frac{1}{100}$$$;  $$$\frac{202}{20200 + 202} \le \frac{1}{100}$$$; In the second test case, you don't need to modify array $$$p$$$, since the inflation coefficients are already good:   $$$\frac{1}{1} \le \frac{100}{100}$$$;  $$$\frac{1}{1 + 1} \le \frac{100}{100}$$$;

package main

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

func main() {

	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

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

		var p, s [100]int64
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &p[i])
			s[i] = p[i]
		}
		for i := 1; i < n; i++ {
			s[i] += s[i-1]
		}

		var ans int64
		for i := 1; i < n; i++ {
			temp := ((100 * p[i] - k * s[i - 1]) + k - 1) / k
			if temp > ans {
				ans = temp
			}
		}
		fmt.Printf("%d\n",ans)
	}
}

package main

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

const eps = 1e-8

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

	var t int
	_, _ = fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		var k int64
		_, _ = fmt.Fscan(in, &n, &k)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		var l, r int64
		l = -1
		r = int64(1e16)
		for r - l > 1 {
			mid := (r + l)/2
			sum := a[0] + mid
			ok := true
			for i := 1; i < n; i++ {
				if a[i] > sum*k/100 {
					ok = false
					break
				}
				sum += a[i]
			}
			if !ok {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Fprintf(out, "%d\n", r)
	}
}

package main

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

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

func main() {
	defer out.Flush()
	var T int64
	_, _ = fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		var n int
		var k int64
		_, _ = fmt.Fscan(in, &n, &k)

		preSum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			_, _ = fmt.Fscan(in, &preSum[i])
			preSum[i] += preSum[i-1]
		}
		var ans int64 = 0
		for i := 2; i <= n; i++ {
			p := preSum[i] - preSum[i-1]
			s := preSum[i-1] + ans
			x := p * 100 / k
			if (p*100)%k > 0 {
				x++
			}
			if s < x {
				ans += x - s
			}
			//fmt.Println(i, "::", x, p)
		}
		//_, _ = fmt.Fprintln(out, ans)
		fmt.Println(ans)
	}
}

package main

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

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

func main() {
	defer out.Flush()
	var T int64
	_, _ = fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		var n int
		var k int64
		_, _ = fmt.Fscan(in, &n, &k)

		preSum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			_, _ = fmt.Fscan(in, &preSum[i])
			preSum[i] += preSum[i-1]
		}
		var ans int64 = 0
		for i := 2; i <= n; i++ {
			p := preSum[i] - preSum[i-1]
			s := preSum[i-1] + ans
			x := p * 100 / k
			if (p*100)%k > 0 {
				x++
			}
			if s < x {
				ans += x - s
			}
			//fmt.Println(i, "::", x, p)
		}
		_, _ = fmt.Fprintln(out, ans)
	}

}

package main

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

func main() {
	a := bufio.NewReader(os.Stdin)
	l, _ := a.ReadString('\n')
	l = strings.Trim(strings.Trim(l, "\n"), "\r")
	ln, _ := strconv.Atoi(l)
	for i := 0; i < ln; i++ {
		s, _ := a.ReadString('\n')
		las := strings.Split(strings.Trim(strings.Trim(s, "\n"), "\r"), " ")
		n, _ := strconv.Atoi(las[0])
		k, _ := strconv.Atoi(las[1])
		str, _ := a.ReadString('\n')
		str = strings.Trim(strings.Trim(str, "\n"), "\r")
		mstr := make([]int64, n)
		mstra := strings.Split(str, " ")
		for j := 0; j < n; j++ {
			mstr[j], _ = strconv.ParseInt(mstra[j], 10, 64)
		}
		fmt.Printf("%d\n", fn(int64(k), mstr))
	}
}

func fn(k int64, a []int64) int64 {
	x := int64(0)
	sum := a[0]
	for i := 1; i < len(a); i++ {
		pr := (100*a[i] - k*sum + k - 1) / k
		x = max(x, pr)
		sum += a[i]
	}
	return x
}

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

package main

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

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

func Max(x, y int64) int64 {
	if x < y {
		return y
	} else {
		return x
	}
}

func main() {
	t := 10000
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		var n, k int64 = 10000, 50
		fmt.Fscan(in, &n, &k)
		p := make([]int64, n)
		var res, sum int64 = 0, 0
		for i := int64(0); i < n; i++ {
			fmt.Fscan(in, &p[i])
			if i > 0 {
				res += Max(0, (100*p[i]+k-1)/k-sum)
				p[0] += Max(0, (100*p[i]+k-1)/k-sum)
				sum += Max(0, (100*p[i]+k-1)/k-sum)
			}
			sum += p[i]
		}
		fmt.Println(res)
	}
}

package main

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

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

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

	var t, n int
	var k int64
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		p := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &p[i])
		}
		currentPrice, fraud := p[0], int64(0)
		for i := 1; i < n; i++ {
			if p[i]*100 > k*(currentPrice+fraud) {
				fraud += ceil(p[i]*100-k*(currentPrice+fraud), k)
			}
			//fmt.Println(p, float64(p[i])/float64(currentPrice+fraud)*100, currentPrice+fraud)
			currentPrice += p[i]
		}
		fmt.Println(fraud)
	}
}

package main

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

/*
1
5 3
30 3 2 1 4
---

1. 3/30 <= 3/100 -> 3/100 <= 3/100
2. 2/103 <= 3/100
3. 1/105 <= 3/100
4. 4/106 <= 3/100

100 3 1
+70 0 0

30
5 3
3 2 2 2 4
5 32
1 1 2 4 2
5 56
2 1 4 3 2
4 64
2 4 1 3
5 43
4 4 2 2 1
5 68
3 3 4 3 2
5 20
2 3 3 1 1
5 64
3 2 4 1 2
5 86
1 1 4 3 2
5 77
2 3 3 3 1
4 48
1 3 3 2
5 62
4 3 4 4 3
3 16
1 1 3
5 86
1 3 2 1 1
5 79
4 3 3 1 1
5 16
4 1 4 1 3
5 88
4 1 4 4 1
5 13
1 1 3 2 1
5 85
2 1 1 1 4
5 34
4 3 4 3 1
5 3
1 1 4 4 4
5 46
2 1 2 4 1
4 84
3 3 4 2
4 53
1 3 4 2
5 95
3 1 1 1 4
5 57
2 1 3 4 4
5 7
1 1 1 4 1
4 53
1 3 2 4
5 80
4 2 3 3 2
4 48
1 3 4 3

1
5 62
4 3 4 4 3
---
1

*/

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

	p := make([]int, n)

	for i := range p {
		scanf("%d", &p[i])
	}
	scanf("\n")

	ans := int64(0)
	sum := int64(p[0])

	for i := int64(1); i < n; i++ {
		d := divCeil(100*int64(p[i])-k*sum, k)

		sum += int64(p[i])

		if d > 0 {
			sum += d
			ans += d
		}
	}

	fmt.Fprintln(writer, ans)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

	return nums[minNumIdx]
}

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

	return nums[maxNumIdx]
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

/*
1
5 3
30 3 2 1 4
---

1. 3/30 <= 3/100 -> 3/100 <= 3/100
2. 2/103 <= 3/100
3. 1/105 <= 3/100
4. 4/106 <= 3/100

100 3 1
+70 0 0

30
5 3
3 2 2 2 4
5 32
1 1 2 4 2
5 56
2 1 4 3 2
4 64
2 4 1 3
5 43
4 4 2 2 1
5 68
3 3 4 3 2
5 20
2 3 3 1 1
5 64
3 2 4 1 2
5 86
1 1 4 3 2
5 77
2 3 3 3 1
4 48
1 3 3 2
5 62
4 3 4 4 3
3 16
1 1 3
5 86
1 3 2 1 1
5 79
4 3 3 1 1
5 16
4 1 4 1 3
5 88
4 1 4 4 1
5 13
1 1 3 2 1
5 85
2 1 1 1 4
5 34
4 3 4 3 1
5 3
1 1 4 4 4
5 46
2 1 2 4 1
4 84
3 3 4 2
4 53
1 3 4 2
5 95
3 1 1 1 4
5 57
2 1 3 4 4
5 7
1 1 1 4 1
4 53
1 3 2 4
5 80
4 2 3 3 2
4 48
1 3 4 3

1
5 62
4 3 4 4 3
---
1

*/

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

	p := make([]int, n)

	for i := range p {
		scanf("%d", &p[i])
	}
	scanf("\n")

	ans := int64(0)
	sum := int64(p[0])

	for i := int64(1); i < n; i++ {
		d := divCeil(100*int64(p[i])-k*sum, k)

		sum += int64(p[i])

		if d > 0 {
			sum += d
			ans += d
		}
	}

	fmt.Fprintln(writer, ans)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

	return nums[minNumIdx]
}

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

	return nums[maxNumIdx]
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	t   int
	n   int
	k   int64
)

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n, &k)

		p := make([]int64, n)
		for i := range p {
			fmt.Fscan(in, &p[i])
		}

		fmt.Fprintln(out, solve3(p, k))

	}

}

func solve3(p []int64, k int64) int64 {

	sum := int64(0)
	ans := int64(0)

	for i := range p {

		//跳過p[0]
		if i != 0 {

			//不符合條件
			if sum*k < p[i]*100 {

				//暫存最小p[0]值
				temp := p[i] * 100 / k

				//p[i]無條件進位
				if p[i]*100%k != 0 {
					temp += 1
				}

				ans += temp - sum

				sum = temp

			}

		}

		sum += p[i]

	}

	return ans

}

package main

import (
	"bufio"
	"fmt"
	"os"
	//. "testgo/helpers"
)

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 main() {
	defer writer.Flush()
	//RedirectInputToFile(reader, "input.txt")
	t := 1
	scan(&t)

	for T := 0; T < t; T++ {
		var (
			n, k int64
		)
		scan(&n)
		scan(&k)

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

		solve(p, k)
	}
}

func solve(p []int64, k int64) {
	prefSumP := make([]int64, len(p))
	for i := range p {
		var prev int64
		if i > 0 {
			prev = prefSumP[i-1]
		}
		prefSumP[i] = prev + p[i]
	}

	ans := int64(0)
	for i := 1; i < len(p); i++ {
		v := (100*p[i] - k*prefSumP[i-1] + k - 1) / k
		if v > ans {
			ans = v
		}
	}
	printf("%v\n", ans)
}

package main

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

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

func main() {
	var t int
	fmt.Fscan(in, &t)

	for t > 0 {
		t--
		var n int
		var k int64
		fmt.Fscan(in, &n, &k)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		var sum, ans int64

		sum = a[0]
		ans = 0

		for i := 1; i < n; i++ {
			l, r := a[i]*100, sum*k
			if l > r {
				nextVal := (l + k - 1) / k
				ans += (nextVal - sum)
				sum = nextVal
			}
			sum += a[i]
		}
		fmt.Println(ans)
	}
}

package main

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

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

func solve() {
	n, k := getI(), getI()
	p := getInts(n)

	lo := int64(p[0])
	hi := int64(100 * 1e9)

	for lo < hi {
		x := lo + (hi-lo)/2

		s := x
		var tooLow bool
		for i := int64(1); i < n; i++ {
			if p[i]*100 > k*s {
				tooLow = true
				break
			}
			s += p[i]
		}

		if tooLow {
			lo = x + 1
		} else {
			hi = x
		}
	}

	out(lo - p[0])
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

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

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

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

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

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

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)
		p := readNNums(reader, n)
		res := solve(n, k, p)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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
}

const INF = 1 << 40

func solve(n, k int, p []int) int64 {
	// x / s > k / 100 => x * 100 > s * k
	P := make([]int64, n)
	for i := 0; i < n; i++ {
		P[i] = int64(p[i])
	}

	K := int64(k)

	check := func(x int64) bool {
		// x is the limit
		var xx int64
		var sum int64
		var i int

		for i < n && xx <= x {
			sum += P[i]
			if i+1 < n {
				// P[i+1] / sum > k / 100
				if P[i+1]*100 > sum*K {
					y := (P[i+1]*100 + K - 1) / K
					xx += y - sum
					sum = y
				}
			}

			i++
		}

		return i == n && xx <= x
	}

	var left, right int64 = 0, INF

	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			right = mid
		} else {
			left = mid + 1
		}
	}
	return right
}

package main

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

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

func main() {
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n, k int
		fmt.Fscan(in, &n, &k)
		var a [101]int64
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
			a[i] += a[i-1]
		}
		var ans int64
		for i := n; i > 1; i-- {
            top := ((a[i]-a[i-1])*100-1)/int64(k) + 1
			if top-a[i-1] > ans {
				ans = top - a[i-1]
			}
		}
		fmt.Fprintln(out, ans)
	}
	out.Flush()
}

package main

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

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {

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

		ARRAY := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}

		var SUM int64
		var SUM1 int64
		for i := 1; i < n; i++ {
			SUM = SUM + ARRAY[i-1]
			SUM1 = SUM1 + ARRAY[i-1]
			if 100*ARRAY[i] > SUM*int64(k) {
				if (100*ARRAY[i])%int64(k) == 0 {
					SUM = SUM + (100*ARRAY[i])/int64(k) - SUM

				} else {
					SUM = SUM + int64((100*ARRAY[i])/int64(k)) - SUM + 1

				}

			}
		}
		fmt.Println(SUM - SUM1)

	}

}

package main

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

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

	solve := func(Case int) {
		var n int
		var k int64
		Fscan(in, &n, &k)
		p := make([]int64, n)
		for i := range p {
			Fscan(in, &p[i])
		}

		f := func(p0 int64) bool {
			s := p0
			for i := 1; i < n; i++ {
				if p[i]*100 > k*s {
					return false
				}
				s += p[i]
			}
			return true
		}

		p0 := search(p[0], 1e15, f)
		Fprintln(out, p0-p[0])
	}

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

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

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

package main

import (
	"fmt"
)

func main() {

	var tcs int
	_, _ = fmt.Scan(&tcs)

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

		var p, s [100]int64
		for i := 0; i < n; i++ {
			_, _ = fmt.Scanf("%d ", &p[i])
			s[i] = p[i]
		}
		for i := 1; i < n; i++ {
			s[i] += s[i-1]
		}

		var ans int64
		for i := 1; i < n; i++ {
			temp := ((100 * p[i] - k * s[i - 1]) + k - 1) / k
			if temp > ans {
				ans = temp
			}
		}
		fmt.Printf("%d\n",ans)
	}
}

package main

import (
	"fmt"
)

func main() {

	var tcs int
	_, _ = fmt.Scan(&tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		var k int64
		_, _ = fmt.Scanf("%d%d", &n, &k)

		var p, s [100]int64
		for i := 0; i < n; i++ {
			_, _ = fmt.Scanf("%d", &p[i])
			s[i] = p[i]
		}
		for i := 1; i < n; i++ {
			s[i] += s[i-1]
		}

		var ans int64
		for i := 1; i < n; i++ {
			temp := ((100 * p[i] - k * s[i - 1]) + k - 1) / k
			if temp > ans {
				ans = temp
			}
		}
		fmt.Printf("%d\n",ans)
	}
}

package main

import (
	"fmt"
)

func main() {

	var tcs int
	_, _ = fmt.Scanf("%d", &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		var k int64
		_, _ = fmt.Scanf("%d %d", &n, &k)

		var p, s [100]int64
		for i := 0; i < n; i++ {
			_, _ = fmt.Scanf("%d", &p[i])
			s[i] = p[i]
		}
		for i := 1; i < n; i++ {
			s[i] += s[i-1]
		}

		var ans int64
		for i := 1; i < n; i++ {
			temp := ((100 * p[i] - k * s[i - 1]) + k - 1) / k
			if temp > ans {
				ans = temp
			}
		}
		fmt.Printf("%d\n",ans)
	}
}

package main

import (
	"fmt"
)

func main() {

	var tcs int
	_, _ = fmt.Scan(&tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		var k int64
		_, _ = fmt.Scanf("%d %d", &n, &k)

		var p, s [100]int64
		for i := 0; i < n; i++ {
			_, _ = fmt.Scanf("%d", &p[i])
			s[i] = p[i]
		}
		for i := 1; i < n; i++ {
			s[i] += s[i-1]
		}

		var ans int64
		for i := 1; i < n; i++ {
			temp := ((100 * p[i] - k * s[i - 1]) + k - 1) / k
			if temp > ans {
				ans = temp
			}
		}
		fmt.Printf("%d\n",ans)
	}
}

package main

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

const eps = 1e-8

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

	var t int
	_, _ = fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		var k float64
		_, _ = fmt.Fscan(in, &n, &k)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		k /= 100
		var l, r int64
		l = -1
		r = int64(1e16)
		for r - l > 1 {
			mid := (r + l)/2
			sum := a[0] + mid
			ok := true
			for i := 1; i < n; i++ {
				if float64(a[i]) - float64(sum)*k > eps {
					ok = false
					break
				}
				sum += a[i]
			}
			if !ok {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Fprintf(out, "%d\n", r)
	}
}

package main

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

const eps = 1e-8

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

	var t int
	_, _ = fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		var k float64
		_, _ = fmt.Fscan(in, &n, &k)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		k /= 100
		var l, r int64
		l = -1
		r = int64(1e16)
		for r - l > 1 {
			mid := (r + l)/2
			sum := a[0] + mid
			ok := true
			for i := 1; i < n; i++ {
				if float64(sum)*k - float64(a[i]) > eps {
					ok = false
					break
				}
				sum += a[i]
			}
			if !ok {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Fprintf(out, "%d\n", r)
	}
}

package main

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

const eps = 1e-8

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

	var t int
	_, _ = fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		var k float64
		_, _ = fmt.Fscan(in, &n, &k)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		k /= 100
		var l, r int64
		l = -1
		r = int64(1e16)
		for r - l > 1 {
			mid := (r + l)/2
			sum := a[0] + mid
			ok := true
			for i := 1; i < n; i++ {
				if float64(a[i]) > float64(sum)*k {
					ok = false
					break
				}
				sum += a[i]
			}
			if !ok {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Fprintf(out, "%d\n", r)
	}
}

package main

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

const eps = 1e-8

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

	var t int
	_, _ = fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		var k float64
		_, _ = fmt.Fscan(in, &n, &k)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		k /= 100
		var l, r int64
		l = -1
		r = int64(1e16)
		for r - l > 1 {
			mid := (r + l)/2
			sum := a[0] + mid
			ok := true
			for i := 1; i < n; i++ {
				if float64(a[i])/k > float64(sum) {
					ok = false
					break
				}
				sum += a[i]
			}
			if !ok {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Fprintf(out, "%d\n", r)
	}
}

package main

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

const eps = 1e-8

func smartCeil(v float64) float64 {
	if v - math.Floor(v) > eps {
		return v + 1
	}
	return v
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	_, _ = fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		var k float64
		_, _ = fmt.Fscan(in, &n, &k)
		a := make([]int64, n + 1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		ans := 0.0
		k /= 100
		sum := float64(a[1])
		for i := 2; i <= n; i++ {
			if float64(a[i])/k >= sum {
				ans += float64(a[i]) / k - sum
				sum += float64(a[i]) / k - sum
			}
			sum += float64(a[i])
		}
		fmt.Fprintf(out, "%d\n", int64(smartCeil(ans)))
	}
	_ = out.Flush()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	_, _ = fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		var k float64
		_, _ = fmt.Fscan(in, &n, &k)
		a := make([]int64, n + 1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		ans := 0.0
		k /= 100
		sum := float64(a[1])
		for i := 2; i <= n; i++ {
			if float64(a[i])/k > sum {
				ans += float64(a[i]) / k - sum
				sum += float64(a[i]) / k - sum
			}
			sum += float64(a[i])
		}
		fmt.Fprintf(out, "%d\n", int64(math.Round(ans)))
	}
	_ = out.Flush()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	_, _ = fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		var k float64
		_, _ = fmt.Fscan(in, &n, &k)
		a := make([]int64, n + 1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		ans := 0.0
		k /= 100
		sum := float64(a[1])
		for i := 2; i <= n; i++ {
			if float64(a[i])/k > sum {
				ans += float64(a[i]) / k - sum
				sum += float64(a[i]) / k - sum
			}
			sum += float64(a[i])
		}
		fmt.Fprintf(out, "%d\n", int64(math.Ceil(ans)))
	}
	_ = out.Flush()
}

package main

import "fmt"

func main() {
	var T int64
	_, _ = fmt.Scan(&T)
	for ; T > 0; T-- {
		var n int
		var k int64
		_, _ = fmt.Scan(&n, &k)
		preSum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			_, _ = fmt.Scan(&preSum[i])
			preSum[i] += preSum[i-1]
		}
		var ans int64 = 0
		for i := 2; i <= n; i++ {
			p := preSum[i] - preSum[i-1]
			s := preSum[i-1] + ans
			x := p * 100 / k
			if s < x {
				ans += x - s
			}
		}
		fmt.Println(ans)
	}

}

/*
5 3
3 2 2 2 4
*/
func max(a int64, b int64) int64 {
	if a >= b {
		return a
	}
	return b
}

package main

import "fmt"

func main() {
	var T int64
	fmt.Scan(&T)
	for ; T > 0; T-- {
		var n, k int
		fmt.Scan(&n, &k)
		preSum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Scan(&preSum[i])
			preSum[i] += preSum[i-1]
		}
		var ans int64 = 0
		for i := 2; i <= n; i++ {
			p := preSum[i] - preSum[i-1]
			s := preSum[i-1] + ans
			if s*int64(k) >= 100*p {
				continue
			}
			ans = ans + (100*p - s*int64(k))
		}
		fmt.Println(ans)
	}

}

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

package main

import "fmt"

func main() {
	var T int64
	fmt.Scan(&T)
	for ; T > 0; T-- {
		var n, k int
		fmt.Scan(&n, &k)
		preSum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Scan(&preSum[i])
			preSum[i] += preSum[i-1]
		}
		var ans int64 = 0
		for i := 2; i <= n; i++ {
			p := preSum[i] - preSum[i-1]
			s := preSum[i-1] + ans
			if s*int64(k) >= 100*p {
				continue
			}
			ans = ans + (100*p - s)
		}
		fmt.Println(ans)
	}

}

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

package main

import "fmt"

func main() {
	var T int64
	fmt.Scan(&T)
	for ; T > 0; T-- {
		var n, k int
		fmt.Scan(&n, &k)
		preSum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Scan(&preSum[i])
			preSum[i] += preSum[i-1]
		}
		var ans int64 = 0
		for i := 2; i <= n; i++ {
			p := preSum[i] - preSum[i-1]
			s := preSum[i-1]
			if s*int64(k) >= 100*p {
				continue
			}
			ans = max(100*p - s,ans)
		}
		fmt.Println(ans)
	}

}

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

package main

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

func main() {
	a := bufio.NewReader(os.Stdin)
	l, _ := a.ReadString('\n')
	l = strings.Trim(strings.Trim(l, "\n"), "\r")
	ln, _ := strconv.Atoi(l)
	for i := 0; i < ln; i++ {
		s, _ := a.ReadString('\n')
		las := strings.Split(strings.Trim(strings.Trim(s, "\n"), "\r"), " ")
		n, _ := strconv.Atoi(las[0])
		k, _ := strconv.Atoi(las[1])
		str, _ := a.ReadString('\n')
		str = strings.Trim(strings.Trim(str, "\n"), "\r")
		mstr := make([]uint64, n)
		mstra := strings.Split(str, " ")
		for j := 0; j < n; j++ {
			proma, _ := strconv.ParseInt(mstra[j], 10, 64)
			mstr[j] = uint64(proma)
		}
		fmt.Printf("%d\n", fn(uint64(k), mstr))
	}
}

func fn(k uint64, a []uint64) uint64 {
	x := uint64(0)
	sum := a[0]
	for i := 1; i < len(a); i++ {
		x = max(x, (100*a[i]-k*sum+k-1)/k)
		sum += a[i]
	}
	return x - a[0]
}

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

package main

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

func main() {
	a := bufio.NewReader(os.Stdin)
	l, _ := a.ReadString('\n')
	l = strings.Trim(strings.Trim(l, "\n"), "\r")
	ln, _ := strconv.Atoi(l)
	for i := 0; i < ln; i++ {
		s, _ := a.ReadString('\n')
		las := strings.Split(strings.Trim(strings.Trim(s, "\n"), "\r"), " ")
		n, _ := strconv.Atoi(las[0])
		k, _ := strconv.Atoi(las[1])
		str, _ := a.ReadString('\n')
		str = strings.Trim(strings.Trim(str, "\n"), "\r")
		mstr := make([]uint64, n)
		mstra := strings.Split(str, " ")
		for j := 0; j < n; j++ {
			proma, _ := strconv.ParseInt(mstra[j], 10, 64)
			mstr[j] = uint64(proma)
		}
		fmt.Printf("%d\n", fn(uint64(k), mstr))
	}
}

func fn(k uint64, a []uint64) uint64 {
	x := uint64(0)
	sum := uint64(0)
	for i := 1; i < len(a); i++ {
		x = max(x, (100*a[i]-k*sum+k-1)/k)
		sum += a[i]
	}
	return x - a[0]
}

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

package main

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

func main() {
	a := bufio.NewReader(os.Stdin)
	l, _ := a.ReadString('\n')
	l = strings.Trim(strings.Trim(l, "\n"), "\r")
	ln, _ := strconv.Atoi(l)
	for i := 0; i < ln; i++ {
		s, _ := a.ReadString('\n')
		las := strings.Split(strings.Trim(strings.Trim(s, "\n"), "\r"), " ")
		n, _ := strconv.Atoi(las[0])
		k, _ := strconv.Atoi(las[1])
		str, _ := a.ReadString('\n')
		str = strings.Trim(strings.Trim(str, "\n"), "\r")
		mstr := make([]int64, n)
		mstra := strings.Split(str, " ")
		for j := 0; j < n; j++ {
			mstr[j], _ = strconv.ParseInt(mstra[j], 10, 64)
		}
		fmt.Printf("%d\n", fn(int64(k), mstr))
	}
}

func fn(k int64, a []int64) (res int64) {
	x := int64(0)
	sum := int64(0)
	for i := 1; i < len(a); i++ {
		x = max(x, (100*a[i]-k*sum+k-1)/k)
		sum += a[i]
	}
	return x - a[0]
}

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

package main

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

func main() {
	a:=bufio.NewReader(os.Stdin)
	l, _ :=a.ReadString('\n')
	l=strings.Trim(strings.Trim(l,"\n"),"\r")
	ln, _ :=strconv.Atoi(l)
	for i:=0; i<ln;i++{
		s,_:=a.ReadString('\n')
		las := strings.Split(strings.Trim(strings.Trim(s, "\n"), "\r")," ")
		n, _ :=strconv.Atoi(las[0])
		k, _ :=strconv.Atoi(las[1])
		str,_:=a.ReadString('\n')
		str = strings.Trim(strings.Trim(str, "\n"), "\r")
		mstr := make([]int64, n)
		mstra := strings.Split(str," ")
		for j:=0; j<n; j++{
			mstr[j], _ = strconv.ParseInt(mstra[j], 10, 64)
		}
		fmt.Printf("%d\n",fn(int64(k), mstr))
	}
}

func fn(k int64, a []int64) (res int64) {
	var B = make([]int64, len(a))
	B[0] = a[0]
	for i:=1; i<len(a); i++{
		B[i]=B[i-1]+a[i]
	}
	for i:=len(a)-1; i>0; i--{
		x:=(100*(B[i]-B[i-1]) - k*B[i-1])/k
		if x > 0{
			res+=x
			B[i-1]+=x
		}
	}
	return res
}

package main

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

func main() {
	a:=bufio.NewReader(os.Stdin)
	l, _ :=a.ReadString('\n')
	l=strings.Trim(strings.Trim(l,"\n"),"\r")
	ln, _ :=strconv.Atoi(l)
	for i:=0; i<ln;i++{
		s,_:=a.ReadString('\n')
		las := strings.Split(strings.Trim(strings.Trim(s, "\n"), "\r")," ")
		n, _ :=strconv.Atoi(las[0])
		k, _ :=strconv.Atoi(las[1])
		str,_:=a.ReadString('\n')
		str = strings.Trim(strings.Trim(str, "\n"), "\r")
		mstr := make([]int64, n)
		mstra := strings.Split(str," ")
		for j:=0; j<n; j++{
			mstr[j], _ = strconv.ParseInt(mstra[j], 10, 64)
		}
		fmt.Printf("%d\n",fn(int64(k), mstr))
	}
}

func fn(k int64, a []int64) (res int64) {
	sum := int64(a[0])
	for i := 1; i < len(a); i++{
		res = max(res, (100 * a[i] - k * sum + k - 1) / k)
		sum += a[i]
	}
	return sum
}

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

package main

import (
	"fmt"
)

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

func main() {
	var t int = 1
	fmt.Scan(&t)
	for ; t != 0; t-- {
		var n, k int
		fmt.Scan(&n, &k)
		p := make([]int, n)
		res, sum := 0, 0
		for i := 0; i < n; i++ {
			fmt.Scan(&p[i])
			if i > 0 {
				res += Max(0, (100*p[i]+k-1)/k-sum)
				p[0] += Max(0, (100*p[i]+k-1)/k-sum)
				sum += Max(0, (100*p[i]+k-1)/k-sum)
			}
			sum += p[i]
		}
		fmt.Println(res)
	}
}

package main

import (
	"fmt"
)

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

func main() {
	var t int
	fmt.Scan(&t)
	for ; t != 0; t-- {
		var n, k int
		fmt.Scan(&n, &k)
		p := make([]int, n)
		res, sum := 0, 0
		for i := 0; i < n; i++ {
			fmt.Scan(&p[i])
			if i > 0 {
				res += Max(0, (100*p[i]+k-1)/k-sum)
				p[0] += Max(0, (100*p[i]+k-1)/k-sum)
			}
			sum += p[i]
		}
		fmt.Println(res)
	}
}

package main

import (
	"fmt"
)

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

func main() {
	var t int
	fmt.Scan(&t)
	for ; t != 0; t-- {
		var n, k int
		fmt.Scan(&n, &k)
		p := make([]int, n)
		res, sum := 0, 0
		for i := 0; i < n; i++ {
			fmt.Scan(&p[i])
			if i > 0 {
				res += Max(0, (100*p[i]+k-1)/k-sum)
				p[0] += (k*p[i] - sum) / k
			}
			sum += p[i]
		}
		fmt.Println(res)
	}
}

package main

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

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		p := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &p[i])
		}
		currentPrice, fraud := p[0], 0
		for i := 1; i < n; i++ {
			if p[i]*100 > k*(currentPrice+fraud) {
				fraud += ceil(p[i]*100-k*(currentPrice+fraud), k)
			}
			//fmt.Println(p, float64(p[i])/float64(currentPrice+fraud)*100, currentPrice+fraud)
			currentPrice += p[i]
		}
		fmt.Println(fraud)
	}
}

package main

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

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		p := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &p[i])
		}
		currentPrice, fraud := p[0], 0
		for i := 1; i < n; i++ {
			if p[i]*100 > k*(currentPrice+fraud) {
				fraud = ceil(p[i]*100-k*currentPrice, k)
			}
			//fmt.Println(p, float64(p[i])/float64(currentPrice+fraud)*100, k, currentPrice+fraud)
			currentPrice += p[i]
		}
		fmt.Println(fraud)
	}
}

package main

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

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		p := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &p[i])
		}
		currentPrice, fraud := p[0], 0
		for i := 1; i < n; i++ {
			if p[i]*100 > k*(currentPrice+fraud) {
				fraud = ceil(p[i]*100-k*currentPrice, k)
			}
			fmt.Println(p, float64(p[i])/float64(currentPrice+fraud)*100, k, currentPrice+fraud)
			currentPrice += p[i]
		}
		fmt.Println(fraud)
	}
}

package main

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

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		p := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &p[i])
		}
		currentPrice, fraud := p[0], 0
		for i := 1; i < n; i++ {
			if p[i]*100 > k*currentPrice {
				delta := ceil(p[i]*100-k*currentPrice, k)
				currentPrice += delta
				fraud += delta
			}
			currentPrice += p[i]
		}
		fmt.Println(fraud)
	}
}

package main

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

/*
1
5 3
30 3 2 1 4
---

1. 3/30 <= 3/100 -> 3/100 <= 3/100
2. 2/103 <= 3/100
3. 1/105 <= 3/100
4. 4/106 <= 3/100

100 3 1
+70 0 0
*/

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

	p := make([]int, n)

	for i := range p {
		scanf("%d", &p[i])
	}
	scanf("\n")

	ans := int64(0)
	sum := int64(p[0])

	for i := int64(1); i < n; i++ {
		d := divCeil(100*int64(p[i])-k*sum, k)

		sum += int64(p[i])

		if d > 0 {
			sum += d
			ans += d
		}
	}

	fmt.Fprintln(writer, ans)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

	return nums[minNumIdx]
}

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

	return nums[maxNumIdx]
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

/*
1
5 3
30 3 2 1 4
---

1. 3/30 <= 3/100 -> 3/100 <= 3/100
2. 2/103 <= 3/100
3. 1/105 <= 3/100
4. 4/106 <= 3/100

100 3 1
+70 0 0
*/

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

	p := make([]int, n)

	for i := range p {
		scanf("%d", &p[i])
	}
	scanf("\n")

	ans := int64(0)
	sum := int64(p[0])

	for i := int64(1); i < n; i++ {
		d := divCeil(100*int64(p[i])-k*sum, k)

		sum += int64(p[i])

		if d > 0 {
			sum += d
			ans += d
		}
	}

	fmt.Fprintln(writer, ans)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

	return nums[minNumIdx]
}

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

	return nums[maxNumIdx]
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	t   int
	n   int
	k   int
)

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n, &k)

		p := make([]int, n)
		for i := range p {
			fmt.Fscan(in, &p[i])
		}

		fmt.Fprintln(out, solve3(p, k))

	}

}

func solve3(p []int, k int) int {

	sum := 0
	ans := 0

	for i := range p {

		//跳過p[0]
		if i != 0 {

			//不符合條件
			if sum*k < p[i]*100 {

				//暫存最小p[0]值
				temp := p[i] * 100 / k

				//p[i]無條件進位
				if p[i]*100%k != 0 {
					temp += 1
				}

				ans += temp - sum

				sum = temp

			}

		}

		sum += p[i]

	}

	return ans

}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	t   int
	n   int
	k   int
)

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n, &k)

		p := make([]int, n)
		for i := range p {
			fmt.Fscan(in, &p[i])
		}

		fmt.Fprintln(out, solve3(p, k))

	}

}

func solve3(p []int, k int) int {

	sum := 0
	ans := 0

	for i := range p {

		//跳過p[0]
		if i != 0 {

			//不符合條件
			if sum*k < p[i]*100 {

				//暫存最小p[0]值
				temp := p[i] * 100 / k

				//p[i]無條件進位
				if p[i]*100%k != 0 {
					temp += 1
				}

				ans += temp - sum

				sum = temp

			}

			sum += p[i]

		}

	}

	return ans

}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	t   int
	n   int
	k   int
)

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n, &k)

		p := make([]int, n)
		for i := range p {
			fmt.Fscan(in, &p[i])
		}

		fmt.Fprintln(out, solve2(p, k))

	}

}

func solve(p []int, k int) int {

	ans := 0

	for i := 1; i < len(p); i++ {

		ans = max(ans, (100*p[i]-k*p[0]+k-1)/k)
		p[0] += p[i]

	}

	return ans
}

func max(a int, b int) int {

	if a >= b {
		return a
	} else {
		return b
	}

}

func solve2(p []int, k int) int {

	sum := 0

	for i := len(p) - 1; i > 0; i-- {

		min := p[i] * 100 / k

		if i == 1 {
			if p[0] < min {
				sum += (min - p[0])
				p[0] = min
			}
		} else {
			if p[0]+p[i-1] < min {
				temp := min - p[0]
				sum += (temp - p[i-1])
				p[i-1] = temp
			}
		}

		//printIntArr(p)

	}

	return sum

}

//印出數字陣列
func printIntArr(array []int) {

	for i := range array {
		fmt.Printf("%d ", array[i])
	}

	fmt.Println()

}

package main

import (
	"bufio"
	"fmt"
	"os"
	//. "testgo/helpers"
)

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 main() {
	defer writer.Flush()
	//RedirectInputToFile(reader, "input.txt")
	t := 1
	scan(&t)

	for T := 0; T < t; T++ {
		var (
			n, k int64
		)
		scan(&n)
		scan(&k)

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

		solve(p, k)
	}
}

func solve(p []int64, k int64) {
	prefSumP := make([]int64, len(p))
	for i := range p {
		var prev int64
		if i > 0 {
			prev = prefSumP[i-1]
		}
		prefSumP[i] = prev + p[i]
	}

	ans := int64(0)
	for i := 1; i < len(p); i++ {
		v := 100*p[i] - k*prefSumP[i-1]
		if v > ans {
			ans = v
		}
	}
	printf("%v\n", ans)
}

package main

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

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

func main() {
	var t int
	fmt.Fscan(in, &t)

	for t > 0 {
		t--
		var n, k int
		fmt.Fscan(in, &n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		sum := a[0]
		ans := 0

		for i := 1; i < n; i++ {
			l, r := a[i]*100, sum*k
			if l > r {
				nextVal := (l + k - 1) / k
				ans += (nextVal - sum)
				sum = nextVal
			}
			sum += a[i]
		}
		fmt.Println(ans)
	}
}


Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he:   will buy exactly $$$n$$$ shovels in total;  the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages.

Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages.

NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels.

package main

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

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

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

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

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

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

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

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

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)

		fmt.Println(solve(n, k))
	}
}

func solve(n, k int) int {
	if k >= n {
		return 1
	}

	if n%k == 0 {
		return n / k
	}

	N, K := int64(n), int64(k)

	zz := int(math.Sqrt(float64(N)))
	ss := make([]int, 0, zz+1)

	for x := int64(1); x*x <= N; x++ {
		if N%x == 0 {
			y := N / x
			if y <= K {
				return int(x)
			}
			ss = append(ss, int(x))
			if x != y {
				ss = append(ss, int(y))
			}
		}
	}

	sort.Ints(ss)

	i := sort.SearchInts(ss, k)

	return n / ss[i-1]
}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

Next:
	for i := 0; i < t; i++ {
		n, k := s.NextInt(), s.NextInt()

		if k >= n {
			fmt.Println(1)
			continue
		}

		var max int
		for j := 1; j <= min(k, int(math.Sqrt(float64(n)))); j++ {
			if n%j == 0 {
				if n/j <= k {
					fmt.Println(j)
					continue Next
				}

				max = n / j
			}
		}

		fmt.Println(max)
	}
}

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

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

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

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

package main

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n,k:= reader.NextInt(),reader.NextInt()
		// aa := make([]int, n)
		// for i := 0; i < len(aa); i++ {
		// 	aa[i] = reader.NextInt()
		// }
		// sort.Ints(aa)
		getMaxDivisors(n,k)
	}
}

func getMaxDivisors(n int, k int) {
    // Vector to store half of the divisors
    v:=[]int{1}
    for i:=1; i<=int(math.Sqrt(float64(n)))+1; i++  {
        if (n%i==0)  {
            if (n/i == i){// check if divisors are equal
                // writer.Printf("%d ", i);
                v=append(v,n/i)
            }else {
                // writer.Printf("%d ", i);

                // push the second divisor in the vector
                v=append(v,n/i)
                v=append(v,i)

            }
        }
    }
    sort.Ints(v)
    // fmt.Println(v)
    ans:=-1
    for i:=0;i<len(v);i++{
    	if(v[i]>ans && v[i]<=k){
    		ans=v[i]
    	}
    }
    writer.Printf("%d \n", n/ans);
    // The vector will be printed in reverse
 }

func sol(aa []int) {
	numOdd:=0
	numEven:=0
	for i:=0;i<len(aa);i++{
		if(aa[i]%2==0){
			numEven++
		}else{
			numOdd++
		}
	}
	if(numOdd%2==0 && numEven%2==0){
		writer.Printf("YES \n")
		return
	}else{
		for i:=0;i<len(aa)-1;i++ {
		if(aa[i]+1==aa[i+1]){
			aa[i]=-1
			aa[i+1]=-1
			numEven--
			numOdd--
			if(numOdd%2==0 && numEven%2==0){
				writer.Printf("YES \n")
				return
			}
		}
	}
	writer.Printf("NO \n")
	}
	// fmt.Println(aa)

	// fmt.Println(numEven,numOdd)
	// if(numOdd%2==0 && numEven%2==0){
	// 	writer.Printf("YES \n")
	// }else{
	// 	writer.Printf("NO \n")
	// }

}

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

/*
URL:
https://codeforces.com/contest/1360/problem/D
*/

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, k int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, k = ReadInt2()
		solve(n, k)
	}
}

func solve(n, k int) {
	a := sub(n, k)
	fmt.Println(n / a)
}

func sub(n, k int) int {
	res := 1

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

	return res
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

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

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t, n, k int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		ans := n
		for i := 1; i <= k && i*i <= n; i++ {
			if n%i == 0 {
				if n/i < ans {
					ans = n / i
				}
				if n/i <= k && i < ans {
					ans = i
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	f := func(n, k int) int {
		if k >= n {
			return 1
		}
		ans := n
		for i := 2; i <= k && i*i <= n; i++ {
			if n%i == 0 {
				ans = min(ans, n/i)
				if n/i <= k {
					ans = min(ans, i)
				}
			}
		}
		return ans
	}
	var t, n, k int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		Fprintln(out, f(n, k))
	}
}

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

package main

import (
	"fmt"
)

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

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for tc := 0; tc < t; tc++ {
		var n, k int
		fmt.Scanf("%d %d\n", &n, &k)
		res := n
		for d := 1; d * d <= n; d++ {
		    if (n % d == 0) {
		        if (n / d <= k) {
		            res = min(res, d)
		        }
		        if (d <= k) {
		            res = min(res, n / d)
		        }
		    }
		}
		fmt.Println(res)
	}
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)
	for tt := rd(); tt > 0; tt-- {
		n, k := rd(), rd()
		ans := int(1e9)
		for ff := int64(1); ff*ff <= int64(n); ff++ {
			f := int(ff)
			if n%f == 0 {
				if f <= k {
					ans = min(ans, n/f)
				}
				if n/f <= k {
					ans = min(ans, f)
				}
			}
		}
		Fprintln(out, ans)
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}

package main

import (
	"fmt"
)

func main(){
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n, k int
		fmt.Scan(&n, &k)
		ans := n
		for i := 1; i*i <= n && i <= k; i++ {
			if n%i == 0 {
				v := n/i
				if v < ans {
					ans = v
				}
				if v <= k && i < ans {
					ans = i
				}

			}

		}
		fmt.Println(ans)

	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

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

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

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

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

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

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

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

func sol(n, k int64) int64 {
	if k >= n {
		return 1
	}
	ret := n
	for i := int64(2); i * i <= n && i <= k; i++ {
		if n % i == 0 {
			ret = min(ret, n/i)
			if n / i <= k {
				ret = min(ret, i)
			}
		}
	}
	return ret
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	f := func(n, k int) int {
		if k >= n {
			return 1
		}
		for i := 2; i <= k && i*i <= n; i++ {
			if n%i == 0 {
				return i
			}
		}
		return n
	}
	var t, n, k int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		Fprintln(out, f(n, k))
	}
}

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

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

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

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

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

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

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

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

var primes []bool
var primeNums []int64

func init() {
	primes = make([]bool, 1e6)
	for i := range primes {
		primes[i] = true
	}
	for i := range primes {
		if i == 0 || i == 1 {
			primes[i] = false
			continue
		}
		if primes[i] == false {
			continue
		}
		primeNums = append(primeNums, int64(i))
		nxt := i+i
		for nxt < len(primes) {
			primes[nxt] = false
			nxt += i
		}
	}
}

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

func sol(n, k int64) int64 {
	if k >= n {
		return 1
	}
	ret := n
	for _, p := range primeNums {
		if p > k {
			break
		}
		if n % p == 0 {
			ret = min(ret, n/p)
			if n / p <= k {
				ret = min(ret, p)
			}
		}
	}
	return ret
}


There are $$$n$$$ houses in a row. They are numbered from $$$1$$$ to $$$n$$$ in order from left to right. Initially you are in the house $$$1$$$.You have to perform $$$k$$$ moves to other house. In one move you go from your current house to some other house. You can't stay where you are (i.e., in each move the new house differs from the current house). If you go from the house $$$x$$$ to the house $$$y$$$, the total distance you walked increases by $$$|x-y|$$$ units of distance, where $$$|a|$$$ is the absolute value of $$$a$$$. It is possible to visit the same house multiple times (but you can't visit the same house in sequence).Your goal is to walk exactly $$$s$$$ units of distance in total.If it is impossible, print "NO". Otherwise print "YES" and any of the ways to do that. Remember that you should do exactly $$$k$$$ moves.

The first line of the input contains three integers $$$n$$$, $$$k$$$, $$$s$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le k \le 2 \cdot 10^5$$$, $$$1 \le s \le 10^{18}$$$) — the number of houses, the number of moves and the total distance you want to walk.

If you cannot perform $$$k$$$ moves with total walking distance equal to $$$s$$$, print "NO". Otherwise print "YES" on the first line and then print exactly $$$k$$$ integers $$$h_i$$$ ($$$1 \le h_i \le n$$$) on the second line, where $$$h_i$$$ is the house you visit on the $$$i$$$-th move. For each $$$j$$$ from $$$1$$$ to $$$k-1$$$ the following condition should be satisfied: $$$h_j \ne h_{j + 1}$$$. Also $$$h_1 \ne 1$$$ should be satisfied.

package main

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

func main()  {

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

	var n, k, s int64
	fmt.Fscan(in, &n, &k, &s)

	if (n - 1) * k < s || s < k {
		fmt.Fprintln(out, "NO")
		return
	}

	fmt.Fprintln(out, "YES")

	cnt := s / (n - 1)
	if s % (n - 1) > 0 {
		cnt++
	}

	for {
		if s - (cnt * (n - 1)) >= k - cnt {
			break
		}
		cnt--
	}

	pos := int64(1)
	for i := 0; i < int(cnt); i++ {
		if pos == 1 {
			pos = n
		} else {
			pos = 1
		}
		fmt.Fprint(out, pos, " ")
		s -= n - 1
	}

	if cnt != k {
		t := int64(1)
		if pos == 1 {
			pos += s - (k - cnt) + 1
		} else {
			pos -= s - (k - cnt) + 1
			t = -1
		}
		fmt.Fprint(out, pos, " ")
		for i := 0; i < int(k - cnt) - 1; i++ {
			pos += t
			fmt.Fprint(out, pos, " ")
			if pos == n || pos == 1 {
				t *= -1
			}
		}
	}

}

package main

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

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

	var n, leftStep, sum int64
	Scan(&n, &leftStep, &sum)

	if sum < leftStep || (n-1)*leftStep < sum {
		Print("NO")
		return
	}
	Println("YES")

	left := sum
	next := n
	for {
		if left-(n-1) >= leftStep {
			Fprintf(out, "%d ", next)
			if next == n {
				next = 1
			} else {
				next = n
			}

			left -= n - 1
			leftStep--
		} else {
			leftStep--

			if next == 1 {
				next = n - (left - leftStep)
				Fprintf(out, "%d ", next)

				d := int64(1)
				for leftStep > 0 {
					next += d
					Fprintf(out, "%d ", next)
					d = -d
					leftStep--
				}
			} else {
				next = 1 + left - leftStep

				Fprintf(out, "%d ", next)

				d := int64(-1)
				for leftStep > 0 {
					next += d
					Fprintf(out, "%d ", next)
					d = -d
					leftStep--
				}
			}

			break
		}
	}
}

package main

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

type music struct {
	a, b int64
}

func main()  {

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

	var n, k, s int64
	fmt.Fscan(in, &n, &k, &s)

	if (n - 1) * k < s || s < k {
		fmt.Fprintln(out, "NO")
		return
	}

	fmt.Fprintln(out, "YES")
	pos := true
	for i := 0; i < int(k); i++ {
		x := s / k
		if s % k >= int64(i) + 1 {
			x++
		}
		if x & 1 == 1 {
			pos = !pos
		}
		if pos {
			fmt.Fprint(out, 1, " ")
		} else {
			fmt.Fprint(out, 2, " ")
		}
	}

}

package main

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

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

	var n, leftStep, sum int64
	Scan(&n, &leftStep, &sum)

	if sum < leftStep || (n-1)*leftStep < sum {
		Print("NO")
		return
	}
	Println("YES")

	left := sum
	next := n
	for {
		if left-(n-1) >= leftStep {
			Fprintf(out, "%d ", next)
			if next == n {
				next = 1
			} else {
				next = n
			}

			left -= n - 1
			leftStep--
		} else {
			leftStep--

			if next == 1 {
				next = n - 1 - (left - leftStep)
				Fprintf(out, "%d ", next)

				d := int64(1)
				for leftStep > 0 {
					next += d
					Fprintf(out, "%d ", next)
					d = -d
					leftStep--
				}
			} else {
				next = 1 + left - leftStep
				Fprintf(out, "%d ", next)

				d := int64(-1)
				for leftStep > 0 {
					next += d
					Fprintf(out, "%d ", next)
					d = -d
					leftStep--
				}
			}

			break
		}

	}
}

package main

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

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

	var n, leftStep, sum int64
	Scan(&n, &leftStep, &sum)

	if sum < leftStep || (n-1)*leftStep < sum {
		Print("NO")
		return
	}
	Println("YES")

	left := sum
	next := n
	for {
		if left-(n-1) >= leftStep {
			Fprintf(out, "%d ", next)
			if next == n {
				next = 1
			} else {
				next = n
			}

			left -= n - 1
			leftStep--
		} else {
			leftStep--

			if next == 1 {
				next = n - 1 - (left - leftStep)
				if leftStep == 0 {
					next++
				}
				Fprintf(out, "%d ", next)

				d := int64(1)
				for leftStep > 0 {
					next += d
					Fprintf(out, "%d ", next)
					d = -d
					leftStep--
				}
			} else {
				next = left - leftStep
				if leftStep == 0 {
					next++
				}
				Fprintf(out, "%d ", next)

				d := int64(-1)
				for leftStep > 0 {
					next += d
					Fprintf(out, "%d ", next)
					d = -d
					leftStep--
				}
			}

			break
		}
	}
}

package main

import (
	. "fmt"
	"runtime"
	"strconv"
)

func main() {
	const PtrSize = 32 << uintptr(^uintptr(0)>>63)
	Println(runtime.GOOS, runtime.GOARCH)
	Println(strconv.IntSize, PtrSize)
}


Now that you have proposed a fake post for the HC2 Facebook page, Heidi wants to measure the quality of the post before actually posting it. She recently came across a (possibly fake) article about the impact of fractal structure on multimedia messages and she is now trying to measure the self-similarity of the message, which is defined aswhere the sum is over all nonempty strings p and  is the number of occurences of p in s as a substring. (Note that the sum is infinite, but it only has a finite number of nonzero summands.)Heidi refuses to do anything else until she knows how to calculate this self-similarity. Could you please help her? (If you would like to instead convince Heidi that a finite string cannot be a fractal anyway – do not bother, we have already tried.)

The input starts with a line indicating the number of test cases T (1 ≤ T ≤ 10). After that, T test cases follow, each of which consists of one line containing a string s (1 ≤ |s| ≤ 100 000) composed of lowercase letters (a-z).

Output T lines, every line containing one number – the answer to the corresponding test case.

NoteA string s contains another string p as a substring if p is a contiguous subsequence of s. For example, ab is a substring of cab but not of acb.

package main

import (
	"bufio"
	. "fmt"
	"index/suffixarray"
	"os"
	"reflect"
	"unsafe"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	var t int
	var s []byte
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &s)
		n := len(s)
		sa := *(*[]int32)(unsafe.Pointer(reflect.ValueOf(suffixarray.New(s)).Elem().FieldByName("sa").Field(0).UnsafeAddr()))
		rank := make([]int, n)
		for i := range rank {
			rank[sa[i]] = i
		}
		height := make([]int, n+1)
		h := 0
		for i, ri := range rank {
			if h > 0 {
				h--
			}
			if ri > 0 {
				for j := int(sa[ri-1]); i+h < n && j+h < n && s[i+h] == s[j+h]; h++ {
				}
			}
			height[ri] = h
		}

		type pair struct{ v, i int }
		pl := make([]int, n+1)
		st := []pair{{-1, 0}}
		for i, v := range height {
			for {
				if top := st[len(st)-1]; top.v < v {
					pl[i] = top.i
					break
				}
				st = st[:len(st)-1]
			}
			st = append(st, pair{v, i})
		}
		pr := make([]int, n+1)
		st = []pair{{-1, n}}
		for i := n - 1; i >= 0; i-- {
			v := height[i]
			for {
				if top := st[len(st)-1]; top.v < v {
					pr[i] = top.i
					break
				}
				st = st[:len(st)-1]
			}
			st = append(st, pair{v, i})
		}

		ans := int64(n) * int64(n+1) / 2
		usedSt := []int{0}
		for i, v := range height {
			for v < usedSt[len(usedSt)-1] {
				usedSt = usedSt[:len(usedSt)-1]
			}
			if v == usedSt[len(usedSt)-1] {
				continue
			}
			usedSt = append(usedSt, v)
			l, r := pl[i], pr[i]
			h, w := int64(v-max(height[l], height[r])), int64(r-l)
			ans += h * w * (w - 1)
		}
		Println(ans)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"index/suffixarray"
	"io"
	"os"
	"reflect"
	"unsafe"
)

// github.com/EndlessCheng/codeforces-go
func CF802I(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	var t int
	var s []byte
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &s)
		n := len(s)
		sa := *(*[]int32)(unsafe.Pointer(reflect.ValueOf(suffixarray.New(s)).Elem().FieldByName("sa").Field(0).UnsafeAddr()))
		rank := make([]int, n)
		for i := range rank {
			rank[sa[i]] = i
		}
		height := make([]int, n+1)
		h := 0
		for i, ri := range rank {
			if h > 0 {
				h--
			}
			if ri > 0 {
				for j := int(sa[ri-1]); i+h < n && j+h < n && s[i+h] == s[j+h]; h++ {
				}
			}
			height[ri] = h
		}

		type pair struct{ v, i int }
		pl := make([]int, n+1)
		st := []pair{{-1, 0}}
		for i, v := range height {
			for {
				if top := st[len(st)-1]; top.v < v {
					pl[i] = top.i
					break
				}
				st = st[:len(st)-1]
			}
			st = append(st, pair{v, i})
		}
		pr := make([]int, n+1)
		st = []pair{{-1, n}}
		for i := n - 1; i >= 0; i-- {
			v := height[i]
			for {
				if top := st[len(st)-1]; top.v < v {
					pr[i] = top.i
					break
				}
				st = st[:len(st)-1]
			}
			st = append(st, pair{v, i})
		}

		ans := int64(n) * int64(n+1) / 2
		usedSt := []int{0}
		for i, v := range height {
			for v < usedSt[len(usedSt)-1] {
				usedSt = usedSt[:len(usedSt)-1]
			}
			if v == usedSt[len(usedSt)-1] {
				continue
			}
			usedSt = append(usedSt, v)
			l, r := pl[i], pr[i]
			h, w := int64(v-max(height[l], height[r])), int64(r-l)
			ans += h * w * (w - 1)
		}
		Fprintln(out, ans)
	}
}

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


You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.You have to color this array in $$$k$$$ colors in such a way that:   Each element of the array should be colored in some color;  For each $$$i$$$ from $$$1$$$ to $$$k$$$ there should be at least one element colored in the $$$i$$$-th color in the array;  For each $$$i$$$ from $$$1$$$ to $$$k$$$ all elements colored in the $$$i$$$-th color should be distinct. Obviously, such coloring might be impossible. In this case, print "NO". Otherwise print "YES" and any coloring (i.e. numbers $$$c_1, c_2, \dots c_n$$$, where $$$1 \le c_i \le k$$$ and $$$c_i$$$ is the color of the $$$i$$$-th element of the given array) satisfying the conditions above. If there are multiple answers, you can print any.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the length of the array $$$a$$$ and the number of colors, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 5000$$$) — elements of the array $$$a$$$.

If there is no answer, print "NO". Otherwise print "YES" and any coloring (i.e. numbers $$$c_1, c_2, \dots c_n$$$, where $$$1 \le c_i \le k$$$ and $$$c_i$$$ is the color of the $$$i$$$-th element of the given array) satisfying the conditions described in the problem statement. If there are multiple answers, you can print any.

NoteIn the first example the answer $$$2~ 1~ 2~ 1$$$ is also acceptable.In the second example the answer $$$1~ 1~ 1~ 2~ 2$$$ is also acceptable.There exist other acceptable answers for both examples.

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, k int

	fmt.Fscanf(buf, "%d %d\n", &n, &k)
	cnt := make([]int, 5010)
	mat := make([]int, n+1)
	cc := make([]int,5010)
	var suc bool = true
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &mat[i])
		cnt[mat[i]]++
		if cnt[mat[i]] > k {
			suc = false
		}
	}
	if suc == false || k > n{
		fmt.Printf("NO\n")
	} else {
		fmt.Printf("YES\n")

		var cflag int = 1
		for i := 0; i < n; i++ {
			if cc[mat[i]] == 0{
				cc[mat[i]] = cflag
				cflag += cnt[mat[i]]
				if cflag > k{
					cflag = 1
				}
			}else {
				cc[mat[i]]++
				if cc[mat[i]] > k {
					cc[mat[i]] = 1
				}
			}
			if i > 0{
				fmt.Printf(" ")
			}
			fmt.Printf("%d", cc[mat[i]])
		}
		fmt.Printf("\n")
	}
}

package main

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

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)

	var n, k int
	var cnt, found = 1, 0
	fmt.Fscan(stdin, &n, &k)

	var a = make([]int, n)
	var res = make([]int, n)
	var mark = map[int][]bool{}
	valid := func(x int) int {
		for i := 0; i < k; i++ {
			if mark[x][i] == false {
				return i + 1
			}
		}
		return -1
	}

	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &a[i])
		if mark[a[i]] == nil {
			mark[a[i]] = make([]bool, k)
		}

		if cnt <= k {
			res[i] = cnt
			mark[a[i]][cnt-1] = true
			cnt++
		} else if found != -1 {
			found = valid(a[i])
			if found == -1 {
				continue
			} else {
				res[i] = found
				mark[a[i]][found-1] = true
			}
		}
	}
	// fmt.Println(mark)

	if found == -1 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		for i := 0; i < n; i++ {
			fmt.Print(res[i], " ")
		}
		fmt.Println()
	}
}

package main

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

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

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

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

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

type ii struct {
	chave, qt int
}

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

    n := ReadInt()
    k := ReadInt()

    v := make([]int, n)

    mapa := make(map[int]int)
    mapa2 := make(map[int]int)

    maior := 0

    for i := 0; i < n; i++ {
    	v[i] = ReadInt()
    	mapa[v[i]]++
    	maior = max(mapa[v[i]], maior)
    }

    ordenado := make([]ii, 0)

    for key,qt := range mapa {
    	ordenado = append(ordenado, ii{key,qt})
	}

	sort.Slice(ordenado, func (i, j int) bool {
		return ordenado[i].qt > ordenado[j].qt
		})

	ultimo := 1

	for _, elem := range ordenado {
		mapa2[elem.chave] = min(ultimo, k - elem.qt + 1)
		ultimo = max(ultimo, mapa2[elem.chave] + elem.qt)
		// fmt.Println(elem, mapa2[elem.chave], ultimo)
	}

	resp := make([]int, n)

	for i, elem := range v {
		resp[i] = mapa2[elem]
    	mapa2[elem]++
    }

    mapaResp := make(map[int]bool)

    for _, elem := range resp {
    	mapaResp[elem] = true
    }

    if len(mapaResp) != k {
    	writer.WriteString("NO")
    	return
    }

	writer.WriteString("YES")
	writer.WriteString("\n")

    for _, elem := range resp {
    	writer.WriteString( strconv.Itoa(elem))
    	writer.WriteString(" ")
    }
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

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

func scanBytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

func scanInt64() int64 {
	scanner.Scan()
	v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return v
}

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

func scanInts(n int) []int {
	l := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		l[i], _ = strconv.Atoi(scanner.Text())
	}

	return l
}

func scanInts64(n int64) []int64 {
	l := make([]int64, n)
	for i := int64(0); i < n; i++ {
		scanner.Scan()
		l[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}

	return l
}

func scanBool() bool {
	scanner.Scan()
	v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return v == 1
}

func scanBools(n int64) []bool {
	l := make([]bool, n)
	for i := int64(0); i < n; i++ {
		scanner.Scan()
		v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		l[i] = v == 1
	}

	return l
}

func scanUint64() uint64 {
	scanner.Scan()
	v, _ := strconv.ParseUint(scanner.Text(), 10, 64)
	return v
}

type ByAge []uint64

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

func main() {
	n, k := scanInt(), scanInt()

	a := make([]int, n)
	cnt := make([]int, 5001)
	used := make([][]bool, 5001)

	for i := 0; i < n; i++ {
		scanner.Scan()
		val, _ := strconv.Atoi(scanner.Text())

		a[i] = val
		cnt[val]++

		used[val] = make([]bool, k+1)

		if cnt[val] > k {
			fmt.Println("NO")
			return
		}
	}

	if k > n {
		fmt.Println("NO")
		return
	}

	c := make([]int, n)
	for i := 0; i < k; i++ {
		c[i] = i + 1

		val := a[i]
		used[val][i+1] = true
	}

	use := func(val int) int {
		for i := 1; i <= k; i++ {
			if !used[val][i] {
				used[val][i] = true
				return i
			}
		}

		return -1
	}

	for i := k; i < n; i++ {
		c[i] = use(a[i])
	}

	fmt.Println("YES")

	for i := 0; i < n; i++ {
		fmt.Println(c[i])
	}
}

func skipZero(a []uint64) []uint64 {
	for len(a) > 0 && a[0] == 0 {
		a = a[1:]
	}

	return a
}

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

	return -a
}

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

	return b
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, k int

	fmt.Fscanf(buf, "%d %d\n", &n, &k)
	cnt := make([]int, 5010)
	mat := make([]int, n+1)
	cc := make([]int,5010)
	var suc bool = true
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &mat[i])
		cnt[mat[i]]++
		if cnt[mat[i]] > k {
			suc = false
		}
	}
	if suc == false || k > n{
		fmt.Printf("NO\n")
	} else {
		fmt.Printf("YES\n")
		for i := 0; i < k; i++ {
			if i > 0{
				fmt.Printf(" ")
			}
			fmt.Printf("%d", i+1)
			cc[mat[i]] = i+1
		}
		for i := k; i < n; i++ {
			fmt.Printf(" ")
			cc[mat[i]]++
			if cc[mat[i]] > k{
				cc[mat[i]] = 1
			}
			fmt.Printf("%d", cc[mat[i]])
		}
		fmt.Printf("\n")
	}
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, k int

	fmt.Fscanf(buf, "%d %d\n", &n, &k)
	cnt := make([]int, 5000+1)
	mat := make([]int, n+1)
	cc := make([]int,5001)
	var suc bool = true
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &mat[i])
		cnt[mat[i]]++
		if cnt[mat[i]] > k {
			suc = false
		}
	}
	if suc == false {
		fmt.Printf("NO\n")
	} else {
		fmt.Printf("YES\n")
		for i := 0; i < k; i++ {
			if i > 0{
				fmt.Printf(" ")
			}
			fmt.Printf("%d", i+1)
			cc[mat[i]] = i+1
		}
		for i := k; i < n; i++ {
			fmt.Printf(" ")
			cc[mat[i]]++
			if cc[mat[i]] > k{
				cc[mat[i]] = 1
			}
			fmt.Printf("%d", cc[mat[i]])
		}
		fmt.Printf("\n")
	}
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, k int

	fmt.Fscanf(buf, "%d %d\n", &n, &k)
	cnt := make([]int, 5000+1)
	mat := make([]int, n+1)
	col := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &mat[i])
	}
	var suc bool = true
	for i := 0; suc && i < n; i++ {
		cnt[mat[i]]++
		if cnt[mat[i]] > k {
			suc = false
			break
		}
		col[i] = cnt[mat[i]]
	}
	if suc == false {
		fmt.Printf("NO\n")
	} else {
		fmt.Printf("YES\n")
		for i := 0; i < n; i++ {
			if i > 0{
				fmt.Printf(" ")
			}
			fmt.Printf("%d", col[i])
		}
		fmt.Printf("\n")
	}
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, k int

	fmt.Fscanf(buf, "%d %d\n", &n, &k)
	cnt := make([]int, 5000+1)
	mat := make([]int, n+1)
	cc := make([]int,5001)
	var suc bool = true
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &mat[i])
		cnt[mat[i]]++
		if cnt[mat[i]] > k {
			suc = false
			break
		}
	}
	if suc == false {
		fmt.Printf("NO\n")
	} else {
		fmt.Printf("YES\n")
		for i := 0; i < k; i++ {
			if i > 0{
				fmt.Printf(" ")
			}
			fmt.Printf("%d", i+1)
			cc[mat[i]] = i+1
		}
		for i := k; i < n; i++ {
			fmt.Printf(" ")
			cc[mat[i]]++
			if cc[mat[i]] > k{
				cc[mat[i]] = 1
			}
			fmt.Printf("%d", cc[mat[i]])
		}
		fmt.Printf("\n")
	}
}

package main

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

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)

	var n, k int
	fmt.Fscan(stdin, &n, &k)

	var a = make([]int, n)
	var res = make([]int, n)
	var mark = make([]int, n+10)
	var flag = true
	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &a[i])
		if mark[a[i]] == 0 {
			mark[a[i]] = 1
		} else {
			mark[a[i]]++
		}
		res[i] = mark[a[i]]
		if res[i] > k {
			flag = false
		}
	}

	if flag == true {
		fmt.Println("YES")
		for i := 0; i < n; i++ {
			fmt.Print(res[i], " ")
		}
		fmt.Println()
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

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

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

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

    n := ReadInt()
    k := ReadInt()

    v := make([]int, n)

    mapa := make(map[int]int)
    mapa2 := make(map[int]int)

    maior := 0

    for i := 0; i < n; i++ {
    	v[i] = ReadInt()
    	mapa[v[i]]++
    	maior = max(mapa[v[i]], maior)
    }

    if maior > k {
    	writer.WriteString("NO")
    	return
    }

	writer.WriteString("YES")
	writer.WriteString("\n")

    for _, elem := range v {
    	writer.WriteString( strconv.Itoa(mapa2[elem]+1))
    	mapa2[elem]++
    	writer.WriteString(" ")
    }
}