You are given an array $$$a$$$ that contains $$$n$$$ integers. You can choose any proper subsegment $$$a_l, a_{l + 1}, \ldots, a_r$$$ of this array, meaning you can choose any two integers $$$1 \le l \le r \le n$$$, where $$$r - l + 1 < n$$$. We define the beauty of a given subsegment as the value of the following expression:$$$$$$\max(a_{1}, a_{2}, \ldots, a_{l-1}, a_{r+1}, a_{r+2}, \ldots, a_{n}) - \min(a_{1}, a_{2}, \ldots, a_{l-1}, a_{r+1}, a_{r+2}, \ldots, a_{n}) + \max(a_{l}, \ldots, a_{r}) - \min(a_{l}, \ldots, a_{r}).$$$$$$Please find the maximum beauty among all proper subsegments.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Then follow the descriptions of each test case. The first line of each test case contains a single integer $$$n$$$ $$$(4 \leq n \leq 10^5)$$$ — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_{i} \leq 10^9$$$) — the elements of the given array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each testcase print a single integer — the maximum beauty of a proper subsegment.

NoteIn the first test case, the optimal segment is $$$l = 7$$$, $$$r = 8$$$. The beauty of this segment equals to $$$(6 - 1) + (5 - 1) = 9$$$.In the second test case, the optimal segment is $$$l = 2$$$, $$$r = 4$$$. The beauty of this segment equals $$$(100 - 2) + (200 - 1) = 297$$$.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] <= a[j]
		})
		fmt.Println(a[n-1] + a[n-2] - a[0] - a[1])
		t--
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
    "sort"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		a:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&a[j])
		}
		sort.Ints(a)
		fmt.Fprintln(out,a[n-1]+a[n-2]-a[0]-a[1])
	}
}

// find add two largest elements and subtract two lowest elements

package main

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

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

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

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

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

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

/**
Run solve the problem CF1720B
Date: 8/24/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1720/B
Problem: CF1720B
**/
func (in *CF1720B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, 4)
		arr[0] = in.NextInt()
		arr[1] = in.NextInt()
		arr[2] = in.NextInt()
		arr[3] = in.NextInt()
		sort.Ints(arr)
		for i := 4; i < n; i++ {
			val := in.NextInt()
			if val < arr[1] {
				arr[1] = val
			} else if val < arr[0] {
				arr[0] = val
			}

			if val > arr[2] {
				arr[2] = val
			} else if val > arr[3] {
				arr[3] = val
			}
			sort.Ints(arr)
		}
		fmt.Println(arr[3] + arr[2] - arr[1] - arr[0])
	}
}

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

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

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int, a []int) int {
	sort.Ints(a)
	return a[n-1] + a[n-2] - a[0] - a[1]
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}

		fmt.Println(solve(n, a))
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var n int
	scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	sort.Slice(a, func(i, j int) bool {
		return a[i] < a[j]
	})
	result := a[n-1] + a[n-2] - a[0] - a[1]
	printf("%d\n", result)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)
		a, b, c, d := 0, 0, math.MaxInt32, math.MaxInt32
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v > a {
				a, b = v, a
			} else if v > b {
				b = v
			}
			if v < c {
				c, d = v, c
			} else if v < d {
				d = v
			}
		}

		fmt.Fprintln(out, (a-c)+(b-d))
	}
}

package main

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

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

	var t int
	Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		Fprintln(out, a[1] + a[0] - a[n - 2] - a[n - 1])
	}
}

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

package main

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

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

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

// func min3(a, b, c int) int {
// 	return min(min(a, b), c)
// }

// func maxSquare(a int) int {
// 	tmp := int(math.Sqrt(float64(a)))
// 	if tmp*tmp == a {
// 		return tmp * tmp
// 	} else {
// 		return (tmp + 1) * (tmp + 1)
// 	}
// }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(in, &n)
		slc := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &slc[i])
		}
		MAX := 1000000001
		MIN := -1
		min1 := MAX
		min2 := MAX
		max1 := MIN
		max2 := MIN
		for i := 0; i < n; i++ {
			if slc[i] < min1 {
				min2 = min1
				min1 = slc[i]
			} else {
				if slc[i] < min2 {
					min2 = slc[i]
				}
			}
			if slc[i] > max1 {
				max2 = max1
				max1 = slc[i]
			} else {
				if slc[i] > max2 {
					max2 = slc[i]
				}
			}
		}
		fmt.Fprintln(out, max1+max2-min1-min2)
	}
}

package main

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

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

func slove() {
	var n int
	fmt.Fscan(rr, &n)
	nums := make([]int, n)
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
	}
	sort.Ints(nums)
	fmt.Fprintln(ww, nums[n-1]+nums[n-2]-nums[0]-nums[1])
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		n := readInt(input)
		arr := readArrInt(input)
		fmt.Println(solve(n, arr))
	}
}

func solve(n int, arr []int) int {
	sort.Ints(arr)
	return arr[n-1] + arr[n-2] - arr[0] - arr[1]
}

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 readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	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"
	"sort"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] <= a[j]
		})
		fmt.Println(a)
		fmt.Println(a[n-1] + a[n-2] - a[0] - a[1])
		t--
	}
}


Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length.Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100).

Print the single number — the maximum number of frames Nicholas can make for his future canvases.

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

func main() {
	var a,b,d int
	fmt.Scan(&a)
	c:=make([]int,101)
	for i:=0;i<a;i++ {
		fmt.Scan(&b)
		c[b]++
		if c[b]%2==0 {
			d++
		}
	}
	d/=2
	fmt.Println(d)
}

package main

import "fmt"

func main() {
    var n,a int
    var f [101]int
    fmt.Scan(&n)
    cnt := 0
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        f[a]++
        if f[a] == 2 {
            cnt++
            f[a] = 0
        }
    }
    fmt.Println(cnt/2)
}

// 127B-mic
package main

import (
	"fmt"
)

func main() {
	var a [3333]int
	var n, c, b, q int
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		fmt.Scan(&b)
		a[b]++
	}
	for i := 1; i <= 100; i++ {
		c += a[i] / 4
		a[i] = a[i] % 4
	}
	for i := 1; i <= 100; i++ {
		if a[i] > 1 {
			q++
		}
	}
	c += q / 2
	fmt.Println(c)
}


You are given $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$. With a cost of one coin you can perform the following operation:Choose one of these numbers and add or subtract $$$1$$$ from it.In particular, we can apply this operation to the same number several times.We want to make the product of all these numbers equal to $$$1$$$, in other words, we want $$$a_1 \cdot a_2$$$ $$$\dots$$$ $$$\cdot a_n = 1$$$. For example, for $$$n = 3$$$ and numbers $$$[1, -3, 0]$$$ we can make product equal to $$$1$$$ in $$$3$$$ coins: add $$$1$$$ to second element, add $$$1$$$ to second element again, subtract $$$1$$$ from third element, so that array becomes $$$[1, -1, -1]$$$. And $$$1\cdot (-1) \cdot (-1) = 1$$$.What is the minimum cost we will have to pay to do that?

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of numbers. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the numbers.

Output a single number — the minimal number of coins you need to pay to make the product equal to $$$1$$$.

NoteIn the first example, you can change $$$1$$$ to $$$-1$$$ or $$$-1$$$ to $$$1$$$ in $$$2$$$ coins.In the second example, you have to apply at least $$$4$$$ operations for the product not to be $$$0$$$.In the third example, you can change $$$-5$$$ to $$$-1$$$ in $$$4$$$ coins, $$$-3$$$ to $$$-1$$$ in $$$2$$$ coins, $$$5$$$ to $$$1$$$ in $$$4$$$ coins, $$$3$$$ to $$$1$$$ in $$$2$$$ coins, $$$0$$$ to $$$1$$$ in $$$1$$$ coin.

package main

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

/* solution */

func solve() {

	n := readInt()
	ans := int64(0)
	positive := true
	hasZero := false
	for i := 0; i < n; i++ {
		v := readInt()
		if v == 0 {
			ans++
			hasZero = true
		} else if v < 0 {
			ans += int64(-v - 1)
			positive = !positive
		} else {
			ans += int64(v - 1)
		}
	}

	if positive || hasZero {
		printInt(ans)
	} else {
		printInt(ans + 2)
	}

}

/* 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)
	reader.Split(bufio.ScanWords)

	solve()

}

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

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 int64) {
	print(strconv.FormatInt(i, 10))
}

package main

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

func main() {
	var q, x, res int64

	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &q)
	n := make([]int64, 0)
	p := make([]int64, 0)

	for i := int64(0); i < q; i++ {
		fmt.Fscanf(scr, "%d", &x)
		if x < 0 {
			n = append(n, x)
		} else if x > 0 {
			p = append(p, x)
		} else {
			res++
		}
	}

	if len(n)%2 != 0 && len(n) > 0 {

		if res == 0 {
			res += (1 - n[0])
			for i := int64(1); i < int64(len(n)); i++ {
				res += (-1 - n[i])
			}
		} else if res > 0 {
			for i := int64(0); i < int64(len(n)); i++ {
				res += (-1 - n[i])
			}
		}

		for i := int64(0); i < int64(len(p)); i++ {
			res += (p[i] - 1)
		}
	} else {
		for i := int64(0); i < int64(len(n)); i++ {
			res += (-1 - n[i])
		}

		for i := int64(0); i < int64(len(p)); i++ {
			res += (p[i] - 1)
		}
	}

	fmt.Println(res)

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n, a, result, zero, minus int64
	fmt.Fscan(in, &n)
	for i := int64(0); i < n; i++ {
		fmt.Fscan(in, &a)
		switch {
		case a > 0:
			result += a - 1
		case a < 0:
			result += -1 - a
			minus += 1
		default:
			zero += 1
		}
	}
	if zero > 0 {
		result += zero
	} else if minus%2 == 1 {
		result += 2
	}
	fmt.Println(result)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func nextInt() int64 {
	in.Scan()
	var r, f int64
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int64(c - '0')
	}
	return r * f
}

func main() {
	in.Split(bufio.ScanWords)
	var r, numN int64
	hasZ := false
	for n := nextInt(); n > 0; n-- {
		a := nextInt()
		switch {
		case a < 0:
			numN++
			r += -1 - a
		case a > 0:
			r += a - 1
		default:
			r++
			hasZ = true
		}
	}
	if numN%2 != 0 && !hasZ {
		r += 2
	}
	fmt.Println(r)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscan(reader, &n)
	var ans int64 = 0
	var cnt0 int = 0
	var ret int = 1
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(reader, &x)
		if x > 0 {
			ans += int64(x - 1)
		} else {
			if x < 0 {
				ans += int64(-x - 1)
				ret = -ret
			} else {
				cnt0 += 1
			}
		}
	}
	if ret == 1 {
		ans += int64(cnt0)
	} else {
		if cnt0 > 0 {
			ans += int64(cnt0)
		} else {
			ans += 2
		}
	}
	fmt.Fprintf(writer, "%v\n", ans)
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

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

//str := PrintlnInts(X...)

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

func main() {
	n := ReadInt()
	a := ReadIntSlice(n)
	ans := int64(0)
	zeroFlag := false
	parity := 0
	for _, v := range a {
		if v == 0 {
			ans += 1
			zeroFlag = true
		} else if v >= 1 {
			ans += int64(v - 1)
		} else if v <= -1 {
			ans += int64(-v - 1)
			parity++
		}
	}

	if zeroFlag {
		fmt.Println(ans)
		return
	}
	if parity%2 == 1 {
		ans += int64(2)
	}
	fmt.Println(ans)
}

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

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

func _gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return _gcd(b, a%b)
}

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9))
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

func readInt64() int64 {
	return readIntNbits(64)
}

func readInt() int {
	return int(readIntNbits(32))
}

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

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

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

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

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

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

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

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

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

	return string(res)
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	ints := make([]int, n)
	var negCount int
	var minCost int64
	var zeroCount int
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &ints[i])
		if ints[i] < 0 {
			negCount++
			minCost += (int64(math.Abs(float64(ints[i]))) - 1)
		} else if ints[i] > 0 {
			minCost += int64(ints[i] - 1)
		} else {
			minCost += 1
			zeroCount += 1
		}
	}
	if negCount%2 == 1 && zeroCount == 0 {
		minCost += 2
	}
	fmt.Printf("%d", minCost)
}

package main

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

func main() {
	var n int64
	fmt.Scan(&n)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var ans, cm, cz int64
	for i := int64(0); i < n; i++ {
		sc.Scan()
		a, _ := strconv.ParseInt(sc.Text(), 10, 64)
		if a > 0 {
			ans += a - 1
		} else if a < 0 {
			ans += -1 - a
			cm++
		} else {
			ans += 1
			cz++
		}
	}
	if cz == 0 && cm%2 == 1 {
		ans += 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()

	n := readi()
	a := make([]int64, n)
	for i := range a {
		a[i] = readll()
	}
	dp := make([][2]int64, n+1)
	dp[0][1] = INF
	for i := range a {
		d0 := absll(1 - a[i])
		d1 := absll(-1 - a[i])
		dp[i+1][0] = minll(dp[i][0]+d0, dp[i][1]+d1)
		dp[i+1][1] = minll(dp[i][0]+d1, dp[i][1]+d0)
	}
	println(dp[n][0])
}

package main

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

func main() {
	inputCount := ScanInt64()
	inputArray := ScanInt64Slice(inputCount)
	answer, sum , k := int64(0), int64(0), int64(0)

	for i := int64(0); i < inputCount; i++{
		if inputArray[i] == 0{
			sum++
		}else if inputArray[i] < 0{
			answer += - 1 - inputArray[i]
			k++
		}else{
			answer += inputArray[i] - 1
		}
	}

	if sum > 0{
		answer += sum
	}else if k % 2 != 0 {
		answer += 2
	}

	P(answer)
	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int64) []int64 {
	arr := make([]int64, n)
	for i := int64(0); i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, 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 sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

// Author: sighduck
// URL: https://codeforces.com/contest/1206/problem/B

package main

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

func Solve(a []int64) int64 {
	coins := int64(0)
	zeros := 0
	negatives := 0
	for _, elem := range a {
		if elem >= 1 {
			coins += int64(elem - 1)
		} else if elem <= -1 {
			coins += int64(-elem - 1)
			negatives += 1
		} else if elem == 0 {
			zeros += 1
		}
	}
	if zeros > 0 {
		return coins + int64(zeros)
	} else if negatives%2 == 1 {
		return coins + int64(2)
	}
	return coins
}

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

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

package main

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

/* solution */

func solve() {

	n := readInt()
	ans := 0
	positive := true
	hasZero := false
	for i := 0; i < n; i++ {
		v := readInt()
		if v == 0 {
			ans++
			hasZero = true
		} else if v < 0 {
			ans += -v - 1
			positive = !positive
		} else {
			ans += v - 1
		}
	}

	if positive || hasZero {
		printInt(ans)
	} else {
		printInt(ans + 2)
	}

}

/* 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)
	reader.Split(bufio.ScanWords)

	solve()

}

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

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

package main

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

func main() {
	var q, x, res int

	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &q)
	n := make([]int, 0)
	p := make([]int, 0)

	for i := 0; i < q; i++ {
		fmt.Fscanf(scr, "%d", &x)
		if x < 0 {
			n = append(n, x)
		} else if x > 0 {
			p = append(p, x)
		} else {
			res++
		}
	}

	if len(n)%2 != 0 && len(n) > 0 {

		if res == 0 {
			res += (-1 - n[0]) + 2
			for i := 1; i < len(n); i++ {
				res += (-1 - n[i])
			}
		} else {
			for i := 0; i < len(n); i++ {
				res += (-1 - n[i])
			}
		}

		for i := 0; i < len(p); i++ {
			res += (p[i] - 1)
		}
	} else {
		for i := 0; i < len(n); i++ {
			res += (-1 - n[i])
		}

		for i := 0; i < len(p); i++ {
			res += (p[i] - 1)
		}
	}

	fmt.Println(res)

}

package main

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

func main() {
	var q, x, res int

	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &q)
	n := make([]int, 0)
	p := make([]int, 0)

	for i := 0; i < q; i++ {
		fmt.Fscanf(scr, "%d", &x)
		if x < 0 {
			n = append(n, x)
		} else if x > 0 {
			p = append(p, x)
		} else {
			res++
		}
	}

	if len(n)%2 != 0 && len(n) > 0 {
		res += (-1 - n[0]) + 2
		for i := 1; i < len(n); i++ {
			res += (-1 - n[i])
		}
		for i := 0; i < len(p); i++ {
			res += (p[i] - 1)
		}
	} else {
		for i := 0; i < len(n); i++ {
			res += (-1 - n[i])
		}

		for i := 0; i < len(p); i++ {
			res += (p[i] - 1)
		}
	}

	fmt.Println(res)

}

package main

import "fmt"

func main() {
	var n, a, result, zero, minus int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		switch {
		case a > 0:
			result += a - 1
		case a < 0:
			result += -1 - a
			minus += 1
		default:
			zero += 1
		}
	}
	if zero > 0 {
		result += zero
	} else if minus%2 == 1 {
		result += 2
	}
	fmt.Println(result)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func nextInt() int {
	in.Scan()
	r, f := 0, 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

func main() {
	in.Split(bufio.ScanWords)
	r, numN, hasZ := 0, 0, false
	for n := nextInt(); n > 0; n-- {
		a := nextInt()
		switch {
		case a < 0:
			numN++
			r += -1 - a
		case a > 0:
			r += a - 1
		default:
			r++
			hasZ = true
		}
	}
	if numN%2 != 0 && !hasZ {
		r += 2
	}
	fmt.Println(r)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscan(reader, &n)
	var ans int64 = 0
	var cnt0 int = 0
	var ret int = 1
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		if x > 0 {
			ans += int64(x - 1)
		} else {
			if x < 0 {
				ans += int64(-x - 1)
				ret = -ret
			} else {
				cnt0 += 1
			}
		}
	}
	if ret == 1 {
		ans += int64(cnt0)
	} else {
		if cnt0 > 0 {
			ans += int64(cnt0)
		} else {
			ans += 2
		}
	}
	fmt.Fprintf(writer, "%v\n", ans)
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

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

//str := PrintlnInts(X...)

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

func main() {
	n := ReadInt()
	a := ReadIntSlice(n)
	ans := 0
	zeroFlag := false
	parity := 0
	for _, v := range a {
		if v == 0 {
			ans += 1
			zeroFlag = true
		} else if v >= 1 {
			ans += v - 1
		} else if v <= -1 {
			ans += -v - 1
			parity++
		}
	}

	if zeroFlag {
		fmt.Println(ans)
		return
	}
	if parity%2 == 1 {
		ans += 2
	}
	fmt.Println(ans)
}

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

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

func _gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return _gcd(b, a%b)
}

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9))
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

func readInt64() int64 {
	return readIntNbits(64)
}

func readInt() int {
	return int(readIntNbits(32))
}

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

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

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

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

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

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

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

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

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

	return string(res)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	ints := make([]int, n)
	var negCount int
	var minCost int
	var zeroCount int
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &ints[i])
		if ints[i] < 0 {
			negCount++
			minCost += (int(math.Abs(float64(ints[i])) - 1))
		} else if ints[i] > 0 {
			minCost += (ints[i] - 1)
		} else {
			minCost += 1
			zeroCount += 1
		}
	}
	if negCount%2 == 1 && zeroCount == 0 {
		minCost += 2
	}
	fmt.Printf("%d", minCost)
}

package main

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

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

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var ans, cm, cz int
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		if a > 0 {
			ans += a - 1
		} else if a < 0 {
			ans += -1 - a
			cm++
		} else {
			ans += 1
			cz++
		}
	}
	if cz == 0 && cm%2 == 1 {
		ans += 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()

	n := readi()
	a := make([]int, n)
	for i := range a {
		a[i] = readi()
	}
	dp := make([][2]int, n+1)
	dp[0][1] = INF
	for i := range a {
		d0 := abs(1 - a[i])
		d1 := abs(-1 - a[i])
		dp[i+1][0] = min(dp[i][0]+d0, dp[i][1]+d1)
		dp[i+1][1] = min(dp[i][0]+d1, dp[i][1]+d0)
	}
	println(dp[n][0])
}

package main

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

func main() {
	inputCount := ScanInt()
	inputArray := ScanIntSlice(inputCount)
	answer, sum , k := 0, 0, 0

	for i := 0; i < inputCount; i++{
		if inputArray[i] == 0{
			sum++
		}else if inputArray[i] < 0{
			answer += - 1 - inputArray[i]
			k++
		}else{
			answer += inputArray[i] - 1
		}
	}

	if sum > 0{
		answer += sum
	}else if k % 2 != 0 {
		answer += 2
	}

	P(answer)
	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, 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 sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	inputCount := ScanInt()
	inputArray := ScanIntSlice(inputCount)
	answer, sum , k := 0, 0, 0

	for i := 0; i < inputCount; i++{
		if inputArray[i] == 0{
			sum++
		}else if inputArray[i] < 0{
			answer += - 1 - inputArray[i]
			k++
		}else{
			answer += inputArray[i] - 1
		}
	}

	if sum > 0{
		answer += sum
	}else if k % 2 == 0 {
		answer += 2
	}

	P(answer)
	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, 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 sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

// Author: sighduck
// URL: https://codeforces.com/contest/1206/problem/B

package main

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

func Solve(a []int) int {
	coins := 0
	zeros := 0
	negatives := 0
	for _, elem := range a {
		if elem >= 1 {
			coins += elem - 1
		} else if elem <= -1 {
			coins += -elem - 1
			negatives += 1
		} else if elem == 0 {
			zeros += 1
		}
	}
	if zeros > 0 {
		return coins + zeros
	} else if negatives%2 == 1 {
		return coins + 2
	}
	return coins
}

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

	var n int
	fmt.Fscan(reader, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
	}
	fmt.Fprintf(writer, "%d\n", Solve(a))
}


You are organizing a boxing tournament, where $$$n$$$ boxers will participate ($$$n$$$ is a power of $$$2$$$), and your friend is one of them. All boxers have different strength from $$$1$$$ to $$$n$$$, and boxer $$$i$$$ wins in the match against boxer $$$j$$$ if and only if $$$i$$$ is stronger than $$$j$$$.The tournament will be organized as follows: $$$n$$$ boxers will be divided into pairs; the loser in each pair leaves the tournament, and $$$\frac{n}{2}$$$ winners advance to the next stage, where they are divided into pairs again, and the winners in all pairs advance to the next stage, and so on, until only one boxer remains (who is declared the winner).Your friend really wants to win the tournament, but he may be not the strongest boxer. To help your friend win the tournament, you may bribe his opponents: if your friend is fighting with a boxer you have bribed, your friend wins even if his strength is lower.Furthermore, during each stage you distribute the boxers into pairs as you wish.The boxer with strength $$$i$$$ can be bribed if you pay him $$$a_i$$$ dollars. What is the minimum number of dollars you have to spend to make your friend win the tournament, provided that you arrange the boxers into pairs during each stage as you wish?

The first line contains one integer $$$n$$$ ($$$2 \le n \le 2^{18}$$$) — the number of boxers. $$$n$$$ is a power of $$$2$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$, where $$$a_i$$$ is the number of dollars you have to pay if you want to bribe the boxer with strength $$$i$$$. Exactly one of $$$a_i$$$ is equal to $$$-1$$$ — it means that the boxer with strength $$$i$$$ is your friend. All other values are in the range $$$[1, 10^9]$$$.

Print one integer — the minimum number of dollars you have to pay so your friend wins.

NoteIn the first test case no matter how you will distribute boxers into pairs, your friend is the strongest boxer and anyway wins the tournament.In the second test case you can distribute boxers as follows (your friend is number $$$2$$$):$$$1 : 2, 8 : 5, 7 : 3, 6 : 4$$$ (boxers $$$2, 8, 7$$$ and $$$6$$$ advance to the next stage);$$$2 : 6, 8 : 7$$$ (boxers $$$2$$$ and $$$8$$$ advance to the next stage, you have to bribe the boxer with strength $$$6$$$);$$$2 : 8$$$ (you have to bribe the boxer with strength $$$8$$$);

package main

import (
	"bufio"
	"container/heap"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"runtime"
	"strconv"
)

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

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

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

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

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

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

type IntHeap []int64

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int64))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func solve() {
	n := ReadInt()
	a := ReadInt64Slice(n)
	p := &IntHeap{}
	heap.Init(p)
	sum := int64(0)
	for i := (n - 1); a[i] > 0 && i >= 0; i-- {
		heap.Push(p, a[i])
		if i&(i+1) == 0 {
			e := heap.Pop(p)
			sum += e.(int64)
		}
	}
	fmt.Printf("%d\n", sum)
}

func main() {
	//t := ReadInt()
	t := 1
	for ; t > 0; t-- {
		solve()
	}
}

package main

import (
	"bufio"
	"container/heap"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"runtime"
	"strconv"
)

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

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

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

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

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

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func solve() {
	n := ReadInt()
	a := ReadIntSlice(n)
	p := &IntHeap{}
	heap.Init(p)
	sum := 0
	for i := n - 1; a[i] > 0 && i >= 0; i-- {
		heap.Push(p, a[i])
		if i&(i+1) == 0 {
			e := heap.Pop(p)
			sum += e.(int)
		}
	}
	fmt.Printf("%d\n", sum)
}

func main() {
	//t := ReadInt()
	t := 1
	for ; t > 0; t-- {
		solve()
	}
}


Madoka is going to enroll in "TSUNS PTU". But she stumbled upon a difficult task during the entrance computer science exam:  A number is called good if it is a multiple of $$$d$$$.  A number is called beatiful if it is good and it cannot be represented as a product of two good numbers. Notice that a beautiful number must be good.Given a good number $$$x$$$, determine whether it can be represented in at least two different ways as a product of several (possibly, one) beautiful numbers. Two ways are different if the sets of numbers used are different.Solve this problem for Madoka and help her to enroll in the best school in Russia!

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — number of test cases. Below comes their description. Each test case consists of two integers $$$x$$$ and $$$d$$$, separated by a space ($$$2 \leq x, d \leq 10^9$$$). It is guaranteed that $$$x$$$ is a multiple of $$$d$$$.

For each set of input data, output "NO" if the number cannot be represented in at least two ways. Otherwise, output "YES". You can output each letter in any case (for example, "YES", "Yes", "yes", "yEs", "yEs" will be recognized as a positive answer).

NoteIn the first example, $$$6$$$ can be represented as $$$6$$$, $$$1 \cdot 6$$$, $$$2 \cdot 3$$$. But $$$3$$$ and $$$1$$$ are not a good numbers because they are not divisible by $$$2$$$, so there is only one way.In the second example, $$$12$$$ can be represented as $$$6 \cdot 2$$$, $$$12$$$, $$$3 \cdot 4$$$, or $$$3 \cdot 2 \cdot 2$$$. The first option is suitable. The second is— no, because $$$12$$$ is not beautiful number ($$$12 = 6 \cdot 2$$$). The third and fourth are also not suitable, because $$$3$$$ is not good number.In the third example, $$$36$$$ can be represented as $$$18 \cdot 2$$$ and $$$6 \cdot 6$$$. Therefore it can be decomposed in at least two ways.

package main

import (
	"fmt"
	"sort"
)

func compose(x int) []int {
	slice := make([]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			slice = append(slice, i)
			x /= i
		}
	}
	if x != 1 {
		slice = append(slice, x)
	}
	return slice
}

func composeBy(x, d *int) int {
	var cnt int
	for *x%*d == 0 {
		cnt++
		*x /= *d
	}
	return cnt
}

func pigeonHole(slice []int, cnt, d int) bool {
	X := make([]int, cnt)
	for i := 0; i < cnt; i++ {
		X[i] = 1
	}
	for _, el := range slice {
		for i := 0; i < cnt; i++ {
			if (X[i]*el)%d == 0 && i != cnt-1 {
				continue
			} else {
				X[i] *= el
				break
			}
		}
	}
	for _, x := range X {
		if x%d == 0 {
			return true
		}
	}
	return false
}

func run() {
	var x, d int
	fmt.Scanf("%d %d\n", &x, &d)
	countD := composeBy(&x, &d)
	composeX := compose(x)
	composeD := compose(d)
	if len(composeX) >= 2 && countD >= 2 {
		fmt.Println("YES")
		return
	}
	if countD >= 3 && len(composeD) >= 2 {
		slice := make([]int, 0)
		slice = append(slice, composeX...)
		slice = append(slice, composeD...)
		sort.Ints(slice)
		if !pigeonHole(slice, countD-1, d) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
	return
}

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	for t := 0; t < T; t++ {
		run()
	}
}

package main

import (
	"fmt"
	"sort"
)

func compose(x int) []int {
	slice := make([]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			slice = append(slice, i)
			x /= i
		}
	}
	if x != 1 {
		slice = append(slice, x)
	}
	return slice
}

func composeBy(x, d *int) int {
	var cnt int
	for *x%*d == 0 {
		cnt++
		*x /= *d
	}
	return cnt
}

func pigeonHole(slice []int, cnt, d int) bool {
	X := make([]int, cnt)
	for i := 0; i < cnt; i++ {
		X[i] = 1
	}
	for _, el := range slice {
		for i := 0; i < cnt; i++ {
			if (X[i]*el)%d == 0 && i != cnt-1 {
				continue
			} else {
				X[i] *= el
				break
			}
		}
	}
	for _, x := range X {
		if x%d == 0 {
			return true
		}
	}
	return false
}

func run() {
	var x, d int
	fmt.Scanf("%d %d\n", &x, &d)
	countD := composeBy(&x, &d)
	composeX := compose(x)
	composeD := compose(d)
	if len(composeX) >= 2 || countD == 1 {
		fmt.Println("YES")
		return
	}
	if countD >= 3 && len(composeD) >= 2 {
		slice := make([]int, 0)
		slice = append(slice, composeX...)
		slice = append(slice, composeD...)
		sort.Ints(slice)
		if !pigeonHole(slice, countD-1, d) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
	return
}

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	for t := 0; t < T; t++ {
		run()
	}
}

package main

import (
	"fmt"
	"sort"
)

func compose(x int) []int {
	slice := make([]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			slice = append(slice, i)
			x /= i
		}
	}
	if x != 1 {
		slice = append(slice, x)
	}
	return slice
}

func composeBy(x, d *int) int {
	var cnt int
	for *x%*d == 0 {
		cnt++
		*x /= *d
	}
	return cnt
}

func pigeonHole(slice []int, cnt, d int) bool {
	X := make([]int, cnt)
	for i := 0; i < cnt; i++ {
		X[i] = 1
	}
	for _, el := range slice {
		for i := 0; i < cnt; i++ {
			if (X[i]*el)%d == 0 && i != cnt-1 {
				continue
			} else {
				X[i] *= el
				break
			}
		}
	}
	for _, x := range X {
		if x%d == 0 {
			return true
		}
	}
	return false
}

func run() {
	var x, d int
	fmt.Scanf("%d %d\n", &x, &d)
	countD := composeBy(&x, &d)
	composeX := compose(x)
	composeD := compose(d)
	if len(composeX) >= 2 {
		fmt.Println("YES")
		return
	}
	if countD >= 3 && len(composeD) >= 2 {
		slice := make([]int, 0)
		slice = append(slice, composeX...)
		slice = append(slice, composeD...)
		sort.Ints(slice)
		if !pigeonHole(slice, countD-1, d) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
	return
}

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	for t := 0; t < T; t++ {
		run()
	}
}

package main

import "fmt"

func compose(x int) []int {
	slice := make([]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			slice = append(slice, i)
			x /= i
		}
	}
	if x != 1 {
		slice = append(slice, x)
	}
	return slice
}

func composeBy(x, d *int) int {
	var cnt int
	for *x%*d == 0 {
		cnt++
		*x /= *d
	}
	return cnt
}

func pigeonHole(slice []int, cnt, d int) bool {
	X := make([]int, cnt)
	for i := 0; i < cnt; i++ {
		X[i] = 1
	}
	for _, el := range slice {
		for i := 0; i < cnt; i++ {
			if (X[i]*el)%d == 0 && i != cnt-1 {
				continue
			} else {
				X[i] *= el
				break
			}
		}
	}
	for _, x := range X {
		if x%d == 0 {
			return true
		}
	}
	return false
}

func run() {
	var x, d int
	fmt.Scanf("%d %d\n", &x, &d)
	countD := composeBy(&x, &d)
	composeX := compose(x)
	composeD := compose(d)
	if len(composeX) >= 2 {
		fmt.Println("YES")
		return
	}
	if countD >= 3 && len(composeD) >= 2 {
		slice := make([]int, 0)
		slice = append(slice, composeX...)
		slice = append(slice, composeD...)
		if !pigeonHole(slice, countD-1, d) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
	return
}

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	for t := 0; t < T; t++ {
		run()
	}
}

package main

import "fmt"

func compose(x int) []int {
	slice := make([]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			slice = append(slice, i)
			x /= i
		}
	}
	if x != 1 {
		slice = append(slice, x)
	}
	return slice
}

func composeBy(x, d *int) int {
	var cnt int
	for *x%*d == 0 {
		cnt++
		*x /= *d
	}
	return cnt
}

func pigeonHole(slice []int, d int) bool {
	x1, x2 := 1, 1
	for _, x := range slice {
		if (x1*x)%d == 0 {
			x2 *= x
		} else {
			x1 *= x
		}
	}
	return x1%d == 0 || x2%d == 0
}

func run() {
	var x, d int
	fmt.Scanf("%d %d\n", &x, &d)
	countD := composeBy(&x, &d)
	composeX := compose(x)
	composeD := compose(d)

	if len(composeX) >= 2 {
		fmt.Println("YES")
		return
	}
	if countD >= 3 && len(composeD) >= 2 {
		slice := make([]int, 0)
		slice = append(slice, composeX...)
		slice = append(slice, composeD...)
		if !pigeonHole(slice, d) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
	return
}

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	for t := 0; t < T; t++ {
		run()
	}
}


This is an interactive taskWilliam has a certain sequence of integers $$$a_1, a_2, \dots, a_n$$$ in his mind, but due to security concerns, he does not want to reveal it to you completely. William is ready to respond to no more than $$$2 \cdot n$$$ of the following questions:  What is the result of a bitwise AND of two items with indices $$$i$$$ and $$$j$$$ ($$$i \neq j$$$)  What is the result of a bitwise OR of two items with indices $$$i$$$ and $$$j$$$ ($$$i \neq j$$$) You can ask William these questions and you need to find the $$$k$$$-th smallest number of the sequence.Formally the $$$k$$$-th smallest number is equal to the number at the $$$k$$$-th place in a 1-indexed array sorted in non-decreasing order. For example in array $$$[5, 3, 3, 10, 1]$$$ $$$4$$$th smallest number is equal to $$$5$$$, and $$$2$$$nd and $$$3$$$rd are $$$3$$$.

It is guaranteed that for each element in a sequence the condition $$$0 \le a_i \le 10^9$$$ is satisfied.

NoteIn the example, the hidden sequence is $$$[1, 6, 4, 2, 3, 5, 4]$$$.Below is the interaction in the example.Query (contestant's program)Response (interactor)Notesand 2 52$$$a_2=6$$$, $$$a_5=3$$$. Interactor returns bitwise AND of the given numbers.or 5 67$$$a_5=3$$$, $$$a_6=5$$$. Interactor returns bitwise OR of the given numbers.finish 5$$$5$$$ is the correct answer. Note that you must find the value and not the index of the kth smallest number.

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

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

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

type Query struct {
	q    string
	i, j int
}

type Conf struct {
	aAB int
	oAB int
	aBC int
	oBC int
	oAC int
}

var memo = make(map[Query]int)
var stdin = NewWordScanner(os.Stdin)

func ask(q string, i, j int) int {
	query := Query{q: q, i: i, j: j}
	if res, exists := memo[query]; exists {
		return res
	}

	fmt.Println(q, i+1, j+1)

	res := stdin.Int()
	memo[query] = res
	return res
}

func answer(res int) {
	fmt.Println("finish", res)
}

func calc(conf Conf) []int {
	bit := func(num int, pos int) int {
		if (num & (1 << pos)) > 0 {
			return 1
		}
		return 0
	}
	reversed := map[Conf][]int{
		{aAB: 0, oAB: 0, aBC: 0, oBC: 0, oAC: 0}: {0, 0, 0},
		{aAB: 0, oAB: 0, aBC: 0, oBC: 1, oAC: 1}: {0, 0, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 0}: {0, 1, 0},
		{aAB: 0, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {0, 1, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 0, oAC: 1}: {1, 0, 0},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 0, 1},
		{aAB: 1, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 1, 0},
		{aAB: 1, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {1, 1, 1},
	}

	res := make([]int, 3)
	for b := 0; b < 31; b++ {
		bitConf := Conf{
			aAB: bit(conf.aAB, b),
			oAB: bit(conf.oAB, b),
			aBC: bit(conf.aBC, b),
			oBC: bit(conf.oBC, b),
			oAC: bit(conf.oAC, b),
		}
		for i, r := range reversed[bitConf] {
			if r == 1 {
				res[i] += 1 << b
			}
		}
	}
	return res
}

func solve(n, k int) int {
	v := make([]int, n)

	step := func(i int) {
		conf := Conf{
			aAB: ask("and", i, i+1),
			oAB: ask("or", i, i+1),
			aBC: ask("and", i+1, i+2),
			oBC: ask("or", i+1, i+2),
			oAC: ask("or", i, i+2),
		}
		for j, val := range calc(conf) {
			v[i+j] = val
		}
	}

	for i := 0; i+2 < n; i += 3 {
		step(i)
	}
	step(n - 3)

	sort.Slice(v, func(i, j int) bool { return v[i] < v[j] })
	return v[k-1]
}

func main() {
	n, k := stdin.Int(), stdin.Int()
	answer(solve(n, k))
}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var n, k int

	/*	arr := []int{1, 6, 4, 2, 3, 5, 4}
		for i := 1; i < len(arr); i++ {
			fmt.Println(arr[0] | arr[i])
			fmt.Println(arr[0] & arr[i])
		}
		fmt.Println(arr[1] | arr[2])
		fmt.Println(arr[1] & arr[2])
	*/
	fmt.Fscanf(r, "%d %d\n", &n, &k)

	or := make([]int, n)
	and := make([]int, n)

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

		fmt.Fscanf(r, "%d\n", &or[i])

		fmt.Printf("and %d %d\n", 1, i+1)
		os.Stdout.Sync()
		fmt.Fscanf(r, "%d\n", &and[i])
	}

	fmt.Printf("or %d %d\n", 2, 3)
	os.Stdout.Sync()
	var or23 int
	fmt.Fscanf(r, "%d\n", &or23)

	fmt.Printf("and %d %d\n", 2, 3)
	os.Stdout.Sync()
	var and23 int
	fmt.Fscanf(r, "%d\n", &and23)

	res := make([]int, n)
	res[0] = ((or[1] | or[2]) ^ (or23)) | (and[1] | and[2])

	for i := 1; i < n; i++ {
		res[i] = res[0] ^ (or[i] ^ and[i])
	}
	//fmt.Println(and[1:], or[1:], or23, res)
	sort.Ints(res)
	fmt.Println("finish", res[k-1])
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

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

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

type Query struct {
	q    string
	i, j int
}

type Conf struct {
	aAB int
	oAB int
	aBC int
	oBC int
	oAC int
}

var memo = make(map[Query]int)
var stdin = NewWordScanner(os.Stdin)

func ask(q string, i, j int) int {
	query := Query{q: q, i: i, j: j}
	if res, exists := memo[query]; exists {
		return res
	}

	fmt.Println(q, i+1, j+1)

	res := stdin.Int()
	memo[query] = res
	return res
}

func answer(res int) {
	fmt.Println("finish", res)
}

func calc(conf Conf) []int {
	bit := func(num int, pos int) int {
		if (num & (1 << pos)) > 0 {
			return 1
		}
		return 0
	}
	reversed := map[Conf][]int{
		{aAB: 0, oAB: 0, aBC: 0, oBC: 0, oAC: 0}: {0, 0, 0},
		{aAB: 0, oAB: 0, aBC: 0, oBC: 1, oAC: 1}: {0, 0, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 0}: {0, 1, 0},
		{aAB: 0, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {0, 1, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 0, oAC: 1}: {1, 0, 0},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 0, 1},
		{aAB: 1, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 1, 0},
		{aAB: 1, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {1, 1, 1},
	}

	res := make([]int, 3)
	for b := 0; b < 31; b++ {
		bitConf := Conf{
			aAB: bit(conf.aAB, b),
			oAB: bit(conf.oAB, b),
			aBC: bit(conf.aBC, b),
			oBC: bit(conf.oBC, b),
			oAC: bit(conf.oAC, b),
		}
		for i, r := range reversed[bitConf] {
			if r == 1 {
				res[i] += 1 << b
			}
		}
	}
	return res
}

func solve(n, k int) int {
	v := make([]int, n)
	for i := 0; i+2 < n; {
		conf := Conf{
			aAB: ask("and", i, i+1),
			oAB: ask("or", i, i+1),
			aBC: ask("and", i+1, i+2),
			oBC: ask("or", i+1, i+2),
			oAC: ask("or", i, i+2),
		}
		for j, val := range calc(conf) {
			v[i+j] = val
		}

		i += 3
		if i+2 > n && i != n {
			i = n - 3
		}
	}

	sort.Slice(v, func(i, j int) bool { return v[i] < v[j] })
	return v[k-1]
}

func main() {
	n, k := stdin.Int(), stdin.Int()
	answer(solve(n, k))
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

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

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

type Query struct {
	q    string
	i, j int
}

type Conf struct {
	aAB int
	oAB int
	aBC int
	oBC int
	oAC int
}

var memo = make(map[Query]int)
var stdin = NewWordScanner(os.Stdin)

func ask(q string, i, j int) int {
	query := Query{q: q, i: i, j: j}
	if res, exists := memo[query]; exists {
		return res
	}

	fmt.Println(q, i+1, j+1)

	res := stdin.Int()
	memo[query] = res
	return res
}

func answer(res int) {
	fmt.Println("finish", res)
}

func calc(conf Conf) []int {
	bit := func(num int, pos int) int {
		if (num & (1 << pos)) > 0 {
			return 1
		}
		return 0
	}
	reversed := map[Conf][]int{
		{aAB: 0, oAB: 0, aBC: 0, oBC: 0, oAC: 0}: {0, 0, 0},
		{aAB: 0, oAB: 0, aBC: 0, oBC: 1, oAC: 1}: {0, 0, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 0}: {0, 1, 0},
		{aAB: 0, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {0, 1, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 0, oAC: 1}: {1, 0, 0},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 0, 1},
		{aAB: 1, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 1, 0},
		{aAB: 1, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {1, 1, 1},
	}

	res := make([]int, 3)
	for b := 0; b < 31; b++ {
		bitConf := Conf{
			aAB: bit(conf.aAB, b),
			oAB: bit(conf.oAB, b),
			aBC: bit(conf.aBC, b),
			oBC: bit(conf.oBC, b),
			oAC: bit(conf.oAC, b),
		}
		for i, r := range reversed[bitConf] {
			if r == 1 {
				res[i] += 1 << b
			}
		}
	}
	return res
}

func solve(n, k int) int {
	v := make([]int, n)
	for i := 0; i < n; {
		conf := Conf{
			aAB: ask("and", i, i+1),
			oAB: ask("or", i, i+1),
			aBC: ask("and", i+1, i+2),
			oBC: ask("or", i+1, i+2),
			oAC: ask("or", i, i+2),
		}
		for j, val := range calc(conf) {
			v[i+j] = val
		}

		i += 3
		if i > n {
			i = n - 3
		}
	}

	sort.Slice(v, func(i, j int) bool { return v[i] < v[j] })
	return v[k-1]
}

func main() {
	n, k := stdin.Int(), stdin.Int()
	answer(solve(n, k))
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

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

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

type Query struct {
	q    string
	i, j int
}

type Conf struct {
	aAB int
	oAB int
	aBC int
	oBC int
	oAC int
}

var memo = make(map[Query]int)
var stdin = NewWordScanner(os.Stdin)

func ask(q string, i, j int) int {
	query := Query{q: q, i: i, j: j}
	if res, exists := memo[query]; exists {
		return res
	}

	fmt.Println(q, i+1, j+1)

	res := stdin.Int()
	memo[query] = res
	return res
}

func answer(res int) {
	fmt.Println("finish", res)
}

func calc(conf Conf) []int {
	bit := func(num int, pos int) int {
		if (num & (1 << pos)) > 0 {
			return 1
		}
		return 0
	}
	reversed := map[Conf][]int{
		{aAB: 0, oAB: 0, aBC: 0, oBC: 0, oAC: 0}: {0, 0, 0},
		{aAB: 0, oAB: 0, aBC: 0, oBC: 1, oAC: 1}: {0, 0, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 0}: {0, 1, 0},
		{aAB: 0, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {0, 1, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 0, oAC: 1}: {1, 0, 0},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 0, 1},
		{aAB: 1, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 1, 0},
		{aAB: 1, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {1, 1, 1},
	}

	res := make([]int, 3)
	for b := 0; b < 31; b++ {
		bitConf := Conf{
			aAB: bit(conf.aAB, b),
			oAB: bit(conf.oAB, b),
			aBC: bit(conf.aBC, b),
			oBC: bit(conf.oBC, b),
			oAC: bit(conf.oAC, b),
		}
		for i, r := range reversed[bitConf] {
			if r == 1 {
				res[i] += 1 << b
			}
		}
	}
	return res
}

func solve(n, k int) int {
	v := make([]int, n)
	for i := 0; i+2 < n; {
		conf := Conf{
			aAB: ask("and", i, i+1),
			oAB: ask("or", i, i+1),
			aBC: ask("and", i+1, i+2),
			oBC: ask("or", i+1, i+2),
			oAC: ask("or", i, i+2),
		}
		for j, val := range calc(conf) {
			v[i+j] = val
		}

		i += 3
		if i != n {
			i = n - 3
		}
	}

	sort.Slice(v, func(i, j int) bool { return v[i] < v[j] })
	return v[k-1]
}

func main() {
	n, k := stdin.Int(), stdin.Int()
	answer(solve(n, k))
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

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

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

type Query struct {
	q    string
	i, j int
}

type Conf struct {
	aAB int
	oAB int
	aBC int
	oBC int
	oAC int
}

var memo = make(map[Query]int)
var stdin = NewWordScanner(os.Stdin)

func ask(q string, i, j int) int {
	query := Query{q: q, i: i, j: j}
	if res, exists := memo[query]; exists {
		return res
	}

	fmt.Println(q, i+1, j+1)

	res := stdin.Int()
	memo[query] = res
	return res
}

func answer(res int) {
	fmt.Println("finish", res)
}

func calc(conf Conf) []int {
	bit := func(num int, pos int) int {
		if (num & (1 << pos)) > 0 {
			return 1
		}
		return 0
	}
	reversed := map[Conf][]int{
		{aAB: 0, oAB: 0, aBC: 0, oBC: 0, oAC: 0}: {0, 0, 0},
		{aAB: 0, oAB: 0, aBC: 0, oBC: 1, oAC: 1}: {0, 0, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 0}: {0, 1, 0},
		{aAB: 0, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {0, 1, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 0, oAC: 1}: {1, 0, 0},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 0, 1},
		{aAB: 1, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 1, 0},
		{aAB: 1, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {1, 1, 1},
	}

	res := make([]int, 3)
	for b := 0; b < 30; b++ {
		bitConf := Conf{
			aAB: bit(conf.aAB, b),
			oAB: bit(conf.oAB, b),
			aBC: bit(conf.aBC, b),
			oBC: bit(conf.oBC, b),
			oAC: bit(conf.oAC, b),
		}
		for i, r := range reversed[bitConf] {
			if r == 1 {
				res[i] += 1 << b
			}
		}
	}
	return res
}

func solve(n, k int) int {
	v := make([]int, n)
	for i := 0; i+2 < n; {
		conf := Conf{
			aAB: ask("and", i, i+1),
			oAB: ask("or", i, i+1),
			aBC: ask("and", i+1, i+2),
			oBC: ask("or", i+1, i+2),
			oAC: ask("or", i, i+2),
		}
		for j, val := range calc(conf) {
			v[i+j] = val
		}

		i += 3
		if i != n {
			i = n - 3
		}
	}

	sort.Slice(v, func(i, j int) bool { return v[i] < v[j] })
	return v[k-1]
}

func main() {
	n, k := stdin.Int(), stdin.Int()
	answer(solve(n, k))
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

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

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

type Query struct {
	q    string
	i, j int
}

type Conf struct {
	aAB int
	oAB int
	aBC int
	oBC int
	oAC int
}

var memo = make(map[Query]int)
var stdin = NewWordScanner(os.Stdin)

func ask(q string, i, j int) int {
	query := Query{q: q, i: i, j: j}
	if res, exists := memo[query]; exists {
		return res
	}

	fmt.Println(q, i+1, j+1)

	res := stdin.Int()
	memo[query] = res
	return res
}

func answer(res int) {
	fmt.Println("finish", res)
}

func calc(conf Conf) []int {
	bit := func(num int, pos int) int {
		if (num & (1 << pos)) > 0 {
			return 1
		}
		return 0
	}
	reversed := map[Conf][]int{
		{aAB: 0, oAB: 0, aBC: 0, oBC: 0, oAC: 0}: {0, 0, 0},
		{aAB: 0, oAB: 0, aBC: 0, oBC: 1, oAC: 1}: {0, 0, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 0}: {0, 1, 0},
		{aAB: 0, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {0, 1, 1},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 0, oAC: 1}: {1, 0, 0},
		{aAB: 0, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 0, 1},
		{aAB: 1, oAB: 1, aBC: 0, oBC: 1, oAC: 1}: {1, 1, 0},
		{aAB: 1, oAB: 1, aBC: 1, oBC: 1, oAC: 1}: {1, 1, 1},
	}

	res := make([]int, 3)
	for b := 0; b < 30; b++ {
		bitConf := Conf{
			aAB: bit(conf.aAB, b),
			oAB: bit(conf.oAB, b),
			aBC: bit(conf.aBC, b),
			oBC: bit(conf.oBC, b),
			oAC: bit(conf.oAC, b),
		}
		for i, r := range reversed[bitConf] {
			if r == 1 {
				res[i] += 1 << b
			}
		}
	}
	return res
}

func solve(n, k int) int {
	v := make([]int, n)
	for i := 0; i+2 < n; i++ {
		conf := Conf{
			aAB: ask("and", i, i+1),
			oAB: ask("or", i, i+1),
			aBC: ask("and", i+1, i+2),
			oBC: ask("or", i+1, i+2),
			oAC: ask("or", i, i+2),
		}
		for j, val := range calc(conf) {
			v[i+j] = val
		}
	}

	sort.Slice(v, func(i, j int) bool { return v[i] < v[j] })
	return v[k-1]
}

func main() {
	n, k := stdin.Int(), stdin.Int()
	answer(solve(n, k))
}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var n, k int

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

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

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

		fmt.Fscanf(r, "%d\n", &or[i])

		fmt.Printf("and %d %d\n", 1, i+1)
		os.Stdout.Sync()
		fmt.Fscanf(r, "%d\n", &and[i])
	}

	fmt.Printf("or %d %d\n", 2, 3)
	os.Stdout.Sync()
	var or23 int
	fmt.Fscanf(r, "%d\n", or23)

	fmt.Printf("and %d %d\n", 2, 3)
	os.Stdout.Sync()
	var and23 int
	fmt.Fscanf(r, "%d\n", and23)

	res := make([]int, n)
	res[0] = ((or[1] | or[2]) ^ (or23)) | (and[1] | and[2])

	for i := 1; i < n; i++ {
		res[i] = res[0] ^ (or[i] ^ and[i])
	}

	sort.Ints(res)
	fmt.Println(res[k-1])
}