Let's call a string $$$s$$$ perfectly balanced if for all possible triplets $$$(t,u,v)$$$ such that $$$t$$$ is a non-empty substring of $$$s$$$ and $$$u$$$ and $$$v$$$ are characters present in $$$s$$$, the difference between the frequencies of $$$u$$$ and $$$v$$$ in $$$t$$$ is not more than $$$1$$$.For example, the strings "aba" and "abc" are perfectly balanced but "abb" is not because for the triplet ("bb",'a','b'), the condition is not satisfied.You are given a string $$$s$$$ consisting of lowercase English letters only. Your task is to determine whether $$$s$$$ is perfectly balanced or not.A string $$$b$$$ is called a substring of another string $$$a$$$ if $$$b$$$ can be obtained by deleting some characters (possibly $$$0$$$) from the start and some characters (possibly $$$0$$$) from the end of $$$a$$$.

The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 2\cdot 10^4$$$) denoting the number of testcases. Each of the next $$$t$$$ lines contain a single string $$$s$$$ ($$$1\leq |s|\leq 2\cdot 10^5$$$), consisting of lowercase English letters. It is guaranteed that the sum of $$$|s|$$$ over all testcases does not exceed $$$2\cdot 10^5$$$.

For each test case, print "YES" if $$$s$$$ is a perfectly balanced string, and "NO" otherwise. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T int
	var S,anc string

	fmt.Fscan(in, &T)
	//list := make([]string,N)

	for i := 0;i < T;i++{
		fmt.Fscan(in, &S)
		val := srtcount(S)
		list := strings.Split(S, val)
		//fmt.Println(val)
		for i:= len(list)-1;i >= 0;i--{
			if i == len(list)-1 {
				if list[i] == ""{
					anc = "YES"
				}
				if strings.HasPrefix(val, list[i]){
					anc = "YES"
				}else{
					anc = "NO"
				}
			}else{
				if list[i] != ""{
					anc = "NO"
				}
			}
		}
		fmt.Println(anc)
	}
}

func srtcount(S string) string{
	arr1 := strings.Split(S, "")
	m := make(map[string]string)
	var s string

	for _,v := range arr1{
		if _,ok := m[v];ok{
			break
		}else{
			m[v] = v
			s += v
		}
	}
	return s
}

package main

import (
	"fmt"
)

func solve() {
	var s string
	fmt.Scan(&s)

	count := map[byte]int{}
	for i := range s {
		count[s[i]]++
	}

	n := len(s)
	seen := map[byte]int{}
	for i := 0; i < len(count); i++ {
		if i % len(count) == 0 {
			seen = map[byte]int{}
		}

		seen[s[i]]++

		if seen[s[i]] > 1 {
			fmt.Println("NO")
			return
		}
	}

	for i := len(count); i < n; i++ {
		if s[i] != s[i % len(count)] {
			fmt.Println("NO")
			return
		}
	}

	fmt.Println("YES")
}

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

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

package main

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

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: out}
}

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

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) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 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
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func ind(a byte) int {
	return int(a) - int('a')
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	t := io.ReadInt()
loop:
	for ; t > 0; t-- {
		s := io.ReadString()

		var us [26][26]bool
		mp := make(map[byte]int, 26)
		mm := make(map[byte]struct{})

		for i := range s {
			mm[s[i]] = struct{}{}
		}

		for i := range s {
			mp[s[i]]++
			for b := range mm {
				if mp[s[i]] > mp[b]+1 {
					fmt.Println("No")
					continue loop
				}
				if mp[s[i]] > mp[b] {
					if us[ind(b)][ind(s[i])] {
						fmt.Println("No")
						continue loop
					}
					us[ind(s[i])][ind(b)] = true
				}
			}
		}
		fmt.Println("Yes")
	}
}

package main

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

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

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

	t := 0
	str := ""
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		fmt.Fscan(in, &str)
		mp := make(map[int32]bool)
		for _, ch := range str {
			mp[ch] = true
		}
		kind := len(mp)
		vis := make(map[byte]bool)
		for left, right := 0, 0; right < len(str); right++ {
			vis[str[right]] = true
			if right-left+1 == kind {
				if len(vis) != kind {
					fmt.Fprintln(out, "NO")
					goto out
				} else {
					delete(vis, str[left])
					left++
				}
			}
		}
		fmt.Fprintln(out, "YES")
	out:
	}
}

package main

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

func ord(b byte) int {
	return int(b - 'a')
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		s, _ := reader.ReadString('\n')
		s = strings.TrimSpace(s)
		was := make([]int, 26)
		pat := ""
		isGood := true
		for i := range s {
			if len(pat) == 0 {
				idx := ord(s[i])
				if was[idx] == 0 {
					was[idx]++
				} else {
					pat = s[:i]
				}
			}
			if len(pat) != 0 && pat[i%len(pat)] != s[i] {
				isGood = false
				break
			}
		}
		if isGood {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

		freq := make([]int, 26)
		var u int
		for _, ch := range s {
			freq[ch-'a']++
			if freq[ch-'a'] == 1 {
				u++
			}
		}

		f := true
		if u > 1 {
			c := make([]bool, 26)
			for i := 0; i < u; i++ {
				if c[s[i]-'a'] {
					f = false
					break
				}
				c[s[i]-'a'] = true
			}

			for i := u; i < len(s); i++ {
				c[s[i-u]-'a'] = false
				if c[s[i]-'a'] {
					f = false
					break
				}
				c[s[i]-'a'] = true
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T,count int
	var S,anc string

	fmt.Fscan(in, &T)
	//list := make([]string,N)

	for i := 0;i < T;i++{
		fmt.Fscan(in, &S)
		val := srtcount(S)
		list := strings.Split(S, val)
		//fmt.Println(val)
		count = 0
		for i:= 0;i < len(list);i++{
			if list[i] != ""{
				if count >= 1{
					anc = "NO"
				}
				count++
				//r := regexp.MustCompile(list[i])
				if !strings.HasPrefix(val, list[i]){
					anc = "NO"
				}else{
					anc = "YES"
				}
			}else{
				anc = "YES"
			}
		}
		fmt.Println(anc)
	}
}

func srtcount(S string) string{
	arr1 := strings.Split(S, "")
	m := make(map[string]string)
	var s string

	for _,v := range arr1{
		if _,ok := m[v];ok{
			break
		}else{
			m[v] = v
			s += v
		}
	}
	return s
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T,count int
	var S,anc string

	fmt.Fscan(in, &T)
	//list := make([]string,N)

	for i := 0;i < T;i++{
		fmt.Fscan(in, &S)
		val := srtcount(S)
		list := strings.Split(S, val)
		//fmt.Println(val)
		count = 0
		for i:= 0;i < len(list);i++{
			anc = "YES"
			if list[i] != ""{
				if count >= 1{
					anc = "NO"
				}
				count++
				//r := regexp.MustCompile(list[i])
				if !strings.HasPrefix(val, list[i]){
					anc = "NO"
				}else{
					anc = "YES"
				}
			}
		}
		fmt.Println(anc)
	}
}

func srtcount(S string) string{
	arr1 := strings.Split(S, "")
	m := make(map[string]string)
	var s string

	for _,v := range arr1{
		if _,ok := m[v];ok{
			break
		}else{
			m[v] = v
			s += v
		}
	}
	return s
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T,count int
	var S,anc string

	fmt.Fscan(in, &T)
	//list := make([]string,N)

	for i := 0;i < T;i++{
		fmt.Fscan(in, &S)
		val := srtcount(S)
		list := strings.Split(S, val)
		//fmt.Println(val)
		for i:= 0;i < len(list);i++{
			anc = "YES"
			if list[i] != ""{
				if count >= 1{
					anc = "NO"
				}
				count++
				//r := regexp.MustCompile(list[i])
				if !strings.HasPrefix(val, list[i]){
					anc = "NO"
				}else{
					anc = "YES"
				}
			}
		}
		fmt.Println(anc)
	}
}

func srtcount(S string) string{
	arr1 := strings.Split(S, "")
	m := make(map[string]string)
	var s string

	for _,v := range arr1{
		if _,ok := m[v];ok{
			break
		}else{
			m[v] = v
			s += v
		}
	}
	return s
}

package main

import (
	"fmt"
)

func solve() {
	var s string
	fmt.Scan(&s)

	count := map[byte]int{}
	for i := range s {
		count[s[i]]++
	}

	if len(count) == 1 {
		fmt.Println("YES")
		return
	}

	n := len(s)
	for k, v := range count {
		if v > 2 {
			fmt.Println("NO")
			return
		}

		if v == 2 && (s[0] != k || s[n - 1] != k) {
			fmt.Println("NO")
			return
		}
	}

	fmt.Println("YES")
}

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

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

package main

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

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: out}
}

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

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) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 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
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func ind(a byte) int {
	return int(a) - int('a')
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	t := io.ReadInt()
loop:
	for ; t > 0; t-- {
		s := io.ReadString()

		var us [26][26]bool
		mp := make(map[byte]int, 26)

		for i := range s {
			mp[s[i]]++
			for b := byte('a'); b <= 'z'; b++ {
				if mp[s[i]] > mp[b]+1 && mp[b] != 0 {
					fmt.Println("No")
					continue loop
				}
				if mp[s[i]] > mp[b] {
					if us[ind(b)][ind(s[i])] {
						fmt.Println("No")
						continue loop
					}
					us[ind(s[i])][ind(b)] = true
				}
			}
		}
		fmt.Println("Yes")
	}
}


Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n.Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in such a way that his array becomes a permutation (i.e. each of the integers from 1 to n was encountered in his array exactly once). If there are multiple ways to do it he wants to find the lexicographically minimal permutation among them.Thus minimizing the number of changes has the first priority, lexicographical minimizing has the second priority.In order to determine which of the two permutations is lexicographically smaller, we compare their first elements. If they are equal — compare the second, and so on. If we have two permutations x and y, then x is lexicographically smaller if xi < yi, where i is the first index in which the permutations x and y differ.Determine the array Ivan will obtain after performing all the changes.

The first line contains an single integer n (2 ≤ n ≤ 200 000) — the number of elements in Ivan's array. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ n) — the description of Ivan's array.

In the first line print q — the minimum number of elements that need to be changed in Ivan's array in order to make his array a permutation. In the second line, print the lexicographically minimal permutation which can be obtained from array with q changes.

NoteIn the first example Ivan needs to replace number three in position 1 with number one, and number two in position 3 with number four. Then he will get a permutation [1, 2, 4, 3] with only two changed numbers — this permutation is lexicographically minimal among all suitable. In the second example Ivan does not need to change anything because his array already is a permutation.

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

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

	n := readInt()
	a := make([]int, n)
	m := make([][]int, n+1)
	used := make([]int, n+1)
	var dupes []int
	for i := range a {
		a[i] = readInt()
		m[a[i]] = append(m[a[i]], i)
		switch len(m[a[i]]) {
		case 1:
		case 2:
			dupes = append(dupes, m[a[i]]...)
		default:
			dupes = append(dupes, i)
		}
	}
	sort.Ints(dupes)
	ans := 0
	for i := 1; i <= n; i++ {
		if len(m[i]) == 0 {
			ans++
			d := dupes[0]
			for ; a[d] < i && m[a[d]][0] == d || used[a[d]] == len(m[a[d]])-1; d = dupes[0] {
				dupes = dupes[1:]
			}
			if m[a[d]][0] == d {
				m[a[d]] = m[a[d]][1:]
			} else {
				used[a[d]]++
			}
			a[d] = i
			dupes = dupes[1:]
		}
	}

	fmt.Fprintln(out, ans)
	for i := range a {
		if i+1 == n {
			fmt.Fprintln(out, a[i])
		} else {
			fmt.Fprint(out, a[i], " ")
		}
	}
}

package main

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

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	count := make([]int, n+1)
	perm := make([]int, n)
	handled := make([]bool, n+1)
	ans := 0

	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &perm[i])
		count[perm[i]]++
	}
	var min int
	for min = 1; min <= n; min++ {
		if count[min] == 0 {
			break
		}
	}
	for i := 0; i < n; i++ {
		if count[perm[i]] > 1 {
			if (!handled[perm[i]] && min < perm[i]) || handled[perm[i]] {
				count[perm[i]]--
				count[min]++
				perm[i] = min
				for ; min <= n; min++ {
					if count[min] == 0 {
						break
					}
				}
				ans++
			}
			handled[perm[i]] = true
		}
	}
	fmt.Printf("%d\n", ans)
	for i := 0; i < n; i++ {
		fmt.Printf("%d ", perm[i])
	}
	fmt.Printf("\n")
}

package main

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

var st_input = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !st_input.Scan() {
		panic(st_input.Err())
	}
	res := 0
	for _, b := range st_input.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func main() {
	st_input.Split(bufio.ScanWords)
	n := readInt()
	a_counts := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		a_counts[i] = 0
	}
	need := make([]int, 0, n+1)
	var a []int = make([]int, n)

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

	for i := 1; i < n+1; i++ {
		if a_counts[i] == 0 {
			need = append(need, i)
		}
	}

	result := 0
	left := make(map[int]int)
	current_need_index := 0

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

		//fmt.Printf("i=%v a[i]=%v a_counts=%v\n", i, a[i], a_counts[a[i]])
		//fmt.Printf("need=%v\n", need)
		//fmt.Printf("left=%v\n\n", left)

		temp := a[i]
		if a_counts[a[i]] == 1 {
			if left[a[i]] == 1 {
				a[i] = need[current_need_index]
				result += 1
				current_need_index += 1
			}
		} else if a_counts[a[i]] > 1 {
			if need[current_need_index] < a[i] {
				a[i] = need[current_need_index]
				result += 1
				current_need_index += 1
			} else if need[current_need_index] > a[i] && left[a[i]] == 1 {
				a[i] = need[current_need_index]
				result += 1
				current_need_index += 1
			}
			a_counts[temp] -= 1
		}
		left[a[i]] = 1
		if current_need_index == len(need) {
			break
		}
	}

	fmt.Printf("%v\n", result)
	for i := 0; i < n; i++ {
		fmt.Printf("%v ", a[i])
	}
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

func main() {
	ms := NewMuchScanner()

	n := ms.ReadInt()

    arr := ms.ReadIntArr(n)

	m := map[int]int{}
	used := map[int]bool{}

	for _, v := range arr {
		m[v]++
	}

	//Queue of values we need to create
	toCreate := priorityQueue{}

	for i := 1; i <= n; i++ {
		if m[i] == 0 {
			heap.Push(&toCreate, i)
		}
		used[i] = false
	}

	moves := 0

	minCandidate := heap.Pop(&toCreate)
	for i := 0; i < n && minCandidate != nil; i++ {
		v := arr[i]
		if m[v] > 1 {
			if minCandidate.(int) < v || used[v] {
				arr[i] = minCandidate.(int)
				m[v]--
				moves++
				minCandidate = heap.Pop(&toCreate)
			}
		}
		used[arr[i]] = true
	}

	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fprintf(writer, "%d\n", moves)
	for _, v := range arr {
		fmt.Fprintf(writer, "%d ", v)

	}
	fmt.Fprintln(writer)

}

type priorityQueue []int

type maxPriorityQueue struct {
	priorityQueue
}

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i] < pq[j]
}

func (pq priorityQueue) Swap(i, j int) {
	if pq.Len() > 0 {
		pq[i], pq[j] = pq[j], pq[i]
	}
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(int))
}

func (pq *priorityQueue) Pop() interface{} {
	n := pq.Len()
	if n == 0 {
		return nil
	}
	item := (*pq)[n-1]
	*pq = (*pq)[0 : n-1]
	return item
}

func (pq maxPriorityQueue) Less(i, j int) bool {
	return pq.priorityQueue[i] > pq.priorityQueue[j]
}

// MuchScanner is a wrapper for bufio.Scanner
type MuchScanner struct {
	scanner *bufio.Scanner
}

// NewMuchScanner creates new insances of MuchScanner
func NewMuchScanner() *MuchScanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return &MuchScanner{
		scanner: sc,
	}
}

// TokenSize sets maximal token size
func (ms *MuchScanner) TokenSize(tokenSize int) {
	ms.scanner.Buffer(make([]byte, tokenSize), tokenSize)
}

// ReadString reads next word as a string
func (ms *MuchScanner) ReadString() string {
	ms.scanner.Scan()
	return ms.scanner.Text()
}

// ReadInt reads next int number
func (ms *MuchScanner) ReadInt() int {
	n, _ := strconv.Atoi(ms.ReadString())
	return n
}

// ReadIntArr reads next n int numbers
func (ms *MuchScanner) ReadIntArr(n int) []int {
	arr := make([]int, n)
	for i := range arr {
		arr[i] = ms.ReadInt()
	}
	return arr
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
	"strings"
)

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

	const capacity = 100000000
	buf := make([]byte, capacity)
	scanner.Buffer(buf, capacity)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	strArr := strings.Fields(scanner.Text())

	arr := make([]int, len(strArr))
	for i, v := range strArr {
		arr[i], _ = strconv.Atoi(v)
	}

	m := map[int]int{}
	used := map[int]bool{}

	for _, v := range arr {
		m[v]++
	}

	//Queue of values we need to create
	toCreate := priorityQueue{}

	for i := 1; i <= n; i++ {
		if m[i] == 0 {
			heap.Push(&toCreate, i)
		}
		used[i] = false
	}

	moves := 0

	minCandidate := heap.Pop(&toCreate)
	for i := 0; i < n && minCandidate != nil; i++ {
		v := arr[i]
		if m[v] > 1 {
			if minCandidate.(int) < v || used[v] {
				arr[i] = minCandidate.(int)
				m[v]--
				moves++
				minCandidate = heap.Pop(&toCreate)
			}
		}
		used[arr[i]] = true
	}

	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fprintf(writer, "%d\n", moves)
	for _, v := range arr {
		fmt.Fprintf(writer, "%d ", v)

	}
	fmt.Fprintln(writer)

}

type priorityQueue []int

type maxPriorityQueue struct {
	priorityQueue
}

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i] < pq[j]
}

func (pq priorityQueue) Swap(i, j int) {
	if pq.Len() > 0 {
		pq[i], pq[j] = pq[j], pq[i]
	}
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(int))
}

func (pq *priorityQueue) Pop() interface{} {
	n := pq.Len()
	if n == 0 {
		return nil
	}
	item := (*pq)[n-1]
	*pq = (*pq)[0 : n-1]
	return item
}

func (pq maxPriorityQueue) Less(i, j int) bool {
	return pq.priorityQueue[i] > pq.priorityQueue[j]
}

package main

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

func solve() {
	n := readInt()
	a := make([]int, n)
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		a[i] = readInt()
		cnt[a[i]]++
	}
	b := make([]int, 0)
	for i := 1; i <= n; i++ {
		if cnt[i] == 0 {
			b = append(b, i)
		}
	}
	changes := 0
	visit := map[int]int{}
	for i := 0; i < n; i++ {
		if cnt[a[i]] > 1 {
			if visit[a[i]] > 0 || (len(b) > 0 && b[0] < a[i]) {
				cnt[a[i]]--
				changes++
				a[i] = b[0]
				b = b[1:]
			} else {
				visit[a[i]]++
			}
		}
	}
	fmt.Println(changes)
	var buffer bytes.Buffer
	for i := 0; i < n; i++ {
		if i > 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(a[i]))
	}
	fmt.Println(buffer.String())
}

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

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

// Codeforces 864 D Make a Permutation, train
package main

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

var in *bufio.Reader

func readFive() (int, int, int, int, int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i := 0; i < len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0], a[1], a[2], a[3], a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j := 0; j < n; j++ {
		aa, err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

type group struct {
	v int
	n int
	used int
	usedv bool
}

var n int
var a []int
var perm []int
var needChange int
var gr []*group

// readData read data for out problem.
func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading n
	n, _, _, _, _ = readFive()
	a = readLineNumbs(n)
}

// solve func solves our problem.
func solve() {
	gr = make([]*group,n+1)
	for _,aa := range a {
		if gr[aa]==nil {
			gr[aa] = new(group)
			gr[aa].n++
			gr[aa].v = aa
		} else {
			gr[aa].n++
		}
	}
	// which numbers need placing
	need := make([]int,n+1)
	ineed := 0
	for i:=1; i<=n; i++ {
		if gr[i] == nil {
			need[ineed] = i
			ineed++
		}
	}
	//fmt.Printf("Need %d places\n", ineed)
	// walk a and place need in groups
	ineed = 0
	perm = make([]int, n)
	for i,aa := range a {
		g := gr[aa]
		if g==nil {
			msg := fmt.Sprintf("gr cannot be nil i,aa = %d %d",i,aa)
			panic(msg)
		} else if g.n==1 {
			perm[i] = aa
		} else {
			// may be can place number from need
			nd := need[ineed]
			if g.usedv || (nd<g.v && g.used<g.n-1) {
				// use nd
				perm[i] = nd
				g.used++
				ineed++
				needChange++
				//fmt.Printf("i=%d Used %d instead of %d\n", i, nd, aa)
			} else {
				// use g.v
				perm[i] = g.v
				g.used++
				g.usedv = true
				//fmt.Printf("i=%d Used %d\n", i, nd)
			}
		}
	}
}

// printRes print problem solution in expected format.
func printRes() {
	fmt.Println(needChange)
	for _,aa := range perm {
		fmt.Printf("%d ", aa)
	}
	fmt.Println()
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

func solve() {
	n := readInt()
	a := readIntArray(n)
	max := make(map[int]int)
	for i := 0; i < n; i++ {
		max[a[i]] = i
	}
	cur := 1
	used := make(map[int]bool)
	ans := 0
	for i := 0; i < n; i++ {
		for _, ok := max[cur]; ok; _, ok = max[cur] {
			cur++
		}
		if used[a[i]] {
			a[i] = cur
			cur++
			ans++
			continue
		}
		if cur < a[i] && max[a[i]] > i {
			a[i] = cur
			cur++
			ans++
		} else {
			used[a[i]] = true
		}
	}
	fmt.Println(ans)
	var buf bytes.Buffer
	for _, x := range a {
		buf.WriteString(strconv.Itoa(x))
		buf.WriteString(" ")
	}
	fmt.Println(buf.String())
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

package main

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

func solve() {
	n := readInt()
	a := readIntArray(n)
	max := make(map[int]int)
	for i := 0; i < n; i++ {
		max[a[i]] = i
	}
	cur := 1
	used := make(map[int]bool)
	ans := 0
	for i := 0; i < n; i++ {
		for _, ok := max[cur]; ok; _, ok = max[cur] {
			cur++
		}
		if used[a[i]] {
			a[i] = cur
			cur++
			ans++
			continue
		}
		if cur < a[i] && max[a[i]] > i {
			a[i] = cur
			cur++
			ans++
		} else {
			used[a[i]] = true
		}
	}
	fmt.Println(ans)
	for _, x := range a {
		fmt.Print(x, " ")
	}
	fmt.Println()
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	strArr := strings.Split(scanner.Text(), " ")
	arr := make([]int, n)
	for i, v := range strArr {
		arr[i], _ = strconv.Atoi(v)
	}

	m := map[int]int{}

	for _, v := range arr {
		m[v]++
	}

	//Queue of values we need to create
	toCreate := priorityQueue{}

	for i := 1; i <= n; i++ {
		if m[i] == 0 {
			heap.Push(&toCreate, i)
		}
	}

	moves := 0

	minCandidate := heap.Pop(&toCreate)
	for i := 0; i < n && minCandidate != nil; i++ {
		v := arr[i]
		if m[v] > 1 {
			if minCandidate.(int) < v {
				arr[i] = minCandidate.(int)
				m[v]--
				moves++
				minCandidate = heap.Pop(&toCreate)
			}
		}
	}

	if minCandidate != nil {
		heap.Push(&toCreate, minCandidate)
	}

	toCreateMax := maxPriorityQueue{toCreate}
	heap.Init(&toCreateMax)

	maxCandidate := heap.Pop(&toCreateMax)
	for i := n - 1; i >= 0 && maxCandidate != nil; i-- {
		v := arr[i]
		if m[v] > 1 {
			if maxCandidate.(int) > v {
				arr[i] = maxCandidate.(int)
				m[v]--
				moves++
				maxCandidate = heap.Pop(&toCreateMax)
			}
		}
	}

	fmt.Printf("%d\n", moves)
	for _, v := range arr {
		fmt.Printf("%d ", v)
	}
	fmt.Println()
}

type priorityQueue []int

type maxPriorityQueue struct {
	priorityQueue
}

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i] < pq[j]
}

func (pq priorityQueue) Swap(i, j int) {
	if pq.Len() > 0 {
		pq[i], pq[j] = pq[j], pq[i]
	}
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(int))
}

func (pq *priorityQueue) Pop() interface{} {
	n := pq.Len()
	if n == 0 {
		return nil
	}
	item := (*pq)[n-1]
	*pq = (*pq)[0 : n-1]
	return item
}

func (pq maxPriorityQueue) Less(i, j int) bool {
	return pq.priorityQueue[i] > pq.priorityQueue[j]
}

package main

import (
	"container/heap"
	"fmt"
)

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

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

	m := map[int]int{}

	for _, v := range arr {
		m[v]++
	}

	//Queue of values we need to create
	toCreate := priorityQueue{}

	toRemoveTotal := 0

	for i := 1; i <= n; i++ {
		entries := m[i]
		if entries == 0 {
			heap.Push(&toCreate, i)
		} else if entries > 1 {
			toRemoveTotal += entries
		}
	}

	moves := 0

	minCandidate := 0

	l := toCreate.Len()
	if l > 0 {
		minCandidate = heap.Pop(&toCreate).(int)
	}
	for i := 0; i < n && l > 0; i++ {
		v := arr[i]
		if m[v] > 1 {
			var removing bool
			if toRemoveTotal > l {
				removing = minCandidate < v
			} else {
				removing = true
			}
			if removing {
				arr[i] = minCandidate
				m[v]--
				toRemoveTotal--
				if m[v] == 1 {
					toRemoveTotal--
				}
				moves++
				l--
				if l > 0 {
					minCandidate = heap.Pop(&toCreate).(int)
				}
			} else {
				toRemoveTotal--
			}
		}
	}

	fmt.Printf("%d\n", moves)
	for _, v := range arr {
		fmt.Printf("%d ", v)
	}

	fmt.Println()
}

type priorityQueue []int

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i] < pq[j]
}

func (pq priorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(int))
}

func (pq *priorityQueue) Pop() interface{} {
	n := pq.Len()
	item := (*pq)[n-1]
	*pq = (*pq)[0 : n-1]
	return item
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
	"strings"
)

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

	const capacity = 100000000
	buf := make([]byte, capacity)
	scanner.Buffer(buf, capacity)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	strArr := strings.Fields(scanner.Text())

	arr := make([]int, len(strArr))
	for i, v := range strArr {
		arr[i], _ = strconv.Atoi(v)
	}

	m := map[int]int{}

	for _, v := range arr {
		m[v]++
	}

	//Queue of values we need to create
	toCreate := priorityQueue{}

	for i := 1; i <= n; i++ {
		if m[i] == 0 {
			heap.Push(&toCreate, i)
		}
	}

	moves := 0

	minCandidate := heap.Pop(&toCreate)
	for i := 0; i < n && minCandidate != nil; i++ {
		v := arr[i]
		if m[v] > 1 {
			if minCandidate.(int) < v {
				arr[i] = minCandidate.(int)
				m[v]--
				moves++
				minCandidate = heap.Pop(&toCreate)
			}
		}
	}

	if minCandidate != nil {
		heap.Push(&toCreate, minCandidate)
	}

	toCreateMax := maxPriorityQueue{toCreate}
	heap.Init(&toCreateMax)

	maxCandidate := heap.Pop(&toCreateMax)
	for i := n - 1; i >= 0 && maxCandidate != nil; i-- {
		v := arr[i]
		if m[v] > 1 {
			if maxCandidate.(int) > v {
				arr[i] = maxCandidate.(int)
				m[v]--
				moves++
				maxCandidate = heap.Pop(&toCreateMax)
			}
		}
	}

	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fprintf(writer, "%d\n", moves)
	for _, v := range arr {
		fmt.Fprintf(writer, "%d ", v)

	}
	fmt.Fprintln(writer)

}

type priorityQueue []int

type maxPriorityQueue struct {
	priorityQueue
}

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i] < pq[j]
}

func (pq priorityQueue) Swap(i, j int) {
	if pq.Len() > 0 {
		pq[i], pq[j] = pq[j], pq[i]
	}
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(int))
}

func (pq *priorityQueue) Pop() interface{} {
	n := pq.Len()
	if n == 0 {
		return nil
	}
	item := (*pq)[n-1]
	*pq = (*pq)[0 : n-1]
	return item
}

func (pq maxPriorityQueue) Less(i, j int) bool {
	return pq.priorityQueue[i] > pq.priorityQueue[j]
}

package main

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

func solve() {
	n := readInt()
	a := make([]int, n)
	cnt := make([][]int, n+1)
	for i := 0; i < n; i++ {
		a[i] = readInt()
		cnt[a[i]] = append(cnt[a[i]], i)
	}
	pos := 0
	changes := 0
	res := make([]int, n)
	for i := 1; i <= n; i++ {
		if len(cnt[i]) == 0 {
			for j := pos; j < n; j++ {
				if len(cnt[a[j]]) > 1 {
					pos = j
					arr := cnt[a[j]]
					res[arr[0]] = i
					cnt[a[j]] = arr[1:]
					changes++
					break
				}
			}
		} else {
			arr := cnt[i]
			res[arr[0]] = i
			cnt[i] = append(arr[1:], 99999999)
		}
	}

	fmt.Println(changes)
	var buffer bytes.Buffer
	for i := 0; i < n; i++ {
		if i > 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(res[i]))
	}
	fmt.Println(buffer.String())
}

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

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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


You are given a tree consisting of $$$n$$$ nodes. You generate an array from the tree by marking nodes one by one.Initially, when no nodes are marked, a node is equiprobably chosen and marked from the entire tree. After that, until all nodes are marked, a node is equiprobably chosen and marked from the set of unmarked nodes with at least one edge to a marked node. It can be shown that the process marks all nodes in the tree. The final array $$$a$$$ is the list of the nodes' labels in order of the time each node was marked.Find the expected number of inversions in the array that is generated by the tree and the aforementioned process.The number of inversions in an array $$$a$$$ is the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i > a_j$$$. For example, the array $$$[4, 1, 3, 2]$$$ contains $$$4$$$ inversions: $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(1, 4)$$$, $$$(3, 4)$$$.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 200$$$) — the number of nodes in the tree. The next $$$n - 1$$$ lines each contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$; $$$x \neq y$$$), denoting an edge between node $$$x$$$ and $$$y$$$. It's guaranteed that the given edges form a tree.

Output the expected number of inversions in the generated array modulo $$$10^9+7$$$. Formally, let $$$M = 10^9+7$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x < M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.

NoteThis is the tree from the first sample:  For the first sample, the arrays are almost fixed. If node $$$2$$$ is chosen initially, then the only possible array is $$$[2, 1, 3]$$$ ($$$1$$$ inversion). If node $$$3$$$ is chosen initially, then the only possible array is $$$[3, 1, 2]$$$ ($$$2$$$ inversions). If node $$$1$$$ is chosen initially, the arrays $$$[1, 2, 3]$$$ ($$$0$$$ inversions) and $$$[1, 3, 2]$$$ ($$$1$$$ inversion) are the only possibilities and equiprobable. In total, the expected number of inversions is $$$\frac{1}{3}\cdot 1 + \frac{1}{3} \cdot 2 + \frac{1}{3} \cdot (\frac{1}{2} \cdot 0 + \frac{1}{2} \cdot 1) = \frac{7}{6}$$$. $$$166666669 \cdot 6 = 7 \pmod {10^9 + 7}$$$, so the answer is $$$166666669$$$.This is the tree from the second sample:   This is the tree from the third sample:

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1540B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod int64 = 1e9 + 7
	const mod2 = (mod + 1) / 2
	pow := func(x, n int64) (res int64) {
		res = 1
		for ; n > 0; n >>= 1 {
			if n&1 > 0 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return
	}

	var n, v, w int
	Fscan(in, &n)
	dis := make([][]int, n)
	for i := range dis {
		dis[i] = make([]int, n)
		for j := range dis[i] {
			dis[i][j] = 1e9
		}
	}
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		dis[v][w] = 1
		dis[w][v] = 1
	}
	for k := range dis {
		for i := range dis {
			for j := range dis {
				dis[i][j] = min(dis[i][j], dis[i][k]+dis[k][j])
			}
		}
	}

	f := make([][]int64, n+1)
	for i := range f {
		f[i] = make([]int64, n+1)
		f[0][i] = 1
	}
	for i := 1; i <= n; i++ {
		for j := 1; j <= n; j++ {
			f[i][j] = (f[i-1][j] + f[i][j-1]) * mod2 % mod
		}
	}
	ans := int64(0)
	for _, d := range dis {
		for v, dv := range dis {
			for w, dvw := range dv[:v] {
				commonDis := (d[v] + d[w] - dvw) / 2
				ans += f[d[v]-commonDis][d[w]-commonDis]
			}
		}
	}
	Fprint(out, ans%mod*pow(int64(n), mod-2)%mod)
}

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

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

package main

import "fmt"

const Mod = 1000000007
const Log = 10

var n int
var g [][]int
var p [][]int
var d []int

func main() {
	fmt.Scan(&n)
	g = make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, 0)
	}
	for i := 1; i < n; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		x -= 1
		y -= 1
		g[x] = append(g[x], y)
		g[y] = append(g[y], x)
	}

	dp := make([][]int64, n)
	for i := 0; i < n; i++ {
		dp[i] = make([]int64, n)
	}
	for i := 1; i < n; i++ {
		dp[0][i] = 1
		dp[i][0] = 0
	}
	ti := inverse(2)
	for i := 1; i < n; i++ {
		for j := 1; j < n; j++ {
			dp[i][j] = ti * (dp[i-1][j] + dp[i][j-1]) % Mod
		}
	}

	nInverse := inverse(int64(n))

	var answer int64
	for i := 0; i < n; i++ {
		p = make([][]int, n)
		for i := 0; i < n; i++ {
			p[i] = make([]int, Log)
			for j := 0; j < Log; j++ {
				p[i][j] = -1
			}
		}
		d = make([]int, n)
		for i := 0; i < n; i++ {
			d[i] = -1
		}

		dfs(i, -1)

		for x := 0; x < n; x++ {
			for y := x + 1; y < n; y++ {
				z := lca(x, y)
				dx := d[x] - d[z]
				dy := d[y] - d[z]
				answer = (answer + nInverse*dp[dy][dx]%Mod) % Mod
			}
		}
	}
	fmt.Println(answer)
}

func getParent(v int, ds int) int {
	for i := Log - 1; i >= 0; i-- {
		if ds&(1<<i) > 0 {
			v = p[v][i]
		}
	}
	return v
}

func lca(x int, y int) int {
	if d[x] > d[y] {
		x, y = y, x
	}

	y = getParent(y, d[y]-d[x])

	if x == y {
		return x
	}

	for i := Log - 1; i >= 0; i-- {
		if p[x][i] != p[y][i] {
			x = p[x][i]
			y = p[y][i]
		}
	}

	return p[x][0]
}

func dfs(x, z int) {
	p[x][0] = z
	for i := 1; i < Log; i++ {
		if p[x][i-1] != -1 {
			p[x][i] = p[p[x][i-1]][i-1]
		}
	}

	d[x] = 0
	if z != -1 {
		d[x] = d[z] + 1
	}
	for _, y := range g[x] {
		if y == z {
			continue
		}
		dfs(y, x)
	}
}

func power(x, y int64) int64 {
	if y == 0 {
		return 1
	}
	result := power(x, y/2)
	if y%2 == 0 {
		return result * result % Mod
	}
	return result * result % Mod * x % Mod
}

func inverse(x int64) int64 {
	return power(x, Mod-2)
}


There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.

The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000,  - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.

Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.

NoteExplanation to the first and second samples from the statement, respectively:

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

var x, y int

func solve(n int) {
	var ans int
	in := make([][3]int, n)
	I(&x, " ")
	I(&y, "\n")
	for i := 0; i < n; i++ {
		I(&in[i][0], " ")
		I(&in[i][1], "\n")
	}
	for i := 0; i < n; i++ {
		if in[i][2] == 1 {
			continue
		}
		ans++
		in[i][2] = 1
		for j := 0; j < n; j++ {
			if oo(in[i], in[j]) {
				in[j][2] = 1
			}
		}
	}
	O(ans, "\n")
}

func oo(a, b [3]int) bool {
	if x-a[0] != 0 {
		return (x-a[0])*(b[1]-a[1]) == (b[0]-a[0])*(y-a[1])
	} else if a[0] == b[0] && a[0] == x {
		return true
	}
	return false
}

package main

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

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

type Point struct {
	x, y int
}

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

	n, x, y := nextInt(), nextInt(), nextInt()
	p := make([]Point, n)
	minShot := 0

	for i := range p {
		p[i].x = nextInt()
		p[i].y = nextInt()
	}

	for i := range p {
		if p[i].x <= 10000 {
			minShot++

			for j := i+1; j < n; j++ {
				if x * (p[i].y - p[j].y) + p[i].x * (p[j].y - y) + p[j].x * (y - p[i].y) == 0 {
					p[j].x = 10001
				}
			}
		}
	}

	println(minShot)
}

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

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

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

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

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

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

package main

import "fmt"

type point struct {
	x int
	y int
}

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

func main() {
	var n, x0, y0, x, y int
	points := make(map[point]bool)
	fmt.Scan(&n, &x0, &y0)
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &y)
		x, y = x-x0, y-y0
		if x < 0 {
			x, y = -x, -y
		}
		if x == 0 {
			y = 1
		}
		if y == 0 {
			x = 1
		}
		for d := 2; d <= abs(x) && d <= abs(y); {
			if x%d == 0 && y%d == 0 {
				x, y = x/d, y/d
			} else {
				d++
			}
		}
		points[point{x, y}] = true
	}
	fmt.Println(len(points))
}

package main

import "fmt"

type point struct {
	x int
	y int
}

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

func main() {
	var n, x0, y0, x, y int
	points := make(map[point]bool)
	fmt.Scan(&n, &x0, &y0)
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &y)
		x, y = x-x0, y-y0
		d := gcd(x, y)
		x, y = x/d, y/d
		points[point{x, y}] = true
	}
	fmt.Println(len(points))
}

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

type Target struct {
  X, Y int
  Done bool
}

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

  n, x, y := getI(), getI(), getI()
  targets := make([]*Target, n)
  for i := 0; i < n; i++ {
    targets[i] = &Target{ X: getI(), Y: getI() }
  }
  count := 0
  for i := 0; i < n; i++ {
    target := targets[i]
    if target.Done {
      continue
    }
    count++
    a, b := target.X - x, target.Y - y
    for j := i+1; j < n; j++ {
      other := targets[j]
      if other.Done {
        continue
      }
      c, d := other.X - x, other.Y - y
      if a*d == b*c {
        other.Done = true
      }
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", count))
}

package main

import (
	"fmt"
	"math"
)

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

	slopes := make([][]int, n)
	for i := 0; i < n; i++ {
		var x, y int
		if _, err := fmt.Scanf("%d %d\n", &x, &y); err != nil {
			return
		}
		// numerator, denominator
		numerator := y - y0
		denominator := x - x0
		// numerator and denominator cannot be both 0
		g := gcd(int(math.Abs(float64(numerator))), int(math.Abs(float64(denominator))))
		numerator = numerator / g
		denominator = denominator / g
		// Make sure that denominator is positive or zero
		if numerator <= 0 && denominator <= 0 || numerator > 0 && denominator < 0 {
			numerator = -numerator
			denominator = -denominator
		}
		slopes[i] = make([]int, 2)
		slopes[i][0] = numerator
		slopes[i][1] = denominator
	}

	shots := 0
	for i := 0; i < n; i++ {
		if slopes[i][1] != -1 { // denominator == 0 means stormtrooper destoried
			shots++
			for j := i + 1; j < n; j++ {
				if slopes[j][0] == slopes[i][0] && slopes[j][1] == slopes[i][1] {
					slopes[j][1] = -1 // Mark as destoried
				}
			}
			slopes[i][1] = -1
		}
	}
	fmt.Println(shots)
}

func gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}
	if y == 0 {
		return x
	} else {
		return gcd(y, x%y)
	}
}

package main

import (
	"fmt"
)

type slope struct {
	// div, rem int
	// sign     bool
	m        float64
	vertical bool
}

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

func getSlope(x0, y0, x1, y1 int) slope {
	if y1 == y0 {
		// return slope{0, 0, false, true}
		return slope{0, true}
	}

	// div := (x1 - x0) / (y1 - y0)
	// rem := abs(x1-x0) % abs(y1-y0)
	// sign := div > 0
	// return slope{abs(div), rem, sign, false}
	return slope{float64(x1-x0) / float64(y1-y0), false}
}

func main() {
	var n, x0, y0 int

	fmt.Scanf("%d %d %d\n", &n, &x0, &y0)

	shots := make(map[slope]bool)
	for i := 0; i < n; i++ {
		var xi, yi int
		fmt.Scanf("%d %d\n", &xi, &yi)
		shots[getSlope(x0, y0, xi, yi)] = true
	}
	fmt.Println(len(shots))
}

package main

// @snippet <contest.go#0.0.1:header/import.go>
import "fmt"
import "io"
import "os"
import "strings"
// @snippet <contest.go#0.0.1:header/typedef.go>
type Int int64
type IntSlice []Int
// @snippet<contest.go#0.0.1:utils/read.go>
var in io.Reader

func ReadInt(n *Int) bool {
  _, err := fmt.Fscan(in, n)
  return err != io.EOF
}

func ReadString(s *string) bool {
  _, err := fmt.Fscan(in, s)
  return err != io.EOF
}

// @snippet <contest.go#0.0.1:utils/stream.go>
func Stdin() io.Reader {
  return os.Stdin
}

func Strin(s string) io.Reader {
  return strings.NewReader(s)
}
// @snippet <contest.go#0.0.1:utils/min.go>

func MinRune(a rune, b rune) rune {
  if a < b {
    return a
  } else {
    return b
  }
}

func MinInt(a Int, b Int) Int {
  if a < b {
    return a
  } else {
    return b
  }
}
// @snippet <contest.go#0.0.1:main.go>

func GcdInt(a Int, b Int) Int {
  if b == 0 {
    return a
  } else {
    return GcdInt(b, a % b)
  }
}

type Solver struct {
  N Int
  X0 Int
  Y0 Int
  X IntSlice
  Y IntSlice
}

func (s *Solver) input() bool {
  if ReadInt(&s.N) {
    if ReadInt(&s.X0) && ReadInt(&s.Y0) {
      s.X = make(IntSlice, s.N)
      s.Y = make(IntSlice, s.N)
      for i := Int(0); i < s.N; i += 1 {
        ReadInt(&s.X[i])
        ReadInt(&s.Y[i])
        s.X[i] -= s.X0
        s.Y[i] -= s.Y0
      }
      return true
    }
  }
  return false
}

type pos struct {
  X Int
  Y Int
}

func AbsInt(x Int) Int {
  if x > 0 {
    return x
  } else {
    return -x
  }
}

func main() {
  in = Stdin()
  s := &Solver{}
  for s.input() {
    m := make(map[pos]bool)
    for i := Int(0); i < s.N; i += 1 {
      if s.X[i] == 0 && s.Y[i] == 0 {
        p := pos{0, 0}
        m[p] = true
      } else if s.X[i] == 0 {
        p := pos{0, 1}
        m[p] = true
      } else if s.Y[i] == 0 {
        p := pos{1, 0}
        m[p] = true
      } else {
        g := GcdInt(s.X[i], s.Y[i])
        p := pos{s.X[i] / g, s.Y[i] / g}
        m[p] = true
      }
    }
    offset := 0
    if m[pos{0, 0}] && (m[pos{0, 1}] || m[pos{1, 0}]) {
      offset = 1
    }
    fmt.Println(len(m) - offset)
  }
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Split(bufio.ScanWords)
	if !sc.Scan() {
		panic("could not scan a word from the reader")
	}
	return sc.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Split(bufio.ScanLines)
	if !sc.Scan() {
		panic("could not scan a line from the reader")
	}
	return sc.Text()
}

func gcd(a, b int) int {
	if a < b {
		return gcd(b, a)
	}
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

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

func mkComp(x, y int) complex64 {
	if x < 0 {
		x, y = -x, -y
	}
	x1 := abs(x)
	y1 := abs(y)
	return complex(float32(x/gcd(x1, y1)), float32(y/gcd(x1, y1)))
}

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

func main() {
	N, X0, Y0 := nextInt(), nextInt(), nextInt()
	sts := make(map[complex64]bool)
	for i := 0; i < N; i++ {
		x, y := nextInt(), nextInt()
		x -= X0
		y -= Y0
		if x == 0 && y == 0 {
			continue
		}
		if y == 0 {
			sts[1] = true
			continue
		}
		if x == 0 {
			sts[1i] = true
			continue
		}
		sts[mkComp(x, y)] = true
	}
	fmt.Println(max(len(sts), 1))
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

var x, y int

func solve(n int) {
	var ans int
	in := make([][3]int, n)
	I(&x, " ")
	I(&y, "\n")
	for i := 0; i < n; i++ {
		I(&in[i][0], " ")
		I(&in[i][1], "\n")
	}
	for i := 0; i < n; i++ {
		if in[i][2] == 1 {
			continue
		}
		ans++
		in[i][2] = 1
		for j := 0; j < n; j++ {
			if oo(in[i], in[j]) {
				in[j][2] = 1
			}
		}
	}
	O(ans, "\n")
}

func oo(a, b [3]int) bool {
	var aa int = 1e7
	if x-a[0] != 0 {
		aa = int((float64(y-a[1])/float64(x-a[0]))*float64(b[0]-a[0]) + float64(a[1]))
	} else if a[0] == b[0] && a[0] == x {
		return true
	}
	return b[1] == aa
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

var x, y int

func solve(n int) {
	var ans int
	in := make([][3]int, n)
	I(&x, " ")
	I(&y, "\n")
	for i := 0; i < n; i++ {
		I(&in[i][0], " ")
		I(&in[i][1], "\n")
	}
	for i := 0; i < n; i++ {
		if in[i][2] == 1 {
			continue
		}
		ans++
		in[i][2] = 1
		for j := 0; j < n; j++ {
			if oo(in[i], in[j]) {
				in[j][2] = 1
			}
		}
	}
	O(ans, "\n")
}

func oo(a, b [3]int) bool {
	var aa int = 1e9
	if x-a[0] != 0 {
		aa = ((y-a[1])/(x-a[0]))*(b[0]-a[0]) + a[1]
	} else if a[0] == b[0] && a[0] == x {
		return true
	}
	return b[1] == aa
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

var x, y int

func solve(n int) {
	var ans int
	in := make([][3]int, n)
	I(&x, " ")
	I(&y, "\n")
	for i := 0; i < n; i++ {
		I(&in[i][0], " ")
		I(&in[i][1], "\n")
	}
	for i := 0; i < n; i++ {
		if in[i][2] == 1 {
			continue
		}
		ans++
		in[i][2] = 1
		for j := 0; j < n; j++ {
			if oo(in[i], in[j]) {
				in[j][2] = 1
			}
		}
	}
	O(ans, "\n")
}

func oo(a, b [3]int) bool {
	aa := 1e7
	if x-a[0] != 0 {
		aa = (float64(y-a[1])/float64(x-a[0]))*float64(b[0]-a[0]) + float64(a[1])
	} else if a[0] == b[0] && a[0] == x {
		return true
	}
	return float64(b[1]) == aa
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

var x, y int

func solve(n int) {
	var ans int
	in := make([][3]int, n)
	I(&x, " ")
	I(&y, "\n")
	for i := 0; i < n; i++ {
		I(&in[i][0], " ")
		I(&in[i][1], "\n")
	}
	for i := 0; i < n; i++ {
		if in[i][2] == 1 {
			continue
		}
		ans++
		in[i][2] = 1
		for j := 0; j < n; j++ {
			if oo(in[i], in[j]) {
				in[j][2] = 1
			}
		}
	}
	O(ans, "\n")
}

func oo(a, b [3]int) bool {
	aa := float64(1e9)
	if x-a[0] != 0 {
		aa = float64(b[1]-y)/float64(float64(y-a[1])/float64(x-a[0])) + float64(x)
	} else if a[0] == b[0] && a[0] == x {
		return true
	}
	return float64(b[0]) == aa
}

package main

import "fmt"

type point struct {
	x int
	y int
}

func main() {
	var n, x0, y0, x, y int
	points := make(map[point]bool)
	fmt.Scan(&n, &x0, &y0)
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &y)
		x, y = x-x0, y-y0
		if x < 0 {
			x, y = -1*x, -1*y
		}
		if x == 0 {
			y = 1
		}
		if y == 0 {
			x = 1
		}
		for d := 2; d <= x && d <= y; d++ {
			if x%d == 0 && y%d == 0 {
				x, y = x/d, y/d
			}
		}
		points[point{x, y}] = true
	}
	fmt.Println(len(points))
}

package main

import "fmt"

type point struct {
	x int
	y int
}

func main() {
	var n, x0, y0, x, y int
	points := make(map[point]bool)
	fmt.Scan(&n, &x0, &y0)
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &y)
		x, y = x-x0, y-y0
		if x < 0 {
			x, y = -1*x, -1*y
		}
		if x == 0 {
			y = 1
		}
		for d := 2; d <= x && d <= y; d++ {
			if x%d == 0 && y%d == 0 {
				x, y = x/d, y/d
			}
		}
		points[point{x, y}] = true
	}
	fmt.Println(len(points))
}

package main

import (
	"fmt"
)

type slope struct {
	div, rem int
	sign     bool
	vertical bool
}

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

func getSlope(x0, y0, x1, y1 int) slope {
	if y1 == y0 {
		return slope{0, 0, false, true}
	}

	div := (x1 - x0) / (y1 - y0)
	rem := abs(x1-x0) % abs(y1-y0)
	sign := div > 0
	return slope{abs(div), rem, sign, false}
}

func main() {
	var n, x0, y0 int

	fmt.Scanf("%d %d %d\n", &n, &x0, &y0)

	shots := make(map[slope]bool)
	for i := 0; i < n; i++ {
		var xi, yi int
		fmt.Scanf("%d %d\n", &xi, &yi)
		shots[getSlope(x0, y0, xi, yi)] = true
	}

	fmt.Println(len(shots))
}

package main

// @snippet <contest.go#0.0.1:header/import.go>
import "fmt"
import "io"
import "os"
import "strings"
// @snippet <contest.go#0.0.1:header/typedef.go>
type Int int64
type IntSlice []Int
// @snippet<contest.go#0.0.1:utils/read.go>
var in io.Reader

func ReadInt(n *Int) bool {
  _, err := fmt.Fscan(in, n)
  return err != io.EOF
}

func ReadString(s *string) bool {
  _, err := fmt.Fscan(in, s)
  return err != io.EOF
}

// @snippet <contest.go#0.0.1:utils/stream.go>
func Stdin() io.Reader {
  return os.Stdin
}

func Strin(s string) io.Reader {
  return strings.NewReader(s)
}
// @snippet <contest.go#0.0.1:utils/min.go>

func MinRune(a rune, b rune) rune {
  if a < b {
    return a
  } else {
    return b
  }
}

func MinInt(a Int, b Int) Int {
  if a < b {
    return a
  } else {
    return b
  }
}
// @snippet <contest.go#0.0.1:main.go>

func GcdInt(a Int, b Int) Int {
  if b == 0 {
    return a
  } else {
    return GcdInt(b, a % b)
  }
}

type Solver struct {
  N Int
  X0 Int
  Y0 Int
  X IntSlice
  Y IntSlice
}

func (s *Solver) input() bool {
  if ReadInt(&s.N) {
    if ReadInt(&s.X0) && ReadInt(&s.Y0) {
      s.X = make(IntSlice, s.N)
      s.Y = make(IntSlice, s.N)
      for i := Int(0); i < s.N; i += 1 {
        ReadInt(&s.X[i])
        ReadInt(&s.Y[i])
        s.X[i] -= s.X0
        s.Y[i] -= s.Y0
      }
      return true
    }
  }
  return false
}

type pos struct {
  X Int
  Y Int
}

func AbsInt(x Int) Int {
  if x > 0 {
    return x
  } else {
    return -x
  }
}

func main() {
  in = Stdin()
  s := &Solver{}
  for s.input() {
    m := make(map[pos]bool)
    for i := Int(0); i < s.N; i += 1 {
      if s.X[i] == 0 && s.Y[i] == 0 {
        p := pos{0, 0}
        m[p] = true
      } else if s.X[i] == 0 {
        p := pos{0, s.Y[i] / AbsInt(s.Y[i])}
        m[p] = true
      } else if s.Y[i] == 0 {
        p := pos{s.X[i] / AbsInt(s.X[i]), 0}
        m[p] = true
      } else {
        g := GcdInt(s.X[i], s.Y[i])
        p := pos{s.X[i] / g, s.Y[i] / g}
        m[p] = true
      }
    }
    fmt.Println(len(m))
  }
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Split(bufio.ScanWords)
	if !sc.Scan() {
		panic("could not scan a word from the reader")
	}
	return sc.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Split(bufio.ScanLines)
	if !sc.Scan() {
		panic("could not scan a line from the reader")
	}
	return sc.Text()
}

func gcd(a, b int) int {
	if a < b {
		return gcd(b, a)
	}
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

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

func mkComp(x, y int) complex64 {
	if x < 0 {
		x, y = -x, -y
	}
	x1 := abs(x)
	y1 := abs(x)
	return complex(float32(x/gcd(x1, y1)), float32(y/gcd(x1, y1)))
}

func main() {
	N, X0, Y0 := nextInt(), nextInt(), nextInt()
	sts := make(map[complex64]bool)
	for i := 0; i < N; i++ {
		x, y := nextInt(), nextInt()
		x -= X0
		y -= Y0
		if y == 0 {
			sts[1] = true
			continue
		}
		if x == 0 {
			sts[1i] = true
			continue
		}
		sts[mkComp(x, y)] = true
	}
	fmt.Println(len(sts))
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Split(bufio.ScanWords)
	if !sc.Scan() {
		panic("could not scan a word from the reader")
	}
	return sc.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Split(bufio.ScanLines)
	if !sc.Scan() {
		panic("could not scan a line from the reader")
	}
	return sc.Text()
}

func gcd(a, b int) int {
	if a < b {
		return gcd(b, a)
	}
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

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

func mkComp(x, y int) complex64 {
	if x < 0 {
		x, y = -x, -y
	}
	x1 := abs(x)
	y1 := abs(x)
	return complex(float32(x/gcd(x1, y1)), float32(y/gcd(x1, y1)))
}

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

func main() {
	N, X0, Y0 := nextInt(), nextInt(), nextInt()
	sts := make(map[complex64]bool)
	for i := 0; i < N; i++ {
		x, y := nextInt(), nextInt()
		x -= X0
		y -= Y0
		if x == 0 && y == 0 {
			continue
		}
		if y == 0 {
			sts[1] = true
			continue
		}
		if x == 0 {
			sts[1i] = true
			continue
		}
		sts[mkComp(x, y)] = true
	}
	fmt.Println(max(len(sts), 1))
}


Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks.

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did. The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:    Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and w is the word that Valentin said.  Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and w is the word that Valentin said.  Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and s is the guess — a lowercase English letter.  All words consist only of lowercase English letters. The total length of all words does not exceed 105. It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter.

Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.

8
! hello
! codeforces
? c
. o
? d
? h
. l
? e

7
! ababahalamaha
? a
? b
? a
? b
? a
? h

NoteIn the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces the word cd and gets an excessive electric shock. In the second test case after the first two electric shocks we understand that the selected letter is e or o. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is e, but Valentin makes 3 more actions before he makes a correct hypothesis.In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks.

package main

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

func solve() {
	lets := make(map[byte]bool)

	n := readInt()
	for j := byte('a'); j <= byte('z'); j++ {
		lets[j] = true
	}
	i := 1
	shocks := 0
	for ; i <= n; i++ {
		result := ([]byte(readString()))[0]
		letters := []byte(readString())

		if len(lets) == 1 {
			if result == '?' && i != n {
				shocks++
			} else if result == '!' {
				shocks++
			}
		}

		switch result {
		case '!':
			m1 := make(map[byte]bool)
			mu := make(map[byte]bool)
			for k, v := range lets {
				if v {
					m1[k] = true
					mu[k] = true
				}
			}

			m2 := make(map[byte]bool)
			for _, c := range letters {
				m2[c] = true
				mu[c] = true
			}

			for k, _ := range mu {
				if m1[k] && m2[k] {
					// intersection with what is
					// still viable and the current
					// string: do nothing
				} else {
					// Not in both sets, not viable
					delete(lets, k)
				}
			}
		case '.', '?':
			for _, c := range letters {
				delete(lets, c)
			}
		}

	}
	fmt.Println(shocks)
}

var scanner *bufio.Scanner

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

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

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

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

package main

import (
  "fmt"
  "bufio"
  "os"
  "strconv"
  "strings"
  /*
  "sort"
  "math"
  */
)

func f(pos [26]int) bool {
  sum := 0
  for i := 0; i < 26; i++ {
    sum += pos[i]
  }
  return sum == 1
}

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

  n := ReadInt32()
  var pos [26]int
  for i := 0; i < 26; i++ {
    pos[i] = 1
  }
  ans := 0
  for i := 0; i < n - 1; i++ {
    scanner.Scan()
    event := scanner.Text()
    scanner.Scan()
    word := scanner.Text()
    if f(pos) && (event == "!" || event == "?") {
      ans++
    }
    if event == "!" {
      for j := 0; j < 26; j++ {
        if !strings.ContainsRune(word, rune('a' + j)) {
          pos[j] = 0
        }
      }
    } else {
      for j := 0; j < 26; j++ {
        if strings.ContainsRune(word, rune('a' + j)) {
          pos[j] = 0
        }
      }
    }
  }
  fmt.Println(ans)

}

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

func ReadInt32() int {
  scanner.Scan()
  ans, _ := strconv.Atoi(scanner.Text())
  return ans
}

func PrintInts(ints ...int) {
  for _, value := range ints {
    writer.WriteString(strconv.Itoa(value))
    writer.WriteByte(' ')
  }
}

package main

import (
  "fmt"
  "bufio"
  "os"
  "strconv"
  "strings"
  /*
  "sort"
  "math"
  */
)

func f(pos [26]int) bool {
  sum := 0
  for i := 0; i < 26; i++ {
    sum += pos[i]
  }
  return sum == 1
}

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

  n := ReadInt32()
  var pos [26]int
  for i := 0; i < 26; i++ {
    pos[i] = 1
  }
  ans := 0
  for i := 0; i < n - 1; i++ {
    scanner.Scan()
    event := scanner.Text()
    scanner.Scan()
    word := scanner.Text()
    if f(pos) && (event == "!" || event == "?") {
      ans++
    }
    if event == "!" {
      for j := 0; j < 26; j++ {
        if !strings.ContainsRune(word, rune('a' + j)) {
          pos[j] = 0
        }
      }
    }
    if event == "." {
      for j := 0; j < 26; j++ {
        if strings.ContainsRune(word, rune('a' + j)) {
          pos[j] = 0
        }
      }
    }
  }
  fmt.Print(ans)

}

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

func ReadInt32() int {
  scanner.Scan()
  ans, _ := strconv.Atoi(scanner.Text())
  return ans
}

func PrintInts(ints ...int) {
  for _, value := range ints {
    writer.WriteString(strconv.Itoa(value))
    writer.WriteByte(' ')
  }
}


В самолёте есть n рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, которые часто летают) и обычные. Перед вами стоит задача рассадить ещё k обычных пассажиров так, чтобы суммарное число соседей у статусных пассажиров было минимально возможным. Два пассажира считаются соседями, если они сидят в одном ряду и между ними нет других мест и прохода между рядами. Если пассажир является соседним пассажиром для двух статусных пассажиров, то его следует учитывать в сумме соседей дважды.

В первой строке следуют два целых числа n и k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10·n) — количество рядов мест в самолёте и количество пассажиров, которых нужно рассадить. Далее следует описание рядов мест самолёта по одному ряду в строке. Если очередной символ равен '-', то это проход между рядами. Если очередной символ равен '.', то это свободное место. Если очередной символ равен 'S', то на текущем месте будет сидеть статусный пассажир. Если очередной символ равен 'P', то на текущем месте будет сидеть обычный пассажир.  Гарантируется, что количество свободных мест не меньше k. Гарантируется, что все ряды удовлетворяют описанному в условии формату.

В первую строку выведите минимальное суммарное число соседей у статусных пассажиров. Далее выведите план рассадки пассажиров, который минимизирует суммарное количество соседей у статусных пассажиров, в том же формате, что и во входных данных. Если в свободное место нужно посадить одного из k пассажиров, выведите строчную букву 'x' вместо символа '.'.

4 9
PP.-PPPS-S.S
PSP-PPSP-.S.
.S.-S..P-SS.
P.S-P.PP-PSP

15
PPx-PPPS-S.S
PSP-PPSP-xSx
xSx-SxxP-SSx
P.S-PxPP-PSP

ПримечаниеВ первом примере нужно посадить ещё двух обычных пассажиров. Для минимизации соседей у статусных пассажиров, нужно посадить первого из них на третье слева место, а второго на любое из оставшихся двух мест, так как независимо от выбора места он станет соседом двух статусных пассажиров. Изначально, у статусного пассажира, который сидит на самом левом месте уже есть сосед. Также на четвёртом и пятом местах слева сидят статусные пассажиры, являющиеся соседями друг для друга (что добавляет к сумме 2).Таким образом, после посадки ещё двух обычных пассажиров, итоговое суммарное количество соседей у статусных пассажиров станет равно пяти.

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
	"sort"
)

type Candidate struct {
	posI, posJ, cost int
}

var (
	data       [][12]byte
	candidates []Candidate
	n, k, ans  int
)

func main() {
	debug.SetGCPercent(-1)

	read()

	do()

	print()
}

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

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &k)

	data = make([][12]byte, n)
	candidates = make([]Candidate, 0, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		bytes := scanner.Bytes()

		for j := 0; j < 12; j++ {
			data[i][j] = bytes[j]

			if bytes[j] == '.' {
				cost := 0

				if j != 0 && bytes[j-1] == 'S' {
					cost++
				}

				if j != 11 && bytes[j+1] == 'S' {
					cost++
				}

				candidates = append(candidates, Candidate{posI: i, posJ: j, cost: cost})
			} else if bytes[j] == 'S' {
				if j != 0 && (bytes[j-1] == 'P' || bytes[j-1] == 'S') {
					ans++
				}

				if j != 11 && (bytes[j+1] == 'P' || bytes[j+1] == 'S') {
					ans++
				}
			}
		}
	}
}

func print() {
	fmt.Println(ans)

	for i := 0; i < n; i++ {
		fmt.Printf("%s\n", data[i])
	}
}

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

	for i := 0; i < k; i++ {
		pI, pJ := candidates[i].posI, candidates[i].posJ

		data[pI][pJ] = 'x'

		ans += candidates[i].cost
	}
}

package main

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

type Candidate struct {
	posI, posJ, cost int
}

var (
	data       [][12]byte
	candidates []Candidate
	n, k, ans  int
)

func main() {
	read()

	do()

	print()
}

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

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &k)

	data = make([][12]byte, n)
	candidates = make([]Candidate, 0, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		bytes := scanner.Bytes()

		for j := 0; j < 12; j++ {
			data[i][j] = bytes[j]

			if bytes[j] == '.' {
				cost := 0

				if j != 0 && bytes[j-1] == 'S' {
					cost++
				}

				if j != 11 && bytes[j+1] == 'S' {
					cost++
				}

				candidates = append(candidates, Candidate{posI: i, posJ: j, cost: cost})
			} else if bytes[j] == 'S' {
				if j != 0 && (bytes[j-1] == 'P' || bytes[j-1] == 'S') {
					ans++
				}

				if j != 11 && (bytes[j+1] == 'P' || bytes[j+1] == 'S') {
					ans++
				}
			}
		}
	}
}

func print() {
	fmt.Println(ans)

	for i := 0; i < n; i++ {
		fmt.Printf("%s\n", data[i])
	}
}

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

	for i := 0; i < k; i++ {
		pI, pJ := candidates[i].posI, candidates[i].posJ

		data[pI][pJ] = 'x'

		ans += candidates[i].cost
	}
}

package main

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

type Place uint8

const (
	Free Place = iota
	Status
	Simple
	Unavailable
	Sit
)

type Row struct {
	place [12]Place
}

func (r *Row) GetNeigh(place int) int {
	cnt := 0

	if r.place[place] != Status {
		return cnt
	}

	if place > 0 && r.place[place - 1] != Free && r.place[place - 1] != Unavailable {
		cnt++
	}
	if place < 11 && r.place[place + 1] != Free && r.place[place + 1] != Unavailable {
		cnt++
	}

	return cnt
}

func (r *Row) GetPrediction(place int) int {
	cnt := 0

	if place > 0 && (r.place[place - 1] == Status){
		cnt++
	}
	if place < 11 && (r.place[place + 1] == Status) {
		cnt++
	}

	return cnt
}

func printRows(rows []*Row) {
	for _, v := range rows {
		var row string
		for _, v := range v.place {
			switch v {
			case Status:
				row += "S"
			case Simple:
				row += "P"
			case Free:
				row += "."
			case Unavailable:
				row += "-"
			case Sit:
				row += "x"
			}
		}
		fmt.Println(row)
	}
}

func printCount(rows []*Row) {
	cnt := 0

	for _, v := range rows {
		for i := range v.place {
			cnt += v.GetNeigh(i)
		}
	}

	fmt.Println(cnt)
}

func main() {
	var rowsCount, pass int
	fmt.Scanln(&rowsCount, &pass)

	rows := make([]*Row, 0, rowsCount)
	reader := bufio.NewScanner(os.Stdin)
	for i := 0; i < rowsCount; i++ {
		row := &Row{}

		reader.Scan()
		line := reader.Text()
		for i, v := range line {
			switch v {
			case 'S':
				row.place[i] = Status
			case 'P':
				row.place[i] = Simple
			case '.':
				row.place[i] = Free
			case '-':
				row.place[i] = Unavailable
			}
		}

		rows = append(rows, row)
	}

	for _, v := range rows {
		for i, place := range v.place {
			if place != Free {
				continue
			}

			if v.GetPrediction(i) != 0 {
				continue
			}

			v.place[i] = Sit
			pass--
			if pass == 0 {
				goto exit
			}
		}
	}

	for _, v := range rows {
		for i, place := range v.place {
			if place != Free {
				continue
			}

			if v.GetPrediction(i) != 1 {
				continue
			}

			v.place[i] = Sit
			pass--
			if pass == 0 {
				goto exit
			}
		}
	}

	for _, v := range rows {
		for i, place := range v.place {
			if place != Free {
				continue
			}

			v.place[i] = Sit
			pass--
			if pass == 0 {
				goto exit
			}
		}
	}

exit:
	printCount(rows)
	printRows(rows)
}

package main

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

var (
	data     [][]byte
	n        int
	k        int
	counters [3]int
	ans      int
	// 0 - никого нет
	// 1 - 1 сосед S
	// 2 - 2 соседа S
)

func main() {
	read()

	do()

	print()
}

func read() {
	scanner := bufio.NewScanner(os.Stdin)
	//f, _ := os.Open("input")
	//scanner := bufio.NewScanner(f)

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &k)

	data = make([][]byte, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		data[i] = scanner.Bytes()

		for j := 1; j < 11; j++ {
			if data[i][j] == '.' {
				if data[i][j-1] != 'S' && data[i][j+1] != 'S' {
					counters[0]++
				} else if (data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S') {
					counters[1]++
				} else {
					counters[2]++
				}
			}
		}

		if data[i][0] == '.' {
			if data[i][1] != 'S' {
				counters[0]++
			} else {
				counters[1]++
			}
		}

		if data[i][11] == '.' {
			if data[i][10] != 'S' {
				counters[0]++
			} else {
				counters[1]++
			}
		}
	}

	if scanner.Err() != nil {
		fmt.Println(scanner.Err())
	}
}

func do() {
	var flag int
	var count int

	if counters[0] >= k {
		flag = 1
	} else if counters[0]+counters[1] >= k {
		flag = 2
		count = k - counters[0]
	} else {
		flag = 3
		count = k - counters[0] - counters[1]
	}

	//fmt.Printf("k = %d\nCount[0] = %d\nCount[1] = %d\nCount[2] = %d\n", k, counters[0], counters[1], counters[2])
	//fmt.Printf("flag = %d\ncount = %d\n", flag, count)
	//for count != 0 || k != 0 {
	for i := 0; i < n; i++ {
		for j := 1; j < 11; j++ {

			if count < 0 {
				fmt.Printf("count < 0: i = %d j = %d\n", i, j)
			}

			if k > 0 {
				switch flag {
				case 3:
					if data[i][j] == '.' && count > 0 && data[i][j-1] == 'S' && data[i][j+1] == 'S' {
						data[i][j] = 'x'
						k--
						count--

					}

					fallthrough
				case 2:
					if flag == 2 {
						if data[i][j] == '.' && count > 0 && ((data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S')) {
							data[i][j] = 'x'
							k--
							count--

						}
					} else if data[i][j] == '.' && ((data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S')) {
						data[i][j] = 'x'
						k--

					}

					fallthrough
				case 1:
					if data[i][j] == '.' && data[i][j-1] != 'S' && data[i][j+1] != 'S' {
						data[i][j] = 'x'
						k--
					}
				}
			}
		}

		switch flag {
		case 3:
			fallthrough
		case 2:
			if k > 0 && data[i][0] == '.' {
				if data[i][1] != 'S' {
					data[i][0] = 'x'
					k--
				} else if flag == 2 && count > 0 {
					data[i][0] = 'x'
					k--
					count--
				} else if flag == 3 {
					data[i][0] = 'x'
					k--
				}
			}

			if k > 0 && data[i][11] == '.' {
				if data[i][10] != 'S' {
					data[i][11] = 'x'
					k--
				} else if flag == 2 && count > 0 {
					data[i][11] = 'x'
					k--
					count--
				} else if flag == 3 {
					data[i][11] = 'x'
					k--
				}
			}
		case 1:
			if k > 0 && data[i][0] == '.' && data[i][1] != 'S' {
				data[i][0] = 'x'
				k--
			}

			if k > 0 && data[i][11] == '.' && data[i][10] != 'S' {
				data[i][11] = 'x'
				k--
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < 12; j++ {
			if data[i][j] == 'S' {
				if j != 0 && (data[i][j-1] == 'P' || data[i][j-1] == 'x' || data[i][j-1] == 'S') {
					ans++
				}
				if j != 11 && (data[i][j+1] == 'P' || data[i][j+1] == 'x' || data[i][j+1] == 'S') {
					ans++
				}
			}
		}
	}
	//}
	/*if count != 0 || k != 0 {
		panic("count != 0 || k != 0")
	}*/

	//fmt.Printf("count = %d\nk = %d\n", count, k)
}

func print() {
	fmt.Println(ans)
	for i := 0; i < n; i++ {
		fmt.Printf("%s\n", data[i])
	}
}

package main

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

type Candidate struct {
	posI, posJ, cost int
}

var (
	data       [][]byte
	candidates []Candidate
	n, k       int
)

func main() {
	read()

	do()

	print()
}

func read() {
	scanner := bufio.NewScanner(os.Stdin)
	// f, _ := os.Open("input")
	// scanner := bufio.NewScanner(f)

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &k)

	data = make([][]byte, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		data[i] = scanner.Bytes()
	}

	if scanner.Err() != nil {
		fmt.Println(scanner.Err())
		panic("err")
	}
}

func print() {
	ans := 0
	for i := 0; i < n; i++ {
		for j := 0; j < 12; j++ {
			if data[i][j] == 'S' {
				if j != 0 && (data[i][j-1] == 'P' || data[i][j-1] == 'x' || data[i][j-1] == 'S') {
					ans++
				}
				if j != 11 && (data[i][j+1] == 'P' || data[i][j+1] == 'x' || data[i][j+1] == 'S') {
					ans++
				}
			}
		}
	}

	fmt.Println(ans)

	for i := 0; i < n; i++ {
		fmt.Printf("%s\n", data[i])
	}
}

func do() {
	for i := 0; i < n; i++ {
		for j := 0; j < 12; j++ {
			if data[i][j] == '.' {
				cost := 0

				if j != 0 && data[i][j-1] == 'S' {
					cost++
				}

				if j != 11 && data[i][j+1] == 'S' {
					cost++
				}

				candidates = append(candidates, Candidate{posI: i, posJ: j, cost: cost})
			}
		}
	}

	if len(candidates) < k {
		panic("bad candidates len")
	}

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

	for i := 0; i < k; i++ {
		pI, pJ := candidates[i].posI, candidates[i].posJ

		data[pI][pJ] = 'x'
	}
}

package main

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

type Candidate struct {
	posI, posJ, cost int
}

var (
	data       [][]byte
	candidates []Candidate
	n, k       int
)

func main() {
	read()

	do()

	print()
}

func read() {
	// scanner := bufio.NewScanner(os.Stdin)
	f, _ := os.Open("input")
	scanner := bufio.NewScanner(f)

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &k)

	data = make([][]byte, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		data[i] = scanner.Bytes()
	}

	if scanner.Err() != nil {
		fmt.Println(scanner.Err())
	}
}

func print() {
	ans := 0
	for i := 0; i < n; i++ {
		for j := 0; j < 12; j++ {
			if data[i][j] == 'S' {
				if j != 0 && (data[i][j-1] == 'P' || data[i][j-1] == 'x' || data[i][j-1] == 'S') {
					ans++
				}
				if j != 11 && (data[i][j+1] == 'P' || data[i][j+1] == 'x' || data[i][j+1] == 'S') {
					ans++
				}
			}
		}
	}

	fmt.Println(ans)

	for i := 0; i < n; i++ {
		fmt.Printf("%s\n", data[i])
	}
}

func do() {
	for i := 0; i < n; i++ {
		for j := 0; j < 12; j++ {
			if data[i][j] == '.' {
				cost := 0

				if j != 0 && data[i][j-1] == 'S' {
					cost++
				}

				if j != 11 && data[i][j+1] == 'S' {
					cost++
				}

				candidates = append(candidates, Candidate{posI: i, posJ: j, cost: cost})
			}
		}
	}

	if len(candidates) < k {
		panic("bad candidates len")
	}

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

	for i := 0; i < k; i++ {
		pI, pJ := candidates[i].posI, candidates[i].posJ

		data[pI][pJ] = 'x'
	}
}

package main

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

var (
	data     [][]byte
	n        int
	k        int
	counters [3]int
	ans      int
	// 0 - никого нет
	// 1 - 1 сосед S
	// 2 - 2 соседа S
)

func main() {
	read()

	do()

	print()
}

func read() {
	scanner := bufio.NewScanner(os.Stdin)
	//f, _ := os.Open("input")
	//scanner := bufio.NewScanner(f)

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &k)

	data = make([][]byte, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		data[i] = scanner.Bytes()

		for j := 1; j < 11; j++ {
			if data[i][j] == '.' {
				if data[i][j-1] != 'S' && data[i][j+1] != 'S' {
					counters[0]++
				} else if (data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S') {
					counters[1]++
				} else {
					counters[2]++
				}
			}
		}

		if data[i][0] == '.' {
			if data[i][1] != 'S' {
				counters[0]++
			} else {
				counters[1]++
			}
		}

		if data[i][11] == '.' {
			if data[i][10] != 'S' {
				counters[0]++
			} else {
				counters[1]++
			}
		}
	}

	if scanner.Err() != nil {
		fmt.Println(scanner.Err())
	}
}

func do() {
	var flag int
	var count int

	if counters[0] >= k {
		flag = 1
	} else if counters[0]+counters[1] >= k {
		flag = 2
		count = k - counters[0]
	} else {
		flag = 3
		count = k - counters[0] - counters[1]
	}

	//fmt.Printf("k = %d\nCount[0] = %d\nCount[1] = %d\nCount[2] = %d\n", k, counters[0],counters[1],counters[2])
	//fmt.Printf("flag = %d\ncount = %d\n", flag, count);

	for i := 0; i < n; i++ {
		for j := 1; j < 11; j++ {
			if k > 0 && data[i][j] == '.' {
				switch flag {
				case 3:
					if count > 0 && data[i][j-1] == 'S' && data[i][j+1] == 'S' {
						data[i][j] = 'x'
						k--
						count--
					}
					fallthrough
				case 2:
					if flag == 2 {
						if count > 0 && ((data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S')) {
							data[i][j] = 'x'
							k--
							count--
						}
					} else {
						if (data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S') {
							data[i][j] = 'x'
							k--
						}
					}
					fallthrough
				case 1:
					if data[i][j-1] != 'S' && data[i][j+1] != 'S' {
						data[i][j] = 'x'
						k--
					}
				}
			}
		}

		switch flag {
		case 3:
		case 2:
			if data[i][0] == '.' {
				if data[i][1] != 'S' {
					data[i][0] = 'x'
					k--
				} else if count > 0 {
					data[i][0] = 'x'
					k--
					count--
				}
			}

			if data[i][11] == '.' {
				if data[i][10] != 'S' {
					data[i][11] = 'x'
					k--
				} else if count > 0 {
					data[i][11] = 'x'
					k--
					count--
				}
			}
		case 1:
			if data[i][0] == '.' && data[i][1] != 'S' {
				data[i][0] = 'x'
				k--
			}

			if data[i][11] == '.' && data[i][10] != 'S' {
				data[i][11] = 'x'
				k--
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < 12; j++ {
			if data[i][j] == 'S' {
				if j != 0 && (data[i][j-1] == 'P' || data[i][j-1] == 'x' || data[i][j-1] == 'S') {
					ans++
				}
				if j != 11 && (data[i][j+1] == 'P' || data[i][j+1] == 'x' || data[i][j+1] == 'S') {
					ans++
				}
			}
		}
	}
}

func print() {
	fmt.Println(ans)
	for i := 0; i < n; i++ {
		fmt.Printf("%s\n", data[i])
	}
}

package main

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

var (
	data     [][]byte
	n        int
	k        int
	counters [3]int
	ans      int
	// 0 - никого нет
	// 1 - 1 сосед S
	// 2 - 2 соседа S
)

func main() {
	read()

	do()

	print()
}

func read() {
	scanner := bufio.NewScanner(os.Stdin)
	// f, _ := os.Open("input")
	// scanner := bufio.NewScanner(f)

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &k)

	data = make([][]byte, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		data[i] = scanner.Bytes()

		for j := 1; j < 11; j++ {
			if data[i][j] == '.' {
				if data[i][j-1] != 'S' && data[i][j+1] != 'S' {
					counters[0]++
				} else if (data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S') {
					counters[1]++
				} else {
					counters[2]++
				}
			}
		}

		if data[i][0] == '.' {
			if data[i][1] != 'S' {
				counters[0]++
			} else {
				counters[1]++
			}
		}

		if data[i][11] == '.' {
			if data[i][10] != 'S' {
				counters[0]++
			} else {
				counters[1]++
			}
		}
	}

	if scanner.Err() != nil {
		fmt.Println(scanner.Err())
	}
}

func do() {
	var flag int
	var count int

	if counters[0] >= k {
		flag = 1
	} else if counters[0]+counters[1] >= k {
		flag = 2
		count = k - counters[0]
	} else {
		flag = 3
		count = k - counters[0] - counters[1]
	}

	//fmt.Printf("k = %d\nCount[0] = %d\nCount[1] = %d\nCount[2] = %d\n", k, counters[0],counters[1],counters[2])
	//fmt.Printf("flag = %d\ncount = %d\n", flag, count);

	for i := 0; i < n; i++ {
		for j := 1; j < 11; j++ {
			if k > 0 && data[i][j] == '.' {
				switch flag {
				case 3:
					if count > 0 && data[i][j-1] == 'S' && data[i][j+1] == 'S' {
						data[i][j] = 'x'
						k--
						count--
						break
					}

					fallthrough
				case 2:
					if flag == 2 {
						if count > 0 && ((data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S')) {
							data[i][j] = 'x'
							k--
							count--
							break
						}
					} else if (data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S') {
						data[i][j] = 'x'
						k--
						break
					}

					fallthrough
				case 1:
					if data[i][j-1] != 'S' && data[i][j+1] != 'S' {
						data[i][j] = 'x'
						k--
					}
				}
			}
		}

		switch flag {
		case 3:
		case 2:
			if k > 0 && data[i][0] == '.' {
				if data[i][1] != 'S' {
					data[i][0] = 'x'
					k--
				} else if count > 0 {
					data[i][0] = 'x'
					k--
					count--
				}
			}

			if k > 0 && data[i][11] == '.' {
				if data[i][10] != 'S' {
					data[i][11] = 'x'
					k--
				} else if count > 0 {
					data[i][11] = 'x'
					k--
					count--
				}
			}
		case 1:
			if k > 0 && data[i][0] == '.' && data[i][1] != 'S' {
				data[i][0] = 'x'
				k--
			}

			if k > 0 && data[i][11] == '.' && data[i][10] != 'S' {
				data[i][11] = 'x'
				k--
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < 12; j++ {
			if data[i][j] == 'S' {
				if j != 0 && (data[i][j-1] == 'P' || data[i][j-1] == 'x' || data[i][j-1] == 'S') {
					ans++
				}
				if j != 11 && (data[i][j+1] == 'P' || data[i][j+1] == 'x' || data[i][j+1] == 'S') {
					ans++
				}
			}
		}
	}
}

func print() {
	fmt.Println(ans)
	for i := 0; i < n; i++ {
		fmt.Printf("%s\n", data[i])
	}
}

package main

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

var (
	data     [][]byte
	n        int
	k        int
	counters [3]int
	ans      int
	// 0 - никого нет
	// 1 - 1 сосед S
	// 2 - 2 соседа S
)

func main() {
	read()

	do()

	print()
}

func read() {
	scanner := bufio.NewScanner(os.Stdin)
	// f, _ := os.Open("input")
	// scanner := bufio.NewScanner(f)

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &k)

	data = make([][]byte, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		data[i] = scanner.Bytes()

		for j := 1; j < 11; j++ {
			if data[i][j] == '.' {
				if data[i][j-1] != 'S' && data[i][j+1] != 'S' {
					counters[0]++
				} else if (data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S') {
					counters[1]++
				} else {
					counters[2]++
				}
			}
		}

		if data[i][0] == '.' {
			if data[i][1] != 'S' {
				counters[0]++
			} else {
				counters[1]++
			}
		}

		if data[i][11] == '.' {
			if data[i][10] != 'S' {
				counters[0]++
			} else {
				counters[1]++
			}
		}
	}

	if scanner.Err() != nil {
		fmt.Println(scanner.Err())
	}
}

func do() {
	var flag int
	var count int

	if counters[0] >= k {
		flag = 1
	} else if counters[0]+counters[1] >= k {
		flag = 2
		count = k - counters[0]
	} else {
		flag = 3
		count = k - counters[0] - counters[1]
	}

	//fmt.Printf("k = %d\nCount[0] = %d\nCount[1] = %d\nCount[2] = %d\n", k, counters[0],counters[1],counters[2])
	//fmt.Printf("flag = %d\ncount = %d\n", flag, count);

	for i := 0; i < n; i++ {
		for j := 1; j < 11; j++ {
			if k > 0 {
				switch flag {
				case 3:
					if data[i][j] == '.' && count > 0 && data[i][j-1] == 'S' && data[i][j+1] == 'S' {
						data[i][j] = 'x'
						k--
						count--

					}

					fallthrough
				case 2:
					if flag == 2 {
						if data[i][j] == '.' && count > 0 && ((data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S')) {
							data[i][j] = 'x'
							k--
							count--

						}
					} else if data[i][j] == '.' && ((data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S')) {
						data[i][j] = 'x'
						k--

					}

					fallthrough
				case 1:
					if data[i][j] == '.' && data[i][j-1] != 'S' && data[i][j+1] != 'S' {
						data[i][j] = 'x'
						k--
					}
				}
			}
		}

		switch flag {
		case 3:
		case 2:
			if k > 0 && data[i][0] == '.' {
				if data[i][1] != 'S' {
					data[i][0] = 'x'
					k--
				} else if count > 0 {
					data[i][0] = 'x'
					k--
					count--
				}
			}

			if k > 0 && data[i][11] == '.' {
				if data[i][10] != 'S' {
					data[i][11] = 'x'
					k--
				} else if count > 0 {
					data[i][11] = 'x'
					k--
					count--
				}
			}
		case 1:
			if k > 0 && data[i][0] == '.' && data[i][1] != 'S' {
				data[i][0] = 'x'
				k--
			}

			if k > 0 && data[i][11] == '.' && data[i][10] != 'S' {
				data[i][11] = 'x'
				k--
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < 12; j++ {
			if data[i][j] == 'S' {
				if j != 0 && (data[i][j-1] == 'P' || data[i][j-1] == 'x' || data[i][j-1] == 'S') {
					ans++
				}
				if j != 11 && (data[i][j+1] == 'P' || data[i][j+1] == 'x' || data[i][j+1] == 'S') {
					ans++
				}
			}
		}
	}
}

func print() {
	fmt.Println(ans)
	for i := 0; i < n; i++ {
		fmt.Printf("%s\n", data[i])
	}
}

package main

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

var (
	data     [][]byte
	n        int
	k        int
	counters [3]int
	ans      int
	// 0 - никого нет
	// 1 - 1 сосед S
	// 2 - 2 соседа S
)

func main() {
	read()

	do()

	print()
}

func read() {
	scanner := bufio.NewScanner(os.Stdin)
	//f, _ := os.Open("input")
	//scanner := bufio.NewScanner(f)

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &k)

	data = make([][]byte, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		data[i] = scanner.Bytes()

		for j := 1; j < 11; j++ {
			if data[i][j] == '.' {
				if data[i][j-1] != 'S' && data[i][j+1] != 'S' {
					counters[0]++
				} else if (data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S') {
					counters[1]++
				} else {
					counters[2]++
				}
			}
		}

		if data[i][0] == '.' {
			if data[i][1] != 'S' {
				counters[0]++
			} else {
				counters[1]++
			}
		}

		if data[i][11] == '.' {
			if data[i][10] != 'S' {
				counters[0]++
			} else {
				counters[1]++
			}
		}
	}

	if scanner.Err() != nil {
		fmt.Println(scanner.Err())
	}
}

func do() {
	var flag int
	var count int

	if counters[0] >= k {
		flag = 1
	} else if counters[0]+counters[1] >= k {
		flag = 2
		count = k - counters[0]
	} else {
		flag = 3
		count = k - counters[0] - counters[1]
	}

	//fmt.Printf("k = %d\nCount[0] = %d\nCount[1] = %d\nCount[2] = %d\n", k, counters[0],counters[1],counters[2])
	//fmt.Printf("flag = %d\ncount = %d\n", flag, count);

	for i := 0; i < n; i++ {
		for j := 1; j < 11; j++ {
			if k > 0 && data[i][j] == '.' {
				switch flag {
				case 3:
					if count > 0 && data[i][j-1] == 'S' && data[i][j+1] == 'S' {
						data[i][j] = 'x'
						k--
						count--
					}
					fallthrough
				case 2:
					if flag == 2 {
						if count > 0 && ((data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S')) {
							data[i][j] = 'x'
							k--
							count--
						}
					} else {
						if (data[i][j-1] == 'S' && data[i][j+1] != 'S') || (data[i][j-1] != 'S' && data[i][j+1] == 'S') {
							data[i][j] = 'x'
							k--
						}
					}
					fallthrough
				case 1:
					if data[i][j-1] != 'S' && data[i][j+1] != 'S' {
						data[i][j] = 'x'
						k--
					}
				}
			}
		}

		switch flag {
		case 3:
		case 2:
			if k > 0 && data[i][0] == '.' {
				if data[i][1] != 'S' {
					data[i][0] = 'x'
					k--
				} else if count > 0 {
					data[i][0] = 'x'
					k--
					count--
				}
			}

			if k > 0 && data[i][11] == '.' {
				if data[i][10] != 'S' {
					data[i][11] = 'x'
					k--
				} else if count > 0 {
					data[i][11] = 'x'
					k--
					count--
				}
			}
		case 1:
			if k > 0 && data[i][0] == '.' && data[i][1] != 'S' {
				data[i][0] = 'x'
				k--
			}

			if k > 0 && data[i][11] == '.' && data[i][10] != 'S' {
				data[i][11] = 'x'
				k--
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < 12; j++ {
			if data[i][j] == 'S' {
				if j != 0 && (data[i][j-1] == 'P' || data[i][j-1] == 'x' || data[i][j-1] == 'S') {
					ans++
				}
				if j != 11 && (data[i][j+1] == 'P' || data[i][j+1] == 'x' || data[i][j+1] == 'S') {
					ans++
				}
			}
		}
	}
}

func print() {
	fmt.Println(ans)
	for i := 0; i < n; i++ {
		fmt.Printf("%s\n", data[i])
	}
}