package main

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

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

const TAM = 2e5 + 100

type Edge struct {
	to int
	x  int
}

var n int
var parent [TAM]int
var parity [TAM]int
var accXor [TAM]int
var tree [TAM][]Edge
var parityGraph [TAM][]Edge
var bfsVisited [TAM]bool

func rootTree(node int) {
	for _, e := range tree[node] {
		if e.to != parent[node] {
			parent[e.to] = node
			rootTree(e.to)
		}
	}
}

func readInput() {
	var nConditions int
	fmt.Fscan(in, &n, &nConditions)
	for i := 1; i <= n; i++ {
		parent[i] = 0
		parity[i] = -1
		accXor[i] = 0
		tree[i] = []Edge{}
		parityGraph[i] = []Edge{}
		bfsVisited[i] = false
	}

	var fr, to, x int
	for edges := 0; edges < n-1; edges++ {
		fmt.Fscan(in, &fr, &to, &x)
		tree[fr] = append(tree[fr], Edge{to: to, x: x})
		tree[to] = append(tree[to], Edge{to: fr, x: x})

		if x >= 0 {
			var parityX = calcParity(x)
			parityGraph[fr] = append(parityGraph[fr], Edge{to: to, x: parityX})
			parityGraph[to] = append(parityGraph[to], Edge{to: fr, x: parityX})
		}
	}

	for edges := 0; edges < nConditions; edges++ {
		fmt.Fscan(in, &fr, &to, &x)
		parityGraph[fr] = append(parityGraph[fr], Edge{to: to, x: x})
		parityGraph[to] = append(parityGraph[to], Edge{to: fr, x: x})
	}

	rootTree(1)
}

func setParity(node, p int) bool {
	if parity[node] == p {
		return true
	}
	if parity[node] != -1 {
		return false
	}
	parity[node] = p
	for _, e := range parityGraph[node] {
		if !setParity(e.to, p^e.x) {
			return false
		}
	}
	return true
}

func calcParity(x int) int {
	var ans = 0
	for i := 0; i < 30; i++ {
		if ((x >> i) & 1) != 0 {
			ans++
		}
	}
	return ans % 2
}

func solveBFS(start int) bool {
	// fmt.Fprintf(out, "start BFS at %d\n", start)
	var queue []int
	queue = append(queue, start)
	for len(queue) > 0 {
		var node = queue[0]
		bfsVisited[node] = true
		// fmt.Fprintf(out, "bfs(%d) parity = %d, acc = %d\n", node, parity[node], accXor[node])
		queue = queue[1:]

		for i, e := range tree[node] {
			if e.to == parent[node] || parity[e.to] == -1 {
				continue
			}
			if e.x != -1 {
				accXor[e.to] = accXor[node] ^ e.x
				if parity[e.to] != calcParity(accXor[e.to]) {
					return false
				}
			} else {
				if parity[node] == parity[e.to] {
					accXor[e.to] = accXor[node]
				} else {
					accXor[e.to] = accXor[node] ^ 1
				}
				tree[node][i].x = accXor[e.to] ^ accXor[node]
			}
			queue = append(queue, e.to)
		}

	}
	return true
}

func solve() {
	for node := 1; node <= n; node++ {
		if parity[node] == -1 {
			if !setParity(node, 0) {
				fmt.Fprintf(out, "NO\n")
				return
			}
		}
	}
	if !solveBFS(1) {
		fmt.Fprintf(out, "NO\n")
		return
	}
	fmt.Fprintf(out, "YES\n")
	for fr := 1; fr <= n; fr++ {
		for _, e := range tree[fr] {
			if e.to != parent[fr] {
				fmt.Fprintf(out, "%d %d %d\n", fr, e.to, e.x)
			}
		}
	}
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		readInput()
		solve()
	}
	out.Flush()
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n, m int
	scan(&n, &m)

	var (
		edges = make([][3]int, n-1)
		adj   = make([][]edge, n)
	)
	for i := 0; i < n-1+m; i++ {
		var x, y, w int
		scan(&x, &y, &w)
		if i < n-1 {
			edges[i] = [3]int{x - 1, y - 1, w}
		}
		if w == -1 {
			continue
		}
		adj[x-1] = append(adj[x-1], edge{y - 1, parity(w)})
		adj[y-1] = append(adj[y-1], edge{x - 1, parity(w)})
	}

	var (
		walk     func(curr, val, prev int)
		ans      = make([]int, n)
		solvable = true
	)
	for i := range ans {
		ans[i] = -1
	}
	walk = func(curr, val, prev int) {
		if ans[curr] != -1 {
			solvable = solvable && ans[curr] == val
			return
		}
		ans[curr] = val
		for _, e := range adj[curr] {
			if e.v == prev {
				continue
			}
			walk(e.v, val^e.p, curr)
		}
	}
	for i := range ans {
		if ans[i] == -1 {
			walk(i, 0, -1)
		}
	}
	if !solvable {
		printf("NO\n")
		return
	}
	printf("YES\n")
	for _, e := range edges {
		w := e[2]
		if w == -1 {
			w = ans[e[0]] ^ ans[e[1]]
		}
		printf("%v %v %v\n", e[0]+1, e[1]+1, w)
	}
}

type edge struct {
	v, p int
}

func parity(x int) (r int) {
	for x > 0 {
		x &= x - 1
		r ^= 1
	}
	return
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	// defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n, m int
	scan(&n, &m)

	var (
		edges = make([][3]int, n-1)
		adj   = make([][]edge, n)
	)
	for i := 0; i < n-1+m; i++ {
		var x, y, w int
		scan(&x, &y, &w)
		if i < n-1 {
			edges[i] = [3]int{x - 1, y - 1, w}
		}
		if w == -1 {
			continue
		}
		adj[x-1] = append(adj[x-1], edge{y - 1, parity(w)})
		adj[y-1] = append(adj[y-1], edge{x - 1, parity(w)})
	}

	var (
		walk     func(v, val, prev int)
		ans      = make([]int, n)
		solvable = true
	)
	walk = func(v, val, prev int) {
		if ans[v] > 0 {
			solvable = solvable && ans[v] == val
			return
		}
		ans[v] = val
		for _, e := range adj[v] {
			if e.v == prev {
				continue
			}
			walk(e.v, val^e.p, v)
		}
	}
	for i := range ans {
		if ans[i] == 0 {
			walk(i, 0, -1)
		}
	}
	if !solvable {
		printer.WriteString("NO\n")
		return
	}
	printer.WriteString("YES\n")
	for _, e := range edges {
		w := e[2]
		if w == -1 {
			w = ans[e[0]] ^ ans[e[1]]
		}
		printer.printInt(e[0] + 1)
		printer.WriteByte(' ')
		printer.printInt(e[1] + 1)
		printer.WriteByte(' ')
		printer.printInt(w)
		printer.WriteByte('\n')
	}
	writer.WriteString(printer.String())
	printer.Reset()
	writer.Flush()
}

type edge struct {
	v, p int
}

func parity(x int) (r int) {
	for x > 0 {
		x &= x - 1
		r ^= 1
	}
	return
}

var printer = FastPrinter{}

type FastPrinter struct{ strings.Builder }

func (p *FastPrinter) printInt(i int) {
	if i == 0 {
		p.WriteByte('0')
		return
	}
	neg := false
	if i < 0 {
		neg = true
		i = -i
	}
	buf := []byte{}
	for i > 0 {
		buf = append(buf, '0'+byte(i%10))
		i /= 10
	}
	if neg {
		buf = append(buf, '-')
	}
	n := len(buf)
	for i := range buf {
		buf[i], buf[n-1-i] = buf[n-1-i], buf[i]
	}
	p.Write(buf)
}

package main

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

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

const TAM = 2e5 + 100

type Edge struct {
	to int
	x  int
}

var n int
var parent [TAM]int
var parity [TAM]int
var accXor [TAM]int
var tree [TAM][]Edge
var parityGraph [TAM][]Edge
var bfsVisited [TAM]bool
var order []int

func rootTree(node int) {
	order = append(order, node)
	for _, e := range tree[node] {
		if e.to != parent[node] {
			parent[e.to] = node
			rootTree(e.to)
		}
	}
}

func readInput() {
	var nConditions int
	fmt.Fscan(in, &n, &nConditions)
	for i := 1; i <= n; i++ {
		parent[i] = 0
		parity[i] = -1
		accXor[i] = 0
		tree[i] = []Edge{}
		parityGraph[i] = []Edge{}
		bfsVisited[i] = false
	}
	order = []int{}

	var fr, to, x int
	for edges := 0; edges < n-1; edges++ {
		fmt.Fscan(in, &fr, &to, &x)
		tree[fr] = append(tree[fr], Edge{to: to, x: x})
		tree[to] = append(tree[to], Edge{to: fr, x: x})
	}

	for edges := 0; edges < nConditions; edges++ {
		fmt.Fscan(in, &fr, &to, &x)
		parityGraph[fr] = append(parityGraph[fr], Edge{to: to, x: x})
		parityGraph[to] = append(parityGraph[to], Edge{to: fr, x: x})
	}

	rootTree(1)
}

func setParity(node, p int) bool {
	if parity[node] == p {
		return true
	}
	if parity[node] != -1 {
		return false
	}
	parity[node] = p
	for _, e := range parityGraph[node] {
		if !setParity(e.to, p^e.x) {
			return false
		}
	}
	return true
}

func calcParity(x int) int {
	var ans = 0
	for i := 0; i < 30; i++ {
		if ((x >> i) & 1) != 0 {
			ans++
		}
	}
	return ans % 2
}

func solveBFS(start int) bool {
	// fmt.Fprintf(out, "start BFS at %d\n", start)
	var queue []int
	queue = append(queue, start)
	for len(queue) > 0 {
		var node = queue[0]
		bfsVisited[node] = true
		// fmt.Fprintf(out, "bfs(%d) parity = %d, acc = %d\n", node, parity[node], accXor[node])
		queue = queue[1:]

		for _, e := range tree[node] {
			if e.to == parent[node] {
				continue
			}
			if e.x != -1 && parity[e.to] == -1 {
				var toParity = calcParity(accXor[node] ^ e.x)
				if !setParity(e.to, toParity) {
					return false
				}
			}
		}

		for i, e := range tree[node] {
			if e.to == parent[node] || parity[e.to] == -1 {
				continue
			}
			if e.x != -1 {
				accXor[e.to] = accXor[node] ^ e.x
				if parity[e.to] != calcParity(accXor[e.to]) {
					return false
				}
			} else {
				if parity[node] == parity[e.to] {
					accXor[e.to] = accXor[node]
				} else {
					accXor[e.to] = accXor[node] ^ 1
				}
				tree[node][i].x = accXor[e.to] ^ accXor[node]
			}
			queue = append(queue, e.to)
		}

	}
	return true
}

func solve() {
	for i := 0; i < n; i++ {
		var node = order[i]
		if bfsVisited[node] {
			continue
		}
		if parity[node] == -1 {
			if !setParity(node, 0) {
				fmt.Fprintf(out, "NO\n")
				return
			}
		}
		if i != 0 {
			var fr = parent[node]
			var to = node
			for i, e := range tree[fr] {
				if e.to == to {
					accXor[e.to] = accXor[fr]
					tree[fr][i].x = 0
				}
			}
		}
		if !solveBFS(node) {
			fmt.Fprintf(out, "NO\n")
			return
		}
	}
	fmt.Fprintf(out, "YES\n")
	for fr := 1; fr <= n; fr++ {
		for _, e := range tree[fr] {
			if e.to != parent[fr] {
				fmt.Fprintf(out, "%d %d %d\n", fr, e.to, e.x)
			}
		}
	}
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		readInput()
		solve()
	}
	out.Flush()
}

package main

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

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

const TAM = 2e5 + 100

type Edge struct {
	to int
	x  int
}

var n int
var parent [TAM]int
var order []int
var parity [TAM]int
var accXor [TAM]int
var tree [TAM][]Edge
var parityGraph [TAM][]Edge

func rootTree(node int) {
	order = append(order, node)
	for _, e := range tree[node] {
		if e.to != parent[node] {
			parent[e.to] = node
			rootTree(e.to)
		}
	}
}

func readInput() {
	var nConditions int
	fmt.Fscan(in, &n, &nConditions)
	for i := 1; i <= n; i++ {
		parent[i] = 0
		tree[i] = []Edge{}
		parityGraph[i] = []Edge{}
		parity[i] = -1
		order = []int{}
	}

	var fr, to, x int
	for edges := 0; edges < n-1; edges++ {
		fmt.Fscan(in, &fr, &to, &x)
		tree[fr] = append(tree[fr], Edge{to: to, x: x})
		tree[to] = append(tree[to], Edge{to: fr, x: x})
	}

	for edges := 0; edges < nConditions; edges++ {
		fmt.Fscan(in, &fr, &to, &x)
		parityGraph[fr] = append(parityGraph[fr], Edge{to: to, x: x})
		parityGraph[to] = append(parityGraph[to], Edge{to: fr, x: x})
	}

	rootTree(1)
}

func setParity(node, p int) bool {
	if parity[node] == p {
		return true
	}
	if parity[node] != -1 {
		return false
	}
	parity[node] = p
	for _, e := range parityGraph[node] {
		if !setParity(e.to, p^e.x) {
			return false
		}
	}
	return true
}

func calcParity(x int) int {
	var ans = 0
	for i := 0; i < 30; i++ {
		if ((x >> i) & 1) != 0 {
			ans++
		}
	}
	return ans % 2
}

func solveBFS(start int) bool {
	// fmt.Fprintf(out, "start BFS at %d\n", start)
	var queue []int
	queue = append(queue, start)
	for len(queue) > 0 {
		var node = queue[0]
		// fmt.Fprintf(out, "bfs(%d) parity = %d, acc = %d\n", node, parity[node], accXor[node])
		queue = queue[1:]

		for _, e := range tree[node] {
			if e.to == parent[node] {
				continue
			}
			if e.x != -1 && parity[e.to] == -1 {
				var startParity = calcParity(accXor[node] ^ e.x)
				if !setParity(e.to, startParity) {
					return false
				}
			}
		}

		for i, e := range tree[node] {
			if e.to == parent[node] || parity[e.to] == -1 {
				continue
			}
			if e.x != -1 {
				accXor[e.to] = accXor[node] ^ e.x
				if parity[e.to] != calcParity(accXor[e.to]) {
					return false
				}
			} else {
				if parity[node] == parity[e.to] {
					accXor[e.to] = accXor[node]
				} else {
					accXor[e.to] = accXor[node] ^ 1
				}
				tree[node][i].x = accXor[e.to] ^ accXor[node]
			}
			queue = append(queue, e.to)
		}

	}
	return true
}

func solve() {
	for i := 0; i < n; i++ {
		if parity[order[i]] == -1 {
			if !setParity(order[i], 0) {
				fmt.Fprintf(out, "NO\n")
				return
			}
			if i != 0 {
				var fr = parent[order[i]]
				var to = order[i]
				for i, e := range tree[fr] {
					if e.to == to {
						accXor[e.to] = accXor[fr]
						tree[fr][i].x = 0
					}
				}
			}
			if !solveBFS(order[i]) {
				fmt.Fprintf(out, "NO\n")
				return
			}
		}
	}
	fmt.Fprintf(out, "YES\n")
	for fr := 1; fr <= n; fr++ {
		for _, e := range tree[fr] {
			if e.to != parent[fr] {
				fmt.Fprintf(out, "%d %d %d\n", fr, e.to, e.x)
			}
		}
	}
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		readInput()
		solve()
	}
	out.Flush()
}


package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,s int
		fmt.Fscan(in,&n,&s)
		fmt.Fprintln(out,(s/((n/2)+1)))
	}
}

package main

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

type CF1566A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1566A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1566A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1566A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1566A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1566A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1566A
Date: 13/03/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1566/A
Problem: CF1566A
**/
func (in *CF1566A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, s := in.NextInt(), in.NextInt()
		pos := int(math.Ceil(float64(n)/2.0)) - 1
		if n-pos != 0 {
			nums := int(math.Floor(float64(s / (n - pos))))
			fmt.Println(nums)
		} else {
			fmt.Println(s)
		}
	}
}

func NewCF1566A(r *bufio.Reader) *CF1566A {
	return &CF1566A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1566A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, s := 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &s)
		fmt.Fprintln(w, s/((n>>1)+1))
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"fmt"
	"log"
)

var (
	t int
)

func main() {
	if _, err := fmt.Scan(&t); err != nil {
		log.Fatal(err)
	}

	for i := 0; i < t; i++ {
		n, s := getValues()
		res := binSearch(n, s)
		fmt.Println(res)
	}
}

func getValues() (int64, int64) {
	var n, s int64
	if _, err := fmt.Scan(&n, &s); err != nil {
		log.Fatal(err)
	}
	return n, s
}

func binSearch(n, s int64) int64 {
	var lowerBound int64 = 0
	var upperBound int64 = s * 10
	for upperBound-lowerBound > 1 {

		var Median int64 = (lowerBound + upperBound) / 2
		var m int64 = n/2 + 1

		if m*Median <= s {
			lowerBound = Median
		} else {
			upperBound = Median
		}
	}
	return lowerBound
}

package main

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

func solve(n, s int) int {
	return s / (n - (n-1)/2)
}

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, s int
)

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &s)
		fmt.Println(solve(n, s))
	}
}

package main

import "fmt"

func main() {
	var t, n, s, temp int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n, &s)
		// fmt.Print(ans, "**")
		temp = (n + 1) / 2
		temp = n - temp + 1
		s = s / temp
		fmt.Println(s)
	}
}

package main

import (
	"fmt"
	"math"
)

func maxMedian(n int, s int) int {
	m := int(math.Ceil(float64(n) / 2))
	l := n - m + 1

	return s / l;
}

func main() {
	t := 0
	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		n := 0
		s := 0

		fmt.Scan(&n)
		fmt.Scan(&s)
		r := maxMedian(n, s)
		fmt.Println(r)
	}
}

package main

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

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

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

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

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

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

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

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

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

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

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

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

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

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

	return
}

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

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

	return num
}

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

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

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n, s int
		fmt.Fscan(input, &n, &s)

		// ARRAY := make([]int, n)

		// STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)

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

		if n%2 == 0 {
			k := (n / 2) + 1
			q := s / k
			fmt.Println(q)

		} else {
			k := (n / 2) + 1
			q := s / k
			fmt.Println(q)
		}

	}
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

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

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

func solve(n, s int64) int64 {
	if n == 1 {
		return s
	}

	return s / (n/2 + 1)
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i++ {
		n, s := stdin.Int64(), stdin.Int64()
		fmt.Println(solve(n, s))
	}
}

package main

import (
	"bufio"
	"math"
	"os"
	"strconv"
)

func solve() {
	n := get64()
	s := get64()

	l, r := L(0), s+1
	for r-l > 1 {
		m := (l + r) / 2
		if m*(n/2+1) <= s {
			l = m
			continue
		}
		r = m
	}

	put64ln(l)
}

const (
	once       = false
	maxBufSize = 10000000
)

var (
	splitFunc = bufio.ScanWords
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(splitFunc)
	in.Buffer(make([]byte, maxBufSize), maxBufSize)

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	t := get()
	for t > 0 {
		solve()
		t--
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func geta1(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get() - 1
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func get64a1(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64() - 1
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES\n")
}

func no() {
	puts("NO\n")
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

func line() {
	out.WriteRune('\n')
}

func space() {
	out.WriteRune(' ')
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func absf(x float64) float64 {
	return math.Abs(x)
}

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

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

func maxf(x float64, y float64) float64 {
	if x > y {
		return x
	}
	return y
}

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func min64(x int64, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func minf(x float64, y float64) float64 {
	if x < y {
		return x
	}
	return y
}

func L(i int) int64 {
	return int64(i)
}

package main

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

//goland:noinspection GoUnusedFunction
func min(a int, nums ...int) int {
	min := a

	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

//goland:noinspection GoUnusedFunction
func max(a int, nums ...int) int {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func fprintlnArr(w io.Writer, arr []int) {
	for _, val := range arr {
		fmt.Fprint(w, val, " ")
	}
	fmt.Fprintln(w)
}

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

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n, s int
		fmt.Fscan(in, &n, &s)
		// s/(n/2+1)
		/*fmt.Fprintln(out, sort.Search(s/(n/2+1), func(x int) bool {
			return s <= (n/2+1)*x
		}))*/
		fmt.Fprintln(out, s/(n/2+1))
	}
}

package main

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

//goland:noinspection GoUnusedFunction
func min(a int, nums ...int) int {
	min := a

	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

//goland:noinspection GoUnusedFunction
func max(a int, nums ...int) int {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func fprintlnArr(w io.Writer, arr []int) {
	for _, val := range arr {
		fmt.Fprint(w, val, " ")
	}
	fmt.Fprintln(w)
}

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

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n, s int
		fmt.Fscan(in, &n, &s)
		fmt.Fprintln(out, sort.Search(s/(n/2+1), func(x int) bool {
			//fmt.Fprintln(out, x)
			return s <= x+n/2*x
		}))
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t, n, s int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		fmt.Scan(&n, &s)
		cells := int(math.Ceil(float64(n) / 2.0))
		if n%2 == 0 {
			cells++
		}

		fmt.Println(s/cells)
	}
}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int

	fmt.Fscanf(r, "%d\n", &T)

	for t := 0; t < T; t++ {
		var n, s int
		fmt.Fscanf(r, "%d %d\n", &n, &s)

		x := s / (n/2 + 1)
		fmt.Println(x)
	}
}

package main

import (
	"bufio"
	"math"
	"os"
	"strconv"
)

func solve() {
	n := get()
	s := get()

	l, r := 0, s+1
	for r-l > 1 {
		m := (l + r) / 2
		if m*(n/2+1) <= s {
			l = m
			continue
		}
		r = m
	}

	putln(l)
}

const (
	once       = false
	maxBufSize = 10000000
)

var (
	splitFunc = bufio.ScanWords
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(splitFunc)
	in.Buffer(make([]byte, maxBufSize), maxBufSize)

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	t := get()
	for t > 0 {
		solve()
		t--
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func geta1(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get() - 1
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func get64a1(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64() - 1
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES\n")
}

func no() {
	puts("NO\n")
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

func line() {
	out.WriteRune('\n')
}

func space() {
	out.WriteRune(' ')
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func absf(x float64) float64 {
	return math.Abs(x)
}

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

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

func maxf(x float64, y float64) float64 {
	return math.Max(x, y)
}

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func min64(x int64, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func minf(x float64, y float64) float64 {
	return math.Min(x, y)
}

func L(i int) int64 {
	return int64(i)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t, n, s int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		fmt.Scan(&n, &s)
		cells := int(math.Ceil(float64(n) / 2.0))
		if n%2 == 0 {
			cells++
		}

		fmt.Println("fin", s/cells)
	}
}


package main

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

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

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

func write(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

type unit struct {
	char  byte
	count int64
}

func (unt *unit) contains(that *unit) int64 {
	if unt.char != that.char || unt.count < that.count {
		return 0
	}
	return unt.count - that.count + 1
}

func unify(unit []unit) []unit {
	last := 0
	for i := 1; i < len(unit); i++ {
		if unit[i].char == unit[i-1].char {
			unit[last].count += unit[i].count
		} else {
			last++
			unit[last] = unit[i]
		}
	}
	return unit[:last+1]
}

type matcher struct {
	text, pattern []unit
}

func (mcr *matcher) generatePi() []int {
	var n = len(mcr.pattern)
	pi := make([]int, n)
	for i, k := 2, 0; i < n-1; i++ {
		for k > 0 && mcr.pattern[i].contains(&mcr.pattern[k+1]) != 1 {
			k = pi[k+1]
		}
		if mcr.pattern[i].contains(&mcr.pattern[k+1]) == 1 {
			k++
		}
		pi[i] = k
	}
	return pi
}

func (mcr *matcher) containsIds(i, j int) int64 {
	return mcr.text[i].contains(&mcr.pattern[j])
}

func (mcr *matcher) countMatches() int64 {
	var m, n int = len(mcr.text), len(mcr.pattern)
	if m < n {
		return 0
	}

	occurrences := int64(0)
	if n <= 2 {
		for i := 0; i < m; i++ {
			if n == 1 {
				occurrences += mcr.containsIds(i, 0)
				continue
			}
			if i == m-1 {
				continue
			}
			if mcr.containsIds(i, 0) > 0 && mcr.containsIds(i+1, 1) > 0 {
				occurrences++
			}
		}
		return occurrences
	}

	pi := mcr.generatePi()

	for i, j := 1, 1; i < m-1; i++ {
		for j > 1 && mcr.containsIds(i, j) != 1 {
			j = pi[j] + 1
		}
		if j < n-1 && mcr.containsIds(i, j) == 1 {
			j++
		}
		if j == n-1 {
			if mcr.containsIds(i+1, n-1) > 0 && mcr.containsIds(i-n+2, 0) > 0 {
				occurrences++
			}
			j = pi[j-1] + 1
		}
	}
	return occurrences
}

func readUnits(units []unit) {
	var tmp string
	n := len(units)
	for i := 0; i < n; i++ {
		read(&units[i].count, &tmp)
		units[i].char = tmp[1]
	}
}

func main() {
	defer writer.Flush()

	var m, n int
	read(&m, &n)

	text := make([]unit, m)
	pattern := make([]unit, n)

	readUnits(text)
	readUnits(pattern)
	text = unify(text)
	pattern = unify(pattern)

	matcher := matcher{text, pattern}

	write(matcher.countMatches())
}

package main

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

var debug bool = false
var debugCounter int = 0
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func Debug(a ...interface{}) {
	if !debug {
		return
	}
	debugCounter++
	fmt.Fprint(writer, debugCounter, " ")
	fmt.Fprintln(writer, a...)
	writer.Flush()
}

type Unit struct {
	char  byte
	count int64
}

func (this *Unit) Equals(that *Unit) bool {
	return this.char == that.char && this.count == that.count
}

func (this *Unit) Contains(that *Unit) int64 {
	if this.char != that.char || this.count < that.count {
		return 0
	}
	return this.count - that.count + 1
}

func Unify(unit []Unit) []Unit {
	last := 0
	for i := 1; i < len(unit); i++ {
		if unit[i].char == unit[i-1].char {
			unit[last].count += unit[i].count
		} else {
			last++
			unit[last] = unit[i]
		}
	}
	return unit[:last+1]
}

type MatchCounter struct {
	text, pattern []Unit
}

func (this *MatchCounter) generatePi() []int {
	var n int = len(this.pattern)
	pi := make([]int, n)
	for i, k := 2, 0; i < n-1; i++ {
		for k > 0 && !this.pattern[i].Equals(&this.pattern[k+1]) {
			k = pi[k+1]
		}
		if this.pattern[i].Equals(&this.pattern[k+1]) {
			k++
		}
		pi[i] = k
	}
	return pi
}

func (this *MatchCounter) CountMatches() int64 {
	var m, n int = len(this.text), len(this.pattern)
	if m < n {
		return 0
	}

	Debug("MATCH START")

	occurrences := int64(0)
	if n <= 2 {
		for i := 0; i < m; i++ {
			if n == 1 {
				occurrences += this.text[i].Contains(&this.pattern[0])
				continue
			}
			if i == m-1 {
				continue
			}
			if this.text[i].Contains(&this.pattern[0]) > 0 && this.text[i+1].Contains(&this.pattern[1]) > 0 {
				occurrences++
			}
		}
		Debug("CASE 1")
		return occurrences
	}

	pi := this.generatePi()
	Debug("PI OK")

	for i, j := 1, 1; i < m-1; i++ {
		for j > 1 && !this.text[i].Equals(&this.pattern[j]) {
			j = pi[j] + 1
		}
		if j < n-1 && this.text[i].Equals(&this.pattern[j]) {
			j++
		}
		if j == n-1 {
			Debug("FOUND", j, m, n, i+1, n-1, i-n+2)
			if this.text[i+1].Contains(&this.pattern[n-1]) > 0 && this.text[i-n+2].Contains(&this.pattern[0]) > 0 {
				occurrences++
			}
			j = pi[j-1] + 1
			Debug("PROCESSED", j, occurrences)
		}
	}
	return occurrences
}

func readUnits(units []Unit) {
	var tmp string
	n := len(units)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &units[i].count, &tmp)
		units[i].char = tmp[1]
	}
}

func main() {
	var m, n int

	fmt.Fscan(reader, &m, &n)
	if m == 200000 && n == 100000 {
		// debug = true
	}
	// debug = true

	text := make([]Unit, m)
	pattern := make([]Unit, n)
	readUnits(text)
	readUnits(pattern)
	Debug("READ OK")

	text = Unify(text)
	pattern = Unify(pattern)
	Debug("UNIFY OK")

	matcher := MatchCounter{text, pattern}
	Debug("INIT OK")

	fmt.Fprintln(writer, matcher.CountMatches())
	writer.Flush()
}

package main

import (
	"fmt"
)

type Unit struct {
	char  byte
	count int
}

func (this *Unit) Equals(that *Unit) bool {
	return this.char == that.char && this.count == that.count
}

func (this *Unit) Contains(that *Unit) int {
	if this.char != that.char {
		return 0
	}
	return this.count - that.count + 1
}

func Unify(unit []Unit) []Unit {
	last := 0
	for i := 1; i < len(unit); i++ {
		if unit[i].char == unit[i-1].char {
			unit[last].count += unit[i].count
		} else {
			last++
			unit[last] = unit[i]
		}
	}
	return unit[:last+1]
}

type MatchCounter struct {
	text, pattern []Unit
}

func (this *MatchCounter) generatePi() []int {
	var n int = len(this.pattern)
	pi := make([]int, n)
	for i, k := 1, 2; i < n-1; i++ {
		for k > 0 && !this.pattern[i].Equals(&this.pattern[k]) {
			k = pi[k]
		}
		if this.pattern[i].Equals(&this.pattern[k]) {
			k++
		}
		pi[i] = k
	}
	return pi
}

func (this *MatchCounter) CountMatches() int64 {
	var m, n int = len(this.text), len(this.pattern)

	occurrences := int64(0)
	if n == 1 {
		for _, unit := range this.text {
			occurrences += int64(unit.Contains(&this.pattern[0]))
		}
		return occurrences
	}

	pi := this.generatePi()

	for i, j := 0, 1; i < m-1; i++ {
		for j > 1 && !this.text[i].Equals(&this.pattern[j]) {
			j = pi[j] + 1
		}
		if j < n-1 && this.text[i].Equals(&this.pattern[j]) {
			j++
		}
		if j == n-1 {
			if this.text[i+1].Contains(&this.pattern[n-1]) > 0 && this.text[i-n+2].Contains(&this.pattern[0]) > 0 {
				occurrences++
			}
			j = pi[j] + 1
		}
	}
	return occurrences
}

func main() {
	var m, n int

	fmt.Scan(&m, &n)
	text := make([]Unit, m)
	pattern := make([]Unit, n)

	var tmp string

	for i := 0; i < m; i++ {
		fmt.Scan(&text[i].count, &tmp)
		text[i].char = tmp[1]
	}

	for i := 0; i < n; i++ {
		fmt.Scan(&pattern[i].count, &tmp)
		pattern[i].char = tmp[1]
	}

	text = Unify(text)
	pattern = Unify(pattern)

	matcher := MatchCounter{text, pattern}

	fmt.Println(matcher.CountMatches())
}

package main

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

var debug bool = false
var debugCounter int = 0
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func Debug(a ...interface{}) {
	if !debug {
		return
	}
	debugCounter++
	fmt.Fprint(writer, debugCounter, " ")
	fmt.Fprintln(writer, a...)
	writer.Flush()
}

type Unit struct {
	char  byte
	count int
}

func (this *Unit) Equals(that *Unit) bool {
	return this.char == that.char && this.count == that.count
}

func (this *Unit) Contains(that *Unit) int {
	if this.char != that.char || this.count < that.count {
		return 0
	}
	return this.count - that.count + 1
}

func Unify(unit []Unit) []Unit {
	last := 0
	for i := 1; i < len(unit); i++ {
		if unit[i].char == unit[i-1].char {
			unit[last].count += unit[i].count
		} else {
			last++
			unit[last] = unit[i]
		}
	}
	return unit[:last+1]
}

type MatchCounter struct {
	text, pattern []Unit
}

func (this *MatchCounter) generatePi() []int {
	var n int = len(this.pattern)
	pi := make([]int, n)
	for i, k := 2, 0; i < n-1; i++ {
		for k > 0 && !this.pattern[i].Equals(&this.pattern[k+1]) {
			k = pi[k+1]
		}
		if this.pattern[i].Equals(&this.pattern[k+1]) {
			k++
		}
		pi[i] = k
	}
	return pi
}

func (this *MatchCounter) CountMatches() int64 {
	var m, n int = len(this.text), len(this.pattern)
	if m < n {
		return 0
	}

	Debug("MATCH START")

	occurrences := int64(0)
	if n <= 2 {
		for i := 0; i < m; i++ {
			if n == 1 {
				occurrences += int64(this.text[i].Contains(&this.pattern[0]))
				continue
			}
			if i == m-1 {
				continue
			}
			if this.text[i].Contains(&this.pattern[0]) > 0 && this.text[i+1].Contains(&this.pattern[1]) > 0 {
				occurrences++
			}
		}
		Debug("CASE 1")
		return occurrences
	}

	pi := this.generatePi()
	Debug("PI OK")

	for i, j := 1, 1; i < m-1; i++ {
		for j > 1 && !this.text[i].Equals(&this.pattern[j]) {
			j = pi[j] + 1
		}
		if j < n-1 && this.text[i].Equals(&this.pattern[j]) {
			j++
		}
		if j == n-1 {
			Debug("FOUND", j, m, n, i+1, n-1, i-n+2)
			if this.text[i+1].Contains(&this.pattern[n-1]) > 0 && this.text[i-n+2].Contains(&this.pattern[0]) > 0 {
				occurrences++
			}
			j = pi[j-1] + 1
			Debug("PROCESSED", j, occurrences)
		}
	}
	return occurrences
}

func readUnits(units []Unit) {
	var tmp string
	n := len(units)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &units[i].count, &tmp)
		units[i].char = tmp[1]
	}
}

func main() {
	var m, n int

	fmt.Fscan(reader, &m, &n)
	if m == 200000 && n == 100000 {
		// debug = true
	}
	// debug = true

	text := make([]Unit, m)
	pattern := make([]Unit, n)
	readUnits(text)
	readUnits(pattern)
	Debug("READ OK")

	text = Unify(text)
	pattern = Unify(pattern)
	Debug("UNIFY OK")

	matcher := MatchCounter{text, pattern}
	Debug("INIT OK")

	fmt.Fprintln(writer, matcher.CountMatches())
	writer.Flush()
}

package main

import (
	"fmt"
)

type Unit struct {
	char  byte
	count int
}

func (this *Unit) Equals(that *Unit) bool {
	return this.char == that.char && this.count == that.count
}

func (this *Unit) Contains(that *Unit) int {
	if this.char != that.char {
		return 0
	}
	return this.count - that.count + 1
}

func Unify(unit []Unit) []Unit {
	last := 0
	for i := 1; i < len(unit); i++ {
		if unit[i].char == unit[i-1].char {
			unit[last].count += unit[i].count
		} else {
			last++
			unit[last] = unit[i]
		}
	}
	return unit[:last+1]
}

type MatchCounter struct {
	text, pattern []Unit
}

func (this *MatchCounter) generatePi() []int {
	var n int = len(this.pattern)
	pi := make([]int, n)
	for i, k := 1, 2; i < n-1; i++ {
		for k > 0 && !this.pattern[i].Equals(&this.pattern[k]) {
			k = pi[k]
		}
		if this.pattern[i].Equals(&this.pattern[k]) {
			k++
		}
		pi[i] = k
	}
	return pi
}

func (this *MatchCounter) CountMatches() int {
	var m, n int = len(this.text), len(this.pattern)

	occurrences := 0
	if n == 1 {
		for _, unit := range this.text {
			occurrences += unit.Contains(&this.pattern[0])
		}
		return occurrences
	}

	pi := this.generatePi()

	for i, j := 0, 1; i < m-1; i++ {
		for j > 1 && !this.text[i].Equals(&this.pattern[j]) {
			j = pi[j] + 1
		}
		if j < n-1 && this.text[i].Equals(&this.pattern[j]) {
			j++
		}
		if j == n-1 {
			if this.text[i+1].Contains(&this.pattern[n-1]) > 0 && this.text[i-n+2].Contains(&this.pattern[0]) > 0 {
				occurrences++
			}
			j = pi[j] + 1
		}
	}
	return occurrences
}

func main() {
	var m, n int

	fmt.Scan(&m, &n)
	text := make([]Unit, m)
	pattern := make([]Unit, n)

	var tmp string

	for i := 0; i < m; i++ {
		fmt.Scan(&text[i].count, &tmp)
		text[i].char = tmp[1]
	}

	for i := 0; i < n; i++ {
		fmt.Scan(&pattern[i].count, &tmp)
		pattern[i].char = tmp[1]
	}

	text = Unify(text)
	pattern = Unify(pattern)

	matcher := MatchCounter{text, pattern}

	fmt.Println(matcher.CountMatches())
}

package main

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

var debug bool = false
var debugCounter int = 0
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func Debug(a ...interface{}) {
	if !debug {
		return
	}
	debugCounter++
	fmt.Fprint(writer, debugCounter, " ")
	fmt.Fprintln(writer, a...)
	writer.Flush()
}

type Unit struct {
	char  byte
	count int
}

func (this *Unit) Equals(that *Unit) bool {
	return this.char == that.char && this.count == that.count
}

func (this *Unit) Contains(that *Unit) int {
	if this.char != that.char || this.count < that.count {
		return 0
	}
	return this.count - that.count + 1
}

func Unify(unit []Unit) []Unit {
	last := 0
	for i := 1; i < len(unit); i++ {
		if unit[i].char == unit[i-1].char {
			unit[last].count += unit[i].count
		} else {
			last++
			unit[last] = unit[i]
		}
	}
	return unit[:last+1]
}

type MatchCounter struct {
	text, pattern []Unit
}

func (this *MatchCounter) generatePi() []int {
	var n int = len(this.pattern)
	pi := make([]int, n)
	for i, k := 2, 0; i < n-1; i++ {
		for k > 0 && !this.pattern[i].Equals(&this.pattern[k+1]) {
			k = pi[k+1]
		}
		if this.pattern[i].Equals(&this.pattern[k+1]) {
			k++
		}
		pi[i] = k
	}
	return pi
}

func (this *MatchCounter) CountMatches() int64 {
	var m, n int = len(this.text), len(this.pattern)
	if m < n {
		return 0
	}

	Debug("MATCH START")

	occurrences := int64(0)
	if n == 1 {
		for _, unit := range this.text {
			occurrences += int64(unit.Contains(&this.pattern[0]))
		}
		Debug("CASE 1")
		return occurrences
	}

	pi := this.generatePi()
	Debug("PI OK")

	for i, j := 1, 1; i < m-1; i++ {
		for j > 1 && !this.text[i].Equals(&this.pattern[j]) {
			j = pi[j] + 1
		}
		if j < n-1 && this.text[i].Equals(&this.pattern[j]) {
			j++
		}
		if j == n-1 {
			Debug("FOUND", j, m, n, i+1, n-1, i-n+2)
			if this.text[i+1].Contains(&this.pattern[n-1]) > 0 && this.text[i-n+2].Contains(&this.pattern[0]) > 0 {
				occurrences++
			}
			j = pi[j-1] + 1
			Debug("PROCESSED", j)
		}
	}
	return occurrences
}

func readUnits(units []Unit) {
	var tmp string
	n := len(units)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &units[i].count, &tmp)
		units[i].char = tmp[1]
	}
}

func main() {
	var m, n int

	fmt.Fscan(reader, &m, &n)
	if m == 200000 && n == 100000 {
		// debug = true
	}

	text := make([]Unit, m)
	pattern := make([]Unit, n)
	readUnits(text)
	readUnits(pattern)
	Debug("READ OK")

	text = Unify(text)
	pattern = Unify(pattern)
	Debug("UNIFY OK")

	matcher := MatchCounter{text, pattern}
	Debug("INIT OK")

	fmt.Fprintln(writer, matcher.CountMatches())
	writer.Flush()
}


package main

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

type Node struct {
	i int
	v int
	p int
	t int
	s int64
}

func main() {

	reader := bufio.NewReader(os.Stdin)
	var n int

	fmt.Fscanf(reader, "%d\n", &n)

	a := make([]Node, n)

	for i := 0; i < n; i++ {
		if i+1 != n {
			fmt.Fscanf(reader, "%d", &a[i].v)
		} else {
			fmt.Fscanf(reader, "%d\n", &a[i].v)
		}

		a[i].i = i
	}

	//sort inc by v
	sort.Slice(a, func(i, j int) bool {
		return a[i].v < a[j].v
	})

	for i := 2; i < 5 && i < n; i++ {
		a[i].s = int64(a[i].v - a[0].v)
		a[i].p = 0
	}

	for i := 5; i < n; i++ {
		a[i].s = int64(a[i].v-a[i-2].v) + a[i-3].s
		a[i].p = i - 2
		for j := i - 3; j > 2 && j > i-5; j-- {
			if a[i].s > int64(a[i].v-a[j].v)+a[j-1].s {
				a[i].s = int64(a[i].v-a[j].v) + a[j-1].s
				a[i].p = j
			}
		}
	}

	term := 0

	for i := n - 1; i >= 0; {
		term++
		for j := i; j >= a[i].p; j-- {
			a[j].t = term
		}

		i = a[i].p - 1
	}

	fmt.Printf("%d %d\n", a[n-1].s, a[0].t)

	//sort inc by i
	sort.Slice(a, func(i, j int) bool {
		return a[i].i < a[j].i
	})
	for i := 0; i < n; i++ {
		fmt.Printf("%d ", a[i].t)
	}

	fmt.Println()
}

package main

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

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

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

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

type elt struct {
	val int
	pos int
	grp int
}

var (
	n int
	a []elt
)

func val(start, end int) int64 {
	return int64(a[end].val - a[start].val)
}

func mAdd(x int64, rest int64) int64 {
	if rest == math.MaxInt64 {
		return math.MaxInt64
	}
	return int64(x) + rest
}

type memT struct {
	present bool
	tot     int64
	pos     int
}

var (
	mem []memT
)

func dyn0(start int) int64 {
	tot, _ := dyn(start)
	return tot
}

// dyn returns the sum beginning with position start and next splitpoint.
func dyn(start int) (tot int64, pos int) {
	// 0-2 elements remaining.
	if len(a)-start <= 2 {
		return math.MaxInt64, -1
	}

	// 3-5 elements remaining.
	if len(a)-start <= 5 {
		return val(start, len(a)-1), -1
	}

	// Memoization.
	it := &mem[start]
	if it.present {
		return it.tot, it.pos
	}
	defer func() {
		mem[start] = memT{
			present: true,
			tot:     tot,
			pos:     pos,
		}
	}()

	// At this point, more than >= 6 elements are remaining.
	part3 := mAdd(val(start, start+2), dyn0(start+3)) // split to 3 elements and rest
	part4 := mAdd(val(start, start+3), dyn0(start+4)) // split to 4 elements and rest
	part5 := mAdd(val(start, start+4), dyn0(start+5)) // split to 5 elements and rest

	if part3 <= part4 && part3 <= part5 {
		return part3, start + 3
	}
	if part4 <= part3 && part4 <= part5 {
		return part4, start + 4
	}
	return part5, start + 5
}

func main() {
	defer writer.Flush()

	// Read input.
	Scanf("%d\n", &n)
	a = make([]elt, n)
	for i := 0; i < n; i++ {
		Scanf("%d", &a[i].val)
		a[i].pos = i
	}

	// Sort input.
	sort.Slice(a, func(i, j int) bool {
		return a[i].val < a[j].val
	})

	// Calculate groups.
	mem = make([]memT, n)
	minDiv, nextGrp := dyn(0)
	nGrps := 1
	for i := 0; i < n; i++ {
		if i == nextGrp {
			_, nextGrp = dyn(i)
			nGrps++
		}
		a[i].grp = nGrps
	}

	// Reverse the sort.
	ba := make([]elt, n)
	for _, ai := range a {
		ba[ai.pos] = ai
	}

	// Print the final output.
	Printf("%d %d\n", minDiv, nGrps)
	for _, bi := range ba {
		Printf("%d ", bi.grp)
	}
}

package main

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

type Node struct {
	i int
	v int
	p int
	t int
	s int64
}

func main() {

	reader := bufio.NewReader(os.Stdin)
	var n int

	fmt.Fscanf(reader, "%d\n", &n)

	a := make([]Node, n)

	for i := 0; i < n; i++ {
		if i+1 != n {
			fmt.Fscanf(reader, "%d", &a[i].v)
		} else {
			fmt.Fscanf(reader, "%d\n", &a[i].v)
		}

		a[i].i = i
	}

	//sort inc by v
	sort.Slice(a, func(i, j int) bool {
		return a[i].v < a[j].v
	})

	for i := 2; i < 5 && i < n; i++ {
		a[i].s = int64(a[i].v - a[0].v)
		a[i].p = 0
	}

	for i := 5; i < n; i++ {
		a[i].s = int64(a[i].v-a[i-2].v) + a[i-3].s
		a[i].p = i - 2
		for j := i - 3; j > 2 && j > i-5; j-- {
			if a[i].s > int64(a[i].v-a[j].v)+a[j-1].s {
				a[i].s = int64(a[i].v-a[j].v) + a[j-1].s
				a[i].p = j
			}
		}
	}

	term := n / 3

	for i := n - 1; i >= 0; {
		for j := i; j >= a[i].p; j-- {
			a[j].t = term
		}

		i = a[i].p - 1
		term--
	}

	fmt.Printf("%d %d\n", a[n-1].s, a[n-1].t)

	//sort inc by i
	sort.Slice(a, func(i, j int) bool {
		return a[i].i < a[j].i
	})
	for i := 0; i < n; i++ {
		fmt.Printf("%d ", a[i].t)
	}

	fmt.Println()
}


package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"sort"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, I uint
	fmt.Fscanf(reader, "%d %d\n", &n, &I)
	var K = 1 << (8 * I / n)
	if 8 * I / n > 20 {
		fmt.Printf("0")
		return
	}
	a := make([]int, n)
	for i := uint(0);i < n;i ++ {
		fmt.Fscanf(reader, "%d ", &a[i])
	}
	sort.Ints(a)
	b, count := []int{}, 1
	for i := 1;i < len(a);i ++ {
		if a[i] != a[i - 1] {
			b = append(b, count)
			count = 1
		} else {
			count ++
		}
	}
	b = append(b, count)
	if len(b) <= K {
		fmt.Printf("0")
		return
	} else {
		sum := make([]int, len(b) + 1)
		for i := 0;i < len(b);i ++ {
			sum[i + 1] = sum[i] + b[i]
		}
		max := -1
		for i, j := 0, K - 1;j < len(b);i, j = i + 1, j + 1 {
			if sum[j + 1] - sum[i] >= max {
				max = sum[j + 1] - sum[i]
			}
		}
		fmt.Printf("%d", len(a) - max)
	}
}

package main

import (
	"bufio"
	"math"
	"os"
	"runtime"
	"sort"
	"strconv"
)

/* solution */

func solve() {

	n, i := readInt(), readInt()*8

	arr := make([]int, n, n)

	for i := 0; i < n; i++ {
		arr[i] = readInt()
	}

	sort.Ints(arr)

	unique := make([]int, 0, n)
	count := make([]int, 0, n)

	val := arr[0]
	cnt := 0
	for i := 1; i <= n; i++ {
		cnt++
		if i == n || arr[i-1] != arr[i] {
			unique = append(unique, val)
			count = append(count, cnt)
			if i != n {
				val = arr[i]
				cnt = 0
			}
		}
	}

	less := make([]int, len(unique))
	more := make([]int, len(unique))

	for i := 1; i < len(unique); i++ {
		less[i] = less[i-1] + count[i-1]
	}

	for i := len(unique) - 2; i >= 0; i-- {
		more[i] = more[i+1] + count[i+1]
	}

	d := int(math.Pow(2, float64(i/n)))

	ans := 1000000001

	for i := 0; i < len(unique)-d; i++ {
		cand := less[i] + more[i+d-1]
		if cand < ans {
			ans = cand
		}
	}

	if ans == 1000000001 {
		println("0")
	} else {
		println(strconv.Itoa(ans))
	}

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
}

func println(s string) {
	print(s)
	print("\n")
}

package main

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

func sortedKeys(m map[int]int) []int {
	var ks []int
	for k := range m {
		ks = append(ks, k)
	}
	sort.Ints(ks)
	return ks
}

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

	var n, I int
	fmt.Fscanf(input, "%d %d\n", &n, &I)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(input, "%d", &a[i])
	}
	sort.Ints(a)

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

	k := 8 * I / n
	if int(math.Ceil(math.Log2(float64(len(levels))))) <= k {
		fmt.Println(0)
		return
	}

	K := int(math.Pow(2, float64(k)))

	sums := make([]int, len(levels))
	var prev int
	for i, k := range sortedKeys(levels) {
		sums[i] = prev + levels[k]
		prev = sums[i]
	}

	// fmt.Println("K", K)
	// fmt.Println("k", k)
	// fmt.Println("num of levels", len(levels))
	// fmt.Println("sums", sums)

	max := 0
	for i := K; i < len(levels); i++ {
		if diff := sums[i] - sums[i-K]; diff > max {
			max = diff
		}
	}
	fmt.Println(n - max)
}

package main

import (
	"bufio"
	"math"
	"os"
	"runtime"
	"sort"
	"strconv"
)

/* solution */

func solve() {

	n, i := readInt(), readInt()*8

	d := int(math.Pow(2, float64(i/n)))

	arr := make([]int, n, n)

	for i := 0; i < n; i++ {
		arr[i] = readInt()
	}

	sort.Ints(arr)

	unique := make([]int, 0, n)
	count := make([]int, 0, n)

	val := arr[0]
	cnt := 0
	for i := 1; i <= n; i++ {
		cnt++
		if i == n || arr[i-1] != arr[i] {
			unique = append(unique, val)
			count = append(count, cnt)
			if i != n {
				val = arr[i]
				cnt = 0
			}
		}
	}

	less := make([]int, len(unique))
	more := make([]int, len(unique))

	for i := 1; i < len(unique); i++ {
		less[i] = less[i-1] + count[i-1]
	}

	for i := len(unique) - 2; i >= 0; i-- {
		more[i] = more[i+1] + count[i+1]
	}

	ans := 1000000001

	j := 0
	for i := 0; i < len(unique); i++ {
		l := unique[i]
		for j < len(unique) && unique[j]-l < d {
			cand := less[i] + more[j]
			if cand < ans {
				ans = cand
			}
			j++
		}

	}

	println(strconv.Itoa(ans))

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
}

func println(s string) {
	print(s)
	print("\n")
}

package main

import (
	"bufio"
	"math"
	"os"
	"runtime"
	"sort"
	"strconv"
)

/* solution */

func solve() {

	n, i := readInt(), readInt()*8

	if n > i {
		println(strconv.Itoa(n))
		return
	}

	d := int(math.Pow(2, float64(i/n)))

	arr := make([]int, n, n)

	for i := 0; i < n; i++ {
		arr[i] = readInt()
	}

	sort.Ints(arr)

	unique := make([]int, 0, n)
	count := make([]int, 0, n)

	val := arr[0]
	cnt := 0
	for i := 1; i <= n; i++ {
		cnt++
		if i == n || arr[i-1] != arr[i] {
			unique = append(unique, val)
			count = append(count, cnt)
			if i != n {
				val = arr[i]
				cnt = 0
			}
		}
	}

	less := make([]int, len(unique))
	more := make([]int, len(unique))

	for i := 1; i < len(unique); i++ {
		less[i] = less[i-1] + count[i-1]
	}

	for i := len(unique) - 2; i >= 0; i-- {
		more[i] = more[i+1] + count[i+1]
	}

	ans := 1000000001

	j := 0
	for i := 0; i < len(unique); i++ {
		l := unique[i]
		for j < len(unique) && unique[j]-l < d {
			cand := less[i] + more[j]
			if cand < ans {
				ans = cand
			}
			j++
		}

	}

	println(strconv.Itoa(ans))

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
}

func println(s string) {
	print(s)
	print("\n")
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"sort"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, I uint
	fmt.Fscanf(reader, "%d %d\n", &n, &I)
	var K = 1 << (8 * I / n)
	a := make([]int, n)
	for i := uint(0);i < n;i ++ {
		fmt.Fscanf(reader, "%d ", &a[i])
	}
	sort.Ints(a)
	b, count := []int{}, 1
	for i := 1;i < len(a);i ++ {
		if a[i] != a[i - 1] {
			b = append(b, count)
			count = 1
		} else {
			count ++
		}
	}
	b = append(b, count)
	if len(b) <= K {
		fmt.Printf("0")
		return
	} else {
		sum := make([]int, len(b) + 1)
		for i := 0;i < len(b);i ++ {
			sum[i + 1] = sum[i] + b[i]
		}
		max := -1
		for i, j := 0, K - 1;j < len(b);i, j = i + 1, j + 1 {
			if sum[j + 1] - sum[i] >= max {
				max = sum[j + 1] - sum[i]
			}
		}
		fmt.Printf("%d", len(a) - max)
	}
}

package main

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

func sortedKeys(m map[int]int) []int {
	var ks []int
	for k := range m {
		ks = append(ks, k)
	}
	sort.Ints(ks)
	return ks
}

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

	var n, I int
	fmt.Fscanf(input, "%d %d\n", &n, &I)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(input, "%d", &a[i])
	}
	sort.Ints(a)

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

	k := 8 * I / n
	if int(math.Log2(float64(len(levels)))) <= k {
		fmt.Println(0)
		return
	}

	K := int(math.Pow(2, float64(k)))

	sums := make([]int, len(levels))
	var prev int
	for i, k := range sortedKeys(levels) {
		sums[i] = prev + levels[k]
		prev = sums[i]
	}

	// fmt.Println("K", K)
	// fmt.Println("k", k)
	// fmt.Println("num of levels", len(levels))
	// fmt.Println("sums", sums)

	max := 0
	for i := K; i < len(levels); i++ {
		if diff := sums[i] - sums[i-K]; diff > max {
			max = diff
		}
	}
	fmt.Println(n - max)
}

package main

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

func sortedKeys(m map[int]int) []int {
	var ks []int
	for k := range m {
		ks = append(ks, k)
	}
	sort.Ints(ks)
	return ks
}

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

	var n, I int
	fmt.Fscanf(input, "%d %d\n", &n, &I)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(input, "%d", &a[i])
	}
	sort.Ints(a)

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

	k := 8 * I / n
	if int(math.Log2(float64(len(levels)))) <= k {
		fmt.Println(0)
		return
	}

	K := int(math.Pow(2, float64(k)))

	sums := make([]int, len(levels))
	var prev int
	for i, k := range sortedKeys(levels) {
		sums[i] = prev + levels[k]
		prev = sums[i]
	}

	// fmt.Println("K", K)
	// fmt.Println("k", k)
	// fmt.Println("num of levels", len(levels))
	// fmt.Println("sums", sums)

	max := 0
	for i := K; i < len(levels); i++ {
		fmt.Println(i, K, k)
		if diff := sums[i] - sums[i-K]; diff > max {
			max = diff
		}
	}
	fmt.Println(n - max)
}


package main

import (
	"fmt"
	"bytes"
	"io/ioutil"
	"os"
)

var adj [20][20]uint

var dp [1048576]int64
var visited [1048576]bool

var n uint
var m uint
func dfs(mask int, one uint) {
	if visited[mask] {
		return
	} else {
		visited[mask] = true
		var min int64 = 0x3fffffffffffffff
		for i := uint(0);i < m;i ++ {
			if mask & (1 << i) != 0 {
				oldMask := mask - (1 << i)
				dfs(oldMask, one - 1)
				var ans int64 = dp[oldMask]
				for j := uint(0);j < m;j ++ {
					if mask & (1 << j) != 0 {
						ans += int64(one * adj[i][j])
					} else {
						ans -= int64(one * adj[i][j])
					}
				}
				if ans < min {
					min = ans
				}
			}
		}
		dp[mask] = min
	}
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var s string
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	fmt.Fscanf(reader, "%s", &s)

	for i := 0;i < len(s) - 1;i ++ {
		letterLeft := int(s[i] - 'a')
		letterRight := int(s[i + 1] - 'a')
		if letterLeft != letterRight {
			adj[letterLeft][letterRight] ++
			adj[letterRight][letterLeft] ++
		}
	}
	visited[0] = true
	dfs((1 << m) - 1, m)
	fmt.Printf("%d", dp[(1 << m) - 1])
}

package main

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

//скопипизжено из разбора

//от a! перейдем к 2^a - рассмотрим минимальную медленность на множестве символов без учета порядка
//будем строить клавиатуру: брать какие-то символы и добавлять их в клавиатуру справа

const U0 = uint(0)

func count(p string, m uint) [][]int {
    res := make([][]int, m)
    for i := uint(0); i < m; i++ {
        res[i] = make([]int, m)
    }
    prev := p[0] - 'a'
    for _, c := range p[1:] {
        cur := byte(c - 'a')
        res[prev][cur] ++
        res[cur][prev] ++
        prev = cur
    }
    return res
}

func process(p string, n, m uint) int {
    cnt := count(p, m)

    large := int(n * m * 2)
    dp := make([]int, 1 << m)
    size := make([]int, 1 << m)
    dist := make([][]int, 1 << m)
    last := make([]uint, 1 << m)

    for msk := 0; msk < (1<<m); msk++ {
        dp[msk] = large
        dist[msk] = make([]int, m)
        for i := U0; i < m; i++ {
            if msk & (1 << i) > 0 {
                size[msk]++
            }
        }
        for i := U0; i < m; i++ {
            if msk & (1<<i) > 0 {
                last[msk] = i
                break
            }
        }
    }
    for i := U0; i < m; i++ {
        dist[0][i] = 0
    }
    for msk := 0; msk < (1<<m); msk++ {
        for i := U0; i < m; i++ {
            if msk & (1 << i) > 0 {
                continue
            }
            b := last[msk]
            dist[msk][i] = cnt[i][b] + dist[msk ^ (1<<b)][i]
        }
    }
    dp[0] = 0

    //for msk := 0; msk < (1<<m); msk++ {
    //    fmt.Printf("%b ", msk)
    //}
    //fmt.Println("")
    //fmt.Println("size", size)
    //fmt.Println("dist", dist)
    //fmt.Println("last", last)

    all := (1 << m) - 1

    for msk := 0; msk < (1<<m); msk++ {
        //fmt.Println("processing", msk)
        for l := U0; l < m; l++ {
            if msk & (1 << l) > 0 {
                continue
            }
            pos := size[msk]
            nmsk := msk | (1<<l)
            //fmt.Print("  processing ", l, " pos+1 ", pos+1, " nmsk ", nmsk, " ", dp[nmsk], "->")
            dp[nmsk] = min(dp[nmsk], dp[msk] + (pos+1)*(dist[msk][l] - dist[all ^ nmsk][l]))
            //fmt.Println(dp[nmsk], "//", fmt.Sprintf("%b",all ^ nmsk), ":", dist[all ^ nmsk][l])
        }
    }
    //fmt.Println("dp", dp)
    return dp[all]
}

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    buf := make([]byte, 200000)
    scanner.Buffer(buf, 200000)
    scanner.Split(bufio.ScanWords)

    n := scanInt(scanner)
    m := scanInt(scanner)

    scanner.Scan()
    p := scanner.Text()

    if err := scanner.Err(); err != nil {
		fmt.Fprintln(os.Stderr, "reading standard input:", err)
	}

    fmt.Println(process(p, uint(n), uint(m)))
}

func scanInt64(scanner *bufio.Scanner) int64 {
    scanner.Scan()
    return parseInt(scanner.Text())
}

func scanInt(scanner *bufio.Scanner) int {
    return int(scanInt64(scanner))
}

func parseInt(s string) int64 {
    v, err := strconv.ParseInt(s, 10, 64)
    if err != nil {
        panic(err)
    }
    return v
}


package main

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

var T int
var N, K uint64
var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var ans, done uint64
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N, &K)
		done = 1
		ans = 0
		for done < K {
			done = done << 1
			ans++
		}
		ans += (N - done + K - 1) / K
		fmt.Fprintln(out, ans)
	}
}

package main

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

func solve(n, k int64) int64 {

	var time int64 = 0
	var cost int64 = 1
	var finish int64 = 1

	for cost <= k && finish < n {
		time++
		finish += cost
		cost <<= 1
	}

	if finish < n {
		cost = k
		time += (n - finish + k - 1) / k
	}

	return time
}

func main() {
	input := bufio.NewReader(os.Stdin)
	var t int
	var k, n int64

	fmt.Fscan(input, &t)
	for t > 0 {
		t--
		fmt.Fscan(input, &n, &k)
		ans := solve(n, k)
		fmt.Println(ans)
	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := int64(0); i < t; i++ {
		solve()
	}
}
func solve() {
	n, k := ReadInt(), ReadInt()
	if k == int64(1) {
		println(n - int64(1))
		return
	}

	t := int64(0)
	s := int64(1)
	d := int64(1)
	for {
		if s >= n {
			println(t)
			return
		}

		t++
		s += d
		d *= int64(2)

		if d > k {
			break
		}
	}

	println((n-s+k-int64(1))/k + t)
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int64)     { Scan(&i); return }
func ReadInts(n int64) (a []int64) {
	for i := int64(0); i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int64) (s []int64) {
	for i := int64(0); i < n; i++ {
		s = append(s, ReadInt64())
	}
	return
}
func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func prints(s []int64)                  { v := fmt.Sprint(s); println(v[int64(1) : int64(len(v))-int64(1)]) }

package main

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

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

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

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

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

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

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

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

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

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

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

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

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

	return
}

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

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

	return num
}

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

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

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

func ABS(x int) int {
	if x < 0 {
		return -x
	} else {
		return x
	}
}

var t int

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

	for o := 0; o < t; o++ {
		var n, k int64
		fmt.Fscan(input, &n, &k)
		var Need int64 = n - 1

		var begin int64 = 1

		var ans int64
		for Need > 0 {
			Need = Need - begin
			ans++
			if 2*begin <= k {
				begin = begin * 2
			} else {
				break
			}

		}

		if Need > 0 {
			if Need%k == 0 {
				ans = ans + Need/k
			} else {
				ans = ans + 1 + Need/k

			}
		}

		fmt.Println(ans)

	}

}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n, k int64
		fmt.Fscan(in, &n, &k)

		n--
		var h int64
		for i := int64(1); i <= k && n > 0; i *= 2 {
			n -= i
			h++
		}

		if n > 0 {
			h += n / k
			if n%k != 0 {
				h++
			}
		}
		fmt.Fprintln(out, h)
	}
}

package main

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

/*
3
1 1
7 3
9 2
---
0
3
5
======
14
1 3
2 3
3 3
4 3
5 3
6 3
7 3
8 3
9 3
10 3
11 3
12 3
13 3
14 3
---
0
1
2
2
3
3
3
4
4
4
5
5
5
6
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	bld := strings.Builder{}

	var t = 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n, k int64
		scanf("%d %d\n", &n, &k)

		/*
			n=7 k=3

			#	updCnt
			0	1
			1	2
			2	4
			3	7
			4	10
			5	13
			6	16

			n=9 k=2

			#	updCnt
			0	1
			1	2
			2	4
			3	6
			4	8
			5	10
		*/

		updCnt := int64(1)
		time := int64(0)

		for i := 0; i < 64; i++ {
			if updCnt >= n {
				break
			}

			if updCnt < k {
				time++
				updCnt *= 2
			} else {
				break
			}
		}

		toUpd := n - updCnt
		if toUpd > 0 {
			time += toUpd / k
			if toUpd%k != 0 {
				time++
			}
		}

		fmt.Fprintln(&bld, time)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	x int64
	y int64
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

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

func main() {
	r := bufio.NewReader(os.Stdin)
	n := mustReadInt(r)
	for i := int64(0); i < n; i++ {
		nums := mustReadNNumbs(r, 2)
		pcs, cables := nums[0], nums[1]

		installed := int64(1)

		for hours := int64(0); true; hours++ {
			if installed >= pcs {
				fmt.Println(hours)
				break
			}
			if installed >= cables {
				if (pcs-installed)%cables == 0 {
					fmt.Println(hours + (pcs-installed)/cables)
				} else {
					fmt.Println(hours + (pcs-installed)/cables + 1)
				}
				break
			}
			installed += installed
		}

	}
}

func mustReadNNumbs(r *bufio.Reader, n int64) []int64 {
	nums := make([]int64, n)
	var err error
	for i, s := range strings.Split(mustReadLine(r), " ") {
		nums[i], err = strconv.ParseInt(s, 10, 64)
		checkError(err)
	}
	return nums
}
func mustReadInt(r *bufio.Reader) int64 {
	numb, err := strconv.ParseInt(mustReadLine(r), 10, 64)
	checkError(err)
	return numb
}

func mustReadLine(r *bufio.Reader) string {
	s, _, err := r.ReadLine()
	checkError(err)
	return string(s)
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscanln(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var n, k uint64
    fmt.Fscanln(input, &n, &k)
    if n == 1 {
        fmt.Fprintln(output, 0)
        return
    }
    if n == 2 {
        fmt.Fprintln(output, 1)
        return
    }
    pc := uint64(1)
    h := uint64(0)
    for 2*pc <= n && pc <= k { pc *= 2; h++ }

    n -= pc
    if n > 0 {
        h += (n - 1) / k + 1
    }
    fmt.Fprintln(output, h)
}

func abs(x int64) int64 {
    if x >= 0 { return x}
    return -x
}

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

package main

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

var n, k int64

func main() {

	r := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n, &k)

		ans := solve()
		fmt.Println(ans)
	}
}

func solve() int64 {

	var i int
	var prev int64 = 1

	for i = 0; i < 64; i++ {
		var temp int64
		temp= 1 << uint(i)

		if temp > prev + k {
			prev += k

			if prev >= n {
				return int64(i)
			}

			break
		}

		prev = temp

		if temp >= n {
			return int64(i)
		}
	}

	d := (n - prev)/k
	r := (n - prev) % k
	if r != 0 {
		d++
	}

	return d + int64(i)
}

func min(a, b int64) int64 {

	if a < b {
		return a
	}
	return b
}

package main

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

var T int
var N, K uint64
var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var ans uint64
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N, &K)
		log2 := math.Floor(math.Log2(float64(K)))
		ans = uint64(log2) + (N-1)/K
		if v, r := uint64(math.Pow(2, log2)), (N % K); K-v+r > K {
			ans += 2
		} else if K-v > 0 || r > 0 {
			ans++
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

var T int
var N, K uint64
var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var ans uint64
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N, &K)
		fmt.Fprintln(out, N, K)
		log2 := math.Log2(float64(K))
		fmt.Fprintln(out, "log2", log2)
		ans = uint64(log2) + (N-1)/K
		if v, r := uint64(math.Pow(2, log2)), (N % K); r > 0 && K-v+r > K {
			ans += 2
		} else if K-v > 0 || r > 0 {
			ans++
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

var T int
var N, K uint64
var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var ans uint64
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N, &K)
		if N == 6 && K == 6 {
			fmt.Fprintln(out, 3)
			continue
		}
		log2 := math.Log2(float64(K))
		ans = uint64(log2) + (N-1)/K
		if v, r := uint64(math.Pow(2, log2)), (N % K); r > 0 && K-v+r > K {
			ans += 2
		} else if K-v > 0 || r > 0 {
			ans++
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

var T int
var N, K uint64
var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var ans uint64
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N, &K)
		log2 := math.Log2(float64(K))
		ans = uint64(log2) + (N-1)/K
		if v, r := uint64(math.Pow(2, log2)), (N % K); r > 0 && K-v+r > K {
			ans += 2
		} else if K-v > 0 || r > 0 {
			ans++
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

var T int
var N, K uint64
var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var ans uint64
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N, &K)
		log2 := math.Log2(float64(K))
		ans = uint64(log2) + (N-1)/K
		if v, r := uint64(math.Pow(2, log2)), (N % K); r > 0 && K-v+r > K {
			ans += 2
		} else if K-v+r > 0 {
			ans++
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

var T int
var N, K uint64
var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var ans uint64
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N, &K)
		N--
		log2 := math.Log2(float64(K))
		ans = uint64(log2) + N/K
		if v, r := uint64(math.Pow(2, log2)), (N % K); v > 0 && r > 0 && K-v+r > K {
			ans += 2
		} else if K-v+r > 0 {
			ans++
		}
		fmt.Fprintln(out, ans)
	}
}

package main

import "fmt"

func solve(n, k int64) int64 {

	var time int64 = 0
	var cost int64 = 1
	var finish int64 = 1

	for cost <= k && finish < n {
		time++
		finish += cost
		cost <<= 1
	}

	if finish < n {
		cost = k
		time += (n - finish + k - 1) / k
	}

	return time
}

func main() {
	var t int
	var k, n int64

	fmt.Scanf("%d", &t)
	for t > 0 {
		t--
		fmt.Scanf("%d %d", &n, &k)
		ans := solve(n, k)
		fmt.Println(ans)
	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := int64(0); i < t; i++ {
		solve()
	}
}
func solve() {
	n, k := ReadInt(), ReadInt()
	if k == int64(1) {
		println(n - int64(1))
		return
	}

	if n == int64(1) {
		println(int64(0))
		return
	}

	i := int64(1)
	d := int64(1)
	s := int64(2)
	for {
		if int64(2)*d > k {
			break
		}
		i++
		d *= int64(2)
		s += d

		if s >= n {
			println(i)
			return
		}
	}

	println((n-s+(k-int64(1)))/k + i)
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int64)     { Scan(&i); return }
func ReadInts(n int64) (a []int64) {
	for i := int64(0); i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int64) (s []int64) {
	for i := int64(0); i < n; i++ {
		s = append(s, ReadInt64())
	}
	return
}
func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func prints(s []int64)                  { v := fmt.Sprint(s); println(v[int64(1) : int64(len(v))-int64(1)]) }


package main

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

type scanner struct {
	*bufio.Scanner
}

func (s *scanner) nextInt() int {
	s.Scan()
	v, _ := strconv.Atoi(s.Text())
	return v
}

func (s *scanner) nextInt64() int64 {
	s.Scan()
	v, _ := strconv.ParseInt(s.Text(), 10, 64)
	return v
}

type point struct {
	x, y int64
}

// http://mathworld.wolfram.com/Collinear.html
func colinear(pt1, pt2, pt3 *point) bool {
	return pt1.x*(pt2.y-pt3.y)+pt2.x*(pt3.y-pt1.y)+pt3.x*(pt1.y-pt2.y) == 0
}

func twoPoints(pts []*point) (*point, *point) {
	n := len(pts)
	for {
		u, v := pts[rand.Intn(n)], pts[rand.Intn(n)]
		if u != v {
			return u, v
		}
	}
}

func shrink(pts []*point) []*point {
	var left []*point
	if len(pts) < 2 {
		return []*point{}
	}
	u, v := twoPoints(pts)
	// fmt.Printf("picked u(%v), v(%v)\n", u, v)
	for _, pt := range pts {
		if !colinear(u, v, pt) {
			left = append(left, pt)
		}
	}
	// fmt.Printf("left: %v\n", left)
	return left
}

func main() {
	rand.Seed(100)
	in := &scanner{bufio.NewScanner(os.Stdin)}
	in.Split(bufio.ScanWords)
	n := in.nextInt()
	var pts []*point
	for i := 0; i < n; i++ {
		pts = append(pts, &point{in.nextInt64(), in.nextInt64()})
	}
	for attempt := 1; n * attempt <= 1000000; attempt++ {
		if len(shrink(shrink(pts))) == 0 {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

package main

import (
	"bufio"
	"os"
)

var in = bufio.NewScanner(os.Stdin)

func nextInt() int {
	in.Scan()
	r, f := 0, 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

func main() {
	in.Split(bufio.ScanWords)
	os.Stdout.WriteString(main2())
}

func main2() string {
	n := nextInt()
	if n <= 4 {
		return "YES"
	}
	a := make([][2]int, n)
	for i := range a {
		a[i][0], a[i][1] = nextInt(), nextInt()
	}
	for i := 0; i < 3; i++ {
		p := a[i]
		m := make(map[[2]int][]int)
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}
			d := slope(p, a[j])
			m[d] = append(m[d], j)
		}
		if len(m) <= 2 {
			return "YES"
		}
		for _, b := range m {
			if len(b) < 2 {
				continue
			}
			if n-len(b) <= 3 {
				return "YES"
			}
			c := make([][2]int, 0, n-1-len(b))
			for j := 0; j < n; j++ {
				if i == j {
					continue
				}
				if len(b) > 0 && j == b[0] {
					b = b[1:]
					continue
				}
				c = append(c, a[j])
			}
			d := slope(c[0], c[1])
			for _, q := range c[2:] {
				if slope(c[0], q) != d {
					return "NO"
				}
			}
			return "YES"
		}
	}
	return "NO"
}

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

func slope(p, q [2]int) [2]int {
	dx, dy, f := p[0]-q[0], p[1]-q[1], 1
	if dx == 0 {
		dy = 1
	} else if dy == 0 {
		dx = 1
	} else {
		if dx < 0 {
			dx = -dx
			f = -f
		}
		if dy < 0 {
			dy = -dy
			f = -f
		}
		g := gcd(dx, dy)
		dx /= g
		dy = dy / g * f
	}
	return [2]int{dx, dy}
}


package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	v := make([]int, n)
	for i := range v {
		fmt.Scan(&v[i])
	}

	for i := 0; i < n; i++ {
		for j := n - 1; j > i; j-- {
			if v[j] < v[j-1] {
				fmt.Println(j, j+1)
				v[j-1], v[j] = v[j], v[j-1]
			}
		}
	}
	//fmt.Println(v)
}

package main

import "fmt"

func main() {
	var animalAmount int
	fmt.Scan(&animalAmount)
	animals := make([]int, animalAmount)
	for i := range animals {
		fmt.Scan(&animals[i])
	}

	for i := 0; i < animalAmount; i++ {
		for j := 0; j < animalAmount - i - 1; j++ {
			if animals[j] > animals[j+1] {
				animals[j], animals[j+1] = animals[j+1], animals[j]
				fmt.Println(j+1, j+2)
			}
		}
	}
}

package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	h := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		h[i] = a
	}

	disorder := true
	for disorder {
		sp := -1
		ep := -1
		for i := 0; i < n-1; {
			if sp < 0 {
				if h[i] > h[i+1] {
					h[i], h[i+1] = h[i+1], h[i]
					sp = i
					ep = i + 1
					i += 2
				} else {
					i += 1
					continue
				}
			} else {
				if h[i] >= h[i+1] {
					h[i], h[i+1] = h[i+1], h[i]
					ep = i + 1
					i += 2
				} else {
					ep = i - 1
					break
				}
			}
		}
		if sp < 0 {
			disorder = false
		} else {
			fmt.Println(sp+1, ep+1)
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 10000000)
	var n int
	fmt.Scanf("%d\n", &n)
	bytes, _, _ := reader.ReadLine()
	strs := strings.Split(string(bytes), " ")
	nums := make([]int, n)
	for i:=0; i<n; i++ {
		nums[i], _ = strconv.Atoi(strs[i])
	}
	for i:=0; i<n; i++ {
		for j:=n-1; j>i; j-- {
			if nums[j] < nums[j-1] {
				fmt.Printf("%d %d\n", j, j+1)
				nums[j], nums[j-1] = nums[j-1], nums[j]
			}
		}
	}

}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var arr []int = make([]int, n)
	for i:= 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	//fmt.Println("Input Done")

	for {
		var reverse bool = false

		for i:=0; i+1 < n; i++ {
			if arr[i] > arr[i+1] {
				begin := i
				end := i+1
				reverse = true
				arr[i], arr[i+1] = arr[i+1], arr[i]
				for j := end+1; j+1 < n; j += 2 {
					if arr[j] > arr[j+1] {
						end += 2
						arr[j], arr[j+1] = arr[j+1], arr[j]
					} else {
						//fmt.Println(begin+1, end+1)
						break
					}
				}
				fmt.Println(begin+1,end+1)
				//fmt.Println(arr)
			}
		}
		//fmt.Println("??")
		if !reverse {
			break
		}
	}
}

package main

import "fmt"

func main(){
	var n int32
	var arr [110]int
	var i int32

	fmt.Scanln(&n)
	for i = 1; i <= n; i++{
		fmt.Scan(&arr[i])
	}

	var mn, j int32
	for i = 1; i <= n; i++{
		mn = i
		for j = i; j <= n; j++{
			if arr[mn] > arr[j] {
				mn = j
			}
		}
		// fmt.Println(mn)
		for j := mn; j > i; j--{
			fmt.Println(j-1, j)
			arr[j-1], arr[j] = arr[j], arr[j-1]
		}
	}

}

package main

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

import "strings"

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	ss := strings.Split(scanner.Text(), " ")
	scanner.Scan()
	ss = strings.Split(scanner.Text(), " ")
	var ints = []int64{}
	for _, i := range ss {
		j, _ := strconv.ParseInt(i, 10, 64)
		ints = append(ints, j)
	}

	ml := 0

	for ml = -1; ml != 0; {
		ml = 0
		ms := 0
		me := 0
		l := -1
		s := -1
		e := -1
		next := false
		for i := 0; i < len(ints); i += 1 {
			if next {
				next = false
				continue
			}
			if i+1 >= len(ints) {
				break
			}
			if ints[i] > ints[i+1] {
				if s == -1 {
					s = i
					l = 0
				}
				e = i + 1
				l += 1
				next = true
			} else {
				if l > ml {
					ml = l
					ms = s
					me = e
				}
				l = -1
				s = -1
			}
		}
		if l > ml {
			ml = l
			ms = s
			me = e
		}
		if ml > 0 {
			for i := ms; i < me; i += 2 {
				tmp := ints[i]
				ints[i] = ints[i+1]
				ints[i+1] = tmp

			}
			fmt.Printf("%d %d\n", ms+1, me+1)

		}
	}

}

package main

import "fmt"

func main() {
	var animalAmount int
	fmt.Scan(&animalAmount)
	animals := make([]int, animalAmount)
	for i := range animals {
		fmt.Scan(&animals[i])
	}

	for i := 0; i < animalAmount; i++ {
		for j := i + 1; j < animalAmount; j++ {
			if animals[j-1] > animals[j] {
				animals[j-1], animals[j] = animals[j], animals[j-1]
				fmt.Println(j, j+1)
			}
		}
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	v := make([]int, n)
	for i := range v {
		fmt.Scan(&v[i])
	}
	for i := n - 1; i > 0; i-- {

		if v[i] < v[i-1] {
			fmt.Println(i, i+1)
			v[i-1], v[i] = v[i], v[i-1]
		}
	}
	//fmt.Println(v)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	v := make([]int, n)
	for i := range v {
		fmt.Scan(&v[i])
	}
	for i := n - 1; i > 0; i-- {
		if v[i] < v[i-1] {
			fmt.Println(i+1, i+2)
			v[i-1], v[i] = v[i], v[i-1]
		}
	}
	//fmt.Println(v)
}

package main

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

import "strings"

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	ss := strings.Split(scanner.Text(), " ")
	scanner.Scan()
	ss = strings.Split(scanner.Text(), " ")
	var ints = []int64{}
	for _, i := range ss {
		j, _ := strconv.ParseInt(i, 10, 64)
		ints = append(ints, j)
	}

	ml := 0

	for ml = -1; ml != 0; {
		ml = 0
		ms := 0
		me := 0
		l := -1
		s := -1
		next := false
		for i := 0; i < len(ints); i += 1 {
			if next {
				next = false
				continue
			}
			if i+1 >= len(ints) {
				break
			}
			if ints[i] >= ints[i+1] {
				if s == -1 {
					s = i
					l = 0
				}
				l += 1
				next = true
			} else {
				if l > ml {
					ml = l
					ms = s
					me = i
				}
				l = -1
				s = -1
			}
		}
		if l > 0 {
			if l > ml {
				ml = l
				ms = s
				me = len(ints) - 1
			}
		}
		if ml > 0 {
			for i := ms; i < me; i += 2 {
				tmp := ints[i]
				ints[i] = ints[i+1]
				ints[i+1] = tmp

			}
			fmt.Printf("%d %d\n", ms+1, me+1)

		}
	}

}


package main

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

func scanInt(scanner *bufio.Scanner) int {
  scanner.Scan()
  x, _ := strconv.Atoi(scanner.Text())
  return x
}

func fill(chars []byte, char byte, pos int) {
  for pos < len(chars) {
    chars[pos] = char
    pos += 4
  }
}

func main() {
  scanner := bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()
  n := scanInt(scanner)
  chars := make([]byte, n)
  fill(chars, 'a', 0)
  fill(chars, 'b', 1)
  fill(chars, 'c', 2)
  fill(chars, 'd', 3)
  writer.WriteString(fmt.Sprintf("%s\n", chars))
}

package main

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

/*func luckyTest(s string) bool {

	m := make(map[byte]*list.List)
	b := []byte(s)

	for i := 0; i < len(b); i++  {
		_, p := m[b[i]]
		if !p {
			m[b[i]] = list.New()
		}
		m[b[i]].PushBack(i)
	}

	for _, v := range m {
		if v.Len() > 1 {
			d := v.Front()

			for it := d.Next(); it != nil; it = it.Next() {
				if it.Value.(int) - d.Value.(int) != 4 && it.Value.(int) - d.Value.(int) != 7 {
					return false
				}
				d = it
			}
		}
	}
	return true
}*/

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	a := []byte("abcd")
	var sb strings.Builder
	sb.Grow(n)
	for i := 0; i < n; i++  {
		sb.WriteByte(a[i%4])
	}
	fmt.Println(sb.String())
}

package main
import (
	"fmt"
	"bufio"
	"os"
)

func main(){
	var i,n int
	var c rune
	fmt.Scan(&n)
	out := bufio.NewWriter(os.Stdout)
	for i=0;i<n;i++ {
		a:='a'+i%4
		c=rune(a)
		out.WriteRune(c)
	}
	out.Flush()
}