package main

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

func main() {

    inputString := scanString()
    start, end := 0, len(inputString) - 1
    firstArray := []int{}
	secondArray := []int{}

	for start < end{
		for start < end && inputString[start] != '('{
			start++
		}
		for start < end && inputString[end] != ')'{
			end--
		}
		if start >= end{
			break
		}
		firstArray = append(firstArray, start+1)
		secondArray = append(secondArray, end+1)
		start++
		end--
	}

	sort.Ints(firstArray)
	sort.Ints(secondArray)

	if len(firstArray) == 0{
		printFmt(0)
	}else{
		printFmt(1)
		printFmt(len(firstArray)+len(secondArray))
		fmt.Print(spaceSeperatedStringFromArray(firstArray), spaceSeperatedStringFromArray(secondArray))
	}

	close(channelType)
	oWg.Wait()
}

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

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			writer.WriteString(line + "\n")
		}
	}()
}

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if (a == 0) {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}

/*
URL:
https://codeforces.com/problemset/problem/1305/B
*/

package main

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

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

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

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

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

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

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

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

var (
	S []rune
	n int
)

func main() {
	S = ReadRuneSlice()
	n = len(S)

	A := []int{}
	l, r := 0, n-1
	for l < r {
		for l < n && S[l] != '(' {
			l++
		}

		for r >= 0 && S[r] != ')' {
			r--
		}

		if l < r {
			A = append(A, l+1, r+1)
			l++
			r--
		} else {
			break
		}
	}

	sort.Sort(sort.IntSlice(A))

	if len(A) == 0 {
		fmt.Println(0)
		return
	}

	fmt.Println(1)
	fmt.Println(len(A))
	fmt.Println(PrintIntsLine(A...))
}

func solve() {
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

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

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

	ans := [][]int{}
	for {
		n := len(s)
		used := make([]bool, n)
a := []int{}
		i := 0
		j:=n-1
		for {
			for ; i < n; i++ {
				if s[i] == '(' {
					break
				}
			}
			for ;j>=0;j-- {
				if s[j] ==')' {
					break
				}
			}
			if i<j {
				used[i]=true
				used[j]=true
				a = append(a, i,j)
				i++
				j--
			} else {
				break
			}
		}
		if len(a) == 0 {
			break
		}
		sort.Ints(a)
		ans = append(ans, a)
		newS := []byte{}
		for i, b := range used {
			if !b {
				newS = append(newS, s[i])
			}
		}
s=newS
//println(string(s))
		//cl := make([]int, n)
		//cr := make([]int, n)
		//for i, b := range s {
		//	if i == 0 {
		//		if b == '(' {
		//			cl[0]=1
		//		}
		//	} else {
		//		cl[i] =cl[i-1]
		//		if b == '(' {
		//			cl[i]++
		//		}
		//	}
		//}
		//for i := n - 1; i >= 0; i-- {
		//	b := s[i]
		//	if i == n-1 {
		//		if b == ')' {
		//			cr[n-1]=1
		//		}
		//	} else {
		//		cr[i] =cr[i+1]
		//		if b == ')' {
		//			cr[i]++
		//		}
		//	}
		//}
		//ans := 0
		//for i := range s {
		//	if cl[i]<cr[i] {
		//		ans=cl[i]
		//	} else {
		//		break
		//	}
		//}
		//for i, b := range s {
		//	if b=='(' {
		//
		//	}
		//}
	}

	Fprintln(out, len(ans))
	for _, a := range ans {
		Fprintln(out, len(a))
		for i, v := range a {
			if i > 0 {
				Fprint(out, " ")
			}
			Fprint(out, v+1)
		}
		Fprintln(out)
	}

}

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

package main

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

func main() {
	s := ScanWord()
	i := getSimpleIndex(s)
	sort.Ints(i)
	if len(i) == 0 {
		P(0)
	} else {
		P(1)
		P(len(i))
		P(SArr(i))
	}

	close(O)
	oWg.Wait()
}

func getSimpleIndex(s string) []int {
	openP := make([]int, 0, len(s))
	closeP := make([]int, 0, len(s))

	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			openP = append(openP, i)
		} else if s[i] == ')' {
			closeP = append(closeP, i)
		}
	}

	left, right := 0, len(closeP)-1
	openIndex := []int{}
	closeIndex := []int{}

	for left < len(openP) && right >= 0 && openP[left] < closeP[right] {
		openIndex = append(openIndex, openP[left]+1)
		closeIndex = append(closeIndex, closeP[right]+1)
		left++
		right--
	}
	r := append(openIndex, closeIndex...)
	return r
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main
import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var s string
	fmt.Fscan(r, &s)
	a := make([]int, 0, len(s))
	b := make([]int, 0, len(s))
	for i, e := range s {
		if e == '(' {
			a = append(a, i)
		}
		if s[len(s)-i-1] == ')' {
			b = append(b, len(s)-i-1)
		}
	}
	c := make([]int, 0, len(s))
	for i , j := 0, 0; i < len(a) && j < len(b) && a[i] < b[j];i, j = i + 1, j + 1 {
		c = append(c, a[i]+1, b[j]+1)
	}
	if len(c) == 0 {
		fmt.Fprintln(w, "0")
		return
	}
	sort.Ints(c)
	fmt.Fprintln(w, 1)
	fmt.Fprintln(w, len(c))
	for i, e := range c {
		if i == 0 {
			fmt.Fprint(w, e)
		} else {
			fmt.Fprint(w," ", e)
		}
	}
	fmt.Fprintln(w)
}

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 main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, 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(inf, 1000010)

	s := NextBytes()
	n := len(s)
	var l, r int
	left := make([]int, 0, n)
	right := make([]int, 0, n)
	result := make([][]int, 0)
	for {
		for l, r = 0, n-1; l < r; {
			for l < r && s[l] != '(' {
				l++
			}
			for l < r && s[r] != ')' {
				r--
			}
			if l < r && s[l] == '(' && s[r] == ')' {
				left = append(left, l)
				right = append(right, r)
				l++
				r--
			} else {
				break
			}
		}
		if len(left) > 0 {
			// stderr("part", string(s), "left", left, "right", right)
			t := make([]int, len(left)+len(right))
			for i, pos := range left {
				t[i] = pos
			}
			for i := len(right) - 1; i >= 0; i-- {
				t[len(left)+len(right)-i-1] = right[i]
			}
			result = append(result, t)

			nl := 0
			for i, l, r := 0, 0, len(right)-1; i < n; i++ {
				for l < len(left) && left[l] < i {
					l++
				}
				for l == len(left) && r >= 0 && right[r] < i {
					r--
				}
				if l < len(left) && left[l] == i || l == len(left) && r >= 0 && right[r] == i {
					continue
				}
				s[nl] = s[i]
				nl++
			}
			s = s[:nl]
			n = nl
			// stderr(string(s))
			left = left[:0]
			right = right[:0]
		} else {
			break
		}
	}

	fmt.Fprintln(out, len(result))
	for _, ar := range result {
		fmt.Fprintln(out, len(ar))
		for _, pos := range ar {
			fmt.Fprint(out, pos+1, " ")
		}
		fmt.Fprintln(out)
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line := readLine(reader)
	i, j := 0, len(line)-1
	ops := 0
	result := make([]int, 0)
	for i < j && i < len(line) && j >= 0 {
		for i <= len(line)-1 && line[i] == ')'  {
			i++
		}
		for j >= 0 && line[j] == '(' {
			j--
		}
		if i < j && i < len(line) && j >= 0 {
			ops += 2
			result = append(result, i+1, j+1)
			i++
			j--
		}
	}
	if ops == 0 {
		fmt.Println(0)
		return
	}
	fmt.Println(1)
	fmt.Println(ops)
	sort.Ints(result)
	for _, i := range result {
		fmt.Printf("%d ", i)
	}
}

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line := readLine(reader)
	i,j := 0, len(line)-1
	ops := 0
	result := make([]int, 0)
	for i<j {
		for line[i] == ')' && i <= len(line)-1{
			i++
		}
		for line[j] == '(' && j >= 0{
			j--
		}
		if i < j && i < len(line) && j >=0 {
			ops += 2
			result = append(result, i+1, j+1)
			i++
			j--
		}
	}
	fmt.Println(ops)
	sort.Ints(result)
	for _, i := range result {
		fmt.Printf("%d ", i)
	}
}

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

package main

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

func main() {
	s := ScanWord()
	i := getSimpleIndex(s)
	if len(i) == 0 {
		P(0)
	} else {
		P(1)
		P(len(i))
		P(SArr(i))
	}

	close(O)
	oWg.Wait()
}

func getSimpleIndex(s string) []int {
	openP := make([]int, 0, len(s))
	closeP := make([]int, 0, len(s))

	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			openP = append(openP, i)
		} else if s[i] == ')' {
			closeP = append(closeP, i)
		}
	}

	left, right := 0, len(closeP)-1
	openIndex := []int{}
	closeIndex := []int{}

	for left < len(openP) && right >= 0 {
		openIndex = append(openIndex, openP[left]+1)
		closeIndex = append(closeIndex, closeP[right]+1)
		left++
		right--
	}
	r := append(openIndex, closeIndex...)
	return r
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	s := ScanWord()
	i := getSimpleIndex(s)
	if len(i) == 0 {
		P(0)
	} else {
		P(1)
		P(len(i))
		P(SArr(i))
	}

	close(O)
	oWg.Wait()
}

func getSimpleIndex(s string) []int {
	openP := make([]int, 0, len(s))
	closeP := make([]int, 0, len(s))

	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			openP = append(openP, i)
		} else if s[i] == ')' {
			closeP = append(closeP, i)
		}
	}

	left, right := 0, len(closeP)-1
	openIndex := []int{}
	closeIndex := []int{}

	for left < len(openP) && right >= 0 && openP[left] < closeP[right] {
		openIndex = append(openIndex, openP[left]+1)
		closeIndex = append(closeIndex, closeP[right]+1)
		left++
		right--
	}
	r := append(openIndex, closeIndex...)
	return r
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {

    inputString := scanString()
    start, end := 0, len(inputString) - 1
    firstArray := []int{}
	secondArray := []int{}

	for start < end{
		for start < end && inputString[start] != '('{
			start++
		}
		for start < end && inputString[end] != ')'{
			end--
		}
		if start >= end{
			break
		}
		firstArray = append(firstArray, start+1)
		secondArray = append(secondArray, end+1)
		start++
		end--
	}

	if len(firstArray) == 0{
		printFmt(0)
	}else{
		printFmt(1)
		printFmt(len(firstArray)+len(secondArray))
		fmt.Print(spaceSeperatedStringFromArray(firstArray), spaceSeperatedStringFromArray(secondArray))
	}

	close(channelType)
	oWg.Wait()
}

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

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			writer.WriteString(line + "\n")
		}
	}()
}

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if (a == 0) {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}

package main
import (
	"bufio"
	"fmt"
	"os"
)
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var s string
	fmt.Fscan(r, &s)
	a := make([]int, 0, len(s))
	b := make([]int, 0, len(s))
	for i, e := range s {
		if e == '(' {
			a = append(a, i)
		}
		if s[len(s)-i-1] == ')' {
			b = append(b, len(s)-i-1)
		}
	}
	c := make([]int, 0, len(s))
	for i , j := 0, 0; i < len(a) && j < len(b) && a[i] < b[j];i, j = i + 1, j + 1 {
		c = append(c, a[i]+1, b[j]+1)
	}
	if len(c) == 0 {
		fmt.Fprintln(w, "0")
		return
	}
	fmt.Fprintln(w, len(c)/2)
	fmt.Fprintln(w, len(c))
	for i, e := range c {
		if i == 0 {
			fmt.Fprint(w, e)
		} else {
			fmt.Fprint(w," ", e)
		}
	}
	fmt.Fprintln(w)
}

package main
import (
	"bufio"
	"fmt"
	"os"
)
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var s string
	fmt.Fscan(r, &s)
	a := make([]int, 0, len(s))
	b := make([]int, 0, len(s))
	for i, e := range s {
		if e == '(' {
			a = append(a, i)
		}
		if s[len(s)-i-1] == ')' {
			b = append(b, len(s)-i-1)
		}
	}
	c := make([]int, 0, len(s))
	for i , j := 0,len(b) - 1; i < len(a) && j >= 0 && a[i] < b[j];i, j = i + 1, j - 1 {
		c = append(c, a[i]+1, b[j]+1)
	}
	if len(c) == 0 {
		fmt.Fprintln(w, "0")
		return
	}
	fmt.Fprintln(w, len(c)/2)
	fmt.Fprintln(w, len(c))
	for i, e := range c {
		if i == 0 {
			fmt.Fprint(w, e)
		} else {
			fmt.Fprint(w," ", e)
		}
	}
	fmt.Fprintln(w)
}


package main

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

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

const mod = 998244353

type node struct {
	cnt int64
	s   string
}

func main() {
	defer out.Flush()

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

	nodes := make([]node, 1<<n+1)
	for i := 1 << (n - 1); i < 1<<n; i++ {
		nodes[i].cnt = 1
		nodes[i].s = s[i-1 : i]
	}
	for i := 1<<(n-1) - 1; i >= 1; i-- {
		lt, rt := nodes[i*2], nodes[i*2+1]
		if lt.s == rt.s {
			nodes[i].cnt = (lt.cnt * rt.cnt) % mod
			nodes[i].s = s[i-1:i] + lt.s + rt.s
		} else {
			nodes[i].cnt = (2 * lt.cnt * rt.cnt) % mod
			if lt.s < rt.s {
				nodes[i].s = s[i-1:i] + lt.s + rt.s
			} else {
				nodes[i].s = s[i-1:i] + rt.s + lt.s
			}
		}
	}
	fmt.Fprintln(out, nodes[1].cnt)
}

package main

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

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

func main() {
	defer out.Flush()
	const mod = 998244353
	var n int
	fmt.Fscan(in, &n)
	var str string
	fmt.Fscan(in, &str)
	str = " " + str

	arr := make([]string, 2<<19)
	res := 1
	var dfs func(rt, length int)
	dfs = func(rt, length int) {
		if length == 1 {
			arr[rt] = string(str[rt])
			return
		}

		dfs(rt<<1, length>>1)
		dfs(rt<<1|1, length>>1)
		a := arr[rt<<1]
		b := arr[rt<<1|1]
		if a != b {
			res = (res + res) % mod
		}
		if a > b {
			arr[rt<<1], arr[rt<<1|1] = arr[rt<<1|1], arr[rt<<1]
		}
		arr[rt] = string(str[rt]) + arr[rt<<1] + arr[rt<<1|1]
	}
	dfs(1, 1<<n-1)
	fmt.Fprintln(out, res%mod)
}

package main

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

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

const mod = 998244353

type node struct {
	cnt int64
	s   string
}

func main() {
	defer out.Flush()

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

	nodes := make([]node, 1<<n+1)
	for i := 1 << (n - 1); i < 1<<n; i++ {
		nodes[i].cnt = 1
		nodes[i].s = s[i-1 : i]
	}
	for i := 1<<(n-1) - 1; i >= 1; i-- {
		lt, rt := nodes[i*2], nodes[i*2+1]
		if lt.s == rt.s {
			nodes[i].cnt = (lt.cnt * rt.cnt) % mod
			nodes[i].s = lt.s + rt.s
		} else {
			nodes[i].cnt = (2 * lt.cnt * rt.cnt) % mod
			if lt.s < rt.s {
				nodes[i].s = lt.s + rt.s
			} else {
				nodes[i].s = rt.s + lt.s
			}
		}
	}
	fmt.Fprintln(out, nodes[1].cnt)
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF933A(_r io.Reader, _w io.Writer) {
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	sum := make([][2]int, n+1)
	for i := range a {
		Fscan(in, &a[i])
		sum[i+1][0] = sum[i][0]
		sum[i+1][1] = sum[i][1]
		sum[i+1][a[i]-1]++
	}
	ans := 0
	for _, s := range sum {
		ans = max(ans, s[0]+sum[n][1]-s[1])
	}
	for i := 1; i <= n; i++ {
		maxL := 0
		for _, s := range sum[:i] {
			maxL = max(maxL, s[0]+sum[i-1][1]-s[1])
		}
		maxR := 0
		for _, s := range sum[i:] {
			maxR = max(maxR, s[0]-sum[i-1][0]+sum[n][1]-s[1])
		}
		ans = max(ans, maxL+maxR)
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF933A(_r io.Reader, _w io.Writer) {
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	sum := make([][2]int, n+1)
	for i := range a {
		Fscan(in, &a[i])
		sum[i+1][0] = sum[i][0]
		sum[i+1][1] = sum[i][1]
		sum[i+1][a[i]-1]++
	}
	ans := 0
	for i := range a {
		maxL := 0
		for _, s := range sum[:i+1] {
			maxL = max(maxL, s[0]+sum[i][1]-s[1])
		}
		maxR := 0
		for _, s := range sum[i:] {
			maxR = max(maxR, s[0]-sum[i][0]+sum[n][1]-s[1])
		}
		ans = max(ans, maxL+maxR)
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF933A(_r io.Reader, _w io.Writer) {
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	sum := make([][2]int, n+1)
	for i := range a {
		Fscan(in, &a[i])
		sum[i+1][0] = sum[i][0]
		sum[i+1][1] = sum[i][1]
		sum[i+1][a[i]-1]++
	}
	ans := 0
	for i := 1; i <= n; i++ {
		maxL := 0
		for _, s := range sum[:i] {
			maxL = max(maxL, s[0]+sum[i-1][1]-s[1])
		}
		maxR := 0
		for _, s := range sum[i:] {
			maxR = max(maxR, s[0]-sum[i-1][0]+sum[n][1]-s[1])
		}
		ans = max(ans, maxL+maxR)
	}
	Fprint(out, ans)
}

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


package main

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

type Prob struct {
    in *bufio.Reader
}

func (prob *Prob) NextLine() string {
    line, _, _ := prob.in.ReadLine()
    return string(line[:])
}

func (prob *Prob) NextByte() byte {
    bt, _ := prob.in.ReadByte()
    return bt
}

func (prob *Prob) Next() string {
    var buff bytes.Buffer
    bt := prob.NextByte()
    for bt == '\n' || bt == ' ' {
        bt = prob.NextByte()
    }
    for bt != '\n' && bt != ' ' {
        buff.WriteByte(bt)
        bt = prob.NextByte()
    }
    return buff.String()
}

func (prob *Prob) NextInt() int {
    var x int
    bt := prob.NextByte()
    for bt > '9' || bt < '0' {
        if bt == '-' {
            return -prob.NextInt()
        }
        bt = prob.NextByte()
    }
    for bt >= '0' && bt <= '9' {
        x = x * 10 + int(bt - '0')
        bt = prob.NextByte()
    }
    return x
}

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

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

func Gcd(a int, b int) int {
    if a == 0 {
        return b
    } else {
        return Gcd(b % a, a)
    }
}

func Abs(a int) int {
    if a < 0 {
        return -a
    } else {
        return a
    }
}

type P struct {
    a int
    b int
}

func (a *P) Sp() {
    if a.b < 0 {
        a.a *= -1
        a.b *= -1
    }
    gcd := Gcd(Abs(a.a), Abs(a.b))
    if gcd != 0 {
        a.a /= gcd
        a.b /= gcd
    }
    if a.b == 0 && a.a != 0 {
        a.a = 1
    }
}

type PS []P

func (a PS) Len() int {
    return len(a)
}

func (a PS) Swap(i int, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a PS) Less(i int, j int) bool {
    if a[i].a != a[j].a {
        return a[i].a < a[j].a
    } else {
        return a[i].b < a[j].b
    }
}

func (prob Prob) Solve() {
    n := prob.NextInt()
    ps := make([]P, n, n)
    for i := 0; i < n; i++ {
        ps[i].a = prob.NextInt()
    }
    for i := 0; i < n; i++ {
        ps[i].b = prob.NextInt()
        ps[i].Sp()
    }
    sort.Sort(PS(ps))
    res := 0
    zero := 0
    for i := 0; i < n; {
        if ps[i].a == 0 {
            if ps[i].b == 0 {
                zero++
            }
            i++
            continue
        }
        j := i
        for ; j < n && ps[i].a == ps[j].a && ps[i].b == ps[j].b; j++ {}
        res = Max(res, j - i)
        i = j
    }
    fmt.Println(res + zero)
}

func main() {
    Prob{in: bufio.NewReader(os.Stdin)}.Solve()
}

package main

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

type Num struct {
	f int
	u int64
	d int64
}

type Nums []*Num

func (s Nums) Len() int {
	return len(s)
}

func (s Nums) Swap(a, b int) {
	tmp := s[a]
	s[a] = s[b]
	s[b] = tmp
}
func (s Nums) Less(i, j int) bool {
	if s[i].f == 0 && s[j].f == 1 {
		return false
	}
	if s[i].f == 1 && s[j].f == 0 {
		return true
	}
	if s[i].f == 0 && s[j].f == 0 {
		if s[i].u*s[j].d < s[i].d*s[j].u {
			return true
		}
		return false
	} else {
		if s[i].u*s[j].d < s[i].d*s[j].u {
			return false
		}
		return true
	}
}
func nof(n int64) int64 {
	if n < 0 {
		return 0 - n
	}
	return n
}
func getf(u, d int64) int {
	if u == 0 {
		return 0
	}
	if (u > 0 && d > 0) || (u < 0 && d < 0) {
		return 0
	}
	return 1
}
func eq(a, b *Num) bool {
	if a.f != b.f {
		return false
	}
	if a.u*b.d != a.d*b.u {
		return false
	}
	return true
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	a := make([]int64, n)
	var v int64
	mat := make(Nums, 0)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
	}
	fmt.Fscanf(buf, "\n")
	tmp := 0
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &v)
		num := &Num{
		}
		if a[i] == 0 && v != 0 {
			continue
		}
		if v == 0 && a[i] == 0 {
			tmp++
			continue
		}
		v = 0 - v
		num.f = getf(v, a[i])
		num.u = nof(v)
		num.d = nof(a[i])
		mat = append(mat, num)
	}
	fmt.Fscanf(buf, "\n")
	sort.Sort(mat)
	ln := len(mat)
	ans := 0
	f := 0
	r := 0
//	fmt.Printf("ln=%d\n", ln)
	for f < ln {
		r = f
		for r < ln && eq(mat[f], mat[r]) {
			r++
		}
		if ans < r-f {
			ans = r - f
		}
		f = r
	}
	fmt.Printf("%d\n", ans+tmp)
}

/*
URL:
https://codeforces.com/problemset/problem/1133/D
*/

package main

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

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

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

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

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

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

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

var (
	n    int
	A, B []int
	C, D []int
)

func main() {
	n = ReadInt()
	A, B = ReadIntSlice(n), ReadIntSlice(n)

	C, D = []int{}, []int{}
	ans := 0
	for i := 0; i < n; i++ {
		a, b := A[i], B[i]
		if a == 0 {
			if b == 0 {
				ans++
			}
		} else {
			C = append(C, a)
			D = append(D, b)
		}
	}

	memo := make(map[Value]int)
	for i := 0; i < len(C); i++ {
		a, b := C[i], D[i]
		g := Gcd(AbsInt(a), AbsInt(b))
		a /= g
		b /= g

		if a < 0 {
			a *= -1
			b *= -1
		}

		v := Value{bunbo: a, bunshi: -b}
		memo[v]++
	}

	num := 0
	for _, v := range memo {
		ChMax(&num, v)
	}
	fmt.Println(ans + num)
}

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

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

type Value struct {
	bunbo, bunshi int
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a < 0 || b < 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	if a == 0 {
		return b
	}
	if b == 0 {
		return a
	}

	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

type Prob struct {
    in *bufio.Reader
}

func (prob *Prob) NextLine() string {
    line, _, _ := prob.in.ReadLine()
    return string(line[:])
}

func (prob *Prob) NextByte() byte {
    bt, _ := prob.in.ReadByte()
    return bt
}

func (prob *Prob) Next() string {
    var buff bytes.Buffer
    bt := prob.NextByte()
    for bt == '\n' || bt == ' ' {
        bt = prob.NextByte()
    }
    for bt != '\n' && bt != ' ' {
        buff.WriteByte(bt)
        bt = prob.NextByte()
    }
    return buff.String()
}

func (prob *Prob) NextInt() int {
    var x int
    bt := prob.NextByte()
    for bt > '9' || bt < '0' {
        if bt == '-' {
            return -prob.NextInt()
        }
        bt = prob.NextByte()
    }
    for bt >= '0' && bt <= '9' {
        x = x * 10 + int(bt - '0')
        bt = prob.NextByte()
    }
    return x
}

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

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

type P struct {
    a int
    b int
}

type PS []P

func (a PS) Len() int {
    return len(a)
}

func (a PS) Swap(i int, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a PS) Less(i int, j int) bool {
    sa := a[i].a * a[i].b
    sb := a[j].a * a[j].b
    if sa < 0 && sb > 0 {
        return true
    } else if sa > 0 && sb < 0 {
        return false
    } else if sa > 0 {
        return a[i].a * a[j].b < a[i].b * a[j].a
    } else {
        return a[i].a * a[j].b > a[i].b * a[j].a
    }
}

func (prob Prob) Solve() {
    n := prob.NextInt()
    ps := make([]P, n, n)
    for i := 0; i < n; i++ {
        ps[i].a = prob.NextInt()
    }
    for i := 0; i < n; i++ {
        ps[i].b = prob.NextInt()
    }
    sort.Sort(PS(ps))
    res := 0
    zero := 0
    i := 0
    j := 0
    for ; i < n; i++ {
        if ps[i].a == 0 {
            if ps[i].b == 0 {
                zero++
            }
            continue
        }
        j = Max(i, j)
        for ; j < n && ps[i].a * ps[j].b == ps[i].b * ps[j].a; j++ {}
        res = Max(res, j - i)
    }
    fmt.Println(res + zero)
}

func main() {
    Prob{in: bufio.NewReader(os.Stdin)}.Solve()
}

package main

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

type Prob struct {
    in *bufio.Reader
}

func (prob *Prob) NextLine() string {
    line, _, _ := prob.in.ReadLine()
    return string(line[:])
}

func (prob *Prob) NextByte() byte {
    bt, _ := prob.in.ReadByte()
    return bt
}

func (prob *Prob) Next() string {
    var buff bytes.Buffer
    bt := prob.NextByte()
    for bt == '\n' || bt == ' ' {
        bt = prob.NextByte()
    }
    for bt != '\n' && bt != ' ' {
        buff.WriteByte(bt)
        bt = prob.NextByte()
    }
    return buff.String()
}

func (prob *Prob) NextInt() int {
    var x int
    bt := prob.NextByte()
    for bt > '9' || bt < '0' {
        if bt == '-' {
            return -prob.NextInt()
        }
        bt = prob.NextByte()
    }
    for bt >= '0' && bt <= '9' {
        x = x * 10 + int(bt - '0')
        bt = prob.NextByte()
    }
    return x
}

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

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

type P struct {
    a int
    b int
}

type PS []P

func (a PS) Len() int {
    return len(a)
}

func (a PS) Swap(i int, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a PS) Less(i int, j int) bool {
    return a[i].a * a[j].b < a[i].b * a[j].a
}

func (prob Prob) Solve() {
    n := prob.NextInt()
    ps := make([]P, n, n)
    for i := 0; i < n; i++ {
        ps[i].a = prob.NextInt()
    }
    for i := 0; i < n; i++ {
        ps[i].b = prob.NextInt()
    }
    sort.Sort(PS(ps))
    res := 0
    i := 0
    j := 0
    for ; i < n; i++ {
        for ; j < n && ps[i].a * ps[j].b >= ps[i].b * ps[j].a; j++ {}
        res = Max(res, j - i)
    }
    fmt.Println(res)
}

func main() {
    Prob{in: bufio.NewReader(os.Stdin)}.Solve()
}

package main

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

type Prob struct {
    in *bufio.Reader
}

func (prob *Prob) NextLine() string {
    line, _, _ := prob.in.ReadLine()
    return string(line[:])
}

func (prob *Prob) NextByte() byte {
    bt, _ := prob.in.ReadByte()
    return bt
}

func (prob *Prob) Next() string {
    var buff bytes.Buffer
    bt := prob.NextByte()
    for bt == '\n' || bt == ' ' {
        bt = prob.NextByte()
    }
    for bt != '\n' && bt != ' ' {
        buff.WriteByte(bt)
        bt = prob.NextByte()
    }
    return buff.String()
}

func (prob *Prob) NextInt() int {
    var x int
    bt := prob.NextByte()
    for bt > '9' || bt < '0' {
        if bt == '-' {
            return -prob.NextInt()
        }
        bt = prob.NextByte()
    }
    for bt >= '0' && bt <= '9' {
        x = x * 10 + int(bt - '0')
        bt = prob.NextByte()
    }
    return x
}

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

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

type P struct {
    a int
    b int
}

type PS []P

func (a PS) Len() int {
    return len(a)
}

func (a PS) Swap(i int, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a PS) Less(i int, j int) bool {
    return a[i].a * a[j].b < a[i].b * a[j].a
}

func (prob Prob) Solve() {
    n := prob.NextInt()
    ps := make([]P, n, n)
    for i := 0; i < n; i++ {
        ps[i].a = prob.NextInt()
    }
    for i := 0; i < n; i++ {
        ps[i].b = prob.NextInt()
    }
    sort.Sort(PS(ps))
    res := 0
    zero := 0
    i := 0
    j := 0
    for ; i < n; i++ {
        if ps[i].a == 0 {
            if ps[i].b == 0 {
                zero++
            }
            continue
        }
        j = Max(i, j)
        for ; j < n && ps[i].a * ps[j].b >= ps[i].b * ps[j].a; j++ {}
        res = Max(res, j - i)
    }
    fmt.Println(res + zero)
}

func main() {
    Prob{in: bufio.NewReader(os.Stdin)}.Solve()
}

package main

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

type Prob struct {
    in *bufio.Reader
}

func (prob *Prob) NextLine() string {
    line, _, _ := prob.in.ReadLine()
    return string(line[:])
}

func (prob *Prob) NextByte() byte {
    bt, _ := prob.in.ReadByte()
    return bt
}

func (prob *Prob) Next() string {
    var buff bytes.Buffer
    bt := prob.NextByte()
    for bt == '\n' || bt == ' ' {
        bt = prob.NextByte()
    }
    for bt != '\n' && bt != ' ' {
        buff.WriteByte(bt)
        bt = prob.NextByte()
    }
    return buff.String()
}

func (prob *Prob) NextInt() int {
    var x int
    bt := prob.NextByte()
    for bt > '9' || bt < '0' {
        if bt == '-' {
            return -prob.NextInt()
        }
        bt = prob.NextByte()
    }
    for bt >= '0' && bt <= '9' {
        x = x * 10 + int(bt - '0')
        bt = prob.NextByte()
    }
    return x
}

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

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

func Gcd(a int, b int) int {
    if a == 0 {
        return b
    } else {
        return Gcd(b % a, a)
    }
}

func Abs(a int) int {
    if a < 0 {
        return -a
    } else {
        return a
    }
}

type P struct {
    a int
    b int
}

func (a *P) Sp() {
    if a.b < 0 {
        a.a *= -1
        a.b *= -1
    }
    gcd := Gcd(Abs(a.a), Abs(a.b))
    if gcd != 0 {
        a.a /= gcd
        a.b /= gcd
    }
    if a.b == 0 {
        a.a = 1
    }
}

type PS []P

func (a PS) Len() int {
    return len(a)
}

func (a PS) Swap(i int, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a PS) Less(i int, j int) bool {
    if a[i].a != a[j].a {
        return a[i].a < a[j].a
    } else {
        return a[i].b < a[j].b
    }
}

func (prob Prob) Solve() {
    n := prob.NextInt()
    ps := make([]P, n, n)
    for i := 0; i < n; i++ {
        ps[i].a = prob.NextInt()
    }
    for i := 0; i < n; i++ {
        ps[i].b = prob.NextInt()
        ps[i].Sp()
    }
    sort.Sort(PS(ps))
    res := 0
    zero := 0
    for i := 0; i < n; {
        if ps[i].a == 0 {
            if ps[i].b == 0 {
                zero++
            }
            i++
            continue
        }
        j := i
        for ; j < n && ps[i].a == ps[j].a && ps[i].b == ps[j].b; j++ {}
        res = Max(res, j - i)
        i = j
    }
    fmt.Println(res + zero)
}

func main() {
    Prob{in: bufio.NewReader(os.Stdin)}.Solve()
}

package main

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

type Prob struct {
    in *bufio.Reader
}

func (prob *Prob) NextLine() string {
    line, _, _ := prob.in.ReadLine()
    return string(line[:])
}

func (prob *Prob) NextByte() byte {
    bt, _ := prob.in.ReadByte()
    return bt
}

func (prob *Prob) Next() string {
    var buff bytes.Buffer
    bt := prob.NextByte()
    for bt == '\n' || bt == ' ' {
        bt = prob.NextByte()
    }
    for bt != '\n' && bt != ' ' {
        buff.WriteByte(bt)
        bt = prob.NextByte()
    }
    return buff.String()
}

func (prob *Prob) NextInt() int {
    var x int
    bt := prob.NextByte()
    for bt > '9' || bt < '0' {
        if bt == '-' {
            return -prob.NextInt()
        }
        bt = prob.NextByte()
    }
    for bt >= '0' && bt <= '9' {
        x = x * 10 + int(bt - '0')
        bt = prob.NextByte()
    }
    return x
}

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

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

func Gcd(a int, b int) int {
    if a == 0 {
        return b
    } else {
        return Gcd(b % a, a)
    }
}

func Abs(a int) int {
    if a < 0 {
        return -a
    } else {
        return a
    }
}

type P struct {
    a int
    b int
}

func (a *P) Sp() {
    if a.b < 0 {
        a.a *= -1
        a.b *= -1
    }
    gcd := Gcd(Abs(a.a), Abs(a.b))
    if gcd != 0 {
        a.a /= gcd
        a.b /= gcd
    }
}

type PS []P

func (a PS) Len() int {
    return len(a)
}

func (a PS) Swap(i int, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a PS) Less(i int, j int) bool {
    if a[i].a != a[j].a {
        return a[i].a < a[j].a
    } else {
        return a[i].b < a[j].b
    }
}

func (prob Prob) Solve() {
    n := prob.NextInt()
    ps := make([]P, n, n)
    for i := 0; i < n; i++ {
        ps[i].a = prob.NextInt()
    }
    for i := 0; i < n; i++ {
        ps[i].b = prob.NextInt()
        ps[i].Sp()
    }
    sort.Sort(PS(ps))
    res := 0
    zero := 0
    i := 0
    j := 0
    for ; i < n; i++ {
        if ps[i].a == 0 {
            if ps[i].b == 0 {
                zero++
            }
            continue
        }
        j = Max(i, j)
        for ; j < n && ps[i].a == ps[j].a && ps[i].b == ps[j].b; j++ {}
        res = Max(res, j - i)
    }
    fmt.Println(res + zero)
}

func main() {
    Prob{in: bufio.NewReader(os.Stdin)}.Solve()
}


package main

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

func dist(a, b, n int) int {
	return (b + n - a) % n
}

func getNumsFromOneLine(ir *bufio.Reader) []int {
	stream, _ := ir.ReadString('\n')
	// Trims the stream and then splits
	trimmedStream := strings.TrimSpace(stream)
	splitArr := strings.Split(trimmedStream, " ")
	// convert strings to integers and store them in a slice
	nums := make([]int, len(splitArr))
	for index, val := range splitArr {
		nums[index], _ = strconv.Atoi(val)
	}
	return nums
}

func main() {
	ir := bufio.NewReader(os.Stdin)
	nm := getNumsFromOneLine(ir)
	n, m := nm[0], nm[1]
	des := make([]int, 5004) // station i 的 destination 是des[i]
	cnt := make([]int, 5004) // station i 里面共有 candy cnt[1]个
	for i := 0; i < m; i += 1 {
		ab := getNumsFromOneLine(ir)
		a, b := ab[0], ab[1]
		if des[a] == 0 {
			des[a] = b
		} else {
			if dist(a, b, n) < dist(a, des[a], n) {
				des[a] = b // 永远使得最后一轮距离最短
			}
		}
		cnt[a] += 1
	}

	res := make([]string, 0)
	for i := 1; i < n+1; i++ { // 起点是 station i
		curRes := 0
		for j := 1; j < n+1; j++ {
			if des[j] > 0 {
				// curRes 永远取最大那个
				// 对于某个 station j 来说，所需要走的距离为从起点 station i 到 station j 的距离       +
				//                                    (candy 数 - 1) * n                       +
				//                                     从 station j 到达最终的 destination des[j]
				curRes = int(math.Max(float64(curRes), float64(dist(i, j, n) + (cnt[j] - 1) * n + dist(j, des[j], n))))
			}
		}
		res = append(res, strconv.Itoa(curRes))
	}
	fmt.Println(strings.Join(res, " "))
}

package main

import (
	"fmt"
	"math"
	"strconv"
)

func dist(a, b, n int) int {
	return (b + n - a) % n
}

func main() {
	var nn, mm string
	fmt.Scanf("%s %s\n", &nn, &mm)
	n, _ := strconv.Atoi(nn)
	m, _ := strconv.Atoi(mm)
	//fmt.Println(n, m)
	nums, cnt := [5004]int{}, [5004]int{}
	for i := 0; i < m; i++ {
		var aa, bb string
		fmt.Scanf("%s %s\n", &aa, &bb)
		a, _ := strconv.Atoi(aa)
		b, _ := strconv.Atoi(bb)
		//fmt.Println(aa, bb)
		if nums[a] == 0 {
			nums[a] = b
		} else {
			cnt[a] += 1
			if dist(a, b, n) < dist(a, nums[a], n) {
				nums[a] = b
			}

		}
	}
	res := ""
	for i := 1; i < n+1; i++ {
		ans := 0
		for j := 1; j < n+1; j++ {
			if nums[j] > 0 {
				ans = int(math.Max(float64(ans), float64(dist(i, j, n) + cnt[j] * n + dist(j, nums[j], n))))
			}
		}
		res += strconv.Itoa(ans) + " "
	}
	fmt.Println(res[:len(res)-1])
}

package main

import (
	"fmt"
	"math"
	"strconv"
)

func dist(a, b, n int) int {
	return (b + n - a) % n
}

func main() {
	var nn, mm string
	fmt.Scanf("%s %s", &nn, &mm)
	n, _ := strconv.Atoi(nn)
	m, _ := strconv.Atoi(mm)
	nums, cnt := [5004]int{}, [5004]int{}
	for i := 0; i < m; i++ {
		var aa, bb string
		fmt.Scanf("%s %s", &aa, &bb)
		a, _ := strconv.Atoi(aa)
		b, _ := strconv.Atoi(bb)
		if nums[a] == 0 {
			nums[a] = b
		} else {
			cnt[a] += 1
			if dist(a, b, n) < dist(a, nums[a], n) {
				nums[a] = b
			}

		}
	}
	res := ""
	for i := 1; i < n+1; i++ {
		ans := 0
		for j := 1; j < n+1; j++ {
			if nums[j] > 0 {
				ans = int(math.Max(float64(ans), float64(dist(i, j, n) + cnt[j] * n + dist(j, nums[j], n))))
			}
		}
		res += strconv.Itoa(ans) + " "
	}
	fmt.Println(res[:len(res)-1])
}


package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var ss, tt string
	fmt.Scan(&ss)
	fmt.Scan(&tt)
	s:=make([]uint8,n)
	t:=make([]uint8,n)
	for i:=0;i<n;i++ {
		s[i]=ss[i]
		t[i]=tt[i]
	}
	a := make([]int, 400)
	b := make([]int, 400)
	for i := 0; i < n; i++ {
		a[s[i]]++
	}
	for i := 0; i < n; i++ {
		b[t[i]]++
	}
	for i := 'a'; i <= 'z'; i++ {
		if a[i] != b[i] {
			fmt.Println(-1);
			return
		}
	}
	ind:=0
	res:=make([]int,10000)
	for i := 0; i < n; i++ {
		//fmt.Printf("! %d\n",i)
		j := i
		for j = i; s[j] != t[i]; j++ {
			//fmt.Println(j)
		}
		for j>i {
			res[ind]=j
			j--
			ind++
			c:=s[j]
			s[j]=s[j+1]
			s[j+1]=c
		}
	}
	fmt.Println(ind)
	for i:=0;i<ind;i++ {
		fmt.Printf("%d ",res[i])
	}
}

package main

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

var allAns []int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	s1 := ""
	s2 := ""
	fmt.Fscanf(in, "%s\n", &s1)
	fmt.Fscanf(in, "%s\n", &s2)
	allAns = make([]int, 0)
	ok := move([]byte(s1), []byte(s2), 1)
	if !ok {
		fmt.Fprintf(out, "%d\n", -1)
		return
	}
	fmt.Fprintf(out, "%d\n", len(allAns))
	if len(allAns) > 0 {
		fmt.Fprintf(out, "%d", allAns[0])
		for i := 1; i < len(allAns); i++ {
			fmt.Fprintf(out, " %d", allAns[i])
		}
		fmt.Fprintf(out, "\n")
	}

	return
}

func move(s1, s2 []byte, offset int) bool {
	n := len(s1)
	if n == 0 {
		return true
	}
	found := -1
	for i := 0; i < n; i++ {
		if s1[i] == s2[0] {
			found = i
			break
		}
	}
	if found == -1 {
		return false
	}
	for i := found - 1; i >= 0; i-- {
		allAns = append(allAns, i+offset)
		s1[i], s1[i+1] = s1[i+1], s1[i]
	}
	return move(s1[1:], s2[1:], offset+1)
}

package main

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

func main()  {

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

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

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

	result := make([]int, 0)

	for i := 0; i < n; i++ {

		pos := -1
		for j := i; j < n; j++ {
			if t[i] == s[j] {
				pos = j
				break
			}
		}

		if pos == -1 {
			fmt.Fprintln(out, "-1")
			return
		}

		for j := pos - 1; j >= i; j-- {
			result = append(
				result,
				j + 1,
			)
		}

		s = s[:i] + s[pos:pos+1] + s[i:pos] + s[pos+1:]

	}

	fmt.Fprintln(out, len(result))
	for i := 0; i < len(result); i++ {
		fmt.Fprint(out, result[i], " ")
	}

}

package main

import (
	"fmt"
	"os"
)

var n int

func main() {
	fmt.Scanf("%d\n", &n)
	var st, ed string
	fmt.Scanf("%s\n%s\n", &st, &ed)
	step := 0
	steps := make([]int, 0)
	for step < n {
		if st[step] != ed[step] {
			f := false
			for i := step + 1; i < n; i++ {
				if st[i] == ed[step] {
					f = true
					for j := i - 1; j >= step; j-- {
						steps = append(steps, j)
					}
					st = swap(st, step, i)
					break
				}
			}
			if !f {
				fmt.Println(-1)
				os.Exit(0)
			}
		}
		step++
	}
	fmt.Println(len(steps))
	if len(steps) != 0 {
		fmt.Print(steps[0] + 1)
		for i := 1; i < len(steps); i++ {
			fmt.Print(" ", steps[i]+1)
		}
		fmt.Println()
	}
}
func swap(s string, st int, ed int) string {
	bytes := []byte(s)
	t := bytes[ed]
	for i := ed; i > st; i-- {
		bytes[i] = bytes[i-1]
	}
	bytes[st] = t
	return string(bytes)
}

package main

import (
	. "fmt"
)

func swapBytes(bs []byte, p1, p2 int) {
	tmp := bs[p2]
	bs[p2] = bs[p1]
	bs[p1] = tmp
}

func main() {
	var n int
	var s1, s2 string
	Scan(&n, &s1, &s2)

	cnt1 := make([]int, 26)
	cnt2 := make([]int, 26)
	for _, c := range s1 {
		cnt1[c-'a']++
	}
	for _, c := range s2 {
		cnt2[c-'a']++
	}

	if Sprint(cnt1) != Sprint(cnt2) {
		Println(-1)
	} else {
		b1 := []byte(s1)
		b2 := []byte(s2)

		cnt:=0
		var ans []interface{}

		for i, b := range b2 {
			if b != b1[i] {
				for j := i; j < n; j++ {
					if b == b1[j] {
						for k := j-1; k >=i; k-- {
							swapBytes(b1, k, k+1)

							cnt++
							ans = append(ans,k+1)
						}
						break
					}
				}
			}
		}

		Println(cnt)
		Print(ans...)
	}

}

package main

import (
	"fmt"
	"sort"
	"strings"
)

func SortString(s string) string {
	sa := strings.Split(s, "")
	sort.Strings(sa)
	return strings.Join(sa, "")
}

func SwapItem(stringArray []string, i int) []string {
	tmp := stringArray[i]
	stringArray[i] = stringArray[i-1]
	stringArray[i-1] = tmp
	return stringArray
}

func SearchItemIndex(stringArray []string, s string, startIndex int) int {
	l := len(stringArray)
	for i := startIndex; i < l; i++ {
		if stringArray[i] == s {
			return i
		}
	}
	return -1
}

func main() {
	var n int
	var s, t string
	fmt.Scanln(&n)
	fmt.Scanln(&s)
	fmt.Scanln(&t)

	if s == t {
		fmt.Println("0")
		return
	}

	sortedS := SortString(s)
	sortedT := SortString(t)

	if sortedS != sortedT {
		fmt.Println("-1")
		return
	}

	sArray := strings.Split(s, "")
	tArray := strings.Split(t, "")

	var result []int

	for k, v := range tArray {
		if sArray[k] == v {
			continue
		}

		index := SearchItemIndex(sArray, v, k+1)
		for i := index; i > k; i-- {
			sArray = SwapItem(sArray, i)
			result = append(result, i)
		}
	}

	output := fmt.Sprint(result)
	output = strings.Replace(output, "[", "", -1)
	output = strings.Replace(output, "]", "", -1)

	fmt.Println(len(result))
	fmt.Println(output)
}

package main

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

func main()  {

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

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

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

	result := make([]int, 0)

	for i := 0; i < n; i++ {

		pos := -1
		for j := i; j < n; j++ {
			if t[i] == s[j] {
				pos = j
				break
			}
		}

		if pos == -1 {
			fmt.Fprintln(out, "-1")
			break
		}

		for j := pos - 1; j >= i; j-- {
			result = append(
				result,
				j + 1,
			)
		}

		s = s[:i] + s[pos:pos+1] + s[i:pos] + s[pos+1:]

	}

	fmt.Fprintln(out, len(result))
	for i := 0; i < len(result); i++ {
		fmt.Fprint(out, result[i], " ")
	}

}

package main

import (
	"fmt"
	"os"
)

var n int

func main() {
	fmt.Scanf("%d\n", &n)
	var st, ed string
	fmt.Scanf("%s\n%s\n", &st, &ed)
	step := 0
	steps := make([]int, 0)
	for step < n {
		if st[step] != ed[step] {
			f := false
			for i := step + 1; i < n; i++ {
				if st[i] == ed[step] {
					f = true
					for j := i - 1; j >= step; j-- {
						steps = append(steps, j)
					}
					st = swap(st, step, i)
					break
				}
			}
			if !f {
				fmt.Println(-1)
				os.Exit(0)
			}
		}
		step++
	}
	fmt.Println(len(steps))
	if len(steps) == 0 {
		fmt.Print(steps[0] + 1)
		for i := 1; i < len(steps); i++ {
			fmt.Print(" ", steps[i]+1)
		}
		fmt.Println()
	}
}
func swap(s string, st int, ed int) string {
	bytes := []byte(s)
	t := bytes[ed]
	for i := ed; i > st; i-- {
		bytes[i] = bytes[i-1]
	}
	bytes[st] = t
	return string(bytes)
}

package main

import (
	. "fmt"
)

func swapBytes(bs []byte, p1, p2 int) {
	tmp := bs[p2]
	bs[p2] = bs[p1]
	bs[p1] = tmp
}

func main() {
	var n int
	var s1, s2 string
	Scan(&n, &s1, &s2)

	cnt1 := make([]int, 26)
	cnt2 := make([]int, 26)
	for _, c := range s1 {
		cnt1[c-'a']++
	}
	for _, c := range s2 {
		cnt2[c-'a']++
	}

	if Sprint(cnt1) != Sprint(cnt2) {
		Println(-1)
	} else {
		b1 := []byte(s1)
		b2 := []byte(s2)

		for i, b := range b2 {
			if b != b1[i] {
				for j := i; j < n; j++ {
					if b == b1[j] {
						for k := j-1; k >=i; k-- {
							swapBytes(b1, k, k+1)
							Printf("%d ", k+1)
						}
						break
					}
				}
			}
		}
	}

}

package main

import (
	"fmt"
	"sort"
	"strings"
)

func SortString(s string) string {
	sa := strings.Split(s, "")
	sort.Strings(sa)
	return strings.Join(sa, "")
}

func SwapItem(stringArray []string, i int) []string {
	tmp := stringArray[i]
	stringArray[i] = stringArray[i-1]
	stringArray[i-1] = tmp
	return stringArray
}

func SearchItemIndex(stringArray []string, s string) int {
	for k, v := range stringArray {
		if v == s {
			return k
		}
	}
	return -1
}

func main() {
	var n int
	var s, t string
	fmt.Scanln(&n)
	fmt.Scanln(&s)
	fmt.Scanln(&t)

	sortedS := SortString(s)
	sortedT := SortString(t)

	if sortedS != sortedT {
		fmt.Println("-1")
		return
	}

	sArray := strings.Split(s, "")
	tArray := strings.Split(t, "")

	var result []int

	for k, v := range tArray {
		if sArray[k] == v {
			continue
		}

		index := SearchItemIndex(sArray, v)
		for i := index; i > k; i-- {
			sArray = SwapItem(sArray, i)
			result = append(result, i)
		}
	}

	output := fmt.Sprint(result)
	output = strings.Replace(output, "[", "", -1)
	output = strings.Replace(output, "]", "", -1)

	fmt.Println(len(result))
	fmt.Println(output)
}


package main

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

func main() {
	var n int
	var a,b,c string
	b="miao."
	c="lala."
	input := bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanLines)
	input.Scan()
	bb,_:=strconv.Atoi(input.Text())
	n=bb
	for  k:=0;k<n;k++{
		input.Scan()
		a = input.Text()
		cek1 := strings.HasPrefix(a,b)
		cek2 := strings.HasSuffix(a,c)
		if cek1==false && cek2==true  {
			fmt.Println("Freda's")
		} else if cek1==true && cek2==false {
			fmt.Println("Rainbow's")
		} else {
			fmt.Println("OMG>.< I don't know!")
		}
	}
}

package main

import "os"
import "bufio"
import "strconv"
import "strings"

func main(){
	var n int
	r := bufio.NewScanner(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	f := "lala."
	ra := "miao."
	for i:=0; i<n; i++ {
		r.Scan()
		if strings.HasSuffix(r.Text(), f) && !strings.HasPrefix(r.Text(), ra) {
			w.WriteString("Freda's\n")
		} else if strings.HasPrefix(r.Text(), ra) && !strings.HasSuffix(r.Text(), f) {
			w.WriteString("Rainbow's\n")
		} else {
			w.WriteString("OMG>.< I don't know!\n")
		}
		w.Flush()
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    n, _ := strconv.Atoi(scanner.Text())
    for i := 0; i < n; i++ {
        scanner.Scan()
        if len(scanner.Text()) < 5 {
            fmt.Println("OMG>.< I don't know!")
        } else {
            begin, end := scanner.Text()[:5], scanner.Text()[len(scanner.Text())-5:]
            if (begin == "miao.") && (end != "lala.") {
                fmt.Println("Rainbow's")
            } else if (begin != "miao.") && (end == "lala.") {
                fmt.Println("Freda's")
            } else {
                fmt.Println("OMG>.< I don't know!")
            }
        }
    }
}

//312A

package main

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

var (
	in  *bufio.Scanner = bufio.NewScanner(os.Stdin)
	out *bufio.Writer  = bufio.NewWriter(os.Stdout)
)

func NextInt() int {
	in.Scan()
	ans, _ := strconv.Atoi(in.Text())
	return ans
}

func main() {
	in.Split(bufio.ScanLines)
	n := NextInt()
	for i := 0; i < n; i++ {
		in.Scan()
		x := strings.HasPrefix(in.Text(), "miao.")
		y := strings.HasSuffix(in.Text(), "lala.")
		if x && !y {
			out.WriteString("Rainbow's\n")
		} else if !x && y {
			out.WriteString("Freda's\n")
		} else {
			out.WriteString("OMG>.< I don't know!\n")
		}
	}
	out.Flush()
}

package main

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

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

func main() {
	scanner.Split(bufio.ScanLines)
	n := NextInt()
	for i := 0; i < n; i++ {
		scanner.Scan()
		miao, lala := strings.HasPrefix(scanner.Text(), "miao."),
			strings.HasSuffix(scanner.Text(), "lala.")
		if miao && !lala {
			w.WriteString("Rainbow's\n")
		} else if !miao && lala {
			w.WriteString("Freda's\n")
		} else {
			w.WriteString("OMG>.< I don't know!\n")
		}
	}
	w.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    count, _ := strconv.Atoi(scanner.Text())

    for i := 0; i < count; i++ {
        scanner.Scan()
        text := scanner.Text()

        const miao = "miao."
        isRainbow := text == miao || strings.HasPrefix(text, miao)
        const lala = "lala."
        isFreda := text == lala || strings.HasSuffix(text, lala)

        if isFreda && isRainbow == false {
            fmt.Println("Freda's")
        } else
        if isRainbow && isFreda == false {
            fmt.Println("Rainbow's")
        } else {
            fmt.Println("OMG>.< I don't know!")
        }
    }
}

package main

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

func main() {
	var n,i,s,t,j int
	i,s,j =0,0,0
	var a,b,c string
	b="miao."
	c="lala."
	input := bufio.NewScanner(os.Stdin)
	fmt.Scan(&n)
	for  k:=0;k<=n;k++{
		input.Scan()
		a = input.Text()
		t=len(a)
		if t==0 || a==""{
			fmt.Println("OMG>.< I don't know!")
			continue
		} else {
			for k:=0;k<5;k++ {
				if a[k]==b[k] {
					s++
				}
			}
		}
		for k:=t-5;k<t;k++ {
			if a[k]==c[i] {
				j++
				i++
			}
		}
		if s==j || s!=5 && j!=5 {
			fmt.Println("OMG>.< I don't know!")
		} else if s==5 && j!=5 {
			fmt.Println("Rainbow's")
		} else {
			fmt.Println("Freda's")
		}
		i=0
		s=0
		j=0
	}
}

package main

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

func main() {
    var count int

    fmt.Fscanln(os.Stdin, &count)

    var results = make([]string, count)

    for i := 0; i < count; i++ {

        reader := bufio.NewReader(os.Stdin)
        text, _ := reader.ReadString('\n')
        text = strings.ReplaceAll(text, "\n", "")
        text = strings.ReplaceAll(text, "\r", "")

        const miao = "miao."
        isRainbow := text == miao || strings.HasPrefix(text, miao)
        const lala = "lala."
        isFreda := text == lala || strings.HasSuffix(text, lala)

        const s = "OMG>.< I don't know!"

        if isFreda && isRainbow {
           results[i] = s
        } else
        if isFreda {
           results[i] = "Freda's"
        } else
        if isRainbow {
           results[i] = "Rainbow's"
        } else {
           results[i] = s
        }
    }

    for _, line := range results {
       fmt.Println(line)
    }
}

package main

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

func main() {
    var count int

    fmt.Fscan(os.Stdin, &count)

    var results = make([]string, count)

    for i := 0; i < count; i++ {

        reader := bufio.NewReader(os.Stdin)
        text, _ := reader.ReadString('\n')
        text = strings.ReplaceAll(text, "\n", "")

        const miao = "miao."
        isRainbow := text == miao || strings.HasPrefix(text, miao)
        const lala = "lala."
        isFreda := text == lala || strings.HasSuffix(text, lala)

        const s = "OMG>.< I don't know!"

        if isFreda && isRainbow {
           results[i] = s
        } else
        if isFreda {
           results[i] = "Freda's"
        } else
        if isRainbow {
           results[i] = "Rainbow's"
        } else {
           results[i] = s
        }
    }

    for _, line := range results {
       fmt.Println(line)
    }
}

package main

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

func main() {
    var count int

    fmt.Fscan(os.Stdin, &count)

    var results = make([]string, count)

    var text string
    for i := 0; i < count; i++ {
        fmt.Fscan(os.Stdin, &text)

        const miao = "miao."
        isRainbow := text == miao || strings.HasPrefix(text, miao)
        const lala = "lala."
        isFreda := text == lala || strings.HasSuffix(text, lala)

        const s = "OMG>.< I don't know!"

        if isFreda && isRainbow {
            results[i] = s
        } else
        if isFreda {
            results[i] = "Freda's"
        } else
        if isRainbow {
            results[i] = "Rainbow's"
        } else {
            results[i] = s
        }
    }

    for _, line := range results {
        fmt.Println(line)
    }
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var n int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        if len(scanner.Text()) < 5 {
            fmt.Println("OMG>.< I don't know!")
        } else {
            begin, end := scanner.Text()[:5], scanner.Text()[len(scanner.Text())-5:]
            if (begin == "miao.") && (end != "lala.") {
                fmt.Println("Rainbow's")
            } else if (begin != "miao.") && (end == "lala.") {
                fmt.Println("Freda's")
            } else {
                fmt.Println("OMG>.< I don't know!")
            }
        }
    }
}

//312A

package main

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

func NextInt() int {
	in := bufio.NewScanner(os.Stdin)
	in.Scan()
	ans, _ := strconv.Atoi(in.Text())
	return ans
}

func main() {
	in := bufio.NewScanner(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	in.Split(bufio.ScanLines)
	n := NextInt()
	for i := 0; i < n; i++ {
		in.Scan()
		miao, lala := strings.HasPrefix(in.Text(), "miao."),
			strings.HasSuffix(in.Text(), "lala.")
		if miao && !lala {
			out.WriteString("Rainbow's\n")
		} else if !miao && lala {
			out.WriteString("Freda's\n")
		} else {
			out.WriteString("OMG>.< I don't know!\n")
		}
	}
	out.Flush()
}


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, q int
	fmt.Fscan(reader, &n, &q)
	a := make([]int, n+10)
	for i := 0; i <= n; i++ {
		a[i] = i
	}
	var cmd int
	var is_rev int = 0
	var head, tail int = 1, n + 1 // [head, tail) is current interval.

	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &cmd)
		if cmd == 1 {
			var p int
			fmt.Fscan(reader, &p)
			if p*2 > tail-head {
				is_rev ^= 1
				p = tail - head - p
			}
			if is_rev == 1 {
				for i, j := tail-2*p, 1; i < tail-p; i++ {
					a[i] += a[tail-1] - a[tail-1-j]
					j++
				}
				tail -= p
			} else {
				for i, j := head+p, 1; i < head+p*2; i++ {
					j++
					a[i] -= a[head+p-j]
				}
				a[head+p-1] = 0
				head += p
			}
		} else {
			var l, r int
			fmt.Fscan(reader, &l, &r)
			if is_rev == 0 {
				fmt.Println(a[r+head-1] - a[l+head-1])
			} else {
				fmt.Println(a[tail-1-l] - a[tail-r-1])
			}
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, q int
	fmt.Fscan(reader, &n, &q)
	a := make([]int, n+10)
	for i := 0; i <= n; i++ {
		a[i] = i
	}
	var cmd int
	var is_rev int = 0
	var head, tail int = 1, n + 1 // [head, tail) is current interval.

	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &cmd)
		if cmd == 1 {
			var p int
			fmt.Fscan(reader, &p)
			if p*2 > tail-head {
				is_rev ^= 1
				p = tail - head - p
			}
			if is_rev == 1 {
				for i, j := tail-2*p, 1; i < tail-p; i++ {
					a[i] += a[tail-1] - a[tail-1-j]
					j++
				}
				for i := tail - p; i < tail; i++ {
					a[i] = 0
				}
				tail -= p
			} else {
				for i, j := head+p, 1; i < head+p*2; i++ {
					j++
					a[i] -= a[head+p-j]
					a[head+p-j] = 0
				}
				a[head+p-1] = 0
				head += p
			}
		} else {
			var l, r int
			fmt.Fscan(reader, &l, &r)
			if is_rev == 0 {
				fmt.Println(a[r+head-1] - a[l+head-1])
			} else {
				fmt.Println(a[tail-1-l] - a[tail-r-1])
			}
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var n, q int
	fmt.Scan(&n, &q)
	a := make([]int, n+10)
	for i := 0; i <= n; i++ {
		a[i] = i
	}
	var cmd int
	var is_rev int = 0
	var head, tail int = 1, n + 1 // [head, tail) is current interval.

	for i := 0; i < q; i++ {
		fmt.Scan(&cmd)
		if cmd == 1 {
			var p int
			fmt.Scan(&p)
			if p*2 > tail-head {
				is_rev ^= 1
				p = tail - head - p
			}
			if is_rev == 1 {
				fmt.Println("rev", tail-2*p, tail-p-1)
				for i, j := tail-2*p, 1; i < tail-p; i++ {
					a[i] += a[tail-1] - a[tail-1-j]
					j++
				}
				for i := tail - p; i < tail; i++ {
					a[i] = 0
				}
				tail -= p
			} else {
				for i, j := head+p, 1; i < head+p*2; i++ {
					j++
					a[i] -= a[head+p-j]
					a[head+p-j] = 0
				}
				a[head+p-1] = 0
				head += p
			}
		} else {
			var l, r int
			fmt.Scan(&l, &r)
			if is_rev == 0 {
				fmt.Println(a[r+head-1] - a[l+head-1])
			} else {
				fmt.Println(a[tail-1-l] - a[tail-r-1])
			}
		}
	}
}


package main

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

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

const (
	//MaxScanTokenSize = 64 * 1024 // package default
	MaxScanTokenSize = 8 * 1024 * 1024 // 8M
)

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

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
}

func readIntArray(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; i++ {
		a[i] = readInt()
	}
	return a
}

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

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

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

type UnionFindSet struct {
	N int
	Parent []int
}

func NewUnionFindSet(n int) *UnionFindSet {
	ufs := &UnionFindSet{
		N: n,
		Parent: make([]int, n, n),
	}
	for i := range ufs.Parent {
		ufs.Parent[i] = i;
	}
	return ufs
}

func (ufs *UnionFindSet) find(x int) int {
	parent := &ufs.Parent[x]
	if *parent != x {
		*parent = ufs.find(*parent)
	}
	return *parent
}

func (ufs *UnionFindSet) union(x, y int) {
	ufs.Parent[ufs.find(x)] = ufs.find(y)
}

func (ufs *UnionFindSet) show() {
	return
	for i, p := range ufs.Parent {
		fmt.Fprintf(writer, "[%2d]%2d ", i, p)
	}
	fmt.Fprintln(writer)
}

func main() {
	defer writer.Flush()

	n, q := readInt(), readInt()
	ufs := NewUnionFindSet(n + 1)
	next := make([]int, n + 1, n + 1)
	for i := range next {
		next[i] = i + 1
	}
	ufs.show()
	for i := 0; i < q; i++ {
		c, x, y := readInt(), readInt(), readInt()
		//fmt.Fprintf(writer, "c = %d, x = %d, y = %d\n", c, x, y)
		switch c {
		case 1:
			ufs.union(x, y)

			ufs.show()
		case 2:
			if x > y {
				x, y = y, x
			}
			for j := x; j < y; {
				nxt := next[j]
				if y > next[j] {
					next[j] = y
				}
				ufs.union(j, nxt)
				j = nxt
			}

			ufs.show()
		case 3:
			ans := "YES"
			if ufs.find(x) != ufs.find(y) {
				ans = "NO"
			}
			fmt.Fprintln(writer, ans)

			ufs.show()
		}
	}

}

package main

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

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

	var n, q, op, x, y int
	Fscan(in, &n, &q)
	fa := make([]int, n+1)
	next := make([]int, n+1)
	for i := range fa {
		fa[i] = i
		next[i] = i + 1
	}
	var f func(int) int
	f = func(x int) int {
		if fa[x] != x {
			fa[x] = f(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[f(from)] = f(to) }
	for ; q > 0; q-- {
		Fscan(in, &op, &x, &y)
		if op == 1 {
			merge(x, y)
		} else if op == 2 {
			for i := x + 1; i <= y; {
				merge(i-1, i)
				i, next[i] = next[i], next[y]
			}
		} else if f(x) == f(y) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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