package main

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

type Contest struct {
	in *bufio.Scanner
	out io.Writer
}

func NewSubmitContest() *Contest {
	C := &Contest{bufio.NewScanner(os.Stdin), os.Stdout}
	C.SetSplit(bufio.ScanWords)
	return C
}

func NewTestContest(testIn string, testOut *bytes.Buffer) *Contest  {
	C := &Contest{bufio.NewScanner(strings.NewReader(testIn)), testOut}
	C.SetSplit(bufio.ScanWords)
	return C
}

func (C *Contest) SetSplit(split bufio.SplitFunc) *Contest  {
	C.in.Split(split)
	return C
}

func (C *Contest) InStr() string {
	C.in.Scan()
	return C.in.Text()
}

func (C *Contest) InBytes() []byte {
	C.in.Scan()
	return C.in.Bytes()
}

func (C *Contest) InInt() int {
	C.in.Scan()
	i, _ := strconv.Atoi(C.in.Text())
	return i
}

func (C *Contest) InInt64() int64 {
	C.in.Scan()
	i, _ := strconv.ParseInt(C.in.Text(), 10, 64)
	return i
}

func (C *Contest) Out(format string, a ...interface{}) {
	fmt.Fprintf(C.out, format, a...)
}

func (C *Contest) MaxInt64(i1, i2 int64) int64 {
	if i1 > i2 {
		return i1
	}
	return i2
}

var (
	n, k int
	a []int64
	dpDone [][]bool
	dpRes [][]bool
)

// https://codeforces.com/contest/981/problem/D
func problem(C *Contest) {
	n = C.InInt()
	k = C.InInt()

	a = make([]int64, n)
	for i := range a {
		a[i] = C.InInt64()
	}

	dpRes = make([][]bool, n + 1)
	for i := range dpRes {
		dpRes[i] = make([]bool, k + 1)
	}

	var best, x int64
	for i := 62; i >= 0; i-- {
		dpDone = make([][]bool, n + 1)
		for i := range dpDone {
			dpDone[i] = make([]bool, k + 1)
		}

		x = int64(1) << uint(i)
		if checkSplit(best|x, n, k) {
			best |= x
		}
	}

	C.Out("%d\n", best)
}

func checkSplit(x int64, n int, k int) bool {
	if k < 0 {
		return false
	} else if dpDone[n][k] {
		return dpRes[n][k]
	} else {
		dpDone[n][k] = true
	}

	sum := int64(0)
	for i := n - 1; i >= 0; i-- {
		sum += a[i]
		if sum & x == x {
			if checkSplit(x, i, k - 1) {
				dpRes[n][k] = true
				return dpRes[n][k]
			}
		}
	}

	dpRes[n][k] = (n == 0) && (k == 0)
	return dpRes[n][k]
}

func main() {
	c := NewSubmitContest()
	problem(c)
}

package main

import "fmt"

func pos(a []int64, k int, m int64) bool {
	sum := make([]int64, len(a)+1)
	for i := range a {
		sum[i+1] = sum[i] + a[i]
	}

	dp := make([][]bool, k+1)
	dp[0] = make([]bool, len(a)+1)
	dp[0][0] = true
	for i := 1; i <= k; i++ {
		dp[i] = make([]bool, len(a)+1)
		for used := i; used <= len(a); used++ {
			for prev := i - 1; prev < used; prev++ {
				dp[i][used] = dp[i-1][prev] && (sum[used]-sum[prev])&m == m
				if dp[i][used] {
					break
				}
			}
		}
	}
	return dp[k][len(a)]
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int64, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	cur := int64(0)
	for bit := int64(1 << 60); bit > 0; bit /= 2 {
		if pos(a, k, cur|bit) {
			cur |= bit
		}
	}
	fmt.Println(cur)
}

package main

import "fmt"

const maxn  = 55

var (
	n, k int
	sum [maxn]int64
	dp [maxn][maxn]bool
)

func read() {
	fmt.Scan(&n, &k)
	var tmp int64
	for i := 1; i <= n; i++ {
		fmt.Scan(&tmp)
		sum[i] = sum[i - 1] + tmp
	}
}

func check(x int64) bool {
	for i := 1; i <= n; i++ {
		dp[i][1] = (sum[i] & x) == x
	}
	for i := 2; i <= k; i++ {
		for j := i; j <= n; j++ {
			dp[j][i] = false
			for l := i - 1; l < j; l++ {
				if dp[l][i - 1] && ((sum[j] - sum[l]) & x) == x {
					dp[j][i] = true
				}
			}
		}
	}
	return dp[n][k]
}

func solve() {
	var ans int64 = 0
	for i := 60; i >= 0; i-- {
		if check(ans + (1 << uint(i))) {
			ans += 1 << uint(i)
		}
	}
	fmt.Println(ans)
}

func main() {
	read()
	solve()
}

package main

import . "fmt"

func main() {
	var n, k int
	Scan(&n, &k)
	sum := make([]uint64, n+1)
	for i := 1; i <= n; i++ {
		var a uint64
		Scan(&a)
		sum[i] = sum[i-1] + a
	}

	ans := uint64(0)
	for i := 55; i >= 0; i-- {
		bits := ans | 1<<uint(i)
		var dp [51][51]bool
		for r := 1; r <= n; r++ {
			dp[1][r] = bits&sum[r] == bits
		}
		for i := 2; i <= k; i++ {
			for l := i - 1; l < n; l++ {
				if dp[i-1][l] {
					for r := l + 1; r <= n; r++ {
						dp[i][r] = dp[i][r] || bits&(sum[r]-sum[l]) == bits
					}
				}
			}
		}
		if dp[k][n] {
			ans = bits
		}
	}
	Println(ans)
}

package main

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

func found(bits uint64, sum []uint64, k int) bool {
	n := len(sum) - 1
	var dp [51][51]bool
	for r := 1; r <= n; r++ {
		dp[1][r] = bits&sum[r] == bits
	}
	for i := 2; i <= k; i++ {
		for l := i - 1; l < n; l++ {
			if dp[i-1][l] {
				for r := l + 1; r <= n; r++ {
					dp[i][r] = dp[i][r] || bits&(sum[r]-sum[l]) == bits
				}
			}
		}
	}
	return dp[k][n]
}

func Sol981D(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n, k int
	Fscan(in, &n, &k)
	sum := make([]uint64, n+1)
	for i := 1; i <= n; i++ {
		var a uint64
		Fscan(in, &a)
		sum[i] = sum[i-1] + a
	}

	ans := uint64(0)
	for i := 55; i >= 0; i-- {
		pow2 := uint64(1) << uint(i)
		if found(ans|pow2, sum, k) {
			ans |= pow2
		}
	}

	Fprintln(out, ans)
}

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

package main

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

type Contest struct {
	in *bufio.Scanner
	out io.Writer
}

func NewSubmitContest() *Contest {
	C := &Contest{bufio.NewScanner(os.Stdin), os.Stdout}
	C.SetSplit(bufio.ScanWords)
	return C
}

func NewTestContest(testIn string, testOut *bytes.Buffer) *Contest  {
	C := &Contest{bufio.NewScanner(strings.NewReader(testIn)), testOut}
	C.SetSplit(bufio.ScanWords)
	return C
}

func (C *Contest) SetSplit(split bufio.SplitFunc) *Contest  {
	C.in.Split(split)
	return C
}

func (C *Contest) InStr() string {
	C.in.Scan()
	return C.in.Text()
}

func (C *Contest) InBytes() []byte {
	C.in.Scan()
	return C.in.Bytes()
}

func (C *Contest) InInt() int {
	C.in.Scan()
	i, _ := strconv.Atoi(C.in.Text())
	return i
}

func (C *Contest) InInt64() int64 {
	C.in.Scan()
	i, _ := strconv.ParseInt(C.in.Text(), 10, 64)
	return i
}

func (C *Contest) Out(format string, a ...interface{}) {
	fmt.Fprintf(C.out, format, a...)
}

func (C *Contest) MaxInt64(i1, i2 int64) int64 {
	if i1 > i2 {
		return i1
	}
	return i2
}

var (
	n, k int
	a []int64
	best, x int64
	cDone, cRes [][]bool
)

// https://codeforces.com/contest/981/problem/D
func problem(C *Contest) {
	n = C.InInt()
	k = C.InInt()

	a = make([]int64, n)
	for i := range a {
		a[i] = C.InInt64()
	}

	cRes = newCache(n, k)
	best = int64(0)
	for i := 62; i >= 0; i-- {
		cDone = newCache(n, k)
		x = int64(1) << uint(i)
		if checkSplit(best|x, n, k) {
			best |= x
		}
	}

	C.Out("%d\n", best)
}

func newCache(n int, k int) [][]bool {
	c := make([][]bool, n + 1)
	for i := range c {
		c[i] = make([]bool, k + 1)
	}

	return c
}

func checkSplit(x int64, n int, k int) bool {
	if k < 0 {
		return false
	} else if cDone[n][k] {
		return cRes[n][k]
	} else {
		cDone[n][k] = true
	}

	sum := int64(0)
	for i := n - 1; i >= 0; i-- {
		sum += a[i]
		if sum & x == x {
			if checkSplit(x, i, k - 1) {
				cRes[n][k] = true
				return cRes[n][k]
			}
		}
	}

	cRes[n][k] = (n == 0) && (k == 0)
	return cRes[n][k]
}

func main() {
	c := NewSubmitContest()
	problem(c)
}

package main

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

type Contest struct {
	in *bufio.Scanner
	out io.Writer
}

func NewSubmitContest() *Contest {
	C := &Contest{bufio.NewScanner(os.Stdin), os.Stdout}
	C.SetSplit(bufio.ScanWords)
	return C
}

func NewTestContest(testIn string, testOut *bytes.Buffer) *Contest  {
	C := &Contest{bufio.NewScanner(strings.NewReader(testIn)), testOut}
	C.SetSplit(bufio.ScanWords)
	return C
}

func (C *Contest) SetSplit(split bufio.SplitFunc) *Contest  {
	C.in.Split(split)
	return C
}

func (C *Contest) InStr() string {
	C.in.Scan()
	return C.in.Text()
}

func (C *Contest) InBytes() []byte {
	C.in.Scan()
	return C.in.Bytes()
}

func (C *Contest) InInt() int {
	C.in.Scan()
	i, _ := strconv.Atoi(C.in.Text())
	return i
}

func (C *Contest) InInt64() int64 {
	C.in.Scan()
	i, _ := strconv.ParseInt(C.in.Text(), 10, 64)
	return i
}

func (C *Contest) Out(format string, a ...interface{}) {
	fmt.Fprintf(C.out, format, a...)
}

func (C *Contest) MaxInt64(i1, i2 int64) int64 {
	if i1 > i2 {
		return i1
	}
	return i2
}

var (
	n, k int
	a []int64
)

// https://codeforces.com/contest/981/problem/D
func problem(C *Contest) {
	n = C.InInt()
	k = C.InInt()

	a = make([]int64, n)
	for i := range a {
		a[i] = C.InInt64()
	}

	var best, x int64
	for i := uint(10); i > 0; i-- {
		x = int64(1) << i
		if checkSplit(best|x, n, k) {
			best |= x
		}
	}

	C.Out("%d\n", best)
}

func checkSplit(x int64, n int, k int) bool {
	sum := int64(0)
	for i := n - 1; i >= 0; i-- {
		sum += a[i]
		if sum & x == x {
			if checkSplit(x, i, k - 1) {
				return true
			}
		}
	}

	return k == 0
}

func main() {
	c := NewSubmitContest()
	problem(c)
}

package main

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

type Contest struct {
	in *bufio.Scanner
	out io.Writer
}

func NewSubmitContest() *Contest {
	C := &Contest{bufio.NewScanner(os.Stdin), os.Stdout}
	C.SetSplit(bufio.ScanWords)
	return C
}

func NewTestContest(testIn string, testOut *bytes.Buffer) *Contest  {
	C := &Contest{bufio.NewScanner(strings.NewReader(testIn)), testOut}
	C.SetSplit(bufio.ScanWords)
	return C
}

func (C *Contest) SetSplit(split bufio.SplitFunc) *Contest  {
	C.in.Split(split)
	return C
}

func (C *Contest) InStr() string {
	C.in.Scan()
	return C.in.Text()
}

func (C *Contest) InBytes() []byte {
	C.in.Scan()
	return C.in.Bytes()
}

func (C *Contest) InInt() int {
	C.in.Scan()
	i, _ := strconv.Atoi(C.in.Text())
	return i
}

func (C *Contest) InInt64() int64 {
	C.in.Scan()
	i, _ := strconv.ParseInt(C.in.Text(), 10, 64)
	return i
}

func (C *Contest) Out(format string, a ...interface{}) {
	fmt.Fprintf(C.out, format, a...)
}

func (C *Contest) MaxInt64(i1, i2 int64) int64 {
	if i1 > i2 {
		return i1
	}
	return i2
}

var (
	n, k int
	a []int64
)

// https://codeforces.com/contest/981/problem/D
func problem(C *Contest) {
	n = C.InInt()
	k = C.InInt()

	a = make([]int64, n)
	for i := range a {
		a[i] = C.InInt64()
	}

	var best, x int64
	for i := uint(63); i > 0; i-- {
		x = int64(1) << i
		if checkSplit(best|x, n, k) {
			best |= x
		}
	}

	C.Out("%d\n", best)
}

func checkSplit(x int64, n int, k int) bool {
	sum := int64(0)
	for i := n - 1; i >= 0; i-- {
		sum += a[i]
		if sum & x == x {
			if checkSplit(x, i, k - 1) {
				return true
			}
		}
	}

	return (k == 0) && (n == 0)
}

func main() {
	c := NewSubmitContest()
	problem(c)
}


// 342B
package main

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

func main() {
	var n, m, s, f, t, l, r, i uint64
	in := bufio.NewReader(os.Stdin)
	t, i = 0, 0
	fmt.Scan(&n, &m, &s, &f)
	for ; ; i++ {
		if t == i && i < m {
			fmt.Fscan(in, &t)
		}
		if t == i+1 {
			fmt.Fscan(in, &l, &r)
		} else {
			l = 0
			r = 0
		}
		if s < f && (s+1 < l || s > r) {
			fmt.Print(string('R'))
			s++
		} else if s > f && (s < l || s-1 > r) {
			fmt.Print(string('L'))
			s--
		} else if s == f {
			break
		} else {
			fmt.Print(string('X'))
		}
	}
}

package main

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

var (
	sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
	wr *bufio.Writer  = bufio.NewWriter(os.Stdout)
)

type Watch struct{ t, l, r int }

func nextInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func main() {
	sc.Split(bufio.ScanWords)
	_, m, s, f := nextInt(), nextInt(), nextInt(), nextInt()
	watch := make([]Watch, m)
	for i := 0; i < m; i++ {
		watch[i].t, watch[i].l, watch[i].r = nextInt(), nextInt(), nextInt()
	}

	for t := 1; s != f; t++ {
		neigh, dir := s+1, "R"
		if s > f {
			neigh, dir = s-1, "L"
		}
		if len(watch) > 0 && watch[0].t == t && (watch[0].l <= s && s <= watch[0].r || watch[0].l <= neigh && neigh <= watch[0].r) {
			fmt.Fprint(wr, "X")
		} else {
			fmt.Fprint(wr, dir)
			s = neigh
		}
		if len(watch) > 0 && watch[0].t == t {
			watch = watch[1:]
		}
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

package main

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

var (
	sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
	wr *bufio.Writer  = bufio.NewWriter(os.Stdout)
)

type Watch struct{ t, l, r int }

func nextInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func main() {
	sc.Split(bufio.ScanWords)
	_, m, s, f := nextInt(), nextInt(), nextInt(), nextInt()
	watch := make([]Watch, m)
	for i := 0; i < m; i++ {
		watch[i].t, watch[i].l, watch[i].r = nextInt(), nextInt(), nextInt()
	}

	for t := 1; s != f; t++ {
		neigh, dir := s+1, "R"
		if s > f {
			neigh, dir = s-1, "L"
		}
		if len(watch) > 0 && watch[0].t == t && (watch[0].l <= s && s <= watch[0].r || watch[0].l <= neigh && neigh <= watch[0].r) {
			fmt.Fprint(wr, "X")
			watch = watch[1:]
		} else {
			fmt.Fprint(wr, dir)
			s = neigh
		}
	}
	fmt.Fprintln(wr)
	wr.Flush()
}


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

func main() {
	var n, m int
	fmt.Scanf("%v %v\n", &n, &m)
	// is a rectangle if each line is a copy of the line above
	reader := bufio.NewReader(os.Stdin)
	//scanner.Scan() //get first line
	prevline,_ := reader.ReadString('\n')
	blank := strings.Repeat(".", m) + "\n"
	//fmt.Println("Prev: ",prevline)
	//fmt.Println("blank: ",blank)
	//fmt.Println(strings.Compare(strings.TrimSpace(prevline), strings.TrimSpace(blank)))
	count := 0
	for i := 0; i < n; i++ {
		if strings.Compare(strings.TrimSpace(prevline), strings.TrimSpace(blank)) == 0 {
			//fmt.Println("Blank found - retrying: ", prevline)
			prevline,_ = reader.ReadString('\n') //read until first nonblank
			count += 1
		}
	}
	//fmt.Println("Prevline:", prevline)
	rect := 1
	for i := 0; i < n - count - 1; i++ {
		nextline,_ := reader.ReadString('\n')
		//fmt.Println(i)
		//fmt.Println("Nextline: ",nextline)
		if strings.Compare(prevline, nextline) == 0 {
			// so far so good
			prevline = nextline
		} else {
			if strings.Compare(strings.TrimSpace(nextline), strings.TrimSpace(blank)) != 0 {
				rect = 0
				fmt.Println("NO")
				break
			}
			break
		}
	}
	if rect == 1 {
		fmt.Println("YES")
	}

}

package main

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

func main() {
  var n, m int
  in := bufio.NewReader(os.Stdin)
  fmt.Fscan(in, &n, &m)
  startx, starty := n, m
  finx, finy := 0, 0
  count := 0
  for i := 0; i < n; i++ {
    var s string
    fmt.Fscan(in, &s)
    for k := 0; k < m; k++ {
      if s[k] == 'X' {
        if startx > i {
          startx = i
        }
        if starty > k {
          starty = k
        }
        if finx < i {
          finx = i
        }
        if finy < k {
          finy = k
        }
        count++
      }
    }
  }

  shouldbe := (finx - startx+1) * (finy - starty+1)
  if shouldbe == count {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var p []string
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		p = append(p, s)
	}
	sV := 0
	for i := 0; i < m; i++ {
		s := 0
		for j := 0; j < n; j++ {
			if p[j][i] == 'X' {
				s++
			}
		}
		if sV == 0 {
			sV = s
			continue
		}
		if s != sV && s != 0 {
			fmt.Println("NO")
			return
		}
	}
	sH := 0
	for i := 0; i < n; i++ {
		s := 0
		for j := 0; j < m; j++ {
			if p[i][j] == 'X' {
				s++
			}
		}
		if sH == 0 {
			sH = s
			continue
		}
		if s != sH && s != 0 {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

package main

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

func solve() {
    m, _ := readInt(), readInt()
    a := make([]string, m)
    is, js, cnt := []int{}, []int{}, 0
    for i := range a {
        a[i] = readString()
        for j, r := range a[i] {
            if r == 'X' {
                cnt++
                is = append(is, i)
                js = append(js, j)
            }
        }
    }
    sort.Ints(is)
    sort.Ints(js)
    ans := "NO"
    if s := (is[len(is)-1]-is[0]+1) * (js[len(js)-1]-js[0]+1); s == cnt {
        ans = "YES"
    }
    fmt.Println(ans)
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

// Math

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// IO

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

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

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

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

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

// Sort

type Ints64 []int64

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

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

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

func main() {
	var n, m int
	fmt.Scanf("%v %v\n", &n, &m)
	// is a rectangle if each line is a copy of the line above
	reader := bufio.NewReader(os.Stdin)
	//scanner.Scan() //get first line
	prevline,_ := reader.ReadString('\n')
	blank := strings.Repeat(".", m) + "\n"
	count := 0
	for i := 0; i < n; i++ {
		if strings.Compare(prevline, blank) != 0 {
			prevline,_ = reader.ReadString('\n') //read until first nonblank
			count += 1
		}
	}
	//fmt.Println("Prevline:", prevline)
	rect := 1
	for i := 0; i < n - count; i++ {
		nextline,_ := reader.ReadString('\n')
		//fmt.Println(i)
		//fmt.Println("Nextline: ",nextline)
		if strings.Compare(prevline, nextline) == 0 {
			// so far so good
			prevline = nextline
		} else {
			if strings.Compare(nextline, blank) != 0 {
				rect = 0
				fmt.Println("NO")
				break
			}
			break
		}
	}
	if rect == 1 {
		fmt.Println("YES")
	}

}

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

func main() {
	var n, m int
	fmt.Scanf("%v %v\n", &n, &m)
	// is a rectangle if each line is a copy of the line above
	reader := bufio.NewReader(os.Stdin)
	//scanner.Scan() //get first line
	prevline,_ := reader.ReadString('\n')
	//fmt.Println("Prevline:", prevline)
	rect := 1
	for i := 0; i < n - 1; i++ {
		nextline,_ := reader.ReadString('\n')
		//fmt.Println(i)
		//fmt.Println("Nextline: ",nextline)
		if strings.Compare(prevline, nextline) == 0 {
			// so far so good
		} else {
			rect = 0
			fmt.Println("NO")
			break
		}
	}
	if rect == 1 {
		fmt.Println("YES")
	}

}


package main

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

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

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n,m,a int
    ScanInts(&n)
    pos := make([]int,n+1)
    for i := 0; i < n; i++ {
        ScanInts(&a)
        pos[a] = i
    }
    ScanInts(&m)
    v, p := int64(0), int64(0)
    for i := 0; i < m; i++ {
        ScanInts(&a)
        v += int64(pos[a]+1)
        p += int64(n-pos[a])
    }
    fmt.Println(v,p)
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	n := scanInt(scanner)
	arr := make([]int, n)
	position := make(map[int]int)
	for i := 0; i < n; i++ {
		arr[i] = scanInt(scanner)
		position[arr[i]] = i
	}
	left, right := int64(0), int64(0)
	m := scanInt(scanner)
	for i := 0; i < m; i++ {
		pos := position[scanInt(scanner)]
		left += int64(pos+1)
		right += int64(n-pos)
	}
	writer.WriteString(fmt.Sprintf("%d %d\n", left, right))
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	//"sort"
)

func main() {
	var n,m,q,l,k,i int64
	l,k=0,0
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	a :=make([]int64,100001)
	for i=1;i<=n;i++ {
		input.Scan()
		bb,_:=strconv.ParseInt(input.Text(),0,64)
		a[bb]=i
	}
	input.Scan()
	c,_:=strconv.ParseInt(input.Text(),0,64)
	m=c
	for i=1;i<=m;i++ {
		input.Scan()
		aa,_:=strconv.ParseInt(input.Text(),0,64)
		q=aa
		k+=a[q]
		l+=n-a[q]+1
	}
	fmt.Println(k,l)
}

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
		n := reader.NextInt64()
		aa:=make([]int64,n)
		for i:=range aa {
			aa[i]=reader.NextInt64()
		}
		m:=reader.NextInt64()
		bb:=make([]int64,m)
		for i:=range bb {
			bb[i]=reader.NextInt64()
		}
		hm:=make(map[int64]int64,n)
		for i,v:=range aa {
			hm[v]=int64(i)
		}
		left,right:=int64(0),int64(0)
		for _,v:=range bb {
			left+=hm[v]+1
			right+=n-hm[v]
		}
		writer.Printf("%d %d \n",left,right)
}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

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

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	//"sort"
)

func main() {
	var n,m,q,l,k,i int64
	l,k=0,0
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	a :=make([]int64,100001)
	for i=1;i<=n;i++ {
		input.Scan()
		bb,_:=strconv.ParseInt(input.Text(),0,64)
		a[bb]=i
	}
	fmt.Scan(&m)
	for i=1;i<=m;i++ {
		input.Scan()
		aa,_:=strconv.ParseInt(input.Text(),0,64)
		q=aa
		k+=a[q]
		l+=n-a[q]+1
	}
	fmt.Println(k,l)
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	//"sort"
)

func main() {
	var n,m,q,l,k,i int64
	var p int
	l,k=0,0
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	a :=make([]int64,100001)
	for i=1;i<=n;i++ {
		input.Scan()
		bb,_:=strconv.Atoi(input.Text())
		//fmt.Scan(&p)
		p=bb
		a[p]=i
	}
	fmt.Scan(&m)
	for i=1;i<=m;i++ {
		input.Scan()
		aa,_:=strconv.ParseInt(input.Text(),0,64)
		q=aa
		k+=a[q]
		l+=n-a[q]+1
	}
	fmt.Println(k,l)
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	//"sort"
)

func main() {
	var n,m,p,q,l,k,i int64
	l,k=0,0
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	a :=make([]int64,100001)
	for i=1;i<=n;i++ {
		input.Scan()
		bb,_:=strconv.ParseInt(input.Text(),0,64)
		//fmt.Scan(&p)
		p=bb
		a[p]=i
	}
	fmt.Scan(&m)
	for i=1;i<=m;i++ {
		input.Scan()
		aa,_:=strconv.ParseInt(input.Text(),0,64)
		q=aa
		k+=a[q]
		l+=n-a[q]+1
	}
	fmt.Println(k,l)
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	//"sort"
)

func main() {
	var n,m,q,l,k,i int64
	l,k=0,0
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	a :=make([]int64,100001)
	for i=1;i<=n;i++ {
		input.Scan()
		bb,_:=strconv.Atoi(input.Text())
		a[bb]=i
	}
	fmt.Scan(&m)
	for i=1;i<=m;i++ {
		input.Scan()
		aa,_:=strconv.ParseInt(input.Text(),0,64)
		q=aa
		k+=a[q]
		l+=n-a[q]+1
	}
	fmt.Println(k,l)
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	n := scanInt(scanner)
	arr := make([]int, n)
	position := make(map[int]int)
	for i := 0; i < n; i++ {
		arr[i] = scanInt(scanner)
		position[arr[i]] = i
	}
	left, right := 0, 0
	m := scanInt(scanner)
	for i := 0; i < m; i++ {
		pos := position[scanInt(scanner)]
		left += pos+1
		right += n-pos
	}
	writer.WriteString(fmt.Sprintf("%d %d\n", left, right))
}

package main

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

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

    ScanInts := func(a... *int64) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.ParseInt(scanner.Text(),10,64)
        }
    }

    var n,m int
    var a int64
    fmt.Scan(&n)
    pos := make([]int,n+1)
    for i := 0; i < n; i++ {
        ScanInts(&a)
        pos[a] = i
    }
    fmt.Scan(&m)
    v, p := int64(0), int64(0)
    for i := 0; i < m; i++ {
        ScanInts(&a)
        v += int64(pos[a]+1)
        p += int64(n-pos[a])
    }
    fmt.Println(v,p)
}

package main

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

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

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n,m,a int
    fmt.Scan(&n)
    pos := make([]int,n+1)
    for i := 0; i < n; i++ {
        ScanInts(&a)
        pos[a] = i
    }
    fmt.Scan(&m)
    v, p := int64(0), int64(0)
    for i := 0; i < m; i++ {
        ScanInts(&a)
        v += int64(pos[a]+1)
        p += int64(n-pos[a])
    }
    fmt.Println(v,p)
}

package main

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

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

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            for scanner.Scan() { if scanner.Text() != "" { break } }
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n,m,a int
    fmt.Scan(&n)
    pos := make([]int,n+1)
    for i := 0; i < n; i++ {
        ScanInts(&a)
        pos[a] = i
    }
    fmt.Scan(&m)
    v, p := int64(0), int64(0)
    for i := 0; i < m; i++ {
        ScanInts(&a)
        v += int64(pos[a]+1)
        p += int64(n-pos[a])
    }
    fmt.Println(v,p)
}


package main

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

type song struct {
	id   int
	rate int
	like int
}

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

func solve(n int, p []int, s string) string {
	songs := make([]song, n)
	for i := 0; i < n; i++ {
		songs[i] = song{i, p[i], int(s[i] - '0')}
	}
	sort.Slice(songs, func(i, j int) bool {
		return songs[i].rate < songs[j].rate
	})
	sort.SliceStable(songs, func(i, j int) bool {
		return songs[i].like < songs[j].like
	})
	result := make([]string, n)
	for i := range songs {
		result[songs[i].id] = fmt.Sprint(i + 1)
	}
	return strings.Join(result, " ")
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		p := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &p[i])
		}
		fmt.Fscan(reader, &s)
		fmt.Println(solve(n, p, s))
	}
}

package main

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

type Node struct {
	idx  int
	like uint8
	val  int
}

type Nodes []Node

//Len()
func (s Nodes) Len() int {
	return len(s)
}

//Less()
func (s Nodes) Less(i, j int) bool {
	if s[i].like == s[j].like {
		return s[i].val > s[j].val
	}
	return s[i].like > s[j].like
}

//Swap()
func (s Nodes) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	n := 0

	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

	m := 0
	fmt.Fscan(f, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(f, &m)
		var res = make([]int, m, m)
		var arr = make(Nodes, m, m)
		for j := 0; j < m; j++ {
			arr[j].idx = j
			fmt.Fscan(f, &arr[j].val)
		}
		like := ""
		fmt.Fscan(f, &like)

		for j := 0; j < m; j++ {
			arr[j].like = like[j]
		}
		sort.Sort(arr)
		cnt := m
		for k := 0; k < m; k++ {
			res[arr[k].idx] = cnt
			cnt--
		}
		fmt.Fprint(w, res[0])
		for k := 1; k < m; k++ {
			fmt.Fprintf(w, " %v", res[k])
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

package main

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

func solve(P []int, s string) []int {
	n := len(P)
	// sum(abs(P[i] - Q[i])) min
	// 需要把大值分配给喜欢的部分
	var A []Pair
	var B []Pair

	for i := 0; i < n; i++ {
		if s[i] == '0' {
			A = append(A, Pair{P[i], i})
		} else {
			B = append(B, Pair{P[i], i})
		}
	}

	sort.Slice(A, func(i, j int) bool {
		return A[i].Less(A[j])
	})

	sort.Slice(B, func(i, j int) bool {
		return B[i].Less(B[j])
	})

	Q := make([]int, n)
	cur := n

	for i := 0; i < len(B); i++ {
		Q[B[i].second] = cur
		cur--
	}

	for i := 0; i < len(A); i++ {
		Q[A[i].second] = cur
		cur--
	}

	return Q
}

type Pair struct {
	first, second int
}

func (this Pair) Less(that Pair) bool {
	return this.first > that.first
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer
	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		P := readNNums(reader, n)
		s, _ := reader.ReadString('\n')
		res := solve(P, s)
		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

package main

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

type marker struct {
	Priority int
	Position int
}

func CF1622B(rawIn io.Reader, rawOut io.Writer) {
	in := bufio.NewReader(rawIn)
	out := bufio.NewWriter(rawOut)
	defer out.Flush()

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

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

		fmt.Fscanln(in)
		var ratings string
		fmt.Fscanln(in, &ratings)

		likedSongs, dislikedSongs := gatherMarkers(ps, ratings)
		sort.SliceStable(likedSongs, func(i, j int) bool {
			return likedSongs[i].Priority < likedSongs[j].Priority
		})
		sort.SliceStable(dislikedSongs, func(i, j int) bool {
			return dislikedSongs[i].Priority < dislikedSongs[j].Priority
		})

		result := make([]int, n)
		for i := 0; i < len(dislikedSongs); i++ {
			result[dislikedSongs[i].Position] = i + 1
		}
		for i := 0; i < len(likedSongs); i++ {
			result[likedSongs[i].Position] = i + 1 + len(dislikedSongs)
		}
		for i := 0; i < len(result); i++ {
			fmt.Fprintf(out, "%d ", result[i])
		}
		fmt.Fprintln(out)
	}
}

func gatherMarkers(ps []int, ratings string) ([]marker, []marker) {
	likedSongs := make([]marker, 0, len(ps))
	dislikedSongs := make([]marker, 0, len(ps))
	for i := 0; i < len(ps); i++ {
		if string(ratings[i]) == "1" {
			likedSongs = append(likedSongs, marker{Position: i, Priority: ps[i]})
		} else {
			dislikedSongs = append(dislikedSongs, marker{Position: i, Priority: ps[i]})
		}
	}
	return likedSongs, dislikedSongs
}

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

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		p := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &p[i])
		}
		var s string
		fmt.Fscan(reader, &s)
		count := strings.Count(s, "0")
		wrong_ones := make([]int, 0)
		wrong_zeros := make([]int, 0)
		for i := 0; i < n; i++ {
			if s[i] == '0' && p[i] > count {
				wrong_zeros = append(wrong_zeros, i)
			}
			if s[i] == '1' && p[i] <= count {
				wrong_ones = append(wrong_ones, i)

			}
		}
		// fmt.Println(count, wrong_ones, wrong_zeros)
		for i := 0; i < len(wrong_ones); i++ {
			p[wrong_ones[i]], p[wrong_zeros[i]] = p[wrong_zeros[i]], p[wrong_ones[i]]
		}
		for i := 0; i < n; i++ {
			write_int(f, p[i])
			if i == n-1 {
				write_string(f, "\n")
			} else {
				write_string(f, " ")
			}
		}

	}
}

package main

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

type song struct {
	id     int
	rating int
	liked  int
}

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)

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

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

		for i, ch := range s {
			if ch == '1' {
				songs[i].liked = 1
			}
		}

		sort.SliceStable(songs, func(i, j int) bool {
			if songs[i].liked == songs[j].liked {
				return songs[i].rating < songs[j].rating
			}
			return songs[i].liked < songs[j].liked
		})

		ratings := make([]int, n)
		for i, song := range songs {
			ratings[song.id] = i + 1
		}

		for _, v := range ratings {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		p := readArrayInt(reader)
		s := readString(reader)

		var x []int
		var y []int

		for i := 0; i < n; i++ {
			if s[i] == '0' {
				x = append(x, p[i])
			} else {
				y = append(y, p[i])
			}
		}

		sort.Ints(x)
		sort.Ints(y)

		q := make([]int, n+1)

		for i, v := range x {
			q[v] = i + 1
		}

		for i, v := range y {
			q[v] = i + len(x) + 1
		}

		for i := 0; i < n; i++ {
			fmt.Fprint(writer, q[p[i]], " ")
		}
		fmt.Fprintln(writer)

		t--
	}

	writer.Flush()
}

func sum(a1 int64, n int64) int64 {
	return (2*a1 + (n-1)*4) * n / 2
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

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

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

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

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

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

func solve() {
	var n int
	scan(&n)

	var p = make([]int, n)
	for i := range p {
		scan(&p[i])
	}

	var s string
	scan(&s)

	var liked, disliked = make([]int, 0), make([]int, 0)
	for i := range s {
		if s[i] == '0' {
			disliked = append(disliked, i)
		} else {
			liked = append(liked, i)
		}
	}

	sort.Slice(liked, func(i, j int) bool { return p[liked[i]] < p[liked[j]] })
	sort.Slice(disliked, func(i, j int) bool { return p[disliked[i]] < p[disliked[j]] })

	var (
		q   = make(map[int]int)
		num = 0
	)
	for _, i := range disliked {
		num++
		q[p[i]] = num
	}
	for _, i := range liked {
		num++
		q[p[i]] = num
	}

	for _, i := range p {
		printf("%v ", q[i])
	}
	printf("\n")
}

package main

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

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

type Song struct {
	Id      int
	Rating  int
	LikeIdx int // 0: dislike, 1: like
}

func solve(t int) {
	n := readInt()
	songs := make([]Song, n)
	for i := 0; i < n; i++ {
		songs[i] = Song{
			Id:     i + 1,
			Rating: readInt(),
		}
	}
	s := readString()
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			songs[i].LikeIdx = 1
		}
	}
	sort.Slice(songs, func(i, j int) bool {
		return songs[i].LikeIdx < songs[j].LikeIdx ||
			(songs[i].LikeIdx == songs[j].LikeIdx && songs[i].Rating < songs[j].Rating)
	})
	for i := 0; i < n; i++ {
		songs[i].Rating = i + 1
	}
	sort.Slice(songs, func(i, j int) bool {
		return songs[i].Id < songs[j].Id
	})
	for i := 0; i < n; i++ {
		print(songs[i].Rating, " ")
	}
	println()
}

func main() {
	var t int
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		solve(i)
	}
}

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"os"
)

type pair struct {
	idx int
	val int
}

type myHeap []pair

func (h *myHeap) Less(i, j int) bool {
	return (*h)[i].val > (*h)[j].val
}

func (h *myHeap) Swap(i, j int) {
	(*h)[i], (*h)[j] = (*h)[j], (*h)[i]
}

func (h *myHeap) Len() int {
	return len(*h)
}

func (h *myHeap) Pop() (v interface{}) {
	*h, v = (*h)[:h.Len()-1], (*h)[h.Len()-1]
	return
}

func (h *myHeap) Push(v interface{}) {
	*h = append(*h, v.(pair))
}

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		Fscan(in, &arr[i])
	}
	var s string
	Fscan(in, &s)
	one := new(myHeap)
	zero := new(myHeap)
	cur := n
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			heap.Push(one, pair{i, arr[i]})
		}
	}
	for i := 0; i < n; i++ {
		if s[i] == '0' {
			heap.Push(zero, pair{i, arr[i]})
		}
	}
	ans := make([]int, n)
	for cur != 0 {
		if one.Len() != 0 {
			pop := heap.Pop(one).(pair)
			ans[pop.idx] = cur
		} else {
			pop := heap.Pop(zero).(pair)
			ans[pop.idx] = cur
		}
		cur--
	}
	for i := 0; i < n; i++ {
		Fprintf(out, "%d ", ans[i])
	}
	Fprintln(out)
}

func main() {

	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 0
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

type E struct {
	val, ind int
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		n, s, o, p := 0, "", map[int]int{}, 0
		fmt.Fscan(f, &n)
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &p)
			o[j] = p
		}
		fmt.Fscan(f, &s)
		a, b, c, k := []E{}, []E{}, make([]int, n), n
		for j := 0; j < len(s); j++ {
			if string(s[j]) == "1" {
				a = append(a, E{val: o[j], ind: j})
			} else {
				b = append(b, E{val: o[j], ind: j})
			}
		}
		sort.Slice(a, func(i, j int) bool { return a[i].val > a[j].val })
		sort.Slice(b, func(i, j int) bool { return b[i].val > b[j].val })
		for j := 0; j < len(a); j++ {
			c[a[j].ind] = k
			k--
		}
		for j := 0; j < len(b); j++ {
			c[b[j].ind] = k
			k--
		}
		for j := 0; j < len(c); j++ {
			fmt.Fprint(w, c[j], " ")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		var n int
		fmt.Fscan(in, &n)
		var p []int = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &p[i])
		}
		var liked string
		var count0 = 0
		fmt.Fscan(in, &liked)
		for i := 0; i < n; i++ {
			if liked[i] == '0' {
				count0++
			}
		}

		var order []int = make([]int, n)
		for i := 0; i < n; i++ {
			order[i] = i
		}
		// fmt.Fprintf(out, "order = %v\n", order)
		sort.Slice(order, func(i, j int) bool {
			return p[order[i]] < p[order[j]]
		})
		var cur0 = 1
		var cur1 = count0 + 1
		var ans []int = make([]int, n)
		for _, i := range order {
			if liked[i] == '0' {
				ans[i] = cur0
				cur0++
			} else {
				ans[i] = cur1
				cur1++
			}
		}
		for i := 0; i < n; i++ {
			fmt.Fprintf(out, "%d ", ans[i])
		}
		fmt.Fprintln(out)
	}
	out.Flush()
}

package main

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

type marker struct {
	Priority int
	Position int
}

func CF1622B(rawIn io.Reader, rawOut io.Writer) {
	in := bufio.NewReader(rawIn)
	out := bufio.NewWriter(rawOut)
	defer out.Flush()

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

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

		fmt.Fscanln(in)
		var ratings string
		fmt.Fscanln(in, &ratings)

		likedSongs, dislikedSongs := gatherMarkers(ps, ratings)
		sort.SliceStable(likedSongs, func(i, j int) bool {
			return likedSongs[i].Priority < likedSongs[j].Priority
		})
		sort.SliceStable(dislikedSongs, func(i, j int) bool {
			return dislikedSongs[i].Priority < dislikedSongs[j].Priority
		})
		fmt.Println(likedSongs)
		fmt.Println(dislikedSongs)

		result := make([]int, n)
		for i := 0; i < len(dislikedSongs); i++ {
			result[dislikedSongs[i].Position] = i + 1
		}
		for i := 0; i < len(likedSongs); i++ {
			result[likedSongs[i].Position] = i + 1 + len(dislikedSongs)
		}
		for i := 0; i < len(result); i++ {
			fmt.Fprintf(out, "%d ", result[i])
		}
		fmt.Fprintln(out)
	}
}

func gatherMarkers(ps []int, ratings string) ([]marker, []marker) {
	likedSongs := make([]marker, 0, len(ps))
	dislikedSongs := make([]marker, 0, len(ps))
	for i := 0; i < len(ps); i++ {
		if string(ratings[i]) == "1" {
			likedSongs = append(likedSongs, marker{Position: i, Priority: ps[i]})
		} else {
			dislikedSongs = append(dislikedSongs, marker{Position: i, Priority: ps[i]})
		}
	}
	return likedSongs, dislikedSongs
}

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


package main

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

func main()  {

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

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

	var tom, rank, s1, s2, s3, s4 int
	fmt.Fscanf(in, "%d %d %d %d\n", &s1, &s2, &s3, &s4)

	rank = 1
	tom = s1 + s2 + s3 + s4

	for i := 1; i < n; i++ {
		fmt.Fscanf(in, "%d %d %d %d\n", &s1, &s2, &s3, &s4)
		if tom < s1 + s2 + s3 + s4 {
			rank++
		}

	}

	fmt.Fprintln(out, rank)

}

package main

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

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

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

type student struct {
	id, score int
}

func main() {
	var n, a, b, c, d int
	scanf("%d\n", &n)
	students := make([]*student, n)
	for i := 0; i < n; i++ {
		scanf("%d %d %d %d\n", &a, &b, &c, &d)
		students[i] = &student{id: i, score: a + b + c + d}
	}

	sort.Slice(students, func(i, j int) bool {
		if students[i].score != students[j].score {
			return students[i].score > students[j].score
		}
		return students[i].id < students[j].id
	})

	for i, s := range students {
		if s.id == 0 {
			printf("%d\n", i+1)
			break
		}
	}

	writer.Flush()
}

package main

import (
	"fmt"
	)

func main() {
	var students, score, scoreTomas, student int

	fmt.Scan(&students)
	for i:=0; i<students; i++ {
		var a, b, c, d int
		fmt.Scan(&a, &b, &c, &d)

		if i == 0 {
		   scoreTomas = a + b + c + d;
		} else {
		   score = a + b + c + d;
		   if score > scoreTomas {
		   		student ++
		   }
		}
	}

	fmt.Printf("%d", student + 1)
}

package main

import "fmt"

func main() {
	var n, a, b, c, d, smith, rank int
	fmt.Scan(&n)
	rank = 1
	smith = -1
	for ; n > 0; n-- {
		fmt.Scan(&a, &b, &c, &d)
		if smith == -1 {
			smith = a + b + c + d
		}
		if a+b+c+d > smith {
			rank++
		}

	}
	fmt.Println(rank)
}

package main

import (
	"fmt"
)

type pair struct {
	first  int
	second int
}

func main() {
	var n int

	fmt.Scan(&n)

	a := [1000][5]int{}
	sum := [1000]pair{}

	for i := 0; i < n; i++ {
		for j := 0; j < 4; j++ {
			fmt.Scan(&a[i][j])
			sum[i].first += a[i][j]
		}
		sum[i].second = i + 1
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n-i-1; j++ {
			if sum[j].first < sum[j+1].first {
				sum[j], sum[j+1] = sum[j+1], sum[j]
			}
		}
	}

	for i := 0; i < n; i++ {
		if sum[i].second == 1 {
			fmt.Println(i + 1)
			break
		}
	}

}

package main

import (
  "fmt"
  )

func main(){
  var n,m,r int
  fmt.Scan(&n)
  for i:=0;i<n;i++ {
    o := make([]int,4)
    fmt.Scan(&o[0],&o[1],&o[2],&o[3])
    x := o[0]+o[1]+o[2]+o[3]
    if i ==0 {
      r = x
      m++
      } else {
      if x > r {
        m++
        }
      }
    }
  fmt.Println(m)

  }

// A. The Rank
/*
John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.

There are 𝑛 students, each of them has a unique id (from 1 to 𝑛). Thomas's id is 1. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.

In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids.

Please help John find out the rank of his son.

Input
The first line contains a single integer 𝑛 (1≤𝑛≤1000) — the number of students.

Each of the next 𝑛 lines contains four integers 𝑎𝑖, 𝑏𝑖, 𝑐𝑖, and 𝑑𝑖 (0≤𝑎𝑖,𝑏𝑖,𝑐𝑖,𝑑𝑖≤100) — the grades of the 𝑖-th student on English, German, Math, and History. The id of the 𝑖-th student is equal to 𝑖.

Output
Print the rank of Thomas Smith. Thomas's id is 1.

Examples
Input
5
100 98 100 100
100 100 100 100
100 100 99 99
90 99 90 100
100 98 60 99

Output
2

Input
6
100 80 90 99
60 60 60 60
90 60 100 60
60 100 60 80
100 100 0 100
0 0 0 0

Output
1

Note
In the first sample, the students got total scores: 398, 400, 398, 379, and 357. Among the 5 students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is 2.

In the second sample, the students got total scores: 369, 240, 310, 300, 300, and 0. Among the 6 students, Thomas got the highest score, so his rank is 1.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input1))

	t, ans := 0, 1
	for i := 0; i < n; i++ {
		input2, _ := reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(input2), " ")

		e, _ := strconv.Atoi(arr[0])
		g, _ := strconv.Atoi(arr[1])
		m, _ := strconv.Atoi(arr[2])
		h, _ := strconv.Atoi(arr[3])

		s := e + g + m + h
		if i == 0 {
			t = s
		}
		if t < s {
			ans++
		}
	}
	fmt.Print(ans)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var a, b, c, d int
	fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)
	tomScore := a + b + c + d
	tomRank := 1
	for i := 1; i < n; i++ {
		fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)
		otherScore := a + b + c + d
		if otherScore > tomScore {
			tomRank++
		}
	}
	fmt.Println(tomRank)
}

package main

import "fmt"

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

	ans := 1
	for i := range make([]struct{}, n) {
		score := 0
		for range make([]struct{}, 4) {
			var a int
			fmt.Scan(&a)
			score += a
		}
		if i == 0 {
			thomas = score
		}
		if score > thomas {
			ans++
		}
	}
	fmt.Println(ans)
}

package main

import (
    "fmt"
    "sort"
)

type Pair struct {
    sum int
    id int
}

type Pairs []Pair

func (arr Pairs) Len() int {
    return len(arr)
}

func (arr Pairs) Swap(i, j int) {
    arr[i], arr[j] = arr[j], arr[i]
}

func (arr Pairs) Less(i, j int) bool {
    if arr[i].sum != arr[j].sum {
        return arr[i].sum < arr[j].sum
    }
    return arr[i].id > arr[j].id
}

func main() {
    var n int
    fmt.Scan(&n)
    arr := make([]Pair, n)
    for iter := 0; iter < n; iter++ {
        var a, b, c, d int
        fmt.Scan(&a, &b, &c, &d)
        arr[iter].id = iter
        arr[iter].sum = a + b + c + d
    }
    sort.Sort(Pairs(arr))
    for iter := 0; iter < n; iter++ {
        if arr[iter].id == 0 {
            fmt.Println(n - iter)
        }
    }
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := 0
	s1, s2, s3, s4 := 0, 0, 0, 0
	fmt.Fscanf(in, "%d %d %d %d\n", &s1, &s2, &s3, &s4)
	a = s1 + s2 + s3 + s4
	rank := 1
	for i := 1; i < n; i++ {
		fmt.Fscanf(in, "%d %d %d %d\n", &s1, &s2, &s3, &s4)
		b := s1 + s2 + s3 + s4
		if b > a {
			rank++
		}
	}
	fmt.Fprintf(out, "%d\n", rank)
	return
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var a, b, c, d int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
	tomScore := a + b + c + d
	tomRank := 1
	for i := 1; i < n; i++ {
		fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
		otherScore := a + b + c + d
		if otherScore > tomScore {
			tomRank++
		}
	}
	fmt.Println(tomRank)
}

package main

import "fmt"

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

	for i := range make([]struct{}, n) {
		cnt := 0
		for range make([]struct{}, 4) {
			var a int
			fmt.Scan(&a)
			cnt += a
		}
		if cnt > cntMx {
			ans = i + 1
			cntMx = cnt
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	)

func main() {
	var students, score, scoreMax, student int

	fmt.Scan(&students)
	for i:=0; i<students; i++ {
		var a, b, c, d int
		fmt.Scan(&a, &b, &c, &d)

		score = a + b + c + d

		if score >= scoreMax {
			scoreMax = score
			student = i
		}
	}

	fmt.Printf("%d", student + 1)
}

package main

import (
	"fmt"
	)

func main() {
	var students, score, scoreMax, student int

	fmt.Scan(&students)
	for i:=0; i<students; i++ {
		var a, b, c, d int
		fmt.Scan(&a, &b, &c, &d)

		score = a + b + c + d;
		if score >= scoreMax {
			scoreMax = score
			student = i
		}
	}

	fmt.Printf("%d", student + 1)
}