Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that:  $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$.  Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct) — the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.

For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ — its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.

NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$:  $$$[3,2]$$$ which gives us $$$|3-2|=1$$$.  $$$[3,1]$$$ which gives us $$$|3-1|=2$$$.  $$$[2,1]$$$ which gives us $$$|2-1|=1$$$.  $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.

package main

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

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 main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		P := readNNums(reader, n)
		res := solve(n, P)
		fmt.Println(len(res))
		var buf bytes.Buffer
		for i := 0; i < len(res); i++ {
			buf.WriteString(strconv.Itoa(res[i]))
			buf.WriteByte(' ')
		}
		fmt.Println(buf.String())
	}
}

func solve(n int, P []int) []int {
	// find moutain peek
	var res = make([]int, 0, n)
	res = append(res, P[0])
	for i := 0; i < n-1; {
		j := i + 1
		if P[j] > P[i] {
			for j < n && P[j] > P[j-1] {
				j++
			}

		} else {
			for j < n && P[j] < P[j-1] {
				j++
			}
		}
		// j - 1 is the peek
		j--

		if i == j {
			break
		}

		res = append(res, P[j])
		i = j
	}
	return res
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		ans := []int{a[0]}
		for i := 1; i < n-1; i++ {
			if !same(a[i]-a[i-1], a[i+1]-a[i]) {
				ans = append(ans, a[i])
			}
		}
		ans = append(ans, a[n-1])
		fmt.Fprintf(out, "%d\n", len(ans))
		for i := 0; i < len(ans)-1; i++ {
			fmt.Fprintf(out, "%d ", ans[i])
		}
		fmt.Fprintf(out, "%d\n", ans[len(ans)-1])
	}
	return
}

func same(a, b int) bool {
	if a > 0 && b > 0 {
		return true
	}
	if a < 0 && b < 0 {
		return true
	}
	return false
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		n, _ := strconv.Atoi(string(line))
		line = readLine(reader)
		pns := strings.Split(string(line), " ")
		pn := make([]int, n)
		flag := make([]bool, n)
		for i := 0; i < n; i++ {
			pn[i], _ = strconv.Atoi(pns[i])
		}
		del := 0
		for i := 1; i < n-1; i++ {
			if (pn[i] >= pn[i-1] && pn[i+1] >= pn[i]) ||
				(pn[i] <= pn[i-1] && pn[i+1] <= pn[i]) {
				flag[i] = true
				del++
			}
		}
		fmt.Println(n - del)
		for i := 0; i<n;i++ {
			if !flag[i] {
				fmt.Printf("%d ", pn[i])
			}
		}
		fmt.Println()
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

/*
URL:
https://codeforces.com/contest/1364/problem/B
*/

package main

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

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

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

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

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

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

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	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
)

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

var (
	t int

	n int
	P []int
)

func main() {
	t = ReadInt()

	for i := 0; i < t; i++ {
		n = ReadInt()
		P = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	F := make([]bool, n)
	D := make([]int, 0)
	for i := 1; i < n; i++ {
		d := P[i] - P[i-1]
		D = append(D, d)
	}

	F[0], F[n-1] = true, true
	for i := 1; i < n-1; i++ {
		if (D[i-1] > 0 && D[i] > 0) || (D[i-1] < 0 && D[i] < 0) {
			F[i] = false
		} else {
			F[i] = true
		}
	}

	answers := []int{}
	for i := 0; i < n; i++ {
		if F[i] {
			answers = append(answers, P[i])
		}
	}

	fmt.Println(len(answers))
	fmt.Println(PrintIntsLine(answers...))
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		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)
}

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

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

package main

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

var nTest, n int
var a [100000]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &nTest)

	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &n)

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

		res := []int{a[0]}
		for i := 1; i < n-1; i++ {
			if !((a[i-1] < a[i] && a[i] < a[i+1]) || (a[i-1] > a[i] && a[i] > a[i+1])) {
				res = append(res, a[i])
			}
		}

		res = append(res, a[n-1])
		fmt.Fprintln(out, len(res))
		for _, v := range res {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
	out.Flush()
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	tt := NextInt()
	for ; tt > 0; tt-- {
		n := NextInt()
		a := make([]int, n)
		var ret []int
		for i := 0; i < n; i++ {
			a[i] = NextInt()
		}
		j := 0
		for i := 1; i < n; i++ {
			if a[i] > a[j] {
				ret = append(ret, a[j])
				for ; i + 1 < n && a[i] < a[i + 1]; i++ {}
				j = i
			} else {
				ret = append(ret, a[j])
				for ; i + 1 < n && a[i] > a[i + 1]; i++ {}
				j = i
			}
		}
		ret = append(ret, a[j])
		fmt.Println(len(ret))
		for i := 0; i < len(ret); i++ {
			fmt.Print(ret[i], " ")
		}
		fmt.Println()
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, now int
	fmt.Fscanf(in, "%d\n", &t)
	for now < t {
		now++
		var n int
		fmt.Fscanf(in, "%d %d\n", &n)
		var num int
		mas := make([]int, n+1)
		ans := make([]int, 0, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &mas[i])
		}
		fmt.Fscanf(in, "\n")
		num = mas[0]
		help := make([]int, n)
		for i := 0; i < n - 1; i++ {
			if mas[i] < mas[i + 1]{
				help[i] = 1
			}
		}
		ind := help[0]
		num = mas[0]
		var flag bool
		for i := 0; i < n;i++{
			if help[i] != ind{
				ans = append(ans, num)
				ind = 1 - ind
				num = mas[i]
				if i == n-1{
					flag=true
				}
			}
		}
		if len(ans) == 0{
			ans = append(ans, mas[0])
			ans = append(ans, mas[n-1])
		} else {
			ans = append(ans, num)
			if !flag{
				ans = append(ans, mas[n - 1])
			}

		}
		fmt.Fprintln(out, len(ans))
		for _, i := range ans{
			fmt.Fprintf(out, "%v ", i)
		}
		fmt.Fprintln(out)
	}
	return
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, now int
	fmt.Fscanf(in, "%d\n", &t)
	for now < t {
		now++
		var n int
		fmt.Fscanf(in, "%d %d\n", &n)
		var num int
		mas := make([]int, n+1)
		ans := make([]int, 0, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &mas[i])
		}
		fmt.Fscanf(in, "\n")
		num = mas[0]
		help := make([]int, n)
		for i := 0; i < n - 1; i++ {
			if mas[i] < mas[i + 1]{
				help[i] = 1
			}
		}
		ind := help[0]
		num = mas[0]
		for i := 0; i < n;i++{
			if help[i] != ind{
				ans = append(ans, num)
				ind = 1 - ind
				num = mas[i]
			}
		}
		if len(ans) == 0{
			ans = append(ans, mas[0])
			ans = append(ans, mas[n-1])
		} else {
			ans = append(ans, num)
			ans = append(ans, mas[n - 1])
		}
		fmt.Fprintln(out, len(ans))
		for _, i := range ans{
			fmt.Fprintf(out, "%v ", i)
		}
		fmt.Fprintln(out)
	}
	return
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, now int
	fmt.Fscanf(in, "%d\n", &t)
	for now < t {
		now++
		var n int
		fmt.Fscanf(in, "%d %d\n", &n)
		var num int
		mas := make([]int, n+1)
		ans := make([]int, 0, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &mas[i])
		}
		fmt.Fscanf(in, "\n")
		num = mas[0]
		help := make([]int, n)
		for i := 0; i < n - 1; i++ {
			if mas[i] < mas[i + 1]{
				help[i] = 1
			}
		}
		ind := help[0]
		num = help[0]
		for i := 0; i < n;i++{
			if help[i] != ind{
				ans = append(ans, num)
				ind = 1 - ind
				num = mas[i]
			}
		}
		if len(ans) == 0{
			ans = append(ans, mas[0])
			ans = append(ans, mas[n-1])
		} else {
			ans = append(ans, num)
			ans = append(ans, mas[n - 1])
		}
		fmt.Fprintln(out, len(ans))
		for _, i := range ans{
			fmt.Fprintf(out, "%v ", i)
		}
		fmt.Fprintln(out)
	}
	return
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, now int
	fmt.Fscanf(in, "%d\n", &t)
	for now < t {
		now++
		var n int
		fmt.Fscanf(in, "%d %d\n", &n)
		var num int
		mas := make([]int, n+1)
		ans := make([]int, 0, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &mas[i])
		}
		fmt.Fscanf(in, "\n")
		num = mas[0]
		help := make([]int, n)
		for i := 1; i < n; i++ {
			if mas[i] > mas[i - 1]{
				help[i] = 1
			}
		}
		ind := help[0]
		for i := 0; i < n;i++{
			if help[i] != ind{
				ans = append(ans, num)
				ind = 1 - ind
				num = mas[i]
			} else {
				num = mas[i]
			}
		}
		if len(ans) == 0{
			ans = append(ans, mas[0])
		}
		ans = append(ans, mas[n-1])
		fmt.Fprintln(out, len(ans))
		for _, i := range ans{
			fmt.Fprintf(out,"%v ", i)
		}
		fmt.Fprintln(out)
	}
	return
}


The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help.A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers b1, b2, ..., bm (m ≤ n). All numbers from the message and from the key belong to the interval from 0 to c - 1, inclusive, and all the calculations are performed modulo c.Encryption is performed in n - m + 1 steps. On the first step we add to each number a1, a2, ..., am a corresponding number b1, b2, ..., bm. On the second step we add to each number a2, a3, ..., am + 1 (changed on the previous step) a corresponding number b1, b2, ..., bm. And so on: on step number i we add to each number ai, ai + 1, ..., ai + m - 1 a corresponding number b1, b2, ..., bm. The result of the encryption is the sequence a1, a2, ..., an after n - m + 1 steps.Help the Beaver to write a program that will encrypt messages in the described manner.

The first input line contains three integers n, m and c, separated by single spaces.  The second input line contains n integers ai (0 ≤ ai < c), separated by single spaces — the original message.  The third input line contains m integers bi (0 ≤ bi < c), separated by single spaces — the encryption key. The input limitations for getting 30 points are:    1 ≤ m ≤ n ≤ 103  1 ≤ c ≤ 103  The input limitations for getting 100 points are:    1 ≤ m ≤ n ≤ 105  1 ≤ c ≤ 103

Print n space-separated integers — the result of encrypting the original message.

NoteIn the first sample the encryption is performed in two steps: after the first step a = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step a = (0, 1, 1, 0), and that is the answer.

package main

import (
	"fmt"
	"strings"
)

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

	fmt.Scan(&n)
	fmt.Scan(&m)
	fmt.Scan(&c)

	plain := make([]int, n)
	key := make([]int, m)

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

	for i := 0; i < n-m+1; i++ {
		for j := 0; j < m; j++ {
			plain[i+j] = (plain[i+j] + key[j]) % c
		}
	}
	out := fmt.Sprint(plain)
	fmt.Println(strings.Trim(out, "[]"))
}


There is a prison that can be represented as a rectangular matrix with $$$n$$$ rows and $$$m$$$ columns. Therefore, there are $$$n \cdot m$$$ prison cells. There are also $$$n \cdot m$$$ prisoners, one in each prison cell. Let's denote the cell in the $$$i$$$-th row and the $$$j$$$-th column as $$$(i, j)$$$.There's a secret tunnel in the cell $$$(r, c)$$$, that the prisoners will use to escape! However, to avoid the risk of getting caught, they will escape at night.Before the night, every prisoner is in his own cell. When night comes, they can start moving to adjacent cells. Formally, in one second, a prisoner located in cell $$$(i, j)$$$ can move to cells $$$( i - 1 , j )$$$ , $$$( i + 1 , j )$$$ , $$$( i , j - 1 )$$$ , or $$$( i , j + 1 )$$$, as long as the target cell is inside the prison. They can also choose to stay in cell $$$(i, j)$$$.The prisoners want to know the minimum number of seconds needed so that every prisoner can arrive to cell $$$( r , c )$$$ if they move optimally. Note that there can be any number of prisoners in the same cell at the same time.

The first line contains an integer $$$t$$$ $$$(1 \le t \le 10^4)$$$, the number of test cases. Each of the next $$$t$$$ lines contains four space-separated integers $$$n$$$, $$$m$$$, $$$r$$$, $$$c$$$ ($$$1 \le r \le n \le 10^9$$$, $$$1 \le c \le m \le 10^9$$$).

Print $$$t$$$ lines, the answers for each test case.

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n, m, r, c := ReadInt(), ReadInt(), ReadInt(), ReadInt()
		println(solve(n, m, r, c))
	}
}

func solve(n, m, r, c int) int {
	return Max((n-r), (r-1)) + Max((m-c), (c-1))
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func printInts(a ...int)                { s := fmt.Sprint(a); println(s[1 : len(s)-1]) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

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

package main

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

var (
	t int

	n, m, r, c int64
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n, m, r, c = readll4()
		r--
		c--

		solve()
	}
}

func solve() {
	R := Max(r, n-1-r)
	C := Max(c, m-1-c)

	ans := R + C

	printf("%d\n", ans)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

	return s
}

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

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

package main

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

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m, &r, &c)
		fmt.Println(max(n-r, r-1) + max(m-c, c-1))
	}
}


Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).

The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$) — the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.

Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.

NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.

/*
go run a.go
582426543750017 789023129080207 4395672028302
312 2197836014149
*/
package main

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

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

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

func main() {
	defer writer.Flush()
	var a, b, c int64
	var r float64
	scanf("%d %d %d\n", &a, &b, &c)
	if (a+b)/c > a/c+b/c {
		x := c*((a/c)+1) - a
		y := c*((b/c)+1) - b
		r = math.Min(float64(x), float64(y))
	}
	printf("%d %d\n", (a+b)/c, int64(r))
}

package main

import (
    "fmt"
)

func main() {
    var x, y, z, r int64
    fmt.Scan(&x, &y, &z)
    if (x + y) / z > x / z + y / z {
        if x % z >= y % z {
            r = z - x % z
        } else {
            r = z - y % z
        }
    }
    fmt.Println((x + y) / z, r)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1181/problem/A

package main

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

type Solution struct {
	Coconuts int64
	Transfer int64
}

func Solve(x, y, z int64) Solution {
	a, b := x%z, y%z
	if a+b < z {
		return Solution{Coconuts: x/z + y/z, Transfer: 0}
	}
	if a >= b {
		return Solution{Coconuts: (x + y) / z, Transfer: z - a}
	}
	return Solution{Coconuts: (x + y) / z, Transfer: z - b}
}

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

	var x, y, z int64
	fmt.Fscanf(reader, "%d %d %d\n", &x, &y, &z)

	solution := Solve(x, y, z)
	fmt.Fprintf(writer, "%d %d\n", solution.Coconuts, solution.Transfer)
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var a, b, c uint64

	fmt.Fscanln(os.Stdin, &a, &b, &c)

	r := uint64(0)
	s := false
	if b%c >= c-a%c {
		r = c - a%c
		s = true
	}

	if a%c >= c-b%c {
		if !s {
			r = c - b%c
		} else {
			if c-b%c < r {
				r = c - b%c
			}
		}
	}

	fmt.Fprint(os.Stdout, (a+b)/c, r)
}

/*
go run a.go
*/
package main

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

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

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

func main() {
	defer writer.Flush()
	var a, b, c int64
	var r float64
	scanf("%d %d %d\n", &a, &b, &c)
	//fmt.Println(int((a + b) / c))
	// fmt.Println(int(a / c))
	// fmt.Println(int(b / c))
	//fmt.Println(int((a+b)/c) > (int(a/c) + int(b/c)))
	if (a+b)/c > a/c+b/c {
		x := c*((a/c)+1) - a
		y := c*((b/c)+1) - b
		// fmt.Println(c*float64((int(b/c)+1)) - b)
		r = math.Min(float64(x), float64(y))
	}
	printf("%d %d\n", int((a+b)/c), int(r))
}

/*
go run a.go
*/
package main

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

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

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

func main() {
	defer writer.Flush()
	var a, b, c, r float64
	scanf("%f %f %f\n", &a, &b, &c)
	//fmt.Println(int((a + b) / c))
	// fmt.Println(int(a / c))
	// fmt.Println(int(b / c))
	//fmt.Println(int((a+b)/c) > (int(a/c) + int(b/c)))
	if int((a+b)/c) > (int(a/c) + int(b/c)) {
		// fmt.Println(c*float64((int(a/c)+1)) - a)
		// fmt.Println(c*float64((int(b/c)+1)) - b)
		r = math.Min(c*float64((int(a/c)+1))-a, c*float64((int(b/c)+1))-b)
	}
	printf("%d %d\n", int((a+b)/c), int(r))
}

/*
go run a.go
582426543750017 789023129080207 4395672028302
312 2197836014149
*/
package main

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

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

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

func main() {
	defer writer.Flush()
	var a, b, c int64
	var r float64
	scanf("%d %d %d\n", &a, &b, &c)
	if (a+b)/c > a/c+b/c {
		x := c*((a/c)+1) - a
		y := c*((b/c)+1) - b
		r = math.Min(float64(x), float64(y))
	}
	printf("%d %d\n", int((a+b)/c), int(r))
}

/*
go run a.go
*/
package main

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

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

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

func main() {
	defer writer.Flush()
	var a, b, c float64
	scanf("%f %f %f\n", &a, &b, &c)
	printf("%d %d\n", int((a+b)/c), int(math.Min(math.Mod(a, c), math.Mod(b, c))))
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var x, y, z int64
    fmt.Scan(&x, &y, &z)
    fmt.Println((x + y) % z, int(math.Min(float64(x % z), float64(y % z))))
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var x, y, z, r int64
    fmt.Scan(&x, &y, &z)
    if (x + y) / z > x / z + y / z {
        r = z - int64(math.Max(float64(x % z), float64(y % z)))
    }
    fmt.Println((x + y) / z, r)
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var x, y, z int64
    fmt.Scan(&x, &y, &z)
    fmt.Println((x + y) / z, int(math.Min(float64(x % z), float64(y % z))))
}


You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.

The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters.

On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters. If the answer consists of zero characters, output «-» (a minus sign).

NoteIn the first example strings a and b don't share any symbols, so the longest string that you can get is empty.In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.

package main

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

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

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

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

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

func main() {
	defer w.Flush()
	var a, b string
	for I(&a, &b) == nil {
		solve(a, b)
	}
}

func solve(a, b string) {
	i, j := 0, 0
	var p, s []int
	p = append(p, -1e9)
	for i < len(b) && j < len(a) {
		if b[i] == a[j] {
			p = append(p, j)
			i++
		}
		j++
	}
	i, j = len(b)-1, len(a)-1
	s = append(s, 1e9)
	for i >= 0 && j >= 0 {
		if b[i] == a[j] {
			s = append(s, j)
			i--
		}
		j--
	}
	i, j = 0, len(p)-1
	var ans string
	var max int
	for j >= 0 && i < len(s) {
		if len(b) > i+j-1 && p[j] < s[i] {
			if i+j > max {
				max = i + j
				ans = b[:j]
				if i > 0 {
					ans = b[:j] + b[len(b)-i:]
				}
			}
			i++
			continue
		}
		j--
	}
	if len(ans) == 0 {
		ans = "-"
	}
	O(ans, "\n")
}

package main

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

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

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

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

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

type Int int64

func main() {
	defer w.Flush()
	var a, b string
	for I(&a, &b) == nil {
		solve(a, b)
	}
}

func solve(a, b string) {
	p, s := make([]int, len(a)+1), make([]int, len(a)+1)
	aa, bb := reverse(a), reverse(b)
	for i := 1; i < len(p); i++ {
		if p[i-1] < len(b) && a[i-1] == b[p[i-1]] {
			p[i] = p[i-1] + 1
		} else {
			p[i] = p[i-1]
		}
		if s[i-1] < len(b) && aa[i-1] == bb[s[i-1]] {
			s[i] = s[i-1] + 1
		} else {
			s[i] = s[i-1]
		}
	}
	var l, r, max int
	for i := 0; i < len(p); i++ {
		o, oo := p[i], s[len(p)-1-i]
		if o+oo > max && o+oo <= len(a) {
			l, r = o, oo
			max = o + oo
		}
	}
	var ans string
	if max == 0 {
		ans = "-"
	} else if max > len(b) {
		ans = b
	} else {
		ans = b[:l] + reverse(bb[:r])
	}
	O(ans, "\n")
}

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

package main

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

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

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

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

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

func main() {
	defer w.Flush()
	var a, b string
	for I(&a, &b) == nil {
		solve(a, b)
	}
}

func solve(a, b string) {
	i, j := 0, 0
	var p, s []int
	for i < len(b) && j < len(a) {
		if b[i] == a[j] {
			p = append(p, i)
			i++
		}
		j++
	}
	i, j = len(b)-1, len(a)-1
	for i >= 0 && j >= 0 {
		if b[i] == a[j] {
			s = append(s, i)
			i--
		}
		j--
	}
	var ans string
	if len(p) == 0 && len(s) == 0 {
		ans = "-"
	} else if len(p) == 0 {
		ans = b[s[len(s)-1]:]
	} else if len(s) == 0 {
		o := 1
		if p[len(p)-1] == len(b)-1 {
			o--
		}
		ans = b[:p[len(p)-1]+o]
	} else {
		o := 1
		if p[len(p)-1] == len(b)-1 || p[len(p)-1] == len(b)-1-s[len(s)-1] {
			o--
		}
		r := b[:p[len(p)-1]+o]
		l := b[s[len(s)-1]:]
		if len(r)+len(l) <= len(a) {
			ans = r + l
		} else {
			diff := len(r) + len(l) - len(a)
			if diff == len(r) {
				ans = l
			} else if diff == len(l) {
				ans = r
			} else if diff > len(r) {
				diff -= len(r)
				ans = l[diff:]
			} else if diff > len(l) {
				diff -= len(l)
				ans = r[:len(r)-diff]
			} else {
				ans = r[:len(r)-diff] + l
			}
		}
	}
	O(ans, "\n")
}


You know, it's hard to conduct a show with lots of participants and spectators at the same place nowadays. Still, you are not giving up on your dream to make a car crash showcase! You decided to replace the real cars with remote controlled ones, call the event "Remote Control Kaboom Show" and stream everything online.For the preparation you arranged an arena — an infinite 2D-field. You also bought $$$n$$$ remote controlled cars and set them up on the arena. Unfortunately, the cars you bought can only go forward without turning left, right or around. So you additionally put the cars in the direction you want them to go.To be formal, for each car $$$i$$$ ($$$1 \le i \le n$$$) you chose its initial position ($$$x_i, y_i$$$) and a direction vector ($$$dx_i, dy_i$$$). Moreover, each car has a constant speed $$$s_i$$$ units per second. So after car $$$i$$$ is launched, it stars moving from ($$$x_i, y_i$$$) in the direction ($$$dx_i, dy_i$$$) with constant speed $$$s_i$$$.The goal of the show is to create a car collision as fast as possible! You noted that launching every car at the beginning of the show often fails to produce any collisions at all. Thus, you plan to launch the $$$i$$$-th car at some moment $$$t_i$$$. You haven't chosen $$$t_i$$$, that's yet to be decided. Note that it's not necessary for $$$t_i$$$ to be integer and $$$t_i$$$ is allowed to be equal to $$$t_j$$$ for any $$$i, j$$$.The show starts at time $$$0$$$. The show ends when two cars $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) collide (i. e. come to the same coordinate at the same time). The duration of the show is the time between the start and the end.What's the fastest crash you can arrange by choosing all $$$t_i$$$? If it's possible to arrange a crash then print the shortest possible duration of the show. Otherwise, report that it's impossible.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 25000$$$) — the number of cars. Each of the next $$$n$$$ lines contains five integers $$$x_i$$$, $$$y_i$$$, $$$dx_i$$$, $$$dy_i$$$, $$$s_i$$$ ($$$-10^3 \le x_i, y_i \le 10^3$$$; $$$1 \le |dx_i| \le 10^3$$$; $$$1 \le |dy_i| \le 10^3$$$; $$$1 \le s_i \le 10^3$$$) — the initial position of the $$$i$$$-th car, its direction vector and its speed, respectively. It's guaranteed that all cars start at distinct positions (i. e. $$$(x_i, y_i) \neq (x_j, y_j)$$$ for $$$i \neq j$$$).

Print the shortest possible duration of the show if it's possible to arrange a crash by choosing all $$$t_i$$$. Otherwise, print "No show :(". Your answer is considered correct if its absolute or relative error does 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}$$$.

NoteHere is the picture for the first example:   The fastest cars to crash are cars $$$2$$$ and $$$4$$$. Let's launch car $$$2$$$ at $$$0$$$, car $$$4$$$ at about $$$0.096762$$$ and cars $$$1$$$ and $$$3$$$ at arbitrary time. That way cars $$$2$$$ and $$$4$$$ will crash into each other at about $$$0.585902$$$. So here's what it looks like at the moment of the collision:  Here's the picture for the second example:

package main

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

type vec struct{ x, y int }

func (a vec) sub(b vec) vec { return vec{a.x - b.x, a.y - b.y} }
func (a vec) dot(b vec) int { return a.x*b.x + a.y*b.y }
func (a vec) det(b vec) int { return a.x*b.y - a.y*b.x }
func (a vec) len() float64  { return math.Hypot(float64(a.x), float64(a.y)) }

// github.com/EndlessCheng/codeforces-go
func CF1359F(_r io.Reader, out io.Writer) {
	min := func(a, b float64) float64 {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b float64) float64 {
		if a > b {
			return a
		}
		return b
	}
	type car struct {
		p, d    vec
		s, norm float64
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	cs := make([]car, n)
	for i := range cs {
		Fscan(in, &cs[i].p.x, &cs[i].p.y, &cs[i].d.x, &cs[i].d.y, &cs[i].s)
		cs[i].norm = cs[i].d.len()
	}

	ans := 1e99
	for i, p := range cs {
		for j := i + 1; j < n; j++ {
			q := cs[j]
			u := p.p.sub(q.p)
			if det := p.d.det(q.d); det != 0 {
				t1 := q.d.det(u)
				t2 := p.d.det(u)
				if det > 0 && t1 >= 0 && t2 >= 0 || det < 0 && t1 <= 0 && t2 <= 0 {
					ans = min(ans, max(p.norm*float64(t1)/(p.s*float64(det)), q.norm*float64(t2)/(q.s*float64(det))))
				}
			} else {
				if u.det(p.d) != 0 {
					continue
				}
				l := math.Hypot(float64(u.x), float64(u.y))
				if p.d.dot(q.d) > 0 {
					if u.dot(q.d) >= 0 {
						ans = min(ans, l/q.s)
					} else {
						ans = min(ans, l/p.s)
					}
				} else {
					if u.dot(q.d) > 0 {
						ans = min(ans, l/(p.s+q.s))
					}
				}
			}
		}
	}
	if ans == 1e99 {
		Fprint(out, "No show :(")
	} else {
		Fprintf(out, "%.8f", ans)
	}
}

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

package main

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

type vec struct{ x, y int }

func (a vec) sub(b vec) vec { return vec{a.x - b.x, a.y - b.y} }
func (a vec) dot(b vec) int { return a.x*b.x + a.y*b.y }
func (a vec) det(b vec) int { return a.x*b.y - a.y*b.x }
func (a vec) len() float64  { return math.Hypot(float64(a.x), float64(a.y)) }

type car struct {
	p, d vec
	s, l float64
}

// github.com/EndlessCheng/codeforces-go
func main() {
	Min := func(a, b float64) float64 {
		if a < b {
			return a
		}
		return b
	}
	Max := func(a, b float64) float64 {
		if a > b {
			return a
		}
		return b
	}
	Abs := func(x float64) float64 {
		if x < 0 {
			return -x
		}
		return x
	}

	in := bufio.NewReader(os.Stdin)
	var n int
	Fscan(in, &n)
	c := make([]car, n)
	for i := range c {
		Fscan(in, &c[i].p.x, &c[i].p.y, &c[i].d.x, &c[i].d.y, &c[i].s)
		c[i].l = c[i].d.len()
	}

	ans := 1e99
	s := 0.
	for i, p := range c {
		for j := i + 1; j < n; j++ {
			q := c[j]
			u := p.p.sub(q.p)
			if d := p.d.det(q.d); d != 0 {
				if d1, d2 := q.d.det(u), p.d.det(u); d > 0 && d1 >= 0 && d2 >= 0 || d < 0 && d1 <= 0 && d2 <= 0 {
					ans = Min(ans, Max(p.l*float64(d1)/(p.s*float64(d)), q.l*float64(d2)/(q.s*float64(d))))
				}
				continue
			}
			if u.det(p.d) != 0 {
				continue
			}
			if p.d.dot(q.d) > 0 {
				if u.dot(q.d) > 0 {
					s = q.s
				} else {
					s = p.s
				}
			} else if u.dot(q.d) > 0 {
				s = p.s + q.s
			} else {
				continue
			}
			if p.d.x != 0 {
				ans = Min(ans, Abs(p.l*float64(u.x)/(s*float64(p.d.x))))
			} else {
				ans = Min(ans, Abs(p.l*float64(u.y)/(s*float64(p.d.y))))
			}
		}
	}
	if ans == 1e99 {
		Print("No show :(")
	} else {
		Printf("%.8f", ans)
	}
}

package main

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

type vec struct{ x, y int }

func (a vec) sub(b vec) vec { return vec{a.x - b.x, a.y - b.y} }
func (a vec) dot(b vec) int { return a.x*b.x + a.y*b.y }
func (a vec) det(b vec) int { return a.x*b.y - a.y*b.x }
func (a vec) len() float64  { return math.Hypot(float64(a.x), float64(a.y)) }

type car struct {
	p, d vec
	s, l float64
}

// github.com/EndlessCheng/codeforces-go
func main() {
	min := func(a, b float64) float64 {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b float64) float64 {
		if a > b {
			return a
		}
		return b
	}

	in := bufio.NewReader(os.Stdin)
	var n int
	Fscan(in, &n)
	c := make([]car, n)
	for i := range c {
		Fscan(in, &c[i].p.x, &c[i].p.y, &c[i].d.x, &c[i].d.y, &c[i].s)
		c[i].l = c[i].d.len()
	}

	ans := 1e99
	for i, p := range c {
		for j := i + 1; j < n; j++ {
			q := c[j]
			u := p.p.sub(q.p)
			if d := p.d.det(q.d); d != 0 {
				if t1, t2 := q.d.det(u), p.d.det(u); d > 0 && t1 >= 0 && t2 >= 0 || d < 0 && t1 <= 0 && t2 <= 0 {
					ans = min(ans, max(p.l*float64(t1)/(p.s*float64(d)), q.l*float64(t2)/(q.s*float64(d))))
				}
				continue
			}
			if u.det(p.d) != 0 {
				continue
			}
			l := math.Sqrt(float64(u.x*u.x + u.y*u.y))
			if p.d.dot(q.d) > 0 {
				if u.dot(q.d) >= 0 {
					ans = min(ans, l/q.s)
				} else {
					ans = min(ans, l/p.s)
				}
			} else if u.dot(q.d) > 0 {
				ans = min(ans, l/(p.s+q.s))
			}
		}
	}
	if ans == 1e99 {
		Print("No show :(")
	} else {
		Printf("%.8f", ans)
	}
}

package main

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

type vec struct{ x, y int }

func (a vec) sub(b vec) vec { return vec{a.x - b.x, a.y - b.y} }
func (a vec) dot(b vec) int { return a.x*b.x + a.y*b.y }
func (a vec) det(b vec) int { return a.x*b.y - a.y*b.x }
func (a vec) len() float64  { return Hypot(float64(a.x), float64(a.y)) }

type car struct {
	p, d vec
	s, l float64
}

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	Fscan(in, &n)
	c := make([]car, n)
	for i := range c {
		Fscan(in, &c[i].p.x, &c[i].p.y, &c[i].d.x, &c[i].d.y, &c[i].s)
		c[i].l = c[i].d.len()
	}

	ans := 1e99
	for i, p := range c {
		for j := i + 1; j < n; j++ {
			q := c[j]
			u := p.p.sub(q.p)
			if d := p.d.det(q.d); d != 0 {
				if t1, t2 := q.d.det(u), p.d.det(u); d > 0 && t1 >= 0 && t2 >= 0 || d < 0 && t1 <= 0 && t2 <= 0 {
					ans = Min(ans, Max(p.l*float64(t1)/(p.s*float64(d)), q.l*float64(t2)/(q.s*float64(d))))
				}
				continue
			}
			if u.det(p.d) != 0 {
				continue
			}
			l := u.len()
			if p.d.dot(q.d) > 0 {
				if u.dot(q.d) >= 0 {
					ans = Min(ans, l/q.s)
				} else {
					ans = Min(ans, l/p.s)
				}
			} else if u.dot(q.d) > 0 {
				ans = Min(ans, l/(p.s+q.s))
			}
		}
	}
	if ans == 1e99 {
		Print("No show :(")
	} else {
		Printf("%.8f", ans)
	}
}

package main

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

type vec struct{ x, y int }
type vecF struct{ x, y float64 }

func (a vec) sub(b vec) vec      { return vec{a.x - b.x, a.y - b.y} }
func (a vec) mul(k float64) vecF { return vecF{float64(a.x) * k, float64(a.y) * k} }
func (a vec) dot(b vec) int      { return a.x*b.x + a.y*b.y }
func (a vec) det(b vec) int      { return a.x*b.y - a.y*b.x }
func (a vecF) len() float64      { return math.Hypot(a.x, a.y) }

// github.com/EndlessCheng/codeforces-go
func CF1359F(_r io.Reader, out io.Writer) {
	min := func(a, b float64) float64 {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b float64) float64 {
		if a > b {
			return a
		}
		return b
	}
	type car struct {
		p, d vec
		s    float64
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	cs := make([]car, n)
	for i := range cs {
		Fscan(in, &cs[i].p.x, &cs[i].p.y, &cs[i].d.x, &cs[i].d.y, &cs[i].s)
	}

	ans := 1e99
	for i, p := range cs {
		for j := i + 1; j < n; j++ {
			q := cs[j]
			u := p.p.sub(q.p)
			if det := p.d.det(q.d); det != 0 {
				t1 := q.d.det(u)
				t2 := p.d.det(u)
				if det > 0 && t1 >= 0 && t2 >= 0 || det < 0 && t1 <= 0 && t2 <= 0 {
					l1, l2 := p.d.mul(float64(t1)/float64(det)).len(), q.d.mul(float64(t2)/float64(det)).len()
					ans = min(ans, max(l1/p.s, l2/q.s))
				}
			} else {
				l := math.Hypot(float64(u.x), float64(u.y))
				if p.d.dot(q.d) > 0 {
					if u.dot(q.d) >= 0 {
						ans = min(ans, l/q.s)
					} else {
						ans = min(ans, l/p.s)
					}
				} else {
					if u.dot(q.d) > 0 {
						ans = min(ans, l/(p.s+q.s))
					}
				}
			}
		}
	}
	if ans == 1e99 {
		Fprint(out, "No show :(")
	} else {
		Fprintf(out, "%.8f", ans)
	}
}

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