package main

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

var scanner *bufio.Scanner

func getI() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n := int(getI())
  original := make([]int, n)
  for i := range original {
    original[i] = int(getI())
  }
  sorted := make([]int, n)
  copy(sorted, original)
  sort.Ints(sorted)
  if sorted[n-1] == 1 {
    sorted[n-1] = 2
  } else {
    sorted[n-1] = 1
  }
  sort.Ints(sorted)
  writer.WriteString(fmt.Sprintf("%d", sorted[0]))
  for i := 1; i < n; i++ {
    writer.WriteString(fmt.Sprintf(" %d", sorted[i]))
  }
  writer.WriteString("\n")
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    sort.Ints(a)
    for i := 0; i < n; i++ {
        if i == 0 {
            if (n == 1) && (a[i] == 1) { writer.WriteString("2") } else { writer.WriteString("1") }
        } else if i == (n-1) {
            if a[i] == 1 { writer.WriteString("2") } else { writer.WriteString(strconv.Itoa(a[i-1])) }
        } else {
            writer.WriteString(strconv.Itoa(a[i-1]))
        }
        if i == (n-1) { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
    }
    writer.Flush()
}

package main

import "fmt"
import "sort"
import "os"
import "bufio"
import "strconv"

func main(){
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	for i:=0; i<n; i++ {
		r.Scan()
		arr[i], _ = strconv.Atoi(r.Text())
	}
	sort.Ints(arr)
	if arr[n-1] != 1 {
		arr[n-1] = 1
	} else {
		arr[n-1] = 2
	}
	sort.Ints(arr)
	for j:=0; j<n; j++ {
		fmt.Print(arr[j], " ")
	}
	fmt.Println()
}

// 135A
package main

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

func main() {
	var x int
	fmt.Scan(&x)
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	a := make([]int, x)
	for i := 0; i < x; i++ {
		in.Scan()
		a[i], _ = strconv.Atoi(in.Text())
	}
	sort.Sort(sort.IntSlice(a))
	if a[x-1] == 1 {
		a[x-1] = 2
	} else {
		a[x-1] = 1
	}
	sort.Sort(sort.IntSlice(a))
	for i := 0; i < x; i++ {
		fmt.Print(a[i], " ")
	}
}

// 135A-mic_rizal
package main

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

func main() {
    var n, max, x int
    z := bufio.NewReader(os.Stdin)
    fmt.Fscan(z, &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(z, &a[i])
        if a[i] > max {
            max = a[i]
            x = i
        }
    }

    if a[x] > 1 {
        a[x] = 1
    } else {
        a[x] = 2
    }
    sort.Sort(sort.IntSlice(a))
    for i := 0; i < n; i++ {
        fmt.Print(a[i])
        fmt.Print(" ")
    }
    fmt.Println()
}

package main

import "fmt"
import "sort"

func main(){
	var n int
	fmt.Scan(&n)
	arr := make([]float64, n)
	for i:=0; i<n; i++ {
		fmt.Scan(&arr[i])
	}
	sort.Sort(sort.Float64Slice(arr))
	if arr[n-1] != 1 {
		arr[n-1] = 1
	} else {
		arr[n-1] = 2
	}
	sort.Sort(sort.Float64Slice(arr))
	for j:=0; j<n; j++ {
		fmt.Print(arr[j], " ")
	}
	fmt.Println()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    sort.Ints(a)
    for i := 0; i < n; i++ {
        if i == 0 {
            writer.WriteString("1")
        } else {
            writer.WriteString(strconv.Itoa(a[i-1]))
        }
        if i == (n-1) { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
    }
    writer.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    sort.Ints(a)
    for i := 0; i < n; i++ {
        if i == 0 {
            writer.WriteString("1")
        } else if i == (n-1) {
            if a[i] == 1 { writer.WriteString("2") } else { writer.WriteString(strconv.Itoa(a[i-1])) }
        } else {
            writer.WriteString(strconv.Itoa(a[i-1]))
        }
        if i == (n-1) { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
    }
    writer.Flush()
}

// 135A
package main

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

func main() {
	var x int
	fmt.Scan(&x)
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	a := make([]int, x)
	for i := 0; i < x; i++ {
		in.Scan()
		a[i], _ = strconv.Atoi(in.Text())
	}
	sort.Sort(sort.IntSlice(a))
	if a[x-1] == 1 {
		a[x-1] = 2
	} else {
		a[x-1] = 1
	}
	sort.Sort(sort.IntSlice(a))
	for i := 0; i < x; i++ {
		fmt.Print(a[i])
	}
}


package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var a, b, c int64
	fmt.Fscanf(reader, "%d %d %d", &a, &b, &c)
	delta := b * b - 4 * a * c
	if a == 0 && b == 0 && c == 0 {
		fmt.Printf("-1")
	} else if a == 0 && b == 0 {
		fmt.Printf("0")
	} else if a == 0 {
		fmt.Printf("1\n%f", float64(-c)/float64(b))
	} else if delta < 0 {
		fmt.Printf("0")
	} else if delta == 0 {
		fmt.Printf("1\n%f", float64(-b)/float64(2 * a))
	} else if delta > 0 {
		x1 := (float64(-b) + math.Sqrt(float64(delta))) / float64(2 * a)
		x2 := (float64(-b) - math.Sqrt(float64(delta))) / float64(2 * a)
		if x1 < x2 {
			fmt.Printf("2\n%f\n%f", x1, x2)
		} else {
			fmt.Printf("2\n%f\n%f", x2, x1)
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF20B(in io.Reader, out io.Writer) {
	var a, b, c int64
	Fscan(in, &a, &b, &c)
	if a == 0 {
		if b == 0 {
			if c == 0 {
				Fprint(out, -1)
			} else {
				Fprint(out, 0)
			}
		} else {
			Fprintf(out, "1\n%.5f", float64(-c)/float64(b))
		}
	} else {
		d := b*b - 4*a*c
		if d < 0 {
			Fprint(out, 0)
		} else if d == 0 {
			Fprintf(out, "1\n%.5f", float64(-b)/float64(2*a))
		} else {
			dd := math.Sqrt(float64(d))
			x, y := (float64(-b)-dd)/float64(2*a), (float64(-b)+dd)/float64(2*a)
			if x > y {
				x, y = y, x
			}
			Fprintf(out, "2\n%.5f %.5f", x, y)
		}
	}
}

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

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var a, b, c int64
	fmt.Fscanf(reader, "%d %d %d", &a, &b, &c)
	delta := b * b - 4 * a * c
	if a == 0 && b == 0 && c == 0 {
		fmt.Printf("-1")
	} else if a == 0 && b == 0 {
		fmt.Printf("0")
	} else if a == 0 {
		fmt.Printf("%f", float64(-c)/float64(b))
	} else if delta < 0 {
		fmt.Printf("0")
	} else if delta == 0 {
		fmt.Printf("1\n%f", float64(-b)/float64(2 * a))
	} else if delta > 0 {
		x1 := (float64(-b) + math.Sqrt(float64(delta))) / float64(2 * a)
		x2 := (float64(-b) - math.Sqrt(float64(delta))) / float64(2 * a)
		if x1 < x2 {
			fmt.Printf("2\n%f\n%f", x1, x2)
		} else {
			fmt.Printf("2\n%f\n%f", x2, x1)
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF20B(in io.Reader, out io.Writer) {
	var a, b, c int64
	Fscan(in, &a, &b, &c)
	if a == 0 {
		if b == 0 {
			if c == 0 {
				Fprint(out, -1)
			} else {
				Fprint(out, 0)
			}
		} else {
			Fprintf(out, "1\n%.5f", float64(-c)/float64(b))
		}
	} else {
		d := b*b - 4*a*c
		if d < 0 {
			Fprint(out, -1)
		} else if d == 0 {
			Fprintf(out, "1\n%.5f", float64(-b)/float64(2*a))
		} else {
			dd := math.Sqrt(float64(d))
			x, y := (float64(-b)-dd)/float64(2*a), (float64(-b)+dd)/float64(2*a)
			if x > y {
				x, y = y, x
			}
			Fprintf(out, "2\n%.5f %.5f", x, y)
		}
	}
}

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


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1074D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	fa, dis := map[int]int{}, map[int]int{}
	var find func(int) int
	find = func(x int) int {
		if fx, ok := fa[x]; ok && fx != x {
			ffx := find(fx)
			dis[x] ^= dis[fx]
			fa[x] = ffx
			return ffx
		}
		return x
	}
	merge := func(from, to, d int) {
		fFrom, fTo := find(from), find(to)
		if fFrom != fTo {
			dis[fFrom] = d ^ dis[from] ^ dis[to]
			fa[fFrom] = fTo
		}
	}
	same := func(x, y int) bool { return find(x) == find(y) }

	var q, t, l, r, x int
	last := 0
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &t, &l, &r)
		l ^= last
		r ^= last
		if l > r {
			l, r = r, l
		}
		r++
		if t == 1 {
			Fscan(in, &x)
			merge(l, r, x^last)
		} else {
			if same(l, r) {
				last = dis[l] ^ dis[r]
				Fprintln(out, last)
			} else {
				last = 1
				Fprintln(out, -1)
			}
		}
	}
}

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

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

var p map[int]int
var x map[int]int
var s map[int]int

func get(v int) (int, int) {
	if par, ok := p[v]; !ok || par == v {
		return v, 0
	}
	var t int
	p[v], t = get(p[v])
	x[v] ^= t

	return p[v], x[v]
}

func getSize(v int) int {
	if r, ok := s[v]; ok {
		return r
	}
	return 1
}

func unite(a, b, xor int) {
	a, xa := get(a)
	b, xb := get(b)

	if a == b {
		return
	}

	if getSize(a) > getSize(b) {
		a, b = b, a
	}

	p[a] = b
	x[a] = xor ^ xa ^ xb
	s[a] += getSize(b)
}

func query(a, b int) (int, bool) {
	a, xa := get(a)
	b, xb := get(b)

	if a != b {
		return -1, false
	}
	return xa ^ xb, true
}

func main() {

	var q int
	fmt.Fscan(in, &q)

	p = make(map[int]int, 2*q)
	x = make(map[int]int, 2*q)
	s = make(map[int]int, 2*q)

	last := 0
	for i := 0; i < q; i++ {
		var t int
		fmt.Fscan(in, &t)
		switch t {
		case 1:
			var l, r, x int
			fmt.Fscan(in, &l, &r, &x)
			l, r, x = l^last, r^last, x^last
			if l > r {
				l, r = r, l
			}
			r += 1
			unite(l, r, x)
		case 2:
			var l, r int
			fmt.Fscan(in, &l, &r)
			l, r = l^last, r^last
			if l > r {
				l, r = r, l
			}
			r += 1

			answer, ok := query(l, r)
			if ok {
				last = answer
			} else {
				last = 1
			}
			fmt.Printf("%d\n", answer)
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	fa, dis := map[int]int{}, map[int]int{}
	var find func(int) int
	find = func(x int) int {
		if fx, ok := fa[x]; ok && fx != x {
			ffx := find(fx)
			dis[x] ^= dis[fx]
			fa[x] = ffx
			return ffx
		}
		return x
	}
	merge := func(from, to, d int) {
		fFrom, fTo := find(from), find(to)
		if fFrom != fTo {
			dis[fFrom] = d ^ dis[from] ^ dis[to]
			fa[fFrom] = fTo
		}
	}
	same := func(x, y int) bool { return find(x) == find(y) }

	var q, t, l, r, x int
	last := 0
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &t, &l, &r)
		l ^= last
		r ^= last
		if l > r {
			l, r = r, l
		}
		r++
		if t == 1 {
			Fscan(in, &x)
			merge(l, r, x^last)
		} else {
			if same(l, r) {
				last = dis[l] ^ dis[r]
				Fprintln(out, last)
			} else {
				last = 1
				Fprintln(out, -1)
			}
		}
	}
}

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

var p map[int]int
var x map[int]int
var s map[int]int

func get(v int) (int, int) {
	if par, ok := p[v]; !ok || par == v {
		return v, 0
	}
	var t int
	p[v], t = get(p[v])
	x[v] ^= t

	return p[v], x[v]
}

func getSize(v int) int {
	if _, ok := s[v]; !ok {
		s[v] = 1
	}
	return s[v]
}

func unite(a, b, xor int) {
	a, xa := get(a)
	b, xb := get(b)

	if a == b {
		return
	}

	if getSize(a) > getSize(b) {
		a, b = b, a
	}

	p[a] = b
	x[a] = xor ^ xa ^ xb
	s[a] += getSize(b)
}

func query(a, b int) (int, bool) {
	a, xa := get(a)
	b, xb := get(b)

	if a != b {
		return -1, false
	}
	return xa ^ xb, true
}

func main() {

	var q int
	fmt.Fscan(in, &q)

	p = make(map[int]int, 2*q)
	x = make(map[int]int, 2*q)
	s = make(map[int]int, 2*q)

	last := 0
	for i := 0; i < q; i++ {
		var t int
		fmt.Fscan(in, &t)
		switch t {
		case 1:
			var l, r, x int
			fmt.Fscan(in, &l, &r, &x)
			l, r, x = l^last, r^last, x^last
			if l > r {
				l, r = r, l
			}
			r += 1
			unite(l, r, x)
		case 2:
			var l, r int
			fmt.Fscan(in, &l, &r)
			l, r = l^last, r^last
			if l > r {
				l, r = r, l
			}
			r += 1

			answer, ok := query(l, r)
			if ok {
				last = answer
			} else {
				last = 1
			}
			fmt.Printf("%d\n", answer)
		}
	}
}

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

var p map[int]int
var x map[int]int

func get(v int) (int, int) {
	if par, ok := p[v]; !ok || par == v {
		return v, 0
	}
	var t int
	p[v], t = get(p[v])
	x[v] ^= t

	return p[v], x[v]
}

func unite(a, b, xor int) {
	a, xa := get(a)
	b, xb := get(b)

	if a == b {
		return
	}

	p[a] = b
	x[a] = xor ^ xa ^ xb
}

func query(a, b int) (int, bool) {
	a, xa := get(a)
	b, xb := get(b)

	if a != b {
		return -1, false
	}
	return xa ^ xb, true
}

func main() {

	var q int
	fmt.Fscan(in, &q)

	p = make(map[int]int, 2*q)
	x = make(map[int]int, 2*q)

	last := 0
	for i := 0; i < q; i++ {
		var t int
		fmt.Fscan(in, &t)
		switch t {
		case 1:
			var l, r, x int
			fmt.Fscan(in, &l, &r, &x)
			l, r, x = l^last, r^last, x^last
			if l > r {
				l, r = r, l
			}
			r += 1
			unite(l, r, x)
		case 2:
			var l, r int
			fmt.Fscan(in, &l, &r)
			l, r = l^last, r^last
			if l > r {
				l, r = r, l
			}
			r += 1

			answer, ok := query(l, r)
			if ok {
				last = answer
			} else {
				last = 1
			}
			fmt.Printf("%d\n", answer)
		}
	}
}

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

var p map[int]int
var x map[int]int

func get(v int) (int, int) {
	if par, ok := p[v]; !ok || par == v {
		return v, 0
	}
	var t int
	p[v], t = get(p[v])
	x[v] ^= t

	return p[v], x[v]
}

func unite(a, b, xor int) {
	a, xa := get(a)
	b, xb := get(b)

	if a == b {
		return
	}
	if (a ^ b ^ xor) % 313 < 166 {
		a, b = b, a
	}
	p[a] = b
	x[a] = xor ^ xa ^ xb
}

func query(a, b int) (int, bool) {
	a, xa := get(a)
	b, xb := get(b)

	if a != b {
		return -1, false
	}
	return xa ^ xb, true
}

func main() {

	var q int
	fmt.Fscan(in, &q)

	p = make(map[int]int, 2*q)
	x = make(map[int]int, 2*q)

	last := 0
	for i := 0; i < q; i++ {
		var t int
		fmt.Fscan(in, &t)
		switch t {
		case 1:
			var l, r, x int
			fmt.Fscan(in, &l, &r, &x)
			l, r, x = l^last, r^last, x^last
			if l > r {
				l, r = r, l
			}
			r += 1
			unite(l, r, x)
		case 2:
			var l, r int
			fmt.Fscan(in, &l, &r)
			l, r = l^last, r^last
			if l > r {
				l, r = r, l
			}
			r += 1

			answer, ok := query(l, r)
			if ok {
				last = answer
			} else {
				last = 1
			}
			fmt.Printf("%d\n", answer)
		}
	}
}

package main

import "fmt"

var p map[int]int
var x map[int]int

func get(v int) (int, int) {
	if par, ok := p[v]; !ok || par == v {
		return v, 0
	}
	var t int
	p[v], t = get(p[v])
	x[v] ^= t

	return p[v], x[v]
}

func unite(a, b, xor int) {
	a, xa := get(a)
	b, xb := get(b)

	if a == b {
		return
	}

	p[a] = b
	x[a] = xor ^ xa ^ xb
}

func query(a, b int) (int, bool) {
	a, xa := get(a)
	b, xb := get(b)

	if a != b {
		return -1, false
	}
	return xa ^ xb, true
}

func main() {

	var q int
	fmt.Scanf("%d", &q)

	p = make(map[int]int, 2 * q)
	x = make(map[int]int, 2 * q)

	last := 0
	for i := 0; i < q; i++ {
		var t int
		fmt.Scanf("%d", &t)
		switch t {
		case 1:
			var l, r, x int
			fmt.Scanf("%d%d%d", &l, &r, &x)
			l, r, x = l ^ last, r ^ last, x ^ last
			if l > r {
				l, r = r, l
			}
			r += 1
			unite(l, r, x)
		case 2:
			var l, r int
			fmt.Scanf("%d%d", &l, &r)
			l, r = l ^ last, r ^ last
			if l > r {
				l, r = r, l
			}
			r += 1

			answer, ok := query(l, r)
			if ok {
				last = answer
			} else {
				last = 1
			}
			fmt.Printf("%d\n", answer)
		}
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF160D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var n, m, v, w, wi, c int
	Fscan(in, &n, &m)
	fa := make([]int, n+1)
	for i := range fa {
		fa[i] = i
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	type edge struct{ v, w, i int }
	edges := [1e6 + 1][]edge{}
	for i := 0; i < m; i++ {
		Fscan(in, &v, &w, &wi)
		edges[wi] = append(edges[wi], edge{v, w, i})
	}
	ans := make([]int8, m)

	type nb struct{ to, eid int }
	g := make([][]nb, n+1)
	dfn := make([]int, n+1)
	id := make([]int, n+1)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		c++
		dfn[v] = c
		lowV := c
		for _, e := range g[v] {
			if w := e.to; dfn[w] == 0 {
				lowW := f(w, v)
				if lowW > dfn[v] {
					ans[e.eid] = 1
				}
				lowV = min(lowV, lowW)
			} else if w != fa && dfn[w] < dfn[v] {
				lowV = min(lowV, dfn[w])
			}
		}
		for _, e := range g[v] {
			if id[e.to] == 0 {
				id[e.to] = e.eid + 1
			} else {
				ans[id[e.to]-1] = 0
				ans[e.eid] = 0
			}
		}
		for _, e := range g[v] {
			id[e.to] = 0
		}
		return lowV
	}
	for _, es := range edges {
		if es == nil {
			continue
		}
		vs := []int{}
		for _, e := range es {
			if v, w, i := find(e.v), find(e.w), e.i; v != w {
				g[v] = append(g[v], nb{w, i})
				g[w] = append(g[w], nb{v, i})
				vs = append(vs, v, w)
			} else {
				ans[i] = 2
			}
		}
		for _, v := range vs {
			if dfn[v] == 0 {
				f(v, -1)
			}
		}
		for i := 0; i < len(vs); i += 2 {
			v, w := vs[i], vs[i+1]
			fa[find(v)] = find(w)
			g[v] = nil
			g[w] = nil
			dfn[v] = 0
			dfn[w] = 0
		}
	}

	s := [3]string{"at least one", "any", "none"}
	for _, t := range ans {
		Fprintln(out, s[t])
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var n, m, v, w, wi, c int
	Fscan(in, &n, &m)
	fa := make([]int, n+1)
	for i := range fa {
		fa[i] = i
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	type edge struct{ v, w, i int }
	edges := [1e6 + 1][]edge{}
	for i := 0; i < m; i++ {
		Fscan(in, &v, &w, &wi)
		edges[wi] = append(edges[wi], edge{v, w, i})
	}
	ans := make([]int8, m)

	type nb struct{ to, eid int }
	g := make([][]nb, n+1)
	dfn := make([]int, n+1)
	id := make([]int, n+1)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		c++
		dfn[v] = c
		lowV := c
		for _, e := range g[v] {
			if w := e.to; dfn[w] == 0 {
				lowW := f(w, v)
				if lowW > dfn[v] {
					ans[e.eid] = 1
				}
				lowV = min(lowV, lowW)
			} else if w != fa && dfn[w] < dfn[v] {
				lowV = min(lowV, dfn[w])
			}
		}
		for _, e := range g[v] {
			if id[e.to] == 0 {
				id[e.to] = e.eid + 1
			} else {
				ans[id[e.to]-1] = 0
				ans[e.eid] = 0
			}
		}
		for _, e := range g[v] {
			id[e.to] = 0
		}
		return lowV
	}
	for _, es := range edges {
		if es == nil {
			continue
		}
		vs := []int{}
		for _, e := range es {
			if v, w, i := find(e.v), find(e.w), e.i; v != w {
				g[v] = append(g[v], nb{w, i})
				g[w] = append(g[w], nb{v, i})
				vs = append(vs, v, w)
			} else {
				ans[i] = 2
			}
		}
		for _, v := range vs {
			if dfn[v] == 0 {
				f(v, -1)
			}
		}
		for i := 0; i < len(vs); i += 2 {
			v, w := vs[i], vs[i+1]
			fa[find(v)] = find(w)
			g[v] = nil
			g[w] = nil
			dfn[v] = 0
			dfn[w] = 0
		}
	}

	s := [3]string{"at least one", "any", "none"}
	for _, t := range ans {
		Fprintln(out, s[t])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF160D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var n, m, v, w, wi, c int
	Fscan(in, &n, &m)
	fa := make([]int, n+1)
	for i := range fa {
		fa[i] = i
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	type edge struct{ v, w, i int }
	edges := [1e6 + 1][]edge{}
	for i := 0; i < m; i++ {
		Fscan(in, &v, &w, &wi)
		edges[wi] = append(edges[wi], edge{v, w, i})
	}
	ans := make([]int8, m)

	type nb struct{ to, eid int }
	g := make([][]nb, n+1)
	dfn := make([]int, n+1)
	id := make([]int, n+1)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		c++
		dfn[v] = c
		lowV := c
		for _, e := range g[v] {
			if w := e.to; dfn[w] == 0 {
				lowW := f(w, v)
				if lowW > dfn[v] {
					ans[e.eid] = 1
				}
				lowV = min(lowV, lowW)
			} else if w != fa && dfn[w] < dfn[v] {
				lowV = min(lowV, dfn[w])
			}
		}
		for _, e := range g[v] {
			if id[e.to] == 0 {
				id[e.to] = e.eid
			} else {
				ans[id[e.to]] = 0
				ans[e.eid] = 0
			}
		}
		for _, e := range g[v] {
			id[e.to] = 0
		}
		return lowV
	}
	for _, es := range edges {
		if es == nil {
			continue
		}
		vs := []int{}
		for _, e := range es {
			if v, w, i := find(e.v), find(e.w), e.i; v != w {
				g[v] = append(g[v], nb{w, i})
				g[w] = append(g[w], nb{v, i})
				vs = append(vs, v, w)
			} else {
				ans[i] = 2
			}
		}
		for _, v := range vs {
			if dfn[v] == 0 {
				f(v, -1)
			}
		}
		for i := 0; i < len(vs); i += 2 {
			v, w := vs[i], vs[i+1]
			fa[find(v)] = find(w)
			g[v] = nil
			g[w] = nil
			dfn[v] = 0
			dfn[w] = 0
		}
	}

	s := [3]string{"at least one", "any", "none"}
	for _, t := range ans {
		Fprintln(out, s[t])
	}
}

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


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

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


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

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

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


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)

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


package main

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

const eof = 0

type any = interface{}

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

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

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

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

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

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

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

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

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

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

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

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

	t := myio.ReadInt()
	sol := func() {
		n := myio.ReadInt()
		p := make([]int, n)
		v := make([]int, n)
		vis := make([]bool, n)
		for i := 0; i < n; i++ {
			t := myio.ReadInt() - 1
			p[i] = t
		}
		for i := 0; i < n; i++ {
			t := myio.ReadInt() - 1
			v[p[i]] = t
		}
		color := 0
		var sum int64 = 0
		for i := 0; i < n; i++ {
			if vis[i] {
				continue
			}
			c := 1
			for t := v[i]; !vis[t]; t = v[t] {
				vis[t] = true
				c++
			}
			sum += calcSum(color, c/2, n)
			color += c / 2
		}
		myio.Println(sum)
	}
	for ; t > 0; t-- {
		sol()
	}
}

func calcSum(color, c, n int) (sum int64) {
	for i := 0; i < c; i++ {
		sum += (int64)(n - 1 - color - i - color - i)
		sum += (int64)(n - 1 - color - i - (color + (i+1)%c))
	}
	return
}

package main

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

func solve(in io.Reader, out io.Writer) {
	var n int
	Fscan(in, &n)
	a := make([]int, n)
	b := map[int]int{}
	vis := make([]bool, n)

	for i := range a {
		Fscan(in, &a[i])
		a[i]--
	}
	for i := 0; i < n; i++ {
		var x int
		Fscan(in, &x)
		b[x-1] = i
	}
	cnt := 0
	for i := range a {
		if vis[i] {
			continue
		}
		vis[i] = true
		k := 1
		cur := a[i]
		for b[cur] != i {
			vis[b[cur]] = true
			cur = a[b[cur]]
			k++
		}
		cnt += k / 2
	}

	Fprintln(out, int64(n-cnt)*int64(cnt)*2)

}

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

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func abs(a int) int { if a < 0 { return -a }; return a }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi()
		CA := gis(N); CB := gis(N); for i:=0;i<N;i++ { CA[i]--; CB[i]-- }
		CAinv := make([]int,N); for i,c := range CA { CAinv[c] = i }
		perms := make([][]int,0)
		sb := make([]bool,N)
		for i:=0;i<N;i++ {
			v := CA[i]; if sb[v] { continue }
			p := []int{v}; idx := i; sb[v] = true;
			for CB[idx] != v { p = append(p,CB[idx]); sb[CB[idx]] = true; idx = CAinv[CB[idx]] }
			perms = append(perms,p)
		}
		permlt := func (a,b []int) bool {
			if len(a)%2 != len(b)%2 {
				if len(a)%2 == 0 { return true } else { return false }
			}
			return len(a) > len(b)
		}
		sort.Slice(perms,func(i,j int) bool { return permlt(perms[i],perms[j]) } )
		cc := make([]int,N); order := make([]int,0,N)
		top,bot := N-1,0; for top >= bot { order = append(order,top); top--; if top>=bot { order = append(order,bot); bot++ } }
		curs := 0
		for _,p := range perms {
			lp := len(p)
			if lp % 2 == 0 {
				for _,x := range p { cc[x] = order[curs]; curs++ }
			} else {
				for i:=0;i<lp-1;i++ { x := p[i]; cc[x] = order[curs]; curs++ }
			}
		}
		for _,p := range perms {
			lp := len(p)
			if lp % 2 == 1 { x := p[lp-1]; cc[x] = order[curs]; curs++ }
		}
		ans := int64(0);
		for i:=0;i<N;i++ { ans += int64(abs(cc[CA[i]]-cc[CB[i]])) }
		fmt.Fprintln(wrtr,ans)
	}
}

package main

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

func solve(in io.Reader, out io.Writer) {
	var n int
	Fscan(in, &n)
	a := make([]int, n)
	b := map[int]int{}
	vis := make([]bool, n)

	for i := range a {
		Fscan(in, &a[i])
		a[i]--
	}
	for i := 0; i < n; i++ {
		var x int
		Fscan(in, &x)
		b[x-1] = i
	}
	cnt := 0
	for i := range a {
		if vis[i] {
			continue
		}
		vis[i] = true
		k := 1
		cur := a[i]
		for b[cur] != i {
			vis[b[cur]] = true
			cur = a[b[cur]]
			k++
		}
		cnt += k / 2
	}

	Fprintln(out, (n-cnt)*cnt*2)

}

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

package main

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

const eof = 0

type any = interface{}

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

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

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

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

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

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

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

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

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

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

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

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

	t := myio.ReadInt()
	sol := func() {
		n := myio.ReadInt()
		p := make([]int, n)
		v := make([]int, n)
		vis := make([]bool, n)
		for i := 0; i < n; i++ {
			t := myio.ReadInt() - 1
			p[i] = t
		}
		for i := 0; i < n; i++ {
			t := myio.ReadInt() - 1
			v[p[i]] = t
		}
		color := 0
		sum := 0
		for i := 0; i < n; i++ {
			if vis[i] {
				continue
			}
			c := 1
			for t := v[i]; !vis[t]; t = v[t] {
				vis[t] = true
				c++
			}
			sum += calcSum(color, c/2, n)
			color += c / 2
		}
		myio.Println(sum)
	}
	for ; t > 0; t-- {
		sol()
	}
}

func calcSum(color, c, n int) (sum int) {
	for i := 0; i < c; i++ {
		sum += (n - 1 - color - i - color - i)
		sum += (n - 1 - color - i - (color + (i+1)%c))
	}
	return
}