Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.Restore the the original sequence knowing digits remaining on the board.

The first line of the input contains integer n (1 ≤ n ≤ 105) — the length of the sequence. Next n lines contain one element of the sequence each. Each element consists only of digits and question marks. No element starts from digit 0. Each element has length from 1 to 8 characters, inclusive.

If the answer exists, print in the first line "YES" (without the quotes). Next n lines must contain the sequence of positive integers — a possible variant of Peter's sequence. The found sequence must be strictly increasing, it must be transformed from the given one by replacing each question mark by a single digit. All numbers on the resulting sequence must be written without leading zeroes. If there are multiple solutions, print any of them. If there is no answer, print a single line "NO" (without the quotes).

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

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

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


Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt  — dynamic programming. Here is his algorithm for this problem.   However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that   $$$1 \le n,m \le 500$$$ (as Bob hates large matrix);  $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers);  the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it!

The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$).

Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix.  Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column.

NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$.

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

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


There are $$$n$$$ students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the second coach chooses the second team.The $$$i$$$-th student has integer programming skill $$$a_i$$$. All programming skills are distinct and between $$$1$$$ and $$$n$$$, inclusive.Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and $$$k$$$ closest students to the left of him and $$$k$$$ closest students to the right of him (if there are less than $$$k$$$ students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of students and the value determining the range of chosen students during each move, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the programming skill of the $$$i$$$-th student. It is guaranteed that all programming skills are distinct.

Print a string of $$$n$$$ characters; $$$i$$$-th character should be 1 if $$$i$$$-th student joins the first team, or 2 otherwise.

NoteIn the first example the first coach chooses the student on a position $$$3$$$, and the row becomes empty (all students join the first team).In the second example the first coach chooses the student on position $$$4$$$, and the row becomes $$$[2, 1]$$$ (students with programming skills $$$[3, 4, 5]$$$ join the first team). Then the second coach chooses the student on position $$$1$$$, and the row becomes empty (and students with programming skills $$$[1, 2]$$$ join the second team).In the third example the first coach chooses the student on position $$$1$$$, and the row becomes $$$[1, 3, 5, 4, 6]$$$ (students with programming skills $$$[2, 7]$$$ join the first team). Then the second coach chooses the student on position $$$5$$$, and the row becomes $$$[1, 3, 5]$$$ (students with programming skills $$$[4, 6]$$$ join the second team). Then the first coach chooses the student on position $$$3$$$, and the row becomes $$$[1]$$$ (students with programming skills $$$[3, 5]$$$ join the first team). And then the second coach chooses the remaining student (and the student with programming skill $$$1$$$ joins the second team).In the fourth example the first coach chooses the student on position $$$3$$$, and the row becomes $$$[2, 1]$$$ (students with programming skills $$$[3, 4, 5]$$$ join the first team). Then the second coach chooses the student on position $$$1$$$, and the row becomes empty (and students with programming skills $$$[1, 2]$$$ join the second team).

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
}


You like playing chess tournaments online.In your last tournament you played $$$n$$$ games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get $$$0$$$ points. When you win you get $$$1$$$ or $$$2$$$ points: if you have won also the previous game you get $$$2$$$ points, otherwise you get $$$1$$$ point. If you win the very first game of the tournament you get $$$1$$$ point (since there is not a "previous game").The outcomes of the $$$n$$$ games are represented by a string $$$s$$$ of length $$$n$$$: the $$$i$$$-th character of $$$s$$$ is W if you have won the $$$i$$$-th game, while it is L if you have lost the $$$i$$$-th game.After the tournament, you notice a bug on the website that allows you to change the outcome of at most $$$k$$$ of your games (meaning that at most $$$k$$$ times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug.Compute the maximum score you can get by cheating in the optimal way.

Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1\le t \le 20,000$$$) — the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers $$$n, k$$$ ($$$1\le n\le 100,000$$$, $$$0\le k\le n$$$) – the number of games played and the number of outcomes that you can change. The second line contains a string $$$s$$$ of length $$$n$$$ containing only the characters W and L. If you have won the $$$i$$$-th game then $$$s_i=\,$$$W, if you have lost the $$$i$$$-th game then $$$s_i=\,$$$L. It is guaranteed that the sum of $$$n$$$ over all testcases does not exceed $$$200,000$$$.

For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way.

8
5 2
WLWLL
6 5
LLLWWL
7 1
LWLWLWL
15 5
WWWLLLWWWLLLWWW
40 7
LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL
1 0
L
1 1
L
6 1
WLLWLW

NoteExplanation of the first testcase. Before changing any outcome, the score is $$$2$$$. Indeed, you won the first game, so you got $$$1$$$ point, and you won also the third, so you got another $$$1$$$ point (and not $$$2$$$ because you lost the second game).An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is $$$7=1+2+2+2$$$: $$$1$$$ point for the first game and $$$2$$$ points for the second, third and fourth game.Explanation of the second testcase. Before changing any outcome, the score is $$$3$$$. Indeed, you won the fourth game, so you got $$$1$$$ point, and you won also the fifth game, so you got $$$2$$$ more points (since you won also the previous game).An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is $$$11 = 1+2+2+2+2+2$$$: $$$1$$$ point for the first game and $$$2$$$ points for all the other games.

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


You are given an undirected weighted connected graph with $$$n$$$ vertices and $$$m$$$ edges without loops and multiple edges.The $$$i$$$-th edge is $$$e_i = (u_i, v_i, w_i)$$$; the distance between vertices $$$u_i$$$ and $$$v_i$$$ along the edge $$$e_i$$$ is $$$w_i$$$ ($$$1 \le w_i$$$). The graph is connected, i. e. for any pair of vertices, there is at least one path between them consisting only of edges of the given graph.A minimum spanning tree (MST) in case of positive weights is a subset of the edges of a connected weighted undirected graph that connects all the vertices together and has minimum total cost among all such subsets (total cost is the sum of costs of chosen edges).You can modify the given graph. The only operation you can perform is the following: increase the weight of some edge by $$$1$$$. You can increase the weight of each edge multiple (possibly, zero) times.Suppose that the initial MST cost is $$$k$$$. Your problem is to increase weights of some edges with minimum possible number of operations in such a way that the cost of MST in the obtained graph remains $$$k$$$, but MST is unique (it means that there is only one way to choose MST in the obtained graph).Your problem is to calculate the minimum number of operations required to do it.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5, n - 1 \le m \le 2 \cdot 10^5$$$) — the number of vertices and the number of edges in the initial graph. The next $$$m$$$ lines contain three integers each. The $$$i$$$-th line contains the description of the $$$i$$$-th edge $$$e_i$$$. It is denoted by three integers $$$u_i, v_i$$$ and $$$w_i$$$ ($$$1 \le u_i, v_i \le n, u_i \ne v_i, 1 \le w \le 10^9$$$), where $$$u_i$$$ and $$$v_i$$$ are vertices connected by the $$$i$$$-th edge and $$$w_i$$$ is the weight of this edge. It is guaranteed that the given graph doesn't contain loops and multiple edges (i.e. for each $$$i$$$ from $$$1$$$ to $$$m$$$ $$$u_i \ne v_i$$$ and for each unordered pair of vertices $$$(u, v)$$$ there is at most one edge connecting this pair of vertices). It is also guaranteed that the given graph is connected.

Print one integer — the minimum number of operations to unify MST of the initial graph without changing the cost of MST.

NoteThe picture corresponding to the first example: You can, for example, increase weight of the edge $$$(1, 6)$$$ or $$$(6, 3)$$$ by $$$1$$$ to unify MST.The picture corresponding to the last example: You can, for example, increase weights of edges $$$(1, 5)$$$ and $$$(2, 4)$$$ by $$$1$$$ to unify MST.

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

}