During their training for the ICPC competitions, team "Jee You See" stumbled upon a very basic counting problem. After many "Wrong answer" verdicts, they finally decided to give up and destroy turn-off the PC. Now they want your help in up-solving the problem.You are given 4 integers $$$n$$$, $$$l$$$, $$$r$$$, and $$$z$$$. Count the number of arrays $$$a$$$ of length $$$n$$$ containing non-negative integers such that:  $$$l\le a_1+a_2+\ldots+a_n\le r$$$, and  $$$a_1\oplus a_2 \oplus \ldots\oplus a_n=z$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. Since the answer can be large, print it modulo $$$10^9+7$$$.

Print the number of arrays $$$a$$$ satisfying all requirements modulo $$$10^9+7$$$.

package main

import (
	"bufio"
	"fmt"
	"os"
	_ "runtime/pprof"
)

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO
var n int
var z int64
var C [][]int

const (
	maxn = 1024
	mod  = 1000000007
)

func mkarr(n, m, fill int) [][]int {
	a := make([][]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	p := a[0]
	p[0] = fill
	for i := 1; i < m; i *= 2 {
		copy(p[i:], p[:i])
	}
	for i := 1; i < n; i++ {
		copy(a[i], p)
	}
	return a
}

func dp_(n int, limit int64) int64 {
	inf := n * 2
	f := make([]int64, inf+1)
	g := make([]int64, inf+1)
	f[0] = 1
	for i := 61; i >= 0; i-- {
		for j := 0; j <= inf; j++ {
			g[j] = 0
		}
		for j := 0; j < inf; j++ {
			if f[j] > 0 {
				for one_bit := (int)((z >> i) & 1); one_bit <= n; one_bit += 2 {
					if j < one_bit {
						break
					}
					next := (j - one_bit) * 2
					if i > 0 {
						next += (int)(limit>>(i-1)) & 1
					}
					if next > inf {
						next = inf
					}
					g[next] = (g[next] + f[j]*(int64)(C[n][one_bit])) % mod
				}
			}
		}
		if f[inf] > 0 {
			for one_bit := (int)((z >> i) & 1); one_bit <= n; one_bit += 2 {
				g[inf] = (g[inf] + f[inf]*(int64)(C[n][one_bit])) % mod
			}
		}
		for j := 0; j <= inf; j++ {
			f[j] = g[j]
		}
	}
	var ans int64 = 0
	for j := 0; j <= inf; j++ {
		ans = (ans + f[j] + mod) % mod
	}
	return ans
}

func sol() {
	n = myio.ReadInt()
	l := myio.ReadInt64()
	r := myio.ReadInt64()
	z = myio.ReadInt64()
	C = mkarr(n+1, n+1, 0)
	for i := 0; i <= n; i++ {
		C[i][0] = 1
		C[i][i] = 1
	}
	for i := 2; i <= n; i++ {
		for j := 1; j < i; j++ {
			C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod
		}
	}

	myio.Println((dp_(n, r) - dp_(n, l-1) + mod) % mod)
}

func main() {

	// p, _ := os.Create("1.profile")
	// pprof.StartCPUProfile(p)
	// defer pprof.StopCPUProfile()

	// in, _ := os.Open("2.in")
	// out, _ := os.Create("2.out")
	// defer in.Close()
	// defer out.Close()
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()
	sol()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	_ "runtime/pprof"
)

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO
var n int
var z int64
var C, memo [][]int

const (
	maxn = 1024
	mod  = 1000000007
)

func mkarr(n, m, fill int) [][]int {
	a := make([][]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	p := a[0]
	p[0] = fill
	for i := 1; i < m; i *= 2 {
		copy(p[i:], p[:i])
	}
	for i := 1; i < n; i++ {
		copy(a[i], p)
	}
	return a
}

func getC(a, b int) int {
	if C[a][b] > 0 {
		return C[a][b]
	}
	if b == 0 || a == b {
		C[a][b] = 1
		return C[a][b]
	}
	C[a][b] = (getC(a-1, b-1) + getC(a-1, b)) % mod
	return C[a][b]
}

func dp(b, rem int, val int64) int {
	if rem > n*2 {
		rem = n * 2
	}
	if rem < 0 {
		return 0
	}
	if b == -1 {
		return 1
	}
	if memo[b][rem] != -1 {
		return memo[b][rem]
	}
	var ans int64 = 0
	var cb = (int)((z >> b) & 1)
	for i := cb; i <= n; i += 2 {
		cbs := (int)((val >> b) & 1)
		nextRem := 2 * (rem + cbs - i)
		toAdd := (int64)(C[n][i]) * (int64)(dp(b-1, nextRem, val)) % mod
		ans = ans + toAdd
	}
	memo[b][rem] = (int)(ans % mod)
	return memo[b][rem]
}

func sol() {
	n = myio.ReadInt()
	l := myio.ReadInt64()
	r := myio.ReadInt64()
	z = myio.ReadInt64()
	C = mkarr(n+1, n+1, 0)
	for i := 0; i <= n; i++ {
		C[i][0] = 1
		C[i][i] = 1
	}
	for i := 2; i <= n; i++ {
		for j := 1; j < i; j++ {
			C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod
		}
	}

	memo = mkarr(61, n*2+2, -1)
	ra := dp(60, 0, l-1)
	memo = mkarr(61, n*2+2, -1)
	rb := dp(60, 0, r)
	myio.Println((rb - ra + mod) % mod)
}

func main() {

	// p, _ := os.Create("1.profile")
	// pprof.StartCPUProfile(p)
	// defer pprof.StopCPUProfile()

	// in, _ := os.Open("1.in")
	// out, _ := os.Create("1.out")
	// defer in.Close()
	// defer out.Close()
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()
	sol()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	_ "runtime/pprof"
)

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO
var n int
var z int64
var C, memo [][]int

const (
	maxn = 1024
	mod  = 1000000007
)

func mkarr(n, m, fill int) [][]int {
	a := make([][]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	p := a[0]
	p[0] = fill
	for i := 1; i < m; i *= 2 {
		copy(p[i:], p[:i])
	}
	for i := 1; i < n; i++ {
		copy(a[i], p)
	}
	return a
}

func getC(a, b int) int {
	if C[a][b] > 0 {
		return C[a][b]
	}
	if b == 0 || a == b {
		C[a][b] = 1
		return C[a][b]
	}
	C[a][b] = (getC(a-1, b-1) + getC(a-1, b)) % mod
	return C[a][b]
}

func getCb(v int64, b int) int {
	if (v>>b)&1 == 0 {
		return 0
	}
	return 1
}

func dp(b, rem int, val int64) int {
	if rem > n*2 {
		rem = n * 2
	}
	if rem < 0 {
		return 0
	}
	if b == -1 {
		return 1
	}
	if memo[b][rem] != -1 {
		return memo[b][rem]
	}
	var ans int64 = 0
	var cb = getCb(z, b)
	for i := cb; i <= n; i += 2 {
		cbs := getCb(val, b)
		nextRem := 2 * (rem + cbs - i)
		toAdd := (int64)(C[n][i]) * (int64)(dp(b-1, nextRem, val)) % mod
		ans = ans + toAdd
	}
	memo[b][rem] = (int)(ans % mod)
	return memo[b][rem]
}

func sol() {
	n = myio.ReadInt()
	l := myio.ReadInt64()
	r := myio.ReadInt64()
	z = myio.ReadInt64()
	C = mkarr(n+1, n+1, 0)
	for i := 0; i <= n; i++ {
		C[i][0] = 1
		C[i][i] = 1
	}
	for i := 2; i <= n; i++ {
		for j := 1; j < i; j++ {
			C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod
		}
	}

	memo = mkarr(61, n*2+2, -1)
	ra := dp(60, 0, l-1)
	memo = mkarr(61, n*2+2, -1)
	rb := dp(60, 0, r)
	myio.Println((rb - ra + mod) % mod)
}

func main() {

	// p, _ := os.Create("1.profile")
	// pprof.StartCPUProfile(p)
	// defer pprof.StopCPUProfile()

	// in, _ := os.Open("1.in")
	// out, _ := os.Create("1.out")
	// defer in.Close()
	// defer out.Close()
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()
	sol()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	_ "runtime/pprof"
)

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO
var n int
var z int64
var C, memo [][]int

const (
	maxn = 1024
	mod  = 1000000007
)

func mkarr(n, m, fill int) [][]int {
	a := make([][]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	p := a[0]
	p[0] = fill
	for i := 1; i < m; i *= 2 {
		copy(p[i:], p[:i])
	}
	for i := 1; i < n; i++ {
		copy(a[i], p)
	}
	return a
}

func getC(a, b int) int {
	if C[a][b] > 0 {
		return C[a][b]
	}
	if b == 0 || a == b {
		C[a][b] = 1
		return C[a][b]
	}
	C[a][b] = (getC(a-1, b-1) + getC(a-1, b)) % mod
	return C[a][b]
}

func getCb(v int64, b int) int {
	if (v>>b)&1 == 0 {
		return 0
	}
	return 1
}

func dp(b, rem int, val int64) int {
	if rem > n*2 {
		rem = n * 2
	}
	if rem < 0 {
		return 0
	}
	if b == -1 {
		return 1
	}
	if memo[b][rem] != -1 {
		return memo[b][rem]
	}
	var ans int64 = 0
	var cb = getCb(z, b)
	for i := cb; i <= n; i += 2 {
		cbs := getCb(val, b)
		nextRem := 2 * (rem + cbs - i)
		toAdd := (int64)(C[n][i]) * (int64)(dp(b-1, nextRem, val))
		ans = (ans + toAdd) % mod
	}
	memo[b][rem] = (int)(ans)
	return memo[b][rem]
}

func sol() {
	n = myio.ReadInt()
	l := myio.ReadInt64()
	r := myio.ReadInt64()
	z = myio.ReadInt64()
	C = mkarr(n+1, n+1, 0)
	for i := 0; i <= n; i++ {
		C[i][0] = 1
		C[i][i] = 1
	}
	for i := 2; i <= n; i++ {
		for j := 1; j < i; j++ {
			C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod
		}
	}

	memo = mkarr(61, n*2+2, -1)
	ra := dp(60, 0, l-1)
	memo = mkarr(61, n*2+2, -1)
	rb := dp(60, 0, r)
	myio.Println((rb - ra + mod) % mod)
}

func main() {

	// p, _ := os.Create("1.profile")
	// pprof.StartCPUProfile(p)
	// defer pprof.StopCPUProfile()

	// in, _ := os.Open("1.in")
	// out, _ := os.Create("1.out")
	// defer in.Close()
	// defer out.Close()
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()
	sol()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	_ "runtime/pprof"
)

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO
var n int
var z int64
var C, memo [][]int

const (
	maxn = 1024
	mod  = 1000000007
)

func mkarr(n, m, fill int) [][]int {
	a := make([][]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	p := a[0]
	p[0] = fill
	for i := 1; i < m; i *= 2 {
		copy(p[i:], p[:i])
	}
	for i := 1; i < n; i++ {
		copy(a[i], p)
	}
	return a
}

func getC(a, b int) int {
	if C[a][b] > 0 {
		return C[a][b]
	}
	if b == 0 || a == b {
		C[a][b] = 1
		return C[a][b]
	}
	C[a][b] = (getC(a-1, b-1) + getC(a-1, b)) % mod
	return C[a][b]
}

func getCb(v int64, b int) int {
	if (v>>b)&1 == 0 {
		return 0
	}
	return 1
}

func dp(b, rem int, val int64) int {
	if rem > n*2 {
		rem = n * 2
	}
	if rem < 0 {
		return 0
	}
	if b == -1 {
		return 1
	}
	if memo[b][rem] != -1 {
		return memo[b][rem]
	}
	var ans int64 = 0
	var cb = getCb(z, b)
	for i := cb; i <= n; i += 2 {
		cbs := getCb(val, b)
		nextRem := 2 * (rem + cbs - i)
		toAdd := (int64)(C[n][i]) * (int64)(dp(b-1, nextRem, val)) % mod
		ans = (ans + toAdd) % mod
	}
	memo[b][rem] = (int)(ans)
	return memo[b][rem]
}

func sol() {
	n = myio.ReadInt()
	l := myio.ReadInt64()
	r := myio.ReadInt64()
	z = myio.ReadInt64()
	C = mkarr(n+1, n+1, 0)
	for i := 0; i <= n; i++ {
		C[i][0] = 1
		C[i][i] = 1
	}
	for i := 2; i <= n; i++ {
		for j := 1; j < i; j++ {
			C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod
		}
	}

	memo = mkarr(61, n*2+2, -1)
	ra := dp(60, 0, l-1)
	memo = mkarr(61, n*2+2, -1)
	rb := dp(60, 0, r)
	myio.Println((rb - ra + mod) % mod)
}

func main() {

	// p, _ := os.Create("1.profile")
	// pprof.StartCPUProfile(p)
	// defer pprof.StopCPUProfile()

	// in, _ := os.Open("1.in")
	// out, _ := os.Create("1.out")
	// defer in.Close()
	// defer out.Close()
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()
	sol()
}

package main

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

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO
var n int
var z int64
var C, memo [][]int

const (
	maxn = 1024
	mod  = 1000000007
)

func mkarr(n, m, fill int) [][]int {
	a := make([][]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	p := a[0]
	p[0] = fill
	for i := 1; i < m; i *= 2 {
		copy(p[i:], p[:i])
	}
	for i := 1; i < n; i++ {
		copy(a[i], p)
	}
	return a
}

func getC(a, b int) int {
	if C[a][b] > 0 {
		return C[a][b]
	}
	if b == 0 || a == b {
		C[a][b] = 1
		return C[a][b]
	}
	C[a][b] = (getC(a-1, b-1) + getC(a-1, b)) % mod
	return C[a][b]
}

func getCb(v int64, b int) int {
	if (v>>b)&1 == 0 {
		return 0
	}
	return 1
}

func dp(b, rem int, val int64) int {
	if rem > n*2 {
		rem = n * 2
	}
	if rem < 0 {
		return 0
	}
	if b == -1 {
		return 1
	}
	if memo[b][rem] != -1 {
		return memo[b][rem]
	}
	var ans int64 = 0
	var cb = getCb(z, b)
	for i := cb; i <= n; i += 2 {
		cbs := getCb(val, b)
		nextRem := 2 * (rem + cbs - i)
		toAdd := (int64)(getC(n, i)) * (int64)(dp(b-1, nextRem, val)) % mod
		ans = (ans + toAdd) % mod
	}
	memo[b][rem] = (int)(ans)
	return memo[b][rem]
}

func sol() {
	n = myio.ReadInt()
	l := myio.ReadInt64()
	r := myio.ReadInt64()
	z = myio.ReadInt64()
	C = mkarr(maxn, maxn, 0)

	memo = mkarr(61, n*2+2, -1)
	ra := dp(60, 0, l-1)
	memo = mkarr(61, n*2+2, -1)
	rb := dp(60, 0, r)
	myio.Println((rb - ra + mod) % mod)
}

func main() {
	myio = NewIO(os.Stdin, os.Stdout)
	defer myio.Flush()
	sol()
}

package main

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

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO
var n int
var z int64
var C, memo [][]int

const (
	maxn = 1024
	mod  = 1000000007
)

func mkarr(n, m, fill int) [][]int {
	a := make([][]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	for j := 0; j < m; j++ {
		a[0][j] = fill
	}
	for i := 1; i < n; i++ {
		copy(a[i], a[0])
	}
	return a
}

func getC(a, b int) int {
	if C[a][b] > 0 {
		return C[a][b]
	}
	if b == 0 || a == b {
		C[a][b] = 1
		return C[a][b]
	}
	C[a][b] = (getC(a-1, b-1) + getC(a-1, b)) % mod
	return C[a][b]
}

func getCb(v int64, b int) int {
	if (v>>b)&1 == 0 {
		return 0
	}
	return 1
}

func dp(b, rem int, val int64) int {
	if rem > n*2 {
		rem = n * 2
	}
	if rem < 0 {
		return 0
	}
	if b == -1 {
		return 1
	}
	if memo[b][rem] != -1 {
		return memo[b][rem]
	}
	var ans int64 = 0
	var cb = getCb(z, b)
	for i := cb; i <= n; i += 2 {
		cbs := getCb(val, b)
		nextRem := 2 * (rem + cbs - i)
		toAdd := (int64)(getC(n, i)) * (int64)(dp(b-1, nextRem, val)) % mod
		ans = (ans + toAdd) % mod
	}
	memo[b][rem] = (int)(ans)
	return memo[b][rem]
}

func sol() {
	n = myio.ReadInt()
	l := myio.ReadInt64()
	r := myio.ReadInt64()
	z = myio.ReadInt64()
	C = mkarr(maxn, maxn, 0)

	memo = mkarr(61, n*2+2, -1)
	ra := dp(60, 0, l-1)
	memo = mkarr(61, n*2+2, -1)
	rb := dp(60, 0, r)
	myio.Println((rb - ra + mod) % mod)
}

func main() {
	myio = NewIO(os.Stdin, os.Stdout)
	defer myio.Flush()
	sol()
}

package main

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

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO
var n int
var z int64
var C, memo [][]int

const (
	maxn = 1024
	mod  = 1000000007
)

func mkarr(n, m, fill int) [][]int {
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			a[i][j] = fill
		}
	}
	return a
}

func getC(a, b int) int {
	if C[a][b] > 0 {
		return C[a][b]
	}
	if b == 0 || a == b {
		C[a][b] = 1
		return C[a][b]
	}
	C[a][b] = (getC(a-1, b-1) + getC(a-1, b)) % mod
	// fmt.Println(a, b, C[a][b])
	return C[a][b]
}

func getCb(v int64, b int) int {
	if (v>>b)&1 == 0 {
		return 0
	}
	return 1
}

func dp(b, rem int, val int64) int {
	if rem > n*2 {
		rem = n * 2
	}
	if rem < 0 {
		return 0
	}
	if b == -1 {
		return 1
	}
	if memo[b][rem] != -1 {
		return memo[b][rem]
	}
	var ans int64 = 0
	var cb = getCb(z, b)
	for i := cb; i <= n; i += 2 {
		cbs := getCb(val, b)
		nextRem := 2 * (rem + cbs - i)
		toAdd := (int64)(getC(n, i)) * (int64)(dp(b-1, nextRem, val)) % mod
		ans = (ans + toAdd) % mod
	}
	memo[b][rem] = (int)(ans)
	return memo[b][rem]
}

func sol() {
	n = myio.ReadInt()
	l := myio.ReadInt64()
	r := myio.ReadInt64()
	z = myio.ReadInt64()
	C = mkarr(maxn, maxn, 0)

	memo = mkarr(61, n*2+2, -1)
	ra := dp(60, 0, l-1)
	memo = mkarr(61, n*2+2, -1)
	rb := dp(60, 0, r)
	// fmt.Println(ra, rb)
	myio.Println((rb - ra + mod) % mod)
}

func main() {
	myio = NewIO(os.Stdin, os.Stdout)
	defer myio.Flush()
	sol()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi64() int64 { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func powmod64(a,e,mod int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func makefact64(n int64,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=int64(1);i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod64(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
const MOD int64 = 1000000007
type st struct {idx,v int64}
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N,L,R,Z := gi64(),gi64(),gi64(),gi64()
	fact,factinv := makefact64(N+10,MOD)
	combarr := make([]int64,N+1)
	for i:=int64(0);i<=N;i++ { combarr[i] = fact[N] * factinv[i] % MOD * factinv[N-i] % MOD  }
	var dp [61][2002]int64
	var bitdp func(idx int64, rem int64, val int64) int64
	bitdp = func(idx int64, rem int64, val int64) int64 {
		if rem > 2*N { rem = 2*N }
		if rem < 0 { return 0 }
		if idx < 0 { return 1 }
		if dp[idx][rem] != -1 { return dp[idx][rem] }
		ans := int64(0); st := int64(0); if Z & (int64(1) << uint64(idx)) != 0 { st++ }
		for i:=st;i<=N;i+=2 {
			cbs := int64(0); if val & (int64(1) << uint64(idx)) != 0 { cbs++ }
			adder := combarr[i] * bitdp(idx-1, 2*(rem+cbs-i), val) % MOD
			ans += adder; ans %= MOD
		}
		//fmt.Printf("DBG: bitdp(%v,%v,%v)=%v\n",idx,rem,val,ans)
		dp[idx][rem] = ans
		return ans
	}
	calc := func(ubound int64) int64 {
		for i:=0;i<=60;i++ { for j:=int64(0);j<=2*N;j++ { dp[i][j] = -1 } }
		return bitdp(60,0,ubound)
	}
	ans := (calc(R)+MOD-calc(L-1)) % MOD
	fmt.Println(ans)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	_ "runtime/pprof"
)

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO
var n int
var z int64
var C, memo [][]int

const (
	maxn = 1024
	mod  = 1000000007
)

func mkarr(n, m, fill int) [][]int {
	a := make([][]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	p := a[0]
	p[0] = fill
	for i := 1; i < m; i *= 2 {
		copy(p[i:], p[:i])
	}
	for i := 1; i < n; i++ {
		copy(a[i], p)
	}
	return a
}

func getC(a, b int) int {
	if C[a][b] > 0 {
		return C[a][b]
	}
	if b == 0 || a == b {
		C[a][b] = 1
		return C[a][b]
	}
	C[a][b] = (getC(a-1, b-1) + getC(a-1, b)) % mod
	return C[a][b]
}

func getCb(v int64, b int) int {
	if (v>>b)&1 == 0 {
		return 0
	}
	return 1
}

func dp(b, rem int, val int64) int {
	if rem > n*2 {
		rem = n * 2
	}
	if rem < 0 {
		return 0
	}
	if b == -1 {
		return 1
	}
	if memo[b][rem] != -1 {
		return memo[b][rem]
	}
	var ans int64 = 0
	var cb = getCb(z, b)
	for i := cb; i <= n; i += 2 {
		cbs := getCb(val, b)
		nextRem := 2 * (rem + cbs - i)
		toAdd := (int64)(C[n][i]) * (int64)(dp(b-1, nextRem, val))
		ans = ans + toAdd
	}
	memo[b][rem] = (int)(ans % mod)
	return memo[b][rem]
}

func sol() {
	n = myio.ReadInt()
	l := myio.ReadInt64()
	r := myio.ReadInt64()
	z = myio.ReadInt64()
	C = mkarr(n+1, n+1, 0)
	for i := 0; i <= n; i++ {
		C[i][0] = 1
		C[i][i] = 1
	}
	for i := 2; i <= n; i++ {
		for j := 1; j < i; j++ {
			C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod
		}
	}

	memo = mkarr(61, n*2+2, -1)
	ra := dp(60, 0, l-1)
	memo = mkarr(61, n*2+2, -1)
	rb := dp(60, 0, r)
	myio.Println((rb - ra + mod) % mod)
}

func main() {

	// p, _ := os.Create("1.profile")
	// pprof.StartCPUProfile(p)
	// defer pprof.StopCPUProfile()

	// in, _ := os.Open("1.in")
	// out, _ := os.Create("1.out")
	// defer in.Close()
	// defer out.Close()
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()
	sol()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	_ "runtime/pprof"
)

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO
var n int
var z int64
var C, memo [][]int

const (
	maxn = 1024
	mod  = 1000000007
)

func mkarr(n, m, fill int) [][]int {
	a := make([][]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	p := a[0]
	p[0] = fill
	for i := 1; i < m; i *= 2 {
		copy(p[i:], p[:i])
	}
	for i := 1; i < n; i++ {
		copy(a[i], p)
	}
	return a
}

func getC(a, b int) int {
	if C[a][b] > 0 {
		return C[a][b]
	}
	if b == 0 || a == b {
		C[a][b] = 1
		return C[a][b]
	}
	C[a][b] = (getC(a-1, b-1) + getC(a-1, b)) % mod
	return C[a][b]
}

func getCb(v int64, b int) int {
	if (v>>b)&1 == 0 {
		return 0
	}
	return 1
}

func dp(b, rem int, val int64) int {
	if rem > n*2 {
		rem = n * 2
	}
	if rem < 0 {
		return 0
	}
	if b == -1 {
		return 1
	}
	if memo[b][rem] != -1 {
		return memo[b][rem]
	}
	var ans int64 = 0
	var cb = getCb(z, b)
	for i := cb; i <= n; i += 2 {
		cbs := getCb(val, b)
		nextRem := 2 * (rem + cbs - i)
		toAdd := (int64)(C[n][i]) * (int64)(dp(b-1, nextRem, val)) % mod
		ans = (ans + toAdd) % mod
	}
	memo[b][rem] = (int)(ans)
	return memo[b][rem]
}

func sol() {
	n = myio.ReadInt()
	l := myio.ReadInt64()
	r := myio.ReadInt64()
	z = myio.ReadInt64()
	C = mkarr(n+1, n+1, 0)
	for i := 0; i <= n; i++ {
		C[i][0] = 1
		C[i][i] = 1
	}
	for i := 2; i <= n; i++ {
		for j := 2; j < i; j++ {
			C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod
		}
	}

	memo = mkarr(61, n*2+2, -1)
	ra := dp(60, 0, l-1)
	memo = mkarr(61, n*2+2, -1)
	rb := dp(60, 0, r)
	myio.Println((rb - ra + mod) % mod)
}

func main() {

	myio = NewIO(os.Stdin, os.Stdout)
	defer myio.Flush()
	sol()
}


Sam lives in Awesomeburg, its downtown has a triangular shape. Also, the following is true about the triangle:  its vertices have integer coordinates,  the coordinates of vertices are non-negative, and  its vertices are not on a single line. He calls a point on the downtown's border (that is the border of the triangle) safe if he can reach this point from at least one point of the line $$$y = 0$$$ walking along some straight line, without crossing the interior of the triangle.  In the picture the downtown is marked with grey color. The first path is invalid because it does not go along a straight line. The second path is invalid because it intersects with the interior of the downtown. The third and fourth paths are correct. Find the total length of the unsafe parts of the downtown border. It can be proven that these parts are segments and their number is finite.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Description of the test cases follows. Each test case contains three lines, each of them contains two integers $$$x_i$$$, $$$y_i$$$ ($$$0 \le x_i, y_i \le 10^9$$$) — coordinates of the vertices of the downtown's border.

For each test case print a single number — the answer to the problem. Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{-9}$$$. Formally let your answer be $$$a$$$, jury answer be $$$b$$$. Your answer will be considered correct if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-9}$$$.

NoteIn the picture, the downtowns of the first three test cases are illustrated. Triangles are enumerated according to the indices of test cases they belong to.  In the first two test cases, all points on the borders of the downtowns are safe, thus the answers are $$$0$$$.In the following picture unsafe points for the third test case are marked with black color:  In the fourth test case, all points on the border of the downtown are safe.

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	type pair struct { x, y int }
	p := make([]pair, 3)
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		for i := 0; i < 3; i++ {
			Fscan(r, &p[i].x, &p[i].y)
		}
		sort.Slice(p, func(i, j int) bool {
			if p[i].y == p[j].y {
				return p[i].x < p[j].x
			}
			return p[i].y < p[j].y
		})
		if p[1].y == p[2].y && p[0].y != p[1].y {
			Fprintln(w, p[2].x - p[1].x)
		} else {
			Fprintln(w, 0)
		}
	}
}

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

// To correct later, do not forget that the flat part of the triangle can be at its bottom and not necessarily only on the top so slighty more treatment is required

package main

import (
	"fmt"
	"math"
)

func main() {
	t := 0
	fmt.Scan(&t)
	out := ""
	for i := 0; i < t; i++ {
		xs := make([]int, 3)
		ys := make([]int, 3)
		for j := 0; j < 3; j++ {
			fmt.Scan(&xs[j], &ys[j])
		}
		out = out + fmt.Sprintln(solve(xs, ys))
	}
	fmt.Println(out)
}

func solve(xs, ys []int) float64 {
	index1, index2 := duplicatesArray(ys)
	if index1 == -1 {
		return 0.0
	}
	return math.Sqrt(math.Pow(float64(xs[index1]-xs[index2]), 2) - math.Pow(float64(ys[index1]-ys[index2]), 2))
}

func duplicatesArray(arr []int) (index1, index2 int) {
	visited := make(map[int]bool, 0)
	for i, v := range arr {
		if visited[v] && v != 0 {
			pos := pos(arr, v)
			if v == min(arr) {
				return -1, -1
			} else {
				return i, pos
			}
		} else {
			visited[v] = true
		}
	}
	return -1, -1
}

func pos(arr []int, value int) int {
	for k, v := range arr {
		if v == value {
			return k
		}
	}
	return -1
}

func min(array []int) int {
	var min int = array[0]
	for _, value := range array {
		if min > value {
			min = value
		}
	}
	return min
}

package main

import (
	"fmt"
)

func abs(z int64) int64 {
	if z < 0 {
		return -z
	}
	return z
}

func main() {
	var t, i, ax, ay, bx, by, cx, cy int64
	fmt.Scanln(&t)
	var length int64
	for i = 0; i < t; i++ {
		length = 0
		fmt.Scanln(&ax, &ay)
		fmt.Scanln(&bx, &by)
		fmt.Scanln(&cx, &cy)

		if ay == by && ay != 0 && ay > cy {
			length = abs(ax - bx)
		}
		if cy == by && cy != 0 && cy > ay {
			length = abs(cx - bx)
		}
		if ay == cy && ay != 0 && ay > by {
			length = abs(cx - ax)
		}

		fmt.Println(length)
	}

}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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 ax, ay, bx, by, cx, cy int
		fmt.Fscan(in, &ax, &ay, &bx, &by, &cx, &cy)

		if ay == by && cy < ay {
			fmt.Fprintln(out, abs(ax-bx))
		} else if ay == cy && by < ay {
			fmt.Fprintln(out, abs(ax-cx))
		} else if by == cy && ay < by {
			fmt.Fprintln(out, abs(bx-cx))
		} else {
			fmt.Fprintln(out, 0)
		}
	}

}

package main

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

/*
2
1 1
3 1
2 2
1 2
3 1
3 2
---
0
2
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var x1, y1, x2, y2, x3, y3 int
	scanf("%d %d\n%d %d\n%d %d\n", &x1, &y1, &x2, &y2, &x3, &y3)

	if y1 == y2 && y1 != 0 && y3 < y1 {
		fmt.Fprintln(writer, abs(x1-x2))
	} else if y1 == y3 && y1 != 0 && y2 < y1 {
		fmt.Fprintln(writer, abs(x1-x3))
	} else if y2 == y3 && y2 != 0 && y1 < y2 {
		fmt.Fprintln(writer, abs(x2-x3))
	} else {
		fmt.Fprintln(writer, 0)
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return nums[idx], idx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1642A
Date: 9/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1642/A
Problem: CF1642A
**/
func (in *CF1642A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		m := make([][]float64, 3)
		m[0] = []float64{
			float64(in.NextInt()), float64(in.NextInt()),
		}
		m[1] = []float64{
			float64(in.NextInt()), float64(in.NextInt()),
		}
		m[2] = []float64{
			float64(in.NextInt()), float64(in.NextInt()),
		}
		ans := 0.0

		if m[0][1] == m[1][1] && m[0][1] > m[2][1] {
			ans = math.Abs(m[0][0] - m[1][0])
		} else if m[0][1] == m[2][1] && m[0][1] > m[1][1] {
			ans = math.Abs(m[0][0] - m[2][0])
		} else if m[1][1] == m[2][1] && m[1][1] > m[0][1] {
			ans = math.Abs(m[1][0] - m[2][0])
		}

		fmt.Printf("%f\n", ans)
	}
}

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

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

package main

import (
	"fmt"
	"math"
)

func main() {
	t := 0
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var a, b, c, d, e, f float64

		fmt.Scan(&b, &a, &d, &c, &f, &e)

		var ans float64

		if a == c && e < a {
			ans = math.Abs(b - d)
		} else if c == e && a < c {
			ans = math.Abs(d - f)
		} else if a == e && c < a {
			ans = math.Abs(b - f)
		}

		fmt.Println(ans)
	}
}

//nolint
package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

//}

func Solve() {
	var p1, p2, p3 Point
	scanPoint(&p1)
	scanPoint(&p2)
	scanPoint(&p3)
	println(check(&p1, &p2, &p3) + check(&p2, &p3, &p1) + check(&p1, &p3, &p2))
}

type Point struct {
	x, y float64
}

func scanPoint(p *Point) {
	scan(&p.x)
	scan(&p.y)
}

func check(p1, p2, p3 *Point) float64 {
	if p1.y == p2.y && p3.y < p1.y {
		return math.Abs(p1.x - p2.x)
	}
	return 0
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func Test_Case(){
	var a,b,c,d,e,f int64

	scanf("%d %d\n", &a, &b)
	scanf("%d %d\n", &c, &d)
	scanf("%d %d\n", &e, &f)
	var ans float64
	if b == d && f < b {
		ans = math.Abs(float64(a-c))
	} else if f == d && b < d {
		ans = math.Abs(float64(e-c))
	} else if b == f && d < b {
		ans = math.Abs(float64(a-e))
	}
	printf("%f\n", ans)
}

func main(){

 	defer writer.Flush()

	var t int64
	scanf("%d\n", &t)
	for t > 0 {
		Test_Case()
		t = t-1
	}
}

package main

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

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

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
}

func main() {
	defer out.Flush()

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var ax, ay, bx, by, cx, cy int
		fmt.Fscan(in, &ax, &ay, &bx, &by, &cx, &cy)
		maxy := max(ay, max(by, cy))
		var minx, maxx int = 1e9, 0
		if ay == maxy {
			minx = min(minx, ax)
			maxx = max(maxx, ax)
		}
		if by == maxy {
			minx = min(minx, bx)
			maxx = max(maxx, bx)
		}
		if cy == maxy {
			minx = min(minx, cx)
			maxx = max(maxx, cx)
		}
		fmt.Fprintln(out, maxx-minx)
	}
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	x, y := make([]int, 3), make([]int, 3)
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		for i := 0; i < 3; i++ {
			Fscan(r, &x[i], &y[i])
		}
		if y[0] != y[1] && y[1] != y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] && y[1] == y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] && y[1] != y[2] {
			if y[2] < y[0] && x[0] != x[1] {
				Fprintf(w, "%d\n", abs((x[0])-(x[1])))
			} else {
				Fprintln(w, 0)
			}
		} else if y[1] == y[2] && y[2] != y[0] {
			if y[0] < y[1] {
				Fprintf(w, "%d\n", abs((x[1])-(x[2])))
			} else {
				Fprintln(w, 0)
			}
		} else if y[2] == y[0] && y[0] != y[1] {
			if y[1] < y[2] {
				Fprintf(w, "%d\n", abs((x[2])-(x[0])))
			} else {
				Fprintln(w, 0)
			}
		}
	}
}

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

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	x, y := make([]int, 3), make([]int, 3)
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		for i := 0; i < 3; i++ {
			Fscan(r, &x[i], &y[i])
		}
		if y[0] != y[1] && y[1] != y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] && y[1] == y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] {
			if y[2] < y[0] {
				Fprintf(w, "%f\n", abs(float64(x[0])-float64(x[1])))
			} else {
				Fprintln(w, 0)
			}
		} else  if y[1] == y[2] {
			if y[0] < y[1] {
				Fprintf(w, "%f\n", abs(float64(x[1])-float64(x[2])))
			} else {
				Fprintln(w, 0)
			}
		} else if y[2] == y[0]  {
			if y[1] < y[2] {
				Fprintf(w, "%f\n", abs(float64(x[2])-float64(x[0])))
			} else {
				Fprintln(w, 0)
			}
		}
	}
}

func abs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	x, y := make([]float64, 3), make([]float64, 3)
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		for i := 0; i < 3; i++ {
			Fscan(r, &x[i], &y[i])
		}
		if y[0] != y[1] && y[1] != y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] && y[1] == y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] {
			if y[2] < y[0] {
				Fprintf(w, "%f\n", abs(x[0]-x[1]))
			} else {
				Fprintln(w, 0)
			}
		} else  if y[1] == y[2] {
			if y[0] < y[1] {
				Fprintf(w, "%f\n", abs(x[1]-x[2]))
			} else {
				Fprintln(w, 0)
			}
		} else if y[2] == y[0]  {
			if y[1] < y[2] {
				Fprintf(w, "%f\n", abs(x[2]-x[0]))
			} else {
				Fprintln(w, 0)
			}
		}
	}
}

func abs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	x, y := make([]float64, 3), make([]float64, 3)
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		for i := 0; i < 3; i++ {
			Fscan(r, &x[i], &y[i])
		}
		if y[0] != y[1] && y[1] != y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] && y[1] == y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] {
			if y[2] < y[0] {
				Fprintf(w, "%f\n", abs(x[0]-x[1]))
			} else {
				Fprintln(w, 0)
			}
		} else  if y[1] == y[2] {
			if y[0] < y[1] {
				Fprintf(w, "%f\n", abs(x[1]-x[2]))
			} else {
				Fprintln(w, 0)
			}
		} else if y[2] == y[3]  {
			if y[1] < y[2] {
				Fprintf(w, "%f\n", abs(x[2]-x[3]))
			} else {
				Fprintln(w, 0)
			}
		}
	}
}

func abs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	x, y := make([]float64, 3), make([]float64, 3)
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		for i := 0; i < 3; i++ {
			Fscan(r, &x[i], &y[i])
		}
		if y[0] != y[1] && y[1] != y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] && y[1] == y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] {
			if y[2] < y[0] {
				Fprintf(w, "%f\n", abs(x[0]-x[1]))
			} else {
				Fprintln(w, 0)
			}
		} else  if y[1] == y[2] {
			if y[0] < y[1] {
				Fprintf(w, "%f\n", abs(x[1]-x[2]))
			} else {
				Fprintln(w, 0)
			}

		}
	}
}

func abs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	x, y := make([]float64, 3), make([]float64, 3)
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		for i := 0; i < 3; i++ {
			Fscan(r, &x[i], &y[i])
		}
		if y[0] != y[1] && y[1] != y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] && y[1] == y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] {
			if y[2] < y[0] {
				Fprintf(w, "%.12f\n", abs(x[0]-x[1]))
			} else {
				Fprintln(w, 0)
			}
		} else  if y[1] == y[2] {
			if y[0] < y[1] {
				Fprintf(w, "%.12f\n", abs(x[1]-x[2]))
			} else {
				Fprintln(w, 0)
			}

		}
	}
}

func abs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	x, y := make([]float64, 3), make([]float64, 3)
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		for i := 0; i < 3; i++ {
			Fscan(r, &x[i], &y[i])
		}
		if y[0] != y[1] && y[1] != y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] && y[1] == y[2] {
			Fprintln(w, 0)
			continue
		} else if y[0] == y[1] {
			if y[2] < y[0] {
				Fprintf(w, "%12.f\n", abs(x[0]-x[1]))
			} else {
				Fprintln(w, 0)
			}
		} else  if y[1] == y[2] {
			if y[0] < y[1] {
				Fprintf(w, "%12.f\n", abs(x[1]-x[2]))
			} else {
				Fprintln(w, 0)
			}

		}
	}
}

func abs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

package main

import (
	"fmt"
	"math"
)

func main() {
	t := 0
	fmt.Scan(&t)
	out := ""
	for i := 0; i < t; i++ {
		xs := make([]int, 3)
		ys := make([]int, 3)
		for j := 0; j < 3; j++ {
			fmt.Scan(&xs[j], &ys[j])
		}
		out = out + fmt.Sprintln(solve(xs, ys))
	}
	fmt.Println(out)
}

func solve(xs, ys []int) float64 {
	index1, index2 := duplicatesArray(ys)
	if index1 == -1 {
		return 0.0
	}
	return math.Sqrt(math.Pow(float64(xs[index1]-xs[index2]), 2) - math.Pow(float64(ys[index1]-ys[index2]), 2))
}

func duplicatesArray(arr []int) (index1, index2 int) {
	visited := make(map[int]bool, 0)
	for i, v := range arr {
		if visited[v] && v != 0 {
			pos := pos(arr, v)
			return i, pos
		} else {
			visited[v] = true
		}
	}
	return -1, -1
}

func pos(arr []int, value int) int {
	for k, v := range arr {
		if v == value {
			return k
		}
	}
	return -1
}

package main

import (
	"fmt"
	"math"
)

func main() {
	t := 0
	fmt.Scan(&t)
	out := ""
	for i := 0; i < t; i++ {
		xs := make([]int, 3)
		ys := make([]int, 3)
		for j := 0; j < 3; j++ {
			fmt.Scan(&xs[j], &ys[j])
		}
		out = out + fmt.Sprintln(solve(xs, ys))
	}
	fmt.Println(out)
}

func solve(xs, ys []int) float64 {
	index1, index2 := duplicatesArray(ys)
	if index1 == -1 {
		fmt.Println(0)
		return 0.0
	}
	return math.Sqrt(math.Pow(float64(xs[index1]-xs[index2]), 2) - math.Pow(float64(ys[index1]-ys[index2]), 2))
}

func duplicatesArray(arr []int) (index1, index2 int) {
	visited := make(map[int]bool, 0)
	for i, v := range arr {
		if visited[v] {
			return i, pos(arr, v)
		} else {
			visited[v] = true
		}
	}
	return -1, -1
}

func pos(arr []int, value int) int {
	for k, v := range arr {
		if v == value {
			return k
		}
	}
	return -1
}

package main

import (
	"fmt"
)

func abs(z int64) int64 {
	if z < 0 {
		return -z
	}
	return z
}

func main() {
	var t, i, ax, ay, bx, by, cx, cy int64
	fmt.Scanln(&t)
	var length int64
	for i = 0; i < t; i++ {
		length = 0
		fmt.Scanln(&ax, &ay)
		fmt.Scanln(&bx, &by)
		fmt.Scanln(&cx, &cy)

		if ay == by && ay != 0 && ay > cy {
			length = abs(ax - bx)
		}
		if cy == by && cy != 0 && cy > ay {
			length = abs(cx - bx)
		}
		if ay == cy && ay != 0 && ay > by {
			length = abs(cx - bx)
		}

		fmt.Println(length)
	}

}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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 ax, ay, bx, by, cx, cy int
		fmt.Fscan(in, &ax, &ay, &bx, &by, &cx, &cy)

		if ay == by && ay != 0 && by != 0 {
			fmt.Fprintln(out, abs(ax-bx))
		} else if ay == cy && ay != 0 && cy != 0 {
			fmt.Fprintln(out, abs(ax-cx))
		} else if by == cy && by != 0 && cy != 0 {
			fmt.Fprintln(out, abs(bx-cx))
		} else {
			fmt.Fprintln(out, 0)
		}
	}

}

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var x1, y1, x2, y2, x3, y3 int
	scanf("%d %d\n%d %d\n%d %d\n", &x1, &y1, &x2, &y2, &x3, &y3)

	if y1 == y2 && y1 != 0 {
		fmt.Fprintln(writer, abs(x1-x2))
	} else if y1 == y3 && y1 != 0 {
		fmt.Fprintln(writer, abs(x1-x3))
	} else if y2 == y3 && y2 != 0 {
		fmt.Fprintln(writer, abs(x2-x3))
	} else {
		fmt.Fprintln(writer, 0)
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return nums[idx], idx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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


The new camp by widely-known over the country Spring Programming Camp is going to start soon. Hence, all the team of friendly curators and teachers started composing the camp's schedule. After some continuous discussion, they came up with a schedule $$$s$$$, which can be represented as a binary string, in which the $$$i$$$-th symbol is '1' if students will write the contest in the $$$i$$$-th day and '0' if they will have a day off.At the last moment Gleb said that the camp will be the most productive if it runs with the schedule $$$t$$$ (which can be described in the same format as schedule $$$s$$$). Since the number of days in the current may be different from number of days in schedule $$$t$$$, Gleb required that the camp's schedule must be altered so that the number of occurrences of $$$t$$$ in it as a substring is maximum possible. At the same time, the number of contest days and days off shouldn't change, only their order may change.Could you rearrange the schedule in the best possible way?

The first line contains string $$$s$$$ ($$$1 \leqslant |s| \leqslant 500\,000$$$), denoting the current project of the camp's schedule. The second line contains string $$$t$$$ ($$$1 \leqslant |t| \leqslant 500\,000$$$), denoting the optimal schedule according to Gleb. Strings $$$s$$$ and $$$t$$$ contain characters '0' and '1' only.

In the only line print the schedule having the largest number of substrings equal to $$$t$$$. Printed schedule should consist of characters '0' and '1' only and the number of zeros should be equal to the number of zeros in $$$s$$$ and the number of ones should be equal to the number of ones in $$$s$$$. In case there multiple optimal schedules, print any of them.

NoteIn the first example there are two occurrences, one starting from first position and one starting from fourth position.In the second example there is only one occurrence, which starts from third position. Note, that the answer is not unique. For example, if we move the first day (which is a day off) to the last position, the number of occurrences of $$$t$$$ wouldn't change.In the third example it's impossible to make even a single occurrence.

package main

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

var (
	base      = uint64(31)
	maxN      = 500000 + 10
	mod       = uint64(1e9 + 7)
	hashed    = make([]uint64, maxN)
	powerBase = make([]uint64, maxN)
)

func solve(s string, t string) string {
	res := make([]byte, len(s))
	count := map[byte]int{}
	id := 0
	lengthPattern := len(t)

	for i := range s {
		count[s[i]]++
	}

	//find the logest suffix == prefix
	for i := 0; i < len(t)-1; i++ {
		if hashed[i] == getHash(len(t)-1-i, len(t)-1) {
			lengthPattern = len(t) - (i + 1)
			//exp: 11011
			//pre 11 = suf 11
			//=> lengthPattern is 3 : 110
		}
	}

	for i := range res {
		id = i % lengthPattern
		if count[t[id]] != 0 {
			res[i] = t[id]
			count[t[id]]--
			continue
		}
		if t[id] == '1' {
			res[i] = '0'
		} else {
			res[i] = '1'
		}
	}

	return string(res)
}

func getHash(start int, end int) uint64 {
	return (hashed[end] - hashed[start-1]*powerBase[end-start+1] + mod*mod) % mod
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func initHash(t string, n int) {
	hashed[0] = uint64(t[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(t[i])) % mod
	}
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var s, t string
	initPowerBase()
	fmt.Fscanf(r, "%s\n", &s)
	fmt.Fscanf(r, "%s\n", &t)
	initHash(t, len(t))
	fmt.Println(solve(s, t))
}

package main

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

var (
	base      = uint64(31)
	maxN      = 500000 + 10
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = []uint64{}
)

func solve(s string, t string, n int) string {
	res := make([]byte, len(s))
	count := map[byte]int{}
	lengthPattern, id := n, 0

	for i := range s {
		count[s[i]]++
	}

	//find the logest suffix == prefix
	for i := 0; i < n-1; i++ {
		if hashed[i] == getHash(n-1-i, n-1) {
			lengthPattern = n - (i + 1)
			//exp: 11011
			//pre 11 = suf 11
			//=> lengthPattern is 3 : 110
		}
	}

	for i := range res {
		id = i % lengthPattern
		if count[t[id]] != 0 {
			res[i] = t[id]
			count[t[id]]--
			continue
		}
		if t[id] == '1' {
			res[i] = '0'
		} else {
			res[i] = '1'
		}
	}

	return string(res)
}

func getHash(start int, end int) uint64 {
	return (hashed[end] - hashed[start-1]*powerBase[end-start+1] + mod*mod) % mod
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func initHash(t string, n int) {
	hashed = make([]uint64, n)
	hashed[0] = uint64(t[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(t[i])) % mod
	}
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var s, t string
	initPowerBase()
	fmt.Fscanf(r, "%s\n", &s)
	fmt.Fscanf(r, "%s\n", &t)
	initHash(t, len(t))
	fmt.Println(solve(s, t, len(t)))
}

package main

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

func kmp(str []byte, l int) []int {
	next := make([]int, l)
	next[0] = -1
	for i := 1; i < l; i++ {
		f := next[i-1]
		for f>=0&&str[f+1] != str[i]{
			f = next[f]
		}
		next[i] = -1
		if str[f+1]==str[i]{
			next[i] = f+1
		}
	}
	//fmt.Printf("%v\n", next)
	return next
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var str1,str2 string
	b := new(bytes.Buffer)
	fmt.Fscanf(buf, "%s\n", &str1)
	fmt.Fscanf(buf, "%s\n", &str2)

	s1 := []byte(str1)
	s2 := []byte(str2)

	len1 := len(s1)
	len2 := len(s2)
	cnt1 := 0
	cnt2 := 0
	for _, c := range s1 {
		if c == '1' {
			cnt1++
		}
	}
	for _, c := range s2 {
		if c == '1' {
			cnt2++
		}
	}
	if len1 < len2 || cnt2 > cnt1 || len2-cnt2 > len1-cnt1 {
		fmt.Printf("%s\n", str1)
		return
	}
	next := kmp(s2, len2)
	seg1 := 0
	seg0 := 0
	for i := next[len2-1] + 1; i < len2; i++ {
		if s2[i] == '1' {
			seg1++
		} else {
			seg0++
		}
	}
	len1 -= len2
	cnt1 -= cnt2
	cnt2 = -1
	if seg1 > 0 {
		cnt2 = cnt1 / seg1
	}
	if seg0 > 0 && (cnt2 == -1 || cnt2 > (len1-cnt1)/seg0) {
		cnt2 = (len1 - cnt1) / seg0
	}
	b.WriteString(str2)
//	fmt.Printf("%s", str2)
	tmp := s2[next[len2-1]+1:]
	for j := 0; j < cnt2; j++ {
		b.Write(tmp)
		//fmt.Printf("%s",tmp)
		//for i := next[len2-1] + 1; i < len2; i++ {
		//	fmt.Printf("%c", s2[i])
		//}
	}
	//c0 := make([]byte, (len1-cnt1)-cnt2*seg0)
	if (len1-cnt1)-cnt2*seg0 > 0 {
		for i := 0; i < (len1-cnt1)-cnt2*seg0; i++ {
			//c0[i] = '0'
			b.WriteByte('0')
		}
		//fmt.Printf("%s", c0)
	}
	//c1 := make([]byte, (cnt1)-cnt2*seg1)
	if (cnt1)-cnt2*seg1 > 0 {

		for i := 0; i < (cnt1)-cnt2*seg1; i++ {
			b.WriteByte('1')
			//c1[i] = '1'
		}
		//fmt.Printf("%s", c1)
	}
	fmt.Printf("%s\n",b.String())
}

/**
01010101
0101010
 */

package main

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

func solve(s string, t string) string {
	res := make([]byte, len(s))
	count := map[byte]int{}
	id := 0

	for i := range s {
		count[s[i]]++
	}

	for i := range res {
		id = i % len(t)
		if count[t[id]] != 0 {
			res[i] = t[id]
			count[t[id]]--
			continue
		}
		if t[id] == '1' {
			res[i] = '0'
		} else {
			res[i] = '1'
		}
	}

	return string(res)
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var s, t string
	fmt.Fscanf(r, "%s\n", &s)
	fmt.Fscanf(r, "%s\n", &t)
	fmt.Println(solve(s, t))
}

package main

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

var (
	base      = uint64(31)
	maxN      = 500000 + 10
	powerBase = make([]uint64, maxN)
	hashed    = []uint64{}
)

func solve(s string, t string, n int) string {
	res := make([]byte, len(s))
	count := map[byte]int{}
	lengthPattern, id := n, 0

	for i := range s {
		count[s[i]]++
	}

	//find the logest suffix == prefix
	for i := 0; i < n-1; i++ {
		if hashed[i] == getHash(n-1-i, n-1) {
			lengthPattern = n - (i + 1)
			//exp: 11011
			//pre 11 = suf 11
			//=> lengthPattern is 3 : 110
		}
	}

	for i := range res {
		id = i % lengthPattern
		if count[t[id]] != 0 {
			res[i] = t[id]
			count[t[id]]--
			continue
		}
		if t[id] == '1' {
			res[i] = '0'
		} else {
			res[i] = '1'
		}
	}

	return string(res)
}

func getHash(start int, end int) uint64 {
	return hashed[end] - hashed[start-1]*powerBase[end-start+1]
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base
	}
}

func initHash(t string, n int) {
	hashed = make([]uint64, n)
	hashed[0] = uint64(t[0])

	for i := 1; i < n; i++ {
		hashed[i] = hashed[i-1]*base + uint64(t[i])
	}
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var s, t string
	initPowerBase()
	fmt.Fscanf(r, "%s\n", &s)
	fmt.Fscanf(r, "%s\n", &t)
	initHash(t, len(t))
	fmt.Println(solve(s, t, len(t)))
}

package main

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

func kmp(str []byte, l int) []int {
	next := make([]int, l)
	next[0] = -1
	for i := 1; i < l; i++ {
		f := i - 1
		for f >= 0 && str[next[f]+1] != str[i] {
			f = next[f]
		}
		if f != -1 || str[0] == str[i] {
			next[i] = next[f]+1
		} else {
			next[i] = -1
		}
	}
	fmt.Printf("%v\n", next)
	return next
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var str1, str2 string
	fmt.Fscanf(buf, "%s\n", &str1)
	fmt.Fscanf(buf, "%s\n", &str2)
	len1 := len(str1)
	len2 := len(str2)
	s1 := []byte(str1)
	s2 := []byte(str2)
	cnt1 := 0
	cnt2 := 0
	for _, c := range s1 {
		if c == '1' {
			cnt1++
		}
	}
	for _, c := range s2 {
		if c == '1' {
			cnt2++
		}
	}
	if len1 < len2 || cnt2 > cnt1 || len2-cnt2 > len1-cnt1 {
		fmt.Printf("%s\n", str1)
		return
	}
	next := kmp([]byte(str2), len2)
	seg1 := 0
	seg0 := 0
	for i := next[len2-1] + 1; i < len2; i++ {
		if s2[i] == '1' {
			seg1++
		} else {
			seg0++
		}
	}
	len1 -= len2
	cnt1 -= cnt2
	cnt2 = -1
	if seg1 > 0 {
		cnt2 = cnt1 / seg1
	}
	if seg0 > 0 && (cnt2 == -1 || cnt2 > (len1-cnt1)/seg0) {
		cnt2 = (len1 - cnt1) / seg0
	}

	fmt.Printf("%s", str2)
	for j := 0; j < cnt2; j++ {
		for i := next[len2-1] + 1; i < len2; i++ {
			fmt.Printf("%c", s2[i])
		}
	}
	for i:=0;i < (len1-cnt1)-cnt2*seg0;i++{
		fmt.Printf("0")
	}
	for i:=0;i < (cnt1)-cnt2*seg1;i++{
		fmt.Printf("1")
	}
	fmt.Printf("\n")
}
/**
01010101
0101010
 */


Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 to n inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with n meteorids, colours of which being integer sequences a1, a2, ..., an and b1, b2, ..., bn respectively. Meteoroids' colours were also between 1 and n inclusive, and the two sequences were not identical, that is, at least one i (1 ≤ i ≤ n) exists, such that ai ≠ bi holds.Well, she almost had it all — each of the sequences a and b matched exactly n - 1 elements in Sengoku's permutation. In other words, there is exactly one i (1 ≤ i ≤ n) such that ai ≠ pi, and exactly one j (1 ≤ j ≤ n) such that bj ≠ pj.For now, Sengoku is able to recover the actual colour sequences a and b through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night.

The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third line contains n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ n) — the sequence of colours in the second meteor outburst. At least one i (1 ≤ i ≤ n) exists, such that ai ≠ bi holds.

Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.

NoteIn the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.

package main

import (
	"fmt"
)

func ReadArr(n int) []int{
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	return arr
}

var (
	n int
	a, b, ans []int
)

func Read() {
	fmt.Scan(&n)
	a = ReadArr(n)
	b = ReadArr(n)
	ans = make([]int, n)
}

func main() {
	Read()
	used := make([]bool, n)
	misses := [2]int{-1, -1}
	for i := 0; i < n; i++ {
		if a[i] == b[i] {
			used[a[i] - 1] = true
			ans[i] = a[i]
		} else {
			if misses[0] == -1 {
				misses[0] = i
			} else {
				misses[1] = i
			}
		}
	}

	unused := [2]int{-1, -1}
	for i, u := range used {
		if !u {
			if unused[0] == -1 {
				unused[0] = i + 1
			} else {
				unused[1] = i + 1
			}
		}
	}

	if misses[1] == -1 {
		ans[misses[0]] = unused[0]
	} else {
		ans[misses[0]] = unused[0]
		ans[misses[1]] = unused[1]
		if (a[misses[0]] != ans[misses[0]] && a[misses[1]] != ans[misses[1]]) ||
			(b[misses[0]] != ans[misses[0]] && b[misses[1]] != ans[misses[1]]) {
			ans[misses[0]] = unused[1]
			ans[misses[1]] = unused[0]
		}
	}

	printAns()
}
func printAns() {
	for _, e := range ans {
		fmt.Print(e, " ")
	}
}

package main

import (
    "fmt"
)

var (
    n int
    a []int
    b []int
)

func solve(i int, j int) bool {
    ma := map[int]bool{}
    mb := map[int]bool{}
    r := make([]int, n)

    for k := 0; k < n; k++ {
        var x = a[k]
        if k == i {
            x = b[k]
        } else if k == j {
            x = a[k]
        } else {
            if a[k] != b[k] { return false }
        }
        if ma[x] { return false }
        if mb[x] { return false }

        ma[x] = true
        mb[x] = true

        r[k] = x
    }
    for i := 0; i < n; i++ {
        fmt.Printf("%d", r[i])
        if (i == n - 1) {
            fmt.Printf("\n")
        } else {
            fmt.Printf(" ")
        }
    }
    return true
}

func solve2(i int, k int) bool {
    ma := map[int]bool{}
    mb := map[int]bool{}
    r := make([]int, n)

    for j := 0; j < n; j++ {
        var x = a[j]
        if j == i {
            x = k
        } else {
            if a[j] != b[j] { return false }
        }
        if ma[x] { return false }
        if mb[x] { return false }

        ma[x] = true
        mb[x] = true

        r[j] = x
    }

    for i := 0; i < n; i++ {
        fmt.Printf("%d", r[i])
        if (i == n - 1) {
            fmt.Printf("\n")
        } else {
            fmt.Printf(" ")
        }
    }
    return true
}

func main() {
    for {
        _, err := fmt.Scan(&n)
        if err != nil { break }

        a = make([]int, n)
        b = make([]int, n)
        ma := map[int]int{}
        va := map[int]bool{}
        mb := map[int]int{}
        vb := map[int]bool{}

        for i := 0; i < n; i++ {
            fmt.Scan(&a[i])
            x := a[i]
            if ma[x] > 0 {
                va[ma[x]-1] = true
                va[i] = true
            }
            ma[x] = i + 1
        }
        for i := 0; i < n; i++ {
            fmt.Scan(&b[i])
            x := b[i]
            if mb[x] > 0 {
                vb[mb[x]-1] = true
                vb[i] = true
            }
            mb[x] = i + 1
        }

        solved := false
        for i := 0; i < n && !solved; i++ {
            if va[i] == false { continue }
            for j := 0; j < n && !solved; j++ {
                if vb[j] == false { continue }
                if i == j {
                    for k := 1; k <= n && !solved; k++ {
                        solved = solve2(i, k)
                    }
                } else {
                    solved = solve(i, j)
                }
            }
        }
    }
}

package main

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

func check(arr []int) bool {
	tmp := make([]int, len(arr))
	copy(tmp, arr)
	sort.Ints(tmp)
	for i := 0; i < len(tmp)-1; i++ {
		if tmp[i] == tmp[i+1] {
			return false
		}
	}
	return true
}

func main() {
	var n, count int
	var line string
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	for _, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
		n, _ = strconv.Atoi(j)
	}
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n)
	line, _ = reader.ReadString('\n')
	for i, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
		a[i], _ = strconv.Atoi(j)
	}
	line, _ = reader.ReadString('\n')
	for i, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
		b[i], _ = strconv.Atoi(j)
	}
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			count++
		}
	}
	if count == 1 {
		for i := 0; i < n; i++ {
			if a[i] == b[i] {
				c[i] = a[i]
			} else {
				c[i] = 0
			}
		}
		for i := 0; i < n; i++ {
			if a[i] != b[i] {
				tmp := 0
				for {
					tmp++
					if tmp != a[i] && tmp != b[i] {
						c[i] = tmp
						if check(c) {
							goto metka2
						}
					}
				}
			}
		}
	} else {
	metka:
		for i := 0; i < n; i++ {
			if a[i] == b[i] {
				c[i] = a[i]
			} else {
				tmp := rand.Int()
				if tmp%2 == 0 {
					c[i] = a[i]
				} else {
					c[i] = b[i]
				}
			}
		}
		if !check(c) {
			goto metka
		}
	}
metka2:
	for _, j := range c {
		fmt.Printf("%d ", j)
	}
}

package main

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

type Reader struct {
  scanner *bufio.Scanner
}

func StdinReader() Reader {
  reader := Reader{bufio.NewScanner(os.Stdin)}
  reader.scanner.Split(bufio.ScanWords)
  return reader
}

func (r *Reader) NextInt() int {
  ok := r.scanner.Scan()
  if !ok {
    panic("EOF")
  }
  result, err := strconv.Atoi(r.scanner.Text())
  if err != nil {
    panic("no int")
  }
  return result
}

func main() {
  in := StdinReader()

  n := in.NextInt()
  a := make([]int, n)
  for i := 0; i < n; i++ {
    a[i] = in.NextInt()
  }
  b := make([]int, n)
  for i := 0; i < n; i++ {
    b[i] = in.NextInt()
  }

  find_missing := func(a []int) int {
    res := 0
    for i := 0; i < n; i++ {
      res = res ^ (i + 1) ^ a[i]
    }
    return res
  }

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

    for i := 0; i < n; i++ {
      if prev[a[i]] != -1 {
        return prev[a[i]], i
      }
      prev[a[i]] = i
    }
    panic("")
  }

  ai, aj := find_dup(a)
  ax := find_missing(a) ^ a[ai]

  bi, bj := find_dup(b)
  bx := find_missing(b) ^ b[bi]

  for _, i := range []int{ai, aj} {
    for _, j := range []int{bi, bj} {
      tmpa, tmpb := a[i], b[j]
      a[i], b[j] = ax, bx
      same := true
      for k := 0; k < n; k++ {
        if a[k] != b[k] {
          same = false
        }
      }
      if same {
        for k := 0; k < n; k++ {
          fmt.Printf("%d ", a[k])
        }
        fmt.Printf("\n")
        return
      }
      a[i], b[j] = tmpa, tmpb
    }
  }

  return
}

package main

import (
	"fmt"
)

func ReadArr(n int) []int{
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	return arr
}

var (
	n int
	a, b, ans []int
)

func Read() {
	fmt.Scan(&n)
	a = ReadArr(n)
	b = ReadArr(n)
	ans = make([]int, n)
}

func main() {
	Read()
	mistakes := 0
	anyMisPos := 0
	for i := 0; i < n; i++ {
		ans[i] = a[i]
		if a[i] != b[i] {
			mistakes++
			anyMisPos = i
		}
	}
	if mistakes == 1 {
		mistake := 1
		for a[anyMisPos] == mistake || b[anyMisPos] == mistake {
			mistake++
		}
		ans[anyMisPos] = mistake

	}
	if mistakes == 2 {
		ans[anyMisPos] = b[anyMisPos]
	}
	printAns()
}
func printAns() {
	for _, e := range ans {
		fmt.Print(e, " ")
	}
}

package main

import (
	"fmt"
)

func ReadArr(n int) []int{
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	return arr
}

var (
	n int
	a, b, ans []int
)

func Read() {
	fmt.Scan(&n)
	a = ReadArr(n)
	b = ReadArr(n)
	ans = make([]int, n)
}

func main() {
	Read()
	used := make([]bool, n)
	misses := [2]int{-1, -1}
	for i := 0; i < n; i++ {
		if a[i] == b[i] {
			used[a[i] - 1] = true
			ans[i] = a[i]
		} else {
			if misses[0] == -1 {
				misses[0] = i
			} else {
				misses[1] = i
			}
		}
	}

	unused := [2]int{-1, -1}
	for i, u := range used {
		if !u {
			if unused[0] == -1 {
				unused[0] = i + 1
			} else {
				unused[1] = i + 1
			}
		}
	}

	if misses[1] == -1 {
		ans[misses[0]] = unused[0]
	} else {
		if a[misses[0]] == unused[0] || b[misses[0]] == unused[0] {
			ans[misses[0]] = unused[0]
			ans[misses[1]] = unused[1]
		} else {
			ans[misses[0]] = unused[1]
			ans[misses[1]] = unused[0]
		}
	}

	printAns()
}
func printAns() {
	for _, e := range ans {
		fmt.Print(e, " ")
	}
}

package main

import (
	"fmt"
)

func ReadArr(n int) []int{
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	return arr
}

var (
	n int
	a, b, ans []int
)

func Read() {
	fmt.Scan(&n)
	a = ReadArr(n)
	b = ReadArr(n)
	ans = make([]int, n)
}

func main() {
	Read()
	used := make([]bool, n)
	for i := 0; i < n; i++ {
		if a[i] == b[i] {
			used[a[i] - 1] = true
			ans[i] = a[i]
		}
	}

	for i := range ans {
		if ans[i] == 0 {
			if !used[a[i] - 1] {
				ans[i] = a[i]
				used[a[i] - 1] = true
			} else if !used[b[i] - 1] {
				ans[i] = b[i]
				used[b[i] - 1] = true
			} else { // 1 mistake -> !a && !b
				for i, e := range used {
					if !e {
						ans[i] = i + 1
						used[i] = true
					}
				}
			}
		}
	}

	printAns()
}
func printAns() {
	for _, e := range ans {
		fmt.Print(e, " ")
	}
}

package main

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

func check(arr []int) bool {
	tmp := make([]int, len(arr))
	copy(tmp, arr)
	sort.Ints(tmp)
	for i := 0; i < len(tmp)-1; i++ {
		if tmp[i] == tmp[i+1] {
			return false
		}
	}
	return true
}

func main() {
	var n, count int
	var line string
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	for _, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
		n, _ = strconv.Atoi(j)
	}
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n)
	line, _ = reader.ReadString('\n')
	for i, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
		a[i], _ = strconv.Atoi(j)
	}
	line, _ = reader.ReadString('\n')
	for i, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
		b[i], _ = strconv.Atoi(j)
	}
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			count++
		}
	}
	if count == 1 {
		for i := 0; i < n; i++ {
			if a[i] == b[i] {
				c[i] = a[i]
			} else {
				tmp := 1
				for {
					if tmp != a[i] && tmp != b[i] {
						c[i] = tmp
						break
					}
					tmp++
				}
			}
		}
	} else {
	metka:
		for i := 0; i < n; i++ {
			if a[i] == b[i] {
				c[i] = a[i]
			} else {
				tmp := rand.Int()
				if tmp%2 == 0 {
					c[i] = a[i]
				} else {
					c[i] = b[i]
				}
			}
		}
		if !check(c) {
			goto metka
		}
	}
	for _, j := range c {
		fmt.Printf("%d ", j)
	}
}


Circular land is an $$$2n \times 2n$$$ grid. Rows of this grid are numbered by integers from $$$1$$$ to $$$2n$$$ from top to bottom and columns of this grid are numbered by integers from $$$1$$$ to $$$2n$$$ from left to right. The cell $$$(x, y)$$$ is the cell on the intersection of row $$$x$$$ and column $$$y$$$ for $$$1 \leq x \leq 2n$$$ and $$$1 \leq y \leq 2n$$$.There are $$$n^2$$$ of your friends in the top left corner of the grid. That is, in each cell $$$(x, y)$$$ with $$$1 \leq x, y \leq n$$$ there is exactly one friend. Some of the other cells are covered with snow.Your friends want to get to the bottom right corner of the grid. For this in each cell $$$(x, y)$$$ with $$$n+1 \leq x, y \leq 2n$$$ there should be exactly one friend. It doesn't matter in what cell each of friends will be.You have decided to help your friends to get to the bottom right corner of the grid.For this, you can give instructions of the following types:   You select a row $$$x$$$. All friends in this row should move to the next cell in this row. That is, friend from the cell $$$(x, y)$$$ with $$$1 \leq y < 2n$$$ will move to the cell $$$(x, y + 1)$$$ and friend from the cell $$$(x, 2n)$$$ will move to the cell $$$(x, 1)$$$.  You select a row $$$x$$$. All friends in this row should move to the previous cell in this row. That is, friend from the cell $$$(x, y)$$$ with $$$1 < y \leq 2n$$$ will move to the cell $$$(x, y - 1)$$$ and friend from the cell $$$(x, 1)$$$ will move to the cell $$$(x, 2n)$$$.  You select a column $$$y$$$. All friends in this column should move to the next cell in this column. That is, friend from the cell $$$(x, y)$$$ with $$$1 \leq x < 2n$$$ will move to the cell $$$(x + 1, y)$$$ and friend from the cell $$$(2n, y)$$$ will move to the cell $$$(1, y)$$$.  You select a column $$$y$$$. All friends in this column should move to the previous cell in this column. That is, friend from the cell $$$(x, y)$$$ with $$$1 < x \leq 2n$$$ will move to the cell $$$(x - 1, y)$$$ and friend from the cell $$$(1, y)$$$ will move to the cell $$$(2n, y)$$$. Note how friends on the grid border behave in these instructions.  Example of applying the third operation to the second column. Here, colorful circles denote your friends and blue cells are covered with snow. You can give such instructions any number of times. You can give instructions of different types. If after any instruction one of your friends is in the cell covered with snow he becomes ill.In order to save your friends you can remove snow from some cells before giving the first instruction:   You can select the cell $$$(x, y)$$$ that is covered with snow now and remove snow from this cell for $$$c_{x, y}$$$ coins. You can do this operation any number of times.You want to spend the minimal number of coins and give some instructions to your friends. After this, all your friends should be in the bottom right corner of the grid and none of them should be ill.Please, find how many coins you will spend.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \leq n \leq 250$$$). Each of the next $$$2n$$$ lines contains $$$2n$$$ integers $$$c_{i, 1}, c_{i, 2}, \ldots, c_{i, 2n}$$$ ($$$0 \leq c_{i, j} \leq 10^9$$$) — costs of removing snow from cells. If $$$c_{i, j} = 0$$$ for some $$$i, j$$$ than there is no snow in cell $$$(i, j)$$$. Otherwise, cell $$$(i, j)$$$ is covered with snow. It is guaranteed that $$$c_{i, j} = 0$$$ for $$$1 \leq i, j \leq n$$$. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$250$$$.

For each test case output one integer — the minimal number of coins you should spend.

NoteIn the first test case you can remove snow from the cells $$$(2, 1)$$$ and $$$(2, 2)$$$ for $$$100$$$ coins. Then you can give instructions   All friends in the first collum should move to the previous cell. After this, your friend will be in the cell $$$(2, 1)$$$.  All friends in the second row should move to the next cell. After this, your friend will be in the cell $$$(2, 2)$$$. In the second test case you can remove all snow from the columns $$$3$$$ and $$$4$$$ for $$$22$$$ coins. Then you can give instructions   All friends in the first row should move to the next cell.  All friends in the first row should move to the next cell.  All friends in the second row should move to the next cell.  All friends in the second row should move to the next cell.  All friends in the third column should move to the next cell.  All friends in the third column should move to the next cell.  All friends in the fourth column should move to the next cell.  All friends in the fourth column should move to the next cell. It can be shown that none of the friends will become ill and that it is impossible to spend less coins.

package main

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

func min(n ...uint64) uint64 {
	min := n[0]
	for _, a := range n {
		if a < min {
			min = a
		}
	}
	return min
}

func solve(grid [][]uint64, n uint64) uint64 {
	var sum uint64 = 0
	for i := n; i < 2*n; i++ {
		for j := n; j < 2*n; j++ {
			sum += grid[i][j]
		}
	}

	return min(
		sum+grid[n][0],
		sum+grid[0][n],

		sum+grid[n][n-1],
		sum+grid[n-1][n],

		sum+grid[2*n-1][0],
		sum+grid[0][2*n-1],

		sum+grid[2*n-1][n-1],
		sum+grid[n-1][2*n-1],
	)
}

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

	// -2147483648 2147483647
	// 4999999993  4999999993
	// 			   4294967295
	//			    705032697

	var t int
	Fscan(in, &t)
	for t > 0 {
		var n int
		Fscan(in, &n)
		grid := make([][]uint64, 2*n)
		for i := 0; i < 2*n; i++ {
			row := make([]uint64, 2*n)
			for j := 0; j < 2*n; j++ {
				var c uint64
				Fscan(in, &c)
				row[j] = c
				// shop = append(shop, []int{l, r, c})
			}
			grid[i] = row
		}
		res := solve(grid, uint64(n))
		Fprintln(out, res)
		t--
	}
}

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

package main

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

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

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

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

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

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

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

	// var dp = [101][101][2]int{}
	// for i := range dp {
	// 	for j := range dp[i] {
	// 		for k := range dp[i][j] {
	// 			dp[i][j][k] = 1 << 30
	// 		}
	// 	}
	// }
	var n int
	scan(&n)
	var (
		c   [500][500]int64
		ans int64
	)
	for i := 0; i < 2*n; i++ {
		for j := 0; j < 2*n; j++ {
			scan(&c[i][j])
			if i >= n && j >= n {
				ans += c[i][j]
			}
		}
	}
	printf("%v\n", ans+min(
		c[n][0], c[2*n-1][0],
		c[n][n-1], c[2*n-1][n-1],
		c[0][n], c[0][2*n-1],
		c[n-1][n], c[n-1][2*n-1],
	))
}

func min(s ...int64) int64 {
	r := s[0]
	for _, i := range s {
		if r > i {
			r = i
		}
	}
	return r
}

package main

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

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

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

func main() {
	defer out.Flush()

	costs := [510][510]int64{}

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var n int
		fmt.Fscan(in, &n)
		for r := 0; r < 2*n; r++ {
			for c := 0; c < 2*n; c++ {
				fmt.Fscan(in, &costs[r][c])
			}
		}

		var total int64

		for r := 0; r < n; r++ {
			for c := 0; c < n; c++ {
				total += costs[n+r][n+c]
			}
		}

		var extra int64 = 1e15
		extra = min(extra, costs[0][n])
		extra = min(extra, costs[0][2*n-1])
		extra = min(extra, costs[n-1][n])
		extra = min(extra, costs[n-1][2*n-1])
		extra = min(extra, costs[n][0])
		extra = min(extra, costs[n][n-1])
		extra = min(extra, costs[2*n-1][0])
		extra = min(extra, costs[2*n-1][n-1])

		fmt.Fprintln(out, total+extra)
	}
}

package main

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

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

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		grid := make([][]int, 2*n)
		for i := 0; i < 2*n; i++ {
			grid[i] = readNNums(reader, 2*n)
		}
		res := solve(n, grid)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

func solve(n int, C [][]int) int64 {
	var res int64
	for i := n; i < 2*n; i++ {
		for j := n; j < 2*n; j++ {
			res += int64(C[i][j])
		}
	}
	cell := 1 << 30
	cell = min(cell, C[0][n])
	cell = min(cell, C[0][2*n-1])
	cell = min(cell, C[n][0])
	cell = min(cell, C[2*n-1][0])
	cell = min(cell, C[n-1][n])
	cell = min(cell, C[n-1][2*n-1])
	cell = min(cell, C[n][n-1])
	cell = min(cell, C[2*n-1][n-1])

	return res + int64(cell)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1621D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		ans := int64(0)
		a := make([][]int64, n*2)
		for i := range a {
			a[i] = make([]int64, n*2)
			for j := range a[i] {
				Fscan(in, &a[i][j])
				if i >= n && j >= n {
					ans += a[i][j]
				}
			}
		}
		min := int64(1e9)
		for _, v := range []int64{a[0][n], a[0][n*2-1], a[n-1][n], a[n-1][n*2-1], a[n][0], a[n][n-1], a[n*2-1][0], a[n*2-1][n-1]} {
			if v < min {
				min = v
			}
		}
		Fprintln(out, ans+min)
	}
}

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

package main

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

func min(n ...int) int {
	if len(n) == 0 {
		return math.MinInt32
	}

	min := n[0]
	for _, a := range n {
		if a < min {
			min = a
		}
	}
	return min
}

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

func solve(grid [][]int, n int) int {
	sum := 0
	for i := n; i < 2*n; i++ {
		for j := n; j < 2*n; j++ {
			sum += grid[i][j]
		}
	}

	return min(
		sum+grid[n][0],
		sum+grid[0][n],

		sum+grid[n][n-1],
		sum+grid[n-1][n],

		sum+grid[2*n-1][0],
		sum+grid[0][2*n-1],

		sum+grid[2*n-1][n-1],
		sum+grid[n-1][2*n-1],
	)
}

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

	var t int
	Fscan(in, &t)
	for t > 0 {
		var n int
		Fscan(in, &n)
		grid := make([][]int, 2*n)
		for i := 0; i < 2*n; i++ {
			row := make([]int, 2*n)
			for j := 0; j < 2*n; j++ {
				var c int
				Fscan(in, &c)
				row[j] = c
				// shop = append(shop, []int{l, r, c})
			}
			grid[i] = row
		}
		res := solve(grid, n)
		Fprintln(out, res)
		t--
	}
}

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

package main

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

func min(n ...int) int {
	if len(n) == 0 {
		return math.MinInt32
	}

	min := n[0]
	for _, a := range n {
		if a < min {
			min = a
		}
	}
	return min
}

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

func solve(grid [][]int, n int) int {
	sum := 0
	for i := n; i < 2*n; i++ {
		for j := n; j < 2*n; j++ {
			sum += grid[i][j]
		}
	}

	var a, b, c, d, e, f, g, h int
	for i := n; i < 2*n; i++ {
		a += grid[0][i]
	}
	for i := n; i < 2*n; i++ {
		d += grid[i][0]
	}
	for i := 0; i < n; i++ {
		b += grid[i][2*n-1]
	}
	for i := 0; i < n; i++ {
		c += grid[2*n-1][i]
	}

	for i := 0; i < n; i++ {
		e += grid[i][n]
	}
	for i := n; i < 2*n; i++ {
		f += grid[n-1][i]
	}
	for i := 0; i < n; i++ {
		g += grid[n][i]
	}
	for i := n; i < 2*n; i++ {
		h += grid[i][n-1]
	}

	return min(
		sum+grid[0][2*n-1],
		sum+grid[2*n-1][0],

		sum+grid[n][n-1],
		sum+grid[n-1][n],

		sum+grid[0][n],
		sum+grid[n][0],

		sum+grid[2*n-1][n-1],
		sum+grid[n-1][2*n-1],

		sum+a,
		sum+b,
		sum+c,
		sum+d,
		sum+e,
		sum+f,
		sum+g,
		sum+h,
	)
}

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

	var t int
	Fscan(in, &t)
	for t > 0 {
		var n int
		Fscan(in, &n)
		grid := make([][]int, 2*n)
		for i := 0; i < 2*n; i++ {
			row := make([]int, 2*n)
			for j := 0; j < 2*n; j++ {
				var c int
				Fscan(in, &c)
				row[j] = c
				// shop = append(shop, []int{l, r, c})
			}
			grid[i] = row
		}
		res := solve(grid, n)
		Fprintln(out, res)
		t--
	}
}

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

package main

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

func min(n ...int) int {
	if len(n) == 0 {
		return math.MinInt32
	}

	min := n[0]
	for _, a := range n {
		if a < min {
			min = a
		}
	}
	return min
}

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

func solve(grid [][]int, n int) int {
	sum := 0
	for i := n; i < 2*n; i++ {
		for j := n; j < 2*n; j++ {
			sum += grid[i][j]
		}
	}

	var a, b, c, d int
	for i := n; i < 2*n; i++ {
		a += grid[0][i]
	}
	for i := n; i < 2*n; i++ {
		d += grid[i][0]
	}
	for i := 0; i < n; i++ {
		b += grid[i][2*n-1]
	}
	for i := 0; i < n; i++ {
		c += grid[2*n-1][i]
	}

	return min(
		sum+grid[0][2*n-1],
		sum+grid[2*n-1][0],

		sum+grid[n][n-1],
		sum+grid[n-1][n],

		sum+grid[0][n],
		sum+grid[n][0],

		sum+grid[2*n-1][n-1],
		sum+grid[n-1][2*n-1],

		sum+a,
		sum+b,
		sum+c,
		sum+d,
	)
}

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

	var t int
	Fscan(in, &t)
	for t > 0 {
		var n int
		Fscan(in, &n)
		grid := make([][]int, 2*n)
		for i := 0; i < 2*n; i++ {
			row := make([]int, 2*n)
			for j := 0; j < 2*n; j++ {
				var c int
				Fscan(in, &c)
				row[j] = c
				// shop = append(shop, []int{l, r, c})
			}
			grid[i] = row
		}
		res := solve(grid, n)
		Fprintln(out, res)
		t--
	}
}

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

package main

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

func min(n ...int) int {
	if len(n) == 0 {
		return math.MinInt32
	}

	min := n[0]
	for _, a := range n {
		if a < min {
			min = a
		}
	}
	return min
}

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

func solve(grid [][]int, n int) int {
	sum := 0
	for i := n; i < 2*n; i++ {
		for j := n; j < 2*n; j++ {
			sum += grid[i][j]
		}
	}

	var a, b, c, d int
	for i := n; i < 2*n; i++ {
		a += grid[0][i]
	}
	for i := n; i < 2*n; i++ {
		d += grid[i][0]
	}
	for i := 0; i < n; i++ {
		b += grid[i][2*n-1]
	}
	for i := 0; i < n; i++ {
		c += grid[2*n-1][i]
	}

	return min(
		sum+grid[n][0],
		sum+grid[n][n-1],
		sum+grid[0][n],
		sum+grid[n-1][n],
		sum+grid[0][2*n-1],
		sum+grid[2*n-1][0],
		sum+a,
		sum+b,
		sum+c,
		sum+d,
	)
}

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

	var t int
	Fscan(in, &t)
	for t > 0 {
		var n int
		Fscan(in, &n)
		grid := make([][]int, 2*n)
		for i := 0; i < 2*n; i++ {
			row := make([]int, 2*n)
			for j := 0; j < 2*n; j++ {
				var c int
				Fscan(in, &c)
				row[j] = c
				// shop = append(shop, []int{l, r, c})
			}
			grid[i] = row
		}
		res := solve(grid, n)
		Fprintln(out, res)
		t--
	}
}

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

package main

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

func min(n ...int) int {
	if len(n) == 0 {
		return math.MinInt32
	}

	min := n[0]
	for _, a := range n {
		if a < min {
			min = a
		}
	}
	return min
}

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

func solve(grid [][]int, n int) int {
	sum := 0
	for i := n; i < 2*n; i++ {
		for j := n; j < 2*n; j++ {
			sum += grid[i][j]
		}
	}
	return min(
		sum+grid[n][0],
		sum+grid[n][n-1],
		sum+grid[0][n],
		sum+grid[n-1][n],
		sum+grid[0][2*n-1],
		sum+grid[2*n-1][0],
	)
}

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

	var t int
	Fscan(in, &t)
	for t > 0 {
		var n int
		Fscan(in, &n)
		grid := make([][]int, 2*n)
		for i := 0; i < 2*n; i++ {
			row := make([]int, 2*n)
			for j := 0; j < 2*n; j++ {
				var c int
				Fscan(in, &c)
				row[j] = c
				// shop = append(shop, []int{l, r, c})
			}
			grid[i] = row
		}
		res := solve(grid, n)
		Fprintln(out, res)
		t--
	}
}

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