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

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

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


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

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

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


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


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
}

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"
	"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"
	"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 (
    "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] && !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"
)

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


package main
import (
	"fmt"
	//"sort"
	"unicode/utf8"
	"bufio"
	"os"
)
func main() {
	var n,j int
	var p,a string
	fmt.Scan(&n,&p)
	ma := utf8.RuneCountInString(p)
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	for i:=0;i<n-1;i++ {
		input.Scan()
		a=input.Text()
		//fmt.Scan(&a)
		lena:=utf8.RuneCountInString(a)
		j=0
		for ;j<lena && a[j]==p[j]; {
			j++
		}
		if j<ma {
			ma=j
		}
		p=a
	}
	fmt.Println(ma)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var n int
    fmt.Scan(&n)
    s := make([]string,n)
    for i := 0; i < n; i++ {
        for scanner.Scan() { if scanner.Text() != "" { break } }
        s[i] = scanner.Text()
    }
    ans := 0
    for i := 0; i < len(s[0]); i++ {
        ok := true
        for j := 0; j < n; j++ {
            if s[j][i] != s[0][i] { ok = false; break }
        }
        if ok { ans++ } else { break }
    }
    fmt.Println(ans)
}

// 172A-mic
package main

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

func main() {
    var x, sum int
    fmt.Scan(&x)
    s := make([]string, x)
    z := bufio.NewReader(os.Stdin)
    for i := 0; i < x; i++ {
        fmt.Fscan(z, &s[i])
    }
    for i := 0; i < len(s[0]); i++ {
        c := 0
        for z := 1; z < x; z++ {
            if s[z][i] == s[0][i] {
                c++
            }
        }
        if c == x-1 {
            sum++
        } else {
            break
        }

    }
    fmt.Println(sum)
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/172/A

package main

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

func longestCommonPrefix(s1 string, s2 string) string {
	ptr1 := 0
	ptr2 := 0
	for ptr1 < len(s1) && ptr2 < len(s2) {
		if s1[ptr1] != s2[ptr2] {
			return s1[:ptr1]
		}
		ptr1 += 1
		ptr2 += 1
	}
	return s1
}

func Solve(n int, strings []string) int {
	prefix := strings[0]
	for i := 1; i < n; i++ {
		prefix = longestCommonPrefix(prefix, strings[i])
		if len(prefix) == 0 {
			return 0
		}
	}
	return len(prefix)
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	strings := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%s\n", &strings[i])
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, strings))
}

package main

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

func main() {
	var (
		n, i, j, maxj int32
		s             []string
		olv           *bufio.Reader
	)

	olv = bufio.NewReader(os.Stdin)

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

	//fmt.Println(s)
	//for i = 0; i < n; i++ {
	//	fmt.Print(len(s[i]), " ")

	//}
	//fmt.Println()

	maxj = int32(len(s[0]))
	for j = 0; j < maxj; {
		c := s[0][j]
		for i = 1; i < n && s[i][j] == c; i++ {
		}
		if i == n {
			j++
		} else {
			break
		}
	}
	fmt.Println(j)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var n int
    fmt.Scan(&n)
    s := make([]string,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        s[i] = scanner.Text()
    }
    ans := 0
    for i := 0; i < len(s[0]); i++ {
        ok := true
        for j := 0; j < n; j++ {
            if s[j][i] != s[0][i] { ok = false; break }
        }
        if ok { ans++ } else { break }
    }
    fmt.Println(ans)
}