Petya has an array $$$a$$$ consisting of $$$n$$$ integers. He wants to remove duplicate (equal) elements.Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of elements in Petya's array. The following line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1\,000$$$) — the Petya's array.

In the first line print integer $$$x$$$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $$$x$$$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.

NoteIn the first example you should remove two integers $$$1$$$, which are in the positions $$$1$$$ and $$$4$$$. Also you should remove the integer $$$5$$$, which is in the position $$$2$$$.In the second example you should remove integer $$$2$$$, which is in the position $$$1$$$, and two integers $$$4$$$, which are in the positions $$$2$$$ and $$$4$$$.In the third example you should remove four integers $$$6$$$, which are in the positions $$$1$$$, $$$2$$$, $$$3$$$ and $$$4$$$.

package main

import "fmt"

func main() {
	var n int
	var a [50]string
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[n-i-1])
	}
	var len_result int
	var result [50]string
	for i := 0; i < n; i++ {
		exists := false
		for j := 0; j < len_result; j++ {
			if result[j] == a[i] {
				exists = true
				break
			}
		}
		if !exists {
			result[len_result] = a[i]
			len_result++
		}
	}
	fmt.Println(len_result)
	for j := 0; j < len_result; j++ {
		fmt.Print(result[len_result-j-1], " ")
	}
}

package main

import "fmt"

func Process(a []int64) (int64, []int64) {
	var m = map[int64]bool{}
	var r = make([]int64, 0)

	for i := len(a) - 1; i >= 0; i-- {
		if _, exist := m[a[i]]; !exist {
			r = append([]int64{a[i]}, r...)
		}

		m[a[i]] = true
	}

	return int64(len(r)), r
}

func main() {
	var n int64

	fmt.Scanln(&n)

	var a, _ = ScanN(n)

	var r1, r2 = Process(a)

	fmt.Println(r1)

	PrintSlice(r2)
}

func ScanN(n int64) ([]int64, error) {
	in := make([]int64, n)
	for i := range in {
		_, err := fmt.Scan(&in[i])
		if err != nil {
			return in[:i], err
		}
	}
	return in, nil
}

func PrintSlice(a []int64) {
	for i := 0; i < len(a); i++ {
		if i == len(a)-1 {
			fmt.Print(a[i])
		} else {
			fmt.Print(a[i], " ")
		}
	}
}

package main

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

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

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

	a := make([]int, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i], _ = strconv.Atoi(scanner.Text())
	}

	total := 0
	set := make([]int, 1001)

	for i := 0; i < 1001; i++ {
		set[i] = -1
	}

	for i, el := range a {
		if set[el] == -1 {
			total++
		} else {
			a[set[el]] = -1
		}
		set[el] = i
	}
	fmt.Println(total)

	for _, el := range a {
		if el == -1 {
			continue
		}
		if set[el] == -1 {
			continue
		}
		fmt.Printf("%d ", el)
	}
	fmt.Printf("\n")
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	ans := make([]int, 0)
	mp := make(map[int]bool)
	for i := n-1; i >= 0; i-- {
		if _, ok := mp[a[i]]; ok {
			continue
		}
		mp[a[i]] = true
		ans = append(ans, a[i])
	}
	fmt.Printf("%d\n%d", len(ans), ans[len(ans)-1])
	for i := len(ans)-2; i >= 0; i-- {
		fmt.Printf(" %d", ans[i])
	}
	fmt.Println()
}

package main

import "fmt"

const (
	maxn = 55
)

var (
	n int
	a [maxn]int
	m map[int]bool
	ans []int
)

func main() {
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	m = make(map[int]bool)
	for i := n - 1; i >= 0; i-- {
		_, inMap := m[a[i]]
		if !inMap {
			ans = append(ans, a[i])
			m[a[i]] = true
		}
	}

	fmt.Println(len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Printf("%v ", ans[i])
	}
}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n int
	Scan(&n)
	a := make([]int, n)
	for i := range a {
		Scan(&a[i])
	}
	u := []int{}
	vis := [1001]bool{}
	for i := n - 1; i >= 0; i-- {
		if !vis[a[i]] {
			vis[a[i]] = true
			u = append(u, a[i])
		}
	}
	Println(len(u))
	for i := len(u) - 1; i >= 0; i-- {
		Print(u[i], " ")
	}
}

package main
import (
	"fmt"
	"sort"
)

var set, no []int
func check(f int) int{
	 var r int
	 for i, a := range no {
	 	  if a == f {
	 	  	 r = i
	 	  }
	 }

	 return r
}
func main() {
	 var n int
	 var used = make(map[int]bool)
	 fmt.Scanf("%d", &n)

	 for i:=0; i<n; i ++ {
	 		var x int
	 		fmt.Scan(&x)
	 		no = append(no, x)
	 }

	 for _, x := range no {
	 	    if used[x] == false {
	 			  set = append(set, check(x))
	 			  used[x] = true
	 		}
	 }

	 fmt.Printf("%d\n", len(set))
	 sort.Ints(set)
	 for _, a := range set {
	 	    fmt.Printf("%d ", no[a])
	 }
}

package main

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

func main() {
	var line string
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	_, _ = strconv.Atoi(arrStartStrings[0])
	start := make([]int, 0)
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	m := make(map[int]bool)
	sl := len(arrStartStrings)
	for i := sl - 1; i >= 0; i-- {
		tmp, _ := strconv.Atoi(arrStartStrings[i])
		if m[tmp] == false {
			start = append(start, tmp)
			m[tmp] = true
		}
	}
	for i, j := 0, len(start)-1; i < j; i, j = i+1, j-1 {
		start[i], start[j] = start[j], start[i]
	}
	fmt.Println(len(start))
	for i := 0; i < len(start); i++ {
		if i == 0 {
			fmt.Printf("%d", start[i])
		} else {
			fmt.Printf(" %d", start[i])
		}
	}
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	A := io.NextIntArray(N)

	cnt := 0
	seen := make(map[int]bool)
	good := make([]bool, N)
	for i := N - 1; i >= 0; i-- {
		if !seen[A[i]] {
			cnt++
			seen[A[i]] = true
			good[i] = true
		}
	}

	io.Println(cnt)
	for i, v := range A {
		if good[i] {
			io.Printf("%d ", v)
		}
	}
	io.Println()
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	m := make(map[int]bool)
	k := make([]int,n)
	var l []int
	for i:=0;i<n;i++{
		fmt.Scan(&k[i])
	}

	for i := n-1; i>=0;i-- {
		_,ok := m[k[i]]
		if !ok {
			l = append(l,k[i])
			m[k[i]] = true
		}
	}
	for i :=0;i<len(l)/2;i++{
		l[i],l[len(l)-i-1]=l[len(l)-i-1],l[i]
	}
	fmt.Println(len(l))
	s := fmt.Sprint(l)
	fmt.Println(s[1:len(s)-1])
}

package main

import "fmt"

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

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

	m := make(map[int]bool)
	cnt := 0
	for i := n - 1; i >= 0; i-- {
		v, _ := m[a[i]]
		if v {
			a[i] = -1
		} else {
			m[a[i]] = true
			cnt++
		}
	}

	fmt.Println(cnt)
	for i := 0; i < n; i++ {
		if a[i] != -1 {
			fmt.Print(a[i], " ")
			//fmt.Printf("%d ", a[i])
		}
	}

	fmt.Println()
}

package main

import "fmt"

func Process(a []int64) (int64, []int64) {
	var m = map[int64]bool{}
	var r = make([]int64, 0)

	for i := len(a) - 1; i >= 0; i-- {
		if _, exist := m[a[i]]; !exist {
			r = append([]int64{a[i]}, r...)
		}

		m[a[i]] = true
	}

	return int64(len(r)), r
}

func main() {
	var n int64

	fmt.Scanln(&n)

	var a, _ = ScanN(n)

	var r1, r2 = Process(a)

	fmt.Println(r1)
	PrintSlice(r2)
}

func ScanN(n int64) ([]int64, error) {
	in := make([]int64, n)
	for i := range in {
		_, err := fmt.Scan(&in[i])
		if err != nil {
			return in[:i], err
		}
	}
	return in, nil
}

func PrintSlice(a []int64) {
	for i := 0; i < len(a); i++ {
		if i == len(a)-1 {
			fmt.Print(a[i])
		} else {
			fmt.Print(a, " ")
		}
	}
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	A := io.NextIntArray(N)

	seen := make(map[int]bool)
	good := make([]bool, N)
	for i := N - 1; i >= 0; i-- {
		if !seen[A[i]] {
			seen[A[i]] = true
			good[i] = true
		}
	}

	for i, v := range A {
		if good[i] {
			io.Printf("%d ", v)
		}
	}
	io.Println()
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


This is an easier version of the problem. In this version, $$$n \le 500$$$.Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gifted him a string consisting of opening and closing brackets only. Petya believes, that the beauty of the bracket string is a number of its cyclical shifts, which form a correct bracket sequence.To digress from his problems, Vasya decided to select two positions of the string (not necessarily distinct) and swap characters located at this positions with each other. Vasya will apply this operation exactly once. He is curious what is the maximum possible beauty he can achieve this way. Please help him.We remind that bracket sequence $$$s$$$ is called correct if:   $$$s$$$ is empty;  $$$s$$$ is equal to "($$$t$$$)", where $$$t$$$ is correct bracket sequence;  $$$s$$$ is equal to $$$t_1 t_2$$$, i.e. concatenation of $$$t_1$$$ and $$$t_2$$$, where $$$t_1$$$ and $$$t_2$$$ are correct bracket sequences. For example, "(()())", "()" are correct, while ")(" and "())" are not.The cyclical shift of the string $$$s$$$ of length $$$n$$$ by $$$k$$$ ($$$0 \leq k < n$$$) is a string formed by a concatenation of the last $$$k$$$ symbols of the string $$$s$$$ with the first $$$n - k$$$ symbols of string $$$s$$$. For example, the cyclical shift of string "(())()" by $$$2$$$ equals "()(())".Cyclical shifts $$$i$$$ and $$$j$$$ are considered different, if $$$i \ne j$$$.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 500$$$), the length of the string. The second line contains a string, consisting of exactly $$$n$$$ characters, where each of the characters is either "(" or ")".

The first line should contain a single integer — the largest beauty of the string, which can be achieved by swapping some two characters. The second line should contain integers $$$l$$$ and $$$r$$$ ($$$1 \leq l, r \leq n$$$) — the indices of two characters, which should be swapped in order to maximize the string's beauty. In case there are several possible swaps, print any of them.

NoteIn the first example, we can swap $$$7$$$-th and $$$8$$$-th character, obtaining a string "()()()()()". The cyclical shifts by $$$0, 2, 4, 6, 8$$$ of this string form a correct bracket sequence.In the second example, after swapping $$$5$$$-th and $$$10$$$-th character, we obtain a string ")(())()()(()". The cyclical shifts by $$$11, 7, 5, 3$$$ of this string form a correct bracket sequence.In the third example, swap of any two brackets results in $$$0$$$ cyclical shifts being correct bracket sequences.

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

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

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

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

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

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

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

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

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

/*********** DP sub-functions ***********/

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

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

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

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

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

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(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 := PowInt(a, halfE)
		return half * half
	}

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

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

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

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

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

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n int
var S []rune

func main() {
	n = ReadInt()
	S = ReadRuneSlice()

	// S[4], S[9] = S[9], S[4]
	// sub()

	ans := 0
	l, r := 0, 0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			// 入れ替える
			S[i], S[j] = S[j], S[i]

			tmp := sub()
			if ans < tmp {
				ans = tmp
				l, r = i, j
			}

			// もとに戻す
			S[i], S[j] = S[j], S[i]
		}
	}
	fmt.Println(ans)
	fmt.Println(l+1, r+1)
}

type Char struct {
	idx int
	c   rune
}

func sub() int {
	// スタックで字句解析する
	s := make([]Char, 0, 1000)
	memo := []int{}
	for i := 0; i < n; i++ {
		r := S[i]
		char := Char{idx: i, c: r}

		if len(s) == 0 || r == '(' {
			s = append(s, char)
			continue
		}

		if r == ')' && s[len(s)-1].c == '(' {
			popped := s[len(s)-1]
			s = s[:len(s)-1]
			if len(s) == 0 || s[len(s)-1].c == ')' {
				memo = append(memo, popped.idx)
			}
		} else {
			s = append(s, char)
		}
	}

	// スタックに何も残っていないときはmemoの長さ
	if len(s) == 0 {
		return len(memo)
	}

	// 残ったカッコの数をチェック
	op, cl := 0, 0
	for i := 0; i < len(s); i++ {
		if s[i].c == '(' {
			op++
		} else {
			cl++
		}
	}
	// 数が一致しないとダメ
	if op != cl {
		return 0
	}

	l, r := 0, 0
	for i := 0; i < len(s); i++ {
		if s[i].c == '(' {
			r = s[i].idx
			break
		}
	}
	for i := len(s) - 1; i >= 0; i-- {
		if s[i].c == ')' {
			l = s[i].idx
			break
		}
	}

	// fmt.Println(memo)
	// for i := 0; i < len(s); i++ {
	// 	fmt.Printf("%d: %c\n", s[i].idx, s[i].c)
	// }
	// fmt.Printf("lidx: %d, ridx: %d\n", l, r)

	ans := 0
	for i := 0; i < len(memo); i++ {
		if l < memo[i] && memo[i] <= r {
			ans++
		}
	}

	return ans + 1
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	var s string
	fmt.Fscanf(reader, "%d\n%s\n", &n, &s)
	sum := make([]int, n+1)
	for i := n - 1; i >= 0; i-- {
		if s[i] == ')' {
			sum[i] = sum[i+1] + 1
		} else {
			sum[i] = sum[i+1] - 1
		}
	}

	if sum[0] != 0 {
		fmt.Printf("0\n1 1\n")
		return
	}

	min := 2 * n
	total := 0
	a := 1
	b := 1

	for i := 0; i < n; i++ {
		if sum[i] < min {
			min = sum[i]
			total = 1
		} else if sum[i] == min {
			total++
		}
	}

	//fmt.Printf("%d %d\n%d %d\n", min, total, a, b)

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if s[i] == s[j] {
				continue
			}

			sub := 0
			if s[i] == ')' {
				sub = 2
			} else {
				sub = -2
			}
			cha := 0
			tmin := 2 * n
			ttotal := 0

			for k := 0; k < n; k++ {
				if k > i && k <= j {
					cha = sub
				} else {
					cha = 0
				}

				if sum[k]+cha < tmin {
					tmin = sum[k]
					ttotal = 1
				} else if sum[k]+cha == tmin {
					ttotal++
				}
			}

			if ttotal > total {
				total = ttotal
				a = i
				b = j
			}
		}
	}

	fmt.Printf("%d\n%d %d\n", total, a+1, b+1)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	var s string
	fmt.Fscanf(reader, "%d\n%s\n", &n, &s)
	sum := make([]int, n+1)
	for i := n - 1; i >= 0; i-- {
		if s[i] == ')' {
			sum[i] = sum[i+1] + 1
		} else {
			sum[i] = sum[i+1] - 1
		}
	}

	if sum[0] != 0 {
		fmt.Printf("0\n1 1\n")
		return
	}

	min := 2 * n
	total := 0
	a := 1
	b := 1

	for i := 0; i < n; i++ {
		if sum[i] < min {
			min = sum[i]
			total = 1
		} else if sum[i] == min {
			total++
		}
	}

	//fmt.Printf("%d %d\n%d %d\n", min, total, a, b)

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if s[i] == s[j] {
				continue
			}

			sub := 0
			if s[i] == ')' {
				sub = 2
			} else {
				sub = -2
			}
			cha := 0
			tmin := 2 * n
			ttotal := 0

			for k := 0; k < n; k++ {
				if k > i && k <= j {
					cha = sub
				} else {
					cha = 0
				}

				if sum[i]+cha < tmin {
					tmin = sum[k]
					ttotal = 1
				} else if sum[k]+cha == tmin {
					ttotal++
				}
			}

			if ttotal > total {
				total = ttotal
				a = i
				b = j
			}
		}
	}

	fmt.Printf("%d\n%d %d\n", total, a+1, b+1)
}


You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).

The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.

Output one number — length of the longest substring that can be met in the string at least twice.

package main

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

var scanner *bufio.Scanner

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

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

  s := getS()
  n := len(s)
  max := 0
  seen := map[string]bool{}
  for i := 0; i < n; i++ {
    for j := i+1; j <= n; j++ {
      if seen[s[i:j]] && j-i > max {
        max = j-i
      }
      seen[s[i:j]] = true
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", max))
}


Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not. The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).

The tic-tac-toe position is given in four lines. Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.

Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.

NoteIn the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.In the second example it wasn't possible to win by making single turn.In the third example Ilya could have won by placing X in the last row between two existing Xs.In the fourth example it wasn't possible to win by making single turn.

package main

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

func I(i interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, i)
}

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

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

var in [4]string

func check() bool {
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			if in[i][j] == 'x' {
				if strings.Contains(in[i], "xxx") ||
					(i+2 < 4 && ((in[i+1][j] == 'x' && in[i+2][j] == 'x') ||
						(j+2 < 4 && in[i+1][j+1] == 'x' && in[i+2][j+2] == 'x') ||
						(j-2 >= 0 && in[i+1][j-1] == 'x' && in[i+2][j-2] == 'x'))) {
					O("YES", "\n")
					return true
				}
			}
		}
	}
	return false
}

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()
	for i := 0; i < 4; i++ {
		I(&in[i], "\n")
	}
	if check() {
		return
	}
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			if in[i][j] == '.' {
				a := []rune(in[i])
				a[j] = 'x'
				in[i] = string(a)
				if check() {
					return
				}
				a[j] = '.'
				in[i] = string(a)
			}
		}
	}
	O("NO", "\n")
}

package main

import "fmt"

func getField() [4][4]rune {
	var field [4][4]rune
	var c rune
	for i := range field {
		for j := range field[i] {
			for {
				_, err := fmt.Scanf("%c", &c)
				if err != nil {
					panic(err)
				}
				if c == 'x' || c == 'o' || c == '.' {
					field[i][j] = c
					break
				}
			}
		}
	}
	return field
}

var patterns [][]rune = [][]rune{
	{'.', 'x', 'x'},
	{'x', '.', 'x'},
	{'x', 'x', '.'},
}

func inPatterns3(x1, x2, x3 rune) bool {
	for i := range patterns {
		pattern := patterns[i]
		if x1 == pattern[0] && x2 == pattern[1] && x3 == pattern[2] {
			return true
		}
	}
	return false
}

func inPatterns4(x1, x2, x3, x4 rune) bool {
	return inPatterns3(x1, x2, x3) || inPatterns3(x2, x3, x4)
}

func canWin(field [4][4]rune) bool {
	for _, f := range field {
		if inPatterns4(f[0], f[1], f[2], f[3]) {
			return true
		}
	}

	for i := range field {
		if inPatterns4(field[0][i], field[1][i], field[2][i], field[3][i]) {
			return true
		}
	}

	if inPatterns4(field[0][0], field[1][1], field[2][2], field[3][3]) ||
		inPatterns4(field[0][3], field[1][2], field[2][1], field[3][0]) {
		return true
	}
	if inPatterns3(field[1][0], field[2][1], field[3][2]) ||
		inPatterns3(field[0][1], field[1][2], field[2][3]) ||
		inPatterns3(field[2][0], field[1][1], field[0][2]) ||
		inPatterns3(field[3][1], field[2][2], field[1][3]) {
		return true
	}

	return false
}

func main() {
	if canWin(getField()) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

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

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

    // your code here
    rows := make([]string, 4)
    for i := 0; i < 4; i++ {
        fmt.Fscanf(in, "%s\n", &rows[i])
    }
    lines := []string{}
    for r := 0; r < 4; r++ {
        lines = append(lines, rows[r])
    }
    for c := 0; c < 4; c++ {
        line := ""
        for r := 0; r < 4; r++ {
            line += rows[r][c:c+1]
        }
        lines = append(lines, line)
    }
    for r := 0; r < 2; r++ {
        for c := 0; c < 2; c++ {
            if r == 1 && c == 1 {
                break
            }
            line := ""
            for i := 0; r + i < 4 && c + i < 4; i++ {
                line += string(rows[r+i][c + i])
            }
            lines = append(lines, line)
            line = ""
            cc := 3 - c
            for i := 0; r + i < 4 && cc - i >= 0; i++ {
                line += string(rows[r+i][cc-i])
            }
            lines = append(lines, line)
        }
    }
    for _, line := range lines {
        for i := range line {
            if line[i:i+1] == "." && strings.Contains(line[0:i]+"x"+line[i+1:], "xxx") {
                fmt.Println("YES")
                return
            }
        }
    }
    fmt.Println("NO")
}

package main

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

func main() {
	const b_size int = 4

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)

	board := [b_size]string{}

	for i := 0; i < b_size; i++ {
		if s, err := reader.ReadString('\n'); err != nil {
			if err == io.EOF {
				break
			} else {
				return
			}
		} else {
			s = re.ReplaceAllString(s, "")
			board[i] = s
		}
	}

	ok := false
	candidate := make([]rune, b_size)
	n := 0

	for i := 0; i < b_size; i++ {
		// Horizontally
		for j := 0; j < b_size; j++ {
			candidate[j] = rune(board[i][j])
		}
		if is_ok(candidate, b_size) {
			ok = true
			break
		}

		// Vertically
		for j := 0; j < b_size; j++ {
			candidate[j] = rune(board[j][i])
		}
		if is_ok(candidate, b_size) {
			ok = true
			break
		}
	}

	if ok {
		fmt.Println("YES")
		return
	}

	dia_array := make([][b_size]rune, (b_size*2-1)*2)
	for j := 0; j < b_size; j++ {
		off0 := j
		off1 := (b_size*2 - 1) + (b_size - j - 1)
		for i := 0; i < b_size; i++ {
			dia_array[i+off0][j] = rune(board[i][j])
			dia_array[i+off1][j] = rune(board[i][j])
		}
	}

	for i := 0; i < (b_size*2-1)*2; i++ {
		n = 0
		for j := 0; j < b_size; j++ {
			if dia_array[i][j] != dia_array[0][b_size-1] {
				candidate[n] = dia_array[i][j]
				n++
			}
		}
		if is_ok(candidate, n) {
			ok = true
			break
		}
	}

	if ok {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func is_ok(candidate []rune, n int) bool {
	if n < 3 {
		return false
	} else {
		for e := 3; e <= n; e++ {
			xs := 0
			dots := 0
			for i := e - 3; i < e; i++ {
				if candidate[i] == 'x' {
					xs++
				} else if candidate[i] == '.' {
					dots++
				} else { // 'o'
					continue
				}
			}
			if xs == 2 && dots == 1 {
				return true
			}
		}
	}
	return false
}

package main

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

func solve() {
	field := make([][]int, 4)
	for i := 0; i < 4; i++ {
		field[i] = make([]int, 4)
		for j, ch := range readString() {
			switch ch {
			case 'x':
				field[i][j] = 1
			case 'o':
				field[i][j] = 2
			}
		}
	}
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			if field[i][j] == 0 {
				field[i][j] = 1
				if win(field) {
					fmt.Println("YES")
					return
				}
				field[i][j] = 0
			}
		}
	}
	fmt.Println("NO")
}

func win(field [][]int) bool {
	for j := 0; j < 4; j++ {
		for i := 0; i < 2; i++ {
			if field[j][i] == 1 && field[j][i+1] == 1 && field[j][i+2] == 1 {
				return true
			}
		}
	}
	for j := 0; j < 4; j++ {
		for i := 0; i < 2; i++ {
			if field[i][j] == 1 && field[i+1][j] == 1 && field[i+2][j] == 1 {
				return true
			}
		}
	}
	for i := 0; i < 2; i++ {
		for j := 0; j < 2; j++ {
			if field[i][j] == 1 && field[i+1][j+1] == 1 && field[i+2][j+2] == 1 {
				return true
			}
		}
	}
	for i := 0; i < 2; i++ {
		for j := 0; j < 2; j++ {
			if field[i][3-j] == 1 && field[i+1][3-j-1] == 1 && field[i+2][3-j-2] == 1 {
				return true
			}
		}
	}
	return false
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

// Codeforces 754 B  IlyaTicTacToe,
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
var in *bufio.Reader

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

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

var field [4][4]byte
var canWin string
var dx []int = []int {1,1,0,-1}
var dy []int = []int {0, 1,1,1}

func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading field
	for i:=0; i<4; i++ {
		s, err := in.ReadString('\n')
		if err != nil {
			fmt.Println("read failure", err)
			panic(err)
		}
		for j:=0; j<4; j++ {
			field[i][j] = s[j]
		}
	}
}

func solve() {
	canWin = "NO"
	for dir:=0; dir<4; dir++ {
		for y0:=0; y0<4; y0++ {
			y1 := y0 + 2*dy[dir]
			if y1<0 || y1>=4 {
				continue
			}
			for x0:=0; x0<4; x0++ {
				x1 := x0+2*dx[dir]
				if x1<0 || x1>=4 {
					continue
				}
				cntX := 0
				cntO := 0
				for k:=0; k<3; k++ {
					xx := x0 + k*dx[dir]
					yy := y0 + k*dy[dir]
					if field[yy][xx]=='x' {
						cntX++
					} else if field[yy][xx]=='o' {
						cntO++
					}
				}
				if cntX>=2 && cntO==0 {
					canWin = "YES"
				}
			}
		}
	}
}

func printRes() {
	fmt.Println(canWin)
}

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

package main
import "fmt"

const size int = 4;
func solve(T []string,x int,y int) bool{
    //fmt.Println(x,y);
    T[x]=T[x][:y]+string('x')+T[x][y+1:];
    possible:=false;
    for i:=0;i<size;i++{
        for j:=0;j<size;j++{
            if T[i][j]=='x'{
                for dx:=-1;dx<=1;dx++{
                    for dy:=-1;dy<=1;dy++{
                        if dx==0&&dy==0{
                            continue;
                        }
                        cnt:=0;
                        for k:=0;k<3;k++{
                            nx:=i+dx*k;
                            ny:=j+dy*k;
                            if nx>=0&&nx<size&&ny>=0&&ny<size&&T[nx][ny]=='x'{
                                cnt++;
                            }else{
                                break;
                            }
                        }
                        if cnt==3{
                            possible=true;
                        }
                    }
                }
            }
        }
    }
    T[x]=T[x][:y]+string('.')+T[x][y+1:];
    return possible;
}
func main(){
    for true{
        var T []string;
        var v string;
        if items,_:=fmt.Scanln(&v);items==0{
            break;
        }
        T=append(T,v);
        for i:=0;i<size-1;i++{
            fmt.Scanln(&v);
            T=append(T,v);
        }
        //fmt.Println(T);
        ok:=false;
        for i:=0;i<size;i++{
            for j:=0;j<size;j++{
                if T[i][j]=='.'{
                    ok=ok||solve(T,i,j);
                    //fmt.Println(T);
                }
            }
        }
        if ok{
            fmt.Println("YES");
        }else{
            fmt.Println("NO");
        }
    }
}

package main

import "fmt"

const size = 4
const x = 'x'
const dot = '.'

func checkVertical(table [][]rune) bool {
	for i := 0; i < size; i++ {
		if table[i][0] == x && table[i][1] == x && table[i][2] == x {
			return true
		}

		if table[i][1] == x && table[i][2] == x && table[i][3] == x {
			return true
		}
	}

	return false
}

func checkHorizontal(table [][]rune) bool {
	for j := 0; j < size; j++ {
		if table[0][j] == x && table[1][j] == x && table[2][j] == x {
			return true
		}

		if table[1][j] == x && table[2][j] == x && table[3][j] == x {
			return true
		}
	}

	return false
}

func checkDiagonal(table [][]rune) bool {
	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			var ii, jj int

			ii = i + 2
			jj = j + 2

			if ii < size && jj < size && table[i][j] == x && table[i+1][j+1] == x && table[i+2][j+2] == x {
				return true
			}

			ii = i + 2
			jj = j - 2

			if ii < size && jj >= 0 && table[i][j] == x && table[i+1][j-1] == x && table[i+2][j-2] == x {
				return true
			}
		}
	}

	return false
}

func main() {
	table := make([][]rune, size)

	for i := 0; i < size; i++ {
		table[i] = make([]rune, size)

		var row string
		fmt.Scanf("%s\n", &row)

		for p, s := range row {
			table[i][p] = s
		}
	}

	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			if table[i][j] == dot {
				table[i][j] = x
				if checkHorizontal(table) || checkVertical(table) || checkDiagonal(table) {
					fmt.Println("YES")
					return
				}
				table[i][j] = dot
			}
		}
	}

	fmt.Println("NO")
}

package main

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

func I(i interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, i)
}

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

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

var in [4]string

func check() bool {
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			if in[i][j] == 'x' {
				if strings.Contains(in[i], "xxx") ||
					(i+2 < 4 && ((in[i+1][j] == 'x' && in[i+2][j] == 'x') ||
						(j+2 < 4 && in[i+1][j+1] == 'x' && in[i+2][j+2] == 'x') ||
						(i-2 >= 0 && in[i+1][j-1] == 'x' && in[i+2][j-2] == 'x'))) {
					O("YES", "\n")
					return true
				}
			}
		}
	}
	return false
}

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()
	for i := 0; i < 4; i++ {
		I(&in[i], "\n")
	}
	if check() {
		return
	}
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			if in[i][j] == '.' {
				a := []rune(in[i])
				a[j] = 'x'
				in[i] = string(a)
				if check() {
					return
				}
				a[j] = '.'
				in[i] = string(a)
			}
		}
	}
	O("NO", "\n")
}

package main

import "fmt"

const size = 4
const x = 'x'
const dot = '.'

func checkVertical(table [][]rune) bool {
	for i := 0; i < size; i++ {
		if table[i][0] == x && table[i][1] == x && table[i][2] == x {
			return true
		}

		if table[i][1] == x && table[i][2] == x && table[i][3] == x {
			return true
		}
	}

	return false
}

func checkHorizontal(table [][]rune) bool {
	for j := 0; j < size; j++ {
		if table[j][0] == x && table[j][1] == x && table[j][2] == x {
			return true
		}

		if table[j][1] == x && table[j][2] == x && table[j][3] == x {
			return true
		}
	}

	return false
}

func checkDiagonal(table [][]rune) bool {
	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			var ii, jj int

			ii = i + 2
			jj = j + 2

			if ii < size && jj < size && table[i][j] == x && table[i+1][j+1] == x && table[i+2][j+2] == x {
				return true
			}

			ii = i + 2
			jj = j - 2

			if ii < size && jj >= 0 && table[i][j] == x && table[i+1][j-1] == x && table[i+2][j-2] == x {
				return true
			}
		}
	}

	return false
}

func main() {
	table := make([][]rune, size)

	for i := 0; i < size; i++ {
		table[i] = make([]rune, size)

		var row string
		fmt.Scanf("%s\n", &row)

		for p, s := range row {
			table[i][p] = s
		}
	}

	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			if table[i][j] == dot {
				table[i][j] = x
				if checkHorizontal(table) || checkVertical(table) || checkDiagonal(table) {
					fmt.Println("YES")
					return
				}
				table[i][j] = dot
			}
		}
	}

	fmt.Println("NO")
}

package main

import "fmt"

const size = 4
const x = 'x'
const dot = '.'

func checkVertical(table [][]rune) bool {
	for i := 0; i < size; i++ {
		if table[i][0] == x && table[i][1] == x && table[i][2] == x {
			return true
		}

		if table[i][1] == x && table[i][2] == x && table[i][3] == x {
			return true
		}
	}

	return false
}

func checkHorizontal(table [][]rune) bool {
	for j := 0; j < size; j++ {
		if table[j][0] == x && table[j][1] == x && table[j][2] == x {
			return true
		}

		if table[j][1] == x && table[j][2] == x && table[j][3] == x {
			return true
		}
	}

	return false
}

func checkDiagonal(table [][]rune) bool {
	if table[0][0] == x && table[1][1] == x && table[2][2] == x {
		return true
	}

	if table[1][1] == x && table[2][2] == x && table[3][3] == x {
		return true
	}

	if table[0][3] == x && table[1][2] == x && table[2][1] == x {
		return true
	}

	if table[3][0] == x && table[2][1] == x && table[1][2] == x {
		return true
	}

	return false
}

func main() {
	table := make([][]rune, size)

	for i := 0; i < size; i++ {
		table[i] = make([]rune, size)

		var row string
		fmt.Scanf("%s\n", &row)

		for p, s := range row {
			table[i][p] = s
		}
	}

	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			if table[i][j] == dot {
				table[i][j] = x
				if checkHorizontal(table) || checkVertical(table) || checkDiagonal(table) {
					fmt.Println("YES")
					return
				}
				table[i][j] = dot
			}
		}
	}

	fmt.Println("NO")
}

package main

import "fmt"

const size = 4

func checkVertical(table [][]rune) bool {
	for i := 0; i < size; i++ {
		if table[i][0] == 'X' && table[i][1] == 'X' && table[i][2] == 'X' {
			return true
		}

		if table[i][1] == 'X' && table[i][2] == 'X' && table[i][3] == 'X' {
			return true
		}
	}

	return false
}

func checkHorizontal(table [][]rune) bool {
	for j := 0; j < size; j++ {
		if table[j][0] == 'X' && table[j][1] == 'X' && table[j][2] == 'X' {
			return true
		}

		if table[j][1] == 'X' && table[j][2] == 'X' && table[j][3] == 'X' {
			return true
		}
	}

	return false
}

func checkDiagonal(table [][]rune) bool {
	if table[0][0] == 'X' && table[1][1] == 'X' && table[2][2] == 'X' {
		return true
	}

	if table[1][1] == 'X' && table[2][2] == 'X' && table[3][3] == 'X' {
		return true
	}

	if table[0][3] == 'X' && table[1][2] == 'X' && table[2][1] == 'X' {
		return true
	}

	if table[3][0] == 'X' && table[2][1] == 'X' && table[1][2] == 'X' {
		return true
	}

	return false
}

func main() {
	table := make([][]rune, size)

	for i := 0; i < size; i++ {
		table[i] = make([]rune, size)

		var row string
		fmt.Scanf("%s\n", &row)

		for p, s := range row {
			table[i][p] = s
		}
	}

	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			if table[i][j] == '.' {
				table[i][j] = 'X'
				if checkHorizontal(table) || checkVertical(table) || checkDiagonal(table) {
					fmt.Println("YES")
					return
				}
				table[i][j] = '.'
			}
		}
	}

	fmt.Println("NO")
}


Yura is a mathematician, and his cognition of the world is so absolute as if he have been solving formal problems a hundred of trillions of billions of years. This problem is just that!Consider all non-negative integers from the interval $$$[0, 10^{n})$$$. For convenience we complement all numbers with leading zeros in such way that each number from the given interval consists of exactly $$$n$$$ decimal digits.You are given a set of pairs $$$(u_i, v_i)$$$, where $$$u_i$$$ and $$$v_i$$$ are distinct decimal digits from $$$0$$$ to $$$9$$$.Consider a number $$$x$$$ consisting of $$$n$$$ digits. We will enumerate all digits from left to right and denote them as $$$d_1, d_2, \ldots, d_n$$$. In one operation you can swap digits $$$d_i$$$ and $$$d_{i + 1}$$$ if and only if there is a pair $$$(u_j, v_j)$$$ in the set such that at least one of the following conditions is satisfied:  $$$d_i = u_j$$$ and $$$d_{i + 1} = v_j$$$,  $$$d_i = v_j$$$ and $$$d_{i + 1} = u_j$$$. We will call the numbers $$$x$$$ and $$$y$$$, consisting of $$$n$$$ digits, equivalent if the number $$$x$$$ can be transformed into the number $$$y$$$ using some number of operations described above. In particular, every number is considered equivalent to itself.You are given an integer $$$n$$$ and a set of $$$m$$$ pairs of digits $$$(u_i, v_i)$$$. You have to find the maximum integer $$$k$$$ such that there exists a set of integers $$$x_1, x_2, \ldots, x_k$$$ ($$$0 \le x_i < 10^{n}$$$) such that for each $$$1 \le i < j \le k$$$ the number $$$x_i$$$ is not equivalent to the number $$$x_j$$$.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 50\,000$$$) — the number of digits in considered numbers. The second line contains an integer $$$m$$$ ($$$0 \le m \le 45$$$) — the number of pairs of digits in the set. Each of the following $$$m$$$ lines contains two digits $$$u_i$$$ and $$$v_i$$$, separated with a space ($$$0 \le u_i < v_i \le 9$$$). It's guaranteed that all described pairs are pairwise distinct.

Print one integer — the maximum value $$$k$$$ such that there exists a set of integers $$$x_1, x_2, \ldots, x_k$$$ ($$$0 \le x_i < 10^{n}$$$) such that for each $$$1 \le i < j \le k$$$ the number $$$x_i$$$ is not equivalent to the number $$$x_j$$$. As the answer can be big enough, print the number $$$k$$$ modulo $$$998\,244\,353$$$.

NoteIn the first example we can construct a set that contains all integers from $$$0$$$ to $$$9$$$. It's easy to see that there are no two equivalent numbers in the set.In the second example there exists a unique pair of equivalent numbers: $$$01$$$ and $$$10$$$. We can construct a set that contains all integers from $$$0$$$ to $$$99$$$ despite number $$$1$$$.

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
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 gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; 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 vecset(a []int, v int) { la := len(a); for i:=0;i<la;i++ { a[i] = v } }
const MOD = 998244353
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,M := gi(),gi(); mask := ia(10); for i:=0;i<M;i++ { u,v := gi(),gi(); mask[u] |= 1 << uint(v); mask[v] |= 1 << uint(u) }
	f := ia(520); g := ia(520); f[0] = 1
	for i:=1;i<=N;i++ {
		vecset(g,0)
		for j:=0;j<(1<<9);j++ {
			if f[j] != 0 {
				for k:=0;k<10;k++ {
					if (j >> uint(k)) & 1 == 0 {
						g[(j | ((1<<uint(k))-1)) & mask[k]] += f[j]
						g[(j | ((1<<uint(k))-1)) & mask[k]] %= MOD
					}
				}

			}
		}
		copy(f,g)
	}
	ans := 0
	for i:=0;i<(1<<9);i++ { ans += f[i]; ans %= MOD }
	fmt.Println(ans)
}


This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, but not happily ever after: one day a vicious dragon attacked the kingdom and stole Victoria. The King was full of grief, yet he gathered his noble knights and promised half of his kingdom and Victoria's hand in marriage to the one who will save the girl from the infernal beast.Having travelled for some time, the knights found the dragon's lair and all of them rushed there to save Victoria. Each knight spat on the dragon once and, as the dragon had quite a fragile and frail heart, his heart broke and poor beast died. As for the noble knights, they got Victoria right to the King and started brawling as each one wanted the girl's hand in marriage.The problem was that all the noble knights were equally noble and equally handsome, and Victoria didn't want to marry any of them anyway. Then the King (and he was a very wise man and didn't want to hurt anybody's feelings) decided to find out who will get his daughter randomly, i.e. tossing a coin. However, there turned out to be n noble knights and the coin only has two sides. The good thing is that when a coin is tossed, the coin falls on each side with equal probability. The King got interested how to pick one noble knight using this coin so that all knights had equal probability of being chosen (the probability in that case should always be equal to 1 / n). First the King wants to know the expected number of times he will need to toss a coin to determine the winner. Besides, while tossing the coin, the King should follow the optimal tossing strategy (i.e. the strategy that minimizes the expected number of tosses). Help the King in this challenging task.

The first line contains a single integer n from the problem's statement (1 ≤ n ≤ 10000).

Print the sought expected number of tosses as an irreducible fraction in the following form: "a/b" (without the quotes) without leading zeroes.

package main

import (
	"fmt"
	"math/big"
)

var con, cof *big.Rat

func main() {
	var n int64
	fmt.Scanf("%d", &n)
	var count int64
	for n % 2 == 0 {
		count, n = count + 1, n >> 1
	}
	conA := big.NewInt(0)
	cofA, cofD := big.NewInt(0), uint(0)
	for d, c, p := uint(1), int64(2), big.NewInt(2);n != 1; d, c = d + 1, c << 1{
			if c == n + 1 {
				// conA/conB  += (c * d) / p
				conA.Lsh(conA, d - cofD)
				conA.Add(big.NewInt(c * int64(d)), conA)
				cofD = d

				// cofA/cofB += 1 / p
				cofA.Sub(p, big.NewInt(1))
				break
			} else if c > n + 1 {

				conA.Lsh(conA, d - cofD)
				conA.Add(big.NewInt(n * int64(d)), conA)
				cofD = d

				c = c - n
			}
		p.Lsh(p, 1)
	}
	if n == 1 {
		fmt.Printf("%d/1", count)
		return
	}

	rat := &big.Rat{}
	rat.SetFrac(conA, cofA)
	rat.Add(rat, big.NewRat(count, 1))
	fmt.Printf("%s\n", rat.String())
}

package main

import (
	"fmt"
	"math/big"
)

var con, cof *big.Rat

func main() {
	var n int64
	fmt.Scanf("%d", &n)
	var count int64
	for n % 2 == 0 {
		count, n = count + 1, n >> 1
	}
	con, cof = big.NewRat(count, 1), big.NewRat(1, 1)
	half := big.NewRat(1, 2)
	for d, c, p := int64(1), int64(2), big.NewRat(1, 2);n != 1; d, c = d + 1, c << 1{
		if c >= n {
			tmp := &big.Rat{}
			if c == n + 1 {
				tmp.Mul(big.NewRat(c * d, 1), p)
				con.Add(con, tmp)
				cof.Sub(cof, p)
				break
			} else {
				tmp.Mul(big.NewRat(n * d, 1), p)
				con.Add(con, tmp)
				c = c - n
			}
		}
		p.Mul(p, half)
	}

	cof.Inv(cof)
	con.Mul(con, cof)
	fmt.Printf("%s\n", con.String())
}

package main

import (
	"fmt"
	"math/big"
)

var con, cof *big.Rat
var n, depth uint

func search(d uint, value uint) {
	if d == depth {
		con.Add(con, big.NewRat(int64(depth), 1 << depth))
		if value >= n {
			cof.Add(cof, big.NewRat(1, 1 << depth))
		}
		return
	} else if value < n {
		search(d + 1, value)
		search(d + 1, value | (1 << (depth - d - 1)))
	} else {
		con.Add(con, big.NewRat(int64(d), 1 << (depth - d)))
		cof.Add(cof, big.NewRat(1, 1 << (depth - d)))
	}
}

func main() {
	con, cof = big.NewRat(0, 1), big.NewRat(0, 1)
	fmt.Scanf("%d", &n)
	for depth = 0;(1 << depth) < n;depth ++ {

	}
	search(0, 0)
	cof.Sub(big.NewRat(1,1), cof)
	cof.Inv(cof)
	con.Mul(con, cof)
	fmt.Printf("%s", con.String())
}

package main

import (
	"fmt"
	"math/big"
)

var con, cof *big.Rat
var n, depth uint

func search(d uint, value uint) {
	if d == depth {
		con.Add(con, big.NewRat(int64(depth), 1 << depth))
		if value >= n {
			cof.Add(cof, big.NewRat(1, 1 << depth))

		}
		return
	} else if value < n {
		search(d + 1, value)
		search(d + 1, value | (1 << (depth - d - 1)))
	} else {
		con.Add(con, big.NewRat(int64(d), 1 << d))
		cof.Add(cof, big.NewRat(1, 1 << d))
	}
}

func main() {
	con, cof = big.NewRat(0, 1), big.NewRat(0, 1)
	fmt.Scanf("%d", &n)
	for depth = 0;(1 << depth) < n;depth ++ {

	}
	search(0, 0)
	cof.Sub(big.NewRat(1,1), cof)
	cof.Inv(cof)
	con.Mul(con, cof)
	fmt.Printf("%s", con.String())
}

package main

import (
	"fmt"
	"math/big"
)

var con, cof *big.Rat
var n, depth uint

func search(d uint, value uint) {
	if d == depth {
		con.Add(con, big.NewRat(int64(depth), 1 << depth))
		if value >= n {
			cof.Add(cof, big.NewRat(1, 1 << depth))
		}
		return
	} else if value < n {
		search(d + 1, value)
		search(d + 1, value | (1 << (depth - d - 1)))
	} else {
		con.Add(con, big.NewRat(int64(d), 1 << (depth - d + 1)))
		cof.Add(cof, big.NewRat(1, 1 << (depth - d + 1)))
	}
}

func main() {
	con, cof = big.NewRat(0, 1), big.NewRat(0, 1)
	fmt.Scanf("%d", &n)
	for depth = 0;(1 << depth) < n;depth ++ {

	}
	search(0, 0)
	cof.Sub(big.NewRat(1,1), cof)
	cof.Inv(cof)
	con.Mul(con, cof)
	fmt.Printf("%s", con.String())
}

package main

import (
	"fmt"
	"math/big"
)

var con, cof *big.Rat
var n, depth uint

func search(d uint, value uint) {
	if d == depth {
		con.Add(con, big.NewRat(int64(depth), 1 << depth))
		if value >= n {
			cof.Add(cof, big.NewRat(1, 1 << depth))

		}
		return
	} else if value < n {
		search(d + 1, value)
		search(d + 1, value | (1 << (depth - d - 1)))
	} else {
		con.Add(con, big.NewRat(int64(d), 1 << d))
		cof.Add(cof, big.NewRat(1, 1 << d))
	}
}

func main() {
	con, cof = big.NewRat(0, 1), big.NewRat(0, 1)
	fmt.Scanf("%d", &n)
	for depth = 0;(1 << depth) < n;depth ++ {

	}
	search(0, 0)
	cof.Sub(big.NewRat(1,1), cof)
	cof.Inv(cof)
	con.Mul(con, cof)
	fmt.Printf("%s\n", con.String())
}


One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array A.Lesha is tired now so he asked you to split the array. Help Lesha!

The first line contains single integer n (1 ≤ n ≤ 100) — the number of elements in the array A. The next line contains n integers a1, a2, ..., an ( - 103 ≤ ai ≤ 103) — the elements of the array A.

If it is not possible to split the array A and satisfy all the constraints, print single line containing "NO" (without quotes). Otherwise in the first line print "YES" (without quotes). In the next line print single integer k — the number of new arrays. In each of the next k lines print two integers li and ri which denote the subarray A[li... ri] of the initial array A being the i-th new array. Integers li, ri should satisfy the following conditions:   l1 = 1  rk = n  ri + 1 = li + 1 for each 1 ≤ i < k.  If there are multiple answers, print any of them.

package main

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

func I(i interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, i)
}

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

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

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n int
	I(&n, "\n")
	in := make([]int, n)
	sum := 0
	start := 1
	end := 1
	var out [][2]int
	for i, _ := range in {
		I(&in[i], " ")
		sum += in[i]
		if sum != 0 {
			end = i + 1
			out = append(out, [2]int{start, end})
			start = i + 2
			if i != n-1 {
				sum = 0
			}
		}
	}
	if sum == 0 && len(out) == 0 {
		O("NO", "\n")
		return
	}
	if sum == 0 {
		out[len(out)-1][1] = n
	}
	O("YES", "\n")
	O(len(out), "\n")
	for _, o := range out {
		O(o[0], " ")
		O(o[1], "\n")
	}
}

package main

import "fmt"

func getArr() []int {
	var (
		n   int
		arr []int
	)
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}
	arr = make([]int, n)
	for i := range arr {
		if _, err := fmt.Scan(&arr[i]); err != nil {
			panic(err)
		}
	}
	return arr
}

type Split struct {
	Start, End int
	Next, Prev *Split
}

func (split *Split) CalcSum() int {
	var sum int
	for i := split.Start; i < split.End; i++ {
		sum += arr[i]
	}
	return sum
}

func (split *Split) Process() bool {
	fullSum := split.CalcSum()
	saveEnd := split.End
	if fullSum == 0 {
		curSum := 0
		for i := split.Start; i < saveEnd; i++ {
			curSum += arr[i]
			if curSum != 0 && (fullSum-curSum) != 0 {
				split.End = i + 1
				rs := &Split{Start: i + 1, End: saveEnd}
				rs.Next = split.Next
				rs.Prev = split
				split.Next = rs
				if split.Process() && rs.Process() {
					return true
				} else {
					split.Next = rs.Next
				}
			}
		}
		return false
	} else {
		return true
	}
}

func (split *Split) FirstSplit() *Split {
	for split.Prev != nil {
		split = split.Prev
	}
	return split
}

func (split *Split) Len() int {
	var n int
	for split != nil {
		split = split.Next
		n += 1
	}
	return n
}

var arr []int

func main() {
	arr = getArr()

	spl := &Split{Start: 0, End: len(arr)}

	if spl.Process() {
		fmt.Println("YES")
		fspl := spl.FirstSplit()
		fmt.Println(fspl.Len())
		for fspl != nil {
			fmt.Println(fspl.Start+1, fspl.End)
			fspl = fspl.Next
		}
	} else {
		fmt.Println("NO")
	}
}

//http://codeforces.com/contest/754/problem/A
package main

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

func main() {

	var (
		n int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n)
	a := make([]int, n)

	zeroes := true
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &a[i])

		zeroes = zeroes && (a[i] == 0)
		sum += a[i]
	}

	if zeroes {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")

	if sum != 0 {
		fmt.Println(1)
		fmt.Println(1, n)
		return
	}

	fmt.Println("2")
	sum = 0
	i := 0
	for sum == 0 {
		sum += a[i]
		i++
	}

	fmt.Println(1, i)
	fmt.Println(i + 1, n)
}

package main

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

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

	sum := 0
	has_non_zero := false

	array := 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
		}
		array[i] = a
		sum += a
		if a != 0 {
			has_non_zero = true
		}
	}

	if !has_non_zero {
		fmt.Println("NO")
	} else if sum != 0 {
		fmt.Println("YES")
		fmt.Println("1\n1", n)
	} else {
		s := 0
		bound := -1
		for i := 0; i < n; i++ {
			s += array[i]
			if s != 0 {
				bound = i
				break
			}
		}
		fmt.Println("YES")
		fmt.Println(2)
		fmt.Println(1, bound+1)
		fmt.Println(bound+2, n)
	}
}

package main

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

func solve() {
	n := readInt()
	a := make([]int, n)
	total := 0
	for i := 0; i < n; i++ {
		a[i] = readInt()
		if a[i] == 0 {
			total++
		}
	}
	if total == n {
		fmt.Println("NO")
		return
	}
	res := make([][]int, 0)
	for i := 0; i < n; i++ {
		start := i
		sum := a[i]
		for sum == 0 && i+1 < n {
			i++
			sum += a[i]
		}
		for i+1 < n && a[i+1] == 0 {
			i++
			sum += a[i]
		}
		if sum == 0 {
			fmt.Println("NO")
			return
		}
		res = append(res, []int{start + 1, i + 1})
	}
	fmt.Println("YES")
	fmt.Println(len(res))
	for _, v := range res {
		fmt.Println(v[0], v[1])
	}
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

package main
import "fmt"
func main(){
    for true{
        var n int;
        if items,_:=fmt.Scan(&n);items==0{
            break;
        }
        var myVec []int;
        for i:=0;i<n;i++{
            var x int;
            fmt.Scan(&x);
            myVec=append(myVec,x);
        }
        //fmt.Println(myVec);
        ok:=true;
        var L,R []int;
        for i:=0;i<n;i++{
            ind:=-1;
            sum:=0;
            for j:=i;j<n;j++{
                sum+=myVec[j];
                if sum != 0{
                    ind=j;
                }
            }
            if ind==-1{
                ok=false;
                break;
            }
            L=append(L,i);
            R=append(R,ind);
            i=ind;
        }
        if !ok{
            fmt.Println("NO");
            continue;
        }
        fmt.Println("YES");
        fmt.Println(len(L));
        for i:=0;i<len(L);i++{
            fmt.Println(L[i]+1,R[i]+1);
        }
    }
}

package main

import "fmt"

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

	arr := make([]int, n)
	sum := 0
	hasNonZero := false

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
		sum += arr[i]
		if arr[i] != 0 {
			hasNonZero = true
		}
	}

	if !hasNonZero {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")

		if sum != 0 {
			fmt.Printf("1\n%d %d", 1, n)
		} else {
			fmt.Println("2")

			subSum := 0

			for i, val := range arr {
				subSum += val

				if subSum != 0 {
					fmt.Printf("%d %d\n%d %d", 1, i+1, i+2, n)
					break
				}
			}
		}
	}
}

package main

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

func I(i interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, i)
}

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

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

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n int
	I(&n, "\n")
	in := make([]int, n)
	sum := 0
	start := 1
	end := 1
	var out [][2]int
	for i, _ := range in {
		I(&in[i], " ")
		sum += in[i]
		if sum != 0 {
			end = i + 1
			out = append(out, [2]int{start, end})
			start = i + 2
			if i != n-1 {
				sum = 0
			}
		}
	}
	if sum == 0 {
		O("NO", "\n")
		return
	}
	O("YES", "\n")
	O(len(out), "\n")
	for _, o := range out {
		O(o[0], " ")
		O(o[1], "\n")
	}
}

package main

import "fmt"

func getArr() []int {
	var (
		n   int
		arr []int
	)
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}
	arr = make([]int, n)
	for i := range arr {
		if _, err := fmt.Scan(&arr[i]); err != nil {
			panic(err)
		}
	}
	return arr
}

type Split struct {
	Start, End int
	Next, Prev *Split
}

func (split *Split) CalcSum() int {
	var sum int
	for i := split.Start; i < split.End; i++ {
		sum += arr[i]
	}
	return sum
}

func (split *Split) Process() bool {
	fullSum := split.CalcSum()
	saveEnd := split.End
	if fullSum == 0 {
		curSum := 0
		for i := split.Start; i < saveEnd; i++ {
			curSum += arr[i]
			if curSum != 0 && (fullSum-curSum) != 0 {
				split.End = i + 1
				rs := &Split{Start: i + 1, End: saveEnd}
				rs.Next = split.Next
				rs.Prev = split
				split.Next = rs
				if split.Process() && rs.Process() {
					return true
				} else {
					split.Next = rs.Next
				}
			}
		}
		return false
	} else {
		return true
	}
}

func (split *Split) FirstSplit() *Split {
	for split.Prev != nil {
		split = split.Prev
	}
	return split
}

func (split *Split) Len() int {
	var n int
	for split.Next != nil {
		split = split.Next
		n += 1
	}
	return n
}

var arr []int

func main() {
	arr = getArr()

	spl := &Split{Start: 0, End: len(arr)}

	if spl.Process() {
		fmt.Println("YES")
		fspl := spl.FirstSplit()
		fmt.Println(fspl.Len())
		for {
			fmt.Println(fspl.Start+1, fspl.End)
			fspl = fspl.Next
			if fspl == nil {
				break
			}
		}
	} else {
		fmt.Println("NO")
	}
}

//http://codeforces.com/contest/754/problem/A
package main

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

func main() {

	var (
		n int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n)
	a := make([]int, n)

	zeroes := true
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &a[i])

		zeroes = zeroes && (a[i] == 0)
		sum += a[i]
	}

	if zeroes {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")

	if sum != 0 {
		fmt.Println(1)
		fmt.Println(1, n)
		return
	}

	fmt.Println("2")
	sum = 0
	i := 0
	for sum == 0 {
		sum += a[i]
		i++
	}

	fmt.Println(1, i + 1)
	fmt.Println(i + 2, n)
}

package main

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

func solve() {
	n := readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}
	res := make([][]int, 0)
	for i := 0; i < n; i++ {
		start := i
		sum := a[i]
		for sum == 0 && i+1 < n {
			i++
			sum += a[i]
		}
		for i+1 < n && a[i+1] == 0 {
			i++
			sum += a[i]
		}
		if sum == 0 {
			fmt.Println("NO")
			return
		}
		res = append(res, []int{start + 1, i + 1})
	}
	if len(res) > 1 {
		fmt.Println("YES")
		fmt.Println(len(res))
		for _, v := range res {
			fmt.Println(v[0], v[1])
		}
	} else {
		fmt.Println("NO")
	}
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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


You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.

The first line contains integers n and k — the number and digit capacity of numbers correspondingly (1 ≤ n, k ≤ 8). Next n lines contain k-digit positive integers. Leading zeroes are allowed both in the initial integers and the integers resulting from the rearranging of digits.

Print a single number: the minimally possible difference between the largest and the smallest number after the digits are rearranged in all integers by the same rule.

NoteIn the first sample, if we rearrange the digits in numbers as (3,1,4,2), then the 2-nd and the 4-th numbers will equal 5237 and 2537 correspondingly (they will be maximum and minimum for such order of digits).In the second sample, if we swap the second digits and the first ones, we get integers 100, 99 and 102.

package main

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

var scanner *bufio.Scanner

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

var writer *bufio.Writer
var best int = -1
var g [][]int
var numRows, numCols int

func permute(i int) {
  if i == numCols {
    xs := make([]int, numRows)
    for i := range g {
      x := 0
      for _, d := range g[i] {
        x = 10*x + d
      }
      xs[i] = x
    }
    sort.Ints(xs)
    diff := xs[numRows-1] - xs[0]
    if best == -1 || diff < best {
      best = diff
    }
  } else {
    permute(i+1)
    for j := i+1; j < numCols; j++ {
      for k := range g {
        g[k][i], g[k][j] = g[k][j], g[k][i]
      }
      permute(i+1)
      for k := range g {
        g[k][i], g[k][j] = g[k][j], g[k][i]
      }
    }
  }
}

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

  numRows, numCols = getI(), getI()
  g = make([][]int, numRows)
  for i := range g {
    s := getS()
    g[i] = make([]int, numCols)
    for j := range g[i] {
      g[i][j] = int(s[j]-'0')
    }
  }
  permute(0)

  writer.WriteString(fmt.Sprintf("%d\n", best))
}


Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop.In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of r burles (1 ≤ r ≤ 9).What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of r burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.

The single line of input contains two integers k and r (1 ≤ k ≤ 1000, 1 ≤ r ≤ 9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".  Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.

NoteIn the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.In the second example it is enough for Polycarp to buy one shovel.In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.

package main

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

func main() {
	var k, r int
	var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

	n := 1
	for m := k % 10; m != 0 && m != r; m = (m + k) % 10 {
		n++
	}

	fmt.Print(n)
}

package main

import "fmt"

func main() {
	var k,r int;
	fmt.Scan(&k, &r)
	for i:=1; i<=10; i++ {
		sum := k * i
		if sum % 10 == 0 || sum % 10 == r {
			fmt.Println(i)
			break
		}
	}
}

package main

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

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

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

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

func main() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var k int
	for I(&k, " ") == nil {
		solve(k)
	}
}
func solve(k int) {
	var r int
	I(&r, "\n")
	i := 1
	for k*i%10 != r && k*i%10 != 0 {
		i++
	}
	O(i, "\n")
}

package main

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

func solve() {
    k, r := readInt(), readInt()
    for i := 1; i < 11; i++ {
        res := i*k % 10
        if res == r || res == 0 {
            fmt.Println(i)
            break
        }
    }
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

// Math

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

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

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

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

// Sort

type Ints64 []int64

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

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

func main() {
	var k, r int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &k, &r)
	for i := 1; i <= 10; i++ {
		if k*i%10 == 0 || (k*i-r)%10 == 0 {
			fmt.Println(i)
			break
		}
	}
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func solution(k int, r int) int {
	for x := 1; x <= 20; x++ {
		p := x * k
		if (p%10 == 0) || (p%10 == r) {
			return x
		}
	}
	return 10
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var k, r int
	fmt.Fscanf(bufin, "%d %d\n", &k, &r)

	fmt.Fprintf(bufout, "%d\n", solution(k, r))
}

package main

import "fmt"

func main() {
    var k, r int
    fmt.Scanf("%d %d", &k, &r)
    for n := 1; ; n++ {
        a := n * k
        b := a - r
        if a % 10 == 0 || b % 10 == 0 {
            fmt.Printf("%d\n", n)
            return
        }
    }
}

// codeforces project main.go
package main

import (
	"fmt"
)

var (
	k, r int
)

func main() {
	fmt.Scan(&k, &r)
	var i int = 1
	tmp := k
	for ; (k-r)%10 != 0; i++ {
		if k%10 == 0 {
			break
		}
		k += tmp
	}
	fmt.Println(i)
}

package main

import "fmt"

func main() {
	var k, r int16
	fmt.Scan(&k, &r)
	var i int16
	for i = 1; i <= 10; i++ {
		if i * k % 10 == r || i * k % 10 == 0 {
			break
		}
	}
	fmt.Println(i)
}

package main

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

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

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

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

    // your code here
    var k, r int
    fmt.Fscanf(in, "%d %d\n", &k, &r)
    amount := k
    for amount % 10 != 0 && amount % 10 != r {
        amount += k
    }
    fmt.Println(amount / k)
}

package main

import (
	"fmt"
)

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

func main() {
	var k, r int
	fmt.Scanf("%d %d \n", &k, &r)
	sol := 1
	for (sol*k)%10 != 0 && (sol*k)%10 != r {
		sol++
	}
	fmt.Print(sol)
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var k string
	var r int
	fmt.Scanf("%s %d\n", &k, &r)
	unitDigit, _ := strconv.Atoi(string(k[len(k)-1]))
	for i := 1; i <= 9; i++ {
		x := strconv.Itoa(unitDigit * i)
		newUnitDigit, _ := strconv.Atoi(string(x[len(x)-1]))
		// fmt.Println(unitDigit, i, x, newUnitDigit, r)
		if newUnitDigit == r || newUnitDigit == 0 {
			fmt.Println(i)
			break
		}
	}

}

package main

import (
	"bufio"
	"os"

	"strings"
	"strconv"
	"fmt"
)

func getString() string {
	sc := bufio.NewScanner(os.Stdin)
	for sc.Scan() {
		return sc.Text()
	}
	return sc.Text()
}

func main() {
	str := getString()
	ar := strings.Split(str, " ")
	k, _ := strconv.Atoi(ar[0])
	r, _ := strconv.Atoi(ar[1])
	i := 1
	if dec :=  k%10; dec != 0 {
		tmp := dec
		for {
			if tmp%10 == 0 {
				fmt.Println(i)
				return
			}
			if tmp-r == 0 {
				fmt.Println(i)
				return
			} else {
				i++
				tmp = dec * i
				if tmp > 10 {
					tmp = tmp % 10
				}
				continue
			}
		}
	} else {
		fmt.Println(i)
	}

}

package main

import "fmt"

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

	for i := 1; i < 10; i++ {
		if (k*i)%10 == r || (k*i)%10 == 0 {
			fmt.Printf("%d\n", i)
			return
		}
	}

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

package main

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

func main() {
	var k, r int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &k, &r)
	sum := 0
	i := 0
	for ; ; i++ {
		sum += k
		if sum%10 == 0 || sum%10 == r {
			break
		}
	}
	fmt.Println(i + 1)
}

package main

import "fmt"

func main() {
	var k, r int
	fmt.Scan(&k, &r)
	var cnt = 1
	var remain = k % 10
	for remain != r && remain != 0 {
		remain = (k + remain) % 10
		cnt++
	}
	fmt.Print(cnt)
}

package main

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

func main() {
	var k, r int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &k)
	fmt.Fscan(reader, &r)
	buyNumber := 1
	for {
		if (buyNumber*k)%10 == 0 {
			break
		} else if (((buyNumber * k) % 10) - r) == 0 {
			break
		}
		buyNumber++
	}
	fmt.Println(buyNumber)
}

package main

import "fmt"

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

	i := 1
	for {
		tmp := i * k
		if tmp%10 == 0 || tmp%10 == r {
			fmt.Println(i)
			return
		}
		i++
	}
}

package main

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}
func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	sc := NewScanner()
	k, r := sc.NextInt(), sc.NextInt()
	for l := 1; l <= 10; l++ {
		g := k * l
		if g % 10 == 0 || g % 10 == r {
			fmt.Println(l)
			return
		}
	}

}

package main

import "fmt"

func main() {
	var k, r, mod uint
	fmt.Scan(&k, &r)
	mod = k % 10
	for i := uint(1); i <= 9; i++ {
		if (i*mod%10) == r || (i*mod%10) == 0 {
			fmt.Println(i)
			return
		}
	}
}

package main

import "fmt"

// https://codeforces.com/problemset/problem/732/A
// A. Buy a Shovel
// time limit per test
// 1 second
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop.

// In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of r burles (1 ≤ r ≤ 9).

// What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of r burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
// Input

// The single line of input contains two integers k and r (1 ≤ k ≤ 1000, 1 ≤ r ≤ 9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".

// Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
// Output

// Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.

func main() {
	var k, r int
	_, _ = fmt.Scan(&k, &r)

	nShovles := 1
	for {
		price := nShovles * k

		mod := price % 10
		if mod == 0 || mod == r {
			break
		}
		nShovles++
	}

	fmt.Print(nShovles)
}

package main

import "fmt"

// https://codeforces.com/problemset/problem/732/A
// комментарии к решению
// Десятичных монет неограниченное количество, поэтому нас интересует
// строго десятичный остаток стоимости, что приводит к конечному кол-ву
// решений. Перебираем все на листочке и выписываем двумерный массив решений
func taskSolution(k int, r int) int {
	counts := [][]int{
		{1, 1, 1, 1, 1, 1, 1, 1, 1},  // k%10 = 0
		{1, 2, 3, 4, 5, 6, 7, 8, 9},  // k%10 = 1
		{5, 1, 5, 2, 5, 3, 5, 4, 5},  // k%10 = 2
		{7, 4, 1, 8, 5, 2, 9, 6, 3},  // k%10 = 3
		{5, 3, 5, 1, 5, 4, 5, 2, 5},  // k%10 = 4
		{2, 2, 2, 2, 1, 2, 2, 2, 2},  // k%10 = 5
		{10, 2, 5, 4, 5, 1, 5, 3, 5}, // k%10 = 6
		{3, 6, 9, 2, 5, 8, 1, 4, 7},  // k%10 = 7
		{5, 4, 5, 3, 5, 2, 5, 1, 5},  // k%10 = 8
		{9, 8, 7, 6, 5, 4, 3, 2, 1},  // k%10 = 9
	}

	return counts[k%10][r-1]
}

func main() {
	var k, r int
	if _, err := fmt.Scan(&k, &r); err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(k, r))
}

package main

import "fmt"

func main()  {
	var priceOfShovel int
	fmt.Scan(&priceOfShovel)
	var change int
	fmt.Scan(&change)
	sumOfShovels := 1
	shovelPrice := 0
	actualPrice := 0
	count := 1
	for index := 0; index < count; index++ {
		shovelPrice = priceOfShovel * count
		actualPrice = shovelPrice % 10

		if actualPrice == change || actualPrice == 0  {
			break
		}

		sumOfShovels = sumOfShovels + 1
		count++
	}
	fmt.Print(count)
}

package main

import (
	"fmt"
)

func main() {
	var k, r int
	fmt.Scanf("%d %d", &k, &r)
	for i := 1; i <= 9; i++ {
		if k*i%10 == 0 || k*i%10 == r {
			fmt.Println(i)
			break
		}
	}
}

package main

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

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

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

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

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

	var k, r int = ReadInt32(), ReadInt32()

	for i := 1; i <= 10; i++ {
		if k*i%10 == r || k*i%10 == 0 {
			PrintInts(i)
			break
		}
	}
}

package main

import (
	"fmt"
)

var (
	k, r int
)

func main() {
	fmt.Scan(&k, &r)

	if (k-r)%10 == 0 {
		println(1)
	} else {
		var i int
		tmp := k
		m := (k - r) % 10
		for i = 1; m != 0; i++ {
			k += tmp
			m = (k - r) % 10
		}
		println(i)
	}
}

// codeforces project main.go
package main

import (
	"fmt"
)

var (
	k, r int
)

func main() {
	fmt.Scan(&k, &r)
	var i int = 1
	tmp := k
	for ; (k-r)%10 != 0; i++ {
		if k%10 == 0 {
			break
		}
		k += tmp
	}
	println(i)
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var k string
	var r int
	fmt.Scanf("%s %d\n", &k, &r)
	unitDigit, _ := strconv.Atoi(string(k[len(k)-1]))
	flag := false
	for i := 0; i <= 9; i++ {
		x := strconv.Itoa(unitDigit * i)
		newUnitDigit, _ := strconv.Atoi(string(x[len(x)-1]))
		// fmt.Println(unitDigit, i, x, newUnitDigit, r)
		if newUnitDigit == r {
			fmt.Println(i)
			flag = true
			break
		}
	}
	if !flag {
		fmt.Println(r)
	}

}

package main

import (
	"bufio"
	"os"

	"strings"
	"strconv"
	"fmt"
)

func getString() string {
	sc := bufio.NewScanner(os.Stdin)
	for sc.Scan() {
		return sc.Text()
	}
	return sc.Text()
}

func main() {
	str := getString()
	ar := strings.Split(str, " ")
	k, _ := strconv.Atoi(ar[0])
	r, _ := strconv.Atoi(ar[1])
	if dec :=  k%10; dec != 0 {
		i := 1
		for {
			if dec%r == 0 {
				fmt.Println(i)
				return
			} else {
				i++
				dec = dec * i
				continue
			}
		}
	} else {
		fmt.Println(1)
	}

}

package main

import "fmt"

func main() {
	var k, r int
	fmt.Scan(&k, &r)
	var cnt = 1
	var remain = k % 10
	for remain != r && remain == 0 {
		remain = (k + remain) % 10
		cnt++
	}
	fmt.Print(cnt)
}

package main

import "fmt"

// https://codeforces.com/problemset/problem/732/A
// комментарии к решению
// Десятичных монет неограниченное количество, поэтому нас интересует
// строго десятичный остаток стоимости, что приводит к конечному кол-ву
// решений. Перебираем все на листочке и выписываем двумерный массив решений
func taskSolution(k int, r int) int {
	counts := [][]int{
		// r =   1   2   3   4   5   6   7   8   9
		{1, 1, 1, 1, 1, 1, 1, 1, 1},  // k%10 = 0
		{1, 2, 3, 4, 5, 6, 7, 8, 9},  // k%10 = 1
		{5, 1, 5, 2, 5, 3, 5, 4, 5},  // k%10 = 2
		{7, 4, 1, 8, 5, 2, 9, 6, 3},  // k%10 = 3
		{5, 3, 5, 1, 5, 4, 5, 2, 5},  // k%10 = 4
		{2, 2, 2, 2, 2, 2, 2, 2, 2},  // k%10 = 5
		{10, 2, 5, 4, 5, 1, 5, 3, 5}, // k%10 = 6
		{3, 6, 9, 2, 5, 8, 1, 4, 7},  // k%10 = 7
		{5, 4, 5, 3, 5, 2, 5, 1, 5},  // k%10 = 8
		{9, 8, 7, 6, 5, 4, 3, 2, 1},  // k%10 = 9
	}

	return counts[k%10][r-1]
}

func main() {
	var k, r int
	if _, err := fmt.Scan(&k, &r); err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(k, r))
}


Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y violet and z orange spheres. Can he get them (possible, in multiple actions)?

The first line of the input contains three integers a, b and c (0 ≤ a, b, c ≤ 1 000 000) — the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, x, y and z (0 ≤ x, y, z ≤ 1 000 000) — the number of blue, violet and orange spheres that he needs to get.

If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".

NoteIn the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs.

package main

import "fmt"

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

func available(a, b int) int {
    if a > b {
        dif := a - b
        if dif%2 == 0 {
            return dif/2
        } else {
            return (dif - 1)/2
        }
    }
    return 0
}

func main() {
    var a, b, c, x, y, z int
    fmt.Scan(&a, &b, &c, &x, &y, &z)

    needed := max(0, x-a) + max(0, y-b) + max(0, z-c)
    ava := available(a, x) + available(b, y) + available(c, z)

    if needed > ava {
        fmt.Println("No")
    } else {
        fmt.Println("Yes")
    }
}

package main

import "fmt"

func main(){
	var (
		a int
		b int
		c int
		x int
		y int
		z int
	)
	fmt.Scanf("%d %d %d ",&a,&b,&c)
	fmt.Scanf("%d %d %d ",&x,&y,&z)
	if (x > a){
		x -= a
		a = 0
	}else {
		a -= x
		x = 0
	}
	if (y > b){
		y -= b
		b = 0
	}else {
		b -= y
		y = 0
	}
	if (z > c){
		z -= c
		c = 0
	}else {
		c -= z
		z = 0
	}
	if (x + y + z) <= (a/2 + b/2 + c/2){
		fmt.Print("Yes")
	}else {
		fmt.Print("No")
	}
}

package main

import "fmt"

func main() {
        var a, b [3]int
        //      fmt.Println(i)
        fmt.Scanf("%d %d %d\n", &a[0], &a[1], &a[2])
        fmt.Scanf("%d %d %d\n", &b[0], &b[1], &b[2])
        acnt, bcnt := 0, 0
        for i := 0; i < 3; i++ {
                if a[i]-b[i] > 0 {
                        acnt += (((a[i] - b[i]) / 2) * 2)
                } else {
                        bcnt += (b[i] - a[i])
                }
        }
        //fmt.Println(acnt)
        //fmt.Println(bcnt)
        if acnt/2 >= bcnt {
                fmt.Println("Yes")
        } else {
                fmt.Println("No")
        }
}

package main

import (
	"fmt"
)

func main() {
	var a [3]int
	if _, err := fmt.Scanf("%d %d %d\n", &a[0], &a[1], &a[2]); err != nil {
		return
	}
	var x [3]int
	if _, err := fmt.Scanf("%d %d %d\n", &x[0], &x[1], &x[2]); err != nil {
		return
	}

	var d [3]int
	neg := 0
	for i := 0; i < 3; i++ {
		d[i] = a[i] - x[i]
		if d[i] < 0 {
			neg += d[i]
		}
	}

	for neg < 0 {
		ok := false
		for i := 0; i < 3; i++ {
			if d[i] >= 2 {
				neg++
				d[i] -= 2
				ok = true
				break
			}
		}
		if !ok {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}

package main

import "fmt"

func main() {
    var a, b, c, x, y, z int
    fmt.Scanf("%d%d%d\n",&a,&b,&c);
    fmt.Scanf("%d%d%d\n",&x,&y,&z);
    aa := a - x
    if (aa > 0) {
        aa /= 2
    }
    bb := b - y
    if (bb > 0) {
        bb /= 2
    }
    cc := c - z
    if (cc > 0) {
        cc /= 2
    }

    ans := aa + bb + cc

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

package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	var x, y, z int
	fmt.Scan(&x, &y, &z)
	var addA = a - x
	var addB = b - y
	var addC = c - z
	var add int
	var minus int
	if addA > 0 {
		add += addA / 2
	} else {
		minus += addA
	}
	if addB > 0 {
		add += addB / 2
	} else {
		minus += addB
	}
	if addC > 0 {
		add += addC / 2
	} else {
		minus += addC
	}
	if add+minus >= 0 {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}

package main

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

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

	var a, b, c int
	var tA, tB, tC int

	fmt.Fscanf(stdin, "%d%d%d\n", &a, &b, &c)
	fmt.Fscanf(stdin, "%d%d%d\n", &tA, &tB, &tC)

	a = a - tA
	b = b - tB
	c = c - tC

	// fmt.Println(a, b, c)

	if a < 0 {
		a = a * 2
	} else {
		a = a / 2 * 2
	}
	if b < 0 {
		b = b * 2
	} else {
		b = b / 2 * 2
	}
	if c < 0 {
		c = c * 2
	} else {
		c = c / 2 * 2
	}

	if a + b + c >= 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

package main

import "fmt"

func main(){
	var (
		a int
		b int
		c int
		x int
		y int
		z int
	)
	fmt.Scanf("%d%d%d",&a,&b,&c)
	fmt.Scanf("%d%d%d",&x,&y,&z)
	if (x > a){
		x -= a
		a = 0
	}else {
		a -= x
		x = 0
	}
	if (y > b){
		y -= b
		b = 0
	}else {
		b -= y
		y = 0
	}
	if (z > c){
		z -= c
		c = 0
	}else {
		c -= z
		z = 0
	}
	if (x + y + z) <= (a/2 + b/2 + c/2){
		fmt.Println("Yes")
	}else {
		fmt.Println("No")
	}
}

package main

import "fmt"

func main(){
	var (
		a int
		b int
		c int
		x int
		y int
		z int
	)
	fmt.Scanf("%d%d%d",&a,&b,&c)
	fmt.Scanf("%d%d%d",&x,&y,&z)
	if (x > a){
		x -= a
		a = 0
	}else {
		a -= x
		x = 0
	}
	if (y > b){
		y -= b
		b = 0
	}else {
		b -= y
		y = 0
	}
	if (z > c){
		z -= c
		c = 0
	}else {
		c -= z
		z = 0
	}
	if (x + y + z) <= (a/2 + b/2 + c/2){
		fmt.Print("Yes")
	}else {
		fmt.Print("No")
	}
}

package main

import "fmt"

func main() {
        var a, b [3]int
        for i := 0; i < 3; i++ {
                //      fmt.Println(i)
                fmt.Scanf("%d", &a[i])
        }
        for i := 0; i < 3; i++ {
                fmt.Scanf("%d", &b[i])
        }
        acnt, bcnt := 0, 0
        for i := 0; i < 3; i++ {
                if a[i]-b[i] > 0 {
                        acnt += (((a[i] - b[i]) / 2) * 2)
                } else {
                        bcnt += (b[i] - a[i])
                }
        }
        //fmt.Println(acnt)
        //fmt.Println(bcnt)
        if acnt/2 >= bcnt {
                fmt.Println("Yes")
        } else {
                fmt.Println("No")
        }
}

package main

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

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

	var a, b, c int
	var tA, tB, tC int

	fmt.Fscanf(stdin, "%d%d%d\n", &a, &b, &c)
	fmt.Fscanf(stdin, "%d%d%d\n", &tA, &tB, &tC)

	a = a - tA
	b = b - tB
	c = c - tC

	// fmt.Println(a, b, c)

	if a < 0 {
		a = a * 2
	}
	if b < 0 {
		b = b * 2
	}
	if c < 0 {
		c = c * 2
	}

	if a + b + c >= 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}