There is a classroom with two rows of computers. There are $$$n$$$ computers in each row and each computer has its own grade. Computers in the first row has grades $$$a_1, a_2, \dots, a_n$$$ and in the second row — $$$b_1, b_2, \dots, b_n$$$.Initially, all pairs of neighboring computers in each row are connected by wire (pairs $$$(i, i + 1)$$$ for all $$$1 \le i < n$$$), so two rows form two independent computer networks.Your task is to combine them in one common network by connecting one or more pairs of computers from different rows. Connecting the $$$i$$$-th computer from the first row and the $$$j$$$-th computer from the second row costs $$$|a_i - b_j|$$$.You can connect one computer to several other computers, but you need to provide at least a basic fault tolerance: you need to connect computers in such a way that the network stays connected, despite one of its computer failing. In other words, if one computer is broken (no matter which one), the network won't split in two or more parts.That is the minimum total cost to make a fault-tolerant network?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of computers in each row. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the grades of computers in the first row. The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$) — the grades of computers in the second row. It's guaranteed that the total sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print a single integer — the minimum total cost to make a fault-tolerant network.

NoteIn the first test case, it's optimal to connect four pairs of computers:   computer $$$1$$$ from the first row with computer $$$2$$$ from the second row: cost $$$|1 - 4| = 3$$$;  computer $$$3$$$ from the first row with computer $$$2$$$ from the second row: cost $$$|1 - 4| = 3$$$;  computer $$$2$$$ from the first row with computer $$$1$$$ from the second row: cost $$$|10 - 20| = 10$$$;  computer $$$2$$$ from the first row with computer $$$3$$$ from the second row: cost $$$|10 - 25| = 15$$$;  In total, $$$3 + 3 + 10 + 15 = 31$$$.In the second test case, it's optimal to connect $$$1$$$ from the first row with $$$1$$$ from the second row, and $$$4$$$ from the first row with $$$4$$$ from the second row.

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 n int
		fmt.Fscan(in, &n)

		a := make([]int64, n)
		b := make([]int64, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		for i := range b {
			fmt.Fscan(in, &b[i])
		}

		m := n - 1
		cands1 := [3]int{0, m, bestCand(b, a[0])}
		cands2 := [3]int{0, m, bestCand(b, a[m])}

		var min int64 = 5_000_000_000
		for _, v := range cands1 {
			for _, u := range cands2 {
				cur := abs(a[0]-b[v]) + abs(a[m]-b[u])

				if v != 0 && u != 0 {
					cur += abs(b[0] - a[bestCand(a, b[0])])
				}
				if v != m && u != m {
					cur += abs(b[m] - a[bestCand(a, b[m])])
				}

				min = Min(cur, min)
			}
		}

		res := min
		fmt.Fprintln(out, res)
	}
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}
func Min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func bestCand(ar []int64, x int64) int {
	best := int64(5_000_000_000)
	pos := 0
	for i := range ar {
		if t := abs(x - ar[i]); t < best {
			best = t
			pos = i
		}
	}
	return pos
}

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 n int
		fmt.Fscan(in, &n)

		a := make([]int64, n)
		b := make([]int64, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		for i := range b {
			fmt.Fscan(in, &b[i])
		}

		m := n - 1
		cands1 := [3]int{0, m, bestCand(b, a[0])}
		cands2 := [3]int{0, m, bestCand(b, a[m])}

		var min int64 = 5_000_000_000
		for _, v := range cands1 {
			for _, u := range cands2 {
				cur := abs(a[0]-b[v]) + abs(a[m]-b[u])

				if v > 0 && u > 0 {
					cur += abs(b[0] - a[bestCand(a, b[0])])
				}
				if v < m && u < m {
					cur += abs(b[m] - a[bestCand(a, b[m])])
				}

				min = Min(cur, min)
			}
		}

		res := min
		fmt.Fprintln(out, res)
	}
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}
func Min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func bestCand(ar []int64, x int64) int {
	best := int64(5_000_000_000)
	pos := 0
	for i := range ar {
		if t := abs(x - ar[i]); t < best {
			best = t
			pos = i
		}
	}
	return pos
}

package main

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

/*
1
6
5 6 4 1 6 1
2 4 1 5 4 1
---
1 = min(3, 0+1)
=====
1
5
9 5 5 5 1
1 5 5 5 9
---
0
=======
1
4
1 5 1 1
9 9 3 9
---
14 = min(8+8, 2+4+8)
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	b := make([]int, n)

	for i := range b {
		scanf("%d", &b[i])
	}
	scanf("\n")

	findBestCandidateIdx := func(cur int, nums []int) int {
		bestIdx := 0

		for i, num := range nums {
			if abs(num-cur) < abs(nums[bestIdx]-cur) {
				bestIdx = i
			}
		}

		return bestIdx
	}

	fstCnds := []int{0, findBestCandidateIdx(a[0], b), n - 1}
	lstCnds := []int{0, findBestCandidateIdx(a[n-1], b), n - 1}

	best := int64(maxInt)

	for _, i := range fstCnds {
		for _, j := range lstCnds {
			ans := int64(abs(a[0]-b[i]) + abs(a[n-1]-b[j]))

			if i > 0 && j > 0 {
				ans += int64(abs(b[0] - a[findBestCandidateIdx(b[0], a)]))
			}

			if i < n-1 && j < n-1 {
				ans += int64(abs(b[n-1] - a[findBestCandidateIdx(b[n-1], a)]))
			}

			best = min(best, ans)
		}
	}

	fmt.Fprintln(writer, best)
}

//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 int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int64) int64 {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int64) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

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

	return maxNumIdx
}

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

//goland:noinspection GoUnusedFunction
func findSet(parent []int, v int) int {
	if v == parent[v] {
		return v
	}

	parent[v] = findSet(parent, parent[v])

	return parent[v]
}

//goland:noinspection GoUnusedFunction
func unionSets(parent []int, v, u int) {
	v = findSet(parent, v)
	u = findSet(parent, u)

	if v != u {
		parent[v] = u
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func f(a []int64, v int64) int64 {
	res := int64(1e9)
	for _, w := range a {
		res = min(res, abs(w-v))
	}
	return res
}

func CF1651C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int64, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		Fprintln(out, min(
			abs(a[0]-b[0])+abs(a[n-1]-b[n-1]),
			abs(a[0]-b[n-1])+abs(a[n-1]-b[0]),
			abs(a[0]-b[0])+f(a, b[n-1])+f(b, a[n-1]),
			abs(a[0]-b[n-1])+f(a, b[0])+f(b, a[n-1]),
			abs(a[n-1]-b[0])+f(a, b[n-1])+f(b, a[0]),
			abs(a[n-1]-b[n-1])+f(a, b[0])+f(b, a[0]),
			f(a, b[0])+f(a, b[n-1])+f(b, a[0])+f(b, a[n-1]),
		))
	}
}

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

func min(a ...int64) int64 {
	ans := a[0]
	for _, val := range a[1:] {
		if val < ans {
			ans = val
		}
	}
	return ans
}

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

package main

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

var in = bufio.NewReader(os.Stdin)

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

func findMinDiffIdx(x int, ys []int) int {
	minDiff := abs(x - ys[0])
	minDiffIdx := 0
	for i, y := range ys {
		if abs(x-y) < minDiff {
			minDiff = abs(x - y)
			minDiffIdx = i
		}
	}
	return minDiffIdx
}

type line struct {
	ai, bi int
}

func solve() {
	var n int
	fmt.Fscan(in, &n)

	a := make([]int, n)
	for i := range a {
		fmt.Fscan(in, &a[i])
	}
	b := make([]int, n)
	for i := range b {
		fmt.Fscan(in, &b[i])
	}

	aLefts := []line{
		{0, 0},
		{0, n - 1},
		{0, findMinDiffIdx(a[0], b)},
	}
	aRights := []line{
		{n - 1, 0},
		{n - 1, n - 1},
		{n - 1, findMinDiffIdx(a[n-1], b)},
	}
	bLefts := []line{
		{0, 0},
		{n - 1, 0},
		{findMinDiffIdx(b[0], a), 0},
	}
	bRights := []line{
		{0, n - 1},
		{n - 1, n - 1},
		{findMinDiffIdx(b[n-1], a), n - 1},
	}

	var minSum int64 = 4_000_000_000
	for _, aL := range aLefts {
		for _, aR := range aRights {
			for _, bL := range bLefts {
				for _, bR := range bRights {
					lines := make(map[line]struct{})
					lines[aL] = struct{}{}
					lines[aR] = struct{}{}
					lines[bL] = struct{}{}
					lines[bR] = struct{}{}

					var sum int64 = 0
					for line := range lines {
						sum += int64(abs(a[line.ai] - b[line.bi]))
					}
					if sum < minSum {
						minSum = sum
					}
				}
			}
		}
	}
	fmt.Println(minSum)
}

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

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

package main

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

const mod = 998244353
const mx = int64(1e18 + 10)

func getIdx(arr []int64,val int64)int64{
	idx := int64(-1)
	cur := int64(1e9)
	for i,v := range arr{
		if abs(v - val) < cur{
			idx = int64(i)
			cur = abs(v - val)
		}
	}
	return idx
}

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int64
	fmt.Fscan(in,&n)
	a := make([]int64,n)
	b := make([]int64,n)
	for i := int64(0); i < n; i++ {
		fmt.Fscan(in,&a[i])
	}
	for i := int64(0); i < n; i++ {
		fmt.Fscan(in,&b[i])
	}
	var1 := []int64{0,getIdx(b,a[0]),n-1}
	var2 := []int64{0,getIdx(b,a[n - 1]),n-1}
	ans := mx
	for _,i := range var1{
		for _,j := range var2{
			cur := abs(a[0] - b[i]) + abs(a[n - 1] - b[j])
			if i != 0 && j != 0{
				cur += abs(b[0] - a[getIdx(a,b[0])])
			}
			if i != n - 1 && j != n - 1{
				cur += abs(b[n - 1] - a[getIdx(a,b[n - 1])])
			}
			ans = min(ans,cur)
		}
	}
	fmt.Fprintln(out,ans)
}

func abs(a int64)int64{
	if a > 0{
		return a
	}
	return -a
}
func sum(a,b int64)int64{
	return (b + a) * (b - a + 1) / 2
}

func max(a,b int64)int64{
	if a > b{
		return a
	}
	return b
}
func min(a,b int64)int64{
	if a > b{
		return b
	}
	return a
}
func gcd(a,b int)int{
	if a % b == 0{
		return b
	}
	return gcd(b,a%b)
}

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

package main

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

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n := cin.NextInt()
	a, b := cin.NextInt64s(n), cin.NextInt64s(n)
	ll, lr := abs(a[0]-b[0]), abs(a[0]-b[n-1])
	rl, rr := abs(a[n-1]-b[0]), abs(a[n-1]-b[n-1])
	lc, rc := ll, rr
	cl, cr := ll, rr
	for c := 0; c < n; c++ {
		if abs(a[0]-b[c]) < lc {
			lc = abs(a[0] - b[c])
		}
		if abs(a[n-1]-b[c]) < rc {
			rc = abs(a[n-1] - b[c])
		}
		if abs(a[c]-b[0]) < cl {
			cl = abs(a[c] - b[0])
		}
		if abs(a[c]-b[n-1]) < cr {
			cr = abs(a[c] - b[n-1])
		}
	}
	ans := ll + rr
	if lr+rl < ans {
		ans = lr + rl
	}
	if ll+rc+cr < ans {
		ans = ll + rc + cr
	}
	if lr+rc+cl < ans {
		ans = lr + rc + cl
	}
	if rl+lc+cr < ans {
		ans = rl + lc + cr
	}
	if rr+lc+cl < ans {
		ans = rr + lc + cl
	}
	if lc+rc+cl+cr < ans {
		ans = lc + rc + cl + cr
	}
	cout.Println(ans)
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

func (i *scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(i.Next(), 10, 64)
	return v
}

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker

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 n int
		fmt.Fscan(in, &n)

		a := make([]int64, n)
		b := make([]int64, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		for i := range b {
			fmt.Fscan(in, &b[i])
		}

		corners := [4]bool{false, false, false, false}
		res := int64(0)

		az := 0
		for i := range b {
			if abs(a[0]-b[i]) < abs(a[0]-b[az]) {
				az = i
			}
		}
		res += abs(a[0] - b[az])
		corners[0] = true
		if az == 0 {
			corners[2] = true
		} else if az == n-1 {
			corners[3] = true
		}

		ae := 0
		for i := range b {
			if abs(a[n-1]-b[i]) < abs(a[n-1]-b[ae]) {
				ae = i
			}
		}
		res += abs(a[n-1] - b[ae])
		corners[1] = true
		if ae == 0 {
			corners[2] = true
		} else if ae == n-1 {
			corners[3] = true
		}

		if !corners[2] {
			bz := 0
			for i := range a {
				if abs(b[0]-a[i]) < abs(b[0]-a[bz]) {
					bz = i
				}
			}
			res += abs(b[0] - a[bz])
			corners[2] = true
		}
		if !corners[3] {
			be := 0
			for i := range a {
				if abs(b[n-1]-a[i]) < abs(b[n-1]-a[be]) {
					be = i
				}
			}
			res += abs(b[n-1] - a[be])
			corners[3] = true
		}

		fmt.Fprintln(out, res)
	}
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)

		a := make([]int64, n)
		b := make([]int64, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		for i := range b {
			fmt.Fscan(in, &b[i])
		}

		simple := min(
			abs(a[0]-b[0])+abs(a[n-1]-b[n-1]),
			abs(a[0]-b[n-1])+abs(a[n-1]-b[0]),
		)

		corners := [4]bool{false, false, false, false}
		res := int64(0)

		az := 0
		for i := range b {
			if abs(a[0]-b[i]) < abs(a[0]-b[az]) {
				az = i
			}
		}
		res += abs(a[0] - b[az])
		corners[0] = true
		if az == 0 {
			corners[2] = true
		} else if az == n-1 {
			corners[3] = true
		}

		ae := 0
		for i := range b {
			if abs(a[n-1]-b[i]) < abs(a[n-1]-b[ae]) {
				ae = i
			}
		}
		res += abs(a[n-1] - b[ae])
		corners[1] = true
		if ae == 0 {
			corners[2] = true
		} else if ae == n-1 {
			corners[3] = true
		}

		if !corners[2] {
			bz := 0
			for i := range a {
				if abs(b[0]-a[i]) < abs(b[0]-a[bz]) {
					bz = i
				}
			}
			res += abs(b[0] - a[bz])
			corners[2] = true
		}
		if !corners[3] {
			be := 0
			for i := range a {
				if abs(b[n-1]-a[i]) < abs(b[n-1]-a[be]) {
					be = i
				}
			}
			res += abs(b[n-1] - a[be])
			corners[3] = true
		}

		res = min(simple, res)
		fmt.Fprintln(out, res)
	}
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)

		a := make([]int64, n)
		b := make([]int64, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		for i := range b {
			fmt.Fscan(in, &b[i])
		}

		simple := min(
			abs(a[0]-b[0])+abs(a[n-1]-b[n-1]),
			abs(a[0]-b[n-1])+abs(a[n-1]-b[0]),
		)

		az := 0
		for i := range b {
			if abs(a[0]-b[i]) < abs(a[0]-b[az]) {
				az = i
			}
		}
		ae := 0
		for i := range b {
			if abs(a[n-1]-b[i]) < abs(a[n-1]-b[ae]) {
				ae = i
			}
		}
		bz := 0
		for i := range b {
			if abs(b[0]-a[i]) < abs(b[0]-a[bz]) {
				bz = i
			}
		}
		be := 0
		for i := range b {
			if abs(b[n-1]-a[i]) < abs(b[n-1]-a[be]) {
				be = i
			}
		}

		res := abs(a[0]-b[az]) + abs(a[n-1]-b[ae]) +
			abs(b[0]-a[bz]) + abs(b[n-1]-a[be])

		if az == bz && az == 0 {
			res -= abs(a[0] - b[az])
		}
		if az == n-1 && be == 0 {
			res -= abs(a[0] - b[az])
		}
		if ae == be && ae == n-1 {
			res -= abs(a[n-1] - b[ae])
		}
		if ae == 0 && bz == n-1 {
			res -= abs(a[n-1] - b[ae])
		}

		res = min(simple, res)
		fmt.Fprintln(out, res)
	}
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)

		a := make([]int, n)
		b := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		for i := range b {
			fmt.Fscan(in, &b[i])
		}

		simple := min(
			abs(a[0]-b[0])+abs(a[n-1]-b[n-1]),
			abs(a[0]-b[n-1])+abs(a[n-1]-b[0]),
		)

		az := 0
		for i := range b {
			if abs(a[0]-b[i]) < abs(a[0]-b[az]) {
				az = i
			}
		}
		ae := 0
		for i := range b {
			if abs(a[n-1]-b[i]) < abs(a[n-1]-b[ae]) {
				ae = i
			}
		}
		bz := 0
		for i := range b {
			if abs(b[0]-a[i]) < abs(b[0]-a[bz]) {
				bz = i
			}
		}
		be := 0
		for i := range b {
			if abs(b[n-1]-a[i]) < abs(b[n-1]-a[be]) {
				be = i
			}
		}

		res := abs(a[0]-b[az]) + abs(a[n-1]-b[ae]) +
			abs(b[0]-a[bz]) + abs(b[n-1]-a[be])

		if az == bz && az == 0 {
			res -= abs(a[0] - b[az])
		}
		if az == n-1 && be == 0 {
			res -= abs(a[0] - b[az])
		}
		if ae == be && ae == n-1 {
			res -= abs(a[n-1] - b[ae])
		}
		if ae == 0 && bz == n-1 {
			res -= abs(a[n-1] - b[ae])
		}

		res = min(simple, res)
		fmt.Fprintln(out, res)
	}
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		ara := make([]int64, n)
		arb := make([]int64, n)
		for i := range ara {
			fmt.Fscan(in, &ara[i])
		}
		for i := range arb {
			fmt.Fscan(in, &arb[i])
		}

		l := n - 1
		mins := []int64{
			1_000_000_001, 1_000_000_001, 1_000_000_001, 1_000_000_001}
		for i := 1; i < l; i++ {
			if t := abs(ara[0] - arb[i]); mins[0] > t {
				mins[0] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(ara[l] - arb[i]); mins[1] > t {
				mins[1] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(arb[0] - ara[i]); mins[2] > t {
				mins[2] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(arb[l] - ara[i]); mins[3] > t {
				mins[3] = t
			}
		}

		easy := abs(ara[0]-arb[0]) + abs(ara[l]-arb[l])
		semieasy := abs(ara[0]-arb[l]) + abs(ara[l]-arb[0])
		hard := mins[0] + mins[1] + mins[2] + mins[3]
		stoopid := []int64{
			abs(arb[0]-ara[l]) + abs(ara[l]-arb[l]) + mins[0],
			abs(ara[0]-arb[0]) + abs(ara[0]-arb[l]) + mins[1],
			abs(ara[0]-arb[l]) + abs(arb[l]-ara[l]) + mins[2],
			abs(ara[0]-arb[0]) + abs(arb[0]-ara[l]) + mins[3],
		}
		omegaHard := min(
			min(stoopid[0], stoopid[1]), min(stoopid[2], stoopid[3]))

		fmt.Fprintln(out, min(min(omegaHard, hard), min(semieasy, easy)))

	}
}

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

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

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 n int
		fmt.Fscan(in, &n)
		ara := make([]int64, n)
		arb := make([]int64, n)
		for i := range ara {
			fmt.Fscan(in, &ara[i])
		}
		for i := range arb {
			fmt.Fscan(in, &arb[i])
		}

		l := n - 1
		mins := []int64{
			1_000_000_001, 1_000_000_001, 1_000_000_001, 1_000_000_001}
		for i := 1; i < l; i++ {
			if t := abs(ara[0] - arb[i]); mins[0] > t {
				mins[0] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(ara[l] - arb[i]); mins[1] > t {
				mins[1] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(arb[0] - ara[i]); mins[2] > t {
				mins[2] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(arb[l] - ara[i]); mins[3] > t {
				mins[3] = t
			}
		}

		easy := abs(ara[0]-arb[0]) + abs(ara[l]-arb[l])
		semieasy := abs(ara[0]-arb[l]) + abs(ara[0]-arb[l])
		hard := mins[0] + mins[1] + mins[2] + mins[3]
		stoopid := []int64{
			abs(arb[0]-ara[l]) + abs(ara[l]-arb[l]) + mins[0],
			abs(ara[0]-arb[0]) + abs(ara[0]-arb[l]) + mins[1],
			abs(ara[0]-arb[l]) + abs(arb[l]-ara[l]) + mins[2],
			abs(ara[0]-arb[0]) + abs(arb[0]-ara[l]) + mins[3],
		}
		omegaHard := min(
			min(stoopid[0], stoopid[1]), min(stoopid[2], stoopid[3]))

		fmt.Fprintln(out, min(min(omegaHard, hard), min(semieasy, easy)))

	}
}

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

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

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 n int
		fmt.Fscan(in, &n)
		ara := make([]int64, n)
		arb := make([]int64, n)
		for i := range ara {
			fmt.Fscan(in, &ara[i])
		}
		for i := range arb {
			fmt.Fscan(in, &arb[i])
		}

		l := n - 1
		mins := []int64{
			1_000_000_001, 1_000_000_001, 1_000_000_001, 1_000_000_001}
		for i := 1; i < l; i++ {
			if t := abs(ara[0] - arb[i]); mins[0] > t {
				mins[0] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(ara[l] - arb[i]); mins[1] > t {
				mins[1] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(arb[0] - ara[i]); mins[2] > t {
				mins[2] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(arb[l] - ara[i]); mins[3] > t {
				mins[3] = t
			}
		}

		easy := abs(ara[0]-arb[0]) + abs(ara[l]-arb[l])
		semieasy := abs(ara[0]-arb[l]) + abs(ara[0]-arb[l])
		hard := mins[0] + mins[1] + mins[2] + mins[3]

		fmt.Fprintln(out, min(hard, (min(semieasy, easy))))

	}
}

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

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

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 n int
		fmt.Fscan(in, &n)
		ara := make([]int64, n)
		arb := make([]int64, n)
		for i := range ara {
			fmt.Fscan(in, &ara[i])
		}
		for i := range arb {
			fmt.Fscan(in, &arb[i])
		}

		l := n - 1
		mins := []int64{
			1_000_000_001, 1_000_000_001, 1_000_000_001, 1_000_000_001}
		for i := 0; i < n; i++ {
			if t := abs(ara[0] - arb[i]); mins[0] > t {
				mins[0] = t
			}
		}
		for i := 0; i < n; i++ {
			if t := abs(ara[l] - arb[i]); mins[1] > t {
				mins[1] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(arb[0] - ara[i]); mins[2] > t {
				mins[2] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(arb[l] - ara[i]); mins[3] > t {
				mins[3] = t
			}
		}

		easy := abs(ara[0]-arb[0]) + abs(ara[l]-arb[l])
		semieasy := abs(ara[0]-arb[l]) + abs(ara[0]-arb[l])
		hard := mins[0] + mins[1] + mins[2] + mins[3]

		fmt.Fprintln(out, min(hard, (min(semieasy, easy))))

	}
}

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

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

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 n int
		fmt.Fscan(in, &n)
		ara := make([]int64, n)
		arb := make([]int64, n)
		for i := range ara {
			fmt.Fscan(in, &ara[i])
		}
		for i := range arb {
			fmt.Fscan(in, &arb[i])
		}

		l := n - 1
		mins := []int64{
			1_000_000_001, 1_000_000_001, 1_000_000_001, 1_000_000_001}
		for i := 0; i < n; i++ {
			if t := abs(ara[0] - arb[i]); mins[0] > t {
				mins[0] = t
			}
		}
		for i := 0; i < n; i++ {
			if t := abs(ara[l] - arb[i]); mins[1] > t {
				mins[1] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(arb[0] - ara[i]); mins[2] > t {
				mins[2] = t
			}
		}
		for i := 1; i < l; i++ {
			if t := abs(arb[l] - ara[i]); mins[3] > t {
				mins[3] = t
			}
		}

		easy := abs(ara[0]-arb[0]) + abs(ara[l]-arb[l])
		hard := mins[0] + mins[1] + mins[2] + mins[3]
		if easy < hard {
			fmt.Fprintln(out, easy)
		} else {
			fmt.Fprintln(out, hard)
		}
	}
}

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

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 n int
		fmt.Fscan(in, &n)
		ara := make([]int64, n)
		arb := make([]int64, n)
		for i := range ara {
			fmt.Fscan(in, &ara[i])
		}
		for i := range arb {
			fmt.Fscan(in, &arb[i])
		}

		l := n - 1
		mins := []int64{
			1_000_000_001, 1_000_000_001, 1_000_000_001, 1_000_000_001}
		for i := 0; i < n; i++ {
			if t := abs(ara[0] - arb[i]); mins[0] > t {
				mins[0] = t
			}
		}
		for i := 0; i < n; i++ {
			if t := abs(ara[l] - arb[i]); mins[1] > t {
				mins[1] = t
			}
		}
		for i := 0; i < n; i++ {
			if t := abs(ara[i] - arb[0]); mins[2] > t {
				mins[2] = t
			}
		}
		for i := 0; i < n; i++ {
			if t := abs(ara[i] - arb[l]); mins[3] > t {
				mins[3] = t
			}
		}

		easy := abs(ara[0]-arb[0]) + abs(ara[l]-arb[l])
		hard := mins[0] + mins[1] + mins[2] + mins[3]
		if easy < hard {
			fmt.Fprintln(out, easy)
		} else {
			fmt.Fprintln(out, hard)
		}
	}
}

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

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 n int
		fmt.Fscan(in, &n)
		ara := make([]int, n)
		arb := make([]int, n)
		for i := range ara {
			fmt.Fscan(in, &ara[i])
		}
		for i := range arb {
			fmt.Fscan(in, &arb[i])
		}

		l := n - 1
		mins := []int{
			1_000_000_001, 1_000_000_001, 1_000_000_001, 1_000_000_001}
		for i := 0; i < n; i++ {
			if t := abs(ara[0] - arb[i]); mins[0] > t {
				mins[0] = t
			}
		}
		for i := 0; i < n; i++ {
			if t := abs(ara[l] - arb[i]); mins[1] > t {
				mins[1] = t
			}
		}
		for i := 0; i < n; i++ {
			if t := abs(ara[i] - arb[0]); mins[2] > t {
				mins[2] = t
			}
		}
		for i := 0; i < n; i++ {
			if t := abs(ara[i] - arb[l]); mins[3] > t {
				mins[3] = t
			}
		}

		easy := abs(ara[0]-arb[0]) + abs(ara[l]-arb[l])
		hard := mins[0] + mins[1] + mins[2] + mins[3]
		if easy < hard {
			fmt.Fprintln(out, easy)
		} else {
			fmt.Fprintln(out, hard)
		}
	}
}

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

package main

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

/*
1
6
5 6 4 1 6 1
2 4 1 5 4 1
---
1 = min(3, 0+1)
=====
1
5
9 5 5 5 1
1 5 5 5 9
---
0
=======
1
4
1 5 1 1
9 9 3 9
---
14 = min(8+8, 2+4+8)
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	b := make([]int, n)

	for i := range b {
		scanf("%d", &b[i])
	}
	scanf("\n")

	findBestCandidateIdx := func(cur int, nums []int) int {
		bestIdx := 0

		for i, num := range nums {
			if abs(num-cur) < abs(nums[bestIdx]-cur) {
				bestIdx = i
			}
		}

		return bestIdx
	}

	fstCnds := []int{0, findBestCandidateIdx(a[0], b), n - 1}
	lstCnds := []int{0, findBestCandidateIdx(a[n-1], b), n - 1}

	best := maxInt

	for _, i := range fstCnds {
		for _, j := range lstCnds {
			ans := abs(a[0]-b[i]) + abs(a[n-1]-b[j])

			if i > 0 && j > 0 {
				ans += abs(b[0] - a[findBestCandidateIdx(b[0], a)])
			}

			if i < n-1 && j < n-1 {
				ans += abs(b[n-1] - a[findBestCandidateIdx(b[n-1], a)])
			}

			best = min(best, ans)
		}
	}

	fmt.Fprintln(writer, best)
}

//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 int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

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

	return maxNumIdx
}

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

//goland:noinspection GoUnusedFunction
func findSet(parent []int, v int) int {
	if v == parent[v] {
		return v
	}

	parent[v] = findSet(parent, parent[v])

	return parent[v]
}

//goland:noinspection GoUnusedFunction
func unionSets(parent []int, v, u int) {
	v = findSet(parent, v)
	u = findSet(parent, u)

	if v != u {
		parent[v] = u
	}
}

package main

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

/*
1
6
5 6 4 1 6 1
2 4 1 5 4 1
---
1 = min(3, 0+1)
=====
1
5
9 5 5 5 1
1 5 5 5 9
---
0
=======
1
4
1 5 1 1
9 9 3 9
---
14 = min(8+8, 2+4+8)
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	b := make([]int, n)

	for i := range b {
		scanf("%d", &b[i])
	}
	scanf("\n")

	cost1 := abs(a[0]-b[0]) + abs(a[n-1]-b[n-1])
	cost2 := abs(a[0]-b[n-1]) + abs(a[n-1]-b[0])

	cost := 0
	{

		a0bi := maxInt
		a0biIdx := -1

		for i := 0; i < n; i++ {
			if abs(a[0]-b[i]) < a0bi {
				a0bi = abs(a[0] - b[i])
				a0biIdx = i
			}
		}
		cost += a0bi

		b0ai := maxInt
		b0aiIdx := -1
		if a0biIdx != 0 {
			for i := 1; i < n; i++ {
				if abs(b[0]-a[i]) < b0ai {
					b0ai = abs(b[0] - a[i])
					b0aiIdx = i
				}
			}

			cost += b0ai
		}

		anbi := maxInt
		anbiIdx := -1

		for i := n - 1; i > 0; i-- {
			if i == a0biIdx {
				continue
			}

			if abs(a[n-1]-b[i]) < anbi {
				anbi = abs(a[n-1] - b[i])
				anbiIdx = i
			}
		}
		cost += anbi

		bnai := maxInt
		if anbiIdx != n-1 {
			for i := n - 1; i > 0; i-- {
				if i == b0aiIdx {
					continue
				}

				if abs(b[n-1]-a[i]) < bnai {
					bnai = abs(b[n-1] - a[i])
					//b0aiIdx = i
				}
			}

			cost += bnai
		}
	}

	bestCost := min(cost, cost1, cost2)

	fmt.Fprintln(writer, bestCost)
}

//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 ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

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

	return nums[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"
)

/*
1
6
5 6 4 1 6 1
2 4 1 5 4 1
---
1 = min(3, 0+1)
=====
1
5
9 5 5 5 1
1 5 5 5 9
---
0
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	b := make([]int, n)

	for i := range b {
		scanf("%d", &b[i])
	}
	scanf("\n")

	//cost1 := abs(a[0]-b[0]) + abs(a[n-1]-b[n-1])
	//cost2 := abs(a[0]-b[n-1]) + abs(a[n-1]-b[0])

	cost := 0
	{

		a0bi := maxInt
		a0biIdx := -1

		for i := 0; i < n; i++ {
			if abs(a[0]-b[i]) < a0bi {
				a0bi = abs(a[0] - b[i])
				a0biIdx = i
			}
		}
		cost += a0bi

		if a0biIdx != 0 {
			b0ai := maxInt
			//b0a1Idx := -1

			for i := 1; i < n; i++ {
				if abs(b[0]-a[i]) < b0ai {
					b0ai = abs(b[0] - a[i])
					//b0a1Idx = i
				}
			}

			cost += b0ai
		}

		anbi := maxInt
		anbiIdx := -1

		for i := n - 1; i >= 0; i-- {
			if abs(a[n-1]-b[i]) < anbi {
				anbi = abs(a[n-1] - b[i])
				anbiIdx = i
			}
		}
		cost += anbi

		if anbiIdx != n-1 {
			bnai := maxInt
			for i := n - 1; i >= 0; i-- {
				if abs(b[n-1]-a[i]) < bnai {
					bnai = abs(b[n-1] - a[i])
					//b0a1Idx = i
				}
			}

			cost += bnai
		}
	}

	bestCost := min(cost)

	fmt.Fprintln(writer, bestCost)
}

//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 ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

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

	return nums[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"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func f(a []int64, v int64) int64 {
	res := int64(1e9)
	for _, w := range a {
		res = min(res, abs(w-v))
	}
	return res
}

func CF1651C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int64, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		ans := min(abs(a[0]-b[0])+abs(a[n-1]-b[n-1]), abs(a[0]-b[n-1])+abs(a[n-1]-b[0]))
		ans = min(ans, abs(a[0]-b[0])+f(a, b[n-1])+f(b, a[n-1]))
		ans = min(ans, abs(a[0]-b[n-1])+f(a, b[0])+f(b, a[n-1]))
		ans = min(ans, abs(a[n-1]-b[n-1])+f(a, b[0])+f(b, a[0]))
		ans = min(ans, f(a, b[0])+f(a, b[n-1])+f(b, a[0])+f(b, a[n-1]))
		Fprintln(out, ans)
	}
}

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

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

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


Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $$$2 \cdot n$$$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $$$n$$$ people in each row). Students are numbered from $$$1$$$ to $$$n$$$ in each row in order from left to right.  Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all $$$2n$$$ students (there are no additional constraints), and a team can consist of any number of students. Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.

The first line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of students in each row. The second line of the input contains $$$n$$$ integers $$$h_{1, 1}, h_{1, 2}, \ldots, h_{1, n}$$$ ($$$1 \le h_{1, i} \le 10^9$$$), where $$$h_{1, i}$$$ is the height of the $$$i$$$-th student in the first row. The third line of the input contains $$$n$$$ integers $$$h_{2, 1}, h_{2, 2}, \ldots, h_{2, n}$$$ ($$$1 \le h_{2, i} \le 10^9$$$), where $$$h_{2, i}$$$ is the height of the $$$i$$$-th student in the second row.

Print a single integer — the maximum possible total height of players in a team Demid can choose.

NoteIn the first example Demid can choose the following team as follows:   In the second example Demid can choose the following team as follows:

package main

import (
	"bufio"
	"os"
	"runtime"
	"strconv"
)

/* solution */

func solve() {

	n := readInt()
	a := make([]int64, n)
	b := make([]int64, n)

	for i := 0; i < n; i++ {
		a[i] = readInt64()
	}

	for i := 0; i < n; i++ {
		b[i] = readInt64()
	}

	if n > 1 {
		a[1] += b[0]
		b[1] += a[0]
	}

	for i := 2; i < n; i++ {
		if a[i-2] > a[i-1] {
			b[i] += a[i-2]
		} else {
			b[i] += a[i-1]
		}
		if b[i-2] > b[i-1] {
			a[i] += b[i-2]
		} else {
			a[i] += b[i-1]
		}
	}

	if a[n-1] > b[n-1] {
		printInt64(a[n-1])
	} else {
		printInt64(b[n-1])
	}

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"strconv"
)
const (
	MAXN=int(1e5+7)
)
var a,b [MAXN] int64
var dp [MAXN][3] int64

func read() (int64, error) {
	b, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		return 0, err
	}
	// use strconv.ParseUint and strconv.ParseFloat in a similar way
	return strconv.ParseInt(string(b[:len(b)-1]), 10, 0)
}

func main(){
	input, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		return
	}
	inputReader := bytes.NewReader(input)
	var N int
	_,_=fmt.Fscanf(inputReader, "%d\n", &N)
	for i:=0 ;i<N-1;i++ {
		_,_=fmt.Fscanf(inputReader,"%d ",&a[i])
		//fmt.Println(a[i])
	}
	_,_=fmt.Fscanf(inputReader,"%d\n",&a[N-1])

	for i:=0;i<N-1;i++ {
		_,_=fmt.Fscanf(inputReader,"%d",&b[i])
		//fmt.Println(b[i])
	}
	_,_=fmt.Fscanf(inputReader,"%d\n",&b[N-1])
	//solve
	max:= func(a,b int64)int64 {
		if a>b{
			return a
		}else{
			return b
		}
	}

	for i:=1;i<=N;i++ {
		//00
		for j:=0;j<3;j++{
			dp[i][0]=max(dp[i][0],dp[i-1][j])
		}
		//01
		dp[i][1]=max(dp[i][1],dp[i-1][0]+b[i-1])//00
		dp[i][1]=max(dp[i][1],dp[i-1][2]+b[i-1])
		//10
		dp[i][2]=max(dp[i][2],dp[i-1][0]+a[i-1])
		dp[i][2]=max(dp[i][2],dp[i-1][1]+a[i-1])
		//11
		//fmt.Println(dp[i][0],dp[i][1],dp[i][2])
	}
	var ans int64=0
	for i:=0;i<3;i++ {
		ans=max(ans,dp[N][i])
	}
	fmt.Println(ans)

}

package main

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

var (
	n        int64
	students [2][100005]int64
	dp       [2][100005]int64
)

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

func recurse(row int64, idx int64) int64 {
	// fmt.Printf("row = %d, idx = %d\n", row, idx)
	if idx == n {
		return 0
	}
	if dp[row][idx] != -1 {
		return dp[row][idx]
	}
	dp[row][idx] = max(
		// include student row, idx
		students[row][idx]+recurse(1-row, idx+1),
		// do not include student row, idx
		recurse(row, idx+1),
	)
	return dp[row][idx]
}

func main() {
	var i, j int64
	in := bufio.NewReader(os.Stdin)

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

	for i = 0; i < 2; i++ {
		for j = 0; j < n; j++ {
			dp[i][j] = -1
		}
	}

	ans := max(recurse(0, 0), recurse(1, 0))
	fmt.Println(ans)
}

package main

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

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

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

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

	var n int64
	fmt.Fscanf(input, "%d\n", &n)

	hs := make([][]int64, 2)
	for i := range hs {
		for j := int64(0); j < n; j++ {
			var h int64
			fmt.Fscanf(input, "%d", &h)
			hs[i] = append(hs[i], h)
		}
		fmt.Fscanf(input, "\n")
	}

	dp := make([][]int64, 2)
	for i := range dp {
		dp[i] = make([]int64, n+1)
	}

	for i := int64(1); i <= n; i++ {
		dp[0][i] = max(dp[0][i-1], dp[1][i-1]+hs[0][i-1])
		dp[1][i] = max(dp[1][i-1], dp[0][i-1]+hs[1][i-1])
	}
	// fmt.Println(hs[0], hs[1], dp)
	fmt.Println(max(dp[0][n], dp[1][n]))
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int64, n)
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	fmt.Fscanf(in, "\n")
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &b[i])
	}
	fmt.Fscanf(in, "\n")
	f := make([][]int64, n)
	for i := 0; i < n; i++ {
		f[i] = make([]int64, 2)
	}
	f[0][0] = a[0]
	f[0][1] = b[0]
	maxa := a[0]
	maxb := b[0]
	for i := 1; i < n; i++ {
		f[i][0] = maxb + a[i]
		f[i][1] = maxa + b[i]
		if f[i][0] > maxa {
			maxa = f[i][0]
		}
		if f[i][1] > maxb {
			maxb = f[i][1]
		}
	}
	ans := maxa
	if maxb > ans {
		ans = maxb
	}
	fmt.Fprintf(out, "%d\n", ans)
	return
}

func gcd(a, b uint64) uint64 {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

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

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

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

func ok(a, b int) bool {
	if min(abs(a-b), abs(a+b)) <= min(abs(a), abs(b)) && max(abs(a+b), abs(a-b)) >= max(abs(a), abs(b)) {
		return true
	}
	return false
}

package main

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

func main() {
	defer out.Flush()
	n := ScanInt()
	h1 := ScanInts(n)
	h2 := ScanInts(n)

	dp := make([][2]int64, n+2)
	for i := 1; i <= n; i++ {
		dp[i][0] = Mx(dp[i-1][1]+int64(h2[i-1]), dp[i-1][0])
		dp[i][1] = Mx(dp[i-1][0]+int64(h1[i-1]), dp[i-1][1])
	}
	P(Mx(dp[n][0], dp[n][1]))
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int       { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func max(x, y int64) int64 {
	if x < y {
		return y
	}
	return x
}

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

	n := 0
	h := [2][100100]int64{}
	fmt.Fscanf(input, "%d\n", &n)
	for j := 0; j < 2; j++ {
		for i := 0; i < n; i++ {
			fmt.Fscanf(input, "%d", &h[j][i])
		}
		fmt.Fscanf(input, "\n")
	}

	ans0, ans1, ansx := int64(0), int64(0), int64(0)
	for i := n - 1; i >= 0; i-- {
		ans0, ans1, ansx = h[0][i]+max(ans1, ansx), h[1][i]+max(ans0, ansx), max(ans1, max(ans0, ansx))
		// fmt.Println(h[0][i], h[1][i], max(ans0, max(ans1, ansx)))
	}
	fmt.Println(max(ans0, max(ans1, ansx)))
}

// Author: sighduck
// URL: https://codeforces.com/contest/1195/problem/C

package main

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

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

func Solve(n int, h1 []int64, h2 []int64) int64 {
	if n == 1 {
		return max(h1[0], h2[0])
	}
	h1[1] += h2[0]
	h2[1] += h1[0]
	for i := 2; i < n; i++ {
		h1[i] += max(h2[i-1], h2[i-2])
		h2[i] += max(h1[i-1], h1[i-2])
	}
	return max(h1[n-1], h2[n-1])
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	h1 := make([]int64, n)
	h2 := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &h1[i])
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &h2[i])
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, h1, h2))
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"strconv"
)
const (
	MAXN=int(1e5+7)
)
var a,b [MAXN] int64
var dp [MAXN][3] int64

func read() (int64, error) {
	b, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		return 0, err
	}
	// use strconv.ParseUint and strconv.ParseFloat in a similar way
	return strconv.ParseInt(string(b[:len(b)-1]), 10, 0)
}

func main(){
	input, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		return
	}
	inputReader := bytes.NewReader(input)
	var N int
	_,_=fmt.Fscanf(inputReader, "%d\n", &N)
	for i:=0 ;i<N-1;i++ {
		_,_=fmt.Fscanf(inputReader,"%d ",&a[i])
		//fmt.Println(a[i])
	}
	_,_=fmt.Fscanf(inputReader,"%d ",&a[N-1])

	for i:=0;i<N-1;i++ {
		_,_=fmt.Fscanf(inputReader,"%d",&b[i])
		//fmt.Println(b[i])
	}
	_,_=fmt.Fscanf(inputReader,"%d ",&b[N-1])
	//solve
	max:= func(a,b int64)int64 {
		if a>b{
			return a
		}else{
			return b
		}
	}

	for i:=1;i<=N;i++ {
		//00
		for j:=0;j<3;j++{
			dp[i][0]=max(dp[i][0],dp[i-1][j])
		}
		//01
		dp[i][1]=max(dp[i][1],dp[i-1][0]+b[i-1])//00
		dp[i][1]=max(dp[i][1],dp[i-1][2]+b[i-1])
		//10
		dp[i][2]=max(dp[i][2],dp[i-1][0]+a[i-1])
		dp[i][2]=max(dp[i][2],dp[i-1][1]+a[i-1])
		//11
		//fmt.Println(dp[i][0],dp[i][1],dp[i][2])
	}
	var ans int64=0
	for i:=0;i<3;i++ {
		ans=max(ans,dp[N][i])
	}
	fmt.Println(ans)

}

package main

import "fmt"

var n int64
var students, dp [2][100005]int64

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

func recurse(row int64, idx int64) int64 {
	// fmt.Printf("row = %d, idx = %d\n", row, idx)
	if idx == n {
		return 0
	}
	if dp[row][idx] != -1 {
		return dp[row][idx]
	}
	dp[row][idx] = max(
		// include student row, idx
		students[row][idx]+recurse(1-row, idx+1),
		// do not include student row, idx
		recurse(row, idx+1),
	)
	return dp[row][idx]
}

func main() {

	var i, j int64
	fmt.Scanf("%d", &n)
	for i = 0; i < n; i++ {
		fmt.Scanf("%d", &students[0][i])
	}
	for i = 0; i < n; i++ {
		fmt.Scanf("%d", &students[1][i])
	}

	for i = 0; i < 2; i++ {
		for j = 0; j < n; j++ {
			dp[i][j] = -1
		}
	}
	ans := max(recurse(0, 0), recurse(1, 0))
	fmt.Println(ans)
}

package main

import "fmt"

var n int64
var students, dp [2][100005]int64

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

func recurse(row int64, idx int64) int64 {
	// fmt.Printf("row = %d, idx = %d\n", row, idx)
	if idx == n {
		return 0
	}
	if dp[row][idx] != -1 {
		return dp[row][idx]
	}
	dp[row][idx] = max(
		// include student row, idx
		students[row][idx]+recurse(1-row, idx+1),
		// do not include student row, idx
		recurse(row, idx+1),
	)
	return dp[row][idx]
}

func main() {

	var i, j int64
	fmt.Scanln(&n)
	for i = 0; i < n; i++ {
		fmt.Scanf("%d ", &students[0][i])
	}
	for i = 0; i < n; i++ {
		fmt.Scanf("%d ", &students[1][i])
	}

	for i = 0; i < 2; i++ {
		for j = 0; j < n; j++ {
			dp[i][j] = -1
		}
	}
	ans := max(recurse(0, 0), recurse(1, 0))
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"os"
)

var (
	n        int64
	students [2][100005]int64
	dp       [2][100005]int64
)

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

func recurse(row int64, idx int64) int64 {
	// fmt.Printf("row = %d, idx = %d\n", row, idx)
	if idx == n {
		return 0
	}
	if dp[row][idx] != -1 {
		return dp[row][idx]
	}
	dp[row][idx] = max(
		// include student row, idx
		students[row][idx]+recurse(1-row, idx+1),
		// do not include student row, idx
		recurse(row, idx+1),
	)
	return dp[row][idx]
}

func main() {

	var i, j int64
	fmt.Fscanf(os.Stdin, "%d", &n)
	for i = 0; i < n; i++ {
		fmt.Fscanf(os.Stdin, "%d", &students[0][i])
	}
	for i = 0; i < n; i++ {
		fmt.Fscanf(os.Stdin, "%d", &students[1][i])
	}

	for i = 0; i < 2; i++ {
		for j = 0; j < n; j++ {
			dp[i][j] = -1
		}
	}
	ans := max(recurse(0, 0), recurse(1, 0))
	fmt.Println(ans)
}

package main

import "fmt"

var n int64
var students, dp [2][100005]int64

// var dp [2][100005]int64

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

func recurse(row int64, idx int64) int64 {
	// fmt.Printf("row = %d\n idx = %d\n", row, idx)
	if idx == n {
		return 0
	}
	if dp[row][idx] != -1 {
		return dp[row][idx]
	}
	dp[row][idx] = max(
		// include student row, idx
		students[row][idx]+recurse(1-row, idx+1),
		// do not include student row, idx
		recurse(row, idx+1),
	)
	return dp[row][idx]
}

func main() {

	var i, j int64
	fmt.Scanf("%d\n", &n)
	for i = 0; i < n; i++ {
		fmt.Scanf("%d", &students[0][i])
	}
	for i = 0; i < n; i++ {
		fmt.Scanf("%d", &students[1][i])
	}

	for i = 0; i < 2; i++ {
		for j = 0; j < n; j++ {
			dp[i][j] = -1
		}
	}
	ans := max(recurse(0, 0), recurse(1, 0))
	fmt.Printf("%d\n", ans)
}

package main

import "fmt"

var n int
var students [2][100005]int
var dp [2][100005]int

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

func recurse(row int, idx int) int {
	// fmt.Printf("row = %d\n idx = %d\n", row, idx)
	if idx == n {
		return 0
	}
	if dp[row][idx] != -1 {
		return dp[row][idx]
	}
	ans := max(
		// include student row, idx
		students[row][idx]+recurse(1-row, idx+1),
		// do not include student row, idx
		recurse(row, idx+1),
	)
	dp[row][idx] = ans
	return ans
}

func main() {

	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &students[0][i])
	}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &students[1][i])
	}

	for i := 0; i < 2; i++ {
		for j := 0; j < n; j++ {
			dp[i][j] = -1
		}
	}
	ans := max(recurse(0, 0), recurse(1, 0))
	fmt.Printf("%d\n", ans)
}

package main

import "fmt"

var n int
var students [2][100005]int
var dp [2][100005]int

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

func recurse(row int, idx int) int {
	// fmt.Printf("row = %d\n idx = %d\n", row, idx)
	if idx == n {
		return 0
	}
	if dp[row][idx] != -1 {
		return dp[row][idx]
	}
	ans := max(
		// include student row, idx
		students[row][idx]+recurse(1-row, idx+1),
		// do not include student row, idx
		recurse(row, idx+1),
	)
	dp[row][idx] = ans
	return ans
}

func main() {

	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &students[0][i])
	}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &students[1][i])
	}

	for i := 0; i < 2; i++ {
		for j := 0; j < n; j++ {
			dp[i][j] = -1
		}
	}
	// fmt.Printf("n = %d\n", n)
	// for i := 0; i < n; i++ {
	// 	fmt.Printf("%d ", students[0][i])
	// }
	// fmt.Println()
	// for i := 0; i < n; i++ {
	// 	fmt.Printf("%d ", students[1][i])
	// }
	// fmt.Println()

	ans := max(recurse(0, 0), recurse(1, 0))
	fmt.Printf("%d\n", ans)
}

package main

import (
	"fmt"
)

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

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

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

	hs := make([][]int, 2)
	for i := range hs {
		for j := 0; j < n; j++ {
			var h int
			fmt.Scanf("%d", &h)
			hs[i] = append(hs[i], h)
		}
	}

	dp := make([][]int, 2)
	for i := range dp {
		dp[i] = make([]int, n+1)
	}

	for i := 1; i <= n; i++ {
		dp[0][i] = max(dp[0][i-1], dp[1][i-1]+hs[0][i-1])
		dp[1][i] = max(dp[1][i-1], dp[0][i-1]+hs[1][i-1])
	}
	// fmt.Println(hs[0], hs[1], dp)
	fmt.Println(max(dp[0][n], dp[1][n]))
}

package main

import (
	"fmt"
)

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

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

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

	hs := make([][]int, 2)
	for i := range hs {
		for j := 0; j < n; j++ {
			var h int
			fmt.Scanf("%d%c", &h)
			hs[i] = append(hs[i], h)
		}
	}

	dp := make([][]int, 2)
	for i := range dp {
		dp[i] = make([]int, n+1)
	}

	for i := 1; i <= n; i++ {
		dp[0][i] = max(dp[0][i-1], dp[1][i-1]+hs[0][i-1])
		dp[1][i] = max(dp[1][i-1], dp[0][i-1]+hs[1][i-1])
	}
	// fmt.Println(hs[0], hs[1], dp)
	fmt.Println(max(dp[0][n], dp[1][n]))
}

// Copyright (C) 2017 Kazumasa Kohtaka <kkohtaka@gmail.com> All right reserved
// This file is available under the MIT license.

package main

import (
	"fmt"
)

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

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

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

	hs := make([][]int, 2)
	for i := range hs {
		for j := 0; j < n; j++ {
			var h int
			fmt.Scanf("%d", &h)
			hs[i] = append(hs[i], h)
		}
	}

	dp := make([][]int, 2)
	for i := range dp {
		dp[i] = make([]int, n+1)
	}

	for i := 1; i <= n; i++ {
		dp[0][i] = max(dp[0][i-1], dp[1][i-1]+hs[0][i-1])
		dp[1][i] = max(dp[1][i-1], dp[0][i-1]+hs[1][i-1])
	}

	fmt.Println(max(dp[0][n], dp[1][n]))
}

// Copyright (C) 2017 Kazumasa Kohtaka <kkohtaka@gmail.com> All right reserved
// This file is available under the MIT license.

package main

import (
	"fmt"
	"math"
)

func solve(hs1, hs2 []int, max, idx, sum int) int {
	if idx == len(hs1) {
		return sum
	}
	x1 := hs1[idx]
	x2 := hs2[idx]
	var ans int
	if x1 < max {
		ans = solve(hs1, hs2, x1, idx+1, sum+x1)
	}
	if x2 < max {
		a := solve(hs1, hs2, x2, idx+1, sum+x2)
		if a > ans {
			ans = a
		}
	}
	a := solve(hs1, hs2, max, idx+1, sum)
	if a > ans {
		ans = a
	}
	return ans
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var hs1 []int
	for i := 0; i < n; i++ {
		var h int
		fmt.Scanf("%d", &h)
		hs1 = append(hs1, h)
	}
	var hs2 []int
	for i := 0; i < n; i++ {
		var h int
		fmt.Scanf("%d", &h)
		hs2 = append(hs2, h)
	}

	fmt.Println(solve(hs1, hs2, math.MaxInt32, 0, 0))
}

package main

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

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

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

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

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

	hs := make([][]int, 2)
	for i := range hs {
		for j := 0; j < n; j++ {
			var h int
			fmt.Fscanf(input, "%d", &h)
			hs[i] = append(hs[i], h)
		}
		fmt.Fscanf(input, "\n")
	}

	dp := make([][]int, 2)
	for i := range dp {
		dp[i] = make([]int, n+1)
	}

	for i := 1; i <= n; i++ {
		dp[0][i] = max(dp[0][i-1], dp[1][i-1]+hs[0][i-1])
		dp[1][i] = max(dp[1][i-1], dp[0][i-1]+hs[1][i-1])
	}
	// fmt.Println(hs[0], hs[1], dp)
	fmt.Println(max(dp[0][n], dp[1][n]))
}

package main

import (
	"fmt"
)

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

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

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

	hs := make([][]int, 2)
	for i := range hs {
		for j := 0; j < n; j++ {
			var h int
			fmt.Scanf("%d", &h)
			hs[i] = append(hs[i], h)
		}
	}

	dp := make([][]int, 2)
	for i := range dp {
		dp[i] = make([]int, n+1)
	}

	for i := 1; i <= n; i++ {
		dp[0][i] = max(dp[0][i-1], dp[1][i-1]+hs[0][i-1])
		dp[1][i] = max(dp[1][i-1], dp[0][i-1]+hs[1][i-1])
	}
	fmt.Println(hs[0], hs[1], dp)
	fmt.Println(max(dp[0][n], dp[1][n]))
}

package main

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

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

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

	n := 0
	h := [2][100100]int{}
	fmt.Fscanf(input, "%d\n", &n)
	for j := 0; j < 2; j++ {
		for i := 0; i < n; i++ {
			fmt.Fscanf(input, "%d ", &h[j][i])
		}
	}

	ans0, ans1, ansx := 0, 0, 0
	for i := n - 1; i >= 0; i-- {
		ans0, ans1, ansx = h[0][i]+max(ans1, ansx), h[1][i]+max(ans0, ansx), max(ans1, max(ans0, ansx))
		// fmt.Println(h[0][i], h[1][i], max(ans0, max(ans1, ansx)))
	}
	fmt.Println(max(ans0, max(ans1, ansx)))
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
func max(i, j int) int {
    if i > j {
        return i
    }
    return j
}
func main() {
	input := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 100500)
	input.Buffer(buf, 100500)
	input.Split(bufio.ScanWords)

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
    h := [2][100100]int {}
    ans0, ans1, ans3 := 0, 0, 0

    for j := 0; j < 2; j ++ {
        for i := 0; i < n; i ++ {
            input.Scan()
            x, _ := strconv.Atoi(input.Text())
            h[j][i] = x
        }
    }
    for i := n - 1; i >= 0; i -- {
        cur_ans0, cur_ans1, cur_ans3 := max(h[0][i] + ans1, h[0][i] + ans3), max(h[1][i] + ans0, h[1][i] + ans3), max(ans1, ans0)
        ans0 = max(cur_ans0, ans0)
        ans1 = max(cur_ans1, ans1)
        ans3 = max(cur_ans3, ans3)
    }
    fmt.Println(max(ans0, max(ans3, ans1)))
}

package main

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

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

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

	n := 0
	h := [2][100100]int{}
	fmt.Fscanf(input, "%d\n", &n)
	for j := 0; j < 2; j++ {
		for i := 0; i < n; i++ {
			fmt.Fscanf(input, "%d", &h[j][i])
		}
		fmt.Fscanf(input, "\n")
	}

	ans0, ans1, ansx := 0, 0, 0
	for i := n - 1; i >= 0; i-- {
		ans0, ans1, ansx = h[0][i]+max(ans1, ansx), h[1][i]+max(ans0, ansx), max(ans1, max(ans0, ansx))
		// fmt.Println(h[0][i], h[1][i], max(ans0, max(ans1, ansx)))
	}
	fmt.Println(max(ans0, max(ans1, ansx)))
}

package main

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

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

func main() {
	input := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 100500)
	input.Buffer(buf, 100500)
	input.Split(bufio.ScanWords)

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	h := [2][100100]int{}
	for j := 0; j < 2; j++ {
		for i := 0; i < n; i++ {
			input.Scan()
			x, _ := strconv.Atoi(input.Text())
			h[j][i] = x
		}
	}
	ans0, ans1, ansx := 0, 0, 0
	for i := n - 1; i >= 0; i-- {
		ans0, ans1, ansx = h[0][i]+max(ans1, ansx), h[1][i]+max(ans0, ansx), max(ans1, max(ans0, ansx))
	}
	fmt.Println(max(ans0, max(ans1, ansx)))
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
func max(i, j int) int {
    if i > j {
        return i
    }
    return j
}
func main() {
	input := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 10000003)
	input.Buffer(buf, 10000003)
	input.Split(bufio.ScanWords)

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
    h := [2][100100]int {}
    ans0, ans1, ans3 := 0, 0, 0

    for j := 0; j < 2; j ++ {
        for i := 0; i < n; i ++ {
            input.Scan()
            x, _ := strconv.Atoi(input.Text())
            h[j][i] = x
        }
    }
    for i := n - 1; i >= 0; i -- {
        cur_ans0, cur_ans1, cur_ans3 := max(h[0][i] + ans1, h[0][i] + ans3), max(h[1][i] + ans0, h[1][i] + ans3), max(ans1, ans0)
        ans0 = max(cur_ans0, ans0)
        ans1 = max(cur_ans1, ans1)
        ans3 = max(cur_ans3, ans3)
    }
    fmt.Println(max(ans0, max(ans3, ans1)))
}

package main

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

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

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

	n := 0
	h := [2][100100]int{}
	fmt.Fscanf(input, "%d\n", &n)
	for j := 0; j < 2; j++ {
		for i := 0; i < n; i++ {
			fmt.Fscanf(input, "%d", &h[j][i])
		}
		fmt.Fscanf(input, "\n")
	}

	ans0, ans1, ansx := int(0), int(0), int(0)
	for i := n - 1; i >= 0; i-- {
		ans0, ans1, ansx = h[0][i]+max(ans1, ansx), h[1][i]+max(ans0, ansx), max(ans1, max(ans0, ansx))
		// fmt.Println(h[0][i], h[1][i], max(ans0, max(ans1, ansx)))
	}
	fmt.Println(max(ans0, max(ans1, ansx)))
}

package main

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

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

func main() {
	input := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 100500)
	input.Buffer(buf, 100500)
	input.Split(bufio.ScanWords)

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	h := [2][100100]int{}
	for j := 0; j < 2; j++ {
		for i := 0; i < n; i++ {
			input.Scan()
			x, err := strconv.Atoi(input.Text())
			if err != nil {
				os.Exit(-1)
			}
			h[j][i] = x
		}
	}
	ans0, ans1, ansx := 0, 0, 0
	for i := n - 1; i >= 0; i-- {
		ans0, ans1, ansx = h[0][i]+max(ans1, ansx), h[1][i]+max(ans0, ansx), max(ans1, max(ans0, ansx))
		// fmt.Println(h[0][i], h[1][i], max(ans0, max(ans1, ansx)))
	}
	fmt.Println(max(ans0, max(ans1, ansx)))
}


If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.  However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.  You have met a cat. Can you figure out whether it's normal or grumpy?

NotePlease make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.

package main

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

var cs map[int]int = make(map[int]int)

func Init() {}
func Solve(io *FastIO) {
	var s string
	var grumpy = "don't even  are you serious?  worse  terrible  go die in a hole  no way"
	var normal = "great!  don't think so  not bad  don't touch me!  cool"
	for i := 0; i < 10; i++ {
		io.Println(i)
		io.FlushOutput()
		s = io.NextLine()
		if s == "no" {
			continue
		}
		if out := strings.Index(grumpy, s); out != -1 {
			io.Println("grumpy")
			return
		} else if out := strings.Index(normal, s); out != -1 {
			io.Println("normal")
			return
		}
	}
}

type FastIO struct {
	//by megaspazz
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}
func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = res*10 + int(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = int64(-1)
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = res*10 + int64(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}
func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt() + 1
	}
	return arr
}
func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}
func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}
func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}
func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}
func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}
func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}
func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}
func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

//http://codeforces.com/problemset/problem/952/B

package main

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

type catType string

const (
	unknown catType = "none"
	normal  catType = "normal"
	grumpy  catType = "grumpy"
)

func main() {
	interactionArray := make([]string, 10)
	var res catType
	for i := 0; i < 10; i++ {
		interactionArray = pet(i, interactionArray)
		res = evaluateCatType(interactionArray)
		if res != unknown {
			break
		}
	}
	fmt.Println(res)
}

func pet(area int, interactionArray []string) []string {
	in := bufio.NewReader(os.Stdin)
	fmt.Println(area)
	catResponse, err := in.ReadString('\n')
	if err == nil {
		interactionArray[area] = strings.TrimSpace(catResponse)
	}
	return interactionArray
}

func evaluateCatType(interactionArray []string) catType {
	negativeResponses := 0
	for i := 0; i < len(interactionArray); i++ {
		interaction := interactionArray[i]

		switch interaction {
		case "no":
			negativeResponses++
		case "terrible":
			return grumpy
		case "worse":
			return grumpy
		case "are you serious?":
			return grumpy
		case "don't even":
			return grumpy
		case "go die in a hole":
			return grumpy
		case "no way":
			return grumpy
		case "cool":
			return normal
		case "not bad":
			return normal
		case "don't touch me!":
			return normal
		case "don't think so":
			return normal
		case "great!":
			return normal
		default:
			break
		}

		if negativeResponses > 3 {
			return normal
		}
	}

	return unknown
}

package main

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

var cs map[int]int = make(map[int]int)

func Init() {}
func Solve(io *FastIO) {
	var s string
	var grumpy = "don't even  are you serious?  worse  terrible  go die in a hole  no way"
	var normal = "great!  don't think so  not bad  don't touch me!  cool"
	for i := 0; i < 10; i++ {
		io.Println(i)
		io.FlushOutput()
		s = io.NextString()
		if s == "no" {
			continue
		}
		if out := strings.Index(grumpy, s); out != -1 {
			io.Println("grumpy")
			return
		} else if out := strings.Index(normal, s); out != -1 {
			io.Println("normal")
			return
		}
	}
}

type FastIO struct {
	//by megaspazz
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}
func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = res*10 + int(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = int64(-1)
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = res*10 + int64(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}
func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt() + 1
	}
	return arr
}
func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}
func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}
func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}
func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}
func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}
func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}
func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}
func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

var cs map[int]int = make(map[int]int)

func Init() {}
func Solve(io *FastIO) {
	var s string
	var grumpy = "don't even  are you serious?  worse  terrible  go die in a hole  no way"
	var normal = "great!  don't think so  not bad  don't touch me!  cool"
	for i := 0; i < 10; i++ {
		io.Println(i)
		io.FlushOutput()
		s = io.NextString()
		io.FlushOutput()
		if s == "no" {
			continue
		}
		if out := strings.Index(grumpy, s); out != -1 {
			io.Println("grumpy")
			return
		} else if out := strings.Index(normal, s); out != -1 {
			io.Println("normal")
			return
		}
	}
}

type FastIO struct {
	//by megaspazz
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}
func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = res*10 + int(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = int64(-1)
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = res*10 + int64(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}
func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt() + 1
	}
	return arr
}
func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}
func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}
func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}
func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}
func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}
func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}
func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}
func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}