There are $$$n$$$ left boots and $$$n$$$ right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings $$$l$$$ and $$$r$$$, both of length $$$n$$$. The character $$$l_i$$$ stands for the color of the $$$i$$$-th left boot and the character $$$r_i$$$ stands for the color of the $$$i$$$-th right boot.A lowercase Latin letter denotes a specific color, but the question mark ('?') denotes an indefinite color. Two specific colors are compatible if they are exactly the same. An indefinite color is compatible with any (specific or indefinite) color.For example, the following pairs of colors are compatible: ('f', 'f'), ('?', 'z'), ('a', '?') and ('?', '?'). The following pairs of colors are not compatible: ('f', 'g') and ('a', 'z').Compute the maximum number of pairs of boots such that there is one left and one right boot in a pair and their colors are compatible.Print the maximum number of such pairs and the pairs themselves. A boot can be part of at most one pair.

The first line contains $$$n$$$ ($$$1 \le n \le 150000$$$), denoting the number of boots for each leg (i.e. the number of left boots and the number of right boots). The second line contains the string $$$l$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th left boot. The third line contains the string $$$r$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th right boot.

Print $$$k$$$ — the maximum number of compatible left-right pairs of boots, i.e. pairs consisting of one left and one right boot which have compatible colors. The following $$$k$$$ lines should contain pairs $$$a_j, b_j$$$ ($$$1 \le a_j, b_j \le n$$$). The $$$j$$$-th of these lines should contain the index $$$a_j$$$ of the left boot in the $$$j$$$-th pair and index $$$b_j$$$ of the right boot in the $$$j$$$-th pair. All the numbers $$$a_j$$$ should be distinct (unique), all the numbers $$$b_j$$$ should be distinct (unique). If there are many optimal answers, print any of them.

package main

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

type shuts struct {
	lshut []int
	rshut []int
}

type boots [][2]int

func (s boots) Len() int {
	return len(s)
}
func (s boots) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s boots) Less(i, j int) bool {
	return s[i][0] < s[j][0]
}

type boots2 [][2]int

func (s boots2) Len() int {
	return len(s)
}
func (s boots2) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s boots2) Less(i, j int) bool {
	return s[i][0] > s[j][0]
}

func main() {

	read := bufio.NewReader(os.Stdin)
	write := bufio.NewWriter(os.Stdout)
	var n int
	var lstr, rstr string

	propar := make(map[int]shuts)

	fmt.Fscan(read, &n)
	fmt.Fscan(read, &lstr)
	fmt.Fscan(read, &rstr)

	var res [][2]int
	var lxv [][2]int
	var rxv [][2]int

	for i := 0; i < n; i++ {
		lc := int(lstr[i])
		if lc != 63 {
			shu := propar[lc]
			shu.lshut = append(shu.lshut, i+1)
			propar[lc] = shu
		} else {
			bot := [2]int{63, i + 1}
			lxv = append(lxv, bot)
		}

		rc := int(rstr[i])
		if rc != 63 {
			shu := propar[rc]
			shu.rshut = append(shu.rshut, i+1)
			propar[rc] = shu
		} else {
			bot := [2]int{63, i + 1}
			rxv = append(rxv, bot)
		}
	}

	for color, shu := range propar {
		nl := len(shu.lshut)
		nr := len(shu.rshut)
		nmin := nl
		nmax := nr
		amax := shu.rshut
		lrmax := 1
		if nmin > nr {
			nmin = nr
			nmax = nl
			amax = shu.lshut
			lrmax = 0
		}

		for i := 0; i < nmin; i++ {
			para := [2]int{shu.lshut[i], shu.rshut[i]}
			res = append(res, para)
		}
		for i := nmin; i < nmax; i++ {
			bot := [2]int{color, amax[i]}
			if lrmax == 0 {
				lxv = append(lxv, bot)
			} else {
				rxv = append(rxv, bot)
			}
		}

	}
	sort.Sort(boots(lxv))
	sort.Sort(boots2(rxv))
	nx := len(lxv)
	for i := 0; i < nx; i++ {
		if lxv[i][0] == 63 || rxv[i][0] == 63 {
			para := [2]int{lxv[i][1], rxv[i][1]}
			res = append(res, para)
		}
	}
	nres := len(res)
	fmt.Fprintln(write, nres)
	for i := 0; i < nres; i++ {
		fmt.Fprintln(write, res[i][0], res[i][1])
	}
	write.Flush()

}

/*
10
codeforces
dodivthree
*/

package main

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

func addD(m map[byte][]int, key byte, index int) {
	if len(m[key]) <= 0 {
		m[key] = make([]int, 0)
	}
	m[key] = append(m[key], index+1)
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	st := make([]int, n*2)
	stf := 0
	s1 := make([]byte, n+1)
	s2 := make([]byte, n+1)
	fmt.Fscanf(buf, "%s\n", &s1)
	fmt.Fscanf(buf, "%s\n", &s2)

	m1 := make(map[byte][]int)
	m2 := make(map[byte][]int)
	for i := 0; i < n; i++ {
		addD(m1, s1[i], i)
		addD(m2, s2[i], i)
	}
//	fmt.Printf("m1=%v\n",m1)
//	fmt.Printf("m2=%v\n",m2)
	for i := 0; i < 26; i++ {
		c := 'a' + byte(i)
		front := 0
		l := len(m1[c])
		for front < l {
			if len(m2[c]) > 0 {
				st[stf] = m1[c][front]
				stf++
				st[stf] = m2[c][0]
				stf++
				m2[c] = m2[c][1:]
				//		ans++
			} else if len(m2['?']) > 0 {
				st[stf] = m1[c][front]
				stf++
				st[stf] = m2['?'][0]
				stf++
				m2['?'] = m2['?'][1:]
				//	ans++
			} else {
				break
			}
			front++
		}
	}
	//fmt.Printf("m1=%v\n",m1)
	//fmt.Printf("m2=%v\n",m2)
	sf1 := 0
	sf2:=0
	stack1 := make([]int, n+1)
	stack2 := make([]int, n+1)
	for i:= 0;i < 26;i++{
		c := 'a' + byte(i)
		l1 := len(m1[c])
		if l1 > 0{
			for j:=0;j < l1;j++{
				stack1[sf1] = m1[c][j]
				sf1++
			}
		}
		l2 := len(m2[c])
		if l2 > 0{
			for j:=0;j < l2;j++{
			//	fmt.Printf("f2=%d--%d %c %d\n",sf2,m2[c][j],c,l2)
				stack2[sf2] = m2[c][j]
				sf2++
			}
		}
	}
	left1 := len(m1['?'])
	ff := 0
	front := 0
	for front < left1{
		if ff < sf2 {
			st[stf] = m1['?'][front]
			stf++
			st[stf] = stack2[ff]
			stf++
			ff++
			front++
		}else if len(m2['?']) > 0{
			st[stf] = m1['?'][front]
			stf++
			st[stf] = m2['?'][0]
			stf++
			front++
			m2['?'] = m2['?'][1:]
		}else {
			break
		}
	}
	m1['?'] = m1['?'][front:]
	left2 := len(m2['?'])
	front = 0
	ff = 0
	for front < left2{
		if ff < sf1 {
			st[stf] = stack1[ff]
			stf++
			st[stf] = m2['?'][front]
			stf++
			ff++
			front++
		}else {
			break
		}
	}
	fmt.Printf("%d\n", stf/2)
	for i := 0; i+1 < stf; i += 2 {
		fmt.Printf("%d %d\n", st[i], st[i+1])
	}
}

/**
01010101
0101010
 */

package main

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

type Pair struct {
	leftIndex  int
	rightIndex int
}

func newPair(leftIndex int, rightIndex int) Pair {
	return Pair{leftIndex: leftIndex, rightIndex: rightIndex}
}

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

	var n int
	fmt.Fscanln(in, &n)
	pairs := make([]Pair, 0)

	lefts := make(map[rune][]int)
	leftWilds := make([]int, 0)
	for i := 1; i <= n; i++ {
		c, _, _ := in.ReadRune()

		if c == '?' {
			leftWilds = append(leftWilds, i)
			continue
		}
		lefts[c] = append(lefts[c], i)
	}

	in.ReadLine()
	rightWilds := make([]int, 0)
	for i := 1; i <= n; i++ {
		c, _, _ := in.ReadRune()

		if c == '?' {
			rightWilds = append(rightWilds, i)
			continue
		}

		if len(lefts[c]) != 0 {
			left := lefts[c][0]
			pairs = append(pairs, newPair(left, i))
			lefts[c] = lefts[c][1:]
		} else if len(leftWilds) != 0 {
			left := leftWilds[0]
			pairs = append(pairs, newPair(left, i))
			leftWilds = leftWilds[1:]
		}
	}

	for _, list := range lefts {
		if list == nil {
			continue
		}
		for len(list) != 0 && len(rightWilds) != 0 {
			pairs = append(pairs, newPair(list[0], rightWilds[0]))
			list = list[1:]
			rightWilds = rightWilds[1:]
		}
	}

	for len(leftWilds) != 0 {
		if len(rightWilds) == 0 {
			break
		}
		pairs = append(pairs, newPair(leftWilds[0], rightWilds[0]))
		leftWilds = leftWilds[1:]
		rightWilds = rightWilds[1:]
	}

	fmt.Println(len(pairs))
	for _, pair := range pairs {
		fmt.Println(pair.leftIndex, pair.rightIndex)
	}
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

type Pair struct {
	leftIndex  int
	rightIndex int
}

func newPair(leftIndex int, rightIndex int) Pair {
	return Pair{leftIndex: leftIndex, rightIndex: rightIndex}
}

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

	var n int
	fmt.Fscanln(in, &n)
	pairs := list.New()

	lefts := make(map[rune]*list.List)
	leftWilds := list.New()
	for i := 1; i <= n; i++ {
		c, _, _ := in.ReadRune()

		if c == '?' {
			leftWilds.PushBack(i)
			continue
		}
		if lefts[c] == nil {
			lefts[c] = list.New()
		}
		lefts[c].PushBack(i)
	}

	in.ReadLine()
	rightWilds := list.New()
	for i := 1; i <= n; i++ {
		c, _, _ := in.ReadRune()

		if c == '?' {
			rightWilds.PushBack(i)
			continue
		}

		if lefts[c] != nil && lefts[c].Len() != 0 {
			left := lefts[c].Remove(lefts[c].Front()).(int)
			pairs.PushBack(newPair(left, i))
		} else if leftWilds.Len() != 0 {
			left := leftWilds.Remove(leftWilds.Front()).(int)
			pairs.PushBack(newPair(left, i))
		}
	}

	for _, list := range lefts {
		if list == nil {
			continue
		}
		for list.Len() != 0 && rightWilds.Len() != 0 {
			left := list.Remove(list.Front()).(int)
			right := rightWilds.Remove(rightWilds.Front()).(int)
			pairs.PushBack(newPair(left, right))
		}
	}

	for left := leftWilds.Front(); left != nil; left = left.Next() {
		if rightWilds.Len() == 0 {
			break
		}
		right := rightWilds.Remove(rightWilds.Front()).(int)
		pairs.PushBack(newPair(left.Value.(int), right))
	}

	fmt.Println(pairs.Len())
	for it := pairs.Front(); it != nil; it = it.Next() {
		pair := it.Value.(Pair)
		fmt.Println(pair.leftIndex, pair.rightIndex)
	}
}

package main

import "fmt"

func solve(n int, left, right string) map[int]int {
	const QuestionMark = '?'

	strToCountMap := func(str string) map[rune][]int {
		countMap := map[rune][]int{}
		for i, ch := range str {
			_, found := countMap[ch]
			if !found {
				countMap[ch] = []int{}
			}

			countMap[ch] = append(countMap[ch], i)
		}

		return countMap
	}

	res := map[int]int{}

	leftMap, rightMap := strToCountMap(left), strToCountMap(right)

	//fmt.Println(rightMap)

	for i, leftChar := range left {
		if leftChar != QuestionMark {
			for _, ch := range [...]rune{leftChar, QuestionMark} {
				_, found := rightMap[ch]

				if found && len(rightMap[ch]) > 0 {
					res[i] = rightMap[ch][0]

					leftMap[leftChar] = leftMap[leftChar][1:]
					rightMap[ch] = rightMap[ch][1:]

					break
				}
			}
		}
	}

	for _, rightChar := range right {
		if len(rightMap[rightChar]) > 0 {
			//fmt.Println(rightChar, rightMap[rightChar])

			_, found := leftMap[QuestionMark]

			if found && len(leftMap[QuestionMark]) > 0 {
				res[leftMap[QuestionMark][0]] = rightMap[rightChar][0]

				leftMap[QuestionMark] = leftMap[QuestionMark][1:]
				rightMap[rightChar] = rightMap[rightChar][1:]
			}
		}
	}

	return res
}

func main() {
	n := 0
	left, right := "", ""

	fmt.Scan(&n)
	fmt.Scan(&left, &right)

	ans := solve(n, left, right)
	fmt.Println(len(ans))
	for l, r := range ans {
		fmt.Println(l+1, r+1)
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1141/problem/D

package main

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

type Pair struct {
	ai int
	bi int
}

type CharPos struct {
	char string
	pos  int
}

func createMap(s string) map[string][]int {
	m := make(map[string][]int)
	for i, elem := range s {
		char := string(elem)
		m[char] = append(m[char], i+1)
	}
	return m
}

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

func remainingChars(m map[string][]int, reverse bool) []CharPos {
	chars := []CharPos{}
	for char := range m {
		for _, elem := range m[char] {
			chars = append(chars, CharPos{char, elem})
		}
	}
	sort.Slice(chars, func(i, j int) bool {
		if chars[i].char == "?" {
			return !reverse
		}
		if chars[j].char == "?" {
			return reverse
		}
		if reverse {
			return chars[i].char > chars[j].char
		}
		return chars[i].char < chars[j].char
	})
	return chars
}

func Solve(n int, a string, b string) []Pair {
	aMap := createMap(a)
	bMap := createMap(b)
	answer := []Pair{}
	for char := range aMap {
		if char == "?" {
			continue
		}
		minLength := min(len(aMap[char]), len(bMap[char]))
		for i := 0; i < minLength; i++ {
			var ai, bi int
			ai, aMap[char] = aMap[char][len(aMap[char])-1], aMap[char][:len(aMap[char])-1]
			bi, bMap[char] = bMap[char][len(bMap[char])-1], bMap[char][:len(bMap[char])-1]
			answer = append(answer, Pair{ai, bi})
		}
	}
	aChars := remainingChars(aMap, false)
	bChars := remainingChars(bMap, true)
	for i, aElem := range aChars {
		bElem := bChars[i]
		if aElem.char == "?" || bElem.char == "?" {
			answer = append(answer, Pair{aElem.pos, bElem.pos})
		}
	}
	return answer
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	var a, b string
	fmt.Fscanf(reader, "%s\n%s\n", &a, &b)

	answer := Solve(n, a, b)
	fmt.Fprintf(writer, "%d\n", len(answer))
	for _, elem := range answer {
		fmt.Fprintf(writer, "%d %d\n", elem.ai, elem.bi)
	}
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

type Pair struct {
	leftIndex  int
	rightIndex int
}

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

	var n int
	fmt.Fscanln(in, &n)
	pairs := list.New()

	lefts := make(map[rune]*list.List)
	leftWilds := list.New()
	for i := 1; i <= n; i++ {
		c, _, _ := in.ReadRune()

		if c == '?' {
			leftWilds.PushBack(i)
			continue
		}
		if lefts[c] == nil {
			lefts[c] = list.New()
		}
		lefts[c].PushBack(i)
	}

	in.Discard(1)
	rightWilds := list.New()
	for i := 1; i <= n; i++ {
		c, _, _ := in.ReadRune()

		if c == '?' {
			rightWilds.PushBack(i)
			continue
		}

		if lefts[c] != nil && lefts[c].Len() != 0 {
			pairs.PushBack(Pair{
				leftIndex:  lefts[c].Front().Value.(int),
				rightIndex: i,
			})
			lefts[c].Remove(lefts[c].Front())
		} else if leftWilds.Len() != 0 {
			pairs.PushBack(Pair{
				leftIndex:  leftWilds.Front().Value.(int),
				rightIndex: i,
			})
			leftWilds.Remove(leftWilds.Front())
		}
	}

	for _, list := range lefts {
		if rightWilds.Len() == 0 {
			break
		}
		for list.Len() != 0 {
			pairs.PushBack(Pair{
				leftIndex:  list.Front().Value.(int),
				rightIndex: rightWilds.Front().Value.(int),
			})
			list.Remove(list.Front())
			rightWilds.Remove(rightWilds.Front())
		}
	}

	for left := leftWilds.Front(); left != nil; left = left.Next() {
		if rightWilds.Len() == 0 {
			break
		}
		pairs.PushBack(Pair{
			leftIndex:  left.Value.(int),
			rightIndex: rightWilds.Front().Value.(int),
		})
		rightWilds.Remove(rightWilds.Front())
	}

	fmt.Println(pairs.Len())
	for it := pairs.Front(); it != nil; it = it.Next() {
		pair := it.Value.(Pair)
		fmt.Println(pair.leftIndex, pair.rightIndex)
	}
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

type Pair struct {
	leftIndex  interface{}
	rightIndex interface{}
}

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

	var n int
	fmt.Fscanln(in, &n)
	pairs := list.New()

	lefts := make(map[rune]*list.List)
	leftWilds := list.New()
	for i := 1; i <= n; i++ {
		c, _, _ := in.ReadRune()

		if c == '?' {
			leftWilds.PushBack(i)
			continue
		}
		if lefts[c] == nil {
			lefts[c] = list.New()
		}
		lefts[c].PushBack(i)
	}

	in.Discard(1)
	rightWilds := list.New()
	for i := 1; i <= n; i++ {
		c, _, _ := in.ReadRune()

		if c == '?' {
			rightWilds.PushBack(i)
			continue
		}

		if lefts[c] != nil && lefts[c].Len() != 0 {
			pairs.PushBack(Pair{
				leftIndex:  lefts[c].Front().Value,
				rightIndex: i,
			})
			lefts[c].Remove(lefts[c].Front())
		} else if leftWilds.Len() != 0 {
			pairs.PushBack(Pair{
				leftIndex: leftWilds.Front().Value,
				rightIndex: i,
			})
			leftWilds.Remove(leftWilds.Front())
		}
	}

	for _, list := range lefts {
		if rightWilds.Len() == 0 {
			break
		}
		for list.Len() != 0 {
			pairs.PushBack(Pair{
				leftIndex: list.Front().Value,
				rightIndex: rightWilds.Front().Value,
			})
			list.Remove(list.Front())
			rightWilds.Remove(rightWilds.Front())
		}
	}

	for left := leftWilds.Front(); left != nil; left = left.Next() {
		if rightWilds.Len() == 0 {
			break
		}
		pairs.PushBack(Pair{
			leftIndex: left.Value,
			rightIndex: rightWilds.Front().Value,
			})
		rightWilds.Remove(rightWilds.Front())
	}

	fmt.Println(pairs.Len())
	for it := pairs.Front(); it != nil; it = it.Next() {
		pair := it.Value.(Pair)
		fmt.Println(pair.leftIndex, pair.rightIndex)
	}
}

package main

import "fmt"

func solve(n int, left, right string) map[int]int {
	const QuestionMark = '?'

	strToCountMap := func(str string) map[rune][]int {
		countMap := map[rune][]int{}
		for i, ch := range str {
			_, found := countMap[ch]
			if !found {
				countMap[ch] = []int{}
			}

			countMap[ch] = append(countMap[ch], i)
		}

		return countMap
	}

	res := map[int]int{}

	leftMap, rightMap := strToCountMap(left), strToCountMap(right)

	for i, leftChar := range left {
		if leftChar != QuestionMark {
			for _, ch := range [...]rune{leftChar, QuestionMark} {
				_, found := rightMap[ch]

				if found && len(rightMap[ch]) > 0 {
					res[i] = rightMap[ch][0]

					leftMap[leftChar] = leftMap[leftChar][1:]
					rightMap[ch] = rightMap[ch][1:]

					break
				}
			}
		}
	}

	for j, rightChar := range right {
		if len(rightMap[rightChar]) > 0 {
			_, found := leftMap[QuestionMark]

			if found && len(leftMap[QuestionMark]) > 0 {
				res[leftMap[QuestionMark][0]] = j

				leftMap[QuestionMark] = leftMap[QuestionMark][1:]
				rightMap[rightChar] = rightMap[rightChar][1:]
			}
		}
	}

	return res
}

func main() {
	n := 0
	left, right := "", ""

	fmt.Scan(&n)
	fmt.Scan(&left, &right)

	ans := solve(n, left, right)
	fmt.Println(len(ans))
	for l, r := range ans {
		fmt.Println(l+1, r+1)
	}
}


Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.

The first line contains integer n (1 ≤ n ≤ 1000) — the number of gears. The second line contains n digits a1, a2, ..., an (0 ≤ ai ≤ n - 1) — the sequence of active teeth: the active tooth of the i-th gear contains number ai.

In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.

NoteIn the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.

package main

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

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

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

	n := nextInt()
	a := make([]int, n)

	for i := range a {
		a[i] = nextInt()
	}

	dif := (n - a[0]) % n
	a[0] = 0

	for i := 1; i < n; i++ {
		if i%2 == 0 {
			a[i] = (a[i] + dif) % n
		} else {
			a[i] = (a[i] + n - dif) % n
		}

		if a[i]-1 != a[i-1] {
			println("No")
			return
		}
	}

	println("Yes")
	// println(a)
}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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 print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

import (
    "fmt"

)

func main(){
    var n int
    fmt.Scanf("%d\n", &n)
    //fmt.Println(n)
    var g0 int
    fmt.Scanf("%d", &g0)
    //fmt.Println(g0)
    rot := n - g0

    for i := 0; i < n - 1; i += 1 {
        fmt.Scanf("%d", &g0)
        //fmt.Println(g0)
        if i % 2 == 0 {
            g0 -= rot
        } else {
            g0 += rot
        }
        g0 += n * 10
        g0 %= n

        if g0 != i + 1 {
            fmt.Println("No")
            return
        }
    }

    fmt.Println("Yes")
}

package main

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

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

	situations := make(map[string]int)

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

	target_code := gears_to_code(target, n)
	situations[gears_to_code(gears, n)] = 1

	for true {
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				gears[i] = (gears[i] + 1) % n
			} else {
				if gears[i] > 0 {
					gears[i] = gears[i] - 1
				} else {
					gears[i] = n - 1
				}
			}
		}

		sit := gears_to_code(gears, n)
		if target_code == sit {
			fmt.Println("Yes")
			return
		} else if situations[sit] > 0 {
			fmt.Println("No")
			return
		} else {
			situations[sit] = 1
		}
	}
}

func gears_to_code(g []int, n int) string {
	res := make([]string, n)
	for i := 0; i < n; i++ {
		res[i] = strconv.Itoa(g[i])
	}
	return strings.Join(res, "")
}

package main

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

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

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

func getLine() string {
	s, _ := reader.ReadString('\n')
	for len(s) > 0 && (s[len(s)-1] == '\n' || s[len(s)-1] == '\r') {
		s = s[:len(s)-1]
	}
	return s
}

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

	var n int
	scanf("%d\n", &n)
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d", &a[i])
	}
	var k = -1
	var d = a[0]
	var check = true
	for i := 0; i < n && check; i++ {
		if (a[i]+k*d+n)%n != i {
			check = false
		}
		k *= -1
	}
	if check {
		printf("Yes\n")
	} else {
		printf("No\n")
	}
}

package main

import (
	"fmt"
)

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

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

	first := n - an[0]
	ans := true
	for i := 1; i < n; i++ {
		if i%2 != 0 {
			an[i] -= first
			an[i] += n
		} else {
			an[i] += first
		}
		if an[i]%n != i {
			ans = false
			break
		}
	}

	if ans {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

package main

import (
    "fmt"

)

func main(){
    var n int
    fmt.Scanf(" %d", &n)
    var g0 int
    fmt.Scanf(" %d", &g0)
    rot := n - g0

    for i := 0; i < n - 1; i += 1 {
        fmt.Scanf(" %d", &g0)

        if i % 2 == 0 {
            g0 -= rot
        } else {
            g0 += rot
        }
        g0 += n * 10
        g0 %= n

        if g0 != i + 1 {
            fmt.Println("No")
            return
        }
    }

    fmt.Println("Yes")
}

package main

import (
    "fmt"

)

func main(){
    var n int
    fmt.Scanf("%d", &n)
    var g0 int
    fmt.Scanf("%d", &g0)
    rot := n - g0

    for i := 0; i < n - 1; i += 1 {
        fmt.Scanf("%d", &g0)
        if i % 2 == 0 {
            g0 -= rot
        } else {
            g0 += rot
        }
        g0 %= n
        if g0 < 0 {
            g0 += n
        }
        if g0 != i + 1 {
            fmt.Println("No")
            return
        }
    }

    fmt.Println("Yes")
}

package main

import (
    "fmt"

)

func main(){
    var n int
    fmt.Scanf("%d", &n)

    var g0 int
    fmt.Scanf(" %d", &g0)
    rot := n - g0

    for i := 0; i < n - 1; i += 1 {
        fmt.Scanf(" %d", &g0)

        if i % 2 == 0 {
            g0 -= rot
        } else {
            g0 += rot
        }
        g0 += n * 10
        g0 %= n

        if g0 != i + 1 {
            fmt.Println("No")
            return
        }
    }

    fmt.Println("Yes")
}


Zibi is a competitive programming coach. There are $$$n$$$ competitors who want to be prepared well. The training contests are quite unusual – there are two people in a team, two problems, and each competitor will code exactly one of them. Of course, people in one team will code different problems.Rules of scoring also aren't typical. The first problem is always an implementation problem: you have to implement some well-known algorithm very fast and the time of your typing is rated. The second one is an awful geometry task and you just have to get it accepted in reasonable time. Here the length and difficulty of your code are important. After that, Zibi will give some penalty points (possibly negative) for each solution and the final score of the team is the sum of them (the less the score is, the better).We know that the $$$i$$$-th competitor will always have score $$$x_i$$$ when he codes the first task and $$$y_i$$$ when he codes the second task. We can assume, that all competitors know each other's skills and during the contest distribute the problems in the way that minimizes their final score. Remember that each person codes exactly one problem in a contest.Zibi wants all competitors to write a contest with each other. However, there are $$$m$$$ pairs of people who really don't like to cooperate and they definitely won't write a contest together. Still, the coach is going to conduct trainings for all possible pairs of people, such that the people in pair don't hate each other. The coach is interested for each participant, what will be his or her sum of scores of all teams he trained in?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 300\,000$$$, $$$0 \le m \le 300\,000$$$) — the number of participants and the number of pairs of people who will not write a contest together. Each of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 \le x_i, y_i \le 10^9$$$) — the scores which will the $$$i$$$-th competitor get on the first problem and on the second problem. It is guaranteed that there are no two people having both $$$x_i$$$ and $$$y_i$$$ same. Each of the next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \ne v_i$$$) — indices of people who don't want to write a contest in one team. Each unordered pair of indices will appear at most once.

Output $$$n$$$ integers — the sum of scores for all participants in the same order as they appear in the input.

NoteIn the first example, there will be only one team consisting of persons $$$1$$$ and $$$3$$$. The optimal strategy for them is to assign the first task to the $$$3$$$-rd person and the second task to the $$$1$$$-st person, this will lead to score equal to $$$1 + 2 = 3$$$.In the second example, nobody likes anyone, so there won't be any trainings. It seems that Zibi won't be titled coach in that case...

package main

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

var in = bufio.NewScanner(os.Stdin)

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

type participant struct {
	i    int
	x, y int64
}

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

	n := readInt()
	m := readInt()
	participants := make([]participant, n)
	for i := range participants {
		participants[i].i = i
		participants[i].x = readInt()
		participants[i].y = readInt()
	}

	ans := make([]int64, n)
	for i := int64(0); i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		score := participants[u].x + participants[v].y
		if o := participants[v].x + participants[u].y; score > o {
			score = o
		}
		ans[u] -= score
		ans[v] -= score
	}

	sort.Slice(participants, func(i, j int) bool { return participants[i].x-participants[i].y < participants[j].x-participants[j].y })

	sumX := int64(0)
	for i := range ans {
		ans[participants[i].i] += int64(i)*participants[i].y + sumX
		sumX += participants[i].x
	}
	sumY := int64(0)
	for i := range ans {
		idx := n-1-int64(i)
		ans[participants[idx].i] += int64(i)*participants[idx].x + sumY
		sumY += participants[idx].y
	}

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

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

package main

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

var stdin io.Reader
var scanner *bufio.Scanner

func nextInt() int {
	//scanner.Scan()
	//x, _ := strconv.Atoi(scanner.Text())
	var x int
	fmt.Fscan(stdin, &x)
	return x
}

type contestant struct {
	id, x, y int
}

type byDif []contestant

func (a byDif) Len() int           { return len(a) }
func (a byDif) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byDif) Less(i, j int) bool { return a[i].x-a[i].y < a[j].x-a[j].y }

var N, E int
var idToPos []int
var enemies [][]int
var ctts []contestant
var sumX, sumY []int64

func leftOf(sum []int64, pos int) int64 {
	if pos < 0 {
		return 0
	}
	return sum[pos]
}

func rightOf(sum []int64, pos int) int64 {
	if pos >= len(sum) {
		return 0
	}
	res := sum[len(sum)-1]
	if pos > 0 {
		res -= sum[pos-1]
	}
	return res
}

func main() {
	stdin = bufio.NewReader(os.Stdin)
	scanner = bufio.NewScanner(stdin)
	scanner.Split(bufio.ScanWords)

	N, E = nextInt(), nextInt()

	ctts = make([]contestant, N)
	for i := range ctts {
		ctts[i] = contestant{id: i, x: nextInt(), y: nextInt()}
	}

	enemies = make([][]int, N)
	for i := range enemies {
		enemies[i] = make([]int, 0, 8)
	}

	for i := 0; i < E; i++ {
		a, b := nextInt()-1, nextInt()-1
		enemies[a] = append(enemies[a], b)
		enemies[b] = append(enemies[b], a)
	}

	sort.Sort(byDif(ctts))
	idToPos = make([]int, N)
	for i := range ctts {
		idToPos[ctts[i].id] = i
	}

	//fmt.Printf("idToPos=%v \n", idToPos)

	sumX = make([]int64, N)
	sumY = make([]int64, N)
	sumX[0] = int64(ctts[0].x)
	sumY[0] = int64(ctts[0].y)
	for i := 1; i < N; i++ {
		sumX[i] = sumX[i-1] + int64(ctts[i].x)
		sumY[i] = sumY[i-1] + int64(ctts[i].y)
	}

	answers := make([]int64, N)

	for cur := 0; cur < N; cur++ {
		ll := leftOf(sumX, cur-1) + int64(cur)*int64(ctts[cur].y)
		rr := rightOf(sumY, cur+1) + int64(N-cur-1)*int64(ctts[cur].x)

		total := ll + rr

		for _, enemyId := range enemies[ctts[cur].id] {
			enemyPos := idToPos[enemyId]
			if enemyPos < cur {
				total = total - int64(ctts[cur].y) - int64(ctts[enemyPos].x)
			} else {
				total = total - int64(ctts[cur].x) - int64(ctts[enemyPos].y)
			}
		}

		answers[ctts[cur].id] = total
	}

	output := bufio.NewWriterSize(os.Stdout, N*5)
	defer output.Flush()

	for _, x := range answers {
		fmt.Fprintf(output, "%d ", x)
	}
}

package main

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

var stdin io.Reader
var scanner *bufio.Scanner

func nextInt() int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	//fmt.Fscan(stdin, &x)
	return x
}

type contestant struct {
	id, x, y int
}

type byDif []contestant

func (a byDif) Len() int           { return len(a) }
func (a byDif) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byDif) Less(i, j int) bool { return a[i].x-a[i].y < a[j].x-a[j].y }

var N, E int
var idToPos []int
var enemies [][]int
var ctts []contestant
var sumX, sumY []int64

func leftOf(sum []int64, pos int) int64 {
	if pos < 0 {
		return 0
	}
	return sum[pos]
}

func rightOf(sum []int64, pos int) int64 {
	if pos >= len(sum) {
		return 0
	}
	res := sum[len(sum)-1]
	if pos > 0 {
		res -= sum[pos-1]
	}
	return res
}

func main() {
	stdin = bufio.NewReader(os.Stdin)
	scanner = bufio.NewScanner(stdin)
	scanner.Split(bufio.ScanWords)

	N, E = nextInt(), nextInt()

	ctts = make([]contestant, N)
	for i := range ctts {
		ctts[i] = contestant{id: i, x: nextInt(), y: nextInt()}
	}

	enemies = make([][]int, N)
	for i := range enemies {
		enemies[i] = make([]int, 0, 8)
	}

	for i := 0; i < E; i++ {
		a, b := nextInt()-1, nextInt()-1
		enemies[a] = append(enemies[a], b)
		enemies[b] = append(enemies[b], a)
	}

	sort.Sort(byDif(ctts))
	idToPos = make([]int, N)
	for i := range ctts {
		idToPos[ctts[i].id] = i
	}

	//fmt.Printf("idToPos=%v \n", idToPos)

	sumX = make([]int64, N)
	sumY = make([]int64, N)
	sumX[0] = int64(ctts[0].x)
	sumY[0] = int64(ctts[0].y)
	for i := 1; i < N; i++ {
		sumX[i] = sumX[i-1] + int64(ctts[i].x)
		sumY[i] = sumY[i-1] + int64(ctts[i].y)
	}

	answers := make([]int64, N)

	for cur := 0; cur < N; cur++ {
		ll := leftOf(sumX, cur-1) + int64(cur)*int64(ctts[cur].y)
		rr := rightOf(sumY, cur+1) + int64(N-cur-1)*int64(ctts[cur].x)

		total := ll + rr

		for _, enemyId := range enemies[ctts[cur].id] {
			enemyPos := idToPos[enemyId]
			if enemyPos < cur {
				total = total - int64(ctts[cur].y) - int64(ctts[enemyPos].x)
			} else {
				total = total - int64(ctts[cur].x) - int64(ctts[enemyPos].y)
			}
		}

		answers[ctts[cur].id] = total
	}

	output := bufio.NewWriterSize(os.Stdout, N*5)
	defer output.Flush()

	for _, x := range answers {
		fmt.Fprintf(output, "%d ", x)
	}
}

package main

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

var stdin io.Reader

func nextInt() int {
	var x int
	fmt.Fscan(stdin, &x)
	return x
}

type contestant struct {
	id, x, y int
}

type byDif []contestant

func (a byDif) Len() int           { return len(a) }
func (a byDif) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byDif) Less(i, j int) bool { return a[i].x-a[i].y < a[j].x-a[j].y }

var N, E int
var idToPos []int
var enemies [][]int
var ctts []contestant
var sumX, sumY []int64

func leftOf(sum []int64, pos int) int64 {
	if pos < 0 {
		return 0
	}
	return sum[pos]
}

func rightOf(sum []int64, pos int) int64 {
	if pos >= len(sum) {
		return 0
	}
	res := sum[len(sum)-1]
	if pos > 0 {
		res -= sum[pos-1]
	}
	return res
}

func main() {
	stdin = bufio.NewReader(os.Stdin)
	N, E = nextInt(), nextInt()

	ctts = make([]contestant, N)
	for i := range ctts {
		ctts[i] = contestant{id: i, x: nextInt(), y: nextInt()}
	}

	enemies = make([][]int, N)
	for i := range enemies {
		enemies[i] = make([]int, 0, 8)
	}

	for i := 0; i < E; i++ {
		a, b := nextInt()-1, nextInt()-1
		enemies[a] = append(enemies[a], b)
		enemies[b] = append(enemies[b], a)
	}

	sort.Sort(byDif(ctts))
	idToPos = make([]int, N)
	for i := range ctts {
		idToPos[ctts[i].id] = i
	}

	//fmt.Printf("idToPos=%v \n", idToPos)

	sumX = make([]int64, N)
	sumY = make([]int64, N)
	sumX[0] = int64(ctts[0].x)
	sumY[0] = int64(ctts[0].y)
	for i := 1; i < N; i++ {
		sumX[i] = sumX[i-1] + int64(ctts[i].x)
		sumY[i] = sumY[i-1] + int64(ctts[i].y)
	}

	answers := make([]int64, N)

	for cur := 0; cur < N; cur++ {
		ll := leftOf(sumX, cur-1) + int64(cur)*int64(ctts[cur].y)
		rr := rightOf(sumY, cur+1) + int64(N-cur-1)*int64(ctts[cur].x)

		total := ll + rr

		for _, enemyId := range enemies[ctts[cur].id] {
			enemyPos := idToPos[enemyId]
			if enemyPos < cur {
				total = total - int64(ctts[cur].y) - int64(ctts[enemyPos].x)
			} else {
				total = total - int64(ctts[cur].x) - int64(ctts[enemyPos].y)
			}
		}

		answers[ctts[cur].id] = total
	}

	output := bufio.NewWriterSize(os.Stdout, N*5)
	defer output.Flush()

	for _, x := range answers {
		fmt.Fprintf(output, "%d ", x)
	}
}


Andre has very specific tastes. Recently he started falling in love with arrays.Andre calls an nonempty array $$$b$$$ good, if sum of its elements is divisible by the length of this array. For example, array $$$[2, 3, 1]$$$ is good, as sum of its elements — $$$6$$$ — is divisible by $$$3$$$, but array $$$[1, 1, 2, 3]$$$ isn't good, as $$$7$$$ isn't divisible by $$$4$$$. Andre calls an array $$$a$$$ of length $$$n$$$ perfect if the following conditions hold:   Every nonempty subarray of this array is good.  For every $$$i$$$ ($$$1 \le i \le n$$$), $$$1 \leq a_i \leq 100$$$. Given a positive integer $$$n$$$, output any perfect array of length $$$n$$$. We can show that for the given constraints such an array always exists.An array $$$c$$$ is a subarray of an array $$$d$$$ if $$$c$$$ can be obtained from $$$d$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).

For every test, output any perfect array of length $$$n$$$ on a separate line.

NoteArray $$$[19, 33]$$$ is perfect as all $$$3$$$ its subarrays: $$$[19]$$$, $$$[33]$$$, $$$[19, 33]$$$, have sums divisible by their lengths, and therefore are good.

package main

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

var (
	t int8
	n int8
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)

		for ; n > 0; n-- {
			if n == 1 {
				fmt.Printf("1\n")
			} else {
				fmt.Printf("1 ")
			}
		}
	}
}

// Written by : Syed Mujtaba
// Seek knowledge from the cradle to the grave
package main

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

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

func main() {
  defer writer.Flush()
  var t int
  scanf("%d\n", &t)

  for i := 0; i < t; i++ {
  	var n int
  	scanf("%d\n", &n)
  	for j := 0; j < n; j++ {
  		printf("1 ")
  	}
  	printf("\n")
  }
}

package main

import "fmt"

func main () {
	var t int64
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var a int64
		fmt.Scan(&a)
		for ; a > 0; a-- {
			fmt.Print("1 ")
		}
		fmt.Println()
	}
}

package main

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

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

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

func solveA() {
	n := 0
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		printf("1 ")
	}
	printf("\n")
}

func solveB() {
	n := 0
	scanf("%d\n", &n)
	d := make(map[int]int)
	ans := "NO"
	for k, i := 0, 0; i < n; i++ {
		scanf("%d ", &k)
		d[k]++
		if d[k] > 1 {
			ans = "YES"
		}
	}
	printf(ans + "\n")
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solveA()
	}
}

/*
URL:
https://codeforces.com/contest/1438/problem/A
*/

package main

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

var (
	t int

	n int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()

		solve()
	}
}

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

	printf("%s\n", PrintIntsLine(A...))
}

/*******************************************************************/

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

// abs is integer version of math.Abs
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// debugf is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func debugf(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			Fprint(out, "1 ")
		}
		Fprintln(out)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}
}

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

package main

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

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

		for i := 0; i < n; i++ {
			fmt.Printf("1 ")
		}

		fmt.Println()
	}
}

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		result := ""
		for i := 0; i < n; i++ {
			result += "1 "
		}
		fmt.Println(result)
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

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

		for j := 0; j < n; j++ {
			fmt.Print("1 ")
		}
		fmt.Println()
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		res := solve(sint64())
		for _, d := range res {
			printf("%d ", d)
		}
		printf("\n")
	}
}

func solve(n int64) []int64 {
	ret := []int64{}
	for ; n > 0; n-- {
		ret = append(ret, 1)
	}
	return ret
}

package main

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

func main() {
	var t, n, c0, c1, h int
	var s string

	reader := bufio.NewReader(os.Stdin)

	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &c0, &c1, &h)
		fmt.Fscan(reader, &s)

		fmt.Println(cal(n, c0, c1, h, s))
	}
}

func cal(n int, c0 int, c1 int, h int, s string) int {

	buyD := 0
	buyC := 0

	for i := range s {
		if s[i] == '0' {
			buyD += c0
		}
		if s[i] == '1' {
			buyD += c1
		}
	}

	for i := range s {
		if s[i] == '0' {
			if c0 > c1 {
				buyC += h
				buyC += c1
			} else {
				buyC += c0
			}
		}

		if s[i] == '1' {
			if c1 > c0 {
				buyC += h
				buyC += c0
			} else {
				buyC += c1
			}
		}
	}

	if buyC >= buyD {
		return buyD
	} else {
		return buyC
	}

}


A sequence $$$a_1, a_2, \dots, a_n$$$ is called good if, for each element $$$a_i$$$, there exists an element $$$a_j$$$ ($$$i \ne j$$$) such that $$$a_i+a_j$$$ is a power of two (that is, $$$2^d$$$ for some non-negative integer $$$d$$$).For example, the following sequences are good:  $$$[5, 3, 11]$$$ (for example, for $$$a_1=5$$$ we can choose $$$a_2=3$$$. Note that their sum is a power of two. Similarly, such an element can be found for $$$a_2$$$ and $$$a_3$$$),  $$$[1, 1, 1, 1023]$$$,  $$$[7, 39, 89, 25, 89]$$$,  $$$[]$$$. Note that, by definition, an empty sequence (with a length of $$$0$$$) is good.For example, the following sequences are not good:  $$$[16]$$$ (for $$$a_1=16$$$, it is impossible to find another element $$$a_j$$$ such that their sum is a power of two),  $$$[4, 16]$$$ (for $$$a_1=4$$$, it is impossible to find another element $$$a_j$$$ such that their sum is a power of two),  $$$[1, 3, 2, 8, 8, 8]$$$ (for $$$a_3=2$$$, it is impossible to find another element $$$a_j$$$ such that their sum is a power of two). You are given a sequence $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you need to remove to make it good? You can delete an arbitrary set of elements.

The first line contains the integer $$$n$$$ ($$$1 \le n \le 120000$$$) — the length of the given sequence. The second line contains the sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).

Print the minimum number of elements needed to be removed from the given sequence in order to make it good. It is possible that you need to delete all $$$n$$$ elements, make it empty, and thus get a good sequence.

NoteIn the first example, it is enough to delete one element $$$a_4=5$$$. The remaining elements form the sequence $$$[4, 7, 1, 4, 9]$$$, which is good.

package main

import (
	"fmt"
	"sort"
)

func main() {
	var (
		n, ans int
		a []int
	)

	fmt.Scan(&n)
	ans = n;
	a = make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	for i, val := range a {
		var found bool
		for j := 0; !found && j < 31; j++ {
			p := 1 << uint(j)
			req := p - val
			if req < 0 {
				continue
			}

			ind := sort.Search(n, func(ind int) bool {
				return a[ind] > req
			})
			found = ind - 1 >= 0 && a[ind-1] == req && ind-1 != i

			ind = sort.Search(n, func(ind int) bool {
				return a[ind] >= req
			})
			found = found || (ind < n && a[ind] == req && ind != i)
		}

		if found {
			ans--
		}
	}

	fmt.Println(ans)
}

package main

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

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

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

	twos := make([]int, 32)
	for i := range twos {
		twos[i] = 1 << uint(i)
	}

	set := make(map[int]int, n)
	for i := 0; i < n; i++ {
		var c int
		fmt.Fscan(in, &c)
		set[c]++
	}

	cnt := 0
	for i := range set {
		if set[i] == 0 {
			continue
		}

		found := false
		for _, two := range twos {
			if two < i {
				continue
			}

			diff := two - i
			if (diff != i && set[diff] > 0) || (diff == i && set[diff] > 1) {
				found = true
				break
			}
		}

		if !found {
			cnt += set[i]
		}
	}

	fmt.Println(cnt)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var arr [120005]int
	var pows [33]int64
	mp := make(map[int64]int)

	for i := 1; i <= 31; i++ {
		pows[i] = 1 << uint(i)
	}

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

	var cnt int = 0
	for i := 1; i <= n; i++ {
		for j := 1; j <= 31; j++ {
			tmp := pows[j] - int64(arr[i])
			if tmp <= 0 {
				continue
			} else if mp[tmp] <= 0 {
				continue
			}

			if (tmp == int64(arr[i]) && mp[tmp] > 1) || (tmp != int64(arr[i]) && mp[tmp] > 0) {
				cnt++
				break
			}
		}
	}

	fmt.Println(n - cnt)
}

package main

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

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

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

	twos := make([]int, 32)
	for i := range twos {
		twos[i] = 1 << uint(i)
	}

	set := make(map[int]int, n)
	for i := 0; i < n; i++ {
		var c int
		fmt.Fscan(in, &c)
		set[c]++
	}

	cnt := 0
	for i := 1; i <= 120000; i++ {
		if set[i] == 0 {
			continue
		}

		found := false
		for _, two := range twos {
			if two < i {
				continue
			}

			diff := two - i
			if (diff != i && set[diff] > 0) || (diff == i && set[diff] > 1) {
				found = true
				break
			}
		}

		if !found {
			cnt += set[i]
		}
	}

	fmt.Println(cnt)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var arr [120005]int
	var pows [33]int64
	mp := make(map[int64]int)

	for i := 1; i <= 31; i++ {
		pows[i] = 2 << uint(i)
	}

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

	var cnt int = 0
	for i := 1; i <= n; i++ {
		for j := 1; j <= 31; j++ {
			tmp := pows[j] - int64(arr[i])
			if tmp <= 0 {
				continue
			} else if mp[tmp] <= 0 {
				continue
			}

			if (tmp == int64(arr[i]) && mp[tmp] > 1) || (tmp != int64(arr[i]) && mp[tmp] > 0) {
				cnt++
				break
			}
		}
	}

	fmt.Println(n - cnt)
}


On a chessboard with a width of $$$10^9$$$ and a height of $$$10^9$$$, the rows are numbered from bottom to top from $$$1$$$ to $$$10^9$$$, and the columns are numbered from left to right from $$$1$$$ to $$$10^9$$$. Therefore, for each cell of the chessboard you can assign the coordinates $$$(x,y)$$$, where $$$x$$$ is the column number and $$$y$$$ is the row number.Every day there are fights between black and white pieces on this board. Today, the black ones won, but at what price? Only the rook survived, and it was driven into the lower left corner — a cell with coordinates $$$(1,1)$$$. But it is still happy, because the victory has been won and it's time to celebrate it! In order to do this, the rook needs to go home, namely — on the upper side of the field (that is, in any cell that is in the row with number $$$10^9$$$).Everything would have been fine, but the treacherous white figures put spells on some places of the field before the end of the game. There are two types of spells:   Vertical. Each of these is defined by one number $$$x$$$. Such spells create an infinite blocking line between the columns $$$x$$$ and $$$x+1$$$.  Horizontal. Each of these is defined by three numbers $$$x_1$$$, $$$x_2$$$, $$$y$$$. Such spells create a blocking segment that passes through the top side of the cells, which are in the row $$$y$$$ and in columns from $$$x_1$$$ to $$$x_2$$$ inclusive. The peculiarity of these spells is that it is impossible for a certain pair of such spells to have a common point. Note that horizontal spells can have common points with vertical spells.    An example of a chessboard. Let's recall that the rook is a chess piece that in one move can move to any point that is in the same row or column with its initial position. In our task, the rook can move from the cell $$$(r_0,c_0)$$$ into the cell $$$(r_1,c_1)$$$ only under the condition that $$$r_1 = r_0$$$ or $$$c_1 = c_0$$$ and there is no blocking lines or blocking segments between these cells (For better understanding, look at the samples).Fortunately, the rook can remove spells, but for this it has to put tremendous efforts, therefore, it wants to remove the minimum possible number of spells in such way, that after this it can return home. Find this number!

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$0 \le n,m \le 10^5$$$) — the number of vertical and horizontal spells. Each of the following $$$n$$$ lines contains one integer $$$x$$$ ($$$1 \le x < 10^9$$$) — the description of the vertical spell. It will create a blocking line between the columns of $$$x$$$ and $$$x+1$$$. Each of the following $$$m$$$ lines contains three integers $$$x_1$$$, $$$x_2$$$ and $$$y$$$ ($$$1 \le x_{1} \le x_{2} \le 10^9$$$, $$$1 \le y < 10^9$$$) — the numbers that describe the horizontal spell. It will create a blocking segment that passes through the top sides of the cells that are in the row with the number $$$y$$$, in columns from $$$x_1$$$ to $$$x_2$$$ inclusive. It is guaranteed that all spells are different, as well as the fact that for each pair of horizontal spells it is true that the segments that describe them do not have common points.

In a single line print one integer — the minimum number of spells the rook needs to remove so it can get from the cell $$$(1,1)$$$ to at least one cell in the row with the number $$$10^9$$$

NoteIn the first sample, in order for the rook return home, it is enough to remove the second horizontal spell.  Illustration for the first sample. On the left it shows how the field looked at the beginning. On the right it shows how the field looked after the deletion of the second horizontal spell. It also shows the path, on which the rook would be going home. In the second sample, in order for the rook to return home, it is enough to remove the only vertical spell. If we tried to remove just one of the horizontal spells, it would not allow the rook to get home, because it would be blocked from above by one of the remaining horizontal spells (either first one or second one), and to the right it would be blocked by a vertical spell.  Illustration for the second sample. On the left it shows how the field looked at the beginning. On the right it shows how it looked after the deletion of the vertical spell. It also shows the path, on which the rook would be going home. In the third sample, we have two horizontal spells that go through the whole field. These spells can not be bypassed, so we need to remove both of them.  Illustration for the third sample. On the left it shows how the field looked at the beginning. On the right it shows how the field looked after the deletion of the horizontal spells. It also shows the path, on which the rook would be going home. In the fourth sample, we have no spells, which means that we do not need to remove anything.In the fifth example, we can remove the first vertical and third horizontal spells.  Illustration for the fifth sample. On the left it shows how the field looked at the beginning. On the right it shows how it looked after the deletions. It also shows the path, on which the rook would be going home.

package main

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

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

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

	ver := make([]int, n)
	for i := range ver {
		fmt.Fscan(in, &ver[i])
	}
	sort.Ints(ver)

	hor := make([]int, 0, m)
	for i := 0; i < m; i++ {
		var x1, x2, y int
		fmt.Fscan(in, &x1, &x2, &y)
		if x1 == 1 {
			hor = append(hor, x2)
		}
	}
	sort.Ints(hor)

	ans := n + len(hor) - sort.Search(len(hor), func(i int) bool {
		return hor[i] == 1e9
	})
	for i := range ver {
		cur := i + len(hor) - sort.Search(len(hor), func(j int) bool {
			return hor[j] >= ver[i]
		})
		if ans > cur {
			ans = cur
		}
	}
	fmt.Println(ans)
}


You are given a tree $$$G$$$ with $$$n$$$ vertices and an integer $$$k$$$. The vertices of the tree are numbered from $$$1$$$ to $$$n$$$.For a vertex $$$r$$$ and a subset $$$S$$$ of vertices of $$$G$$$, such that $$$|S| = k$$$, we define $$$f(r, S)$$$ as the size of the smallest rooted subtree containing all vertices in $$$S$$$ when the tree is rooted at $$$r$$$. A set of vertices $$$T$$$ is called a rooted subtree, if all the vertices in $$$T$$$ are connected, and for each vertex in $$$T$$$, all its descendants belong to $$$T$$$.You need to calculate the sum of $$$f(r, S)$$$ over all possible distinct combinations of vertices $$$r$$$ and subsets $$$S$$$, where $$$|S| = k$$$. Formally, compute the following: $$$$$$\sum_{r \in V} \sum_{S \subseteq V, |S| = k} f(r, S),$$$$$$ where $$$V$$$ is the set of vertices in $$$G$$$.Output the answer modulo $$$10^9 + 7$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$3 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le n$$$). Each of the following $$$n - 1$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$), denoting an edge between vertex $$$x$$$ and $$$y$$$. It is guaranteed that the given edges form a tree.

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func powmod64(a,e,mod int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func makefact64(n int64,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=int64(1);i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod64(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
const MOD int64 = 1000000007
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N,K := gi(),gi(); X,Y := fill2(N-1); for i:=0;i<N-1;i++ { X[i]--; Y[i]-- }
	fact,factinv := makefact64(int64(N+10),MOD)
	comb := func(n,r int) int64 { if n < 0 || r < 0 || r > n { return 0 }; return fact[n] * factinv[r] % MOD * factinv[n-r] % MOD }
	gr := make([][]int,N)
	for i:=0;i<N-1;i++ { x,y := X[i],Y[i]; gr[x] = append(gr[x],y); gr[y] = append(gr[y],x) }
	var dfs1 func(n,p int) int
	szarr := ia(N)
	dfs1 = func(n,p int) int {
		sz := 1;
		for _,c := range gr[n] { if c == p { continue }; sz += dfs1(c,n) }
		szarr[n] = sz; return sz
	}
	dfs1(0,-1)
	ans := int64(0)
	bsize := ia(N)
	var dfs2 func(n,p int)
	dfs2 = func(n,p int) {
		used := 1; bsize = bsize[:0]
		for _,c := range gr[n] { if c == p { continue }; bsize = append(bsize,szarr[c]); used += szarr[c] }
		if used < N { bsize = append(bsize,N-used) } // these are the nodes on top
		// Now we do when we are root.  We need to count all of the graphs minus the graphs that are contained in exactly one sidebranch
		branchsum := int64(0); for _,x := range bsize { branchsum += comb(x,K) }; branchsum %= MOD
		ans += (comb(N,K) + MOD - branchsum) % MOD * int64(N) % MOD
		// Now we loop through the possibility of the roots in the branches
		for _,x := range bsize {
			rootChoices := int64(x)
			numGraphs := (comb(N-x,K) + MOD - (branchsum - comb(x,K))) % MOD
			subGraphSize := int64(N-x)
			ans += rootChoices * numGraphs % MOD * subGraphSize % MOD
		}
		ans %= MOD
		for _,c := range gr[n] { if c == p { continue }; dfs2(c,n) }
	}
	dfs2(0,-1)
	fmt.Println(ans)
}


Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.

Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.

NoteConsider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3.In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal.In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	mul := int64(1)
	for _, b := range in.Bytes() {
		if b == '-' {
			mul *= -1
			continue
		}
		res = res*10 + int64(b-'0')
	}
	return mul * res
}
func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	k := readInt()
	a := make([]int64, n)
	min := int64(1e9)
	for i := range a {
		a[i] = readInt()
		if min > a[i] {
			min = a[i]
		}
		if i > 0 {
			if (a[i]-a[i-1])%k != 0 {
				fmt.Println(-1)
				return
			}
		}
	}
	var res int64
	for _, a := range a {
		res += (a - min) / k
	}
	fmt.Println(res)
}

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

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

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

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

func solve(n, k int) {
	in := make(arr, n)
	for i := range in {
		I(&in[i])
	}
	if len(in) == 1 {
		O("0\n")
		return
	}
	sort.Sort(in)
	var ans int64 = 0
	for i := range in {
		if i != n-1 {
			if (in[i]-in[i+1])%int64(k) != 0 {
				O("-1\n")
				return
			}
		}
		ans += (in[i] - in[n-1]) / int64(k)
	}
	O(ans, "\n")
}

type arr []int64

func (a arr) Len() int           { return len(a) }
func (a arr) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a arr) Less(i, j int) bool { return a[i] > a[j] }

package main

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

func solve() {
	n := readInt()
	k := readInt64()
	a := make([]int, n)
	m := math.MaxInt32
	for i := 0; i < n; i++ {
		a[i] = readInt()
		m = min(m, a[i])
	}
	var total int64
	for i := 0; i < n; i++ {
		d := int64(a[i] - m)
		if d%k != 0 {
			fmt.Println(-1)
			return
		}
		total += d / k
	}

	fmt.Println(total)
}

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

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main

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

func main() {
	var n, k, min, summ int64
	var tmp int
	min = 1000000001
	var line string
	var arr []int64
	var arrS []string
	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d %d\n", &n, &k)
	line, _ = reader.ReadString('\n')
	arrS = strings.Split(strings.TrimSpace(line), " ")
	for j := range arrS {
		tmp, _ = strconv.Atoi(arrS[j])
		if int64(tmp) < min {
			min = int64(tmp)
		}
		arr = append(arr, int64(tmp))
	}
	for i := 0; i < len(arr); i++ {
		if (arr[i]-min)%k != 0 {
			fmt.Println("-1")
			os.Exit(0)
		} else {
			summ = summ + ((arr[i] - min) / k)
		}
	}
	fmt.Println(summ)
}

package main

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

func solve() {
	n := readInt()
	k := readInt()
	a := make([]int, n)
	m := math.MaxInt32
	for i := 0; i < n; i++ {
		a[i] = readInt()
		m = min(m, a[i])
	}
	var total int
	for i := 0; i < n; i++ {
		d := a[i] - m
		if d%k != 0 {
			fmt.Println(-1)
			return
		}
		total += d / k
	}

	fmt.Println(total)
}

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

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main

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

func main() {
	var n, k, tmp, min, summ int
	min = 1000000001
	var line string
	var arr []int
	var arrS []string
	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d %d\n", &n, &k)
	line, _ = reader.ReadString('\n')
	arrS = strings.Split(strings.TrimSpace(line), " ")
	for j := range arrS {
		tmp, _ = strconv.Atoi(arrS[j])
		if tmp < min {
			min = tmp
		}
		arr = append(arr, tmp)
	}
	for i := 0; i < len(arr); i++ {
		if (arr[i]-min)%k != 0 {
			fmt.Println("-1")
			os.Exit(0)
		} else {
			summ = summ + ((arr[i] - min) / k)
		}
	}
	fmt.Println(summ)
}

package main

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

func main() {
	var k, tmp, min, summ int
	min = 1000000001
	var line string
	var arr []int
	var arrS []string
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	arrS = strings.Split(strings.TrimSpace(line), " ")
	for j := range arrS {
		tmp, _ = strconv.Atoi(arrS[j])
		arr = append(arr, tmp)
	}
	k = arr[1]
	arr = []int{}
	line, _ = reader.ReadString('\n')
	arrS = strings.Split(strings.TrimSpace(line), " ")
	for j := range arrS {
		tmp, _ = strconv.Atoi(arrS[j])
		if tmp < min {
			min = tmp
		}
		arr = append(arr, tmp)
	}
	for i := 0; i < len(arr); i++ {
		if (arr[i]-min)%k != 0 {
			fmt.Println("-1")
			os.Exit(0)
		} else {
			summ = summ + ((arr[i] - min) / k)
		}
	}
	fmt.Println(summ)
}


String diversity is the number of symbols that occur in the string at least once. Diversity of s will be denoted by d(s). For example , d("aaa")=1, d("abacaba")=3.Given a string s, consisting of lowercase Latin letters. Consider all its substrings. Obviously, any substring diversity is a number from 1 to d(s). Find statistics about substrings diversity: for each k from 1 to d(s), find how many substrings of s has a diversity of exactly k.

The input consists of a single line containing s. It contains only lowercase Latin letters, the length of s is from 1 to 3·105.

Print to the first line the value d(s). Print sequence t1, t2, ..., td(s) to the following lines, where ti is the number of substrings of s having diversity of exactly i.

NoteConsider the first example.We denote by s(i, j) a substring of "abca" with the indices in the segment [i, j].  s(1, 1) =  "a", d("a") = 1  s(2, 2) =  "b", d("b") = 1  s(3, 3) =  "c", d("c") = 1  s(4, 4) =  "a", d("a") = 1  s(1, 2) =  "ab", d("ab") = 2  s(2, 3) =  "bc", d("bc") = 2  s(3, 4) =  "ca", d("ca") = 2  s(1, 3) =  "abc", d("abc") = 3  s(2, 4) =  "bca", d("bca") = 3  s(1, 4) =  "abca", d("abca") = 3 Total number of substring with diversity 1 is 4, with diversity 2 equals 3, 3 diversity is 3.

package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]uint64, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()

	ln = len(str)
	for i = 0; i < ln; i++ {
		// fmt.Println(str[i])
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += uint64(add[j])
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]uint64, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()

	ln = len(str)
	for i = 0; i < ln; i++ {
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += uint64(add[j])
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

// http://codeforces.ru/problemset/status/386/problem/C/page/1?order=BY_PROGRAM_LENGTH_ASC
import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func S(s string, i int, j int) int {
	tmp := make([]int, 26)
	ans := 0
	for t := i; t <= j; t++ {
		if tmp[s[t]-'a'] == 0 {
			tmp[s[t]-'a'] = 1
			ans++
		}
	}
	return ans
}

func main() {
	var ln int
	answer := make([]int, 30)

	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}

	str := loadData()
	fmt.Println(str)

	ln = len(str)
	var d int = S(str, 0, ln-1)
	for i := 0; i < ln; i++ {
		for j := i; j < ln; j++ {
			t := S(str, i, j)
			//fmt.Printf("i=%d; j=%d; t=%d\n", i, j, t)
			answer[t]++

		}
	}

	fmt.Printf("%d\n", d)
	for i := 1; i <= d; i++ {
		fmt.Printf("%d ", answer[i])
	}
}

package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]uint32, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()

	ln = len(str)
	for i = 0; i < ln; i++ {
		// fmt.Println(str[i])
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += uint32(add[j])
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]int, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()
	fmt.Println(str)

	ln = len(str)
	for i = 0; i < ln; i++ {
		// fmt.Println(str[i])
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += add[j]
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

// http://codeforces.ru/problemset/status/386/problem/C/page/1?order=BY_PROGRAM_LENGTH_ASC
import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func S(s string, i int, j int) int {
	tmp := make([]int, 26)
	ans := 0
	for t := i; t <= j; t++ {
		if tmp[s[t]-'a'] == 0 {
			tmp[s[t]-'a'] = 1
			ans++
		}
	}
	return ans
}

func main() {
	var ln int
	answer := make([]int, 30)

	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}

	str := loadData()
	fmt.Println(str)

	ln = len(str)
	var d int = S(str, 0, ln-1)
	for i := 0; i < ln; i++ {
		for j := i; j < ln; j++ {
			t := S(str, i, j)
			//fmt.Printf("i=%d; j=%d; t=%d\n", i, j, t)
			answer[t]++

		}
	}

	fmt.Printf("%d\n", d)
	for i := 1; i <= d; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]int, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()

	ln = len(str)
	for i = 0; i < ln; i++ {
		// fmt.Println(str[i])
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += add[j]
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]int, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()
	fmt.Println(str)

	ln = len(str)
	for i = 0; i < ln; i++ {
		// fmt.Println(str[i])
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += add[j]
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d ", answer[i])
	}
}


You have a simple and connected undirected graph consisting of $$$n$$$ nodes and $$$m$$$ edges.Consider any way to pair some subset of these $$$n$$$ nodes such that no node is present in more than one pair. This pairing is valid if for every pair of pairs, the induced subgraph containing all $$$4$$$ nodes, two from each pair, has at most $$$2$$$ edges (out of the $$$6$$$ possible edges). More formally, for any two pairs, $$$(a,b)$$$ and $$$(c,d)$$$, the induced subgraph with nodes $$$\{a,b,c,d\}$$$ should have at most $$$2$$$ edges. Please note that the subgraph induced by a set of nodes contains nodes only from this set and edges which have both of its end points in this set.Now, do one of the following:   Find a simple path consisting of at least $$$\lceil \frac{n}{2} \rceil$$$ nodes. Here, a path is called simple if it does not visit any node multiple times.  Find a valid pairing in which at least $$$\lceil \frac{n}{2} \rceil$$$ nodes are paired. It can be shown that it is possible to find at least one of the two in every graph satisfying constraints from the statement.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). Description of the test cases follows. The first line of each test case contains $$$2$$$ integers $$$n, m$$$ ($$$2 \le n \le 5\cdot 10^5$$$, $$$1 \le m \le 10^6$$$), denoting the number of nodes and edges, respectively.  The next $$$m$$$ lines each contain $$$2$$$ integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$), denoting that there is an undirected edge between nodes $$$u$$$ and $$$v$$$ in the given graph. It is guaranteed that the given graph is connected, and simple  — it does not contain multiple edges between the same pair of nodes, nor does it have any self-loops.  It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5\cdot 10^5$$$. It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$10^6$$$.

For each test case, the output format is as follows.  If you have found a pairing, in the first line output "PAIRING" (without quotes).    Then, output $$$k$$$ ($$$\lceil \frac{n}{2} \rceil \le 2\cdot k \le n$$$), the number of pairs in your pairing.  Then, in each of the next $$$k$$$ lines, output $$$2$$$ integers $$$a$$$ and $$$b$$$  — denoting that $$$a$$$ and $$$b$$$ are paired with each other. Note that the graph does not have to have an edge between $$$a$$$ and $$$b$$$! This pairing has to be valid, and every node has to be a part of at most $$$1$$$ pair.  Otherwise, in the first line output "PATH" (without quotes).   Then, output $$$k$$$ ($$$\lceil \frac{n}{2} \rceil \le k \le n$$$), the number of nodes in your path.  Then, in the second line, output $$$k$$$ integers, $$$v_1, v_2, \ldots, v_k$$$, in the order in which they appear on the path. Formally, $$$v_i$$$ and $$$v_{i+1}$$$ should have an edge between them for every $$$i$$$ ($$$1 \le i < k$$$). This path has to be simple, meaning no node should appear more than once.

NoteThe path outputted in the first case is the following.   The pairing outputted in the second case is the following.   Here is an invalid pairing for the same graph  — the subgraph $$$\{1,3,4,5\}$$$ has $$$3$$$ edges.   Here is the pairing outputted in the third case.   It's valid because —   The subgraph $$$\{1,8,2,5\}$$$ has edges ($$$1$$$,$$$2$$$) and ($$$1$$$,$$$5$$$).  The subgraph $$$\{1,8,4,10\}$$$ has edges ($$$1$$$,$$$4$$$) and ($$$4$$$,$$$10$$$).  The subgraph $$$\{4,10,2,5\}$$$ has edges ($$$2$$$,$$$4$$$) and ($$$4$$$,$$$10$$$). Here is the pairing outputted in the fourth case.

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

type priorityQueue [][2]int

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

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

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.([2]int))
}

func (pq *priorityQueue) Pop() (res interface{}) {
	res = (*pq)[len(*pq)-1]
	*pq = (*pq)[:len(*pq)-1]
	return res
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

var (
	dx [4]int = [4]int{-1, 0, 1, 0}
	dy [4]int = [4]int{0, 1, 0, -1}
)

const (
	mod = 1000000007
)

func mult(a, b int64) int64 {
	return (a * b) % mod
}
func add(a, b int64) int64 {
	return (a + b) % mod
}

func sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

var (
	adj   [][]int
	par   []int
	depth []int
	vis   []bool
)

func solve() {
	n, m := nextInt(), nextInt()
	adj = make([][]int, n)
	for i := 0; i < m; i++ {
		u, v := nextInt()-1, nextInt()-1
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
	}
	par = make([]int, n)
	depth = make([]int, n)
	vis = make([]bool, n)
	par[0] = -1
	depth[0] = 1
	dfs(0)
	for i, v := range depth {
		if v >= (n+1)/2 {
			printf("PATH\n%d\n", v)
			for i != 0 {
				printf("%d ", i+1)
				i = par[i]
			}
			printf("1\n")
			return
		}
	}
	printf("PAIRING\n")
	res := [][2]int{}
	prev := make([]int, n+1)
	Fill(prev, -1)
	for i, v := range depth {
		if prev[v] == -1 {
			prev[v] = i
		} else {
			res = append(res, [2]int{i, prev[v]})
			prev[v] = -1
		}
	}
	printf("%d\n", len(res))
	for _, v := range res {
		printf("%d %d\n", v[0]+1, v[1]+1)
	}
}

func dfs(i int) {
	vis[i] = true
	for _, e := range adj[i] {
		if !vis[e] {
			par[e] = i
			depth[e] = depth[i] + 1
			dfs(e)
		}
	}
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "in"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		// file2, err := os.Create(name + ".out")
		// if err != nil {
		// 	log.Fatal(err)
		// }
		in = bufio.NewReaderSize(file1, 8192)
		// out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

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

package main

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

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

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

		vis := make([]bool, n+1)
		par, dep := make([]int, n+1), make([]int, n+1)
		deep := 0
		var pairs [][2]int
		cur := make([]int, n+1)
		var dfs func(int)
		dfs = func(u int) {
			vis[u] = true
			for _, v := range g[u] {
				if !vis[v] {
					par[v] = u
					dep[v] = dep[u] + 1
					if dep[v] > dep[deep] {
						deep = v
					}
					if cur[dep[v]] == 0 {
						cur[dep[v]] = v
					} else {
						pairs = append(pairs, [2]int{cur[dep[v]], v})
						cur[dep[v]] = 0
					}
					dfs(v)
				}
			}
		}
		dfs(1)

		if dep[deep] >= (n+1)/2 {
			var path []int
			cur := deep
			for cur != 0 {
				path = append(path, cur)
				cur = par[cur]
			}
			io.Println("PATH")
			io.Println(len(path))
			io.PrintlnInts(path...)
		} else {
			io.Println("PAIRING")
			io.Println(len(pairs))
			for _, p := range pairs {
				io.PrintlnInts(p[0], p[1])
			}
		}
	}
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

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

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

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

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

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

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

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

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

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

		vis := make([]bool, n+1)
		par, dep := make([]int, n+1), make([]int, n+1)
		deep := 0
		var pairs [][2]int
		cur := make([]int, n+1)
		var dfs func(int)
		dfs = func(u int) {
			vis[u] = true
			for _, v := range g[u] {
				if !vis[v] {
					par[v] = u
					dep[v] = dep[u] + 1
					if dep[v] > dep[deep] {
						deep = v
					}
					if cur[dep[v]] == 0 {
						cur[dep[v]] = v
					} else {
						pairs = append(pairs, [2]int{cur[dep[v]], v})
						cur[dep[v]] = 0
					}
					dfs(v)
				}
			}
		}
		dfs(1)

		if dep[deep] >= (n+1)/2 {
			var path []int
			cur := deep
			for cur != 0 {
				path = append(path, cur)
				cur = par[cur]
			}
			io.Println("PATH")
			io.Println(len(path))
			io.PrintlnInts(path...)
		} else {
			io.Println("PAIRING")
			io.Println(len(pairs))
			for _, p := range pairs {
				io.PrintlnInts(p[0], p[1])
			}
		}
	}
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

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

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

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

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

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

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

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

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

		vis := make([]bool, n+1)
		par := make([]int, n+1)
		deep, dep := 0, 0
		var pairs [][]int
		cur := make([]int, n+1)

		var dfs func(int, int)
		dfs = func(u, d int) {
			vis[u] = true
			for _, v := range g[u] {
				if !vis[v] {
					par[v] = u
					if d > dep {
						deep, dep = v, d
					}
					if cur[d] == 0 {
						cur[d] = v
					} else {
						pairs = append(pairs, []int{cur[d], v})
						cur[d] = 0
					}
					dfs(v, d+1)
				}
			}
		}
		dfs(1, 1)

		if dep >= (n+1)/2 {
			var path []int
			cur := deep
			for cur != 0 {
				path = append(path, cur)
				cur = par[cur]
			}
			io.Println("PATH")
			io.Println(len(path))
			io.PrintlnInts(path...)
		} else {
			io.Println("PAIRING")
			io.Println(len(pairs))
			for _, p := range pairs {
				io.PrintlnInts(p...)
			}
		}
	}
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

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

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

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

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

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

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}