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 := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)
		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
}

func solve(n int, A []int) int64 {
	B := make([]int64, n)
	for i := 0; i < n; i++ {
		B[i] = int64(A[i])
	}
	var cnt int64

	for i := 1; i < n; i++ {
		B[i] += cnt
		if B[i] < B[i-1] {
			cnt += B[i-1] - B[i]
			B[i] = B[i-1]
		}
	}

	return cnt
}

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

package main

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

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

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

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

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

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

const (
	oo  = 100000000
	mod = 1000000007
)

func mult(a, b int64) int64 {
	return (a * b) % mod
}
func add(a, b int64) int64 {
	return (a + b) % mod
}
func sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

var (
	adj   [][]int
	depth []int
)

func pow(a, b int64) int64 {
	if b == 0 {
		return 1
	}
	res := pow(a, b/2)
	res = mult(res, res)
	if b%2 == 1 {
		res = mult(res, a)
	}
	return res
}

func solve() {
	n := nextInt()
	prev := nextInt()
	var res int64
	for i := 1; i < n; i++ {
		x := nextInt()
		if x < prev {
			res += int64(prev - x)
		}
		prev = x
	}
	printf("%d\n", res)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		file1, err := os.Open("input.txt")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create("output.txt")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// start := time.Now()

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

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

package main

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

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

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

	for t := input(); t > 0; t-- {
		n := input()
		a := make([]uint64, n)
		m := make([]uint64, n-1)

		for i := range a {
			a[i] = input()
		}

		var i, cost uint64
		for i = 1; i < n; i++ {
			if a[i] < a[i-1] {
				m[i-1] = a[i-1] - a[i]
			}
		}

		for i := range m {
			cost += m[i]
		}

		fmt.Println(cost)
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a, aPrev, n int64
		count := int64(0)
		fmt.Fscan(in, &n)
		for j := int64(0); j < n; j++ {
			aPrev = a
			fmt.Fscan(in, &a)
			if j == 0 {
				continue
			}
			if aPrev > a {
				count += aPrev - a
			}
		}
		fmt.Println(count)
	}
}

package main

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

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

	var t, n int

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var ans int64
		fmt.Fscan(input, &n)
		arr := make([]int64, n)

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

			if i > 0 && arr[i] < arr[i-1] {
				ans += arr[i-1] - arr[i]
			}
		}

		fmt.Println(ans)
	}
}

package main
import (
        "fmt"
        "os"
        "bufio"
)
func main(){
    var t, n, a, b int
    in := bufio.NewReader(os.Stdin)
    out := os.Stdout
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        var ans int64 = 0
        fmt.Fscan(in, &n)
        fmt.Fscan(in, &a)
        n--
        for ; n > 0; n-- {
            fmt.Fscan(in, &b)
            if a > b {
                ans += int64(a-b)
            }
            a = b
        }
        fmt.Fprintln(out, ans)
    }
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

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

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.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 suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.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
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		printf("%d\n", sol(n, a))
	}
}

func sol(n int64, a []int64) int64 {
	ret := int64(0)
	for i := n-1; i > 0; i-- {
		if a[i] < a[i-1] {
			ret += a[i-1] - a[i]
		}
	}
	return ret
}

package main

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

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

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

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

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

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

const (
	oo  = 100000000
	mod = 1000000007
)

func mult(a, b int64) int64 {
	return (a * b) % mod
}
func add(a, b int64) int64 {
	return (a + b) % mod
}
func sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

var (
	adj   [][]int
	depth []int
)

func pow(a, b int64) int64 {
	if b == 0 {
		return 1
	}
	res := pow(a, b/2)
	res = mult(res, res)
	if b%2 == 1 {
		res = mult(res, a)
	}
	return res
}

func solve() {
	n := nextInt()
	ranges := [][2]int{}
	min := nextInt()
	max := min
	for i := 1; i < n; i++ {
		x := nextInt()
		if x >= max {
			max = x
		} else {
			ranges = append(ranges, [2]int{min, max})
			min, max = x, x
		}
	}
	ranges = append(ranges, [2]int{min, max})
	res := 0
	for i := len(ranges) - 1; i > 0; i-- {
		add := Max(0, ranges[i-1][1]-ranges[i][0])
		res += add
	}
	printf("%d\n", res)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		file1, err := os.Open("input.txt")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create("output.txt")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// start := time.Now()

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

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

package main

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

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

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

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

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

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

const (
	oo  = 100000000
	mod = 1000000007
)

func mult(a, b int64) int64 {
	return (a * b) % mod
}
func add(a, b int64) int64 {
	return (a + b) % mod
}
func sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

var (
	adj   [][]int
	depth []int
)

func pow(a, b int64) int64 {
	if b == 0 {
		return 1
	}
	res := pow(a, b/2)
	res = mult(res, res)
	if b%2 == 1 {
		res = mult(res, a)
	}
	return res
}

func solve() {
	n := nextInt()
	prev := nextInt()
	res := 0
	for i := 1; i < n; i++ {
		x := nextInt()
		if x < prev {
			res += prev - x
		}
		prev = x
	}
	printf("%d\n", res)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		file1, err := os.Open("input.txt")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create("output.txt")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// start := time.Now()

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

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

package main

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

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

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

	for t := input(); t > 0; t-- {
		n := input()
		a := make([]uint64, n)

		for i := range a {
			a[i] = input()
		}

		var max, cost, i uint64

		max = a[0]

		for i = 1; i < n; i++ {
			if a[i] < max {
				cost = max - a[i]
			} else {
				max = a[i]
			}
		}

		fmt.Println(cost)
	}

}

package main

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

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

	var t, n int

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var ans, mx, mn, zp, fl int64
		fmt.Fscan(input, &n)
		arr := make([]int64, n)

		id := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i])
			if arr[i] > mx {
				mx = arr[i]
				id = i
			}
		}

		mn = mx
		for i := id + 1; i < n; i++ {
			if arr[i] < mn {
				mn = arr[i]
			}
		}

		ans = mx - mn
		zp = ans
		fl = 0

		for i := 0; i < id; i++ {
			if arr[i] > arr[i+1] {
				fl += (arr[i] - arr[i+1])
				arr[i+1] = arr[i]
			}
		}

		if fl >= zp {
			fl -= zp
		}

		fmt.Println(ans - fl)
	}
}


package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func readString() string {
	if !in.Scan() {
		panic(in.Err())
	}
	return in.Text()
}

type edge struct {
	to int
	c  bool
}

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

	n := readInt()
	m := readInt()
	edges := make([][]edge, n+1)
	for i := 0; i < m; i++ {
		u := readInt()
		v := readInt()
		c := readString() == "R"
		edges[u] = append(edges[u], edge{v, c})
		edges[v] = append(edges[v], edge{u, c})
	}
	val := make([]int, n+1)
	last := 0
	canTrue := true
	canFalse := true
	var solTrue, solFalse []int
	for i := 1; i <= n; i++ {
		if val[i] > 0 {
			continue
		}
		try := func(want, set bool) ([]int, bool) {
			var ret []int
			last += 2
			var st []int
			st = append(st, i)
			if set {
				val[i] = last
				ret = append(ret, i)
			} else {
				val[i] = last - 1
			}
			for len(st) > 0 {
				v := st[len(st)-1]
				st = st[:len(st)-1]
				isSet := val[v] == last
				for _, e := range edges[v] {
					cur := e.c
					if isSet {
						cur = !cur
					}
					ws := cur != want
					switch val[e.to] {
					case last:
						if !ws {
							return nil, false
						}
					case last - 1:
						if ws {
							return nil, false
						}
					default:
						if ws {
							val[e.to] = last
							ret = append(ret, e.to)
						} else {
							val[e.to] = last - 1
						}
						st = append(st, e.to)
					}
				}
			}
			return ret, true
		}
		for _, c := range []struct {
			val bool
			can *bool
			sol *[]int
		}{
			{true, &canTrue, &solTrue},
			{false, &canFalse, &solFalse},
		} {
			if !*c.can {
				continue
			}
			sol1, can1 := try(c.val, false)
			sol2, can2 := try(c.val, true)
			*c.can = can1 || can2
			if !*c.can {
				continue
			}
			if can1 && can2 {
				if len(sol1) < len(sol2) {
					*c.sol = append(*c.sol, sol1...)
				} else {
					*c.sol = append(*c.sol, sol2...)
				}
			} else {
				if can1 {
					*c.sol = append(*c.sol, sol1...)
				} else {
					*c.sol = append(*c.sol, sol2...)
				}
			}
		}
	}
	if !canTrue && !canFalse {
		fmt.Println("-1")
		return
	}
	var sol []int
	if canTrue && canFalse {
		if len(solTrue) < len(solFalse) {
			sol = solTrue
		} else {
			sol = solFalse
		}
	} else {
		if canFalse {
			sol = solFalse
		} else {
			sol = solTrue
		}
	}
	fmt.Fprintln(out, len(sol))
	for i := range sol {
		fmt.Fprintln(out, sol[i])
	}
}

package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
    stdout = bufio.NewWriter(os.Stdout)
}

type Edge struct {
    from, to int
    color rune
}

var edges [][]Edge
var visit []int
var list [][]int

func dfs(node int, flip int, color rune) bool {

    //fmt.Fprintf(stdout, "%v %v %v %v\n", node, visit[node], flip, color)
    if visit[node] != 0 {
        return visit[node] == flip
    }

    visit[node] = flip
    list[flip] = append(list[flip], node)

    for _, edge := range edges[node] {
        if (flip == 2 && edge.color == color) || (flip == 1 && edge.color != color) {
            if dfs(edge.to, 2, color) == false {
                return false
            }
        } else {
            if dfs(edge.to, 1, color) == false {
                return false
            }
        }
    }
    return true
}

func try(color rune) (res []int, ok bool) {
    visit   = make([]int, len(edges))
    list    = make([][]int, 3)

    for i := 0; i < len(visit); i++ {
        if visit[i] != 0 {
            continue
        }

        list[1] = make([]int, 0)
        list[2] = make([]int, 0)

        if dfs(i, 1, color) == false {
            return res, false
        }

        if len(list[1]) <= len(list[2]) {
            for _, n := range list[1] {
                res = append(res, n)
            }
        } else {
            for _, n := range list[2] {
                res = append(res, n)
            }
        }
    }

    return res, true
}

func main() {

    n, m := 0, 0
    fmt.Fscanf(stdin, "%d%d\n", &n, &m)

    edges = make([][]Edge, n)

    for i := 0; i < m; i++ {
        var from, to int
        var color rune
        fmt.Fscanf(stdin, "%d%d %c\n", &from, &to, &color)
        from--
        to--

        edges[from] = append(edges[from], Edge{from, to, color})
        edges[to] = append(edges[to], Edge{to, from, color})
    }

    v1, ok1 := try('R')
    v2, ok2 := try('B')

    if ok1 == false && ok2 == false {
        fmt.Fprintf(stdout, "-1\n")
    } else {
        var v []int
        if ok1 == true {
            v = v1
        } else {
            v = v2
        }

        if ok2 == true && len(v) > len(v2) {
            v = v2
        }
        fmt.Fprintf(stdout, "%v\n", len(v))
        for _, vv := range v {
            fmt.Fprintf(stdout, "%v ", vv + 1)
        }
        fmt.Fprintf(stdout, "\n")
    }

    stdout.Flush()
}

package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
    stdout = bufio.NewWriter(os.Stdout)
}

type Edge struct {
    from, to int
    color rune
}

var edges [][]Edge
var visit []int
var list [][]int

func dfs(node int, flip int, color rune) bool {

    //fmt.Fprintf(stdout, "%v %v %v %v\n", node, visit[node], flip, color)
    if visit[node] != 0 {
        return visit[node] == flip
    }

    visit[node] = flip
    list[flip] = append(list[flip], node)

    for _, edge := range edges[node] {
        if (flip == 2 && edge.color == color) || (flip == 1 && edge.color != color) {
            if dfs(edge.to, 2, color) == false {
                return false
            }
        } else {
            if dfs(edge.to, 1, color) == false {
                return false
            }
        }
    }
    return true
}

func try(color rune) (res []int, ok bool) {
    visit   = make([]int, len(edges))
    list    = make([][]int, 3)

    for i := 0; i < len(visit); i++ {
        if visit[i] != 0 {
            continue
        }

        list[1] = make([]int, 0)
        list[2] = make([]int, 0)

        if dfs(i, 1, color) == false {
            return res, false
        }

        if len(list[1]) <= len(list[2]) {
            for _, n := range list[1] {
                res = append(res, n)
            }
        } else {
            for _, n := range list[2] {
                res = append(res, n)
            }
        }
    }

    return res, true
}

func main() {

    n, m := 0, 0
    fmt.Fscanf(stdin, "%d%d\n", &n, &m)

    edges = make([][]Edge, n)

    for i := 0; i < m; i++ {
        var from, to int
        var color rune
        fmt.Fscanf(stdin, "%d%d %c\n", &from, &to, &color)
        from--
        to--

        edges[from] = append(edges[from], Edge{from, to, color})
        edges[to] = append(edges[to], Edge{to, from, color})
    }

    v1, ok1 := try('R')
    v2, ok2 := try('B')

    if ok1 == false && ok2 == false {
        fmt.Fprintf(stdout, "-1\n")
    } else {
        var v []int
        if ok1 == true {
            v = v1
        }

        if ok2 == true && len(v) > len(v2) {
            v = v2
        }
        fmt.Fprintf(stdout, "%v\n", len(v))
        for _, vv := range v {
            fmt.Fprintf(stdout, "%v ", vv + 1)
        }
        fmt.Fprintf(stdout, "\n")
    }

    stdout.Flush()
}

package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
    stdout = bufio.NewWriter(os.Stdout)
}

type Edge struct {
    from, to int
    color rune
}

var edges [][]Edge
var visit []int
var list [][]int

func dfs(node int, flip int, color rune) bool {

    //fmt.Fprintf(stdout, "%v %v %v %v\n", node, visit[node], flip, color)
    if visit[node] != 0 {
        return visit[node] == flip
    }

    visit[node] = flip
    list[flip] = append(list[flip], node)

    for _, edge := range edges[node] {
        if (flip == 2 && edge.color == color) || (flip == 1 && edge.color != color) {
            if dfs(edge.to, 2, color) == false {
                return false
            }
        } else {
            if dfs(edge.to, 1, color) == false {
                return false
            }
        }
    }
    return true
}

func try(color rune) (res []int, ok bool) {
    visit   = make([]int, len(edges))
    list    = make([][]int, 3)

    for i := 0; i < len(visit); i++ {
        if visit[i] != 0 {
            continue
        }

        list[1] = make([]int, 0)
        list[2] = make([]int, 0)

        if dfs(i, 1, color) == false {
            return res, false
        }

        if len(list[1]) <= len(list[2]) {
            for _, n := range list[1] {
                res = append(res, n)
            }
        } else {
            for _, n := range list[2] {
                res = append(res, n)
            }
        }
    }

    return res, true
}

func main() {

    n, m := 0, 0
    fmt.Fscanf(stdin, "%d%d\n", &n, &m)

    edges = make([][]Edge, n)

    for i := 0; i < m; i++ {
        var from, to int
        var color rune
        fmt.Fscanf(stdin, "%d%d %c\n", &from, &to, &color)
        from--
        to--

        edges[from] = append(edges[from], Edge{from, to, color})
        edges[to] = append(edges[to], Edge{to, from, color})
    }

    v1, ok1 := try('R')
    v2, ok2 := try('B')

    if ok1 == false && ok2 == false {
        fmt.Fprintf(stdout, "-1\n")
    } else {
        v := v1
        if len(v) > len(v2) {
            v = v2
        }
        fmt.Fprintf(stdout, "%v\n", len(v))
        for _, vv := range v {
            fmt.Fprintf(stdout, "%v ", vv + 1)
        }
        fmt.Fprintf(stdout, "\n")
    }

    stdout.Flush()
}

package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

type Point struct {
	x, y int
}

type Vector struct {
	dx, dy int
}

func main() {
	n, count := 0, 0
	fmt.Fscanf(stdin, "%d\n", &n)

	points := make([]Point, n)
	vectors := make(map[Vector]int)

	for i := 0; i < n; i++ {
		fmt.Fscanf(stdin, "%d%d\n", &points[i].x, &points[i].y)
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			var vector Vector

			if points[i].x > points[j].x || (points[i].x == points[j].x && points[i].y >= points[j].y) {
				vector = Vector{points[i].x - points[j].x, points[i].y - points[j].y}
			} else {
				vector = Vector{points[j].x - points[i].x, points[j].y - points[i].y}
			}
			count += vectors[vector]
			vectors[vector]++
		}
	}
	fmt.Fprintf(stdout, "%d\n", count / 2)

	stdout.Flush()
}


package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

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

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	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 GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

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

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var W, H int
		var x1, y1, x2, y2 int
		var w, h int

		fmt.Fscan(input, &W, &H)
		fmt.Fscan(input, &x1, &y1, &x2, &y2)
		fmt.Fscan(input, &w, &h)

		var leftEMPTY, rightEMPTY, upEMPTY, downEMPTY int
		leftEMPTY = x1
		downEMPTY = y1
		rightEMPTY = W - x2
		upEMPTY = H - y2

		var ans int
		var leftNEED, rightNEED, upNEED, downNEED int
		leftNEED = w - leftEMPTY
		rightNEED = w - rightEMPTY
		upNEED = h - upEMPTY
		downNEED = h - downEMPTY
		if leftNEED <= 0 || rightNEED <= 0 || upNEED <= 0 || downNEED <= 0 {
			ans = 0
		} else {
			ARR := make([]int, 0)
			if leftEMPTY >= rightNEED {
				ARR = append(ARR, rightNEED)
				ARR = append(ARR, leftNEED)

			}
			if upEMPTY >= downNEED {
				ARR = append(ARR, upNEED)
				ARR = append(ARR, downNEED)
			}

			if len(ARR) == 0 {
				ans = -1
			} else {
				sort.Ints(ARR)
				ans = ARR[0]
			}

		}
		if ans == -1 {
			fmt.Println(-1)
		} else {
			wee := strconv.Itoa(ans)
			wee = wee + ".000000"
			fmt.Println(wee)
		}

	}

}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var W, H int
		fmt.Fscan(r, &W, &H)

		var x1, y1, x2, y2 int
		fmt.Fscan(r, &x1, &y1, &x2, &y2)

		var w, h int
		fmt.Fscan(r, &w, &h)

		ans := solve(W, H, x1, y1, x2, y2, w, h)
		fmt.Printf("%.6f", ans)
		fmt.Println()
	}
}

func solve(W, H, x1, y1, x2, y2, w, h int) float64 {
	if w <= x1 || w <= W - x2{
		return 0
	}
	if h <= y1 || h <= H - y2 {
		return 0
	}

	var dx1 int
	var dy1 int
	var dx2 int
	var dy2 int

	if w + (x2 - x1) <= W {
		dx1 = w - x1
	} else {
		dx1 = -1
	}

	if w + (x2 - x1) <= W {
		dx2 = x2 - (W - w)

	} else {
		dx2 = -1
	}

	if h + (y2 - y1) <= H {
		dy1 = h - y1
	} else {
		dy1 = -1
	}

	if h + (y2 - y1) <= H {
		dy2 = y2 - (H - h)
	} else {
		dy2 = -1
	}

	if dx1 == -1 && dy1 == -1{
		return -1
	}
	if dx1 == -1{
		return min(float64(dy1), float64(dy2))
	}
	if dy1 == -1 {
		return min(float64(dx1), float64(dx2))
	}

	a := min(min(float64(dy1), float64(dy2)), min(float64(dx1), float64(dx2)))

	d1 := math.Sqrt(math.Pow(float64(dx1), 2) + math.Pow(float64(dy1), 2))
	d2 := math.Sqrt(math.Pow(float64(dx1), 2) + math.Pow(float64(dy2), 2))
	d3 := math.Sqrt(math.Pow(float64(dx2), 2) + math.Pow(float64(dy1), 2))
	d4 := math.Sqrt(math.Pow(float64(dx2), 2) + math.Pow(float64(dy2), 2))

	return min(a, min(d1, min(d2, min(d3, d4))))
}

func min(f1, f2 float64) float64 {
	if f1 < f2 {
		return f1
	}
	return f2
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var w, h int
		fmt.Fscan(in, &w, &h)

		var x1, y1, x2, y2 int
		fmt.Fscan(in, &x1, &y1, &x2, &y2)

		var bw, bh int
		fmt.Fscan(in, &bw, &bh)

		m := math.MaxInt

		for i := 0; i < 4; i++ {
			switch i {
			case 0: // x1 overlap
				ol := bw - x1
				if ol <= 0 {
					m = 0
					break
				}

				if ol < m && x2+ol <= w {
					m = ol
				}
			case 1: // y1 overlap
				ol := bh - y1
				if ol <= 0 {
					m = 0
					break
				}

				if ol < m && y2+ol <= h {
					m = ol
				}
			case 2: // x2 overlap
				ol := x2 - (w - bw)
				if ol <= 0 {
					m = 0
					break
				}

				if ol < m && x1-ol >= 0 {
					m = ol
				}
			case 3: // y2 overlap
				ol := y2 - (h - bh)
				if ol <= 0 {
					m = 0
					break
				}

				if ol < m && y1-ol >= 0 {
					m = ol
				}
			}
		}

		if m == math.MaxInt {
			fmt.Fprintln(out, -1)
		} else {
			fmt.Fprintf(out, "%d.000000000\n", m)
		}
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var W, H int
		fmt.Fscan(r, &W, &H)

		var x1, y1, x2, y2 int
		fmt.Fscan(r, &x1, &y1, &x2, &y2)

		var w, h int
		fmt.Fscan(r, &w, &h)

		ans := solve(W, H, x1, y1, x2, y2, w, h)
		fmt.Printf("%.6f", ans)
		fmt.Println()
	}
}

func solve(W, H, x1, y1, x2, y2, w, h int) float64 {
	if w <= x1 || w <= W - x2{
		return 0
	}
	if h <= y1 || h <= H - y2 {
		return 0
	}

	var dx1 int
	var dy1 int
	var dx2 int
	var dy2 int

	if w + (x2 - x1) <= W {
		dx1 = w - x1
	} else {
		dx1 = -1
	}

	if w + (x2 - x1) <= W {
		dx2 = x2 - (W - w)

	} else {
		dx2 = -1
	}

	if h + (y2 - y1) <= H {
		dy1 = h - y1
	} else {
		dy1 = -1
	}

	if h + (y2 - y1) <= H {
		dy2 = y2 - (H - h)
	} else {
		dy2 = -1
	}

	if dx1 == -1 && dy1 == -1{
		return -1
	}
	if dx1 == -1{
		return min(float64(dy1), float64(dy2))
	}
	if dy1 == -1 {
		return min(float64(dx1), float64(dx2))
	}

	d1 := math.Sqrt(math.Pow(float64(dx1), 2) + math.Pow(float64(dy1), 2))
	d2 := math.Sqrt(math.Pow(float64(dx1), 2) + math.Pow(float64(dy2), 2))
	d3 := math.Sqrt(math.Pow(float64(dx2), 2) + math.Pow(float64(dy1), 2))
	d4 := math.Sqrt(math.Pow(float64(dx2), 2) + math.Pow(float64(dy2), 2))

	return min(d1, min(d2, min(d3, d4)))
}

func min(f1, f2 float64) float64 {
	if f1 < f2 {
		return f1
	}
	return f2
}


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


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"
	"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"
)

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