There are $$$n$$$ students at your university. The programming skill of the $$$i$$$-th student is $$$a_i$$$. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this university is if it has $$$2 \cdot 10^5$$$ students ready for the finals!Each team should consist of at least three students. Each student should belong to exactly one team. The diversity of a team is the difference between the maximum programming skill of some student that belongs to this team and the minimum programming skill of some student that belongs to this team (in other words, if the team consists of $$$k$$$ students with programming skills $$$a[i_1], a[i_2], \dots, a[i_k]$$$, then the diversity of this team is $$$\max\limits_{j=1}^{k} a[i_j] - \min\limits_{j=1}^{k} a[i_j]$$$).The total diversity is the sum of diversities of all teams formed.Your task is to minimize the total diversity of the division of students and find the optimal way to divide the students.

The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the programming skill of the $$$i$$$-th student.

In the first line print two integers $$$res$$$ and $$$k$$$ — the minimum total diversity of the division of students and the number of teams in your division, correspondingly. In the second line print $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$1 \le t_i \le k$$$), where $$$t_i$$$ is the number of team to which the $$$i$$$-th student belong. If there are multiple answers, you can print any. Note that you don't need to minimize the number of teams. Each team should consist of at least three students.

NoteIn the first example, there is only one team with skills $$$[1, 1, 2, 3, 4]$$$ so the answer is $$$3$$$. It can be shown that you cannot achieve a better answer.In the second example, there are two teams with skills $$$[1, 2, 5]$$$ and $$$[12, 13, 15]$$$ so the answer is $$$4 + 3 = 7$$$.In the third example, there are three teams with skills $$$[1, 2, 5]$$$, $$$[129, 185, 581, 1041]$$$ and $$$[1580, 1909, 8150]$$$ so the answer is $$$4 + 912 + 6570 = 7486$$$.

package main

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

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

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

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

type elt struct {
	val int
	pos int
	grp int
}

var (
	n int
	a []elt
)

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

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

type memT struct {
	present bool
	tot     int64
	pos     int
}

var (
	mem []memT
)

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

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

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

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

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

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

func main() {
	defer writer.Flush()

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

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

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

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

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

package main

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

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

func main() {

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

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

	a := make([]Node, n)

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

		a[i].i = i
	}

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

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

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

	term := 0

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

		i = a[i].p - 1
	}

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

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

	fmt.Println()
}

package main

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

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

func main() {

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

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

	a := make([]Node, n)

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

		a[i].i = i
	}

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

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

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

	term := n / 3

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

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

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

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

	fmt.Println()
}


One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of $$$n$$$ non-negative integers.If there are exactly $$$K$$$ distinct values in the array, then we need $$$k = \lceil \log_{2} K \rceil$$$ bits to store each value. It then takes $$$nk$$$ bits to store the whole file.To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers $$$l \le r$$$, and after that all intensity values are changed in the following way: if the intensity value is within the range $$$[l;r]$$$, we don't change it. If it is less than $$$l$$$, we change it to $$$l$$$; if it is greater than $$$r$$$, we change it to $$$r$$$. You can see that we lose some low and some high intensities.Your task is to apply this compression in such a way that the file fits onto a disk of size $$$I$$$ bytes, and the number of changed elements in the array is minimal possible.We remind you that $$$1$$$ byte contains $$$8$$$ bits.$$$k = \lceil log_{2} K \rceil$$$ is the smallest integer such that $$$K \le 2^{k}$$$. In particular, if $$$K = 1$$$, then $$$k = 0$$$.

The first line contains two integers $$$n$$$ and $$$I$$$ ($$$1 \le n \le 4 \cdot 10^{5}$$$, $$$1 \le I \le 10^{8}$$$) — the length of the array and the size of the disk in bytes, respectively. The next line contains $$$n$$$ integers $$$a_{i}$$$ ($$$0 \le a_{i} \le 10^{9}$$$) — the array denoting the sound file.

Print a single integer — the minimal possible number of changed elements.

NoteIn the first example we can choose $$$l=2, r=3$$$. The array becomes 2 2 2 3 3 3, the number of distinct elements is $$$K=2$$$, and the sound file fits onto the disk. Only two values are changed.In the second example the disk is larger, so the initial file fits it and no changes are required.In the third example we have to change both 1s or both 3s.

package main

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

/* solution */

func solve() {

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

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

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

	sort.Ints(arr)

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

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

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

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

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

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

	ans := 1000000001

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

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

}

/* stubs */

func main() {

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

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

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

	solve()

}

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

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

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

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

package main

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

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

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

package main

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

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

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

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

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

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

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

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

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

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

package main

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

/* solution */

func solve() {

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

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

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

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

	sort.Ints(arr)

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

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

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

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

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

	ans := 1000000001

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

	}

	println(strconv.Itoa(ans))

}

/* stubs */

func main() {

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

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

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

	solve()

}

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

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

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

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

package main

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

/* solution */

func solve() {

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

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

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

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

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

	sort.Ints(arr)

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

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

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

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

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

	ans := 1000000001

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

	}

	println(strconv.Itoa(ans))

}

/* stubs */

func main() {

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

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

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

	solve()

}

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

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

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

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

package main

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

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

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

package main

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

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

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

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

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

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

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

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

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

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

package main

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

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

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

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

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

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

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

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

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

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


You have a password which you often type — a string $$$s$$$ of length $$$n$$$. Every character of this string is one of the first $$$m$$$ lowercase Latin letters.Since you spend a lot of time typing it, you want to buy a new keyboard.A keyboard is a permutation of the first $$$m$$$ Latin letters. For example, if $$$m = 3$$$, then there are six possible keyboards: abc, acb, bac, bca, cab and cba.Since you type your password with one finger, you need to spend time moving your finger from one password character to the next. The time to move from character $$$s_i$$$ to character $$$s_{i+1}$$$ is equal to the distance between these characters on keyboard. The total time you have to spend typing the password with a keyboard is called the slowness of this keyboard.More formaly, the slowness of keyboard is equal to $$$\sum\limits_{i=2}^{n} |pos_{s_{i-1}} - pos_{s_i} |$$$, where $$$pos_x$$$ is position of letter $$$x$$$ in keyboard.For example, if $$$s$$$ is aacabc and the keyboard is bac, then the total time of typing this password is $$$|pos_a - pos_a| + |pos_a - pos_c| + |pos_c - pos_a| + |pos_a - pos_b| + |pos_b - pos_c|$$$ = $$$|2 - 2| + |2 - 3| + |3 - 2| + |2 - 1| + |1 - 3|$$$ = $$$0 + 1 + 1 + 1 + 2 = 5$$$.Before buying a new keyboard you want to know the minimum possible slowness that the keyboard can have.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^5, 1 \le m \le 20$$$). The second line contains the string $$$s$$$ consisting of $$$n$$$ characters. Each character is one of the first $$$m$$$ Latin letters (lowercase).

Print one integer – the minimum slowness a keyboard can have.

NoteThe first test case is considered in the statement.In the second test case the slowness of any keyboard is $$$0$$$.In the third test case one of the most suitable keyboards is bacd.

package main

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

var adj [20][20]uint

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

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

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

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

package main

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

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

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

const U0 = uint(0)

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

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

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

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

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

    all := (1 << m) - 1

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

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

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

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

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

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

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

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

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

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


Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.

For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.

NoteLet's consider the test cases of the example:  $$$n=8$$$, $$$k=3$$$:   during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$;  during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$;  during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$;  during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$.   $$$n=6$$$, $$$k=6$$$:   during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$;  during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$;  during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$.   $$$n=7$$$, $$$k=1$$$:   during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$;  during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$;  during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$;  during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$;  during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$;  during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.

package main

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

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

func main() {
	defer out.Flush()

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

package main

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

func solve(n, k int64) int64 {

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

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

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

	return time
}

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

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

package main

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

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

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

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

		if d > k {
			break
		}
	}

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

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

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

package main

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

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

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

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

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

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

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

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

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

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

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

var t int

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

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

		var begin int64 = 1

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

		}

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

			}
		}

		fmt.Println(ans)

	}

}

package main

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

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

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

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

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

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

package main

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

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

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

	bld := strings.Builder{}

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

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

		/*
			n=7 k=3

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

			n=9 k=2

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

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

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

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

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

		fmt.Fprintln(&bld, time)
	}

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

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

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

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

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

	return true
}

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

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

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

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

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

package main

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

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

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

		installed := int64(1)

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

	}
}

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

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

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

package main

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

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

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

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

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

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

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

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

package main

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

var n, k int64

func main() {

	r := bufio.NewReader(os.Stdin)

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

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

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

func solve() int64 {

	var i int
	var prev int64 = 1

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

		if temp > prev + k {
			prev += k

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

			break
		}

		prev = temp

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

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

	return d + int64(i)
}

func min(a, b int64) int64 {

	if a < b {
		return a
	}
	return b
}

package main

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

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

func main() {
	defer out.Flush()

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

package main

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

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

func main() {
	defer out.Flush()

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

package main

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

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

func main() {
	defer out.Flush()

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

package main

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

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

func main() {
	defer out.Flush()

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

package main

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

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

func main() {
	defer out.Flush()

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

package main

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

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

func main() {
	defer out.Flush()

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

package main

import "fmt"

func solve(n, k int64) int64 {

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

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

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

	return time
}

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

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

package main

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

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

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

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

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

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

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

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


Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.Help her to do so in finding the total number of such segments.

The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 ≤ n ≤ 105, 1 ≤ |k| ≤ 10). Next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — affection values of chemicals.

Output a single integer — the number of valid segments.

NoteDo keep in mind that k0 = 1.In the first sample, Molly can get following different affection values:  2: segments [1, 1], [2, 2], [3, 3], [4, 4]; 4: segments [1, 2], [2, 3], [3, 4]; 6: segments [1, 3], [2, 4]; 8: segments [1, 4]. Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4].

package main

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

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

func solve(n, k int, a []int) (r uint64) {
	var c []int64
	if k == 1 {
		c = []int64{1}
	} else if k == -1 {
		c = []int64{-1, 1}
	} else {
		c = make([]int64, 0)
		var x int64 = 1
		for abs(x) <= int64(n) * 1000000000 {
			c = append(c, x)
			x = x * int64(k)
		}
	}
	b := make(map[int64]uint)
	b[0] = 1
	var s int64
	for _, x := range a {
		s = s + int64(x)
		for _, y := range c {
			t := s - y
			if u, ok := b[t]; ok {
				r = r + uint64(u)
			}
		}
		b[s] += 1
	}
	return
}

func main() {
	var cin *ParserReader
	if false {
		f, _ := os.Open("c.in")
		cin = NewParser(bufio.NewReaderSize(f, 1 << 16))
	} else {
		cin = NewParser(bufio.NewReaderSize(os.Stdin, 1 << 16))
	}
	n := cin.nextInt()
	k := cin.nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = cin.nextInt()
	}
	fmt.Printf("%v", solve(n, k, a))
}

// some io

type ParserReader struct {
	r   io.ByteReader
	err error
	c   byte
}

func NewParser(r io.ByteReader) *ParserReader {
	return &ParserReader{r, nil, 0}
}

func (p *ParserReader) next() error {
	p.c, p.err = p.r.ReadByte()
	return p.err
}

func isDigit(c byte) bool {
	return '0' <= c && c <= '9'
}

func (p *ParserReader) nextUInt64() uint64 {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint64
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint64(p.c-'0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextUInt() uint {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint(p.c-'0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextInt64() int64 {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int64(p.nextUInt64())
	if sign {
		return -r
	}
	return r
}

func (p *ParserReader) nextInt() int {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int(p.nextUInt())
	if sign {
		return -r
	}
	return r
}

func isSpace(c byte) bool {
	return c < 32 || c == ' ' || c == '\n' || c == '\t'
}

func (p *ParserReader) nextString() string {
	for isSpace(p.c) && p.err == nil {
		p.next()
	}
	r := make([]byte, 0, 1)
	for !isSpace(p.c) && p.err == nil {
		r = append(r, p.c)
		p.next()
	}
	return string(r)
}


You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?

The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.

If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.

NoteIn the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.

package main

import (
	"bufio"
	"os"
)

var in = bufio.NewScanner(os.Stdin)

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

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

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

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

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

package main

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

type scanner struct {
	*bufio.Scanner
}

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

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

type point struct {
	x, y int64
}

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

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

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

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


Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.

The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.

Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li < ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.

NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.

package main

import "fmt"

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

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

package main

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

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

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

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

package main

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

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

}

package main

import "fmt"

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

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

package main

import (
	"fmt"
)

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

	for {
		var reverse bool = false

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

package main

import "fmt"

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

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

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

}

package main

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

import "strings"

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

	ml := 0

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

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

		}
	}

}

package main

import "fmt"

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

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

package main

import "fmt"

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

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

package main

import "fmt"

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

package main

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

import "strings"

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

	ml := 0

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

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

		}
	}

}


Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each individual letter all its positions in the string are written out in the increasing order. This results in 26 lists of numbers; some of them can be empty. A string is considered lucky if and only if in each list the absolute difference of any two adjacent numbers is a lucky number. For example, let's consider string "zbcdzefdzc". The lists of positions of equal letters are: b: 2 c: 3, 10 d: 4, 8 e: 6 f: 7 z: 1, 5, 9 Lists of positions of letters a, g, h, ..., y are empty.This string is lucky as all differences are lucky numbers. For letters z: 5 - 1 = 4, 9 - 5 = 4, for letters c: 10 - 3 = 7, for letters d: 8 - 4 = 4. Note that if some letter occurs only once in a string, it doesn't influence the string's luckiness after building the lists of positions of equal letters. The string where all the letters are distinct is considered lucky.Find the lexicographically minimal lucky string whose length equals n.

The single line contains a positive integer n (1 ≤ n ≤ 105) — the length of the sought string.

Print on the single line the lexicographically minimal lucky string whose length equals n.

NoteThe lexical comparison of strings is performed by the < operator in modern programming languages. String a is lexicographically less than string b if exists such i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj.

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

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

package main

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

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

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

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

package main

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

/*func luckyTest(s string) bool {

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

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

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

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

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