package main

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

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

	in := make([]bool, 1000001, 1000001)
	cur := 0
	ans := 0

	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		c := bs.Text()[0]
		bs.Scan()
		p, _ := strconv.Atoi(bs.Text())
		if c == '+' {
			in[p] = true
			cur++
			if ans < cur {
				ans = cur
			}
		} else {
			if in[p] {
				cur--
			} else {
				ans++
			}
			in[p] = false
		}
	}

	fmt.Println(ans)
}

Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms:  "+ ri" — the reader with registration number ri entered the room;  "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.

Print a single integer — the minimum possible capacity of the reading room.

NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.

package main
import (
	"fmt"
)
func main(){
	var n, register int
	var action string
	var peopleMap map[int] bool
	peopleMap = make(map[int]bool)
	var tmpList []int
	var peopleList []int
	res := 0
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++{
		fmt.Scanf("%s%d\n", &action, &register)
		if action == "+"{
			peopleMap[register] = true
			tmpList = append(tmpList, register)
		}else{
			tmpList = append(tmpList, register * -1)
			_, ok := peopleMap[register]
			if ok{
				delete(peopleMap, register)
			}else{
				peopleList = append(peopleList, register)
			}
		}
	}
	peopleMap = make(map[int]bool)
	peopleList = append(peopleList, tmpList...)
	for i := 0; i < len(peopleList); i++{
		if peopleList[i] > 0{
			peopleMap[peopleList[i]] = true
		}else{
			now := peopleList[i] * -1
			delete(peopleMap, now)
		}
		res = Max(res, len(peopleMap))
	}
	fmt.Println(res)
}

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


package main

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

func main() {
	get := wrapStdin()
	n, a, b := get.Int(), get.Int(), get.Int()

	if a*b < n {
		fmt.Println(-1)
		fmt.Fprintf(os.Stderr, runtime.GOMAXPROCS(0))
		return
	}

	g := func(b int) func() int {
		return func() int {
			t := b
			b += 2
			if t > n {
				t = 0
			}
			return t
		}
	}
	ev, od := g(2), g(1)

	for i := 0; i < a; i++ {
		for j := 0; j < b; j++ {
			var x int
			if (i^j)&1 == 0 {
				x = od()
			} else {
				x = ev()
			}
			fmt.Printf("%d ", x)
		}
		fmt.Printf("\n")
	}
}

type Input struct {
	*bufio.Scanner
}

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func (in Input) Int() int {
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x
}
func (in Input) IntOk() (int, bool) {
	ok := in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x, ok
}

There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.New parliament assembly hall is a rectangle consisting of a × b chairs — a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hallWe know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.

The first line of the input contains three integers n, a and b (1 ≤ n ≤ 10 000, 1 ≤ a, b ≤ 100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.

If there is no way to assigns seats to parliamentarians in a proper way print -1. Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.

NoteIn the first sample there are many other possible solutions. For example, 3 20 1and 2 13 0The following assignment 3 21 0is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.

package main

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

func main() {
	get := wrapStdin()
	n, a, b := get.Int(), get.Int(), get.Int()

	if a*b < n {
		fmt.Println(-1)
		return
	}

	g := func(b int) func() int {
		return func() int {
			t := b
			b += 2
			if t > n {
				t = 0
			}
			return t
		}
	}
	ev, od := g(2), g(1)

	for i := 0; i < a; i++ {
		for j := 0; j < b; j++ {
			var x int
			if (i^j)&1 == 0 {
				x = od()
			} else {
				x = ev()
			}
			fmt.Printf("%d ", x)
		}
		fmt.Printf("\n")
	}
}

type Input struct {
	*bufio.Scanner
}

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func (in Input) Int() int {
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x
}
func (in Input) IntOk() (int, bool) {
	ok := in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x, ok
}


// 25B
package main

import (
	"fmt"
)

func main() {
	var i, n int
	var s string
	fmt.Scan(&n, &s)
	for i = 0; i < n-2-n%2; i += 2 {
		fmt.Print(s[i], s[i+1], string('-'))
	}
	fmt.Println(s[i : n-i])
}

Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.

The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups.

Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.

package main

import (
	"fmt"
)

func main() {

	var (
		lo, i     int32
		orig, ans string
	)

	fmt.Scan(&lo)
	fmt.Scan(&orig)
	if lo < 4 {
		ans = orig
	} else {
		if lo%2 > 0 {
			ans = orig[0:3]
			i = 3
		} else {
			ans = orig[0:2]
			i = 2
		}
		for i < lo {
			ans += "-"
			ans += orig[i : i+2]
			i += 2
		}
	}

	fmt.Println(ans)
}


package main
import (
	"fmt"
)

func main() {
	var input, x int
	x=1
	fmt.Scan(&input)
	for i:=1; i<input; i++ {
		x+=i
		if x>input {
			fmt.Println(x%input)
		} else {
			fmt.Println(x)
		}
	}
}

A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to n clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if n = 5, then after the third throw the child number 2 has the ball again. Overall, n - 1 throws are made, and the game ends.The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.

The first line contains integer n (2 ≤ n ≤ 100) which indicates the number of kids in the circle.

In the single line print n - 1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    pos, plus := 0, 1
    for i := 1; i < n; i++ {
        pos = (pos+plus)%n
        fmt.Print(pos+1)
        if i != (n-1) { fmt.Print(" ") } else { fmt.Println() }
        plus++
    }
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var a, b string
	likes := map[string]map[string]int{}
	for i := 0; i < n; i++ {
		fmt.Scanf("%s likes %s\n", &a, &b)
		_, ok := likes[a]
		if !ok {
			likes[a] = map[string]int{}
		}
		likes[a][b] = 1
	}
	var n1, n2, n3 int
	fmt.Scanf("%d %d %d\n", &n1, &n2, &n3)
	heroes := []string{"Anka", "Chapay", "Cleo", "Troll", "Dracul", "Snowy", "Hexadecimal"}
	ans1, ans2 := math.MaxInt32, math.MinInt32
	g1, g2, g3 := 0, 0, 0
	for i := 1; i <= 5; i++ {
		for j := 1; j <= 5; j++ {
			if i+j >= 7 {
				continue
			}
			k := 7 - i - j
			t := calc(n1/i, n2/j, n3/k)
			if t < ans1 {
				ans1 = t
				g1, g2, g3 = i, j, k
			}
		}
	}
	var i, j, k uint
	var t int
	for i = 0; i < 128; i++ {
		if count(i) != g1 {
			continue
		}
		for j = 0; j < 128; j++ {
			if count(j) != g2 {
				continue
			}
			k = 127 - i - j
			if count(k) != g3 {
				continue
			}
			t = calc2(i, heroes, likes) + calc2(j, heroes, likes) + calc2(k, heroes, likes)
			if t > ans2 {
				ans2 = t
			}
		}
	}
	fmt.Println(ans1, ans2)
}

func calc2(n uint, h []string, l map[string]map[string]int) int {
	ans := 0
	q := []int{}
	for i := 0; i < 7; i++ {
		if n&(1<<i) != 0 {
			q = append(q, i)
		}
	}

	for i := 0; i < len(q); i++ {
		for j := i + 1; j < len(q); j++ {
			if l[h[q[i]]][h[q[j]]] == 1 {
				ans++
			}
			if l[h[q[j]]][h[q[i]]] == 1 {
				ans++
			}
		}
	}
	return ans
}

func count(n uint) int {
	ans := 0
	for n != 0 {
		ans++
		n = n & (n - 1)
	}
	return ans
}

func calc(a, b, c int) int {
	if a < b {
		a, b = b, a
	}
	if b > c {
		return a - c
	}
	if c > a {
		return c - b
	}
	return a - b
}

The year of 2012 is coming...According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us mere mortals from the effect of this terrible evil.The seven great heroes are: amazon Anka, barbarian Chapay, sorceress Cleo, druid Troll, necromancer Dracul, paladin Snowy and a professional hit girl Hexadecimal. Heroes already know how much experience will be given for each of the three megabosses: a for Mephisto, b for Diablo and c for Baal.Here's the problem: heroes are as much as seven and megabosses are only three! Then our heroes decided to split into three teams, where each team will go to destroy their own megaboss. Each team member will receive a  of experience, rounded down, where x will be the amount of experience for the killed megaboss and y — the number of people in the team.Heroes do not want to hurt each other's feelings, so they want to split into teams so that the difference between the hero who received the maximum number of experience and the hero who received the minimum number of experience were minimal. Since there can be several divisions into teams, then you need to find the one in which the total amount of liking in teams were maximum.It is known that some heroes like others. But if hero p likes hero q, this does not mean that the hero q likes hero p. No hero likes himself.The total amount of liking in teams is the amount of ordered pairs (p,q), such that heroes p and q are in the same group, and hero p likes hero q (but it is not important if hero q likes hero p). In case of heroes p and q likes each other and they are in the same group, this pair should be counted twice, as (p,q) and (q,p).A team can consist even of a single hero, but it is important that every megaboss was destroyed. All heroes must be involved in the campaign against evil. None of the heroes can be in more than one team.It is guaranteed that every hero is able to destroy any megaboss alone.

The first line contains a single non-negative integer n (0≤n≤42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠ q). Every liking is described in the input exactly once, no hero likes himself.
In the last line are given three integers a, b and c (1≤a,b,c≤2·10^9), separated by spaces: the experience for Mephisto, the experience for Diablo and experience for Baal.
In all the pretests, except for examples from the statement, the following condition is satisfied: a=b=c.

Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team).
When calculating the second answer, the team division should satisfy the difference-minimizing contraint. I.e. primary you should minimize the difference in the experience and secondary you should maximize the total amount of liking.

A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.

3
Troll likes Dracul
Dracul likes Anka
Snowy likes Hexadecimal
210 200 180

2
Anka likes Chapay
Chapay likes Anka
10000 50 50

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var a, b string
	likes := map[string]map[string]int{}
	for i := 0; i < n; i++ {
		fmt.Scanf("%s likes %s\n", &a, &b)
		_, ok := likes[a]
		if !ok {
			likes[a] = map[string]int{}
		}
		likes[a][b] = 1
	}
	var n1, n2, n3 int
	fmt.Scanf("%d %d %d\n", &n1, &n2, &n3)
	heroes := []string{"Anka", "Chapay", "Cleo", "Troll", "Dracul", "Snowy", "Hexadecimal"}
	ans1, ans2 := math.MaxInt32, math.MinInt32
	g := make(map[int][]int)
	for i := 1; i <= 5; i++ {
		for j := 1; j <= 5; j++ {
			if i+j >= 7 {
				continue
			}
			k := 7 - i - j
			t := calc(n1/i, n2/j, n3/k)
			if t <= ans1 {
				ans1 = t
				_, ok := g[t]
				if !ok {
					g[t] = make([]int, 0)
				}
				g[t] = append(g[t], i, j, k)
			}
		}
	}
	var i, j, k uint
	var t int
	for len(g[ans1]) != 0 {
		g1, g2, g3 := g[ans1][0], g[ans1][1], g[ans1][2]
		g[ans1] = g[ans1][3:]
		for i = 0; i < 128; i++ {
			if count(i) != g1 {
				continue
			}
			for j = 0; j < 128; j++ {
				if count(j) != g2 {
					continue
				}
				k = 127 - i - j
				if count(k) != g3 {
					continue
				}
				t = calc2(i, heroes, likes) + calc2(j, heroes, likes) + calc2(k, heroes, likes)
				if t > ans2 {
					ans2 = t
				}
			}
		}
	}
	fmt.Println(ans1, ans2)
}

func calc2(n uint, h []string, l map[string]map[string]int) int {
	ans := 0
	q := []int{}
	for i := 0; i < 7; i++ {
		if n&(1<<i) != 0 {
			q = append(q, i)
		}
	}

	for i := 0; i < len(q); i++ {
		for j := i + 1; j < len(q); j++ {
			if l[h[q[i]]][h[q[j]]] == 1 {
				ans++
			}
			if l[h[q[j]]][h[q[i]]] == 1 {
				ans++
			}
		}
	}
	//fmt.Println(n, ans)
	return ans
}

func count(n uint) int {
	ans := 0
	for n != 0 {
		ans++
		n = n & (n - 1)
	}
	return ans
}

func calc(a, b, c int) int {
	if a < b {
		a, b = b, a
	}
	if b > c {
		return a - c
	}
	if c > a {
		return c - b
	}
	return a - b
}

[{'input': ['3\r\nTroll likes Dracul\r\nDracul likes Anka\r\nSnowy likes Hexadecimal\r\n210 200 180\r\n'], 'output': ['30 3\r\n']}, {'input': ['2\r\nAnka likes Chapay\r\nChapay likes Anka\r\n10000 50 50\r\n'], 'output': ['1950 2\r\n']}, {'input': ['11\r\nSnowy likes Dracul\r\nAnka likes Dracul\r\nChapay likes Snowy\r\nHexadecimal likes Troll\r\nAnka likes Cleo\r\nChapay likes Dracul\r\nAnka likes Chapay\r\nSnowy likes Troll\r\nAnka likes Hexadecimal\r\nCleo likes Chapay\r\nTroll likes Cleo\r\n100 100 100\r\n'], 'output': ['17 5\r\n']}, {'input': ['14\r\nChapay likes Cleo\r\nCleo likes Anka\r\nDracul likes Snowy\r\nSnowy likes Cleo\r\nChapay likes Anka\r\nSnowy likes Anka\r\nChapay likes Troll\r\nTroll likes Anka\r\nAnka likes Snowy\r\nChapay likes Dracul\r\nDracul likes Anka\r\nHexadecimal likes Chapay\r\nSnowy likes Dracul\r\nCleo likes Dracul\r\n15 15 15\r\n'], 'output': ['2 6\r\n']}, {'input': ['4\r\nAnka likes Cleo\r\nSnowy likes Cleo\r\nAnka likes Hexadecimal\r\nCleo likes Snowy\r\n1 1 1\r\n'], 'output': ['0 3\r\n']}, {'input': ['8\r\nSnowy likes Anka\r\nHexadecimal likes Snowy\r\nTroll likes Dracul\r\nHexadecimal likes Troll\r\nSnowy likes Troll\r\nAnka likes Snowy\r\nSnowy likes Chapay\r\nAnka likes Chapay\r\n70 70 70\r\n'], 'output': ['12 5\r\n']}, {'input': ['0\r\n100 300 600\r\n'], 'output': ['50 0\r\n']}, {'input': ['3\r\nChapay likes Hexadecimal\r\nAnka likes Cleo\r\nTroll likes Snowy\r\n15 15000 90\r\n'], 'output': ['2985 2\r\n']}, {'input': ['0\r\n1 1 10000\r\n'], 'output': ['1999 0\r\n']}, {'input': ['13\r\nCleo likes Hexadecimal\r\nCleo likes Snowy\r\nHexadecimal likes Anka\r\nAnka likes Snowy\r\nTroll likes Snowy\r\nChapay likes Hexadecimal\r\nHexadecimal likes Snowy\r\nSnowy likes Chapay\r\nTroll likes Cleo\r\nAnka likes Hexadecimal\r\nHexadecimal likes Cleo\r\nChapay likes Dracul\r\nSnowy likes Dracul\r\n1000000000 2000000000 1000000000\r\n'], 'output': ['166666666 6\r\n']}, {'input': ['12\r\nCleo likes Hexadecimal\r\nChapay likes Anka\r\nHexadecimal likes Cleo\r\nAnka likes Snowy\r\nAnka likes Cleo\r\nDracul likes Snowy\r\nAnka likes Troll\r\nSnowy likes Anka\r\nCleo likes Anka\r\nHexadecimal likes Troll\r\nHexadecimal likes Chapay\r\nSnowy likes Troll\r\n1000000000 1 2000000000\r\n'], 'output': ['499999999 7\r\n']}, {'input': ['0\r\n2000000000 2000000000 2000000000\r\n'], 'output': ['333333334 0\r\n']}, {'input': ['2\r\nSnowy likes Hexadecimal\r\nTroll likes Dracul\r\n2000000000 2000000000 2000000000\r\n'], 'output': ['333333334 2\r\n']}, {'input': ['12\r\nSnowy likes Chapay\r\nCleo likes Dracul\r\nHexadecimal likes Snowy\r\nHexadecimal likes Anka\r\nDracul likes Chapay\r\nCleo likes Troll\r\nDracul likes Snowy\r\nSnowy likes Dracul\r\nTroll likes Chapay\r\nDracul likes Anka\r\nChapay likes Hexadecimal\r\nTroll likes Dracul\r\n436364663 856574374 347564737\r\n'], 'output': ['111742423 6\r\n']}, {'input': ['12\r\nAnka likes Dracul\r\nDracul likes Troll\r\nCleo likes Troll\r\nSnowy likes Hexadecimal\r\nHexadecimal likes Chapay\r\nCleo likes Dracul\r\nCleo likes Chapay\r\nHexadecimal likes Anka\r\nSnowy likes Cleo\r\nHexadecimal likes Snowy\r\nCleo likes Snowy\r\nChapay likes Snowy\r\n584329075 428752235 675234087\r\n'], 'output': ['77788420 6\r\n']}, {'input': ['8\r\nAnka likes Chapay\r\nDracul likes Snowy\r\nSnowy likes Cleo\r\nCleo likes Anka\r\nCleo likes Troll\r\nHexadecimal likes Troll\r\nTroll likes Cleo\r\nSnowy likes Dracul\r\n325432666 254352394 547360304\r\n'], 'output': ['55277237 6\r\n']}, {'input': ['18\r\nSnowy likes Troll\r\nChapay likes Hexadecimal\r\nCleo likes Snowy\r\nDracul likes Snowy\r\nSnowy likes Chapay\r\nTroll likes Cleo\r\nSnowy likes Anka\r\nDracul likes Hexadecimal\r\nHexadecimal likes Anka\r\nAnka likes Hexadecimal\r\nAnka likes Chapay\r\nTroll likes Anka\r\nAnka likes Snowy\r\nAnka likes Troll\r\nSnowy likes Cleo\r\nHexadecimal likes Troll\r\nHexadecimal likes Dracul\r\nCleo likes Anka\r\n20000 1000 20000\r\n'], 'output': ['5666 8\r\n']}, {'input': ['6\r\nChapay likes Troll\r\nTroll likes Cleo\r\nCleo likes Troll\r\nChapay likes Snowy\r\nAnka likes Snowy\r\nTroll likes Dracul\r\n987499608 272739716 133573597\r\n'], 'output': ['113301305 5\r\n']}, {'input': ['6\r\nAnka likes Troll\r\nTroll likes Chapay\r\nTroll likes Hexadecimal\r\nHexadecimal likes Cleo\r\nSnowy likes Hexadecimal\r\nChapay likes Troll\r\n740076959 230477703 987799796\r\n'], 'output': ['98788895 5\r\n']}, {'input': ['17\r\nCleo likes Dracul\r\nTroll likes Cleo\r\nAnka likes Chapay\r\nAnka likes Troll\r\nChapay likes Snowy\r\nTroll likes Snowy\r\nChapay likes Dracul\r\nHexadecimal likes Snowy\r\nDracul likes Snowy\r\nTroll likes Hexadecimal\r\nHexadecimal likes Anka\r\nCleo likes Snowy\r\nHexadecimal likes Dracul\r\nSnowy likes Chapay\r\nSnowy likes Hexadecimal\r\nSnowy likes Dracul\r\nDracul likes Troll\r\n112909524 619275170 403563648\r\n'], 'output': ['88872300 9\r\n']}, {'input': ['1\r\nHexadecimal likes Chapay\r\n848189141 631955593 79523012\r\n'], 'output': ['203206701 1\r\n']}, {'input': ['18\r\nAnka likes Troll\r\nDracul likes Chapay\r\nHexadecimal likes Dracul\r\nChapay likes Dracul\r\nAnka likes Hexadecimal\r\nSnowy likes Cleo\r\nDracul likes Anka\r\nSnowy likes Anka\r\nSnowy likes Hexadecimal\r\nDracul likes Troll\r\nDracul likes Snowy\r\nHexadecimal likes Anka\r\nChapay likes Hexadecimal\r\nSnowy likes Dracul\r\nCleo likes Snowy\r\nChapay likes Cleo\r\nAnka likes Dracul\r\nTroll likes Anka\r\n838821770 712931449 361810998\r\n'], 'output': ['124167182 8\r\n']}, {'input': ['18\r\nHexadecimal likes Chapay\r\nTroll likes Dracul\r\nTroll likes Snowy\r\nCleo likes Dracul\r\nChapay likes Snowy\r\nDracul likes Chapay\r\nCleo likes Snowy\r\nDracul likes Hexadecimal\r\nTroll likes Anka\r\nAnka likes Troll\r\nHexadecimal likes Dracul\r\nChapay likes Hexadecimal\r\nCleo likes Chapay\r\nAnka likes Hexadecimal\r\nSnowy likes Dracul\r\nChapay likes Troll\r\nAnka likes Snowy\r\nDracul likes Cleo\r\n240256138 922743697 38909902\r\n'], 'output': ['191776022 10\r\n']}, {'input': ['0\r\n477107314 230715335 261545417\r\n'], 'output': ['43678104 0\r\n']}, {'input': ['16\r\nChapay likes Snowy\r\nHexadecimal likes Anka\r\nChapay likes Troll\r\nDracul likes Cleo\r\nTroll likes Hexadecimal\r\nHexadecimal likes Dracul\r\nChapay likes Cleo\r\nSnowy likes Cleo\r\nSnowy likes Anka\r\nTroll likes Chapay\r\nSnowy likes Hexadecimal\r\nTroll likes Snowy\r\nCleo likes Hexadecimal\r\nAnka likes Snowy\r\nSnowy likes Chapay\r\nAnka likes Dracul\r\n843382501 58524777 503038818\r\n'], 'output': ['192994632 8\r\n']}, {'input': ['5\r\nTroll likes Chapay\r\nAnka likes Snowy\r\nAnka likes Dracul\r\nChapay likes Anka\r\nSnowy likes Troll\r\n709201888 431802832 597079932\r\n'], 'output': ['82638550 3\r\n']}, {'input': ['18\r\nCleo likes Snowy\r\nSnowy likes Hexadecimal\r\nCleo likes Hexadecimal\r\nTroll likes Dracul\r\nHexadecimal likes Snowy\r\nDracul likes Troll\r\nChapay likes Anka\r\nChapay likes Cleo\r\nTroll likes Chapay\r\nHexadecimal likes Chapay\r\nAnka likes Snowy\r\nTroll likes Snowy\r\nDracul likes Snowy\r\nDracul likes Chapay\r\nChapay likes Troll\r\nCleo likes Troll\r\nHexadecimal likes Cleo\r\nAnka likes Chapay\r\n864225278 509037060 402199775\r\n'], 'output': ['86975205 9\r\n']}, {'input': ['12\r\nCleo likes Hexadecimal\r\nTroll likes Cleo\r\nAnka likes Cleo\r\nHexadecimal likes Troll\r\nAnka likes Snowy\r\nHexadecimal likes Anka\r\nTroll likes Hexadecimal\r\nTroll likes Anka\r\nDracul likes Cleo\r\nCleo likes Troll\r\nDracul likes Troll\r\nChapay likes Anka\r\n762445890 377707484 324080158\r\n'], 'output': ['92108551 6\r\n']}, {'input': ['21\r\nChapay likes Dracul\r\nSnowy likes Chapay\r\nSnowy likes Troll\r\nCleo likes Chapay\r\nCleo likes Troll\r\nChapay likes Cleo\r\nSnowy likes Anka\r\nDracul likes Anka\r\nTroll likes Snowy\r\nSnowy likes Cleo\r\nChapay likes Hexadecimal\r\nCleo likes Anka\r\nCleo likes Snowy\r\nHexadecimal likes Cleo\r\nHexadecimal likes Snowy\r\nHexadecimal likes Anka\r\nHexadecimal likes Troll\r\nAnka likes Snowy\r\nDracul likes Troll\r\nChapay likes Anka\r\nSnowy likes Hexadecimal\r\n482557397 502108264 750230216\r\n'], 'output': ['9775434 8\r\n']}, {'input': ['6\r\nTroll likes Chapay\r\nHexadecimal likes Snowy\r\nCleo likes Dracul\r\nCleo likes Anka\r\nChapay likes Anka\r\nAnka likes Chapay\r\n758376921 432619768 578580897\r\n'], 'output': ['72980564 5\r\n']}, {'input': ['5\r\nChapay likes Cleo\r\nAnka likes Hexadecimal\r\nAnka likes Chapay\r\nCleo likes Troll\r\nAnka likes Cleo\r\n299076810 225593528 36830738\r\n'], 'output': ['62861532 3\r\n']}, {'input': ['13\r\nAnka likes Cleo\r\nCleo likes Troll\r\nChapay likes Cleo\r\nSnowy likes Troll\r\nChapay likes Anka\r\nChapay likes Snowy\r\nSnowy likes Chapay\r\nAnka likes Snowy\r\nSnowy likes Dracul\r\nCleo likes Hexadecimal\r\nDracul likes Chapay\r\nAnka likes Hexadecimal\r\nSnowy likes Cleo\r\n554338888 280967932 682619964\r\n'], 'output': ['96188303 7\r\n']}, {'input': ['17\r\nHexadecimal likes Chapay\r\nChapay likes Snowy\r\nChapay likes Troll\r\nAnka likes Hexadecimal\r\nCleo likes Troll\r\nSnowy likes Cleo\r\nCleo likes Anka\r\nCleo likes Hexadecimal\r\nAnka likes Snowy\r\nChapay likes Hexadecimal\r\nAnka likes Cleo\r\nDracul likes Snowy\r\nChapay likes Anka\r\nTroll likes Hexadecimal\r\nTroll likes Anka\r\nAnka likes Dracul\r\nHexadecimal likes Anka\r\n828886798 548024213 166661324\r\n'], 'output': ['107350782 9\r\n']}, {'input': ['2\r\nTroll likes Cleo\r\nAnka likes Cleo\r\n14344913 559182022 405430772\r\n'], 'output': ['172049094 2\r\n']}, {'input': ['22\r\nCleo likes Snowy\r\nCleo likes Troll\r\nChapay likes Dracul\r\nSnowy likes Troll\r\nDracul likes Chapay\r\nDracul likes Snowy\r\nChapay likes Cleo\r\nSnowy likes Chapay\r\nDracul likes Troll\r\nAnka likes Hexadecimal\r\nSnowy likes Anka\r\nHexadecimal likes Cleo\r\nHexadecimal likes Troll\r\nDracul likes Anka\r\nCleo likes Hexadecimal\r\nHexadecimal likes Dracul\r\nChapay likes Troll\r\nChapay likes Hexadecimal\r\nAnka likes Snowy\r\nTroll likes Hexadecimal\r\nSnowy likes Hexadecimal\r\nAnka likes Chapay\r\n458053183 602148195 994999698\r\n'], 'output': ['102639975 9\r\n']}, {'input': ['5\r\nTroll likes Dracul\r\nAnka likes Chapay\r\nCleo likes Anka\r\nChapay likes Cleo\r\nSnowy likes Hexadecimal\r\n222 400 400\r\n'], 'output': ['89 5\r\n']}, {'input': ['0\r\n2000000000 2000000000 1\r\n'], 'output': ['666666665 0\r\n']}, {'input': ['0\r\n1200000000 1200000000 1200000000\r\n'], 'output': ['200000000 0\r\n']}, {'input': ['0\r\n1 2000000000 2000000000\r\n'], 'output': ['666666665 0\r\n']}]


package main
import "fmt"
import "math"

func main(){
	var n,ans,i int64
	fmt.Scan(&n)
	x:=int64(math.Sqrt(math.Pow(4,float64(n))))
	for i=1; i<=x;i++{ans+=i}
	fmt.Println(ans)
}

Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.  Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.

The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).

NoteThe first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.

// 185A
package main

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

func main() {
	var n, x, y, m int64
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &n)
	y, x, m = 1, 2, 1000000007
	for n != 0 {
		if n%2 != 0 {
			y = (y * x) % m
		}
		x = (x * x) % m
		n = n / 2
	}
	fmt.Fprint(out, ((y*y+y)/2)%m)
	out.Flush()
}


package main

import (
  "fmt"
  "math"
  "unicode"
)

type Key struct {
  x,y float64
}
type Keyboard struct {
  m map[rune][]Key
}

func main() {
  hand := 0
  keyboard := Keyboard{}
  keyboard.m = make(map[rune][]Key)
  var m,n int
  var x float64
  var no_sense string
  fmt.Scanf("%d %d %f", &m,&n,&x)
  fmt.Scanf("%s", &no_sense)
  for i := 0; i < m; i++ {
    var keys string
    fmt.Scanf("%s", &keys)
    fmt.Scanf("%s", &no_sense)
    for pos,char:= range keys{
      keyboard.m[char] = append(keyboard.m[char],Key{float64(i)+0.5,float64(pos)+0.5,})
    }
  }
  var e,text string
  fmt.Scanf("%s", &e)
  fmt.Scanf("%s", &no_sense)
  fmt.Scanf("%s", &text)
  s_key := 'S'
  for _,char:= range text{
    v1, e1 := keyboard.m[unicode.ToLower(char)]
    if !e1{
      hand = -1
      break
    }
    if unicode.IsUpper(char) {
      one_hand := false
      v2, e2 := keyboard.m[s_key]
      if !e2{
        hand = -1
        break
      }
      for _,k1:= range v2{
        for _,k2:= range v1{
          if keyboard.e_distance(k1, k2) <= x*x{
            one_hand = true
            break
          }
        }
      }
      if !one_hand {
        hand++
      }
    }
  }
  fmt.Println(hand)
}

func (Keyboard) e_distance(k1 Key, k2 Key) float64{
  return math.Pow(k1.x - k2.x, 2) + math.Pow(k1.y - k2.y, 2)
}

Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has n rows of keys containing m keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they make lowercase letters uppercase.Vasya can press one or two keys with one hand. However, he can only press two keys if the Euclidean distance between the centers of the keys does not exceed x. The keys are considered as squares with a side equal to 1. There are no empty spaces between neighbouring keys.Vasya is a very lazy boy, that's why he tries to type with one hand as he eats chips with his other one. However, it is possible that some symbol can't be typed with one hand only, because the distance between it and the closest "Shift" key is strictly larger than x. In this case he will have to use his other hand. Having typed the symbol, Vasya returns other hand back to the chips.You are given Vasya's keyboard and the text. Count the minimum number of times Vasya will have to use the other hand.

The first line contains three integers n, m, x (1≤n,m≤30,1≤x≤50).
Next n lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly m keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys are marked with the "S" symbol.
Then follow the length of the text q (1≤q≤5·10^5). The last line contains the text T, which consists of q symbols, which are uppercase and lowercase Latin letters.

If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes).

In the first sample the symbol "A" is impossible to print as there's no "Shift" key on the keyboard.
In the second sample the symbol "e" is impossible to print as there's no such key on the keyboard.
In the fourth sample the symbols "T", "G" are impossible to print with one hand. The other letters that are on the keyboard can be printed. Those symbols come up in the text twice, thus, the answer is 2.

3 9 4
qwertyuio
asdfghjkl
SzxcvbnmS
35
TheQuIcKbRoWnFOXjummsovertHeLazYDOG

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Key struct {
  R, C int
  Ch rune
}

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

  var n, m, x int
  line, _ := reader.ReadString('\n')
  fmt.Sscanf(line, "%d %d %d", &n, &m, &x)
  keys := []Key{}
  for r := 0; r < n; r++ {
    line, _ := reader.ReadString('\n')
    s := strings.TrimSpace(line)
    for c, ch := range s {
      keys = append(keys, Key{ r, c, ch })
    }
  }
  cost := map[rune]int{}
  for i := 0; i < len(keys); i++ {
    a := keys[i]
    if a.Ch != 'S' {
      cost[a.Ch] = 1
      continue
    }
    for j := 0; j < len(keys); j++ {
      b := keys[j]
      if b.Ch != 'S' {
        ch := b.Ch - 'a' + 'A'
        if cost[ch] == 1 {
          continue
        }
        cost[ch] = 2
        d2 := (a.R - b.R)*(a.R - b.R) + (a.C - b.C)*(a.C - b.C)
        if d2 <= x*x {
          cost[ch] = 1
        }
      }
    }
  }
  reader.ReadString('\n')
  line, _ = reader.ReadString('\n')
  s := strings.TrimSpace(line)
  result := 0
  for _, ch := range s {
    c, found := cost[ch]
    if !found {
      writer.WriteString("-1\n")
      return
    }
    result += c-1
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

[{'input': ['2 2 1\r\nab\r\ncd\r\n1\r\nA\r\n'], 'output': ['-1\r\n']}, {'input': ['2 2 1\r\nab\r\ncd\r\n1\r\ne\r\n'], 'output': ['-1\r\n']}, {'input': ['2 2 1\r\nab\r\ncS\r\n5\r\nabcBA\r\n'], 'output': ['1\r\n']}, {'input': ['3 9 4\r\nqwertyuio\r\nasdfghjkl\r\nSzxcvbnmS\r\n35\r\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\r\n'], 'output': ['2\r\n']}, {'input': ['10 9 3\r\noboxlgpey\r\nyxcuwkkmp\r\njuqeflhwq\r\nsfnxqtjqS\r\nkkudcnyjl\r\nhgjlcrkjq\r\njnofqksxn\r\nqbhsnuguv\r\nlvahnifao\r\nebwnnlrwe\r\n35\r\nCodeforcesBetaRoundproblemAtestfive\r\n'], 'output': ['4\r\n']}, {'input': ['2 7 4\r\niuqtieo\r\nysxcgmS\r\n2\r\nsQ\r\n'], 'output': ['1\r\n']}, {'input': ['1 2 4\r\nbS\r\n8\r\nbBbbbBbb\r\n'], 'output': ['0\r\n']}, {'input': ['7 8 5\r\nfqiubjpm\r\nqbshcsyk\r\ncjbxpbef\r\nptwpmapx\r\nryazscbm\r\nqnvsgzrf\r\nhtardzkz\r\n9\r\nuxrmwkayy\r\n'], 'output': ['0\r\n']}, {'input': ['8 6 4\r\nefvmov\r\nkeofnw\r\npwajpe\r\nknptky\r\nSibruu\r\nrgdukk\r\nbsxosd\r\nhovgSe\r\n10\r\nECreruXmsC\r\n'], 'output': ['-1\r\n']}, {'input': ['10 3 2\r\nukk\r\neqt\r\nfex\r\nqSh\r\ntvz\r\nfjn\r\niol\r\nehd\r\nnte\r\ngyx\r\n5\r\ncgQxI\r\n'], 'output': ['-1\r\n']}, {'input': ['10 10 19\r\nowqjcaSpqn\r\nvgrhboqahn\r\nbzziocjmbu\r\npurqsmiSop\r\nxcsifctjhy\r\nycyytwoamk\r\nrnjfxsxowl\r\nnkgcywcdff\r\nbazljrisqv\r\nkcakigSekq\r\n100\r\nzewpATtssQVicNrlRrcoifTutTAfFMUEfDFKoNyQbSrSYxTGMadNkRpmJvoEqUsqPYgAdQreaUrwDKMNFWiwdRRCcJBPorfMVMoK\r\n'], 'output': ['0\r\n']}, {'input': ['10 10 26\r\nwxmssptheb\r\nzpxbxsyxsy\r\nqbjkpaywqp\r\nfwhnuzjcgq\r\nycgaanzedz\r\njrycrbzqfs\r\ngswwakybus\r\nfhtxhljedz\r\noSepmyjosv\r\ndwviycevdn\r\n100\r\nyapwUfnyPzgZyFvAHGKWVbXQHkuhJDoUTvCAtdMMCQmKchxKkilUTECOqYJFUSHPqKiRKhDXZgHxwApDWlShdwakmVCgaeKCLOMX\r\n'], 'output': ['0\r\n']}, {'input': ['10 10 3\r\nrvouufmnqu\r\nbyukrnmnhr\r\nzjggwxgvkz\r\ntcagkSitiw\r\nhryajgtpwc\r\njragfhqoks\r\nkgroxxkuvp\r\nbpgrkqiyns\r\njbuhjjkziw\r\nomjmbaggsw\r\n100\r\nCpRzrPqPngYvrVJFCWRPMRwrpXcbtiwfoFcAkRaNjzpMMKOQAzBxSrxGbIHaYgmSqhhxhZTmhFttKnhFzRfKxYXshUZRvtKJIzZq\r\n'], 'output': ['12\r\n']}, {'input': ['10 10 2\r\nfriuxvShvg\r\nerslojqtgu\r\nzeqsmdewry\r\nwvhbeeyeSu\r\ngkofbjaavr\r\ntwkcdxugps\r\nnzlylSmafu\r\nstamkpxnzt\r\nuwxwximkrm\r\nmzxyboazbl\r\n100\r\nmRIfAtrLKmztpVkAmojDCiIgseBwlUilBIixDQhqNhNAqVLLIobuCIretLdSvixNNdCiouFMXtwHZFlObCeaygmIiFBfaCirbmCa\r\n'], 'output': ['19\r\n']}, {'input': ['10 10 2\r\nbddahSqkmk\r\npxbocxayjs\r\nottvdazstk\r\nlaxuidqlqb\r\nkfjwdpdfat\r\nxlipuubkgv\r\niqyomzfktm\r\niwbgidmwyu\r\nrngqkeupsf\r\nbqndtekryw\r\n100\r\nMNQgWFLhHycqwjSsbTkbgMYAIHFYARRmOsinYMFjOxxnLjiKfeiBbMpoeTdzUMORPaAxRNfvdAPFaKkPdxdAjjJgGCxkDzmSasqq\r\n'], 'output': ['37\r\n']}, {'input': ['10 10 2\r\nnxcwdrsmrv\r\nSyjahsosvp\r\nvkrqbxhgbv\r\nwkxywavtnn\r\nepkyoviqbi\r\nsfmpvhuwwq\r\nnlsostrotx\r\ntcdguorhny\r\nimixrqzSdu\r\nxzhdhdwibt\r\n100\r\nUzzaWiRFYbAqxIDMrRBBDoGQhSzSqSLEddAiJsZcxbemdeuddamNYdWOvzlYSCuHIRpnuxdNxAsnZMiLXBYwnrMcrbNeLrUYhZOB\r\n'], 'output': ['17\r\n']}, {'input': ['10 10 23\r\nhtyvouoiqi\r\nvySvsfqadv\r\nxvqyqjyutq\r\npjcrrphzbk\r\nhlqfyoqfmo\r\nezcSwleoew\r\nxkwqrajxyg\r\nngSiftgoso\r\njyndgicccr\r\nlgjvokydhp\r\n100\r\nJzVVfotldIRcyjhTNRcFlTxFeZKRwavZxYcvdDOQyUvTmryFRuRBcRvmscegtspkPuchqlFEKbrfpTOSlSFOARsbbvSenMwNmaRj\r\n'], 'output': ['0\r\n']}, {'input': ['10 10 7\r\nifcwalsdbj\r\njpykymrbei\r\nrylzgkyefh\r\noilvvexpjp\r\niptgodpfim\r\ndSrqejaixu\r\npksxlsniwa\r\nmoSenxtfbc\r\noqssptcenz\r\nqdhmouvyas\r\n100\r\nqtMDVUXJpSEFgPsLKyRJVRbfVoYaCKJDnQDLFVngVjSPzzVyMnMyuyahMRiBJuNhKtgpVqvukUolLvYEmidvXotgQUJukYwIweUW\r\n'], 'output': ['0\r\n']}, {'input': ['10 10 1\r\nmdxafehbkr\r\nyuhenybjps\r\ntvfwmiwcoh\r\njmzrepzjvx\r\nnqyorkSnuk\r\ntSmztmwidv\r\ncmmajnlqrw\r\nfiqewpdwax\r\nuesmkdcplt\r\nlgkomdcqbo\r\n100\r\nmcEQmAvFqKYMXLHQUDeIulkmAMRkIUtbKihTFJwJYQfcAelNrZWSAwHunwZTrdHaRWokgCyLqbubOpEHuZiDVoFHjvkMSoBPyGOI\r\n'], 'output': ['39\r\n']}, {'input': ['10 10 2\r\nnhfafdwqhh\r\neyvitpcthk\r\nrpiotuoqzh\r\nnxxnhuaxee\r\nyevrtirzwf\r\nkbtSsamyel\r\nfeenjvxsmo\r\nkqpenxjmde\r\nlqsamthlwp\r\njdyyqsbtbk\r\n100\r\nUHucxPWDaKonVpXEctuqYUAQnrFEZaTYxhoacNbHIMevlbDejXjitEzyVrTfcfBHWRMdJvaTkbkqccyHjtzpTbKmRAXwlXCtFKNX\r\n'], 'output': ['29\r\n']}, {'input': ['10 10 1\r\nsufnxxpdnx\r\nvttibpllhv\r\nlvbrjmfdjx\r\ngmtexvrnfh\r\nygsqrsSwxd\r\nkxbbjxgbzs\r\nedutwocmzd\r\nfebjgknyai\r\nvcvquagvrs\r\ndrdoarhgoc\r\n100\r\nZoZJXhUWyaLgBTpgbznABKHuyFcKzJmGaMhoKkKfyOGacLwBspaKtAEdwMZJFYiZUFNDxdDIDgKSCRvsbGUOXRqalbpuEqkduYpW\r\n'], 'output': ['44\r\n']}, {'input': ['10 10 2\r\ncstcrltzsl\r\nblotmquzvj\r\nuiitiytlgx\r\nwumpfdaprd\r\ntfxohqpztn\r\nvfrpsccddo\r\nneegusrkxw\r\niijfjozqjq\r\nioegbvuhew\r\npjjpqdxvqu\r\n100\r\nkPCBONfZLkeXzWVuSgvinPENazcnRoBcUHXwRzPyvNIiDlDSeKOYmiUmjooXuzTCtIRxKDAYeTLgjsenxHoymVazMALUADQpjVjV\r\n'], 'output': ['-1\r\n']}, {'input': ['10 10 1\r\nqztnjglyrc\r\nnukswgzajl\r\nqnpbdwjvbb\r\nliiakzcrlz\r\nnolwfzzvxd\r\nmqvhiySttx\r\nqwuizSjuto\r\nqbgwiwjukx\r\nkomyvblgkc\r\ntkzlxzgsru\r\n100\r\nYUzTZDzLFkMUhjQWbwljJCRyZGFzgJcozvROiwPktRGxkMKiPyiTvhDrtusPYhMgVAOFIjAvlpzcrUvrMrMbhkpUiyAytKfYOGTF\r\n'], 'output': ['37\r\n']}, {'input': ['10 10 1\r\nmgziiihbkq\r\niobjknuogh\r\nvntwahSopu\r\nsjsxjpaqvm\r\nwqgrodizst\r\nselzugktoi\r\nvbhfzvgjfn\r\nliqlfdcjhf\r\nbpbtpmimxb\r\npksfiydpfw\r\n100\r\nwAVZXEhKTuajdCauVTIwgnfbxWuUSmtXkjHZtNVcfTsiSAPLdpdEFdTJLZRjptUcRhAmrNjKMXmuDGatAQoaIpbddnzRGHsJrhoq\r\n'], 'output': ['39\r\n']}, {'input': ['10 10 2\r\nshbqxycvfm\r\notydudkttw\r\nqhatsxsngz\r\nixvyujtyjc\r\nsbvqhnjbak\r\neggcguuuka\r\nxcydfgjzeb\r\nytpdkcdrsq\r\nefqlpywggu\r\nfcnfrhnouo\r\n100\r\nHPqtuVckdUOhsnuhnbpekWvWKUnAEaOCihpeEvmaOKOPcIZiMixGJGEuXAaOxuUNyrIesmldLEqGnvyDKPDvFkCbRebCORHmUgeV\r\n'], 'output': ['-1\r\n']}, {'input': ['1 1 50\r\nS\r\n29\r\nargjhoaiogjiSjqfhjksdvjkSvcvn\r\n'], 'output': ['-1\r\n']}, {'input': ['1 1 50\r\nS\r\n1\r\nS\r\n'], 'output': ['-1\r\n']}, {'input': ['1 1 50\r\na\r\n29\r\nargjhoaiogjiSjqfhjksdvjkSvcvn\r\n'], 'output': ['-1\r\n']}, {'input': ['1 1 50\r\nz\r\n29\r\nargjhoaiogjiSjqfhjksdvjkSvcvn\r\n'], 'output': ['-1\r\n']}, {'input': ['2 1 2\r\nS\r\nc\r\n4\r\nCSSA\r\n'], 'output': ['-1\r\n']}]


// 92B
package main

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

func main() {
	var s string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &s)
	var a, b, c int
	for i := 1; i < len(s); i++ {
		if s[i] == 1 {
			a = i
			b = c
		} else {
			c++
			if a > 0 {
				b += a*2 - 1
			}
		}
	}
	fmt.Println(b + c)
}

Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.Fangy takes some positive integer x and wants to get a number one from it. While x is not equal to 1, Fangy repeats the following action: if x is odd, then he adds 1 to it, otherwise he divides x by 2. Fangy knows that for any positive integer number the process ends in finite time.How many actions should Fangy perform to get a number one from number x?

The first line contains a positive integer x in a binary system. It is guaranteed that the first digit of x is different from a zero and the number of its digits does not exceed 10^6.

Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1.

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

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

  line, _ := reader.ReadString('\n')
  s := strings.TrimSpace(line)
  count := len(s)-1
  for i := len(s)-1; i > 0; i-- {
    if s[i] == '1' {
      count += 2;
      for seek := i-1; seek > 0; seek-- {
        if s[seek] == '0' {
          count++
        }
      }
      break
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", count))
}


package main

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

const MAX_NM = 100
const MAX_CHAR = int('z')

func main() {
	reader := NewStdReader(os.Stdin)

	n, m := reader.ReadInt(), reader.ReadInt()

	countRow := [MAX_NM][MAX_CHAR]byte{}
	countCol := [MAX_NM][MAX_CHAR]byte{}

	table := [MAX_NM][MAX_NM]byte{}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			c := reader.ReadChar()
			table[i][j] = c
			countRow[i][c]++
			countCol[j][c]++
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			c := table[i][j]

			if countRow[i][c] == 1 && countCol[j][c] == 1 {
				fmt.Print(string(c))
			}
		}
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadChar() byte {
	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}

		if b >= 'a' && b <= 'z' {
			return b
		}
	}

	return 0
}

An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.You are suggested to solve an African crossword and print the word encrypted there.

The first line contains two integers n and m (1 ≤ n, m ≤ 100). Next n lines contain m lowercase Latin letters each. That is the crossword grid.

Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, m := getI(), getI()
  mark := make([][]bool, n)
  rows := make([]string, n)
  for r := range rows {
    rows[r] = getS()
    mark[r] = make([]bool, m)
  }
  for r := range rows {
    seen := map[byte]int{}
    for c := 0; c < m; c++ {
      ch := rows[r][c]
      if seen[ch] != 0 {
        mark[r][seen[ch]-1] = true
        mark[r][c] = true
      } else {
        seen[ch] = c+1
      }
    }
  }
  for c := 0; c < m; c++ {
    seen := map[byte]int{}
    for r := range rows {
      ch := rows[r][c]
      if seen[ch] != 0 {
        mark[seen[ch]-1][c] = true
        mark[r][c] = true
      } else {
        seen[ch] = r+1
      }
    }
  }
  chars := []byte{}
  for r := range rows {
    for c := 0; c < m; c++ {
      if !mark[r][c] {
        chars = append(chars, rows[r][c])
      }
    }
  }
  writer.WriteString(fmt.Sprintf("%s\n", string(chars)))
}

[{'input': '3 3\r\ncba\r\nbcd\r\ncbc\r\n', 'output': ['abcd']}, {'input': '5 5\r\nfcofd\r\nooedo\r\nafaoa\r\nrdcdf\r\neofsf\r\n', 'output': ['codeforces']}, {'input': '4 4\r\nusah\r\nusha\r\nhasu\r\nsuha\r\n', 'output': ['ahhasusu']}, {'input': '7 5\r\naabcd\r\neffgh\r\niijkk\r\nlmnoo\r\npqqrs\r\nttuvw\r\nxxyyz\r\n', 'output': ['bcdeghjlmnprsuvwz']}, {'input': '10 10\r\naaaaaaaaaa\r\nbccceeeeee\r\ncdfffffffe\r\ncdfiiiiile\r\ncdfjjjjile\r\ndddddddile\r\nedfkkkkile\r\nedddddddde\r\ngggggggggg\r\nhhhhhhhhhe\r\n', 'output': ['b']}, {'input': '15 3\r\njhg\r\njkn\r\njui\r\nfth\r\noij\r\nyuf\r\nyfb\r\nugd\r\nhgd\r\noih\r\nhvc\r\nugg\r\nyvv\r\ntdg\r\nhgf\r\n', 'output': ['hkniftjfbctd']}, {'input': '17 19\r\nbmzbmweyydiadtlcoue\r\ngmdbyfwurpwbpuvhifn\r\nuapwyndmhtqvkgkbhty\r\ntszotwflegsjzzszfwt\r\nzfpnscguemwrczqxyci\r\nvdqnkypnxnnpmuduhzn\r\noaquudhavrncwfwujpc\r\nmiggjmcmkkbnjfeodxk\r\ngjgwxtrxingiqquhuwq\r\nhdswxxrxuzzfhkplwun\r\nfagppcoildagktgdarv\r\neusjuqfistulgbglwmf\r\ngzrnyxryetwzhlnfewc\r\nzmnoozlqatugmdjwgzc\r\nfabbkoxyjxkatjmpprs\r\nwkdkobdagwdwxsufees\r\nrvncbszcepigpbzuzoo\r\n', 'output': ['lcorviunqvgblgjfsgmrqxyivyxodhvrjpicbneodxjtfkpolvejqmllqadjwotmbgxrvs']}, {'input': '1 1\r\na\r\n', 'output': ['a']}, {'input': '2 2\r\nzx\r\nxz\r\n', 'output': ['zxxz']}, {'input': '1 2\r\nfg\r\n', 'output': ['fg']}, {'input': '2 1\r\nh\r\nj\r\n', 'output': ['hj']}, {'input': '1 3\r\niji\r\n', 'output': ['j']}, {'input': '3 1\r\nk\r\np\r\nk\r\n', 'output': ['p']}, {'input': '2 3\r\nmhw\r\nbfq\r\n', 'output': ['mhwbfq']}, {'input': '3 2\r\nxe\r\ner\r\nwb\r\n', 'output': ['xeerwb']}, {'input': '3 7\r\nnutuvjg\r\ntgqutfn\r\nyfjeiot\r\n', 'output': ['ntvjggqfnyfjeiot']}, {'input': '5 4\r\nuzvs\r\namfz\r\nwypl\r\nxizp\r\nfhmf\r\n', 'output': ['uzvsamfzwyplxizphm']}, {'input': '8 9\r\ntjqrtgrem\r\nrwjcfuoey\r\nywrjgpzca\r\nwabzggojv\r\najqmmcclh\r\nozilebskd\r\nqmgnbmtcq\r\nwakptzkjr\r\n', 'output': ['mrjcfuyyrjpzabzvalhozilebskdgnbtpzr']}, {'input': '9 3\r\njel\r\njws\r\ntab\r\nvyo\r\nkgm\r\npls\r\nabq\r\nbjx\r\nljt\r\n', 'output': ['elwtabvyokgmplabqbxlt']}, {'input': '7 6\r\neklgxi\r\nxmpzgf\r\nxvwcmr\r\nrqssed\r\nouiqpt\r\ndueiok\r\nbbuorv\r\n', 'output': ['eklgximpzgfvwcmrrqedoiqptdeiokuorv']}, {'input': '14 27\r\npzoshpvvjdpmwfoeojapmkxjrnk\r\nitoojpcorxjdxrwyewtmmlhjxhx\r\ndoyopbwusgsmephixzcilxpskxh\r\nygpvepeuxjbnezdrnjfwdhjwjka\r\nrfjlbypoalbtjwrpjxzenmeipfg\r\nkhjhrtktcnajrnbefhpavxxfnlx\r\nvwlwumqpfegjgvoezevqsolaqhh\r\npdrvrtzqsoujqfeitkqgtxwckrl\r\nxtepjflcxcrfomhqimhimnzfxzg\r\nwhkfkfvvjwkmwhfgeovwowshyhw\r\nolchgmhiehumivswgtfyhqfagbp\r\ntdudrkttpkryvaiepsijuejqvmq\r\nmuratfqqdbfpefmhjzercortroh\r\nwxkebkzchupxumfizftgqvuwgau\r\n', 'output': ['zshdanicdyldybwgclygzrhkayatwxznmicbpvlupfsoewcleploqngsyolceswtyqbpyasmuadbpcehqva']}, {'input': '1 100\r\nysijllpanprcrrtvokqmmupuptvawhvnekeybdkzqaduotmkfwybqvytkbjfzyqztmxckizheorvkhtyoohbswcmhknyzlgxordu\r\n', 'output': ['g']}, {'input': '2 100\r\ngplwoaggwuxzutpwnmxhotbexntzmitmcvnvmuxknwvcrnsagvdojdgaccfbheqojgcqievijxapvepwqolmnjqsbejtnkaifstp\r\noictcmphxbrylaarcwpruiastazvmfhlcgticvwhpxyiiqokxcjgwlnfykkqdsfmrfaedzchrfzlwdclqjxvidhomhxqnlmuoowg\r\n', 'output': ['rbe']}, {'input': '3 100\r\nonmhsoxoexfwavmamoecptondioxdjsoxfuqxkjviqnjukwqjwfadnohueaxrkreycicgxpmogijgejxsprwiweyvwembluwwqhj\r\nuofldyjyuhzgmkeurawgsrburovdppzjiyddpzxslhyesvmuwlgdjvzjqqcpubfgxliulyvxxloqyhxspoxvhllbrajlommpghlv\r\nvdohhghjlvihrzmwskxfatoodupmnouwyyfarhihxpdnbwrvrysrpxxptdidpqabwbfnxhiziiiqtozqjtnitgepxjxosspsjldo\r\n', 'output': ['blkck']}, {'input': '100 1\r\na\r\nm\r\nn\r\nh\r\na\r\nx\r\nt\r\na\r\no\r\np\r\nj\r\nz\r\nr\r\nk\r\nq\r\nl\r\nb\r\nr\r\no\r\ni\r\ny\r\ni\r\np\r\ni\r\nt\r\nn\r\nd\r\nc\r\nz\r\np\r\nu\r\nn\r\nw\r\ny\r\ng\r\ns\r\nt\r\nm\r\nz\r\ne\r\nv\r\ng\r\ny\r\nj\r\nd\r\nz\r\ny\r\na\r\nn\r\nx\r\nk\r\nd\r\nq\r\nn\r\nv\r\ng\r\nk\r\ni\r\nk\r\nf\r\na\r\nb\r\nw\r\no\r\nu\r\nw\r\nk\r\nk\r\nb\r\nz\r\nu\r\ni\r\nu\r\nv\r\ng\r\nv\r\nx\r\ng\r\np\r\ni\r\nz\r\ns\r\nv\r\nq\r\ns\r\nb\r\nw\r\ne\r\np\r\nk\r\nt\r\np\r\nd\r\nr\r\ng\r\nd\r\nk\r\nm\r\nf\r\nd\r\n', 'output': ['hlc']}, {'input': '100 2\r\nhd\r\ngx\r\nmz\r\nbq\r\nof\r\nst\r\nzc\r\ndg\r\nth\r\nba\r\new\r\nbw\r\noc\r\now\r\nvh\r\nqp\r\nin\r\neh\r\npj\r\nat\r\nnn\r\nbr\r\nij\r\nco\r\nlv\r\nsa\r\ntb\r\nbl\r\nsr\r\nxa\r\nbz\r\nrp\r\nsz\r\noi\r\nec\r\npw\r\nhf\r\njm\r\nwu\r\nhq\r\nra\r\npv\r\ntc\r\ngv\r\nik\r\nux\r\ntz\r\nbf\r\nty\r\ndk\r\nwo\r\nor\r\nza\r\nkv\r\nqt\r\nfa\r\njy\r\nbk\r\nuv\r\ngk\r\ncz\r\nds\r\nie\r\noq\r\nmf\r\nxn\r\nql\r\nxs\r\nfb\r\niv\r\ncj\r\nkn\r\nns\r\nlg\r\nji\r\nha\r\naj\r\ndg\r\nfj\r\nut\r\nsg\r\nju\r\noc\r\nov\r\nhe\r\nnw\r\nbl\r\nlp\r\nbx\r\nnm\r\nyq\r\ncw\r\nov\r\nxk\r\npg\r\noh\r\npl\r\nuo\r\ngf\r\nul\r\n', 'output': ['dvy']}, {'input': '100 3\r\nruy\r\nmye\r\njgp\r\nscn\r\nktq\r\nalx\r\nmvk\r\nlpm\r\nkry\r\norb\r\nmpu\r\nzcv\r\nlge\r\nkft\r\ndzp\r\ntfb\r\nhqz\r\nuur\r\nhry\r\nzjx\r\ncuo\r\nqqc\r\ntih\r\nenj\r\nvnp\r\nbwi\r\nzzh\r\nhkc\r\nwdr\r\nldh\r\nvel\r\nizj\r\nfhb\r\nqrn\r\nqpp\r\nvzs\r\nlhg\r\nkee\r\nlbq\r\nzhy\r\nwcl\r\nyaa\r\nton\r\nfly\r\nkyw\r\nept\r\ngwq\r\ncoe\r\nopd\r\neez\r\nnmx\r\nnjg\r\nwhy\r\nvel\r\nafq\r\nnbq\r\nulx\r\noxs\r\nbbo\r\nyhx\r\nfmz\r\nnrg\r\nnfm\r\njek\r\nbeu\r\ntya\r\nxgs\r\nsgg\r\nnkq\r\nbbv\r\nwkd\r\ntns\r\nfdt\r\neox\r\nobc\r\neab\r\nkkj\r\noub\r\ngji\r\nrht\r\nozv\r\nysk\r\nsbt\r\nflf\r\npbu\r\nlxb\r\npzs\r\nrzh\r\ncea\r\nkmi\r\nuea\r\nncc\r\nzng\r\nvkn\r\njhn\r\njqw\r\nlqc\r\nmbt\r\nlov\r\ngam\r\n', 'output': ['tvdiixs']}]


package main

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

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

var (
	MOD = 1000000007
)

var (
	n, m int
	a    [100][30]int
	s    [100]string
)

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}

	for i := 0; i < n; i++ {
		for j := 0; j < len(s[i]); j++ {
			a[j][s[i][j]-65] = 1
		}

	}

	ans := 1
	for i := 0; i < m; i++ {
		cnt := 0
		for j := 0; j < 26; j++ {
			cnt = cnt + a[i][j]

		}
		//writeln(cnt)
		ans = (ans * cnt) % MOD
	}

	writeln(ans)

}

func read(num ...*int) {
	for _, value := range num {
		in.Scan()
		*value, _ = strconv.Atoi(in.Text())
	}
}

func writeln(num ...int) {
	for _, value := range num {
		str := strconv.Itoa(value)
		out.WriteString(str)
	}
	out.WriteString("\n")
}

One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≤ i < j ≤ n, 1 ≤ k ≤ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).

The first input line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.

Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).

NoteIn the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".

package main
import "fmt"

func main(){
	var n,m,i,u,count,ans int64
	fmt.Scan(&n,&m)
	s:=make([]string,n)
	for i=0; i<n; i++{ fmt.Scan(&s[i]) }
	ans = 1
	for i=0; i<m; i++{
		var dif [26]int
		count=0
		for u=0; u<n ; u++{
			x:= s[u][i]-'A'
			if dif[x] == 0{ dif[x]++}
		}
		for j:=0; j<26; j++{
			count+= int64(dif[j])
		}
		ans= (ans*count)%1000000007
	}
	fmt.Println(ans)
}

[{'input': '2 3\r\nAAB\r\nBAA\r\n', 'output': ['4\r\n']}, {'input': '4 5\r\nABABA\r\nBCGDG\r\nAAAAA\r\nYABSA\r\n', 'output': ['216\r\n']}, {'input': '1 1\r\nE\r\n', 'output': ['1\r\n']}, {'input': '2 2\r\nNS\r\nPD\r\n', 'output': ['4\r\n']}, {'input': '3 4\r\nPJKD\r\nNFJX\r\nFGFK\r\n', 'output': ['81\r\n']}, {'input': '4 5\r\nSXFMY\r\nATHLM\r\nKDDQW\r\nZWGDS\r\n', 'output': ['1024\r\n']}, {'input': '20 14\r\nJNFKBBBJYZHWQE\r\nLBOKZCPFNKDBJY\r\nXKNWGHQHIOXUPF\r\nDDNRUKVUGHWMXW\r\nMTIZFNAAFEAPHX\r\nIXBQOOHEULZYHU\r\nMRCSREUEOOMUUN\r\nHJTSQWKUFYZDQU\r\nGMCMUZCOPRVEIQ\r\nXBKKGGJECOBLTH\r\nXXHTLXCNJZJUAF\r\nVLJRKXXXWMTPKZ\r\nPTYMNPTBBCWKAD\r\nQYJGOBUBHMEDYE\r\nGTKUUVVNKAHTUI\r\nZNKXYZPCYLBZFP\r\nQCBLJTRMBDWNNE\r\nTDOKJOBKEOVNLZ\r\nFKZUITYAFJOQIM\r\nUWQNSGLXEEIRWF\r\n', 'output': ['515139391\r\n']}, {'input': '5 14\r\nAQRXUQQNSKZPGC\r\nDTTKSPFGGVCLPT\r\nVLZQWWESCHDTAZ\r\nCOKOWDWDRUOMHP\r\nXDTRBIZTTCIDGS\r\n', 'output': ['124999979\r\n']}, {'input': '9 23\r\nOILBYKHRGMPENVFNHLSIUOW\r\nLPJFHTUQUINAALRDGLSQUXR\r\nLYYJJEBNZATAFQWTDZSPUNZ\r\nHSJPIQKKWWERJZIEMLCZUKI\r\nOJYIEYDGPFWRHCMISJCCUEM\r\nLMGKZVFYIVDRTIHBWPCNUTG\r\nUBGGNCITVHAIPKXCLTSAULQ\r\nOWSAWUOXQDBSXXBHTLSXUVD\r\nUGQTIZQPBGMASRQPVPSFUWK\r\n', 'output': ['454717784\r\n']}, {'input': '25 4\r\nLVKG\r\nMICU\r\nZHKW\r\nLFGG\r\nOWQO\r\nLCQG\r\nLVXU\r\nOUKB\r\nLNQX\r\nZJTO\r\nOOQX\r\nLVQP\r\nMFQB\r\nMRQV\r\nOIQH\r\nOPXX\r\nXFKU\r\nFCQB\r\nZPKH\r\nLVCH\r\nNFCU\r\nOVQW\r\nOZKU\r\nLFHX\r\nLPXO\r\n', 'output': ['5733\r\n']}, {'input': '30 10\r\nUTNTGOKZYJ\r\nQHOUHNYZVW\r\nLTVGHJRZVW\r\nMZHYHOLZYJ\r\nERYEUEPZYE\r\nUZDBFTURYJ\r\nRVSMQTIZGW\r\nWDJQHMIRYY\r\nKCORHQPZYE\r\nRRPLFOZZVY\r\nJTXMFNNNYJ\r\nMVTGGOZZVV\r\nEHAFFNUZVF\r\nLBRNWJZNYE\r\nJVMOHTPZYJ\r\nWTARFJLZVV\r\nLVJCWOURVW\r\nLCLQFJYRVV\r\nQVBVGNJRYF\r\nNTZGHOLRYE\r\nMGQKHOUPYJ\r\nRRSSBXPZYJ\r\nRYCRGTLZYJ\r\nJRDEGNKRVW\r\nRZKFGHYRVG\r\nMDJBFNIZYG\r\nMPLWHXIZYE\r\nSRZMHMURVE\r\nMTEBBMRZYJ\r\nJPJIFOLZYM\r\n', 'output': ['919913906\r\n']}, {'input': '40 7\r\nPNTVVER\r\nPAHTQDR\r\nRXMJVAS\r\nVIQNLYC\r\nILPUSVX\r\nYJOXQDJ\r\nSEFODTO\r\nOTJMREL\r\nLIQRZGD\r\nLBJJPOR\r\nRUTYHQO\r\nRIWEPBD\r\nKQUMFIB\r\nISTRRYH\r\nXBTOTGK\r\nRFQODEY\r\nHDSTZTP\r\nYCXFAGL\r\nAREGRFU\r\nLELZUYU\r\nGVABDKH\r\nFJAMMME\r\nACVULXE\r\nJHVPJAS\r\nAAQNMBX\r\nJJGUCXG\r\nOQATILQ\r\nNEOSHJM\r\nHFLWOFM\r\nICYEQHY\r\nFACGLYP\r\nPLLXJEQ\r\nDCHXYPB\r\nAGDDZJJ\r\nLSQRXTN\r\nHDQZXIY\r\nNAHDDWW\r\nQCMXRQN\r\nFDUDSZO\r\nHKBEVTW\r\n', 'output': ['206575993\r\n']}, {'input': '2 2\r\nAA\r\nBB\r\n', 'output': ['4\r\n']}, {'input': '1 10\r\nAAAAAAAAAA\r\n', 'output': ['1\r\n']}, {'input': '2 8\r\nAAAAAAAA\r\nBBBBBBBB\r\n', 'output': ['256\r\n']}, {'input': '10 10\r\nAAAAAAAAAA\r\nBBBBBBBBBB\r\nCCCCCCCCCC\r\nDDDDDDDDDD\r\nAAAAAAAAAA\r\nBBBBBBBBBB\r\nCCCCCCCCCC\r\nDDDDDDDDDD\r\nAAAAAAAAAA\r\nBBBBBBBBBB\r\n', 'output': ['1048576\r\n']}, {'input': '1 20\r\nAAAAAAAAAAAAAAAAAAAA\r\n', 'output': ['1\r\n']}, {'input': '20 1\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\n', 'output': ['7\r\n']}, {'input': '5 60\r\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\r\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\r\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\r\nEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\r\n', 'output': ['449874206\r\n']}, {'input': '50 4\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGGGG\r\nHHHH\r\nIIII\r\nJJJJ\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGGGG\r\nHHHH\r\nIIII\r\nJJJJ\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGGGG\r\nHHHH\r\nIIII\r\nJJJJ\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGGGG\r\nHHHH\r\nIIII\r\nJJJJ\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGGGG\r\nHHHH\r\nIIII\r\nJJJJ\r\n', 'output': ['10000\r\n']}, {'input': '1 100\r\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n', 'output': ['1\r\n']}, {'input': '100 1\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\n', 'output': ['1\r\n']}, {'input': '100 1\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\n', 'output': ['2\r\n']}, {'input': '100 1\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\n', 'output': ['14\r\n']}, {'input': '100 1\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\nW\r\nX\r\nY\r\nZ\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\nW\r\nX\r\nY\r\nZ\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\nW\r\nX\r\nY\r\nZ\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\n', 'output': ['26\r\n']}]


package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: bufio.NewWriter(out)}
}

func (io *IO) ReadInt64() int64 {
	var res int64
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadInt() int {
	var res int
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt64() (int64, int64) {
	var a, b int64
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) []int64 {
	var t int64
	res := make([]int64, 0, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	fmt.Fscanf(io.in, "\n")
	return res
}

type log struct {
	s string
	i int
}

var errOutOfRange = errors.New("out of range")

func (l *log) left() (bool, error) {
	if l.i >= len(l.s) {
		return false, errOutOfRange
	}
	c := l.s[l.i]
	l.i++
	return c == '0', nil
}

func mergeSort(a []int, l *log) error {
	if len(a) == 1 {
		return nil
	}

	err := mergeSort(a[:len(a)/2], l)
	if err != nil {
		return err
	}

	err = mergeSort(a[len(a)/2:], l)
	if err != nil {
		return err
	}

	b := make([]int, 0, len(a))
	i, j := 0, len(a)/2

	for i < len(a) / 2 && j < len(a) {
		left, err := l.left()
		if err != nil {
			return err
		}

		if left {
			b = append(b, a[i])
			i++
		} else {
			b = append(b, a[j])
			j++
		}
	}

	for i < len(a) / 2 {
		b = append(b, a[i])
		i++
	}

	for j < len(a) {
		b = append(b, a[j])
		j++
	}

	for i := range b {
		a[i] = b[i]
	}
	return nil
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	s := io.ReadString()

	aa := make([]int, 0)

	for i := 0; i < 1000; i++ {
		aa = append(aa, i)

		a := make([]int, len(aa))
		copy(a, aa)

		l := log{s, 0}
		err := mergeSort(a, &l)
		if err != nil {
			continue
		}

		if _, err = l.left(); err != nil {
			b := make([]int, len(a))

			for i, v := range a {
				b[v] = i + 1
			}

			fmt.Println(len(a))
			for _, v := range b {
				fmt.Printf("%d ", v)
			}
			return
		}
	}
}

Рассмотрим следующий код сортировки слиянием на языке Python: def sort(a):  n = len(a)  b = [0 for i in range(n)]  log = []  def mergeSort(l, r):    if r - l <;= 1:      return    m = (l + r) >> 1    mergeSort(l, m)    mergeSort(m, r)    i, j, k = l, m, l    while i <; m and j <; r:      if a[i] <; a[j]:        log.append('0')        b[k] = a[i]        i += 1      else:        log.append('1')        b[k] = a[j]        j += 1      k += 1    while i <; m:      b[k] = a[i]      i += 1      k += 1    while j <; r:      b[k] = a[j]      j += 1      k += 1    for p in range(l, r):      a[p] = b[p]  mergeSort(0, n)  return "".join(log)Как можно заметить, этот код использует логирование — важнейший инструмент разработки.Старший разработчик ВКонтакте Вася сгенерировал перестановку $$$a$$$ (массив из $$$n$$$ различных целых чисел от $$$1$$$ до $$$n$$$), дал её на вход функции sort и получил на выходе строку $$$s$$$. На следующий день строку $$$s$$$ Вася нашёл, а перестановка $$$a$$$ потерялась. Вася хочет восстановить любую перестановку $$$a$$$ такую, что вызов функции sort от неё даст ту же строку $$$s$$$. Помогите ему!

Ввод содержит непустую строку $$$s$$$, состоящую из символов 0 и 1.  В этой версии задачи для любого теста существует перестановка длины $$$16$$$, удовлетворяющая условию. Тем не менее, ваш ответ может иметь любую длину, в том числе отличную от $$$16$$$.

В первой строке выведите целое число $$$n$$$ — длину перестановки. Во второй строке выведите $$$n$$$ различных целых чисел $$$a_0, a_1, \ldots, a_{n-1}$$$ ($$$1 \le a_i \le n$$$) — элементы перестановки. Если существует несколько вариантов ответа, выведите любой из них.

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: bufio.NewWriter(out)}
}

func (io *IO) ReadInt64() int64 {
	var res int64
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadInt() int {
	var res int
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt64() (int64, int64) {
	var a, b int64
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) []int64 {
	var t int64
	res := make([]int64, 0, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	fmt.Fscanf(io.in, "\n")
	return res
}

type log struct {
	s string
	i int
}

var errOutOfRange = errors.New("out of range")

func (l *log) left() (bool, error) {
	if l.i >= len(l.s) {
		return false, errOutOfRange
	}
	c := l.s[l.i]
	l.i++
	return c == '0', nil
}

func mergeSort(a []int, l *log) error {
	if len(a) == 1 {
		return nil
	}

	err := mergeSort(a[:len(a)/2], l)
	if err != nil {
		return err
	}

	err = mergeSort(a[len(a)/2:], l)
	if err != nil {
		return err
	}

	b := make([]int, 0, len(a))
	i, j := 0, len(a)/2

	for i < len(a)/2 && j < len(a) {
		left, err := l.left()
		if err != nil {
			return err
		}

		if left {
			b = append(b, a[i])
			i++
		} else {
			b = append(b, a[j])
			j++
		}
	}

	for i < len(a)/2 {
		b = append(b, a[i])
		i++
	}

	for j < len(a) {
		b = append(b, a[j])
		j++
	}

	for i := range b {
		a[i] = b[i]
	}
	return nil
}

func doSomething(n int, s string) int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = i
	}

	l := log{s, 0}
	err := mergeSort(a, &l)
	if err != nil {
		return 1000000000
	}

	return len(l.s) - l.i
}

func doSomethingWithPrint(n int, s string) int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = i
	}

	l := log{s, 0}
	err := mergeSort(a, &l)
	if err != nil {
		return 1000000000
	}

	if _, err = l.left(); err != nil {
		b := make([]int, len(a))

		for i, v := range a {
			b[v] = i + 1
		}

		fmt.Println(len(a))
		for _, v := range b {
			fmt.Printf("%d ", v)
		}
	}

	return len(l.s) - l.i
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	s := io.ReadString()

	l, r := 1, 200000

	for r - l > 1 {
		x1 := l + (r - l) / 3
		x2 := l + (r - l) / 3 * 2

		v1 := doSomething(x1, s)
		v2 := doSomething(x2, s)

		if v1 < v2 {
			l = x1
		} else {
			r = x2
		}
	}

	doSomethingWithPrint(l, s)
}


package main

import "fmt"

func main()  {
   var first ,second,input,n int
   count:=0
   fmt.Scan(&n)

for j:=0;j<n ;{

	fmt.Scan(&input)
   for i := 1;; i++ {
	   first=input-i
	   second=i
	   if first>second {
		   count++
	   }else{

		   fmt.Println(count)
		   count=0
		   break
	   }
   }
   j++
}

}

There are two sisters Alice and Betty. You have $$$n$$$ candies. You want to distribute these $$$n$$$ candies between two sisters in such a way that:  Alice will get $$$a$$$ ($$$a > 0$$$) candies;  Betty will get $$$b$$$ ($$$b > 0$$$) candies;  each sister will get some integer number of candies;  Alice will get a greater amount of candies than Betty (i.e. $$$a > b$$$);  all the candies will be given to one of two sisters (i.e. $$$a+b=n$$$). Your task is to calculate the number of ways to distribute exactly $$$n$$$ candies between sisters in a way described above. Candies are indistinguishable.Formally, find the number of ways to represent $$$n$$$ as the sum of $$$n=a+b$$$, where $$$a$$$ and $$$b$$$ are positive integers and $$$a>b$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^9$$$) — the number of candies you have.

For each test case, print the answer — the number of ways to distribute exactly $$$n$$$ candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print $$$0$$$.

NoteFor the test case of the example, the $$$3$$$ possible ways to distribute candies are:  $$$a=6$$$, $$$b=1$$$;  $$$a=5$$$, $$$b=2$$$;  $$$a=4$$$, $$$b=3$$$.

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		fmt.Println((n - 1) / 2)
	}
}


package main

import (
	"fmt"
)

func main() {
	var word string
	var k int

	fmt.Scan(&word,&k)

	if len(word) < k {
		fmt.Println("impossible")
		return
	}

	var chs map[rune]int = make(map[rune]int,0)

	for _,ch := range word {
		chs[ch]++
	}

	var countRep = 0
	for _,num := range chs {
		countRep += num - 1
	}

    fmt.Println(countRep)
}

Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.

First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≤ k ≤ 26).

Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.

NoteIn the first test case string contains 6 different letters, so we don't need to change anything.In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}.In the third test case, it is impossible to make 7 different letters because the length of the string is 6.

package main

import (
	"fmt"
)

func main() {
	var word string
	var k int

	fmt.Scan(&word,&k)

	if len(word) < k {
		fmt.Println("impossible")
		return
	}

	chs := make(map[rune]int,0)

	for _,ch := range word {
		chs[ch]++
	}

	out := k - len(chs)
	if out < 0 {
		out = 0
	}
    fmt.Println(out)
}

[{'input': 'yandex\r\n6\r\n', 'output': ['0\r\n']}, {'input': 'yahoo\r\n5\r\n', 'output': ['1\r\n']}, {'input': 'google\r\n7\r\n', 'output': ['impossible\r\n']}, {'input': 'a\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'z\r\n2\r\n', 'output': ['impossible\r\n']}, {'input': 'fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\r\n26\r\n', 'output': ['14\r\n']}, {'input': 'nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\r\n26\r\n', 'output': ['12\r\n']}, {'input': 'a\r\n3\r\n', 'output': ['impossible\r\n']}, {'input': 'smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\r\n4\r\n', 'output': ['1\r\n']}, {'input': 'fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\r\n20\r\n', 'output': ['18\r\n']}, {'input': 'swmkwaruyv\r\n5\r\n', 'output': ['0\r\n']}, {'input': 'tnbqpsuhkczmejirvyfdolxwga\r\n22\r\n', 'output': ['0\r\n']}, {'input': 'abcde\r\n3\r\n', 'output': ['0\r\n']}, {'input': 'abb\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'aaaa\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'abcde\r\n2\r\n', 'output': ['0\r\n']}, {'input': 'yandex\r\n4\r\n', 'output': ['0\r\n']}, {'input': 'aaabbbccc\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'abcd\r\n2\r\n', 'output': ['0\r\n']}, {'input': 'asdfgh\r\n2\r\n', 'output': ['0\r\n']}, {'input': 'aab\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'mynameissako\r\n5\r\n', 'output': ['0\r\n']}, {'input': 'abcde\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'abcd\r\n3\r\n', 'output': ['0\r\n']}, {'input': 'abcdef\r\n2\r\n', 'output': ['0\r\n']}, {'input': 'abcdefg\r\n4\r\n', 'output': ['0\r\n']}, {'input': 'abc\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'asdafjsgljdllgjdgkl\r\n5\r\n', 'output': ['0\r\n']}, {'input': 'yaay\r\n3\r\n', 'output': ['1\r\n']}, {'input': 'yaay\r\n4\r\n', 'output': ['2\r\n']}, {'input': 'zzzzzz\r\n2\r\n', 'output': ['1\r\n']}]


package main
import (
	"fmt"
	//"sort"
)
func main() {
	var n,m int
	c:=0
	fmt.Scan(&n)
	a:=make([]int,n+1)
	for i:=0;i<n;i++ {
		fmt.Scan(&m)
		a[m]++
	}
	for i:=1;i<=n;i++ {
		if a[i]==0 {
			c++
		}
	}
	fmt.Println(c)
}

"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).

The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n).

Print the only number — the minimum number of changes needed to get the permutation.

NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2.

package main

import "fmt"
//import "sort"

func main(){
	var n int
	fmt.Scan(&n)
	var aa int
	a := make([]int, 5000)
	for i:=0; i<n; i++ {
		fmt.Scan(&aa)
		a[aa-1] = aa
	}
	tot := 0
//	sort.Ints(a)
	for j:=0; j<n; j++ {
		if a[j] == 0 {
			tot +=1
		} else {
			tot = tot
		}
	}
	fmt.Println(tot)
}


package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type House struct {
  Pos, Size int
}
type Houses []*House
func (houses Houses) Len() int {
  return len(houses)
}
func (houses Houses) Swap(i, j int) {
  houses[i], houses[j] = houses[j], houses[i]
}
func (houses Houses) Less(i, j int) bool {
  return houses[i].Pos < houses[j].Pos
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, s := getI(), getI()
  houses := make([]*House, n)
  for i := 0; i < n; i++ {
    houses[i] = &House{ getI(), getI() }
  }
  sort.Sort(Houses(houses))
  result := 2
  for i := 1; i < n; i++ {
    doubleGap := 2*(houses[i].Pos - houses[i-1].Pos)
    doubleGap -= houses[i].Size + houses[i-1].Size
    if doubleGap >= 2*s {
      result++
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village.Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?

The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000).

Output the amount of possible positions of the new house.

NoteIt is possible for the x-coordinate of the new house to have non-integer value.

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type House struct {
  Pos, Size int
}
type Houses []*House
func (houses Houses) Len() int {
  return len(houses)
}
func (houses Houses) Swap(i, j int) {
  houses[i], houses[j] = houses[j], houses[i]
}
func (houses Houses) Less(i, j int) bool {
  return houses[i].Pos < houses[j].Pos
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, s := getI(), getI()
  houses := make([]*House, n)
  for i := 0; i < n; i++ {
    houses[i] = &House{ getI(), getI() }
  }
  sort.Sort(Houses(houses))
  result := 2
  for i := 1; i < n; i++ {
    doubleGap := 2*(houses[i].Pos - houses[i-1].Pos)
    doubleGap -= houses[i].Size + houses[i-1].Size
    if doubleGap >= 2*s {
      result++
    }
    if doubleGap > 2*s {
      result++
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}


package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func seek(s, a, b string) bool {
  aPos := strings.Index(s, a)
  if aPos != -1 {
    bPos := strings.Index(s[aPos+len(a):], b)
    if bPos != -1 {
      return true
    }
  }
  return false
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  ab := getS()
  n := len(ab)
  baBytes := make([]byte, n)
  for i := 0; i < n; i++ {
    baBytes[i] = ab[n-1-i]
  }
  ba := string(baBytes)
  s1, s2 := getS(), getS()
  forward, backward := seek(ab, s1, s2), seek(ba, s1, s2)
  result := "fantasy"
  if forward && backward {
    result = "both"
  } else if forward {
    result = "forward"
  } else if backward {
    result = "backward"
  }
  writer.WriteString(fmt.Sprintf("%s\n", result))
}

Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.

The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.  The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.

Output one of the four words without inverted commas:    «forward» — if Peter could see such sequences only on the way from A to B;  «backward» — if Peter could see such sequences on the way from B to A;  «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A;  «fantasy» — if Peter could not see such sequences.

NoteIt is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.

package main

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

func reverse(s string) string {
	b := []byte(s)
	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
		b[i], b[j] = b[j], b[i]
	}
	return string(b)
}

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

	var s, s0, s1 string
	var forward, backward bool

	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%s\n", &s0)
	fmt.Fscanf(reader, "%s", &s1)

	findex0 := strings.Index(s, s0)
	findex1 := strings.LastIndex(s, s1)
	if findex0 == -1 || findex1 == -1 || findex1-findex0 < len(s0) {
		forward = false
	} else {
		forward = true
	}

	s = reverse(s)
	bindex0 := strings.Index(s, s0)
	bindex1 := strings.LastIndex(s, s1)
	if bindex0 == -1 || bindex1 == -1 || bindex1-bindex0 < len(s0) {
		backward = false
	} else {
		backward = true
	}

	if forward && backward {
		fmt.Printf("both\n")
	} else if forward && !backward {
		fmt.Printf("forward\n")
	} else if !forward && backward {
		fmt.Printf("backward\n")
	} else {
		fmt.Printf("fantasy")
	}
}

[{'input': 'atob\r\na\r\nb\r\n', 'output': ['forward\r\n']}, {'input': 'aaacaaa\r\naca\r\naa\r\n', 'output': ['both\r\n']}, {'input': 'aaa\r\naa\r\naa\r\n', 'output': ['fantasy\r\n']}, {'input': 'astalavista\r\nastla\r\nlavista\r\n', 'output': ['fantasy\r\n']}, {'input': 'abacabadabacaba\r\nabacaba\r\nabacaba\r\n', 'output': ['both\r\n']}, {'input': 'a\r\na\r\na\r\n', 'output': ['fantasy\r\n']}, {'input': 'ab\r\nb\r\na\r\n', 'output': ['backward\r\n']}, {'input': 'aaa\r\naaaa\r\naaaa\r\n', 'output': ['fantasy\r\n']}, {'input': 'bbabbbbababbaabaabaa\r\nabb\r\nbaab\r\n', 'output': ['forward\r\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\r\nbbbb\r\nbbbbb\r\n', 'output': ['both\r\n']}, {'input': 'babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\r\nabaabababaa\r\nabaabbaa\r\n', 'output': ['forward\r\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\r\nbbbb\r\nbbbbb\r\n', 'output': ['both\r\n']}, {'input': 'aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\r\nabaabababaa\r\nabaabbaa\r\n', 'output': ['backward\r\n']}, {'input': 'aaaa\r\naaa\r\naa\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzz\r\nzzz\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzzzz\r\nzzzz\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzz\r\nzz\r\n', 'output': ['both\r\n']}, {'input': 'aabaa\r\naab\r\nbaa\r\n', 'output': ['fantasy\r\n']}, {'input': 'aabaab\r\naba\r\nab\r\n', 'output': ['forward\r\n']}, {'input': 'aab\r\nb\r\naa\r\n', 'output': ['backward\r\n']}, {'input': 'abacaba\r\naca\r\nba\r\n', 'output': ['both\r\n']}]


package main

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

// Took from here: https://www.codementor.io/tucnak/using-golang-for-competitive-programming-h8lhvxzt3
var reader *bufio.Reader = bufio.NewReaderSize(os.Stdin, 10000000)
var writer *bufio.Writer = bufio.NewWriterSize(os.Stdout,10000000)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

var n, count int
var matrix [1001][1001]int

func main() {
  // STDOUT MUST BE FLUSHED MANUALLY!!!
  defer writer.Flush()

  scanf("%d\n", &n)
  for i := 1; i <= n; i++ {
    var a, b int
    scanf("%d %d\n", &a, &b)
    matrix[a][b] = 1
  }

  for i := 1; i <= 1000; i++ {
    for j := 1; j <= 1000; j++ {
      if matrix[i][j] == 1 {
        count++
        dfs_adaptada(i, j)
        break
      }
    }
  }
  printf(strconv.Itoa(count - 1))
}

func dfs_adaptada(x, y int) () {
  if matrix[x][y] == 1 {
    matrix[x][y] = 2
    for i := x + 1; i <= 1000; i++ {
      if matrix[i][y] == 1 {
        dfs_adaptada(i, y)
      }
    }
    for j := y + 1; j <= 1000; j++ {
      if matrix[x][j] == 1 {
        dfs_adaptada(x, j)
      }
    }
  }
}

Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.We assume that Bajtek can only heap up snow drifts at integer coordinates.

The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift. Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.

Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.

package main

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

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

type Point struct {
	x, y int
	visited bool
}

func flood(points []Point, pos int) {
	points[pos].visited = true
	x, y := points[pos].x, points[pos].y
	for i := 0; i < len(points); i++ {
		if !points[i].visited && (points[i].x == x || points[i].y == y) {
			flood(points, i)
		}
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	points := make([]Point, n)
	for i := 0; i < n; i++ {
		points[i] = Point{x: scanInt(scanner), y: scanInt(scanner)}
	}
	count := -1
	for i := 0; i < n; i++ {
		if points[i].visited {
			continue
		}
		count++
		flood(points, i)
	}
	writer.WriteString(fmt.Sprintf("%d\n", count))
}


// 192B
package main

import (
	"fmt"
)

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

func main() {
	var n int
	fmt.Scan(&n)
	var a [1005]int
	for i := 0; i < n; i++ {
		fmt.Scan(a[i])
	}
	ans := min(a[0], a[n-1])
	for i := 0; i < n-1; i++ {
		ans = min(ans, max(a[i], a[i+1]))
	}
	fmt.Println(ans)
}

In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.

The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles. The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).

Print a single number — the sought number of days.

NoteIn the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.

package main

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

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

func main() {
  scanner := bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n := scanInt(scanner)
  rain := map[int][]int{}
  for pos := 0; pos < n; pos++ {
    day := scanInt(scanner)
    tiles, found := rain[day]
    if !found {
      rain[day] = []int{ pos }
    } else {
      rain[day] = append(tiles, pos)
    }
    tiles = rain[day]
  }
  wreck := make([]bool, n)
  day, done := 0, false
  for !done {
    day++
    tiles, found := rain[day]
    if !found {
      continue
    }
    for _, pos := range tiles {
      if pos == 0 || pos == n-1 || wreck[pos-1] || wreck[pos+1] {
        done = true
        break
      }
      wreck[pos] = true
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", day))
}


Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.Determine how many groups of students will be kicked out of the club.

The first line contains two integers n and m — the initial number of students and laces (). The students are numbered from 1 to n, and the laces are numbered from 1 to m. Next m lines each contain two integers a and b — the numbers of students tied by the i-th lace (1 ≤ a, b ≤ n, a ≠ b). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.

Print the single number — the number of groups of students that will be kicked out from the club.

NoteIn the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.

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"
	"os"
	"sort"
)
type Rost struct {
	Index int
	Rost int
}
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n int
	fmt.Fscan(r, &n)
	a := make([]Rost, n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(r, &x)
		a[i] = Rost{i+1, x}
	}
	sort.Slice(a, func(i, j int) bool { return a[i].Rost < a[j].Rost})
	x := 0
	y := 1
	h := a[y].Rost - a[x].Rost
	for i := 2; i < n; i++ {
		if a[i].Rost - a[i-1].Rost < h {
			h = a[i].Rost - a[i-1].Rost
			x = i-1
			y = i
		}
	}
	fmt.Fprintln(w, a[x].Index, a[y].Index)

}

n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.

The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction.

Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.

package main

import (
    "fmt"
    "math"
)

func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    min, ansi, ansj := 1000, 0, 0
    for i := 0; i < n; i++ { fmt.Scan(&a[i]) }
    for i := 0; i < n; i++ {
        u := int(math.Abs(float64(a[i])-float64(a[(i+1)%n])))
        if min > u {
            min = u
            ansi = i+1
            ansj = ((i+1)%n)+1
        }
    }
    fmt.Println(ansi,ansj)
}