The only difference between easy and hard versions are constraints on $$$n$$$ and $$$k$$$.You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most $$$k$$$ most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals $$$0$$$).Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.You (suddenly!) have the ability to see the future. You know that during the day you will receive $$$n$$$ messages, the $$$i$$$-th message will be received from the friend with ID $$$id_i$$$ ($$$1 \le id_i \le 10^9$$$).If you receive a message from $$$id_i$$$ in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.Otherwise (i.e. if there is no conversation with $$$id_i$$$ on the screen):  Firstly, if the number of conversations displayed on the screen is $$$k$$$, the last conversation (which has the position $$$k$$$) is removed from the screen.  Now the number of conversations on the screen is guaranteed to be less than $$$k$$$ and the conversation with the friend $$$id_i$$$ is not displayed on the screen.  The conversation with the friend $$$id_i$$$ appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down. Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all $$$n$$$ messages.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 200)$$$ — the number of messages and the number of conversations your smartphone can show. The second line of the input contains $$$n$$$ integers $$$id_1, id_2, \dots, id_n$$$ ($$$1 \le id_i \le 10^9$$$), where $$$id_i$$$ is the ID of the friend which sends you the $$$i$$$-th message.

In the first line of the output print one integer $$$m$$$ ($$$1 \le m \le min(n, k)$$$) — the number of conversations shown after receiving all $$$n$$$ messages. In the second line print $$$m$$$ integers $$$ids_1, ids_2, \dots, ids_m$$$, where $$$ids_i$$$ should be equal to the ID of the friend corresponding to the conversation displayed on the position $$$i$$$ after receiving all $$$n$$$ messages.

NoteIn the first example the list of conversations will change in the following way (in order from the first to last message):  $$$[]$$$;  $$$[1]$$$;  $$$[2, 1]$$$;  $$$[3, 2]$$$;  $$$[3, 2]$$$;  $$$[1, 3]$$$;  $$$[1, 3]$$$;  $$$[2, 1]$$$. In the second example the list of conversations will change in the following way:  $$$[]$$$;  $$$[2]$$$;  $$$[3, 2]$$$;  $$$[3, 2]$$$;  $$$[1, 3, 2]$$$;  and then the list will not change till the end.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var n, k int
	var ID string
	fmt.Fscan(in, &n, &k)
	conversations := make([]string, 0, n)
	inConversations := make(map[string]bool, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ID)
		if inConversations[ID] {
			continue
		}
		inConversations[ID] = true
		if len(conversations) < k {
			conversations = append(conversations, ID)
			continue
		}
		inConversations[conversations[0]] = false
		conversations = conversations[1:]
		conversations = append(conversations, ID)
	}
	fmt.Fprint(out, len(conversations), "\n")
	for i := len(conversations) - 1; i >= 0; i-- {
		fmt.Fprint(out, conversations[i], " ")
	}
	out.Flush()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var n, k, ID int
	fmt.Fscan(in, &n, &k)
	conversations := make([]int, 0, k)
	inConversations := make(map[int]bool, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ID)
		if inConversations[ID] {
			continue
		}
		inConversations[ID] = true
		if len(conversations) < k {
			conversations = append(conversations, ID)
			continue
		}
		inConversations[conversations[0]] = false
		conversations = conversations[1:]
		conversations = append(conversations, ID)
	}
	fmt.Fprint(out, len(conversations), "\n")
	for i := len(conversations) - 1; i >= 0; i-- {
		fmt.Fprint(out, conversations[i], " ")
	}
	out.Flush()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var n, k, ID int
	fmt.Fscan(in, &n, &k)
	conversations := make([]int, 0)
	inConversations := make(map[int]bool, 0)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ID)
		if inConversations[ID] {
			continue
		}
		inConversations[ID] = true
		if len(conversations) < k {
			conversations = append(conversations, ID)
			continue
		}
		inConversations[conversations[0]] = false
		conversations = conversations[1:]
		conversations = append(conversations, ID)
	}
	fmt.Fprint(out, len(conversations), "\n")
	for i := len(conversations) - 1; i >= 0; i-- {
		fmt.Fprint(out, conversations[i], " ")
	}
	out.Flush()
}

package main

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

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

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

var (
	n, k  int64
	convs []int64
	convM = make(map[int64]struct{})
)

func main() {
	defer writer.Flush()
	Scanf("%d %d\n", &n, &k)

	for i := int64(0); i < n; i++ {
		var ai int64
		Scanf("%d", &ai)

		// is ai in convs?
		if _, ok := convM[ai]; ok {
			continue
		}

		if int64(len(convs)) >= k {
			delete(convM, convs[0])
			convs = convs[1:]
		}
		convs = append(convs, ai)
		convM[ai] = struct{}{}
	}

	Printf("%d\n", len(convs))
	for i := len(convs) - 1; i >= 0; i-- {
		Printf("%d ", convs[i])
	}
}

package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

type queue struct {
	data []int
}

func (q *queue) queue(v int) {
	q.data = append(q.data, v)
}
func (q *queue) dequeue(v *int) (r bool) {
	if len(q.data) > 0 {
		*v = q.data[0]
		q.data = q.data[1:len(q.data)]
		r = true
	}
	return r
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	id := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < len(id); i++ {
		id[i] = nextInt(sc)
	}
	current := make(map[int]bool, k)
	var q queue
	for i := 0; i < len(id); i++ {
		if !current[id[i]] { // not shown now
			current[id[i]] = true
			q.queue(id[i])
			if len(q.data) > k {
				var t int
				q.dequeue(&t)
				current[t] = false
			}
		}
	}
	fmt.Println(len(q.data))
	for i := len(q.data) - 1; i >= 0; i-- {
		fmt.Print(q.data[i], " ")
	}
	fmt.Println()
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

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

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, k int
var A []int
var Ids []int
var memo map[int]int

func main() {
	n, k = ReadInt2()
	A = ReadIntSlice(n)

	memo = make(map[int]int)
	for i := 0; i < n; i++ {
		memo[A[i]] = 0
	}

	Ids = []int{}
	for i := 0; i < n; i++ {
		a := A[i]

		if isExist(a) {
			continue
		}

		// 追加
		memo[a] = 1

		Ids = append(Ids, a)
		if len(Ids) <= k {
			continue
		} else {
			memo[Ids[0]] = 0
			Ids = Ids[1:]
		}
	}

	fmt.Println(len(Ids))
	reverseIds := rev()
	fmt.Println(PrintIntsLine(reverseIds...))
}

func isExist(id int) bool {
	if value, ok := memo[id]; ok {
		if value == 1 {
			return true
		} else {
			return false
		}
	} else {
		return false
	}
}

func rev() []int {
	res := []int{}

	for i := len(Ids) - 1; i >= 0; i-- {
		res = append(res, Ids[i])
	}

	return res
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

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

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, k int
var A []int
var Ids []int
var memo map[int]int

func main() {
	n, k = ReadInt2()
	A = ReadIntSlice(n)

	memo = make(map[int]int)
	for i := 0; i < n; i++ {
		memo[A[i]] = 0
	}

	Ids = []int{}
	for i := 0; i < n; i++ {
		a := A[i]

		if isExist(a) {
			continue
		}

		// 追加
		memo[a] = 1

		Ids = append(Ids, a)
		if len(Ids) <= k {
			continue
		} else {
			memo[Ids[0]] = 0
			Ids = Ids[1:]
		}
	}

	fmt.Println(len(Ids))
	reverseIds := rev()
	fmt.Println(PrintIntsLine(reverseIds...))
}

func isExist(id int) bool {
	// for i := 0; i < len(Ids); i++ {
	// 	if id == Ids[i] {
	// 		return true
	// 	}
	// }
	// return false

	if value, ok := memo[id]; ok {
		if value == 1 {
			return true
		} else {
			return false
		}
	} else {
		return false
	}
}

func rev() []int {
	res := []int{}

	for i := len(Ids) - 1; i >= 0; i-- {
		res = append(res, Ids[i])
	}

	return res
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

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

func f(in io.Reader, out io.Writer) {
	var n, k int
	fmt.Fscanf(in, "%d %d\n", &n, &k)

	ids := make(chan string, k)
	exists := make(map[string]bool)

	s := bufio.NewScanner(in)
	s.Split(bufio.ScanWords)

	for i := 0; i < n; i += 1 {
		id := read(s)

		if !exists[id] {
			if len(ids) == cap(ids) {
				delete(exists, <-ids)
			}
			exists[id] = true
			ids <- id
		}
	}

	idsCount := len(ids)
	r := make([]string, idsCount)
	for i := idsCount - 1; i >= 0; i -= 1 {
		r[i] = <-ids
	}

	fmt.Fprintln(out, len(r))
	fmt.Fprintln(out, strings.Join(r, " "))
}

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

package main

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

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

	var n, k, t int
	fmt.Fscanf(reader, "%d %d\n", &n, &k)

	set := make(map[int]bool, k)
	slice := make([]int, 0, k)
	del := 0

	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &t)
		if _, ok := set[t]; ok {
			continue
		}

		if len(set) == k {
			delete(set, slice[del])
			//slice = slice[1:]
			del++
		}

		set[t] = true
		slice = append(slice, t)
	}

	fmt.Printf("%d\n", len(slice)-del)

	// for _, v := range slice {
	// 	fmt.Printf("%d ", v)
	// }

	for i := len(slice) - 1; i >= del; i-- {
		fmt.Printf("%d ", slice[i])
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1234/problem/B1, https://codeforces.com/contest/1234/problem/B2

package main

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

func reverseArray(size int, arr []int) []int {
	reversed := make([]int, size)
	for i := 0; i < size; i++ {
		reversed[i] = arr[size-i-1]
	}
	return reversed
}

func Solve(n int, k int, ids []int) []int {
	queue := []int{}
	idSet := make(map[int]bool)
	size := 0
	for _, elem := range ids {
		if !idSet[elem] && size < k {
			idSet[elem] = true
			queue = append(queue, elem)
			size += 1
		} else if !idSet[elem] && size == k {
			idSet[elem] = true
			queue = append(queue, elem)
			idSet[queue[0]] = false
			queue = queue[1:]
		}
	}
	return reverseArray(size, queue)
}

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

	var n, k int
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	ids := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &ids[i])
	}
	fmt.Fscanf(reader, "\n")

	solution := Solve(n, k, ids)
	fmt.Fprintf(writer, "%d\n", len(solution))
	for _, elem := range solution {
		fmt.Fprintf(writer, "%d ", elem)
	}
	fmt.Fprintf(writer, "\n")
}

package main
import (
  "fmt"
  "strconv"
  "strings"
)
type Screen int
var inQueue map[Screen]bool = map[Screen]bool{}
func (c Screen)Set(b bool) {
  if b {
    inQueue[c] = true
  } else {
    delete(inQueue, c)
  }
}
func (c Screen)Get() bool {
  _,x := inQueue[c]
  return x
}
type Queue struct {
  Screens []Screen
  Maxlen int
}
func (q*Queue)Len() int {
  return len(q.Screens)
}

func (q*Queue)Push(s Screen) *Screen {
  var x *Screen
  if q.Len() >= q.Maxlen {
    x = &q.Screens[0]
    q.Screens = q.Screens[1:]
  }
  q.Screens = append(q.Screens, s)
  return x
}

func(q*Queue)Pop() *Screen {
  if q.Len()==0 {
    return nil
  }
  x := &q.Screens[0]
  q.Screens = q.Screens[1:]
  return x
}

func rts(a []Screen) []string {
  k := []string{}
  for i:=len(a)-1;i>=0;i-- {
    k = append(k, strconv.Itoa(int(a[i])))
  }
  return k
}

func main() {
  var n,k int
  var a Screen
  fmt.Scanf("%d%d\n", &n, &k)
  q := Queue{Maxlen:k}
  for i:=0;i<n;i++ {
    fmt.Scanf("%d", &a)
    if !a.Get() {
      a.Set(true)
      b := q.Push(a)
      if b!=nil {
        if a == *b {
          panic("")
        }
        b.Set(false)
      }
    }
  }
  fmt.Println(q.Len())
  fmt.Println(strings.Join(rts(q.Screens), " "))
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

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

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, k int
var A []int
var Ids []int

func main() {
	n, k = ReadInt2()
	A = ReadIntSlice(n)

	Ids = []int{}
	for i := 0; i < n; i++ {
		a := A[i]

		if isExist(a) {
			continue
		}

		newIds := []int{}
		newIds = append(newIds, a)
		if len(Ids) < k {
			newIds = append(newIds, Ids...)
		} else {
			newIds = append(newIds, Ids[:len(Ids)-1]...)
		}
		Ids = newIds
	}

	fmt.Println(len(Ids))
	fmt.Println(PrintIntsLine(Ids...))
}

func isExist(id int) bool {
	for i := 0; i < len(Ids); i++ {
		if id == Ids[i] {
			return true
		}
	}
	return false
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

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

func f(in io.Reader, out io.Writer) {
	var n, k int
	fmt.Fscanf(in, "%d %d\n", &n, &k)

	ids := make(chan string, k)
	exists := make(map[string]bool)

	s := bufio.NewScanner(in)

	for _, id := range strings.Split(read(s), " ") {
		if !exists[id] {
			if len(ids) == cap(ids) {
				delete(exists, <-ids)
			}
			exists[id] = true
			ids <- id
 		}
	}

	idsCount := len(ids)
	r := make([]string, idsCount)
	for i := idsCount - 1; i >= 0; i -= 1 {
		r[i] = <-ids
	}

	fmt.Fprintln(out, len(r))
	fmt.Fprintln(out, strings.Join(r, " "))
}

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

package main

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

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

	var n, k, t int
	fmt.Fscanf(reader, "%d %d\n", &n, &k)

	set := make(map[int]bool, k)
	slice := make([]int, 0, k)

	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &t)
		if _, ok := set[t]; ok {
			continue
		}

		if len(set) == k {
			delete(set, slice[0])
			slice = slice[1:]
		}

		set[t] = true
		slice = append(slice, t)
	}

	fmt.Printf("%d\n", len(slice))

	// for _, v := range slice {
	// 	fmt.Printf("%d ", v)
	// }

	for i := len(slice) - 1; i >= 0; i-- {
		fmt.Printf("%d ", slice[i])
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1234/problem/B1

package main

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

func Solve(n int, k int, ids []int) []int {
	queue := []int{}
	idSet := make(map[int]bool)
	convos := 0
	for _, elem := range ids {
		if !idSet[elem] && convos < k {
			idSet[elem] = true
			queue = append([]int{elem}, queue...)
			convos += 1
		} else if !idSet[elem] && convos == k {
			idSet[queue[convos-1]] = false
			idSet[elem] = true
			queue = queue[:convos-1]
			queue = append([]int{elem}, queue...)
		}
	}
	return queue
}

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

	var n, k int
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	ids := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &ids[i])
	}
	fmt.Fscanf(reader, "\n")

	solution := Solve(n, k, ids)
	fmt.Fprintf(writer, "%d\n", len(solution))
	for _, elem := range solution {
		fmt.Fprintf(writer, "%d ", elem)
	}
	fmt.Fprintf(writer, "\n")
}

package main
import (
  "fmt"
  "strconv"
  "strings"
)
type Screen int
var inQueue map[Screen]bool = map[Screen]bool{}
func (c Screen)Set(b bool) {
  if b {
    inQueue[c] = true
  } else {
    delete(inQueue, c)
  }
}
func (c Screen)Get() bool {
  _,x := inQueue[c]
  return x
}
type Queue struct {
  Screens []Screen
  Maxlen int
}
func (q*Queue)Len() int {
  return len(q.Screens)
}

func (q*Queue)Push(s Screen) *Screen {
  var x *Screen
  if q.Len() >= q.Maxlen {
    x = &q.Screens[0]
    q.Screens = q.Screens[1:]
  }
  q.Screens = append(q.Screens, s)
  return x
}

func(q*Queue)Pop() *Screen {
  if q.Len()==0 {
    return nil
  }
  x := &q.Screens[0]
  q.Screens = q.Screens[1:]
  return x
}

func rts(a []Screen) []string {
  k := []string{}
  for i:=len(a)-1;i>=0;i-- {
    k = append(k, strconv.Itoa(int(a[i])))
  }
  return k
}

func main() {
  var n,k int
  var a Screen
  fmt.Scanf("%d%d", &n, &k)
  fmt.Println("n:", n)
  fmt.Println("k:", k)
  q := Queue{Maxlen:k}
  for i:=0;i<n;i++ {
    fmt.Scanf("%d", &a)
    fmt.Println("read:",a)
    if !a.Get() {
      a.Set(true)
      b := q.Push(a)
      if b!=nil {
        if a == *b {
          panic("")
        }
        b.Set(false)
      }
    }
  }
  fmt.Println(q.Len())
  fmt.Println(strings.Join(rts(q.Screens), " "))
}

package main
import (
  "fmt"
  "strconv"
  "strings"
)
type Screen int
var inQueue map[Screen]bool = map[Screen]bool{}
func (c Screen)Set(b bool) {
  if b {
    inQueue[c] = true
  } else {
    delete(inQueue, c)
  }
}
func (c Screen)Get() bool {
  _,x := inQueue[c]
  return x
}
type Queue struct {
  Screens []Screen
  Maxlen int
}
func (q*Queue)Len() int {
  return len(q.Screens)
}

func (q*Queue)Push(s Screen) *Screen {
  var x *Screen
  if q.Len() >= q.Maxlen {
    x = &q.Screens[0]
    q.Screens = q.Screens[1:]
  }
  q.Screens = append(q.Screens, s)
  return x
}

func(q*Queue)Pop() *Screen {
  if q.Len()==0 {
    return nil
  }
  x := &q.Screens[0]
  q.Screens = q.Screens[1:]
  return x
}

func rts(a []Screen) []string {
  k := []string{}
  for i:=len(a)-1;i>=0;i-- {
    k = append(k, strconv.Itoa(int(a[i])))
  }
  return k
}

func main() {
  var n,k int
  var a Screen
  fmt.Scanf("%d%d", &n, &k)
  q := Queue{Maxlen:k}
  for i:=0;i<n;i++ {
    fmt.Scanf("%d", &a)
    if !a.Get() {
      a.Set(true)
      b := q.Push(a)
      if b!=nil {
        if a == *b {
          panic("")
        }
        b.Set(false)
      }
    }
  }
  fmt.Println(q.Len())
  fmt.Println(strings.Join(rts(q.Screens), " "))
}


There are $$$n$$$ rectangles in a row. You can either turn each rectangle by $$$90$$$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of rectangles. Each of the next $$$n$$$ lines contains two integers $$$w_i$$$ and $$$h_i$$$ ($$$1 \leq w_i, h_i \leq 10^9$$$) — the width and the height of the $$$i$$$-th rectangle.

Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO". You can print each letter in any case (upper or lower).

NoteIn the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].In the second test, there is no way the second rectangle will be not higher than the first one.

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() int {
	var ch byte
	var err error
	for {
		ch, err = reader.ReadByte()
		if err != nil {
			return 0
		}
		if unicode.IsDigit(rune(ch)) {
			break
		}
	}
	result := int(ch & 0xf)
	for {
		ch, err = reader.ReadByte()
		if err != nil || !unicode.IsDigit(rune(ch)) {
			return result
		}
		result = result*10 + int(ch&0xf)
	}
	return result
}

const M int = 1e5 + 5

var (
	n, x, y int
	a, b [M]int
)

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

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

func main() {
	n = readInt()
	for i := 0; i < n; i++ {
		x, y = readInt(), readInt()
		a[i] = max(x, y)
		b[i] = min(x, y)
	}
	last_pick := b[n-1]
	for i := n-1; i > 0; i-- {
		if last_pick <= b[i-1] {
			last_pick = b[i-1]
			continue
		}
		if last_pick <= a[i-1] {
			last_pick = a[i-1]
			continue
		}
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
	return
}

// You can edit this code!
// Click here and start typing.
package main

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var n int
	res := true
	pre := int(1e9) + 15
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n)
	for i := 1; i <= n; i++ {
		var a, b int
		scanner.Scan()
		fmt.Sscan(scanner.Text(), &a, &b)
		if a < b {
			a, b = b, a
		}
		if pre >= a {
			pre = a
		} else if pre >= b {
			pre = b
		} else {
			res = false
		}
	}
	if res {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() int {
	var ch byte
	var err error
	for {
		ch, err = reader.ReadByte()
		if err != nil {
			return 0
		}
		if unicode.IsDigit(rune(ch)) {
			break
		}
	}
	result := int(ch & 0xf)
	for {
		ch, err = reader.ReadByte()
		if err != nil || !unicode.IsDigit(rune(ch)) {
			return result
		}
		result = result*10 + int(ch&0xf)
	}
	return result
}

func solve() bool {
	n := readInt()
	cur := math.MaxInt32
	for i := 0; i < n; i++ {
		a, b := readInt(), readInt()
		if a < b {
			a, b = b, a
		}
		if cur >= a {
			cur = a
		} else if cur >= b {
			cur = b
		} else {
			return false
		}
	}
	return true
}

func main() {
	if solve() {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	mx := int(1e9)
	for i := 0; i < N; i++ {
		C, D := sc.NextInt(), sc.NextInt()

		Q1 := max(C, D)
		Q2 := min(C, D)
		if mx >= Q1 {
			mx = Q1
		} else if mx >= Q2 {
			mx = Q2
		} else {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	for {
		var n int
		_, err := fmt.Scanln(&n)
		if err != nil {
			break
		}

		last := math.MaxInt32
		res := "YES"
		for i := 0; i < n; i++ {
			var w, h int
			fmt.Fscanf(in, "%d%d\n", &w, &h)
			//fmt.Println(w, h)
			if w <= last && h <= last {
				if w >= h {
					last = w
				} else {
					last = h
				}
			} else if w <= last && h > last {
				last = w
			} else if h <= last && w > last {
				last = h
			} else {
				res = "NO"
			}
		}

		fmt.Println(res)
	}
}

package main

import "fmt"

const M int = 1e5 + 5

var (
	n, x, y int
	a, b [M]int
)

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

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

func main() {
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scanln(&x, &y)
		a[i] = max(x, y)
		b[i] = min(x, y)
	}
	last_pick := b[n-1]
	for i := n-1; i > 0; i-- {
		if last_pick <= b[i-1] {
			last_pick = b[i-1]
			continue
		}
		if last_pick <= a[i-1] {
			last_pick = a[i-1]
			continue
		}
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
	return
}

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"
)

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

func main() {
	var n int
	res := true
	pre := int(1e9) + 15
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		if a < b {
			a, b = b, a
		}
		if pre >= a {
			pre = a
		} else if pre >= b {
			pre = b
		} else {
			res = false
			return
		}
	}
	if res {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	mx := int(1e6)
	for i := 0; i < N; i++ {
		C, D := sc.NextInt(), sc.NextInt()

		Q1 := max(C, D)
		Q2 := min(C, D)
		if mx >= Q1 {
			mx = Q1
		} else if mx >= Q2 {
			mx = Q2
		} else {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")

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

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


You are given a permutation $$$a$$$ of size $$$n$$$ and you should perform $$$n$$$ operations on it. In the $$$i$$$-th operation, you can choose a non-empty suffix of $$$a$$$ and increase all of its elements by $$$i$$$. How can we perform the operations to minimize the number of inversions in the final array?Note that you can perform operations on the same suffix any number of times you want.A permutation of size $$$n$$$ is an array of size $$$n$$$ such that each integer from $$$1$$$ to $$$n$$$ occurs exactly once in this array. A suffix is several consecutive elements of an array that include the last element of the array. An inversion in an array $$$a$$$ is a pair of indices $$$(i, j)$$$ such that $$$i > j$$$ and $$$a_{i} < a_{j}$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of the array. The second line contains $$$n$$$ distinct integers $$$a_{1}, a_{2}, \dots, a_{n}$$$ ($$$1 \le a_i \le n$$$), the initial permutation $$$a$$$. It's guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print $$$n$$$ integers $$$x_{1}, x_{2}, \ldots, x_{n}$$$ ($$$1 \le x_{i} \le n$$$ for each $$$1 \le i \le n$$$) indicating that the $$$i$$$-th operation must be applied to the suffix starting at index $$$x_{i}$$$. If there are multiple answers, print any of them.

NoteIn the first test case one of the optimal solutions is to increase the whole array on each operation (that is, choose the suffix starting at index $$$1$$$). The final array $$$[11, 12, 13, 14]$$$ contains $$$0$$$ inversions.In the second test case, $$$a$$$ will be equal to $$$[2, 4, 3, 5, 6]$$$, $$$[2, 4, 3, 7, 8]$$$, $$$[2, 4, 6, 10, 11]$$$, $$$[2, 8, 10, 14, 15]$$$ and $$$[7, 13, 15, 19, 20]$$$ after the first, second, third, fourth, and fifth operations, respectively. So the final array $$$a$$$ has zero inversions.

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
	for fmt.Fscan(r, &T); T > 0; T-- {

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

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

		b := make([][]int, 0, n)
		for i := 1; i < n; i++ {
			if a[i] < a[i-1] {
				b = append(b, []int{a[i-1] - a[i], i})
			}
		}
		sort.Slice(b, func(i, j int) bool { return b[i][0] < b[j][0] })

		for i := 0; i < n - len(b); i++ {
			fmt.Fprintf(w, "%d ", n)
		}
		for _, v := range b {
			fmt.Fprintf(w, "%d ", v[1]+1)
		}
		fmt.Fprintln(w, "")
	}

}

package main

import (
	"bufio"
	"fmt"
	"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 n int
		fmt.Fscan(in, &n)

		aa := make([]int, n+1)
		bb := make([]int, 1e5+5)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &aa[i])
			bb[aa[i]] = i
		}

		for i := 1; i <= n; i++ {
			fmt.Fprintf(out, "%d ", bb[n+1-i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

func solve() {
    var n int
    Fscan(in, &n)
    a := make([]int, n)
    for i := range a {
        Fscan(in, &a[i])
    }
    for i := n - 1; i > 0; i-- {
        a[i] = a[i - 1] - a[i]
    }
    a[0] = n

    b := make([]int, n)
    for i := range b {
        b[i] = i;
    }
    sort.Slice(b, func(i, j int) bool {
        return a[b[i]] < a[b[j]]
    })

    for _, v := range b {
        Fprint(out, v + 1, " ")
    }
    Fprint(out, "\n")
}

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}

package main

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

var in = bufio.NewReader(os.Stdin)

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

func pl(a ...interface{}) { fmt.Println(a...) }
func pf(format string, a ...interface{}) { fmt.Printf(format, a...) }
func scan(a ...interface{}) { fmt.Fscan(in, a...) }

func solve() {
  var n int
  scan(&n)
  a := make([]int, n)
  b := make([]string, n)
  for i := range a {
    scan(&a[i])
    diff := n - a[i]
    if diff == 0 {
      diff = n
    }
    b[diff-1] = fmt.Sprintf("%d", i+1)
  }
  pf("%s\n", strings.Join(b, " "))
}

func main() {
	var T int
	scan(&T)
	for ; T > 0; T-- {
    solve()
	}
}

func ys(b bool) string { return map[bool]string {true: "YES", false: "NO"}[b] }

package main

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

const cf = true

type data struct {
	diff int
	ind  int
}

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	diffs := make([]data, 0, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
		if i > 0 && arr[i] < arr[i-1] {
			diffs = append(diffs, data{diff: arr[i-1] - arr[i], ind: i})
		}
	}
	sort.Slice(diffs, func(i, j int) bool {
		return diffs[i].diff < diffs[j].diff
	})
	cur := 0
	for i := 1; i <= n; i++ {
		if cur == len(diffs) {
			fmt.Fprint(out, "1 ")
		} else {
			fmt.Fprint(out, diffs[cur].ind+1, " ")
			diffs[cur].diff -= i
			if diffs[cur].diff <= 0 {
				cur++
			}
		}
	}
	fmt.Fprintln(out)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func GCD(a, b int) int {
	for a != b {
		if a > b {
			a -= b
		} else {
			b -= a
		}
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

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

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

func _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

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

func sol(n int, a []int) []int {
	ret := make([]int, n)
	for i := range a {
		add := n - a[i]
		if add == 0 {
			add = n
		}
		ret[add-1] = i + 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
	for fmt.Fscan(r, &T); T > 0; T-- {

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

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

		b := make([][]int, 0, n)
		for i := 1; i < n; i++ {
			if a[i] < a[i-1] {
				b = append(b, []int{a[i-1] - a[i], i})
			}
		}
		sort.Slice(b, func(i, j int) bool { return b[i][0] < b[j][0] })

		for _, v := range b {
			fmt.Fprintf(w, "%d ", v[1]+1)
		}

		for i := len(b); i < n; i++ {
			fmt.Fprintf(w, "%d ", n)
		}
		fmt.Fprintln(w, "")
	}

}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

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

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

		res := n
		for i := 1; i < n; i++ {
			if a[i] < a[i-1] {
				res = i + 1
				break
			}
		}

		for i := 0; i < n-1; i++ {
			fmt.Fprintf(w, "%d ", n)
		}
		fmt.Fprintln(w, res)
	}

}

package main

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

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, done int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		m := make([]int, n)
		rr := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			if i > 0 {
				m[i] = max(m[i-1], a[i-1])
			}
		}

		for i := range a {
			if i > 0 { m[i] = max(m[i], a[i-1] + done) }

			if d := m[i] - a[i] - done; d > 0 {
				for j := done; j < done + d && j < n; j++ {
					rr[j] = i+1
				}
				done += d
			}
		}

		for _, v := range rr { fmt.Fprintf(w, "%d ", max(v, 1)) }
		fmt.Fprintln(w, "")
	}

}

package main

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

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, done int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		m := make([]int, n)
		rr := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			if i > 0 {
				m[i] = max(m[i-1], a[i-1])
			}
		}

		for i := range a {
			if i > 0 { m[i] = max(m[i], a[i-1] + done) }
			a[i] += done

			if d := m[i] - a[i]; d > 0 {
				for j := done; j < done + d && j < n; j++ {
					rr[j] = i+1
				}
				done += d
			}
		}

		for _, v := range rr { fmt.Fprintf(w, "%d ", max(v, 1)) }
		fmt.Fprintln(w, "")
	}

}

package main

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

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, done int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		m := make([]int, n)
		rr := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			if i > 0 {
				m[i] = max(m[i-1], a[i])
			}
		}

		for i := range a {
			if i > 0 { m[i] = max(m[i], a[i-1] + done) }
			a[i] += done

			if d := m[i] - a[i]; d > 0 {
				for j := done; j < done + d && j < n; j++ {
					rr[j] = i+1
				}
				done += d
			}
		}

		for _, v := range rr { fmt.Fprintf(w, "%d ", max(v, 1)) }
		fmt.Fprintln(w, "")
	}

}

package main

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

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, done int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		m := make([]int, n)
		rr := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			if i > 0 {
				m[i] = max(m[i-1], a[i])
			}
		}

		for i := range a {
			d := m[i] - a[i] - done
			if d > 0 {
				for j := done; j < done + d; j++ {
					rr[j] = i+1
				}
				done += d
			}
		}

		for i := range rr { fmt.Fprintf(w, "%d ", max(rr[i], 1)) }
		fmt.Fprintln(w, "")
	}

}

package main

import (
	"bufio"
	"fmt"
	"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 n int
		fmt.Fscan(in, &n)

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

		bb := make([]int, n)
		var pos int
		z := 1
	Loop:
		for i := 0; i < n-1; i++ {
			if aa[i] > aa[i+1] {
				d := aa[i+1]
				for aa[i] >= d {
					bb[pos] = i + 2
					pos++
					if pos >= n {
						break Loop
					}
					d += z
					z++
				}
			}
		}

		for i := pos; i < n; i++ {
			bb[i] = 1
		}
		for _, v := range bb {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

import (
	"bufio"
	"fmt"
	"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 n int
		fmt.Fscan(in, &n)

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

		bb := make([]int, n)
		var pos int
		z := 1
	Loop:
		for i := 0; i < n-1; i++ {
			if aa[i] > aa[i+1] {
				d := aa[i+1]
				for aa[i] > d {
					bb[pos] = i + 2
					pos++
					if pos >= n {
						break Loop
					}
					d += z
					z++
				}
			} else {
				z++
			}
		}

		for i := pos; i < n; i++ {
			bb[i] = 1
		}
		for _, v := range bb {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

import (
	"bufio"
	"fmt"
	"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 n int
		fmt.Fscan(in, &n)

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

		var c int
	Loop:
		for i := n - 1; i > 0; i-- {
			if c >= n {
				break
			}
			for aa[i] < aa[i-1] {
				aa[i]++
				fmt.Fprintf(out, "%d ", i+1)
				c++
				if c >= n {
					break Loop
				}
			}
		}

		for i := c; i < n; i++ {
			fmt.Fprintf(out, "%d ", 1)
		}
		fmt.Fprintln(out)
	}
}

package main

import (
	"bufio"
	"fmt"
	"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 n int
		fmt.Fscan(in, &n)

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

		var c int
		bb := make([]int, n)
		var pos int
		for i := n - 1; i > 0; i-- {
			if aa[i]+c < aa[i-1]+c {
				d := aa[i-1] - aa[i]
				c += d
				for j := 0; j < d; j++ {
					if pos < n {
						bb[pos] = i + 1
						pos++
					}
				}
			}
		}

		for i := pos; i < n; i++ {
			bb[i] = n
		}
		for _, v := range bb {
			// for i := v - 1; i < n; i++ {
			// 	aa[i]++
			// }
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)

		// if !sort.IsSorted(sort.IntSlice(aa)) {
		// 	fmt.Fprintln(out, "false")
		// 	fmt.Fprintln(out, orig)
		// 	fmt.Fprintln(out, aa)
		// }
	}
}

package main

import (
	"bufio"
	"fmt"
	"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 n int
		fmt.Fscan(in, &n)

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

		var c int
		bb := make([]int, n)
		var pos int
		for i := 0; i < n-1; i++ {
			if aa[i]+c > aa[i+1]+c {
				d := aa[i] - aa[i+1]
				c += d
				for j := 0; j < d; j++ {
					if pos < n {
						bb[pos] = i + 2
						pos++
					}
				}
			}
		}

		for i := pos; i < n; i++ {
			bb[i] = n
		}
		for _, v := range bb {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

import (
	"bufio"
	"fmt"
	"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 n int
		fmt.Fscan(in, &n)

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

		var c int
		for i := 0; i < n-1; i++ {
			if aa[i]+c > aa[i+1]+c {
				d := aa[i] - aa[i+1]
				c += d
				for j := 0; j < d; j++ {
					fmt.Fprintf(out, "%d ", i+2)
				}
			}
		}
		for i := c; i < n; i++ {
			fmt.Fprintf(out, "%d ", n)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

    op := 1
    ans := make([]int, 0, n)
    for i := n - 1; i > 0; i-- {
        if a[i] < a[i - 1] {
            for ; a[i] < a[i - 1]; op++ {
                ans = append(ans, i + 1)
                a[i] += op
            }
        }
    }

    for ; len(ans) < n; {
        ans = append(ans, 1)
    }

    for i := 0; i < n; i++ {
        Fprint(out, ans[i], " ")
    }
    Fprint(out, "\n")
}

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}

package main

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

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

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

    op := 1
    var ans []int
    for i := 1; i < n; i++ {
        if a[i] < a[i - 1] {
            for ; a[i] < a[i - 1]; op++ {
                ans = append(ans, i + 1)
                a[i] += op
            }
        }
    }

    for ; len(ans) < n; {
        ans = append(ans, 1)
    }

    for i := 0; i < n; i++ {
        Fprint(out, ans[i], " ")
    }
    Fprint(out, "\n")
}

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}


You are given an undirected graph with $$$n$$$ vertices and $$$m$$$ edges. Also, you are given an integer $$$k$$$.Find either a clique of size $$$k$$$ or a non-empty subset of vertices such that each vertex of this subset has at least $$$k$$$ neighbors in the subset. If there are no such cliques and subsets report about it.A subset of vertices is called a clique of size $$$k$$$ if its size is $$$k$$$ and there exists an edge between every two vertices from the subset. A vertex is called a neighbor of the other vertex if there exists an edge between them.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. The next lines contain descriptions of test cases. The first line of the description of each test case contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1 \leq n, m, k \leq 10^5$$$, $$$k \leq n$$$). Each of the next $$$m$$$ lines contains two integers $$$u, v$$$ $$$(1 \leq u, v \leq n, u \neq v)$$$, denoting an edge between vertices $$$u$$$ and $$$v$$$. It is guaranteed that there are no self-loops or multiple edges. It is guaranteed that the sum of $$$n$$$ for all test cases and the sum of $$$m$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case:  If you found a subset of vertices such that each vertex of this subset has at least $$$k$$$ neighbors in the subset in the first line output $$$1$$$ and the size of the subset. On the second line output the vertices of the subset in any order. If you found a clique of size $$$k$$$ then in the first line output $$$2$$$ and in the second line output the vertices of the clique in any order. If there are no required subsets and cliques print $$$-1$$$. If there exists multiple possible answers you can print any of them.

NoteIn the first test case: the subset $$$\{1, 2, 3, 4\}$$$ is a clique of size $$$4$$$.In the second test case: degree of each vertex in the original graph is at least $$$3$$$. So the set of all vertices is a correct answer.In the third test case: there are no cliques of size $$$4$$$ or required subsets, so the answer is $$$-1$$$.

package main

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

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

	var T, n, m, k, v, w int
t:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		g := make([]map[int]bool, n)
		for i := range g {
			g[i] = map[int]bool{}
		}
		deg := make([]int, n)
		for ; m > 0; m-- {
			Fscan(in, &v, &w)
			v--
			w--
			g[v][w] = true
			g[w][v] = true
			deg[v]++
			deg[w]++
		}
		left := n
		del := make([]bool, n)
		q := []int{}
		for i, d := range deg {
			if d < k {
				del[i] = true
				q = append(q, i)
			}
		}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			left--
			if deg[v] == k-1 {
				a := []int{}
				for w := range g[v] {
					if deg[w] >= k-1 {
						a = append(a, w)
					}
				}
				if len(a) == k-1 {
					for i, v := range a {
						for _, w := range a[:i] {
							if !g[v][w] {
								goto o
							}
						}
					}
					Fprint(out, "2\n", v+1, " ")
					for _, v := range a {
						Fprint(out, v+1, " ")
					}
					Fprintln(out)
					continue t
				}
			}
		o:
			deg[v] = 0
			for w := range g[v] {
				deg[w]--
				if deg[w] < k && !del[w] {
					del[w] = true
					q = append(q, w)
				}
			}
		}
		if left > 0 {
			Fprintln(out, 1, left)
			for i, d := range del {
				if !d {
					Fprint(out, i+1, " ")
				}
			}
			Fprintln(out)
		} else {
			Fprintln(out, -1)
		}
	}
}

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

package main

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

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

	var T, n, m, k, v, w int
t:
	for Fscan(I, &T); T > 0; T-- {
		Fscan(I, &n, &m, &k)
		g := make([]map[int]bool, n)
		for i := range g {
			g[i] = map[int]bool{}
		}
		d := make([]int, n)
		for ; m > 0; m-- {
			Fscan(I, &v, &w)
			v--
			w--
			g[v][w] = true
			g[w][v] = true
			d[v]++
			d[w]++
		}
		left := n
		del := make([]bool, n)
		q := []int{}
		for i, v := range d {
			if v < k {
				del[i] = true
				q = append(q, i)
			}
		}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			left--
			if d[v] == k-1 {
				a := []int{}
				for w := range g[v] {
					if d[w] >= k-1 {
						a = append(a, w)
					}
				}
				if len(a) == k-1 {
					for i, v := range a {
						for _, w := range a[:i] {
							if !g[v][w] {
								goto o
							}
						}
					}
					Fprint(O, "2\n", v+1, " ")
					for _, v := range a {
						Fprint(O, v+1, " ")
					}
					Fprintln(O)
					continue t
				}
			}
		o:
			d[v] = 0
			for w := range g[v] {
				if d[w]--; d[w] < k && !del[w] {
					del[w] = true
					q = append(q, w)
				}
			}
		}
		if left > 0 {
			Fprintln(O, 1, left)
			for i, d := range del {
				if !d {
					Fprint(O, i+1, " ")
				}
			}
			Fprintln(O)
		} else {
			Fprintln(O, -1)
		}
	}
}

package main

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

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

	var T, n, m, k, v, w int
t:
	for Fscan(I, &T); T > 0; T-- {
		Fscan(I, &n, &m, &k)
		g := make([]map[int]bool, n)
		for i := range g {
			g[i] = map[int]bool{}
		}
		d := make([]int, n)
		for ; m > 0; m-- {
			Fscan(I, &v, &w)
			v--
			w--
			g[v][w] = true
			g[w][v] = true
			d[v]++
			d[w]++
		}
		left := n
		del := make([]bool, n)
		q := []int{}
		for i, v := range d {
			if v < k {
				del[i] = true
				q = append(q, i)
			}
		}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			left--
			if d[v] == k-1 {
				a := []int{}
				for w := range g[v] {
					if d[w] >= k-1 {
						a = append(a, w)
					}
				}
				if len(a) == k-1 {
					for i, v := range a {
						for _, w := range a[:i] {
							if !g[v][w] {
								goto o
							}
						}
					}
					Fprint(O, "2\n", v+1, " ")
					for _, v := range a {
						Fprint(O, v+1, " ")
					}
					Fprintln(O)
					continue t
				}
			}
		o:
			for w := range g[v] {
				if d[w]--; d[w] < k && !del[w] {
					del[w] = true
					q = append(q, w)
				}
			}
		}
		if left > 0 {
			Fprintln(O, 1, left)
			for i, d := range del {
				if !d {
					Fprint(O, i+1, " ")
				}
			}
			Fprintln(O)
		} else {
			Fprintln(O, -1)
		}
	}
}

package main

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

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

	solve := func(Case int) {
		var n, m, k int
		Fscan(in, &n, &m, &k)

		g := make([][]int, n)
		has := make([]map[int]bool, n)
		for i := range has {
			has[i] = map[int]bool{}
		}
		for i := 0; i < m; i++ {
			var v, w int
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
			has[v][w] = true
			has[w][v] = true
		}

		if k*(k-1)/2 > m {
			Fprintln(out, -1)
			return
		}

		cntV := 0
		for _, vs := range g {
			if len(vs) >= k-1 {
				cntV++
			}
		}
		if cntV < k {
			Fprintln(out, -1)
			return
		}

		if k == 1 {
			Fprintln(out, 2)
			Fprintln(out, 1)
			return
		}

		calc := func(k int, check bool) []int {
			var ans []int
			vis := make([]bool, n)
			var f func(int) bool
			f = func(v int) bool {
				vis[v] = true
				c := 0
				for _, w := range g[v] {
					if len(g[w]) >= k {
						c++
					}
				}
				if c < k {
					return false
				}

				// todo   暴力即可？
				c = 0
				for _, w := range g[v] {
					if !vis[w] {
						if f(w) {
							c++
						}
					} else {
						c++
					}
				}
				if c >= k {
					ans = append(ans, v)
				}
				return c >= k
			}

			for i, vs := range g {
				if len(vs) == k && !vis[i] {
					ans = nil
					if f(i) {
						if check {
							// remove
							mp := map[int]bool{}
						o2:
							for _, v := range ans {
								for w := range mp {
									if !has[v][w] {
										continue o2
									}
								}
								mp[v] = true
								if len(mp) == k+1 {
									keys := make([]int, 0, len(mp))
									for k := range mp {
										keys = append(keys, k)
									}
									return keys
								}
							}
							if len(mp) < k+1 {
								continue
							}
						}

						return ans
					}
				}
			}
			return nil
		}

		ans := calc(k,false)
		if ans != nil {
			Fprintln(out, 1, len(ans))
			for _, v := range ans {
				Fprint(out, v+1, " ")
			}
			Fprintln(out)
			return
		}

		ans = calc(k - 1,true)
		if len(ans) < k {
			Fprintln(out, -1)
			return
		}

		Fprintln(out, 2)
		for _, v := range ans {
			Fprint(out, v+1, " ")
		}
		Fprintln(out)
	}

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

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