package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
var _ = fmt.Println
var _ = sort.Sort

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

	N := ReadInt32()
	outputs := make([]int, N)
	prevMax := 0
	for i := 0; i < N; i += 1 {
		pattern := []byte(ReadString())
		if num := getPatternMax(pattern); num <= prevMax {
			writer.WriteString("NO")
			return
		} else {
			for j := 0; j < len(pattern); j += 1 {
				if pattern[j] == '?' {
					for k := 0; k < 10; k += 1 {
						if j == 0 && k == 0 {
							continue
						}
						pattern[j] = byte(k) + '0'
						if getPatternMax(pattern) > prevMax {
							break
						}
					}
				}
			}
			n := getPatternMax(pattern)
			prevMax = n
			outputs[i] = n
		}
	}
	writer.WriteString("YES")
	for _, n := range outputs {
		writer.WriteString("\n")
		PrintInts(n)
	}
}

func getPatternMax(pattern []byte) int {
	n := 0
	for i := 0; i < len(pattern); i += 1 {
		n *= 10
		if pattern[i] == '?' {
			n += 9
		} else {
			n += int(pattern[i] - '0')
		}
	}
	return n
}

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

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 PrintInts64(ints ...int64) {
	for i, value := range ints {
		writer.WriteString(strconv.FormatInt(value, 10))
		if i != len(ints)-1 {
			writer.WriteByte(' ')
		}
	}
}

func PrintInts(ints ...int) {
	for i, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		if i != len(ints)-1 {
			writer.WriteByte(' ')
		}
	}
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
var _ = fmt.Println
var _ = sort.Sort

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

	N := ReadInt32()
	outputs := make([]int, N)
	pattern := ReadString()
	prevMax, _, _, _ := getPatternMeta(pattern)
	outputs[0] = prevMax
	for i := 1; i < N; i += 1 {
		pattern = ReadString()
		if num, ok := getNumber(pattern, prevMax); !ok {
			writer.WriteString("NO")
			return
		} else {
			outputs[i] = num
			prevMax = num
		}
	}
	writer.WriteString("YES")
	for _, n := range outputs {
		writer.WriteString("\n")
		PrintInts(n)
	}
}

func getNumber(pattern string, prevMax int) (int, bool) {
	if num, err := strconv.Atoi(pattern); err == nil {
		return num, num > prevMax
	}
	// we found some ? mark
	low, high, start, end := getPatternMeta(pattern)
	if low >= high || high <= prevMax {
		return -1, false
	}
	if low > prevMax {
		return low, true
	}
	return findNumber(pattern, prevMax, start, end)
}

func adjustStart(pattern string, prevMax int) int {
	digits := make([]string, 0)
	for i := len(pattern) - 1; i >= 0; i -= 1 {
		mod := prevMax % 10
		prevMax /= 10
		if pattern[i] == '?' {
			digits = append([]string{strconv.Itoa(mod)}, digits...)
		}
	}
	v, _ := strconv.Atoi(strings.Join(digits, ""))
	return v
}

func findNumber(pattern string, prevMax, low, high int) (int, bool) {
	start := low
	end := high
	for start <= end {
		mid := start + (end-start)/2
		midN := createNumber(pattern, mid)
		if midN == prevMax {
			start = mid + 1
			break
		}
		if midN > prevMax {
			end = mid - 1
		} else {
			start = mid + 1
		}
	}
	if start > high {
		return -1, false
	}
	num := createNumber(pattern, start)
	return num, num > prevMax
}

func createNumber(pattern string, mask int) int {
	newData := []byte(pattern)
	for i := len(newData) - 1; i >= 0; i -= 1 {
		if newData[i] == '?' {
			mod := mask % 10
			mask /= 10
			if mod == 0 && i == 0 {
				newData[i] = byte(1)
			} else {
				newData[i] = byte(mod)
			}
		} else {
			newData[i] -= '0'
		}
	}
	ans := 0
	for i := 0; i < len(newData); i += 1 {
		ans = ans * 10 + int(newData[i])
	}
	return ans
}

func getPatternMeta(pattern string) (low, high, start, end int) {
	qDigits := 0
	if pattern[0] == '?' {
		low, high = 1, 9
		start = 1
		qDigits++
	} else {
		val, _ := strconv.Atoi(string(pattern[0]))
		low, high = val, val
	}
	for i := 1; i < len(pattern); i += 1 {
		if pattern[i] == '?' {
			low = low * 10
			high = high*10 + 9
			qDigits++
		} else {
			val, _ := strconv.Atoi(string(pattern[i]))
			low = low*10 + val
			high = high*10 + val
		}
	}
	end = 9
	for i := 1; i < qDigits; i += 1 {
		start *= 10
		end = end*10 + 9
	}

	return
}

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

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 PrintInts64(ints ...int64) {
	for i, value := range ints {
		writer.WriteString(strconv.FormatInt(value, 10))
		if i != len(ints)-1 {
			writer.WriteByte(' ')
		}
	}
}

func PrintInts(ints ...int) {
	for i, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		if i != len(ints)-1 {
			writer.WriteByte(' ')
		}
	}
}

//http://codeforces.com/problemset/problem/490/E

package main

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

func main() {
	reader := NewStdReader(os.Stdin)
	n := reader.ReadInt()

	input := make([]string, n)
	results := make([]string, n)

	pre := []byte{}
	for i := 0; i < n; i++ {
		s := reader.ReadBytes()
		input[i] = string(s)

		if len(s) > len(pre) {
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if j == 0 {
						s[j] = '1'
					} else {
						s[j] = '0'
					}
				}
			}

			results[i] = string(s)
			pre = s
		} else if len(s) == len(pre) {
			set0 := false
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if set0 {
						s[j] = '0'
					}
				} else {
					if s[j] != pre[j] {
						set0 = true
					}
				}
			}

			greater := false
			for j := len(s) - 1; j >= 0; j-- {
				if s[j] == '?' {
					if greater {
						s[j] = pre[j]
					} else {
						if pre[j] < '9' {
							s[j] = pre[j] + 1
							greater = true
						} else {
							s[j] = '0'
						}
					}
				} else {
					if s[j] > pre[j] {
						greater = true
					} else if s[j] < pre[j] {
						greater = false
					}
				}
			}
			if !greater {
				fmt.Print("NO")
				return
			}

			results[i] = string(s)
			pre = s
		} else {
			fmt.Print("NO")
			return
		}
	}

	for i := 0; i < n; i++ {
		if i > 0 {
			if len(results[i]) <= len(results[i-1]) && results[i] < results[i-1] {
				fr := i - 2
				to := i + 2
				if fr < 0 {
					fr = 0
				}
				if to > n-1 {
					to = n - 1
				}
				fmt.Println("BUG ", results[fr:to], input[fr:to])
			}
		}
	}

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

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadBytes() []byte {
	r := []byte{}
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if (b >= '0' && b <= '9') || b == '?' {
			r = append(r, b)
			ok = true
		} else {
			if ok {
				break
			}
		}
	}

	return r
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
var _ = fmt.Println
var _ = sort.Sort

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

	N := ReadInt32()
	outputs := make([]int, N)
	pattern := ReadString()
	prevMax, _, _, _ := getPatternMeta(pattern)
	outputs[0] = prevMax
	for i := 1; i < N; i += 1 {
		pattern = ReadString()
		if num, ok := getNumber(pattern, prevMax); !ok {
			writer.WriteString("NO")
			return
		} else {
			outputs[i] = num
			prevMax = num
		}
	}
	writer.WriteString("YES")
	for _, n := range outputs {
		writer.WriteString("\n")
		PrintInts(n)
	}
}

func getNumber(pattern string, prevMax int) (int, bool) {
	if num, err := strconv.Atoi(pattern); err == nil {
		return num, num > prevMax
	}
	// we found some ? mark
	low, high, start, end := getPatternMeta(pattern)
	if low >= high || high <= prevMax {
		return -1, false
	}
	if low > prevMax {
		return low, true
	}
	return findNumber(pattern, prevMax, start, end)
}

func adjustStart(pattern string, prevMax int) int {
	digits := make([]string, 0)
	for i := len(pattern) - 1; i >= 0; i -= 1 {
		mod := prevMax % 10
		prevMax /= 10
		if pattern[i] == '?' {
			digits = append([]string{strconv.Itoa(mod)}, digits...)
		}
	}
	v, _ := strconv.Atoi(strings.Join(digits, ""))
	return v
}

func findNumber(pattern string, prevMax, low, high int) (int, bool) {
	start := adjustStart(pattern, prevMax)
	end := high
	for start <= end {
		mid := start + (end-start)/2
		midN := createNumber(pattern, mid)
		if midN == prevMax {
			start = mid + 1
			break
		}
		if midN > prevMax {
			end = mid - 1
		} else {
			start = mid + 1
		}
	}
	if start > high {
		return -1, false
	}
	num := createNumber(pattern, start)
	return num, num > prevMax
}

func createNumber(pattern string, mask int) int {
	newData := make([]string, len(pattern))
	for i := len(pattern) - 1; i >= 0; i -= 1 {
		if pattern[i] == '?' {
			mod := mask % 10
			mask /= 10
			if mod == 0 && i == 0 {
				newData[i] = "1"
			} else {
				newData[i] = strconv.Itoa(mod)
			}
		} else {
			newData[i] = string(pattern[i])
		}
	}
	ans, _ := strconv.Atoi(strings.Join(newData, ""))
	return ans
}

func getPatternMeta(pattern string) (low, high, start, end int) {
	qDigits := 0
	if pattern[0] == '?' {
		low, high = 1, 9
		start = 1
		qDigits++
	} else {
		val, _ := strconv.Atoi(string(pattern[0]))
		low, high = val, val
	}
	for i := 1; i < len(pattern); i += 1 {
		if pattern[i] == '?' {
			low = low * 10
			high = high*10 + 9
			qDigits++
		} else {
			val, _ := strconv.Atoi(string(pattern[i]))
			low = low*10 + val
			high = high*10 + val
		}
	}
	end = 9
	for i := 1; i < qDigits; i += 1 {
		start *= 10
		end = end*10 + 9
	}

	return
}

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

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 PrintInts64(ints ...int64) {
	for i, value := range ints {
		writer.WriteString(strconv.FormatInt(value, 10))
		if i != len(ints)-1 {
			writer.WriteByte(' ')
		}
	}
}

func PrintInts(ints ...int) {
	for i, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		if i != len(ints)-1 {
			writer.WriteByte(' ')
		}
	}
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
var _ = fmt.Println
var _ = sort.Sort

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

	N := ReadInt32()
	outputs := make([]int, N)
	prevMax := 0
	for i := 0; i < N; i += 1 {
		pattern := ReadString()
		if num, ok := getNumber(pattern, prevMax); !ok {
			writer.WriteString("NO")
			return
		} else {
			outputs[i] = num
			prevMax = num
		}
	}
	writer.WriteString("YES")
	for _, n := range outputs {
		writer.WriteString("\n")
		PrintInts(n)
	}
}

func getNumber(pattern string, prevMax int) (int, bool) {
	if num, err := strconv.Atoi(pattern); err == nil {
		return num, num > prevMax
	}
	// we found some ? mark
	low, high, start, end := getPatternMeta(pattern)
	if low >= high || high <= prevMax {
		return -1, false
	}
	if low > prevMax {
		return low, true
	}
	for start <= end {
		mid := start + (end-start)/2
		midN := createNumber(pattern, mid)
		if midN == prevMax {
			if mid == end {
				return -1, false
			}
			return createNumber(pattern, mid+1), true
		}
		if midN > prevMax {
			end = mid - 1
		} else {
			start = mid + 1
		}
	}
	num := createNumber(pattern, start)
	return num, num > prevMax
}

func createNumber(pattern string, mask int) int {
	newData := make([]string, len(pattern))
	for i := len(pattern) - 1; i >= 0; i -= 1 {
		if pattern[i] == '?' {
			mod := mask % 10
			mask /= 10
			if mod == 0 && i == 0 {
				newData[i] = "1"
			} else {
				newData[i] = strconv.Itoa(mod)
			}
		} else {
			newData[i] = string(pattern[i])
		}
	}
	ans, _ := strconv.Atoi(strings.Join(newData, ""))
	return ans
}

func getPatternMeta(pattern string) (low, high, start, end int) {
	qDigits := 0
	if pattern[0] == '?' {
		low, high = 1, 9
		start = 1
		qDigits++
	} else {
		val, _ := strconv.Atoi(string(pattern[0]))
		low, high = val, val
	}
	for i := 1; i < len(pattern); i += 1 {
		if pattern[i] == '?' {
			low = low * 10
			high = high*10 + 9
			qDigits++
		} else {
			val, _ := strconv.Atoi(string(pattern[i]))
			low = low*10 + val
			high = high*10 + val
		}
	}
	end = 9
	for i := 1; i < qDigits; i += 1 {
		start *= 10
		end = end*10 + 9
	}

	return
}

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

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 PrintInts64(ints ...int64) {
	for _, value := range ints {
		writer.WriteString(strconv.FormatInt(value, 10))
		writer.WriteByte(' ')
	}
}

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

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
var _ = fmt.Println
var _ = sort.Sort

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

	N := ReadInt32()
	outputs := make([]int, N)
	prevMax := 0
	for i := 0; i < N; i += 1 {
		pattern := ReadString()
		if num, ok := getNumber(pattern, prevMax); !ok {
			writer.WriteString("NO")
			return
		} else {
			outputs[i] = num
			prevMax = num
		}
	}
	writer.WriteString("YES")
	for _, n := range outputs {
		writer.WriteString("\n")
		PrintInts(n)
	}
}

func getNumber(pattern string, prevMax int) (int, bool) {
	if num, err := strconv.Atoi(pattern); err == nil {
		return num, num > prevMax
	}
	// we found some ? mark
	low, high, start, end := getPatternMeta(pattern)
	if low >= high || high <= prevMax {
		return -1, false
	}
	if low > prevMax {
		return low, true
	}
	return findNumber(pattern, prevMax, start, end)
}

func findNumber(pattern string, prevMax, low, high int) (int, bool) {
	start, end := low, high
	for start <= end {
		mid := start + (end-start)/2
		midN := createNumber(pattern, mid)
		if midN == prevMax {
			start = mid + 1
			break
		}
		if midN > prevMax {
			end = mid - 1
		} else {
			start = mid + 1
		}
	}
	if start >= high {
		return -1, false
	}
	num := createNumber(pattern, start)
	return num, num > prevMax
}

func createNumber(pattern string, mask int) int {
	newData := make([]string, len(pattern))
	for i := len(pattern) - 1; i >= 0; i -= 1 {
		if pattern[i] == '?' {
			mod := mask % 10
			mask /= 10
			if mod == 0 && i == 0 {
				newData[i] = "1"
			} else {
				newData[i] = strconv.Itoa(mod)
			}
		} else {
			newData[i] = string(pattern[i])
		}
	}
	ans, _ := strconv.Atoi(strings.Join(newData, ""))
	return ans
}

func getPatternMeta(pattern string) (low, high, start, end int) {
	qDigits := 0
	if pattern[0] == '?' {
		low, high = 1, 9
		start = 1
		qDigits++
	} else {
		val, _ := strconv.Atoi(string(pattern[0]))
		low, high = val, val
	}
	for i := 1; i < len(pattern); i += 1 {
		if pattern[i] == '?' {
			low = low * 10
			high = high*10 + 9
			qDigits++
		} else {
			val, _ := strconv.Atoi(string(pattern[i]))
			low = low*10 + val
			high = high*10 + val
		}
	}
	end = 9
	for i := 1; i < qDigits; i += 1 {
		start *= 10
		end = end*10 + 9
	}

	return
}

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

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 PrintInts64(ints ...int64) {
	for i, value := range ints {
		writer.WriteString(strconv.FormatInt(value, 10))
		if i != len(ints)-1 {
			writer.WriteByte(' ')
		}
	}
}

func PrintInts(ints ...int) {
	for i, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		if i != len(ints)-1 {
			writer.WriteByte(' ')
		}
	}
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
var _ = fmt.Println
var _ = sort.Sort

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

	N := ReadInt32()
	outputs := make([]int, N)
	prevMax := 0
	for i := 0; i < N; i += 1 {
		pattern := ReadString()
		if num, ok := getNumber(pattern, prevMax); !ok {
			writer.WriteString("NO")
			return
		} else {
			outputs[i] = num
			prevMax = num
		}
	}
	writer.WriteString("YES\n")
	for _, n := range outputs {
		PrintInts(n)
		writer.WriteString("\n")
	}
}

func getNumber(pattern string, prevMax int) (int, bool) {
	if num, err := strconv.Atoi(pattern); err == nil {
		return num, num > prevMax
	}
	// we found some ? mark
	low, high, start, end := getPatternMeta(pattern)
	if low >= high || high <= prevMax {
		return -1, false
	}
	if low > prevMax {
		return low, true
	}
	for start <= end {
		mid := start + (end-start)/2
		midN := createNumber(pattern, mid)
		if midN == prevMax {
			if mid == end {
				return -1, false
			}
			return createNumber(pattern, mid+1), true
		}
		if midN > prevMax {
			end = mid - 1
		} else {
			start = mid + 1
		}
	}
	num := createNumber(pattern, start)
	return num, num > prevMax
}

func createNumber(pattern string, mask int) int {
	newData := make([]string, len(pattern))
	for i := len(pattern) - 1; i >= 0; i -= 1 {
		if pattern[i] == '?' {
			mod := mask % 10
			mask /= 10
			if mod == 0 && i == 0 {
				newData[i] = "1"
			} else {
				newData[i] = strconv.Itoa(mod)
			}
		} else {
			newData[i] = string(pattern[i])
		}
	}
	ans, _ := strconv.Atoi(strings.Join(newData, ""))
	return ans
}

func getPatternMeta(pattern string) (low, high, start, end int) {
	qDigits := 0
	if pattern[0] == '?' {
		low, high = 1, 9
		start = 1
		qDigits++
	} else {
		val, _ := strconv.Atoi(string(pattern[0]))
		low, high = val, val
	}
	for i := 1; i < len(pattern); i += 1 {
		if pattern[i] == '?' {
			low = low * 10
			high = high*10 + 9
			qDigits++
		} else {
			val, _ := strconv.Atoi(string(pattern[i]))
			low = low*10 + val
			high = high*10 + val
		}
	}
	end = 9
	for i := 1; i < qDigits; i += 1 {
		start *= 10
		end = end*10 + 9
	}

	return
}

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

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 PrintInts64(ints ...int64) {
	for _, value := range ints {
		writer.WriteString(strconv.FormatInt(value, 10))
		writer.WriteByte(' ')
	}
}

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

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
var _ = fmt.Println
var _ = sort.Sort

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

	N := ReadInt32()
	outputs := make([]int, N)
	prevMax := 0
	for i := 0; i < N; i += 1 {
		pattern := ReadString()
		if num, ok := getNumber(pattern, prevMax); !ok {
			writer.WriteString("NO")
			return
		} else {
			outputs[i] = num
			prevMax = num
		}
	}
	writer.WriteString("YES")
	for _, n := range outputs {
		writer.WriteString("\n")
		PrintInts(n)
	}
}

func getNumber(pattern string, prevMax int) (int, bool) {
	if num, err := strconv.Atoi(pattern); err == nil {
		return num, num > prevMax
	}
	// we found some ? mark
	low, high, start, end := getPatternMeta(pattern)
	if low >= high || high <= prevMax {
		return -1, false
	}
	if low > prevMax {
		return low, true
	}
	return findNumber(pattern, prevMax, start, end)
}

func findNumber(pattern string, prevMax, low, high int) (int, bool) {
	fmt.Println(pattern, prevMax, low, high)
	start, end := low, high
	for start <= end {
		mid := start + (end-start)/2
		midN := createNumber(pattern, mid)
		if midN == prevMax {
			start = mid + 1
			break
		}
		if midN > prevMax {
			end = mid - 1
		} else {
			start = mid + 1
		}
	}
	if start > high {
		return -1, false
	}
	num := createNumber(pattern, start)
	return num, num > prevMax
}

func createNumber(pattern string, mask int) int {
	newData := make([]string, len(pattern))
	for i := len(pattern) - 1; i >= 0; i -= 1 {
		if pattern[i] == '?' {
			mod := mask % 10
			mask /= 10
			if mod == 0 && i == 0 {
				newData[i] = "1"
			} else {
				newData[i] = strconv.Itoa(mod)
			}
		} else {
			newData[i] = string(pattern[i])
		}
	}
	ans, _ := strconv.Atoi(strings.Join(newData, ""))
	return ans
}

func getPatternMeta(pattern string) (low, high, start, end int) {
	qDigits := 0
	if pattern[0] == '?' {
		low, high = 1, 9
		start = 1
		qDigits++
	} else {
		val, _ := strconv.Atoi(string(pattern[0]))
		low, high = val, val
	}
	for i := 1; i < len(pattern); i += 1 {
		if pattern[i] == '?' {
			low = low * 10
			high = high*10 + 9
			qDigits++
		} else {
			val, _ := strconv.Atoi(string(pattern[i]))
			low = low*10 + val
			high = high*10 + val
		}
	}
	end = 9
	for i := 1; i < qDigits; i += 1 {
		start *= 10
		end = end*10 + 9
	}

	return
}

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

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 PrintInts64(ints ...int64) {
	for i, value := range ints {
		writer.WriteString(strconv.FormatInt(value, 10))
		if i != len(ints)-1 {
			writer.WriteByte(' ')
		}
	}
}

func PrintInts(ints ...int) {
	for i, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		if i != len(ints)-1 {
			writer.WriteByte(' ')
		}
	}
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
var _ = fmt.Println
var _ = sort.Sort

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

	N := ReadInt32()
	outputs := make([]int, N)
	prevMax := 0
	for i := 0; i < N; i += 1 {
		pattern := ReadString()
		if num, ok := getNumber(pattern, prevMax); !ok {
			writer.WriteString("NO")
			return
		} else {
			outputs[i] = num
			prevMax = num
		}
	}
	writer.WriteString("YES")
	for _, n := range outputs {
		writer.WriteString("\n")
		PrintInts(n)
	}
}

func getNumber(pattern string, prevMax int) (int, bool) {
	if num, err := strconv.Atoi(pattern); err == nil {
		return num, num > prevMax
	}
	// we found some ? mark
	low, high, start, end := getPatternMeta(pattern)
	if low >= high || high <= prevMax {
		return -1, false
	}
	if low > prevMax {
		return low, true
	}
	for start <= end {
		mid := start + (end-start)/2
		midN := createNumber(pattern, mid)
		if midN == prevMax {
			if mid == end {
				return -1, false
			}
			return createNumber(pattern, mid+1), true
		}
		if midN > prevMax {
			end = mid - 1
		} else {
			start = mid + 1
		}
	}
	num := createNumber(pattern, start)
	return num, num > prevMax
}

func createNumber(pattern string, mask int) int {
	newData := make([]string, len(pattern))
	for i := len(pattern) - 1; i >= 0; i -= 1 {
		if pattern[i] == '?' {
			mod := mask % 10
			mask /= 10
			if mod == 0 && i == 0 {
				newData[i] = "1"
			} else {
				newData[i] = strconv.Itoa(mod)
			}
		} else {
			newData[i] = string(pattern[i])
		}
	}
	ans, _ := strconv.Atoi(strings.Join(newData, ""))
	return ans
}

func getPatternMeta(pattern string) (low, high, start, end int) {
	qDigits := 0
	if pattern[0] == '?' {
		low, high = 1, 9
		start = 1
		qDigits++
	} else {
		val, _ := strconv.Atoi(string(pattern[0]))
		low, high = val, val
	}
	for i := 1; i < len(pattern); i += 1 {
		if pattern[i] == '?' {
			low = low * 10
			high = high*10 + 9
			qDigits++
		} else {
			val, _ := strconv.Atoi(string(pattern[i]))
			low = low*10 + val
			high = high*10 + val
		}
	}
	end = 9
	for i := 1; i < qDigits; i += 1 {
		start *= 10
		end = end*10 + 9
	}

	return
}

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

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 PrintInts64(ints ...int64) {
	for i, value := range ints {
		writer.WriteString(strconv.FormatInt(value, 10))
		if i != len(ints) - 1 {
			writer.WriteByte(' ')
		}
	}
}

func PrintInts(ints ...int) {
	for i, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		if i != len(ints) - 1 {
			writer.WriteByte(' ')
		}
	}
}

//http://codeforces.com/problemset/problem/490/E

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"io"
	"os"
)

func main() {
	reader := NewStdReader(os.Stdin)
	n := reader.ReadInt()

	results := list.New()

	pre := []byte{}
	for i := 0; i < n; i++ {
		s := reader.ReadBytes()

		if len(s) > len(pre) {
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if j == 0 {
						s[j] = '1'
					} else {
						s[j] = '0'
					}
				}
			}

			results.PushBack(string(s))
			pre = s
		} else if len(s) == len(pre) {
			set0 := false
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if set0 {
						s[j] = '0'
					}
				} else {
					if s[j] < pre[j] {
						set0 = true
					}
				}
			}

			greater := false
			for j := len(s) - 1; j >= 0; j-- {
				if s[j] == '?' {
					if greater {
						s[j] = pre[j]
					} else {
						if pre[j] < '9' {
							s[j] = pre[j] + 1
							greater = true
						} else {
							s[j] = '0'
						}
					}
				} else {
					if s[j] > pre[j] {
						greater = true
					}
				}
			}
			if !greater {
				fmt.Print("NO")
				return
			}

			results.PushBack(string(s))
			pre = s
		} else {
			fmt.Print("NO")
			return
		}
	}
	fmt.Println("YES")
	e := results.Front()
	for e != nil {
		fmt.Println(e.Value)
		e = e.Next()
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadBytes() []byte {
	r := []byte{}
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if (b >= '0' && b <= '9') || b == '?' {
			r = append(r, b)
			ok = true
		} else {
			if ok {
				break
			}
		}
	}

	return r
}

//http://codeforces.com/problemset/problem/490/E

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"io"
	"os"
)

func main() {
	reader := NewStdReader(os.Stdin)
	n := reader.ReadInt()

	results := list.New()

	pre := []byte{}
	for i := 0; i < n; i++ {
		s := reader.ReadBytes()

		if len(s) > len(pre) {
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if j == 0 {
						s[j] = '1'
					} else {
						s[j] = '0'
					}
				}
			}

			results.PushBack(string(s))
			pre = s
		} else if len(s) == len(pre) {
			set0 := false
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if set0 {
						s[j] = '0'
					}
				} else {
					if s[j] != pre[j] {
						set0 = true
					}
				}
			}

			greater := false
			for j := len(s) - 1; j >= 0; j-- {
				if s[j] == '?' {
					if greater {
						s[j] = pre[j]
					} else {
						if pre[j] < '9' {
							s[j] = pre[j] + 1
							greater = true
						} else {
							s[j] = '0'
						}
					}
				} else {
					if s[j] > pre[j] {
						greater = true
					}
				}
			}
			if !greater {
				fmt.Print("NO")
				return
			}

			results.PushBack(string(s))
			pre = s
		} else {
			fmt.Print("NO")
			return
		}
	}

	e := results.Front()
	test := ""
	for e != nil {
		s := e.Value.(string)
		if len(s) <= len(test) && s <= test {
			fmt.Println("BUG", test, s)
		}
		test = s
		e = e.Next()
	}

	fmt.Println("YES")
	e = results.Front()
	for e != nil {
		fmt.Println(e.Value)
		e = e.Next()
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadBytes() []byte {
	r := []byte{}
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if (b >= '0' && b <= '9') || b == '?' {
			r = append(r, b)
			ok = true
		} else {
			if ok {
				break
			}
		}
	}

	return r
}

//http://codeforces.com/problemset/problem/490/E

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"io"
	"os"
)

func main() {
	reader := NewStdReader(os.Stdin)
	n := reader.ReadInt()

	results := list.New()

	pre := []byte{}
	for i := 0; i < n; i++ {
		s := reader.ReadBytes()

		if len(s) > len(pre) {
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if j == 0 {
						s[j] = '1'
					} else {
						s[j] = '0'
					}
				}
			}

			results.PushBack(string(s))
			pre = s
		} else if len(s) == len(pre) {
			set0 := false
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if set0 {
						s[j] = '0'
					}
				} else {
					if s[j] != pre[j] {
						set0 = true
					}
				}
			}

			greater := false
			for j := len(s) - 1; j >= 0; j-- {
				if s[j] == '?' {
					if greater {
						s[j] = pre[j]
					} else {
						if pre[j] < '9' {
							s[j] = pre[j] + 1
							greater = true
						} else {
							s[j] = '0'
						}
					}
				} else {
					if s[j] > pre[j] {
						greater = true
					}
				}
			}
			if !greater {
				fmt.Print("NO")
				return
			}

			results.PushBack(string(s))
			pre = s
		} else {
			fmt.Print("NO")
			return
		}
	}
	fmt.Println("YES")
	e := results.Front()
	for e != nil {
		fmt.Println(e.Value)
		e = e.Next()
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadBytes() []byte {
	r := []byte{}
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if (b >= '0' && b <= '9') || b == '?' {
			r = append(r, b)
			ok = true
		} else {
			if ok {
				break
			}
		}
	}

	return r
}

//http://codeforces.com/problemset/problem/490/E

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"io"
	"os"
)

func main() {
	reader := NewStdReader(os.Stdin)
	n := reader.ReadInt()

	results := list.New()

	pre := []byte{}
	for i := 0; i < n; i++ {
		s := reader.ReadBytes()

		if len(s) > len(pre) {
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if j == 0 {
						s[j] = '1'
					} else {
						s[j] = '0'
					}
				}
			}

			results.PushBack(string(s))
			pre = s
		} else if len(s) == len(pre) {
			set0 := false
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if set0 {
						s[j] = '0'
					}
				} else {
					if s[j] != pre[j] {
						set0 = true
					}
				}
			}

			greater := false
			for j := len(s) - 1; j >= 0; j-- {
				if s[j] == '?' {
					if greater {
						s[j] = pre[j]
					} else {
						if pre[j] < '9' {
							s[j] = pre[j] + 1
							greater = true
						} else {
							s[j] = '0'
						}
					}
				} else {
					if s[j] > pre[j] {
						greater = true
					}
				}
			}
			if !greater {
				fmt.Print("NO")
				return
			}

			results.PushBack(string(s))
			pre = s
		} else {
			fmt.Print("NO")
			return
		}
	}

	e := results.Front()
	test := ""
	for e != nil {
		s := e.Value.(string)
		if s <= test {
			fmt.Println("BUG", test, s)
		}
		test = s
		e = e.Next()
	}

	fmt.Println("YES")
	e = results.Front()
	for e != nil {
		fmt.Println(e.Value)
		e = e.Next()
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadBytes() []byte {
	r := []byte{}
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if (b >= '0' && b <= '9') || b == '?' {
			r = append(r, b)
			ok = true
		} else {
			if ok {
				break
			}
		}
	}

	return r
}

//http://codeforces.com/problemset/problem/490/E

package main

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

func main() {
	reader := NewStdReader(os.Stdin)
	n := reader.ReadInt()

	input := make([]string, n)
	results := make([]string, n)

	pre := []byte{}
	for i := 0; i < n; i++ {
		s := reader.ReadBytes()
		input[i] = string(s)

		if len(s) > len(pre) {
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if j == 0 {
						s[j] = '1'
					} else {
						s[j] = '0'
					}
				}
			}

			results[i] = string(s)
			pre = s
		} else if len(s) == len(pre) {
			set0 := false
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if set0 {
						s[j] = '0'
					}
				} else {
					if s[j] != pre[j] {
						set0 = true
					}
				}
			}

			greater := false
			for j := len(s) - 1; j >= 0; j-- {
				if s[j] == '?' {
					if greater {
						s[j] = pre[j]
					} else {
						if pre[j] < '9' {
							s[j] = pre[j] + 1
							greater = true
						} else {
							s[j] = '0'
						}
					}
				} else {
					if s[j] > pre[j] {
						greater = true
					}
				}
			}
			if !greater {
				fmt.Print("NO")
				return
			}

			results[i] = string(s)
			pre = s
		} else {
			fmt.Print("NO")
			return
		}
	}

	for i := 0; i < n; i++ {
		if i > 0 {
			if len(results[i]) <= len(results[i-1]) && results[i] < results[i-1] {
				fr := i - 2
				to := i + 2
				if fr < 0 {
					fr = 0
				}
				if to > n-1 {
					to = n - 1
				}
				fmt.Println("BUG ", results[fr:to], input[fr:to])
			}
		}
	}

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

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadBytes() []byte {
	r := []byte{}
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if (b >= '0' && b <= '9') || b == '?' {
			r = append(r, b)
			ok = true
		} else {
			if ok {
				break
			}
		}
	}

	return r
}

//http://codeforces.com/problemset/problem/490/E

package main

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

func main() {
	reader := NewStdReader(os.Stdin)
	n := reader.ReadInt()

	input := make([]string, n)
	results := make([]string, n)

	pre := []byte{}
	for i := 0; i < n; i++ {
		s := reader.ReadBytes()
		input[i] = string(s)

		if len(s) > len(pre) {
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if j == 0 {
						s[j] = '1'
					} else {
						s[j] = '0'
					}
				}
			}

			results[i] = string(s)
			pre = s
		} else if len(s) == len(pre) {
			set0 := false
			for j := 0; j < len(s); j++ {
				if s[j] == '?' {
					if set0 {
						s[j] = '0'
					}
				} else {
					if s[j] != pre[j] {
						set0 = true
					}
				}
			}

			greater := false
			for j := len(s) - 1; j >= 0; j-- {
				if s[j] == '?' {
					if greater {
						s[j] = pre[j]
					} else {
						if pre[j] < '9' {
							s[j] = pre[j] + 1
							greater = true
						} else {
							s[j] = '0'
						}
					}
				} else {
					if s[j] > pre[j] {
						greater = true
					}
				}
			}
			if !greater {
				fmt.Print("NO")
				return
			}

			results[i] = string(s)
			pre = s
		} else {
			fmt.Print("NO")
			return
		}
	}

	for i := 0; i < n; i++ {
		if i > 0 {
			if len(results[i]) < len(results[i-1]) && results[i] < results[i-1] {
				fr := i - 2
				to := i + 2
				if fr < 0 {
					fr = 0
				}
				if to > n-1 {
					to = n - 1
				}
				fmt.Println("BUG ", results[fr:to], input[fr:to])
			}
		}
	}

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

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadBytes() []byte {
	r := []byte{}
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if (b >= '0' && b <= '9') || b == '?' {
			r = append(r, b)
			ok = true
		} else {
			if ok {
				break
			}
		}
	}

	return r
}


package main

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

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

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

func solve(n int) {
  if n == 0 {
    printf("1 1\n1")
    return
  }
  nbit := 0
  nn := n
  for nn > 0 {
    nbit++
    nn >>= 1
  }
  n32 := n
  n31 := 0
  n22 := 1<<uint(nbit) + n
  n21 := n
  n12 := 1 << uint(nbit)
  n11 := n22
  printf("3 2\n")
  printf("%d %d\n", n11, n12)
  printf("%d %d\n", n21, n22)
  printf("%d %d\n", n31, n32)
}

func main() {
  defer flush()

  var n int
  scanf("%d\n", &n)
  solve(n)
}

/*
URL:
https://codeforces.com/problemset/problem/1332/D
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	k int
)

func main() {
	k = ReadInt()

	n, m := 2, 3
	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
	}

	A[0][0] = 1<<17 + k
	A[0][1] = 1 << 17
	A[0][2] = 1 << 17
	A[1][0] = k
	A[1][1] = 1<<17 + k
	A[1][2] = k

	fmt.Println(n, m)
	for i := 0; i < n; i++ {
		fmt.Println(PrintIntsLine(A[i]...))
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func CF1332D() {
	k, I := 0, 1<<17
	Scan(&k)
	Println(2, 3)
	Println(I|k, I, 0)
	Println(k, I|k, k)
}

func main() { CF1332D() }

/*
URL:
https://codeforces.com/problemset/problem/1332/D
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	k int
)

func main() {
	k = ReadInt()

	n, m := 2, 3
	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
	}

	A[0][0] = 1<<18 + k
	A[0][1] = 1 << 18
	A[0][2] = 1 << 18
	A[1][0] = k
	A[1][1] = 1<<18 + k
	A[1][2] = k

	fmt.Println(n, m)
	for i := 0; i < n; i++ {
		fmt.Println(PrintIntsLine(A[i]...))
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

/*
URL:
https://codeforces.com/problemset/problem/1332/D
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	k int
)

func main() {
	k = ReadInt()

	n, m := 2, 3
	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
	}

	A[0][0] = 1<<20 + k
	A[0][1] = 1 << 20
	A[0][2] = 1 << 20
	A[1][0] = k
	A[1][1] = 1<<20 + k
	A[1][2] = k

	fmt.Println(n, m)
	for i := 0; i < n; i++ {
		fmt.Println(PrintIntsLine(A[i]...))
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func CF1332D() {
	k, I := 0, 1<<20
	Scan(&k)
	Println(2, 3)
	Println(I|k, I, 0)
	Println(k, I|k, k)
}

func main() { CF1332D() }

package main

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

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

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

func solve(n int) {
  if n == 0 {
    printf("1 1\n1")
    return
  }
  nbit := 0
  nn := n
  for nn > 0 {
    nbit++
    nn >>= 1
  }
  n32 := n
  n31 := 0
  n22 := 1<<uint(nbit) + n
  n21 := n
  n12 := 1 << uint(nbit)
  n11 := n22
  printf("%d %d\n", n11, n12)
  printf("%d %d\n", n21, n22)
  printf("%d %d\n", n31, n32)
}

func main() {
  defer flush()

  var n int
  scanf("%d\n", &n)
  solve(n)
}

package main

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

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

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

func solve(n int) {
  if n == 0 {
    printf("1 1\n1")
    return
  }
  nbit := 0
  nn := n
  for nn > 0 {
    nbit++
    nn >>= 1
  }
  n32 := 1<<uint(nbit+1) - 1
  n31 := 0
  n22 := 1<<uint(nbit+2) - 1
  n21 := n32
  n12 := 1<<uint(nbit+1) | (n32 - n)
  n11 := 1<<uint(nbit+2) - 1
  printf("3 2\n")
  printf("%d %d\n", n11, n12)
  printf("%d %d\n", n21, n22)
  printf("%d %d\n", n31, n32)
}

func main() {
  defer flush()

  var n int
  scanf("%d\n", &n)
  solve(n)
}

package main

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

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

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

func solve(n int) {
  if n == 0 {
    printf("1 1\n1")
    return
  }
  nbit := 0
  nn := n
  for nn > 0 {
    nbit++
    nn >>= 1
  }
  n32 := 1<<uint(nbit) - 1
  n31 := 0
  n22 := 1<<uint(nbit+1) - 1
  n21 := n32
  n12 := 1<<uint(nbit) | (n32 - n)
  n11 := n32
  printf("%d %d\n", n11, n12)
  printf("%d %d\n", n21, n22)
  printf("%d %d\n", n31, n32)
}

func main() {
  defer flush()

  var n int
  scanf("%d\n", &n)
  solve(n)
}


package main

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

type LinkF struct {
	next, pre *LinkF
	id, v     int
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, k int
	fmt.Fscanf(buf, "%d %d %d\n", &n, &k)
	nodes := make([]LinkF, n+1)
	rank := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(buf, "%d", &nodes[i].v)
		rank[nodes[i].v] = i
		nodes[i].id = i
		if i > 1 {
			nodes[i].pre = &nodes[i-1]
			nodes[i-1].next = &nodes[i]
		}
	}
	fmt.Fscanf(buf, "\n")
//	fmt.Printf("%v\n",rank)
	color := make([]int, n+1)
	team := 0
	for i := n; i >= 1; i-- {
		if color[rank[i]] != 0 {
			continue
		}
		color[rank[i]] = team + 1
		curl := nodes[rank[i]].pre
		for j := 0; j < k && curl != nil; j++ {
		//	fmt.Printf("pre=%d ",curl.id)
			color[curl.id] = team + 1
			curl = curl.pre
		}
		curr := nodes[rank[i]].next
		for j := 0; j < k && curr != nil; j++ {
	//		fmt.Printf("next=%d ",curr.id)
			color[curr.id] = team + 1
			curr = curr.next
		}
	//	fmt.Printf("\n")
		if curl != nil {
			curl.next = curr
		}
		if curr != nil {
			curr.pre = curl
		}
		team ^= 1
	}
	for i:=1;i <= n;i++{
		fmt.Printf("%d",color[i])
	}
	fmt.Printf("\n")

}

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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 getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n-1; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

type node struct {
	preIndex, index, nextIndex, value int
}

var n, k int
var ns []node
var ans []int

func putNodeTo(p *node, n int) {
	ans[p.index] = n
	l, r := p, p
	for i := 0; i < k && l.preIndex != -1; i++ {
		l = &ns[l.preIndex]
		ans[l.index] = n
	}
	for i := 0; i < k && r.nextIndex != -1; i++ {
		r = &ns[r.nextIndex]
		ans[r.index] = n
	}
	if l.preIndex != -1 && r.nextIndex != -1 {
		ns[l.preIndex].nextIndex, ns[r.nextIndex].preIndex = r.nextIndex, l.preIndex
	} else if l.preIndex != -1 {
		ns[l.preIndex].nextIndex = -1
	} else if r.nextIndex != -1 {
		ns[r.nextIndex].preIndex = -1
	}
}
func temp1() {
	n, k = getLine2Int2()
	inputs := getLine2Ints(n)
	ns = make([]node, n)
	for i := 0; i < n; i++ {
		ns[i].preIndex, ns[i].index, ns[i].value, ns[i].nextIndex = i-1, i, inputs[i], i+1
		if i+1 == n {
			ns[i].nextIndex = -1
		}
	}
}
func temp2() {
	ans = make([]int, n)
	type t struct {
		value, index int
	}
	ts := make([]t, n)
	for i := 0; i < n; i++ {
		ts[i].value, ts[i].index = ns[i].value, ns[i].index
	}
	sort.Slice(ts, func(i, j int) bool {
		return ts[i].value > ts[j].value
	})
	list := 1
	for i := 0; i < n; i++ {
		if ans[ts[i].index] == 0 {
			putNodeTo(&ns[ts[i].index], list)
			list = 3 - list
		}
	}
}
func temp3() {
	for i := 0; i < n; i++ {
		printf("%d", ans[i])
	}
	printf("\n")
}

func main() {
	defer writer.Flush()

	temp1()
	temp2()
	temp3()
}

package main

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

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

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

var arr []int

func main() {
    defer writer.Flush()
    var d, k int
    scanf("%d %d\n", &d, &k)
    arr = make([]int, d)
    for i := range arr {
        scanf("%d", &arr[i])
    }
    solve(d, k)
}

func solve(n, k int) {
    team := make([]int, n)
    prev := make([]int, n)
    next := make([]int, n)
    picked := 0
    h := &MaxHeap{}
    heap.Init(h)
    for i := range arr {
        prev[i] = i - 1
        next[i] = i + 1
        heap.Push(h, i)
    }
    curTeam := 1
    for picked < n {
        curTeam = 1 - curTeam
        member := heap.Pop(h).(int)
        for team[member] != 0 {
            member = heap.Pop(h).(int)
        }
        team[member] = 1 + curTeam
        picked++
        head, tail := member, member
        for i := 0; i < k; i++ {
            if prev[head] != -1 {
                head = prev[head]
            }
            if next[tail] != n {
                tail = next[tail]
            }
            if team[head] == 0 {
                team[head] = 1 + curTeam
                picked++
            }
            if team[tail] == 0 {
                team[tail] = 1 + curTeam
                picked++
            }
        }
        head, tail = prev[head], next[tail]
        if head >= 0 {
            next[head] = tail
        }
        if tail < n {
            prev[tail] = head
        }
    }
    for i := range team {
        printf("%d", team[i])
    }
}

type MaxHeap []int

func (h MaxHeap) Len() int {
    return len(h)
}
func (h MaxHeap) Less(i, j int) bool {
    return arr[h[i]] > arr[h[j]]
}
func (h MaxHeap) Swap(i, j int) {
    h[i], h[j] = h[j], h[i]
}
func (h *MaxHeap) Push(v interface{}) {
    *h = append(*h, v.(int))
}
func (h *MaxHeap) Pop() interface{} {
    ll := len(*h) - 1
    v := (*h)[ll]
    *h = (*h)[0:ll]
    return v
}

package main

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

// Node ..
type Node struct {
	next *Node
	prev *Node
	val  uint
}

func solve(k int, a []uint) []byte {
	removeNode := func(node *Node) {
		if node == nil {
			return
		}

		prev, next := node.prev, node.next
		if prev != nil {
			prev.next = next
		}

		if next != nil {
			next.prev = prev
		}
	}

	L := len(a)

	indices := map[uint]int{}
	for i, n := range a {
		indices[n] = i
	}

	res := make([]byte, L)
	sorted := make([]uint, L)
	copy(sorted, a)

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

	orig := map[uint]*Node{}
	var p *Node
	for _, n := range a {
		node := Node{val: n, prev: p}
		if p != nil {
			(*p).next = &node
		}
		p = &node

		orig[n] = &node
	}

	i := L
	team := 1
	for i > 0 {
		i--
		cur := indices[sorted[i]]
		if res[cur] > 0 {
			continue
		}

		t := byte(team)

		node := orig[sorted[i]]
		prev, next := node.prev, node.next
		for j := 0; j < k; j++ {
			if prev != nil {
				res[indices[prev.val]] = t
				removeNode(prev)
				prev = prev.prev
			}

			if next != nil {
				res[indices[next.val]] = t
				removeNode(next)
				next = next.next
			}
		}

		res[cur] = t
		removeNode(node)

		if team == 1 {
			team = 2
		} else {
			team = 1
		}
	}

	return res
}

func toInt(buf []byte) uint {
	n := uint(0)
	for _, v := range buf {
		n = n*10 + uint(v-'0')
	}

	return n
}

func main() {
	var n, k int

	fmt.Scan(&n, &k)

	a := make([]uint, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := range a {
		scanner.Scan()
		a[i] = toInt(scanner.Bytes())
	}

	ans := solve(k, a)
	for _, n := range ans {
		fmt.Print(n)
	}

	fmt.Println()
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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 getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n-1; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

type node struct {
	preIndex  int
	value     int
	index     int
	nextIndex int
}

var n, k int
var ns []node
var ans []int

func putNodeTo(p *node, n int) {
	ans[p.index] = n
	l, r := p, p
	for i := 0; i < k && l.preIndex != -1; i++ {
		l = &ns[l.preIndex]
		ans[l.index] = n
	}
	for i := 0; i < k && r.nextIndex != -1; i++ {
		r = &ns[r.nextIndex]
		ans[r.index] = n
	}
	if l.preIndex != -1 && r.nextIndex != -1 {
		ns[l.preIndex].nextIndex, ns[r.nextIndex].preIndex = r.nextIndex, l.preIndex
	} else if l.preIndex != -1 {
		ns[l.preIndex].nextIndex = -1
	} else if r.nextIndex != -1 {
		ns[r.nextIndex].preIndex = -1
	}
}
func temp1() {
	n, k = getLine2Int2()
	inputs := getLine2Ints(n)
	ns = make([]node, n)
	for i := 0; i < n; i++ {
		switch i {
		case 0:
			ns[i].preIndex = -1
			ns[i].nextIndex = i + 1
		case n - 1:
			ns[i].preIndex = i - 1
			ns[i].nextIndex = -1
		default:
			ns[i].preIndex = i - 1
			ns[i].nextIndex = i + 1
		}
		ns[i].index = i
		ns[i].value = inputs[i]
	}
}
func temp2() {
	ans = make([]int, n)
	type t struct {
		value int
		index int
	}
	ts := make([]t, n)
	for i := 0; i < n; i++ {
		ts[i].value = ns[i].value
		ts[i].index = ns[i].index
	}
	sort.Slice(ts, func(i, j int) bool {
		return ts[i].value > ts[j].value
	})
	list := 1
	for i := 0; i < n; i++ {
		if ans[ts[i].index] == 0 {
			putNodeTo(&ns[ts[i].index], list)
			list = 3 - list
		}
	}
}
func temp3() {
	for i := 0; i < n; i++ {
		switch i {
		case n - 1:
			printf("%d\n", ans[i])
		default:
			printf("%d ", ans[i])
		}
	}
}

func main() {
	defer writer.Flush()

	temp1()
	temp2()
	temp3()
}

package main

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

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

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

var arr []int

func main() {
    defer writer.Flush()
    var d, k int
    scanf("%d %d\n", &d, &k)
    arr = make([]int, d)
    for i := range arr {
        scanf("%d", &arr[i])
    }
    solve(d, k)
}

func solve(n, k int) {
    team := make([]int, n)
    prev := make([]int, n)
    next := make([]int, n)
    picked := 0
    h := &MaxHeap{}
    heap.Init(h)
    for i := range arr {
        prev[i] = i - 1
        next[i] = i + 1
        heap.Push(h, i)
    }
    curTeam := 1
    for picked < n {
        curTeam = 1 - curTeam
        member := heap.Pop(h).(int)
        for team[member] != 0 {
            member = heap.Pop(h).(int)
        }
        fmt.Println(member)
        team[member] = 1 + curTeam
        picked++
        head, tail := member, member
        for i := 0; i < k; i++ {
            if prev[head] != -1 {
                head = prev[head]
            }
            if next[tail] != n {
                tail = next[tail]
            }
            if team[head] == 0 {
                team[head] = 1 + curTeam
                picked++
            }
            if team[tail] == 0 {
                team[tail] = 1 + curTeam
                picked++
            }
        }
        head, tail = prev[head], next[tail]
        if head >= 0 {
            next[head] = tail
        }
        if tail < n {
            next[tail] = head
        }
    }
    for i := range team {
        printf("%d", team[i])
    }
}

type MaxHeap []int

func (h MaxHeap) Len() int {
    return len(h)
}
func (h MaxHeap) Less(i, j int) bool {
    return arr[h[i]] > arr[h[j]]
}
func (h MaxHeap) Swap(i, j int) {
    h[i], h[j] = h[j], h[i]
}
func (h *MaxHeap) Push(v interface{}) {
    *h = append(*h, v.(int))
}
func (h *MaxHeap) Pop() interface{} {
    ll := len(*h) - 1
    v := (*h)[ll]
    *h = (*h)[0:ll]
    return v
}

package main

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

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

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

var arr []int

func main() {
    defer writer.Flush()
    var d, k int
    scanf("%d %d\n", &d, &k)
    arr = make([]int, d)
    for i := range arr {
        scanf("%d", &arr[i])
    }
    solve(d, k)
}

func solve(n, k int) {
    team := make([]int, n)
    prev := make([]int, n)
    next := make([]int, n)
    picked := 0
    h := &MaxHeap{}
    heap.Init(h)
    for i := range arr {
        prev[i] = i - 1
        next[i] = i + 1
        heap.Push(h, i)
    }
    curTeam := 1
    for picked < n {
        curTeam = 1 - curTeam
        member := heap.Pop(h).(int)
        for team[member] != 0 {
            member = heap.Pop(h).(int)
        }
        team[member] = 1 + curTeam
        picked++
        head, tail := member, member
        for i := 0; i < k; i++ {
            if prev[head] != -1 {
                head = prev[head]
            }
            if next[tail] != n {
                tail = next[tail]
            }
            if team[head] == 0 {
                team[head] = 1 + curTeam
                picked++
            }
            if team[tail] == 0 {
                team[tail] = 1 + curTeam
                picked++
            }
        }
        head, tail = prev[head], next[tail]
        if head >= 0 {
            next[head] = tail
        }
        if tail < n {
            next[tail] = head
        }
    }
    for i := range team {
        printf("%d", team[i])
    }
}

type MaxHeap []int

func (h MaxHeap) Len() int {
    return len(h)
}
func (h MaxHeap) Less(i, j int) bool {
    return arr[h[i]] > arr[h[j]]
}
func (h MaxHeap) Swap(i, j int) {
    h[i], h[j] = h[j], h[i]
}
func (h *MaxHeap) Push(v interface{}) {
    *h = append(*h, v.(int))
}
func (h *MaxHeap) Pop() interface{} {
    ll := len(*h) - 1
    v := (*h)[ll]
    *h = (*h)[0:ll]
    return v
}


package main

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

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

	var T, n, k int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k, &s)
		if !strings.Contains(s, "W") {
			if k == 0 {
				Fprintln(out, 0)
			} else {
				Fprintln(out, 2*(k-1)+1)
			}
			continue
		}

		lr := -2
		s = strings.TrimFunc(s, func(r rune) bool { lr++; return r == 'L' })
		ans := 0
		for _, s := range strings.Split(s, "L") {
			if s != "" {
				ans += 2*(len(s)-1) + 1
			}
		}
		cnt := []int{}
		for _, s := range strings.Split(s, "W") {
			if s != "" {
				cnt = append(cnt, len(s))
			}
		}
		sort.Ints(cnt)
		for _, c := range cnt {
			if k < c {
				ans += 2 * k
				k = 0
				break
			}
			ans += 2*c + 1
			k -= c
		}
		if k > 0 {
			if k > lr {
				k = lr
			}
			ans += 2 * k
		}
		Fprintln(out, ans)
	}
}

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

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		n, k := ReadInt(), ReadInt()
		s := ReadString()
		fmt.Println(solve(n, k, s))
	}
}

const Inf = int(1e6)

func solve(n, k int, s string) int {
	m := make(map[int]int)

	Lcount := 0
	ans := 0
	wSeq := 0
	firstW := -1
	lastW := -1
	for i := 0; i < n; i++ {
		if s[i] == 'L' {
			Lcount++
			if wSeq > 0 {
				ans += wSeq + (wSeq - 1)
			}
			wSeq = 0
		} else {
			wSeq++
			if firstW == -1 {
				firstW = i
			}
			lastW = i
		}
	}
	if wSeq > 0 {
		ans += wSeq + (wSeq - 1)
	}

	k = Min(k, Lcount)
	if Lcount == n {
		if k > 0 {
			return k + (k - 1)
		} else {
			return 0
		}
	}

	if s[0] == 'L' {
		m[Inf]++
	}
	if s[n-1] == 'L' {
		m[Inf]++
	}
	seq := 0
	for i := firstW; i <= lastW; i++ {
		if s[i] == 'L' {
			seq++
		} else {
			if seq > 0 {
				m[seq]++
				seq = 0
			}
		}
	}

	type State struct {
		Len   int
		Count int
	}
	states := make([]*State, 0, len(m))
	for l, c := range m {
		states = append(states, &State{
			Len:   l,
			Count: c,
		})
	}

	sort.Slice(states, func(i, j int) bool {
		return states[i].Len < states[j].Len
	})

	for _, state := range states {
		if k == 0 {
			return ans
		}
		use := Min(k, state.Len*state.Count)
		k -= use
		ans += use/state.Len + use*2
	}
	return ans
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

package main

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

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

	solve := func(Case int) int {
		var n, k int
		var s string
		Fscan(in, &n, &k, &s)
		//t := s
		if !strings.Contains(s, "W") {
			if k == 0 {
				return 0
			}
			return 2*(k-1) + 1
		}
		lr := 0
		for i := 0; s[i] != 'W'; i++ {
			lr++
		}
		for i := n - 1; s[i] != 'W'; i-- {
			lr++
		}

		cnt := []int{}
		s = strings.TrimFunc(s, func(r rune) bool { return r == 'L' })
		sp := strings.Split(s, "W")
		sp2 := strings.Split(s, "L")
		ans := 0
		for _, s := range sp2 {
			if s != "" {
				l := len(s)
				ans+=2*(l-1)+1
			}
		}

		for _, s := range sp {
			if s != "" {
				cnt = append(cnt, len(s))
			}
		}
		sort.Ints(cnt)
		for _, c := range cnt {
			if k >= c {
				k-=c
				ans+=2*c+1
			} else {
				ans+=2*k
				k = 0
			}
			if k ==0 {
				break
			}
		}
		if k > 0 {
			if k > lr {
				k = lr
			}
			ans+=2*k
		}

		return ans
	}

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

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

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		n, k := ReadInt(), ReadInt()
		s := ReadString()
		fmt.Println(solve(n, k, s))
	}
}

const Inf = 1 << 28

func solve(n, k int, s string) int {
	m := make(map[int]int)

	Lcount := 0
	ans := 0
	wSeq := 0
	firstW := -1
	lastW := -1
	for i := 0; i < n; i++ {
		if s[i] == 'L' {
			Lcount++
			if wSeq > 0 {
				ans += wSeq + (wSeq - 1)
			}
			wSeq = 0
		} else {
			wSeq++
			if firstW == -1 {
				firstW = i
			}
			lastW = i
		}
	}
	if wSeq > 0 {
		ans += wSeq + (wSeq - 1)
	}

	k = Min(k, Lcount)
	if Lcount == n {
		if k > 0 {
			return k + (k-1)*2
		} else {
			return 0
		}
	}

	if s[0] == 'L' {
		m[Inf]++
	}
	if s[n-1] == 'L' {
		m[Inf]++
	}
	seq := 0
	for i := firstW; i <= lastW; i++ {
		if s[i] == 'L' {
			seq++
		} else {
			if seq > 0 {
				m[seq]++
				seq = 0
			}
		}
	}

	type State struct {
		Len   int
		Count int
	}
	states := make([]*State, 0, len(m))
	for l, c := range m {
		states = append(states, &State{
			Len:   l,
			Count: c,
		})
	}

	sort.Slice(states, func(i, j int) bool {
		return states[i].Len < states[j].Len
	})

	for _, state := range states {
		if k == 0 {
			return ans
		}
		use := Min(k, state.Len*state.Count)
		k -= use
		ans += use/state.Len + use*2
	}
	return ans
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		n, k := ReadInt(), ReadInt()
		s := ReadString()
		fmt.Println(solve(n, k, s))
	}
}

const Inf = int(1e6)

func solve(n, k int, s string) int {
	m := make(map[int]int)

	Lcount := 0
	ans := 0
	wSeq := 0
	firstW := -1
	lastW := -1
	for i := 0; i < n; i++ {
		if s[i] == 'L' {
			Lcount++
			if wSeq > 0 {
				ans += wSeq + (wSeq - 1)
			}
			wSeq = 0
		} else {
			wSeq++
			if firstW == -1 {
				firstW = i
			}
			lastW = i
		}
	}
	if wSeq > 0 {
		ans += wSeq + (wSeq - 1)
	}

	k = Min(k, Lcount)
	if Lcount == n {
		if k > 0 {
			return k + (k-1)*2
		} else {
			return 0
		}
	}

	if s[0] == 'L' {
		m[Inf]++
	}
	if s[n-1] == 'L' {
		m[Inf]++
	}
	seq := 0
	for i := firstW; i <= lastW; i++ {
		if s[i] == 'L' {
			seq++
		} else {
			if seq > 0 {
				m[seq]++
				seq = 0
			}
		}
	}

	type State struct {
		Len   int
		Count int
	}
	states := make([]*State, 0, len(m))
	for l, c := range m {
		states = append(states, &State{
			Len:   l,
			Count: c,
		})
	}

	sort.Slice(states, func(i, j int) bool {
		return states[i].Len < states[j].Len
	})

	for _, state := range states {
		if k == 0 {
			return ans
		}
		use := Min(k, state.Len*state.Count)
		k -= use
		ans += use/state.Len + use*2
	}
	return ans
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)
var dsu []int
var a []edge
var vis []bool

type edge struct {
	f, t, c int
}

type edgeSlice [] edge

func (a edgeSlice) Len() int {
	return len(a)
}
func (a edgeSlice) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}
func (a edgeSlice) Less(i, j int) bool {
	return a[j].c > a[i].c
}

func getfa(t int) int {
	if dsu[t] == t {
		return t
	} else {
		dsu[t] = getfa(dsu[t])
		return dsu[t]
	}
}

func main() {
	var n, m int
	fmt.Fscan(in, &n, &m)
	a = make([]edge, m, m)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &a[i].f, &a[i].t, &a[i].c)
	}
	dsu = make([]int, n+5, n+5)
	vis = make([]bool, m+5, m+5)
	for i := 1; i <= n; i++ {
		dsu[i] = i
	}
	sort.Sort(edgeSlice(a))
	var startpos, endpos, ans = 0, 0, 0
	for startpos != m {
		endpos = startpos
		for i := startpos + 1; i < m; i++ {
			if a[i].c == a[startpos].c {
				endpos = i
			} else{
				break
			}
		}
		for i := startpos; i <= endpos; i++ {
			if getfa(a[i].f) == getfa(a[i].t) {
				vis[i] = true
			}
		}
		for i := startpos; i <= endpos; i++ {
			if vis[i] {
				continue
			}
			var ss, tt = getfa(a[i].f), getfa(a[i].t)
			if ss == tt {
				ans++
			} else {
				dsu[ss] = tt
			}
		}
		startpos = endpos + 1
	}
	fmt.Printf("%d\n", ans)
}

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<18)
var dsu []int
var a []edge
var vis []bool

type edge struct {
	f, t, c int
}

type edgeSlice [] edge

func (a edgeSlice) Len() int {
	return len(a)
}
func (a edgeSlice) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}
func (a edgeSlice) Less(i, j int) bool {
	return a[j].c > a[i].c
}

func getfa(t int) int {
	if dsu[t] == t {
		return t
	} else {
		dsu[t] = getfa(dsu[t])
		return dsu[t]
	}
}

func main() {
	var n, m int
	fmt.Fscan(in, &n, &m)
	a = make([]edge, m, m)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &a[i].f, &a[i].t, &a[i].c)
	}
	dsu = make([]int, n+5, n+5)
	vis = make([]bool, m+5, m+5)
	for i := 1; i <= n; i++ {
		dsu[i] = i
	}
	sort.Sort(edgeSlice(a))
	var startpos, endpos, ans = 0, 0, 0
	for startpos != m {
		endpos = startpos
		for i := startpos + 1; i < m; i++ {
			if a[i].c == a[startpos].c {
				endpos = i
			} else{
				break
			}
		}
		for i := startpos; i <= endpos; i++ {
			if getfa(a[i].f) == getfa(a[i].t) {
				vis[i] = true
			}
		}
		for i := startpos; i <= endpos; i++ {
			if vis[i] {
				continue
			}
			var ss, tt = getfa(a[i].f), getfa(a[i].t)
			if ss == tt {
				ans++
			} else {
				dsu[ss] = tt
			}
		}
		startpos = endpos + 1
	}
	fmt.Printf("%d\n", ans)
}

package main

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

var (
	pre []int
)

type Edge struct {
	u, v, value int
}
type Edges []*Edge

func (e Edges) Len() int {
	return len(e)
}
func (e Edges) Less(a, b int) bool {
	return e[a].value < e[b].value
}
func (e Edges) Swap(a, b int) {
	var tmp *Edge = nil
	tmp = e[a]
	e[a] = e[b]
	e[b] = tmp
}
func merge(v, u int) bool {
	pv := find(v)
	pu := find(u)
	if pv == pu {
		return false
	}
	pre[pv] = pu
	return true
}
func find(v int) int {
	if pre[v] == 0 {
		return v
	}
	pre[v] = find(pre[v])
	return pre[v]
}
func solveF(edges Edges) int {
	edgeLen := len(edges)
	res := 0
	front:=0
	for front < edgeLen {
		rear := front
		cnt:=0
		for rear<edgeLen&&edges[front].value == edges[rear].value{
			if find(edges[rear].v) != find(edges[rear].u){
				cnt++
			}
			rear++
		}
		for j:=front;j<rear;j++{
			if merge(edges[j].u,edges[j].v){
				cnt--
			}
		}
		res += cnt
		front=rear
	}
	return res
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	edges := make(Edges, m)
	pre = make([]int, n+1)
	for i := 0; i < m; i++ {
		edge := &Edge{}
		fmt.Fscanf(buf, "%d %d %d\n", &edge.u, &edge.v, &edge.value)
		edges[i] = edge
	}
	sort.Sort(edges)
	fmt.Printf("%d\n", solveF(edges))

}

package main

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

var (
	pre []int
)

type Edge struct {
	u, v, value int
}
type Edges []*Edge

func (e Edges) Len() int {
	return len(e)
}
func (e Edges) Less(a, b int) bool {
	return e[a].value < e[b].value
}
func (e Edges) Swap(a, b int) {
	var tmp *Edge = nil
	tmp = e[a]
	e[a] = e[b]
	e[b] = tmp
}
func merge(v, u int) bool {
	pv := find(v)
	pu := find(u)
	if pv == pu {
		return false
	}
	pre[pv] = pu
	return true
}
func find(v int) int {
	if pre[v] == 0 {
		return v
	}
	pre[v] = find(pre[v])
	return pre[v]
}
func solveF(edges Edges) int {
	edgeLen := len(edges)
	res := 0
	prevalue := -1
	for i := 0; i < edgeLen; i++ {
	//	fmt.Printf("u=%d v=%d %d\n",edges[i].u,edges[i].v,edges[i].value)
		if merge(edges[i].u,edges[i].v) == false{
	//		fmt.Printf("u=%d v=%d ****\n",edges[i].u,edges[i].v)
			if edges[i].value == prevalue{
				res++
			}
		}else{
			prevalue = edges[i].value
		}
	}
	return res
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	edges := make(Edges, m)
	pre = make([]int, n+1)
	for i := 0; i < m; i++ {
		edge := &Edge{}
		fmt.Fscanf(buf, "%d %d %d\n", &edge.u, &edge.v, &edge.value)
		edges[i] = edge
	}
	sort.Sort(edges)
	fmt.Printf("%d\n", solveF(edges))

}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi64() int64 { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
type PI struct{ x, y int }
func Kosaraju(n int, diredges []PI) (int, []int) {
	g, grev, visited, visitedInv, scc, s, counter := make([][]int, n), make([][]int, n), make([]bool, n), make([]bool, n), make([]int, n), make([]int, 0, n), 0
	var dfs1, dfs2 func(int)
	for _, xx := range diredges { x, y := xx.x, xx.y; g[x] = append(g[x], y); grev[y] = append(grev[y], x) }
	dfs1 = func(u int) { if !visited[u] { visited[u] = true; for _, c := range g[u] { dfs1(c) }; s = append(s, u) } }
	for i := 0; i < n; i++ { dfs1(i) }
	dfs2 = func(u int) {
		if !visitedInv[u] { visitedInv[u] = true; for _, c := range grev[u] { dfs2(c) }; scc[u] = counter }
	}
	for i := n - 1; i >= 0; i-- { nn := s[i]; if !visitedInv[nn] { dfs2(nn); counter += 1 } }; return counter, scc
}
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N,M,K := gi(),gi(),gi64(); A := gis(N); U,V := fill2(M); for i:=0;i<M;i++ { U[i]--; V[i]-- }
	// Special case for K == 1
	if K == 1 {fmt.Println(minarr(A)); return }
	check := func(ub int) bool {
		a := []PI{}
		for i:=0;i<M;i++ { u,v := U[i],V[i]; if A[u] <= ub && A[v] <= ub {a = append(a,PI{u,v}) } }
		cnt,_ := Kosaraju(N,a)
		if cnt < N { return true } // We found a cycle
		darr := iai(N,-1)
		gr := make([][]int,N)
		for _,p := range a { gr[p.x] = append(gr[p.x],p.y) }
		var dfs func(n int) int
		dfs = func(n int) int {
			if darr[n] == -1 {
				mv := 1
				for _,c := range gr[n] {  mv = max(mv,1+dfs(c)) }
				darr[n] = mv
			}
			return darr[n]
		}
		for i:=0;i<N;i++ { if int64(dfs(i)) >= K { return true } }
		return false
	}
	if !check(1000000000) {
		fmt.Println(-1)
	} else {
		check(4)
		l,u := 0,1000000000
		for u-l > 1 {
			m := (l+u)>>1
			if check(m) { u = m } else { l = m }
		}
		fmt.Println(u)
	}
}

package main

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

const N = 200007

var n, m, totE int
var K int64
var a, f, d, g, to, sub [N]int

func addEdge(x, y int)  {
	totE ++
	sub[totE] = y
	to[totE] = g[x]
	g[x] = totE
}

func Check(val int) bool {
	q := make([]int, 0, n)
	totNum := 0
	for i := 0; i < n; i ++ {
		f[i] = 0
		d[i] = 0
	}
	for i := 0; i < n; i ++ {
		if a[i] <= val {
			totNum ++
			for p := g[i]; p != 0; p = to[p] {
				y := sub[p]
				if a[y] <= val {
					d[y] ++
				}
			}
		}
	}
	L := 0
	for i := 0; i < n; i ++ {
		if a[i] <= val && d[i] == 0 {
			q = append(q, i)
			L ++
			f[i] = 1
			d[i] --
		}
	}
	for L > 0 {
		x := q[0]
		if int64(f[x]) >= K {
			return true
		}
		q = q[1:]
		totNum --
		L --
		for p := g[x]; p != 0; p = to[p] {
			y := sub[p]
			if a[y] <= val {
				if f[x] + 1 > f[y] {
					f[y] = f[x] + 1
				}
				d[y] --
				if d[y] == 0 {
					d[y] --
					q = append(q, y)
					L ++
				}
			}
		}
	}
	return totNum > 0
}

func main()  {
	var in = bufio.NewReader(os.Stdin)
	minv := math.MaxInt32
	maxv := -math.MaxInt32
	fmt.Fscan(in, &n, &m, &K)
	for i := 0; i < n; i ++ {
		fmt.Fscan(in, &a[i])
		if a[i] < minv {
			minv = a[i]
		}
		if a[i] > maxv {
			maxv = a[i]
		}
	}
	for i := 0; i < m; i ++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		addEdge(x-1, y-1)
	}
	L, R := minv, maxv
	for L < R {
		mid := (L+R)/2
		if Check(mid){
			R = mid
		} else {
			L = mid + 1
		}
	}
	if Check(R) {
		fmt.Println(R)
	} else {
		fmt.Println(-1)
	}
}

package main

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

const N = 200007

var n, m, totE int
var K int64
var a, f, d, g, to, sub, q [N]int

var In = bufio.NewReader(os.Stdin)

func ReadInt(out *int) error {
	var ans, sign int = 0, 1
	var readed = false
	c, err := In.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = In.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = In.ReadByte() {
		ans = ans<<3 + ans<<1 + int(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

func ReadInt64(out *int64) error {
	var ans, sign int64 = 0, 1
	var readed = false
	c, err := In.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = In.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = In.ReadByte() {
		ans = ans<<3 + ans<<1 + int64(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

func addEdge(x, y int)  {
	totE ++
	sub[totE] = y
	to[totE] = g[x]
	g[x] = totE
}

func Check(val int) bool {
	totNum := 0
	for i := 0; i < n; i ++ {
		f[i] = 0
		d[i] = 0
	}
	for i := 0; i < n; i ++ {
		if a[i] <= val {
			totNum ++
			for p := g[i]; p != 0; p = to[p] {
				y := sub[p]
				if a[y] <= val {
					d[y] ++
				}
			}
		}
	}
	st, ed := 1, 0
	for i := 0; i < n; i ++ {
		if a[i] <= val && d[i] == 0 {
			ed ++
			q[ed] = i
			f[i] = 1
			d[i] --
		}
	}
	for st <= ed {
		x := q[st]
		if int64(f[x]) >= K {
			return true
		}
		st ++
		totNum --
		for p := g[x]; p != 0; p = to[p] {
			y := sub[p]
			if a[y] <= val {
				if f[x] + 1 > f[y] {
					f[y] = f[x] + 1
				}
				d[y] --
				if d[y] == 0 {
					d[y] --
					ed ++
					q[ed] = y
				}
			}
		}
	}
	return totNum > 0
}

func main()  {
	minv := math.MaxInt32
	maxv := -math.MaxInt32
	ReadInt(&n)
	ReadInt(&m)
	ReadInt64(&K)
	for i := 0; i < n; i ++ {
		ReadInt(&a[i])
		if a[i] < minv {
			minv = a[i]
		}
		if a[i] > maxv {
			maxv = a[i]
		}
	}
	for i := 0; i < m; i ++ {
		var x, y int
		ReadInt(&x)
		ReadInt(&y)
		addEdge(x-1, y-1)
	}
	L, R := minv, maxv
	for L < R {
		mid := (L+R)/2
		if Check(mid){
			R = mid
		} else {
			L = mid + 1
		}
	}
	if Check(R) {
		fmt.Println(R)
	} else {
		fmt.Println(-1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi64() int64 { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N,M,K := gi(),gi(),gi64(); A := gis(N); U,V := fill2(M); for i:=0;i<M;i++ { U[i]--; V[i]-- }
	gr := make([][]int,N)
	for i:=0;i<M;i++ { u,v := U[i],V[i]; gr[u] = append(gr[u],v) }
	visited := make([]bool,N)
	depth := make([]int64,N)
	check := func(v int) bool {
		for i:=0;i<N;i++ { visited[i] = false; depth[i] = -1 }
		var dfs func(n int)
		dfs = func(n int) {
			if depth[n] != -1 { return }
			if A[n] > v { depth[n] = 0; return }
			if visited[n] { depth[n] = 1000000000000000001; return }
			visited[n] = true; m := int64(1)
			for _,c := range gr[n] {
				dfs(c)
				if 1 + depth[c] > m { m = 1 + depth[c] }
			}
			depth[n] = m
		}
		for i:=0;i<N;i++ { dfs(i); if depth[i] >= K { return true } }
		return false
	}
	l,u := 0,1000000001
	for u-l > 1 { m := (u+l)>>1; if check(m) { u = m } else { l = m } }
	if u > 1000000000 { fmt.Println(-1) } else { fmt.Println(u) }
}

package main

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

var in = bufio.NewReader(os.Stdin)

func read(out *int64) error {
	var ans, sign int64 = 0, 1
	var readed = false
	c, err := in.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = in.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = in.ReadByte() {
		ans = ans<<3 + ans<<1 + int64(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

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

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

var n, m, k, idx, cnt int64
var h, e, ne, ai, din, dist [200007]int64

func add(a, b int64) {
	e[idx] = b
	ne[idx] = h[a]
	h[a] = idx
	idx++
}

type node struct {
	a, b int64
}

var pi [200007]node
var si [400007]int64

func top() {
	var Len int64 = 0
	for i := int64(1); i <= n; i++ {
		if din[i] == 0 {
			dist[i] = 1
			si[Len] = i
			Len++
		}
	}
	var p int64 = 0
	for p != Len {
		t := si[p]
		p++
		cnt++
		for i := h[t]; i != int64(-1); i = ne[i] {
			j := e[i]
			din[j]--
			dist[j] = max(dist[j], dist[t]+1)
			if din[j] == 0 {
				si[Len] = j
				Len++
			}
		}
	}
}
func check(x int64) bool {
	cnt = 0
	for i := int64(1); i <= n; i++ {
		h[i] = -1
		dist[i] = 0
		din[i] = 0
	}
	idx = 0
	for i := int64(1); i <= m; i++ {
		a, b := pi[i].a, pi[i].b
		if ai[a] <= x && ai[b] <= x {
			add(a, b)
			din[b]++
		}
	}
	top()
	if cnt < n {
		return true
	} else {
		for i := int64(1); i <= n; i++ {
			if dist[i] >= k {
				return true
			}
		}
	}
	return false
}
func main() {
	read(&n)
	read(&m)
	read(&k)
	var mi int64 = 10000000000
	for i := int64(1); i <= n; i++ {
		read(&ai[i])
		mi = min(mi, ai[i])
	}
	var l, r int64 = 1, 10000000000
	for i := int64(1); i <= m; i++ {
		read(&pi[i].a)
		read(&pi[i].b)
	}
	if m == 0 && k == 1 {
		fmt.Println(mi)
		return
	}
	for l < r {
		mid := (l + r) / 2
		if check(mid) {
			r = mid
		} else {
			l = mid + 1
		}
	}
	if l == int64(10000000000) {
		fmt.Println(-1)
	} else {
		fmt.Println(l)
	}
}

package main

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

const N = 200007

var n, m, totE int
var K int64
var a, f, d, g, to, sub [N]int

func addEdge(x, y int)  {
	totE ++
	sub[totE] = y
	to[totE] = g[x]
	g[x] = totE
}

func Check(val int) bool {
	q := make([]int, 0, n)
	totNum := 0
	for i := 0; i < n; i ++ {
		f[i] = 0
		d[i] = 0
	}
	for i := 0; i < n; i ++ {
		if a[i] <= val {
			totNum ++
			for p := g[i]; p != 0; p = to[p] {
				y := sub[p]
				if a[y] <= val {
					d[y] ++
				}
			}
		}
	}
	L := 0
	for i := 0; i < n; i ++ {
		if a[i] <= val && d[i] == 0 {
			q = append(q, i)
			L ++
			f[i] = 1
			d[i] --
		}
	}
	for L > 1{
		x := q[0]
		if int64(f[x]) >= K {
			return true
		}
		q = q[1:]
		totNum --
		L --
		for p := g[x]; p != 0; p = to[p] {
			y := sub[p]
			if a[y] <= val {
				if f[x] + 1 > f[y] {
					f[y] = f[x] + 1
				}
				d[y] --
				if d[y] == 0 {
					d[y] --
					q = append(q, y)
					L ++
				}
			}
		}
	}
	return totNum > 0
}

func main()  {
	var in = bufio.NewReader(os.Stdin)
	minv := math.MaxInt32
	maxv := -math.MaxInt32
	fmt.Fscan(in, &n, &m, &K)
	for i := 0; i < n; i ++ {
		fmt.Fscan(in, &a[i])
		if a[i] < minv {
			minv = a[i]
		}
		if a[i] > maxv {
			maxv = a[i]
		}
	}
	for i := 0; i < m; i ++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		addEdge(x-1, y-1)
	}
	L, R := minv, maxv
	for L < R {
		mid := (L+R)/2
		if Check(mid){
			R = mid
		} else {
			L = mid + 1
		}
	}
	if Check(R) {
		fmt.Println(R)
	} else {
		fmt.Println(-1)
	}
}

package main

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

const N = 200007

var n, m, totE int
var K int64
var a, f, d, g, to, sub, q [N]int

var In = bufio.NewReader(os.Stdin)

func ReadInt(out *int) error {
	var ans, sign int = 0, 1
	var readed = false
	c, err := In.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = In.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = In.ReadByte() {
		ans = ans<<3 + ans<<1 + int(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

func ReadInt64(out *int64) error {
	var ans, sign int64 = 0, 1
	var readed = false
	c, err := In.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = In.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = In.ReadByte() {
		ans = ans<<3 + ans<<1 + int64(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

func addEdge(x, y int)  {
	totE ++
	sub[totE] = y
	to[totE] = g[x]
	g[x] = totE
}

func Check(val int) bool {
	totNum := 0
	for i := 0; i < n; i ++ {
		f[i] = 0
		d[i] = 0
	}
	for i := 0; i < n; i ++ {
		if a[i] <= val {
			totNum ++
			for p := g[i]; p != 0; p = to[p] {
				y := sub[p]
				if a[y] <= val {
					d[y] ++
				}
			}
		}
	}
	st, ed := 0, 1
	for i := 0; i < n; i ++ {
		if a[i] <= val && d[i] == 0 {
			ed ++
			q[ed] = i
			f[i] = 1
		}
	}
	for st <= ed {
		x := q[st]
		if int64(f[x]) >= K {
			return true
		}
		st ++
		totNum --
		for p := g[x]; p != 0; p = to[p] {
			y := sub[p]
			if a[y] <= val {
				if f[x] + 1 > f[y] {
					f[y] = f[x] + 1
				}
				d[y] --
				if d[y] == 0 {
					d[y] --
					ed ++
					q[ed] = y
				}
			}
		}
	}
	return totNum > 0
}

func main()  {
	minv := math.MaxInt32
	maxv := -math.MaxInt32
	ReadInt(&n)
	ReadInt(&m)
	ReadInt64(&K)
	for i := 0; i < n; i ++ {
		ReadInt(&a[i])
		if a[i] < minv {
			minv = a[i]
		}
		if a[i] > maxv {
			maxv = a[i]
		}
	}
	for i := 0; i < m; i ++ {
		var x, y int
		ReadInt(&x)
		ReadInt(&y)
		addEdge(x-1, y-1)
	}
	L, R := minv, maxv
	for L < R {
		mid := (L+R)/2
		if Check(mid){
			R = mid
		} else {
			L = mid + 1
		}
	}
	if Check(R) {
		fmt.Println(R)
	} else {
		fmt.Println(-1)
	}
}