Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than $$$k$$$ other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.Now each knight ponders: how many coins he can have if only he kills other knights?You should answer this question for each knight.

The first line contains two integers $$$n$$$ and $$$k$$$ $$$(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$$$ — the number of knights and the number $$$k$$$ from the statement. The second line contains $$$n$$$ integers $$$p_1, p_2 ,\ldots,p_n$$$ $$$(1 \le p_i \le 10^9)$$$ — powers of the knights. All $$$p_i$$$ are distinct. The third line contains $$$n$$$ integers $$$c_1, c_2 ,\ldots,c_n$$$ $$$(0 \le c_i \le 10^9)$$$ — the number of coins each knight has.

Print $$$n$$$ integers — the maximum number of coins each knight can have it only he kills other knights.

NoteConsider the first example.   The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has.  The second knight can kill the first knight and add his coin to his own two.  The third knight is the strongest, but he can't kill more than $$$k = 2$$$ other knights. It is optimal to kill the second and the fourth knights: $$$2+11+33 = 46$$$.  The fourth knight should kill the first and the second knights: $$$33+1+2 = 36$$$. In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.In the third example there is only one knight, so he can't kill anyone.

package main

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

type knight struct {
	pow, coin int
}

type kheap []knight

func (h *kheap) Len() int           { return len(*h) }
func (h *kheap) Less(i, j int) bool { return (*h)[i].coin < (*h)[j].coin }
func (h *kheap) Swap(i, j int) {
	(*h)[i], (*h)[j] = (*h)[j], (*h)[i]
}
func (h *kheap) Push(x interface{}) {
	*h = append(*h, x.(knight))
}
func (h *kheap) Pop() interface{} {
	out := (*h)[h.Len()-1]
	*h = (*h)[:h.Len()-1]
	return out
}

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

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

	knights := make([]knight, n)
	for i := range knights {
		fmt.Fscan(in, &knights[i].pow)
	}
	for i := range knights {
		fmt.Fscan(in, &knights[i].coin)
	}

	byp := make([]int, n)
	for i := range byp {
		byp[i] = i
	}
	sort.Slice(byp, func(i, j int) bool {
		return knights[byp[i]].pow < knights[byp[j]].pow
	})

	h := new(kheap)
	heap.Init(h)

	ans := make([]int64, n)

	var sum int64
	for _, kn := range byp {
		sum += int64(knights[kn].coin)
		ans[kn] = sum

		heap.Push(h, knights[kn])
		if h.Len() > k {
			del := heap.Pop(h).(knight)
			sum -= int64(del.coin)
		}
	}

	for _, v := range ans {
		fmt.Print(v, " ")
	}
	fmt.Println()
}

package main

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

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

type Int64Slice []int64

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

var cntv [20]int64
var cntvcnt int
var k int

func addv(v int64) int64 {
	for i := 0; i < k; i++ {
		if v > cntv[i] {
			for j := k - 1; j > i; j-- {
				cntv[j] = cntv[j-1]
			}
			cntv[i] = v
			break
		}
		if cntvcnt < k {
			cntvcnt++
		}
	}
	ret := int64(0)
	for i := 0; i < k; i++ {
		ret = ret + cntv[i]
	}
	return ret
}

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

	// > kill
	// <= k other
	// pickup coin
	n := ReadInt32()
	k = ReadInt32()

	p := make([]int64, n)
	sp := make([]int64, n)
	ans := make([]int64, n)
	for i := 0; i < n; i++ {
		p[i] = ReadInt64()
		sp[i] = p[i]
	}
	c := make([]int64, n)
	for i := 0; i < n; i++ {
		c[i] = ReadInt64()
	}
	sort.Sort(Int64Slice(sp))

	v2index := make(map[int64]int)
	for i := 0; i < n; i++ {
		v2index[p[i]] = i
	}

	anslast := int64(0)
	for i := 0; i < n; i++ {
		ans[v2index[sp[i]]] = anslast + c[v2index[sp[i]]]
		anslast = addv(c[v2index[sp[i]]])
	}

	for i := 0; i < n; i++ {
		fmt.Printf("%v ", ans[i])
	}
	fmt.Printf("\n")
}

func Demo() {
	var n, m int64 = ReadInt64(), ReadInt64()
	PrintInt64s(n, m)
	writer.WriteByte('\n')
	slice := []int64{1, 2, 3, 4, 5}
	PrintInt64s(slice...)

	// sortDemo
	//slice := []int64{5, 3, 4, 2, 1}
	sort.Sort(Int64Slice(slice))

	//s := strconv.FormatBool(true)
	//s := strconv.FormatFloat(3.1415, 'E', -1, 64)
	//s := strconv.FormatInt(-42, 16)
	//s := strconv.FormatUint(42, 16)

}

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

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

func MinFloat64(a float64, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func MaxFloat64(a float64, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func ReadFloat64() float64 {
	scanner.Scan()
	ans, _ := strconv.ParseFloat(scanner.Text(), 64)
	return ans
}

func PrintInt64s(ints ...int64) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(int(value)))
		writer.WriteByte(' ')
	}
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextInt64Array()
	c := sc.NextInt64Array()

	A := make(SortInterFace, N)
	for i := 0; i < N; i++ {
		A[i].index = int64(i)
		A[i].v = p[i]
	}
	sort.Sort(A)

	ans := make([]int64, N)
	buf := make([]int, K)
	num := int64(A[0].v)
	nextBuf := make([]int64, K)
	for i := 0; i < N; i++ {
		s := int64(0)

		if num != A[i].v {
			num = A[i].v
			for _, vv := range nextBuf {
				buf = append(buf, int(vv))
			}
			sort.Ints(buf)
			buf = buf[len(buf)-K:]
			nextBuf = make([]int64, K)
		}

		for _, vv := range buf {
			s += int64(vv)
		}

		ans[A[i].index] = int64(s) + c[A[i].index]

		nextBuf = append(nextBuf, c[A[i].index])

	}
	PrintI64(ans...)

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

func mapInt64ToString(arr []int64) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.FormatInt(arr[i], 10)
	}
	return ret
}
func PrintI64(args ...int64) {
	fmt.Println(strings.Join(mapInt64ToString(args), " "))
}

type tuple struct {
	v     int64
	index int64
}
type SortInterFace []tuple

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].v < s[j].v
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

type knight struct {
	pow, coin int
}

type kheap []knight

func (h *kheap) Len() int           { return len(*h) }
func (h *kheap) Less(i, j int) bool { return (*h)[i].coin < (*h)[j].coin }
func (h *kheap) Swap(i, j int) {
	(*h)[i], (*h)[j] = (*h)[j], (*h)[i]
}
func (h *kheap) Push(x interface{}) {
	*h = append(*h, x.(knight))
}
func (h *kheap) Pop() interface{} {
	out := (*h)[0]
	*h = (*h)[1:]
	return out
}

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

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

	knights := make([]knight, n)
	for i := range knights {
		fmt.Fscan(in, &knights[i].pow)
	}
	for i := range knights {
		fmt.Fscan(in, &knights[i].coin)
	}

	byp := make([]int, n)
	for i := range byp {
		byp[i] = i
	}
	sort.Slice(byp, func(i, j int) bool {
		return knights[byp[i]].pow < knights[byp[j]].pow
	})

	h := new(kheap)
	heap.Init(h)

	var sum int64
	for _, kn := range knights {
		sum += int64(kn.coin)
		fmt.Printf("%d ", sum)

		h.Push(kn)
		if h.Len() > k {
			sum -= int64(h.Pop().(knight).coin)
		}
	}
	fmt.Println()
}

package main

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

type knight struct {
	pow, coin int
}

type kheap []knight

func (h *kheap) Len() int           { return len(*h) }
func (h *kheap) Less(i, j int) bool { return (*h)[i].coin < (*h)[j].coin }
func (h *kheap) Swap(i, j int) {
	(*h)[i], (*h)[j] = (*h)[j], (*h)[i]
}
func (h *kheap) Push(x interface{}) {
	*h = append(*h, x.(knight))
}
func (h *kheap) Pop() interface{} {
	out := (*h)[0]
	*h = (*h)[1:]
	return out
}

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

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

	knights := make([]knight, n)
	for i := range knights {
		fmt.Fscan(in, &knights[i].pow)
	}
	for i := range knights {
		fmt.Fscan(in, &knights[i].coin)
	}

	byp := make([]int, n)
	for i := range byp {
		byp[i] = i
	}
	sort.Slice(byp, func(i, j int) bool {
		return knights[byp[i]].pow < knights[byp[j]].pow
	})

	h := new(kheap)
	heap.Init(h)

	ans := make([]int64, n)

	var sum int64
	for _, kn := range byp {
		sum += int64(knights[kn].coin)
		ans[kn] = sum

		heap.Push(h, knights[kn])
		if h.Len() > k {
			sum -= int64(heap.Pop(h).(knight).coin)
		}
	}

	for _, v := range ans {
		fmt.Print(v, " ")
	}
	fmt.Println()
}

package main

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

type knight struct {
	pow, coin int
}

type kheap []knight

func (h *kheap) Len() int           { return len(*h) }
func (h *kheap) Less(i, j int) bool { return (*h)[i].coin < (*h)[j].coin }
func (h *kheap) Swap(i, j int) {
	(*h)[i], (*h)[j] = (*h)[j], (*h)[i]
}
func (h *kheap) Push(x interface{}) {
	*h = append(*h, x.(knight))
}
func (h *kheap) Pop() interface{} {
	out := (*h)[0]
	*h = (*h)[1:]
	return out
}

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

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

	knights := make([]knight, n)
	for i := range knights {
		fmt.Fscan(in, &knights[i].pow)
	}
	for i := range knights {
		fmt.Fscan(in, &knights[i].coin)
	}

	byp := make([]int, n)
	for i := range byp {
		byp[i] = i
	}
	sort.Slice(byp, func(i, j int) bool {
		return knights[byp[i]].pow < knights[byp[j]].pow
	})

	h := new(kheap)
	heap.Init(h)

	ans := make([]int64, n)

	var sum int64
	for _, kn := range byp {
		sum += int64(knights[kn].coin)
		ans[kn] = sum

		h.Push(knights[kn])
		if h.Len() > k {
			sum -= int64(h.Pop().(knight).coin)
		}
	}

	for _, v := range ans {
		fmt.Print(v, " ")
	}
	fmt.Println()
}

package main

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

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

type Int64Slice []int64

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

var cntv [20]int64
var cntvcnt int
var k int

func addv(v int64) int64 {
	for i := 0; i < k; i++ {
		if v > cntv[i] {
			for j := k - 1; j > i; j-- {
				cntv[j] = cntv[j-1]
			}
			cntv[i] = v
			break
		}
		if cntvcnt < k {
			cntvcnt++
		}
	}
	ret := int64(0)
	for i := 0; i < k; i++ {
		ret = ret + cntv[i]
	}
	return ret
}

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

	// > kill
	// <= k other
	// pickup coin
	n := ReadInt32()
  k = ReadInt32()
  k++

	p := make([]int64, n)
	sp := make([]int64, n)
	ans := make([]int64, n)
	for i := 0; i < n; i++ {
		p[i] = ReadInt64()
		sp[i] = p[i]
	}
	c := make([]int64, n)
	for i := 0; i < n; i++ {
		c[i] = ReadInt64()
	}
	sort.Sort(Int64Slice(sp))

	v2index := make(map[int64]int)
	for i := 0; i < n; i++ {
		v2index[p[i]] = i
	}

	for i := 0; i < n; i++ {
		ans[v2index[sp[i]]] = addv(c[v2index[sp[i]]])
	}

	for i := 0; i < n; i++ {
		fmt.Printf("%v ", ans[i])
	}
	fmt.Printf("\n")
}

func Demo() {
	var n, m int64 = ReadInt64(), ReadInt64()
	PrintInt64s(n, m)
	writer.WriteByte('\n')
	slice := []int64{1, 2, 3, 4, 5}
	PrintInt64s(slice...)

	// sortDemo
	//slice := []int64{5, 3, 4, 2, 1}
	sort.Sort(Int64Slice(slice))

	//s := strconv.FormatBool(true)
	//s := strconv.FormatFloat(3.1415, 'E', -1, 64)
	//s := strconv.FormatInt(-42, 16)
	//s := strconv.FormatUint(42, 16)

}

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

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

func MinFloat64(a float64, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func MaxFloat64(a float64, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func ReadFloat64() float64 {
	scanner.Scan()
	ans, _ := strconv.ParseFloat(scanner.Text(), 64)
	return ans
}

func PrintInt64s(ints ...int64) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(int(value)))
		writer.WriteByte(' ')
	}
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextInt64Array()
	c := sc.NextInt64Array()

	A := make(SortInterFace, N)
	for i := 0; i < N; i++ {
		A[i].index = int64(i)
		A[i].v = p[i]
	}
	sort.Sort(A)

	ans := make([]int64, N)
	for i := 0; i < N; i++ {
		s := int64(0)
		y := 1
		for f := 0; f < K && i-y >= 0; f++ {
			if A[i].v == A[i-y].v {
				f--
			} else {
				s += c[A[i-y].index]
			}
			y++
		}
		ans[A[i].index] = s + c[A[i].index]
	}
	PrintI64(ans...)

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

func mapInt64ToString(arr []int64) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.FormatInt(arr[i], 10)
	}
	return ret
}
func PrintI64(args ...int64) {
	fmt.Println(strings.Join(mapInt64ToString(args), " "))
}

type tuple struct {
	v     int64
	index int64
}
type SortInterFace []tuple

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].v < s[j].v
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextInt64Array()
	c := sc.NextInt64Array()

	A := make(SortInterFace, N)
	for i := 0; i < N; i++ {
		A[i].index = int64(i)
		A[i].v = p[i]
	}
	sort.Sort(A)

	ans := make([]int64, N)
	buf := make([]int, K)
	num := int64(A[0].v)
	nextBuf := make([]int64, K)
	for i := 0; i < N; i++ {
		s := int64(0)

		if num != A[i].v {
			num = A[i].v
			for _, vv := range nextBuf {
				buf = append(buf, int(vv))
			}
			sort.Ints(buf)
			buf = buf[len(buf)-K:]
		}

		for _, vv := range buf {
			s += int64(vv)
		}

		ans[A[i].index] = int64(s) + c[A[i].index]

		nextBuf = append(nextBuf, c[A[i].index])

	}
	PrintI64(ans...)

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

func mapInt64ToString(arr []int64) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.FormatInt(arr[i], 10)
	}
	return ret
}
func PrintI64(args ...int64) {
	fmt.Println(strings.Join(mapInt64ToString(args), " "))
}

type tuple struct {
	v     int64
	index int64
}
type SortInterFace []tuple

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].v < s[j].v
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextInt64Array()
	c := sc.NextInt64Array()

	A := make(SortInterFace, N)
	for i := 0; i < N; i++ {
		A[i].index = int64(i)
		A[i].v = p[i]
	}
	sort.Sort(A)

	ans := make([]int64, N)
	buf := make([]int, K)
	num := int64(0)
	nextBuf := make([]int64, K)
	for i := 0; i < N; i++ {
		s := int64(0)

		for _, vv := range buf {
			s += int64(vv)
		}

		ans[A[i].index] = int64(s) + c[A[i].index]

		nextBuf = append(nextBuf, c[A[i].index])

		if num != A[i].v {
			num = A[i].v
			for _, vv := range nextBuf {
				buf = append(buf, int(vv))
			}
			sort.Ints(buf)
			buf = buf[len(buf)-K:]
		}
	}
	PrintI64(ans...)

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

func mapInt64ToString(arr []int64) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.FormatInt(arr[i], 10)
	}
	return ret
}
func PrintI64(args ...int64) {
	fmt.Println(strings.Join(mapInt64ToString(args), " "))
}

type tuple struct {
	v     int64
	index int64
}
type SortInterFace []tuple

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].v < s[j].v
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextInt64Array()
	c := sc.NextInt64Array()

	A := make(SortInterFace, N)
	for i := 0; i < N; i++ {
		A[i].index = int64(i)
		A[i].v = p[i]
	}
	sort.Sort(A)

	ans := make([]int64, N)
	for i := 0; i < N; i++ {
		s := int64(0)
		for j := i - 1; j >= max(0, i-K); j-- {
			s += c[A[j].index]
		}
		ans[A[i].index] = s + c[A[i].index]
	}
	PrintI64(ans...)

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

func mapInt64ToString(arr []int64) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.FormatInt(arr[i], 10)
	}
	return ret
}
func PrintI64(args ...int64) {
	fmt.Println(strings.Join(mapInt64ToString(args), " "))
}

type tuple struct {
	v     int64
	index int64
}
type SortInterFace []tuple

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].v < s[j].v
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextInt64Array()
	c := sc.NextInt64Array()

	A := make(SortInterFace, N)
	for i := 0; i < N; i++ {
		A[i].index = int64(i)
		A[i].v = p[i]
	}
	sort.Sort(A)

	ans := make([]int64, N)
	for i := 0; i < N; i++ {
		s := int64(0)
		for j := i - 1; j >= max(0, i-K); j-- {
			s += c[A[j].index]
		}
		ans[A[i].index] = s + c[A[i].index]
	}
	PrintI(ans...)

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

func mapToString(arr []int64) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(int(arr[i]))
	}
	return ret
}
func PrintI(args ...int64) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

type tuple struct {
	v     int64
	index int64
}
type SortInterFace []tuple

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].v < s[j].v
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextIntArray()
	c := sc.NextIntArray()

	A := make(SortInterFace, N)
	for i := 0; i < N; i++ {
		A[i].index = i
		A[i].v = p[i]
	}
	sort.Sort(A)

	ans := make([]int, N)
	for i := 0; i < N; i++ {
		s := 0
		for j := i - 1; j >= max(0, i-K); j-- {
			s += c[A[j].index]
		}
		ans[A[i].index] = s + c[A[i].index]
	}
	PrintI(ans...)

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

func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

type tuple struct {
	v     int
	index int
}
type SortInterFace []tuple

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].v < s[j].v
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextInt64Array()
	c := sc.NextInt64Array()

	A := make(SortInterFace, N)
	for i := 0; i < N; i++ {
		A[i].index = int64(i)
		A[i].v = p[i]
	}
	sort.Sort(A)

	ans := make([]int64, N)
	buf := make([]int, K)
	num := int64(A[0].v)
	nextBuf := make([]int64, K)
	for i := 0; i < N; i++ {
		s := int64(0)

		for _, vv := range buf {
			s += int64(vv)
		}

		ans[A[i].index] = int64(s) + c[A[i].index]

		nextBuf = append(nextBuf, c[A[i].index])

		if num != A[i].v {
			num = A[i].v
			for _, vv := range nextBuf {
				buf = append(buf, int(vv))
			}
			sort.Ints(buf)
			buf = buf[len(buf)-K:]
		}
	}
	PrintI64(ans...)

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

func mapInt64ToString(arr []int64) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.FormatInt(arr[i], 10)
	}
	return ret
}
func PrintI64(args ...int64) {
	fmt.Println(strings.Join(mapInt64ToString(args), " "))
}

type tuple struct {
	v     int64
	index int64
}
type SortInterFace []tuple

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].v < s[j].v
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array:  The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers.  The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$.  If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively.

For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints.

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var x,y, n int
		Fscan(in, &n, &x, &y);
		d,dm := y-x,x
		for df:=1;df<=y-x;df++{
			if (y-x)%df != 0{
				continue
			}
			k:=(y-x)/df+1
			if k>n{
				continue
			}
			k=n-k
			if (x-1)/df < k{
				mn:=x%df
				if mn==0{
					mn=df
				}

				if mn+(n-1)*df < dm+(n-1)*d{
					d=df
					dm=mn
				}
			} else {
				if y < dm+(n-1)*d{
					d=df
					dm=y-(n-1)*df
				}
			}
		}
		for i:=0;i<n;i++{
			Fprint(out,dm+i*d," ")
		}
		Fprintln(out,"")
	}
}

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

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		n, x, y := io.NextInt(), io.NextInt(), io.NextInt()

		ans, step := 0, 0
		for gap := n - 1; gap >= 1; gap-- {
			d := y - x
			if d%gap != 0 {
				continue
			}
			step = d / gap
			total := step * (n - 1)
			if y > total {
				ans = y
			} else {
				ans = total + 1
				ans += ((y-ans)%step + step) % step
			}
			break
		}

		a := make([]int, n)
		for i := range a {
			a[i] = ans - i*step
		}
		io.PrintlnInts(a...)
	}
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

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

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

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

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

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

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

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

package main

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

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

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

	for t := in(); t > 0; t-- {
		n, x, y := in(), in(), in()
		d := y-x
		r := n-1
		for r > 0 {
			if d%r == 0 {
				break
			}
			r--
		}

		r = d/r

		c := y
		sgn := false
		for i := 0; i < n ; i++ {
			fmt.Print(c, " ")

			if sgn == false {
				c -= r
			} else {
				c += r
			}

			if c <= 0 {
				c = y + r
				sgn = true
			}
		}

		fmt.Println()
	}
}

package main

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

func main(){
	var (
		t,n,x,y,ymx,p int
	)
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i:=1;i<=t;i++ {
		fmt.Fscan(in, &n, &x, &y)
		n--
		if n==1{
			fmt.Println(x,y)
		}else if n>1{
			ymx = y-x
			if ymx%n==0{
				p=ymx/n
				for y>x{
					fmt.Print(y," ")
					y-=p
				}
				fmt.Print(x)
			}else{
				n--
				for j:=n;j>0;j--{
					if ymx%(j)==0{
						p=ymx/j
						j=1
					}
				}
				n+=2
				tmp:=y
				for tmp>0 && n>0{
					fmt.Print(tmp," ")
					tmp-=p
					n--
				}
				for n>0{
					y+=p
					n--
					fmt.Print(y," ")
				}
			}
			fmt.Println()
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T, n, x, y int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &x, &y)
		for d := 1; ; d++ {
			if (y-x)%d == 0 && (y-x)/d < n {
				for v := y; v > 0 && n > 0; v -= d {
					Fprint(out, v, " ")
					n--
				}
				for v := y + d; n > 0; v += d {
					Fprint(out, v, " ")
					n--
				}
				break
			}
		}
		Fprintln(out)
	}
}

package main

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

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, x, y int
		fmt.Fscan(input, &n, &x, &y)
		var arr []int

		arr = append(arr, x)
		arr = append(arr, y)

		var fl int
		for i := 1; i < 51; i++ {
			for j := 1; j < 51; j++ {
				p := x + (i * j)
				if p == y && (j-1) <= (n-2) {
					fl = i
					break
				}
			}
			if fl > 0 {
				break
			}
		}

		l := 2
		if l < n {
			for i := x + fl; i < y; i += fl {
				arr = append(arr, i)
				l++
				if l == n {
					break
				}
			}
		}

		if l < n {
			for i := x - fl; i > 0; i -= fl {
				arr = append(arr, i)
				l++
				if l == n {
					break
				}
			}
		}

		if l < n {
			for i := y + fl; true; i += fl {
				arr = append(arr, i)
				l++
				if l == n {
					break
				}
			}
		}

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

		fmt.Println()
	}
}

package main

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

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

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

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

func solve() {
	var n, x, y int
	scanf("%d %d %d\n", &n, &x, &y)
	d := y - x
	md, m := 1000000, 1000000
	for i := 1; i <= d; i++ {
		if d % i > 0 {
			continue
		}
		b := y - (n-1)*i
		if b > x {
			continue
		}
		for b <= 0 {
			b += i
		}
		e := b + (n-1)*i
		if e < m {
			m = e
			md = i
		}
	}
	b := y - (n-1)*md
	for b <= 0 {
		b += md
	}
	for i := 0; i < n; i++ {
		printf("%d ", b + i*md)
	}
	printf("\n")
}

func main() {
	t := 0
	scanf("%d\n", &t)
	for t > 0 {
		t--
		solve()
	}

	writer.Flush()
}

package main

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

func main() {
	sc := NewScanner()
	T := sc.NextInt()
	for i := 0; i < T; i++ {
		n, x, y := sc.NextInt(), sc.NextInt(), sc.NextInt()

		k := y - x
		minLast := int(1e9)
		start := 0
		diff := 0
		for i := 1; i <= k; i++ {
			if k%i == 0 {
				s := 0
				end := 0
				q := x / i
				if x-q*i == 0 {
					q--
				}
				s = x - q*i
				end = s + i*(n-1)
				if end < y {
					s += y - end
					if s > x {
						continue
					}

				}
				if minLast > end {
					minLast = end
					start = s
					diff = i
				}
			}
		}
		A := make([]int, n)
		A[0] = start
		for i := 1; i < n; i++ {
			A[i] += A[i-1] + diff
		}
		PrintI(A...)
	}
}

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

func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}

func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	// DEBUG ONLY
	// f, _ := os.Open("data.txt")
	// scanner := bufio.NewScanner(f)

	scanner := bufio.NewScanner(os.Stdin)

	var nCount int64
	scanner.Scan()

	fmt.Sscanf(scanner.Text(), "%d", &nCount)

	var n, x, y int64

	for ; nCount > 0; nCount-- {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d %d ", &n, &x, &y)

		// find the minimum step containing x, y
		var step int64
		for step = 1; ((y-x)/step > n) || ((y-x)%step != 0) || ((y-x)/step+1 > n); step++ {

		}

		// print array between x and y
		for cx := x; cx <= y; n-- {
			fmt.Printf("%d ", cx)
			cx += step
		}

		// items before x
		for cx := x - step; (cx > 0) && (n > 0); n-- {
			fmt.Printf("%d ", cx)
			cx -= step
		}

		// print items after y
		for y += step; n > 0; n-- {
			fmt.Printf("%d ", y)
			y += step
		}

		fmt.Println()

	}

}

package main

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

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

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

	for t := in(); t > 0; t-- {
		n, x, y := in(), in(), in()
		d := y-x
		r := n-1
		for r > 0 {
			if d%r == 0 {
				break
			}
			r--
		}

		r = d/r

		c := y
		sgn := false
		for i := 0; i < n ; i++ {
			fmt.Print(c, " ")

			if sgn == false {
				c -= r
			} else {
				c += r
			}

			if c < 0 {
				c = y + r
				sgn = true
			}
		}

		fmt.Println()
	}
}


Young wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting locations as possible. Russell was trying to form groups, but ran into some difficulties...Most of the young explorers are inexperienced, and sending them alone would be a mistake. Even Russell himself became senior explorer not long ago. Each of young explorers has a positive integer parameter $$$e_i$$$ — his inexperience. Russell decided that an explorer with inexperience $$$e$$$ can only join the group of $$$e$$$ or more people.Now Russell needs to figure out how many groups he can organize. It's not necessary to include every explorer in one of the groups: some can stay in the camp. Russell is worried about this expedition, so he asked you to help him.

The first line contains the number of independent test cases $$$T$$$($$$1 \leq T \leq 2 \cdot 10^5$$$). Next $$$2T$$$ lines contain description of test cases. The first line of description of each test case contains the number of young explorers $$$N$$$ ($$$1 \leq N \leq 2 \cdot 10^5$$$). The second line contains $$$N$$$ integers $$$e_1, e_2, \ldots, e_N$$$ ($$$1 \leq e_i \leq N$$$), where $$$e_i$$$ is the inexperience of the $$$i$$$-th explorer. It's guaranteed that sum of all $$$N$$$ doesn't exceed $$$3 \cdot 10^5$$$.

Print $$$T$$$ numbers, each number on a separate line. In $$$i$$$-th line print the maximum number of groups Russell can form in $$$i$$$-th test case.

NoteIn the first example we can organize three groups. There will be only one explorer in each group. It's correct because inexperience of each explorer equals to $$$1$$$, so it's not less than the size of his group.In the second example we can organize two groups. Explorers with inexperience $$$1$$$, $$$2$$$ and $$$3$$$ will form the first group, and the other two explorers with inexperience equal to $$$2$$$ will form the second group.This solution is not unique. For example, we can form the first group using the three explorers with inexperience equal to $$$2$$$, and the second group using only one explorer with inexperience equal to $$$1$$$. In this case the young explorer with inexperience equal to $$$3$$$ will not be included in any group.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		sort.Ints(a)
		ans := 0
		curNum := 0
		for i := 0; i < n; i++ {
			curNum++
			if a[i] <= curNum {
				ans++
				curNum = 0
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

// @problemURL https://codeforces.com/contest/1355/problem/B
package main

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

func nt(s *bufio.Scanner) string {
	s.Scan()
	return s.Text()
}

func ni(s *bufio.Scanner) int {
	return atoi(nt(s))
}

func atoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var in = bufio.NewReader(os.Stdin)
	s := bufio.NewScanner(in)
	s.Split(bufio.ScanWords)

	// Code
	T := ni(s)
	for tt := 0; tt < T; tt++ {
		n := ni(s)
		ar := make([]int, n)
		for i := 0; i < n; i++ {
			ar[i] = ni(s)
		}
		sort.Ints(ar)
		var ans, i int

		for i < n {
			groupSize := 1
			need := ar[i]
			i++
			for i < n && need > groupSize {
				groupSize++
				need = ar[i]
				i++
			}

			if groupSize >= need {
				ans++
			}

		}
		fmt.Println(ans)
	}
}

package main

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

var sc = WordScanner()
var memory [2000000]int
var memory2 [2000000]int

func solve() int {
	n := sc.Int()
	es := memory[:n]
	dp := memory2[:n]
	for i := range es {
		es[i] = sc.Int()
		dp[i] = 0
	}
	sort.Ints(es)
	var ans int
	for i := range es {
		if es[i] == i + 1 {
			dp[i] = 1
		} else if es[i] < i + 1 {
			dp[i] = 1 + dp[i - es[i]]
		}
		if ans < dp[i] {
			ans = dp[i]
		}
	}
	return ans
}

func main() {
	t := sc.Int()
	for i := 1; i <= t; i++ {
		fmt.Println(solve())
	}
}

type Scanner struct {
	*bufio.Scanner
}

func WordScanner() Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Scanner{sc}
}

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

func (sc Scanner) Int() int {
	i, _ := strconv.Atoi(sc.Text())
	return i
}

// https://codeforces.com/contest/1355/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	e := make([]int, n)
	refs := make([]int, n + 1)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &e[i])
		refs[e[i]]++
	}

	rem := 0
	ans := 0
	for i := 1; i < len(refs); i++ {
		if refs[i] == 0 {
			continue
		}
		ans += (refs[i] + rem) / i
		rem = (refs[i] + rem) % i
	}

	return ans
}

/*
URL:
https://codeforces.com/problemset/problem/1355/B
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n int
	A []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		A = ReadIntSlice(n)

		solve()
	}

	stdout.Flush()
}

func solve() {
	sort.Sort(sort.IntSlice(A))

	comp, cnts := RunLengthEncoding(A)
	resi := 0
	ans := 0
	for i := 0; i < len(comp); i++ {
		val, cnt := comp[i], cnts[i]

		ans += (cnt + resi) / val
		resi = (cnt + resi) % val
	}

	PrintfBufStdout("%d\n", ans)
}

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

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

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

	return runes, lengths
}

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

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		e := ScanInts(n)

		P(solv(n, e))
	}

	out.Flush()
}

func solv(n int, e []int) int {
	c, l := 0, 0
	sort.Ints(e)

	for i := 0; i < n; i++ {
		if e[i] <= (i - l + 1) {
			c++
			l = i + 1
		}
	}

	return c
}

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

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

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

func PS(args ...interface{}) {
	print(" ", args...)
	out.WriteByte('\n')
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case int64:
			str = strconv.FormatInt(v, 10)
		case string:
			str = v
		}
		out.WriteString(str + seperator)
	}
}

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

/*********************** Utils int64 ***********************/
func MnMx64(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn64(args ...int64) int64 { mn, _ := MnMx64(args...); return mn }
func Mx64(args ...int64) int64 { _, mx := MnMx64(args...); return mx }
func LCM64(a, b int64) int64   { return a / GCD64(a, b) * b }
func GCD64(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD64(b%a, a)
}
func SortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func Abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

/*********************** Utils int ***********************/
func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		e := ScanIntSlice(n)

		P(solv(n, e))
	}

	close(O)
	oWg.Wait()
}

func solv(n int, e []int) int {
	c, l := 0, 0
	sort.Ints(e)

	for i := 0; i < n; i++ {
		if e[i] <= (i - l + 1) {
			c++
			l = i + 1
		}
	}

	return c
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

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

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

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

package main

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

func max(var1 int,var2 int)  int  {
	if var1 > var2 {
		return var1
	}
	return var2
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var TestCases int
	fmt.Fscan(in,&TestCases)
	for TestCase:=0;TestCase<TestCases;TestCase++{
		var Length int
		fmt.Fscan(in,&Length)
		var members =make([]int,Length)
		for index:=0;index<Length;index++ {
			fmt.Fscan(in,&members[index])
		}
		sort.Ints(members)
//		PreviousGroup:=0
		TotalPossibleGroups:=0
		PreviousGroupSize:=0
		for index:=0;index<Length;index++{
			group:=members[index]
			if PreviousGroupSize+1>=group {
//				PreviousGroup=0
				TotalPossibleGroups++
				PreviousGroupSize=0
			}else {
//				PreviousGroup = group
				PreviousGroupSize++
			}
		}
		fmt.Println(TotalPossibleGroups)
	}

}

package main

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

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

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	t := nextInt()
	for ti := 0; ti < t; ti++ {
		n := nextInt()
		r := map[int]int{}
		maxE := 0
		for ni := 0; ni < n; ni++ {
			e := nextInt()
			_, ok := r[e]
			if !ok {
				r[e] = 0
			}
			r[e]++
			maxE = max(maxE, e)
		}
		groups := 0
		for i := 1; i <= maxE; i++ {
			_, ok := r[i]
			if !ok {
				continue
			}
			groups += r[i] / i
			_, ok2 := r[i+1]
			if !ok2 {
				r[i+1] = r[i] % i
			} else {
				r[i+1] += r[i] % i
			}
		}
		fmt.Println(groups)
	}

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

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

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

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

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

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

func max(a, b int) int {
	return int(max64(int64(a), int64(b)))
}

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

func min(a, b int) int {
	return int(min64(int64(a), int64(b)))
}

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

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(r, &n)
		e := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &e[i])
		}
		sort.Ints(e)
		ans := 0
		size := 0
		for i := 0; i < n; i++ {
			size++
			if size == e[i] {
				size = 0
				ans++
			}
		}
		fmt.Fprintln(w, ans)
	}

}

package main

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

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 := reader.NextInt64()
		e := make([]int64, n)
		for i := range e {
			e[i] = reader.NextInt64()
		}
		writer.Printf("%d\n", sol(e))
	}
}

func sol(e []int64) int64 {
	sort.Slice(e, func(a, b int) bool {
		return e[a] < e[b]
	})
	groups := int64(0)
	currN := int64(0)
	toFill := int64(0)
	for i := range e {
		toFill = e[i]
		currN++
		if currN == toFill {
			groups++
			currN = 0
			toFill = 0
		}
	}
	return groups
}

package main

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

func max(var1 int,var2 int)  int  {
	if var1 > var2 {
		return var1
	}
	return var2
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var TestCases int
	fmt.Fscan(in,&TestCases)
	for TestCase:=0;TestCase<TestCases;TestCase++{
		var Length int
		fmt.Fscan(in,&Length)
		var members =make([]int,Length)
		for index:=0;index<Length;index++ {
			fmt.Fscan(in,&members[index])
		}
		sort.Ints(members)
//		PreviousGroup:=0
		TotalPossibleGroups:=0
		PreviousGroupSize:=0
		for index:=0;index<Length;index++{
			group:=members[index]
			if PreviousGroupSize+1>=group {
//				PreviousGroup=0
				TotalPossibleGroups++
				PreviousGroupSize=0
			}else {
//				PreviousGroup = group
				PreviousGroupSize++
			}
		}
		println(TotalPossibleGroups)
	}

}

package main

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

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 := reader.NextInt64()
		e := make([]int64, n)
		for i := range e {
			e[i] = reader.NextInt64()
		}
		writer.Printf("%d\n", sol(e))
	}
}

func sol(e []int64) int64 {
	sort.Slice(e, func(a, b int) bool {
		return e[a] < e[b]
	})
	groups := int64(0)
	currN := int64(0)
	toFill := int64(0)
	for i := len(e)-1; i >= 0; i-- {
		if toFill == 0 {
			toFill = e[i]
		}
		currN++
		if currN == toFill {
			groups++
			currN = 0
			toFill = 0
		}
	}
	return groups
}