package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func scan(args ...interface{}) (int, error) {
	return fmt.Fscan(stdin, args...)
}

func printf(format string, args ...interface{}) {
	fmt.Fprintf(stdout, format, args...)
}

var s string

func main() {
	for true {
		if _, err := scan(&s); err != nil {
			break
		}
		n := len(s)
		longest := 0
		count := 1
		var leftBraceStack []int
		leftBraceStack = append(leftBraceStack, -1)
		stackI := 0
		for i := 0; i < n; i++ {
			if s[i] == '(' {
				if stackI + 1 == len(leftBraceStack) {
					leftBraceStack = append(leftBraceStack, i)
				} else {
					leftBraceStack[stackI + 1] = i
				}
				stackI++
			} else {
				if stackI > 0 {
					length := i - leftBraceStack[stackI - 1]
					stackI--
					if length == longest {
						count++
					} else if (length > longest) {
						longest = length
						count = 1
					}
				} else {
					leftBraceStack[0] = i
				}
			}
		}
		printf("%d %d\n", longest, count)
		stdout.Flush()
	}
}

package main

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

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

	var s string
	Fscan(in, &s)
	bs := []byte(s)

	size := 0
	for i, c := range s {
		if c == '(' {
			size++
		} else {
			size--
			if size < 0 {
				bs[i] = ' '
				size = 0
			}
		}
	}
	size = 0
	for i := len(s) - 1; i >= 0; i-- {
		if s[i] == ')' {
			size++
		} else {
			size--
			if size < 0 {
				bs[i] = ' '
				size = 0
			}
		}
	}
	maxLen := map[int]int{0: 1}
	for _, ss := range strings.Split(string(bs), " ") {
		if ss != "" {
			maxLen[len(ss)]++
		}
	}
	ans := 0
	for l := range maxLen {
		if l > ans {
			ans = l
		}
	}
	Fprint(out, ans, maxLen[ans])
}

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

package main

import (
	"os"
	"strings"
	"fmt"
	"strconv"
	"errors"
	"io"
	"unicode/utf8"
	"bytes"
)

func mx(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
func main() {
	source := []rune(nextWord())
	d := make([]int, len(source))
	t := 0
	m := 0
	for i, x := range source {
		if x == '(' {
			t++
			d[i] = t
		} else {
			d[i] = t
			if t > 0 {
				t--
			}
		}
		m = mx(m, d[i])
	}
	//for i := m; i >= 0; i-- {
	//	for _, x := range d {
	//		if x == i {
	//			fmt.Print(x)
	//		} else {
	//			fmt.Print(" ")
	//		}
	//	}
	//	fmt.Println()
	//}

	l := make([]int, m + 1)
	prev := d[len(d) - 1]
	maxlen := 0
	lencount := make(map[int]int)
	for i := len(d) - 1; i >= 0; i-- {
		if d[i] < prev {
			if l[d[i]] > 0 {
				l[d[i]] += l[d[i + 1]]
			}
			cl := l[d[i + 1]]
			if cl % 2 != 0 {
				cl--
			}
			if _, ok := lencount[cl]; ok {
				lencount[cl]++
			} else {
				lencount[cl] = 1
			}
			maxlen = mx(maxlen, cl)
			l[d[i + 1]] = 0
		}
		l[d[i]]++
		prev = d[i]
	}
	if source[0] == '(' {
		cl := l[d[0]]
		if cl % 2 != 0 {
			cl--
		}
		if _, ok := lencount[cl]; ok {
			lencount[cl]++
		} else {
			lencount[cl] = 1
		}
		maxlen = mx(maxlen, cl)
	}
	if maxlen == 0 {
		fmt.Println("0 1")
	} else {
		fmt.Printf("%d %d\n", maxlen, lencount[maxlen])
	}
}

var lineScanner *Scanner
var wordScanner *Scanner

func init() {
	lineScanner = NewScanner(os.Stdin)
	wordScanner = NewScanner(strings.NewReader(""))
	wordScanner.Split(ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = NewScanner(strings.NewReader(line))
		wordScanner.Split(ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
	empties      int       // Count of successive empty tokens.
	scanCalled   bool      // Scan has been called; buffer is in use.
	done         bool      // Scan has finished.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong         = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar   = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
// MaxScanTokenSize is the maximum size used to buffer a token
// unless the user provides an explicit buffer with Scan.Buffer.
// The actual maximum token size may be smaller as the buffer
// may need to include, for instance, a newline.
	MaxScanTokenSize = 2 * 1024 * 2014

	startBufSize = 4096 // Size of initial allocation for buffer.
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// ErrFinalToken is a special sentinel error value. It is intended to be
// returned by a Split function to indicate that the token being delivered
// with the error is the last token and scanning should stop after this one.
// After ErrFinalToken is received by Scan, scanning stops with no error.
// The value is useful to stop processing early or when it is necessary to
// deliver a final empty token. One could achieve the same behavior
// with a custom error value but providing one here is tidier.
// See the emptyFinalToken example for a use of this value.
var ErrFinalToken = errors.New("final token")

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
// Scan panics if the split function returns 100 empty tokens without
// advancing the input. This is a common error mode for scanners.
func (s *Scanner) Scan() bool {
	if s.done {
		return false
	}
	s.scanCalled = true
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		// If we've run out of data but have an error, give the split function
		// a chance to recover any remaining, possibly empty token.
		if s.end > s.start || s.err != nil {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				if err == ErrFinalToken {
					s.token = token
					s.done = true
					return true
				}
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				if s.err == nil || advance > 0 {
					s.empties = 0
				} else {
					// Returning tokens not advancing input at EOF.
					s.empties++
					if s.empties > 100 {
						panic("bufio.Scan: 100 empty tokens without progressing")
					}
				}
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is needed.
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			// Guarantee no overflow in the multiplication below.
			const maxInt = int(^uint(0) >> 1)
			if len(s.buf) >= s.maxTokenSize || len(s.buf) > maxInt/2 {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize == 0 {
				newSize = startBufSize
			}
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0; ; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				s.empties = 0
				break
			}
			loop++
			if loop > 10 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end-s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Buffer sets the initial buffer to use when scanning and the maximum
// size of buffer that may be allocated during scanning. The maximum
// token size is the larger of max and cap(buf). If max <= cap(buf),
// Scan will use this buffer only and do no allocation.
//
// By default, Scan uses an internal buffer and sets the
// maximum token size to MaxScanTokenSize.
//
// Buffer panics if it is called after scanning has started.
func (s *Scanner) Buffer(buf []byte, max int) {
	if s.scanCalled {
		panic("Buffer called after Scan")
	}
	s.buf = buf[0:cap(buf)]
	s.maxTokenSize = max
}

// Split sets the split function for the Scanner.
// The default split function is ScanLines.
//
// Split panics if it is called after scanning has started.
func (s *Scanner) Split(split SplitFunc) {
	if s.scanCalled {
		panic("Split called after Scan")
	}
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[0 : len(data)-1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return start, nil, nil
}

package main

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

type Pair struct {
	leftIndex  int
	rightIndex int
}

type Brace struct {
	brace byte
	index int
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var s string
	fmt.Fscanf(reader, "%s\n", &s)
	b := []byte(s)

	braceStack, bracePointer := make([]*Brace, 1000000, 1000000), 0
	pairStack, pairPointer := make([]*Pair, 1000000, 1000000), 0
	max, maxCount := 0, 0

	for i := 0; i < len(b); i++ {
		flag := false
		if bracePointer != 0 {
			if braceStack[bracePointer-1].brace == '(' && b[i] == ')' {
				pair := Pair{braceStack[bracePointer-1].index, i}
				bracePointer--
				for pairPointer != 0 {
					p := pairStack[pairPointer-1]
					if p.rightIndex == pair.leftIndex-1 {
						pair.leftIndex = p.leftIndex
						pairPointer--
					} else if p.rightIndex == pair.rightIndex-1 && p.leftIndex == pair.leftIndex+1 {
						pairPointer--
					} else {
						break
					}
				}
				pairStack[pairPointer] = &pair
				pairPointer++
				size := pair.rightIndex - pair.leftIndex + 1
				if size > max {
					max = size
					maxCount = 0
				}
				if size == max {
					maxCount++
				}
				flag = true
			}
		}
		if !flag {
			braceStack[bracePointer] = &Brace{b[i], i}
			bracePointer++
		}
	}
	if max == 0 {
		fmt.Printf("0 1")
	} else {
		fmt.Printf("%d %d", max, maxCount)
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')
	a, b := solve(s)

	fmt.Printf("%d %d\n", a, b)
}

func solve(s string) (int, int) {
	n := len(s)
	dp := make([]int, n)

	st := make([]int, n)
	var p int

	for i := 0; i < n; i++ {
		dp[i] = -1
		if s[i] == '(' {
			st[p] = i
			p++
			continue
		}
		if s[i] == ')' {
			if p == 0 {
				continue
			}
			dp[i] = st[p-1]
			p--
			if dp[i] > 0 && dp[dp[i]-1] >= 0 {
				dp[i] = dp[dp[i]-1]
			}
		}
	}

	var best int
	var cnt = 1
	for i := 0; i < n; i++ {
		if dp[i] < 0 {
			continue
		}
		if i-dp[i]+1 > best {
			best = i - dp[i] + 1
			cnt = 1
		} else if i-dp[i]+1 == best {
			cnt++
		}
	}

	return best, cnt
}

package main

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

var scanner *bufio.Scanner

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

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

  max, count := 0, 1
  line, _ := reader.ReadString('\n')
  s := strings.TrimSpace(line)
  depth := 0
  starts := make([]int, len(s)+1)
  starts[0] = -1
  for pos, rune := range s {
    if rune == '(' {
      depth++
      starts[depth] = pos
    } else if depth == 0 {
      starts[0] = pos
    } else {
      depth--
      length := pos - starts[depth]
      if length == max {
        count++
      } else if length > max {
        max = length
        count = 1
      }
      //writer.WriteString(fmt.Sprintf("depth = %d, starts[%d] = %d, pos = %d, length = %d, max = %d, count = %d\n", depth, depth, starts[depth], pos, length, max, count))
    }
  }
  writer.WriteString(fmt.Sprintf("%d %d\n", max, count))
}

package main

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

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

	var s string
	fmt.Fscanf(r, "%s", &s)

	good := make([]bool, len(s))
	beg := make([]int, len(s))

	for i := 0; i < len(s)-1; i++ {
		if s[i] == ')' {
			continue
		}

		l, r := i, i+1
		stop := false
		for !stop {
			stop = true
			for l >= 0 && r < len(s) && s[l] == '(' && s[r] == ')' {
				good[l] = true
				good[r] = true
				beg[r] = l - 1
				beg[l] = l - 1
				l--
				r++
			}
			stk := make([]int, 0)
			for l >= 0 && good[l] {
				stop = false
				stk = append(stk, l)
				l = beg[l]
			}
			for _, e := range stk {
				beg[e] = l
			}
		}
	}

	best, count := 0, 1
	for i := 0; i < len(s); i++ {
		cc := 0
		for i < len(s) && good[i] {
			i++
			cc++
		}
		if cc == 0 {
			continue
		}
		if best == cc {
			count++
		} else if best < cc {
			best = cc
			count = 1
		}
	}

	fmt.Printf("%d %d\n", best, count)
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var s string
	fmt.Fscanf(reader, "%s\n", &s)
	b := []byte(s)

	var leftCount, rightCount, maxPair, maxCount int

	for i := 0; i < len(b); i++ {
		if s[i] == '(' {
			leftCount++
		} else if s[i] == ')' {
			rightCount++
		}
		if leftCount < rightCount {
			if leftCount > maxPair {
				maxPair = leftCount
				maxCount = 0
			}
			if leftCount == maxPair {
				maxCount++
			}
			leftCount, rightCount = 0, 0
		}
	}
	if rightCount > maxPair {
		maxPair = rightCount
		maxCount = 0
	}
	if rightCount == maxPair {
		maxCount++
	}
	if maxPair == 0 {
		fmt.Printf("0 1")
	} else {
		fmt.Printf("%d %d", maxPair*2, maxCount)
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')
	a, b := solve(s)

	fmt.Sprintf("%d %d\n", a, b)
}

func solve(s string) (int, int) {
	n := len(s)
	dp := make([]int, n)

	st := make([]int, n)
	var p int

	for i := 0; i < n; i++ {
		dp[i] = -1
		if s[i] == '(' {
			st[p] = i
			p++
			continue
		}
		if s[i] == ')' {
			if p == 0 {
				continue
			}
			dp[i] = st[p-1]
			p--
			if dp[i] > 0 && dp[dp[i]-1] >= 0 {
				dp[i] = dp[dp[i]-1]
			}
		}
	}

	var best int
	var cnt = 1
	for i := 0; i < n; i++ {
		if dp[i] < 0 {
			continue
		}
		if i-dp[i]+1 > best {
			best = i - dp[i] + 1
			cnt = 1
		} else if i-dp[i]+1 == best {
			cnt++
		}
	}

	return best, cnt
}

package main

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

var scanner *bufio.Scanner

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

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

  max, count := 0, 1
  line, _ := reader.ReadString('\n')
  s := strings.TrimSpace(line)
  starts := make([]int, len(s))
  depth := 0
  for pos, rune := range s {
    if rune == '(' {
      depth++
      starts[depth] = pos
    } else if depth == 0 {
      starts[0] = pos+1
    } else {
      depth--
      length := pos + 1 - starts[depth]
      if length == max {
        count++
      } else if length > max {
        max = length
        count = 1
      }
    }
  }
  writer.WriteString(fmt.Sprintf("%d %d\n", max, count))
}

package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func scan(args ...interface{}) (int, error) {
	return fmt.Fscan(stdin, args...)
}

func printf(format string, args ...interface{}) {
	fmt.Fprintf(stdout, format, args...)
}

var s string

func main() {
	for true {
		if _, err := scan(&s); err != nil {
			break
		}
		n := len(s)
		longest := 0
		count := 1
		var leftBraceStack []int
		stackI := 0
		for i := 0; i < n; i++ {
			if s[i] == '(' {
				if stackI == len(leftBraceStack) {
					leftBraceStack = append(leftBraceStack, i)
				} else {
					leftBraceStack[stackI] = i
				}
				stackI++
			} else {
				if stackI > 0 {
					length := i - leftBraceStack[stackI - 1] + 1
					stackI--
					if length == longest {
						count++
					} else if (length > longest) {
						longest = length
						count = 1
					}
				}
			}
		}
		printf("%d %d\n", longest, count)
		stdout.Flush()
	}
}

package main

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

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

	var s string
	Fscan(in, &s)

	maxLen := map[int]int{0: 1}
	size, pairCnt := 0, 0
	for _, c := range s {
		if c == '(' {
			size++
		} else {
			size--
			if size >= 0 {
				pairCnt++
				maxLen[2*pairCnt]++
			} else {
				size, pairCnt = 0, 0
			}
		}
	}
	ans := 0
	for l := range maxLen {
		if l > ans {
			ans = l
		}
	}
	Fprintln(out, ans, maxLen[ans])
}

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

package main

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

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

	var s string
	Fscan(in, &s)
	s += "$"

	maxLen := map[int]int{0: 1}
	cnt := 0
	size := 0
	for _, c := range s {
		if c == '(' {
			size++
			cnt++
		} else if c == ')' {
			size--
			if size < 0 {
				size = 0
				if cnt > 0 {
					maxLen[cnt]++
					cnt = 0
				}
			} else {
				cnt++
			}
		} else {
			if size == 0 && cnt > 0 {
				maxLen[cnt]++
			}
		}
	}
	ans := 0
	for l := range maxLen {
		if l > ans {
			ans = l
		}
	}
	Fprintln(out, ans, maxLen[ans])
}

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

package main

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

func mx(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
func main() {
	depth, current, max := 0, 0, 0
	counts := make(map[int]int)
	counts[0] = 1
	source := []rune(nextWord())
	for i, x := range source {
		if x == '(' {
			depth++
		} else if x == ')' {
			if depth > 0 {
				depth--
				current++
				if depth == 0 {
					if i < len(source) - 1 && source[i + 1] == '(' {
						continue
					}
					max = mx(max, current)
					if _, ex := counts[current]; ex {
						counts[current]++
					} else {
						counts[current] = 1
					}
					current = 0
				}
			}
		}
		if i % 100 == 0 {
			runtime.GC()
		}
	}
	max = mx(max, current)
	if _, ex := counts[current]; ex && current > 0 {
		counts[current]++
	} else {
		counts[current] = 1
	}
	printf("%d %d\n", max * 2, counts[max])
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

func mx(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
func main() {
	r := bufio.NewReaderSize(os.Stdin, 2000000)
	src, _ := r.ReadString(byte('\n'))
	source := []rune(src)
	d := make([]int, len(source))
	t := 0
	m := 0
	for i, x := range source {
		if x == '(' {
			t++
			d[i] = t
		} else {
			d[i] = t
			if t > 0 {
				t--
			}
		}
		m = mx(m, d[i])
	}
	//for i := m; i >= 0; i-- {
	//	for _, x := range d {
	//		if x == i {
	//			fmt.Print(x)
	//		} else {
	//			fmt.Print(" ")
	//		}
	//	}
	//	fmt.Println()
	//}

	l := make([]int, m + 1)
	prev := d[len(d) - 1]
	maxlen := 0
	lencount := make(map[int]int)
	for i := len(d) - 1; i >= 0; i-- {
		if d[i] < prev {
			if l[d[i]] > 0 {
				l[d[i]] += l[d[i + 1]]
			}
			cl := l[d[i + 1]]
			if cl % 2 != 0 {
				cl--
			}
			if _, ok := lencount[cl]; ok {
				lencount[cl]++
			} else {
				lencount[cl] = 1
			}
			maxlen = mx(maxlen, cl)
			l[d[i + 1]] = 0
		}
		l[d[i]]++
		prev = d[i]
	}
	if source[0] == '(' {
		cl := l[d[0]]
		if cl % 2 != 0 {
			cl--
		}
		if _, ok := lencount[cl]; ok {
			lencount[cl]++
		} else {
			lencount[cl] = 1
		}
		maxlen = mx(maxlen, cl)
	}
	if maxlen == 0 {
		fmt.Println("0 1")
	} else {
		fmt.Printf("%d %d\n", maxlen, lencount[maxlen])
	}
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

func mx(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("Recovered", r)
		}
	}()
	source := []rune(nextWord())
	d := make([]int, len(source))
	t := 0
	m := 0
	for i, x := range source {
		if x == '(' {
			t++
			d[i] = t
		} else {
			d[i] = t
			if t > 0 {
				t--
			}
		}
		m = mx(m, d[i])
	}
	//for i := m; i >= 0; i-- {
	//	for _, x := range d {
	//		if x == i {
	//			fmt.Print(x)
	//		} else {
	//			fmt.Print(" ")
	//		}
	//	}
	//	fmt.Println()
	//}

	l := make([]int, m + 1)
	prev := d[len(d) - 1]
	maxlen := 0
	lencount := make(map[int]int)
	for i := len(d) - 1; i >= 0; i-- {
		if d[i] < prev {
			if l[d[i]] > 0 {
				l[d[i]] += l[d[i + 1]]
			}
			cl := l[d[i + 1]]
			if cl % 2 != 0 {
				cl--
			}
			if _, ok := lencount[cl]; ok {
				lencount[cl]++
			} else {
				lencount[cl] = 1
			}
			maxlen = mx(maxlen, cl)
			l[d[i + 1]] = 0
		}
		l[d[i]]++
		prev = d[i]
	}
	if source[0] == '(' {
		cl := l[d[0]]
		if cl % 2 != 0 {
			cl--
		}
		if _, ok := lencount[cl]; ok {
			lencount[cl]++
		} else {
			lencount[cl] = 1
		}
		maxlen = mx(maxlen, cl)
	}
	if maxlen == 0 {
		fmt.Println("0 1")
	} else {
		fmt.Printf("%d %d\n", maxlen, lencount[maxlen])
	}
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

func mx(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
func main() {
	depth, current, max := 0, 0, 0
	counts := make(map[int]int)
	counts[0] = 1
	for i, x := range []rune(nextWord()) {
		if x == '(' {
			depth++
		} else if x == ')' {
			if depth > 0 {
				depth--
				current++
				if depth == 0 {
					max = mx(max, current)
					if _, ex := counts[current]; ex {
						counts[current]++
					} else {
						counts[current] = 1
					}
					current = 0
				}
			}
		}
		if i % 100 == 0 {
			runtime.GC()
		}
	}
	printf("%d %d\n", max * 2, counts[max])
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}


package main

import (
	"fmt"
	"log"
	"strings"
)

func main() {
	t := readInt();
	for cases := 0; cases < t; cases++ {
		n := readInt();

		init := strings.Repeat("(", n) + strings.Repeat(")", n); // ((()))
		fmt.Println(init);

		current := []rune(init);
		for i := n-1; i >= 1; i-- {
			current[i], current[i + 1] =  current[i + 1], current[i];
			fmt.Println(string(current));
		}
	}
}

func readInt() int {
	var t int;
	_, err := fmt.Scanf("%d\n", &t)
	if err != nil {
		log.Fatal(err);
	}
	return t;
}

package main

import "fmt"

func GenDepth(depth int) []string {
	ret := make([]string, 0, depth)
	for i := 0; i < depth; i++ {
		var s string
		for j := 0; j < depth-i; j++ {
			s += "()"
		}
		for k := 0; k < i; k++ {
			s = "(" + s + ")"
		}
		//fmt.Println(s)
		ret = append(ret, s)
	}
	return ret
}

func main() {
	var t, n int
	var res []string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n)
		res = append(res, GenDepth(n)...)
	}
	for _, elem := range res {
		fmt.Println(elem)
	}
}

package main

import (
	"fmt"
	"strings"
)

//A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.
//
//You are given an integer 𝑛. Your goal is to construct and print exactly 𝑛 different regular bracket sequences of length 2𝑛.
//
//Input
//The first line contains one integer 𝑡 (1≤𝑡≤50) — the number of test cases.
//
//Each test case consists of one line containing one integer 𝑛 (1≤𝑛≤50).
//
//Output
//For each test case, print 𝑛 lines, each containing a regular bracket sequence of length exactly 2𝑛. All bracket sequences you output for a testcase should be different (though they may repeat in different test cases). If there are multiple answers, print any of them. It can be shown that it's always possible.

func main() {
	var t, n int
	mp := make(map[int][]string)
	for fmt.Scan(&t); t > 0; t-- {
		fmt.Scan(&n)
		if arr, ok := mp[n]; ok {
			for _, v := range arr {
				fmt.Println(v)
			}
		} else {
			ans := generateParenthesis(n)
			mp[n] = ans
			for _, v := range ans {
				fmt.Println(v)
			}
		}
	}
}

func generateParenthesis(n int) []string {
	s := []byte(strings.Repeat("(", n) + strings.Repeat(")", n))
	ans := []string{string(s)}
	for i := 1; i < n; i++ {
		s[i], s[2*n-1-i] = s[2*n-1-i], s[i]
		ans = append(ans, string(s))
		s[i], s[2*n-1-i] = s[2*n-1-i], s[i]
	}
	return ans
}

package main

import "fmt"

// InsertNodeToTree ...
func InsertNodeToTree(L int, H int, R int, T string, N int, j *int) {
	if H == 0 {
		*j = *j + 1
		fmt.Println(T)
		return
	}

	if R > 0 && R-L > 0 && *j < N {
		InsertNodeToTree(L, H-1, R-1, T+")", N, j)
	}

	if L > 0 && *j < N {
		InsertNodeToTree(L-1, H-1, R, T+"(", N, j)
	}
	return
}

func main() {
	var t, n, j int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d\n", &n)
		j = 0
		InsertNodeToTree(n, 2*n, n, "", n, &j)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)

		for j:=n;j>0;j--{
			for k:=1;k<=j;k++{
				fmt.Fprintf(out,"(")
			}
			for k:=1;k<=j;k++{
				fmt.Fprintf(out,")")
			}
			for k:=n;k>j;k--{
				fmt.Fprintf(out,"()")
			}
			fmt.Fprintln(out,)
		}
	}
}

package main

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

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

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

		var buf bytes.Buffer
		for i := 0; i < n; i++ {
			buf.WriteString("()")
		}

		s := buf.String()
		fmt.Fprintln(out, s)
		var pos int
		for i := 0; i < n-1; i++ {
			buf.Reset()

			buf.WriteString(s[:pos])
			buf.WriteString("(())")
			buf.WriteString(s[pos+4:])
			fmt.Fprintln(out, buf.String())
			pos += 2
		}
	}
}

package main

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

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

	for test := parseInt(getString(reader)); test > 0; test-- {
		n := parseInt(getString(reader))
		permutations := make([]string, 0, n)
		baseArray := make([]byte, 0, 2*n)
		for i := 0; i < n; i++ {
			baseArray = append(baseArray, byte('('), byte(')'))
		}
		permutations = append(permutations, string(baseArray))
		for i := 1; i < n; i++ {
			baseArray[2*i] = byte(')')
			baseArray[2*i-1] = byte('(')
			permutations = append(permutations, string(baseArray))
		}
		for i := 0; i < n; i++ {
			writer.WriteString(fmt.Sprintln(permutations[i]))
		}
	}
	writer.Flush()
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	t, _ := reader.ReadString('\n')
	t = strings.TrimSpace(t)
	total, _ := strconv.Atoi(t)
	open := "("
	close := ")"
	for x := 0; x < total; x++ {
		n, _ := reader.ReadString('\n')
		n = strings.TrimSpace(n)
		nn, _ := strconv.Atoi(n)
		for i := 0; i < nn; i++ {
			for j := 0; j < i+1; j++ {
				fmt.Print(open)
			}
			for j := 0; j < i+1; j++ {
				fmt.Print(close)
			}
			for j := 0; j < nn-(i+1); j++ {
				fmt.Print(open, close)
			}
			fmt.Printf("\n")
		}
	}
}

package main

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

type CF1574A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1574A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1574A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1574A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1574A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1574A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1574A
Date: 6/12/21
User: epradere
URL: https://codeforces.com/problemset/problem/1574/A
Problem: CF1574A
**/
func (in *CF1574A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

		for i := 0; i < n; i++ {
			str := ""
			cont := 0
			ws := false
			for j := 0; j < 2*n; j++ {
				if cont <= i && !ws {
					str += "("
					cont++
				} else if ws && cont <= 0 {
					if -cont%2 == 0 {
						str += "("
					} else {
						str += ")"
					}
					cont--
				} else {
					ws = true
					str += ")"
					cont--
				}

			}
			fmt.Println(str)

		}
	}
}

func NewCF1574A(r *bufio.Reader) *CF1574A {
	return &CF1574A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1574A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		for i := n; i >= 1; i-- {
			for j := 0; j < i; j++ {
				fmt.Print("(")
			}
			for j := 0; j < i; j++ {
				fmt.Print(")")
			}
			for j := 0; j < n-i; j++ {
				fmt.Print("()")
			}
			fmt.Println()
		}
	}
}

package main

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

func RegularBracket() {
	// Codeforces 1574A
	// Construct exactly n different regular bracket sequences of length 2n.

	sc := bufio.NewScanner(os.Stdin)
	nested := func(i int) string {
		result := make([]byte, 2*i)
		for j := 0; j < i; j++ {
			result[j] = '('
			result[i+j] = ')'
		}
		return string(result)
	}
	brackets := make([][]string, 51)
	brackets[1] = []string{"()"}
	for i := 2; i < len(brackets); i++ {
		brackets[i] = make([]string, i)
		brackets[i][0] = nested(i)
		for j := 1; j < len(brackets[i]); j++ {
			brackets[i][j] = brackets[i-1][j-1] + "()"
		}
	}
	for tcs := ScanPosInt(sc); tcs > 0; tcs-- {
		n := ScanPosInt(sc)
		for _, solution := range brackets[n] {
			fmt.Println(solution)
		}
	}
}

func main() {
	RegularBracket()
}

func ScanPosInt(sc *bufio.Scanner) (n int) {
	sc.Scan()
	buf := sc.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

package main

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

func Problem1574A(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	t := 0
	fmt.Fscanln(in, &t)

	for tcNo := 1; tcNo <= t; tcNo++ {
		n := 0
		fmt.Fscanln(in, &n)

		result := make([]string, 0)
		for i := 0; i < n; i++ {
			temp := strings.Repeat("()", n-i-1) + strings.Repeat("(", i+1) + strings.Repeat(")", i+1)
			result = append(result, temp)
		}
		fmt.Fprintln(out, strings.Join(result, "\n"))
	}
}

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

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()

	}
}

func solve() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		for j := 0; j <= i; j++ {
			fmt.Printf("(")
		}
		for j := 0; j <= i; j++ {
			fmt.Printf(")")
		}
		for j := i + 1; j < n; j++ {
			fmt.Printf("()")
		}
		fmt.Println()
	}

}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		var n int
		fmt.Scan(&n)
		var s string
		for i := 0; i < n; i++ {
			s += "("
		}
		for i := 0; i < n; i++ {
			s += ")"
		}
		r := []rune(s)
		fmt.Println(string(r))
		ant := n
		for i := 0; i < n-1; i++ {
			r[ant-1], r[ant] = r[ant], r[ant-1]
			fmt.Println(string(r))
			ant -= 1
		}
		t -= 1
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

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

		solve(n)
	}
}

func solve(n int) {
	//2 * n

	for i := n; i >= 1; i-- {

		for j := 0; j < i; j++ {
			fmt.Print("(")
		}

		for j := 0; j < n - i; j++ {
			fmt.Print(")(")
		}

		for j := 0; j < i; j++ {
			fmt.Print(")")
		}

		fmt.Println()
	}
}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

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

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscanf(r, "%d\n", &n)

		var gen func(k int) []string
		gen = func(k int) []string {
			if k == 2 {
				return []string{"()"}
			} else {
				x := gen(k - 2)
				res := []string{}

				for _, v := range x {
					res = append(res, "()"+v)
					res = append(res, "("+v+")")
				}

				if len(res) < n {
					return res
				}

				return res[:n]
			}
		}

		x := gen(n * 2)

		for i := 0; i < n; i++ {
			fmt.Println(x[i])
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func ReadInput() []string {
	var t int
	fmt.Fscan(os.Stdin, &t)
	var res []string = make([]string, 0, t)
	for i := 0; i < t; i++ {
		var l int
		fmt.Fscan(os.Stdin, &l)
		var s string
		fmt.Fscan(os.Stdin, &s)
		res = append(res, s)
	}
	return res
}

func main() {
	Sslice := ReadInput()
	//fmt.Println(Sslice)
	for i := 0; i < len(Sslice); i++ {
		var s string
		OtherRow := Sslice[i]
		for j := 0; j < len(OtherRow); j++ {
			switch OtherRow[j] {
			case 'U':
				s += "D"
			case 'D':
				s += "U"
			default:
				s += string(OtherRow[j])
			}
		}
		fmt.Println(s)
	}
}

package main

import "fmt"

// InsertNodeToTree ...
func InsertNodeToTree(L int, H int, R int, T string, N int, j *int) {
	if H == 0 {
		*j = *j + 1
		fmt.Println(T)
		return
	}

	if R > 0 && R-L > 0 && *j < N {
		InsertNodeToTree(L, H-1, R-1, T+")", N, j)
	}

	if L > 0 && *j < N {
		InsertNodeToTree(L-1, H-1, R, T+"(", N, j)
	}
	return
}

func main() {
	var t, n, j int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d", &n)
		j = 0
		InsertNodeToTree(n, 2*n, n, "", n, &j)
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
)
func main() {

	var T int
	fmt.Scan(&T)
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	for z := 0; z < T; z++ {
		r.Scan()
		red := toInt(r.Bytes())
		r.Scan()
		green := toInt(r.Bytes())
		r.Scan()
		blue := toInt(r.Bytes())
		r.Scan()
		white := toInt(r.Bytes())
		evenCount := 0
		oddCount := 0

		if red % 2 == 0 {
			evenCount++
		} else {
			oddCount++
		}

		if green % 2 == 0 {
			evenCount++
		} else {
			oddCount++
		}

		if blue % 2 == 0 {
			evenCount++
		} else {
			oddCount++
		}
		if white%2 == 0 {
			if evenCount == 3  || evenCount == 2 || evenCount == 0 {
				fmt.Println("Yes")
				continue
			}
			// 1
			fmt.Println("No")
		} else {
			if evenCount == 3 || evenCount == 0 {
				fmt.Println("Yes")
				continue
			} else if evenCount == 1 {
				if red != 0 && blue != 0 && green!=0 {
					fmt.Println("Yes")
					continue
				}
			}
			// 2
			fmt.Println("No")
		}

	}

}

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

package main

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

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

	input := func() uint64 {
		scanner.Scan()
		i, _ := strconv.ParseUint(scanner.Text(), 10, 64)
		return i
	}

	for t := input(); t > 0; t-- {
		a := make([]uint64, 4)

		for i := range a {
			a[i] = input()
		}

		min := a[0]

		for i := 0; i < 3; i++ {
			if min > a[i] {
				min = a[i]
			}
		}

		var i uint64
		var found bool = false
		for ; i <= min; i = i*i+1 {
			numEven := 0

			for j := 0; j < 4; j++ {
				if a[j]%2 == 0 {
					numEven++
				}
			}

			if numEven >= 3 {
				found = true
			}

			if found {
				break
			}

			for j := 0; j < 3; j++ {
				a[j]--
			}

			a[3] += 3
		}

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

package main

import "fmt"

type Colours struct {
	R, G, B, W int
}

func (c *Colours) countOdd() int {
	return (c.R & 1) + (c.G & 1) + (c.B & 1) + (c.W & 1)
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		var c Colours
		fmt.Scanf("%d %d %d %d\n", &c.R, &c.G, &c.B, &c.W)

		// possible to form a palindrome if number of odd colours is <= 1
		// operation: reduce R, G, B by 1, add 1 to W -- flips parity of all
		if c.countOdd() <= 1 || (c.countOdd() >= 3 && c.R > 0 && c.G > 0 && c.B > 0) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var r, g, b, w int
		fmt.Fscan(in, &r)
		fmt.Fscan(in, &g)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &w)

		odds := 0
		whiteOdds := 0

		if r%2 != 0 {
			odds++
		}
		if g%2 != 0 {
			odds++
		}
		if b%2 != 0 {
			odds++
		}
		if w%2 != 0 {
			whiteOdds++
		}

		if (odds + whiteOdds) <= 1 {
			fmt.Println("Yes")
			continue
		}

		if r == 0 || g == 0 || b == 0 {
			fmt.Println("No")
			continue
		}

		if whiteOdds == 1 && odds == 2 {
			fmt.Println("Yes")
			continue
		}

		if odds == 3 {
			fmt.Println("Yes")
			continue
		}

		fmt.Println("No")

	}
}

/*
URL:
https://codeforces.com/contest/1395/problem/A
*/

package main

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

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

var (
	t int

	r, g, b, w int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		r, g, b, w = ReadInt4()

		solve()
	}
}

func solve() {
	S := int64(r) + int64(g) + int64(b) + int64(w)

	tmp := []int{r, g, b, w}
	even := 0
	for _, a := range tmp {
		if a%2 == 0 {
			even++
		}
	}

	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		// if even == 4 || even == 3 {
		fmt.Println("Yes")
		return
	}

	mini := Min(r, g, b)
	if mini == 0 {
		fmt.Println("No")
		return
	}

	tmp2 := []int{r - 1, g - 1, b - 1, w + 3}
	even = 0
	for _, a := range tmp2 {
		if a%2 == 0 {
			even++
		}
	}
	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		// if even == 4 || even == 3 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

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
)

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

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

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

/********** 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...)

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

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

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

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

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(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
}

/*
URL:
https://codeforces.com/contest/1395/problem/A
*/

package main

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

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

var (
	t int

	r, g, b, w int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		r, g, b, w = ReadInt4()

		solve()
	}
}

func solve() {
	// S := r + g + b + w

	tmp := []int{r, g, b, w}
	even := 0
	for _, a := range tmp {
		if a%2 == 0 {
			even++
		}
	}

	// if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
	if even == 4 || even == 3 {
		fmt.Println("Yes")
		return
	}

	mini := Min(r, g, b)
	if mini == 0 {
		fmt.Println("No")
		return
	}

	tmp2 := []int{r - 1, g - 1, b - 1, w + 3}
	even = 0
	for _, a := range tmp2 {
		if a%2 == 0 {
			even++
		}
	}
	// if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
	if even == 4 || even == 3 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

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
)

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

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

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

/********** 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...)

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

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

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

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

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(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"
	"os"
	"strconv"
)

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

	input := func() uint64 {
		scanner.Scan()
		i, _ := strconv.ParseUint(scanner.Text(), 10, 64)
		return i
	}

	for t := input(); t > 0; t-- {
		a := make([]uint64, 4)

		for i := range a {
			a[i] = input()
		}

		min := a[0]

		for i := 0; i < 3; i++ {
			if min > a[i] {
				min = a[i]
			}
		}

		for i := 0; i < 3; i++ {
			a[i] -= min
		}

		a[3] += 3 * min

		numEven := 0

		for i := 0; i < 4; i++ {
			if a[i]%2 == 0 {
				numEven++
			}
		}

		if numEven >= 3 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var r, g, b, w int
		fmt.Fscan(in, &r)
		fmt.Fscan(in, &g)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &w)

		odds := 0
		whiteOdds := 0

		if r%2 != 0 {
			odds++
		}
		if g%2 != 0 {
			odds++
		}
		if b%2 != 0 {
			odds++
		}
		if w%2 != 0 {
			whiteOdds++
		}

		if (odds + whiteOdds) <= 1 {
			fmt.Println("Yes")
			continue
		}

		if r == 0 || g == 0 || b == 0 {
			fmt.Println("No")
			continue
		}

		if whiteOdds == 1 && odds == 2 {
			fmt.Println("Yes")
			continue
		}

		if whiteOdds == 0 && odds == 3 {
			fmt.Println("Yes")
			continue
		}

		fmt.Println("No")

	}
}

/*
URL:
https://codeforces.com/contest/1395/problem/A
*/

package main

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

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

var (
	t int

	r, g, b, w int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		r, g, b, w = ReadInt4()

		solve()
	}
}

func solve() {
	S := r + g + b + w

	tmp := []int{r, g, b, w}
	even := 0
	for _, a := range tmp {
		if a%2 == 0 {
			even++
		}
	}

	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		fmt.Println("Yes")
		return
	}

	// mini := Min(tmp...)
	mini := Min(r, g, b)
	if mini == 0 {
		fmt.Println("No")
		return
	}

	tmp2 := []int{r - 1, g - 1, b - 1, w + 3}
	even = 0
	for _, a := range tmp2 {
		if a%2 == 0 {
			even++
		}
	}
	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

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
)

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

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

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

/********** 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...)

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

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

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

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

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(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
}

/*
URL:
https://codeforces.com/contest/1395/problem/A
*/

package main

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

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

var (
	t int

	r, g, b, w int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		r, g, b, w = ReadInt4()

		solve()
	}
}

func solve() {
	S := r + g + b + w

	tmp := []int{r, g, b, w}
	even := 0
	for _, a := range tmp {
		if a%2 == 0 {
			even++
		}
	}

	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		fmt.Println("Yes")
		return
	}

	mini := Min(tmp...)
	if mini == 0 {
		fmt.Println("No")
		return
	}

	tmp2 := []int{r - 1, g - 1, b - 1, w + 3}
	even = 0
	for _, a := range tmp2 {
		if a%2 == 0 {
			even++
		}
	}
	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

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
)

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

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

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

/********** 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...)

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

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

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

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

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(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
}

/*
URL:
https://codeforces.com/contest/1395/problem/A
*/

package main

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

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

var (
	t int

	r, g, b, w int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		r, g, b, w = ReadInt4()

		solve()
	}
}

func solve() {
	tmp := []int{r, g, b, w}
	even := 0
	for _, a := range tmp {
		if a%2 == 0 {
			even++
		}
	}

	if even == 4 || even == 3 {
		fmt.Println("Yes")
		return
	}

	mini := Min(tmp...)
	if mini == 0 {
		fmt.Println("No")
		return
	}

	tmp2 := []int{r - 1, g - 1, b - 1, w + 3}
	even = 0
	for _, a := range tmp2 {
		if a%2 == 0 {
			even++
		}
	}
	if even == 4 || even == 3 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

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
)

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

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

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

/********** 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...)

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

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

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

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

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(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
}


// 286A
package main

import (
	"fmt"
)

func main() {
	var n, i, x, sum int
	fmt.Scan(&n)
	if n%4 == 2 || n%4 == 3 {
		fmt.Print(-1)
		return
	}
	sum = n + 2
	for i = 1; i <= n/2/2; i++ {
		x += 2
		fmt.Printf("%d %d ", x, sum-x)
	}
	if n&1 == 1 {
		fmt.Printf("%d ", n/2+1)
	}
	sum -= 2
	x = n/2 + 1
	for i = 1; i <= n/2/2; i++ {
		x -= 2
		fmt.Printf("%d %d ", x, sum-x)
	}
}

//286A
package main
import "fmt"

func main() {
	var nn, x, y int
	var a[100005]int
	fmt.Scan(&nn)
	x=nn
	if nn==1 {
		fmt.Println("1")
	} else {
		if nn%4==0 || nn%4==1 {
			for i:=1; i<=nn/2; i++ {
				a[i]=i+1
				a[i+1]=x
				a[x-1]=i
				a[x]=x-1
				x=x-2
				i++
			}
			if nn%2==0 {
				for i:=1; i<=nn; i++ {
					fmt.Print(a[i]," ")
				}
			} else {
				y=nn/2+1
				a[y]=y
				for i:=1; i<=nn; i++ {
					fmt.Print(a[i]," ")
				}
			}
		} else {
			fmt.Println("-1")
		}
	}
	fmt.Println()
}

// 286B
package main

import (
	"fmt"
)

func main() {
	var n, i, x, sum int
	fmt.Scan(&n)
	if n%4 == 2 || n%4 == 3 {
		fmt.Print(-1)
		return
	}
	sum = n + 2
	for i = 1; i <= n/2/2; i++ {
		x += 2
		fmt.Printf("%d %d ", x, sum-x)
	}
	if n&1 == 1 {
		fmt.Printf("%d ", n/2+1)
	}
	sum -= 2
	x = n/2 + 1
	for i = 1; i <= n/2/2; i++ {
		x -= 2
		fmt.Printf("%d %d ", x, sum-x)
	}
}


/*
https://codeforces.com/contest/1647/problem/C

*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line_arr := strings.Fields(line)
	T, _ := strconv.Atoi(line_arr[0])
	for t := 0; t<T; t++ {
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		N, _ := strconv.Atoi(line_arr[0])
		M, _ := strconv.Atoi(line_arr[1])
		arr := make([][]rune, N)
		for i:=0; i<N; i++ {
			arr[i] = make([]rune, M)
			line, _ = reader.ReadString('\n')
			for j:=0; j<M; j++ {
				arr[i][j] = rune(line[j])
			}
		}
		//fmt.Printf("arr: %c\n", arr)
		nsteps, retarr := computeSteps(N, M, arr)
		fmt.Println(nsteps)
		for i:=0; i<nsteps; i++ {
			fmt.Printf("%d %d %d %d\n", retarr[i][0], retarr[i][1], retarr[i][2], retarr[i][3])
		}
	}
}

func computeSteps(n, m int, arr [][]rune) (nsteps int, retarr [][]int) {

	if arr[0][0] == '1' {
		nsteps = -1
		return
	}

	// process rows
	for i:=0; i<n; i++ {
		for j:=m-1; j>0; j-- {
			if arr[i][j] == '1' {
				nsteps++
				rect := []int{i+1, j, i+1, j+1}
				retarr = append(retarr, rect)
			}
		}
	}

	// process onlt the left most column
	for i:=n-1; i>0; i-- {
		if arr[i][0] == '1' {
			nsteps++
			rect := []int{i, 1, i+1, 1}
			retarr = append(retarr, rect)
		}
	}
	return
}

package main

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

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

const mod = 998244353

// 1 2 3 4
func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		grids := make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &grids[i])
		}
		if grids[0][0] == '1' {
			fmt.Fprintln(out, -1)
			continue
		}
		var ans [][]int
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if grids[i][j] == '1' {
					if i == 0 {
						ans = append(ans, []int{i + 1, j, i + 1, j + 1})
					} else {
						ans = append(ans, []int{i, j + 1, i + 1, j + 1})
					}
				}
			}
		}
		fmt.Fprintln(out, len(ans))
		for i := 0; i < len(ans); i++ {
			fmt.Fprintln(out, ans[i][0], ans[i][1], ans[i][2], ans[i][3])
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)
	for t := 0; t < q; t++ {
		var n, m int
		fmt.Scan(&n, &m)
		A := make([]string, n)
		for i, _ := range A {
			fmt.Scan(&A[i])
		}
		if A[0][0] == '1' {
			fmt.Println(-1)
			continue
		} else {
			fmt.Println(n * m)
		}
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if A[i][j] == '0' {
					fmt.Println(i + 1, j + 1, i + 1, j + 1)
				} else {
					if i == 0 {
						fmt.Println(i + 1, j, i + 1, j + 1)
					} else {
						fmt.Println(i, j + 1, i + 1, j + 1)
					}
				}
			}
		}
	}
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var t int
	Fscan(in, &t)

	for k := 0; k < t; k++ {
		var n, m int

		Fscan(in, &n, &m)

		a := make([]string, n+1)

		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}

		if a[0][0] == '1' {
			Fprintln(out, "-1")
			continue
		}

		cnt := 0

		ans := make([]string, 0)
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if a[i][j] == '1' {
					cnt++
					if j > 0 {
						ans = append(ans, Sprint(i+1, j, i+1, j+1))
					} else {
						ans = append(ans, Sprint(i, j+1, i+1, j+1))
					}

				}
			}
		}
		Fprintln(out, cnt)
		for _, s := range ans {
			Fprintln(out, s)
		}

	}

}

package main

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

func solve(arr [][]int, out io.Writer) {
	n, m := len(arr), len(arr[0])
	ans := make([][]int, 0, n*m+5)
	for i := n - 1; i >= 0; i-- {
		for j := m - 1; j >= 0; j-- {
			if arr[i][j] == 0 {
				continue
			}
			if j == 0 {
				ans = append(ans, []int{i - 1, 0, i, 0})
			} else {
				ans = append(ans, []int{i, j - 1, i, j})
			}
		}
	}
	Fprintln(out, len(ans))
	for _, v := range ans {
		Fprintf(out, "%d %d %d %d\n", v[0]+1, v[1]+1, v[2]+1, v[3]+1)
	}
}
func CF1647C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var n, m int
	var s string
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		arr := make([][]int, n)
		for i := range arr {
			arr[i] = make([]int, m)
		}
		for i := 0; i < n; i++ {
			Fscan(in, &s)
			for j := 0; j < m; j++ {
				if s[j] == '1' {
					arr[i][j] = 1
				} else {
					arr[i][j] = 0
				}
			}
		}
		if arr[0][0] == 1 {
			Fprintln(out, -1)
		} else {
			solve(arr, out)
		}
		out.Flush()
	}
}

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

package main

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

var in = bufio.NewReader(os.Stdin)

func read(out *int) error {
	var ans, sign int = 0, 1
	var readed = false
	c, err := in.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = in.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = in.ReadByte() {
		ans = ans<<3 + ans<<1 + int(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}
func read1(out *int) error {
	c, err := in.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = in.ReadByte() {
	}
	*out = int(c - '0')
	return err
}

var n, m, T int
var s [105][105]int

type nod struct {
	x1, y1, x2, y2 int
}

func makenod(x1, y1, x2, y2 int) (ret nod) {
	ret.x1 = x1
	ret.y1 = y1
	ret.x2 = x2
	ret.y2 = y2
	return
}
func solve() {
	read(&n)
	read(&m)
	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			read1(&s[i][j])
		}
	}
	ve := make([]nod, 0)
	if s[1][1] == 1 {
		fmt.Println("-1")
		return
	}
	for i := 0; i <= n+1; i++ {
		s[i][0] = 0
		s[i][m+1] = 0
	}
	for j := 0; j <= m+1; j++ {
		s[0][j] = 0
		s[n+1][j] = 0
	}
	for i := 1; i <= n; i++ {
		for j := m; j >= 2; j-- {
			if s[i][j] == 1 {
				ve = append(ve, makenod(i, j-1, i, j))
			}
		}
	}
	for i := n; i >= 2; i-- {
		if s[i][1] == 1 {
			ve = append(ve, makenod(i-1, 1, i, 1))
		}
	}
	fmt.Printf("%d\n", len(ve))
	for _, i := range ve {
		fmt.Printf("%d %d %d %d\n", i.x1, i.y1, i.x2, i.y2)
	}
}
func main() {
	read(&T)
	for ; T > 0; T-- {
		solve()
	}
}

package main

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

/*
2
1 1
0
1 1
1
---
0
-1
====

1
2 3
001
010
---
1 2 2 2
1 2 1 3
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, m int
	scanf("%d %d\n", &n, &m)

	tbl := make([]string, n)

	cnt := 0

	for i := range tbl {
		scanf("%s\n", &tbl[i])

		for _, r := range tbl[i] {
			if r == '1' {
				cnt++
			}
		}
	}

	if tbl[0][0] == '1' {
		fmt.Fprintln(writer, -1)
		return
	}

	fmt.Fprintln(writer, cnt)

	for i := n - 1; i > 0; i-- {
		for j := m - 1; j >= 0; j-- {
			if tbl[i][j] == '1' {
				fmt.Fprintln(writer, i, j+1, i+1, j+1)
			}
		}
	}

	for j := m - 1; j > 0; j-- {
		if tbl[0][j] == '1' {
			fmt.Fprintln(writer, 1, j, 1, j+1)
		}
	}
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	idx := 0
	for i, num := range nums {
		if num > nums[idx] {
			idx = i
		}
	}

	return nums[idx]
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

func main() {
	_r, _w := os.Stdin, os.Stdout
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var solve func()
	// Todo...
	solve = func() {
		var n, m int
		Fscan(in, &n, &m)
		rec := make([][]int, n+2)
		for i := 0; i < n+2; i++ {
			rec[i] = make([]int, m+2)
		}
		for i := 0; i < n+2; i++ {
			for j := 0; j < m+2; j++ {
				rec[i][j] = 1
			}
		}
		var s string
		for i := 1; i <= n; i++ {
			Fscan(in, &s)
			for j := 1; j <= m; j++ {
				if s[j-1] == '1' {
					rec[i][j] = 1
				} else {
					rec[i][j] = 0
				}
			}
		}
		ok := true
		ans := make([][]int, 0)
		for i := 1; i <= n; i++ {
			for j := m; j >= 1; j-- {
				if rec[i][j] == 1 {
					if j-1 >= 1 {
						ans = append(ans, []int{i, j - 1, i, j})
						rec[i][j] = 0
					}
				}
			}
		}
		for j := 1; j <= m; j++ {
			for i := n; i >= 1; i-- {
				if rec[i][j] == 1 {
					if i-1 >= 1 {
						ans = append(ans, []int{i - 1, j, i, j})
						rec[i][j] = 0
					}
				}
			}
		}
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				if rec[i][j] == 1 {

					ok = false
				}
			}
		}
		if ok {
			Fprintln(out, len(ans))
			for _, v := range ans {
				Fprintln(out, v[0], " ", v[1], " ", v[2], " ", v[3])
			}
			Fprintln(out)
		} else {
			Fprintln(out, "-1")
		}
	}
	// End...
	var T int = 1
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

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

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

const mod = 998244353

// 1 2 3 4
func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		grids := make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &grids[i])
		}
		if grids[0][0] == '1' {
			fmt.Fprintln(out, -1)
			continue
		}
		var ans [][]int
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if grids[i][j] == '1' {
					if i == 0 {
						ans = append(ans, []int{i, j - 1, i, j})
					} else {
						ans = append(ans, []int{i - 1, j, i, j})
					}
				}
			}
		}
		fmt.Fprintln(out, len(ans))
		for i := 0; i < len(ans); i++ {
			fmt.Fprintln(out, ans[i][0], ans[i][1], ans[i][2], ans[i][3])
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)
	for t := 0; t < q; t++ {
		var n, m int
		fmt.Scan(&n, &m)
		A := make([]string, n)
		for i, _ := range A {
			fmt.Scan(&A[i])
		}
		if A[0][0] == '1' {
			fmt.Println(-1)
			continue
		} else {
			fmt.Println(n * m)
		}
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if A[i][j] == '0' {
					fmt.Println(i, j, i, j)
				} else {
					if i == 0 {
						fmt.Println(i, j-1, i, j)
					} else {
						fmt.Println(i-1, j, i, j)
					}
				}
			}
		}
	}
}