package main

//Attention!!!
//Fscan(in,&xx),Fprintln(out,xx)
import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

type A []int

func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t int
	Fscan(in, &t)
	for ; t != 0; t-- {
		var (
			x    int64
			n, k int
			s    string
		)
		Fscan(in, &n, &k, &x)
		Fscan(in, &s)
		p := make([]int64, n+5)
		c := make([]int64, n+5)
		x--
		for i := n - 1; i >= 0; i-- {
			cnt := 0
			for i >= 0 && s[i] == '*' {
				i--
				cnt += k
			}
			p[i+1] = int64(cnt + 1)
		}
		for i := n - 1; i >= 0; i-- {
			if p[i] != 0 {
				c[i] = x % p[i]
				x /= p[i]
			}
		}
		for i := 0; i <= n-1; i++ {
			if s[i] == 'a' {
				Fprintf(out, "%c", 'a')
			} else {
				for ; c[i] != 0; c[i]-- {
					Fprintf(out, "%c", 'b')
				}
			}
		}
		Fprintln(out)
	}

}
func main() { solve(os.Stdin, os.Stdout) }
func min(a int, b int) int {
	if a <= b {
		return a
	}
	return b
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n, k, x int64
	scan(&n, &k, &x)
	x--
	var s string
	scan(&s)
	var cnt = make([]int64, 0)
	for i := 0; i < len(s); {
		if s[i] != '*' {
			i++
			continue
		}
		j := i
		for ; j < len(s) && s[j] == '*'; j++ {
		}
		cnt = append(cnt, k*int64(j-i)+1)
		i = j
	}
	for i := len(cnt) - 1; i >= 0; i-- {
		x, cnt[i] = x/cnt[i], x-(x/cnt[i])*cnt[i]
	}
	for i, p := 0, 0; i < len(s); {
		if s[i] != '*' {
			i++
			printf("a")
			continue
		}
		j := i
		for ; j < len(s) && s[j] == '*'; j++ {
		}
		printf(strings.Repeat("b", int(cnt[p])))
		p++
		i = j
	}
	printf("\n")
}

package main

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

var n, k, x int64

var s string

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n, &k, &x)

		fmt.Fscan(r, &s)

		a := solve()

		fmt.Println(a)
	}
}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() string {

	var arr []int

	var cnt int

	for j := 0; j < len(s); j++ {
		if s[j] == '*' {
			cnt++
		} else {
			if cnt != 0 {
				arr = append(arr, cnt)
				cnt = 0
			}

		}
	}
	if cnt != 0 {
		arr = append(arr, cnt)
	}

	var bts bytes.Buffer

	var prod = big.NewInt(1)

	b := make([]int, len(arr))

	X := big.NewInt(x)

	var j int
	for j = len(arr) - 1; j >= 0; j-- {
		p := int64(arr[j]) * k + 1
		prod = prod.Mul(prod, big.NewInt(p))

		if prod.Cmp(X) > 0 {
			break
		}
	}

	if j == - 1 {
		j = 0
	}

	for i := j; i < len(arr); i++ {
		p := int64(arr[i]) * k + 1
		prod = prod.Div(prod, big.NewInt(p))

		var q int64
		for q = 1; q <= p; q++ {

			temp := big.NewInt(1)
			temp = temp.Mul(prod,  big.NewInt(q))

			if temp.Cmp(X) > 0 || temp.Cmp(X) == 0 {

				q--
				b[i] = int(q)

				temp := big.NewInt(1)
				temp = temp.Mul(prod, big.NewInt(q))

				X = X.Sub(X, temp)

				break
			}
		}
	}

	var prev byte = 'c'
	cnt = 0

	for i := 0; i < len(s); i++ {
		if s[i] == 'a' {
			bts.WriteByte('a')

		} else {
			if prev != '*' {
				for j := 0; j < b[cnt]; j++ {
					bts.WriteByte('b')
				}

				cnt++
			}
		}

		prev = s[i]
	}

	return bts.String()
}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

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

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

	var T, n int
	var k, x int64
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k, &x, &s)
		if x == 1 {
			Fprintln(out, strings.ReplaceAll(s, "*", ""))
			continue
		}
		x--
		d := []int{}
		for i, c := n-1, 0; i >= 0; i-- {
			if s[i] == '*' {
				c++
				if i == 0 || s[i-1] != '*' {
					k := k*int64(c) + 1
					d = append(d, int(x%k))
					x /= k
					c = 0
				}
			}
		}
		ans := []byte{}
		j := len(d) - 1
		for i, b := range s {
			if b == 'a' {
				ans = append(ans, 'a')
			} else if i == n-1 || s[i+1] == 'a' {
				ans = append(ans, bytes.Repeat([]byte{'b'}, d[j])...)
				j--
			}
		}
		Fprintf(out, "%s\n", ans)
	}
}

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

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n, k, x int64
	scan(&n, &k, &x)
	x--
	var s string
	scan(&s)
	var cnt = make([]int64, 0)
	for i := 0; i < len(s); {
		if s[i] != '*' {
			i++
			continue
		}
		j := i
		for ; j < len(s) && s[j] == '*'; j++ {
		}
		cnt = append(cnt, k*int64(j-i)+1)
		i = j
	}
	for i := len(cnt) - 1; i >= 0; i-- {
		x, cnt[i] = x/cnt[i], x%cnt[i]
	}
	for i, p := 0, 0; i < len(s); {
		if s[i] != '*' {
			i++
			printf("a")
			continue
		}
		j := i
		for ; j < len(s) && s[j] == '*'; j++ {
		}
		printf(strings.Repeat("b", int(cnt[p])))
		p++
		i = j
	}
	printf("\n")
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n, k, x int64
	scan(&n, &k, &x)
	var s string
	scan(&s)
	var gs = make([]int64, 0)
	for i := 0; i < len(s); {
		if s[i] != '*' {
			i++
			continue
		}
		j := i
		for ; j < len(s) && s[j] == '*'; j++ {
		}
		gs = append(gs, k*int64(j-i))
		i = j
	}
	var (
		cntgs  = make([]int64, len(gs))
		create func(ifrom int, num int64)
	)
	create = func(ifrom int, num int64) {
		if ifrom == -1 {
			return
		}
		y := (num + gs[ifrom]) / (gs[ifrom] + 1)
		cntgs[ifrom] = (num) / y
		create(ifrom-1, y)
	}
	create(len(gs)-1, x)
	var ans = []string{}
	for i, i1 := 0, 0; i < len(s); {
		if s[i] != '*' {
			i++
			ans = append(ans, "a")
			continue
		}
		j := i
		for ; j < len(s) && s[j] == '*'; j++ {
		}
		ans = append(ans, strings.Repeat("b", int(cntgs[i1])-1))
		i1++
		i = j
	}
	printf("%v\n", strings.Join(ans, ""))
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n, k, x int64
	scan(&n, &k, &x)
	var s string
	scan(&s)
	var gs = make([]int64, 0)
	for i := 0; i < len(s); {
		if s[i] != '*' {
			i++
			continue
		}
		j := i
		for ; j < len(s) && s[j] == '*'; j++ {
		}
		gs = append(gs, k*int64(j-i))
		i = j
	}
	var (
		cntgs  = make([]int64, len(gs))
		create func(ifrom int, num int64)
	)
	create = func(ifrom int, num int64) {
		if ifrom == -1 {
			return
		}
		y := (num + gs[ifrom]) / (gs[ifrom] + 1)
		cntgs[ifrom] = (num + y - 1) / y
		create(ifrom-1, y)
	}
	create(len(gs)-1, x)
	var ans = []string{}
	for i, i1 := 0, 0; i < len(s); {
		if s[i] != '*' {
			i++
			ans = append(ans, "a")
			continue
		}
		j := i
		for ; j < len(s) && s[j] == '*'; j++ {
		}
		ans = append(ans, strings.Repeat("b", int(cntgs[i1])-1))
		i1++
		i = j
	}
	printf("%v\n", strings.Join(ans, ""))
}

package main

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

var n, k, x int64

var s string

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n, &k, &x)

		fmt.Fscan(r, &s)

		a := solve()

		fmt.Println(a)
	}
}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() string {

	var arr []int

	var cnt int

	for j := 0; j < len(s); j++ {
		if s[j] == '*' {
			cnt++
		} else {
			if cnt != 0 {
				arr = append(arr, cnt)
				cnt = 0
			}

		}
	}
	if cnt != 0 {
		arr = append(arr, cnt)
	}

	var bts bytes.Buffer

	var prod int64 = 1

	b := make([]int, len(arr))

	var j int
	for j = len(arr) - 1; j >= 0; j-- {
		p := int64(arr[j]) * k + 1
		prod = prod * p

		if prod > x {
			break
		}
	}

	if j == - 1 {
		j = 0
	}

	for i := j; i < len(arr); i++ {
		p := int64(arr[i]) * k + 1
		prod = prod / p

		var q int64
		for q = 1; q <= p; q++ {

			if prod * q >= x {

				q--
				b[i] = int(q)

				x -= prod * q

				break
			}
		}
	}

	var prev byte = 'c'
	cnt = 0

	for i := 0; i < len(s); i++ {
		if s[i] == 'a' {
			bts.WriteByte('a')

		} else {
			if prev != '*' {
				for j := 0; j < b[cnt]; j++ {
					bts.WriteByte('b')
				}

				cnt++
			}
		}

		prev = s[i]
	}

	return bts.String()
}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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


package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func getHighest(n int, s []byte) []int {
	from := 1
	res := make([]int, n)
	for i := 0; i < n-1; {
		// stderr("highest", "n=", n, "i=", i, string(s), res)
		j := i
		for j < n-1 && s[j] == '>' {
			j++
		}
		for k := j; k >= i; k-- {
			res[k] = from
			from++
		}
		i = j + 1
	}
	if res[n-1] == 0 {
		res[n-1] = from
		from++
	}
	return res
}

func solve(n int, s []byte) ([]int, []int) {
	highest := getHighest(n, s)
	t := make([]byte, n-1)
	for i := 0; i < n-1; i++ {
		if s[i] == '>' {
			t[n-1-i-1] = '<'
		} else {
			t[n-1-i-1] = '>'
		}
	}
	lowest := getHighest(n, t)
	for l, r := 0, n-1; l <= r; l, r = l+1, r-1 {
		lowest[l], lowest[r] = lowest[r], lowest[l]
	}
	return lowest, highest
}

func main() {
	f := os.Stdin
	out := os.Stdout
	// f, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(f, 200010)

	T := NextInt()

	for t := 0; t < T; t++ {
		n := NextInt()
		s := NextBytes()
		a, b := solve(n, s)
		for i := 0; i < n; i++ {
			fmt.Fprint(out, a[i], " ")
		}
		fmt.Fprintln(out)
		for i := 0; i < n; i++ {
			fmt.Fprint(out, b[i], " ")
		}
		fmt.Fprintln(out)
	}
}

package main

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

// 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() {
		var n int
		var s string
		Fscan(in, &n, &s)
		ans := make([]int, n)
		up := n
		for i := range s {
			if s[i] == '>' {
				ans[i] = up
				up--
			}
		}
		down := 1
		for i := n - 1; i >= 0; i-- {
			if ans[i] > 0 {
				continue
			}
			end := i
			for ; i >= 0 && ans[i] == 0; i-- {
			}
			i++
			for j := i; j <= end; j++ {
				ans[j] = down
				down++
			}
		}
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)

		ans = make([]int, n)
		up = n
		for i := len(s) - 1; i >= 0; i-- {
			if s[i] == '<' {
				ans[i+1] = up
				up--
			}
		}
		down = 1
		for i := 0; i < n; i++ {
			if ans[i] > 0 {
				continue
			}
			end := i
			for ; i < n && ans[i] == 0; i++ {
			}
			i--
			for j := i; j >= end; j-- {
				ans[j] = down
				down++
			}
		}
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

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

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

package main

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

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

	solve := func() {
		var n int
		var s string
		Fscan(in, &n, &s)
		//if n == 2 {
		//	if s[0] == '<' {
		//		Fprintln(out, 1, 2)
		//		Fprintln(out, 1, 2)
		//	} else {
		//		Fprintln(out, 2, 1)
		//		Fprintln(out, 2, 1)
		//	}
		//	return
		//}

		//incCnt := strings.Count(s, "<")
		ans1 := make([]int, n)
		top := n
		for i := range s {
			if s[i] == '>' {
				ans1[i] = top
				top--
			}
		}
		down := 1
		for i := n - 1; i >= 0; i-- {
			if ans1[i] > 0 {
				continue
			}
			st := i-1
			for ; st >= 0 && s[st] == '<'; st-- {
			}
			st++
			for j := st; j <= i; j++ {
				ans1[j] = down
				down++
			}

		}

		//
		//used := make([]bool, n+1)
		//top := n
		//for st := 0; st < n-1; st++ {
		//	if s[st] == '>' {
		//		if st == n-2 || s[st+1] == '>' {
		//
		//			ans1 = append(ans1, top)
		//			used[top] = true
		//
		//			top--
		//
		//			continue
		//		}
		//
		//	}
		//
		//	end := st
		//	if s[st] == '>' {
		//		end++
		//	}
		//	for ; end < n-1; end++ {
		//		if s[end] == '>' {
		//			break
		//		}
		//	}
		//	end--
		//	//s[st:end] is <<<<<...
		//	//if end > st {
		//	for i := st; i <= end; i++ {
		//		ans1 = append(ans1, incCnt)
		//		used[incCnt] = true
		//		incCnt--
		//	}
		//	//}
		//	st = end
		//
		//}

		for i, v := range ans1 {
			if i > 0 {
				Fprint(out, " ")
			}
			Fprint(out, v)
		}
		Fprintln(out)

		ans2 := make([]int, n)
		top = n
		for i := len(s)-1;i>=0;i-- {
			if s[i]=='<' {
				ans2[i+1] = top
				top--
			}
		}
		down = 1
		for i :=0;i<n;i++ {
			if ans2[i]> 0 {
				continue
			}
			st := i
			for ;st <n && ans2[st] == 0;st++ {
			}
			st--
			for j := st; j >= i; j-- {
				ans2[j] = down
				down++
			}
		}
		for i, v := range ans2 {
			if i > 0 {
				Fprint(out, " ")
			}
			Fprint(out, v)
		}
		Fprintln(out)
		return
	}

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

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

package main

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

// 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() {
		var n int
		var s string
		Fscan(in, &n, &s)
		ans := make([]int, n)
		up := n
		for i := range s {
			if s[i] == '>' {
				ans[i] = up
				up--
			}
		}
		down := 1
		for i := n - 1; i >= 0; i-- {
			if ans[i] > 0 {
				continue
			}
			end := i
			for ; i >= 0 && ans[i] == 0; i-- {
			}
			i++
			for j := i; j <= end; j++ {
				ans[j] = down
				down++
			}
		}
		for i, v := range ans {
			if i > 0 {
				Fprint(out, " ")
			}
			Fprint(out, v)
		}
		Fprintln(out)

		ans = make([]int, n)
		up = n
		for i := len(s) - 1; i >= 0; i-- {
			if s[i] == '<' {
				ans[i+1] = up
				up--
			}
		}
		down = 1
		for i := 0; i < n; i++ {
			if ans[i] > 0 {
				continue
			}
			end := i
			for ; i < n && ans[i] == 0; i++ {
			}
			i--
			for j := i; j >= end; j-- {
				ans[j] = down
				down++
			}
		}
		for i, v := range ans {
			if i > 0 {
				Fprint(out, " ")
			}
			Fprint(out, v)
		}
		Fprintln(out)
	}

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

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

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	tests := scanInt()
	for t := 0; t < tests; t++ {
		n := scanInt()
		s := scanString()

		arr := make([]int, n)
		// for i := 0; i < n; i++ {
		// 	arr[i] = n-i
		// }

		c0 := make([]int, n)
		c0[n-1] = 1
		for i := 0; i < n-1; i++ {
			c0[n-2-i] = c0[n-2-i+1]
			if s[n-2-i] == '>' {
				c0[n-2-i]++
			}
		}

		p0 := n-1
		ma0 := 1

		for p0 >= 0 {
			cnt := 0
			for i := p0; i >= 0 ; i-- {
				cnt++
				if i != 0 {
					if c0[i] != c0[i-1] {
						break
					}
				}
			}

			for i := 0; i < cnt ; i++ {
				arr[p0+1-cnt+i] = ma0+i
			}

			ma0 += cnt
			p0 -= cnt
		}

		for i := 0; i < n; i++ {
			fmt.Printf("%d ", arr[i])
		}
		fmt.Println()

		c := make([]int, n)
		c[n-1] = 1
		for i := 0; i < n-1; i++ {
			c[n-2-i] = c[n-2-i+1]
			if s[n-2-i] == '<' {
				c[n-2-i]++
				// arr[n-2-i],arr[n-2-i+1] = arr[n-2-i+1],arr[n-2-i]
			}
		}

		// fmt.Println(arr)
		// fmt.Println(c)

		p := 0
		ma := 0

		for p < n {
			cnt := 0
			for i := p; i < n; i++ {
				cnt++
				if i < n-1 {
					if c[i] != c[i+1] {
						break
					}
				}
			}

			ma += cnt
			for i := 0; i < cnt; i++ {
				fmt.Printf("%d ", ma-i)
			}

			p += cnt
		}

		fmt.Println()

	}
}


package main

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

type Edge struct {
	a     int
	b     int
	l     int
	times int64
}

type Vertex struct {
	neighbor []int
	edges    []int
	visited  bool
	size     int
}

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

	count  int = 0
	n      int
	nodes  []Vertex
	edges  []Edge
	q      int
	r      []int
	w      []int
	result []float64
)

func in() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	n = readInt()
	nodes = make([]Vertex, n)
	edges = make([]Edge, n-1)
	for i := 0; i < n-1; i++ {
		var e *Edge = new(Edge)
		e.a = readInt()
		e.b = readInt()
		e.l = readInt()
		e.a -= 1
		e.b -= 1
		edges[i] = *e

		nodes[e.a].neighbor = append(nodes[e.a].neighbor, e.b)
		nodes[e.b].neighbor = append(nodes[e.b].neighbor, e.a)
		nodes[e.a].edges = append(nodes[e.a].edges, i)
		nodes[e.b].edges = append(nodes[e.b].edges, i)
	}
	q = readInt()
	r = make([]int, q)
	w = make([]int, q)
	for i := 0; i < q; i++ {
		r[i] = readInt()
		w[i] = readInt()
		r[i]--
	}
}

func out() {
	writer = bufio.NewWriter(os.Stdout)

	defer writer.Flush()

	for _, r := range result {
		printFloat64(r)
		printLine()
	}
}

func run() {
	dfs(&nodes[0])

	var precalc float64 = 0
	for _, e := range edges {
		precalc += float64(e.times) * float64(e.l) * 2
	}

	result = make([]float64, q)
	for i, road := range r {
		nw := w[i]
		e := &edges[road]
		precalc = precalc - float64(e.times)*float64(e.l-nw)*2
		result[i] = calc(precalc)
		e.l = nw
	}
}

func calc(r float64) float64 {
	return r * 3 / float64(n) / float64(n-1)
}

func dfs(v *Vertex) int { // sizeA
	count++
	v.visited = true
	size := 1
	for i, neighbor := range v.neighbor {
		if !nodes[neighbor].visited {
			sizeA := dfs(&nodes[neighbor])
			edge := &edges[v.edges[i]]
			edge.times = int64(sizeA) * int64(n-sizeA)
			size += sizeA
		}
	}
	v.size = size
	return size
}

func main() {
	in()
	run()
	out()
}

// Read.

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

func readInt64() int64 {
	ans, _ := strconv.ParseInt(readString(), 10, 64)
	return ans
}

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printSpace() {
	printString(" ")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFloat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 10, 64))
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF500D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ l, c int64 }
	type edge struct{ to, id int }

	var n, v, w, q, id int
	Fscan(in, &n)
	es := make([]pair, n)
	g := make([][]edge, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w, &es[i].l)
		v--
		w--
		g[v] = append(g[v], edge{w, i})
		g[w] = append(g[w], edge{v, i})
	}

	size := make([]int, n)
	var _f func(v, fa int) int
	_f = func(v, fa int) int {
		sz := 1
		for _, e := range g[v] {
			if w := e.to; w != fa {
				sz += _f(w, v)
			}
		}
		size[v] = sz
		return sz
	}
	_f(0, -1)

	var f func(v, fa int)
	f = func(v, fa int) {
		for _, e := range g[v] {
			if w := e.to; w != fa {
				if s, z := int64(size[w]), int64(n-size[w]); s > 1 && z > 1 {
					es[e.id].c = s * z * (s + z - 2)
				} else {
					es[e.id].c = int64(n-1) * int64(n-2)
				}
				f(w, v)
			}
		}
	}
	f(0, -1)
	s := 0.
	for _, p := range es[1:] {
		s += float64(p.l * p.c)
	}
	c := float64(int64(n) * int64(n-1) * int64(n-2) / 6)
	for Fscan(in, &q); q > 0; q-- {
		var l int64
		Fscan(in, &id, &l)
		e := es[id]
		s -= float64(e.c * (e.l - l))
		Fprintf(out, "%.10f\n", s/c)
		es[id].l = l
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF500D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ l, c int64 }
	type edge struct{ to, id int }

	var n, v, w, q, id int
	Fscan(in, &n)
	es := make([]pair, n)
	g := make([][]edge, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w, &es[i].l)
		v--
		w--
		g[v] = append(g[v], edge{w, i})
		g[w] = append(g[w], edge{v, i})
	}

	size := make([]int, n)
	var _f func(v, fa int) int
	_f = func(v, fa int) int {
		sz := 1
		for _, e := range g[v] {
			if w := e.to; w != fa {
				sz += _f(w, v)
			}
		}
		size[v] = sz
		return sz
	}
	_f(0, -1)

	var f func(v, fa int)
	f = func(v, fa int) {
		for _, e := range g[v] {
			if w := e.to; w != fa {
				if s, z := int64(size[w]), int64(n-size[w]); s > 1 && z > 1 {
					es[e.id].c = s * z * (s + z - 2)
				} else {
					es[e.id].c = int64(n-1) * int64(n-2)
				}
				f(w, v)
			}
		}
	}
	f(0, -1)
	s := 0.
	for _, p := range es[1:] {
		s += float64(p.l * p.c)
	}
	c := float64(int64(n) * int64(n-1) * int64(n-2) / 6)
	for Fscan(in, &q); q > 0; q-- {
		var l int64
		Fscan(in, &id, &l)
		e := es[id]
		s -= float64(e.c * (e.l - l))
		Fprintf(out, "%.7f\n", s/c)
		es[id].l = l
	}
}

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

package main

import (
	"fmt"
)

type Edge struct {
	a     int
	b     int
	l     int
	times int64
}

type Vertex struct {
	children []int
	edges    []int
	size     int
}

var (
	n      int
	nodes  []Vertex
	edges  []Edge
	q      int
	r      []int
	w      []int
	result []float64
)

func in() {
	fmt.Scan(&n)
	nodes = make([]Vertex, n)
	edges = make([]Edge, n-1)
	for i := 0; i < n-1; i++ {
		var e *Edge = new(Edge)
		fmt.Scan(&e.a, &e.b, &e.l)
		e.a -= 1
		e.b -= 1
		edges[i] = *e

		var node *Vertex
		if e.a < e.b {
			node = &nodes[e.a]
			node.children = append(node.children, e.b)
		} else {
			node = &nodes[e.b]
			node.children = append(node.children, e.a)
		}
		node.edges = append(node.edges, i)
	}
	fmt.Scan(&q)
	r = make([]int, q)
	w = make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Scan(&r[i], &w[i])
		r[i]--
	}
}

func out() {
	for _, r := range result {
		fmt.Printf("%.10f\n", r)
	}
}

func run() {
	dfs(&nodes[0])

	var precalc float64 = 0
	for _, e := range edges {
		precalc += float64(e.times) * float64(e.l) * 2
	}

	result = make([]float64, q)
	for i, road := range r {
		nw := w[i]
		e := &edges[road]
		precalc = precalc - float64(e.times)*float64(e.l-nw)*2
		result[i] = calc(precalc)
		e.l = nw
	}
}

func calc(r float64) float64 {
	return r * 3 / float64(n*(n-1))
}

func dfs(v *Vertex) int { // sizeA
	size := 1
	for i, children := range v.children {
		sizeA := dfs(&nodes[children])
		edge := &edges[v.edges[i]]
		edge.times = int64(sizeA) * int64(n-sizeA)
		size += sizeA
	}
	v.size = size
	return size
}

func main() {
	in()
	run()
	out()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF500D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ l, c int64 }
	type edge struct{ to, id int }

	var n, v, w, q, id int
	Fscan(in, &n)
	es := make([]pair, n)
	g := make([][]edge, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w, &es[i].l)
		v--
		w--
		g[v] = append(g[v], edge{w, i})
		g[w] = append(g[w], edge{v, i})
	}

	size := make([]int, n)
	var _f func(v, fa int) int
	_f = func(v, fa int) int {
		sz := 1
		for _, e := range g[v] {
			if w := e.to; w != fa {
				sz += _f(w, v)
			}
		}
		size[v] = sz
		return sz
	}
	_f(0, -1)

	var f func(v, fa int)
	f = func(v, fa int) {
		for _, e := range g[v] {
			if w := e.to; w != fa {
				if s, z := int64(size[w]), int64(n-size[w]); s > 1 && z > 1 {
					es[e.id].c = s * z * (s + z - 2)
				} else {
					es[e.id].c = int64(n-1) * int64(n-2)
				}
				f(w, v)
			}
		}
	}
	f(0, -1)
	s := int64(0)
	for _, p := range es[1:] {
		s += p.l * p.c
	}
	c := float64(int64(n) * int64(n-1) * int64(n-2) / 6)
	for Fscan(in, &q); q > 0; q-- {
		var l int64
		Fscan(in, &id, &l)
		e := es[id]
		s -= e.c * (e.l - l)
		Fprintf(out, "%.8f\n", float64(s)/c)
		es[id].l = l
	}
}

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


/*
URL:
https://codeforces.com/contest/1492/problem/C
*/

package main

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

var (
	println = fmt.Println

	n, m int
	S, T []rune

	I [30][]int
	P []int
)

func main() {
	defer stdout.Flush()

	n, m = readi2()
	S, T = readrs(), readrs()

	for idx, r := range S {
		v := int(r - 'a')
		I[v] = append(I[v], idx)
	}
	// debugf("I: %v\n", I)

	P = make([]int, m)
	si := 0
	for i := 0; i < m; i++ {
		r := T[i]

		for si < n && S[si] != r {
			si++
		}
		P[i] = si

		si++
	}
	// debugf("P: %v\n", P)

	ans := 1
	for i := 0; i < m-1; i++ {
		wid := P[i+1] - P[i]
		chmax(&ans, wid)
	}
	// debugf("ans: %v\n", ans)

	for i := m - 1; i >= 0; i-- {
		nxtIdx := n
		if i+1 < m {
			nxtIdx = P[i+1]
		}

		r := T[i]
		ri := int(r - 'a')
		// nxtIdx未満で最大を調べる
		maxi := BinarySearch(0, len(I[ri]), func(mid int) bool {
			return I[ri][mid] < nxtIdx
		})
		// P[i] = maxi
		P[i] = I[ri][maxi]

		// iの前後と比較
		if i+1 < m {
			chmax(&ans, P[i+1]-P[i])
		}
		if i-1 >= 0 {
			chmax(&ans, P[i]-P[i-1])
		}
		// debugf("P: %v\n", P)
	}

	println(ans)
}

type jf func(mid int) bool

func BinarySearch(initOK, initNG int, isOK jf) (ok int) {
	_abs := func(a int) int {
		if a < 0 {
			return -a
		}
		return a
	}

	ng := initNG
	ok = initOK
	for _abs(ok-ng) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

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

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

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

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

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

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

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

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

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

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

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

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

	return s
}

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

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, ans int
	var s, t []byte
	Fscan(in, &n, &m, &s, &t)
	l := make([]int, m)
	r := make([]int, m)
	k := 0
	for i, b := range t {
		for s[k] != b {
			k++
		}
		l[i] = k
		k++
	}
	k = n - 1
	for i := m - 1; i >= 0; i-- {
		b := t[i]
		for s[k] != b {
			k--
		}
		r[i] = k
		k--
	}
	for i := 1; i < m; i++ {
		ans = max(ans, max(max(l[i]-l[i-1], r[i]-r[i-1]), r[i]-l[i-1]))
	}
	Fprintln(out, ans)
}

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

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

	var n, m int
	var s, t []byte
	Fscan(in, &n, &m, &s, &t)
	l := make([]int, m)
	r := make([]int, m)
	i := 0
	for j, b := range t {
		for s[i] != b {
			i++
		}
		l[j] = i
		i++
	}
	i = n - 1
	for j := m - 1; j >= 0; j-- {
		b := t[j]
		for s[i] != b {
			i--
		}
		r[j] = i
		i--
	}

	ans := 0
	for i := 1; i < m; i++ {
		ans = max(ans, l[i]-l[i-1])
		ans = max(ans, r[i]-r[i-1])
	}

	for i := 0; i < m-1; i++ {
		ans = max(ans, r[i+1]-l[i])
	}

	Fprintln(out, ans)
}

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)

	var n, m int
	var s, t string
	fmt.Fscan(in, &n, &m)
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &t)

	maxWidth := 1
	positions := make([]int, m)
	for i, j := 0, 0; j < m; j++ {
		for ; s[i] != t[j]; i++ {
		}
		positions[j] = i
		i++
		if j > 0 && positions[j]-positions[j-1] > maxWidth {
			maxWidth = positions[j] - positions[j-1]
		}
	}
	for i, j := n-1, m-1; j >= 0; j-- {
		for ; s[i] != t[j]; i-- {
		}
		positions[j] = i
		i--
		if j > 0 && positions[j]-positions[j-1] > maxWidth {
			maxWidth = positions[j] - positions[j-1]
		}
	}

	fmt.Println(maxWidth)
}

package main

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

func main() {

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

	var n, m int
	fmt.Fscan(in, &n, &m)
	var s, t string
	fmt.Fscan(in, &s, &t)

	l := make([]int, m)
	r := make([]int, m)

	j := 0
	for i := 0; i < m; i++ {
		for s[j] != t[i] {
			j++
		}
		l[i] = j
		j++
	}
	j = n - 1
	for i := m - 1; i >= 0; i-- {
		for s[j] != t[i] {
			j--
		}
		r[i] = j
		j--
	}

	res := 0
	for i := 0; i < m - 1; i++ {
		x := r[i + 1] - l[i]
		if x > res {
			res = x
		}
	}
	fmt.Fprintln(out, res)
}

package main

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

var in *bufio.Reader

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

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

	var s, t string
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &t)

	tIdx := 0
	leftest := make([]int, m)
	for sIdx, si := range []byte(s) {
		if si == t[tIdx] {
			leftest[tIdx] = sIdx
			tIdx++
		}
		if tIdx == m {
			break
		}
	}

	tIdx = m - 1
	rightest := make([]int, m)
	for sIdx := n - 1; sIdx >= 0; sIdx-- {
		if s[sIdx] == t[tIdx] {
			rightest[tIdx] = sIdx
			tIdx--
		}
		if tIdx < 0 {
			break
		}
	}

	maxV := 0
	for i := 1; i < m; i++ {
		if rightest[i]-leftest[i-1] > maxV {
			maxV = rightest[i] - leftest[i-1]
		}
	}
	fmt.Println(maxV)
}

package main
import (
	.	"fmt"
	"bufio"
	"os"
)
var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func Reverse(s []int) {
	for i, j := 0, len(s) - 1; i < j; i, j = i + 1, j - 1 {
		s[i], s[j] = s[j], s[i]
	}
}

func WhyIsGoStdLibSoReducedReallyNoMaxForInts(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

func main() {
	var t int
	Fscan(in, &t, &t)
	var a, b string
	Fscan(in, &a, &b)
	mls := make([]int, 0, len(b))
	for i := 0; len(mls) < len(b); i++ {
		if b[len(mls)] == a[i] {
			mls = append(mls, i)
		}
	}
	mrs := make([]int, 0, len(b))
	for i := len(a) - 1; len(mrs) < len(b); i-- {
		if b[len(b) - len(mrs) - 1] == a[i] {
			mrs = append(mrs, i)
		}
	}
	Reverse(mrs)
	ans := 0
	for i := 0; i < len(b) - 1; i++ {
		ans = WhyIsGoStdLibSoReducedReallyNoMaxForInts(ans, mrs[i+1] - mls[i])
	}
	Print(ans)
}

package main

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

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

	// single test case
	var n, m int
	Fscan(in, &n, &m)

	var s, t []byte
	Fscan(in, &s, &t)

	l := make([]int, m)
	r := make([]int, m)

	pos := 0
	for i, b := range t {
		for s[pos] != b {
			pos++
		}
		l[i] = pos
		pos++
	}

	pos = n - 1
	for i := m - 1; i >= 0; i-- {
		b := t[i]
		for s[pos] != b {
			pos--
		}
		r[i] = pos
		pos--
	}

	answer := 0
	for i := 1; i < m; i++ {
		answer = max(answer, max(max(l[i]-l[i-1], r[i]-r[i-1]), r[i]-l[i-1]))

	}
	Fprint(out, answer)

	// 입력 에러 방지
	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("읽지않은 데이터 발견：\n" + _s)
	}
}

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

// LETYLETYLETY
func main() { CF704C(os.Stdin, os.Stdout) }

// YTELYTELYTEL

package main

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

func max(x, y int) int{
	if x > y{
		return x
	}
	return y

}

func main(){
	in := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(in, &n, &m)
	in.ReadString('\n')
	s, _ := in.ReadString('\n')
	t, _ := in.ReadString('\n')
	pl := make([]int, m)
	pr := make([]int, m)

	j := 0
	for i:=0; i<m; i++{
		for s[j] != t[i]{
			j++
		}
		pl[i] = j
		j++
	}
	j = n-1
	for i:=m-1; i>=0; i--{
		for s[j] != t[i]{
			j--
		}
		pr[i] = j
		j--
	}

	result := 0
	for i := 0; i<m-1; i++{
		result =max(result, pr[i+1]-pl[i])
	}

	fmt.Println(result)
}

package main

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

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

func scanf(pattern string, a ...interface{})  { fmt.Fscanf(reader, pattern, a...) }
func printf(pattern string, a ...interface{}) { fmt.Fprintf(writer, pattern, a...) }
func ceil(a, b int64) int64                   { return (a + b - 1) / b }
func min(a, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}
func max(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	defer writer.Flush()
	var m int
	var n int
	scanf("%d %d\n", &m, &n)

	var s string
	var t string
	scanf("%s\n", &s)
	scanf("%s\n", &t)
	type pair struct {
		first  int
		second int
	}

	left := make([]int, len(t))
	right := make([]int, len(t))

	j := 0
	for i := 0; i < len(t); i++ {
		for s[j] != t[i] {
			j++
		}
		left[i] = j
		j++
	}

	j = len(s) - 1
	for i := len(t) - 1; i >= 0; i-- {
		for s[j] != t[i] {
			j--
		}
		right[i] = j
		j--
	}

	ans := 0
	for i := 0; i < len(t)-1; i++ {
		w := right[i+1] - left[i]
		ans = int(max(int64(ans), int64(w)))
	}
	printf("%d\n", ans)
}

package main

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

func main() {

	input := bufio.NewReader(os.Stdin)
	output := bufio.NewWriter(os.Stdout)
	defer output.Flush()

	var n, m int
	fmt.Fscan(input, &n, &m)

	var s, t string
	fmt.Fscan(input, &s, &t)

	p := make([]int, m)
	q := make([]int, m)

	r := 0
	for i := 0; i < m; i++ {
		for s[r] != t[i] {
			r++
		}
		p[i] = r
		r++
	}
	r = n - 1
	for i := m - 1; i >= 0; i-- {
		for s[r] != t[i] {
			r--
		}
		q[i] = r
		r--
	}

	result := 0
	for i := 0; i < m-1; i++ {
		x := q[i+1] - p[i]
		if x > result {
			result = x
		}
	}

	fmt.Fprintln(output, result)
}

package main

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

func solveA() {}

func solveB() {}

func solveC() {
	var n, m int
	scan(&n, &m)

	var s, t string
	scan(&s, &t)

	posl := make([]int, len(t))
	j := 0
	for i := range s {
		if s[i] == t[j] {
			posl[j] = i
			j++
		}
		if j == len(t) {
			break
		}
	}

	posr := make([]int, len(t))
	j = len(t) - 1
	for i := len(s) - 1; i >= 0; i-- {
		if s[i] == t[j] {
			posr[j] = i
			j--
		}
		if j == -1 {
			break
		}
	}

	if m%2 == 1 {
		left := posl[(m-1)/2-1]
		right := posr[(m-1)/2+1]
		symb := t[(m-1)/2]

		mx := -1
		for i := left + 1; i <= right-1; i++ {
			if s[i] == symb {
				mx = max(mx, max(i-left, right-i))
			}
		}

		for i := 1; i < m; i++ {
			mx = max(mx, posr[i]-posl[i-1])
		}

		printf("%d", mx)
	} else {
		mx := -1
		for i := 1; i < m; i++ {
			mx = max(mx, posr[i]-posl[i-1])
		}
		printf("%d", mx)
	}
}

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

func solveD() {}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	//scan(&T)
	for t := 0; t < T; t++ {
		solveC()
	}
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

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

func scanf(pattern string, a ...interface{})  { fmt.Fscanf(reader, pattern, a...) }
func printf(pattern string, a ...interface{}) { fmt.Fprintf(writer, pattern, a...) }
func ceil(a, b int64) int64                   { return (a + b - 1) / b }
func min(a, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}
func max(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	defer writer.Flush()
	var m int
	var n int
	scanf("%d %d\n", &m, &n)

	var s string
	var t string
	scanf("%s\n", &s)
	scanf("%s\n", &t)
	type pair struct {
		first  int
		second int
	}
	count := make([]pair, 26)

	for i := range count {
		count[i].first = math.MaxInt32
	}

	j := 0
	for i := 0; i < len(t); i++ {
		for s[j] != t[i] {
			j++
		}
		p := int(t[i] - 'a')
		count[p].first = int(min(int64(count[p].first), int64(j)))
		j++
	}

	// fmt.Println(count)

	j = len(s) - 1
	for i := len(t) - 1; i >= 0; i-- {
		for s[j] != t[i] {
			j--
		}
		p := int(t[i] - 'a')
		count[p].second = int(max(int64(count[p].second), int64(j)))
		j--
	}

	// fmt.Println(count)
	ans := 0
	for i := 0; i < len(t)-1; i++ {
		cur := t[i] - 'a'
		next := t[i+1] - 'a'
		w := count[next].second - count[cur].first
		ans = int(max(int64(ans), int64(w)))
	}
	printf("%d\n", ans)
}

package main

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

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

func scanf(pattern string, a ...interface{})  { fmt.Fscanf(reader, pattern, a...) }
func printf(pattern string, a ...interface{}) { fmt.Fprintf(writer, pattern, a...) }
func ceil(a, b int64) int64                   { return (a + b - 1) / b }
func min(a, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}
func max(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	defer writer.Flush()
	var m int
	var n int
	scanf("%d %d\n", &m, &n)

	var s string
	var t string
	scanf("%s\n", &s)
	scanf("%s\n", &t)
	type pair struct {
		first  int
		second int
	}
	count := make([]pair, 26)

	j := 0
	for i := 0; i < len(t); i++ {
		minIdx := math.MaxInt32
		for i < len(t)-1 && s[j] != t[i+1] {
			if s[j] == t[i] {
				minIdx = int(min(int64(minIdx), int64(j)))
			}
			j++
		}
		p := int(t[i] - 'a')
		count[p].first = minIdx
	}

	minIdx := math.MaxInt32
	for j < len(s) {
		if s[j] == t[len(t)-1] {
			minIdx = int(min(int64(minIdx), int64(j)))
		}
		j++
	}
	count[t[len(t)-1]-'a'].first = minIdx

	// fmt.Println(count)

	j = len(s) - 1
	for i := len(t) - 1; i >= 0; i-- {
		maxIdx := math.MinInt32
		for i > 0 && s[j] != t[i-1] {
			if s[j] == t[i] {
				maxIdx = int(max(int64(maxIdx), int64(j)))
			}
			j--
		}
		p := int(t[i] - 'a')
		count[p].second = maxIdx
	}

	maxIdx := math.MinInt32
	for j >= 0 {
		if s[j] == t[0] {
			maxIdx = int(max(int64(maxIdx), int64(j)))
		}
		j--
	}
	count[t[0]-'a'].second = maxIdx
	// fmt.Println(count)
	ans := 0
	for i := 0; i < len(t)-1; i++ {
		cur := t[i] - 'a'
		next := t[i+1] - 'a'
		w := count[next].second - count[cur].first
		ans = int(max(int64(ans), int64(w)))
	}
	printf("%d\n", ans)
}

package main

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

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

func scanf(pattern string, a ...interface{})  { fmt.Fscanf(reader, pattern, a...) }
func printf(pattern string, a ...interface{}) { fmt.Fprintf(writer, pattern, a...) }
func ceil(a, b int64) int64                   { return (a + b - 1) / b }
func min(a, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}
func max(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	defer writer.Flush()
	var m int
	var n int
	scanf("%d %d\n", &m, &n)

	var s string
	var t string
	scanf("%s\n", &s)
	scanf("%s\n", &t)
	type pair struct {
		first  int
		second int
	}
	count := make([]pair, 26)

	j := 0
	for i := 0; i < len(t); i++ {
		minIdx := math.MaxInt32
		for i < len(t)-1 && s[j] != t[i+1] {
			if s[j] == t[i] {
				minIdx = int(min(int64(minIdx), int64(j)))
			}
			j++
		}
		p := int(t[i] - 'a')
		count[p].first = minIdx
	}

	minIdx := math.MaxInt32
	for j < len(s) {
		if s[j] == t[len(t)-1] {
			minIdx = int(min(int64(minIdx), int64(j)))
		}
		j++
	}
	count[t[len(t)-1]-'a'].first = minIdx

	// fmt.Println(count)

	j = 0
	for i := 0; i < len(t); i++ {
		maxIdx := math.MinInt32
		for i < len(t)-1 && s[j] != t[i+1] {
			if s[j] == t[i] {
				maxIdx = int(max(int64(maxIdx), int64(j)))
			}
			j++
		}
		p := int(t[i] - 'a')
		count[p].second = maxIdx
	}

	maxIdx := math.MinInt32
	for j < len(s) {
		if s[j] == t[len(t)-1] {
			maxIdx = int(max(int64(maxIdx), int64(j)))
		}
		j++
	}
	count[t[len(t)-1]-'a'].second = minIdx
	// fmt.Println(count)
	ans := 0
	for i := 0; i < len(t)-1; i++ {
		cur := t[i] - 'a'
		next := t[i+1] - 'a'
		w := count[next].second - count[cur].first
		ans = int(max(int64(ans), int64(w)))
	}
	printf("%d\n", ans)
}

package main

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

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

func scanf(pattern string, a ...interface{})  { fmt.Fscanf(reader, pattern, a...) }
func printf(pattern string, a ...interface{}) { fmt.Fprintf(writer, pattern, a...) }
func ceil(a, b int64) int64                   { return (a + b - 1) / b }
func min(a, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}
func max(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	defer writer.Flush()
	var m int
	var n int
	scanf("%d %d\n", &m, &n)

	var s string
	var t string
	scanf("%s\n", &s)
	scanf("%s\n", &t)
	type pair struct {
		first  int
		second int
	}
	count := make([]pair, 26)
	for i := range count {
		count[i].first = math.MaxInt32
		count[i].second = math.MinInt32
	}
	for i, c := range s {
		p := int(c - 'a')
		count[p].first = int(min(int64(count[p].first), int64(i)))
		count[p].second = int(max(int64(count[p].second), int64(i)))
	}

	// fmt.Println(count)
	ans := 0
	for i := 1; i < len(t); i++ {
		cur := t[i] - 'a'
		prev := t[i-1] - 'a'
		w := count[cur].second - count[prev].first
		ans = int(max(int64(ans), int64(w)))
	}
	printf("%d\n", ans)
}

package main

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

func main() {

	input := bufio.NewReader(os.Stdin)
	output := bufio.NewWriter(os.Stdout)
	defer output.Flush()

	fmt.Println("Please Enter Your Input: ")

	var n, m int
	fmt.Fscan(input, &n, &m)

	var s, t string
	fmt.Fscan(input, &s, &t)

	p := make([]int, m)
	q := make([]int, m)

	r := 0
	for i := 0; i < m; i++ {
		for s[r] != t[i] {
			r++
		}
		p[i] = r
		r++
	}
	r = n - 1
	for i := m - 1; i >= 0; i-- {
		for s[r] != t[i] {
			r--
		}
		q[i] = r
		r--
	}

	result := 0
	for i := 0; i < m-1; i++ {
		x := q[i+1] - p[i]
		if x > result {
			result = x
		}
	}

	fmt.Fprintln(output, result)
}

package main

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

func main() {

	input := bufio.NewReader(os.Stdin)
	output := bufio.NewWriter(os.Stdout)
	defer output.Flush()

	fmt.Println("Please Enter Your Input: ")

	var n, m int
	fmt.Fscan(input, &n, &m)

	var s, t string
	fmt.Fscan(input, &s, &t)

	p := make([]int, m)
	q := make([]int, m)

	r := 0
	for i := 0; i < m; i++ {
		for s[r] != t[i] {
			r++
		}
		p[i] = r
		r++
	}
	r = n - 1
	for i := m - 1; i >= 0; i-- {
		for s[r] != t[i] {
			r--
		}
		q[i] = r
		r--
	}

	result := 0
	for i := 0; i < m-1; i++ {
		x := q[i+1] - p[i]
		if x > result {
			result = x
		}
	}

	fmt.Fprintln(output, "Your Output Is: ", result)
	fmt.Println(" ")
}

package main

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

func solveA() {}

func solveB() {}

func solveC() {
	var n, m int
	scan(&n, &m)

	var s, t string
	scan(&s, &t)

	posl := make([]int, len(t))
	j := 0
	for i := range s {
		if s[i] == t[j] {
			posl[j] = i
			j++
		}
		if j == len(t) {
			break
		}
	}

	posr := make([]int, len(t))
	j = len(t) - 1
	for i := len(s) - 1; i >= 0; i-- {
		if s[i] == t[j] {
			posr[j] = i
			j--
		}
		if j == -1 {
			break
		}
	}

	if len(t)%2 == 1 {
		left := posl[(m-1)/2-1]
		right := posr[(m-1)/2+1]
		symb := t[(m-1)/2]

		mx := -1
		for i := left + 1; i <= right-1; i++ {
			if s[i] == symb {
				mx = max(mx, max(i-left, right-i))
			}
		}
		printf("%d", mx)
	} else {
		mx := posr[len(t)/2] - posl[len(t)/2-1]
		printf("%d", mx)
	}
}

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

func solveD() {}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	//scan(&T)
	for t := 0; t < T; t++ {
		solveC()
	}
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

func solveA() {}

func solveB() {}

func solveC() {
	var n, m int
	scan(&n, &m)

	var s, t string
	scan(&s, &t)

	pos := make([]int, len(t))

	l, r := 0, len(s)-1
	for i := 0; i < len(t)/2; i++ {
		front := t[i]
		back := t[len(t)-i-1]

		for l <= r && s[l] != front {
			l++
		}
		pos[i] = l
		l++

		for l <= r && s[r] != back {
			r--
		}
		pos[len(t)-i-1] = r
		r--
	}

	if len(t)%2 == 1 {
		left := pos[len(t)/2-1]
		right := pos[len(t)/2+1]
		symb := t[len(t)/2]

		mx := -1
		for i := l; i <= r; i++ {
			if s[i] == symb {
				mx = max(mx, max(i-left, right-i))
			}
		}
		printf("%d", mx)
	} else {
		mx := pos[len(t)/2] - pos[len(t)/2-1]
		printf("%d", mx)
	}
}

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

func solveD() {}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	//scan(&T)
	for t := 0; t < T; t++ {
		solveC()
	}
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

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

	var n, m int
	var s, t string
	fmt.Fscan(in, &n, &m)
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &t)

	maxWidth := 0
	positions := make([]int, m)
	for i, j := 0, 0; j < m; j++ {
		for ; s[i] != t[j]; i++ {
		}
		positions[j] = i
		if j > 0 && positions[j]-positions[j-1] > maxWidth {
			maxWidth = positions[j] - positions[j-1]
		}
	}
	for i, j := n-1, m-1; j >= 0; j-- {
		for ; s[i] != t[j]; i-- {
		}
		positions[j] = i
		if j > 0 && positions[j]-positions[j-1] > maxWidth {
			maxWidth = positions[j] - positions[j-1]
		}
	}

	fmt.Println(maxWidth)
}

package main

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

func main() {

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

	var n, m int
	fmt.Fscan(in, &n, &m)
	var s, t string
	fmt.Fscan(in, &s, &t)

	l := make([]int, m)
	r := make([]int, m)

	j := 0
	for i := 0; i < m; i++ {
		for s[j] != t[i] {
			j++
		}
		l[i] = j
	}
	j = n - 1
	for i := m - 1; i >= 0; i-- {
		for s[j] != t[i] {
			j--
		}
		r[i] = j
	}

	res := 0
	for i := 0; i < m - 1; i++ {
		x := r[i + 1] - l[i]
		if x > res {
			res = x
		}
	}
	fmt.Fprintln(out, res)
}


package main

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

func min(a,b int)int {
    var res int;
    if a<b {
        res=a
    } else {
        res=b;
    }
    return res;
}

func solve(){
    var n,i,odd,even,x,ans int
    n=readInt()
    odd=0
    even=0
    for i=0;i<n;i++ {
        x=readInt()
        if x%2==1 {
            odd++
        } else {
            even++;
        }
    }
    ans=min(odd,even);
    odd-=ans;
    ans+=odd/3;
    fmt.Println(ans)
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}
func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import "fmt"
import "bufio"
import "os"

func main() {
    var n, a, ch, nch int
    ch = 0
    nch = 0
    in := bufio.NewReader(os.Stdin)
    fmt.Fscan(in, &n)
    for i:=0; i<n; i++{
        fmt.Fscan(in, &a)
        if (a%2==0){
            ch++;
        }else{
            nch++;
        }
    }
    if(nch<=ch){
        fmt.Printf("%d", nch)
    }else{
        fmt.Printf("%d", ch+(nch-ch)/3)
    }
}

package main

import "fmt"
import "bufio"
import "os"

func main() {
    var n int
    in := bufio.NewReader(os.Stdin)
    fmt.Fscan(in, &n)
    var odd int
    var x int

    for i := 0; i < n; i++{
        fmt.Fscan(in, &x)
        if x%2 == 1{
             odd = odd + 1
        }
    }

    if n  >= 2 * odd{
       fmt.Println(odd)
    }
    if n < 2 * odd{
      var ans int = n-odd+(odd - (n -odd))/3
      fmt.Println(ans)
    }
}

package main

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

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

	var even = 0
	var odd = 0

	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(in, &x)
		if x % 2 == 0 {
			even += 1
		} else {
			odd += 1
		}
	}

	var mn int = 0
	if even < odd {
		mn = even
	} else {
		mn = odd
	}

	var ans int = mn
	odd -= mn
	even -= mn

	if odd > 1 {
		ans += odd / 3
	}

	fmt.Println(ans)
}

package main

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

var qn = 0
var qc = 0

func main() {

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

    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    for o := 0; o < t; o++ {
        scanner.Scan()
        val := toInt(scanner.Bytes())
        if val%2==1 {
            qn++
        } else {
            qc++
        }
    }
	if qc >= qn {
		fmt.Println(qn)
	} else {
		var res = qc
		qn = qn - res
		res = res + qn/3
		fmt.Println(res)
	}
}

func toInt(buf []byte) (n int) {
    for _, v := range buf {
        n = n*10 + int(v-'0')

    }
    return
}

package main

import "fmt"
import "bufio"
import "os"

func main() {
    in := bufio.NewReader(os.Stdin)
	var n int
    fmt.Fscan(in, &n)
    var aa int
	countOdd := 0
	countEven := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &aa)
		if aa % 2 == 1 {
			countOdd++
		} else {
			countEven++
		}
	}
    count := 0
	for {
		if (countOdd == 0) {
			break
		}
		if (countEven > 0) {
			count++
			countOdd--
			countEven--
		} else if (countOdd >= 3) {
			count++;
			countOdd -= 3
		} else {
			break
		}
	}
	fmt.Println(count)
}

package main

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

func main() {
	var n, k1, k2, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
	    fmt.Fscan(in, &a)
	    if a % 2 > 0 {
	        k1++
	    } else {
	        k2++
	    }
	}
	if k1 < k2 {
	    fmt.Print(k1)
	} else {
	    fmt.Print(k2 + (k1 - k2) / 3)
	}
}

package main

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

func main() {
    var n int
    in := bufio.NewReader(os.Stdin)
    fmt.Fscanf(in, "%d\n", &n)
	e, o, jwb := 0, 0, 0
	var x int
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &x)
		if x%2==1 {
		    o += 1
		} else {
		    e += 1
		}
	}
	if e<=o {
	    jwb = e
	    o -= e
	    jwb += o/3
	} else {
	    jwb = o
	}
	fmt.Println(jwb)
}

package main

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

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	x := 0
	e, o, jwb := 0, 0, 0
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &x)
		if x % 2 == 1 {
			o += 1
		} else {
			e += 1
		}
	}
	if e <= o {
		jwb = e
		o -= e
		jwb += o/3
	} else {
		jwb = o
	}
	fmt.Printf("%d\n", jwb)
}

package main

import "fmt"
import "os"
import "bufio"

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

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

	var ji int
	ji = 0
	var ou int
	ou = 0
	var ai int
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ai)
		if ai%2 == 1 {
			ji++
		}
	}
	ou = n - ji
	if ji <= ou {
		fmt.Println(ji)
	} else {
		fmt.Println(ou + (ji-ou)/3)
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func rint(pint *int) {
	fmt.Fscan(in, pint)
}

func main() {
  var n, x int
  b := 0;
  a := 0;
  rint(&n)
  for i:=0; i < n; i++{
    rint(&x)
    if x%2==0{
      a++;
    } else {
      b++;
    }
  }
  if a >= b{
    fmt.Print(b);
  } else {
    c := a;
    c = c + (b - a) / 3;
    fmt.Print(c);
  }
}

package main

import "fmt"
import "bufio"
import "os"

func main() {
	var n, aa, odd, ans, even int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &aa)
	     if aa % 2 == 1 {
	          if even > 0 {
	             even--
	             ans++
	          } else {
	               odd++
	          }

	     } else {
	          if odd > 0 {
	               ans++
	               odd--
	          } else {
	               even++
	          }
	     }
	}
	ans += odd / 3
     fmt.Println(ans)
}

package main

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

func solve() {
    n := readInt()
    a := 0
    b := 0
    x := 0
   for  i := 0; i < n; i++ {
        x = readInt()
        if x % 2 == 0 {
            a++
            }  else{
            b++
            }
    }
 if b <= a{
        fmt.Println(b)
    } else{
       fmt.Println(a + (b - a) / 3)
    }

}
var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

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

func main() {
    var n int
    var a int
    in := bufio.NewReader(os.Stdin)

    fmt.Fscan(in, &n)

    odd := 0
    even := 0

    for i := 0; i < n; i++ {
        fmt.Fscan(in, &a)
        if (a % 2 == 1) {
            odd += 1
        } else {
            even += 1
        }
    }
    if (odd < even) {
        fmt.Printf("%d\n", odd);
    } else {
        fmt.Printf("%d\n", even + (odd - even) / 3);
    }

}

package main

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

func main() {
    ints := getInts()
    var T int
    var chet int
        var nechet int
    T, ints = ints[0], ints[1:]

    for i := 0; i < T; i++ {
		var q int
		q = ints[i]
		if q%2 == 0{
		    chet++;
		    nechet--;
		}
		nechet++;
	}
	if (chet >= nechet){
	    fmt.Println(nechet)
	}else
	{
	    fmt.Println(chet+(nechet-chet)/3)
	}

}

func getInts() []int {
    //assumes POSITIVE INTEGERS. Check v for '-' if you have negative.
    var buf []byte
    buf, _ = ioutil.ReadAll(os.Stdin)
    var ints []int
    num := int(0)
    found := false
    for _, v := range buf {
        if '0' <= v && v <= '9' {
            num = 10*num + int(v - '0') //could use bitshifting here.
            found = true
        } else if found {
            ints = append(ints, num)
            found = false
            num = 0
        }
    }
    if found {
        ints = append(ints, num)
        found = false
        num = 0
    }
    return ints
}

package main

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

var scanner *bufio.Scanner
var t [1e6 + 1]bool

func init_scanner() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024 * 20
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
}

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

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

func main() {
	init_scanner()
	even, odd := 0, 0
	n := readInt()
	for i := 0; i < n; i++ {
		x := readInt()
		if x % 2 == 0 {
			even += 1;
		} else { odd += 1
		}
	}
	if (even > odd) {
	    fmt.Println(odd)
	} else {
	    fmt.Println(even + (odd - even) / 3)
	}
}

package main

import "fmt"
import "bufio"
import "os"

func main() {
	var n int
	var e int = 0
	var o int = 0
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		var k int
		fmt.Fscan(in, &k)
		if k % 2 == 1 {
		    o++
		} else {
		    e++
		}
	}
	var res int
	if (e >= o) {
	    res = o
	} else {
	    res = e + (o - e) / 3;
	}
	fmt.Println(res)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n := toInt(scanner.Bytes())
	a := 0
	b := 0
	for i := 0; i < n; i++ {
		scanner.Scan()
		x := toInt(scanner.Bytes())
		if x % 2 == 1 {
			a++
		} else {
			b++
		}
	}
	if a > b {
		x := (a - b) / 3
		a -= 2 * x
		b += x
		a = b
	}
	fmt.Printf("%d\n", a)
}

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

package main

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

const (
	// times for reading 1 million ints
	useBuffer  = true // 24s   => 2.2s
	useScanner = true // 2.2s  => 450ms
	useBytes   = true // 450ms => 280ms
)

var scanner *bufio.Scanner
var reader io.Reader

func init() {
	if !useBuffer {
		reader = os.Stdin
	} else if !useScanner {
		reader = bufio.NewReader(os.Stdin)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
		scanner.Split(bufio.ScanWords)
	}
}

func readInt() int {
	if !useScanner {
		// good ole fmt.Fscan
		var i int
		if _, err := fmt.Fscan(reader, &i); err != nil {
			die(err)
		}
		return i
	}
	// scan for the next token
	if !scanner.Scan() {
		die(io.ErrUnexpectedEOF)
	}
	if !useBytes {
		// allocate string and let standard library parse
		i, err := strconv.Atoi(scanner.Text())
		if err != nil {
			die(err)
		}
		return i
	}
	// manually parse existing bytes without allocation
	i, err := atoi(scanner.Bytes())
	if err != nil {
		die(err)
	}
	return i
}

func atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func min(a int, b int) int {
 if (a < b){
   return a
 }
 return b
}
func main() {
var n int
fmt.Scan(&n)
a := make([]int, n)
for i := 0; i < n; i++ {
   a[i] = readInt();
}
c := 0
  for i:=0; i < n; i++ {
    if (a[i] % 2 == 1){
      c++
    }
  }
  uc := n - c

  if (c <= uc){
    fmt.Printf("%d\n", c)
    return;
  }

  b := (c-uc) / 3
  c -= b * 3;

  fmt.Printf("%d\n", b + min(uc, c))
}

package main

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

var scanner *bufio.Scanner

func scanner_init() {
    scanner = bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func readInt() int {
	/* scan for the next token */
	if !scanner.Scan() {
		die(io.ErrUnexpectedEOF)
	}
	/* manually parse existing bytes without allocation */
	i, err := atoi(scanner.Bytes())
	if err != nil {
		die(err)
	}
	return i
}

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

func main() {
scanner_init()
var n int
fmt.Scan(&n)
a := make([]int, n)
for i := 0; i < n; i++ {
   a[i] = readInt();
}
c := 0
  for i:=0; i < n; i++ {
    if (a[i] % 2 == 1){
      c++
    }
  }
  uc := n - c

  if (c <= uc){
    fmt.Printf("%d\n", c)
    return;
  }

  b := (c-uc) / 3
  c -= b * 3;

  fmt.Printf("%d\n", b + min(uc, c))
}

package main

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

func solve() {
    var n,odd,even,input int
    n = readInt()
    odd=0
    even=0
    for i := 0; i < n ; i++  {
        input = readInt()
        if(input%2==1){
	        odd++
	}else{
		even++
	}
    }
    if(odd<=even){
        fmt.Println(odd)
    }else {
	fmt.Println(even+(odd-even)/3)
    }
}
var scanner *bufio.Scanner
func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}
func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

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

var scanner *bufio.Scanner = nil

func scanner_init() {
    scanner = bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func readInt() int {
	if scanner == nil {
		scanner_init()
	}
	if !scanner.Scan() {
		die(io.ErrUnexpectedEOF)
	}
	/* manually parse existing bytes without allocation */
	i, err := atoi(scanner.Bytes())
	if err != nil {
		die(err)
	}
	return i
}

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

func main() {
var n int
fmt.Scan(&n)
a := make([]int, n)
for i := 0; i < n; i++ {
   a[i] = readInt();
}
c := 0
  for i:=0; i < n; i++ {
    if (a[i] % 2 == 1){
      c++
    }
  }
  uc := n - c

  if (c <= uc){
    fmt.Printf("%d\n", c)
    return;
  }

  b := (c-uc) / 3
  c -= b * 3;

  fmt.Printf("%d\n", b + min(uc, c))
}

package main

import "fmt"
import "bufio"
import "os"

func toInt(buf []byte) (n int) {
    for _, v := range buf {
        n = n*10 + int(v-'0')
    }
    return
}

func main(){
    var n int
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    scanner.Scan()
    fmt.Sscanf(scanner.Text(), "%d", &n)
    var odd, even int
    odd = 0
    even = 0
    var k int
    for a := 0; a < n; a++{
        scanner.Scan()
        fmt.Sscanf(scanner.Text(), "%d", &k)
        if (k % 2 == 0){
            even++;
        } else {
            odd++;
        }
    }
    if (odd <= even){
        fmt.Println(odd)
    } else {
        fmt.Println(even + (odd - even) / 3)
    }
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func readInt() int {
	// fmt.Println("here")
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := readInt()
	var x int
	var y int
	x = 0
	y = 0
	for i := 0; i < n; i++ {
		value := readInt()
		if value % 2 == 1 {
			x++
		} else {
			y++
		}
	}
	if x <= y {
		fmt.Println(x)
	} else {
		fmt.Println(y + (x - y) / 3)
	}
}

package main
import (
    "bufio"
    "fmt"
    "os"
)

func toInt(buf []byte) (n int) {
    for _, v := range buf {
        n = n*10 + int(v-'0')
    }
    return
}
func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}
func main(){
    var n int
    var odd int = 0
    var even int = 0
    var arr int = 0
    in := bufio.NewReader(os.Stdin)

    fmt.Fscanf(in, "%d\n", &n)
    for ;n > 0; n-- {
        fmt.Fscanf(in, "%d", &arr)
        if  arr%2==0 {
            even++
        }else {
            odd++
        }
    }
    var ans int = min(odd, even)
    odd -= ans
    fmt.Println(ans + odd / 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() {
    defer writer.Flush()
	var n int
	var j int
	var o, e int = 0, 0
	scanf("%d", &n)
	scanf("%d", &j)
	for i := 0; i < n; i++ {
		var s int

		scanf("%d", &s)
		if s % 2 == 0 {
			e = e + 1
		} else {
			o = o + 1
		}

	}

	if e > o{
	    printf("%d", o)
	} else {
	    printf("%d", e + ((o - e) / 3))
	}

}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var ji int
	ji = 0
	var ou int
	ou = 0
	var ai int
	for i := 0; i < n; i++ {
		fmt.Scan(&ai)
		if ai % 2==0 {
			ji++
		} else {
			ou++
		}
	}
	if ji <= ou {
		fmt.Println(ji)
	} else {
		fmt.Println(ou + (ji-ou)/3)
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := 0
	b := 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		if x % 2 == 1 {
			a++
		} else {
			b++
		}
	}
	if a > b {
		a = b
	}
	fmt.Printf("%d", a)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
	n := toInt(scanner.Bytes())
	a := 0
	b := 0
	for i := 0; i < n; i++ {
		x := toInt(scanner.Bytes())
		if x % 2 == 1 {
			a++
		} else {
			b++
		}
	}
	if a > b {
		x := (a - b) / 3
		a -= 2 * x
		b += x
		a = b
	}
	fmt.Printf("%d", a)
}

func toInt(buf []byte) (n int) {
    for _, v := range buf {
        n = n*10 + int(v-'0')
    }
    return
}

package main
import "fmt"

func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}
func Even(number int) bool {
    return number%2 == 0
}
func main(){
	var n int
    fmt.Scanf("%d", &n)
    var arr int
    var odd int
    var even int
    for i := 0; i < n; i++ {
        fmt.Scanf("%d", &arr)
        if Even(arr) { odd++}
        if !Even(arr) { even++}
    }
    fmt.Println(min(odd, even))
}

package main
import "fmt"

func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}
func Even(number int) bool {
    return number%2 == 0
}
func main(){
	var n int
    fmt.Scanf("%d", &n)
    var arr int = 0
    var odd int = 0
    var even int = 0
    for i := 0; i <= n; i++ {
        fmt.Scanf("%d", &arr)
        if arr%2==1 {odd++}
        if arr%2==0 {even++}
    }
    even--;
    fmt.Println(min(odd, even))
}

package main
import (
    "bufio"
    "fmt"
    "os"
)

func toInt(buf []byte) (n int) {
    for _, v := range buf {
        n = n*10 + int(v-'0')
    }
    return
}
func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}
func main(){
    var n int
    var odd int = 0
    var even int = 0
    var arr int = 0
    in := bufio.NewReader(os.Stdin)

    fmt.Fscanf(in, "%d\n", &n)
    fmt.Fscanf(in, "%d", &arr)
    for ;n > 0; n-- {
        fmt.Fscanf(in, " %d", &arr)
        if  arr%2==0 {
            even++
        }else {
            odd++
        }
    }
    var ans int = min(odd, even)
    odd -= ans
    fmt.Println(ans + odd / 3)
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    var odd int
    var x int

    for i := 0; i < n; i++{
        fmt.Scan(&x)
        if x%2 == 1{
             odd = odd + 1
        }
    }

    if n  >= 2 * odd{
       fmt.Println(odd)
    }
    if n < 2 * odd{
      var ans int = n-odd+odd/3
      fmt.Println(ans)
    }
}

package main

import "fmt"
import "bufio"
import "os"
func main() {
    var n int
    fmt.Scan(&n)
    var odd int
    var x int
    scanner := bufio.NewScanner(os.Stdin)
    for i := 0; i < n; i++{
        scanner.Scan()
        fmt.Sscanf(scanner.Text(), "%d", &x)
        if x&1 == 1{
             odd = odd + 1
        }
    }

    if n  >= 2 * odd{
       fmt.Println(odd)
    }
    if n < 2 * odd{
      var ans int = n-odd+(odd - (n -odd))/3
      fmt.Println(ans)
    }
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)
	fmt.Println(n)

	var even = 0
	var odd = 0

	for i := 0; i < n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		fmt.Println(x)
		if x % 2 == 0 {
			even += 1
		} else {
			odd += 1
		}
	}

	var mn int = 0
	if even < odd {
		mn = even
	} else {
		mn = odd
	}

	var ans int = mn
	odd -= mn
	even -= mn

	if odd > 1 {
		ans += odd / 3
	}

	// fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	aa := make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&aa[i])
	}
	count := 0
	for i := 0; i < n; i++ {
		if (aa[i] >= 2 && aa[i] % 2 == 1) {
			count++
		}
	}
	fmt.Println(count)
}

package main

import "fmt"

func main() {
  var n, a, b, x int
  b = 0;
  a = 0;
  fmt.Scanf("%d", &n)
  for i:=0; i < n; i++{
    fmt.Scanf("%d", &x)
    if x%2==0{
      a++;
    } else {
      b++;
    }
  }
  if a >= b{
    fmt.Printf("%d\n", b);
  } else {
    var c int
    c = a;
    c = c + (b - a) / 3;
    fmt.Printf("%d\n", c);
  }
}

package main

import "fmt"

func main() {
  var n, a, b, x int
  b = 0;
  a = 0;
  fmt.Scan(&n)
  for i:=0; i < n; i++{
    fmt.Scan("%d", &x)
    if x%2==0{
      a++;
    } else {
      b++;
    }
  }
  if a >= b{
    fmt.Print(b);
  } else {
    var c int
    c = a;
    c = c + (b - a) / 3;
    fmt.Print(c);
  }
}

package main

import "fmt"

func main() {
  var n, a, b int
  var q [100000]int
  b = 0;
  a = 0;
  fmt.Scan(&n)
  for i:=0; i < n; i++{
    fmt.Scan("%d", &q[i])
    if q[i]%2==0{
      a++;
    } else {
      b++;
    }
  }
  if a >= b{
    fmt.Print(b);
  } else {
    var c int
    c = a;
    c = c + (b - a) / 3;
    fmt.Print(c);
  }
}

package main

import "fmt"

func main() {
  var n, a, b, x int
  b = 0;
  a = 0;
  fmt.Scanf("%d", &n)
  for i:=0; i < n; i++{
    fmt.Scanf("%d", &x)
    if x%2==0{
      a++;
    } else {
      b++;
    }
  }
  if a >= b{
    fmt.Printf("%d", b);
  } else {
    var c int
    c = a;
    c = c + (b - a) / 3;
    fmt.Printf("%d", c);
  }
}

package main

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

var scanner *bufio.Scanner
var t [1e6 + 1]bool

func init_scanner() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024 * 20
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
}

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

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

func main() {
	init_scanner()
	even, odd := 0, 0
	n := readInt()
	for i := 0; i < n; i++ {
		x := readInt()
		if x % 2 == 0 {
			even += 1;
		} else { odd += 1
		}
	}
	if (even > odd) {
	    fmt.Println(odd)
	} else {
	    fmt.Println(even)
	}
}

package main
import "fmt"

func main() {
    var n,ans, input int
    fmt.Scanf("%d\n", &n)
    ans=0
    for i := 0; i < n ; i++  {
        fmt.Scanf("%d", &input)
        if(input%2==1){ans++}
    }
    fmt.Println(ans)
}

package main

import "fmt"

func main() {
    var n, a, ch, nch int
    ch = 0
    nch = 0

    fmt.Scan(&n)
    for i:=0; i<n; i++{
        fmt.Scan(&a)
        if (a%2==0){
            ch++;
        }else{
            nch++;
        }
    }
    if(nch<=ch){
        fmt.Println(nch)
    }else{
        fmt.Println(ch+(nch-ch)/2)
    }
}

package main

import (
	"fmt"
)

func main() {
    var n int
    fmt.Scanf("%d", &n)
	var x, jwb int
	jwb = 0
	for i := 0; i <= n; i++ {
		fmt.Scanf("%d", &x)
		if x%2==1 {
		    jwb = jwb + 1
		}
	}
	fmt.Println(jwb)
}

package main

import (
	"fmt"
)

func main() {
    var n int
    fmt.Scanf("%d", &n)
	var x, e, o int
	e = 0
	o = 0
	for i := 0; i <= n; i++ {
		fmt.Scanf("%d", &x)
		if x%2==1 {
		    o = o + 1
		} else {
		    e = e + 1
		}
	}
	e = e - 1
	var jwb int
	if e<=o {
	    jwb = e
	}
	if (o<e) {
	    jwb = o
	}
	fmt.Println(jwb)
}

package main

import "fmt"

func main() {
	var n, aa, odd, ans int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&aa)
	     if aa % 2 == 1 {
	          odd++
	     } else {
	          if odd > 0 {
	               ans++
	               odd--
	          }
	     }
	}
	ans += odd / 3
     fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var n int
	var e int = 0
	var o int = 0
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var k int
		fmt.Scan(&k)
		if k % 2 == 1 {
		    o++
		} else {
		    e++
		}
	}
	var res int
	if (o > e) {
	    res = e
	} else {
	    res = o
	}
	fmt.Println(res)
}

package main

import "fmt"

func main() {
var n int
fmt.Scan(&n)
a := make([]int, n, n)
for i := 0; i < n; i++ {
   fmt.Scan(&a[i])
}
c := 0
  for i:=0; i < n; i++ {
    if (a[i] % 2 == 1){
      c++
    }
  }
  if (2*c < n) {
    fmt.Printf("%d\n", c)
    return;
  }
  uc := n - c
  ans := 0
  for c < uc {
    c -= 3
    ans++
  }
  fmt.Printf("%d\n", ans+c)
}

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() {
    defer writer.Flush()
	var n int
	var o, e int = 0, 0
	scanf("%d", &n)
	for i := 0; i < n; i++ {
		var s int

		scanf("%d", &s)
		if s % 2 == 0 {
			e = e + 1
		} else {
			o = o + 1
		}
	}
	if e > o{
	    printf("%d", o)
	} else {
	    printf("%d", e + ((o - e) / 3))
	}

}


package main

import "fmt"
import "bufio"
import "os"

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

	var n int
	fmt.Fscanf(buf, "%d\n", &n)

	a := make([]int, n+1)
	b := make([]int, n+1)
	p := make([]int64, n+1)

	const mod = int64(1000000007)
	p[0] = 1

	for i := 1; i <= n; i++ {
		fmt.Fscanf(buf, "%d\n", &a[i])
		b[i] = -1
		p[i] = (p[i-1] * 2) % mod
	}

	result := int64(1)
	remain := n

	step := 0
	for i := 1; i <= n; i++ {
		if b[i] == -1 {
			step++
			j := i
			for b[j] == -1 {
				b[j] = step
				j = a[j]
			}

			if b[j] == step {
				cnt := 1
				for k := a[j]; k != j; k = a[k] {
					cnt++
				}
				result = result * (p[cnt] - 2) % mod
				remain -= cnt
			}
		}
	}

	result = (result * p[remain]) % mod
	fmt.Printf("%d\n", result)
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

const (
	MOD   = 1000000007
	MAX_N = 200010
)

var A [MAX_N][]int
var deg [MAX_N]int
var num, cnt int
var done [MAX_N]bool

func dfs(v int) {
	done[v] = true
	num++
	if deg[v] >= 1 {
		cnt++
	}
	for _, next := range A[v] {
		if !done[next] {
			dfs(next)
		}
	}
}

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	for i := 0; i < N; i++ {
		a := fsc.NextInt()
		a--
		A[i] = append(A[i], a)
		A[a] = append(A[a], i)
		deg[i]++
		deg[a]++
	}
	//fmt.Println(A[:N], len(A), len(A[0]))
	queue := list.New()
	for i := 0; i < N; i++ {
		if deg[i] == 1 {
			queue.PushBack(i)
			deg[i] = 0
		}
	}
	for queue.Len() > 0 {
		pos := queue.Remove(queue.Front())
		switch p := pos.(type) {
		case int:
			for _, v := range A[p] {
				if deg[v] == 0 {
					continue
				}
				deg[v]--
				if deg[v] == 1 {
					deg[v] = 0
					queue.PushBack(v)
				}
			}
		}
	}
	ans := int64(1)

	for i := 0; i < N; i++ {
		if done[i] {
			continue
		}
		num, cnt = 0, 0
		dfs(i)

		tmp := int64(1)
		for j := 0; j < num; j++ {
			tmp *= 2
			tmp %= MOD
		}
		minus := int64(1)
		for j := 0; j < num-cnt+1; j++ {
			minus *= 2
			minus %= MOD
		}
		tmp = (tmp - minus + MOD) % MOD
		ans *= tmp
		ans %= MOD
		//fmt.Println(num, cnt)
	}
	fmt.Println(ans)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	return &FastScanner{r: rdr}
}

func (s *FastScanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}

func (s *FastScanner) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) NextInt64() int64 {
	val, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}

func (s *FastScanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

const (
	MOD   = 1000000007
	MAX_N = 200010
)

var A [MAX_N][]int
var deg [MAX_N]int
var num, cnt int
var done [MAX_N]bool

func dfs(v int) {
	done[v] = true
	num++
	if deg[v] >= 1 {
		cnt++
	}
	for _, next := range A[v] {
		if !done[next] {
			dfs(next)
		}
	}
}

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	for i := 0; i < N; i++ {
		a := fsc.NextInt()
		a--
		A[i] = append(A[i], a)
		A[a] = append(A[a], i)
		deg[i]++
		deg[a]++
	}
	//fmt.Println(A[:N], len(A), len(A[0]))
	queue := list.New()
	for i := 0; i < N; i++ {
		if deg[i] == 1 {
			queue.PushBack(i)
			deg[i] = 0
		}
	}
	for queue.Len() > 0 {
		pos := queue.Remove(queue.Front())
		switch p := pos.(type) {
		case int:
			for _, v := range A[p] {
				if deg[v] == 0 {
					continue
				}
				deg[v]--
				if deg[v] == 1 {
					deg[v] = 0
					queue.PushBack(v)
				}
			}
		}
	}
	ans := 1

	for i := 0; i < N; i++ {
		if done[i] {
			continue
		}
		num, cnt = 0, 0
		dfs(i)

		tmp := 1
		for j := 0; j < num; j++ {
			tmp *= 2
			tmp %= MOD
		}
		minus := 1
		for j := 0; j < num-cnt+1; j++ {
			minus *= 2
			minus %= MOD
		}
		tmp = (tmp - minus + MOD) % MOD
		ans *= tmp
		ans %= MOD
		//fmt.Println(num, cnt)
	}
	fmt.Println(ans)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	return &FastScanner{r: rdr}
}

func (s *FastScanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}

func (s *FastScanner) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) NextInt64() int64 {
	val, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}

func (s *FastScanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

const (
	MOD   = 1000000007
	MAX_N = 200010
)

var A [][]int
var visited [MAX_N]int
var src int
var cnt int
var node int
var multiCnt [MAX_N]map[int]int

func dfs(pos, pre int) {
	visited[pos] = 1
	node++
	for _, next := range A[pos] {
		if next != pre || multiCnt[pos][next] == 2 {
			if visited[next] == 1 { //find cycle
				src = next
			} else if visited[next] == 0 {
				dfs(next, pos)
			}
		}
	}
	visited[pos] = 2
	if src != -1 {
		cnt++
	}
	if src == pos {
		src = -1
	}

}
func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	A = make([][]int, N)
	for i := 0; i < N; i++ {
		multiCnt[i] = map[int]int{}
	}
	//fmt.Println(deg[0][0])
	//fmt.Println(deg)
	for i := 0; i < N; i++ {
		a := fsc.NextInt()
		a--
		A[i] = append(A[i], a)
		A[a] = append(A[a], i)
		multiCnt[i][a]++
		multiCnt[a][i]++
	}

	var ans int
	ans = 1
	for i := 0; i < N; i++ {
		if visited[i] == 0 {
			src = -1
			node = 0
			cnt = 0
			var res1, res2 int
			res1, res2 = 1, 1
			dfs(i, -1)
			//fmt.Println(node, cnt, src)
			for i := 0; i < node; i++ {
				res1 *= 2
				res1 %= MOD
			}
			for i := 0; i < node-cnt+1; i++ {
				res2 *= 2
				res2 %= MOD
			}
			res1 -= res2
			for res1 < 0 {
				res1 += MOD
			}
			ans *= res1
			ans %= MOD
			//fmt.Println(cnt)
		}
	}
	fmt.Println(ans)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	return &FastScanner{r: rdr}
}

func (s *FastScanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}

func (s *FastScanner) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) NextInt64() int64 {
	val, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}

func (s *FastScanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

const (
	MOD   = 1000000007
	MAX_N = 200010
)

var A [][]int
var visited [MAX_N]int
var src int
var cnt int
var node int
var multiCnt [MAX_N]map[int]int

func dfs(pos, pre int) {
	visited[pos] = 1
	node++
	cycle := -1
	for _, next := range A[pos] {
		if next != pre {
			if visited[next] == 1 { //find cycle
				cycle = next
			} else if visited[next] == 0 {
				dfs(next, pos)
			}
		} else if multiCnt[pos][next] == 2 {
			cnt = 2
		}
	}
	if cycle != -1 {
		src = cycle
	}
	visited[pos] = 2
	if src != -1 {
		cnt++
	}
	if src == pos {
		src = -1
	}

}
func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	A = make([][]int, N)
	for i := 0; i < N; i++ {
		multiCnt[i] = map[int]int{}
	}
	//fmt.Println(deg[0][0])
	//fmt.Println(deg)
	for i := 0; i < N; i++ {
		a := fsc.NextInt()
		a--
		A[i] = append(A[i], a)
		A[a] = append(A[a], i)
		multiCnt[i][a]++
		multiCnt[a][i]++
	}

	var ans int64
	ans = 1
	for i := 0; i < N; i++ {
		if visited[i] == 0 {
			src = -1
			node = 0
			cnt = 0
			var res1, res2 int64
			res1, res2 = 1, 1
			dfs(i, -1)
			//fmt.Println(node, cnt, src)
			for i := 0; i < node; i++ {
				res1 *= 2
				res1 %= MOD
			}
			for i := 0; i < node-cnt+1; i++ {
				res2 *= 2
				res2 %= MOD
			}
			res1 -= res2
			for res1 < 0 {
				res1 += MOD
			}
			ans *= res1
			ans %= MOD
			//fmt.Println(cnt)
		}
	}
	fmt.Println(ans)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	return &FastScanner{r: rdr}
}

func (s *FastScanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}

func (s *FastScanner) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) NextInt64() int64 {
	val, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}

func (s *FastScanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

const (
	MOD   = 1000000007
	MAX_N = 200010
)

var A [][]int
var visited [MAX_N]int
var src int
var cnt int

func dfs(pos, pre int) {
	visited[pos] = 1
	for _, next := range A[pos] {
		if next == pre {
			continue
		}
		if visited[next] == 1 { //find cycle
			src = next
		} else if visited[next] == 0 {
			dfs(next, pos)
		}
	}
	visited[pos] = 2
	if src != -1 {
		cnt++
	}
	if src == pos {
		src = -1
	}

}
func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	A = make([][]int, N)

	deg := make([]map[int]int, N)
	for i := 0; i < N; i++ {
		deg[i] = map[int]int{}
	}
	//fmt.Println(deg[0][0])
	//fmt.Println(deg)
	isMulti := false
	for i := 0; i < N; i++ {
		a := fsc.NextInt()
		a--
		A[i] = append(A[i], a)
		A[a] = append(A[a], i)
		deg[i][a]++
		deg[a][i]++
		if deg[i][a] >= 2 || deg[a][i] >= 2 {
			isMulti = true
		}
	}

	src = -1
	if !isMulti {
		dfs(0, -1)
	} else {
		cnt = 2
	}
	//fmt.Println(cnt)
	var res1, res2 int
	res1, res2 = 1, 1
	for i := 0; i < N; i++ {
		res1 *= 2
		res1 %= MOD
	}
	for i := 0; i < N-cnt+1; i++ {
		res2 *= 2
		res2 %= MOD
	}
	res1 -= res2
	for res1 < 0 {
		res1 += MOD
	}
	fmt.Println(res1)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	return &FastScanner{r: rdr}
}

func (s *FastScanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}

func (s *FastScanner) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) NextInt64() int64 {
	val, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}

func (s *FastScanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

const (
	MOD   = 1000000007
	MAX_N = 200010
)

var A [][]int
var visited [MAX_N]int
var src int
var cnt int
var node int
var multiCnt [MAX_N]map[int]int

func dfs(pos, pre int) {
	visited[pos] = 1
	node++
	cycle := -1
	for _, next := range A[pos] {
		if next != pre {
			if visited[next] == 1 { //find cycle
				cycle = next
			} else if visited[next] == 0 {
				dfs(next, pos)
			}
		} else if multiCnt[pos][next] == 2 {
			cnt = 2
		}
	}
	if cycle != -1 {
		src = cycle
	}
	visited[pos] = 2
	if src != -1 {
		cnt++
	}
	if src == pos {
		src = -1
	}

}
func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	A = make([][]int, N)
	for i := 0; i < N; i++ {
		multiCnt[i] = map[int]int{}
	}
	//fmt.Println(deg[0][0])
	//fmt.Println(deg)
	for i := 0; i < N; i++ {
		a := fsc.NextInt()
		a--
		A[i] = append(A[i], a)
		A[a] = append(A[a], i)
		multiCnt[i][a]++
		multiCnt[a][i]++
	}

	var ans int
	ans = 1
	for i := 0; i < N; i++ {
		if visited[i] == 0 {
			src = -1
			node = 0
			cnt = 0
			var res1, res2 int
			res1, res2 = 1, 1
			dfs(i, -1)
			//fmt.Println(node, cnt, src)
			for i := 0; i < node; i++ {
				res1 *= 2
				res1 %= MOD
			}
			for i := 0; i < node-cnt+1; i++ {
				res2 *= 2
				res2 %= MOD
			}
			res1 -= res2
			for res1 < 0 {
				res1 += MOD
			}
			ans *= res1
			ans %= MOD
			//fmt.Println(cnt)
		}
	}
	fmt.Println(ans)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	return &FastScanner{r: rdr}
}

func (s *FastScanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}

func (s *FastScanner) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) NextInt64() int64 {
	val, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}

func (s *FastScanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

const (
	MOD   = 1000000007
	MAX_N = 200010
)

var A [][]int
var visited [MAX_N]int
var src int
var cnt int
var node int
var multiCnt [MAX_N]map[int]int

func dfs(pos, pre int) {
	visited[pos] = 1
	node++
	for _, next := range A[pos] {
		if next != pre {
			if visited[next] == 1 { //find cycle
				src = next
			} else if visited[next] == 0 {
				dfs(next, pos)
			}
		} else if multiCnt[pos][next] == 2 {
			cnt = 2
		}
	}
	visited[pos] = 2
	if src != -1 {
		cnt++
	}
	if src == pos {
		src = -1
	}

}
func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	A = make([][]int, N)
	for i := 0; i < N; i++ {
		multiCnt[i] = map[int]int{}
	}
	//fmt.Println(deg[0][0])
	//fmt.Println(deg)
	for i := 0; i < N; i++ {
		a := fsc.NextInt()
		a--
		A[i] = append(A[i], a)
		A[a] = append(A[a], i)
		multiCnt[i][a]++
		multiCnt[a][i]++
	}

	var ans int
	ans = 1
	for i := 0; i < N; i++ {
		if visited[i] == 0 {
			src = -1
			node = 0
			cnt = 0
			var res1, res2 int
			res1, res2 = 1, 1
			dfs(i, -1)
			//fmt.Println(node, cnt, src)
			for i := 0; i < node; i++ {
				res1 *= 2
				res1 %= MOD
			}
			for i := 0; i < node-cnt+1; i++ {
				res2 *= 2
				res2 %= MOD
			}
			res1 -= res2
			for res1 < 0 {
				res1 += MOD
			}
			ans *= res1
			ans %= MOD
			//fmt.Println(cnt)
		}
	}
	fmt.Println(ans)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	return &FastScanner{r: rdr}
}

func (s *FastScanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}

func (s *FastScanner) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) NextInt64() int64 {
	val, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}

func (s *FastScanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}