You are given an array $$$a$$$ consisting of $$$n$$$ integers. For each $$$i$$$ ($$$1 \le i \le n$$$) the following inequality is true: $$$-2 \le a_i \le 2$$$.You can remove any number (possibly $$$0$$$) of elements from the beginning of the array and any number (possibly $$$0$$$) of elements from the end of the array. You are allowed to delete the whole array.You need to answer the question: how many elements should be removed from the beginning of the array, and how many elements should be removed from the end of the array, so that the result will be an array whose product (multiplication) of elements is maximal. If there is more than one way to get an array with the maximum product of elements on it, you are allowed to output any of them. The product of elements of an empty array (array of length $$$0$$$) should be assumed to be $$$1$$$.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. Then the descriptions of the input test cases follow. The first line of each test case description contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) —the length of array $$$a$$$. The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$|a_i| \le 2$$$) — elements of array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output two non-negative numbers $$$x$$$ and $$$y$$$ ($$$0 \le x + y \le n$$$) — such that the product (multiplication) of the array numbers, after removing $$$x$$$ elements from the beginning and $$$y$$$ elements from the end, is maximal. If there is more than one way to get the maximal product, it is allowed to output any of them. Consider the product of numbers on empty array to be $$$1$$$.

NoteIn the first case, the maximal value of the product is $$$2$$$. Thus, we can either delete the first three elements (obtain array $$$[2]$$$), or the last two and one first element (also obtain array $$$[2]$$$), or the last two elements (obtain array $$$[1, 2]$$$). Thus, in the first case, the answers fit: "3 0", or "1 2", or "0 2".In the second case, the maximum value of the product is $$$1$$$. Then we can remove all elements from the array because the value of the product on the empty array will be $$$1$$$. So the answer is "3 0", but there are other possible answers.In the third case, we can remove the first two elements of the array. Then we get the array: $$$[-2, 2, -1]$$$. The product of the elements of the resulting array is $$$(-2) \cdot 2 \cdot (-1) = 4$$$. This value is the maximum possible value that can be obtained. Thus, for this case the answer is: "2 0".

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i := 0; i <= n; i++ {
		v := 0
		if i < n {
			v = arr[i]
		}
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					ans = mx
					l = i - len(tmp) + lt
					r = n - i + rt
					if i == n {
						r = rt
						l = n - len(tmp) + lt
					}
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 0
	neg := false
	n := len(arr)
	for i := 0; i < n; i++ {
		if arr[i] < 0 {
			neg = !neg
		}
		if abs(arr[i]) == 2 {
			cur++
		}
		if !neg && cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 0
	neg = false
	for i := n - 1; i >= 0; i-- {
		if arr[i] < 0 {
			neg = !neg
		}
		if abs(arr[i]) == 2 {
			cur++
		}
		if !neg && cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

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

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

	c, n := 0, 0
	var arr []int
	Fscan(in, &c)
	for i := 1; i <= c; i++ {
		Fscan(in, &n)
		arr = make([]int, n+2) //头尾充0
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		x, y := 0, n
		max := 0
		two := 0
		sign := 1
		for left, right := 0, 1; right < n+2; right++ { //找相邻的2个0
			if arr[right] == 0 { //确定一段区间，进行双指针查询
				if sign == 1 && two > max {
					max = two
					x = left
					y = n + 1 - right
				} else if sign == -1 && two > max {
					tmp_x := left
					tmp_y := n + 1 - right
					tmp_left := left + 1
					tmp_right := right - 1
					l_min := two
					r_min := two
					l_two := 0
					r_two := 0
					l_sign := 1
					r_sign := 1
					for tmp_left < right {
						if arr[tmp_left] == -2 || arr[tmp_left] == 2 {
							l_two++
						}
						if arr[tmp_left] < 0 {
							l_sign *= -1
						}
						if l_sign == -1 && l_two < l_min {
							l_min = l_two
							tmp_x = tmp_left
						}
						if arr[tmp_right] == -2 || arr[tmp_right] == 2 {
							r_two++
						}
						if arr[tmp_right] < 0 {
							r_sign *= -1
						}
						if r_sign == -1 && r_two < r_min {
							r_min = r_two
							tmp_y = n + 1 - tmp_right
						}
						tmp_left++
						tmp_right--
					}
					if l_min < r_min && two-l_min > max {
						max = two - l_min
						x = tmp_x
						y = n + 1 - right
					} else if r_min < l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					} else if r_min == l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					}
				}
				two = 0
				sign = 1
				left = right
			} else {
				if arr[right] == 2 || arr[right] == -2 {
					two++
				}
				if arr[right] < 0 {
					sign *= -1
				}
			}
		}
		Fprintf(out, "%d %d\n", x, y)
	}
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var t int
	Fscan(in, &t)

	for k := 0; k < t; k++ {
		var n, x int
		Fscan(in, &n)
		maxV := make([]int, n+1)
		maxI := make([]int, n+1)

		minV := make([]int, n+1)
		minI := make([]int, n+1)

		ans := 0
		l := n
		r := 0

		maxV[0], maxI[0] = -1, -1
		minV[0], minI[0] = -1, -1

		for i := 1; i <= n; i++ {
			Fscan(in, &x)

			maxV[i], maxI[i] = -1, -1
			minV[i], minI[i] = -1, -1

			if x == 1 {
				maxV[i], maxI[i] = maxV[i-1], maxI[i-1]
				minV[i], minI[i] = minV[i-1], minI[i-1]

				if maxV[i] == -1 {
					maxV[i] = 0
					maxI[i] = i
				}
			}

			if x == -1 {
				maxV[i], maxI[i] = minV[i-1], minI[i-1]
				minV[i], minI[i] = maxV[i-1], maxI[i-1]

				if minV[i] == -1 {
					minV[i] = 0
					minI[i] = i
				}

			}

			if x == 2 {
				if minV[i-1] >= 0 {
					minV[i] = minV[i-1] + 1
					minI[i] = minI[i-1]
				}

				if maxV[i-1] >= 0 {
					maxV[i] = maxV[i-1] + 1
					maxI[i] = maxI[i-1]
				} else {
					maxV[i] = 1
					maxI[i] = i
				}

			}

			if x == -2 {
				if minV[i-1] >= 0 {
					maxV[i] = minV[i-1] + 1
					maxI[i] = minI[i-1]
				}
				if maxV[i-1] >= 0 {
					minV[i] = maxV[i-1] + 1
					minI[i] = maxI[i-1]
				} else {
					minV[i] = 1
					minI[i] = i
				}
			}

			if maxV[i] > ans {
				ans = maxV[i]
				l = maxI[i] - 1
				r = n - i
			}

		}

		Fprintln(out, l, r)
	}

}

package main

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

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

func sign(a int) int {
  if a == 0 {
    return 0
  } else if a < 0 {
    return -1
  } else {
    return 1
  }
}

func abs_eq_2(a int) int {
  if a == -2 || a == 2 {
    return 1
  }
  return 0
}

func opt(a []int, ans int) (int, int, int) {
  if ans >= 0 {
    return 0, len(a), ans
  }

  ans2 := ans
  ans2_trim := 0
  for i := 0 ; ans2 < 0 && i < len(a) ; i++ {
    ans2 *= sign(a[i])
    ans2 -= sign(ans2) * abs_eq_2(a[i])
    ans2_trim++
  }

  ans3 := ans
  ans3_trim := 0
  for i := len(a) - 1 ; ans3 < 0 && i >= 0 ; i-- {
    ans3 *= sign(a[i])
    ans3 -= sign(ans3) * abs_eq_2(a[i])
    ans3_trim++
  }

  if ans2 > ans3 {
    return ans2_trim, len(a) - ans2_trim, ans2
  } else {
    return 0, len(a) - ans3_trim, ans3
  }
}

func solve(a []int) (int, int, int) {
  if len(a) == 0 {
    return 0, 0, 1
  }

  ans := 1
  size := 0
  for i := 0 ; i < len(a) && a[i] != 0; i++ {
    ans *= sign(a[i])
    ans += sign(ans) * abs_eq_2(a[i])
    size++
  }
  offs1, size1, ans1 := opt(a[0:size], ans)

  if size < len(a) {
    offs2, size2, ans2 := solve(a[size + 1:])
    if ans2 > ans1 {
      return offs2 + size + 1, size2, ans2
    }
  }
  return offs1, size1, ans1
}

func main() {
  defer writer.Flush()
  var t int
  for scanf("%d\n", &t) ; t > 0 ; t-- {
    var n int
    scanf("%d\n", &n)
    a := make([]int, n)
    for i := 0 ; i < n; i++ {
      var val int
      scanf("%d", &val)
      a[i] = val
    }
    scanf("\n")
    offs, size, _ := solve(a)
    printf("%d %d\n", offs, len(a) - offs - size)
  }
}

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		mx, ll, rr := 0, 0, 0
		for i := 0; i < n; i++ {
			if a[i] == 0 {
				continue
			}
			st := i
			c, neg, l, r := 0, false, -1, 0
			for ; i < n && a[i] != 0; i++ {
				if a[i] == -2 || a[i] == 2 {
					c++
				}
				if a[i] < 0 {
					neg = !neg
					if l < 0 {
						l = i
					}
					r = i
				}
			}
			if neg {
				cl, cr := 0, 0
				for j := st; j < i; j++ {
					if a[j] == -2 || a[j] == 2 {
						if j < r {
							cl++
						}
						if j > l {
							cr++
						}
					}
				}
				if cl > cr {
					c, l, r = cl, st, r-1
				} else {
					c, l, r = cr, l+1, i-1
				}
			} else {
				l, r = st, i-1
			}
			if c > mx {
				mx, ll, rr = c, l, r
			}
		}
		if mx == 0 {
			Fprintln(out, n, 0)
		} else {
			Fprintln(out, ll, n-rr-1)
		}
	}
}

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

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		n := 0
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		var zeros []int
		one, two, oone, ttwo := 0, 0, 0, 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
			switch nums[i] {
			case 0:
				zeros = append(zeros, i)
			case 1:
				one++
			case 2:
				two++
			case -1:
				oone++
			case -2:
				ttwo++
			}
		}
		if len(zeros) == 0 {
			_, i, j := cal(nums)
			fmt.Fprintln(out, i, j)
		} else {
			last := -1
			var max = []int{0, n, 0}
			zeros = append(zeros, n)
			for i := 0; i < len(zeros); i++ {
				a,b,c:= cal(nums[last+1:zeros[i]])
				if a > max[0]{
					max = []int{a,b+last+1,c+(n-zeros[i])}
				}
				last = zeros[i]
				//fmt.Println(a,b,c)
			}
			fmt.Fprintln(out, max[1], max[2])
		}
	}
}

func cal(nums []int) (int, int, int) {
	n := len(nums)
	one, two, oone, ttwo := 0, 0, 0, 0
	for i := 0; i < n; i++ {
		switch nums[i] {
		case 1:
			one++
		case 2:
			two++
		case -1:
			oone++
		case -2:
			ttwo++
		}
	}
	newOne, newTwo, newOone, newTtwo := one, two, oone, ttwo
	i := 0
	for ; i < n && (newOone+newTtwo)&1 == 1; i++ {
		switch nums[i] {
		case 1:
			newOne--
		case 2:
			newTwo--
		case -1:
			newOone--
		case -2:
			newTtwo--
		}
	}
	temp := newTwo + newTtwo
	newOne, newTwo, newOone, newTtwo = one, two, oone, ttwo
	j := n - 1
	for ; j >= 0 && (newOone+newTtwo)&1 == 1; j-- {
		switch nums[j] {
		case 1:
			newOne--
		case 2:
			newTwo--
		case -1:
			newOone--
		case -2:
			newTtwo--
		}
	}
	if newTwo+newTtwo > temp {
		return newTwo + newTtwo, 0, n - j - 1
	} else {
		return temp, i, 0
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i := 0; i <= n; i++ {
		v := 0
		if i < n {
			v = arr[i]
		}
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					ans = mx
					l = i - len(tmp) + lt
					r = n - i + rt
					if i == n {
						r = rt
						l = n - len(tmp) + lt
					}
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 0
	neg := false
	n := len(arr)
	for i := 0; i < n; i++ {
		if arr[i] < 0 {
			neg = !neg
		}
		if abs(arr[i]) == 2 {
			cur++
		}
		if !neg && cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	neg = false
	for i := n - 1; i >= 0; i-- {
		if arr[i] < 0 {
			neg = !neg
		}
		if abs(arr[i]) == 2 {
			cur++
		}
		if !neg && cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i := 0; i <= n; i++ {
		v := 0
		if i < n {
			v = arr[i]
		}
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					ans = mx
					l = i - len(tmp) + lt
					r = n - i + rt
					if i == n {
						r = rt
						l = n - len(tmp) + lt
					}
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i := 0; i <= n; i++ {
		v := 0
		if i < n {
			v = arr[i]
		}
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					ans = mx
					l = i - len(tmp) + 1 + lt
					r = n - i - 1 + rt
					if i == n {
						r = rt
						l = n - len(tmp) + lt
					}
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i := 0; i <= n; i++ {
		v := 0
		if i < n {
			v = arr[i]
		}
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					l = i - len(tmp) + 1 + lt
					r = n - i - 1 + rt
					if i == n {
						r = rt
					}
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i := 0; i <= n; i++ {
		v := 0
		if i < n {
			v = arr[i]
		}
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					l = i - len(tmp) + 1 + lt
					r = n - i - 1 + rt
					if i == n {
						r = rt
					}
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin, _ := os.Open("/project/go/algo/input")
	//stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i := 0; i <= n; i++ {
		v := 0
		if i < n {
			v = arr[i]
		}
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					l = i - len(tmp) + 1 + lt
					r = n - i - 1 + rt
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i := 0; i <= n; i++ {
		v := 0
		if i < n {
			v = arr[i]
		}
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n-1 {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					l = i - len(tmp) + 1 + lt
					r = n - i - 1 + rt
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i := 0; i <= n; i++ {
		v := 0
		if i < n {
			v = arr[i]
		}
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n-1 {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					l = i - len(tmp) + 1 + lt
					r = n - i - 1 + rt
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin, _ := os.Open("/project/go/algo/input")
	//stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i, v := range arr {
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n-1 {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					l = i - len(tmp) + 1 + lt
					r = n - i - 1 + rt
					if v == 0 {
						if l != 0 {
							l--
						}
						if r != 0 {
							r--
						}
					}
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i, v := range arr {
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n-1 {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					l = i - len(tmp) + 1 + lt
					r = n - i - 1 + rt
					if v == 0 {
						l--
						r--
					}
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i, v := range arr {
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n-1 {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					l = i - len(tmp) + 1 + lt
					r = n - i - 1 + rt
					if v == 0 {
						l--
						r++
					}
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i, v := range arr {
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n-1 {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					l = i - len(tmp) + 1 + lt
					r = n - i - 1 + rt
					if v == 0 {
						l--
						r++
					}
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin, _ := os.Open("/project/go/algo/input")
	//stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var tmp []int
	ans, l, r := 0, n, 0
	for i, v := range arr {
		if v != 0 {
			tmp = append(tmp, v)
		}
		if v == 0 || i == n-1 {
			if len(tmp) != 0 {
				mx, lt, rt := getMax(tmp)
				if mx > ans {
					l = i - len(tmp) + 1 + lt
					r = n - i - 1 + rt
				}
				tmp = make([]int, 0)
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", l, r)
}
func getMax(arr []int) (mx, l, r int) {
	mx = 0
	cur := 1
	n := len(arr)
	for i := 0; i < n; i++ {
		cur *= arr[i]
		if cur >= mx {
			mx = cur
			l = 0
			r = n - i - 1
		}
	}
	cur = 1
	for i := n - 1; i >= 0; i-- {
		cur *= arr[i]
		if cur > mx {
			mx = cur
			l = i
			r = 0
		}
	}
	return
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

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

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

	c, n := 0, 0
	var arr []int
	Fscan(in, &c)
	for i := 1; i <= c; i++ {
		Fscan(in, &n)
		arr = make([]int, n+2) //头尾充0
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		if i == 1475 {
			Println(arr, n)
		}
		x, y := 0, n
		max := 0
		two := 0
		sign := 1
		for left, right := 0, 1; right < n+2; right++ { //找相邻的2个0
			if arr[right] == 0 { //确定一段区间，进行双指针查询
				if sign == 1 && two > max {
					max = two
					x = left
					y = n + 1 - right
				} else if sign == -1 && two > max {
					tmp_x := left
					tmp_y := n + 1 - right
					tmp_left := left + 1
					tmp_right := right - 1
					l_min := two
					r_min := two
					l_two := 0
					r_two := 0
					l_sign := 1
					r_sign := 1
					for tmp_left <= tmp_right {
						if arr[tmp_left] == -2 || arr[tmp_left] == 2 {
							l_two++
						}
						if arr[tmp_left] < 0 {
							l_sign *= -1
						}
						if l_sign == -1 && l_two < l_min {
							l_min = l_two
							tmp_x = tmp_left
						}
						if arr[tmp_right] == -2 || arr[tmp_right] == 2 {
							r_two++
						}
						if arr[tmp_right] < 0 {
							r_sign *= -1
						}
						if r_sign == -1 && r_two < r_min {
							r_min = r_two
							tmp_y = n + 1 - tmp_right
						}
						tmp_left++
						tmp_right--
					}
					if l_min < r_min && two-l_min > max {
						max = two - l_min
						x = tmp_x
						y = n + 1 - right
					} else if r_min < l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					} else if r_min == l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					}
				}
				two = 0
				sign = 1
				left = right
			} else {
				if arr[right] == 2 || arr[right] == -2 {
					two++
				}
				if arr[right] < 0 {
					sign *= -1
				}
			}
		}
		if c < 100 {
			Fprintf(out, "%d %d\n", x, y)
		}
	}
}

package main

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

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

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

	c, n := 0, 0
	var arr []int
	Fscan(in, &c)
	for ; c > 0; c-- {
		Fscan(in, &n)
		arr = make([]int, n+2) //头尾充0
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		x, y := 0, n
		max := -1
		two := 0
		sign := 1
		for left, right := 0, 1; right < n+2; right++ { //找相邻的2个0
			if arr[right] == 0 { //确定一段区间，进行双指针查询
				if sign == 1 && two > max {
					max = two
					x = left
					y = n + 1 - right
				} else if sign == -1 && two > max {
					tmp_x := left
					tmp_y := n + 1 - right
					tmp_left := left + 1
					tmp_right := right - 1
					l_min := two
					r_min := two
					l_two := 0
					r_two := 0
					l_sign := 1
					r_sign := 1
					for tmp_left <= tmp_right {
						if arr[tmp_left] == -2 || arr[tmp_left] == 2 {
							l_two++
						}
						if arr[tmp_left] < 0 {
							l_sign *= -1
						}
						if l_sign == -1 && l_two < l_min {
							l_min = l_two
							tmp_x = tmp_left
						}
						if arr[tmp_right] == -2 || arr[tmp_right] == 2 {
							r_two++
						}
						if arr[tmp_right] < 0 {
							r_sign *= -1
						}
						if r_sign == -1 && r_two < r_min {
							r_min = r_two
							tmp_y = n + 1 - tmp_right
						}
						tmp_left++
						tmp_right--
					}
					if l_min < r_min && two-l_min > max {
						max = two - l_min
						x = tmp_x
						y = n + 1 - right
					} else if r_min < l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					} else if r_min == l_min && r_min != two && two - r_min > max{
						max = two-r_min
						x = left
						y = tmp_y
					}
				}
				two = 0
				sign = 1
				left = right
			} else {
				if arr[right] == 2 || arr[right] == -2 {
					two++
				}
				if arr[right] < 0 {
					sign *= -1
				}
			}
		}
		Fprintf(out, "%d %d\n", x, y)
	}
}

package main

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

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

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

	c, n := 0, 0
	var arr []int
	Fscan(in, &c)
	for i := 1; i <= c; i++ {
		if i == 1474 || i == 1475 {
			Println(arr, n)
		}
		Fscan(in, &n)
		arr = make([]int, n+2) //头尾充0
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		x, y := 0, n
		max := 0
		two := 0
		sign := 1
		for left, right := 0, 1; right < n+2; right++ { //找相邻的2个0
			if arr[right] == 0 { //确定一段区间，进行双指针查询
				if sign == 1 && two > max {
					max = two
					x = left
					y = n + 1 - right
				} else if sign == -1 && two > max {
					tmp_x := left
					tmp_y := n + 1 - right
					tmp_left := left + 1
					tmp_right := right - 1
					l_min := two
					r_min := two
					l_two := 0
					r_two := 0
					l_sign := 1
					r_sign := 1
					for tmp_left <= tmp_right {
						if arr[tmp_left] == -2 || arr[tmp_left] == 2 {
							l_two++
						}
						if arr[tmp_left] < 0 {
							l_sign *= -1
						}
						if l_sign == -1 && l_two < l_min {
							l_min = l_two
							tmp_x = tmp_left
						}
						if arr[tmp_right] == -2 || arr[tmp_right] == 2 {
							r_two++
						}
						if arr[tmp_right] < 0 {
							r_sign *= -1
						}
						if r_sign == -1 && r_two < r_min {
							r_min = r_two
							tmp_y = n + 1 - tmp_right
						}
						tmp_left++
						tmp_right--
					}
					if l_min < r_min && two-l_min > max {
						max = two - l_min
						x = tmp_x
						y = n + 1 - right
					} else if r_min < l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					} else if r_min == l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					}
				}
				two = 0
				sign = 1
				left = right
			} else {
				if arr[right] == 2 || arr[right] == -2 {
					two++
				}
				if arr[right] < 0 {
					sign *= -1
				}
			}
		}
		if c < 100 {
			Fprintf(out, "%d %d\n", x, y)
		}
	}
}

package main

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

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

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

	c, n := 0, 0
	var arr []int
	Fscan(in, &c)
	for i := 1; i <= c; i++ {
		if i == 1474 || i == 1475 || i == 1476{
			Println(arr)
		}
		Fscan(in, &n)
		arr = make([]int, n+2) //头尾充0
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		x, y := 0, n
		max := 0
		two := 0
		sign := 1
		for left, right := 0, 1; right < n+2; right++ { //找相邻的2个0
			if arr[right] == 0 { //确定一段区间，进行双指针查询
				if sign == 1 && two > max {
					max = two
					x = left
					y = n + 1 - right
				} else if sign == -1 && two > max {
					tmp_x := left
					tmp_y := n + 1 - right
					tmp_left := left + 1
					tmp_right := right - 1
					l_min := two
					r_min := two
					l_two := 0
					r_two := 0
					l_sign := 1
					r_sign := 1
					for tmp_left <= tmp_right {
						if arr[tmp_left] == -2 || arr[tmp_left] == 2 {
							l_two++
						}
						if arr[tmp_left] < 0 {
							l_sign *= -1
						}
						if l_sign == -1 && l_two < l_min {
							l_min = l_two
							tmp_x = tmp_left
						}
						if arr[tmp_right] == -2 || arr[tmp_right] == 2 {
							r_two++
						}
						if arr[tmp_right] < 0 {
							r_sign *= -1
						}
						if r_sign == -1 && r_two < r_min {
							r_min = r_two
							tmp_y = n + 1 - tmp_right
						}
						tmp_left++
						tmp_right--
					}
					if l_min < r_min && two-l_min > max {
						max = two - l_min
						x = tmp_x
						y = n + 1 - right
					} else if r_min < l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					} else if r_min == l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					}
				}
				two = 0
				sign = 1
				left = right
			} else {
				if arr[right] == 2 || arr[right] == -2 {
					two++
				}
				if arr[right] < 0 {
					sign *= -1
				}
			}
		}
		if c < 100 {
			Fprintf(out, "%d %d\n", x, y)
		}
	}
}

package main

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

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

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

	c, n := 0, 0
	var arr []int
	Fscan(in, &c)
	for i := 1; i <= c; i++ {
		if i == 1474 || i == 1475 {
			Println(arr)
		}
		Fscan(in, &n)
		arr = make([]int, n+2) //头尾充0
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		x, y := 0, n
		max := 0
		two := 0
		sign := 1
		for left, right := 0, 1; right < n+2; right++ { //找相邻的2个0
			if arr[right] == 0 { //确定一段区间，进行双指针查询
				if sign == 1 && two > max {
					max = two
					x = left
					y = n + 1 - right
				} else if sign == -1 && two > max {
					tmp_x := left
					tmp_y := n + 1 - right
					tmp_left := left + 1
					tmp_right := right - 1
					l_min := two
					r_min := two
					l_two := 0
					r_two := 0
					l_sign := 1
					r_sign := 1
					for tmp_left <= tmp_right {
						if arr[tmp_left] == -2 || arr[tmp_left] == 2 {
							l_two++
						}
						if arr[tmp_left] < 0 {
							l_sign *= -1
						}
						if l_sign == -1 && l_two < l_min {
							l_min = l_two
							tmp_x = tmp_left
						}
						if arr[tmp_right] == -2 || arr[tmp_right] == 2 {
							r_two++
						}
						if arr[tmp_right] < 0 {
							r_sign *= -1
						}
						if r_sign == -1 && r_two < r_min {
							r_min = r_two
							tmp_y = n + 1 - tmp_right
						}
						tmp_left++
						tmp_right--
					}
					if l_min < r_min && two-l_min > max {
						max = two - l_min
						x = tmp_x
						y = n + 1 - right
					} else if r_min < l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					} else if r_min == l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					}
				}
				two = 0
				sign = 1
				left = right
			} else {
				if arr[right] == 2 || arr[right] == -2 {
					two++
				}
				if arr[right] < 0 {
					sign *= -1
				}
			}
		}
		if c < 100 {
			Fprintf(out, "%d %d\n", x, y)
		}
	}
}

package main

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

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

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

	c, n := 0, 0
	var arr []int
	Fscan(in, &c)
	for i := 1; i <= c; i++ {
		if i == 1475 {
			Println(arr)
		}
		Fscan(in, &n)
		arr = make([]int, n+2) //头尾充0
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		x, y := 0, n
		max := 0
		two := 0
		sign := 1
		for left, right := 0, 1; right < n+2; right++ { //找相邻的2个0
			if arr[right] == 0 { //确定一段区间，进行双指针查询
				if sign == 1 && two > max {
					max = two
					x = left
					y = n + 1 - right
				} else if sign == -1 && two > max {
					tmp_x := left
					tmp_y := n + 1 - right
					tmp_left := left + 1
					tmp_right := right - 1
					l_min := two
					r_min := two
					l_two := 0
					r_two := 0
					l_sign := 1
					r_sign := 1
					for tmp_left <= tmp_right {
						if arr[tmp_left] == -2 || arr[tmp_left] == 2 {
							l_two++
						}
						if arr[tmp_left] < 0 {
							l_sign *= -1
						}
						if l_sign == -1 && l_two < l_min {
							l_min = l_two
							tmp_x = tmp_left
						}
						if arr[tmp_right] == -2 || arr[tmp_right] == 2 {
							r_two++
						}
						if arr[tmp_right] < 0 {
							r_sign *= -1
						}
						if r_sign == -1 && r_two < r_min {
							r_min = r_two
							tmp_y = n + 1 - tmp_right
						}
						tmp_left++
						tmp_right--
					}
					if l_min < r_min && two-l_min > max {
						max = two - l_min
						x = tmp_x
						y = n + 1 - right
					} else if r_min < l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					} else if r_min == l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					}
				}
				two = 0
				sign = 1
				left = right
			} else {
				if arr[right] == 2 || arr[right] == -2 {
					two++
				}
				if arr[right] < 0 {
					sign *= -1
				}
			}
		}
		if c < 100 {
			Fprintf(out, "%d %d\n", x, y)
		}
	}
}

package main

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

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

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

	c, n := 0, 0
	var arr []int
	Fscan(in, &c)
	for ; c > 0; c-- {
		Fscan(in, &n)
		arr = make([]int, n+2) //头尾充0
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		x, y := 0, n
		max := 0
		two := 0
		sign := 1
		for left, right := 0, 1; right < n+2; right++ { //找相邻的2个0
			if arr[right] == 0 { //确定一段区间，进行双指针查询
				if sign == 1 && two > max {
					max = two
					x = left
					y = n + 1 - right
				} else if sign == -1 && two > max {
					tmp_x := left
					tmp_y := n + 1 - right
					tmp_left := left + 1
					tmp_right := right - 1
					l_min := two
					r_min := two
					l_two := 0
					r_two := 0
					l_sign := 1
					r_sign := 1
					for tmp_left <= tmp_right {
						if arr[tmp_left] == -2 || arr[tmp_left] == 2 {
							l_two++
						}
						if arr[tmp_left] < 0 {
							l_sign *= -1
						}
						if l_sign == -1 && l_two < l_min {
							l_min = l_two
							tmp_x = tmp_left
						}
						if arr[tmp_right] == -2 || arr[tmp_right] == 2 {
							r_two++
						}
						if arr[tmp_right] < 0 {
							r_sign *= -1
						}
						if r_sign == -1 && r_two < r_min {
							r_min = r_two
							tmp_y = n + 1 - tmp_right
						}
						tmp_left++
						tmp_right--
					}
					if l_min < r_min && two-l_min > max {
						max = two - l_min
						x = tmp_x
						y = n + 1 - right
					} else if r_min < l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					} else if r_min == l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					}
				}
				two = 0
				sign = 1
				left = right
			} else {
				if arr[right] == 2 || arr[right] == -2 {
					two++
				}
				if arr[right] < 0 {
					sign *= -1
				}
			}
		}
		Fprintf(out, "%d %d\n", x, y)
	}
}

package main

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

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

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

	c, n := 0, 0
	var arr []int
	Fscan(in, &c)
	for ; c > 0; c-- {
		Fscan(in, &n)
		arr = make([]int, n+2) //头尾充0
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		x, y := 0, n
		max := -1
		two := 0
		sign := 1
		for left, right := 0, 1; right < n+2; right++ { //找相邻的2个0
			if arr[right] == 0 { //确定一段区间，进行双指针查询
				if sign == 1 && two > max {
					max = two
					x = left
					y = n + 1 - right
				} else if sign == -1 && two > max {
					tmp_x := left
					tmp_y := right
					tmp_left := left + 1
					tmp_right := right - 1
					l_min := two
					r_min := two
					l_two := 0
					r_two := 0
					l_sign := 1
					r_sign := 1
					for tmp_left < tmp_right {
						if arr[tmp_left] == -2 || arr[tmp_left] == 2 {
							l_two++
						}
						if arr[tmp_left] < 0 {
							l_sign *= -1
						}
						if l_sign == -1 && l_two < l_min {
							l_min = l_two
							tmp_x = tmp_left
						}
						if arr[tmp_right] == -2 || arr[tmp_right] == 2 {
							r_two++
						}
						if arr[tmp_right] < 0 {
							r_sign *= -1
						}
						if r_sign == -1 && r_two < r_min {
							r_min = r_two
							tmp_y = n + 1 - tmp_right
						}
						tmp_left++
						tmp_right--
					}
					if l_min < r_min && two-l_min > max {
						max = two - l_min
						x = tmp_x
						y = n + 1 - right
					} else if r_min < l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					}
				}
				two = 0
				sign = 1
				left = right
			} else {
				if arr[right] == 2 || arr[right] == -2 {
					two++
				}
				if arr[right] < 0 {
					sign *= -1
				}
			}
		}
		Fprintf(out, "%d %d\n", x, y)
	}
}

package main

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

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

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

	c, n := 0, 0
	var arr []int
	Fscan(in, &c)
	for ; c > 0; c-- {
		Fscan(in, &n)
		arr = make([]int, n+2) //头尾充0
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		x, y := 0, n-1
		max := -1
		two := 0
		sign := 1
		for left, right := 0, 1; right < n+2; right++ { //找相邻的2个0
			if arr[right] == 0 { //确定一段区间，进行双指针查询
				if sign == 1 && two > max {
					max = two
					x = left
					y = n+1-right
				} else if sign == -1 && two > max {
					tmp_x := left
					tmp_y := right
					tmp_left := left + 1
					tmp_right := right - 1
					l_min := two
					r_min := two
					l_two := 0
					r_two := 0
					l_sign := 1
					r_sign := 1
					for tmp_left < tmp_right {
						if arr[tmp_left] == -2 || arr[tmp_left] == 2 {
							l_two++
						}
						if arr[tmp_left] < 0 {
							l_sign *= -1
						}
						if l_sign == -1 && l_two < l_min {
							l_min = l_two
							tmp_x = tmp_left
						}
						if arr[tmp_right] == -2 || arr[tmp_right] == 2 {
							r_two++
						}
						if arr[tmp_right] < 0 {
							r_sign *= -1
						}
						if r_sign == -1 && r_two < r_min {
							r_min = r_two
							tmp_y = n+1-tmp_right
						}
						tmp_left++
						tmp_right--
					}
					if l_min < r_min && two-l_min > max {
						max = two - l_min
						x = tmp_x
						y = n+1-right
					} else if r_min < l_min && two-r_min > max {
						max = two - r_min
						x = left
						y = tmp_y
					}
				}
				two = 0
				sign = 1
				left = right
			} else {
				if arr[right] == 2 || arr[right] == -2 {
					two++
				}
				if arr[right] < 0 {
					sign *= -1
				}
			}
		}
		Fprintf(out, "%d %d\n", x, y)
	}
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var t int
	Fscan(in, &t)

	for k := 0; k < t; k++ {
		var n, x int
		Fscan(in, &n)
		maxV := make([]int, n+1)
		maxI := make([]int, n+1)

		minV := make([]int, n+1)
		minI := make([]int, n+1)

		ans := 0
		l := n
		r := 0

		maxV[0], maxI[0] = -1, -1
		minV[0], minI[0] = -1, -1

		for i := 1; i <= n; i++ {
			Fscan(in, &x)

			maxV[i], maxI[i] = -1, -1
			minV[i], minI[i] = -1, -1

			if x == 1 {
				maxV[i], maxI[i] = maxV[i-1], maxI[i-1]
				minV[i], minI[i] = minV[i-1], minI[i-1]

				if maxV[i] == -1 {
					maxV[i] = 0
					maxI[i] = i
				}
			}

			if x == -1 {
				maxV[i], maxI[i] = minV[i-1], minI[i-1]
				minV[i], minI[i] = maxV[i-1], maxI[i-1]

				if minV[i] == -1 {
					minV[i] = 0
					minI[i] = i
				}

			}

			if x == 2 {
				if minV[i-1] > 0 {
					minV[i] = minV[i-1] + 1
					minI[i] = minI[i-1]
				}

				if maxV[i-1] > 0 {
					maxV[i] = maxV[i-1] + 1
					maxI[i] = maxI[i-1]
				} else {
					maxV[i] = 1
					maxI[i] = i
				}

			}

			if x == -2 {
				if minV[i-1] > 0 {
					maxV[i] = minV[i-1] + 1
					maxI[i] = minI[i-1]
				}
				if maxV[i-1] > 0 {
					minV[i] = maxV[i-1] + 1
					minI[i] = maxI[i-1]
				} else {
					minV[i] = 1
					minI[i] = i
				}
			}

			if maxV[i] > ans {
				ans = maxV[i]
				l = maxI[i] - 1
				r = n - i
			}

		}

		Fprintln(out, l, r)
	}

}

package main

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

const (
	INF = 3e5 + 10
)

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

	var t int
	Fscan(in, &t)

	for k := 0; k < t; k++ {
		var n, x int
		Fscan(in, &n)
		maxV := make([]int, n+1)
		maxI := make([]int, n+1)

		minV := make([]int, n+1)
		minI := make([]int, n+1)

		ans := 0
		l := n
		r := 0

		maxV[0], maxI[0] = -1, -1
		minV[0], minI[0] = -1, -1

		for i := 1; i <= n; i++ {
			Fscan(in, &x)

			maxV[i], maxI[i] = -1, -1
			minV[i], minI[i] = -1, -1

			if x == 1 {
				maxV[i], maxI[i] = maxV[i-1], maxI[i-1]
				minV[i], minI[i] = minV[i-1], minI[i-1]
			}

			if x == -1 {
				maxV[i], maxI[i] = minV[i-1], minI[i-1]
				minV[i], minI[i] = maxV[i-1], maxI[i-1]
			}

			if x == 2 {
				if minV[i-1] > 0 {
					minV[i] = minV[i-1] + 1
					minI[i] = minI[i-1]
				}

				if maxV[i-1] > 0 {
					maxV[i] = maxV[i-1] + 1
					maxI[i] = maxI[i-1]
				} else {
					maxV[i] = 1
					maxI[i] = i
				}

			}

			if x == -2 {
				if minV[i-1] > 0 {
					maxV[i] = minV[i-1] + 1
					maxI[i] = minI[i-1]
				}
				if maxV[i-1] > 0 {
					minV[i] = maxV[i-1] + 1
					minI[i] = maxI[i-1]
				} else {
					minV[i] = 1
					minI[i] = i
				}
			}

			if maxV[i] > ans {
				ans = maxV[i]
				l = maxI[i] - 1
				r = n - i
			}

		}

		Fprintln(out, l, r)
	}

}

package main

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

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

func opt(a []int, ans int64) (int, int, int64) {
  if ans >= 0 {
    return 0, len(a), ans
  }

  ans2 := ans
  ans2_trim := 0
  for i := 0 ; ans2 < 0 && i < len(a) ; i++ {
    ans2 /= int64(a[i])
    ans2_trim++
  }

  ans3 := ans
  ans3_trim := 0
  for i := len(a) - 1 ; ans3 < 0 && i >= 0 ; i-- {
    ans3 /= int64(a[i])
    ans3_trim++
  }

  if ans2 > ans3 {
    return ans2_trim, len(a) - ans2_trim, ans2
  } else {
    return 0, len(a) - ans3_trim, ans3
  }
}

func solve(a []int) (int, int, int64) {
  if len(a) == 0 {
    return 0, 0, int64(1)
  }

  ans := int64(1)
  size := 0
  for i := 0 ; i < len(a) && a[i] != 0; i++ {
    ans *= int64(a[i])
    size++
  }
  offs1, size1, ans1 := opt(a[0:size], ans)

  if size < len(a) {
    offs2, size2, ans2 := solve(a[size + 1:])
    if ans2 > ans1 {
      return offs2 + size + 1, size2, ans2
    }
  }
  return offs1, size1, ans1
}

func main() {
  defer writer.Flush()
  var t int
  for scanf("%d\n", &t) ; t > 0 ; t-- {
    var n int
    scanf("%d\n", &n)
    a := make([]int, n)
    for i := 0 ; i < n; i++ {
      var val int
      scanf("%d", &val)
      a[i] = val
    }
    scanf("\n")
    offs, size, _ := solve(a)
    printf("%d %d\n", offs, len(a) - offs - size)
  }
}


Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one of the routers bought before it. You are given the values $$$p_i$$$ — the index of the router to which the $$$i$$$-th router was connected after being purchased ($$$p_i < i$$$).There are $$$n$$$ routers in Boogle in total now. Print the sequence of routers on the path from the first to the $$$n$$$-th router.

The first line contains integer number $$$n$$$ ($$$2 \le n \le 200000$$$) — the number of the routers. The following line contains $$$n-1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$), where $$$p_i$$$ is equal to index of the router to which the $$$i$$$-th was connected after purchase.

Print the path from the $$$1$$$-st to the $$$n$$$-th router. It starts with $$$1$$$ and ends with $$$n$$$. All the elements in the path should be distinct.

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func read_int_array(array_length int) []int {
    input_array := make([]int, array_length)
    for i := 0; i < array_length; i++ {
        fmt.Fscan(reader, &input_array[i])
    }
    return input_array
}

func solve(n int, array []int) {
    if n == 1 {
       fmt.Print(1)
    } else {
        solve(array[n-2], array)
	fmt.Printf(" %d",n)
    }
}

func main() {
    var n int
    fmt.Fscanln(reader, &n)

    input_array := read_int_array(n-1)
    solve(n, input_array)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var input_array []int

func read_int_array(array_length int) {
    for i := 0; i < array_length; i++ {
        fmt.Fscan(reader, &input_array[i])
    }
}

func solve(n int) {
    if n == 1 {
       fmt.Print(1)
    } else {
        solve(input_array[n-2])
	fmt.Printf(" %d",n)
    }
}

func main() {
    var n int
    fmt.Fscanln(reader, &n)

    input_array = make([]int, n-1)
    read_int_array(n-1)

    solve(n)
}

// Codeforces 1057 A Vasya and Isolated Vertices, done 4 attempts
package main

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

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

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

var n int
var p []int
var path []int

func readData() {
	in = bufio.NewReader(os.Stdin)
	n,_,_,_,_ = readFive()
	p1 := readLineNumbs(n-1)
	p = make([]int, n)
	p[0] = 0
	for i:=1; i<n; i++ {
		p[i] = p1[i-1]
	}
}

func solve() {
	rpa := make([]int, n)
	rpa[0] = n
	ni := n-1
	i := 1
	for ; true; i++ {
		//fmt.Printf("ni = %d, ", ni)
		ni = p[ni] - 1
		//fmt.Printf("new ni = %d\n", ni)
		if ni>= 0 {
			rpa[i] = ni+1
			//fmt.Printf("added %v on place %d\n", rpa[i], i)
		} else {
			break
		}
	}
	npa := i;
	// reverse path
	path = make([]int, npa)
	for i=0; i<npa; i++ {
		path[i] = rpa[npa-i-1]
	}
}

func printRes() {
	for _,v := range path {
		fmt.Printf("%d ", v)
	}
	fmt.Println()
}

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanInt := func() int {
		scanner.Scan()
		num, err := strconv.Atoi(scanner.Text())
		if err != nil {
			log.Fatal(err)
		}
		return num
	}

	n, adj := scanInt(), map[int]map[int]bool{}
	for i := 1; i <= n; i++ {
		adj[i] = map[int]bool{}
	}
	for i := 2; i <= n; i++ {
		prev := scanInt()
		adj[prev][i], adj[i][prev] = true, true
	}

	queue, visited, parent, pointer := []int{1}, map[int]bool{1: true}, map[int]int{}, 0
	for pointer < len(queue) {
		task := queue[pointer]
		for k := range adj[task] {
			if visited[k] {
				continue
			}
			visited[k], queue, parent[k] = true, append(queue, k), task
		}
		pointer++
	}

	path, pointer := []int{n}, n
	for parent[pointer] != 0 {
		path, pointer = append(path, parent[pointer]), parent[pointer]
	}

	pathStr := []string{}
	for i := len(path) - 1; i >= 0; i-- {
		pathStr = append(pathStr, strconv.Itoa(path[i]))
	}

	fmt.Println(strings.Join(pathStr, " "))
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func read_int_array(array_length int) []int {
    input_array := make([]int, array_length)
    for i := 0; i < array_length; i++ {
        fmt.Fscan(reader, &input_array[i])
    }
    return input_array
}

func solve(n int, array []int) {
    if n == 1 {
       fmt.Print(1)
    } else {
        solve(array[n-2], array)
	fmt.Printf(" %d",n)
    }
}

func main() {
    var n int
    fmt.Fscanln(reader, &n)

    input_array := read_int_array(n-1)
    fmt.Println(input_array)
    solve(n, input_array)
}


Egor is a famous Russian singer, rapper, actor and blogger, and finally he decided to give a concert in the sunny Republic of Dagestan.There are $$$n$$$ cities in the republic, some of them are connected by $$$m$$$ directed roads without any additional conditions. In other words, road system of Dagestan represents an arbitrary directed graph. Egor will arrive to the city $$$1$$$, travel to the city $$$n$$$ by roads along some path, give a concert and fly away.As any famous artist, Egor has lots of haters and too annoying fans, so he can travel only by safe roads. There are two types of the roads in Dagestan, black and white: black roads are safe at night only, and white roads — in the morning. Before the trip Egor's manager's going to make a schedule: for each city he'll specify it's color, black or white, and then if during the trip they visit some city, the only time they can leave it is determined by the city's color: night, if it's black, and morning, if it's white. After creating the schedule Egor chooses an available path from $$$1$$$ to $$$n$$$, and for security reasons it has to be the shortest possible.Egor's manager likes Dagestan very much and wants to stay here as long as possible, so he asks you to make such schedule that there would be no path from $$$1$$$ to $$$n$$$ or the shortest path's length would be greatest possible.A path is one city or a sequence of roads such that for every road (excluding the first one) the city this road goes from is equal to the city previous road goes into. Egor can move only along paths consisting of safe roads only. The path length is equal to the number of roads in it. The shortest path in a graph is a path with smallest length.

The first line contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n \leq 500000$$$, $$$0 \leq m \leq 500000$$$) — the number of cities and the number of roads. The $$$i$$$-th of next $$$m$$$ lines contains three integers — $$$u_i$$$, $$$v_i$$$ and $$$t_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$t_i \in \{0, 1\}$$$) — numbers of cities connected by road and its type, respectively ($$$0$$$ — night road, $$$1$$$ — morning road).

In the first line output the length of the desired path (or $$$-1$$$, if it's possible to choose such schedule that there's no path from $$$1$$$ to $$$n$$$). In the second line output the desired schedule — a string of $$$n$$$ digits, where $$$i$$$-th digit is $$$0$$$, if the $$$i$$$-th city is a night one, and $$$1$$$ if it's a morning one. If there are multiple answers, print any.

NoteFor the first sample, if we paint city $$$1$$$ white, the shortest path is $$$1 \rightarrow 3$$$. Otherwise, it's $$$1 \rightarrow 2 \rightarrow 3$$$ regardless of other cities' colors.For the second sample, we should paint city $$$3$$$ black, and there are both black and white roads going from $$$2$$$ to $$$4$$$. Note that there can be a road connecting a city with itself.

package main

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

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

	var n, m int
	fmt.Fscan(in, &n, &m)
	g := make([][][2]int, n+1)
	for i := 0; i < m; i++ {
		var u, v, t int
		fmt.Fscan(in, &u, &v, &t)
		g[v] = append(g[v], [2]int{u, t + 1})
	}

	dist, color := make([]int, n+1), make([]int, n+1)
	dist[n] = 1
	q := []int{n}
	for len(q) > 0 {
		var q1 []int
		for _, u := range q {
			for _, p := range g[u] {
				v, t := p[0], p[1]
				if color[v] == 0 {
					color[v] = 3 - t
				} else if color[v] == t && dist[v] == 0 {
					dist[v] = dist[u] + 1
					q1 = append(q1, v)
				}
			}
		}
		q = q1
	}

	fmt.Println(dist[1] - 1)
	for _, c := range color[1:] {
		if c == 0 {
			c = 1
		}
		fmt.Print(c - 1)
	}
	fmt.Println()
}

package main

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

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

	var n, m int
	fmt.Fscan(in, &n, &m)
	g := make([][][2]int, n+1)
	for i := 0; i < m; i++ {
		var u, v, t int
		fmt.Fscan(in, &u, &v, &t)
		g[v] = append(g[v], [2]int{u, t + 1})
	}

	dist, color := make([]int, n+1), make([]int, n+1)
	dist[n] = 1
	q := []int{n}
	for len(q) > 0 {
		u := q[0]
		q = q[1:]
		for _, p := range g[u] {
			v, t := p[0], p[1]
			if color[v] == 0 {
				color[v] = 3 - t
			} else if color[v] == t && dist[v] == 0 {
				dist[v] = dist[u] + 1
				q = append(q, v)
			}
		}
	}

	fmt.Println(dist[1] - 1)
	for _, c := range color[1:] {
		if c == 0 {
			c = 1
		}
		fmt.Print(c - 1)
	}
	fmt.Println()
}

package main

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

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

	var n, m int
	fmt.Fscan(in, &n, &m)
	g := make([][][2]int, n+1)
	for i := 0; i < m; i++ {
		var u, v, t int
		fmt.Fscan(in, &u, &v, &t)
		g[v] = append(g[v], [2]int{u, t + 1})
	}

	dist, color := make([]int, n+1), make([]int, n+1)
	color[n], dist[n] = 0, 1
	q := []int{n}
	for len(q) > 0 {
		u := q[len(q)-1]
		q = q[:len(q)-1]
		for _, p := range g[u] {
			v, t := p[0], p[1]
			if color[v] == 0 {
				color[v] = 3 - t
			} else if color[v] == t && dist[v] == 0 {
				dist[v] = dist[u] + 1
				q = append(q, v)
			}
		}
	}

	fmt.Println(dist[1] - 1)
	for _, c := range color[1:] {
		if c == 0 {
			c = 1
		}
		fmt.Print(c - 1)
	}
	fmt.Println()
}


There are $$$n + 1$$$ cities, numbered from $$$0$$$ to $$$n$$$. $$$n$$$ roads connect these cities, the $$$i$$$-th road connects cities $$$i - 1$$$ and $$$i$$$ ($$$i \in [1, n]$$$).Each road has a direction. The directions are given by a string of $$$n$$$ characters such that each character is either L or R. If the $$$i$$$-th character is L, it means that the $$$i$$$-th road initially goes from the city $$$i$$$ to the city $$$i - 1$$$; otherwise it goes from the city $$$i - 1$$$ to the city $$$i$$$.A traveler would like to visit as many cities of this country as possible. Initially, they will choose some city to start their journey from. Each day, the traveler must go from the city where they currently are to a neighboring city using one of the roads, and they can go along a road only if it is directed in the same direction they are going; i. e., if a road is directed from city $$$i$$$ to the city $$$i + 1$$$, it is possible to travel from $$$i$$$ to $$$i + 1$$$, but not from $$$i + 1$$$ to $$$i$$$. After the traveler moves to a neighboring city, all roads change their directions to the opposite ones. If the traveler cannot go from their current city to a neighboring city, their journey ends; it is also possible to end the journey whenever the traveler wants to.The goal of the traveler is to visit as many different cities as possible (they can visit a city multiple times, but only the first visit is counted). For each city $$$i$$$, calculate the maximum number of different cities the traveler can visit during exactly one journey if they start in the city $$$i$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line contains the string $$$s$$$ consisting of exactly $$$n$$$ characters, each character is either L or R. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case, print $$$n + 1$$$ integers. The $$$i$$$-th integer should be equal to the maximum number of different cities the traveler can visit during one journey if this journey starts in the $$$i$$$-th city.

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1e6), 1e6)
}

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

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

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

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

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

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

func sol(n int64, b []byte) []int64 {
	dpl := make([]int64, n+1)
	for i := 1; i < len(dpl); i++ {
		if i-2 >= 0 && b[i-2] != b[i-1] {
			dpl[i] = dpl[i-1] + 1
		} else {
			dpl[i] = 1
		}
	}
	dpr := make([]int64, n+1)
	for i := len(dpr) - 2; i >= 0; i-- {
		if i+1 < len(b) && b[i+1] != b[i] {
			dpr[i] = dpr[i+1] + 1
		} else {
			dpr[i] = 1
		}
	}
	ret := make([]int64, n+1)
	for i := range ret {
		ret[i] = 1
		lidx := i - 1
		if lidx >= 0 && b[lidx] == 'L' {
			ret[i] += dpl[i]
		}
		ridx := i
		if ridx < len(b) && b[ridx] == 'R' {
			ret[i] += dpr[i]
		}
	}
	return ret
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n int
		fmt.Fscan(in,&n)
		var s []byte
		fmt.Fscan(in,&s)
		l := make([]int,n+5)
		r := make([]int,n+5)
		for i:=0;i<len(s);i++{
			l[i]=1
			if i==0{
				continue
			}
			if s[i]!=s[i-1]{
				l[i]=l[i-1]+1
			}
		}
		for i:=len(s)-1;i>=0;i--{
			r[i]=1
			if i==len(s)-1{
				continue
			}
			if s[i]!=s[i+1]{
				r[i]=r[i+1]+1
			}
		}
		for i:=0;i<=n;i++{
			tmp := 0
			if i-1>=0{
				if s[i-1]=='L'{
					tmp += l[i-1]
				}
			}
			if i<n{
				if s[i]=='R'{
					tmp += r[i]
				}
			}
			fmt.Fprintf(out,"%d ",tmp+1)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

const maxN = 300005

var fl, fr [maxN]int

func main() {
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		fmt.Fscan(in, &n)
		var s string
		fmt.Fscan(in, &s)
		s = " " + s + " "
		var cnt int
		for i := 1; i <= n; i++ {
			if s[i] != s[i-1] {
				cnt++
			} else {
				cnt = 1
			}
			if s[i] == 'L' {
				fl[i] = cnt
			} else {
				fl[i] = 0
			}
		}
		cnt = 0
		fr[n] = 0
		for i := n-1; i >= 0; i-- {
			if s[i+1] != s[i+2] {
				cnt++
			} else {
				cnt = 1
			}
			if s[i+1] == 'R' {
				fr[i] = cnt
			} else {
				fr[i] = 0
			}
		}
		for i := 0; i <= n; i++ {
			fmt.Fprint(out, fl[i]+fr[i]+1, " ")
		}
		fmt.Fprintln(out)
	}
	out.Flush()
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) {
		var n int
		var s []byte
		Fscan(in, &n, &s)
		ans := make([]int, n+1)
		ans2 := make([]int, n+1)

		for i := 0; i < n; {
			st := i
			if s[st] == 'L' {
				i++
				continue
			}
			for ; i < n && (i-st)&1 == 0 == (s[i] == 'R'); i++ {
			}
			for ; st < i; st += 2 {
				ans[st] = i - st
			}
		}

		for i := n - 1; i >= 0; {
			st := i
			if s[st] == 'R' {
				i--
				continue
			}
			for ; i >= 0 && (st-i)&1 == 0 == (s[i] == 'L'); i-- {
			}
			for ; st > i; st -= 2 {
				ans2[st+1] = st - i
			}
		}

		Fprint(out, ans[0]+1, " ")
		for i := 1; i < n; i++ {
			var res int
			if s[i-1] == 'L' && s[i] =='R' {
				res = ans[i]+ans2[i]
			} else {
				res = max(ans[i],ans2[i])
			}
			Fprint(out, res+1, " ")
		}
		Fprintln(out, ans2[n]+1)
	}

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

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

func main() { run(os.Stdin, os.Stdout) }
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that:  b is lexicographically greater than or equal to a.  bi ≥ 2.  b is pairwise coprime: for every 1 ≤ i < j ≤ n, bi and bj are coprime, i. e. GCD(bi, bj) = 1, where GCD(w, z) is the greatest common divisor of w and z. Ehab wants to choose a special array so he wants the lexicographically minimal array between all the variants. Can you find it?An array x is lexicographically greater than an array y if there exists an index i such than xi > yi and xj = yj for all 1 ≤ j < i. An array x is equal to an array y if xi = yi for all 1 ≤ i ≤ n.

The first line contains an integer n (1 ≤ n ≤ 105), the number of elements in a and b. The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 105), the elements of a.

Output n space-separated integers, the i-th of them representing bi.

NoteNote that in the second sample, the array is already pairwise coprime so we printed it.

package main

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

const (
	MaxN    = 1500000
	ArrSize = 130050
)

var n, m int

var nums map[int][]int
var primes []int
var a []int

func init() {
	var sieve [MaxN]bool
	var primesArr [ArrSize]int

	nums = make(map[int][]int)

	cnt := 0
	for i := 2; i < MaxN; i++ {
		if sieve[i] == false {
			primesArr[cnt] = i
			cnt++
			nums[i] = []int{i}
			for j := i + i; j < MaxN; j += i {
				sieve[j] = true
				if nums[j] == nil {
					nums[j] = []int{i}
				} else {
					nums[j] = append(nums[j], i)
				}
			}
		}
	}
	primes = primesArr[:cnt]
}

func checkGcd(s map[int]bool, b []int) bool {
	for j := 0; j < len(b); j++ {
		if s[b[j]] {
			return false
		}
	}
	return true
}

func addDivs(s map[int]bool, b []int) {
	for j := 0; j < len(b); j++ {
		s[b[j]] = true
	}
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	a = make([]int, n)
	s1 := make(map[int]bool)
	k := n
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
		b := nums[a[i]]
		if !checkGcd(s1, b) {
			k = i
			break
		}
		addDivs(s1, b)
	}
	out := bufio.NewWriter(os.Stdout)
	defer func() { out.Flush() }()

	if k == n {
		for i := 0; i < n; i++ {
			fmt.Fprintf(out, "%d ", a[i])
		}
		return
	}
	for {
		a[k]++
		b := nums[a[k]]
		if checkGcd(s1, b) {
			addDivs(s1, b)
			break
		}
	}
	pCount := 0
	for k++; k < n; k++ {
		for {
			if _, ok := s1[primes[pCount]]; !ok {
				a[k] = primes[pCount]
				pCount++
				break
			}
			pCount++
		}
	}
	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", a[i])
	}
}

package main

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

const (
	MaxN    = 1300000
	ArrSize = 100050
)

var n, m int

var nums map[int][]int
var primes []int
var a []int

func init() {
	var sieve [MaxN]bool
	var primesArr [ArrSize]int

	nums = make(map[int][]int)

	cnt := 0
	for i := 2; i < MaxN; i++ {
		if sieve[i] == false {
			primesArr[cnt] = i
			cnt++
			nums[i] = []int{i}
			for j := i + i; j < MaxN; j += i {
				sieve[j] = true
				if nums[j] == nil {
					nums[j] = []int{i}
				} else {
					nums[j] = append(nums[j], i)
				}
			}
		}
	}
	primes = primesArr[:cnt]
}

func checkGcd(s map[int]bool, b []int) bool {
	for j := 0; j < len(b); j++ {
		if s[b[j]] {
			return false
		}
	}
	return true
}

func addDivs(s map[int]bool, b []int) {
	for j := 0; j < len(b); j++ {
		s[b[j]] = true
	}
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	a = make([]int, n)
	s1 := make(map[int]bool)
	k := n
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
		b := nums[a[i]]
		if !checkGcd(s1, b) {
			k = i
			break
		}
		addDivs(s1, b)
	}
	out := bufio.NewWriter(os.Stdout)
	defer func() { out.Flush() }()
	if k == n {
		for i := 0; i < n; i++ {
			fmt.Fprintf(out, "%d ", a[i])
		}
		return
	}
	for {
		a[k]++
		b := nums[a[k]]
		if checkGcd(s1, b) {
			addDivs(s1, b)
			break
		}
	}
	pCount := 0
	for k++; k < n; k++ {
		for {
			if _, ok := s1[primes[pCount]]; !ok {
				a[k] = primes[pCount]
				break
			}
			pCount++
		}
	}
	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", a[i])
	}
}


Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size n × m cells, like this:Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.The key of this game is to find a cycle that contain dots of same color. Consider 4 blue dots on the picture forming a circle as an example. Formally, we call a sequence of dots d1, d2, ..., dk a cycle if and only if it meets the following condition:  These k dots are different: if i ≠ j then di is different from dj.  k is at least 4.  All dots belong to the same color.  For all 1 ≤ i ≤ k - 1: di and di + 1 are adjacent. Also, dk and d1 should also be adjacent. Cells x and y are called adjacent if they share an edge. Determine if there exists a cycle on the field.

The first line contains two integers n and m (2 ≤ n, m ≤ 50): the number of rows and columns of the board. Then n lines follow, each line contains a string consisting of m characters, expressing colors of dots in each line. Each character is an uppercase Latin letter.

Output "Yes" if there exists a cycle, and "No" otherwise.

7 6
AAAAAB
ABBBAB
ABAAAB
ABABBB
ABAAAB
ABBBAB
AAAAAB

NoteIn first sample test all 'A' form a cycle.In second sample there is no such cycle.The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red).

package main

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

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

var (
	visited [][]bool
	n, m int
	board []string
)

const (
	TOP = iota
	RIGHT = iota
	DOWN = iota
	LEFT = iota
)

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

	n, m = nextInt(), nextInt()
	visited = make([][]bool, n)
	board = make([]string, n)

	for i := range board {
		board[i] = next()
		visited[i] = make([]bool, m)
	}

	for i := range board {
		for j := range board[i] {
			if !visited[i][j] {
				visited[i][j] = true

				if (i+1 < n && board[i][j] == board[i+1][j] && !visited[i+1][j] && dfs(i+1, j, DOWN)) ||
				 (j+1 < m && board[i][j] == board[i][j+1] && !visited[i][j+1] && dfs(i, j+1, RIGHT)) {
					println("Yes")
					return
				}
			}
		}
	}

	println("No")
	return
}

func dfs(x, y, lastDirect int) bool {
	// println(x, y, lastDirect)

	switch {
	case lastDirect != DOWN && x-1 >= 0 && board[x][y] == board[x-1][y]:
		if visited[x-1][y] {
			return true
		} else {
			visited[x][y] = true
			return dfs(x-1, y, TOP)
		}
	case lastDirect != TOP && x+1 < n && board[x][y] == board[x+1][y]:
		if visited[x+1][y] {
			return true
		} else {
			visited[x][y] = true
			return dfs(x+1, y, DOWN)
		}
	case lastDirect != RIGHT && y-1 >= 0 && board[x][y] == board[x][y-1]:
		if visited[x][y-1] {
			return true
		} else {
			visited[x][y] = true
			return dfs(x, y-1, LEFT)
		}
	case lastDirect != LEFT && y+1 < m && board[x][y] == board[x][y+1]:
		if visited[x][y+1] {
			return true
		} else {
			visited[x][y] = true
			return dfs(x, y+1, RIGHT)
		}
	}

	return false
}

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

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

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

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

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

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

package main

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

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

var (
	visited [][]bool
	n, m int
	board []string
	dx = []int{0, 1, 0, -1}
	dy = []int{1, 0, -1, 0}
)

const (
	TOP = iota
	RIGHT = iota
	DOWN = iota
	LEFT = iota
)

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

	n, m = nextInt(), nextInt()
	visited = make([][]bool, n)
	board = make([]string, n)

	for i := range board {
		board[i] = next()
		visited[i] = make([]bool, m)
	}

	for i := range board {
		for j := range board[i] {
			if !visited[i][j] {
				// visited[i][j] = true

				// if (i+1 < n && board[i][j] == board[i+1][j] && !visited[i+1][j] && dfs(i+1, j, DOWN)) ||
				//  (j+1 < m && board[i][j] == board[i][j+1] && !visited[i][j+1] && dfs(i, j+1, RIGHT)) {
				// 	println("Yes")
				// 	return
				// }
				if dfs(i, j, i, j) {
					// printf("%d %d ", i, j)
					println("Yes")
					return
				}
			}
		}
	}

	println("No")
	return
}

func dfs(x, y, lastx, lasty int) bool {
	visited[x][y] = true
	// println(x, y, lastx, lasty)

	for i := 0; i < 4; i++ {
		newx, newy := x + dx[i], y + dy[i]

		// println("ok", newx, newy, lastx, lasty, x, y, dx[i], dy[i])
		// if x==0 && y==0 {
		// 	// println()

		// 	// if newx < n && newy	< m {
		// 	// 	println("ok", newx, newy, lastx, lasty, board[newx][newy], board[x][y])

		// 	// }
		// }
		if newx >= 0 && newx < n && newy >= 0 && newy < m && (newx != lastx || newy	!= lasty) && board[x][y] == board[newx][newy] {
			if visited[newx][newy] {
				return true
			}

			if dfs(newx, newy, x, y) {
				return true
			}
		}
	}

	return false
}

// func dfs(x, y, lastDirect int) bool {
// 	// println(x, y, lastDirect)

// 	switch {
// 	case lastDirect != DOWN && x-1 >= 0 && board[x][y] == board[x-1][y]:
// 		if visited[x-1][y] {
// 			return true
// 		} else {
// 			visited[x][y] = true
// 			return dfs(x-1, y, TOP)
// 		}
// 	case lastDirect != TOP && x+1 < n && board[x][y] == board[x+1][y]:
// 		if visited[x+1][y] {
// 			return true
// 		} else {
// 			visited[x][y] = true
// 			return dfs(x+1, y, DOWN)
// 		}
// 	case lastDirect != RIGHT && y-1 >= 0 && board[x][y] == board[x][y-1]:
// 		if visited[x][y-1] {
// 			return true
// 		} else {
// 			visited[x][y] = true
// 			return dfs(x, y-1, LEFT)
// 		}
// 	case lastDirect != LEFT && y+1 < m && board[x][y] == board[x][y+1]:
// 		if visited[x][y+1] {
// 			return true
// 		} else {
// 			visited[x][y] = true
// 			return dfs(x, y+1, RIGHT)
// 		}
// 	}

// 	return false
// }

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

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

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

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

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

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

package main

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

var Dif = [][]int{{-1, 0}, {1, 0}, {0, 1}, {0, -1}}
var grid []string
var vis [][]bool

func findCycle(y, x, py, px int) bool {
  vis[y][x] = true
  rows := len(grid)
  cols := len(grid[0])
  for d := 0; d < 4; d++ {
    ny := Dif[d][0] + y
    nx := Dif[d][1] + x
    if ny < 0 || ny >= rows || nx < 0 || nx >= cols {
      continue
    }
    if ny == py && nx == px {
      continue
    }
    if grid[y][x] != grid[ny][nx] {
      continue
    }
    if vis[ny][nx] {
      return true
    }
    if findCycle(ny, nx, y, x) {
      return true
    }
  }
  return false
}

func main() {
    stdin := bufio.NewReader(os.Stdin)
    var n, m int
    fmt.Fscan(stdin, &n, &m)

    grid = make([]string, n)
    for i := 0; i < n; i++ {
      fmt.Fscan(stdin, &grid[i])
    }

    vis = make([][]bool, n)
    for i := 0; i < n; i++ {
      vis[i] = make([]bool, m)
    }

    found := false
    for i := 0; !found && i < n; i++ {
      for j := 0; !found && j < m; j++ {
        if vis[i][j] {
          continue
        }
        found = findCycle(i, j, -1, -1)
      }
    }

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

package main

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

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

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

type Vertex struct {
  R, C int
}

var edges map[Vertex][]Vertex
var seen map[Vertex]int

func augment(u, v Vertex) {
  _, found := edges[u]
  if !found {
    edges[u] = []Vertex{ v }
  } else {
    edges[u] = append(edges[u], v)
  }
}

func seek(u Vertex, depth int) bool {
  //writer.WriteString(fmt.Sprintf("%d, %d at depth %d\n", u.R, u.C, depth))
  previous, found := seen[u]
  if found {
    return depth-previous > 3
  }
  seen[u] = depth
  neighbors, _ := edges[u]
  for _, v := range neighbors {
    if seek(v, depth+1) {
      return true
    }
  }
  return false
}

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

  n, m := getI(), getI()
  grid := make([]string, n)
  for r := range grid {
    grid[r] = getS()
  }
  edges = map[Vertex][]Vertex{}
  dr, dc := []int{ 0, 1 }, []int{ 1, 0 }
  for r := 0; r < n; r++ {
    for c := 0; c < m; c++ {
      for i := 0; i < 2; i++ {
        R, C := r+dr[i], c+dc[i]
        if R < n && C < m && grid[R][C] == grid[r][c] {
          u, v := Vertex{ r, c }, Vertex{ R, C }
          augment(u, v)
          augment(v, u)
        }
      }
    }
  }
  seen = map[Vertex]int{}
  for r := 0; r < n; r++ {
    for c := 0; c < m; c++ {
      u := Vertex{ r, c }
      if seek(u, 0) {
        writer.WriteString("Yes\n")
        return
      }
    }
  }
  writer.WriteString("No\n")
}

package main

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

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

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

func getLine() string {
	s, _ := reader.ReadString('\n')
	if strings.HasSuffix(s, "\r\n") {
		s = s[:len(s)-2]
	} else if strings.HasSuffix(s, "\n") {
		s = s[:len(s)-1]
	}
	return s
}
func getLine2Int() (n int) {
	scanf("%d\n", &n)
	return
}
func getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

func pcheck(i bool) {
	if i {
		printf("Yes\n")
	} else {
		printf("No\n")
	}
}

var debug = true

func see(a interface{}) {
	if debug {
		printf("DEBUG:%v\n", a)
	}
}

var n, m int

const maxindex = 55

var in [maxindex][maxindex]int
var f [maxindex][maxindex]bool
var dx = []int{0, 1, 0, -1}
var dy = []int{1, 0, -1, 0}
var si, sj int

func check(i, j int) bool {
	si, sj = i, j
	return seek(i, j, 1)
}

func seek(x, y, cnt int) bool {
	if !(x >= 0 && y >= 0 && x < n && y < m && !f[x][y] && in[x][y] == in[si][sj]) {
		return false
	}
	if cnt > 2 && (si == x+1 || si == x-1) && y == sj {
		return true
	}
	if cnt > 2 && (sj == y+1 || sj == y-1) && x == si {
		return true
	}
	f[x][y] = true
	for i := 0; i < 4; i++ {
		tx, ty := x+dx[i], y+dy[i]
		if seek(tx, ty, cnt+1) {
			return true
		}
	}
	f[x][y] = false
	return false
}

func main() {
	defer writer.Flush()

	n, m = getLine2Int2()
	for i := 0; i < n; i++ {
		s := getLine()
		for j := 0; j < m; j++ {
			in[i][j] = int(s[j])
		}
	}
	ok := false
	for i := 0; i < n && !ok; i++ {
		for j := 0; j < m && !ok; j++ {
			if check(i, j) {
				ok = true
			}
		}
	}
	pcheck(ok)
}

package main

import (
	"fmt"
)

var a [][]byte
var b [][]int
var n, m int

func main() {
	fmt.Scan(&n, &m)
	a = make([][]byte, n)
	b = make([][]int, n)

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

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if b[i][j] > 0 {
				continue
			}
			if checkLoops(i, j, 100) {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}

func checkLoops(i int, j int, weight int) bool {
	value := a[i][j]
	if b[i][j] > 0 && weight-b[i][j] > 3 {
		return true
	}

	b[i][j] = weight

	vars := []int{
		i - 1, j,
		i + 1, j,
		i, j - 1,
		i, j + 1,
	}
	for k := 0; k < len(vars); k += 2 {
		_i := vars[k]
		_j := vars[k+1]
		inBounds := _i >= 0 && _j >= 0 && _i < n && _j < m
		if inBounds && a[_i][_j] == value && b[_i][_j] != weight-1 {
			if checkLoops(_i, _j, weight+1) {
				return true
			}
		}
	}

	return false
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

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

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

var dx []int
var dy []int
var u[][] bool
var a[] string
var n, m int

func isOk(x, y int) bool {
    return x >= 0 && x < n && y >= 0 && y < m
}

func clearUsed() {
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            u[i][j] = false
        }
    }
}

func dfs(x, y, d, sx, sy int) bool {
    u[x][y] = true
    ret := false
    for i := 0; i < 4; i++ {
        nx := x + dx[i]
        ny := y + dy[i]
        if isOk(nx, ny) {
            if d >= 3 && nx == sx && ny == sy && a[nx][ny] == a[sx][sy] {
                return true
            }
            if !u[nx][ny] && a[x][y] == a[nx][ny] {
                ret = ret || dfs(nx, ny, d + 1, sx, sy)
            }

        }
    }
    return ret
}

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n = nextInt()
    m = nextInt()
    a = make([]string, n)
    u = make([][]bool, n)
    dx = []int{0, 0, 1, -1}
    dy = []int{1, -1, 0, 0}
    for i := 0; i < n; i++ {
        a[i] = next()
        u[i] = make([]bool, m)
    }

    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            clearUsed()
            if (dfs(i, j, 0, i, j)) {
                fmt.Fprintln(out, "Yes")
                return
            }
        }
    }

    fmt.Fprintln(out, "No")

}

package main

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

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

var (
	visited [][]bool
	n, m int
	board []string
)

const (
	TOP = iota
	RIGHT = iota
	DOWN = iota
	LEFT = iota
)

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

	n, m = nextInt(), nextInt()
	visited = make([][]bool, n)
	board = make([]string, n)

	for i := range board {
		board[i] = next()
		visited[i] = make([]bool, m)
	}

	for i := range board {
		for j := range board[i] {
			if !visited[i][j] {
				visited[i][j] = true

				if (i+1 < n && board[i][j] == board[i+1][j] && dfs(i+1, j, DOWN)) || (j+1 < m && board[i][j] == board[i][j+1] && dfs(i, j+1, RIGHT)) {
					println("Yes")
					return
				}
			}
		}
	}

	println("No")
	return
}

func dfs(x, y, lastDirect int) bool {
	// println(x, y, lastDirect)

	switch {
	case lastDirect != DOWN && x-1 >= 0 && board[x][y] == board[x-1][y]:
		if visited[x-1][y] {
			return true
		} else {
			visited[x][y] = true
			return dfs(x-1, y, TOP)
		}
	case lastDirect != TOP && x+1 < n && board[x][y] == board[x+1][y]:
		if visited[x+1][y] {
			return true
		} else {
			visited[x][y] = true
			return dfs(x+1, y, DOWN)
		}
	case lastDirect != RIGHT && y-1 >= 0 && board[x][y] == board[x][y-1]:
		if visited[x][y-1] {
			return true
		} else {
			visited[x][y] = true
			return dfs(x, y-1, LEFT)
		}
	case lastDirect != LEFT && y+1 < m && board[x][y] == board[x][y+1]:
		if visited[x][y+1] {
			return true
		} else {
			visited[x][y] = true
			return dfs(x, y+1, RIGHT)
		}
	}

	return false
}

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

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

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

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

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

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

package main

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

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

var (
	visited [][]bool
	n, m int
	board []string
)

const (
	TOP = iota
	RIGHT = iota
	DOWN = iota
	LEFT = iota
)

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

	n, m = nextInt(), nextInt()
	visited = make([][]bool, n)
	board = make([]string, n)

	for i := range board {
		board[i] = next()
		visited[i] = make([]bool, m)
	}

	for i := range board {
		for j := range board[i] {
			if !visited[i][j] {
				visited[i][j] = true

				if (i+1 < n && board[i][j] == board[i+1][j] && dfs(i+1, j, DOWN)) || (j+1 < m && board[i][j] == board[i][j+1] && dfs(i, j+1, RIGHT)) {
					println("Yes")
					return
				}
			}
		}
	}

	println("No")
	return
}

func dfs(x, y, lastDirect int) bool {
	// println(x, y, lastDirect)
	ok := make([]bool, 4)

	switch {
	case lastDirect != DOWN && x-1 >= 0 && board[x][y] == board[x-1][y]:
		if visited[x-1][y] {
			return true
		} else {
			visited[x][y] = true
			ok[0] = dfs(x-1, y, TOP)
		}
	case lastDirect != TOP && x+1 < n && board[x][y] == board[x+1][y]:
		if visited[x+1][y] {
			return true
		} else {
			visited[x][y] = true
			ok[1] = dfs(x+1, y, DOWN)
		}
	case lastDirect != RIGHT && y-1 >= 0 && board[x][y] == board[x][y-1]:
		if visited[x][y-1] {
			return true
		} else {
			visited[x][y] = true
			ok[2] = dfs(x, y-1, LEFT)
		}
	case lastDirect != LEFT && y+1 < m && board[x][y] == board[x][y+1]:
		if visited[x][y+1] {
			return true
		} else {
			visited[x][y] = true
			ok[3] = dfs(x, y+1, RIGHT)
		}
	}

	return ok[0] && ok[1] && ok[2] && ok[3]
}

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

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

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

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

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

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

package main

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

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

var (
	visited [][]bool
	n, m int
	board []string
	dx = []int{0, 1, 0, -1}
	dy = []int{1, 0, -1, 0}
)

const (
	TOP = iota
	RIGHT = iota
	DOWN = iota
	LEFT = iota
)

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

	n, m = nextInt(), nextInt()
	visited = make([][]bool, n)
	board = make([]string, n)

	for i := range board {
		board[i] = next()
		visited[i] = make([]bool, m)
	}

	for i := range board {
		for j := range board[i] {
			if !visited[i][j] {
				// visited[i][j] = true

				// if (i+1 < n && board[i][j] == board[i+1][j] && !visited[i+1][j] && dfs(i+1, j, DOWN)) ||
				//  (j+1 < m && board[i][j] == board[i][j+1] && !visited[i][j+1] && dfs(i, j+1, RIGHT)) {
				// 	println("Yes")
				// 	return
				// }
				if dfs(i, j, -1, -1) {
					// printf("%d %d ", i, j)
					println("Yes")
					return
				}
			}
		}
	}

	println("No")
	return
}

func dfs(x, y, lastx, lasty int) bool {
	visited[x][y] = true
	// println(x, y, lastx, lasty)

	for i := 0; i < 4; i++ {
		newx, newy := x + dx[i], y + dy[i]
		// if x==1 && y==3 {
		// 	println(newy >= 0 && newy < m && newx != lastx && newy	!= lasty, n, m)

		// 	if newx < n && newy	< m {
		// 		println("ok", newx, newy, lastx, lasty, board[newx][newy], board[x][y])

		// 	}
		// }
		if newx >= 0 && newx < n && newy >= 0 && newy < m && (newx != lastx || newy	!= lasty) && board[x][y] == board[newx][newy] {
			if visited[newx][newy] {
				return true
			}

			return dfs(newx, newy, x, y)
		}
	}

	return false
}

// func dfs(x, y, lastDirect int) bool {
// 	// println(x, y, lastDirect)

// 	switch {
// 	case lastDirect != DOWN && x-1 >= 0 && board[x][y] == board[x-1][y]:
// 		if visited[x-1][y] {
// 			return true
// 		} else {
// 			visited[x][y] = true
// 			return dfs(x-1, y, TOP)
// 		}
// 	case lastDirect != TOP && x+1 < n && board[x][y] == board[x+1][y]:
// 		if visited[x+1][y] {
// 			return true
// 		} else {
// 			visited[x][y] = true
// 			return dfs(x+1, y, DOWN)
// 		}
// 	case lastDirect != RIGHT && y-1 >= 0 && board[x][y] == board[x][y-1]:
// 		if visited[x][y-1] {
// 			return true
// 		} else {
// 			visited[x][y] = true
// 			return dfs(x, y-1, LEFT)
// 		}
// 	case lastDirect != LEFT && y+1 < m && board[x][y] == board[x][y+1]:
// 		if visited[x][y+1] {
// 			return true
// 		} else {
// 			visited[x][y] = true
// 			return dfs(x, y+1, RIGHT)
// 		}
// 	}

// 	return false
// }

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

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

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

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

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

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