package main

import "fmt"

func solver() {
	var t int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		for i1 := 0; i1 < n; i1++ {
			for j := n; j > 1; j-- {
				if j-1 == i1 {
					fmt.Printf("1 ")
				}
				fmt.Printf("%v ", j)

				if j == 2 && i1 == 0 {
					fmt.Print("1")
				}
			}
			fmt.Println()
		}
	}
}

func main() {
	solver()
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readString(in *bufio.Reader) string {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	return nStr
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func Solve(in int) [][]int {
	var out [][]int

	out = make([][]int, in)

	for i := range out {
		out[i] = make([]int, in)
		fixIndex := 0

		for j := range out[i] {
			if i < j {
				out[i][j] = in - j
			} else {
				out[i][j] = in - (j + 1)
			}

			if i == j {
				out[i][j] = in
			}

			if j > 1 && out[i][j] == (out[i][j-1]+out[i][j-2]) {
				tmp := out[i][j]
				out[i][j] = out[i][fixIndex]
				out[i][fixIndex] = tmp
				fixIndex++
			}
		}
	}

	return out
}

func main() {
	in := bufio.NewReader(os.Stdin)
	n := readInt(in)

	for i := 0; i < n; i++ {
		input := readInt(in)

		res := Solve(input)

		for _, row := range res {
			for j, col := range row {
				if j < len(row)-1 {
					fmt.Printf("%d ", col)
				} else {
					fmt.Printf("%d\n", col)
				}
			}
		}
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o := make([]int, n)
		for j, k := n-1, 0; j >= 0; j-- {
			o[k], k = j+1, k+1
		}
		k, q := 0, make([]int, n)
		copy(q, o)
		for j := 0; j < n; j++ {
			if k > 0 {
				o[k-1], o[k] = o[k], o[k-1]
			}
			for l := 0; l < n; l++ {
				fmt.Fprint(w, o[l], " ")
			}
			k++
			copy(o, q)
			fmt.Fprintln(w, "")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

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 int
		fmt.Fscan(in,&n)
		list:= make([]int,n)
		for j:=n-1;j>=0;j--{
			list[n-j-1]=j+1
		}
		for j:=0;j<n;j++{
			fmt.Fprintf(out,"%v ",list[j])
		}
		fmt.Fprintln(out,)
		for j:=0;j<n-1;j++{
			for k:=0;k<n;k++{
				if k == j {
					fmt.Fprintf(out,"%v ",list[k+1])
					fmt.Fprintf(out,"%v ",list[k])
					k++
					continue
				}
				fmt.Fprintf(out,"%v ",list[k])
			}
			fmt.Fprintln(out,)
		}
	}
}

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fprint(out, 1)
		for i := n; i > 1; i-- {
			Fprint(out, " ", i)
		}
		Fprintln(out)
		for i := n; i > 1; i-- {
			j := n
			for ; j > i; j-- {
				Fprint(out, j, " ")
			}
			Fprint(out, j-1, j, " ")
			for j -= 2; j > 0; j-- {
				Fprint(out, j, " ")
			}
			Fprintln(out)
		}
	}
}

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

package main

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

func solve(scanner *bufio.Scanner) {
	scanner.Scan()
	cur, _ := strconv.Atoi(scanner.Text())
	visited := make([]bool, cur+1)
	cnt := make([]int, 1)
	dfs(cur, visited, &[]int{}, cnt)
}

func dfs(N int, visited []bool, temp *[]int, cnt []int) {
	if cnt[0] >= N {
		return
	}
	if len(*temp) >= N {
		for _, t := range *temp {
			fmt.Printf("%d ", t)
		}
		fmt.Println()
		cnt[0]++
		return
	}
	for i := 1; i <= N; i++ {
		if visited[i] {
			continue
		}
		if len(*temp) >= 2 && ((*temp)[len(*temp)-1]+(*temp)[len(*temp)-2]) == i {
			continue
		}
		visited[i] = true
		*temp = append(*temp, i)
		dfs(N, visited, temp, cnt)
		*temp = (*temp)[:len(*temp)-1]
		visited[i] = false
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		solve(scanner)
	}

}

package main

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

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

func solve(n int) string {
	var r []string
	for i := 1; i <= n; i++ {
		x := fmt.Sprint(i)
		for j := n; j >= 1; j-- {
			if j != i {
				x += fmt.Sprintf(" %d", j)
			}
		}
		r = append(r, x)
	}
	return strings.Join(r, "\n")
}

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

package main

import "fmt"

func main() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		solve()
	}
}
func solve() {
	var n int
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		fmt.Printf("%d ", i)
		for j := n; j >= 1; j-- {
			if j == i {
				continue
			}
			fmt.Printf("%d ", j)
		}
		fmt.Printf("\n")
	}
}

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	p := make([]int, n)

	for i := range p {
		p[i] = n - i
	}

	for i := n - 1; i > 0; i-- {
		for j := range p {
			fmt.Fprintf(writer, "%d ", p[j])
		}
		fmt.Fprintln(writer)

		p[i], p[i-1] = p[i-1], p[i]
	}

	for j := range p {
		fmt.Fprintf(writer, "%d ", p[j])
	}
	fmt.Fprintln(writer)
}

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

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

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int64) int64 {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) (max, idx int) {
	for i, num := range nums {
		if num > nums[idx] {
			idx = i
		}
	}

	return nums[idx], idx
}

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

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

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

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(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 {
	if num == 0 {
		return 0
	}

	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"
	"sort"
)

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

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = i + 1
		}

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

		for _, v := range arr {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)

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

			arr[i], arr[i+1] = arr[i+1], arr[i]
		}
	}
}

// Auto generated using https://github.com/njkevlani/go_bundle
package main

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

func main() {
	s := NewStdinScanner()
	T := NextInt(s)
	for tt := 1; tt <= T; tt++ {
		n := NextInt(s)
		solve(n)
	}
}
func NewStdinScanner() *bufio.Scanner {
	s := bufio.NewScanner(bufio.NewReader(os.Stdin))
	s.Split(bufio.ScanWords)
	return s
}
func NextInt(s *bufio.Scanner) int {
	return atoi(NextToken(s))
}
func atoi(str string) int {
	i, err := strconv.Atoi(str)
	if err != nil {
		panic(err)
	}
	return i
}
func NextToken(s *bufio.Scanner) string {
	if !s.Scan() {
		fmt.Println(s.Err().Error())
		panic("Could not read input")
	}
	return s.Text()
}
func solve(n int) {
	arr := make([]int, n)
	for i := 1; i <= n; i++ {
		arr[i-1] = i
	}
	var count int
	permutationRecursive(arr, &count, 0, len(arr)-1)
}
func permutationRecursive(arr []int, count *int, l, r int) {
	if l == r {
		if isAntiFibonacci(arr) {
			for _, el := range arr {
				fmt.Print(el, " ")
			}
			fmt.Println()
			*count++
			if *count == len(arr) {
				return
			}
		}
	} else {
		for i := l; i <= r; i++ {
			arr[l], arr[i] = arr[i], arr[l]
			if l < 2 || arr[l-2]+arr[l-1] != arr[l] {
				permutationRecursive(arr, count, l+1, r)
				if *count == len(arr) {
					return
				}
			}
			arr[l], arr[i] = arr[i], arr[l]
		}
	}
}
func isAntiFibonacci(arr []int) bool {
	for i := 2; i < len(arr); i++ {
		if arr[i-2]+arr[i-1] == arr[i] {
			return false
		}
	}
	return true
}

//nolint
package main

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

//{
var reader = bufio.NewReader(os.Stdin)
var 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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

//}

func Solve() {
	var n int
	scan(&n)
	arr := [][]int{{3, 2, 1}, {3, 1, 2}, {2, 3, 1}}
	for i := 4; i <= n; i++ {
		for j, l := range arr {
			arr[j] = append([]int{i}, l...)
		}
		tp := append([]int{}, arr[0]...)
		tp[0], tp[1] = tp[1], tp[0]
		arr = append(arr, tp)
	}
	printResult(arr)
}

func printResult(a [][]int) {
	for _, x := range a {
		for _, y := range x {
			print(y, " ")
		}
		println()
	}
}

package main

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

func contains(s []int, e int) bool {
	for i := 0; i < len(s); i++ {
		if e == s[i] {
			return true
		}
	}
	return false
}

func build(s []int, p []int, length int, results int) int {
	//fmt.Println(s, p, length)
	if results == length {
		return results
	}
	if len(p) == length {
		s := strings.Trim(fmt.Sprint(p), "[]")
		fmt.Println(s)
		results += 1
		return results
	}
	for i := 0; i < len(s); i++ {
		if contains(p, s[i]) {
			continue
		}
		if len(p) >= 2 {
			if p[len(p)-1]+p[len(p)-2] == s[i] {
				continue
			}

		}
		//fmt.Println(p)
		results = build(s, append(p, s[i]), length, results)
	}
	return results
}

func main() {
	var tests int
	var err error

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		text := scanner.Text()
		tests, err = strconv.Atoi(text)
		if err != nil {
			log.Fatalln("Error not an integral number of tests")
		}
		if tests < 1 || tests > 48 {
			log.Fatalln("Error test number out of range")
		}
	} else {
		log.Fatalln("Error reading number of tests")
	}
	for i := 0; i < tests; i++ {
		var length int
		if scanner.Scan() {
			text := scanner.Text()
			length, err = strconv.Atoi(text)
			if err != nil {
				log.Fatalln("Error not an integral number for permutation")
			}
			if length < 3 || length > 50 {
				log.Fatalln("Error test case out of range")
			}
		} else {
			log.Fatalln("Error reading permutation")
		}
		s := make([]int, length, length)
		p := make([]int, 0, length)
		for i := 0; i < length; i++ {
			s[i] = i + 1
		}
		build(s, p, length, 0)
	}
}

package main

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

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

func (in *CF1644B) 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 *CF1644B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1644B
Date: 16/03/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1644/B
Problem: CF1644B
**/
func (in *CF1644B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		var sb strings.Builder
		if n == 3 {
			sb.WriteString("3 2 1\n1 3 2\n3 1 2\n")
		} else {
			arr := make([]int, n)
			mapa := make(map[int]bool)
			for i := 0; i < n; i++ {
				mapa[i+1] = true
			}
			ws := true

			for ws {
				ws = false
				for i := 0; i < n; i++ {
					if i == 0 {
						arr[i] = 1
					} else if i == 1 {
						arr[i] = 2
					} else {
						arr[i] = Next(mapa, arr[i-1]+arr[i-2])
					}
					if arr[i] == -1 {
						ws = true
						for i := 0; i < n; i++ {
							mapa[i+1] = true
						}
						break
					}
					delete(mapa, arr[i])
				}

			}

			for i := 0; i < n; i++ {
				for j := 0; j < n; j++ {
					sb.WriteString(fmt.Sprintf("%d ", arr[(i+j)%n]))
				}
				sb.WriteString("\n")
			}
		}
		fmt.Print(sb.String())

	}
}

func Next(mapa map[int]bool, num int) int {
	for k, v := range mapa {
		if v && k != num {
			return k
		}
	}
	return -1
}

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

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

package main

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

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

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = i + 1
		}

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

		var i int
		for c := 0; c < n; c++ {
			for _, v := range arr {
				fmt.Fprintf(out, "%d ", v)
			}
			fmt.Fprintln(out)

			if i == n-2 {
				arr[0], arr[n-1] = arr[n-1], arr[0]
				i = 0
			} else {
				arr[i], arr[i+1] = arr[i+1], arr[i]
			}
			i++
		}
	}
}

package main

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

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

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = i + 1
		}

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

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

//nolint
package main

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

//{
var reader = bufio.NewReader(os.Stdin)
var 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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

//}

func Solve() {
	var n int
	scan(&n)
	arr := [][]int{{2, 1, 3}, {3, 1, 2}, {1, 3, 2}}
	for i := 4; i <= n; i++ {
		for j, l := range arr {
			arr[j] = append(l, i)
		}
		arr = append(arr, append([]int{i}, arr[0][:len(arr[0])-1]...))
	}
	printResult(arr)
}

func printResult(a [][]int) {
	for _, x := range a {
		for _, y := range x {
			print(y, " ")
		}
		println()
	}
}

//nolint
package main

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

//{
var reader = bufio.NewReader(os.Stdin)
var 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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

//}

func Solve() {
	var n int
	scan(&n)
	arr := [][]int{{3, 2, 1}, {1, 3, 2}, {3, 1, 2}}
	for i := 4; i <= n; i++ {
		for j, l := range arr {
			arr[j] = append(l, i)
		}
		arr = append(arr, append([]int{i}, arr[0][:len(arr[0])-1]...))
	}
	printResult(arr)
}

func printResult(a [][]int) {
	for _, x := range a {
		for _, y := range x {
			print(y, " ")
		}
		println()
	}
}

package main

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

func contains(s []int, e int) bool {
	for i := 0; i < len(s); i++ {
		if e == s[i] {
			return true
		}
	}
	return false
}

func build(s []int, p []int, length int, results int) int {
	//fmt.Println(s, p, length)
	if results == length {
		return results
	}
	if len(p) == length {
		fmt.Println(p)
		results += 1
		return results
	}
	for i := 0; i < len(s); i++ {
		if contains(p, s[i]) {
			continue
		}
		if len(p) >= 2 {
			if p[len(p)-1]+p[len(p)-2] == s[i] {
				continue
			}

		}
		//fmt.Println(p)
		results = build(s, append(p, s[i]), length, results)
	}
	return results
}

func main() {
	var tests int
	var err error

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		text := scanner.Text()
		tests, err = strconv.Atoi(text)
		if err != nil {
			log.Fatalln("Error not an integral number of tests")
		}
		if tests < 1 || tests > 48 {
			log.Fatalln("Error test number out of range")
		}
	} else {
		log.Fatalln("Error reading number of tests")
	}
	for i := 0; i < tests; i++ {
		var length int
		if scanner.Scan() {
			text := scanner.Text()
			length, err = strconv.Atoi(text)
			if err != nil {
				log.Fatalln("Error not an integral number for permutation")
			}
			if length < 3 || length > 50 {
				log.Fatalln("Error test case out of range")
			}
		} else {
			log.Fatalln("Error reading permutation")
		}
		s := make([]int, length, length)
		p := make([]int, 0, length)
		for i := 0; i < length; i++ {
			s[i] = i
		}
		build(s, p, length, 0)
	}
}

package main

import "fmt"

func solver() {
	var t int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		for j := n; j >= 1; j-- {
			fmt.Printf("%v ", j)
		}
		fmt.Println()
	}
}

func main() {
	solver()
}

package main

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

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

func (in *CF1644B) 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 *CF1644B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1644B
Date: 16/03/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1644/B
Problem: CF1644B
**/
func (in *CF1644B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		var sb strings.Builder
		if n == 3 {
			sb.WriteString("3 2 1\n1 3 2\n3 1 2\n")
		} else {
			arr := make([]int, n)
			mapa := make(map[int]bool)
			for i := 0; i < n; i++ {
				mapa[i+1] = true
			}
			for i := 0; i < n; i++ {
				if i == 0 {
					arr[i] = 1
				} else if i == 1 {
					arr[i] = 2
				} else {
					arr[i] = Next(mapa, arr[i-1]+arr[i-2])
				}
				delete(mapa, arr[i])
			}

			for i := 0; i < n; i++ {
				for j := 0; j < n; j++ {
					sb.WriteString(fmt.Sprintf("%d ", arr[(i+j)%n]))
				}
				sb.WriteString("\n")
			}
		}
		fmt.Print(sb.String())

	}
}

func Next(mapa map[int]bool, num int) int {
	for k, v := range mapa {
		if v && k != num {
			return k
		}
	}
	return -1
}

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

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

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readString(in *bufio.Reader) string {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	return nStr
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func Solve(in int) [][]int {
	var out [][]int

	out = make([][]int, in)

	for i := range out {
		out[i] = make([]int, in)
		fixIndex := 0

		for j := range out[i] {
			if i < j {
				out[i][j] = in - j
			} else {
				out[i][j] = in - (j + 1)
			}

			if i == j {
				out[i][j] = in
			}

			if j > 1 && out[i][j] == (out[i][j-1]+out[i][j-2]) {
				tmp := out[i][j]
				out[i][j] = out[i][fixIndex]
				out[i][fixIndex] = tmp
				fixIndex++
			}
		}
	}

	return out
}

func main() {
	in := bufio.NewReader(os.Stdin)
	n := readInt(in)

	for i := 0; i < n; i++ {
		input := readInt(in)

		res := Solve(input)

		fmt.Printf("%+v\n", res)
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o := make([]int, n)
		for j, k := n-1, 0; j >= 0; j-- {
			o[k], k = j+1, k+1
		}
		k, q := 0, o
		for j := 0; j < n; j++ {
			if k > 0 {
				o[k-1], o[k] = o[k], o[k-1]
			}
			for l := 0; l < n; l++ {
				fmt.Fprint(w, o[l], " ")
			}
			k++
			o = q
			fmt.Fprintln(w, "")
		}
	}
	w.Flush()
}

func main() {
	solve()
}


package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type readerImpl struct {
	*bufio.Scanner
}

func NewReader() Reader {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &readerImpl{Scanner: s}
}

func (i *readerImpl) NextInt() int {
	i.Scan()
	ret, _ := strconv.Atoi(i.Text())
	return ret
}

func (i *readerImpl) NextInt64() int64 {
	i.Scan()
	ret, _ := strconv.ParseInt(i.Text(), 10, 64)
	return ret
}

func (i *readerImpl) NextString() string {
	i.Scan()
	return i.Text()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (i *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(i.Writer, f, a...)
}

func (i *writerImpl) Flush() {
	i.Writer.Flush()
}

func main() {
	defer writer.Flush()
    R := reader.NextInt64()
    _ = reader.NextInt64()
    grid := [][]rune{}
    for ; R > 0; R-- {
        tmp := []rune{}
        for _, r := range reader.NextString() {
            if r == '.' {
                tmp = append(tmp, 'D')
            } else {
                tmp = append(tmp, r)
            }
        }
        grid = append(grid, tmp)
    }
    if !possible(grid) {
        writer.Printf("No")
        return
    }
    writer.Printf("Yes\n")
    for _, row := range grid {
        writer.Printf("%s\n", string(row))
    }
}

type pos struct {
    i int
    j int
}

func (p pos) valid(maxI, maxJ int) bool {
    return p.i >= 0 && p.i < maxI && p.j >= 0 && p.j < maxJ
}

func possible(grid [][]rune) bool {
    maxI := len(grid)
    maxJ := len(grid[0])
    for i := range grid {
        for j := range grid[i] {
            if grid[i][j] == 'S' {
                for _, p := range []pos{
                    {i+1, j},
                    {i-1, j},
                    {i, j+1},
                    {i, j-1},
                }{
                    if p.valid(maxI, maxJ) && grid[p.i][p.j] == 'W' {
                        return false
                    }
                }
            }
        }
    }
    return true
}

package main

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

func solve() {
	r := readInt()
	c := readInt()
	res := make([]string, r)
	for i := 0; i < r; i++ {
		res[i] = readString()
	}
	for i := 0; i < r; i++ {
		row := res[i]
		for j := 0; j < len(row); j++ {
			if row[j] == 'W' {
				if j > 0 && row[j-1] == 'S' {
					fmt.Println("No")
					return
				}
				if j+1 < c && row[j+1] == 'S' {
					fmt.Println("No")
					return
				}
				if i > 0 && res[i-1][j] == 'S' {
					fmt.Println("No")
					return
				}
				if i+1 < r && res[i+1][j] == 'S' {
					fmt.Println("No")
					return
				}
			}
		}
		res[i] = row
	}
	fmt.Println("Yes")
	for i := 0; i < r; i++ {
		fmt.Println(strings.Replace(res[i], ".", "D", -1))
	}
}

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

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

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

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

package main

import (
	"fmt"
	// "strings"
)

func setD(mas [][]rune, x, y int) {
	if mas[x][y] == 'W' {
		mas[0][0] = 'N'
	} else if mas[x][y] == '.' {
		mas[x][y] = 'D'
	}
}

func main() {
	var n, m int
	var s string
	fmt.Scan(&n, &m)
	var mas [][]rune = make([][]rune, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		mas[i] = []rune(s)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if mas[i][j] == 'S' {
				if i > 0 {
					setD(mas, i - 1, j)
				}
				if i < n - 1 {
					setD(mas, i + 1, j)
				}
				if j > 0 {
					setD(mas, i, j - 1)
				}
				if j < m - 1 {
					setD(mas, i, j + 1)
				}
			}
		}
	}
	if mas[0][0] != 'N' {
		fmt.Println("Yes")
		for i := 0; i < n; i++ {
			fmt.Println(string(mas[i]))
		}
	} else {
		fmt.Println("No")
	}
}

package main

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

func solve() {
	r := readInt()
	c := readInt()
	res := make([]string, r)
	for i := 0; i < r; i++ {
		res[i] = readString()
	}
	for i := 0; i < r; i++ {
		row := res[i]
		for j := 0; j < len(row); j++ {
			if row[j] == 'W' {
				if j > 0 && row[j-1] == 'S' {
					fmt.Println("No")
					return
				}
				if j+1 < c && row[j+1] == 'S' {
					fmt.Println("No")
					return
				}
				if i > 0 && res[i-1][j] == 'S' {
					fmt.Println("No")
					return
				}
				if i+1 < r && res[i+1][j] == 'S' {
					fmt.Println("No")
					return
				}
			}
		}
		res[i] = row
	}
	for i := 0; i < r; i++ {
		fmt.Println(strings.Replace(res[i], ".", "D", -1))
	}
}

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

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

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

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

package main

import (
	"fmt"
	// "strings"
)

func setD(mas [][]rune, x, y int) {
	// if mas[x][y] == 'W' {
	// 	mas[0][0] = 'N'
	// } else if mas[x][y] == '.' {
	// 	mas[x][y] = 'D'
	// }
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var mas [][]rune = make([][]rune, n)
	for i := 0; i < n; i++ {
		mas[i] = make([]rune, m)
	}
	fmt.Scan(&mas)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if mas[i][j] == 'S' {
				if i > 0 {
					setD(mas, i - 1, j)
				}
				if i < n - 1 {
					setD(mas, i + 1, j)
				}
				if j > 0 {
					setD(mas, i, j - 1)
				}
				if j < m - 1 {
					setD(mas, i, j + 1)
				}
			}
		}
	}
	if mas[0][0] != 'N' {
		fmt.Println("Yes")
		for i := 1; i < n; i++ {
			fmt.Println(mas[i])
		}
	} else {
		fmt.Println("No")
	}
}

package main

import (
	"fmt"
	// "strings"
)

func setD(mas [][]rune, x, y int) {
	if mas[x][y] == 'W' {
		mas[0][0] = 'N'
	} else if mas[x][y] == '.' {
		mas[x][y] = 'D'
	}
}

func main() {
	var n, m int
	var s string
	fmt.Scan(&n, &m)
	var mas [][]rune = make([][]rune, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		mas[i] = []rune(s)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if mas[i][j] == 'S' {
				if i > 0 {
					setD(mas, i - 1, j)
				}
				if i < n - 1 {
					setD(mas, i + 1, j)
				}
				if j > 0 {
					setD(mas, i, j - 1)
				}
				if j < m - 1 {
					setD(mas, i, j + 1)
				}
			}
		}
	}
	if mas[0][0] != 'N' {
		fmt.Println("Yes")
		for i := 1; i < n; i++ {
			fmt.Println(string(mas[i]))
		}
	} else {
		fmt.Println("No")
	}
}


package main

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

type pair [2]int

func cachedQuery(m map[pair]int, l, r int) int {
	x, ok := m[pair{l, r}]
	if ok {
		return x
	}
	fmt.Printf("? %d %d\n", l, r)
	scan(&x)
	m[pair{l, r}] = x
	return x
}

func solveC(n int) {
	mem := make(map[pair]int)
	l, r := 1, n
	move := 0

	secondMaxPos := cachedQuery(mem, 1, n)
	if secondMaxPos == 1 {
		l = 1
		r = n
		move = 1
	} else if secondMaxPos == n {
		l = 1
		r = n
		move = -1
	} else {
		pos := cachedQuery(mem, 1, secondMaxPos)
		if pos != secondMaxPos {
			l = secondMaxPos
			r = n
			move = 1
		} else {
			l = 1
			r = secondMaxPos
			move = -1
		}
	}

	//fmt.Println("@", l, r)

	for r-l > 1 {
		m := l + (r-l)/2
		if move == -1 {
			x := cachedQuery(mem, m, secondMaxPos)
			if x == secondMaxPos {
				l = m
			} else {
				r = m
			}
		} else {
			x := cachedQuery(mem, secondMaxPos, m)
			if x == secondMaxPos {
				r = m
			} else {
				l = m
			}
		}

		//fmt.Println("@", l, r)
	}

	if move == -1 {
		fmt.Printf("! %d\n", l)
	} else {
		fmt.Printf("! %d\n", r)
	}

	//fmt.Println(l, r) 1 4 2 5 3
}

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

	T := 1
	// scan(&T)

	for t := 0; t < T; t++ {
		n := 0
		scan(&n)
		solveC(n)
	}
}

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

package main

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

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

func ask(l, r int) int {
	if l == r {
		return -1
	}
	fmt.Fprintf(out, "? %d %d\n", l, r)
	out.Flush()

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

func guess(l, r int) int {
	if l > r {
		panic("impossible")
	}
	if l == r {
		return l
	}
	if r-l == 1 {
		x := ask(l, r)
		if x == l {
			return r
		} else if x == r {
			return l
		} else {
			panic("impossible")
		}
	}

	x := ask(l, r)
	mid := l + (r-l)/2
	if x <= mid { // second max is in the left half
		x2 := ask(l, mid)
		if x2 == x {
			return guess(l, mid)
		} else {
			return guess(mid+1, r)
		}
	} else { // second max is in the right half
		x2 := ask(mid+1, r)
		if x2 == x {
			return guess(mid+1, r)
		} else {
			return guess(l, mid)
		}
	}
}

func main() {
	var n int
	fmt.Fscan(in, &n)

	fmt.Fprintf(out, "! %d\n", guess(1, n))
	out.Flush()
}

package main

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

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

func ask(l, r int) int {
	fmt.Fprintf(out, "? %d %d\n", l, r)
	out.Flush()

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

func guess(l, r int) int {
	if l > r {
		panic("impossible")
	}
	if l == r {
		return l
	}
	if r-l == 1 {
		x := ask(l, r)
		if x == l {
			return r
		} else if x == r {
			return l
		} else {
			panic("impossible")
		}
	}

	x := ask(l, r)
	mid := l + (r-l)/2
	if x <= mid { // second max is in the left half
		x2 := ask(l, mid)
		if x2 == x {
			return guess(l, mid)
		} else {
			return guess(mid+1, r)
		}
	} else { // second max is in the right half
		// The size of the right half is 1.
		if mid+1 == r {
			return guess(l, mid)
		}
		x2 := ask(mid+1, r)
		if x2 == x {
			return guess(mid+1, r)
		} else {
			return guess(l, mid)
		}
	}
}

func main() {
	var n int
	fmt.Fscan(in, &n)

	fmt.Fprintf(out, "! %d\n", guess(1, n))
	out.Flush()
}

package main

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

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

	query := func(l, r int) int {
		fmt.Printf("? %d %d\n", l, r)
		return readNum(reader)
	}

	res := solve(n, query)

	fmt.Printf("! %d\n", res)
}

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') && bs[x] != '-' {
			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, query func(int, int) int) int {
	// max is always between [left, right]
	left, right := 1, n

	for left < right {
		second := query(left, right)
		if left+1 == right {
			// only two, the other one is max
			return left + right - second
		}
		mid := (left + right) / 2
		if mid <= second {
			x := query(mid, right)
			if x == second {
				left = mid
			} else {
				right = mid - 1
			}
		} else {
			// mid > second
			x := query(left, mid)
			if x == second {
				right = mid
			} else {
				left = mid + 1
			}
		}
	}
	return right
}

package main

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

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

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

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

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

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	n := sint64()
	s := req(1, n)

	// highest num in left half
	if s != 1 && s == req(1, s) {
		l := int64(1)
		r := s - 1
		ans := l
		for l <= r {
			m := (l + r) / 2
			if req(m, s) == s {
				ans = m
				l = m + 1
			} else {
				r = m - 1
			}
		}
		submit(ans)
	}

	// highest num in right half
	l := s + 1
	r := n
	ans := r
	for l <= r {
		m := (l + r) / 2
		if req(s, m) == s {
			ans = m
			r = m - 1
		} else {
			l = m + 1
		}
	}
	submit(ans)
}

func req(l, r int64) int64 {
	printf("? %d %d\n", l, r)
	writer.Flush()
	return sint64()
}

func submit(x int64) {
	printf("! %d\n", x)
	writer.Flush()
	os.Exit(0)
}

package main

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

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &n)

	left := 1
	right := n

	for left < right {
		var mid, second int

		fmt.Printf("? %d %d\n", left, right)
		_, _ = fmt.Fscan(in, &second)

		if left+1 == right {
			ans := left + right - second
			fmt.Printf("! %d\n", ans)
			return
		}

		mid = (left + right) / 2

		if second <= mid {
			fmt.Printf("? %d %d\n", left, mid)
			var leftSecond int
			_, _ = fmt.Fscan(in, &leftSecond)

			if second == leftSecond {
				right = mid
			} else {
				left = mid
			}
		} else {
			fmt.Printf("? %d %d\n", mid, right)
			var rightSecond int
			_, _ = fmt.Fscan(in, &rightSecond)

			if second == rightSecond {
				left = mid
			} else {
				right = mid
			}
		}
	}

	fmt.Printf("! %d\n", left)
}

package main

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

const (
	MOD int64 = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

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

	n int
	res int
)

func main() {
	initBuffer()
	var t int = 1
	// t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
}

func count() {
	var i1, i2 int = 1, n
	printIt(i1, i2)
	var x int = getInt()
	if x == 1 {
		i1 = 2
	} else if x == n {
		i2 = n - 1
	} else {
		printIt(1, x)
		if x == getInt() {
			i2 = x - 1
		} else {
			i1 = x + 1
		}
	}
	var k int
	for i1 < i2 {
		k = (i1 + i2) / 2
		if x < i1 {
			printIt(x, k)
			if x == getInt() {
				i2 = k
			} else {
				i1 = k + 1
			}
		} else {
			if i1 + 1 == i2 {
				printIt(i2, x)
				if x == getInt() {
					i1++
				} else {
					i2--
				}
			} else {
				printIt(k, x)
				if x == getInt() {
					i1 = k
				} else {
					i2 = k - 1
				}
			}
		}
	}
	res = i1
}

func printIt(a, b int) {
	out.WriteString("? ")
	out.Write(intToBytes(a))
	out.WriteByte(SP)
	out.Write(intToBytes(b))
	out.WriteByte(NL)
	out.Flush()
}

func output() {
	out.WriteString("! ")
	out.Write(intToBytes(res))
}

func test() {
	fmt.Print()
}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
		res2 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	var res [33]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 33
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 33 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	if n1 > n2 {
		return n1
	}
	return n2
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	if n1 < n2 {
		return n1
	}
	return n2
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(arr[ind])
	out.WriteByte(NL)
	return res
}

package main

import (
	"fmt"
)

func main() {
	var n, m2, res, leftStart, leftEnd, rightStart, rightEnd int

	fmt.Scan(&n)
	start, end := 1, n
	fmt.Printf("? %d %d\n", start, end)
	fmt.Scan(&m2)
	if n == 2 {
		if m2 == 2 {
			fmt.Print("! 1")
		} else {
			fmt.Print("! 2")
		}
		return
	}

	for {
		leftStart, leftEnd = start, start+(end-start)/2
		rightStart, rightEnd = leftEnd+1, end
		if m2 >= start && m2 <= end {
			if end-start == 1 {
				if start == m2 {
					start = end
				}
				break
			}
			if rightStart == rightEnd && m2 == rightEnd {
				leftStart, leftEnd = start, start
				rightStart, rightEnd = end-1, end-1
			}
		}
		//fmt.Println(start, end, leftStart, leftEnd, rightStart, rightEnd)
		if m2 <= leftEnd {
			fmt.Printf("? %d %d\n", min(leftStart, m2), leftEnd)
			fmt.Scan(&res)
			if res == m2 {
				start, end = leftStart, leftEnd
			} else {
				start, end = rightStart, rightEnd
			}
		} else {
			fmt.Printf("? %d %d\n", rightStart, max(rightEnd, m2))
			fmt.Scan(&res)
			if res != m2 {
				start, end = leftStart, leftEnd
			} else {
				start, end = rightStart, rightEnd
			}
		}
		if start == end {
			break
		}
	}
	fmt.Printf("! %d", start)
}

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

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

package main

import (
	. "fmt"
	"os"
)

type (
	input struct{ n int }
	req   struct{ l, r int }
	resp  struct{ v int }
	guess struct{ ans int }
)

// github.com/EndlessCheng/codeforces-go
func run(in input, Q func(req) resp) (gs guess) {
	q := func(l, r int) int {
		if l == r {
			panic(-1)
		}
		return Q(req{l, r}).v
	}
	n := in.n
	ans := 0
	defer func() { gs.ans = ans }()

	//p := q(1, n)
	//
	//if n == 2 {
	//	ans = 3 - p
	//	return
	//}

	l, r := 1, n+1
	for {
		if r-l == 2 {
			ans = l + r - 1 - q(l, r-1)
			return
		}

		if r-l == 3 {
			p, pl, pr := q(l, r-1), q(l, l+1), q(l+1, l+2)
			if pl == pr {
				if p > pl {
					ans = pl - 1
					return
				}
				ans = pl + 1
				return
			}
			if pl == p {
				ans = 2*l + 1 - p
				return
			}
			ans = 2*l + 3 - p
			return
		}

		p := q(l, r-1)
		m := (l + r) >> 1
		if p < m {
			pp := q(l, m-1)
			if pp == p {
				r = m
			} else {
				l = m
			}
		} else {
			pp := q(m, r-1)
			if pp == p {
				l = m
			} else {
				r = m
			}
		}
	}
}

func ioq() {
	in := os.Stdin
	out := os.Stdout

	Q := func(req req) (resp resp) {
		Fprintln(out, "?", req.l, req.r)
		//out.Flush()
		Fscan(in, &resp.v)
		return
	}

	d := input{}
	Fscan(in, &d.n)
	gs := run(d, Q)
	ans := gs.ans
	Fprintln(out, "!", ans)
	//out.Flush()
}

func main() { ioq() }

package main

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

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

func ask(l, r int) int {
	fmt.Fprintf(out, "? %d %d\n", l, r)
	out.Flush()

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

func guess(l, r int) int {
	if l > r {
		panic("impossible")
	}
	if l == r {
		return l
	}
	if r-l == 1 {
		x := ask(l, r)
		if x == l {
			return r
		} else if x == r {
			return l
		} else {
			panic("impossible")
		}
	}

	x := ask(l, r)
	mid := l + (r-l)/2
	if x <= mid {
		// second max is in the left half
		x2 := ask(l, mid)
		if x2 == x {
			return guess(l, mid)
		} else {
			return guess(mid+1, r)
		}
	} else {
		// second max is in the right half
		x2 := ask(mid+1, r)
		if x2 == x {
			return guess(mid+1, r)
		} else {
			return guess(l, mid)
		}
	}
}

func main() {
	var n int
	fmt.Fscan(in, &n)

	fmt.Fprintf(out, "! %d\n", guess(1, n))
	out.Flush()
}

package main

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

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

func ask(l, r int) int {
	fmt.Fprintf(out, "? %d %d\n", l, r)
	out.Flush()

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

func guess(l, r int) int {
	if l > r {
		panic("impossible")
	}
	if l == r {
		return l
	}
	if r-l == 1 {
		x := ask(l, r)
		if x == l {
			return r
		} else if x == r {
			return l
		} else {
			panic("impossible")
		}
	}

	x := ask(l, r)
	if x == l {
		return guess(l+1, r)
	} else if x == r {
		return guess(l, r-1)
	}

	left := ask(l, x)
	if left == x {
		return guess(l, x-1)
	} else {
		return guess(x+1, r)
	}
}

func main() {
	var n int
	fmt.Fscan(in, &n)

	fmt.Fprintf(out, "! %d\n", guess(1, n))
	out.Flush()
}

package main

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

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

func ask(l, r int) int {
	fmt.Fprintf(out, "? %d %d\n", l, r)
	out.Flush()

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

func guess(l, r int) int {
	if l > r {
		panic("impossible")
	}
	if l == r {
		return l
	}
	if r-l == 1 {
		x := ask(l, r)
		if x == l {
			return r
		} else if x == r {
			return l
		} else {
			panic("impossible")
		}
	}

	x := ask(l, r)
	if x == l {
		return guess(l+1, r)
	} else if x == r {
		return guess(l, r-1)
	}

	left := ask(l, x)
	if left == x {
		return guess(l, x-1)
	} else {
		return guess(x+1, r)
	}
}

func main() {
	var n int
	fmt.Fscan(in, &n)

	fmt.Fprintf(out, "! %d\n", guess(1, n))
}

package main

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

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

	query := func(l, r int) int {
		fmt.Printf("? %d %d\n", l, r)
		return readNum(reader)
	}

	res := solve(n, query)

	fmt.Printf("! %d\n", res)
}

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') && bs[x] != '-' {
			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, query func(int, int) int) int {
	// max is always between [left, right]
	left, right := 1, n

	for left < right {
		second := query(left, right)
		if left+1 == right {
			// only two, the other one is max
			return left + right - second
		}
		if second-left > right-second {
			x := query(left, second)
			if x != second {
				// A[x] < A[second], max has to be after second
				left = second + 1
			} else {
				right = second - 1
			}
		} else {
			x := query(second, right)
			if x != second {
				right = second - 1
			} else {
				left = second + 1
			}
		}
	}
	return right
}

package main

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

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

	query := func(l, r int) int {
		fmt.Printf("? %d %d\n", l, r)
		return readNum(reader)
	}

	res := solve(n, query)

	fmt.Printf("! %d\n", res)
}

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') && bs[x] != '-' {
			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, query func(int, int) int) int {
	// max is always between [left, right]
	left, right := 1, n

	for left < right {
		second := query(left, right)
		if left+1 == right {
			// only two, the other one is max
			return left + right - second
		}
		if second-left < right-second {
			x := query(left, second)
			if x != second {
				// A[x] < A[second], max has to be after second
				left = second + 1
			} else {
				right = second - 1
			}
		} else {
			x := query(second, right)
			if x != second {
				right = second - 1
			} else {
				left = second + 1
			}
		}
	}
	return right
}

package main

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

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

	query := func(l, r int) int {
		fmt.Printf("? %d %d\n", l, r)
		return readNum(reader)
	}

	res := solve(n, query)

	fmt.Printf("! %d\n", res)
}

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') && bs[x] != '-' {
			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, query func(int, int) int) int {
	// max is always between [left, right]
	left, right := 1, n

	for left < right {
		second := query(left, right)
		if left+1 == right {
			// only two, the other one is max
			return left + right - second
		}
		choose := rand.Int31n(100)
		if choose < 50 {
			// try first part
			x := query(left, second)
			if x != second {
				// A[x] < A[second], max has to be after second
				left = second + 1
			} else {
				right = second - 1
			}
		} else {
			x := query(second, right)
			if x != second {
				right = second - 1
			} else {
				left = second + 1
			}
		}
	}
	return right
}

package main

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

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

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

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

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

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	n := sint64()
	s := req(1, n)
	s2 := req(1, s)

	// highest num in left half
	if s == s2 {
		l := int64(1)
		r := s - 1
		for l < r {
			m := (l + r) / 2
			nxt := req(m, s) // query right side
			if nxt == s {
				l = m + 1
			} else {
				r = m - 1
			}
		}
		submit((l+r)/2 + 1)
	}

	// highest num in right half
	l := s + 1
	r := n
	for l < r {
		m := (l + r) / 2
		nxt := req(s, m) // query left side
		if nxt == s {
			r = m - 1
		} else {
			l = m + 1
		}
	}
	submit((l+r)/2 - 1)
}

func req(l, r int64) int64 {
	printf("? %d %d\n", l, r)
	writer.Flush()
	return sint64()
}

func submit(x int64) {
	printf("! %d\n", x)
	writer.Flush()
	os.Exit(0)
}

package main

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

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

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

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

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

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	n := sint64()
	s := req(1, n)
	s2 := req(1, s)

	// highest num in left half
	if s == s2 {
		l := int64(1)
		r := s - 1
		for l <= r {
			m := (l + r) / 2
			nxt := req(m, s) // query right side
			if l == r {
				if nxt == s {
					submit(l)
				} else {
					submit(l - 1)
				}
				return
			}
			if nxt == s {
				l = m + 1
			} else {
				r = m - 1
			}
		}
	}

	// highest num in right half
	l := s + 1
	r := n
	for l <= r {
		m := (l + r) / 2
		nxt := req(s, m) // query left side
		if l == r {
			if nxt == s {
				submit(r)
			} else {
				submit(r + 1)
			}
			return
		}
		if nxt == s {
			r = m - 1
		} else {
			l = m + 1
		}
	}
}

func req(l, r int64) int64 {
	printf("? %d %d\n", l, r)
	writer.Flush()
	return sint64()
}

func submit(x int64) {
	printf("! %d\n", x)
	writer.Flush()
}

package main

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

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &n)

	left := 1
	right := n

	for left < right {
		var mid int

		fmt.Printf("? %d %d\n", left, right)
		_, _ = fmt.Fscan(in, &mid)

		if left+1 == right {
			ans := left + right - mid
			fmt.Printf("! %d\n", ans)
			return
		}

		fmt.Printf("? %d %d\n", left, mid)
		var inside int
		_, _ = fmt.Fscan(in, &inside)

		if inside == mid {
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	fmt.Printf("! %d\n", left)
}


package main

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

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

	var a, b int64
	fmt.Fscanf(reader, "%d %d", &a, &b)
	if a*b == 0 {
		fmt.Printf("%d\n", a*a-b*b)
		for i := int64(0); i < a; i++ {
			fmt.Printf("o")
		}
		for i := int64(0); i < b; i++ {
			fmt.Printf("x")
		}
		return
	}

	o := make([]int64, a+1)
	x := make([]int64, b+1)

	for i := int64(1); i <= a; i++ {
		o[i] = (a-i+1)*(a-i+1) + (i - 1)
	}
	for i := int64(1); i <= b; i++ {
		x[i] = (b/i+1)*(b/i+1)*(b%i) + (b/i)*(b/i)*(i-b%i)
	}
	ans := a*a - b*b
	var besta, bestb int64
	for i := int64(1); i <= a; i++ {
		if i <= b && ans <= o[i]-x[i] {
			ans = o[i] - x[i]
			besta, bestb = i, i
		}
		if i+1 <= b && ans <= o[i]-x[i+1] {
			ans = o[i] - x[i+1]
			besta, bestb = i, i+1
		}
	}
	fmt.Printf("%d\n", ans)
	aList := make([]int64, besta)
	bList := make([]int64, bestb)
	aList[0] = a - besta + 1
	for i := int64(1); i < besta; i++ {
		aList[i] = 1
	}
	for i := int64(0); i < (b % bestb); i++ {
		bList[i] = b/bestb + 1
	}
	for i := b % bestb; i < bestb; i++ {
		bList[i] = b / bestb
	}
	for i := int64(0); i < besta; i++ {
		for j := int64(0); j < bList[i]; j++ {
			fmt.Printf("x")
		}
		for j := int64(0); j < aList[i]; j++ {
			fmt.Printf("o")
		}
	}
	if bestb > besta {
		for j := int64(0); j < bList[bestb-1]; j++ {
			fmt.Printf("x")
		}
	}
}

/*********************************************************************************
*     File Name           :     C.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-13 19:56]
*     Last Modified       :     [2014-03-13 20:21]
*     Description         :
**********************************************************************************/

package main

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

func main() {
    scanner.Split(bufio.ScanWords)

    var n, m int64 = scanner.NextInt(), scanner.NextInt()
    var ans int64 = -m * m
    if m == 0 {
        fmt.Println(n * n)
        for i := 0; i < int(n); i++ {
            fmt.Print("o")
        }
    } else if m == 1 {
        fmt.Println(n*n - 1)
        for i := 0; i < int(n); i++ {
            fmt.Print("o")
        }
        fmt.Print("x")
    } else {
        var tmp, f int64 = 1, m
        if f > n+1 {
            f = n + 1
        }
        for i := int64(2); i <= f; i++ {
            t := (m/i)*(m/i)*(i-m%i) + (m/i+1)*(m/i+1)*(m%i)
            t = (i - 2) + (n-i+2)*(n-i+2) - t
            if t > ans {
                ans, tmp = t, i
            }
        }
        fmt.Println(ans)
        r := m % tmp
        x := m / tmp
        for i := int64(1); i < tmp; i++ {
            for j := 0; j < int(x); j++ {
                fmt.Print("x")
            }
            if r > 0 {
                fmt.Print("x")
                r--
            }
            if i == 1 {
                for j := 0; j < int(n-tmp+2); j++ {
                    fmt.Print("o")
                }
            } else {
                fmt.Print("o")
            }
        }
        for j := 0; j < int(x); j++ {
            fmt.Print("x")
        }
    }
    fmt.Println()
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) NextInt() int64 {
    x, err := strconv.Atoi(self.Next())
    if err != nil {
        panic(err)
    }
    return int64(x)
}

package main

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

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

	var a, b int64
	fmt.Fscanf(reader, "%d %d", &a, &b)
	if a == 0 {
		fmt.Printf("%d", -b*b)
		return
	} else if b == 0 {
		fmt.Printf("%d", a*a)
		return
	}

	o := make([]int64, a+1)
	x := make([]int64, b+1)

	for i := int64(1); i <= a; i++ {
		o[i] = (a-i+1)*(a-i+1) + (i - 1)
	}
	for i := int64(1); i <= b; i++ {
		x[i] = (b/i+1)*(b/i+1)*(b%i) + (b/i)*(b/i)*(i-b%i)
	}
	ans := a*a - b*b
	for i := int64(1); i <= a; i++ {
		if i <= b && ans < o[i]-x[i] {
			ans = o[i] - x[i]
		}
		if i+1 <= b && ans < o[i]-x[i+1] {
			ans = o[i] - x[i+1]
		}
	}
	fmt.Printf("%d", ans)
}


package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    var number_test_case int
    fmt.Sscan(scanner.Text(), &number_test_case)
    for i:=0; i < number_test_case; i++ {
        var k, n int
        scanner.Scan()
        fmt.Sscan(scanner.Text(), &n)
        for (1 << k) <= n {
            k ++
        }
        fmt.Println((1 << (k - 1)) - 1)
    }
}

package main

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

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

func solve(n int) int {
	l := 1
	for l<<1 <= n {
		l <<= 1
	}
	return l - 1
}

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

package main
import(
    "fmt"
    "bufio"
    "os"
    //"math"
)
func main() {
	var t int
	var in = bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Fscan(in,&x)
		tmp:=1
		for j:=1;j<=x;j++ {
			tmp*=2
			if tmp > x {
				fmt.Println((tmp/2)-1)
				break
			}
		}
	}
}

package main

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

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

func solve(n int) int {
	l := 1
	for 2*l <= n {
		l *= 2
	}
	return l - 1
}

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

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

		i := 1
		for 2*i <= n {
			i *= 2
		}

		fmt.Println(i - 1)
	}
}

package main

import (
    "bufio"
    "fmt"
    "os"
)
//type int int64
var scan = fmt.Fscan
var println = fmt.Fprintln

var in *bufio.Reader
var out *bufio.Writer
func init(){
    in = bufio.NewReader(os.Stdin)
    out = bufio.NewWriter(os.Stdout)
}

func main(){
	defer out.Flush()
	var t int; scan(in,&t)
	for ;t>0;t-- {
		var a int; scan(in,&a)
		ans := 0
		for a>0{
			a>>=1
			ans++
		}
		ans--
		println(out,(1<<ans)-1)
	}
}

package main
import (
    "os"
    "fmt"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    fmt.Fscan(rd, &q)
    for t := 0; t < q; t++ {
        n := 0
        fmt.Fscan(rd, &n)
        var res uint = 0
        for n > 0 {
            res++
            n /= 2
        }
        fmt.Println((1 << (res - 1)) - 1)
    }
}

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

}

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 int
		fmt.Fscan(input, &n)
		begin := n
		count := 0
		ansss := 1
		for i := 0; i > -1; i++ {
			begin = int(begin / 2)
			if begin >= 1 {
				count++
				ansss = ansss * 2
			} else {
				break
			}

		}
		fmt.Println(ansss - 1)
	}

}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"math/bits"
	"os"
	"strings"
)

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

	solve := func(Case int) {
		var n uint
		Fscan(in, &n)
		Fprintln(out, 1<<(bits.Len(n)-1)-1)
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

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

var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var mu sync.Mutex

func init()        { in.Split(bufio.ScanWords) }
func gets() string { in.Scan(); return in.Text() }
func geti() int    { i, _ := strconv.ParseInt(gets(), 10, 64); return int(i) }

func putln(a ...interface{})          { mu.Lock(); defer mu.Unlock(); fmt.Fprintln(out, a...) }
func putf(f string, a ...interface{}) { mu.Lock(); defer mu.Unlock(); fmt.Fprintf(out, f, a...) }

func flush()   { mu.Lock(); defer mu.Unlock(); out.Flush() }
func flusher() { time.Sleep(10 * time.Millisecond); flush(); go flusher() }
func main()    { go flusher(); defer flush(); main1() }

func main1() {
	// var x int64
	// var y int
	// if unsafe.Sizeof(x) != unsafe.Sizeof(y) {
	// 	panic("bad")
	// }
	for tc := geti(); tc > 0; tc-- {
		n := geti()
		a := 1
		for 2*a <= n {
			a *= 2
		}
		putln(a - 1)
	}
}

package main

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

func main() {
	var n int64
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n = toInt(scanner.Bytes())
	for i := int64(0); i < n; i++ {
		var k int64
		scanner.Scan()
		k = toInt(scanner.Bytes())
		var wow int64 = int64(math.Log2(float64(k)))
		fmt.Println(int64(math.Pow(2, float64(wow)) - 1))
	}
}

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

package main

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

/*
And then there were K

Given an integer n, find the maximum value of integer k
such that the following condition holds:
n & (n−1) & (n−2) & (n−3) & ... (k) = 0
where & denotes the bitwise AND operation.

Input

The first line contains a single integer t: (1≤t≤3⋅104).
Then t test cases follow.

The first line of each test case contains a single integer n: (1≤n≤109).

Output
For each test case, output a single integer, the required integer k.
*/
func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    var number_test_case int
    fmt.Sscan(scanner.Text(), &number_test_case)
    for i:=0; i < number_test_case; i++ {
        var n uint64
        scanner.Scan()
        fmt.Sscan(scanner.Text(), &n)
        fmt.Println(findK(n))
    }
}

// The value of k is the 2^(b-1) - 1
// With b the highest bit of n
func findK(n uint64) int{
    b := bits.Len64(n)
    return (1 << (b-1)) - 1
}

package main

import (
	"fmt"
)

func bLen(x int64) int {
	l := 1
	for x >= 1024 {
		l <<= 10
		x /= 1024
	}
	for x >= 4 {
		l <<= 2
		x /= 4
	}
	for x != 0 {
		l <<= 1
		x /= 2
	}
	l >>= 1
	l -= 1
	return l
}

func main() {
	n := readInt()
	for i := int64(0); i < n; i++ {
		num := readInt()

		fmt.Println(bLen(num))
	}
}

func readInt() int64 {
	var n int64
	fmt.Scan(&n)
	return n
}

package main

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

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

func (in *CF1527A) 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 *CF1527A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1527A
Date: 16/09/21
User: pepradere
URL: https://codeforces.com/problemset/problem/1527/A
Problem: CF1527A
**/
func (in *CF1527A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt64()
		count := int64(1)
		for n > 1 {
			count++
			n /= 2
		}

		fmt.Println(1<<(count-1) - 1)
	}
}

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

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

package main

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

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

	for test := parseInt(getString(reader)); test > 0; test-- {
		n := parseInt(getString(reader))
		writer.WriteString(fmt.Sprintln(int(math.Pow(2, math.Floor(math.Log2(float64(n)))) - 1)))
	}
	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

package main

import (
	"fmt"
)

var cache = map[int64]int64{
	1:  0,
	2:  1,
	5:  3,
	17: 15,
}

func binLen(n int64) int {
	x := 0
	for n != 0 {
		n /= 2
		x++
	}
	return x
}
func solve() {
	n := readInt()
	if v, ok := cache[n]; ok {
		fmt.Println(v)
		return
	}
	x := int64(1<<binLen(n) - 1)
	cache[n] = x
	fmt.Println(x)
}

func main() {
	n := readInt()
	for i := int64(0); i < n; i++ {
		solve()
	}
}

func readInt() int64 {
	var n int64
	fmt.Scan(&n)
	return n
}

package main

import (
	"fmt"
)

var cache = map[int64]int64{
	1:  0,
	2:  1,
	5:  3,
	17: 15,
}

func toBinary(n int64) []bool {
	bytz := []bool{}
	for n != 0 {
		bytz = append(bytz, n%2 == 1)
		n /= 2
	}
	return bytz
}

func toNumNeg(bytz []bool) int64 {
	x := int64(0)
	for i := len(bytz) - 1; i >= 0; i-- {
		x *= 2
		if !bytz[i] {
			x += 1
		}
	}
	return x
}
func solve() {
	n := readInt()
	if v, ok := cache[n]; ok {
		fmt.Println(v)
		return
	}
	x := toNumNeg(toBinary(n))
	cache[n] = x
	fmt.Println(x)
}

func main() {
	n := readInt()
	for i := int64(0); i < n; i++ {
		solve()
	}
}

func readInt() int64 {
	var n int64
	fmt.Scan(&n)
	return n
}

package main

import (
	"fmt"
)

var cache = map[int64]int64{
	2:  1,
	5:  3,
	17: 15,
}

func toBinary(n int64) []bool {
	bytz := []bool{}
	for n != 0 {
		bytz = append(bytz, n%2 == 1)
		n /= 2
	}
	return bytz
}

func toNumNeg(bytz []bool) int64 {
	x := int64(0)
	for i := len(bytz) - 1; i >= 0; i-- {
		x *= 2
		if !bytz[i] {
			x += 1
		}
	}
	return x
}
func solve() {
	n := readInt()
	if v, ok := cache[n]; ok {
		fmt.Println(v)
		return
	}
	x := toNumNeg(toBinary(n))
	if x == 0 {
		x = 1
	}
	cache[n] = x
	fmt.Println(x)
}

func main() {
	n := readInt()
	for i := int64(0); i < n; i++ {
		solve()
	}
}

func readInt() int64 {
	var n int64
	fmt.Scan(&n)
	return n
}

package main

import (
	"fmt"
)

var cache = map[int64]int64{
	2:  1,
	5:  3,
	17: 15,
}

func toBinary(n int64) []bool {
	bytz := []bool{}
	for n != 0 {
		bytz = append(bytz, n%2 == 1)
		n /= 2
	}
	return bytz
}

func toNumNeg(bytz []bool) int64 {
	x := int64(0)
	for i := len(bytz) - 1; i >= 0; i-- {
		x *= 2
		if !bytz[i] {
			x += 1
		}
	}
	return x
}
func solve() {
	n := readInt()
	if v, ok := cache[n]; ok {
		fmt.Println(v)
		return
	}
	x := toNumNeg(toBinary(n))
	cache[n] = x
	fmt.Println(x)
}

func main() {
	n := readInt()
	for i := int64(0); i < n; i++ {
		solve()
	}
}

func readInt() int64 {
	var n int64
	fmt.Scan(&n)
	return n
}

package main
import(
    "fmt"
    "bufio"
    "os"
    //"math"
)
func main() {
	var t int
	var in = bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Fscan(in,&x)
		for j:=x-1;j>0;j--{
			if j & (j-1) == 0 {
				fmt.Println(j-1)
				break
			}
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	var t int
	var in = bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Fscan(in,&x)
		if x < 4 {
			fmt.Println(1)
		} else if x < 8 {
			fmt.Println(3)
		} else {
			fmt.Println(int(math.Sqrt(float64(x)))*4-1)
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	var t int
	var in = bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Fscan(in,&x)
		if x < 4 {
			fmt.Println(1)
		} else if x < 8 {
			fmt.Println(3)
		} else {
			fmt.Println((int(math.Sqrt(float64(x)))-1)*4-1)
		}
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Scan(&x)
		if x <= 2 {
			fmt.Println(1)
		} else {
			fmt.Println(x-2)
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanln(&n)
	for i := 0; i < n; i++ {
		var k int64
		fmt.Scanln(&k)
		var wow int64 = int64(math.Log2(float64(k)))
		fmt.Println(math.Pow(2, float64(wow)) - 1)
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
    var number_test_case int
    fmt.Sscan(scanner.Text(), &number_test_case)
    for i:=0; i < number_test_case; i++ {
        var l int // lenght of the string
        var s string
        scanner.Scan()
        fmt.Sscan(scanner.Text(), &l)
        scanner.Scan()
        s = scanner.Text()
        count0 := 0
        for _,c := range s{
            if c =='0' {
                count0 ++
            }
        }
        if count0 > 1 && count0 % 2 == 1 {
            fmt.Println("ALICE")
        } else {
            fmt.Println("BOB")
        }
    }
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
    var number_test_case int
    fmt.Sscan(scanner.Text(), &number_test_case)
    for i:=0; i < number_test_case; i++ {
        var number uint64
        scanner.Scan()
        fmt.Sscan(scanner.Text(), &number)
        fmt.Println(number - uint64(bits.OnesCount64(number)))
    }
}

package main

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

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

func (in *CF1527A) 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 *CF1527A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1527A
Date: 16/09/21
User: pepradere
URL: https://codeforces.com/problemset/problem/1527/A
Problem: CF1527A
**/
func (in *CF1527A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt64()
		aux := n
		count := int64(1)
		if n == 1 {
			count = 0
		}
		for n > 1 {
			if n%2 != 0 {
				count++
			}
			n /= 2
		}

		fmt.Println(aux - count)
	}
}

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

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

package main

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

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

func (in *CF1527A) 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 *CF1527A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1527A
Date: 16/09/21
User: pepradere
URL: https://codeforces.com/problemset/problem/1527/A
Problem: CF1527A
**/
func (in *CF1527A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt64()
		aux := n
		count := int64(1)
		for n > 1 {
			if n%2 != 0 {
				count++
			}
			n /= 2
		}

		fmt.Println(aux - count)
	}
}

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

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

package main

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

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

	for test := parseInt(getString(reader)); test > 0; test-- {
		n := parseInt(getString(reader))
		writer.WriteString(fmt.Sprintln(math.Pow(2, math.Floor(math.Log2(float64(n)))) - 1))
	}
	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}


package main
import "fmt"

func main() {
	var nn, mm, aa, bb, k, l int
	var x[110][110]int
	var cnt[110]int
	var s[110]int
	var notice bool

	fmt.Scan(&nn, &mm)
	for i:=1; i<=nn; i++ {
		cnt[1]=0
		for j:=1; j<=nn; j++ {
			x[i][j]=0
		}
	}

	for i:=1; i<=mm; i++ {
		fmt.Scan(&aa, &bb)
		x[aa][bb]=1
		x[bb][aa]=1
		cnt[aa]+=1
		cnt[bb]+=1
	}
	k=0
	l=0
	for {
		k=0
		for i:=1; i<=nn; i++ {
			if cnt[i]==1 {
				s[k]=i
				k++
			}
		}
		if k==0 {
			break
		}
		for i:=1; i<=nn; i++ {
			notice=false
			for j:=0; j<k; j++ {
				if s[j]==i {
					notice=true
					break
				}
			}
			if notice==true {
				for j:=1; j<=nn; j++ {
					if x[i][j]==1 {
						x[i][j]=0
						x[j][i]=0
						cnt[i]--
						cnt[j]--
					}
				}
			}
		}
		l++
	}
	fmt.Println(l)
}


package main

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

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

	var n, v, w int
	Fscan(in, &n)
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	type node struct{ dep, fa int }
	nodes := make([]node, n)
	var _f func(v, fa, d int)
	_f = func(v, fa, d int) {
		nodes[v] = node{d, fa}
		for _, w := range g[v] {
			if w != fa {
				_f(w, v, d+1)
			}
		}
	}
	_f(0, -1, 0)

	used := make([]bool, n)
	size := make([]int, n)
	var calcSize func(v, fa int) int
	calcSize = func(v, fa int) int {
		sz := 1
		for _, w := range g[v] {
			if w != fa && !used[w] {
				sz += calcSize(w, v)
			}
		}
		size[v] = sz
		return sz
	}
	var compSize int
	var find func(v, fa int) int
	find = func(v, fa int) int {
		for _, w := range g[v] {
			if w != fa && !used[w] && size[w] > compSize>>1 {
				return find(w, v)
			}
		}
		return v
	}

	ans := make([]byte, n)
	var f func(int, byte)
	f = func(v int, rk byte) {
		calcSize(v, -1)
		compSize = size[v]
		ct := find(v, -1)
		used[ct] = true
		ans[ct] = rk
		for _, w := range g[ct] {
			if !used[w] {
				f(w, rk+1)
			}
		}
	}
	f(0, 'A')
	for _, b := range ans {
		Fprint(out, string(b)+" ")
	}
}

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

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	n := io.NextInt()
	g := make([][]int, n+1)
	for i := 0; i < n-1; i++ {
		u, v := io.NextInt(), io.NextInt()
		g[u] = append(g[u], v)
		g[v] = append(g[v], u)
	}

	ans := make([]int, n+1)
	centroidDecompose(g, func(u int, d int) { ans[u] = 'A' + d })
	for i := 1; i <= n; i++ {
		io.Print(string(ans[i]), " ")
	}
	io.Println()
}

func centroidDecompose(g [][]int, f func(int, int)) {
	remove := func(u, v int) {
		j := len(g[u]) - 1
		for i, x := range g[u] {
			if x == v {
				g[u][i] = g[u][j]
				g[u] = g[u][:j]
				return
			}
		}
	}

	sz := make([]int, len(g))
	var calcSz func(int)
	calcSz = func(u int) {
		sz[u] = 1
		for _, v := range g[u] {
			remove(v, u)
			calcSz(v)
			sz[u] += sz[v]
		}
	}
	calcSz(1)

	var getCentroid func(int) int
	getCentroid = func(u int) int {
		for _, v := range g[u] {
			if sz[v]*2 > sz[u] {
				remove(u, v)
				g[v], sz[u], sz[v] = append(g[v], u), sz[u]-sz[v], sz[u]
				return getCentroid(v)
			}
		}
		return u
	}

	var decompose func(u, d int)
	decompose = func(u, d int) {
		cen := getCentroid(u)
		f(cen, d)
		for _, v := range g[cen] {
			remove(v, cen)
			decompose(v, d+1)
		}
	}
	decompose(1, 0)
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}


package main

import (
	"fmt"
)

//var in = bufio.NewScanner(os.Stdin)
//
//func init() {
//	in.Split(bufio.ScanWords)
//}
//
//func Int() int {
//	in.Scan()
//	r := 0
//	for _, c := range in.Bytes() {
//		r *= 10
//		r += int(c - '0')
//	}
//	return r
//}
//
//func Str() string {
//	in.Scan()
//	r := ""
//	for _, c := range in.Bytes() {
//		r += string(c)
//	}
//	return r
//}

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
}

///==========---------- End of Precode ----------==========///

func main() {
	//_, k, s := Int(), Int(), Str()
	n, k := 0, 0
	s := ""

	fmt.Scanf("%d %d\n%s", &n, &k, &s)

	last, v, p := "", make([]int, 0), make([]int, 0)
	for _, c := range s {
		if string(c) == last {
			v[len(v) - 1] += 1
		} else {
			v = append(v, 1)
			p = append(p, int(c))
			last = string(c)
		}
	}

	res := 0
	for i := 'a'; i <= 'z'; i++ {
		c := 0
		for j := range v {
			if p[j] == int(i) {
				c += v[j] / k
			}
		}
		res = max(res, c)
	}

	fmt.Printf("%d\n", res)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	s := ""
	fmt.Fscanf(in, "%s\n", &s)
	ans := 0
	for i := 'a'; i <= 'z'; i++ {
		curAns := 0
		j := 0
		for j < len(s) {
			for j < len(s) && s[j] != byte(i) {
				j++
			}
			k := 0
			for j < len(s) && s[j] == byte(i) {
				k++
				j++
			}
			curAns += k / m
		}
		if curAns > ans {
			ans = curAns
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
	return
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func scanf(format string, a ...interface{}) { fmt.Fscanf(reader, format, a...) }

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
}

///==========---------- End of Precode ----------==========///

func main() {
	defer writer.Flush() /// MUST BE EXECUTED

	n, k, s := 0, 0, ""
	scanf("%d %d\n%s", &n, &k, &s)

	last, v, p := "", make([]int, 0), make([]int, 0)
	for _, c := range s {
		if string(c) == last {
			v[len(v) - 1] += 1
		} else {
			v = append(v, 1)
			p = append(p, int(c))
			last = string(c)
		}
	}

	res := 0
	for i := 'a'; i <= 'z'; i++ {
		c := 0
		for j := range v {
			if p[j] == int(i) {
				c += v[j] / k
			}
		}
		res = max(res, c)
	}

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

package main

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

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

	dd := strings.Split(scanner.Text(), " ")
	k, _ := strconv.Atoi(dd[1])
	var current int = -1
	var length int
	d := make([]int, 26)
	scanner.Scan()
	mv := 0
	for _, v := range scanner.Text() {
		dv := int(v - 'a')
		if k == 1 {
			d[dv] += 1
			if d[dv] > mv {
				mv = d[dv]
			}
		} else if current == dv {
			length += 1
			if length == k {
				d[current] += 1
				if d[current] > mv {
					mv = d[current]
				}
				current = -1
			}
		} else {
			current = dv
			length = 1
		}

	}
	fmt.Println(mv)
}

package main

import "fmt"

func MinMax(array []int) (int, int) {
    var max int = array[0]
    var min int = array[0]
    for _, value := range array {
        if max < value {
            max = value
        }
        if min > value {
            min = value
        }
    }
    return min, max
}

func  main() {
	var length, k int;
	var input string;

	fmt.Scanf("%d %d\n", &length, &k);
	fmt.Scanf("%s\n", &input);

	var letterDB map[string]map[int]int = make(map[string]map[int]int);

	for i:=0; i < len(input); i++ {
		letterDB[ string(input[i]) ] = make(map[int]int);
	}

	// fmt.Println(letterDB);

	input = input + " "
	for patternLength, i:= 1, 0; i < len(input) - 1; i++ {
		if input[i] == input[i+1] {
			patternLength += 1;
		} else {

			if _, ok := letterDB[string(input[i])][patternLength]; ok {
				letterDB[string(input[i])][patternLength] += 1;
			} else {
				letterDB[string(input[i])][patternLength] = 1;
			}

			patternLength = 1;

		}
	}

	// fmt.Println(letterDB);

	var rankDB map[string]int = make(map[string]int);

	for letter := range letterDB {
		var rank int = 0;
		for patternLength, count := range letterDB[letter] {
			rank += (patternLength/k) * count;
		}
		rankDB[letter] = rank;
	}

	// fmt.Println(rankDB);

	ranks := make([]int, length);
	for _, val := range rankDB {
		ranks = append(ranks, val);
	}

	_, rank := MinMax(ranks);

	fmt.Println(rank);

}

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

func main() {
	var n, k int
	var s string
	fmt.Fscan(in, &n, &k, &s)
	m := make(map[byte]int)
	cur := s[0]
	cnt := 0
	for i := range s {
		if s[i] == cur {
			cnt++
			if cnt == k {
				m[cur]++
				cnt = 0
			}
		} else {
			cnt = 1
			cur = s[i]
		}
	}
	x := 0
	for _, y := range m {
		if x < y {
			x = y
		}
	}
	fmt.Println(x)
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int

	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	str := make([]byte,n)
	fmt.Fscanf(buf, "%s", &str)
	dp := make([]int,26)
	front := 0
	rear := 0
	for front < n{
		for rear < n&&str[rear] == str[front]{
			rear++
		}
		p := int(str[front]-byte('a'))
		dp[p] += (rear-front)/m
		front = rear
	}
	ans := 0
	for i:= 0;i < 26;i++{
		if ans < dp[i]{
			ans = dp[i]
		}
	}
	fmt.Printf("%d\n",ans)

}
/*
11 3
aaabbaabbbb

2 8
1 2 1 2 1 1 1 1
*/

package main

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

var in = bufio.NewScanner(os.Stdin)

func init() {
	in.Split(bufio.ScanWords)
}

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

func Str() string {
	in.Scan()
	r := ""
	for _, c := range in.Bytes() {
		r += string(c)
	}
	return r
}

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
}

///==========---------- End of Precode ----------==========///

func main() {
	_, k, s := Int(), Int(), Str()

	last, v, p := "", make([]int, 0), make([]int, 0)
	for _, c := range s {
		if string(c) == last {
			v[len(v) - 1] += 1
		} else {
			v = append(v, 1)
			p = append(p, int(c))
			last = string(c)
		}
	}

	res := 0
	for i := 'a'; i <= 'z'; i++ {
		c := 0
		for j := range v {
			if p[j] == int(i) && v[j] >= k {
				c += v[j] / k
			}
		}
		res = max(res, c)
	}

	fmt.Printf("%d", res)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func init() {
	in.Split(bufio.ScanWords)
}

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

func Str() string {
	in.Scan()
	r := ""
	for _, c := range in.Bytes() {
		r += string(c)
	}
	return r
}

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
}

///==========---------- End of Precode ----------==========///

func main() {
	_, k, s := Int(), Int(), Str()

	last, v, p := "", make([]int, 0), make([]int, 0)
	for _, c := range s {
		if string(c) == last {
			v[len(v) - 1] += 1
		} else {
			v = append(v, 1)
			p = append(p, int(c))
			last = string(c)
		}
	}

	res := 0
	for i := 'a'; i <= 'z'; i++ {
		c := 0
		for j := range v {
			if p[j] == int(i) && v[j] >= k {
				c++
			}
		}
		res = max(res, c)
	}

	fmt.Printf("%d", res)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func init() {
	in.Split(bufio.ScanWords)
}

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

func Str() string {
	in.Scan()
	r := ""
	for _, c := range in.Bytes() {
		r += string(c)
	}
	return r
}

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
}

///==========---------- End of Precode ----------==========///

func main() {
	_, k, s := Int(), Int(), Str()

	last, v, p := "", make([]int, 0), make([]int, 0)
	for _, c := range s {
		if string(c) == last {
			v[len(v) - 1] += 1
		} else {
			v = append(v, 1)
			p = append(p, int(c))
			last = string(c)
		}
	}

	res := 0
	for i := 'a'; i <= 'z'; i++ {
		c := 0
		for j := range v {
			if p[j] == int(i) {
				c += v[j] / k
			}
		}
		res = max(res, c)
	}

	fmt.Printf("%d\n", res)
}

package main

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

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

	dd := strings.Split(scanner.Text(), " ")
	k, _ := strconv.Atoi(dd[1])
	var current int = -1
	var length int
	d := make([]int, 26)
	scanner.Scan()
	mv := 0
	for _, v := range scanner.Text() {
		dv := int(v - 'a')
		if k == 1 {
			d[dv] += 1
			if d[dv] > mv {
				mv = d[dv]
			}
		} else if current == dv {
			length += 1
			if length == k {
				d[current] += 1
				if d[current] > mv {
					mv = d[current]
				}
				current = -1
			}
		} else {
			current = dv
			length = 1
		}

	}
	fmt.Println(d)
	fmt.Println(mv)
}

package main

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

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

	dd := strings.Split(scanner.Text(), " ")
	k, _ := strconv.Atoi(dd[1])
	var current int = -1
	var length int
	d := make([]int, 26)
	scanner.Scan()
	mv := 0
	for _, v := range scanner.Text() {
		dv := int(v - 'a')
		if current == dv {
			length += 1
			if length == k {
				d[current] += 1
				if d[current] > mv {
					mv = d[current]
				}
				current = -1
			}
		} else {
			current = dv
			length = 1
		}

	}
	fmt.Println(mv)
}

package main

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

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

	dd := strings.Split(scanner.Text(), " ")
	k, _ := strconv.Atoi(dd[1])
	var current int = -1
	var length int
	d := make([]int, 26)
	scanner.Scan()
	mv := 0
	for _, v := range scanner.Text() {
		dv := int(v - 'a')
		if k == 1 {
			d[dv] += 1
			if d[dv] > mv {
				mv = d[dv]
			}
		} else if current == dv {
			length += 1
			if length == k {
				d[current] += 1
				if d[current] > mv {
					mv = d[current]
				}
				current = -1
			}
		} else {
			current = dv
			length = 1
		}

	}
	fmt.Println(mv)
}

package main

import "fmt"

type input string;

// type letter string;
// type _repCount map[int]int;
// type letterDB map[letter]_repCount;

func MinMax(array []int) (int, int) {
    var max int = array[0]
    var min int = array[0]
    for _, value := range array {
        if max < value {
            max = value
        }
        if min > value {
            min = value
        }
    }
    return min, max
}

func  main() {
	var length, k int;
	var input string;

	fmt.Scanf("%d %d", &length, &k);
	fmt.Scanf("%s", &input);

	var letterDB map[string]map[int]int = make(map[string]map[int]int);

	for i:=0; i < len(input); i++ {
		letterDB[ string(input[i]) ] = make(map[int]int);
	}

	// fmt.Println(letterDB);

	input = input + " "
	for patternLength, i:= 1, 0; i < len(input) - 1; i++ {
		if input[i] == input[i+1] {
			patternLength += 1;
		} else {

			if _, ok := letterDB[string(input[i])][patternLength]; ok {
				letterDB[string(input[i])][patternLength] += 1;
			} else {
				letterDB[string(input[i])][patternLength] = 1;
			}

			patternLength = 1;

		}
	}

	// fmt.Println(letterDB);

	var rankDB map[string]int = make(map[string]int);

	for letter := range letterDB {
		var rank int = 0;
		for patternLength, count := range letterDB[letter] {
			rank += (patternLength/k) * count;
		}
		rankDB[letter] = rank;
	}

	// fmt.Println(rankDB);

	ranks := make([]int, length);
	for _, val := range rankDB {
		ranks = append(ranks, val);
	}

	_, rank := MinMax(ranks);

	fmt.Println(rank);

}

// func main() {
// 	var length, k int;
// 	var letters string;

// 	fmt.Scanf("%d %d", &length, &k);
// 	fmt.Scanf("%s", &letters);

// 	fmt.Println(length, k, letters);

// 	var letterMap map[int]map[int]int = make(map[int]map[int]int);

// 	for i:= 0; i < len(letters); i += 1 {
// 		letter := int(letters[i]);
// 		letterMap[letter] = make(map[int]int);
// 	}

// 	fmt.Println("lk\n");

// 	for i, patternLength := 0, 0; i < len(letters); i += 1 {

// 		fmt.Println(i);

// 		if letters[i] == letters[i+1] {
// 			patternLength += 1
// 			// fmt.Println(patternLength);
// 		} else if val, ok := letterMap[i][patternLength]; ok {
// 			fmt.Println("kj", val);
// 			letterMap[i][patternLength] = val + 1;
// 		} else {
// 			fmt.Println("sk");
// 			letterMap[i][patternLength] = 1;
// 		}
// 	}

// 	fmt.Println(letterMap);
// }