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

import (
	"fmt"
)

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

	var t int
	/*scanner.Scan()
	fmt.Sscan(scanner.Text(), &t)*/
	fmt.Scan(&t)
	for i := 1; i <= t; i++ {
		var a, b int
		var instr string
		fmt.Scan(&a, &b, &instr)
		/*scanner.Scan()
		fmt.Sscan(scanner.Text(), &a, &b)
		scanner.Scan()
		fmt.Sscan(scanner.Text(), &instr)*/

		vecGap := []int{}
		pre := -1
		for i := 0; i < len(instr); {
			if instr[i] == '1' {
				if pre != -1 {
					vecGap = append(vecGap, i-pre-1)
				}
				for i < len(instr) && instr[i] == '1' {
					pre = i
					i++
				}
			} else {
				i++
			}
		}

		ans := 0
		if pre != -1 {
			ans = (len(vecGap) + 1) * a
			for i := 0; i < len(vecGap); i++ {
				d := vecGap[i]
				if d*b < a {
					ans = ans - a + d*b
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

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

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

	return b
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for {
		if t == 0 {
			break
		}
		t--

		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)

		var s string
		fmt.Scanf("%s\n", &s)

		s = strings.TrimLeft(s, "0")
		s = strings.TrimRight(s, "0")

		if len(s) == 0 {
			fmt.Println(0)
			continue
		}

		var B []int

		var count int
		for _, si := range s {
			if si == '1' {
				if count != 0 {
					B = append(B, count)
					count = 0
				}
			} else {
				count += 1
			}
		}
		if count != 0 {
			B = append(B, count)
			count = 0
		}

		fmt.Fprintln(os.Stderr, "B", B)

		var F = make([]int, len(B)+1)

		for i, _ := range F {

			if i == 0 {
				F[i] = a
				continue
			}

			bCost := b * B[i-1]
			if i == 1 {
				F[i] = F[i-1] + min(a, bCost)
			} else {
				F[i] = min(F[i-1]+min(a, bCost), F[i-2]+(a+bCost))
			}
			println("F", i, F[i])
		}

		fmt.Println(F[len(F)-1])
	}
}

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

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

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

	var t int
	fmt.Fscan(reader, &t)
	for i := 1; i <= t; i++ {
		var a, b int
		var instr string
		fmt.Fscan(reader, &a, &b, &instr)

		vecGap := []int{}
		pre := -1
		for i := 0; i < len(instr); {
			if instr[i] == '1' {
				if pre != -1 {
					vecGap = append(vecGap, i-pre-1)
				}
				for i < len(instr) && instr[i] == '1' {
					pre = i
					i++
				}
			} else {
				i++
			}
		}

		ans := 0
		if pre != -1 {
			ans = (len(vecGap) + 1) * a
			for i := 0; i < len(vecGap); i++ {
				d := vecGap[i]
				if d*b < a {
					ans = ans - a + d*b
				}
			}
		}
		fmt.Println(ans)
	}
}

/*
URL:
https://codeforces.com/contest/1443/problem/B
*/

package main

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

var (
	t    int
	a, b int64
	S    []rune
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		a, b = readll2()
		S = readrs()

		solve()
	}
}

func solve() {
	comp, cnts := RunLengthEncoding(S)

	// 0だけのときは例外処理
	if len(comp) == 1 && comp[0] == '0' {
		printf("%d\n", 0)
		return
	}

	if comp[len(comp)-1] == '0' {
		comp = comp[:len(comp)-1]
		cnts = cnts[:len(cnts)-1]
	}
	if comp[0] == '0' {
		comp = comp[1:]
		cnts = cnts[1:]
	}

	l := len(comp)

	// one := int64(l / 2)
	one := Kiriage(int64(l), 2)
	Z := []int64{}
	for i := 0; i < l; i++ {
		if comp[i] == '0' {
			Z = append(Z, int64(cnts[i]))
		}
	}
	// debugf("Z: %v\n", Z)

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

	zs := make([]int64, len(Z)+1)
	for i := 0; i < len(Z); i++ {
		zs[i+1] = zs[i] + Z[i]
	}

	ans := a * one
	for i := int64(1); i < int64(len(zs)); i++ {
		val := b*zs[i] + a*(one-i)
		ChMin(&ans, val)
	}

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

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

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

// RunLengthEncoding returns encoded slice of an input.
// Time complexity: O(|S|)
func RunLengthEncoding(S []rune) (comp []rune, cnts []int) {
	comp = []rune{}
	cnts = []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			l++
		} else {
			comp = append(comp, S[i-1])
			cnts = append(cnts, l)
			l = 1
		}
	}
	comp = append(comp, S[len(S)-1])
	cnts = append(cnts, l)

	return
}

// RunLengthDecoding decodes RLE results.
// Time complexity: O(|S|)
func RunLengthDecoding(comp []rune, cnts []int) (S []rune) {
	if len(comp) != len(cnts) {
		panic("S, L are not RunLengthEncoding results")
	}

	S = []rune{}

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

	return
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

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

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

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

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

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

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

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

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

	return s
}

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

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  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()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

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

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

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

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

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

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 min_int(a int, b int) int { if a < b { return a } else { return b } }
func min_int64(a int64, b int64) int64 { if a < b { return a } else { return b } }

func max_int(a int, b int) int { if a > b { return a } else { return b } }
func max_int64(a int64, b int64) int64 { if a > b { return a } else { return b } }

type LeftRightPair struct {
	l, r int
}

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

	for t := 0; t < T; t++ {

		var a, b int
		scanf("%d %d\n", &a, &b);

		var s string
		scanf("%s\n", &s)

		pairs := make([]LeftRightPair, 0)
		for i := 0; i < len(s); i++ {

			if string(s[i]) == "0" {
				continue
			}

			if string(s[i]) == "1" {
				var ones_start_index int = i
				var ones_stop_index int = len(s)
				for j := i + 1; j < len(s); j++ {
					if string(s[j]) == "0" {
						ones_stop_index = j
						break
					}
				}
				i = ones_stop_index
				pairs = append(pairs, LeftRightPair{ones_start_index, ones_stop_index})
			}

		}

		if len(pairs) == 0 {
			printf("0\n")
			continue
		}

		var res int = a
		for i := 1; i < len(pairs); i++ {
			res += min_int((pairs[i].l - pairs[i-1].r)*b, a)
		}

		printf("%d\n", res)

	}

}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		solveSingle()
	}
}

func solveSingle() {
	a := readInt()
	b := readInt()
	s := readString()
	values := make([][]int, 0)
	start := 0
	for start < len(s) {
		cnt := CountValues(s[start], s, start)
		if cnt > 0 {
			values = append(values, []int{int(s[start] - '0'), cnt})
		} else {
			break
		}
		start += cnt
	}
	cost := 0
	for i := 0; i < len(values) - 2; i++ {
		if values[i][0] == 1 {
			cost1 := 2 * a
			cost2 := a + b * values[i+1][1]
			if cost1 > cost2 {
				cost += b * values[i+1][1]
				values[i+2][1] += values[i][1]
				values[i][0] = 0
			}
		}
	}
	for _, value := range values {
		if value[0] == 1 {
			cost += a
		}
	}
	fmt.Println(cost)
}

func CountValues(ex uint8, str string, start int) int {
	cnt := 0
	for i := start; i < len(str) && str[i] == ex; i++ {
		cnt++
	}
	return cnt
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, a, b int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &a, &b)
		fmt.Fscan(in, &s)

		s = strings.Trim(s, "0")
		sum := 0
		emptyStreak := 2 * a
		for i := range s {
			if s[i] == '1' {
				if emptyStreak > 0 {
					if b*emptyStreak < a {
						sum += b * emptyStreak
					} else {
						sum += a
					}
				}
				emptyStreak = 0
			} else {
				emptyStreak++
			}
		}
		fmt.Println(sum)
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

type segment struct {
	start, end int
}

func main() {
	var t int
	fmt.Fscan(reader, &t)

	for i := 0; i < t; i++ {
		var a, b int64
		fmt.Fscan(reader, &a, &b)

		var s string
		fmt.Fscan(reader, &s)

		prev := int64(-1e9)
		var ans int64 = 0
		for j := 0; j < len(s); j++ {
			if s[j] == '0' {
				continue
			}

			len := int64(j) - prev - 1

			// fmt.Println("len: ", len)

			if b*len < a {
				ans += b * len
			} else {
				ans += a
			}

			prev = int64(j)
		}

		fmt.Println(ans)
	}
}

package main

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

/*
2
1 1
01000010
5 1
011011100001

2
6
*/

func SaveCity(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, put, bang int64
	var target string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &bang)
		Fscan(in, &put)
		Fscan(in, &target)

		bangIdx := make([]int, len(target))
		flag := false
		lastBangIdx := -1
		for idx, content := range target {
			if content == '1' {
				if lastBangIdx != -1 {
					bangIdx[idx] = idx - lastBangIdx - 1
				}
				lastBangIdx = idx
				flag = true
			}
		}

		if !flag {
			Fprintln(out, 0)
			continue
		}

		sum := bang
		for idx, content := range target {
			if content == '1' && bangIdx[idx] != 0 {
				sum += min(bang, int64(bangIdx[idx])*put)
			}
		}

		Fprintln(out, sum)
	}
}

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

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

package main

import (
	"fmt"
	"strings"
)

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

	return b
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for {
		if t == 0 {
			break
		}

		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)

		var s string
		fmt.Scanf("%s\n", &s)

		s = strings.TrimLeft(s, "0")
		s = strings.TrimRight(s, "0")

		var B []int

		var count int
		for _, si := range s {
			if si == '1' {
				if count != 0 {
					B = append(B, count)
					count = 0
				}
			} else {
				count += 1
			}
		}
		if count != 0 {
			B = append(B, count)
			count = 0
		}

		var F = make([]int, len(B)+1)

		for i, _ := range F {
			if i == 0 {
				F[i] = a
			} else if i == 1 {
				F[i] = min(a+a, a+b*B[i-1])
			} else {
				F[i] = min(F[i-1]+min(a, b*B[i-1]), F[i-2]+(a+b*B[i-1]))
			}
		}

		fmt.Println(F[len(F)-1])

		t--
	}
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for {
		if t == 0 {
			break
		}

		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)

		var s string
		fmt.Scanf("%s\n", &s)

		s = strings.TrimLeft(s, "0")
		s = strings.TrimRight(s, "0")

		var B []int

		var count int
		for _, si := range s {
			if si == '1' {
				if count != 0 {
					B = append(B, count)
					count = 0
				}
			} else {
				count += 1
			}
		}
		if count != 0 {
			B = append(B, count)
			count = 0
		}

		var F = make([]int, len(B)+1)

		for i, _ := range F {
			if i == 0 {
				F[i] = a
			} else if i == 1 {
				F[i] = int(math.Min(float64(a+a), float64(a+b)))
			} else {
				F[i] = int(math.Min(float64(F[i-1]+a), float64(F[i-2]+(a+b))))
			}
		}

		fmt.Println(F[len(F)-1])

		t--
	}
}

package main

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

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

	return b
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for {
		if t == 0 {
			break
		}

		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)

		var s string
		fmt.Scanf("%s\n", &s)

		s = strings.TrimLeft(s, "0")
		s = strings.TrimRight(s, "0")

		var B []int

		var count int
		for _, si := range s {
			if si == '1' {
				if count != 0 {
					B = append(B, count)
					count = 0
				}
			} else {
				count += 1
			}
		}
		if count != 0 {
			B = append(B, count)
			count = 0
		}

		fmt.Fprintln(os.Stderr, "B", B)

		var F = make([]int, len(B)+1)

		for i, _ := range F {

			if i == 0 {
				F[i] = a
				continue
			}

			bCost := b * B[i-1]
			if i == 1 {
				F[i] = F[i-1] + min(a, bCost)
			} else {
				F[i] = min(F[i-1]+min(a, bCost), F[i-2]+(a+bCost))
			}
			println("F", i, F[i])
		}

		fmt.Println(F[len(F)-1])

		t--
	}
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for {
		if t == 0 {
			break
		}

		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)

		var s string
		fmt.Scanf("%s\n", &s)

		s = strings.TrimLeft(s, "0")
		s = strings.TrimRight(s, "0")

		var B []int

		var count int
		for _, si := range s {
			if si == '1' {
				if count != 0 {
					B = append(B, count)
					count = 0
				}
			} else {
				count += 1
			}
		}
		if count != 0 {
			B = append(B, count)
			count = 0
		}

		var F = make([]int, len(B)+1)

		for i, _ := range F {
			if i == 0 {
				F[i] = a
			} else if i == 1 {
				F[i] = int(math.Min(float64(a+a), float64(a+b*B[i-1])))
			} else {
				F[i] = int(math.Min(float64(F[i-1]+a), float64(F[i-2]+(a+b*B[i-1]))))
			}
		}

		fmt.Println(F[len(F)-1])

		t--
	}
}

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

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

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

	var t int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &t)
	for i := 1; i <= t; i++ {
		var a, b int
		var instr string
		scanner.Scan()
		fmt.Sscan(scanner.Text(), &a, &b)
		scanner.Scan()
		fmt.Sscan(scanner.Text(), &instr)

		vecGap := []int{}
		pre := -1
		for i := 0; i < len(instr); {
			if instr[i] == '1' {
				if pre != -1 {
					vecGap = append(vecGap, i-pre-1)
				}
				for i < len(instr) && instr[i] == '1' {
					pre = i
					i++
				}
			} else {
				i++
			}
		}

		ans := 0
		if pre != -1 {
			ans = (len(vecGap) + 1) * a
			for i := 0; i < len(vecGap); i++ {
				d := vecGap[i]
				if d*b < a {
					ans = ans - a + d*b
				}
			}
		}
		fmt.Println(ans)
	}
}

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

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

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

	var t int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &t)
	for i := 1; i <= t; i++ {
		var a, b int
		var instr string
		scanner.Scan()
		fmt.Sscan(scanner.Text(), &a, &b)
		scanner.Scan()
		fmt.Sscan(scanner.Text(), &instr)

		vecGap := []int{}
		pre := -1
		for i := 0; i < len(instr); {
			if instr[i] == '1' {
				if pre != -1 {
					vecGap = append(vecGap, i-pre-1)
				}
				for i < len(instr) && instr[i] == '1' {
					pre = i
					i++
				}
			} else {
				i++
			}
		}

		ans := (len(vecGap) + 1) * a
		for i := 0; i < len(vecGap); i++ {
			d := vecGap[i]
			if d*b < a {
				ans = ans - a + d*b
			}
		}
		fmt.Println(ans)
	}
}

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, a, b int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &a, &b)
		fmt.Fscan(in, &s)

		s = strings.Trim(s, "0")
		sum := 0
		emptyStreak := 2 * a / b
		for i := range s {
			if s[i] == '1' {
				if emptyStreak > 0 {
					sum += int(math.Min(float64(b*emptyStreak), float64(a)))
				}
				emptyStreak = 0
			} else {
				emptyStreak++
			}
		}
		fmt.Println(s)
	}
}

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, a, b int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &a, &b)
		fmt.Fscan(in, &s)

		s = strings.Trim(s, "0")
		sum := 0
		emptyStreak := 2 * a / b
		for i := range s {
			if s[i] == '1' {
				if emptyStreak > 0 {
					sum += int(math.Min(float64(b*emptyStreak), float64(a)))
				}
				emptyStreak = 0
			} else {
				emptyStreak++
			}
		}
		fmt.Println(sum)
	}
}

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, a, b int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &a, &b)
		fmt.Fscan(in, &s)

		s = strings.Trim(s, "0")
		sum := 0
		emptyStreak := 2 * a / b
		for i := range s {
			if s[i] == '1' {
				if emptyStreak > 0 {
					if b*emptyStreak < a {
						sum += b * emptyStreak
					} else {
						sum += a
					}
				}
				emptyStreak = 0
			} else {
				emptyStreak++
			}
		}
		fmt.Println(sum)
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

type segment struct {
	start, end int
}

func main() {
	var t int
	fmt.Fscan(reader, &t)

	for i := 0; i < t; i++ {
		var a, b int
		fmt.Fscan(reader, &a, &b)

		var s string
		fmt.Fscan(reader, &s)

		prev := int(-1e9)
		ans := 0
		for j := 0; j < len(s); j++ {
			if s[j] == '0' {
				continue
			}

			len := j - prev - 1

			// fmt.Println("len: ", len)

			if b*len < a {
				ans += b * len
			} else {
				ans += a
			}

			prev = j
		}

		fmt.Println(ans)
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

type segment struct {
	start, end int
}

func main() {
	var t int
	fmt.Fscan(reader, &t)

	for i := 0; i < t; i++ {
		var a, b int
		fmt.Fscan(reader, &a, &b)

		var s string
		fmt.Fscan(reader, &s)

		prev := int(-1e9)
		ans := 0
		for j := 0; j < len(s); j++ {
			if s[j] == '0' {
				continue
			}

			len := j - prev -1

			fmt.Println("len: ", len)

			if b*len < a {
				ans += b * len
			} else {
				ans += a
			}

			prev = j
		}

		fmt.Println(ans)
	}
}

package main

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

/*
2
1 1
01000010
5 1
011011100001

2
6
*/

func SaveCity(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, put, bang int64
	var target string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &bang)
		Fscan(in, &put)
		Fscan(in, &target)

		bangIdx := make([]int, len(target))
		flag := false
		lastBangIdx := -1
		for idx, content := range target {
			if content == '1' {
				if lastBangIdx != -1 {
					bangIdx[idx] = idx - lastBangIdx - 1
				}
				lastBangIdx = idx
				flag = true
			}
		}

		if !flag {
			Fprintln(out, 0)
			return
		}

		sum := bang
		for idx, content := range target {
			if content == '1' && bangIdx[idx] != 0 {
				sum += min(bang, int64(bangIdx[idx])*put)
			}
		}

		Fprintln(out, sum)
	}
}

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

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

package main

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

/*
2
1 1
01000010
5 1
011011100001

2
6
*/

func SaveCity(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, put, bang int64
	var target string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &bang)
		Fscan(in, &put)
		Fscan(in, &target)

		bangIdx := make([]int, len(target))
		flag := false
		lastBangIdx := -1
		for idx, content := range target {
			if content == '1' {
				if lastBangIdx != -1 {
					bangIdx[idx] = idx - lastBangIdx - 1
				}
				lastBangIdx = idx
				flag = true
			}
		}

		if !flag {
			Fprintln(out, 0)
		}

		sum := bang
		for idx, content := range target {
			if content == '1' && bangIdx[idx] != 0 {
				sum += min(bang, int64(bangIdx[idx])*put)
			}
		}

		Fprintln(out, sum)
	}
}

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

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

package main

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

/*
2
1 1
01000010
5 1
01101110

2
6
*/

func Save(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, put, bang int64
	var target string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &bang)
		Fscan(in, &put)
		Fscan(in, &target)

		bangIdx := make([]int, len(target))
		lastBangIdx := -1
		for idx, content := range target {
			if content == '1' {
				if lastBangIdx != -1 {
					bangIdx[idx] = idx - lastBangIdx - 1
				}
				lastBangIdx = idx
			}

		}

		sum := bang
		for idx, content := range target {
			if content == '1' && bangIdx[idx] != 0 {
				sum += min(bang, int64(bangIdx[idx])*put)
			}
		}

		Fprintln(out, sum)
	}
}

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

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

package main

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

/*
2
1 1
01000010
5 1
011011100001

2
6
*/

func SaveCity(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, put, bang int64
	var target string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &bang)
		Fscan(in, &put)
		Fscan(in, &target)

		bangIdx := make([]int, len(target))
		flag := false
		lastBangIdx := -1
		for idx, content := range target {
			if content == '1' {
				if lastBangIdx != -1 {
					bangIdx[idx] = idx - lastBangIdx - 1
				}
				lastBangIdx = idx
			} else {
				flag = true
			}
		}

		if flag {
			Fprintln(out, 0)
		}

		sum := bang
		for idx, content := range target {
			if content == '1' && bangIdx[idx] != 0 {
				sum += min(bang, int64(bangIdx[idx])*put)
			}
		}

		Fprintln(out, sum)
	}
}

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

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


package main

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

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

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

	n, k := nextInt64(), nextInt64()
	a := make([]int64, n)
	cntNumR := map[int64]int64{}
	cntNumL := map[int64]int64{}
	ret := int64(0)

	for i := range a {
		a[i] = nextInt64()

		if _, ok := cntNumR[a[i]]; !ok {
			cntNumR[a[i]] = 1
			cntNumL[a[i]] = 0
		} else {
			cntNumR[a[i]]++
		}
	}
	for i := range a {
		cntNumR[a[i]]--
		// println(cntNumR)

		if a[i]%k == 0 {
			l, okL := cntNumL[a[i]/k]
			r, okR := cntNumR[a[i]*k]
			// println(ret, l, r)
			if okL && okR {
				ret += l * r
			}
		}
		cntNumL[a[i]]++

	}

	println(ret)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

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

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

import "fmt"
import "bufio"
import "strconv"
import "os"

const maxn int = 200000

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

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

	var array[maxn] int64
	var n int
	var k int64

	n = nextInt()
	k = nextInt64()

	var m1 map[int64]int64
	var m2 map[int64]int64
	m1 = make(map[int64]int64)
	m2 = make(map[int64]int64)

	for i := 0; i < n; i++ {
		array[i] = nextInt64()
		m2[array[i]] += 1
	}

	var ans int64 = 0
	for i := 0; i < n; i++ {
		var cur int64 = array[i]
		m2[cur] -= 1

		if cur % k == 0 {
			ans += m1[cur / k] * m2[cur * k]
		}

		m1[cur] += 1
	}

	println(ans)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

	var n, k, v int
	Fscan(in, &n, &k)
	if n < 3 {
		Fprint(out, 0)
		return
	}

	ans := int64(0)
	if k == 1 {
		cnt := map[int]int64{}
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			if cnt[v] >= 2 {
				ans += cnt[v] * (cnt[v] - 1) / 2
			}
			cnt[v]++
		}
		Fprint(out, ans)
		return
	}

	cnt0 := map[int]int64{}
	cnt1 := map[int]int64{}
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		if v%k == 0 {
			if v/k%k == 0 {
				ans += cnt1[v/k]
			}
			cnt1[v] += cnt0[v/k]
		}
		cnt0[v]++
	}
	Fprint(out, ans)
}

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

package main

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

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

	var n, k, v int
	Fscan(in, &n, &k)
	if n < 3 {
		Fprint(out, 0)
		return
	}

	ans := int64(0)
	if k == 1 {
		cnt := map[int]int{}
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			if cnt[v] >= 2 {
				ans += int64(cnt[v]) * int64(cnt[v]-1) / 2
			}
			cnt[v]++
		}
		Fprint(out, ans)
		return
	}

	cnt0 := map[int]int{}
	cnt1 := map[int]int64{}
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		if v%k == 0 {
			if v/k%k == 0 {
				ans += cnt1[v/k]
			}
			cnt1[v] += int64(cnt0[v/k])
		}
		cnt0[v]++
	}
	Fprint(out, ans)
}

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

package main

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

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

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

	n, k := nextInt64(), nextInt64()
	a := make([]int64, n)
	cntNumR := map[int64]int{}
	cntNumL := map[int64]int{}
	ret := 0

	for i := range a {
		a[i] = nextInt64()

		if _, ok := cntNumR[a[i]]; !ok {
			cntNumR[a[i]] = 1
			cntNumL[a[i]] = 0
		} else {
			cntNumR[a[i]]++
		}
	}
	for i := range a {
		cntNumR[a[i]]--
		// println(cntNumR)

		if a[i]%k == 0 {
			l, okL := cntNumL[a[i]/k]
			r, okR := cntNumR[a[i]*k]
			// println(ret, l, r)
			if okL && okR {
				ret += l * r
			}
		}
		cntNumL[a[i]]++

	}

	println(ret)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

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

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

	var n, k, v int
	Fscan(in, &n, &k)
	if n < 3 {
		Fprint(out, 0)
		return
	}

	ans := int64(0)
	if k == 1 {
		cnt := map[int]int{}
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			if cnt[v] >= 2 {
				ans += int64(cnt[v]) * int64(cnt[v]-1) / 2
			}
			cnt[v]++
		}
		Fprint(out, ans)
		return
	}

	cnt0 := map[int]int{}
	cnt1 := map[int]int{}
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		if v%k == 0 {
			if v/k%k == 0 {
				ans += int64(cnt1[v/k])
			}
			cnt1[v] += cnt0[v/k]
		}
		cnt0[v]++
	}
	Fprint(out, ans)
}

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


package main

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

// github.com/EndlessCheng/codeforces-go
func CF862C(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n, x int
	Fscan(bufio.NewReader(in), &n, &x)

	var a []int
	f := func(m int) {
		for i := 0; i < m-1; i++ {
			v := 1 << (18 - i)
			x ^= v
			a = append(a, v)
		}
		a = append(a, x)
		n -= m
	}
	switch n % 4 {
	case 0:
		f(4)
	case 2:
		if n == 2 {
			if x == 0 {
				Fprint(out, "NO")
			} else {
				Fprint(out, "YES\n0 ", x)
			}
			return
		}
		f(6)
	default:
		f(n % 4)
	}

	Fprintln(out, "YES")
	has := map[int]bool{}
	for _, v := range a {
		has[v] = true
		Fprint(out, v, " ")
	}
	for i := 0; n > 0; i += 4 {
		if has[i] || has[i+1] || has[i+2] || has[i+3] {
			continue
		}
		Fprint(out, i, i+1, i+2, i+3, " ")
		n -= 4
	}
}

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

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"math/rand"
	"os"
	"strconv"
)

const MAX = 1e6

func solve() {
	n := readInt()
	x := readInt()
	if n == 2 && x == 0 {
		fmt.Println("NO")
		return
	}
	a := make([]int, MAX)
	v := make([]bool, MAX)
	for i := 0; i < MAX; i++ {
		a[i] = i
	}
	shuffleArray(a)
	res := make([]int, n)
	res[0] = x
	start := 0
	for i := 0; i < n-1; i++ {
		for start < MAX {
			next := a[start]
			start++
			if !v[next] {
				need := next ^ res[i]
				if need < MAX && !v[need] {
					res[i] = next
					res[i+1] = need
					v[need] = true
					v[next] = true
					break
				}
			}
		}
		if start == MAX {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	var buffer bytes.Buffer
	for i := 0; i < len(res); i++ {
		if i != 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(res[i]))
	}
	fmt.Println(buffer.String())
}

func shuffleArray(a []int) {
	n := len(a)
	for i := 0; i < n; i++ {
		pos := i + rand.Intn(n-i)
		a[i], a[pos] = a[pos], a[i]
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

const MAX = 1e6

func solve() {
	n := readInt()
	x := readInt()
	if n == 2 && x == 0 {
		fmt.Println("NO")
		return
	}
	v := make([]bool, MAX)
	res := make([]int, n)
	res[0] = x
	v[x] = true
	start := 0
	for i := 0; i < n-1; i++ {
		for start < MAX {
			next := start
			start++
			if !v[next] {
				need := next ^ res[i]
				if need < MAX && !v[need] {
					res[i] = next
					res[i+1] = need
					v[need] = true
					v[next] = true
					break
				}
			}
		}
		if start == MAX {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	var buffer bytes.Buffer
	for i := 0; i < len(res); i++ {
		if i != 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(res[i]))
	}
	fmt.Println(buffer.String())
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

const MAX = 1e6

func solve() {
	n := readInt()
	x := readInt()
	if n == 2 && x == 0 {
		fmt.Println("NO")
		return
	}
	v := make(map[int]bool)
	res := make([]int, n)
	res[0] = x
	v[x] = true
	start := 0
	for i := 0; i < n-1; i++ {
		for start < MAX {
			next := start
			start++
			if !v[next] {
				need := next ^ res[i]
				if need < MAX && !v[need] {
					res[i] = next
					res[i+1] = need
					v[need] = true
					v[next] = true
					break
				}
			}
		}
		if start == MAX {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	var buffer bytes.Buffer
	for i := 0; i < len(res); i++ {
		if i != 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(res[i]))
	}
	fmt.Println(buffer.String())
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

const MAX = 1e6

func solve() {
	n := readInt()
	x := readInt()
	if n == 2 && x == 0 {
		fmt.Println("NO")
		return
	}
	v := make(map[int]bool)
	res := make([]int, n)
	res[0] = x
	v[x] = true
	start := 0
	for i := 0; i < n-1; i++ {
		for start < MAX {
			if !v[start] {
				need := start ^ res[i]
				if need < MAX && !v[need] {
					res[i] = start
					res[i+1] = need
					v[need] = true
					v[start] = true
					start++
					break
				}
			}
			start++
		}
		if start == MAX {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	var buffer bytes.Buffer
	for i := 0; i < len(res); i++ {
		if i != 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(res[i]))
	}
	fmt.Println(buffer.String())
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"math/rand"
	"os"
	"strconv"
)

const MAX = 1e6

func solve() {
	n := readInt()
	x := readInt()
	if n == 2 && x == 0 {
		fmt.Println("NO")
		return
	}
	a := make([]int, MAX)
	v := make([]bool, MAX)
	for i := 0; i < MAX; i++ {
		a[i] = i
	}
	shuffleArray(a)
	res := make([]int, n)
	res[0] = x
	v[x] = true
	start := 0
	for i := 0; i < n-1; i++ {
		for start < MAX {
			next := a[start]
			start++
			if !v[next] {
				need := next ^ res[i]
				if need < MAX && !v[need] {
					res[i] = next
					res[i+1] = need
					v[need] = true
					v[next] = true
					break
				}
			}
		}
		if start == MAX {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	var buffer bytes.Buffer
	for i := 0; i < len(res); i++ {
		if i != 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(res[i]))
	}
	fmt.Println(buffer.String())
}

func shuffleArray(a []int) {
	n := len(a)
	for i := 0; i < n; i++ {
		pos := i + rand.Intn(n-i)
		a[i], a[pos] = a[pos], a[i]
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"math/rand"
	"os"
	"strconv"
)

const MAX = 1e6

func solve() {
	n := readInt()
	x := readInt()
	if n == 2 && x == 0 {
		fmt.Println("NO")
		return
	}
	a := make([]int, MAX)
	v := make([]bool, MAX)
	for i := 0; i < MAX; i++ {
		a[i] = i
	}
	// shuffleArray(a)
	res := make([]int, n)
	res[0] = x
	v[x] = true
	start := 0
	for i := 0; i < n-1; i++ {
		for start < MAX {
			next := a[start]
			start++
			if !v[next] {
				need := next ^ res[i]
				if need < MAX && !v[need] {
					res[i] = next
					res[i+1] = need
					v[need] = true
					v[next] = true
					break
				}
			}
		}
		if start == MAX {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	var buffer bytes.Buffer
	for i := 0; i < len(res); i++ {
		if i != 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(res[i]))
	}
	fmt.Println(buffer.String())
}

func shuffleArray(a []int) {
	n := len(a)
	for i := 0; i < n; i++ {
		pos := i + rand.Intn(n-i)
		a[i], a[pos] = a[pos], a[i]
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF862C(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n, x int
	Fscan(bufio.NewReader(in), &n, &x)

	var a []int
	f := func(m int) {
		mask := 0
		for i := 0; i < m-1; i++ {
			v := 1 << (18 - i)
			mask |= v
			a = append(a, v)
		}
		a = append(a, mask^x)
		n -= m
	}
	switch n % 4 {
	case 0:
		f(4)
	case 2:
		if n == 2 {
			if x == 0 {
				Fprint(out, "NO")
			} else {
				Fprint(out, "YES\n0 ", x)
			}
			return
		}
		f(6)
	default:
		f(n % 4)
	}

	Fprintln(out, "YES")
	has := map[int]bool{}
	for _, v := range a {
		has[v] = true
		Fprint(out, v, " ")
	}
	for i := 0; n > 0; i += 4 {
		if has[i] || has[i+1] || has[i+2] || has[i+3] {
			continue
		}
		Fprint(out, i, i+1, i+2, i+3, " ")
		n -= 4
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF862C(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n, x int
	Fscan(bufio.NewReader(in), &n, &x)

	var a []int
	f := func(m int) {
		mask := 0
		for i := 0; i < m-1; i++ {
			v := 1 << (18 - i)
			mask |= v
			a = append(a, v)
		}
		a = append(a, mask)
		a[0] ^= x
		n -= m
	}
	switch n % 4 {
	case 0:
		f(4)
	case 2:
		if n == 2 {
			if x == 0 {
				Fprint(out, "NO")
			} else {
				Fprint(out, "YES\n0 ", x)
			}
			return
		}
		f(6)
	default:
		f(n % 4)
	}

	Fprintln(out, "YES")
	has := map[int]bool{}
	for _, v := range a {
		has[v] = true
		Fprint(out, v, " ")
	}
	for i := 0; n > 0; i += 4 {
		if has[i] || has[i+1] || has[i+2] || has[i+3] {
			continue
		}
		Fprint(out, i, i+1, i+2, i+3, " ")
		n -= 4
	}
}

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

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"math/rand"
	"os"
	"strconv"
)

const MAX = 1e6

func solve() {
	n := readInt()
	x := readInt()
	a := make([]int, MAX)
	v := make([]bool, MAX)
	for i := 0; i < MAX; i++ {
		a[i] = i
	}
	shuffleArray(a)
	res := make([]int, n)
	res[0] = x
	start := 0
	for i := 0; i < n-1; i++ {
		for start < MAX {
			next := a[start]
			start++
			if !v[next] {
				need := next ^ res[i]
				if need < MAX && next != need && !v[need] {
					res[i] = next
					res[i+1] = need
					v[need] = true
					v[next] = true
					break
				}
			}
		}
		if start == MAX {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	var buffer bytes.Buffer
	for i := 0; i < len(res); i++ {
		if i != 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(res[i]))
	}
	fmt.Println(buffer.String())
}

func shuffleArray(a []int) {
	n := len(a)
	for i := 0; i < n; i++ {
		pos := i + rand.Intn(n-i)
		a[i], a[pos] = a[pos], a[i]
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"math/rand"
	"os"
	"strconv"
)

const MAX = 1e6

func solve() {
	n := readInt()
	x := readInt()
	if n == 2 && x == 0 {
		fmt.Println("NO")
		return
	}
	a := make([]int, MAX)
	v := make([]bool, MAX)
	for i := 0; i < MAX; i++ {
		a[i] = i
	}
	shuffleArray(a)
	res := make([]int, n)
	res[0] = x
	start := 0
	for i := 0; i < n-1; i++ {
		for start < MAX {
			next := a[start]
			start++
			if !v[next] {
				need := next ^ res[i]
				if need < MAX && next != need && !v[need] {
					res[i] = next
					res[i+1] = need
					v[need] = true
					v[next] = true
					break
				}
			}
		}
		if start == MAX {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	var buffer bytes.Buffer
	for i := 0; i < len(res); i++ {
		if i != 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(res[i]))
	}
	fmt.Println(buffer.String())
}

func shuffleArray(a []int) {
	n := len(a)
	for i := 0; i < n; i++ {
		pos := i + rand.Intn(n-i)
		a[i], a[pos] = a[pos], a[i]
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"math/rand"
	"os"
	"strconv"
)

func solve() {
	a := make([]int, 1e6)
	v := make([]bool, len(a))
	n := readInt()
	x := readInt()
	for i := 0; i < len(a); i++ {
		a[i] = i
	}
	shuffleArray(a)
	res := make([]int, 1)
	res[0] = x
	nextIndex := 0
	for i := 0; i < n-1; i++ {
		last := res[len(res)-1]
		for nextIndex < len(a) {
			next := a[nextIndex]
			nextIndex++
			if !v[next] {
				looking := next ^ last
				if looking < len(v) && !v[looking] {
					res[len(res)-1] = next
					res = append(res, looking)
					v[looking] = true
					v[next] = true
					break
				}
			}
		}
		if nextIndex == len(a) {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	var buffer bytes.Buffer
	for i := 0; i < len(res); i++ {
		if i != 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(res[i]))
	}
	fmt.Println(buffer.String())
}

func shuffleArray(a []int) {
	n := len(a)
	for i := 0; i < n; i++ {
		pos := i + rand.Intn(n-i)
		a[i], a[pos] = a[pos], a[i]
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF862C(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n, x int
	Fscan(bufio.NewReader(in), &n, &x)

	var a []int
	f := func(m int) {
		mask := 0
		for i := 0; i < m-1; i++ {
			v := 1 << (19 - i)
			mask ^= v
			a = append(a, v)
		}
		a = append(a, mask)
		a[0] ^= x
		n -= m
	}
	switch n % 4 {
	case 0:
		f(4)
	case 2:
		if n == 2 {
			if x == 0 {
				Fprint(out, "NO")
			} else {
				Fprint(out, "YES\n0 ", x)
			}
			return
		}
		f(6)
	default:
		f(n % 4)
	}

	Fprintln(out, "YES")
	has := map[int]bool{}
	for _, v := range a {
		has[v] = true
		Fprint(out, v, " ")
	}
	for i := 0; n > 0; i += 4 {
		if has[i] || has[i+1] || has[i+2] || has[i+3] {
			continue
		}
		Fprint(out, i, i+1, i+2, i+3, " ")
		n -= 4
	}
}

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


package main

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

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

	var T, n, s, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s)
		c := make([]interface{}, n)
		ps := []int{}
		for i := range c {
			if Fscan(in, &v); v <= s/2 {
				c[i] = 0
				if v == s/2 {
					ps = append(ps, i)
				}
			} else {
				c[i] = 1
			}
		}
		if s&1 == 0 {
			for _, p := range ps[:len(ps)/2] {
				c[p] = 1
			}
		}
		Fprintln(out, c...)
	}
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n, T := readTwoNums(reader)
		A := readNNums(reader, n)
		res := solve(n, T, A)

		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n int, T int, A []int) []int {
	ans := make([]int, n)
	var cnt int

	for i := 0; i < n; i++ {
		if A[i]*2 < T {
			ans[i] = 1
		} else if A[i]*2 == T {
			cnt++
			ans[i] = -1
		}
	}
	if cnt > 0 {
		// divides half
		h1 := cnt / 2
		for i := 0; i < n; i++ {
			if ans[i] == -1 {
				if h1 > 0 {
					ans[i] = 1
					h1--
				} else {
					ans[i] = 0
				}
			}
		}
	}
	return ans
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n, T := readTwoNums(reader)
		A := readNNums(reader, n)
		res := solve(n, T, A)

		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n int, T int, A []int) []int {
	ps := make([]Pair, n)

	for i := 0; i < n; i++ {
		ps[i] = Pair{A[i], i}
	}

	sort.Sort(Pairs(ps))

	ans := make([]int, n)

	var i, j = 0, n - 1
	var cnt int
	for i < j {
		tmp := ps[i].first + ps[j].first
		if tmp == T {
			if ps[i].first != ps[j].first {
				ans[ps[i].second] = 1
				ans[ps[j].second] = 0
			} else {
				ans[ps[i].second] = -1
				ans[ps[j].second] = -1
				cnt += 2
			}
			i++
			j--
		} else if tmp > T {
			ans[ps[j].second] = 0
			j--
		} else {
			ans[ps[i].second] = 1
			i++
		}
	}

	if i == j {
		if ps[i].first*2 != T || cnt == 0 {
			ans[ps[i].second] = 1
		} else {
			ans[ps[i].second] = -1
			cnt++
		}
	}

	if cnt > 0 {
		// divides half
		h1 := cnt / 2
		for i := 0; i < n; i++ {
			if ans[i] == -1 {
				if h1 > 0 {
					ans[i] = 1
					h1--
				} else {
					ans[i] = 0
				}
			}
		}
	}
	return ans
}

type Pair struct {
	first, second int
}

type Pairs []Pair

func (ps Pairs) Len() int {
	return len(ps)
}

func (ps Pairs) Less(i, j int) bool {
	return ps[i].first < ps[j].first
}

func (ps Pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}


package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

type entry struct {
	a byte
	i int
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	last := make([]entry, 0)
	fmt.Fprintln(w, "? 1 1")
	w.Flush()
	var ans string
	fmt.Fscan(r, &ans)
	last = append(last, entry{ans[0], 0})
	for i:=1;i<n;i++ {
		if len(last) != 26 {
			fmt.Fprintf(w, "? 2 %d %d\n", 1, i+1)
			w.Flush()
			var cnt int
			fmt.Fscan(r, &cnt)
			if cnt == len(last) {
				left, right := 0, len(last)-1
				for left < right {
					m := (left + right) / 2
					fmt.Fprintf(w, "? 2 %d %d\n", last[m].i+2, i+1)
					w.Flush()
					var cnt int
					fmt.Fscan(r, &cnt)
					if cnt == len(last) - m - 1 {
						left = m + 1
					} else {
						right = m
					}
				}
				ans += string([]byte{last[left].a})
				last[left].i = i
				sort.Slice(last, func(i, j int) bool {
					return last[i].i < last[j].i
				})
			} else {
				fmt.Fprintf(w, "? 1 %d\n", i+1)
				w.Flush()
				var input string
				fmt.Fscan(r, &input)
				last = append(last, entry{input[0], i})
				sort.Slice(last, func(i, j int) bool {
					return last[i].i < last[j].i
				})
				ans += string([]byte{input[0]})
			}
		} else {
			left, right := 0, 25
			for left < right {
				m := (left + right) / 2
				fmt.Fprintf(w, "? 2 %d %d\n", last[m].i+2, i+1)
				w.Flush()
				var cnt int
				fmt.Fscan(r, &cnt)
				if cnt == 25 - m {
					left = m + 1
				} else {
					right = m
				}
			}
			ans += string([]byte{last[left].a})
			last[left].i = i
			sort.Slice(last, func(i, j int) bool {
				return last[i].i < last[j].i
			})
		}
	}
	fmt.Fprintf(w, "! %s", ans)
}

package main

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

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

	q1 := func(n int) rune {
		fmt.Fprintf(out, "? 1 %d\n", n+1)
		out.Flush()

		var s string
		fmt.Fscan(in, &s)
		return rune(s[0])
	}

	q2 := func(l, r int) int {
		fmt.Fprintf(out, "? 2 %d %d\n", l+1, r+1)
		out.Flush()

		var n int
		fmt.Fscan(in, &n)
		return n
	}

	var n int
	fmt.Fscan(in, &n)
	s := make([]rune, n)
	m := make([]int, 26)
	var cnt int
	for i := 0; i < n; i++ {
		l, r := -1, cnt
		for r-l > 1 {
			mid := (l + r) / 2
			if q2(m[mid], i) < cnt-mid+1 {
				l = mid
			} else {
				r = mid
			}
		}

		if l == -1 {
			s[i] = q1(i)
			m[cnt] = i
			cnt++
		} else {
			s[i] = s[m[l]]
			for j := l; j+1 < cnt; j++ {
				m[j] = m[j+1]
			}
			m[cnt-1] = i
		}
	}
	fmt.Fprintf(out, "! %s\n", string(s))
}

package main

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

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

	q1 := func(n int) rune {
		fmt.Fprintf(out, "? 1 %d\n", n+1)
		out.Flush()

		var s string
		fmt.Fscan(in, &s)
		return rune(s[0])
	}

	q2 := func(l, r int) int {
		fmt.Fprintf(out, "? 2 %d %d\n", l+1, r+1)
		out.Flush()

		var n int
		fmt.Fscan(in, &n)
		return n
	}

	var n int
	fmt.Fscan(in, &n)
	s := make([]rune, n)
	m := make([]int, 26)
	var cnt int
	for i := 0; i < n; i++ {
		l, r := -1, cnt
		for r-l > 1 {
			mid := (l + r) / 2
			if q2(m[mid], i) < cnt-mid+1 {
				l = mid
			} else {
				r = mid
			}
		}

		if l == -1 {
			s[i] = q1(i)
			cnt++
			m[cnt] = i
		} else {
			s[i] = s[m[l]]
			for j := l; j+1 < cnt; j++ {
				m[j] = m[j+1]
			}
			m[cnt-1] = i
		}
	}
	fmt.Fprintf(out, "! %s\n", string(s))
}

package main

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

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

	q1 := func(n int) rune {
		fmt.Fprintf(out, "? 1 %d\n", n)
		out.Flush()

		var s string
		fmt.Fscan(in, &s)
		return rune(s[0])
	}

	q2 := func(l, r int) int {
		fmt.Fprintf(out, "? 2 %d %d\n", l+1, r+1)
		out.Flush()

		var n int
		fmt.Fscan(in, &n)
		return n
	}

	var n int
	fmt.Fscan(in, &n)
	s := make([]rune, n)
	m := make([]int, 26)
	var cnt int
	for i := 0; i < n; i++ {
		l, r := -1, cnt
		for r-l > 1 {
			mid := (l + r) / 2
			if q2(m[mid], i) < cnt-mid+1 {
				l = mid
			} else {
				r = mid
			}
		}

		if l == -1 {
			s[i] = q1(i)
			cnt++
			m[cnt] = i
		} else {
			s[i] = s[m[l]]
			for j := l; j+1 < cnt; j++ {
				m[j] = m[j+1]
			}
			m[cnt-1] = i
		}
	}
	fmt.Fprintf(out, "! %s\n", string(s))
}

package main

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

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

	q1 := func(n int) rune {
		fmt.Fprintf(out, "? 1 %d\n", n)
		out.Flush()

		var s string
		fmt.Fscan(in, &s)
		return rune(s[0])
	}

	q2 := func(l, r int) int {
		fmt.Fprintf(out, "? 2 %d %d\n", l+1, r+1)
		out.Flush()

		var n int
		fmt.Fscan(in, &n)
		return n
	}

	var n int
	fmt.Fscan(in, &n)
	s := make([]rune, n)
	m := make([]int, 26)
	var cnt int
	for i := 0; i < n; i++ {
		l, r := -1, cnt
		for r-l > 1 {
			mid := (l + r) / 2
			if q2(m[mid], i) < cnt-mid+1 {
				l = mid
			} else {
				r = mid
			}
		}

		if l == -1 {
			s[i] = q1(i)
			cnt++
			m[cnt] = i
		} else {
			s[i] = s[m[l]]
			for j := l; j+1 < cnt; j++ {
				m[j] = m[j+1]
			}
			m[cnt-1] = i
		}
	}
	fmt.Fprintln(out, string(s))
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

type entry struct {
	a byte
	i int
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	last := make([]entry, 0)
	fmt.Fprintln(w, "? 1 1")
	w.Flush()
	var ans string
	fmt.Fscan(r, &ans)
	last = append(last, entry{ans[0], 0})
	for i:=1;i<n;i++ {
		if len(last) != 26 {
			fmt.Fprintf(w, "? 2 %d %d\n", 1, i+1)
			w.Flush()
			var cnt int
			fmt.Fscan(r, &cnt)
			if cnt == len(last) {
				left, right := 0, len(last)-1
				for left < right {
					m := (left + right) / 2
					fmt.Fprintf(w, "? 2 %d %d\n", last[m].i+2, i+1)
					w.Flush()
					var cnt int
					fmt.Fscan(r, &cnt)
					if cnt == len(last) - m - 1 {
						left = m + 1
					} else {
						right = m
					}
				}
				ans += string([]byte{last[left].a})
				last[left].i = i
				sort.Slice(last, func(i, j int) bool {
					return last[i].i < last[j].i
				})
			} else {
				fmt.Fprintf(w, "? 1 %d\n", i+1)
				w.Flush()
				var input string
				fmt.Fscan(r, &input)
				last = append(last, entry{input[0], i})
				sort.Slice(last, func(i, j int) bool {
					return last[i].i < last[j].i
				})
				ans += string([]byte{input[0]})
			}
		} else {
			left, right := 0, 25
			for left < right {
				m := (left + right) / 2
				fmt.Fprintf(w, "? 2 %d %d\n", last[m].i+1, i+1)
				w.Flush()
				var cnt int
				fmt.Fscan(r, &cnt)
				if cnt == 25 - m {
					left = m + 1
				} else {
					right = m
				}
			}
			ans += string([]byte{last[left].a})
			last[left].i = i
			sort.Slice(last, func(i, j int) bool {
				return last[i].i < last[j].i
			})
		}
	}
	fmt.Fprintf(w, "! %s", ans)
}