Ehab loves number theory, but for some reason he hates the number $$$x$$$. Given an array $$$a$$$, find the length of its longest subarray such that the sum of its elements isn't divisible by $$$x$$$, or determine that such subarray doesn't exist.An array $$$a$$$ is a subarray of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

The first line contains an integer $$$t$$$ $$$(1 \le t \le 5)$$$ — the number of test cases you need to solve. The description of the test cases follows. The first line of each test case contains 2 integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le x \le 10^4$$$) — the number of elements in the array $$$a$$$ and the number that Ehab hates. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$0 \le a_i \le 10^4$$$) — the elements of the array $$$a$$$.

For each testcase, print the length of the longest subarray whose sum isn't divisible by $$$x$$$. If there's no such subarray, print $$$-1$$$.

NoteIn the first test case, the subarray $$$[2,3]$$$ has sum of elements $$$5$$$, which isn't divisible by $$$3$$$.In the second test case, the sum of elements of the whole array is $$$6$$$, which isn't divisible by $$$4$$$.In the third test case, all subarrays have an even sum, so the answer is $$$-1$$$.

package main

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

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
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, x := readTwoNums(reader)
		A := readNNums(reader, n)
		fmt.Println(solve(n, x, A))
	}
}

func solve(n, x int, A []int) int {
	var sum int
	for i := 0; i < n; i++ {
		sum += A[i]
		sum %= x
	}

	if sum != 0 {
		return n
	}
	var l int
	for l < n && A[l] % x == 0 {
		l++
	}
	if l == n {
		return -1
	}
	var r = n - 1
	for A[r] % x == 0 {
		r--
	}
	return max(n - (l + 1), r)
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, x := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &x)
		a := make([]int, n)
		sum := make([]int, n)
		first := -1
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
			if i == 0 {
				sum[i] = a[i]
			} else {
				sum[i] = sum[i-1] + a[i]
			}
			if sum[i]%x != 0 && first == -1 {
				first = i
			}
		}
		fmt.Fscanf(in, "\n")
		ans := -1
		for i := 0; i < n; i++ {
			if sum[i]%x != 0 {
				ans = i + 1
			}
			if first != -1 && i > first {
				if (sum[i]-sum[first])%x != 0 {
					ans = max(ans, i-first)
				}
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		arr := strings.Split(string(line), " ")
		n, _ := strconv.Atoi(arr[0])
		x, _ := strconv.Atoi(arr[1])
		line = readLine(reader)
		ans := strings.Split(string(line), " ")
		first, end, sum := 0, n-1, 0
		for j := 0; j < n; j++ {
			aj, _ := strconv.Atoi(ans[j])
			sum = (aj + sum) % x
		}
		if sum != 0 {
			fmt.Println(n)
			continue
		}
		for ; first < n; first++ {
			ai, _ := strconv.Atoi(ans[first])
			if ai % x != 0 {
				break
			}
		}
		if first == n {
			fmt.Println(-1)
			continue
		}
		left := n - 1 - first
		for ; end >= 0; end-- {
			ai, _ := strconv.Atoi(ans[end])
			if ai % x != 0 {
				break
			}
		}
		right := end
		if right > left {
			fmt.Println(right)
		} else {
			fmt.Println(left)
		}
	}
}

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

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n, x := nextInt(), nextInt()
		As := nextInts(n)
		fmt.Println(solve(x, As))
	}
}

func solve(x int, As []int) int {
	sum := 0
	for i := 0; i < len(As); i++ {
		sum = (sum + As[i]) % x
	}
	if sum > 0 {
		return len(As)
	}

	lCount := 0
	for i := 0; i < len(As); i++ {
		if As[i]%x == 0 {
			lCount++
		} else {
			break
		}
	}
	if lCount == len(As)-1 {
		return -1
	}

	rCount := 0
	for i := len(As) - 1; i >= 0; i-- {
		if As[i]%x == 0 {
			rCount++
		} else {
			break
		}
	}

	return len(As) - Min(lCount, rCount) - 1
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n, x int
	A    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	if x == 1 {
		fmt.Println(-1)
		return
	}

	R := make([]int, n)
	for i := 0; i < n; i++ {
		R[i] = A[i] % x
	}

	rs := make([]int, n+1)
	for i := 0; i < n; i++ {
		rs[i+1] = rs[i] + R[i]
	}

	total := rs[n]
	if total%x != 0 {
		fmt.Println(n)
		return
	}

	// for i := 0; i < n; i++ {
	// 	if R[i] > 0 {
	// 		if n-1 > 0 {
	// 			fmt.Println(n - 1)
	// 		} else {
	// 			fmt.Println(-1)
	// 		}
	// 		return
	// 	}
	// }
	// fmt.Println(-1)

	// 前から消す
	bef := 0
	for i := 0; i < n; i++ {
		if R[i] != 0 {
			bef = n - (i + 1)
			break
		}
	}

	// 後ろから消す
	aft := 0
	for i := n - 1; i >= 0; i-- {
		if R[i] != 0 {
			aft = i
			break
		}
	}

	ans := Max(bef, aft)
	if ans > 0 {
		fmt.Println(ans)
		return
	}

	fmt.Println(-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

var nTest, n, x int
var a [100000]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &nTest)

	for i := 0; i < nTest; i++ {
		fmt.Fscan(in, &n, &x)

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

		sum1 := sum
		i1 := 0
		for sum1%x == 0 && i1 < n {
			sum1 -= a[i1]
			i1++
		}

		sum2 := sum
		i2 := n - 1
		for sum2%x == 0 && i2 >= 0 {
			sum2 -= a[i2]
			i2--
		}

		len1 := 0
		len2 := 0
		if i1 < n {
			len1 = n - i1
		}

		if i2 >= 0 {
			len2 = i2 + 1
		}

		if len1 == 0 && len2 == 0 {
			fmt.Fprintln(out, -1)
		} else if len1 < len2 {
			fmt.Fprintln(out, len2)
		} else {
			fmt.Fprintln(out, len1)
		}
	}
	out.Flush()
}

package main

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

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	tt := NextInt()
	for ; tt > 0; tt-- {
		n, x := NextInt(), NextInt()

		a := make([]int, n + 1)
		sum := make([]int, n + 1)
		for i := 1; i <= n; i++ {
			a[i] = NextInt()
		}
		for i := 1; i <= n; i++ {
			sum[i] = sum[i - 1] + a[i]
		}

		if sum[n] % x != 0 {
			fmt.Println(n)
		} else {
			ret := -1
			for i := 1; i <= n; i++{
				if sum[i] % x != 0 {
					ret = i
					break
				}
			}
			for j := n; j >= 1; j-- {
				t := sum[n] - sum[j - 1]
				if t % x != 0 {
					if ret != -1 {
						ret = min(ret, n - j + 1)
					} else {
						ret = n - j + 1
					}
					break
				}
			}
			if ret == -1 {
				fmt.Println("-1")
			} else {
				fmt.Println(n - ret)
			}
		}

	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, now int
	fmt.Fscanf(in, "%d\n", &t)
	for now < t {
		now++
		var n, x int
		var sum int64
		fmt.Fscanf(in, "%d %d\n", &n, &x)
		var minN, maxN = n - 1, 0
		mas := make([]int, n + 1)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &mas[i])
			sum += int64(mas[i])
			if mas[i]%x != 0 {
				minN = int(math.Min(float64(minN), float64(i)))
				maxN = int(math.Max(float64(maxN), float64(i)))
			}
		}
		fmt.Fscanf(in, "\n")
		if sum%int64(x) != 0 {
			fmt.Fprintln(out, n)
		} else {
			if minN == n-1 && maxN == 0 {
				fmt.Fprintln(out, -1)
			} else {
				fmt.Fprintln(out, int(math.Max(math.Abs(float64(n-1-minN)), float64(maxN))))
			}
		}

	}
	return
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    var n int
    fmt.Fscan(in, &n)
    for i:=0; i<n; i++ {
        l, d := 0, 0
        fmt.Fscan(in, &l)
        fmt.Fscan(in, &d)
        a := make([]int, l)
        for j:=0; j<l; j++ {fmt.Fscan(in, &a[j])}
        pre, suf := -1, -1
        sum := 0
        for k,v := range a {
            sum += v
            if sum % d != 0 {pre = k}
        }
        sum = 0
        for j:=l-1; j>=0; j-- {
            v := a[j]
            sum += v
            if sum % d != 0 {suf = j}
        }
		if suf == -1 && pre == -1 {fmt.Fprint(out, "-1\n"); continue}
        if (pre+1) > (l-suf) {fmt.Fprint(out, pre+1); fmt.Fprint(out, "\n")} else {fmt.Fprint(out, l-suf); fmt.Fprint(out, "\n")}
    }
}

package main

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

func main() {

	t := NextInt()
	for t > 0 {
		t--
		n, x := NextInt(), NextInt()

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

		for i := 1; i <= n; i++ {
			a[i] = NextInt()
		}

		for i := 1; i <= n; i++ {
			a[i] = (a[i] + a[i-1]) % x
		}

		ans := -1
		for i := 0; i <= n; i++ {
			if a[i] != 0 && i > ans {
				ans = i
			}
			if a[i] != a[n] && n-i > ans {
				ans = n-i
			}
		}
		fmt.Println(ans)
	}
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

package main

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

func main() {

	t := NextInt()
	for t > 0 {
		t--
		n, x := NextInt(), NextInt()

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

		for i := 1; i <= n; i++ {
			a[i] = NextInt()
		}

		for i := 1; i <= n; i++ {
			a[i] = (a[i] + a[i-1]) % x
		}

		ans := -1
		for i := 0; i <= n; i++ {
			if a[i] != 0 && i > ans {
				ans = i
			}
			if a[i] != a[n] && n-i > ans {
				ans = n-i
			}
		}
		fmt.Println(ans)
	}
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	n, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return n
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, x := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &x)
		a := make([]int, n)
		sum := make([]int, n)
		first := -1
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
			if i == 0 {
				sum[i] = a[i]
			} else {
				sum[i] = sum[i-1] + a[i]
			}
			if sum[i]%x != 0 {
				first = i
			}
		}
		fmt.Fscanf(in, "\n")
		ans := -1
		for i := 0; i < n; i++ {
			if sum[i]%x != 0 {
				ans = i + 1
			}
			if first != -1 && i > first {
				if (sum[i]-sum[first])%x != 0 {
					ans = max(ans, i-first)
				}
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n, x := nextInt(), nextInt()
		As := nextInts(n)
		fmt.Println(solve(x, As))
	}
}

func solve(x int, As []int) int {
	l := -1
	r := len(As)
	sum := 0
	for i := 0; i < len(As); i++ {
		sum = (sum + As[i]) % x
		if As[i]%x == 0 {
			if i == l+1 {
				l = i
			}
			if i == r-1 {
				r = i
			}
		}
	}

	if sum > 0 {
		return len(As)
	}
	if l == len(As)-1 {
		return -1
	}
	lcount := l + 1
	rcount := len(As) - r
	return len(As) - Min(lcount, rcount) - 1
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n, x int
	A    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	if x == 1 {
		fmt.Println(-1)
		return
	}

	R := make([]int, n)
	for i := 0; i < n; i++ {
		R[i] = A[i] % x
	}

	rs := make([]int, n+1)
	for i := 0; i < n; i++ {
		rs[i+1] = rs[i] + R[i]
	}

	total := rs[n]
	if total%x != 0 {
		fmt.Println(n)
		return
	}

	for i := 0; i < n; i++ {
		if R[i] > 0 {
			fmt.Println(n - 1)
			return
		}
	}

	fmt.Println(-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n, x int
	A    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	if x == 1 {
		fmt.Println(-1)
		return
	}

	R := make([]int, n)
	for i := 0; i < n; i++ {
		R[i] = A[i] % x
	}

	rs := make([]int, n+1)
	for i := 0; i < n; i++ {
		rs[i+1] = rs[i] + R[i]
	}

	total := rs[n]
	if total%x != 0 {
		fmt.Println(n)
		return
	}

	for i := 0; i < n; i++ {
		if R[i] > 0 {
			if n-1 > 0 {
				fmt.Println(n - 1)
			} else {
				fmt.Println(-1)
			}
			return
		}
	}

	fmt.Println(-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n, x int
	A    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	R := make([]int, n)
	for i := 0; i < n; i++ {
		R[i] = A[i] % x
	}

	rs := make([]int, n+1)
	for i := 0; i < n; i++ {
		rs[i+1] = rs[i] + R[i]
	}

	total := rs[n]
	if total%x != 0 {
		fmt.Println(n)
		return
	}

	for i := 0; i < n; i++ {
		if R[i] > 0 {
			fmt.Println(n - 1)
			return
		}
	}

	fmt.Println(-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    var n int
    fmt.Fscan(in, &n)
    for i:=0; i<n; i++ {
        l, d := 0, 0
        fmt.Fscan(in, &l)
        fmt.Fscan(in, &d)
        a := make([]int, l)
        for j:=0; j<l; j++ {fmt.Fscan(in, &a[j])}
        pre, suf := -1, -1
        sum := 0
        for k,v := range a {
            sum += v
            if sum % d != 0 {pre = k}
        }
        sum = 0
        for j:=l-1; j>=0; j-- {
            v := a[j]
            sum += v
            if sum % d != 0 {suf = j}
        }
		if suf == -1 && pre == -1 {fmt.Fprint(out, "-1\n"); continue}
        if pre > (l-suf) {fmt.Fprint(out, pre); fmt.Fprint(out, "\n")} else {fmt.Fprint(out, l-suf); fmt.Fprint(out, "\n")}
    }
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    var n int
    fmt.Fscan(in, &n)
    for i:=0; i<n; i++ {
        l, d := 0, 0
        fmt.Fscan(in, &l)
        fmt.Fscan(in, &d)
        a := make([]int, l)
        for j:=0; j<l; j++ {fmt.Fscan(in, &a[j])}
        pre, suf := -1, -1
        sum := 0
        for k,v := range a {
            sum += v
            if sum % d != 0 {pre = k}
        }
        sum = 0
        for j:=l-1; j>=0; j-- {
            v := a[j]
            sum += v
            if sum % d != 0 {suf = j}
        }
		if suf == -1 && pre == -1 {fmt.Fprint(out, "-1\n"); continue}
		fmt.Println(pre, suf)
        if pre > (l-suf) {fmt.Fprint(out, pre); fmt.Fprint(out, "\n")} else {fmt.Fprint(out, l-suf); fmt.Fprint(out, "\n")}
    }
}

package main

import "fmt"

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

	for t > 0 {
		t--
		fmt.Scanf("%d%d\n", &n, &x)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i])
		}

		for i := 1; i <= n; i++ {
			a[i] = (a[i] + a[i-1]) % x
		}

		ans := -1
		for i := 0; i <= n; i++ {
			if a[i] != 0 && i > ans {
				ans = i
			}
			if a[i] != a[n] && n-i > ans {
				ans = n-i
			}
		}
		fmt.Println(ans)
	}
}


You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal.Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.If there is no possible sequence then output -1.

The first line consists of two numbers n and k (1 ≤ n, k ≤ 1010).

If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var n, k uint64
	for I(&n, &k) == nil {
		solve(n, k)
	}
	w.Flush()
}

func solve(n, k uint64) {
	m := uint64(math.Sqrt(float64(n)))
	for i := uint64(1); i <= m; i++ {
		if n%i == 0 && i*2/k >= k+1 {
			nn := n
			for j := uint64(1); j < k; j++ {
				oo := (n / i) * j
				O(oo, " ")
				nn -= oo
			}
			O(nn, "\n")
			return

		}
	}
	for i := m; i >= 1; i-- {
		if n%i == 0 && n*2/i/k >= k+1 {
			nn := n
			for j := uint64(1); j < k; j++ {
				oo := i * j
				O(oo, " ")
				nn -= oo
			}
			O(nn, "\n")
			return

		}
	}
	O("-1\n")
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	scanner.Scan()
	k, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	if k == 1 {
		fmt.Println(n)
		os.Exit(0)
	}

	sqrt := int64(math.Sqrt(float64(n))) + 1
	var gcd int64
	for i := int64(1); i <= sqrt; i++ {
		if n%i != 0 {
			continue
		}
		if fit(n, i, k) {
			if i > gcd {
				gcd = i
			}
		}
		if fit(n, n/i, k) {
			if n/i > gcd {
				gcd = n / i
			}
		}
	}
	if gcd == 0 {
		fmt.Println(-1)
		os.Exit(0)
	}
	for i := int64(1); i < k; i++ {
		fmt.Printf("%d ", i*gcd)
	}
	fmt.Println(n - (k*(k-1)*gcd)/2)
}

func fit(n, d, k int64) bool {
	if k > 10e6 {
		return false
	}
	if (k-1)*(k+2) > 10e10 {
		return false
	}
	if k*d > 10e10 {
		return false
	}
	if (k-1)*(k+2)*d >= 2*n {
		return false
	}
	return true
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF803C(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n, k, g int64
	Fscan(in, &n, &k)
	if k > 1e6 {
		Fprint(out, -1)
		return
	}
	s := k * (k + 1) / 2
	for d := int64(1); d*d <= n; d++ {
		if n%d == 0 {
			if d >= s {
				g = n / d
				break
			}
			if n/d >= s {
				g = d
			}
		}
	}
	if g == 0 {
		Fprint(out, -1)
		return
	}
	for i := int64(1); i < k; i++ {
		Fprint(out, i*g, " ")
		n -= i * g
	}
	Fprint(out, n)
}

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

package main

import (
"bufio"
"fmt"
	"math"
	"os"
)
var n, k int64

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

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

	fmt.Fscanf(reader, "%d %d\n", &n, &k)

	if k >= 2 * int64(1e5) {
		fmt.Fprintf(writer, "-1")
		return
	}

	if n < k * (k + 1) / 2 {
		fmt.Fprintf(writer, "-1")
		return
	}

	var base = k * (k + 1) / 2

	var ans = -1

	for z := 1; z <= int(math.Sqrt(float64(n))); z++ {
		if n % int64(z) == 0 {
			if n / int64(z) >= base {
				ans = max(ans, z)
			}

			var mz = n / int64(z)
			if mz != int64(z) {
				if n / int64(mz) >= base {
					ans = max(ans, int(mz))
				}
			}
		}
	}

	if ans == -1 {
		fmt.Fprintf(writer, "-1")
		return
	}

	for i := 1; i <= int(k); i++ {
		var val = int64(ans) * int64(i)

		if i == int(k) {
			val += n - base * int64(ans)
		}

		fmt.Fprintf(writer, "%d ", val)
	}
}

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var n, k int64
	for I(&n, &k) == nil {
		solve(n, k)
	}
	w.Flush()
}

func solve(n, k int64) {
	m := int64(math.Sqrt(float64(n)))
	for i := m; i >= 1; i-- {
		if n%i == 0 && n >= (i*k*(k+1))/2 {
			nn := n
			for j := int64(1); j < k; j++ {
				oo := i * j
				O(oo, " ")
				nn -= oo
			}
			O(nn, "\n")
			return

		}
	}
	O("-1\n")
}

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var n, k int64
	for I(&n, &k) == nil {
		solve(n, k)
	}
	w.Flush()
}

func solve(n, k int64) {
	m := int64(math.Sqrt(float64(n)))
	for i := m; i >= 1; i-- {
		if n%i == 0 && n >= (i*k*(k+1))/2 {
			q := i
			for n%q == 0 && n >= (q*k*(k+1))/2 {
				q += i
			}
			q -= i
			nn := n
			for j := int64(1); j < k; j++ {
				oo := q * j
				O(oo, " ")
				nn -= oo
			}
			O(nn, "\n")
			return

		}
	}
	O("-1\n")
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	scanner.Scan()
	k, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	if k >= int64(math.Sqrt(float64(2*n))) {
		fmt.Println(-1)
		os.Exit(0)
	}
	if k == 1 {
		fmt.Println(n)
		os.Exit(0)
	}

	sqrt := int64(math.Sqrt(float64(n))) + 1
	var gcd int64
	for i := int64(2); i <= sqrt; i++ {
		if n%i != 0 {
			continue
		}
		if fit(n, i, k) {
			if i > gcd {
				gcd = i
			}
		}
		if fit(n, n/i, k) {
			if n/i > gcd {
				gcd = n / i
			}
		}
	}
	if gcd == 0 {
		fmt.Println(-1)
		os.Exit(0)
	}
	for i := int64(1); i < k; i++ {
		fmt.Printf("%d ", i*gcd)
	}
	fmt.Println(n - (k*(k-1)*gcd)/2)
}

func fit(n, d, k int64) bool {
	if k > 10e6 {
		return false
	}
	if (k*k - k) > 10e10 {
		return false
	}
	if (k*k-k)*d >= 2*n {
		return false
	}
	return true
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	scanner.Scan()
	k, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	if k == 1 {
		fmt.Println(n)
		os.Exit(0)
	}

	sqrt := int64(math.Sqrt(float64(n))) + 1
	var gcd int64
	for i := int64(1); i <= sqrt; i++ {
		if n%i != 0 {
			continue
		}
		if fit(n, i, k) {
			if i > gcd {
				gcd = i
			}
		}
		if fit(n, n/i, k) {
			if n/i > gcd {
				gcd = n / i
			}
		}
	}
	if gcd == 0 {
		fmt.Println(-1)
		os.Exit(0)
	}
	for i := int64(1); i < k; i++ {
		fmt.Printf("%d ", i*gcd)
	}
	fmt.Println(n - (k*(k-1)*gcd)/2)
}

func fit(n, d, k int64) bool {
	if k > 10e6 {
		return false
	}
	if (k-1)*(k+2) > 10e10 {
		return false
	}
	if (k-1)*(k+2)*d >= 2*n {
		return false
	}
	return true
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	scanner.Scan()
	k, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	if k == 1 {
		fmt.Println(n)
		os.Exit(0)
	}

	sqrt := int64(math.Sqrt(float64(n))) + 1
	var gcd int64
	for i := int64(1); i <= sqrt; i++ {
		if n%i != 0 {
			continue
		}
		if fit(n, i, k) {
			if i > gcd {
				gcd = i
			}
		}
		if fit(n, n/i, k) {
			if n/i > gcd {
				gcd = n / i
			}
		}
	}
	if gcd == 0 {
		fmt.Println(-1)
		os.Exit(0)
	}
	for i := int64(1); i < k; i++ {
		fmt.Printf("%d ", i*gcd)
	}
	fmt.Println(n - (k*(k-1)*gcd)/2)
}

func fit(n, d, k int64) bool {
	if k > 10e6 {
		return false
	}
	if (k*k - k) > 10e10 {
		return false
	}
	if (k*k-k)*d >= 2*n {
		return false
	}
	return true
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	scanner.Scan()
	k, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	if 2*n < k*(k+1) {
		fmt.Println(-1)
		os.Exit(0)
	}
	if k == 1 {
		fmt.Println(n)
		os.Exit(0)
	}

	l := int64(math.Floor(float64(2*n) / float64(k*(k+1))))
	var gcd int64
	if sqrt := int64(math.Sqrt(float64(n))); l <= sqrt {
		for i := l; i >= 1; i-- {
			if n%i == 0 {
				gcd = int64(i)
				break
			}
		}
	} else {
		for i := int64(1); i <= sqrt+1; i++ {
			if n%i == 0 && n/i <= l {
				gcd = n / i
				break
			}
		}
	}
	if gcd == 0 {
		fmt.Println(-1)
		os.Exit(0)
	}
	sum := n / gcd
	for i := int64(1); i < k; i++ {
		fmt.Printf("%d ", gcd*i)
		sum -= i
	}
	fmt.Println(gcd * sum)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	scanner.Scan()
	k, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	if 2*n < k*(k+1) {
		fmt.Println(-1)
		os.Exit(0)
	}
	if k == 1 {
		fmt.Println(n)
		os.Exit(0)
	}

	l := int64(math.Floor(float64(2*n) / float64(k*(k+1))))
	var gcd int64
	if sqrt := int64(math.Sqrt(float64(n))); l <= sqrt {
		for i := l; i >= 1; i-- {
			if n%i == 0 {
				gcd = int64(i)
				break
			}
		}
	} else {
		for i := int64(1); i <= sqrt+1; i++ {
			if n%i == 0 && n/i <= l {
				gcd = n / i
			}
		}
	}
	sum := n / gcd
	for i := int64(1); i < k; i++ {
		fmt.Printf("%d ", gcd*i)
		sum -= i
	}
	fmt.Println(gcd * sum)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	scanner.Scan()
	k, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	if 2*n < k*(k+1) {
		fmt.Println(-1)
		os.Exit(0)
	}
	if k == 1 {
		fmt.Println(n)
		os.Exit(0)
	}

	l := int64(math.Floor(float64(2*n) / float64(k*(k+1))))
	var gcd int64
	if sqrt := int64(math.Sqrt(float64(n))); l <= sqrt {
		for i := l; i >= 1; i-- {
			if n%i == 0 {
				gcd = int64(i)
				break
			}
		}
	} else {
		for i := int64(1); i <= sqrt+1; i++ {
			if n%i == 0 && n/i < l {
				gcd = n / i
			}
		}
	}
	sum := n / gcd
	for i := int64(1); i < k; i++ {
		fmt.Printf("%d ", gcd*i)
		sum -= i
	}
	fmt.Println(gcd * sum)
}


Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game.Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will consist of m bits. Then he asks Peter to choose some m-bit number. After that, Bob computes the values of n variables. Each variable is assigned either a constant m-bit number or result of bitwise operation. Operands of the operation may be either variables defined before, or the number, chosen by Peter. After that, Peter's score equals to the sum of all variable values.Bob wants to know, what number Peter needs to choose to get the minimum possible score, and what number he needs to choose to get the maximum possible score. In both cases, if there are several ways to get the same score, find the minimum number, which he can choose.

The first line contains two integers n and m, the number of variables and bit depth, respectively (1 ≤ n ≤ 5000; 1 ≤ m ≤ 1000).  The following n lines contain descriptions of the variables. Each line describes exactly one variable. Description has the following format: name of a new variable, space, sign ":=", space, followed by one of:   Binary number of exactly m bits.  The first operand, space, bitwise operation ("AND", "OR" or "XOR"), space, the second operand. Each operand is either the name of variable defined before or symbol '?', indicating the number chosen by Peter.  Variable names are strings consisting of lowercase Latin letters with length at most 10. All variable names are different.

In the first line output the minimum number that should be chosen by Peter, to make the sum of all variable values minimum possible, in the second line output the minimum number that should be chosen by Peter, to make the sum of all variable values maximum possible. Both numbers should be printed as m-bit binary numbers.

5 1
a := 1
bb := 0
cx := ? OR a
d := ? XOR ?
e := d AND bb

NoteIn the first sample if Peter chooses a number 0112, then a = 1012, b = 0112, c = 0002, the sum of their values is 8. If he chooses the number 1002, then a = 1012, b = 0112, c = 1112, the sum of their values is 15.For the second test, the minimum and maximum sum of variables a, bb, cx, d and e is 2, and this sum doesn't depend on the number chosen by Peter, so the minimum Peter can choose is 0.

package main

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

var in *bufio.Reader

func scanf(format string, a ...interface{}) (int, error) {
    return fmt.Fscanf(in, format, a...)
}

func scanln() string {
    s, _ := in.ReadString('\n')
    return strings.TrimSpace(s)
}

const MAX = 10000
const MIN = -1

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

    var n, m int
    scanf("%d %d\n", &n, &m)
    vars := make(map[string][]string, n)
    names := make([]string, n)
    for i := 0; i < n; i++ {
        line := strings.Split(scanln(), " ")
        vars[line[0]] = append([]string(nil), line[2:]...)
        names[i] = line[0]
    }

    minNum := make([]byte, m)
    maxNum := make([]byte, m)
    for i := 0; i < m; i++ {
        minSum, maxSum := MAX, MIN
        var minBit, maxBit byte = 0, 0
        for bit := byte(0); bit <= 1; bit++ {
            assigns := make(map[string]byte, n+1)
            assigns["?"] = bit
            sum := 0
            for _, v := range names {
                val := vars[v]
                if len(val) == 1 {
                    assigns[v] = val[0][i]-'0'
                } else {
                    switch val[1] {
                    case "AND":
                        assigns[v] = assigns[val[0]] & assigns[val[2]]
                    case "OR":
                        assigns[v] = assigns[val[0]] | assigns[val[2]]
                    case "XOR":
                        assigns[v] = assigns[val[0]] ^ assigns[val[2]]
                    default:
                        panic(fmt.Errorf("cannot recognize operator %s", val[1]))
                    }
                }
                sum += int(assigns[v])
            }

            if sum < minSum {
                minSum = sum
                minBit = bit
            }
            if sum > maxSum {
                maxSum = sum
                maxBit = bit
            }
        }

        minNum[i] = minBit + '0'
        maxNum[i] = maxBit + '0'
    }
    fmt.Println(string(minNum))
    fmt.Println(string(maxNum))
}

package main

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

var in *bufio.Reader

func scanf(format string, a ...interface{}) (int, error) {
    return fmt.Fscanf(in, format, a...)
}

func scanln() string {
    s, _ := in.ReadString('\n')
    return strings.TrimSpace(s)
}

const MAX = 10000
const MIN = -1

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

    var n, m int
    scanf("%d %d\n", &n, &m)
    vars := make(map[string][]string, n)
    names := make([]string, n)
    for i := 0; i < n; i++ {
        line := strings.Split(scanln(), " ")
        vars[line[0]] = append([]string(nil), line[2:]...)
        names[i] = line[0]
    }

    minNum := make([]byte, m)
    maxNum := make([]byte, m)
    ch := make(chan []int, m)
    for i := 0; i < m; i++ {
        go func(idx int) {
            minSum, maxSum := MAX, MIN
            minBit, maxBit := 0, 0
            for bit := 0; bit <= 1; bit++ {
                assigns := make(map[string]int, n+1)
                assigns["?"] = bit
                sum := 0
                for _, v := range names {
                    val := vars[v]
                    if len(val) == 1 {
                        assigns[v] = int(val[0][idx]-'0')
                    } else {
                        switch val[1] {
                        case "AND":
                            assigns[v] = assigns[val[0]] & assigns[val[2]]
                        case "OR":
                            assigns[v] = assigns[val[0]] | assigns[val[2]]
                        case "XOR":
                            assigns[v] = assigns[val[0]] ^ assigns[val[2]]
                        default:
                            panic(fmt.Errorf("cannot recognize operator %s", val[1]))
                        }
                    }
                    sum += assigns[v]
                }

                if sum < minSum {
                    minSum = sum
                    minBit = bit
                }
                if sum > maxSum {
                    maxSum = sum
                    maxBit = bit
                }
            }
            ch <- []int{idx, minBit, maxBit}
        }(i)
    }
    for count := 0; count < m; count++ {
        data := <-ch
        minNum[data[0]] = byte(data[1] + '0')
        maxNum[data[0]] = byte(data[2] + '0')
    }
    fmt.Println(string(minNum))
    fmt.Println(string(maxNum))
}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if uu != "?" && uu[0] != '0' && uu[0] != '1' {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if vv != "?" && vv[0] != '0' && vv[0] != '1' {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

func main() {

	bio := bufio.NewReader(os.Stdin)

	line, _ := bio.ReadString('\n')

	line = strings.TrimSpace(line)

	args := strings.Split(line, " ")

	n, _ := strconv.Atoi(args[0])
	m, _ := strconv.Atoi(args[1])

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line, _ = bio.ReadString('\n')
		line = strings.TrimSpace(line)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	var res1, res2 []byte
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1 = append(res1, '1')
			res2 = append(res2, '0')

		} else if cnt1 < cnt2 {
			res1 = append(res1, '0')
			res2 = append(res2, '1')
		} else {
			res1 = append(res1, '0')
			res2 = append(res2, '0')

		}
	}
	fmt.Printf("%v\n", string(res2))

	fmt.Printf("%v\n", string(res1))

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"regexp"
	"unicode"
)

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

type expression struct {
	left, op, right string
}

var vars = make(map[string]expression)
var res = make(map[string][][2]byte)

var n, b int

func process(s string) [][2]byte {
	switch {
	case s == "?":
		r := make([][2]byte, b)
		for i := range r {
			r[i][0] = 0
			r[i][1] = 1
		}
		return r
	case unicode.IsDigit(rune(s[0])):
		r := make([][2]byte, b)
		for i := range r {
			r[i][0] = s[i] & 0x1
			r[i][1] = s[i] & 0x1
		}
		return r
	case unicode.IsLetter(rune(s[0])):
		return get(s)
	default:
		panic(fmt.Errorf("failed to process expression: %s", s))
	}
}

func get(v string) [][2]byte {
	if r, ok := res[v]; ok {
		return r
	}
	e := vars[v]
	var r [][2]byte
	if e.op == "" {
		r = process(e.left)
	} else {
		left, right := process(e.left), process(e.right)
		for i := 0; i < b; i++ {
			switch e.op[0] {
			case 'A':
				r = append(r, [2]byte{
					left[i][0] & right[i][0],
					left[i][1] & right[i][1],
				})
			case 'O':
				r = append(r, [2]byte{
					left[i][0] | right[i][0],
					left[i][1] | right[i][1],
				})
			case 'X':
				r = append(r, [2]byte{
					left[i][0] ^ right[i][0],
					left[i][1] ^ right[i][1],
				})
			default:
				panic("unknown operation")
			}
		}
	}
	res[v] = r
	return r
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &b)
	atom := fmt.Sprintf(`(\?|[[:digit:]]{%d}|[[:alpha:]]+)`, b)
	single := regexp.MustCompile(fmt.Sprintf(`^([[:alpha:]]+) := %s$`, atom))
	double := regexp.MustCompile(fmt.Sprintf(`^([[:alpha:]]+) := %s (AND|OR|XOR) %s$`, atom, atom))
	for i := 0; i < n; i++ {
		scanner.Scan()
		doublesub := double.FindStringSubmatch(scanner.Text())
		if len(doublesub) != 0 {
			vars[doublesub[1]] = expression{
				left:  doublesub[2],
				op:    doublesub[3],
				right: doublesub[4],
			}
		} else {
			singlesub := single.FindStringSubmatch(scanner.Text())
			if len(singlesub) != 0 {
				vars[singlesub[1]] = expression{
					left: singlesub[2],
				}
			}
		}
	}
	total := make([][2]int, b)
	for v := range vars {
		for i, r := range get(v) {
			total[i][0] += int(r[0])
			total[i][1] += int(r[1])
		}
	}
	m := [2][]byte{make([]byte, b), make([]byte, b)}
	for i := 0; i < b; i++ {
		if total[i][0] <= total[i][1] {
			m[0][i] = '0'
		} else {
			m[0][i] = '1'
		}

		if total[i][0] < total[i][1] {
			m[1][i] = '1'
		} else {
			m[1][i] = '0'
		}
	}
	fmt.Println(string(m[0]))
	fmt.Println(string(m[1]))
}

package main

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

var in *bufio.Reader

func scanf(format string, a ...interface{}) (int, error) {
    return fmt.Fscanf(in, format, a...)
}

func scanln() string {
    s, _ := in.ReadString('\n')
    return s[:len(s)-1]
}

const MAX = 10000
const MIN = -1

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

    var n, m int
    scanf("%d %d\n", &n, &m)
    vars := make(map[string][]string, n)
    names := make([]string, n)
    for i := 0; i < n; i++ {
        line := strings.Split(scanln(), " ")
        vars[line[0]] = append([]string(nil), line[2:]...)
        names[i] = line[0]
    }

    minNum := make([]byte, m)
    maxNum := make([]byte, m)
    for i := 0; i < m; i++ {
        minSum, maxSum := MAX, MIN
        var minBit, maxBit byte = 0, 0
        for bit := byte(0); bit <= 1; bit++ {
            assigns := make(map[string]byte, n+1)
            assigns["?"] = bit
            sum := 0
            for _, v := range names {
                val := vars[v]
                if len(val) == 1 {
                    assigns[v] = val[0][i]-'0'
                } else {
                    switch val[1] {
                    case "AND":
                        assigns[v] = assigns[val[0]] & assigns[val[2]]
                    case "OR":
                        assigns[v] = assigns[val[0]] | assigns[val[2]]
                    case "XOR":
                        assigns[v] = assigns[val[0]] ^ assigns[val[2]]
                    default:
                        panic(fmt.Errorf("cannot recognize operator %s", val[1]))
                    }
                }
                sum += int(assigns[v])
            }

            fmt.Println(sum, minSum, maxSum)
            if sum < minSum {
                minSum = sum
                minBit = bit
            }
            if sum > maxSum {
                maxSum = sum
                maxBit = bit
            }
            fmt.Println(sum, minSum, maxSum)
        }

        minNum[i] = minBit + '0'
        maxNum[i] = maxBit + '0'
    }
    fmt.Println(string(minNum))
    fmt.Println(string(maxNum))
}

package main

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

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
}

var in *bufio.Reader

func scanf(format string, a ...interface{}) (int, error) {
    return fmt.Fscanf(in, format, a...)
}

func scanln() string {
    s, _ := in.ReadString('\n')
    return s[:len(s)-1]
}

const MAX = 10000
const MIN = -1

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

    var n, m int
    scanf("%d %d\n", &n, &m)
    vars := make(map[string][]string, n)
    names := make([]string, n)
    for i := 0; i < n; i++ {
        line := strings.Split(scanln(), " ")
        vars[line[0]] = append([]string(nil), line[2:]...)
        names[i] = line[0]
    }

    minNum := make([]byte, m)
    maxNum := make([]byte, m)
    for i := 0; i < m; i++ {
        minSum, maxSum := MAX, MIN
        minBit, maxBit := 0, 0
        for bit := 0; bit <= 1; bit++ {
            assigns := make(map[string]int)
            assigns["?"] = bit
            sum := 0
            for _, v := range names {
                val := vars[v]
                if len(val) == 1 {
                    var err error
                    assigns[v], err = strconv.Atoi(val[0][i:i+1])
                    if err != nil {
                        panic(err)
                    }
                } else {
                    switch val[1] {
                    case "AND":
                        assigns[v] = assigns[val[0]] & assigns[val[2]]
                    case "OR":
                        assigns[v] = assigns[val[0]] | assigns[val[2]]
                    case "XOR":
                        assigns[v] = assigns[val[0]] ^ assigns[val[2]]
                    }
                }
                sum += assigns[v]
            }

            if sum < minSum {
                minSum = sum
                minBit = bit
            }
            if sum > maxSum {
                maxSum = sum
                maxBit = bit
            }
        }

        minNum[i] = byte(minBit + '0')
        maxNum[i] = byte(maxBit + '0')
    }
    fmt.Println(string(minNum))
    fmt.Println(string(maxNum))
}

package main

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

var in *bufio.Reader

func scanf(format string, a ...interface{}) (int, error) {
    return fmt.Fscanf(in, format, a...)
}

func scanln() string {
    s, _ := in.ReadString('\n')
    return s[:len(s)-1]
}

const MAX = 10000
const MIN = -1

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

    var n, m int
    scanf("%d %d\n", &n, &m)
    vars := make(map[string][]string, n)
    names := make([]string, n)
    for i := 0; i < n; i++ {
        line := strings.Split(scanln(), " ")
        vars[line[0]] = append([]string(nil), line[2:]...)
        names[i] = line[0]
    }
    fmt.Println(names, vars)

    minNum := make([]byte, m)
    maxNum := make([]byte, m)
    for i := 0; i < m; i++ {
        minSum, maxSum := MAX, MIN
        var minBit, maxBit byte = 0, 0
        for bit := byte(0); bit <= 1; bit++ {
            assigns := make(map[string]byte, n+1)
            assigns["?"] = bit
            sum := 0
            for _, v := range names {
                val := vars[v]
                if len(val) == 1 {
                    assigns[v] = val[0][i]-'0'
                } else {
                    switch val[1] {
                    case "AND":
                        assigns[v] = assigns[val[0]] & assigns[val[2]]
                    case "OR":
                        assigns[v] = assigns[val[0]] | assigns[val[2]]
                    case "XOR":
                        assigns[v] = assigns[val[0]] ^ assigns[val[2]]
                    default:
                        panic(fmt.Errorf("cannot recognize operator %s", val[1]))
                    }
                }
                sum += int(assigns[v])
            }

            if sum < minSum {
                minSum = sum
                minBit = bit
            }
            if sum > maxSum {
                maxSum = sum
                maxBit = bit
            }
        }

        minNum[i] = minBit + '0'
        maxNum[i] = maxBit + '0'
    }
    fmt.Println(string(minNum))
    fmt.Println(string(maxNum))
}

package main

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

var in *bufio.Reader

func scanf(format string, a ...interface{}) (int, error) {
    return fmt.Fscanf(in, format, a...)
}

func scanln() string {
    s, _ := in.ReadString('\n')
    return s[:len(s)-1]
}

const MAX = 10000
const MIN = -1

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

    var n, m int
    scanf("%d %d\n", &n, &m)
    vars := make(map[string][]string, n)
    names := make([]string, n)
    for i := 0; i < n; i++ {
        line := strings.Split(scanln(), " ")
        vars[line[0]] = append([]string(nil), line[2:]...)
        names[i] = line[0]
    }

    minNum := make([]byte, m)
    maxNum := make([]byte, m)
    for i := 0; i < m; i++ {
        minSum, maxSum := MAX, MIN
        var minBit, maxBit byte = 0, 0
        for bit := byte(0); bit <= 1; bit++ {
            assigns := make(map[string]byte, n+1)
            assigns["?"] = bit
            sum := 0
            for _, v := range names {
                val := vars[v]
                if len(val) == 1 {
                    assigns[v] = val[0][i]-'0'
                } else {
                    switch val[1] {
                    case "AND":
                        assigns[v] = assigns[val[0]] & assigns[val[2]]
                    case "OR":
                        assigns[v] = assigns[val[0]] | assigns[val[2]]
                    case "XOR":
                        assigns[v] = assigns[val[0]] ^ assigns[val[2]]
                    default:
                        panic(fmt.Errorf("cannot recognize operator %s", val[1]))
                    }
                }
                sum += int(assigns[v])
            }

            if sum < minSum {
                minSum = sum
                minBit = bit
            }
            if sum > maxSum {
                maxSum = sum
                maxBit = bit
            }
        }

        minNum[i] = minBit + '0'
        maxNum[i] = maxBit + '0'
    }
    fmt.Println(string(minNum))
    fmt.Println(string(maxNum))
}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if _, exist := M[uu]; exist {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if _, exist := M[vv]; exist {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

func readLine() string {
	var tmp []byte
	var c byte

	for true {
		fmt.Scanf("%c", &c)
		if c == '\n' {
			break
		}
		tmp = append(tmp, c)
	}
	return string(tmp)
}

func main() {

	line := readLine()

	//fmt.Printf("%v", line)

	args := strings.Split(line, " ")

	n, _ := strconv.Atoi(args[1])
	m, _ := strconv.Atoi(args[0])
	//fmt.Printf("%v\n", args[1])

	fmt.Printf("n = %d, m = %d\n", n, m)

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line = readLine()
		//line = strings.Replace(line, "\n", "", -1)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	res1 := make([]int, m+1)
	res2 := make([]int, m+1)
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1[i], res2[i] = 1, 0
		} else if cnt1 < cnt2 {
			res1[i], res2[i] = 0, 1
		} else {
			res1[i], res2[i] = 0, 0
		}
	}

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

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

}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if _, exist := M[uu]; exist {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if _, exist := M[vv]; exist {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

func readLine() string {
	var tmp []byte
	var c byte

	for true {
		fmt.Scanf("%c", &c)
		if c == '\n' {
			break
		}
		tmp = append(tmp, c)
	}
	return string(tmp)
}

func main() {

	line := readLine()

	//fmt.Printf("%v", line)

	args := strings.Split(line, " ")

	n, _ := strconv.Atoi(args[0])
	m, _ := strconv.Atoi(args[1])
	fmt.Printf("%v\n", args[1])

	//fmt.Printf("n = %d, m = %d\n", n, m)

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line = readLine()
		//line = strings.Replace(line, "\n", "", -1)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	res1 := make([]int, m+1)
	res2 := make([]int, m+1)
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1[i], res2[i] = 1, 0
		} else if cnt1 < cnt2 {
			res1[i], res2[i] = 0, 1
		} else {
			res1[i], res2[i] = 0, 0
		}
	}

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

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

}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if _, exist := M[uu]; exist {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if _, exist := M[vv]; exist {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

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

	line, _ := bio.ReadString('\n')

	args := strings.Split(line, " ")
	args[1] = strings.Replace(args[1], "\n", "", -1)

	n, _ := strconv.Atoi(args[0])
	m, _ := strconv.Atoi(args[1])

	//	fmt.Printf("n = %d m = %d\n", n, m)

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line, _ = bio.ReadString('\n')
		line = strings.Replace(line, "\n", "", -1)
		//fmt.Printf("%v\n", line)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	/*for i := 0; i < n; i++ {
		fmt.Printf("%v %v %v %v\n", p[i].w, p[i].u, p[i].op, p[i].v)
	}*/

	res1 := make([]int, m+1)
	res2 := make([]int, m+1)
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1[i], res2[i] = 1, 0
		} else if cnt1 < cnt2 {
			res1[i], res2[i] = 0, 1
		} else {
			res1[i], res2[i] = 0, 0
		}
	}

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

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

}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if _, exist := M[uu]; exist {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if _, exist := M[vv]; exist {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

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

	line, _ := bio.ReadString('\n')

	args := strings.Split(line, " ")
	args[1] = strings.Replace(args[1], "\n", "", -1)

	n, _ := strconv.Atoi(args[0])
	m, _ := strconv.Atoi(args[1])

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line, _ = bio.ReadString('\n')
		line = strings.Replace(line, "\n", "", -1)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	res1 := make([]int, m+1)
	res2 := make([]int, m+1)
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1[i], res2[i] = 1, 0
		} else if cnt1 < cnt2 {
			res1[i], res2[i] = 0, 1
		} else {
			res1[i], res2[i] = 0, 0
		}
	}

	fmt.Printf("m = %d", m)

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

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

}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if _, exist := M[uu]; exist {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if _, exist := M[vv]; exist {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

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

	line, _ := bio.ReadString('\n')

	args := strings.Split(line, " ")
	args[1] = strings.Replace(args[1], "\n", "", -1)

	n, _ := strconv.Atoi(args[0])
	m, _ := strconv.Atoi(args[1])

	fmt.Printf("%d\n", m)

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line, _ = bio.ReadString('\n')
		line = strings.Replace(line, "\n", "", -1)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	res1 := make([]int, m+1)
	res2 := make([]int, m+1)
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1[i], res2[i] = 1, 0
		} else if cnt1 < cnt2 {
			res1[i], res2[i] = 0, 1
		} else {
			res1[i], res2[i] = 0, 0
		}
	}

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

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

}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if _, exist := M[uu]; exist {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if _, exist := M[vv]; exist {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

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

	line, _ := bio.ReadString('\n')

	args := strings.Split(line, " ")
	args[1] = strings.Replace(args[1], "\n", "", -1)

	n, _ := strconv.Atoi(args[0])
	m, _ := strconv.Atoi(args[1])

	fmt.Printf("n = %d, m = %d\n", n, m)

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line, _ = bio.ReadString('\n')
		line = strings.Replace(line, "\n", "", -1)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	res1 := make([]int, m+1)
	res2 := make([]int, m+1)
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1[i], res2[i] = 1, 0
		} else if cnt1 < cnt2 {
			res1[i], res2[i] = 0, 1
		} else {
			res1[i], res2[i] = 0, 0
		}
	}

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

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

}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if _, exist := M[uu]; exist {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if _, exist := M[vv]; exist {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

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

	line, _ := bio.ReadString('\n')

	args := strings.Split(line, " ")
	args[1] = strings.Replace(args[1], "\n", "", -1)

	n, _ := strconv.Atoi(args[0])
	m, _ := strconv.Atoi(args[1])

	//	fmt.Printf("n = %d m = %d\n", n, m)

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line, _ = bio.ReadString('\n')
		line = strings.Replace(line, "\n", "", -1)
		//fmt.Printf("%v\n", line)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	for i := 0; i < n; i++ {
		fmt.Printf("%v %v %v %v\n", p[i].w, p[i].u, p[i].op, p[i].v)
	}

	res1 := make([]int, m+1)
	res2 := make([]int, m+1)
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1[i], res2[i] = 1, 0
		} else if cnt1 < cnt2 {
			res1[i], res2[i] = 0, 1
		} else {
			res1[i], res2[i] = 0, 0
		}
	}

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

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

}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if _, exist := M[uu]; exist {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if _, exist := M[vv]; exist {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

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

	line, _ := bio.ReadString('\n')

	args := strings.Split(line, " ")
	args[1] = strings.Replace(args[1], "\n", "", -1)
	fmt.Printf("%v", args[1])

	n, _ := strconv.Atoi(args[0])
	m, _ := strconv.Atoi(args[1])

	fmt.Printf("n = %d, m = %d\n", n, m)

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line, _ = bio.ReadString('\n')
		line = strings.Replace(line, "\n", "", -1)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	res1 := make([]int, m+1)
	res2 := make([]int, m+1)
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1[i], res2[i] = 1, 0
		} else if cnt1 < cnt2 {
			res1[i], res2[i] = 0, 1
		} else {
			res1[i], res2[i] = 0, 0
		}
	}

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

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

}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if _, exist := M[uu]; exist {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if _, exist := M[vv]; exist {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

func readLine() string {
	var tmp []byte
	var c byte

	for true {
		fmt.Scanf("%c", &c)
		if c == '\n' {
			break
		}
		tmp = append(tmp, c)
	}
	return string(tmp)
}

func main() {

	line := readLine()

	//fmt.Printf("%v", line)

	args := strings.Split(line, " ")

	n, _ := strconv.Atoi(args[0])
	tm, _ := strconv.ParseInt(args[1], 10, 0)
	m := int(tm)
	//fmt.Printf("%v\n", args[1])

	//fmt.Printf("n = %d, m = %d\n", n, m)

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line = readLine()
		//line = strings.Replace(line, "\n", "", -1)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	res1 := make([]int, m+1)
	res2 := make([]int, m+1)
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1[i], res2[i] = 1, 0
		} else if cnt1 < cnt2 {
			res1[i], res2[i] = 0, 1
		} else {
			res1[i], res2[i] = 0, 0
		}
	}

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

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

}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if _, exist := M[uu]; exist {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if _, exist := M[vv]; exist {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

func readLine() string {
	var tmp []byte
	var c byte

	for true {
		fmt.Scanf("%c", &c)
		if c == '\n' {
			break
		}
		tmp = append(tmp, c)
	}
	return string(tmp)
}

func main() {

	line := readLine()

	fmt.Printf("%v", line)

	args := strings.Split(line, " ")

	n, _ := strconv.Atoi(args[0])
	m, _ := strconv.Atoi(args[1])

	//fmt.Printf("n = %d, m = %d\n", n, m)

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line = readLine()
		//line = strings.Replace(line, "\n", "", -1)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	res1 := make([]int, m+1)
	res2 := make([]int, m+1)
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1[i], res2[i] = 1, 0
		} else if cnt1 < cnt2 {
			res1[i], res2[i] = 0, 1
		} else {
			res1[i], res2[i] = 0, 0
		}
	}

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

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

}

package main

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

type Node struct {
	op string
	u  string
	v  string
	w  string
}

var (
	p []Node
	M map[string]int
)

func (node *Node) Eval(x, i int) int {
	var x1, y1, ans int
	uu, vv := node.u, node.v

	if _, exist := M[uu]; exist {
		x1 = M[uu]
	} else {
		if uu == "?" {
			x1 = x
		} else if uu[i] == '1' {
			x1 = 1
		} else {
			x1 = 0
		}
	}

	defer func() {
		M[node.w] = ans
	}()

	if node.op == "" {
		ans = x1
		return ans
	}

	if _, exist := M[vv]; exist {
		y1 = M[vv]
	} else {
		if vv == "?" {
			y1 = x
		} else if vv[i] == '1' {
			y1 = 1
		} else {
			y1 = 0
		}
	}

	if node.op == "AND" {
		ans = x1 & y1
		return ans
	}

	if node.op == "OR" {
		ans = x1 | y1
		return ans
	}

	ans = x1 ^ y1

	return ans

}

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

	line, _ := bio.ReadString('\n')

	args := strings.Split(line, " ")
	args[1] = strings.Replace(args[1], "\n", "", -1)

	n, _ := strconv.Atoi(args[0])
	m, _ := strconv.Atoi(args[1])

	p = make([]Node, n+1)

	for i := 0; i < n; i++ {
		line, _ = bio.ReadString('\n')
		line = strings.Replace(line, "\n", "", -1)

		args = strings.Split(line, " ")

		if len(args) == 3 {
			p[i].u = args[2]
			p[i].w = args[0]
		} else {
			p[i].w = args[0]
			p[i].u = args[2]
			p[i].op = args[3]
			p[i].v = args[4]
		}
	}

	res1 := make([]int, m+1)
	res2 := make([]int, m+1)
	M = make(map[string]int)

	for i := 0; i < m; i++ {
		cnt1, cnt2 := 0, 0

		for j := 0; j < n; j++ {
			cnt1 += p[j].Eval(1, i)
		}

		for j := 0; j < n; j++ {
			cnt2 += p[j].Eval(0, i)
		}

		if cnt1 > cnt2 {
			res1[i], res2[i] = 1, 0
		} else if cnt1 < cnt2 {
			res1[i], res2[i] = 0, 1
		} else {
			res1[i], res2[i] = 0, 0
		}
	}

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

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

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"regexp"
	"unicode"
)

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

type expression struct {
	left, op, right string
}

var vars = make(map[string]expression)
var res = make(map[string][][2]byte)

var n, b int

func process(s string) [][2]byte {
	if s == "?" {
		r := make([][2]byte, b)
		for i := range r {
			r[i][0] = 0
			r[i][1] = 1
		}
		return r
	} else if unicode.IsDigit(rune(s[0])) {
		r := make([][2]byte, b)
		for i := range r {
			r[i][0] = s[i] & 0x1
			r[i][1] = s[i] & 0x1
		}
		return r
	} else if unicode.IsLetter(rune(s[0])) {
		return get(s)
	} else {
		panic(fmt.Errorf("failed to process expression: %s", s))
	}
}

func get(v string) [][2]byte {
	if r, ok := res[v]; ok {
		return r
	}
	e := vars[v]
	var r [][2]byte
	if e.op == "" {
		r = process(e.left)
	} else {
		l := process(e.left)
		r = process(e.right)
		for i := 0; i < b; i++ {
			switch e.op[0] {
			case 'A':
				r[i][0] &= l[i][0]
				r[i][1] &= l[i][1]
			case 'O':
				r[i][0] |= l[i][0]
				r[i][1] |= l[i][1]
			case 'X':
				r[i][0] ^= l[i][0]
				r[i][1] ^= l[i][1]
			default:
				panic("unknown operation")
			}
		}
	}
	res[v] = r
	return r
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &b)
	atom := fmt.Sprintf(`(\?|[[:digit:]]{%d}|[[:alpha:]]+)`, b)
	single := regexp.MustCompile(fmt.Sprintf(`^([[:alpha:]]+) := %s$`, atom))
	double := regexp.MustCompile(fmt.Sprintf(`^([[:alpha:]]+) := %s (AND|OR|XOR) %s$`, atom, atom))
	for i := 0; i < n; i++ {
		scanner.Scan()
		doublesub := double.FindStringSubmatch(scanner.Text())
		if len(doublesub) != 0 {
			vars[doublesub[1]] = expression{
				left:  doublesub[2],
				op:    doublesub[3],
				right: doublesub[4],
			}
		} else {
			singlesub := single.FindStringSubmatch(scanner.Text())
			if len(singlesub) != 0 {
				vars[singlesub[1]] = expression{
					left: singlesub[2],
				}
			}
		}
	}
	total := make([][2]int, b)
	for v := range vars {
		for i, r := range get(v) {
			total[i][0] += int(r[0])
			total[i][1] += int(r[1])
		}
	}
	m := [2][]byte{make([]byte, b), make([]byte, b)}
	for i := 0; i < b; i++ {
		if total[i][0] <= total[i][1] {
			m[0][i] = '0'
		} else {
			m[0][i] = '1'
		}

		if total[i][0] < total[i][1] {
			m[1][i] = '1'
		} else {
			m[1][i] = '0'
		}
	}
	fmt.Println(string(m[0]))
	fmt.Println(string(m[1]))
}