A binary string is a string where each character is either 0 or 1. Two binary strings $$$a$$$ and $$$b$$$ of equal length are similar, if they have the same character in some position (there exists an integer $$$i$$$ such that $$$a_i = b_i$$$). For example:  10010 and 01111 are similar (they have the same character in position $$$4$$$);  10010 and 11111 are similar;  111 and 111 are similar;  0110 and 1001 are not similar. You are given an integer $$$n$$$ and a binary string $$$s$$$ consisting of $$$2n-1$$$ characters. Let's denote $$$s[l..r]$$$ as the contiguous substring of $$$s$$$ starting with $$$l$$$-th character and ending with $$$r$$$-th character (in other words, $$$s[l..r] = s_l s_{l + 1} s_{l + 2} \dots s_r$$$).You have to construct a binary string $$$w$$$ of length $$$n$$$ which is similar to all of the following strings: $$$s[1..n]$$$, $$$s[2..n+1]$$$, $$$s[3..n+2]$$$, ..., $$$s[n..2n-1]$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$). The second line of each test case contains the binary string $$$s$$$ of length $$$2n - 1$$$. Each character $$$s_i$$$ is either 0 or 1.

For each test case, print the corresponding binary string $$$w$$$ of length $$$n$$$. If there are multiple such strings — print any of them. It can be shown that at least one string $$$w$$$ meeting the constraints always exists.

NoteThe explanation of the sample case (equal characters in equal positions are bold):The first test case:   $$$\mathbf{1}$$$ is similar to $$$s[1..1] = \mathbf{1}$$$. The second test case:   $$$\mathbf{000}$$$ is similar to $$$s[1..3] = \mathbf{000}$$$;  $$$\mathbf{000}$$$ is similar to $$$s[2..4] = \mathbf{000}$$$;  $$$\mathbf{000}$$$ is similar to $$$s[3..5] = \mathbf{000}$$$. The third test case:   $$$\mathbf{1}0\mathbf{10}$$$ is similar to $$$s[1..4] = \mathbf{1}1\mathbf{10}$$$;  $$$\mathbf{1}01\mathbf{0}$$$ is similar to $$$s[2..5] = \mathbf{1}10\mathbf{0}$$$;  $$$\mathbf{10}1\mathbf{0}$$$ is similar to $$$s[3..6] = \mathbf{10}0\mathbf{0}$$$;  $$$1\mathbf{0}1\mathbf{0}$$$ is similar to $$$s[4..7] = 0\mathbf{0}0\mathbf{0}$$$. The fourth test case:   $$$0\mathbf{0}$$$ is similar to $$$s[1..2] = 1\mathbf{0}$$$;  $$$\mathbf{0}0$$$ is similar to $$$s[2..3] = \mathbf{0}1$$$.

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"sync"
)
var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _  := strconv.Atoi(intStr)
	return i
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)
	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()
		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}
func work(){
	n:=ReadInt()
	s:=ReadString()
	for i:=0;i<n;i++{
		fmt.Printf("%c",s[n-1])
	}
	fmt.Println("")
}
func main(){
	for t:=ReadInt();t>0;t--{
		work()
	}
	close(out)
}

package main

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

func main() {
	var t, n int
	var s string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &s)
		idx := len(s) / 2
		for j := 0; j < n; j++ {
			fmt.Printf("%s", string(s[idx]))
		}
		fmt.Println()
	}
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		s, _ := reader.ReadString('\n')
		res := solve(n, s)
		buf.WriteString(res)
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n int, s string) string {
	buf := make([]byte, n)
	var j int
	for i := 0; i < n; i++ {
		buf[i] = s[i+j]
		j++
	}

	return string(buf)
}

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		n, s := io.NextInt(), io.Next()
		var ans []byte
		for i := 0; i < n; i++ {
			ok := false
			for j := 0; j < len(ans); j++ {
				if s[i+j] == ans[j] {
					ok = true
					break
				}
			}
			if !ok {
				ans = append(ans, s[i+len(ans)])
			}
		}
		for len(ans) < n {
			ans = append(ans, '0')
		}
		io.Println(string(ans))
	}
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

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

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

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

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

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

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	ini := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	ins := func() string {
		sc.Scan()
		return sc.Text()
	}

	for t := ini(); t > 0; t-- {
		n := ini()

		s := ins()

		ns := make([]byte, n)

		for i := 0; i < n; i++ {
			ns[i] = s[2*i]
		}

		nss := string(ns)

		fmt.Println(nss)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		var str string
		fmt.Fscan(in, &str)
		b := str[n-1]
		for j := 0; j < n; j++ {
			fmt.Print(string(b))
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
)

//找到一个字符串，他与任意长度为n的字符串相似
func main() {
	var t int

	n := 0
	fmt.Scan(&t)
	for t > 0 {
		t--

		fmt.Scan(&n)
		var str string
		fmt.Scan(&str)
		ans:=""
		for i:=0;i<len(str);i+=2 {
			ans += string(str[i])
		}
		fmt.Println(ans)
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var reader = bufio.NewReader(os.Stdin)
//找到一个字符串，他与任意长度为n的字符串相似
func main() {
	var t int

	n := 0
	//fmt.Scan(&t)
	fmt.Fscan(reader,&t)
	for t > 0 {
		t--

		fmt.Fscan(reader,&n)
		//fmt.Scan(&n)
		var str string
		fmt.Fscan(reader,&str)
		//fmt.Scan(&str)
		ans:=""
		for i:=0;i<len(str);i+=2 {
			ans += string(str[i])
		}
		fmt.Println(ans)
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)
var reader = bufio.NewReader(os.Stdin)
//找到一个字符串，他与任意长度为n的字符串相似
func main() {
	var t int

	n := 0
	//fmt.Scan(&t)
	fmt.Fscan(reader,&t)
	for t > 0 {
		t--

		fmt.Fscan(reader,&n)
		//fmt.Scan(&n)
		var str string
		fmt.Fscan(reader,&str)
		//fmt.Scan(&str)
		fmt.Println(strings.Repeat(string(str[n-1]),n))
	}

}

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

package main

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

var (
	t int

	n int
	S []rune
)

func main() {
	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	T := [][]rune{}
	for i := 0; i < n; i++ {
		sub := S[i : i+n]
		T = append(T, sub)
	}
	// PrintfDebug("===\n")
	// for _, sub := range T {
	// 	PrintfDebug("%v\n", string(sub))
	// }
	// PrintfDebug("===\n")

	A := make([]rune, n)
	for i := 0; i < n; i++ {
		A[i] = T[i][i]
	}
	fmt.Println(string(A))
}

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

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

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

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

/********** 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...)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

package main

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

var t int

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

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {

		var n int
		var s string
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &s)

		for i := 0; i < n; i++ {
			fmt.Print(string(s[n-1]))
		}

		fmt.Println()
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

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

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

		var s string
		fmt.Fscan(reader, &s)
		// s, _ := reader.ReadString('\n')
		fmt.Println(strings.Repeat(string(s[n-1]), n))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"sync"
)
var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _  := strconv.Atoi(intStr)
	return i
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)
	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()
		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}
func work(){
	n:=ReadInt()
	s:=ReadString()
	fmt.Println(s[0:n])
}
func main(){
	for t:=ReadInt();t>0;t--{
		work()
	}
	close(out)
}

package main

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

func main() {
	var t, n int
	var s string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &s)
		for j := 0; j < n; j++ {
			fmt.Printf("%s", string(s[n/2]))
		}
		fmt.Println()
	}
}

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		n, s := io.NextInt(), io.Next()
		io.Println(s[:n])
	}
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

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

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

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

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

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

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	ini := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	ins := func() string {
		sc.Scan()
		return sc.Text()
	}

	for t := ini(); t > 0; t-- {
		n := ini()

		s := ins()

		fmt.Println(s[0:n])
	}
}

package main

import (
	"fmt"
)

//找到一个字符串，他与任意长度为n的字符串相似
func main() {
	var t int

	n := 0
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		var str string
		fmt.Scan(&str)

		var tmp int64
		var ans int64 = 0xffffffff
		for j := 0; j <= len(str)-n; j++ {
			for k := j; k < j+n; k++ {
				tmp <<= 1
				if str[k] == '1' {
					tmp |= 1
				}
			}
		}
		ans &= tmp
		for i := 0; i < n; i++ {
			fmt.Printf("%d", (ans>>i)&1)
		}
	}

}

package main

import (
	"fmt"
)

//找到一个字符串，他与任意长度为n的字符串相似
func main() {
	var t int

	n := 0
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		var str string
		fmt.Scan(&str)

		var tmp int64
		var ans int64 = 0xffffffff
		for j := 0; j <= len(str)-n; j++ {
			for k := j; k < j+n; k++ {
				tmp <<= 1
				if str[k] == '1' {
					tmp |= 1
				}
			}
		}
		ans &= tmp
		for i := 0; i < n; i++ {
			fmt.Printf("%d", (ans>>i)&1)
		}
		println()
	}

}

package main

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

var t int

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

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {

		var n int
		var s string
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &s)

		for i := 0; i < (n - 1); i++ {
			fmt.Print(string(48))
		}

		fmt.Println(string(s[n-1]))
	}
}

package main

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

var t int

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

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {

		var n int
		var s string
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &s)

		fmt.Print(string(48))
		for i := 1; i < (n - 1); i++ {
			fmt.Print(string(49))
		}

		fmt.Println(string(48))
	}
}


While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface.  Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$?

The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$).

Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$.

package main

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

/* solution */

func solve() {

	h, l := float64(readInt()), float64(readInt())
	y := math.Atan(l / h)
	x := l/math.Sin(float64(math.Pi-2*y)) - h
	println(strconv.FormatFloat(x, 'f', 9, 64))

}

/* stubs */

func main() {

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

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

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

	solve()

}

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

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

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

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

package main

import "fmt"

func main() {
	var h, l float64
	fmt.Scanf("%f %f", &h, &l)
	fmt.Print((l*l-h*h)/2/h)
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var (
		H int
		L int
	)
	_, _ = fmt.Fscanf(input, "%d %d", &H, &L)

	var ans float64
	fL := float64(L)
	fH := float64(H)

	ans = (fL*fL)/(2*fH) - fH/2

	fmt.Printf("%.13f\n", ans)
}

package main

import "fmt"

func main() {
	var H, L float64
	fmt.Scan(&H, &L)
	fmt.Println((L*L - H*H) / (2 * H))
}

package main

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

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

	var H, L int
	fmt.Fscanf(input, "%d %d\n", &H, &L)
	h := float64(H)
	l := float64(L)
	fmt.Println((l*l - h*h) / h * .5)
}

package main

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

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

	var h, l float64
	Fscan(in, &h, &l)
	Fprintf(out, "%.13f", (l*l-h*h)/(2*h))
}

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

package main

import (
	"fmt"

)

func main() {
	//input
	h, l := 0, 0
	fmt.Scanf("%d %d", &h, &l)
	//output
	fmt.Print(solution(float64(h), float64(l)))
}
func solution(h float64, l float64) float64 {

	r := (l * l - h * h) / (2 * h)
	return r
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var h, l int64
	var result float64

	_, err := fmt.Fscanf(input, "%d %d\n", &h, &l)
	if err != nil {
	}

	result = (float64(l*l) / float64(2*h)) - float64(h)/2.0
	fmt.Printf("%.13f", result)

}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var h, l int
	var result float64

	_, err := fmt.Fscanf(input, "%d %d\n", &h, &l)
	if err != nil {
	}

	result = (float64(l) * float64(l) / (float64(h) * 2)) - float64(h)/2.0
	fmt.Printf("%.13f", result)

}

package main

import (
	"fmt"
)

func main(){
	var h, l uint64
	fmt.Scanln(&h, &l)

	x := float64(l * l - h * h) / float64(2 * h)
	fmt.Printf("%.6f", x)
}

package main

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

func main() {

	//stdin, err := os.Open("in.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("test.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

	var h, l int64
	fmt.Fscanf(reader, "%d %d\n", &h, &l)
	fmt.Fprintf(writer, "%0.10f\n", float64(l*l-h*h)/float64(2*h))
	writer.Flush()
}

package main

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

type myItem struct {
	v   uint8
	idx int
}

type myHeap []myItem

func (h myHeap) Len() int           { return len(h) }
func (h myHeap) Less(i, j int) bool { return h[i].v < h[j].v }
func (h myHeap) Swap(i, j int)      { h[j], h[i] = h[i], h[j] }

func (h *myHeap) Push(x interface{}) {
	*h = append(*h, x.(myItem))
}

func (h *myHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {

	f, _ := os.Open("input.txt")
	defer f.Close()

	scanner := bufio.NewScanner(f)
	scanner.Split(bufio.ScanWords)

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

	k := readInt(scanner)
	arrs := make([][]uint8, k, k)
	pointer := make([]int, k, k)

	h := &myHeap{}
	heap.Init(h)
	for i := 0; i < k; i++ {
		pointer[i] = 0
		n := readInt(scanner)
		if n > 0 {
			arrs[i] = make([]uint8, n, n)
		}
		for j := 0; j < n; j++ {
			v := uint8(readInt(scanner))
			arrs[i][j] = v
			if j == 0 {
				heap.Push(h, myItem{v, i})
			}
		}
	}

	for h.Len() > 0 {
		item := heap.Pop(h).(myItem)
		writer.WriteString(strconv.Itoa(int(item.v)))
		writer.WriteString(" ")
		pointer[item.idx]++
		if pointer[item.idx] < len(arrs[item.idx]) {
			heap.Push(h, myItem{arrs[item.idx][pointer[item.idx]], item.idx})
		}

	}

}

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

package main

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

/* solution */

func solve() {

	h, l := float64(readInt()), float64(readInt())
	r := math.Sqrt(h*h + l*l)
	y := math.Asin(l / r)
	x := l/math.Sin(float64(math.Pi-2*y)) - h
	println(strconv.FormatFloat(x, 'f', 9, 64))

}

/* stubs */

func main() {

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

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

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

	solve()

}

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

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

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

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

package main

import "fmt"

func main() {
	var h, l float32
	fmt.Scanf("%f %f", &h, &l)
	fmt.Print((l*l-h*h)/2/h)
}

package main

import (
	"fmt"

)

func main() {
	//input
	h, l := 0, 0
	fmt.Scanf("%d %d", &h, &l)
	//output
	fmt.Print(solution(float64(h), float64(l)))
}
func solution(h float64, l float64) float64 {

	r := (l * l - h * h) / 2 * h
	return r
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var h int
	var l int
	fmt.Scanf("%d %d", &h, &l)
	fmt.Print(solution(float64(h), float64(l)))
}

func solution(h float64, l float64) float64 {

	k := math.Sqrt((math.Pow(h,2) + math.Pow(l,2)))
	HA :=  (k / math.Sqrt(h))
	return math.Sqrt(HA)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var h int
	var l int
	fmt.Scanf("%d %d", &h, &l)
	result := fmt.Sprintf("%.1f", solution(float64(h), float64(l)))
	fmt.Print(result)
}

func solution(h float64, l float64) float64 {

	k := math.Sqrt((math.Pow(h,2) + math.Pow(l,2)))
	HA :=  (k / math.Sqrt(h))
	return math.Sqrt(HA)
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var h, l int
	var result float64

	_, err := fmt.Fscanf(input, "%d %d\n", &h, &l)
	if err != nil {
	}

	result = (float64(l*l) / float64(2*h)) - float64(h)/2.0
	fmt.Printf("%.13f", result)

}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var h, l int
	var result float32

	_, err := fmt.Fscanf(input, "%d %d\n", &h, &l)
	if err != nil {
	}

	result = (float32(l)/float32(2*h))*float32(l) - float32(h)/2.0
	fmt.Println(result)

}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var h, l int
	var result float64

	_, err := fmt.Fscanf(input, "%d %d\n", &h, &l)
	if err != nil {
	}

	result = (float64(l*l)/float64(2*h)) - float64(h)/2.0
	fmt.Println(result)

}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var h, l int
	var result float64

	_, err := fmt.Fscanf(input, "%d %d\n", &h, &l)
	if err != nil {
	}

	result = float64(l*l-h*h) / float64(2*h)
	fmt.Println(result)

}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var h, l int
	var result float32

	_, err := fmt.Fscanf(input, "%d %d\n", &h, &l)
	if err != nil {
	}

	result = (float32(l*l)/float32(2*h)) - float32(h)/2.0
	fmt.Println(result)

}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var h, l int
	var result float32

	_, err := fmt.Fscanf(input, "%d %d\n", &h, &l)
	if err != nil {
	}

	result = float32(l*l-h*h) / float32(2*h)
	fmt.Println(result)

}

package main

import (
	"fmt"
)

func main(){
	var h, l uint32
	fmt.Scanln(&h, &l)

	x := float64(l * l - h * h) / float64(2 * h)
	fmt.Printf("%.6f", x)
}

package main

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

func main() {

	//stdin, err := os.Open("in.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("test.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

	var h, l int
	fmt.Fscanf(reader, "%d %d\n", &h, &l)
	fmt.Fprintf(writer, "%0.7f\n", float64(l*l-h*h)/float64(2*h))
	writer.Flush()
}


You are given two strings $$$s$$$ and $$$t$$$ of equal length $$$n$$$. In one move, you can swap any two adjacent characters of the string $$$s$$$.You need to find the minimal number of operations you need to make string $$$s$$$ lexicographically smaller than string $$$t$$$.A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds:   $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$;  in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.

The first line of input contains one integer $$$q$$$ ($$$1 \le q \le 10\,000$$$): the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains the string $$$s$$$ consisting of $$$n$$$ lowercase English letters. The third line of each test case contains the string $$$t$$$ consisting of $$$n$$$ lowercase English letters. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print in a separate line the minimal number of operations you need to make string $$$s$$$ lexicographically smaller than string $$$t$$$, or $$$-1$$$, if it's impossible.

4
1
a
a
3
rll
rrr
3
caa
aca
5
ababa
aabba

package main

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

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

const ALPH = 27

func cloneAndSortBytes(original []byte) []byte {
	var arr = make([]byte, len(original))
	copy(arr, original)
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})
	return arr
}

var n int
var a, b []byte
var bitArr []int
var pos [][]int

func createBit() {
	bitArr = make([]int, n+16)
}

func updateBit(i, v int) {
	for i += 10; i < len(bitArr); i += (i & -i) {
		bitArr[i] += v
	}
}

func queryBit(i int) int {
	var ans = 0
	for i += 10; i > 0; i -= (i & -i) {
		ans += bitArr[i]
	}
	return ans
}

func findIndex(startAt int, x byte) int {
	var positions = pos[x]
	var lo = 0
	var hi = len(positions)
	var mi = 0
	for lo < hi {
		mi = (lo + hi) / 2
		if positions[mi]+queryBit(positions[mi]) < startAt {
			lo = mi + 1
		} else {
			hi = mi
		}
	}
	if lo < len(positions) {
		return positions[lo]
	}
	return n
}

func swap(i, j int) int {
	var curj = j + queryBit(j)
	updateBit(0, 1)
	updateBit(j, -1)
	return curj - i
}

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

func solveCase() int64 {
	fmt.Fscan(in, &n, &a, &b)

	var sorteda = cloneAndSortBytes(a)
	if string(sorteda) >= string(b) {
		return -1
	}

	createBit()
	pos = make([][]int, ALPH)

	for i := 0; i < n; i++ {
		a[i] -= 97
		b[i] -= 97
		pos[a[i]] = append(pos[a[i]], i)
	}

	var ans int64 = int64(n) * int64(n)
	var swaps int64 = 0
	for i := 0; i < n; i++ {
		// fmt.Fprintf(out, "i=%d, swaps = %d\n", i, swaps)
		var c byte = 0
		for c = 0; c < b[i]; c++ {
			var j = findIndex(i, c)
			if j < n {
				j += queryBit(j)
				// fmt.Fprintf(out, "index of %c starting at %d is %d (+%d)\n", rune(97+c), i, j, (j - i))
				ans = min(ans, swaps+int64(j-i))
			}
		}
		var j = findIndex(i, c)
		// fmt.Fprintf(out, "appending %c found at %d (new pos is %d)\n", rune(97+c), j, j+queryBit((j)))
		if j == n {
			return ans
		}
		swaps += int64(swap(i, j))
		pos[c] = pos[c][1:]
	}

	return ans
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		fmt.Fprintf(out, "%d\n", solveCase())
	}
	out.Flush()
}

package main

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

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

const ALPH = 26

func cloneAndSortBytes(original []byte) []byte {
	var arr = make([]byte, len(original))
	copy(arr, original)
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})
	return arr
}

var n int
var a, b []byte
var bitArr []int
var pos [][]int

func createBit() {
	bitArr = make([]int, n+12)
}

func updateBit(i, v int) {
	for i += 10; i < len(bitArr); i += (i & -i) {
		bitArr[i] += v
	}
}

func queryBit(i int) int {
	var ans = 0
	for i += 10; i > 0; i -= (i & -i) {
		ans += bitArr[i]
	}
	return ans
}

func findIndex(startAt int, x byte) int {
	var positions = pos[x]
	var lo = 0
	var hi = len(positions)
	var mi = 0
	for lo < hi {
		mi = (lo + hi) / 2
		if positions[mi]+queryBit(positions[mi]) < startAt {
			lo = mi + 1
		} else {
			hi = mi
		}
	}
	if lo < len(positions) {
		return positions[lo]
	}
	return n
}

func swap(i, j int) int {
	var curj = j + queryBit(j)
	updateBit(0, 1)
	updateBit(j, -1)
	return curj - i
}

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

func solveCase() int {
	fmt.Fscan(in, &n, &a, &b)

	var sorteda = cloneAndSortBytes(a)
	if string(sorteda) >= string(b) {
		return -1
	}

	createBit()
	pos = make([][]int, ALPH)

	for i := 0; i < n; i++ {
		a[i] -= 97
		b[i] -= 97
		pos[a[i]] = append(pos[a[i]], i)
	}

	var ans = n * n
	var swaps = 0
	for i := 0; i < n; i++ {
		// fmt.Fprintf(out, "i=%d, swaps = %d\n", i, swaps)
		var c byte = 0
		for c = 0; c < b[i]; c++ {
			var j = findIndex(i, c)
			if j < n {
				j += queryBit(j)
				// fmt.Fprintf(out, "index of %c starting at %d is %d (+%d)\n", rune(97+c), i, j, (j - i))
				ans = min(ans, swaps+(j-i))
			}
		}
		var j = findIndex(i, c)
		// fmt.Fprintf(out, "appending %c found at %d (new pos is %d)\n", rune(97+c), j, j+queryBit((j)))
		if j == n {
			return ans
		}
		swaps += swap(i, j)
		pos[c] = pos[c][1:]
	}

	return ans
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		fmt.Fprintf(out, "%d\n", solveCase())
	}
	out.Flush()
}


Archeologists have found a secret pass in the dungeon of one of the pyramids of Cycleland. To enter the treasury they have to open an unusual lock on the door. The lock consists of n words, each consisting of some hieroglyphs. The wall near the lock has a round switch. Each rotation of this switch changes the hieroglyphs according to some rules. The instruction nearby says that the door will open only if words written on the lock would be sorted in lexicographical order (the definition of lexicographical comparison in given in notes section).The rule that changes hieroglyphs is the following. One clockwise rotation of the round switch replaces each hieroglyph with the next hieroglyph in alphabet, i.e. hieroglyph x (1 ≤ x ≤ c - 1) is replaced with hieroglyph (x + 1), and hieroglyph c is replaced with hieroglyph 1.Help archeologist determine, how many clockwise rotations they should perform in order to open the door, or determine that this is impossible, i.e. no cyclic shift of the alphabet will make the sequence of words sorted lexicographically.

The first line of the input contains two integers n and c (2 ≤ n ≤ 500 000, 1 ≤ c ≤ 106) — the number of words, written on the lock, and the number of different hieroglyphs. Each of the following n lines contains the description of one word. The i-th of these lines starts with integer li (1 ≤ li ≤ 500 000), that denotes the length of the i-th word, followed by li integers wi, 1, wi, 2, ..., wi, li (1 ≤ wi, j ≤ c) — the indices of hieroglyphs that make up the i-th word. Hieroglyph with index 1 is the smallest in the alphabet and with index c — the biggest. It's guaranteed, that the total length of all words doesn't exceed 106.

If it is possible to open the door by rotating the round switch, print integer x (0 ≤ x ≤ c - 1) that defines the required number of clockwise rotations. If there are several valid x, print any of them. If it is impossible to open the door by this method, print  - 1.

NoteWord a1, a2, ..., am of length m is lexicographically not greater than word b1, b2, ..., bk of length k, if one of two conditions hold:   at first position i, such that ai ≠ bi, the character ai goes earlier in the alphabet than character bi, i.e. a has smaller character in the first position where they differ;  if there is no such position i and m ≤ k, i.e. the first word is a prefix of the second or two words are equal. The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.In the first sample, after the round switch is rotated 1 position clockwise the words look as follows:1 323 1 23 1 2 3In the second sample, words are already sorted in lexicographical order.In the last sample, one can check that no shift of the alphabet will work.

package main

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

func findStart(cur []int) (int, bool) {
    for i := 1; i < len(cur); i++ {
        if cur[i] < cur[i-1] {
            prev := cur[i]
            for d := 0; d < len(cur); d++ {
                if j := (i+d) % len(cur); cur[j] >= prev {
                    prev = cur[j]
                } else {
                    return 0, false
                }
            }
            return i, true
        }
    }
    return 0, true
}

func solve() {
    n, c := readInt(), readInt()
    a := make([][]int, n)
    for i := range a {
        a[i] = readIntArray(readInt())
    }
    cnts, need, can := make([]int, c+2), 0, true
    var process func(l, r, lvl int)
    process = func(l, r, lvl int) {
        cur := []int{}
        for i := l; i < r; i++ {
            cur = append(cur, a[i][lvl])
        }

        start, ok := findStart(cur);
        if !ok {
            can = false
            return
        }

        if cur[start] < cur[(start+len(cur)-1) % len(cur)] {
            mn, mx := 0, c-cur[len(cur)-1]+1
            if start > 0 {
                mn = c-cur[0]+1
            } else {
                cnts[c-cur[start]+1]++
                cnts[c]--
            }
            cnts[mn]++
            cnts[mx]--
            need++
        }

        was, nextL, nextLvl := false, l, lvl+1
        for i := l;; {
            if i < r && a[i][lvl] == a[nextL][lvl] {
                if len(a[i]) == nextLvl {
                    if was {
                        can = false
                        return
                    }
                    nextL = i+1
                } else {
                    was = true
                }
                i++
            } else {
                if i > nextL+1 {
                    process(nextL, i, nextLvl)
                }
                was, nextL = false, i
                if i == r {
                    break
                }
            }
        }
    }

    process(0, n, 0)
    ans := -1
    if can {
        s := 0
        for i, cnt := range cnts {
            s += cnt
            if s == need {
                ans = i
                break
            }
        }
    }
    fmt.Println(ans)
}

// 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"
	"strconv"
)

func findStart(cur []int) (int, bool) {
    for i := 1; i < len(cur); i++ {
        if cur[i] < cur[i-1] {
            prev := cur[i]
            for d := 0; d < len(cur); d++ {
                if j := (i+d) % len(cur); cur[j] >= prev {
                    prev = cur[j]
                } else {
                    return 0, false
                }
            }
            return i, true
        }
    }
    return 0, true
}

func solve() {
    n, c := readInt(), readInt()
    a := make([][]int, n)
    for i := range a {
        a[i] = readIntArray(readInt())
    }
    cnts, need, can := make([]int, c+2), 0, true
    var process func(l, r, lvl int)
    process = func(l, r, lvl int) {
        cur := []int{}
        for i := l; i < r; i++ {
            cur = append(cur, a[i][lvl])
        }

        start, ok := findStart(cur);
        if !ok {
            can = false
            return
        }

        mn, mx := 0, c-cur[len(cur)-1]+1
        if start > 0 {
            mn = c-cur[0]+1
        }

        if c == 1000000 {
            fmt.Print(l, r, lvl, "->", mn, mx, "|")
        }

        if cur[start] < cur[(start+len(cur)-1) % len(cur)] {
            cnts[mn]++
            cnts[mx]--
            need++
        }

        was, nextL, nextLvl := false, l, lvl+1
        for i := l;; {
            if i < r && a[i][lvl] == a[nextL][lvl] {
                if len(a[i]) == nextLvl {
                    if was {
                        can = false
                        return
                    }
                    nextL = i+1
                } else {
                    was = true
                }
                i++
            } else {
                if i > nextL+1 {
                    process(nextL, i, nextLvl)
                }
                was, nextL = false, i
                if i == r {
                    break
                }
            }
        }
    }

    process(0, n, 0)
    ans := -1
    if can {
        s := 0
        for i, cnt := range cnts {
            s += cnt
            if s == need {
                ans = i
                break
            }
        }
    }
    fmt.Println(ans)
}

// 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"
	"strconv"
)

func findStart(cur []int) (int, bool) {
    for i := 1; i < len(cur); i++ {
        if cur[i] < cur[i-1] {
            prev := cur[i]
            for d := 0; d < len(cur); d++ {
                if j := (i+d) % len(cur); cur[j] >= prev {
                    prev = cur[j]
                } else {
                    return 0, false
                }
            }
            return i, true
        }
    }
    return 0, true
}

func solve() {
    n, c := readInt(), readInt()
    a := make([][]int, n)
    for i := range a {
        a[i] = readIntArray(readInt())
    }
    cnts, need, can := make([]int, c+1), 0, true
    var process func(l, r, lvl int)
    process = func(l, r, lvl int) {
        cur := []int{}
        for i := l; i < r; i++ {
            if lvl < len(a[i]) {
                cur = append(cur, a[i][lvl])
            }
        }

        if len(cur) < 2 {
            return
        }

        start, ok := findStart(cur);
        if !ok {
            can = false
            return
        }

        mn, mx := 0, c-cur[len(cur)-1]+1
        if start > 0 {
            mn = c-cur[0]+1
        }

        if cur[start] < cur[(start+len(cur)-1) % len(cur)] {
            cnts[mn]++
            cnts[mx]--
            need++
        }

        was, nextL, nextLvl := false, l, lvl+1
        for i := l; i <= r; i++ {
            if i < r && a[i][lvl] == a[nextL][lvl] {
                if len(a[i]) == nextLvl {
                    if was {
                        can = false
                        return
                    }
                } else {
                    was = true
                }
            } else {
                process(nextL, i, nextLvl)
                was, nextL = false, i
            }
        }
    }

    process(0, n, 0)
    ans := -1
    if can {
        s := 0
        for i, cnt := range cnts {
            s += cnt
            if s == need {
                ans = i
            }
        }
    }
    fmt.Println(ans)
}

// 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"
	"strconv"
)

func findStart(cur []int) (int, bool) {
    for i := 1; i < len(cur); i++ {
        if cur[i] < cur[i-1] {
            prev := cur[i]
            for d := 0; d < len(cur); d++ {
                if j := (i+d) % len(cur); cur[j] >= prev {
                    prev = cur[j]
                } else {
                    return 0, false
                }
            }
            return i, true
        }
    }
    return 0, true
}

func solve() {
    n, c := readInt(), readInt()
    a := make([][]int, n)
    for i := range a {
        a[i] = readIntArray(readInt())
    }
    cnts, need, can := make([]int, c+2), 0, true
    var process func(l, r, lvl int)
    process = func(l, r, lvl int) {
        cur := []int{}
        for i := l; i < r; i++ {
            cur = append(cur, a[i][lvl])
        }

        start, ok := findStart(cur);
        if !ok {
            can = false
            return
        }

        mn, mx := 0, c-cur[len(cur)-1]+1
        if start > 0 {
            mn = c-cur[0]+1
        }

        if cur[start] < cur[(start+len(cur)-1) % len(cur)] {
            cnts[mn]++
            cnts[mx]--
            need++
        }

        was, nextL, nextLvl := false, l, lvl+1
        for i := l;; {
            if i < r && a[i][lvl] == a[nextL][lvl] {
                if len(a[i]) == nextLvl {
                    if was {
                        can = false
                        return
                    }
                    nextL = i+1
                } else {
                    was = true
                }
                i++
            } else {
                if i > nextL+1 {
                    process(nextL, i, nextLvl)
                }
                was, nextL = false, i
                if i == r {
                    break
                }
            }
        }
    }

    process(0, n, 0)
    ans := -1
    if can {
        s := 0
        for i, cnt := range cnts {
            s += cnt
            if s == need {
                ans = i
                break
            }
        }
    }
    fmt.Println(ans)
}

// 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"
	"strconv"
)

func findStart(cur []int) (int, bool) {
    for i := 1; i < len(cur); i++ {
        if cur[i] < cur[i-1] {
            prev := cur[i]
            for d := 0; d < len(cur); d++ {
                if j := (i+d) % len(cur); cur[j] >= prev {
                    prev = cur[j]
                } else {
                    return 0, false
                }
            }
            return i, true
        }
    }
    return 0, true
}

func solve() {
    n, c := readInt(), readInt()
    a := make([][]int, n)
    for i := range a {
        a[i] = readIntArray(readInt())
    }
    cnts, need, can := make([]int, c+1), 0, true
    var process func(l, r, lvl int)
    process = func(l, r, lvl int) {
        cur := []int{}
        for i := l; i < r; i++ {
            if lvl < len(a[i]) {
                cur = append(cur, a[i][lvl])
            }
        }

        if len(cur) < 2 {
            return
        }

        start, ok := findStart(cur);
        if !ok {
            can = false
            return
        }

        mn, mx := 0, c-cur[len(cur)-1]+1
        if start > 0 {
            mn = c-cur[0]+1
        }

        if cur[start] < mx {
            cnts[mn]++
            cnts[mx]--
            need++
        }
        was, nextL, nextLvl := false, l, lvl+1
        for i := l; i <= r; i++ {
            if i < r && a[i][lvl] == a[nextL][lvl] {
                if len(a[i]) == nextLvl {
                    if was {
                        can = false
                        return
                    }
                } else {
                    was = true
                }
            } else {
                process(nextL, i, nextLvl)
                was, nextL = false, i
            }
        }
    }

    process(0, n, 0)
    ans := -1
    if can {
        s := 0
        for _, cnt := range cnts {
            s += cnt
            if s == need {
                ans = cnt
            }
        }
    }
    fmt.Println(ans)
}

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


Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that also lies in the range from 1 to 109, inclusive. It is not allowed to replace a number with itself or to change no number at all. After the replacement Petya sorted the array by the numbers' non-decreasing. Now he wants to know for each position: what minimum number could occupy it after the replacement and the sorting.

The first line contains a single integer n (1 ≤ n ≤ 105), which represents how many numbers the array has. The next line contains n space-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive.

Print n space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.

package main

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

var scanner *bufio.Scanner

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

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

  n := int(getI())
  original := make([]int, n)
  for i := range original {
    original[i] = int(getI())
  }
  sorted := make([]int, n)
  copy(sorted, original)
  sort.Ints(sorted)
  if sorted[n-1] == 1 {
    sorted[n-1] = 2
  } else {
    sorted[n-1] = 1
  }
  sort.Ints(sorted)
  writer.WriteString(fmt.Sprintf("%d", sorted[0]))
  for i := 1; i < n; i++ {
    writer.WriteString(fmt.Sprintf(" %d", sorted[i]))
  }
  writer.WriteString("\n")
}

package main

import "fmt"
import "sort"
import "os"
import "bufio"
import "strconv"

func main(){
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	for i:=0; i<n; i++ {
		r.Scan()
		arr[i], _ = strconv.Atoi(r.Text())
	}
	sort.Ints(arr)
	if arr[n-1] != 1 {
		arr[n-1] = 1
	} else {
		arr[n-1] = 2
	}
	sort.Ints(arr)
	for j:=0; j<n; j++ {
		fmt.Print(arr[j], " ")
	}
	fmt.Println()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    sort.Ints(a)
    for i := 0; i < n; i++ {
        if i == 0 {
            if (n == 1) && (a[i] == 1) { writer.WriteString("2") } else { writer.WriteString("1") }
        } else if i == (n-1) {
            if a[i] == 1 { writer.WriteString("2") } else { writer.WriteString(strconv.Itoa(a[i-1])) }
        } else {
            writer.WriteString(strconv.Itoa(a[i-1]))
        }
        if i == (n-1) { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
    }
    writer.Flush()
}

// 135A
package main

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

func main() {
	var x int
	fmt.Scan(&x)
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	a := make([]int, x)
	for i := 0; i < x; i++ {
		in.Scan()
		a[i], _ = strconv.Atoi(in.Text())
	}
	sort.Sort(sort.IntSlice(a))
	if a[x-1] == 1 {
		a[x-1] = 2
	} else {
		a[x-1] = 1
	}
	sort.Sort(sort.IntSlice(a))
	for i := 0; i < x; i++ {
		fmt.Print(a[i], " ")
	}
}

// 135A-mic_rizal
package main

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

func main() {
    var n, max, x int
    z := bufio.NewReader(os.Stdin)
    fmt.Fscan(z, &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(z, &a[i])
        if a[i] > max {
            max = a[i]
            x = i
        }
    }

    if a[x] > 1 {
        a[x] = 1
    } else {
        a[x] = 2
    }
    sort.Sort(sort.IntSlice(a))
    for i := 0; i < n; i++ {
        fmt.Print(a[i])
        fmt.Print(" ")
    }
    fmt.Println()
}

package main

import "fmt"
import "sort"

func main(){
	var n int
	fmt.Scan(&n)
	arr := make([]float64, n)
	for i:=0; i<n; i++ {
		fmt.Scan(&arr[i])
	}
	sort.Sort(sort.Float64Slice(arr))
	if arr[n-1] != 1 {
		arr[n-1] = 1
	} else {
		arr[n-1] = 2
	}
	sort.Sort(sort.Float64Slice(arr))
	for j:=0; j<n; j++ {
		fmt.Print(arr[j], " ")
	}
	fmt.Println()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    sort.Ints(a)
    for i := 0; i < n; i++ {
        if i == 0 {
            writer.WriteString("1")
        } else {
            writer.WriteString(strconv.Itoa(a[i-1]))
        }
        if i == (n-1) { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
    }
    writer.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    sort.Ints(a)
    for i := 0; i < n; i++ {
        if i == 0 {
            writer.WriteString("1")
        } else if i == (n-1) {
            if a[i] == 1 { writer.WriteString("2") } else { writer.WriteString(strconv.Itoa(a[i-1])) }
        } else {
            writer.WriteString(strconv.Itoa(a[i-1]))
        }
        if i == (n-1) { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
    }
    writer.Flush()
}

// 135A
package main

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

func main() {
	var x int
	fmt.Scan(&x)
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	a := make([]int, x)
	for i := 0; i < x; i++ {
		in.Scan()
		a[i], _ = strconv.Atoi(in.Text())
	}
	sort.Sort(sort.IntSlice(a))
	if a[x-1] == 1 {
		a[x-1] = 2
	} else {
		a[x-1] = 1
	}
	sort.Sort(sort.IntSlice(a))
	for i := 0; i < x; i++ {
		fmt.Print(a[i])
	}
}


Lunar New Year is approaching, and Bob received a gift from his friend recently — a recursive sequence! He loves this sequence very much and wants to play with it.Let $$$f_1, f_2, \ldots, f_i, \ldots$$$ be an infinite sequence of positive integers. Bob knows that for $$$i > k$$$, $$$f_i$$$ can be obtained by the following recursive equation:$$$$$$f_i = \left(f_{i - 1} ^ {b_1} \cdot f_{i - 2} ^ {b_2} \cdot \cdots \cdot f_{i - k} ^ {b_k}\right) \bmod p,$$$$$$which in short is$$$$$$f_i = \left(\prod_{j = 1}^{k} f_{i - j}^{b_j}\right) \bmod p,$$$$$$where $$$p = 998\,244\,353$$$ (a widely-used prime), $$$b_1, b_2, \ldots, b_k$$$ are known integer constants, and $$$x \bmod y$$$ denotes the remainder of $$$x$$$ divided by $$$y$$$.Bob lost the values of $$$f_1, f_2, \ldots, f_k$$$, which is extremely troublesome – these are the basis of the sequence! Luckily, Bob remembers the first $$$k - 1$$$ elements of the sequence: $$$f_1 = f_2 = \ldots = f_{k - 1} = 1$$$ and the $$$n$$$-th element: $$$f_n = m$$$. Please find any possible value of $$$f_k$$$. If no solution exists, just tell Bob that it is impossible to recover his favorite sequence, regardless of Bob's sadness.

The first line contains a positive integer $$$k$$$ ($$$1 \leq k \leq 100$$$), denoting the length of the sequence $$$b_1, b_2, \ldots, b_k$$$. The second line contains $$$k$$$ positive integers $$$b_1, b_2, \ldots, b_k$$$ ($$$1 \leq b_i < p$$$). The third line contains two positive integers $$$n$$$ and $$$m$$$ ($$$k < n \leq 10^9$$$, $$$1 \leq m < p$$$), which implies $$$f_n = m$$$.

Output a possible value of $$$f_k$$$, where $$$f_k$$$ is a positive integer satisfying $$$1 \leq f_k < p$$$. If there are multiple answers, print any of them. If no such $$$f_k$$$ makes $$$f_n = m$$$, output $$$-1$$$ instead. It is easy to show that if there are some possible values of $$$f_k$$$, there must be at least one satisfying $$$1 \leq f_k < p$$$.

NoteIn the first sample, we have $$$f_4 = f_3^2 \cdot f_2^3 \cdot f_1^5$$$. Therefore, applying $$$f_3 = 4$$$, we have $$$f_4 = 16$$$. Note that there can be multiple answers.In the third sample, applying $$$f_7 = 1$$$ makes $$$f_{23333} = 1$$$.In the fourth sample, no such $$$f_1$$$ makes $$$f_{88888} = 66666$$$. Therefore, we output $$$-1$$$ instead.

package main

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

var scanner *bufio.Scanner

func init() {
	scanner = bufio.NewScanner(bufio.NewReaderSize(os.Stdin, 1<<20))
	scanner.Split(bufio.ScanWords)
}

func NextInt64() int64 {
	scanner.Scan()
	var res int64
	var negative bool
	bytes := scanner.Bytes()
	if bytes[0] == '-' {
		negative = true
		bytes = bytes[1:]
	}
	for _, c := range bytes {
		res = res*10 + int64(c-'0')
	}
	if negative {
		res = -res
	}
	return res
}

func NextInt() int {
	return int(NextInt64())
}

func NextBigInt() *big.Int {
	scanner.Scan()
	n := new(big.Int)
	n, _ = n.SetString(scanner.Text(), 10)
	return n
}

const P = 998244353
const root = 3

//sum (min(r - i, min(x[l .. j[i]])) for i in range(l, r)

func polyMul(a, b []int64, mod int64) []int64 {
	res := make([]int64, len(a)+len(b)-1)
	for i, x := range a {
		for j, y := range b {
			res[i+j] += x * y
			res[i+j] %= mod
		}
	}
	return res
}

func polyMod(a, b []int64, mod int64) []int64 {
	res := a[:]
	for i := len(a) - 1; i >= len(b); i-- {
		for j, x := range b {
			res[i-1-j] += x * res[i]
			res[i-1-j] %= mod
		}
	}
	return res[:len(b)]
}

type BGStep struct {
	step  int64
	baby  []int64
	giant map[int64]int64
}

func pow(x int64, n int64, mod int64) int64 {
	res := int64(1)
	for ; n > 0; n >>= 1 {
		if n%2 == 1 {
			res = res * x % mod
		}
		x = x * x % mod
	}
	return res
}

func NewBGStep(p int64, r int64) BGStep {
	res := BGStep{}
	res.step = int64(math.Sqrt(float64(p) + 2))
	res.baby = make([]int64, res.step)
	res.giant = make(map[int64]int64, res.step)

	rstep := pow(r, res.step, p)

	rr := pow(r, p-2, p)

	res.baby[0] = 1
	curg := int64(1)

	res.giant[curg] = 0

	for i := int64(0); i+1 < res.step; i++ {
		res.baby[i+1] = res.baby[i] * rr % p
		curg = curg * rstep % p

		res.giant[curg] = i + 1
	}

	return res
}

func (b BGStep) Logarithm(x int64) int64 {
	if x == 0 {
		panic("x == 0")
	}

	for i := int64(0); i < b.step; i++ {
		v := x * b.baby[i] % P
		if index, ok := b.giant[v]; ok {
			return index*b.step + i
		}
	}

	panic("this shouldn't happen")
}

func GCD(a, b int64, x, y *int64) int64 {
	if b == 0 {
		*x, *y = 1, 0
		return a
	}
	//a * x + b * y == g

	//a == b * k + a'

	g := GCD(b, a%b, x, y)

	// b * x + (a - k * b) * y == g

	*x, *y = *y, *x-a/b**y

	return g
}

func main() {
	k := NextInt()
	var b []int64
	for i := 0; i < k; i++ {
		b = append(b, NextInt64())
	}

	n, m := NextInt64() - 1, NextInt64()

	bgs := NewBGStep(P, root)

	log := bgs.Logarithm(m)

	poly := make([]int64, k)
	poly[0] = 1

	pt := make([]int64, k + 1)
	pt[1] = 1
	pt = polyMod(pt, b, P - 1)

	for ; n > 0; n >>= 1 {
		if n%2 == 1 {
			poly = polyMod(polyMul(poly, pt, P-1), b, P-1)
		}
		pt = polyMod(polyMul(pt, pt, P-1), b, P-1)
	}

	U := poly[k-1]
	Z := log

	//X * U == Z mod (P - 1)
	// X * u * gu == Z mod (P - 1)

	var x, y int64
	gu := GCD(U, P-1, &x, &y)

	//fmt.Println(gu)

	if Z%gu != 0 {
		fmt.Println("-1")
		return
	}

	// X * u == (Z / gu) mod (P - 1) / gu

	GCD(U/gu, (P-1)/gu, &x, &y)

	if x < 0 {
		x += P - 1
	}

	x = x * (Z / gu) % (P - 1)

	fmt.Println(pow(root, x, P))
}


You are given an equation:  Ax2 + Bx + C = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order.

The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0.

In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var a, b, c int64
	fmt.Fscanf(reader, "%d %d %d", &a, &b, &c)
	delta := b * b - 4 * a * c
	if a == 0 && b == 0 && c == 0 {
		fmt.Printf("-1")
	} else if a == 0 && b == 0 {
		fmt.Printf("0")
	} else if a == 0 {
		fmt.Printf("1\n%f", float64(-c)/float64(b))
	} else if delta < 0 {
		fmt.Printf("0")
	} else if delta == 0 {
		fmt.Printf("1\n%f", float64(-b)/float64(2 * a))
	} else if delta > 0 {
		x1 := (float64(-b) + math.Sqrt(float64(delta))) / float64(2 * a)
		x2 := (float64(-b) - math.Sqrt(float64(delta))) / float64(2 * a)
		if x1 < x2 {
			fmt.Printf("2\n%f\n%f", x1, x2)
		} else {
			fmt.Printf("2\n%f\n%f", x2, x1)
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF20B(in io.Reader, out io.Writer) {
	var a, b, c int64
	Fscan(in, &a, &b, &c)
	if a == 0 {
		if b == 0 {
			if c == 0 {
				Fprint(out, -1)
			} else {
				Fprint(out, 0)
			}
		} else {
			Fprintf(out, "1\n%.5f", float64(-c)/float64(b))
		}
	} else {
		d := b*b - 4*a*c
		if d < 0 {
			Fprint(out, 0)
		} else if d == 0 {
			Fprintf(out, "1\n%.5f", float64(-b)/float64(2*a))
		} else {
			dd := math.Sqrt(float64(d))
			x, y := (float64(-b)-dd)/float64(2*a), (float64(-b)+dd)/float64(2*a)
			if x > y {
				x, y = y, x
			}
			Fprintf(out, "2\n%.5f %.5f", x, y)
		}
	}
}

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

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var a, b, c int64
	fmt.Fscanf(reader, "%d %d %d", &a, &b, &c)
	delta := b * b - 4 * a * c
	if a == 0 && b == 0 && c == 0 {
		fmt.Printf("-1")
	} else if a == 0 && b == 0 {
		fmt.Printf("0")
	} else if a == 0 {
		fmt.Printf("%f", float64(-c)/float64(b))
	} else if delta < 0 {
		fmt.Printf("0")
	} else if delta == 0 {
		fmt.Printf("1\n%f", float64(-b)/float64(2 * a))
	} else if delta > 0 {
		x1 := (float64(-b) + math.Sqrt(float64(delta))) / float64(2 * a)
		x2 := (float64(-b) - math.Sqrt(float64(delta))) / float64(2 * a)
		if x1 < x2 {
			fmt.Printf("2\n%f\n%f", x1, x2)
		} else {
			fmt.Printf("2\n%f\n%f", x2, x1)
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF20B(in io.Reader, out io.Writer) {
	var a, b, c int64
	Fscan(in, &a, &b, &c)
	if a == 0 {
		if b == 0 {
			if c == 0 {
				Fprint(out, -1)
			} else {
				Fprint(out, 0)
			}
		} else {
			Fprintf(out, "1\n%.5f", float64(-c)/float64(b))
		}
	} else {
		d := b*b - 4*a*c
		if d < 0 {
			Fprint(out, -1)
		} else if d == 0 {
			Fprintf(out, "1\n%.5f", float64(-b)/float64(2*a))
		} else {
			dd := math.Sqrt(float64(d))
			x, y := (float64(-b)-dd)/float64(2*a), (float64(-b)+dd)/float64(2*a)
			if x > y {
				x, y = y, x
			}
			Fprintf(out, "2\n%.5f %.5f", x, y)
		}
	}
}

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


There is an array $$$a$$$ of $$$2^{30}$$$ integers, indexed from $$$0$$$ to $$$2^{30}-1$$$. Initially, you know that $$$0 \leq a_i < 2^{30}$$$ ($$$0 \leq i < 2^{30}$$$), but you do not know any of the values. Your task is to process queries of two types: 1 l r x: You are informed that the bitwise xor of the subarray $$$[l, r]$$$ (ends inclusive) is equal to $$$x$$$. That is, $$$a_l \oplus a_{l+1} \oplus \ldots \oplus a_{r-1} \oplus a_r = x$$$, where $$$\oplus$$$ is the bitwise xor operator. In some cases, the received update contradicts past updates. In this case, you should ignore the contradicting update (the current update). 2 l r: You are asked to output the bitwise xor of the subarray $$$[l, r]$$$ (ends inclusive). If it is still impossible to know this value, considering all past updates, then output $$$-1$$$.Note that the queries are encoded. That is, you need to write an online solution.

The first line contains a single integer $$$q$$$ ($$$1 \leq q \leq 2 \cdot 10^5$$$) — the number of queries. Each of the next $$$q$$$ lines describes a query. It contains one integer $$$t$$$ ($$$1 \leq t \leq 2$$$) — the type of query. The given queries will be encoded in the following way: let $$$last$$$ be the answer to the last query of the second type that you have answered (initially, $$$last = 0$$$). If the last answer was $$$-1$$$, set $$$last = 1$$$.  If $$$t = 1$$$, three integers follow, $$$l'$$$, $$$r'$$$, and $$$x'$$$ ($$$0 \leq l', r', x' < 2^{30}$$$), meaning that you got an update. First, do the following: $$$l = l' \oplus last$$$, $$$r = r' \oplus last$$$, $$$x = x' \oplus last$$$ and, if $$$l > r$$$, swap $$$l$$$ and $$$r$$$.This means you got an update that the bitwise xor of the subarray $$$[l, r]$$$ is equal to $$$x$$$ (notice that you need to ignore updates that contradict previous updates). If $$$t = 2$$$, two integers follow, $$$l'$$$ and $$$r'$$$ ($$$0 \leq l', r' < 2^{30}$$$), meaning that you got a query. First, do the following: $$$l = l' \oplus last$$$, $$$r = r' \oplus last$$$ and, if $$$l > r$$$, swap $$$l$$$ and $$$r$$$.For the given query, you need to print the bitwise xor of the subarray $$$[l, r]$$$. If it is impossible to know, print $$$-1$$$. Don't forget to change the value of $$$last$$$. It is guaranteed there will be at least one query of the second type.

After every query of the second type, output the bitwise xor of the given subarray or $$$-1$$$ if it is still impossible to know.

NoteIn the first example, the real queries (without being encoded) are: 12 2 1 2 2 0 1073741823 1 1 2 5 2 1 1 2 2 2 2 1 2 1 2 3 6 2 1 1 1 1 3 0 2 1 1 2 2 2 2 3 3  The answers for the first two queries are $$$-1$$$ because we don't have any such information on the array initially.  The first update tells us $$$a_1 \oplus a_2 = 5$$$. Note that we still can't be certain about the values $$$a_1$$$ or $$$a_2$$$ independently (for example, it could be that $$$a_1 = 1, a_2 = 4$$$, and also $$$a_1 = 3, a_2 = 6$$$).  After we receive all three updates, we have enough information to deduce $$$a_1, a_2, a_3$$$ independently. In the second example, notice that after the first two updates we already know that $$$a_5 \oplus a_6 = 12$$$, so the third update is contradicting, and we ignore it.

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	fa, dis := map[int]int{}, map[int]int{}
	var find func(int) int
	find = func(x int) int {
		if fx, ok := fa[x]; ok && fx != x {
			ffx := find(fx)
			dis[x] ^= dis[fx]
			fa[x] = ffx
			return ffx
		}
		return x
	}
	merge := func(from, to, d int) {
		fFrom, fTo := find(from), find(to)
		if fFrom != fTo {
			dis[fFrom] = d ^ dis[from] ^ dis[to]
			fa[fFrom] = fTo
		}
	}
	same := func(x, y int) bool { return find(x) == find(y) }

	var q, t, l, r, x int
	last := 0
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &t, &l, &r)
		l ^= last
		r ^= last
		if l > r {
			l, r = r, l
		}
		r++
		if t == 1 {
			Fscan(in, &x)
			merge(l, r, x^last)
		} else {
			if same(l, r) {
				last = dis[l] ^ dis[r]
				Fprintln(out, last)
			} else {
				last = 1
				Fprintln(out, -1)
			}
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1074D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	fa, dis := map[int]int{}, map[int]int{}
	var find func(int) int
	find = func(x int) int {
		if fx, ok := fa[x]; ok && fx != x {
			ffx := find(fx)
			dis[x] ^= dis[fx]
			fa[x] = ffx
			return ffx
		}
		return x
	}
	merge := func(from, to, d int) {
		fFrom, fTo := find(from), find(to)
		if fFrom != fTo {
			dis[fFrom] = d ^ dis[from] ^ dis[to]
			fa[fFrom] = fTo
		}
	}
	same := func(x, y int) bool { return find(x) == find(y) }

	var q, t, l, r, x int
	last := 0
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &t, &l, &r)
		l ^= last
		r ^= last
		if l > r {
			l, r = r, l
		}
		r++
		if t == 1 {
			Fscan(in, &x)
			merge(l, r, x^last)
		} else {
			if same(l, r) {
				last = dis[l] ^ dis[r]
				Fprintln(out, last)
			} else {
				last = 1
				Fprintln(out, -1)
			}
		}
	}
}

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

package main

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

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

var p map[int]int
var x map[int]int
var s map[int]int

func get(v int) (int, int) {
	if par, ok := p[v]; !ok || par == v {
		return v, 0
	}
	var t int
	p[v], t = get(p[v])
	x[v] ^= t

	return p[v], x[v]
}

func getSize(v int) int {
	if _, ok := s[v]; !ok {
		s[v] = 1
	}
	return s[v]
}

func unite(a, b, xor int) {
	a, xa := get(a)
	b, xb := get(b)

	if a == b {
		return
	}

	if getSize(a) > getSize(b) {
		a, b = b, a
	}

	p[a] = b
	x[a] = xor ^ xa ^ xb
	s[a] += getSize(b)
}

func query(a, b int) (int, bool) {
	a, xa := get(a)
	b, xb := get(b)

	if a != b {
		return -1, false
	}
	return xa ^ xb, true
}

func main() {

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

	p = make(map[int]int, 2*q)
	x = make(map[int]int, 2*q)
	s = make(map[int]int, 2*q)

	last := 0
	for i := 0; i < q; i++ {
		var t int
		fmt.Fscan(in, &t)
		switch t {
		case 1:
			var l, r, x int
			fmt.Fscan(in, &l, &r, &x)
			l, r, x = l^last, r^last, x^last
			if l > r {
				l, r = r, l
			}
			r += 1
			unite(l, r, x)
		case 2:
			var l, r int
			fmt.Fscan(in, &l, &r)
			l, r = l^last, r^last
			if l > r {
				l, r = r, l
			}
			r += 1

			answer, ok := query(l, r)
			if ok {
				last = answer
			} else {
				last = 1
			}
			fmt.Printf("%d\n", answer)
		}
	}
}

package main

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

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

var p map[int]int
var x map[int]int

func get(v int) (int, int) {
	if par, ok := p[v]; !ok || par == v {
		return v, 0
	}
	var t int
	p[v], t = get(p[v])
	x[v] ^= t

	return p[v], x[v]
}

func unite(a, b, xor int) {
	a, xa := get(a)
	b, xb := get(b)

	if a == b {
		return
	}

	p[a] = b
	x[a] = xor ^ xa ^ xb
}

func query(a, b int) (int, bool) {
	a, xa := get(a)
	b, xb := get(b)

	if a != b {
		return -1, false
	}
	return xa ^ xb, true
}

func main() {

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

	p = make(map[int]int, 2*q)
	x = make(map[int]int, 2*q)

	last := 0
	for i := 0; i < q; i++ {
		var t int
		fmt.Fscan(in, &t)
		switch t {
		case 1:
			var l, r, x int
			fmt.Fscan(in, &l, &r, &x)
			l, r, x = l^last, r^last, x^last
			if l > r {
				l, r = r, l
			}
			r += 1
			unite(l, r, x)
		case 2:
			var l, r int
			fmt.Fscan(in, &l, &r)
			l, r = l^last, r^last
			if l > r {
				l, r = r, l
			}
			r += 1

			answer, ok := query(l, r)
			if ok {
				last = answer
			} else {
				last = 1
			}
			fmt.Printf("%d\n", answer)
		}
	}
}

package main

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

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

var p map[int]int
var x map[int]int

func get(v int) (int, int) {
	if par, ok := p[v]; !ok || par == v {
		return v, 0
	}
	var t int
	p[v], t = get(p[v])
	x[v] ^= t

	return p[v], x[v]
}

func unite(a, b, xor int) {
	a, xa := get(a)
	b, xb := get(b)

	if a == b {
		return
	}
	if (a ^ b ^ xor) % 313 < 166 {
		a, b = b, a
	}
	p[a] = b
	x[a] = xor ^ xa ^ xb
}

func query(a, b int) (int, bool) {
	a, xa := get(a)
	b, xb := get(b)

	if a != b {
		return -1, false
	}
	return xa ^ xb, true
}

func main() {

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

	p = make(map[int]int, 2*q)
	x = make(map[int]int, 2*q)

	last := 0
	for i := 0; i < q; i++ {
		var t int
		fmt.Fscan(in, &t)
		switch t {
		case 1:
			var l, r, x int
			fmt.Fscan(in, &l, &r, &x)
			l, r, x = l^last, r^last, x^last
			if l > r {
				l, r = r, l
			}
			r += 1
			unite(l, r, x)
		case 2:
			var l, r int
			fmt.Fscan(in, &l, &r)
			l, r = l^last, r^last
			if l > r {
				l, r = r, l
			}
			r += 1

			answer, ok := query(l, r)
			if ok {
				last = answer
			} else {
				last = 1
			}
			fmt.Printf("%d\n", answer)
		}
	}
}

package main

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

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

var p map[int]int
var x map[int]int
var s map[int]int

func get(v int) (int, int) {
	if par, ok := p[v]; !ok || par == v {
		return v, 0
	}
	var t int
	p[v], t = get(p[v])
	x[v] ^= t

	return p[v], x[v]
}

func getSize(v int) int {
	if r, ok := s[v]; ok {
		return r
	}
	return 1
}

func unite(a, b, xor int) {
	a, xa := get(a)
	b, xb := get(b)

	if a == b {
		return
	}

	if getSize(a) > getSize(b) {
		a, b = b, a
	}

	p[a] = b
	x[a] = xor ^ xa ^ xb
	s[a] += getSize(b)
}

func query(a, b int) (int, bool) {
	a, xa := get(a)
	b, xb := get(b)

	if a != b {
		return -1, false
	}
	return xa ^ xb, true
}

func main() {

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

	p = make(map[int]int, 2*q)
	x = make(map[int]int, 2*q)
	s = make(map[int]int, 2*q)

	last := 0
	for i := 0; i < q; i++ {
		var t int
		fmt.Fscan(in, &t)
		switch t {
		case 1:
			var l, r, x int
			fmt.Fscan(in, &l, &r, &x)
			l, r, x = l^last, r^last, x^last
			if l > r {
				l, r = r, l
			}
			r += 1
			unite(l, r, x)
		case 2:
			var l, r int
			fmt.Fscan(in, &l, &r)
			l, r = l^last, r^last
			if l > r {
				l, r = r, l
			}
			r += 1

			answer, ok := query(l, r)
			if ok {
				last = answer
			} else {
				last = 1
			}
			fmt.Printf("%d\n", answer)
		}
	}
}

package main

import "fmt"

var p map[int]int
var x map[int]int

func get(v int) (int, int) {
	if par, ok := p[v]; !ok || par == v {
		return v, 0
	}
	var t int
	p[v], t = get(p[v])
	x[v] ^= t

	return p[v], x[v]
}

func unite(a, b, xor int) {
	a, xa := get(a)
	b, xb := get(b)

	if a == b {
		return
	}

	p[a] = b
	x[a] = xor ^ xa ^ xb
}

func query(a, b int) (int, bool) {
	a, xa := get(a)
	b, xb := get(b)

	if a != b {
		return -1, false
	}
	return xa ^ xb, true
}

func main() {

	var q int
	fmt.Scanf("%d", &q)

	p = make(map[int]int, 2 * q)
	x = make(map[int]int, 2 * q)

	last := 0
	for i := 0; i < q; i++ {
		var t int
		fmt.Scanf("%d", &t)
		switch t {
		case 1:
			var l, r, x int
			fmt.Scanf("%d%d%d", &l, &r, &x)
			l, r, x = l ^ last, r ^ last, x ^ last
			if l > r {
				l, r = r, l
			}
			r += 1
			unite(l, r, x)
		case 2:
			var l, r int
			fmt.Scanf("%d%d", &l, &r)
			l, r = l ^ last, r ^ last
			if l > r {
				l, r = r, l
			}
			r += 1

			answer, ok := query(l, r)
			if ok {
				last = answer
			} else {
				last = 1
			}
			fmt.Printf("%d\n", answer)
		}
	}
}


You are given a connected weighted undirected graph without any loops and multiple edges. Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the given graph that includes all of the graph's vertexes. The weight of a tree is defined as the sum of weights of the edges that the given tree contains. The minimum spanning tree (MST) of a graph is defined as the graph's spanning tree having the minimum possible weight. For any connected graph obviously exists the minimum spanning tree, but in the general case, a graph's minimum spanning tree is not unique.Your task is to determine the following for each edge of the given graph: whether it is either included in any MST, or included at least in one MST, or not included in any MST.

The first line contains two integers n and m (2 ≤ n ≤ 105, ) — the number of the graph's vertexes and edges, correspondingly. Then follow m lines, each of them contains three integers — the description of the graph's edges as "ai bi wi" (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106, ai ≠ bi), where ai and bi are the numbers of vertexes connected by the i-th edge, wi is the edge's weight. It is guaranteed that the graph is connected and doesn't contain loops or multiple edges.

Print m lines — the answers for all edges. If the i-th edge is included in any MST, print "any"; if the i-th edge is included at least in one MST, print "at least one"; if the i-th edge isn't included in any MST, print "none". Print the answers for the edges in the order in which the edges are specified in the input.

NoteIn the second sample the MST is unique for the given graph: it contains two first edges.In the third sample any two edges form the MST for the given graph. That means that each edge is included at least in one MST.

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var n, m, v, w, wi, c int
	Fscan(in, &n, &m)
	fa := make([]int, n+1)
	for i := range fa {
		fa[i] = i
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	type edge struct{ v, w, i int }
	edges := [1e6 + 1][]edge{}
	for i := 0; i < m; i++ {
		Fscan(in, &v, &w, &wi)
		edges[wi] = append(edges[wi], edge{v, w, i})
	}
	ans := make([]int8, m)

	type nb struct{ to, eid int }
	g := make([][]nb, n+1)
	dfn := make([]int, n+1)
	id := make([]int, n+1)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		c++
		dfn[v] = c
		lowV := c
		for _, e := range g[v] {
			if w := e.to; dfn[w] == 0 {
				lowW := f(w, v)
				if lowW > dfn[v] {
					ans[e.eid] = 1
				}
				lowV = min(lowV, lowW)
			} else if w != fa && dfn[w] < dfn[v] {
				lowV = min(lowV, dfn[w])
			}
		}
		for _, e := range g[v] {
			if id[e.to] == 0 {
				id[e.to] = e.eid + 1
			} else {
				ans[id[e.to]-1] = 0
				ans[e.eid] = 0
			}
		}
		for _, e := range g[v] {
			id[e.to] = 0
		}
		return lowV
	}
	for _, es := range edges {
		if es == nil {
			continue
		}
		vs := []int{}
		for _, e := range es {
			if v, w, i := find(e.v), find(e.w), e.i; v != w {
				g[v] = append(g[v], nb{w, i})
				g[w] = append(g[w], nb{v, i})
				vs = append(vs, v, w)
			} else {
				ans[i] = 2
			}
		}
		for _, v := range vs {
			if dfn[v] == 0 {
				f(v, -1)
			}
		}
		for i := 0; i < len(vs); i += 2 {
			v, w := vs[i], vs[i+1]
			fa[find(v)] = find(w)
			g[v] = nil
			g[w] = nil
			dfn[v] = 0
			dfn[w] = 0
		}
	}

	s := [3]string{"at least one", "any", "none"}
	for _, t := range ans {
		Fprintln(out, s[t])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF160D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var n, m, v, w, wi, c int
	Fscan(in, &n, &m)
	fa := make([]int, n+1)
	for i := range fa {
		fa[i] = i
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	type edge struct{ v, w, i int }
	edges := [1e6 + 1][]edge{}
	for i := 0; i < m; i++ {
		Fscan(in, &v, &w, &wi)
		edges[wi] = append(edges[wi], edge{v, w, i})
	}
	ans := make([]int8, m)

	type nb struct{ to, eid int }
	g := make([][]nb, n+1)
	dfn := make([]int, n+1)
	id := make([]int, n+1)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		c++
		dfn[v] = c
		lowV := c
		for _, e := range g[v] {
			if w := e.to; dfn[w] == 0 {
				lowW := f(w, v)
				if lowW > dfn[v] {
					ans[e.eid] = 1
				}
				lowV = min(lowV, lowW)
			} else if w != fa && dfn[w] < dfn[v] {
				lowV = min(lowV, dfn[w])
			}
		}
		for _, e := range g[v] {
			if id[e.to] == 0 {
				id[e.to] = e.eid + 1
			} else {
				ans[id[e.to]-1] = 0
				ans[e.eid] = 0
			}
		}
		for _, e := range g[v] {
			id[e.to] = 0
		}
		return lowV
	}
	for _, es := range edges {
		if es == nil {
			continue
		}
		vs := []int{}
		for _, e := range es {
			if v, w, i := find(e.v), find(e.w), e.i; v != w {
				g[v] = append(g[v], nb{w, i})
				g[w] = append(g[w], nb{v, i})
				vs = append(vs, v, w)
			} else {
				ans[i] = 2
			}
		}
		for _, v := range vs {
			if dfn[v] == 0 {
				f(v, -1)
			}
		}
		for i := 0; i < len(vs); i += 2 {
			v, w := vs[i], vs[i+1]
			fa[find(v)] = find(w)
			g[v] = nil
			g[w] = nil
			dfn[v] = 0
			dfn[w] = 0
		}
	}

	s := [3]string{"at least one", "any", "none"}
	for _, t := range ans {
		Fprintln(out, s[t])
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF160D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var n, m, v, w, wi, c int
	Fscan(in, &n, &m)
	fa := make([]int, n+1)
	for i := range fa {
		fa[i] = i
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	type edge struct{ v, w, i int }
	edges := [1e6 + 1][]edge{}
	for i := 0; i < m; i++ {
		Fscan(in, &v, &w, &wi)
		edges[wi] = append(edges[wi], edge{v, w, i})
	}
	ans := make([]int8, m)

	type nb struct{ to, eid int }
	g := make([][]nb, n+1)
	dfn := make([]int, n+1)
	id := make([]int, n+1)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		c++
		dfn[v] = c
		lowV := c
		for _, e := range g[v] {
			if w := e.to; dfn[w] == 0 {
				lowW := f(w, v)
				if lowW > dfn[v] {
					ans[e.eid] = 1
				}
				lowV = min(lowV, lowW)
			} else if w != fa && dfn[w] < dfn[v] {
				lowV = min(lowV, dfn[w])
			}
		}
		for _, e := range g[v] {
			if id[e.to] == 0 {
				id[e.to] = e.eid
			} else {
				ans[id[e.to]] = 0
				ans[e.eid] = 0
			}
		}
		for _, e := range g[v] {
			id[e.to] = 0
		}
		return lowV
	}
	for _, es := range edges {
		if es == nil {
			continue
		}
		vs := []int{}
		for _, e := range es {
			if v, w, i := find(e.v), find(e.w), e.i; v != w {
				g[v] = append(g[v], nb{w, i})
				g[w] = append(g[w], nb{v, i})
				vs = append(vs, v, w)
			} else {
				ans[i] = 2
			}
		}
		for _, v := range vs {
			if dfn[v] == 0 {
				f(v, -1)
			}
		}
		for i := 0; i < len(vs); i += 2 {
			v, w := vs[i], vs[i+1]
			fa[find(v)] = find(w)
			g[v] = nil
			g[w] = nil
			dfn[v] = 0
			dfn[w] = 0
		}
	}

	s := [3]string{"at least one", "any", "none"}
	for _, t := range ans {
		Fprintln(out, s[t])
	}
}

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


One day Natalia was walking in the woods when she met a little mushroom gnome. The gnome told her the following story:Everybody knows that the mushroom gnomes' power lies in the magic mushrooms that grow in the native woods of the gnomes. There are n trees and m magic mushrooms in the woods: the i-th tree grows at a point on a straight line with coordinates ai and has the height of hi, the j-th mushroom grows at the point with coordinates bj and has magical powers zj.But one day wild mushroommunchers, the sworn enemies of mushroom gnomes unleashed a terrible storm on their home forest. As a result, some of the trees began to fall and crush the magic mushrooms. The supreme oracle of mushroom gnomes calculated in advance the probability for each tree that it will fall to the left, to the right or will stand on. If the tree with the coordinate x and height h falls to the left, then all the mushrooms that belong to the right-open interval [x - h, x), are destroyed. If a tree falls to the right, then the mushrooms that belong to the left-open interval (x, x + h] are destroyed. Only those mushrooms that are not hit by a single tree survive.Knowing that all the trees fall independently of each other (i.e., all the events are mutually independent, and besides, the trees do not interfere with other trees falling in an arbitrary direction), the supreme oracle was also able to quickly calculate what would be the expectation of the total power of the mushrooms which survived after the storm. His calculations ultimately saved the mushroom gnomes from imminent death.Natalia, as a good Olympiad programmer, got interested in this story, and she decided to come up with a way to quickly calculate the expectation of the sum of the surviving mushrooms' power.

The first line contains two integers n and m (1 ≤ n ≤ 105, 1 ≤ m ≤ 104) — the number of trees and mushrooms, respectively. Each of the next n lines contain four integers — ai, hi, li, ri (|ai| ≤ 109, 1 ≤ hi ≤ 109, 0 ≤ li, ri, li + ri ≤ 100) which represent the coordinate of the i-th tree, its height, the percentage of the probabilities that the tree falls to the left and to the right, respectively (the remaining percentage is the probability that the tree will stand on). Each of next m lines contain two integers bj, zj (|bj| ≤ 109, 1 ≤ zj ≤ 103) which represent the coordinate and the magical power of the j-th mushroom, respectively. An arbitrary number of trees and mushrooms can grow in one point.

Print a real number — the expectation of the total magical power of the surviving mushrooms. The result is accepted with relative or absolute accuracy 10 - 4.

NoteIt is believed that the mushroom with the coordinate x belongs to the right-open interval [l, r) if and only if l ≤ x < r. Similarly, the mushroom with the coordinate x belongs to the left-open interval (l, r] if and only if l < x ≤ r.In the first test the mushroom survives with the probability of 50%, depending on where the single tree falls.In the second test the mushroom survives only if neither of the two trees falls on it. It occurs with the probability of 50%  ×  50% = 25%.Pretest №12 is the large test with 105 trees and one mushroom.

package main

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

type Point struct {
	X    int
	Type int
	Prob float64
}

type ByX []Point

func (a ByX) Len() int      { return len(a) }
func (a ByX) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

func (a ByX) Less(i, j int) bool {
	if a[i].X < a[j].X {
		return true
	}
	if a[i].X > a[j].X {
		return false
	}
	return a[i].Type < a[j].Type
}

func main() {
	var (
		n, m int
	)

	if _, err := fmt.Fscanf(os.Stdin, "%d %d\n", &n, &m); err != nil {
		log.Fatal(err)
	}

	var (
		in     = bufio.NewScanner(os.Stdin)
		points = []Point{}
	)

	for i := 0; i < n; i++ {
		in.Scan()
		if err := in.Err(); err != nil {
			log.Fatal("reading standard input:", err)
		}
		var (
			x, h int
			l, r float64
		)
		if _, err := fmt.Sscanf(in.Text(), "%d %d %f %f\n", &x, &h, &l, &r); err != nil {
			log.Fatal(err)
		}
		points = append(points, Point{x - h, 1, 100.0 - l})
		points = append(points, Point{x, 2, 100.0 - l})
		points = append(points, Point{x + 1, 1, 100.0 - r})
		points = append(points, Point{x + h + 1, 2, 100.0 - r})
	}

	for i := 0; i < m; i++ {
		in.Scan()
		if err := in.Err(); err != nil {
			log.Fatal("reading standard input:", err)
		}
		var (
			p = Point{Type: 3}
		)
		if _, err := fmt.Sscanf(in.Text(), "%d %f\n", &p.X, &p.Prob); err != nil {
			log.Fatal(err)
		}
		points = append(points, p)
	}

	sort.Sort(ByX(points))

	// pretty.Println(points)

	var (
		tp, s float64
		skip  int
	)

	for _, p := range points {
		if p.Type == 1 && p.Prob == 0.0 {
			skip++
		} else if p.Type == 2 && p.Prob == 0.0 {
			skip--
		} else if p.Type == 1 {
			tp += math.Log(p.Prob / 100.0)
		} else if p.Type == 2 {
			tp -= math.Log(p.Prob / 100.0)
		} else if p.Type == 3 && skip == 0 {
			s += p.Prob * math.Exp(tp)
		}
		// pretty.Println(p, skip, s, tp)
	}

	fmt.Printf("%f\n", s)
}

package main

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

type Point struct {
	X    int
	Type int
	Prob float64
}

type ByX []Point

func (a ByX) Len() int      { return len(a) }
func (a ByX) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

func (a ByX) Less(i, j int) bool {
	if a[i].X < a[j].X {
		return true
	}
	if a[i].X > a[j].X {
		return false
	}
	return a[i].Type < a[j].Type
}

func main() {
	var (
		n, m int
	)

	if _, err := fmt.Fscanf(os.Stdin, "%d %d\n", &n, &m); err != nil {
		log.Fatal(err)
	}

	var (
		in     = bufio.NewScanner(os.Stdin)
		points = []Point{}
	)

	for i := 0; i < n; i++ {
		in.Scan()
		if err := in.Err(); err != nil {
			log.Fatal("reading standard input:", err)
		}
		var (
			x, h int
			l, r float64
		)
		if _, err := fmt.Sscanf(in.Text(), "%d %d %f %f\n", &x, &h, &l, &r); err != nil {
			log.Fatal(err)
		}
		points = append(points, Point{x - h, 1, 1 - l/100.0})
		points = append(points, Point{x, 2, 1 - l/100.0})
		points = append(points, Point{x + 1, 1, 1 - r/100.0})
		points = append(points, Point{x + h + 1, 2, 1 - r/100.0})
	}

	for i := 0; i < m; i++ {
		in.Scan()
		if err := in.Err(); err != nil {
			log.Fatal("reading standard input:", err)
		}
		var (
			p = Point{Type: 3}
		)
		if _, err := fmt.Sscanf(in.Text(), "%d %f\n", &p.X, &p.Prob); err != nil {
			log.Fatal(err)
		}
		points = append(points, p)
	}

	sort.Sort(ByX(points))

	var (
		tp   float64 = 1.0
		s    float64
		skip int
	)

	for _, p := range points {
		if p.Type == 1 && p.Prob == 0.0 {
			skip++
		} else if p.Type == 2 && p.Prob == 0.0 {
			skip--
		} else if p.Type == 1 {
			if tp < 1 {
				tp = tp * p.Prob
			} else {
				tp = p.Prob
			}
		} else if p.Type == 2 {
			tp = tp / p.Prob
		} else if p.Type == 3 && skip == 0 {
			s += p.Prob * tp
		}
	}

	fmt.Printf("%f\n", s)
}


There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?Note that outcome of a match can not be a draw, it has to be either win or loss.

The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105). Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.

For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).

NoteSample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).

package main

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

var in = bufio.NewScanner(os.Stdin)

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

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

	for t := readInt(); t > 0; t-- {
		n, k, d1, d2 := readInt(), readInt(), readInt(), readInt()
		if n%3 != 0 {
			fmt.Fprintln(out, "no")
			continue
		}
		can := func(d1, d2 int64) bool {
			x := k - d1 + d2
			if x%3 != 0 {
				return false
			}
			b := x / 3
			a := d1 + b
			c := b - d2
			return a >= 0 && b >= 0 && c >= 0 && a <= n/3 && b <= n/3 && c <= n/3
		}
		if can(d1, d2) || can(d1, -d2) || can(-d1, d2) || can(-d1, -d2) {
			fmt.Fprintln(out, "yes")
		} else {
			fmt.Fprintln(out, "no")
		}
	}
}