You found a map of a weirdly shaped labyrinth. The map is a grid, consisting of $$$n$$$ rows and $$$n$$$ columns. The rows of the grid are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns of the grid are numbered from $$$1$$$ to $$$n$$$ from left to right.The labyrinth has $$$n$$$ layers. The first layer is the bottom left corner (cell $$$(1, 1)$$$). The second layer consists of all cells that are in the grid and adjacent to the first layer by a side or a corner. The third layer consists of all cells that are in the grid and adjacent to the second layer by a side or a corner. And so on. The labyrinth with $$$5$$$ layers, for example, is shaped as follows:   The layers are separated from one another with walls. However, there are doors in these walls.Each layer (except for layer $$$n$$$) has exactly two doors to the next layer. One door is placed on the top wall of the layer and another door is placed on the right wall of the layer. For each layer from $$$1$$$ to $$$n-1$$$ you are given positions of these two doors. The doors can be passed in both directions: either from layer $$$i$$$ to layer $$$i+1$$$ or from layer $$$i+1$$$ to layer $$$i$$$.If you are standing in some cell, you can move to an adjacent by a side cell if a wall doesn't block your move (e.g. you can't move to a cell in another layer if there is no door between the cells).Now you have $$$m$$$ queries of sort: what's the minimum number of moves one has to make to go from cell $$$(x_1, y_1)$$$ to cell $$$(x_2, y_2)$$$.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of layers in the labyrinth. The $$$i$$$-th of the next $$$n-1$$$ lines contains four integers $$$d_{1,x}, d_{1,y}, d_{2,x}$$$ and $$$d_{2,y}$$$ ($$$1 \le d_{1,x}, d_{1,y}, d_{2,x}, d_{2,y} \le n$$$) — the coordinates of the doors. Both cells are on the $$$i$$$-th layer. The first cell is adjacent to the top wall of the $$$i$$$-th layer by a side — that side is where the door is. The second cell is adjacent to the right wall of the $$$i$$$-th layer by a side — that side is where the door is. The next line contains a single integer $$$m$$$ ($$$1 \le m \le 2 \cdot 10^5$$$) — the number of queries. The $$$j$$$-th of the next $$$m$$$ lines contains four integers $$$x_1, y_1, x_2$$$ and $$$y_2$$$ ($$$1 \le x_1, y_1, x_2, y_2 \le n$$$) — the coordinates of the cells in the $$$j$$$-th query.

For each query, print a single integer — the minimum number of moves one has to make to go from cell $$$(x_1, y_1)$$$ to cell $$$(x_2, y_2)$$$.

NoteHere is the map of the labyrinth from the second example. The doors are marked red.

package main

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

const eof = 0
const inf int64 = 1 << 62

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

type Node struct {
	aa, ab, ba, bb int64
}

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

func Concat(a, b *Node) (c Node) {
	c.aa = min(a.aa+b.aa, a.ab+b.ba)
	c.ab = min(a.aa+b.ab, a.ab+b.bb)
	c.ba = min(a.ba+b.aa, a.bb+b.ba)
	c.bb = min(a.ba+b.ab, a.bb+b.bb)
	return
}

type Point struct {
	x, y int
}

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

func (p *Point) level() int {
	return max(p.x, p.y)
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func dis(p1, p2 *Point) int64 {
	return (int64)(abs(p1.x-p2.x) + abs(p1.y-p2.y))
}

func sol() {
	n := myio.ReadInt()
	a := make([]Point, n)
	b := make([]Point, n)
	for i := 1; i < n; i++ {
		a[i].x = myio.ReadInt() + 1
		a[i].y = myio.ReadInt()
		b[i].x = myio.ReadInt()
		b[i].y = myio.ReadInt() + 1
	}

	// init tree
	L := make([]int, n*4)
	R := make([]int, n*4)
	D := make([]Node, n*4)

	var buildTree func(int, int, int)

	buildTree = func(id, l, r int) {
		if l >= r {
			return
		}
		L[id], R[id] = l, r
		if l+1 == r {
			D[id] = Node{
				aa: dis(&a[l], &a[l+1]),
				ab: dis(&a[l], &b[l+1]),
				ba: dis(&b[l], &a[l+1]),
				bb: dis(&b[l], &b[l+1]),
			}
			return
		}
		m := l + (r-l+1)/2
		lc := id << 1
		rc := lc | 1
		buildTree(lc, l, m)
		buildTree(rc, m, r)
		D[id] = Concat(&D[lc], &D[rc])
	}

	buildTree(1, 1, n-1)

	var query func(int, int, int, *Node)
	query = func(id, l, r int, m *Node) {
		if l == r {
			return
		}
		if r <= L[id] || R[id] <= l {
			return
		}
		if L[id] >= l && R[id] <= r {
			*m = Concat(m, &D[id])
			return
		}
		query(id<<1, l, r, m)
		query((id<<1)|1, l, r, m)
	}

	q := myio.ReadInt()
	for ; q > 0; q-- {
		var p1, p2 Point
		p1.x = myio.ReadInt()
		p1.y = myio.ReadInt()
		p2.x = myio.ReadInt()
		p2.y = myio.ReadInt()
		l1, l2 := p1.level(), p2.level()
		if l1 == l2 {
			myio.Println(dis(&p1, &p2))
			continue
		}
		if l1 > l2 {
			p1, p2 = p2, p1
			l1, l2 = l2, l1
		}
		// l1->l2
		mat := Node{0, inf, inf, 0}
		query(1, l1, l2-1, &mat)
		var da, db int64
		da = dis(&p1, &a[l1])
		db = dis(&p1, &b[l1])
		da, db = min(da+mat.aa, db+mat.ba), min(db+mat.bb, da+mat.ab)
		ans := min(
			da+dis(&p2, &a[l2-1]),
			db+dis(&p2, &b[l2-1]),
		)
		myio.Println(ans)
	}
}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	// t = myio.ReadInt()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

const eof = 0
const inf int64 = 1 << 62

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

type Node struct {
	aa, ab, ba, bb int64
}

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

func Concat(a, b *Node) (c Node) {
	c.aa = min(a.aa+b.aa, a.ab+b.ba)
	c.ab = min(a.aa+b.ab, a.ab+b.bb)
	c.ba = min(a.ba+b.aa, a.bb+b.ba)
	c.bb = min(a.ba+b.ab, a.bb+b.bb)
	return
}

type Point struct {
	x, y int
}

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

func (p *Point) level() int {
	return max(p.x, p.y)
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func dis(p1, p2 Point) int64 {
	return (int64)(abs(p1.x-p2.x) + abs(p1.y-p2.y))
}

func sol() {
	n := myio.ReadInt()
	a := make([]Point, n)
	b := make([]Point, n)
	for i := 1; i < n; i++ {
		a[i].x = myio.ReadInt() + 1
		a[i].y = myio.ReadInt()
		b[i].x = myio.ReadInt()
		b[i].y = myio.ReadInt() + 1
	}

	// init tree
	L := make([]int, n*4)
	R := make([]int, n*4)
	D := make([]Node, n*4)

	var buildTree func(int, int, int)

	buildTree = func(id, l, r int) {
		if l >= r {
			return
		}
		L[id], R[id] = l, r
		if l+1 == r {
			a1, a2, b1, b2 := a[l], a[l+1], b[l], b[l+1]
			D[id] = Node{
				aa: dis(a1, a2),
				ab: dis(a1, b2),
				ba: dis(b1, a2),
				bb: dis(b1, b2),
			}
			return
		}
		m := l + (r-l+1)/2
		lc := id << 1
		rc := lc | 1
		buildTree(lc, l, m)
		buildTree(rc, m, r)
		D[id] = Concat(&D[lc], &D[rc])
	}

	buildTree(1, 1, n-1)

	var query func(int, int, int, *Node)
	query = func(id, l, r int, m *Node) {
		if l == r {
			return
		}
		if r <= L[id] || R[id] <= l {
			return
		}
		if L[id] >= l && R[id] <= r {
			*m = Concat(m, &D[id])
			return
		}
		query(id<<1, l, r, m)
		query((id<<1)|1, l, r, m)
	}

	q := myio.ReadInt()
	for ; q > 0; q-- {
		var p1, p2 Point
		p1.x = myio.ReadInt()
		p1.y = myio.ReadInt()
		p2.x = myio.ReadInt()
		p2.y = myio.ReadInt()
		l1, l2 := p1.level(), p2.level()
		if l1 == l2 {
			myio.Println(dis(p1, p2))
			continue
		}
		if l1 > l2 {
			p1, p2 = p2, p1
			l1, l2 = l2, l1
		}
		// l1->l2
		mat := Node{0, inf, inf, 0}
		query(1, l1, l2-1, &mat)
		var da, db int64
		da = dis(p1, Point{a[l1].x, a[l1].y})
		db = dis(p1, Point{b[l1].x, b[l1].y})
		da, db = min(da+mat.aa, db+mat.ba), min(db+mat.bb, da+mat.ab)
		ans := min(
			da+dis(p2, Point{a[l2-1].x, a[l2-1].y}),
			db+dis(p2, Point{b[l2-1].x, b[l2-1].y}),
		)
		myio.Println(ans)
	}
}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	// t = myio.ReadInt()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

const eof = 0
const inf int64 = 1 << 62

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

type Node struct {
	aa, ab, ba, bb int64
}

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

func Concat(a, b *Node) (c Node) {
	c.aa = min(a.aa+b.aa, a.ab+b.ba)
	c.ab = min(a.aa+b.ab, a.ab+b.bb)
	c.ba = min(a.ba+b.aa, a.bb+b.ba)
	c.bb = min(a.ba+b.ab, a.bb+b.bb)
	return
}

type Point struct {
	x, y int
}

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

func (p *Point) level() int {
	return max(p.x, p.y)
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func dis(p1, p2 Point) int64 {
	return (int64)(abs(p1.x-p2.x) + abs(p1.y-p2.y))
}

func sol() {
	n := myio.ReadInt()
	a := make([]Point, n)
	b := make([]Point, n)
	for i := 1; i < n; i++ {
		a[i].x = myio.ReadInt()
		a[i].y = myio.ReadInt()
		b[i].x = myio.ReadInt()
		b[i].y = myio.ReadInt()
	}

	// init tree
	L := make([]int, n*4)
	R := make([]int, n*4)
	D := make([]Node, n*4)

	var buildTree func(int, int, int)

	buildTree = func(id, l, r int) {
		if l >= r {
			return
		}
		L[id], R[id] = l, r
		if l+1 == r {
			a1, a2, b1, b2 := a[l], a[l+1], b[l], b[l+1]
			a1.x++
			a2.x++
			b1.y++
			b2.y++
			D[id] = Node{
				aa: dis(a1, a2),
				ab: dis(a1, b2),
				ba: dis(b1, a2),
				bb: dis(b1, b2),
			}
			return
		}
		m := l + (r-l+1)/2
		lc := id << 1
		rc := lc | 1
		buildTree(lc, l, m)
		buildTree(rc, m, r)
		D[id] = Concat(&D[lc], &D[rc])
	}

	buildTree(1, 1, n-1)

	var query func(int, int, int, *Node)
	query = func(id, l, r int, m *Node) {
		// fmt.Println("query", id, L[id], R[id], "->", l, r, *m)
		if l == r {
			return
		}
		if r <= L[id] || R[id] <= l {
			return
		}
		if L[id] >= l && R[id] <= r {
			*m = Concat(m, &D[id])
			return
		}
		query(id<<1, l, r, m)
		query((id<<1)|1, l, r, m)
	}

	q := myio.ReadInt()
	for ; q > 0; q-- {
		var p1, p2 Point
		p1.x = myio.ReadInt()
		p1.y = myio.ReadInt()
		p2.x = myio.ReadInt()
		p2.y = myio.ReadInt()
		l1, l2 := p1.level(), p2.level()
		if l1 == l2 {
			myio.Println(dis(p1, p2))
			continue
		}
		if l1 > l2 {
			p1, p2 = p2, p1
			l1, l2 = l2, l1
		}
		// l1->l2
		mat := Node{0, inf, inf, 0}
		query(1, l1, l2-1, &mat)
		var da, db int64
		// fmt.Println("l1=", l1, "l2=", l2, "mat=", mat, p1, p2)
		da = dis(p1, Point{a[l1].x + 1, a[l1].y})
		db = dis(p1, Point{b[l1].x, b[l1].y + 1})
		da, db = min(da+mat.aa, db+mat.ba), min(db+mat.bb, da+mat.ab)
		ans := min(
			da+dis(p2, Point{a[l2-1].x + 1, a[l2-1].y}),
			db+dis(p2, Point{b[l2-1].x, b[l2-1].y + 1}),
		)
		// myio.Println(mat)
		myio.Println(ans)
	}
}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	// t = myio.ReadInt()
	for ; t > 0; t-- {
		sol()
	}
}


Polycarp found the string $$$s$$$ and the permutation $$$p$$$. Their lengths turned out to be the same and equal to $$$n$$$.A permutation of $$$n$$$ elements — is an array of length $$$n$$$, in which every integer from $$$1$$$ to $$$n$$$ occurs exactly once. For example, $$$[1, 2, 3]$$$ and $$$[4, 3, 5, 1, 2]$$$ are permutations, but $$$[1, 2, 4]$$$, $$$[4, 3, 2, 1, 2]$$$ and $$$[0, 1, 2]$$$ are not.In one operation he can multiply $$$s$$$ by $$$p$$$, so he replaces $$$s$$$ with string $$$new$$$, in which for any $$$i$$$ from $$$1$$$ to $$$n$$$ it is true that $$$new_i = s_{p_i}$$$. For example, with $$$s=wmbe$$$ and $$$p = [3, 1, 4, 2]$$$, after operation the string will turn to $$$s=s_3 s_1 s_4 s_2=bwem$$$.Polycarp wondered after how many operations the string would become equal to its initial value for the first time. Since it may take too long, he asks for your help in this matter.It can be proved that the required number of operations always exists. It can be very large, so use a 64-bit integer type.

The first line of input contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases in input. The first line of each case contains single integer $$$n$$$ ($$$1 \le n \le 200$$$) — the length of string and permutation. The second line of each case contains a string $$$s$$$ of length $$$n$$$, containing lowercase Latin letters. The third line of each case contains $$$n$$$ integers — permutation $$$p$$$ ($$$1 \le p_i \le n$$$), all $$$p_i$$$ are different.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case of input. As an answer output single integer — the minimum number of operations, after which the string $$$s$$$ will become the same as it was before operations.

NoteIn the first sample operation doesn't change the string, so it will become the same as it was after $$$1$$$ operations.In the second sample the string will change as follows: $$$s$$$ = babaa $$$s$$$ = abaab $$$s$$$ = baaba $$$s$$$ = abbaa $$$s$$$ = baaab $$$s$$$ = ababa

package main

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		arr := make([]int, n)
		m := make([]int, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			m[arr[i]] = i
		}

		ans := int64(1)
		vis := make([]bool, n)
		for i := 0; i < n; i++ {
			if vis[i] {
				continue
			}
			var buf bytes.Buffer
			z := arr[i]
			buf.WriteByte(s[z-1])
			vis[i] = true
			for z != i+1 {
				z = arr[z-1]
				buf.WriteByte(s[z-1])
				vis[m[z]] = true
			}
			c := int64(1)
			s2 := buf.String()
			for i := 1; i < len(s2); i++ {
				var match int
				for j := 0; j < len(s2); j++ {
					if s2[(i+j)%len(s2)] != s2[j] {
						break
					}
					match++
				}
				if match == len(s2) {
					break
				}
				c++
			}
			ans = lcm(ans, c)
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		arr := make([]int, n)
		m := make([]int, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			m[arr[i]] = i
		}

		ans := int64(1)
		vis := make([]bool, n)
		for i := 0; i < n; i++ {
			if vis[i] {
				continue
			}
			var buf bytes.Buffer
			z := arr[i]
			buf.WriteByte(s[z-1])
			vis[i] = true
			for z != i+1 {
				z = arr[z-1]
				buf.WriteByte(s[z-1])
				vis[m[z]] = true
			}
			c := int64(1)
			orig := buf.String()
			s2 := string(orig[1:]) + string(orig[0])
			for s2 != orig {
				s2 = string(s2[1:]) + string(s2[0])
				c++
			}
			ans = lcm(ans, c)
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

var (
	p   [205]int
	vis [205]bool
	str []byte
)

func gcd(a, b int64) int64 {
	for b != 0 {
		a %= b
		if a == 0 {
			break
		}
		b %= a
	}
	return a + b
}

func lcm(a, b int64) int64 {
	return a / gcd(a, b) * b
}

func equal(a, b []byte) bool {
	for i := range a {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func repeat(base []byte, nums int) (res []byte) {
	res = make([]byte, 0, len(base)*nums)
	for i := 1; i <= nums; i++ {
		res = append(res, base...)
	}
	return
}

func minReStr(str []byte) int {
	n := len(str)
	res := 1<<31 - 1
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			t := n / i
			if equal(repeat(str[:i], t), str) && res > i {
				res = i
			}
			if equal(repeat(str[:t], i), str) && res > t {
				res = t
			}
		}
	}
	return res
}

func search(x int) (res []byte) {
	res = append(res, str[x])
	vis[x] = true
	for i := p[x]; i != x; i = p[i] {
		res = append(res, str[i])
		vis[i] = true
	}
	return res
}

func run(_r io.Reader, _w io.Writer) {
	const eof = 0
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, _n, buf := 0, 0, make([]byte, 1<<12)
	rc := func() byte {
		if _i == _n {
			_n, _ = _r.Read(buf)
			if _n == 0 {
				return eof
			}
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	rs := func(n int) []byte {
		b := rc()
		for ; b == '\n' || b == '\r'; b = rc() {
			if b == eof {
				return nil
			}
		}
		res := make([]byte, n+1)
		for i := 1; i <= n; i++ {
			res[i] = b
			b = rc()
		}
		return res
	}
	read := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
			if b == eof {
				return
			}
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	for t := read(); t > 0; t-- {
		n := read()
		str = rs(n)
		for i := 1; i <= n; i++ {
			p[i] = read()
			vis[i] = false
		}
		res := int64(1)
		for i := 1; i <= n; i++ {
			if !vis[i] {
				res = lcm(res, int64(minReStr(search(i))))
			}
		}
		Fprintln(out, res)
	}
}

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

package main

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

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		arr := make([]int, n)
		m := make([]int, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			m[arr[i]] = i
		}

		ans := 1
		vis := make([]bool, n)
		for i := 0; i < n; i++ {
			if vis[i] {
				continue
			}
			var buf bytes.Buffer
			z := arr[i]
			buf.WriteByte(s[z-1])
			vis[i] = true
			for z != i+1 {
				z = arr[z-1]
				buf.WriteByte(s[z-1])
				vis[m[z]] = true
			}
			c := 1
			orig := buf.String()
			s2 := string(orig[1:]) + string(orig[0])
			for s2 != orig {
				s2 = string(s2[1:]) + string(s2[0])
				c++
			}
			ans = lcm(ans, c)
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

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

		s2 := s
		b := make([]byte, n)
		g := make([]int, n)
		var c int
		x := 1
		for c < n {
			for i, v := range arr {
				b[i] = s2[v-1]
				if g[i] == 0 && b[i] == s[i] {
					c++
					g[i] = x
				}
			}
			s2 = string(b)
			x++
		}

		ans := 1
		for _, v := range g {
			ans = lcm(ans, v)
		}
		fmt.Println(ans)
	}
}

package main

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

var (
	p   [205]int
	vis [205]bool
	str []byte
)

func gcd(a, b int64) int64 {
	for b != 0 {
		a %= b
		if a == 0 {
			break
		}
		b %= a
	}
	return a + b
}

func lcm(a, b int64) int64 {
	return a / gcd(a, b) * b
}

func equal(a, b []byte) bool {
	for i := range a {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func repeat(base []byte, nums int) (res []byte) {
	res = make([]byte, 0, len(base)*nums)
	for i := 1; i <= nums; i++ {
		res = append(res, base...)
	}
	return
}

func minReStr(str []byte) int {
	n := len(str)
	res := 1<<31 - 1
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			t := n / i
			if equal(repeat(str[:i], t), str) && res > i {
				res = i
			}
			if equal(repeat(str[:t], i), str) && res > t {
				res = t
			}
		}
	}
	return res
}

func search(x int) (res []byte) {
	res = append(res, str[x])
	vis[x] = true
	for i := p[x]; i != x; i = p[i] {
		res = append(res, str[i])
		vis[i] = true
	}
	return res
}

func run(_r io.Reader, _w io.Writer) {
	const eof = 0
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, _n, buf := 0, 0, make([]byte, 1<<12)
	rc := func() byte {
		if _i == _n {
			_n, _ = _r.Read(buf)
			if _n == 0 {
				return eof
			}
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	rs := func(n int) []byte {
		b := rc()
		for ; b == '\n' || b == '\r'; b = rc() {
			if b == eof {
				return nil
			}
		}
		res := make([]byte, n+1)
		for i := 1; i <= n; i++ {
			res[i] = b
			b = rc()
		}
		return res
	}
	read := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
			if b == eof {
				return
			}
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	for t := read(); t > 0; t-- {
		n := read()
		str = rs(n)
		for i := 1; i <= n; i++ {
			p[i] = read()
		}
		res := int64(1)
		for i := 1; i <= n; i++ {
			if !vis[i] {
				res = lcm(res, int64(minReStr(search(i))))
			}
		}
		Fprintln(out, res)
	}
}

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

package main

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

var (
	p [205]int
)

func gcd(a, b int64) int64 {
	for b != 0 {
		a %= b
		if a == 0 {
			break
		}
		b %= a
	}
	return a + b
}

func lcm(a, b int64) int64 {
	return a / gcd(a, b) * b
}

func run(_r io.Reader, _w io.Writer) {
	const eof = 0
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, _n, buf := 0, 0, make([]byte, 1<<12)
	rc := func() byte {
		if _i == _n {
			_n, _ = _r.Read(buf)
			if _n == 0 {
				return eof
			}
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	rs := func(n int) []byte {
		b := rc()
		for ; b == '\n' || b == '\r'; b = rc() {
			if b == eof {
				return nil
			}
		}
		res := make([]byte, n+1)
		for i := 1; i <= n; i++ {
			res[i] = b
			b = rc()
		}
		return res
	}
	read := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
			if b == eof {
				return
			}
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	for t := read(); t > 0; t-- {
		n := read()
		str := rs(n)
		for i := 1; i <= n; i++ {
			p[i] = read()
		}
		tmp := p[1]
		cnt := int64(1)
		for str[tmp] != str[1] {
			tmp = p[tmp]
			cnt++
		}
		res := cnt
		for i := 2; i <= n; i++ {
			tmp := p[i]
			cnt := int64(1)
			for str[tmp] != str[i] {
				tmp = p[tmp]
				cnt++
			}
			res = lcm(res, cnt)
		}
		Fprintln(out, res)
	}
}

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


Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.Sofa A is standing to the left of sofa B if there exist two such cells a and b that xa < xb, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that ya < yb, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way. Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.The note also stated that there are cntl sofas to the left of Grandpa Maks's sofa, cntr — to the right, cntt — to the top and cntb — to the bottom.Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.

The first line contains one integer number d (1 ≤ d ≤ 105) — the number of sofas in the storehouse. The second line contains two integer numbers n, m (1 ≤ n, m ≤ 105) — the size of the storehouse. Next d lines contains four integer numbers x1, y1, x2, y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x1, y1) and (x2, y2) have common side, (x1, y1)  ≠  (x2, y2) and no cell is covered by more than one sofa. The last line contains four integer numbers cntl, cntr, cntt, cntb (0 ≤ cntl, cntr, cntt, cntb ≤ d - 1).

Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.

NoteLet's consider the second example.   The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).  The second sofa has cntl = 2, cntr = 1, cntt = 2 and cntb = 0.  The third sofa has cntl = 2, cntr = 1, cntt = 1 and cntb = 1. So the second one corresponds to the given conditions.In the third example   The first sofa has cntl = 1, cntr = 1, cntt = 0 and cntb = 1.  The second sofa has cntl = 1, cntr = 1, cntt = 1 and cntb = 0. And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.

package main

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

type SofaCoord struct {
	leftX int
	topY int
	rightX int
	bottomY int
	standing bool
	idx int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer([]byte{}, int(math.Pow(10,8)))
	scanner.Scan()

	d, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	nmStrArr := strings.Split(scanner.Text(), " ")
	n, _ := strconv.Atoi(nmStrArr[0])
	m, _ := strconv.Atoi(nmStrArr[1])

	sofaCoords := []SofaCoord{}
	leftCoordIdx := make([][]int, n+1)
	rightCoordIdx := make([][]int, n+1)
	leftCnt := make([]int, n+1)
	rightCnt := make([]int, n+1)
	topCoordIdx := make([][]int, m+1)
	botCoordIdx := make([][]int, m+1)
	topCnt := make([]int, m+1)
	botCnt := make([]int, m+1)
	for i := 0; i < d; i++ {
		scanner.Scan()
		coordStrArr := strings.Split(scanner.Text(), " ")
		x1, _ := strconv.Atoi(coordStrArr[0])
		y1, _ := strconv.Atoi(coordStrArr[1])
		x2, _ := strconv.Atoi(coordStrArr[2])
		y2, _ := strconv.Atoi(coordStrArr[3])
		leftX := x1; rightX := x2;
		if x2 < x1 || (x1 == x2 && y1 > y2){
			leftX = x2; rightX = x1
		}
		topY := y1; bottomY := y2;
		if y2 < y1 || (y1 == y2 && x2 < x1) {
			topY = y2; bottomY = y1;
		}
		standing := leftX == rightX
		sofaCoords = append(sofaCoords, SofaCoord{leftX,topY,rightX,bottomY, standing, i})
		leftCoordIdx[leftX] = append(leftCoordIdx[leftX], i)
		leftCnt[leftX] += 1
		rightCnt[rightX] += 1
		rightCoordIdx[rightX] = append(rightCoordIdx[rightX], i)
		topCoordIdx[topY] = append(topCoordIdx[topY], i)
		botCoordIdx[bottomY] = append(botCoordIdx[bottomY], i)
		topCnt[topY] += 1
		botCnt[bottomY] += 1
	}

	scanner.Scan()
	cntStrArr := strings.Split(scanner.Text(), " ")
	l, _ := strconv.Atoi(cntStrArr[0])
	r, _ := strconv.Atoi(cntStrArr[1])
	t, _ := strconv.Atoi(cntStrArr[2])
	b, _ := strconv.Atoi(cntStrArr[3])

	respIdx := map[int][]bool{}

	leftFound := false
	for i := 1; i <= n; i++ {
		leftCnt[i] += leftCnt[i-1]
		if leftCnt[i] > l {
			if leftCnt[i-1] == l {
				for _, j := range leftCoordIdx[i] {
					if sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						leftFound = true
					}
				}
			}
			if leftCnt[i] == l+1 {
				for _, j := range leftCoordIdx[i] {
					if !sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						leftFound = true
					}
				}
			}
			break
		}
	}
	if !leftFound {
		fmt.Println(-1)
		return
	}
	//fmt.Println(respIdx)

	rightFound := false
	for i := n; i > 0; i-- {
		if i < n {
			rightCnt[i] += rightCnt[i+1]
		}
		if rightCnt[i] > r {
			if i == n || (i < n && rightCnt[i+1] == r) {
				for _, j := range rightCoordIdx[i] {
					if sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						rightFound = true
					}
				}
			}
			if rightCnt[i] == r+1 {
				for _, j := range rightCoordIdx[i] {
					if !sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						rightFound = true
					}
				}
			}
			break
		}
	}
	if !rightFound {
		fmt.Println(-1)
		return
	}

	topFound := false
	for i := 1; i <= m; i++ {
		topCnt[i] += topCnt[i-1]
		if topCnt[i] > t {
			//fmt.Printf("i: %v, topCnt[i]: %v, topCnt[i-1]: %v, t: %v, topCoordIdx: %v\n", i, topCnt[i], topCnt[i-1], t, topCoordIdx)
			if topCnt[i-1] == t {
				for _, j := range topCoordIdx[i] {
					if !sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						topFound = true
					}
				}
			}
			if topCnt[i] == t+1 {
				for _, j := range topCoordIdx[i] {
					if sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						topFound = true
					}
				}
			}
			break
		}
	}
	if !topFound {
		fmt.Println(-1)
		return
	}

	botFound := false
	for i := m; i > 0; i-- {
		if i < m {
			botCnt[i] += botCnt[i+1]
		}
		if botCnt[i] > b {
			if i == m || (i < m && botCnt[i+1] == b) {
				for _, j := range botCoordIdx[i] {
					if !sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						botFound = true
					}
				}
			}
		}
		if botCnt[i] == b+1 {
			for _, j := range botCoordIdx[i] {
				if sofaCoords[j].standing {
					respIdx[j] = append(respIdx[j], true)
					botFound = true
				}
			}
		}
	}
	if !botFound {
		fmt.Println(-1)
		return
	}

	for idx := range respIdx {
		if len(respIdx[idx]) == 4 {
			fmt.Println(idx+1)
			return
		}
	}

	fmt.Println(-1)
	return

}

package main

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

type SofaCoord struct {
	leftX int
	topY int
	rightX int
	bottomY int
	standing bool
	idx int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer([]byte{}, int(math.Pow(10,8)))
	scanner.Scan()

	d, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	scanner.Text()
	//nmStrArr := strings.Split(scanner.Text(), " ")
	//n, _ := strconv.Atoi(nmStrArr[0])
	//m, _ := strconv.Atoi(nmStrArr[1])

	sofaCoords := []SofaCoord{}
	sortedCoords := []SofaCoord{}
	for i := 0; i < d; i++ {
		scanner.Scan()
		coordStrArr := strings.Split(scanner.Text(), " ")
		x1, _ := strconv.Atoi(coordStrArr[0])
		y1, _ := strconv.Atoi(coordStrArr[1])
		x2, _ := strconv.Atoi(coordStrArr[2])
		y2, _ := strconv.Atoi(coordStrArr[3])
		leftX := x1; rightX := x2;
		if x2 < x1 || (x1 == x2 && y1 > y2){
			leftX = x2; rightX = x1
		}
		topY := y1; bottomY := y2;
		if y2 < y1 || (y1 == y2 && x2 < x1) {
			topY = y2; bottomY = y1;
		}
		standing := leftX == rightX
		sofaCoords = append(sofaCoords, SofaCoord{leftX,topY,rightX,bottomY, standing, i})
		sortedCoords = append(sortedCoords, SofaCoord{leftX,topY,rightX,bottomY,standing, i})
	}

	scanner.Scan()
	cntStrArr := strings.Split(scanner.Text(), " ")
	l, _ := strconv.Atoi(cntStrArr[0])
	r, _ := strconv.Atoi(cntStrArr[1])
	t, _ := strconv.Atoi(cntStrArr[2])
	b, _ := strconv.Atoi(cntStrArr[3])

	respMap := make(map[int][]bool, d)
	for i := 0; i < d; i++ {
		respMap[i] = make([]bool, 4)
		for j := 0; j < 4; j++ {
			respMap[i][j] = false
		}
	}

	// sort by left
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].leftX < sortedCoords[j].leftX || (sortedCoords[i].leftX == sortedCoords[j].leftX && !sortedCoords[j].standing)
	})

	respMap[sortedCoords[l].idx][0] = true
	for i := l+1; i < d; i++ {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			if sortedCoords[i].standing == sortedCoords[l].standing {
				if !sortedCoords[l].standing {
					fmt.Println(-1)
					return
				}
				respMap[sortedCoords[i].idx][0] = true
			}
		} else {
			break
		}
	}
	for i := l-1; i >= 0; i-- {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			if sortedCoords[i].standing == sortedCoords[l].standing {
				respMap[sortedCoords[i].idx][0] = true
			}
		} else {
			break
		}
	}

	// sort by right
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].rightX > sortedCoords[j].rightX || (sortedCoords[i].rightX == sortedCoords[j].rightX && !sortedCoords[j].standing)
	})

	respMap[sortedCoords[r].idx][1] = true
	for i := r+1; i < d; i++ {
		if sortedCoords[i].rightX == sortedCoords[r].rightX {
			if sortedCoords[i].standing == sortedCoords[r].standing {
				if !sortedCoords[r].standing {
					fmt.Println(-1)
					return
				}
				respMap[sortedCoords[i].idx][1] = true
			}
		} else {
			break
		}
	}
	for i := r-1; i >= 0; i-- {
		if sortedCoords[i].rightX == sortedCoords[r].rightX {
			if sortedCoords[i].standing == sortedCoords[r].standing {
				respMap[sortedCoords[i].idx][1] = true
			}
		} else {
			break
		}
	}

	//sort by top
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].topY < sortedCoords[j].topY || (sortedCoords[i].topY == sortedCoords[j].topY && sortedCoords[j].standing)
	})

	respMap[sortedCoords[t].idx][2] = true
	for i := t+1; i < d; i++ {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			if sortedCoords[i].standing == sortedCoords[t].standing {
				if sortedCoords[t].standing {
					fmt.Println(-1)
					return
				}
				respMap[sortedCoords[i].idx][2] = true
			}
		} else {
			break
		}
	}
	for i := t-1; i >= 0; i-- {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			if sortedCoords[i].standing == sortedCoords[t].standing {
				respMap[sortedCoords[i].idx][2] = true
			}
		} else {
			break
		}
	}

	// sort by bottom
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].bottomY > sortedCoords[j].bottomY || (sortedCoords[i].bottomY == sortedCoords[j].bottomY && sortedCoords[j].standing)
	})
	respMap[sortedCoords[b].idx][3] = true
	for i := b+1; i < d; i++ {
		if sortedCoords[i].bottomY == sortedCoords[b].bottomY {
			if sortedCoords[i].standing == sortedCoords[b].standing {
				if sortedCoords[b].standing {
					fmt.Println(-1)
					return
				}
				respMap[sortedCoords[i].idx][3] = true
			}
		} else {
			break
		}
	}
	for i := b-1; i >= 0; i-- {
		if sortedCoords[i].bottomY == sortedCoords[b].bottomY {
			if sortedCoords[i].standing == sortedCoords[b].standing {
				respMap[sortedCoords[i].idx][3] = true
			}
		} else {
			break
		}
	}

	found := false
	for i := 0; i < d; i++ {
		if respMap[i][0] && respMap[i][1] && respMap[i][2] && respMap[i][3] {
			fmt.Println(i+1)
			found = true
			break
		}
	}
	if !found {
		fmt.Println(-1)
	}

}

package main

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

type SofaCoord struct {
	leftX int
	topY int
	rightX int
	bottomY int
	standing bool
	idx int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer([]byte{}, int(math.Pow(10,8)))
	scanner.Scan()

	d, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	scanner.Text()
	//nmStrArr := strings.Split(scanner.Text(), " ")
	//n, _ := strconv.Atoi(nmStrArr[0])
	//m, _ := strconv.Atoi(nmStrArr[1])

	sofaCoords := []SofaCoord{}
	sortedCoords := []SofaCoord{}
	for i := 0; i < d; i++ {
		scanner.Scan()
		coordStrArr := strings.Split(scanner.Text(), " ")
		x1, _ := strconv.Atoi(coordStrArr[0])
		y1, _ := strconv.Atoi(coordStrArr[1])
		x2, _ := strconv.Atoi(coordStrArr[2])
		y2, _ := strconv.Atoi(coordStrArr[3])
		leftX := x1; rightX := x2;
		if x2 < x1 || (x1 == x2 && y1 > y2){
			leftX = x2; rightX = x1
		}
		topY := y1; bottomY := y2;
		if y2 < y1 || (y1 == y2 && x2 < x1) {
			topY = y2; bottomY = y1;
		}
		standing := leftX == rightX
		sofaCoords = append(sofaCoords, SofaCoord{leftX,topY,rightX,bottomY, standing, i})
		sortedCoords = append(sortedCoords, SofaCoord{leftX,topY,rightX,bottomY,standing, i})
	}

	scanner.Scan()
	cntStrArr := strings.Split(scanner.Text(), " ")
	l, _ := strconv.Atoi(cntStrArr[0])
	r, _ := strconv.Atoi(cntStrArr[1])
	t, _ := strconv.Atoi(cntStrArr[2])
	b, _ := strconv.Atoi(cntStrArr[3])

	// sort by left
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].leftX < sortedCoords[j].leftX
	})

	respMap := make(map[int][]bool, d)
	for i := 0; i < d; i++ {
		respMap[i] = make([]bool, 4)
		for j := 0; j < 4; j++ {
			respMap[i][j] = false
		}
	}

	respMap[sortedCoords[l].idx][0] = true
	for i := l+1; i < d; i++ {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			respMap[sortedCoords[i].idx][0] = true
		} else {
			break
		}
	}
	for i := l-1; i >= 0; i-- {
		if !sortedCoords[i].standing && !sortedCoords[l].standing && sortedCoords[i].leftX == sortedCoords[l].leftX {
			respMap[sortedCoords[i].idx][0] = true
		} else {
			break
		}
	}

	// sort by right
	respMap[sortedCoords[d-r-1].idx][1] = true
	for i := d-r; i < d; i++ {
		if sortedCoords[i].rightX == sortedCoords[d-r-1].rightX {
			respMap[sortedCoords[i].idx][1] = true
		} else {
			break
		}
	}
	for i := d-r-2; i >= 0; i-- {
		if !sortedCoords[i].standing && !sortedCoords[d-r-1].standing && sortedCoords[i].rightX == sortedCoords[d-r-1].rightX {
			respMap[sortedCoords[i].idx][1] = true
		} else {
			break
		}
	}

	//sort by top
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].topY < sortedCoords[j].topY
	})

	respMap[sortedCoords[t].idx][2] = true
	for i := t+1; i < d; i++ {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			respMap[sortedCoords[i].idx][2] = true
		} else {
			break
		}
	}
	for i := t-1; i >= 0; i-- {
		if sortedCoords[i].standing && sortedCoords[t].standing && sortedCoords[i].topY == sortedCoords[t].topY {
			respMap[sortedCoords[i].idx][2] = true
		} else {
			break
		}
	}

	// sort by bottom
	respMap[sortedCoords[d-b-1].idx][3] = true
	for i := d-b; i < d; i++ {
		if sortedCoords[i].bottomY == sortedCoords[d-b-1].bottomY {
			respMap[sortedCoords[i].idx][3] = true
		} else {
			break
		}
	}
	for i := d-b-2; i >= 0; i-- {
		if sortedCoords[i].standing && sortedCoords[d-b-1].standing && sortedCoords[i].bottomY == sortedCoords[d-b-1].bottomY {
			respMap[sortedCoords[i].idx][3] = true
		} else {
			break
		}
	}

	found := false
	for i := 0; i < d; i++ {
		if respMap[i][0] && respMap[i][1] && respMap[i][2] && respMap[i][3] {
			fmt.Println(i+1)
			found = true
			break
		}
	}
	if !found {
		fmt.Println(-1)
	}

}

package main

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

type SofaCoord struct {
	leftX int
	topY int
	rightX int
	bottomY int
	idx int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer([]byte{}, int(math.Pow(10,8)))
	scanner.Scan()

	d, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	scanner.Text()
	//nmStrArr := strings.Split(scanner.Text(), " ")
	//n, _ := strconv.Atoi(nmStrArr[0])
	//m, _ := strconv.Atoi(nmStrArr[1])

	sofaCoords := []SofaCoord{}
	sortedCoords := []SofaCoord{}
	for i := 0; i < d; i++ {
		scanner.Scan()
		coordStrArr := strings.Split(scanner.Text(), " ")
		x1, _ := strconv.Atoi(coordStrArr[0])
		y1, _ := strconv.Atoi(coordStrArr[1])
		x2, _ := strconv.Atoi(coordStrArr[2])
		y2, _ := strconv.Atoi(coordStrArr[3])
		leftX := x1; rightX := x2;
		if x2 < x1 || (x1 == x2 && y1 > y2){
			leftX = x2; rightX = x1
		}
		topY := y1; bottomY := y2;
		if y2 < y1 || (y1 == y2 && x2 < x1) {
			topY = y2; bottomY = y1;
		}
		sofaCoords = append(sofaCoords, SofaCoord{leftX,topY,rightX,bottomY,i})
		sortedCoords = append(sortedCoords, SofaCoord{leftX,topY,rightX,bottomY,i})
	}

	scanner.Scan()
	cntStrArr := strings.Split(scanner.Text(), " ")
	l, _ := strconv.Atoi(cntStrArr[0])
	r, _ := strconv.Atoi(cntStrArr[1])
	t, _ := strconv.Atoi(cntStrArr[2])
	b, _ := strconv.Atoi(cntStrArr[3])

	// sort by left
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].leftX < sortedCoords[j].leftX
	})

	respMap := make(map[int][]bool, d)
	for i := 0; i < d; i++ {
		respMap[i] = make([]bool, 4)
		for j := 0; j < 4; j++ {
			respMap[i][j] = false
		}
	}

	respMap[sortedCoords[l].idx][0] = true
	for i := l+1; i < d; i++ {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			respMap[sortedCoords[i].idx][0] = true
		} else {
			break
		}
	}
	for i := l-1; i >= 0; i-- {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			respMap[sortedCoords[i].idx][0] = true
		} else {
			break
		}
	}

	// sort by right
	respMap[sortedCoords[d-r-1].idx][1] = true
	for i := d-r; i < d; i++ {
		if sortedCoords[i].rightX == sortedCoords[d-r-1].rightX {
			respMap[sortedCoords[i].idx][1] = true
		} else {
			break
		}
	}
	for i := d-r-2; i >= 0; i-- {
		if sortedCoords[i].rightX == sortedCoords[d-r-1].rightX {
			respMap[sortedCoords[i].idx][1] = true
		} else {
			break
		}
	}

	//sort by top
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].topY < sortedCoords[j].topY
	})

	respMap[sortedCoords[t].idx][2] = true
	for i := t+1; i < d; i++ {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			respMap[sortedCoords[i].idx][2] = true
		} else {
			break
		}
	}
	for i := t-1; i >= 0; i-- {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			respMap[sortedCoords[i].idx][2] = true
		} else {
			break
		}
	}

	// sort by bottom
	respMap[sortedCoords[d-b-1].idx][3] = true
	for i := d-b; i < d; i++ {
		if sortedCoords[i].bottomY == sortedCoords[d-b-1].bottomY {
			respMap[sortedCoords[i].idx][3] = true
		} else {
			break
		}
	}
	for i := d-b-2; i >= 0; i-- {
		if sortedCoords[i].bottomY == sortedCoords[d-b-1].bottomY {
			respMap[sortedCoords[i].idx][3] = true
		} else {
			break
		}
	}

	found := false
	for i := 0; i < d; i++ {
		if respMap[i][0] && respMap[i][1] && respMap[i][2] && respMap[i][3] {
			fmt.Println(i+1)
			found = true
			break
		}
	}
	if !found {
		fmt.Println(-1)
	}

}

package main

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

type SofaCoord struct {
	leftX int
	topY int
	rightX int
	bottomY int
	standing bool
	idx int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer([]byte{}, int(math.Pow(10,8)))
	scanner.Scan()

	d, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	scanner.Text()
	//nmStrArr := strings.Split(scanner.Text(), " ")
	//n, _ := strconv.Atoi(nmStrArr[0])
	//m, _ := strconv.Atoi(nmStrArr[1])

	sofaCoords := []SofaCoord{}
	sortedCoords := []SofaCoord{}
	for i := 0; i < d; i++ {
		scanner.Scan()
		coordStrArr := strings.Split(scanner.Text(), " ")
		x1, _ := strconv.Atoi(coordStrArr[0])
		y1, _ := strconv.Atoi(coordStrArr[1])
		x2, _ := strconv.Atoi(coordStrArr[2])
		y2, _ := strconv.Atoi(coordStrArr[3])
		leftX := x1; rightX := x2;
		if x2 < x1 || (x1 == x2 && y1 > y2){
			leftX = x2; rightX = x1
		}
		topY := y1; bottomY := y2;
		if y2 < y1 || (y1 == y2 && x2 < x1) {
			topY = y2; bottomY = y1;
		}
		standing := leftX == rightX
		sofaCoords = append(sofaCoords, SofaCoord{leftX,topY,rightX,bottomY, standing, i})
		sortedCoords = append(sortedCoords, SofaCoord{leftX,topY,rightX,bottomY,standing, i})
	}

	scanner.Scan()
	cntStrArr := strings.Split(scanner.Text(), " ")
	l, _ := strconv.Atoi(cntStrArr[0])
	r, _ := strconv.Atoi(cntStrArr[1])
	t, _ := strconv.Atoi(cntStrArr[2])
	b, _ := strconv.Atoi(cntStrArr[3])

	// sort by left
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].leftX < sortedCoords[j].leftX || (sortedCoords[i].leftX == sortedCoords[j].leftX && !sortedCoords[j].standing)
	})

	respMap := make(map[int][]bool, d)
	for i := 0; i < d; i++ {
		respMap[i] = make([]bool, 4)
		for j := 0; j < 4; j++ {
			respMap[i][j] = false
		}
	}

	respMap[sortedCoords[l].idx][0] = true
	for i := l+1; i < d; i++ {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			if sortedCoords[i].standing == sortedCoords[l].standing {
				respMap[sortedCoords[i].idx][0] = true
			}
		} else {
			break
		}
	}
	for i := l-1; i >= 0; i-- {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			if sortedCoords[i].standing == sortedCoords[l].standing {
				respMap[sortedCoords[i].idx][0] = true
			}
		} else {
			break
		}
	}

	// sort by right
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].rightX > sortedCoords[j].rightX || (sortedCoords[i].rightX == sortedCoords[j].rightX && !sortedCoords[j].standing)
	})

	respMap[sortedCoords[r].idx][1] = true
	for i := r+1; i < d; i++ {
		if sortedCoords[i].rightX == sortedCoords[r].rightX {
			if sortedCoords[i].standing == sortedCoords[r].standing {
				respMap[sortedCoords[i].idx][1] = true
			}
		} else {
			break
		}
	}
	for i := r-1; i >= 0; i-- {
		if sortedCoords[i].rightX == sortedCoords[r].rightX {
			if sortedCoords[i].standing == sortedCoords[r].standing {
				respMap[sortedCoords[i].idx][1] = true
			}
		} else {
			break
		}
	}

	//sort by top
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].topY < sortedCoords[j].topY || (sortedCoords[i].topY == sortedCoords[j].topY && sortedCoords[j].standing)
	})

	respMap[sortedCoords[t].idx][2] = true
	for i := t+1; i < d; i++ {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			if sortedCoords[i].standing == sortedCoords[t].standing {
				respMap[sortedCoords[i].idx][2] = true
			}
		} else {
			break
		}
	}
	for i := t-1; i >= 0; i-- {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			if sortedCoords[i].standing == sortedCoords[t].standing {
				respMap[sortedCoords[i].idx][2] = true
			}
		} else {
			break
		}
	}

	// sort by bottom
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].bottomY > sortedCoords[j].bottomY || (sortedCoords[i].bottomY == sortedCoords[j].bottomY && sortedCoords[j].standing)
	})
	respMap[sortedCoords[b].idx][3] = true
	for i := b+1; i < d; i++ {
		if sortedCoords[i].bottomY == sortedCoords[b].bottomY {
			if sortedCoords[i].standing == sortedCoords[b].standing {
				respMap[sortedCoords[i].idx][3] = true
			}
		} else {
			break
		}
	}
	for i := b-1; i >= 0; i-- {
		if sortedCoords[i].bottomY == sortedCoords[b].bottomY {
			if sortedCoords[i].standing == sortedCoords[b].standing {
				respMap[sortedCoords[i].idx][3] = true
			}
		} else {
			break
		}
	}

	found := false
	for i := 0; i < d; i++ {
		if respMap[i][0] && respMap[i][1] && respMap[i][2] && respMap[i][3] {
			fmt.Println(i+1)
			found = true
			break
		}
	}
	if !found {
		fmt.Println(-1)
	}

}


This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You may also refer to the guide on interactive problems: https://codeforces.com/blog/entry/45307.You are given a string $$$t$$$ consisting of $$$n$$$ lowercase Latin letters. This string was cyphered as follows: initially, the jury had a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. Then they applied a sequence of no more than $$$n$$$ (possibly zero) operations. $$$i$$$-th operation is denoted by two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i, b_i \le n$$$), and means swapping two elements of the string with indices $$$a_i$$$ and $$$b_i$$$. All operations were done in the order they were placed in the sequence. For example, if $$$s$$$ is xyz and $$$2$$$ following operations are performed: $$$a_1 = 1, b_1 = 2$$$; $$$a_2 = 2, b_2 = 3$$$, then after the first operation the current string is yxz, and after the second operation the current string is yzx, so $$$t$$$ is yzx.You are asked to restore the original string $$$s$$$. Unfortunately, you have no information about the operations used in the algorithm (you don't even know if there were any operations in the sequence). But you may run the same sequence of operations on any string you want, provided that it contains only lowercase Latin letters and its length is $$$n$$$, and get the resulting string after those operations.Can you guess the original string $$$s$$$ asking the testing system to run the sequence of swaps no more than $$$3$$$ times?The string $$$s$$$ and the sequence of swaps are fixed in each test; the interactor doesn't try to adapt the test to your solution.

Initially the testing system sends one string $$$t$$$, consisting of lowercase Latin letters ($$$1 \le |t| = n \le 10^4$$$).

To give the answer, your program should print one line $$$!$$$ $$$s$$$ with a line break in the end. After that, it should flush the output and terminate gracefully.

NoteIn the sample, the testcase described in the statement is used. The participant asks the first query with string baa, which is transformed to aab. The second query contains string aba, which is transformed to baa. The third query contains string aab, which is transformed to aba. The participant can deduce that the initial string $$$s$$$ was xyz.Note for hacking phase:To submit a test in hacking phase, you should provide it in the following format:The first line should contain the string $$$s$$$ you guess, consisting of $$$n \in [1, 10000]$$$ lowercase Latin letters.The second line should contain $$$k$$$ ($$$0 \le k \le n$$$) — the number of swap operations in the sequence.Then $$$k$$$ lines should follow, $$$i$$$-th of them should denote $$$i$$$-th operation with two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i, b_i \le n$$$).For example, the sample test would look like that:xyz21 22 3

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 main() {
	var input string
	// int('a') == 97, int('z') == 122
	scanf("%s\n", &input)
	n := len(input)
	const chunkSize = 3
	// small hack for lesser memory allocations
	tmp := make([]byte, chunkSize*n)
	var triplets [][]byte
	for i := 0; i < len(tmp); i += chunkSize {
		end := i + chunkSize
		triplets = append(triplets, tmp[i:end])
	}
	// now we need to generate unique triplets from 0 to n
	// O(n) solution
	req1, req2, req3 := make([]byte, n), make([]byte, n), make([]byte, n)
	for i := 0; i < n; i++ {
		req1[i] = byte('a' + i%26)
		req2[i] = byte('a' + (i/26)%26)
		req3[i] = byte('a' + ((i/26)/26)%26)
	}
	// printf("triplets: %+v\n", triplets)
	var ans1, ans2, ans3 string
	printf("? %v\n", string(req1))
	writer.Flush()
	scanf("%s\n", &ans1)
	printf("? %v\n", string(req2))
	writer.Flush()
	scanf("%s\n", &ans2)
	printf("? %v\n", string(req3))
	writer.Flush()
	scanf("%s\n", &ans3)
	// so we need to find (i, j) pairs with brute force
	swaps := make([]int, n)
	for i := 0; i < n; i++ {
		swaps[i] = (int(ans1[i]) - 'a') + (int(ans2[i])-'a')*26 + (int(ans3[i])-'a')*26*26
		// printf("swaps[%d] = %v\n", i, swaps[i])
	}
	// printf("sorted swaps: %+v\n", swaps)
	original := make([]byte, n)
	for i := range original {
		original[i] = 'a'
	}
	for i := 0; i < n; i++ {
		// original[i] = input[swaps[i]]
		original[swaps[i]] = input[i]
	}
	printf("! %v\n", string(original))
	writer.Flush()
}

type swap struct {
	i int
	j int
}

package main

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

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

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

func main() {
	var input string
	// int('a') == 97, int('z') == 122
	scanf("%s\n", &input)
	n := len(input)
	const chunkSize = 3
	// small hack for lesser memory allocations
	tmp := make([]byte, chunkSize*n)
	var triplets [][]byte
	for i := 0; i < len(tmp); i += chunkSize {
		end := i + chunkSize
		triplets = append(triplets, tmp[i:end])
	}
	// now we need to generate unique triplets from 0 to n
	// O(n) solution
	req1, req2, req3 := make([]byte, n), make([]byte, n), make([]byte, n)
	for i := 0; i < n; i++ {
		triplets[i][0], triplets[i][1], triplets[i][2] = byte(i%26), byte((i/26)%26), byte((i/26e2)%26)
		req1[i], req2[i], req3[i] = triplets[i][0]+97, triplets[i][1]+97, triplets[i][2]+97
	}
	// printf("triplets: %+v\n", triplets)
	var ans1, ans2, ans3 string
	printf("? %v\n", string(req1))
	writer.Flush()
	scanf("%s\n", &ans1)
	printf("? %v\n", string(req2))
	writer.Flush()
	scanf("%s\n", &ans2)
	printf("? %v\n", string(req3))
	writer.Flush()
	scanf("%s\n", &ans3)
	// so we need to find (i, j) pairs with brute force
	swaps := make([]swap, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if req1[i] == ans1[j] && req2[i] == ans2[j] && req3[i] == ans3[j] {
				// i, j is swap
				swap := swap{i, j}
				swaps = append(swaps, swap)
			}
		}
	}
	sort.Slice(swaps, func(i, j int) bool {
		if swaps[i].i == swaps[j].i {
			return swaps[i].j < swaps[j].j
		}
		return swaps[i].i < swaps[j].i
	})
	// printf("sorted swaps: %+v\n", swaps)
	original := make([]byte, n)
	for _, swap := range swaps {
		original[swap.i] = input[swap.j]
	}
	printf("! %v\n", string(original))
	writer.Flush()
}

type swap struct {
	i int
	j int
}

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 main() {
	var input string
	// int('a') == 97, int('z') == 122
	scanf("%s\n", &input)
	n := len(input)
	const chunkSize = 3
	// small hack for lesser memory allocations
	tmp := make([]byte, chunkSize*n)
	var triplets [][]byte
	for i := 0; i < len(tmp); i += chunkSize {
		end := i + chunkSize
		triplets = append(triplets, tmp[i:end])
	}
	// now we need to generate unique triplets from 0 to n
	// O(n) solution
	req1, req2, req3 := make([]byte, n), make([]byte, n), make([]byte, n)
	for i := 0; i < n; i++ {
		triplets[i][0], triplets[i][1], triplets[i][2] = byte(i%26), byte((i/26)%26), byte((i/26e2)%26)
		req1[i], req2[i], req3[i] = triplets[i][0]+97, triplets[i][1]+97, triplets[i][2]+97
	}
	// printf("triplets: %+v\n", triplets)
	var ans1, ans2, ans3 string
	printf("? %v\n", string(req1))
	writer.Flush()
	scanf("%s\n", &ans1)
	printf("? %v\n", string(req2))
	writer.Flush()
	scanf("%s\n", &ans2)
	printf("? %v\n", string(req3))
	writer.Flush()
	scanf("%s\n", &ans3)
	// so we need to find (i, j) pairs with brute force
	swaps := make([]byte, n)
	for i := 0; i < n; i++ {
		swaps[i] = (ans1[i] - 'a') + (ans2[i]-'a')*26 + (ans3[i]-'a')*26*26
	}
	// printf("sorted swaps: %+v\n", swaps)
	original := make([]byte, n)
	for i := 0; i < n; i++ {
		original[swaps[i]] = input[i]
	}
	printf("! %v\n", string(original))
	writer.Flush()
}

type swap struct {
	i int
	j int
}

package main

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

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

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

func main() {
	var input string
	// int('a') == 97, int('z') == 122
	scanf("%s\n", &input)
	n := len(input)
	const chunkSize = 3
	// small hack for lesser memory allocations
	tmp := make([]byte, chunkSize*n)
	var triplets [][]byte
	for i := 0; i < len(tmp); i += chunkSize {
		end := i + chunkSize
		triplets = append(triplets, tmp[i:end])
	}
	// now we need to generate unique triplets from 0 to n
	// O(n) solution
	req1, req2, req3 := make([]byte, n), make([]byte, n), make([]byte, n)
	for i := 0; i < n; i++ {
		triplets[i][0], triplets[i][1], triplets[i][2] = byte(i%26), byte((i/26)%26), byte((i/26e2)%26)
		req1[i], req2[i], req3[i] = triplets[i][0]+97, triplets[i][1]+97, triplets[i][2]+97
	}
	// printf("triplets: %+v\n", triplets)
	var ans1, ans2, ans3 string
	printf("? %v\n", string(req1))
	writer.Flush()
	scanf("%s\n", &ans1)
	printf("? %v\n", string(req2))
	writer.Flush()
	scanf("%s\n", &ans2)
	printf("? %v\n", string(req3))
	writer.Flush()
	scanf("%s\n", &ans3)
	// so we need to find (i, j) pairs with brute force
	swaps := make([]swap, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if req1[i] == ans1[j] && req2[i] == ans2[j] && req3[i] == ans3[j] {
				// i, j is swap
				swap := swap{i, j}
				swaps = append(swaps, swap)
			}
		}
	}
	sort.Slice(swaps, func(i, j int) bool {
		if swaps[i].i == swaps[j].i {
			return swaps[i].j < swaps[j].j
		}
		return swaps[i].i < swaps[j].i
	})
	// printf("sorted swaps: %+v\n", swaps)
	original := make([]byte, n)
	for _, swap := range swaps {
		original[swap.j] = input[swap.i]
	}
	printf("! %v\n", string(original))
	writer.Flush()
}

type swap struct {
	i int
	j int
}

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 main() {
	var input string
	// int('a') == 97, int('z') == 122
	scanf("%s\n", &input)
	n := len(input)
	const chunkSize = 3
	// small hack for lesser memory allocations
	tmp := make([]byte, chunkSize*n)
	var triplets [][]byte
	for i := 0; i < len(tmp); i += chunkSize {
		end := i + chunkSize
		triplets = append(triplets, tmp[i:end])
	}
	// now we need to generate unique triplets from 0 to n
	// O(n) solution
	req1, req2, req3 := make([]byte, n), make([]byte, n), make([]byte, n)
	for i := 0; i < n; i++ {
		req1[i] = byte('a' + i%26)
		req2[i] = byte('a' + (i/26)%26)
		req3[i] = byte('a' + ((i/26)/26)%26)
	}
	// printf("triplets: %+v\n", triplets)
	var ans1, ans2, ans3 string
	printf("? %v\n", string(req1))
	writer.Flush()
	scanf("%s\n", &ans1)
	printf("? %v\n", string(req2))
	writer.Flush()
	scanf("%s\n", &ans2)
	printf("? %v\n", string(req3))
	writer.Flush()
	scanf("%s\n", &ans3)
	// so we need to find (i, j) pairs with brute force
	swaps := make([]int64, n)
	for i := 0; i < n; i++ {
		swaps[i] = int64((ans1[i] - 'a') + (ans2[i]-'a')*26 + (ans3[i]-'a')*26*26)
		// printf("swaps[%d] = %v\n", i, swaps[i])
	}
	// printf("sorted swaps: %+v\n", swaps)
	original := make([]byte, n)
	for i := range original {
		original[i] = 'a'
	}
	for i := 0; i < n; i++ {
		original[i] = input[swaps[i]]
		// original[swaps[i]] = input[i]
	}
	printf("! %v\n", string(original))
	writer.Flush()
}

type swap struct {
	i int
	j int
}

package main

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

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

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

func main() {
	var input string
	// int('a') == 97, int('z') == 122
	scanf("%s\n", &input)
	n := len(input)
	const chunkSize = 3
	// small hack for lesser memory allocations
	tmp := make([]byte, chunkSize*n)
	var triplets [][]byte
	for i := 0; i < len(tmp); i += chunkSize {
		end := i + chunkSize
		triplets = append(triplets, tmp[i:end])
	}
	// now we need to generate unique triplets from 0 to n
	// O(n) solution
	req1, req2, req3 := make([]byte, n), make([]byte, n), make([]byte, n)
	for i := 0; i < n; i++ {
		triplets[i][0], triplets[i][1], triplets[i][2] = byte(i%26), byte((i/26)%26), byte((i/26e2)%26)
		req1[i], req2[i], req3[i] = triplets[i][0]+97, triplets[i][1]+97, triplets[i][2]+97
	}
	// printf("triplets: %+v\n", triplets)
	var ans1, ans2, ans3 string
	printf("? %v\n", string(req1))
	writer.Flush()
	scanf("%s\n", &ans1)
	printf("? %v\n", string(req2))
	writer.Flush()
	scanf("%s\n", &ans2)
	printf("? %v\n", string(req3))
	writer.Flush()
	scanf("%s\n", &ans3)
	// so we need to find (i, j) pairs with brute force
	swaps := make([]swap, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if req1[i] == ans1[j] && req2[i] == ans2[j] && req3[i] == ans3[j] {
				// i, j is swap
				swap := swap{i, j}
				swaps = append(swaps, swap)
			}
		}
	}
	sort.Slice(swaps, func(i, j int) bool {
		if swaps[i].i == swaps[j].i {
			return swaps[i].j < swaps[j].j
		}
		return swaps[i].i < swaps[j].i
	})
	// printf("sorted swaps: %+v\n", swaps)
	original := make([]byte, n)
	for _, swap := range swaps {
		original[swap.j] = input[swap.i]
	}
	printf("%v\n", string(original))
	writer.Flush()
}

type swap struct {
	i int
	j int
}

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 main() {
	var input string
	// int('a') == 97, int('z') == 122
	scanf("%s\n", &input)
	n := len(input)
	const chunkSize = 3
	// small hack for lesser memory allocations
	tmp := make([]byte, chunkSize*n)
	var triplets [][]byte
	for i := 0; i < len(tmp); i += chunkSize {
		end := i + chunkSize
		triplets = append(triplets, tmp[i:end])
	}
	// now we need to generate unique triplets from 0 to n
	// O(n) solution
	req1, req2, req3 := make([]byte, n), make([]byte, n), make([]byte, n)
	for i := 0; i < n; i++ {
		req1[i] = byte('a' + i%26)
		req2[i] = byte('a' + (i/26)%26)
		req3[i] = byte('a' + ((i/26)/26)%26)
	}
	// printf("triplets: %+v\n", triplets)
	var ans1, ans2, ans3 string
	printf("? %v\n", string(req1))
	writer.Flush()
	scanf("%s\n", &ans1)
	printf("? %v\n", string(req2))
	writer.Flush()
	scanf("%s\n", &ans2)
	printf("? %v\n", string(req3))
	writer.Flush()
	scanf("%s\n", &ans3)
	// so we need to find (i, j) pairs with brute force
	swaps := make([]byte, n)
	for i := 0; i < n; i++ {
		swaps[i] = (ans1[i] - 'a') + (ans2[i]-'a')*26 + (ans3[i]-'a')*26*26
		// printf("swaps[%d] = %v\n", i, swaps[i])
	}
	// printf("sorted swaps: %+v\n", swaps)
	original := make([]byte, n)
	for i := 0; i < n; i++ {
		original[i] = input[swaps[i]]
	}
	for i, val := range original {
		if val == 0 {
			original[i] = 'a'
		}
	}
	printf("! %v\n", string(original))
	writer.Flush()
}

type swap struct {
	i int
	j int
}

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 main() {
	var input string
	// int('a') == 97, int('z') == 122
	scanf("%s\n", &input)
	n := len(input)
	const chunkSize = 3
	// small hack for lesser memory allocations
	tmp := make([]byte, chunkSize*n)
	var triplets [][]byte
	for i := 0; i < len(tmp); i += chunkSize {
		end := i + chunkSize
		triplets = append(triplets, tmp[i:end])
	}
	// now we need to generate unique triplets from 0 to n
	// O(n) solution
	req1, req2, req3 := make([]byte, n), make([]byte, n), make([]byte, n)
	for i := 0; i < n; i++ {
		req1[i] = byte('a' + i%26)
		req2[i] = byte('a' + (i/26)%26)
		req3[i] = byte('a' + ((i/26)/26)%26)
	}
	// printf("triplets: %+v\n", triplets)
	var ans1, ans2, ans3 string
	printf("? %v\n", string(req1))
	writer.Flush()
	scanf("%s\n", &ans1)
	printf("? %v\n", string(req2))
	writer.Flush()
	scanf("%s\n", &ans2)
	printf("? %v\n", string(req3))
	writer.Flush()
	scanf("%s\n", &ans3)
	// so we need to find (i, j) pairs with brute force
	swaps := make([]byte, n)
	for i := 0; i < n; i++ {
		swaps[i] = (ans1[i] - 'a') + (ans2[i]-'a')*26 + (ans3[i]-'a')*26*26
		// printf("swaps[%d] = %v\n", i, swaps[i])
	}
	// printf("sorted swaps: %+v\n", swaps)
	original := make([]byte, n)
	for i := 0; i < n; i++ {
		// original[i] = input[swaps[i]]
		original[swaps[i]] = input[i]
	}
	for i, val := range original {
		if val == 0 {
			original[i] = 'a'
		}
	}
	printf("! %v\n", string(original))
	writer.Flush()
}

type swap struct {
	i int
	j int
}

package main

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

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

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

func main() {
	var input string
	// int('a') == 97, int('z') == 122
	scanf("%s\n", &input)
	n := len(input)
	const chunkSize = 3
	// small hack for lesser memory allocations
	tmp := make([]byte, chunkSize*n)
	var triplets [][]byte
	for i := 0; i < len(tmp); i += chunkSize {
		end := i + chunkSize
		triplets = append(triplets, tmp[i:end])
	}
	// now we need to generate unique triplets from 0 to n
	// O(n) solution
	req1, req2, req3 := make([]byte, n), make([]byte, n), make([]byte, n)
	for i := 0; i < n; i++ {
		triplets[i][0], triplets[i][1], triplets[i][2] = byte(i%26), byte((i/26)%26), byte((i/26e2)%26)
		req1[i], req2[i], req3[i] = triplets[i][0]+97, triplets[i][1]+97, triplets[i][2]+97
	}
	// printf("triplets: %+v\n", triplets)
	var ans1, ans2, ans3 string
	printf("? %v\n", string(req1))
	writer.Flush()
	scanf("%s\n", &ans1)
	printf("? %v\n", string(req2))
	writer.Flush()
	scanf("%s\n", &ans2)
	printf("? %v\n", string(req3))
	writer.Flush()
	scanf("%s\n", &ans3)
	// so we need to find (i, j) pairs with brute force
	swaps := make([]swap, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if req1[i] == ans1[j] && req2[i] == ans2[j] && req3[i] == ans3[j] {
				// i, j is swap
				swap := swap{i, j}
				swaps = append(swaps, swap)
			}
		}
	}
	sort.Slice(swaps, func(i, j int) bool {
		if swaps[i].i == swaps[j].i {
			return swaps[i].j < swaps[j].j
		}
		return swaps[i].i < swaps[j].i
	})
	// printf("sorted swaps: %+v\n", swaps)
	original := make([]byte, n)
	for _, swap := range swaps {
		original[swap.i] = input[swap.j]
	}
	for i, val := range original {
		if val == 0 {
			original[i] = input[i]
		}
	}
	printf("! %v\n", string(original))
	writer.Flush()
}

type swap struct {
	i int
	j int
}

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 main() {
	var input string
	// int('a') == 97, int('z') == 122
	scanf("%s\n", &input)
	n := len(input)
	const chunkSize = 3
	// small hack for lesser memory allocations
	tmp := make([]byte, chunkSize*n)
	var triplets [][]byte
	for i := 0; i < len(tmp); i += chunkSize {
		end := i + chunkSize
		triplets = append(triplets, tmp[i:end])
	}
	// now we need to generate unique triplets from 0 to n
	// O(n) solution
	req1, req2, req3 := make([]byte, n), make([]byte, n), make([]byte, n)
	for i := 0; i < n; i++ {
		req1[i] = byte('a' + i%26)
		req2[i] = byte('a' + (i/26)%26)
		req3[i] = byte('a' + ((i/26)/26)%26)
	}
	// printf("triplets: %+v\n", triplets)
	var ans1, ans2, ans3 string
	printf("? %v\n", string(req1))
	writer.Flush()
	scanf("%s\n", &ans1)
	printf("? %v\n", string(req2))
	writer.Flush()
	scanf("%s\n", &ans2)
	printf("? %v\n", string(req3))
	writer.Flush()
	scanf("%s\n", &ans3)
	// so we need to find (i, j) pairs with brute force
	swaps := make([]byte, n)
	for i := 0; i < n; i++ {
		swaps[i] = (ans1[i] - 'a') + (ans2[i]-'a')*26 + (ans3[i]-'a')*26*26
		printf("swaps[%d] = %v\n", i, swaps[i])
	}
	// printf("sorted swaps: %+v\n", swaps)
	original := make([]byte, n)
	for i := 0; i < n; i++ {
		original[i] = input[swaps[i]]
	}
	for i, val := range original {
		if val == 0 {
			original[i] = 'a'
		}
	}
	printf("! %v\n", string(original))
	writer.Flush()
}

type swap struct {
	i int
	j int
}

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 main() {
	var input string
	// int('a') == 97, int('z') == 122
	scanf("%s\n", &input)
	n := len(input)
	const chunkSize = 3
	// small hack for lesser memory allocations
	tmp := make([]byte, chunkSize*n)
	var triplets [][]byte
	for i := 0; i < len(tmp); i += chunkSize {
		end := i + chunkSize
		triplets = append(triplets, tmp[i:end])
	}
	// now we need to generate unique triplets from 0 to n
	// O(n) solution
	req1, req2, req3 := make([]byte, n), make([]byte, n), make([]byte, n)
	for i := 0; i < n; i++ {
		req1[i] = byte('a' + i%26)
		req2[i] = byte('a' + (i/26)%26)
		req3[i] = byte('a' + ((i/26)/26)%26)
	}
	// printf("triplets: %+v\n", triplets)
	var ans1, ans2, ans3 string
	printf("? %v\n", string(req1))
	writer.Flush()
	scanf("%s\n", &ans1)
	printf("? %v\n", string(req2))
	writer.Flush()
	scanf("%s\n", &ans2)
	printf("? %v\n", string(req3))
	writer.Flush()
	scanf("%s\n", &ans3)
	// so we need to find (i, j) pairs with brute force
	swaps := make([]int64, n)
	for i := 0; i < n; i++ {
		swaps[i] = int64((ans1[i] - 'a') + (ans2[i]-'a')*26 + (ans3[i]-'a')*26*26)
		// printf("swaps[%d] = %v\n", i, swaps[i])
	}
	// printf("sorted swaps: %+v\n", swaps)
	original := make([]byte, n)
	for i := range original {
		original[i] = 'a'
	}
	for i := 0; i < n; i++ {
		// original[i] = input[swaps[i]]
		original[swaps[i]] = input[i]
	}
	printf("! %v\n", string(original))
	writer.Flush()
}

type swap struct {
	i int
	j int
}


A tournament is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes u and v (u ≠ v) exists either an edge going from u to v, or an edge from v to u.You are given a tournament consisting of n vertexes. Your task is to find there a cycle of length three.

The first line contains an integer n (1 ≤ n ≤ 5000). Next n lines contain the adjacency matrix A of the graph (without spaces). Ai, j = 1 if the graph has an edge going from vertex i to vertex j, otherwise Ai, j = 0. Ai, j stands for the j-th character in the i-th line. It is guaranteed that the given graph is a tournament, that is, Ai, i = 0, Ai, j ≠ Aj, i (1 ≤ i, j ≤ n, i ≠ j).

Print three distinct vertexes of the graph a1, a2, a3 (1 ≤ ai ≤ n), such that Aa1, a2 = Aa2, a3 = Aa3, a1 = 1, or "-1", if a cycle whose length equals three does not exist.  If there are several solutions, print any of them.

package main

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

var a [5000]string
var n int
var visit [5000]bool
var stackPos [5000]int
var stack [5000]int
var loop []int

func dfs(x, top int) bool {
	visit[x] = true
	stackPos[x] = top
	stack[top] = x
	for i := 0;i < n;i ++ {
		if a[x][i] == '1' && visit[i] && stackPos[i] != -1 {
			// find a loop
			loop = stack[stackPos[i]: top + 1]
			return true
		} else if a[x][i] == '1' && !visit[i] {
			if dfs(i, top + 1) {
				return true
			}
		}
	}
	stackPos[x] = -1
	stack[top] = 0
	return false
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%s\n", &a[i])
		stackPos[i] = -1
	}
	for i := 0;i < n;i ++ {
		if !visit[i] {
			if dfs(i, 0) {
				break
			}
		}
	}
	if len(loop) == 0 {
		fmt.Printf("-1")
	} else {
		for {
			if len(loop) == 3 {
				fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
				break
			} else {
				if a[loop[2]][loop[0]] == '1' {
					fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
					break
				} else {
					loop[1] = loop[0]
					loop = loop[1:]
				}
			}
		}
	}
}

// Codeforces 117C XXX too slow, wrong approach
package main

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

// BitSet structure for efficiently saving array of nits
type BitSet struct {
    a []uint64
}

func (b *BitSet) setBit(i int) {
    idx := i/64
    o := uint(i % 64)
    bb := b.a[idx]
    bb = bb | (1<<o)
    b.a[idx] = bb
}

func (b *BitSet) clearBit(i int) {
    idx := i/64
    o := uint(i % 64)
    bb := b.a[idx]
    bb = bb & (^(1<<o))
    b.a[idx] = bb
}

func (b *BitSet) isSet(i int) bool {
    idx := i/64
    o := uint(i % 64)
    bb := b.a[idx]
    bSet := (bb & (1<<o)) != 0
    return bSet
}
func (b *BitSet) newBitSet(i int) {
    ln := i/64+1
    b.a = make([]uint64, ln)
}

var aa []BitSet
var u BitSet
// touched points
var tou BitSet
var curc []int
var n int

func findCycle(i int, lev int) int {
	//fmt.Println("findCycle, i,lev=",i,lev)
    curc[lev] = i
    u.setBit(i)
    tou.setBit(i)
    for j:=0; j<n; j++ {
        if aa[i].isSet(j) {
            if u.isSet(j) {
                curc[lev+1] = j
                curc[lev+2] = -1
	            //fmt.Println("foundCycle, j,lev=",j,lev)
                return (lev+1)
            }
            if tou.isSet(j) {
            	continue
            }
            ret := findCycle(j, lev+1)
            if ret>=0 {
                return ret
            }
        }
    }
    u.clearBit(i)
    return -1
}

func findThree() (int, int, int) {
    // find -1 and elem before this in curc
    last := -1
    ilast := -1
    bc := -1
    for i:=0; i<n+2; i++ {
        //fmt.Println("i,curc_i=",i,curc[i])
        if curc[i]==-1 {
            last = curc[i-1]
            ilast = i-1
            break
        }
    }
    //fmt.Println("last=", last)
    if last==-1 {
        panic("nor last")
    }
    for i:=ilast-1; i>=0; i-- {
        if curc[i]==last {
            bc = i
        }
    }
    //fmt.Println("last,bc=", last, bc)
    c := curc[bc]
    for i:=bc; i<n; i++ {
        a := curc[i]
        b := curc[i+1]
        if aa[b].isSet(c) {
            return a,b,c
        }
    }
    panic("cannot find a,b,c")
}

func main() {
	// reading n
	in := bufio.NewReader(os.Stdin)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		return
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	n, err = strconv.Atoi(ss[0])
	if err != nil {
		fmt.Println("n atoi failure", err)
		return
	}
    // reading bit set matrix a
    aa = make([]BitSet, n)
    curc = make([]int, n+2)
    u.newBitSet(n)
    tou.newBitSet(n)
	for i:=0; i<n; i++ {
        s, err = in.ReadString('\n')
        if err != nil {
            fmt.Println("read failure", err)
            return
        }
        aa[i].newBitSet(n)
 		for j:=0; j<n; j++ {
            c := s[j]
            if c=='1' {
                aa[i].setBit(j)
            }
        }
	}
	//fmt.Println("Cycles read data passed")
    // looking for cycles
    for i:=0; i<n; i++ {
        if !tou.isSet(i) {
        	//fmt.Println("look for cycles from", i)
        	if findCycle(i,0) >= 0 {
        		a,b,c := findThree()
	            fmt.Printf("%d %d %d\n", a+1,b+1,c+1)
	            return
        	}
        }
    }

	// print result
	fmt.Println("-1")
}

package main

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

var a [5000]string
var n int
var visit [5000]bool
var stackPos [5000]int
var stack [5000]int
var loop []int

func dfs(x, top int) bool {
	visit[x] = true
	stackPos[x] = top
	stack[top] = x
	for i := 0;i < n;i ++ {
		if a[x][i] == '1' && visit[i] && stackPos[i] != -1 {
			// find a loop
			loop = stack[stackPos[i]: (top - stackPos[i] + 1)]
			return true
		} else if a[x][i] == '1' && !visit[i] {
			if dfs(i, top + 1) {
				return true
			}
		}
	}
	stackPos[x] = -1
	return false
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%s\n", &a[i])
		stackPos[i] = -1
	}
	for i := 0;i < n;i ++ {
		if !visit[i] {
			if dfs(i, 0) {
				break
			}
		}
	}
	if len(loop) == 0 {
		fmt.Printf("-1")
	} else {
		for i := 0;i < len(loop) - 1;i ++ {
			if a[loop[i]][loop[i + 1]] != '1' {
				fmt.Printf("crashed!\n")
			}
		}
		if a[loop[len(loop) - 1]][loop[0]] != '1' {
			fmt.Printf("crashed!\n")
		}
		for {
			if len(loop) == 3 {
				fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
				break
			} else {
				if a[loop[2]][loop[0]] == '1' {
					fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
					break
				} else {
					loop[1] = loop[0]
					loop = loop[1:]
				}
			}
		}
	}
}

package main

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

var a [5000]string
var n int
var visit [5000]bool
var stackPos [5000]int
var stack [5000]int
var loop []int

func dfs(x, top int) bool {
	visit[x] = true
	stackPos[x] = top
	stack[top] = x
	for i := 0;i < n;i ++ {
		if a[x][i] == '1' && visit[i] && stackPos[i] != -1 {
			// find a loop
			loop = stack[stackPos[i]: (top - stackPos[i] + 1)]
			return true
		} else if a[x][i] == '1' && !visit[i] {
			if dfs(i, top + 1) {
				return true
			}
		}
	}
	stackPos[x] = -1
	return false
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%s\n", &a[i])
		stackPos[i] = -1
	}
	for i := 0;i < n;i ++ {
		if !visit[i] {
			if dfs(i, 0) {
				break
			}
		}
	}
	if len(loop) == 0 {
		fmt.Printf("-1")
	} else {
		for {
			if len(loop) == 3 {
				fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
				break
			} else {
				if a[loop[1]][loop[len(loop) - 1]] == '1' {
					fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[len(loop) - 1] + 1)
					break
				} else {
					loop = loop[1:]
				}
			}
		}
	}
}

package main

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

var a [5000]string
var n int
var visit [5000]bool
var stackPos [5000]int
var stack [5000]int
var loop []int

func dfs(x, top int) bool {
	visit[x] = true
	stackPos[x] = top
	stack[top] = x
	for i := 0;i < n;i ++ {
		if a[x][i] == '1' && visit[i] && stackPos[i] != -1 {
			// find a loop
			loop = stack[stackPos[i]: (top - stackPos[i] + 1)]
			return true
		} else if a[x][i] == '1' && !visit[i] {
			if dfs(i, top + 1) {
				return true
			}
		}
	}
	stackPos[x] = -1
	return false
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%s\n", &a[i])
		stackPos[i] = -1
	}
	for i := 0;i < n;i ++ {
		if !visit[i] {
			if dfs(i, 0) {
				break
			}
		}
	}
	if len(loop) == 0 {
		fmt.Printf("-1")
	} else {
		for {
			if len(loop) == 3 {
				fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
				break
			} else {
				if a[loop[2]][loop[0]] == '1' {
					fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
					break
				} else {
					loop[1] = loop[0]
					loop = loop[1:]
				}
			}
		}
	}
}

package main

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

var a [5000]string
var n int
var visit [5000]bool
var stackPos [5000]int
var stack [5000]int
var loop []int

func dfs(x, top int) bool {
	visit[x] = true
	stackPos[x] = top
	stack[top] = x
	for i := 0;i < n;i ++ {
		if a[x][i] == '1' && visit[i] && stackPos[i] != -1 {
			// find a loop
			loop = stack[stackPos[i]: (top - stackPos[i] + 1)]
			return true
		} else if a[x][i] == '1' && !visit[i] {
			if dfs(i, top + 1) {
				return true
			}
		}
	}
	stackPos[x] = -1
	stack[top] = 0
	return false
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%s\n", &a[i])
		stackPos[i] = -1
	}
	for i := 0;i < n;i ++ {
		if !visit[i] {
			if dfs(i, 0) {
				break
			}
		}
	}
	if len(loop) == 0 {
		fmt.Printf("-1")
	} else {
		for i := 0;i < len(loop) - 1;i ++ {
			if a[loop[i]][loop[i + 1]] != '1' {
				fmt.Printf("crashed A!\n")
			}
		}
		if a[loop[len(loop) - 1]][loop[0]] != '1' {
			fmt.Printf("crashed B!\n")
		}
		for {
			if len(loop) == 3 {
				fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
				break
			} else {
				if a[loop[2]][loop[0]] == '1' {
					fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
					break
				} else {
					loop[1] = loop[0]
					loop = loop[1:]
				}
			}
		}
	}
}