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

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


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 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"
    "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]))
}


package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	mat := map[int64]map[int64]bool{}
	for i := int64(0); i < n-1; i++ {
		a, b := reader.NextInt64(), reader.NextInt64()
		if mat[a] == nil {
			mat[a] = map[int64]bool{}
		}
		if mat[b] == nil {
			mat[b] = map[int64]bool{}
		}
		mat[a][b] = true
		mat[b][a] = true
	}
	//writer.Printf("%v\n", mat)
	writer.Printf("%d %d\n", solveMin(mat), solveMax(mat))
}

func solveMin(mat map[int64]map[int64]bool) int64 {
	set := map[int64]bool{}
	dfs(mat, set, 1, 0, 0)
	if len(set) == 1 {
		return 1
	} else {
		return 3
	}
}

func dfs(mat map[int64]map[int64]bool, set map[int64]bool, to int64, from int64, curr int64) {
	if len(mat[to]) == 1 {
		set[curr] = true
	}
	curr ^= 1
	for child := range mat[to] {
		if child != from {
			dfs(mat, set, child, to, curr)
		}
	}
}

func solveMax(mat map[int64]map[int64]bool) int64 {
	ret := int64(len(mat)) - 1
	for i := range mat {
		cnt := int64(0)
		for nxt := range mat[i] {
			if len(mat[nxt]) == 1 {
				cnt++
			}
		}
		if cnt != 0 {
			ret -= cnt - 1
		}
	}
	return ret
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	mat := map[int64]map[int64]bool{}
	for i := int64(0); i < n-1; i++ {
		a, b := reader.NextInt64(), reader.NextInt64()
		if mat[a] == nil {
			mat[a] = map[int64]bool{}
		}
		if mat[b] == nil {
			mat[b] = map[int64]bool{}
		}
		mat[a][b] = true
		mat[b][a] = true
	}
	writer.Printf("%d %d\n", solveMin(mat), solveMax(mat))
}

func solveMin(mat map[int64]map[int64]bool) int64 {
	set := map[bool]struct{}{}

	var dfs func(int64, int64, bool)
	dfs = func(from, to int64, curr bool) {
		if len(mat[to]) == 1 {
			set[curr] = struct{}{}
		}
		for child := range mat[to] {
			if child != from {
				dfs(to, child, !curr)
			}
		}
	}
	dfs(0, 1, true)

	if len(set) == 1 {
		return 1
	} else {
		return 3
	}
}

func solveMax(mat map[int64]map[int64]bool) int64 {
	ret := int64(len(mat)) - 1
	for i := range mat {
		cnt := int64(0)
		for nxt := range mat[i] {
			if len(mat[nxt]) == 1 {
				cnt++
			}
		}
		if cnt != 0 {
			ret -= cnt - 1
		}
	}
	return ret
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	mat := map[int64]map[int64]bool{}
	for i := int64(0); i < n-1; i++ {
		a, b := reader.NextInt64(), reader.NextInt64()
		if mat[a] == nil {
			mat[a] = map[int64]bool{}
		}
		if mat[b] == nil {
			mat[b] = map[int64]bool{}
		}
		mat[a][b] = true
		mat[b][a] = true
	}
	//writer.Printf("%v\n", mat)
	writer.Printf("%d %d\n", solveMin(mat), solveMax(mat))
}

func solveMin(mat map[int64]map[int64]bool) int64 {
	set := map[int64]bool{}
	dfs(mat, set, 1, 0, 0)
	if len(set) == 1 {
		return 1
	} else {
		return 3
	}
}

func dfs(mat map[int64]map[int64]bool, set map[int64]bool, to int64, from int64, curr int64) {
	if len(mat[to]) == 1 {
		set[curr] = true
	}
	curr ^= 1
	for child := range mat[to] {
		if child != from {
			dfs(mat, set, child, to, curr)
		}
	}
}

func solveMax(mat map[int64]map[int64]bool) int64 {
	ret := int64(len(mat)) - 1
	for i := range mat {
		cnt := int64(0)
		for nxt := range mat[i+1] {
			if len(mat[nxt]) == 1 {
				cnt++
			}
		}
		ret -= max(0, cnt-1)
	}
	return ret
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	mat := map[int64]map[int64]bool{}
	for i := int64(0); i < n-1; i++ {
		a, b := reader.NextInt64(), reader.NextInt64()
		if mat[a] == nil {
			mat[a] = map[int64]bool{}
		}
		if mat[b] == nil {
			mat[b] = map[int64]bool{}
		}
		mat[a][b] = true
		mat[b][a] = true
	}
	//writer.Printf("%v\n", mat)
	writer.Printf("%d %d\n", solveMin(mat), solveMax(mat))
}

func solveMin(mat map[int64]map[int64]bool) int64 {
	set := map[int64]bool{}
	dfs(mat, set,  1, 0, 0)
	if len(set) == 1 {
		return 1
	} else {
		return 3
	}
}

func dfs(mat map[int64]map[int64]bool, set map[int64]bool, to int64, from int64, curr int64) {
	if len(mat[to]) == 1 {
		set[curr] = true
	}
	curr ^= 1
	for child := range mat[to] {
		if child != from {
			dfs(mat, set, child, to, curr)
		}
	}
}

func solveMax(mat map[int64]map[int64]bool) int64 {
	ret := int64(len(mat)) - 1
	for i := range mat {
		cnt := int64(0)
		for nxt := range mat[i+1] {
			if len(mat[nxt]) == 1 {
				cnt++
			}
		}
		if cnt != 0 {
			ret -= cnt-1
		}
	}
	return ret
}


package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o, tot := make([]int64, n), 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &o[j])
		}
		for j := 0; j < n; j++ {
			for o[j]%2 == 0 {
				o[j] = o[j] >> 1
				tot++
			}
		}
		sort.Slice(o, func(i, j int) bool { return o[i] < o[j] })
		for j := 0; j < tot; j++ {
			o[n-1] = o[n-1] << 1
		}
		ans := int64(0)
		for j := 0; j < n; j++ {
			ans += o[j]
		}
		fmt.Fprintln(w, ans)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

		arr := make([]int, n)
		t := int64(1)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])

			for arr[i]%2 == 0 {
				arr[i] /= 2
				t *= 2
			}
		}

		sort.Ints(arr)
		t *= int64(arr[n-1])
		for i := 0; i < n-1; i++ {
			t += int64(arr[i])
		}
		fmt.Fprintln(out, t)
	}
}

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    a := make([]int64, n)
    ans := int64(0)
    for i := 0; i < n; i ++ {
        fmt.Fscan(input, &a[i])
    }
    shift := 0
    for i := 0; i < n; i++ {
        if a[i] & 1 == 1 { continue }
        for a[i] & 1 == 0 {
            shift++
            a[i] /= 2
        }
    }
    sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
    a[n - 1] = a[n - 1] << shift
    for i := 0; i < n; i++ {
        ans += a[i]
    }
    fmt.Fprintln(output, ans)
}

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

package main

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

/*
3
1
1
1
3
2
8 8
---
1
3
64
======
1
3
2 3 4
---
26
======
1
15
8 8 8 8 8 8 8 8 8 8 8 8 8 8 15
---
*/

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

	bld := strings.Builder{}

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

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int64, n)

		for i := 0; i < n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		k := int64(1)

		for i := 0; i < n; i++ {
			for a[i]%2 == 0 {
				a[i] /= 2
				k *= 2
			}
		}

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

		a[n-1] *= k

		sum := int64(0)
		for _, num := range a {
			sum += num
		}

		fmt.Fprintln(&bld, sum)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	fst int
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

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

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

	return true
}

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

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

// Examples:
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 2
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	lenNum := int(math.Log10(float64(num))) + 1
	if pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

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

package main

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

func main(){
	var N_INPS int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N_INPS)
	var inps [][]int64
	var a int64
	for i:=0; i < N_INPS; i++ {
		scanner.Scan()
		scanner.Scan()
		var inp []int64
		for _, part := range strings.Split(scanner.Text(), " "){
			a, _ = strconv.ParseInt(part, 10, 64)
			inp = append(inp, a)
		}
		inps = append(inps, inp)
	}
	for _, inp := range inps {
		fmt.Println(compute_max(inp))
	}
}

func compute_max(arr []int64) int64{
	count := 0
	for i, _ := range arr {
		for arr[i]%2 == 0 {
			arr[i] /= 2
			count ++
		}
	}
	//sort.Slice(arr, func (x, y int) bool {return arr[x] < arr[y]})
	//arr[len(arr)-1] *= int64(math.Pow(2, float64(count)))
	max_el := 0
	for i, _ := range arr {
		if arr[i] > arr[max_el]{
			max_el = i
		}
	}
	arr[max_el] *= int64(math.Pow(2, float64(count)))
	return sum_arr(arr)
}

func sum_arr(arr []int64) int64{
	sum := int64(0)
	for _, num := range arr {
		sum += num
	}
	return sum
}

package main

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

func main(){
	var N_INPS int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N_INPS)
	var inps [][]int64
	var a int64
	for i:=0; i < N_INPS; i++ {
		scanner.Scan()
		scanner.Scan()
		var inp []int64
		for _, part := range strings.Split(scanner.Text(), " "){
			a, _ = strconv.ParseInt(part, 10, 64)
			inp = append(inp, a)
		}
		inps = append(inps, inp)
	}
	for _, inp := range inps {
		fmt.Println(compute_max(inp))
	}
}

func compute_max(arr []int64) int64{
	count := 0
	for i, _ := range arr {
		for arr[i]%2 == 0 {
			arr[i] /= 2
			count ++
		}
	}
	sort.Slice(arr, func (x, y int) bool {return arr[x] < arr[y]})
	arr[len(arr)-1] *= int64(math.Pow(2, float64(count)))
	return sum_arr(arr)
}

func sum_arr(arr []int64) int64{
	sum := int64(0)
	for _, num := range arr {
		sum += num
	}
	return sum
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o, tot := make([]int, n), 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &o[j])
		}
		for j := 0; j < n; j++ {
			for o[j]%2 == 0 {
				o[j] = o[j] >> 1
				tot++
			}
		}
		sort.Slice(o, func(i, j int) bool { return o[i] < o[j] })
		for j := 0; j < tot; j++ {
			o[n-1] = o[n-1] << 1
		}
		ans := int64(0)
		for j := 0; j < n; j++ {
			ans += int64(o[j])
		}
		fmt.Fprintln(w, ans)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o, tot, mx, k := make([]int64, n), 0, int64(-1), 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &o[j])
		}
		sort.Slice(o, func(i, j int) bool { return o[i] < o[j] })
		for j := 0; j < n; j++ {
			if o[j]%2 != 0 && o[j] > mx {
				mx, k = o[j], j
			}
		}
		if mx != -1 {
			o[k], o[n-1] = o[n-1], o[k]
		}
		for j := 0; j < n; j++ {
			for o[j]%2 == 0 {
				if j == n-1 && mx == -1 {
					break
				}
				o[j] = o[j] >> 1
				tot++
			}
		}
		for j := 0; j < tot; j++ {
			o[n-1] = o[n-1] << 1
		}
		ans := int64(0)
		for j := 0; j < n; j++ {
			ans += o[j]
		}
		fmt.Fprintln(w, ans)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o, tot, mx, k := make([]int64, n), 0, int64(-1), 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &o[j])
			if o[j]%2 != 0 && o[j] > mx {
				mx, k = o[j], j
			}
		}
		sort.Slice(o, func(i, j int) bool { return o[i] < o[j] })
		if mx != -1 {
			o[k], o[n-1] = o[n-1], o[k]
		}
		for j := 0; j < n; j++ {
			for o[j]%2 == 0 {
				if j == n-1 && mx == -1 {
					break
				}
				o[j] = o[j] >> 1
				tot++
			}
		}
		for j := 0; j < tot; j++ {
			o[n-1] = o[n-1] << 1
		}
		ans := int64(0)
		for j := 0; j < n; j++ {
			ans += o[j]
		}
		fmt.Fprintln(w, ans)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func Sum(o []int) int {
	sum := 0
	for i := 0; i < len(o); i++ {
		sum += o[i]
	}
	return sum
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o, tot, mx, k := make([]int, n), 0, -1, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &o[j])
			if o[j]%2 != 0 && o[j] > mx {
				mx, k = o[j], j
			}
		}
		sort.Ints(o)
		if mx != -1 {
			o[k], o[n-1] = o[n-1], o[k]
		}
		for j := 0; j < n; j++ {
			for o[j]%2 == 0 {
				if j == n-1 && mx == -1 {
					break
				}
				o[j] = o[j] >> 1
				tot++
			}
		}
		for j := 0; j < tot; j++ {
			o[n-1] = o[n-1] << 1
		}
		fmt.Fprintln(w, Sum(o))
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

		var x int
		var m1, m2 int
		var t int
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v == 2 || v == 4 || v == 8 || v == 16 {
				x += bits.Len(uint(v)) - 1
				t++
			} else if v%2 == 0 {
				x++
				t += v / 2
			} else {
				t += v
			}

			if v > m1 {
				m1, m2 = v, m1
			} else if v > m2 {
				m2 = v
			}

		}

		total := int64(m1)
		if m1 == 16 || m1 == 8 || m1 == 4 || m1 == 2 && m2 != 0 {
			total = int64(m2)
		}

		if total%2 == 0 {
			if bits.OnesCount(uint(total)) == 1 {
				x -= bits.Len(uint(total)) - 1
				t--
			} else {
				t -= int(total / 2)
				x--
			}
		} else {
			t -= int(total)
		}

		for i := 0; i < x; i++ {
			total *= 2
		}

		if n == 1 {
			fmt.Fprintln(out, m1)
		} else {
			fmt.Fprintln(out, total+int64(t))

		}
	}
}

package main

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

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

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

		var x int
		var m1, m2 int
		var t int
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v == 2 || v == 4 || v == 8 || v == 16 {
				x += bits.Len(uint(v)) - 1
				t++
			} else if v%2 == 0 {
				x++
				t += v / 2
			} else {
				t += v
			}

			if v > m1 {
				m1, m2 = v, m1
			} else if v > m2 {
				m2 = v
			}

		}

		total := int64(m1)
		if m1 == 16 || m1 == 8 || m1 == 4 || m1 == 2 && m2 != 0 {
			total = int64(m2)
		}

		if total%2 == 0 {
			if bits.OnesCount(uint(total)) == 1 {
				x -= bits.Len(uint(total)) - 1
				t--
			} else {
				t -= int(total / 2)
				x--
			}
		} else {
			t -= int(total)
		}

		for i := 0; i < x; i++ {
			total *= 2
		}

		fmt.Fprintln(out, total+int64(t))
	}
}

package main

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

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

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

		var x int
		var m1, m2 int
		var t int
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v == 2 || v == 4 || v == 8 || v == 16 {
				x += bits.Len(uint(v)) - 1
				t++
			} else if v%2 == 0 {
				x++
				t += v / 2
			} else {
				t += v
			}

			if v > m1 {
				m1, m2 = v, m1
			} else if v > m2 {
				m2 = v
			}

		}

		total := int64(m1)
		if m1 == 16 || m1 == 8 || m1 == 4 || m1 == 2 {
			total = int64(m2)
		}

		if total%2 == 0 {
			if bits.OnesCount(uint(total)) == 1 {
				x -= bits.Len(uint(total)) - 1
				t--
			} else {
				t -= int(total / 2)
				x--
			}
		} else {
			t -= int(total)
		}

		for i := 0; i < x; i++ {
			total *= 2
		}

		fmt.Fprintln(out, total+int64(t))
	}
}