package main

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

var (
	sumx   []int64
	sumy   []int64
	x0, y0 int64
	x1, y1 int64
)

func getD(day int64, n int64) (int64, int64) {
	if day <= n {
		return sumx[day-1], sumy[day-1]
	}
	d := day / n
	l := day - d*n
	if l > 0 {
		return sumx[n-1]*d + sumx[l-1], sumy[n-1]*d + sumy[l-1]
	} else {
		return sumx[n-1] * d, sumy[n-1] * d
	}

}
func cabs(a, b int64) int64 {
	a -= b
	if a < 0 {
		a = 0 - a
	}
	return a
}
func solveC(day, n int64) bool {
	dx, dy := getD(day, n)
	xmid := x0 + dx
	ymid := y0 + dy

	if day >= cabs(xmid, x1)+cabs(ymid, y1) {
		return true
	} else {
		return false
	}
}
func bsearchC(l, r, n int64) int64 {
	var ans int64 = -1
	for l <= r {
		mid := ((l + r) >> 1)
		if solveC(mid, n) {
			ans = mid
			r = mid - 1
		} else {
			l = mid + 1
		}
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d %d\n", &x0, &y0)
	fmt.Fscanf(buf, "%d %d\n", &x1, &y1)
	fmt.Fscanf(buf, "%d\n", &n)
	str := make([]byte, n+1)
	fmt.Fscanf(buf, "%s\n", &str)
//	fmt.Printf("s==%s\n",str)
	sumx = make([]int64,n)
	sumy = make([]int64,n)
	var prex, prey int64
	for i := 0; i < n; i++ {
		if str[i] == 'U' {
			sumx[i] = prex
			sumy[i] = prey + 1
		} else if str[i] == 'D' {
			sumx[i] = prex
			sumy[i] = prey - 1

		} else if str[i] == 'L' {
			sumx[i] = prex - 1
			sumy[i] = prey
		} else if str[i] == 'R' {
			sumx[i] = prex + 1
			sumy[i] = prey
		}
		prex = sumx[i]
		prey = sumy[i]
	}
	var maxx int64 = 1000000000
	fmt.Printf("%d\n", bsearchC(int64(1), int64(100000)*maxx, int64(n)))
}
/**
0 0
0 1
3
UDD
 */

package main

import (
	"bufio"
	"fmt"
	"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...) }

type p struct {
	x int64
	y int64
}

func abs(x int64) int64 {
	if x > 0 {
		return x
	}
	return -x
}

func (p *p) String() string {
	return fmt.Sprintf("x: %v; y: %v\n", p.x, p.y)
}

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()
	var n int64
	start := p{0, 0}
	end := p{0, 0}
	scanf("%d %d\n", &start.x, &start.y)
	scanf("%d %d\n", &end.x, &end.y)
	scanf("%d\n", &n)
	var forecast string
	scanf("%s\n", &forecast)
	move := make([]p, n+1)
	cur := p{0, 0} // cur is endpoint where ship is going to be if it stays still
	move[0] = cur
	for i, c := range forecast {
		switch c {
		case 'U':
			cur.y++
		case 'D':
			cur.y--
		case 'L':
			cur.x--
		case 'R':
			cur.x++
		}
		move[i+1] = cur
	}
	// printf("move: %+v\n", move)
	// printf("end: %+v\n", end)
	// Let's use binary search. K is amount of days used for journey
	// To get to finish point we need to move for atleas 1 time close
	// to endpoint. Max manchaten distance is 2 * 10*9, max weather forecast
	// length is 10^5, hence upper bound is 2 * 10 ^ 14.
	// lower bound is 0
	// To check what (x2, y2) is accesible, lets calculate (x3, y3)
	// k value for (x3,y3) found with binary search, and ship stays still
	// if |x2 - x3| + |y2 - y3| <= k then (x2,y2) is accesible
	// To calculate (x3,y3) we know what k/n cycles past and k % n days of new cicle
	// Whats O(1) using move array above

	var x, y, dist int64
	l, r := int64(0), int64(1e18)
	for (r - l) > 1 {
		mid := (int64(l+r) / 2)
		cnt, rem := mid/n, mid%n
		x = start.x + move[rem].x + cnt*move[n].x
		y = start.y + move[rem].y + cnt*move[n].y
		dist = abs(x-end.x) + abs(y-end.y)
		if dist <= mid {
			r = mid
		} else {
			l = mid
		}
	}

	if r > 5e17 {
		r = int64(-1)
	}

	printf("%d\n", r)
}

package main

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

func abs(x int64) int64{
	if x < 0 {
		return -x
	} else {
		return x
	}
}
var dx, dy int64
var x1, x2, y1, y2, n int64
var px, py [100001]int64

func search(day, left, right int) int {
	if left > right {
		return -1
	}
	mid := (left + right) / 2
	x, y := int64(mid) * dx + px[day], int64(mid) * dy + py[day]
	if abs(x - x2) + abs(y - y2) <= int64(day) + int64(mid) * n {
		ans := search(day, left, mid - 1)
		if ans == -1 {
			return mid
		} else {
			return ans
		}
	} else {
		return search(day, mid + 1, right)
	}
}

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

	var s string
	fmt.Fscanf(reader, "%d %d\n", &x1, &y1)
	fmt.Fscanf(reader, "%d %d\n", &x2, &y2)
	fmt.Fscanf(reader, "%d\n", &n)
	fmt.Fscanf(reader, "%s", &s)
	px[0], py[0] = x1, y1
	for i := 0;i < int(n);i ++ {
		switch s[i] {
		case 'U':
			px[i + 1], py[i + 1] = px[i], py[i] + 1
		case 'D':
			px[i + 1], py[i + 1] = px[i], py[i] - 1
		case 'L':
			px[i + 1], py[i + 1] = px[i] - 1, py[i]
		case 'R':
			px[i + 1], py[i + 1] = px[i] + 1, py[i]
		}
	}
	dx, dy = px[n] - px[0], py[n] - py[0]
	var ans int64 = 1e16
	for i := 0;i < int(n);i ++ {
		cycle := search(i, 0, 1000000000)
		if cycle == -1 {
			continue
		}
		newAns := int64(i) + int64(cycle) * n
		if ans > newAns {
			ans = newAns
		}
	}
	if ans == 1e16 {
		fmt.Printf("-1")
	} else {
		fmt.Printf("%d", ans)
	}
}

package main

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

func abs(x int64) int64{
	if x < 0 {
		return -x
	} else {
		return x
	}
}
var dx, dy int64
var x1, x2, y1, y2, n int64
var px, py [100001]int64

func search(day, left, right int) int {
	if left > right {
		return -1
	}
	mid := (left + right) / 2
	x, y := int64(mid) * dx + px[day], int64(mid) * dy + py[day]
	if abs(x - x2) + abs(y - y2) <= int64(day) + int64(mid) * n {
		ans := search(day, left, mid - 1)
		if ans == -1 {
			return mid
		} else {
			return ans
		}
	} else {
		return search(day, mid + 1, right)
	}
}

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

	var s string
	fmt.Fscanf(reader, "%d %d\n", &x1, &y1)
	fmt.Fscanf(reader, "%d %d\n", &x2, &y2)
	fmt.Fscanf(reader, "%d\n", &n)
	fmt.Fscanf(reader, "%s", &s)
	px[0], py[0] = x1, y1
	for i := 0;i < int(n);i ++ {
		switch s[i] {
		case 'U':
			px[i + 1], py[i + 1] = px[i], py[i] + 1
		case 'D':
			px[i + 1], py[i + 1] = px[i], py[i] - 1
		case 'L':
			px[i + 1], py[i + 1] = px[i] - 1, py[i]
		case 'R':
			px[i + 1], py[i + 1] = px[i] + 1, py[i]
		}
	}
	dx, dy = px[n] - px[0], py[n] - py[0]
	if (abs(x1 + dx - x2) + abs(y1 + dy - y2)) - (abs(x1 - x2) + abs(y1 - y2)) == n {
		fmt.Printf("-1")
		return
	}
	var ans int64 = 1e16
	for i := 0;i < int(n);i ++ {
		cycle := search(i, 0, 1000000000)
		newAns := int64(i) + int64(cycle) * n
		if ans > newAns {
			ans = newAns
		}
	}
	fmt.Printf("%d", ans)
}

package main

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

var (
	sumx   []int64
	sumy   []int64
	x0, y0 int64
	x1, y1 int64
)

func getD(day int64, n int64) (int64, int64) {
	if day <= n {
		return sumx[day-1], sumy[day-1]
	}
	d := day / n
	l := day - d*n
	if l > 0 {
		return sumx[n-1]*d + sumx[l-1], sumy[n-1]*d + sumy[l-1]
	} else {
		return sumx[n-1] * d, sumy[n-1] * d
	}

}
func cabs(a, b int64) int64 {
	a -= b
	if a < 0 {
		a = 0 - a
	}
	return a
}
func solveC(day, n int64) bool {
	dx, dy := getD(day, n)
	xmid := x0 + dx
	ymid := y0 + dy
	if day >= cabs(xmid, x1)+cabs(ymid, y1) {
		return true
	} else {
		return false
	}
}
func bsearchC(l, r, n int64) int64 {
	var ans int64 = -1
	for l < r {
		mid := ((l + r) >> 1)
		if solveC(mid, n) {
			ans = mid
			r = mid - 1
		} else {
			l = mid + 1
		}
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d %d\n", &x0, &y0)
	fmt.Fscanf(buf, "%d %d\n", &x1, &y1)
	fmt.Fscanf(buf, "%d\n", &n)
	str := make([]byte, n+1)
	fmt.Fscanf(buf, "%s\n", &str)
//	fmt.Printf("s==%s\n",str)
	sumx = make([]int64,n)
	sumy = make([]int64,n)
	var prex, prey int64
	for i := 0; i < n; i++ {
		if str[i] == 'U' {
			sumx[i] = prex
			sumy[i] = prey + 1
		} else if str[i] == 'D' {
			sumx[i] = prex
			sumy[i] = prey - 1

		} else if str[i] == 'L' {
			sumx[i] = prex - 1
			sumy[i] = prey
		} else if str[i] == 'R' {
			sumx[i] = prex + 1
			sumy[i] = prey
		}
		prex = sumx[i]
		prey = sumy[i]
	}
	var maxx int64 = 1000000000
	fmt.Printf("%d\n", bsearchC(int64(1), int64(100000)*maxx, int64(n)))
}


package main

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

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

	solve := func(Case int) {
		var n,m,x,y,tx,ty int
		Fscan(in, &n, &m, &x, &y, &tx, &ty)
		ans := 0
		dx,dy := 1,1
		for x!= tx && y != ty {

			if x+dx < 1 || x+dx > n  {
				dx=-dx
			}
			if y+dy< 1 || y+dy>m {
				dy=-dy
			}
			x+=dx
			y+=dy
			ans++
		}

		Fprintln(out, ans)
	}

	T := 1
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}

}

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

package main

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

type IO interface {
	GetInt() int
	GetChar() byte
	GetString() string
}

type FastIO struct {
	IO
	in *bufio.Reader
}

func (t *FastIO) GetInt() (res int) {
	p := 1
	c, _ := t.in.ReadByte()

	for ; c < '0' || c > '9'; c, _ = t.in.ReadByte() {
	}
	// No comment...
	res = 0
	if c == '-' {
		p = -1
	} else {
		res = int(c - '0')
	}

	for c, _ = t.in.ReadByte(); c >= '0' && c <= '9'; c, _ = t.in.ReadByte() {
		res = res*10 + int(c-'0')
	}

	res *= p
	return
}

func solve(fast FastIO) {
	var n, m, i1, j1, i2, j2 int
	n = fast.GetInt()
	m = fast.GetInt()
	i1 = fast.GetInt()
	j1 = fast.GetInt()
	i2 = fast.GetInt()
	j2 = fast.GetInt()

	var (
		a int
		b int
	)

	if i2 >= i1 {
		a = i2 - i1
	} else {
		a = (n-i1)*2 + (i1 - i2)
	}

	if j2 >= j1 {
		b = (j2 - j1)
	} else {
		b = (m-j1)*2 + (j1 - j2)
	}

	fmt.Print(math.Min(float64(a), float64(b)), " ")
}

func main() {
	fast := FastIO{}
	fast.in = bufio.NewReader(os.Stdin)

	var t int

	fmt.Scan(&t)
	for ; t > 0; t-- {
		solve(fast)
	}
}

package main

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

type IO interface {
	GetInt() int
	GetChar() byte
	GetString() string
}

type FastIO struct {
	IO
	in *bufio.Reader
}

func (t *FastIO) GetInt() (res int) {
	p := 1
	c, _ := t.in.ReadByte()

	for ; c < '0' || c > '9'; c, _ = t.in.ReadByte() {
	}

	res = 0
	if c == '-' {
		p = -1
	} else {
		res = int(c - '0')
	}

	for c, _ = t.in.ReadByte(); c >= '0' && c <= '9'; c, _ = t.in.ReadByte() {
		res = res*10 + int(c-'0')
	}

	res *= p
	return
}

func solve(fast FastIO) {
	var n, m, i1, j1, i2, j2 int
	n = fast.GetInt()
	m = fast.GetInt()
	i1 = fast.GetInt()
	j1 = fast.GetInt()
	i2 = fast.GetInt()
	j2 = fast.GetInt()

	var (
		a int
		b int
	)

	if i2 >= i1 {
		a = i2 - i1
	} else {
		a = (n-i1)*2 + (i1 - i2)
	}

	if j2 >= j1 {
		b = (j2 - j1)
	} else {
		b = (m-j1)*2 + (j1 - j2)
	}

	fmt.Println(math.Min(float64(a), float64(b)))
}

func main() {
	fast := FastIO{}
	fast.in = bufio.NewReader(os.Stdin)

	var t int

	fmt.Scan(&t)
	for ; t > 0; t-- {
		solve(fast)
	}
}

package main

import (
	"fmt"
	"math"
)

func solve() {
	var n, m, i1, j1, i2, j2 int
	fmt.Scan(&n)
	fmt.Scan(&m)
	fmt.Scan(&i1)
	fmt.Scan(&j1)
	fmt.Scan(&i2)
	fmt.Scan(&j2)

	var (
		a int
		b int
	)

	if i2 >= i1 {
		a = i2 - i1
	} else {
		a = (n-i1)*2 + (i1 - i2)
	}

	if j2 >= j1 {
		b = (j2 - j1)
	} else {
		b = (m-j1)*2 + (j1 - j2)
	}

	fmt.Println(math.Min(float64(a), float64(b)))
}

func main() {
	var t int
	fmt.Scan(&t)

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n, m, i1, j1, i2, j2 int
		fmt.Scanf("%d %d %d %d %d %d\n", &n, &m, &i1, &j1, &i2, &j2)

		var (
			a int
			b int
		)

		if i2 >= i1 {
			a = i2 - i1
		} else {
			a = (n-i1)*2 + (i1 - i2)
		}

		if j2 >= j1 {
			b = (j2 - j1)
		} else {
			b = (m-j1)*2 + (j1 - j2)
		}

		fmt.Print(math.Min(float64(a), float64(b)), " ")
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n, m, i1, j1, i2, j2 int
		fmt.Scan(&n, &m, &i1, &j1, &i2, &j2)

		var (
			a int
			b int
		)

		if i2 >= i1 {
			a = i2 - i1
		} else {
			a = (n-i1)*2 + (i1 - i2)
		}

		if j2 >= j1 {
			b = (j2 - j1)
		} else {
			b = (m-j1)*2 + (j1 - j2)
		}

		fmt.Print(math.Min(float64(a), float64(b)), " ")
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n, m, i1, j1, i2, j2 int
		fmt.Scan(&n, &m, &i1, &j1, &i2, &j2)

		var (
			a int
			b int
		)

		if i2 >= i1 {
			a = i2 - i1
		} else {
			a = (n-i1)*2 + (i1 - i2)
		}

		if j2 >= j1 {
			b = (j2 - j1)
		} else {
			b = (m-j1)*2 + (j1 - j2)
		}

		fmt.Println(math.Min(float64(a), float64(b)))
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m, rb, cb, rd, cd := 0, 0, 0, 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m, &rb, &cb, &rd, &cd)
		tot, dr, dc := 0, 1, 1
		for {
			if rb == rd || cb == cd {
				break
			}
			if !(1 <= rb+dr && rb+dr <= n) {
				dr = -dr
			}
			if !(1 <= cb+dc && cb+dc <= m) {
				dc = -dc
			}
			rb, cb, tot = rb+dr, cb+dc, tot+1
		}
		fmt.Fprintln(w, tot)
	}
	w.Flush()
}

func main() {
	solve()
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var y,x,ys,xs,yf,xf int
		fmt.Fscan(in,&y,&x,&ys,&xs,&yf,&xf,)
		if yf == ys || xf == xs {
			fmt.Fprintln(out,0)
			continue
		}
		var r,c int
		if yf > ys {
			r = yf-ys
		} else {
			r = 2*y-yf-ys
		}
		if xf > xs {
			c = xf-xs
		} else {
			c = 2*x-xs-xf
		}
		if r > c {
			fmt.Fprintln(out,c)
		} else {
			fmt.Fprintln(out,r)
		}
	}
}

package main

import (
	"fmt"
)

func oneDim(s, e, w int) int {
	if e >= s {
		return e - s
	} else {
		return w - s + w - e
	}
}
func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}
func Solve(n, m, rb, cb, rd, cd int) int {
	r := oneDim(rb, rd, n)
	c := oneDim(cb, cd, m)
	return min(r, c)
}
func main() {
	n := 0
	_, err := fmt.Scanf("%d\n", &n)
	if err != nil {
		fmt.Println("error:", err)
	}
	for i := 0; i < n; i++ {
		var n, m, rb, rd, cd, cb int
		_, err = fmt.Scanf("%d %d %d %d %d %d\n", &n, &m, &rb, &cb, &rd, &cd)
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(Solve(n, m, rb, cb, rd, cd))
	}
}

package main

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

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

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

		rowD := calculateLineDist(rd, rb, n)
		colD := calculateLineDist(cd, cb, m)

		if rowD < colD {
			fmt.Fprintf(out, "%d\n", rowD)
		} else {
			fmt.Fprintf(out, "%d\n", colD)
		}
	}
}

func calculateLineDist(target int, init int, limit int) int {
	if target >= init {
		return target - init
	} else {
		return (limit - init) + (limit - target)
	}
}

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

package main

import (
	"fmt"
)

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

func main() {
	var t, n, m, rb, cb, rd, cd int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n, &m, &rb, &cb, &rd, &cd)
		ans := 0
		if rd < rb {
			ans = n - rb + n - rd
		} else {
			ans = rd - rb
		}

		if cd < cb {
			ans = min(ans, m-cb+m-cd)
		} else {
			ans = min(ans, cd-cb)
		}
		fmt.Println(ans)
	}

}

package main

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

func main() {
	//file, _ := os.Open("input.txt")
	//in := bufio.NewReader(file)
	in := bufio.NewReader(os.Stdin)

	input1 := readArrInt(in)
	t := input1[0]
	for ; t != 0; t-- {
		input := readArrInt(in)
		n, m, y1, x1, y2, x2 := input[0], input[1], input[2], input[3], input[4], input[5]
		x, y := true, true
		ans := 0
		for {
			if y1 == y2 || x1 == x2 {
				break
			}
			ans++
			if m != 1 {
				if x && x1 == m {
					x = false
				} else if !x && x1 == 1 {
					x = true
				}
				if x {
					x1++
				} else {
					x1--
				}
			}
			if n != 1 {
				if y && y1 == n {
					y = false
				} else if !y && y1 == 1 {
					y = true
				}
				if y {
					y1++
				} else {
					y1--
				}
			}
		}
		fmt.Println(ans)
	}
}

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

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

func readFloat(in *bufio.Reader) float64 {
	nStr := readStr(in)
	n, _ := strconv.ParseFloat(nStr, 64)
	return n
}

func readInt(in *bufio.Reader) int {
	nStr := readStr(in)
	n, _ := strconv.Atoi(nStr)
	return n
}

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

func readLineNumbs(in *bufio.Reader) []string {
	line := readStr(in)
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

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

var h int
var w int
var targetx int
var targety int

func solve(x, y int) int {
	var dx = 1
	var dy = 1
	var ans = 0

	for x != targetx && y != targety {
		if x+dx < 1 || x+dx > h {
			dx = -dx
		}
		if y+dy < 1 || y+dy > w {
			dy = -dy
		}
		x += dx
		y += dy
		ans++
	}
	return ans
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		var initx int
		var inity int
		fmt.Fscan(in, &h, &w, &initx, &inity, &targetx, &targety)
		fmt.Fprintf(out, "%d\n", solve(initx, inity))
	}
	out.Flush()
}

package main

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

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

func (in *CF1623A) 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 *CF1623A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
https://codeforces.com/problemset/problem/1623/A
Date: 22/03/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1623/A
Problem: CF1623A
**/
func (in *CF1623A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m, ix, iy, fx, fy := in.NextInt(), in.NextInt(), in.NextInt(), in.NextInt(), in.NextInt(), in.NextInt()
		ans := 0
		dx, dy := 1, 1
		for ix != fx && iy != fy {

			if ix+dx > n {
				dx *= -1
			}

			if ix+dx < 1 {
				dx *= -1
			}

			if iy+dy > m {
				dy *= -1
			}

			if iy+dy < 1 {
				dy *= -1
			}

			ix += dx
			iy += dy
			ans++

			if ix == fx {
				break
			}
			if iy == fy {
				break
			}

		}

		fmt.Println(ans)
	}
}

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

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

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--
		in := readNNums(reader, 6)
		res := solve(in[0], in[1], in[2], in[3], in[4], in[5])
		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, m int, rb int, cb int, rd int, cd int) int {

	var res int
	dr, dc := 1, 1

	for rb != rd && cb != cd {
		res++

		if rb == n && dr == 1 {
			dr = -1
		}
		if rb == 1 && dr == -1 {
			dr = 1
		}

		if cb == m && dc == 1 {
			dc = -1
		}
		if cb == 1 && dc == -1 {
			dc = 1
		}

		rb += dr
		cb += dc
	}

	return res
}

package main

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

const (
	Inf = 0x3f3f3f3f
)

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)
)

var (
	T                    int
	n, m, x1, y1, x2, y2 int
)

func solveOne(a, b, n int) int {
	if a <= b {
		return b - a
	}
	return a - b + 2*(n-a)
}

func solve() int {
	a, b := solveOne(x1, x2, n), solveOne(y1, y2, m)
	if a > b {
		return b
	}
	return a
}

func Init() {
}

func main() {
	_, _ = fmt.Fscan(rr, &T)
	for iCase := 1; iCase <= T; iCase++ {
		_, _ = fmt.Fscan(rr, &n, &m, &x1, &y1, &x2, &y2)

		Init()
		_, _ = fmt.Fprintln(ww, solve())
	}
	_ = ww.Flush()
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n, m, rRow, rCol, dRow, dCol int
		fmt.Fscan(in, &n, &m, &rRow, &rCol, &dRow, &dCol)
		dr, dc := 1, 1
		var secs int
		for rRow != dRow && rCol != dCol {
			if rRow == n {
				dr = -1
			}

			if rRow == 1 {
				dr = 1
			}

			if rCol == m {
				dc = -1
			}

			if rCol == 1 {
				dc = 1
			}

			rRow += dr
			rCol += dc
			secs++
		}
		fmt.Fprintln(out, secs)
	}
	out.Flush()
}

package main

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

var (
	reader                  = bufio.NewReader(os.Stdin)
	t, n, m, rb, cb, rd, cd int
)

func solve(n, m, rb, cb, rd, cd int) int {
	var c, r int
	if rd >= rb {
		r = rd - rb
	} else {
		r = 2*n - rd - rb
	}
	if cd >= cb {
		c = cd - cb
	} else {
		c = 2*m - cb - cd
	}
	if r > c {
		return c
	}
	return r
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &m, &rb, &cb, &rd, &cd)
		fmt.Println(solve(n, m, rb, cb, rd, cd))
	}
}

package main

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

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

	t := readInt(reader)

	for t > 0 {
		a := readArrayInt(reader)
		n, m, r_b, c_b, r_d, c_d := a[0], a[1], a[2], a[3], a[4], a[5]

		x, y := r_d - r_b, c_d - c_b
		if x < 0 {
			x = 2*n - r_d - r_b
		}

		if y < 0 {
			y = 2*m - c_d - c_b
		}

		if x < y {
			fmt.Fprintln(writer, x)
		} else {
			fmt.Fprintln(writer, y)
		}

		t--
	}

	writer.Flush()
}

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

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

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

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

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

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

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

	return value
}

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

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

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

	var ar []int

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

	return ar
}

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

	var ar []int64

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

	return ar
}

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

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

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

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

package main

import (
	"fmt"
)

func main() {

	t := 0
	fmt.Scan(&t)

	for t > 0 {

		m, n, im, in, dm, dn := 0, 0, 0, 0, 0, 0

		fmt.Scan(&m, &n, &im, &in, &dm, &dn)
		fmt.Println(solve(m, n, im, in, dm, dn))

		t--
	}

}

func solve(m, n, im, in, dm, dn int) int {

	t := 0
	direction := 0

	for im != dm && in != dn {

		switch direction {
		case 0:
			if im+1 > m && in+1 > n {
				im--
				in--
				direction = 2
			} else if im+1 > m {
				im--
				in++
				direction = 1
			} else if in+1 > n {
				im++
				in--
				direction = 3
			} else {
				im++
				in++
			}
		case 1:
			if im-1 < 0 && in+1 > n {
				im++
				in--
				direction = 3
			} else if im-1 < 0 {
				im++
				in++
				direction = 0
			} else if in+1 > n {
				im--
				in--
				direction = 2
			} else {
				im--
				in++
			}
		case 2:
			if im-1 < 0 && in-1 < 0 {
				im++
				in++
				direction = 0
			} else if im-1 < 0 {
				im++
				in--
				direction = 3
			} else if in-1 < 0 {
				im--
				in++
				direction = 1
			} else {
				im--
				in--
			}
		default:
			if im+1 > m && in-1 < 0 {
				im--
				in++
				direction = 1
			} else if im+1 > m {
				im--
				in--
				direction = 2
			} else if in-1 < 0 {
				im++
				in++
				direction = 0
			} else {
				im++
				in--
			}
		}

		//fmt.Println(im, in)
		t++
	}

	return t
}

func printMatrix(matrix [][]int) {
	for i := range matrix {

		for j := range matrix[i] {
			fmt.Printf("%d ", matrix[i][j])
		}

		fmt.Println()

	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	testCount, _ := strconv.Atoi(scanner.Text())

	for i := 0; i < testCount; i++ {
		scanner.Scan()
		parameters := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(parameters[0])
		m, _ := strconv.Atoi(parameters[1])
		rb, _ := strconv.Atoi(parameters[2])
		cb, _ := strconv.Atoi(parameters[3])
		rd, _ := strconv.Atoi(parameters[4])
		cd, _ := strconv.Atoi(parameters[5])

		// dirty is a flag that represents whether the dirty cell is
		// present.
		dirty := true
		// dr is the vertical movement delta.
		dr := 1
		// dc is the horizontal movement delta.
		dc := 1
		// steps represents the number of steps taken
		// by the robot to clean the dirty cell.
		steps := 0

		for dirty {
			// Clear the dirty flag if the column or row matches.
			if rb == rd || cb == cd {
				dirty = false
			} else {
				// Reverse the vertical movement if a
				// collision with the horizontal walls is determined.
				if rb+dr > n {
					dr *= -1
				}

				// Reverse the horizontal movement if a
				// collision with the vertical walls is detected.
				if cb+dc > m {
					dc *= -1
				}

				// Update the position of the robot.
				rb += dr
				cb += dc

				steps++
			}
		}

		fmt.Println(steps)
	}
}

package main

import "fmt"

func main() {
	var caseNum int
	fmt.Scanf("%d\n", &caseNum)
	for i := 0; i < caseNum; i++ {
		dr := 1
		dc := 1
		cnt := 0
		var n, m, rb, cb, rd, cd int
		fmt.Scanf("%d %d %d %d %d %d\n", &n, &m, &rb, &cb, &rd, &cd)
		for {
			//fmt.Printf("%d %d\n", rb, cb)
			if rb == rd || cb == cd {
				fmt.Printf("%d\n", cnt)
				break
			}
			if (rb == 1 && dr < 0) || (rb == n && dr > 0) {
				dr *= -1
			}
			if (cb == 1 && dc < 0) || (cb == m && dc > 0) {
				dc *= -1
			}
			rb += dr
			cb += dc
			cnt++
		}
	}
}

package main

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

const (
	NL string = "\n"
	CR string = "\r"
)

type gridPoint struct {
	r, c int
}

type Actor struct {
	pos gridPoint
}

func isNotResult(r Actor, d Actor) bool {
	return r.pos.c != d.pos.c && r.pos.r != d.pos.r
}

func Solve(nums []int) {
	grid := Actor{}
	robot := Actor{}
	dirt := Actor{}
	var dr,dc int = 1, 1

	for i := 0; i < len(nums); i+=2 {
		switch {
		case i == 0:
			grid.pos.r = nums[0]
			grid.pos.c = nums[1]

		case i == 2:
			robot.pos.r = nums[2]
			robot.pos.c = nums[3]

		case i == 4:
			dirt.pos.r = nums[4]
			dirt.pos.c = nums[5]
		}
	}

	var ss int = 0
	for isNotResult(robot, dirt) {
		if robot.pos.r==grid.pos.r { dr=-1 }
		if robot.pos.c==grid.pos.c { dc=-1 }
		if robot.pos.r==1 { dr=1 }
		if robot.pos.c==1 { dc=1 }
		robot.pos.r+=dr
		robot.pos.c+=dc
		ss+=1
	}
	fmt.Println(ss)
}

func ReadInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, CR, "")
	nStr = strings.ReplaceAll(nStr, NL, "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func ReadArrInt(in *bufio.Reader) []int {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, CR, "")
	line = strings.ReplaceAll(line, NL, "")
	numbs := strings.Split(line, " ")
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	bufIn := bufio.NewReader(os.Stdin)
	N := ReadInt(bufIn)
	for i := 0; i < N; i++ {
		numbers := ReadArrInt(bufIn)
		Solve(numbers)
	}
}

package main

import "fmt"

var (
	T, n, m, rb, cb, rd, cd int
)

func main() {
	fmt.Scanf("%d\n", &T)
	for T > 0 {
		fmt.Scanf("%d %d %d %d %d %d\n", &n, &m, &rb, &cb, &rd, &cd)
		x, y, ans := rb, cb, 0
		dx, dy := 1, 1
		for x != rd && y != cd {
			tx, ty := x+dx, y+dy
			if tx > n {
				dx = -dx
				tx = x + dx
			}
			if ty > m {
				dy = -dy
				ty = y + dy
			}
			x, y = tx, ty
			ans++
		}
		fmt.Printf("%d\n", ans)
		T--
	}
}

package main

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

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

func solve(t int) {
	n, m, x, y, x1, y1 := readInt(), readInt(), readInt(), readInt(), readInt(), readInt()
	result := 0
	dx, dy := 1, 1
	for x != x1 && y != y1 {
		if x+dx < 1 || x+dx > n {
			dx *= -1
		}
		if y+dy < 1 || y+dy > m {
			dy *= -1
		}
		result += 1
		x += dx
		y += dy
	}
	println(result)
}

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

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

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

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

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

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

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

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

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

package main

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

type IO interface {
	GetInt() int
	GetChar() byte
	GetString() string
}

type FastIO struct {
	IO
	in *bufio.Reader
}

func (t *FastIO) GetInt() (res int) {
	p := 1
	c, _ := t.in.ReadByte()

	for ; c < '0' || c > '9'; c, _ = t.in.ReadByte() {
	}
	// No comment...
	res = 0
	if c == '-' {
		p = -1
	} else {
		res = int(c - '0')
	}

	for c, _ = t.in.ReadByte(); c >= '0' && c <= '9'; c, _ = t.in.ReadByte() {
		res = res*10 + int(c-'0')
	}

	res *= p
	return
}

func solve(fast FastIO) {
	var n, m, i1, j1, i2, j2 int
	n = fast.GetInt()
	m = fast.GetInt()
	i1 = fast.GetInt()
	j1 = fast.GetInt()
	i2 = fast.GetInt()
	j2 = fast.GetInt()

	var (
		a int
		b int
	)

	if i2 >= i1 {
		a = i2 - i1
	} else {
		a = (n-i1)*2 + (i1 - i2)
	}

	if j2 >= j1 {
		b = (j2 - j1)
	} else {
		b = (m-j1)*2 + (j1 - j2)
	}

	fmt.Print(math.Min(float64(a), float64(b)), ' ')
}

func main() {
	fast := FastIO{}
	fast.in = bufio.NewReader(os.Stdin)

	var t int

	fmt.Scan(&t)
	for ; t > 0; t-- {
		solve(fast)
	}
}

package main

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

type IO interface {
	GetInt() int
	GetChar() byte
	GetString() string
}

type FastIO struct {
	IO
	in *bufio.Reader
}

func (t *FastIO) GetInt() (res int) {
	p := 1
	c, _ := t.in.ReadByte()

	for ; c < '0' || c > '9'; c, _ = t.in.ReadByte() {
	}
	// No comment...
	res = 0
	if c == '-' {
		p = -1
	} else {
		res = int(c - '0')
	}

	for c, _ = t.in.ReadByte(); c >= '0' && c <= '9'; c, _ = t.in.ReadByte() {
		res = res*10 + int(c-'0')
	}

	res *= p
	return
}

func solve(fast FastIO) {
	var n, m, i1, j1, i2, j2 int
	n = fast.GetInt()
	m = fast.GetInt()
	i1 = fast.GetInt()
	j1 = fast.GetInt()
	i2 = fast.GetInt()
	j2 = fast.GetInt()

	var (
		a int
		b int
	)

	if i2 >= i1 {
		a = i2 - i1
	} else {
		a = (n-i1)*2 + (i1 - i2)
	}

	if j2 >= j1 {
		b = (j2 - j1)
	} else {
		b = (m-j1)*2 + (j1 - j2)
	}

	fmt.Print(math.Min(float64(a), float64(b)))
}

func main() {
	fast := FastIO{}
	fast.in = bufio.NewReader(os.Stdin)

	var t int

	fmt.Scan(&t)
	for ; t > 0; t-- {
		solve(fast)
	}
}

package main

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

type IO interface {
	GetInt() int
	GetChar() byte
	GetString() string
}

type FastIO struct {
	IO
	in *bufio.Reader
}

func (t *FastIO) GetInt() (res int) {
	p := 1
	c, _ := t.in.ReadByte()
	res = 0
	if c == '-' {
		p = -1
	} else {
		res = int(c - '0')
	}

	for c, _ = t.in.ReadByte(); c >= '0' && c <= '9'; c, _ = t.in.ReadByte() {
		res = res*10 + int(c-'0')
	}

	res *= p
	return
}

func solve(fast FastIO) {
	var n, m, i1, j1, i2, j2 int
	n = fast.GetInt()
	m = fast.GetInt()
	i1 = fast.GetInt()
	j1 = fast.GetInt()
	i2 = fast.GetInt()
	j2 = fast.GetInt()

	var (
		a int
		b int
	)

	if i2 >= i1 {
		a = i2 - i1
	} else {
		a = (n-i1)*2 + (i1 - i2)
	}

	if j2 >= j1 {
		b = (j2 - j1)
	} else {
		b = (m-j1)*2 + (j1 - j2)
	}

	fmt.Println(math.Min(float64(a), float64(b)))
}

func main() {
	fast := FastIO{}
	fast.in = bufio.NewReader(os.Stdin)

	var t int

	fmt.Scan(&t)
	for ; t > 0; t-- {
		solve(fast)
	}
}

package main

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

type IO interface {
	GetInt() int
	GetChar() byte
	GetString() string
}

type FastIO struct {
	IO
	in *bufio.Reader
}

func (t *FastIO) GetInt() (res int) {
	p := 1
	c, _ := t.in.ReadByte()
	res = 0
	if c == '-' {
		p = -1
	} else {
		res = int(c - '0')
	}

	for c, _ = t.in.ReadByte(); c >= '0' && c <= '9'; c, _ = t.in.ReadByte() {
		res = res*10 + int(c-'0')
	}

	res *= p
	return
}

func main() {
	fast := FastIO{}
	fast.in = bufio.NewReader(os.Stdin)

	t := fast.GetInt()

	for ; t > 0; t-- {
		var n, m, i1, j1, i2, j2 int
		n = fast.GetInt()
		m = fast.GetInt()
		i1 = fast.GetInt()
		j1 = fast.GetInt()
		i2 = fast.GetInt()
		j2 = fast.GetInt()

		var (
			a int
			b int
		)

		if i2 >= i1 {
			a = i2 - i1
		} else {
			a = (n-i1)*2 + (i1 - i2)
		}

		if j2 >= j1 {
			b = (j2 - j1)
		} else {
			b = (m-j1)*2 + (j1 - j2)
		}

		fmt.Print(math.Min(float64(a), float64(b)), " ")
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n, m, i1, j1, i2, j2 int
		fmt.Scanf("%d %d %d %d %d %d\n", &n, &m, &i1, &j1, &i2, &j2)

		fmt.Println(n, m, i1, j1, i2, j2)

		var (
			a int
			b int
		)

		if i2 >= i1 {
			a = i2 - i1
		} else {
			a = (n-i1)*2 + (i1 - i2)
		}

		if j2 >= j1 {
			b = (j2 - j1)
		} else {
			b = (m-j1)*2 + (j1 - j2)
		}

		fmt.Print(math.Min(float64(a), float64(b)), " ")
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for ; t > 0; t-- {
		var n, m, i1, j1, i2, j2 int
		fmt.Scanf("%d %d %d %d %d %d", &n, &m, &i1, &j1, &i2, &j2)

		var (
			a int
			b int
		)

		if i2 >= i1 {
			a = i2 - i1
		} else {
			a = (n-i1)*2 + (i1 - i2)
		}

		if j2 >= j1 {
			b = (j2 - j1)
		} else {
			b = (m-j1)*2 + (j1 - j2)
		}

		fmt.Print(math.Min(float64(a), float64(b)), " ")
	}
}

package main

import (
	"fmt"
	"math"
)

func solve() {
	var n, m, i1, j1, i2, j2 int
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d", &m)
	fmt.Scanf("%d", &i1)
	fmt.Scanf("%d", &j1)
	fmt.Scanf("%d", &i2)
	fmt.Scanf("%d", &j2)

	var (
		a int
		b int
	)

	if i2 >= i1 {
		a = i2 - i1
	} else {
		a = (n-i1)*2 + (i1 - i2)
	}

	if j2 >= j1 {
		b = (j2 - j1)
	} else {
		b = (m-j1)*2 + (j1 - j2)
	}

	fmt.Println(math.Min(float64(a), float64(b)))
}

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n, m, i1, j1, i2, j2 int
		fmt.Scan(&n, &m, &i1, &j1, &i2, &j2)

		var (
			a int
			b int
		)

		if i2 >= i1 {
			a = i2 - i1
		} else {
			a = (n-i1)*2 + (i1 - i2)
		}

		if j2 >= j1 {
			b = (j2 - j1)
		} else {
			b = (m-j1)*2 + (j1 - j2)
		}

		fmt.Print(math.Min(float64(a), float64(b)), ' ')
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		n, m, rb, cb, rd, cd, dr, dc, tot := 0, 0, 0, 0, 0, 0, 1, 1, 0
		fmt.Fscan(f, &n, &m, &rb, &cb, &rd, &cd)
		revr, revc := false, false
		if rb != rd && cb != cd {
			for rb+dr != rd && cb+dc != cd {
				if rb+dr == n || rb+dr == 1 {
					revr = !revr
				}
				if cb+dc == m || cb+dc == 1 {
					revc = !revc
				}
				if revr {
					dr--
				} else {
					dr++
				}
				if revc {
					dc--
				} else {
					dc++
				}
				fmt.Fprintln(w, rb+dr, cb+dc)
				tot++
			}
		}
		fmt.Fprintln(w, tot)
	}
	w.Flush()
}

func main() {
	solve()
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var y,x,ys,xs,yf,xf int
		fmt.Fscan(in,&y,&x,&ys,&xs,&yf,&xf,)
		if yf == ys || xf == xs {
			fmt.Fprintln(out,0)
			continue
		}
		if yf>ys && xf>xs {
			fmt.Fprintln(out,min(yf-ys,xf-xs))
			continue
		}
		if yf > ys {
			fmt.Fprintln(out,yf-ys)
			continue
		}
		if xf > xs {
			fmt.Fprintln(out,xf-xs)
			continue
		}
		fmt.Fprintln(out,min(2*x-xs-xf,2*y-yf-ys))
	}
}
func min(a,b int) int {
	if a<=b{return a}
	return b
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var y,x,ys,xs,yf,xf int
		fmt.Fscan(in,&y,&x,&ys,&xs,&yf,&xf,)
		if yf == ys || xf == xs {
			fmt.Fprintln(out,0)
			continue
		}
		if yf>ys && xf>xs {
			fmt.Fprintln(out,min(yf-ys,xf-xs))
			continue
		}
		if yf > ys {
			fmt.Fprintln(out,yf-ys)
			continue
		}
		if xf > xs {
			fmt.Fprintln(out,xf-xs)
			continue
		}
		fmt.Fprintln(out,min((x-xs)+(x-xf),(y-ys)+(y-yf)))
	}
}
func min(a,b int) int {
	if a<=b{return a}
	return b
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var y,x,ys,xs,yf,xf int
		fmt.Fscan(in,&y,&x,&ys,&xs,&yf,&xf,)
		if yf == ys || xf == xs {
			fmt.Fprintln(out,0)
			continue
		}
		if yf>ys && xf>xs {
			fmt.Fprintln(out,min(yf-ys,xf-xs))
			continue
		}
		if yf > ys {
			fmt.Fprintln(out,yf-ys)
			continue
		}
		if xf > xs {
			fmt.Fprintln(out,xf-xs)
			continue
		}
		fmt.Fprintln(out,min(abs(xs-x)+abs(xf-x),abs(ys-y)+abs(yf-y)))
	}
}
func min(a,b int) int {
	if a<=b{return a}
	return b
}
func abs(a int) int {
	if a<0{return a*-1}
	return a
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var y,x,ys,xs,yf,xf int
		fmt.Fscan(in,&y,&x,&ys,&xs,&yf,&xf,)
		if yf == ys || xf == xs {
			fmt.Fprintln(out,0)
			continue
		}
		if yf > ys {
			fmt.Fprintln(out,yf-ys)
			continue
		}
		if xf > xs {
			fmt.Fprintln(out,xf-xs)
			continue
		}
		fmt.Fprintln(out,min(abs(xs-x)+abs(xf-x),abs(ys-y)+abs(yf-y)))
	}
}
func min(a,b int) int {
	if a<=b{return a}
	return b
}
func abs(a int) int {
	if a<0{return a*-1}
	return a
}

package main

import (
	"fmt"
)

func oneDim(s, e, w int) int {
	if e >= s {
		return e - s
	} else {
		return w - s + w - e
	}
}
func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}
func Solve(n, m, rb, cb, rd, cd int) int {
	r := oneDim(rb, rd, n)
	c := oneDim(cb, cd, m)
	return min(r, c)
}
func main() {
	n := 0
	_, err := fmt.Scanf("%d", &n)
	if err != nil {
		fmt.Println("error:", err)
	}
	for i := 0; i < n; i++ {
		var n, m, rb, rd, cd, cb int
		_, err = fmt.Scanf("%d %d %d %d %d %d\n", &n, &m, &rb, &cb, &rd, &cd)
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(Solve(n, m, rb, cb, rd, cd))
	}
}

package main

import (
	"fmt"
)

func oneDim(s, e, w int) int {
	if e >= s {
		return e - s
	} else {
		return w - s + w - e
	}
}
func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}
func Solve(n, m, rb, cb, rd, cd int) int {
	r := oneDim(rb, rd, n)
	c := oneDim(cb, cd, m)
	return min(r, c)
}
func main() {
	n := 0
	_, err := fmt.Scanf("%d", &n)
	if err != nil {
		fmt.Println("error:", err)
	}
	for i := 0; i < n; i++ {
		var n, m, rb, rd, cd, cb int
		_, err = fmt.Scanf("%d %d %d %d %d %d", &n, &m, &rb, &cb, &rd, &cd)
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(Solve(n, m, rb, cb, rd, cd))
	}
}

package main

import (
	"fmt"
)

func oneDim(s, e, w int) int {
	if e >= s {
		return e - s
	} else {
		return w - s + w - e
	}
}
func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}
func Solve(n, m, rb, cb, rd, cd int) int {
	r := oneDim(rb, rd, n)
	c := oneDim(cb, cd, m)
	return min(r, c)
}
func main() {
	n := 0
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var n, m, rb, rd, cd, cb int
		fmt.Scanf("%d %d %d %d %d %d", n, m, rb, cb, rd, cd)
		fmt.Println(Solve(n, m, rb, cb, rd, cd))
	}
}

package main

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

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

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

		rowD := calculateLineDist(rd, rb, m)
		colD := calculateLineDist(cd, cb, m)

		if rowD < colD {
			fmt.Fprintf(out, "%d\n", rowD)
		} else {
			fmt.Fprintf(out, "%d\n", colD)
		}
	}
}

func calculateLineDist(target int, init int, limit int) int {
	if target >= init {
		return target - init
	} else {
		return (limit - init) + (limit - target)
	}
}

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

package main

import (
	"fmt"
)

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

func main() {
	var t, n, m, rb, cb, rd, cd int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n, &m, &rb, &cb, &rd, &cd)
		ans := 0
		if rd < rb {
			ans = n - rb + n - rd
		} else {
			ans = rd - rb
		}

		if cd < cb {
			ans = min(ans, m-cb+m-cd)
		} else {
			ans = min(ans, cd-cb)
		}
		fmt.Println(ans)
	}

}


package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()
	sort.Ints(A)

	i := 0
	j := 1
	count := 0
	for i < N && j < N {
		if A[i] >= A[j] {
			j++
		} else {
			i++
			j++
			count++
		}
	}
	fmt.Println(count)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main
import (
	"bufio"
	"fmt"
	"sort"
	"os"
)
func main(){
	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(in, &n)
	a:=make([]int,n)
	for i := 0; i<n; i++ {
		fmt.Fscan(in,&a[i])
	}
	sort.Ints(a)
	b:=make([]int,n)
	copy(b, a)
	ans:=0
	for i := 0; i<n; i++ {
		for ;len(b)!=0&&b[0]<=a[i]; {
			b=b[1:]
		}
		if len(b)!=0{
			ans+=1
			b=b[1:]
		}
	}
	fmt.Printf("%d\n",ans)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	for {
		var n int
		_, err := fmt.Scanln(&n)
		if err != nil {
			break
		}

		cnt_map := make(map[int]int)
		remain_cnt_map := make(map[int]int)
		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(in, &a)
			cnt_map[a]++
			remain_cnt_map[a]++
		}
		var unique_list sort.IntSlice
		for k, _ := range cnt_map {
			unique_list = append(unique_list, k)
		}
		unique_list.Sort()
		//fmt.Println(unique_list)
		res := 0
		for l, r := 0, 1; l < len(unique_list) && r < len(unique_list); {
			cnt_l := cnt_map[unique_list[l]]
			cnt_r := remain_cnt_map[unique_list[r]]
			if cnt_l <= cnt_r {
				res += cnt_l
				l++
				remain_cnt_map[unique_list[r]] -= cnt_l
				if l == r || remain_cnt_map[unique_list[r]] <= 0 {
					r++
				}

			} else {
				res += cnt_r
				cnt_map[unique_list[l]] -= cnt_r
				r++
			}
		}

		fmt.Println(res)
	}
}

package main

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

type NumCnt struct {
	num   int
	cnt_l int
	cnt_r int
}

type NumCntList []NumCnt

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

func main() {
	in := bufio.NewReader(os.Stdin)
	for {
		var n int
		_, err := fmt.Scanln(&n)
		if err != nil {
			break
		}

		cnt_map := make(map[int]int)
		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(in, &a)
			cnt_map[a]++
		}
		var unique_list NumCntList
		for k, v := range cnt_map {
			unique_list = append(unique_list, NumCnt{k, v, v})
		}
		sort.Sort(unique_list)
		//fmt.Println(unique_list)
		res := 0
		for l, r := 0, 1; l < len(unique_list) && r < len(unique_list); {
			cnt_l := &unique_list[l].cnt_l
			cnt_r := &unique_list[r].cnt_r
			if *cnt_l <= *cnt_r {
				res += *cnt_l
				l++
				*cnt_r -= *cnt_l
				if l == r || *cnt_r <= 0 {
					r++
				}
			} else {
				res += *cnt_r
				*cnt_l -= *cnt_r
				r++
			}
		}

		fmt.Println(res)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	for {
		var n int
		_, err := fmt.Scanln(&n)
		if err != nil {
			break
		}

		cnt_map := make(map[int]int)
		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(in, &a)
			cnt_map[a]++
		}
		var unique_list sort.IntSlice
		for k, _ := range cnt_map {
			unique_list = append(unique_list, k)
		}
		unique_list.Sort()
		//fmt.Println(unique_list)
		res := 0
		for l, r := 0, 1; l < len(unique_list) && r < len(unique_list); {
			cnt_l := cnt_map[unique_list[l]]
			cnt_r := cnt_map[unique_list[r]]
			if cnt_l <= cnt_r {
				res += cnt_l
				l++
				r++
			} else {
				res += cnt_r
				cnt_map[unique_list[l]] -= cnt_r
				r++
			}
		}

		fmt.Println(res)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	for {
		var n int
		_, err := fmt.Scanln(&n)
		if err != nil {
			break
		}

		cnt_map := make(map[int]int)
		remain_cnt_map := make(map[int]int)
		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(in, &a)
			cnt_map[a]++
			remain_cnt_map[a]++
		}
		var unique_list sort.IntSlice
		for k, _ := range cnt_map {
			unique_list = append(unique_list, k)
		}
		unique_list.Sort()
		//fmt.Println(unique_list)
		res := 0
		for l, r := 0, 1; l < len(unique_list) && r < len(unique_list); {
			cnt_l := cnt_map[unique_list[l]]
			cnt_r := remain_cnt_map[unique_list[r]]
			if cnt_l <= cnt_r {
				res += cnt_l
				l++
				remain_cnt_map[unique_list[r]] -= cnt_l
				if remain_cnt_map[unique_list[r]] <= 0 {
					r++
				}

			} else {
				res += cnt_r
				cnt_map[unique_list[l]] -= cnt_r
				r++
			}
		}

		fmt.Println(res)
	}
}


package main

import "fmt"

func main() {
	var t, x, m, n int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&x, &n, &m)
		for x > 0 && (n > 0 || m > 0) {
			if x > 20 && n > 0 {
				n -= 1
				x = x/2 + 10
			} else if m > 0 {
				m -= 1
				x -= 10
			} else {
				break
			}
		}
		if x > 0 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

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

func main() {
	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)

	var t, x, n, m, i int
	fmt.Fscanf(rd, "%d\n", &t)

	for i = 0; i < t; i++ {
		fmt.Fscanf(rd, "%d %d %d\n", &x, &n, &m)
		for x > 20 {
			if n == 0 {
				break
			}
			x /= 2
			x += 10
			n--
		}

		if x > m*10 {
			fmt.Fprintf(wr, "NO\n")
		} else {
			fmt.Fprintf(wr, "YES\n")
		}
	}
	wr.Flush()
}

package main

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

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

	solve := func(_case int) bool {
		//if _case == 7 {
		//	println()
		//}
		var x, n, m int
		Fscan(in, &x, &n, &m)
		for x > 0 {
			if n == 0 && m == 0 {
				return false
			}

			if m == 0 {
				x = x/2 + 10
				n--
			} else if n == 0 {
				x -= 10
				m--
			} else {
				x1 := x/2 + 10
				x2 := x - 10
				if x1 < x {
					x=x1
					n--
				} else {
					x=x2
					m--
				}
			}
		}
		return true
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		Fprintln(out, map[bool]string{true: "YES", false: "NO"} [solve(_case)])
	}
}

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

package main

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

func main() {
	SolveKanaAndDragon()
}

func SolveKanaAndDragon() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		text := scanner.Text()

		inputs := strings.Split(text, " ")

		if len(inputs) > 1 {
			life, _ := strconv.Atoi(inputs[0])
			voidout, _ := strconv.Atoi(inputs[1])
			lightning, _ := strconv.Atoi(inputs[2])
			fmt.Println(KanaAndDragon(float64(life), float64(voidout), float64(lightning)))
		}
		//fmt.Println(text)
	}
}

func KanaAndDragon(life, voidout, lightning float64) string {
	for life > 20 && voidout > 0 {
		life = math.Floor(life / 2) + 10
		voidout--
	}

	if life - lightning*10 <= 0 {
		return "YES"
	}
	return "NO"
}

package main

import "fmt"

func main() {
	var testNum int
	fmt.Scanln(&testNum)
	for i := 0; i<testNum; i++{
		fight()
	}

}

func fight(){
	var x,n,m int
	fmt.Scanln(&x,&n,&m)
	for n>0 && x>20{
		void(&x)
		n--
	}
	for m>0{
		x -= 10
		m--
		if x<=0 {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")

}

func void(x *int){
	*x = *x/2 + 10
}

package main

import (
	"fmt"
	"math"
)

func main () {
	var t int
	fmt.Scan(&t)
	for i:=0; i < t; i++ {
		var x, n, m int
		fmt.Scan(&x, &n, &m)
		var cur_x int
		cur_x = x
		if (cur_x > 20 && n > 0) {
			for ok := true; ok; ok = (cur_x > 20 && n > 0) {
				cur_x = int(math.Floor(float64(cur_x)/2.)) + 10
				n -= 1
			}
		}
		cur_x -= m * 10
		if cur_x <= 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

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

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

func max(arr []int) (max int) {
	max = arr[0]
	for _, val := range arr {
		if val > max {
			max = val
		}
	}
	return max
}

func main() {
	var t int
	fmt.Scan(&t)
	for qt := 0; qt < t; qt++ {
		var x, n, m int
		fmt.Scan(&x, &n, &m)
		for x > 0 && n > 0 && x/2 + 10 < x {
			n--
			x = x/2 + 10
		}
		if x <= m * 10 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

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

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

func main() {
	for t:=scanInt(); t > 0; t-- {
		x, n, m := scanInt(), scanInt(), scanInt()
		for i := 0; i < n; i++ {
			if x <= 20 {
				break
			}
			x = x / 2 + 10
		}

		if x <= m * 10 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	. "fmt"
)

var In = Scan

func main() {
	var t int; In(&t)
	for i := 0; i < t; i++ {
		var x, n, m int64; In(&x, &n, &m)
		for ; x > 20 && n > 0; {
			x /= 2
			x += 10
			n -= 1
		}
		if m * 10 >= x {
			Println("YES")
		} else {
			Println("NO")
		}
	}
}

package main

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

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

type writerImpl struct {
    *bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
    *bufio.Scanner
}

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

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

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

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

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

func main() {
    defer writer.Flush()
    t := reader.NextInt64()
    for ; t > 0; t-- {
        x, n, m := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
        for ; x > 20 && n > 0; n-- {
            x /= 2
            x += 10
        }
        x -= m*10
        if x <= 0 {
            writer.Printf("YES\n")
        } else {
            writer.Printf("NO\n")
        }
    }
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var x, n, m int64
		fmt.Fscan(in, &x, &n, &m, )
		for ; x > 20 && n > 0; n-- {
			x = x/2 + 10
		}
		if x > m*10 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var x, n, m int64
		fmt.Fscan(in, &x, &n, &m, )
		for ; x > 20 && n > 0; n-- {
			x = x/2 + 10
		}
		for ; m > 0; m-- {
			x -= 10
		}
		if x > 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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 scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

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

func exec() {
	var x, n, m int64
	scanf("%d %d %d\n", &x, &n, &m)

	for i := n; i > 0 && x > 20; i-- {
		x = x/2 + 10
	}
	x -= 10 * m

	if x <= 0 {
		printf("YES\n")
		return
	}
	printf("NO\n")
}

// @problemURL url.com
package main

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

func nt(s *bufio.Scanner) string {
	s.Scan()
	return s.Text()
}

func ni(s *bufio.Scanner) int {
	return atoi(nt(s))
}

func atoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var in = bufio.NewReader(os.Stdin)
	s := bufio.NewScanner(in)
	s.Split(bufio.ScanWords)

	// Code
	for T := ni(s); T > 0; T-- {
		x, n, m := ni(s), ni(s), ni(s)

		for x > 0 && (m > 0 || n > 0) {
			if x > 20 && n > 0 {
				x /= 2
				x += 10
				n--
			} else if m > 0 {
				x -= 10
				m--
			} else {
				break
			}
		}

		if x > 0 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}

}

package main

import (
	"fmt"
)

func main() {
	var T int
	fmt.Scan(&T)

	for t := 0; t < T; t++ {
		var x, a, b int
		fmt.Scan(&x, &a, &b)

		for ; a > 0; a--{
			if x / 2 + 10 < x {
				x = x / 2 + 10
			}
		}
		for ; b > 0; b-- {
			x -= 10
		}

		if x <= 0 {
			fmt.Println("YES")
		}else {
			fmt.Println("NO")
		}
	}
}

// http://acm.timus.ru/problem.aspx?space=1&num=1741
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscanln(input, &T)

	for i := 0; i < T; i++ {
		var x, n, m int
		fmt.Fscan(input, &x, &n, &m)
		fmt.Println(solve(x, n, m))
	}
}

func solve(x, n, m int) string {
	for n > 0 && x > 10 {
		x = (x >> 1) + 10
		n--
	}

	if x <= 10 * m {
		return "YES"
	} else {
		return "NO"
	}
}

package main

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

func solve(x int, n int, m int) string {
	for x > 0 && (n > 0 || m > 0) {
		for x > 20 && n > 0 {
			x = voidAbsorptions(x)
			n--
		}

		if x <= 20 || m > 0 {
			if m > 0 {
				x = lightningStrikes(x)
				m--
				continue
			}
		}

		if x <= 20 && m == 0 {
			return "NO"
		}
	}

	if x > 0 {
		return "NO"
	}

	return "YES"
}

func voidAbsorptions(x int) int {
	return x/2 + 10
}

func lightningStrikes(x int) int {
	return x - 10
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var t, x, n, m int
	fmt.Fscanf(r, "%d\n", &t)

	for tc := 0; tc < t; tc++ {
		fmt.Fscanf(r, "%d %d %d\n", &x, &n, &m)
		fmt.Fprintf(os.Stdout, "%s\n", solve(x, n, m))
	}
}

// @problemURL url.com
package main

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

func nt(s *bufio.Scanner) string {
	s.Scan()
	return s.Text()
}

func ni(s *bufio.Scanner) int {
	return atoi(nt(s))
}

func atoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var in = bufio.NewReader(os.Stdin)
	s := bufio.NewScanner(in)
	s.Split(bufio.ScanWords)

	// Code
	for T := ni(s); T > 0; T-- {
		x, n, m := ni(s), ni(s), ni(s)

		for x > 0 && (m > 0 || n > 0) {
			if x >= 41 && n > 0 {
				x /= 2
				x += 10
				n--
			} else if m > 0 {
				x -= 10
				m--
			} else {
				break
			}
		}

		if x > 0 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}

}

package main

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

func main() {
	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)

	var t, x, n, m, i int
	fmt.Fscanf(rd, "%d\n", &t)

	for i = 0; i < t; i++ {
		fmt.Fscanf(rd, "%d %d %d\n", &x, &n, &m)
		for x > 20 {
			x /= 2
			x += 10
			n--
			if n == 0 {
				break
			}
		}

		if x > m*10 {
			fmt.Fprintf(wr, "NO\n")
		} else {
			fmt.Fprintf(wr, "YES\n")
		}
	}
	wr.Flush()
}

package main

import "fmt"

func main() {
	var t, x, m, n int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&x, &n, &m)
		for x > 0 && (n > 0 || m > 0) {
			if x > 20 && n > 0 {
				n -= 1
				x = x/2 + 10
			} else {
				m -= 1
				x -= 10
			}
		}
		if x > 0 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}


package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

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

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

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

const (
	oo  = 100000000
	mod = 1
)

func mult(a, b int64) int64 {
	return (a * b) % mod
}
func add(a, b int64) int64 {
	return (a + b) % mod
}
func sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

func solve() {
	r, g, b := nextInt(), nextInt(), nextInt()
	x, y, z := make([]int, r), make([]int, g), make([]int, b)
	for i := range x {
		x[i] = nextInt()
	}
	for i := range y {
		y[i] = nextInt()
	}
	for i := range z {
		z[i] = nextInt()
	}
	sort.Ints(x)
	sort.Ints(y)
	sort.Ints(z)
	dp := make([][][]int, r+1)
	for i := range dp {
		dp[i] = make([][]int, g+1)
		for j := range dp[i] {
			dp[i][j] = make([]int, b+1)
		}
	}

	for i := 0; i <= r; i++ {
		for j := 0; j <= g; j++ {
			for k := 0; k <= b; k++ {
				if i > 0 && j > 0 {
					dp[i][j][k] = Max(dp[i][j][k], dp[i-1][j-1][k]+x[i-1]*y[j-1])
				}
				if i > 0 && k > 0 {
					dp[i][j][k] = Max(dp[i][j][k], dp[i-1][j][k-1]+x[i-1]*z[k-1])
				}
				if j > 0 && k > 0 {
					dp[i][j][k] = Max(dp[i][j][k], dp[i][j-1][k-1]+y[j-1]*z[k-1])
				}
			}
		}
	}
	printf("%d\n", dp[r][g][b])
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		file1, err := os.Open("input.txt")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create("output.txt")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// start := time.Now()

	// for t := nextInt(); t > 0; t-- {
	solve()
	// }

	// printf("%v\n", time.Now().Sub(start))
}

// R, G, B = map(int, input().split())
// rs = [int(x) for x in input().split()]
// gs = [int(x) for x in input().split()]
// bs = [int(x) for x in input().split()]
// rs.sort()
// gs.sort()
// bs.sort()
// sticks = [rs, gs, bs]
// import sys
// sys.setrecursionlimit(1000)
// memo = dict()
// def dfs(i,j,k):
//     if (i,j,k) in memo:
//         return memo[(i,j,k)]
//     if sum([i==-1,j==-1,k==-1])>1:
//         return 0
//     a = gs[j]*bs[k] + dfs(i,j-1,k-1) if j>=0 and k>=0 else 0
//     b = rs[i]*bs[k] + dfs(i-1,j,k-1) if i>=0 and k>=0 else 0
//     c = rs[i]*gs[j] + dfs(i-1,j-1,k) if i>=0 and j>=0 else 0
//     r = max(a,b,c)
//     memo[(i,j,k)] = r
//     return r
// ans = dfs(R-1, G-1, B-1)
// print(ans)

package main

import (
	"fmt"
	"sort"
)

type ky struct {
	i, j, k int
}

var memo map[ky]int

func dfs(i int, j int, k int) int {
	if v, ok := memo[ky{i, j, k}]; ok {
		return v
	}
	if (i == -1 && j == -1) || (i == -1 && k == -1) || (j == -1 && k == -1) {
		return 0
	}
	a, b, c := 0, 0, 0
	if j >= 0 && k >= 0 {
		a = gs[j]*bs[k] + dfs(i, j-1, k-1)
	}
	if i >= 0 && k >= 0 {
		b = rs[i]*bs[k] + dfs(i-1, j, k-1)
	}
	if i >= 0 && j >= 0 {
		c = rs[i]*gs[j] + dfs(i-1, j-1, k)
	}
	// r := math.Max(a, b, c)
	best := 0
	if a > best {
		best = a
	}
	if b > best {
		best = b
	}
	if c > best {
		best = c
	}
	memo[ky{i, j, k}] = best
	return best
}

var rs []int
var bs []int
var gs []int

func main() {
	var R, G, B int
	fmt.Scan(&R, &G, &B)
	rs = make([]int, R)
	gs = make([]int, G)
	bs = make([]int, B)
	for i := 0; i < R; i++ {
		fmt.Scan(&rs[i])
	}
	for i := 0; i < G; i++ {
		fmt.Scan(&gs[i])
	}
	for i := 0; i < B; i++ {
		fmt.Scan(&bs[i])
	}
	sort.Ints(rs)
	sort.Ints(bs)
	sort.Ints(gs)
	memo = make(map[ky]int)

	ans := dfs(R-1, G-1, B-1)
	fmt.Printf("%d", ans)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1398D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	var r, g, b int
	Fscan(in, &r, &g, &b)
	x := make(sort.IntSlice, r)
	for i := range x {
		Fscan(in, &x[i])
	}
	sort.Sort(sort.Reverse(x))
	y := make(sort.IntSlice, g)
	for i := range y {
		Fscan(in, &y[i])
	}
	sort.Sort(sort.Reverse(y))
	z := make(sort.IntSlice, b)
	for i := range z {
		Fscan(in, &z[i])
	}
	sort.Sort(sort.Reverse(z))
	dp := make([][][]int, r+1)
	for i := range dp {
		dp[i] = make([][]int, g+1)
		for j := range dp[i] {
			dp[i][j] = make([]int, b+1)
			for k := range dp[i][j] {
				dp[i][j][k] = -1
			}
		}
	}
	var f func(i, j, k int) int
	f = func(i, j, k int) (res int) {
		dv := &dp[i][j][k]
		if *dv != -1 {
			return *dv
		}
		defer func() { *dv = res }()
		if i < r && j < g {
			res = max(res, x[i]*y[j]+f(i+1, j+1, k))
		}
		if i < r && k < b {
			res = max(res, x[i]*z[k]+f(i+1, j, k+1))
		}
		if j < g && k < b {
			res = max(res, y[j]*z[k]+f(i, j+1, k+1))
		}
		return
	}
	Fprint(out, f(0, 0, 0))
}

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

package main

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

type triple struct{
	idx1 int
	idx2 int
	idx3 int
}

var n1, n2, n3 int
var err error
var arr1, arr2, arr3 []int
var memo = make(map[triple]int)

func conv(b bool) int {
	if b {return 1}
	return 0
}

func max(num1, num2, num3 int) int {
	ans := num1
	if num2 > ans {ans = num2}
	if num3 > ans {ans = num3}
	return ans
}

func dp(idx1 int, idx2 int, idx3 int) int {
	key := triple{idx1, idx2, idx3}
	if val, ok := memo[key]; ok {
		return val
	}
	last1 := conv(idx1 == n1)
	last2 := conv(idx2 == n2)
	last3 := conv(idx3 == n3)
	if last1 + last2 + last3 > 1 {
		return 0
	}
	var ans int
	if last1 + last2 + last3 == 1 {
		if last1 == 1 {
			ans = arr2[idx2]*arr3[idx3] + dp(idx1, idx2+1, idx3+1)
		} else if last2 == 1 {
			ans = arr1[idx1]*arr3[idx3] + dp(idx1+1, idx2, idx3+1)
		} else {
			ans = arr1[idx1]*arr2[idx2] + dp(idx1+1, idx2+1, idx3)
		}
	} else {
		ans = max(
			arr2[idx2]*arr3[idx3]+dp(idx1, idx2+1, idx3+1),
			arr1[idx1]*arr3[idx3]+dp(idx1+1, idx2, idx3+1),
			arr1[idx1]*arr2[idx2]+dp(idx1+1, idx2+1, idx3),
		)
	}
	memo[key] = ans
	return ans
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n1, err = strconv.Atoi(sc.Text())
	sc.Scan()
	n2, err = strconv.Atoi(sc.Text())
	sc.Scan()
	n3, err = strconv.Atoi(sc.Text())

	arr1 = make([]int, n1)
	arr2 = make([]int, n2)
	arr3 = make([]int, n3)
	for i := 0; i < n1; i++ {
		sc.Scan()
		arr1[i], _ = strconv.Atoi(sc.Text())
	}
	for i := 0; i < n2; i++ {
		sc.Scan()
		arr2[i], _ = strconv.Atoi(sc.Text())
	}
	for i := 0; i < n3; i++ {
		sc.Scan()
		arr3[i], _ = strconv.Atoi(sc.Text())
	}
	sort.Slice(arr1, func(i, j int) bool {
		return arr1[i] > arr1[j]
	})
	sort.Slice(arr2, func(i, j int) bool {
		return arr2[i] > arr2[j]
	})
	sort.Slice(arr3, func(i, j int) bool {
		return arr3[i] > arr3[j]
	})
	fmt.Println(dp(0, 0, 0))
}


package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		fmt.Println(n)
		for i := 0; i < n; i++ {
			fmt.Printf("%d ", i+1)
		}
		fmt.Println()
	}
}

package main

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

func main() {

	var t int

	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &t)

	for t > 0 {
		var n int
		fmt.Fscan(reader, &n)

		fmt.Printf("%d\n", n)
		for i := 1; i <= n; i++ {
			fmt.Printf("%d ", i)
		}
		fmt.Printf("\n")

		t--
	}
}

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var n int64
		fmt.Scanf("%d\n", &n)
		fmt.Println(n)
		for j:= int64(1);j<=n;j++ {
			fmt.Printf("%d ", j)
		}
		fmt.Println()
	}
}

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

package main

import "fmt"

var t,n int

func main()  {
	fmt.Scan(&t)
	for i:=1;i<=t;i++{
		fmt.Scan(&n)
		fmt.Println(n)
		for j:=1;j<=n;j++{
			fmt.Printf("%d ",j)
		}
		fmt.Println()
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1447A(in io.Reader, out io.Writer) {
	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fprintln(out, n)
		for i := 1; i <= n; i++ {
			Fprint(out, i, " ")
		}
		Fprintln(out)
	}
}

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

package main

import "fmt"

func main() {
	T := 0
	fmt.Scanf("%d\n", &T)
	for t := 0; t < T; t++ {
		n := 0
		fmt.Scanf("%d\n", &n)
		fmt.Println(n)
		for i := 0; i < n; i++ {
			fmt.Print(i+1, " ")
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {
	var t int
	for fmt.Scan(&t); t > 0; t-- {
	    var n int
	    fmt.Scan(&n)
	    fmt.Println(n)
	    for a := 1; a <= n; a++ {
		    fmt.Printf("%d ",a) }
	    fmt.Println() } }

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

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

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

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

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

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		printf("%d\n", n)
		for i := int64(1); i <= n; i++ {
			printf("%d ", i)
		}
		printf("\n")
	}
}

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var n int64
		fmt.Scanf("%d\n", &n)
		fmt.Println(n)
		for j:= n;j>=1;j-- {
			fmt.Printf("%d ", j)
		}
		fmt.Println()
	}
}

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

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var n int64
		fmt.Scanf("%d\n", &n)
		for j:= n;j>=1;j-- {
			fmt.Printf("%d ", j)
		}
		fmt.Println()
	}
}

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

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		for i := 0; i < n; i++ {
			fmt.Printf("%d ", i+1)
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {
	T := 0
	fmt.Scanf("%d", &T)
	for t := 0; t < T; t++ {
		n := 0
		fmt.Scanf("%d", &n)
		fmt.Println(n)
		for i := 0; i < n; i++ {
			fmt.Print(i+1, " ")
		}
		fmt.Println()
	}
}


// https://codeforces.com/problemset/problem/1080/B
package main

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

func formula(pos int64) int64 {
	if pos % 2 == 0 {
		return int64(pos/2)
	}
	return int64(pos-1)/2 - pos
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	numInputs, _ := strconv.ParseInt(scanner.Text(), 10, 32)
	for numInputs > 0 {
		scanner.Scan()
		inputs := strings.Split(scanner.Text(), " ")
		start, _ := strconv.ParseInt(inputs[0], 10, 32)
		last, _ := strconv.ParseInt(inputs[1], 10, 32)
		fmt.Println(int64(formula(last)) - int64(formula(start-1)))
		numInputs--
	}
}

package main

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

func main(){

	buf := bufio.NewReader(os.Stdin)

	var n int

	fmt.Fscanf(buf, "%d\n", &n)
	for i:=1 ;i <= n;i++{
		var l int64
		var r int64
		fmt.Fscanf(buf, "%d %d\n", &l,&r)
		var ans int64 = 0
		if (l&1)==0{
			ans += l
			l++
		}
		if l<=r && (r&1)==1{
			ans -= r
			r--
		}
		//fmt.Printf("l=%d r=%d\n",l,r)
		if l<=r {
			ans += (r - l+1) / 2
		}
		fmt.Printf("%d\n",ans)
	}

}

package main

import (
	"fmt"
)
var (
	t, n, m int
	ans int
)
func main() {
	fmt.Scanln(&t)
	for t != 0 {
		t--
		fmt.Scanln(&n, &m)
		ans = 0
		if (n % 2 == 1 && m % 2 == 1) {
			ans = -n + (n - m) / 2
		} else if (n % 2 == 1) {
			ans = (m - n + 1) / 2
		} else if (m % 2 == 1) {
			ans = (n - m - 1) / 2
		} else {
			ans = n + (m - n ) / 2
		}
		fmt.Println(ans)
	}
}

package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	q := readi()
	for i := 0; i < q; i++ {
		l := readi()
		r := readi()
		println(solve(l, r))
	}
}

func even(a int) bool {
	return a%2 == 0
}

func solve(l, r int) int {
	if l == r {
		if even(l) {
			return l
		} else {
			return -l
		}
	}
	if even(l) {
		return l + solve(l+1, r)
	}
	if !even(r) {
		return -r + solve(l, r-1)
	}
	return (r - l + 1) / 2
}

package main

import "fmt"

func main() {
	var t, s, e int
	fmt.Scan(&t)
	for t > 0 {
		fmt.Scan(&s, &e)
		result := 0
		diff := e - s + 1
		if diff % 2 == 1 {
			diff -= 1
		}
		if diff > 0 {
			if s % 2 == 1 {
				result = diff/2
			} else {
				result = -diff/2
			}
		}
		if diff != e - s + 1 {
			if e % 2 == 1 {
				result -= e
			} else {
				result += e
			}
		}
		t -= 1
		fmt.Println(result)
	}
}

package main

import (
	"fmt"
)

func main() {
	var n, a, b int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &a, &b)
		//fmt.Println("should be", SumB(a, b))
		if a == b {
			ans := a
			if !isEven(a) {
				ans *= -1
			}
			fmt.Printf("%d\n", ans)
			continue
		}
		if isEven(a) && isEven(b) {
			fmt.Printf("%d\n", (a+b)/2)
			continue
		}
		if !isEven(a) && !isEven(b) {
			fmt.Printf("%d\n", ((a+b)/2)*-1)
			continue
		}
		if !isEven(a) && isEven(b) {
			fmt.Printf("%d\n", Roundup(2, b-a))
			continue
		}
		fmt.Printf("%d\n", Roundup(2, b-a)*-1)
	}
	return
}

func isEven(a int) bool {
	if a%2 == 0 {
		return true
	}
	return false
}

func Roundup(a, b int) int {
	sum := b / a
	sum += 1
	return sum
}

func SumB(a, b int) int {
	sum := 0
	for i := a; i <= b; i++ {
		if isEven(i) {
			sum += i
		} else {
			sum -= i
		}
	}
	return sum
}

// N number in total
// If l is odd, 1 * (N / 2) + last sepecial if there is any
// If l is even, -1 * (N / 2) + last sepecial if there is any
package main

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

func solve(l, r int) {
	n := r - l + 1
	res := n / 2
	if l%2 == 0 {
		res *= -1
	}
	if n%2 == 1 {
		if r%2 == 1 {
			res -= r
		} else {
			res += r
		}
	}
	fmt.Println(res)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	q, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < q; i++ {
		scanner.Scan()
		l, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		r, _ := strconv.Atoi(scanner.Text())
		solve(l, r)
	}
}

// https://codeforces.com/problemset/problem/1080/B
package main

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

func formula(pos int64) float64 {
	ceil, floor := math.Ceil(float64(pos)/2), math.Floor(float64(pos)/2)
	if pos % 2 == 0 {
		return ceil * (ceil + 1) - (floor * floor)
	} else {
		return floor * (floor + 1) - (ceil * ceil)
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	numInputs, _ := strconv.ParseInt(scanner.Text(), 10, 32)
	for numInputs > 0 {
		scanner.Scan()
		inputs := strings.Split(scanner.Text(), " ")
		start, _ := strconv.ParseInt(inputs[0], 10, 32)
		end, _ := strconv.ParseInt(inputs[1], 10, 32)
		fmt.Println(int(formula(end)) - int(formula(start-1)))
		numInputs--
	}
}


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)
		A := make([][]byte, n)
		for i := 0; i < n; i++ {
			A[i], _ = reader.ReadBytes('\n')
		}
		reader.ReadBytes('\n')

		B := make([][]byte, n)
		for i := 0; i < n; i++ {
			B[i], _ = reader.ReadBytes('\n')
		}

		res := solve(n, A, B)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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, A [][]byte, B [][]byte) bool {

	for j := 0; j < n; j++ {
		if A[0][j] != B[0][j] {
			// need to flip this column
			for i := 0; i < n; i++ {
				A[i][j] = byte('0' + '1' - A[i][j])
			}
		}
	}

	for i := 0; i < n; i++ {
		// if true, need to flip, else not
		flag := A[i][0] != B[i][0]
		for j := 0; j < n; j++ {
			if flag != (A[i][j] != B[i][j]) {
				return false
			}
		}
	}
	return true
}

package main

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

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

	solve := func(Case int) {
		var n int
		var s []byte
		Fscan(in, &n)
		a := make([][]byte, n)
		for i := range a {
			a[i] = make([]byte, n)
			Fscan(in, &a[i])
		}
		for _, r := range a {
			Fscan(in, &s)
			for j, b := range s {
				r[j] ^= b
			}
		}
		for _, r := range a {
			if r[0] == 1 {
				for j := range r {
					r[j] ^= 1
				}
			}
		}
		for j := range a {
			for _, r := range a {
				if r[j] != a[0][j] {
					Fprintln(out, "NO")
					return
				}
			}
		}
		Fprintln(out, "YES")
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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