package main

import "fmt"
import "sort"

func main() {
    arr := make([]int, 4, 4)
    for i:=0;i<4;i++ {
        fmt.Scanf("%d", &arr[i])
    }
    sort.Ints(arr)
    for i:=0;i<3;i++ {
        fmt.Printf("%d ", (arr[3]-arr[i]))
    }
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	nums := make([]int, 4)
	for i := 0; i < 4; i++ {
		fmt.Scan(&nums[i])
	}
	sort.Ints(nums)
	max := nums[3]
	for i := 0; i < 3; i++ {
		fmt.Println(max - nums[i])
	}
}

package main

import "fmt"

func max4(a, b, c, d int) int {
	if a > b && a > c && a > d {
		return a
	} else if b > a && b > c && b > d {
		return b
	} else if c > a && c > b && c > d {
		return c
	}
	return d
}

func printResult(a, b, c, r int) {
	fmt.Println(r-a, r-b, r-c)
}

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	var r = max4(a, b, c, d)
	if r == a {
		printResult(b, c, d, r)
	} else if r == b {
		printResult(a, c, d, r)
	} else if r == c {
		printResult(a, b, d, r)
	} else {
		printResult(a, b, c, r)
	}
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var x [4]int
	var maxIndex int
	for i := 0; i < 4; i++ {
		sc.Scan()
		x[i], _ = strconv.Atoi(sc.Text())
		if x[i] > x[maxIndex] {
			maxIndex = i
		}
	}

	first := true
	for i, v := range x {
		if i == maxIndex {
			continue
		}
		if !first {
			fmt.Print(" ")
		}
		fmt.Print(x[maxIndex] - v)
		first = false
	}
	fmt.Println()
}

package main

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

func main(){
	in := bufio.NewReader(os.Stdin)
	var input [4]int
	fmt.Fscan(in,&input[0],&input[1],&input[2],&input[3])
	max,left := max4(input)
	//fmt.Println(max,left)
	for _,v := range left{
		fmt.Printf("%d ",max -v )
	}
}

func max4(input [4]int) (int,[]int){
	maxIdx := 0
	for i:=0;i<len(input);i++{
		if input[maxIdx]<input[i]{
			maxIdx = i
		}
	}
	//fmt.Println(maxIdx)
	max := input[maxIdx]
	return max,append(input[0:maxIdx],input[maxIdx+1:len(input)]...)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, c, d int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
	s := []int{a, b, c, d}
	sort.Ints(s)
	k := s[3] - s[0]
	l := s[3] - s[1]
	m := s[3] - s[2]
	fmt.Println(k, l, m)
}

// A. Restoring Three Numbers
/*
Polycarp has guessed three positive integers 𝑎, 𝑏 and 𝑐. He keeps these
numbers in secret, but he writes down four numbers on a board in
arbitrary order — their pairwise sums (three numbers) and sum of all
three numbers (one number). So, there are four numbers on a board in
random order: 𝑎+𝑏, 𝑎+𝑐, 𝑏+𝑐 and 𝑎+𝑏+𝑐.

You have to guess three numbers 𝑎, 𝑏 and 𝑐 using given numbers.
Print three guessed integers in any order.

Pay attention that some given numbers 𝑎, 𝑏 and 𝑐 can be equal
(it is also possible that 𝑎=𝑏=𝑐).

Input

The only line of the input contains four positive integers 𝑥1,𝑥2,𝑥3,𝑥4
(2≤𝑥𝑖≤109) — numbers written on a board in random order.
It is guaranteed that the answer exists for the given number 𝑥1,𝑥2,𝑥3,𝑥4.

Output

Print such positive integers 𝑎, 𝑏 and 𝑐 that four numbers written on a board
are values 𝑎+𝑏, 𝑎+𝑐, 𝑏+𝑐 and 𝑎+𝑏+𝑐 written in some order. Print 𝑎, 𝑏 and 𝑐
in any order. If there are several answers, you can print any.
It is guaranteed that the answer exists.

Examples
Input
3 6 5 4

Output
2 1 3

Input
40 40 40 60

Output
20 20 20

Input
201 101 101 200

Output
1 100 100
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()
	v := strings.Split(string(input), " ")
	x1, _ := strconv.Atoi(v[0])
	x2, _ := strconv.Atoi(v[1])
	x3, _ := strconv.Atoi(v[2])
	x4, _ := strconv.Atoi(v[3])
	// sol1154A(x1, x2, x3, x4)
	sol2_1154A(x1, x2, x3, x4)
}

func sol1154A(x1, x2, x3, x4 int) {
	if x1 > x2 && x1 > x3 && x1 > x4 {
		fmt.Print(x1-x2, x1-x3, x1-x4)
	} else if x2 > x1 && x2 > x3 && x2 > x4 {
		fmt.Print(x2-x1, x2-x3, x2-x4)
	} else if x3 > x1 && x3 > x2 && x3 > x4 {
		fmt.Print(x3-x1, x3-x2, x3-x4)
	} else if x4 > x1 && x4 > x2 && x4 > x3 {
		fmt.Print(x4-x1, x4-x2, x4-x3)
	}
}

func sol2_1154A(x1, x2, x3, x4 int) {
	arr := []int{x1, x2, x3, x4}
	sort.Ints(arr)
	fmt.Print(arr[3]-arr[0], arr[3]-arr[1], arr[3]-arr[2])
}

// A. Restoring Three Numbers
/*
Polycarp has guessed three positive integers 𝑎, 𝑏 and 𝑐. He keeps these
numbers in secret, but he writes down four numbers on a board in
arbitrary order — their pairwise sums (three numbers) and sum of all
three numbers (one number). So, there are four numbers on a board in
random order: 𝑎+𝑏, 𝑎+𝑐, 𝑏+𝑐 and 𝑎+𝑏+𝑐.

You have to guess three numbers 𝑎, 𝑏 and 𝑐 using given numbers.
Print three guessed integers in any order.

Pay attention that some given numbers 𝑎, 𝑏 and 𝑐 can be equal
(it is also possible that 𝑎=𝑏=𝑐).

Input

The only line of the input contains four positive integers 𝑥1,𝑥2,𝑥3,𝑥4
(2≤𝑥𝑖≤109) — numbers written on a board in random order.
It is guaranteed that the answer exists for the given number 𝑥1,𝑥2,𝑥3,𝑥4.

Output

Print such positive integers 𝑎, 𝑏 and 𝑐 that four numbers written on a board
are values 𝑎+𝑏, 𝑎+𝑐, 𝑏+𝑐 and 𝑎+𝑏+𝑐 written in some order. Print 𝑎, 𝑏 and 𝑐
in any order. If there are several answers, you can print any.
It is guaranteed that the answer exists.

Examples
Input
3 6 5 4

Output
2 1 3

Input
40 40 40 60

Output
20 20 20

Input
201 101 101 200

Output
1 100 100
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()
	v := strings.Split(string(input), " ")
	x1, _ := strconv.Atoi(v[0])
	x2, _ := strconv.Atoi(v[1])
	x3, _ := strconv.Atoi(v[2])
	x4, _ := strconv.Atoi(v[3])
	sol1154A(x1, x2, x3, x4)
}

func sol1154A(x1, x2, x3, x4 int) {
	if x1 > x2 && x1 > x3 && x1 > x4 {
		fmt.Print(x1-x2, x1-x3, x1-x4)
	} else if x2 > x1 && x2 > x3 && x2 > x4 {
		fmt.Print(x2-x1, x2-x3, x2-x4)
	} else if x3 > x1 && x3 > x2 && x3 > x4 {
		fmt.Print(x3-x1, x3-x2, x3-x4)
	} else if x4 > x1 && x4 > x2 && x4 > x3 {
		fmt.Print(x4-x1, x4-x2, x4-x3)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	x := make([]int, 4)
	fmt.Scan(&x[0], &x[1], &x[2], &x[3])
	sort.Ints(x)
	fmt.Println(x[3]-x[0], x[3]-x[1], x[3]-x[2])
}

package main

import(
    "fmt"
    "sort"
)

func main(){
    var(
       arr = make([]int,4)
    )
    fmt.Scan(&arr[0],&arr[1],&arr[2],&arr[3])
    sort.Ints(arr)
    fmt.Println(arr[3]-arr[2],arr[3]-arr[1],arr[3]-arr[0])
}

package main

import "fmt"

func insertionSort(array []int) []int {
	var key, j, n int
	n = len(array)
	for i := 1; i < n; i++ {
		key = array[i]
		j = i - 1
		for j >= 0 && array[j] > key {
			array[j + 1] = array[j]
			j--
		}
		array[j + 1] = key
	}
	return array
}

func main() {
	var x1, x2, x3, x4 int
	_, _ = fmt.Scan(&x1, &x2, &x3, &x4)
	var arr = []int{x1, x2, x3, x4}
	array := insertionSort(arr)
	for i := 0; i < 3; i++ {
		fmt.Print(array[3]- array[i], " ")
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	ch := make([]int, 4)
	fmt.Scan(&ch[0], &ch[1], &ch[2], &ch[3])
	sort.Ints(ch)
	fmt.Println(ch[3]-ch[0], ch[3]-ch[1], ch[3]-ch[2])
}

package main

import (
	"fmt"
)

func max(a, b, c, d int) int {
	if a >= b && a >= c && a >= d {
		return a
	}
	if b >= a && b >= c && b >= d {
		return b
	}
	if c >= a && c >= b && c >= d {
		return c
	}
	if d >= a && d >= b && d >= c {
		return d
	}
	return -1
}

func main() {
	var a, b, c, d int

	fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)
	if a != max(a, b, c, d) {
		fmt.Print(max(a, b, c, d) - a)
		fmt.Print(" ")
	}
	if b != max(a, b, c, d) {
		fmt.Print(max(a, b, c, d) - b)
		fmt.Print(" ")
	}
	if c != max(a, b, c, d) {
		fmt.Print(max(a, b, c, d) - c)
		fmt.Print(" ")
	}
	if d != max(a, b, c, d) {
		fmt.Print(max(a, b, c, d) - d)
		fmt.Print(" ")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var nums [4]uint64
	fmt.Fscanf(in, "%d %d %d %d", &nums[0], &nums[1], &nums[2], &nums[3])
	result := restoringThreeNumbers(nums)
	fmt.Printf("%d %d %d", result[0], result[1], result[2])
}

func restoringThreeNumbers(nums [4]uint64) []uint64 {
	var count int
	mapOfNums := make(map[int]uint64)
	result := make([]uint64, 3, 3)

	sumOfAllNums := (nums[0] + nums[1] + nums[2] + nums[3]) / 3
	for i := 0; i < 4; i++ {
		if nums[i] != sumOfAllNums {
			mapOfNums[count] = nums[i]
			count++
		}
	}

	result[0] = sumOfAllNums - mapOfNums[0]
	result[1] = sumOfAllNums - mapOfNums[1]
	result[2] = sumOfAllNums - mapOfNums[2]

	return result
}

package main

import ("fmt"
        "sort")

func main()  {
	input:=make([]int,4)
	var out [3]int

	for i := 0; i <4; i++ {
		fmt.Scan(&input[i])
	}
	sort.Ints(input)
	for i := 0; i < 3; i++ {
		out[i]=input[3]-input[i]
	}

	fmt.Print(out[0],out[1],out[2])
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	mat := make([]int, 4)
	for i := 0; i < 4; i++ {
		fmt.Fscanf(buf, "%d", &mat[i])
	}
	fmt.Fscanf(buf, "\n")
	sort.Ints(mat)
	x1 :=(mat[0]+mat[1]-mat[2])/2
	x2 := mat[0]-x1
	x3 := mat[1]-x1
	fmt.Printf("%d %d %d\n",x1,x2,x3)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	arr := make([]int, 4, 4)
	for i := 0; i < 4; i++ {
		fmt.Scanf("%d", &arr[i])
	}
	sort.Ints(arr)
	for i := 0; i < 3; i++ {
		fmt.Printf("%d ", (arr[3] - arr[i]))
	}
}

package main

import (
	"fmt"
)

func max(nums []int) int {
	max := nums[0]

	var n int
	for _, n = range nums {
		if n > max {
			max = n
		}
	}

	return max
}

func main() {
	var nums []int
	for i := 0; i < 4; i++ {
		var n int

		fmt.Scanf("%d", &n)
		nums = append(nums, n)
	}

	m := max(nums)

	var nums1 []int

	for _, n := range nums {
		if n != m {
			nums1 = append(nums1, n)
		}
	}

	var ab, bc, ac int
	ab, bc, ac = nums1[0], nums1[1], nums1[2]

	c := m - ab
	a := m - bc
	b := m - ac

	if a+b+c == m {
		fmt.Println(a, b, c)
		return
	}

	bc, ac, ab = nums1[0], nums1[1], nums1[2]

	c = m - ab
	a = m - bc
	b = m - ac

	if a+b+c == m {
		fmt.Println(a, b, c)
		return
	}

	ac, ab, bc = nums1[0], nums1[1], nums1[2]

	c = m - ab
	a = m - bc
	b = m - ac

	if a+b+c == m {
		fmt.Println(a, b, c)
		return
	}
}

package main

import "fmt"

func main() {
	var buf []int
	var n, maxn int
	for i:=0; i<4; i++ {
		fmt.Scan(&n)
		buf = append(buf, n)
	}
	for i:=0; i<4; i++ {
		if buf[i]>maxn {
			maxn = buf[i]
		}
	}
	for i:= 0; i<4; i++ {
		if buf[i] != maxn {
			fmt.Print(maxn-buf[i], " ")
		}
	}
}

package main

import (
	"fmt"
)

func max(nums []int) (int, int) {
	max := nums[0]
	max_index := 0

	for i, n := range nums {
		if n > max {
			max = n
			max_index = i
		}
	}

	return max, max_index
}

func main() {
	var nums []int

	for i := 0; i < 4; i++ {
		var n int

		fmt.Scanf("%d", &n)
		nums = append(nums, n)
	}

	m, i := max(nums)
	nums = append(nums[:i], nums[i+1:]...)

	var ab, bc, ac *int
	var a, b, c int
	for i := 0; i < 3; i++ {
		ab = &nums[(0+i)%len(nums)]
		bc = &nums[(1+i)%len(nums)]
		ac = &nums[(2+i)%len(nums)]

		c = m - *ab
		a = m - *bc
		b = m - *ac

		if a+b+c == m {
			break
		}
	}
	fmt.Println(a, b, c)
}

package main

import (
	"fmt"
)

func main() {

	var a, b, c, d int
	fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)

	if a > b && a > c && a > d {
		fmt.Print(a-b, a-c, a-d)
	} else if b > a && b > c && b > d {
		fmt.Print(b-a, b-c, b-d)
	} else if c > a && c > b && c > d {
		fmt.Print(c-a, c-b, c-d)
	} else if d > a && d > b && d > c {
		fmt.Print(d-a, d-b, d-c)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

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

func main()  {
	//a + b
	//a + c
	//b + c
	//a + b + c

	var x1,x2,x3,x4 int
	fmt.Scan(&x1)
	fmt.Scan(&x2)
	fmt.Scan(&x3)
	fmt.Scan(&x4)
	m := max(x1,max(x2,max(x3,x4)))
	 a1,a2,a3,a4 := 0,0,0,0
	if(m != x1){
		a1 = m - x1
	}
	if(m != x2){
		a2 = m - x2
	}
	if(m != x3){
		a3 = m - x3
	}
	if(m != x4){
		a4 = m - x4
	}
	if(a1 != 0){
		fmt.Print(a1," ")
	}
	 if(a2 != 0){
	 	fmt.Print(a2," ")
	 }
	 if(a3 != 0){
	 	fmt.Print(a3," ")
	 }
	 if(a4 != 0){
	 	fmt.Print(a4," ")
	 }

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

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

func main()  {
	//a + b
	//a + c
	//b + c
	//a + b + c

	a := make([]int,4,4)
	for i := 0 ; i < 4;i++{
			var x int
			fmt.Scan(&x)
			a[i] = x
	}
	sort.Ints(a)
	fmt.Print(a[3] - a[2]," ",a[3] - a[1]," ",a[3] - a[0])

}

package main

import (
	"fmt"
	"sort"
)

const alen = 4

// https://codeforces.com/problemset/problem/1154/A
// комментарии к решению
// Пусть s1 <= s2 <= s3 <= s4 и
// a + b = s1
// b + c = s2
// a + c = s3
// a + b + c = s4
// Тогда
// a = s4 - s2
// b = s4 - s3
// c = s4 - s1
func taskSolution(in []int) string {
	sort.Ints(in)
	s1, s2, s3, s4 := in[0], in[1], in[2], in[3]
	a, b, c := s4-s2, s4-s3, s4-s1
	return fmt.Sprint(a, b, c)
}

func main() {
	a := []int{}
	for i := 0; i < alen; i += 1 {
		var ai int
		if _, err := fmt.Scan(&ai); err != nil {
			panic(err)
		}
		a = append(a, ai)
	}

	fmt.Println(taskSolution(a))
}

package main

import "fmt"

func main(){
	var i, sum3 int
	x := make([]int, 4)
	for i = 0; i < 4; i++{
		fmt.Scan(&x[i])
		if x[i] > sum3{
			sum3 = x[i]
		}
	}
	for i = 3; i >= 0; i--{
		if x[i] != sum3{
			fmt.Print(sum3 - x[i], " ")
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	a := make([]int, 4)

	_, _ = fmt.Scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3])

	sort.Ints(a)

	fmt.Printf("%d ", a[3]-a[0])
	fmt.Printf("%d ", a[3]-a[1])
	fmt.Printf("%d ", a[3]-a[2])

}

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024*1024)
	line := readLine(reader)

	nums := strings.Split(line, " ")
	ints := make([]int, len(nums))
	max := 0
	for i, s := range nums {
		ints[i], _ = strconv.Atoi(s)
		if ints[i] > max {
			max = ints[i]
		}
	}
	var results []string
	for i := 0; i < len(ints); i++ {
		if max-ints[i] != 0 {
			results = append(results, strconv.Itoa(max-ints[i]))
		}
	}
	fmt.Println(strings.Join(results, " "))
}

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

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

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

package main

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

var reader = bufio.NewReader(os.Stdin)

func readInt() int {
	var ch byte
	var err error
	for {
		ch, err = reader.ReadByte()
		if err != nil {
			return 0
		}
		if unicode.IsDigit(rune(ch)) {
			break
		}
	}
	result := int(ch & 0xf)
	for {
		ch, err = reader.ReadByte()
		if err != nil || !unicode.IsDigit(rune(ch)) {
			return result
		}
		result = result*10 + int(ch&0xf)
	}
}

func main() {
	arr := make([]int, 4, 4)
	for i := 0; i < 4; i++ {
		arr[i] = readInt()
	}
	sort.Ints(arr)
	fmt.Printf("%d %d %d", arr[3]-arr[0], arr[3]-arr[1], arr[3]-arr[2])
}

package main

import (
	"fmt"
)

func main() {
	var mas [4]uint32

	for k := 0; k < len(mas); k++ {
		fmt.Scan(&mas[k])
	}
	//+сортировка пузырьком
	var i = 0
	var swapCnt = false

	for i < len(mas) {
		if i+1 != len(mas) && mas[i] > mas[i+1] {
			mas[i], mas[i+1] = mas[i+1], mas[i]
			swapCnt = true
		}
		i++
		if i == len(mas) && swapCnt == true {
			swapCnt = false
			i = 0
		}
	}
	//-сортировка пузырьком

	fmt.Println(mas[3]-mas[0], mas[3]-mas[1], mas[3]-mas[2])

}

package main

import (
	"fmt"
	"sort"
)

func main () {
	var arr []int
	var a int
	for i:=0; i<4; i++ {
		fmt.Scan(&a)
		arr = append(arr, a)
	}
	sort.Ints(arr)
	fmt.Println(arr[3]-arr[0], arr[3]-arr[1], arr[3]-arr[2])
}

package main

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

func toIntArray(f string) []int {
	sp := strings.Split(f, " ")
	rs := make([]int, len(sp))
	for i, v := range sp {
		rs[i], _ = strconv.Atoi(v)
	}
	return rs
}

func main() {
	reader := bufio.NewScanner(os.Stdin)
	reader.Scan()

	ints := toIntArray(reader.Text())
	sort.Ints(ints)
	fmt.Println(ints[3]-ints[2], ints[3]-ints[1], ints[3]-ints[0])
}

package main

import "fmt"

// https://codeforces.com/problemset/problem/1154/A
// A. Restoring Three Numbers
// time limit per test
// 1 second
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// Polycarp has guessed three positive integers a
// , b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c

// .

// You have to guess three numbers a
// , b and c

// using given numbers. Print three guessed integers in any order.

// Pay attention that some given numbers a
// , b and c can be equal (it is also possible that a=b=c

// ).
// Input

// The only line of the input contains four positive integers x1,x2,x3,x4
// (2≤xi≤109) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number x1,x2,x3,x4

// .
// Output

// Print such positive integers a
// , b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists.

func main() {
	var x1, x2, x3, x4 int
	_, _ = fmt.Scan(&x1, &x2, &x3, &x4)

	xMax := intMax(x1, x2, x3, x4)

	for _, x := range []int{x1, x2, x3, x4} {
		if x < xMax {
			_, _ = fmt.Print(xMax-x, " ")
		}
	}
}

func intMax(ints ...int) int {
	max := ints[0]
	for i := 1; i < len(ints); i++ {
		if ints[i] > max {
			max = ints[i]
		}
	}
	return max
}

// Author: sighduck
// URL: https://codeforces.com/contest/1154/problem/A

package main

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

type Solution struct {
	A int
	B int
	C int
}

func Solve(w, x, y, z int) Solution {
	a := []int{w, x, y, z}
	sort.Ints(a)
	return Solution{a[3] - a[0], a[3] - a[1], a[3] - a[2]}
}

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

	var w, x, y, z int
	fmt.Fscanf(reader, "%d %d %d %d\n", &w, &x, &y, &z)

	solution := Solve(w, x, y, z)
	fmt.Fprintf(writer, "%d %d %d\n", solution.A, solution.B, solution.C)
}

package main

import (
	"fmt"
	"sort"
)

func main()  {
	var num [4]int

	for i := 0; i < 4; i++ {
		fmt.Scanf("%d", &num[i])
	}
	sort.Ints(num[:])

	a := num[3] - num[0]
	b := num[3] - num[1]
	c := num[3] - num[2]

	fmt.Printf("%d %d %d", a, b, c)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var sum1, sum2, sum3, sum4 int
	fmt.Scan(&sum1, &sum2, &sum3, &sum4)
	var nums = []int{sum1, sum2, sum3, sum4}
	sort.Ints(nums)
	fmt.Println(nums[3]-nums[0], nums[3]-nums[1], nums[3]-nums[2])
}

package main

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

var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var a [4]int

func main() {
	for i := 0; i < 4; i++ {
		fmt.Fscan(reader, &a[i])
	}
	sort.Sort(sort.IntSlice(a[:]))
	fmt.Println(a[3]-a[0], a[3]-a[1], a[3]-a[2])
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var q,w,e,r uint32
	fmt.Fscanf(in, "%d %d %d %d", &q, &w, &e, &r)
	if q > w && q > e && q > r{
		fmt.Println(q-w, q-e, q-r)
	}else if w > q && w > e && w > r{
		fmt.Println(w-q, w-e, w-r)
	}else if e > q && e > w && e > r{
		fmt.Println(e-q, e-w, e-r)
	}else if r > q && r > w && r > e{
		fmt.Println(r-q, r-w, r-e)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	buf := []int{a, b, c, d}
	sort.Ints(buf)
	fmt.Print(buf[3]-buf[0], buf[3]-buf[1], buf[3]-buf[2])
}

package main

import (
	"fmt"
	"sort"
)

func main()  {
	var num [4]int

	for i := 0; i < 4; i++ {
		fmt.Scanf("%d", &num[i])
	}
	sort.Ints(num[:])
	tot := num[3]

	a := tot - num[0]
	b := tot - num[1]
	c := tot - num[2]
	fmt.Println(a, b, c)

}

package main

import ("fmt")

func max(x , y int) int {
	if(x>y){
		return x
	} else{
		return y
	}
}
func main(){
	var a ,b,c,d int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

    var z int  = max(a , max(b , max(c , d)))

    if(z-a > 0){
    	fmt.Print(z-a)
    	fmt.Print(" ")
    }
    if(z-b > 0){
    	fmt.Print(z-b)
    	fmt.Print(" ")
    }
    if(z-c > 0){
    	fmt.Print(z-c)
    	fmt.Print(" ")
    }
    if(z-d > 0){
    	fmt.Print(z-d)
    	fmt.Print(" ")
    }
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	a := [4]int{}
	fmt.Fscanf(reader, "%d %d %d %d\n", &a[0], &a[1], &a[2], &a[3])
	for i := 1; i < 4; i++ {
		if a[i] > a[0] {
			a[0], a[i] = a[i], a[0]
		}
	}
	fmt.Fprintf(writer, "%d %d %d\n", a[0]-a[1], a[0]-a[2], a[0]-a[3])
}

//Sri VatapatraSayi's Grace

package main

import (
	"fmt"
	"sort"
)

func main() {

	var receive int

	slice := make([]int, 4)
	for i := 0; i < 4; i++ {
		fmt.Scan(&receive)
		slice[i] = receive
	}

	sort.Ints(slice)
	for i := 0; i < 3; i++ {
		fmt.Print(slice[3]-slice[i], " ")
	}
}

package main

import "fmt"

func main() {
	var m [4]int

	for i := 0; i < 4; i++ {
		fmt.Scan(&m[i])
		if m[i] > m[0] {
			tmp := m[0]
			m[0] = m[i]
			m[i] = tmp
		}
	}

	for i := 1; i < 4; i++ {
		fmt.Print(m[0] - m[i], " ")
	}
}

package main

import "fmt"

func main() {
	sum := make([]int, 4)
	tot := 0
	for i:=0; i<4; i++ {fmt.Scan(&sum[i]); tot += sum[i]}
	max, maxI := 0, 0
	for k, v := range sum {
		if v > max {max, maxI = v, k}
	}
	tot -= max
	c, abI := 0, 0
	for k, v := range sum {
		if k == maxI {continue}
		if (tot - v) % 2 == 0 {c, abI = (max - v), k; continue}
	}
	for k, v := range sum {
		if k == maxI || k == abI {continue}
		fmt.Print(v - c)
		fmt.Print(" ")
	}
	fmt.Println(c)
}

package main

import (
	"fmt"
	"sort"
)

//a+b, a+c, b+c, a+b+c
func solve(x ...int64) (int64, int64, int64) {
	var a, b, c int64
	/*
		b = x1 -a
		c = x2 - a
		a - 2a + x1 + x2 = x4
		a = -x4 +x1 + x2
	*/

	sort.Slice(x, func(i, j int) bool {
		return x[i] < x[j]
	})

	a = -x[3] + x[0] + x[1]
	b = x[0] - a
	c = x[1] - a

	return a, b, c
}

func main() {
	var x1, x2, x3, x4 int64

	fmt.Scan(&x1, &x2, &x3, &x4)

	a, b, c := solve(x1, x2, x3, x4)
	fmt.Println(a, b, c)
}

package main

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

func main(){
	in := bufio.NewReader(os.Stdin)
	var input [4]int
	fmt.Fscan(in,&input[0],&input[1],&input[2],&input[3])
	max,left := max4(input)
	for _,v := range left{
		fmt.Printf("%d ",max -v )
	}
}

func max4(input [4]int) (int,[]int){
	maxIdx := 0
	for i:=0;i<len(input);i++{
		if input[maxIdx]<input[i]{
			maxIdx = i
		}
	}
	return input[maxIdx],append(input[0:maxIdx],input[maxIdx+1:len(input)]...)
}

package main

import ("fmt"
        "sort")

func main()  {
	input:=make([]int,4)
	var out [3]int

	for i := 0; i <4; i++ {
		fmt.Scan(&input[i])
	}
	sort.Ints(input)
	for i := 0; i < 3; i++ {
		out[i]=input[3]-input[i]
	}

	fmt.Print(out)
}

package main

import "fmt"

func main() {
	var buf []int
	var a, b, c, n int
	for i:=0; i<4; i++ {
		fmt.Scan(&n)
		buf = append(buf, n)
	}
	c = buf[3]-buf[0]
	b = buf[2]-c
	a = buf[1]-c
	fmt.Println(a, b, c)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

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

func main()  {
	//a + b
	//a + c
	//b + c
	//a + b + c

	var x1,x2,x3,x4 int
	fmt.Scan(&x1)
	fmt.Scan(&x2)
	fmt.Scan(&x3)
	fmt.Scan(&x4)
	c := x4 - x1
	a := x2 - c
	b := x1 - a
	fmt.Print(a,b,c)

}

package main

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

var reader *bufio.Reader

func readLine() string {
	r, _ := reader.ReadString('\n')
	return strings.Trim(r, "\n")
}

func solve(nums []int) {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	for i := 1; i < 4; i++ {
		if nums[0] < nums[i] {
			nums[0], nums[i] = nums[i], nums[0]
		}
	}
	fmt.Fprintf(out, "%d %d %d", nums[0]-nums[1], nums[0]-nums[2], nums[0]-nums[3])
}

func main() {
	reader = bufio.NewReader(os.Stdin)
	line := readLine()
	numsStr := strings.Split(line, " ")
	nums := make([]int, len(numsStr))
	for i := 0; i < len(numsStr); i++ {
		nums[i], _ = strconv.Atoi(numsStr[i])
	}
	solve(nums)
}

package main

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

var reader *bufio.Reader

func readLine() string {
	r, _ := reader.ReadString('\n')
	return strings.Trim(r, "\n")
}

func solve(nums []int) {
	for i := 1; i < 4; i++ {
		if nums[0] < nums[i] {
			nums[0], nums[i] = nums[i], nums[0]
		}
	}
	fmt.Printf("%d %d %d", nums[0]-nums[1], nums[0]-nums[2], nums[0]-nums[3])
}

func main() {
	reader = bufio.NewReader(os.Stdin)
	line := readLine()
	numsStr := strings.Split(line, " ")
	nums := make([]int, len(numsStr))
	for i := 0; i < len(numsStr); i++ {
		nums[i], _ = strconv.Atoi(numsStr[i])
	}
	solve(nums)
}

package main

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

var reader *bufio.Reader

func readLine() string {
	r, _ := reader.ReadString('\n')
	return strings.Trim(r, "\n")
}

func solve(nums []int) {
	for i := 1; i < 4; i++ {
		if nums[0] < nums[i] {
			nums[0], nums[i] = nums[i], nums[0]
		}
	}
	fmt.Printf("%d %d %d\n", nums[0]-nums[1], nums[0]-nums[2], nums[0]-nums[3])
}

func main() {
	reader = bufio.NewReader(os.Stdin)
	line := readLine()
	numsStr := strings.Split(line, " ")
	nums := make([]int, len(numsStr))
	for i := 0; i < len(numsStr); i++ {
		nums[i], _ = strconv.Atoi(numsStr[i])
	}
	solve(nums)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var nums [4]int
	fmt.Fscanf(in, "%d %d %d %d", &nums[0], &nums[1], &nums[2], &nums[3])
	fmt.Println(restoringThreeNumbers(nums))
}

func restoringThreeNumbers(nums [4]int) (int, int, int) {
	var count int
	mapOfNums := make(map[int]int)

	sumOfAllNums := (nums[0] + nums[1] + nums[2] + nums[3]) / 3

	for i := 0; i < 4; i++ {
		if nums[i] != sumOfAllNums {
			mapOfNums[count] = nums[i]
			count++
		}
	}

	num1 := sumOfAllNums - mapOfNums[0]
	num2 := mapOfNums[1] - num1
	num3 := mapOfNums[2] - num2

	return num1, num2, num3
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var nums [4]int
	fmt.Fscanf(in, "%d %d %d %d", &nums[0], &nums[1], &nums[2], &nums[3])
	result := restoringThreeNumbers(nums)
	fmt.Printf("%d %d %d", result[0], result[1], result[2])
}

func restoringThreeNumbers(nums [4]int) []int {
	var count int
	mapOfNums := make(map[int]int)
	result := make([]int, 3, 3)

	sumOfAllNums := (nums[0] + nums[1] + nums[2] + nums[3]) / 3

	for i := 0; i < 4; i++ {
		if nums[i] != sumOfAllNums {
			mapOfNums[count] = nums[i]
			count++
		}
	}

	result[0] = sumOfAllNums - mapOfNums[0]
	result[1] = sumOfAllNums - mapOfNums[1]
	result[2] = sumOfAllNums - mapOfNums[2]

	return result
}

package main

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

func readLineOfInts(reader *bufio.Reader) []int {
	line, _ := reader.ReadString('\n')
	line = strings.Trim(line, "\n")
	splits := strings.Split(line, " ")
	ints := make([]int, len(splits))
	for i, v := range splits {
		i64, _ := strconv.ParseInt(v, 10, 32)
		ints[i] = int(i64)
	}
	return ints
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	ints := readLineOfInts(reader)
	sort.Ints(ints)
	fmt.Println(ints[3]-ints[2], ints[3]-ints[1], ints[3]-ints[0])
}

package main

import (
	"fmt"
)

func max(nums []int) (int, int) {
	max := nums[0]
	max_index := 0

	for i, n := range nums {
		if n > max {
			max = n
			max_index = i
		}
	}

	return max, max_index
}

func main() {
	var nums []int

	for i := 0; i < 4; i++ {
		var n int

		fmt.Scanf("%d", &n)
		nums = append(nums, n)
	}

	m, i := max(nums)
	nums = append(nums[:i], nums[i:]...)

	var ab, bc, ac *int
	var a, b, c int
	for i := 0; i < 3; i++ {
		ab = &nums[(0+i)%len(nums)]
		bc = &nums[(1+i)%len(nums)]
		ac = &nums[(2+i)%len(nums)]

		c = m - *ab
		a = m - *bc
		b = m - *ac

		if a+b+c == m {
			break
		}
	}
	fmt.Println(a, b, c)
}


package main

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

func modinv(b, m int) int {
	return modexp(b, m - 2, m)
}

func modexp(b, p, m int) int {
	if b == 0 { return 0 }
	if p == 0 { return 1 }
	if p == 1 { return b % m }
	res := modexp(b, p>>1, m)
	res = (res * res) % m
	if p % 2 == 1 { res = (b * res) % m }
	return res
}

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

	mod := 998244353
	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, k, zk int
		fmt.Fscan(r, &n)

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

		for i := 0; i < k; i++ {
			zk += a[i]
		}

		res := 0
		for i := 1; i <= zk; i++ {
			res += ((n*n)%mod - n) * modinv(2*i*i, mod)
			res %= mod
		}
		fmt.Fprintln(w, res)
	}

}

package main

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

func modinv(b, m int) int {
	return modexp(b, m - 2, m)
}

func modexp(b, p, m int) int {
	if b == 0 { return 0 }
	if p == 0 { return 1 }
	if p == 1 { return b % m }
	res := modexp(b, p>>1, m)
	res = (res * res) % m
	if p % 2 == 1 { res = (b * res) % m }
	return res
}

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

	mod := 998244353
	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, k, zk int
		fmt.Fscan(r, &n)

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

		for i := 0; i < k; i++ {
			zk += a[i]
		}

		res := 0
		for i := 1; i <= zk; i++ {
			res += modinv(2*i*i, mod)
			res %= mod
		}
		res = ( res * ((n*(n-1))%mod) ) % mod
		fmt.Fprintln(w, res)
	}

}

package main

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

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

const MOD int64 = 998244353

var T, N int64
var A []int64

func mpow(a, n int64) int64 {
	if n == 0 {
		return 1
	}
	r := mpow(a, n/2)
	r = (r * r) % MOD
	if n%2 == 1 {
		r *= a
	}
	return r % MOD
}

func reverse(a int64) int64 {
	return mpow(a, MOD-2)
}

func solve() int64 {
	n0, n1 := int64(0), int64(0)
	for i := 0; int64(i) < N; i++ {
		if A[i] == 0 {
			n0 += 1
		} else {
			n1 += 1
		}
	}
	dp := make([]int64, n0+1)

	dp[n0] = 0
	for i := n0 - 1; i >= 0; i-- {
		var p int64 = (((2 * (((n0 - i) * (n0 - i)) % MOD)) % MOD) * reverse((N*(N-1))%MOD)) % MOD
		dp[i] = (((1 + (p*dp[i+1])%MOD) % MOD) * reverse(p)) % MOD
	}

	c := 0
	for i := 0; int64(i) < n0; i++ {
		if A[i] == 0 {
			c += 1
		}
	}

	return dp[c] % MOD
}

func main() {
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	A = make([]int64, 200005)
	for tt := int64(1); tt <= T; tt += 1 {
		fmt.Fscan(in, &N)
		for i := 0; int64(i) < N; i++ {
			fmt.Fscan(in, &A[i])
		}

		fmt.Println(solve())
	}
}

package main

import "fmt"

const mod = 998244353

func qpow(a, b int64) int64 {
	var ans int64
	ans = 1
	for b > 0 {
		if b%2 == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		b >>= 1
	}
	return ans
}

func cal(x int64) int64 {
	return qpow(x*x%mod, mod-2)
}

func solve() {
	var n, k, sum, i int64
	var arr []int64
	fmt.Scan(&n)
	for i = 0; i < n; i++ {
		var tmp int64
		fmt.Scan(&tmp)
		arr = append(arr, tmp)
		sum += tmp
	}
	for i = 0; i < n-sum; i++ {
		k += arr[i]
	}

	var ans int64
	for i = 0; i <= k; i++ {
		ans = (ans + cal(i)) % mod
	}
	ans = (((ans * n) % mod) * (n - 1)) % mod
	ans = (ans * qpow(2, mod-2)) % mod
	fmt.Println(ans)
}

func main() {
	tt := 0
	fmt.Scan(&tt)
	for i := 0; i < tt; i++ {
		solve()
	}
}

package main

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

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

var MOD int64 = 998244353

var T, N int64
var A []int64

func mpow(a, n int64) int64 {
	if n == 0 {
		return 1
	}
	r := mpow(a, n/2)
	r = (r * r) % MOD
	if n%2 == 1 {
		r *= a
	}
	return r % MOD
}

func reverse(a int64) int64 {
	return mpow(a, MOD-2)
}

func solve() int64 {
	n0, n1 := int64(0), int64(0)
	for i := 0; int64(i) < N; i++ {
		if A[i] == 0 {
			n0 += 1
		} else {
			n1 += 1
		}
	}
	dp := make([]int64, n0+1)

	dp[n0] = 0
	for i := n0 - 1; i >= 0; i-- {
		p := (((2 * ((n0 - i) * (n0 - i) % MOD)) % MOD) * reverse(N*(N-1))) % MOD
		dp[i] = ((1 + (p*dp[i+1])%MOD) % MOD * reverse(p)) % MOD
	}

	c := 0
	for i := 0; int64(i) < n0; i++ {
		if A[i] == 0 {
			c += 1
		}
	}

	return dp[c] % MOD
}

func main() {
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	A = make([]int64, 200005)
	for tt := int64(1); tt <= T; tt += 1 {
		fmt.Fscan(in, &N)
		for i := 0; int64(i) < N; i++ {
			fmt.Fscan(in, &A[i])
		}

		fmt.Println(solve())

	}
}

package main

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

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

var MOD int64 = 998244353

var T, N int64
var A []int64

func mpow(a, n int64) int64 {
	if n == 0 {
		return 1
	}
	r := mpow(a, n/2)
	r = (r * r) % MOD
	if n%2 == 1 {
		r *= a
	}
	return r % MOD
}

func reverse(a int64) int64 {
	return mpow(a, MOD-2)
}

func solve() int64 {
	n0, n1 := int64(0), int64(0)
	for i := 0; int64(i) < N; i++ {
		if A[i] == 0 {
			n0 += 1
		} else {
			n1 += 1
		}
	}
	dp := make([]int64, n0+1)

	dp[n0] = 0
	for i := n0 - 1; i >= 0; i-- {
		p := (((2 * ((n0 - i) * (n0 - i) % MOD)) % MOD) * reverse(N*(N-1))) % MOD
		dp[i] = ((1 + (p*dp[i+1])%MOD) % MOD * reverse(p)) % MOD
	}

	c := 0
	for i := 0; int64(i) < n0; i++ {
		if A[i] == 0 {
			c += 1
		}
	}

	fmt.Fprintln(os.Stderr, c)

	return dp[c]

}

func main() {
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	A = make([]int64, 200005)
	for tt := int64(1); tt <= T; tt += 1 {
		fmt.Fscan(in, &N)
		for i := 0; int64(i) < N; i++ {
			fmt.Fscan(in, &A[i])
		}

		fmt.Println(solve())

	}
}

package main

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

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

var MOD int64 = 998244353

var T, N int64
var A []int64

func mpow(a, n int64) int64 {
	if n == 0 {
		return 1
	}
	r := mpow(a, n/2)
	r = (r * r) % MOD
	if n%2 == 1 {
		r *= a
	}
	return r % MOD
}

func reverse(a int64) int64 {
	return mpow(a, MOD-2)
}

func solve() int64 {
	n0, n1 := int64(0), int64(0)
	for i := 0; int64(i) < N; i++ {
		if A[i] == 0 {
			n0 += 1
		} else {
			n1 += 1
		}
	}
	dp := make([]int64, n0+1)

	dp[n0] = 0
	for i := n0 - 1; i >= 0; i-- {

		p := (((2 * ((n0 - i) * (n0 - i) % MOD)) % MOD) * reverse(N*(N-1))) % MOD
		dp[i] = ((1 + (p*dp[i+1])%MOD) % MOD * reverse(p)) % MOD
	}

	c := 0
	for i := 0; int64(i) < n0; i++ {
		if A[i] == 0 {
			c += 1
		}
	}

	return dp[c]

}

func main() {
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	A = make([]int64, 200005)
	for tt := int64(1); tt <= T; tt += 1 {
		fmt.Fscan(in, &N)
		for i := 0; int64(i) < N; i++ {
			fmt.Fscan(in, &A[i])
		}

		fmt.Println(solve())

	}
}

package main

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

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

var MOD int64 = 998244353

var T, N int64
var A []int64

func mpow(a, n int64) int64 {
	if n == 0 {
		return 1
	}
	r := mpow(a, n/2)
	r = r * r % MOD
	if n%2 == 1 {
		r *= a
	}
	return r % MOD
}

func reverse(a int64) int64 {
	return mpow(a, MOD-2)
}

func solve() int64 {
	n0, n1 := int64(0), int64(0)
	for i := 0; int64(i) < N; i++ {
		if A[i] == 0 {
			n0 += 1
		} else {
			n1 += 1
		}
	}
	dp := make([]int64, n0+1)

	dp[n0] = 0
	for i := n0 - 1; i >= 0; i-- {
		p := (2 * (n0 - i) * (n0 - i) % MOD) * reverse(N*(N-1)) % MOD
		dp[i] = (1 + p*dp[i+1]) % MOD * reverse(p) % MOD
	}

	c := 0
	for i := 0; int64(i) < n0; i++ {
		if A[i] == 0 {
			c += 1
		}
	}

	return dp[c]

}

func main() {
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	A = make([]int64, 200005)
	for tt := int64(1); tt <= T; tt += 1 {
		fmt.Fscan(in, &N)
		for i := 0; int64(i) < N; i++ {
			fmt.Fscan(in, &A[i])
		}

		fmt.Println(solve())

	}
}

package main

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

func modinv(b, m int) int {
	return modexp(b, m - 2, m)
}

func modexp(b, p, m int) int {
	if b == 0 { return 0 }
	if p == 0 { return 1 }
	if p == 1 { return b % m }
	res := modexp(b, p>>1, m)
	res = (res * res) % m
	if p % 2 == 1 { res = (b * res) % m }
	return res
}

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

	mod := 998244353
	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, k, zk int
		fmt.Fscan(r, &n)

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

		for i := 0; i < k; i++ {
			zk += a[i]
		}

		res := 0
		for i := 1; i <= zk; i++ {
			res += modinv(2*i*i, mod)
			res %= mod
		}
		res = (res*n*(n-1)) % mod
		fmt.Fprintln(w, res)
	}

}

package main

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

type frac struct {
	num int
	denom int
}

func sum (f1, f2 frac) frac {
	num := f1.num * f2.denom + f2.num * f1.denom
	denom := f2.denom * f1.denom
	gcd_ := gcd(num, denom)
	return frac{num/gcd_, denom/gcd_}
}

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

func modinv(b, m int) int {
	return modexp(b, m - 2, m)
}

func modexp(b, p, m int) int {
	if b == 0 { return 0 }
	if p == 0 { return 1 }
	if p == 1 { return b }
	res := modexp(b, p>>1, m)
	res = (res * res) % m
	if p % 2 == 1 { res = (b * res) % m }
	return res
}

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

	mod := 998244353
	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, k, zk int
		fmt.Fscan(r, &n)

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

		for i := 0; i < k; i++ {
			zk += a[i]
		}

		res := frac{0, 1}
		for i := 1; i <= zk; i++ {
			res = sum(res, frac{n*(n-1), 2*i*i})
		}

		ans := (res.num * modinv(res.denom, mod)) % mod
		fmt.Fprintln(w, ans)
	}

}


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

func main() {
	var nn, k, l int
	var x[1025]int
	var aa[1025]int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	r.Scan()
	nn, _ = strconv.Atoi(r.Text())
	for i:=0; i<nn; i++ {
		r.Scan()
		aa[i], _ = strconv.Atoi(r.Text())
	}
	x[0]=aa[0]
	if aa[0]<aa[1] {
		x[1]=aa[0]
	} else {
		x[1]=aa[1]
	}
	for i:=2; i<nn; i++ {
		if x[i-1]<aa[i] {
			k=x[i-1]
		} else {
			k=aa[i]
		}
		if x[i-2]<aa[i] {
			l=x[i-2]
		} else {
			l=aa[i]
		}
		if k>l {
			x[i]=k
		} else {
			x[i]=l
		}
	}
	fmt.Println(x[nn-1])
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
  scanner.Scan()
  x, _ := strconv.Atoi(scanner.Text())
  return x
}

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

  n := scanInt(scanner)
  rain := map[int][]int{}
  for pos := 0; pos < n; pos++ {
    day := scanInt(scanner)
    tiles, found := rain[day]
    if !found {
      rain[day] = []int{ pos }
    } else {
      rain[day] = append(tiles, pos)
    }
    tiles = rain[day]
  }
  wreck := make([]bool, n)
  day, done := 0, false
  for !done {
    day++
    tiles, found := rain[day]
    if !found {
      continue
    }
    for _, pos := range tiles {
      if pos == 0 || pos == n-1 || wreck[pos-1] || wreck[pos+1] {
        done = true
        break
      }
      wreck[pos] = true
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", day))
}

// 192B
package main

import (
	"fmt"
)

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

func main() {
	var n int
	fmt.Scan(&n)
	var a [1005]int
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	ans := min(a[0], a[n-1])
	for i := 0; i < n-1; i++ {
		ans = min(ans, max(a[i], a[i+1]))
	}
	fmt.Println(ans)
}

//192B
package main
import "fmt"

func main() {
	var nn, k, l int
	var x[1025]int
	var aa[1025]int
	fmt.Scan(&nn)
	for i:=0; i<nn; i++ {
		fmt.Scanf("%d", &aa[i])
	}
	x[0]=aa[0]
	if aa[0]<aa[1] {
		x[1]=aa[0]
	} else {
		x[1]=aa[1]
	}
	for i:=2; i<nn; i++ {
		if x[i-1]<aa[i] {
			k=x[i-1]
		} else {
			k=aa[i]
		}
		if x[i-2]<aa[i] {
			l=x[i-2]
		} else {
			l=aa[i]
		}
		if k>l {
			x[i]=k
		} else {
			x[i]=l
		}
	}
	fmt.Println(x[nn-1])
}

// 192B
package main

import (
	"fmt"
)

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

func main() {
	var n int
	fmt.Scan(&n)
	var a [1005]int
	for i := 0; i < n; i++ {
		fmt.Scan(a[i])
	}
	ans := min(a[0], a[n-1])
	for i := 0; i < n-1; i++ {
		ans = min(ans, max(a[i], a[i+1]))
	}
	fmt.Println(ans)
}


package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

var reader = bufio.NewReader(os.Stdin)

func main() {
	var n, m int

	fmt.Fscan(reader, &n, &m)

	w := make([]int, n)
	b := make([]int, m)

	d := make([]int, n)
	rs := list.New()

	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &w[i])
	}

	for i := 0; i < m; i++ {
		var j int
		fmt.Fscan(reader, &j)
		b[i] = j - 1
	}

	for i := 0; i < m; i++ {
		if d[b[i]] == 0 {
			rs.PushBack(b[i])
		}
		d[b[i]] = 1
	}

	for i := 0; i < n; i++ {
		if d[i] == 0 {
			rs.PushBack(i)
		}
		d[i] = 1
	}

	var res int

	for i := 0; i < m; i++ {
		e := new(list.Element)
		for e = rs.Front(); e != nil; e = e.Next() {
			if e.Value == b[i] {
				break
			}
			j, _ := e.Value.(int)
			res += w[j]
		}
		rs.Remove(e)
		rs.PushFront(e.Value)
	}

	fmt.Println(res)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int

	fmt.Scanf("%d %d", &n, &m)

	ws := make([]int, n)
	rs := make([]int, m)
	for i := range ws {
		fmt.Scan(&ws[i])
	}
	for i := range rs {
		fmt.Scan(&rs[i])
	}

	fmt.Println(solve(ws, rs))
}

type kv struct {
	k int
	v int
}

func solve(ws []int, rs []int) int {
	count := make(map[int]int)
	state := make([]int, len(ws))

	s := 0
	for _, v := range rs {
		if _, ok := count[v]; ok == false {
			count[v]++
			state[s] = v
			s++
		}
	}

	// fmt.Println(state)

	sum := 0
	for i := range rs {
		for j, v := range state {
			if v == rs[i] {
				newState := make([]int, len(ws))
				if j > 0 {
					newState[0] = v

					copy(newState[1:j+1], state[0:j])
					copy(newState[j+1:], state[j+1:])

					state = newState
					// fmt.Println(state)
				}

				break
			} else {
				sum += ws[v-1]
				// fmt.Printf("lifted: %d\n", v)
			}
		}
	}
	return sum
}

package main

import (
	"fmt"
)

var (
	n      int
	m      int
	w      []int
	b      []int
	result int
)

func in() {
	fmt.Scan(&n, &m)
	w = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&w[i])
	}
	b = make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&b[i])
		b[i]--
	}
}

func out() {
	fmt.Println(result)
}

func run() {
	stack := make([]int, n)
	p := 0
	preproc := make([]bool, n)
	for _, v := range b {
		if !preproc[v] {
			stack[p] = v
			p++
			preproc[v] = true
		}
	}

	result = 0
	for _, book := range b {
		weight := 0
		temp := stack[0]
		i := 0
		for ; stack[i] != book; i++ {
			weight += w[stack[i]]
			stack[i], temp = temp, stack[i]
		}
		stack[0], stack[i] = stack[i], temp
		result += weight
	}
}

func main() {
	in()
	run()
	out()
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int

	fmt.Scanf("%d %d", &n, &m)

	ws := make([]int, n)
	rs := make([]int, m)
	for i := range ws {
		fmt.Scan(&ws[i])
	}
	for i := range rs {
		fmt.Scan(&rs[i])
	}

	fmt.Println(solve(ws, rs))
}

type kv struct {
	k int
	v int
}

type KvList []kv

func (kvl KvList) Swap(i, j int) { kvl[i], kvl[j] = kvl[j], kvl[i] }
func (kvl KvList) Len() int      { return len(kvl) }
func (kvl KvList) Less(i, j int) bool {
	if kvl[i].v == kvl[j].v {
		return kvl[i].k < kvl[j].k
	}
	return kvl[i].v > kvl[j].v
}

func solve(ws []int, rs []int) int {
	count := make(map[int]int)

	for _, v := range rs {
		count[v]++
	}

	var ss KvList
	for k, v := range count {
		ss = append(ss, kv{k, v})
	}

	sort.Sort(ss)

	state := make([]int, len(ws))

	for i := range state {
		state[i] = ss[i].k
	}

	// fmt.Println(state)

	sum := 0
	for i := range rs {
		for j, v := range state {
			if v == rs[i] {
				newState := make([]int, len(ws))
				if j > 0 {
					newState[0] = v

					copy(newState[1:j+1], state[0:j])
					copy(newState[j+1:], state[j+1:])

					state = newState
					// fmt.Println(state)
				}

				break
			} else {
				sum += ws[v-1]
				// fmt.Printf("lifted: %d\n", v)
			}
		}
	}
	return sum
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int

	fmt.Scanf("%d %d", &n, &m)

	ws := make([]int, n)
	rs := make([]int, m)
	for i := range ws {
		fmt.Scan(&ws[i])
	}
	for i := range rs {
		fmt.Scan(&rs[i])
	}

	fmt.Println(solve(ws, rs))
}

type kv struct {
	k int
	v int
}

type KvList []kv

func (kvl KvList) Swap(i, j int) { kvl[i], kvl[j] = kvl[j], kvl[i] }
func (kvl KvList) Len() int      { return len(kvl) }
func (kvl KvList) Less(i, j int) bool {
	if kvl[i].v == kvl[j].v {
		return kvl[i].k < kvl[j].k
	}
	return kvl[i].v > kvl[j].v
}

func solve(ws []int, rs []int) int {
	count := make(map[int]int)

	for _, v := range rs {
		count[v]++
	}

	var ss KvList
	for k, v := range count {
		ss = append(ss, kv{k, v})
	}

	fmt.Println(ss)
	sort.Sort(ss)
	fmt.Println(ss)

	state := make([]int, len(ws))

	for i := range state {
		state[i] = ss[i].k
	}

	fmt.Println(state)

	sum := 0
	for i := range rs {
		for j, v := range state {
			if v == rs[i] {
				newState := make([]int, len(ws))
				if j > 0 {
					newState[0] = v

					copy(newState[1:j+1], state[0:j])
					copy(newState[j+1:], state[j+1:])

					state = newState
					fmt.Println(state)
				}

				break
			} else {
				sum += v
				fmt.Printf("lifted: %d\n", v)
			}
		}
	}
	return sum
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int

	fmt.Scanf("%d %d", &n, &m)

	ws := make([]int, n)
	rs := make([]int, m)
	for i := range ws {
		fmt.Scan(&ws[i])
	}
	for i := range rs {
		fmt.Scan(&rs[i])
	}

	fmt.Println(solve(ws, rs))
}

type kv struct {
	k int
	v int
}

type KvList []kv

func (kvl KvList) Swap(i, j int) { kvl[i], kvl[j] = kvl[j], kvl[i] }
func (kvl KvList) Len() int      { return len(kvl) }
func (kvl KvList) Less(i, j int) bool {
	if kvl[i].v == kvl[j].v {
		return kvl[i].k < kvl[j].k
	}
	return kvl[i].v > kvl[j].v
}

func solve(ws []int, rs []int) int {
	count := make(map[int]int)

	for _, v := range rs {
		count[v]++
	}

	var ss KvList
	for k, v := range count {
		ss = append(ss, kv{k, v})
	}

	sort.Sort(ss)

	state := make([]int, len(ws))

	for i := range state {
		state[i] = ss[i].k
	}

	// fmt.Println(state)

	sum := 0
	for i := range rs {
		for j, v := range state {
			if v == rs[i] {
				newState := make([]int, len(ws))
				if j > 0 {
					newState[0] = v

					copy(newState[1:j+1], state[0:j])
					copy(newState[j+1:], state[j+1:])

					state = newState
					// fmt.Println(state)
				}

				break
			} else {
				sum += v
				// fmt.Printf("lifted: %d\n", v)
			}
		}
	}
	return sum
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

var reader = bufio.NewReader(os.Stdin)

func main() {
	var n, m int

	fmt.Fscan(reader, &n, &m)

	w := make([]int, n)
	b := make([]int, m)

	d := make([]int, n)
	rs := list.New()

	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &w[i])
	}

	for i := 0; i < m; i++ {
		var j int
		fmt.Fscan(reader, &j)
		b[i] = j - 1
	}

	for i := 0; i < m; i++ {
		if d[b[i]] == 0 {
			rs.PushBack(b[i])
		}
		d[b[i]] = 1
	}

	for i := 0; i < n; i++ {
		if d[i] == 0 {
			rs.PushBack(i)
		}
		d[i] = 1
	}

	var res int

	for i := 0; i < m; i++ {
		e := new(list.Element)
		for e = rs.Front(); e != nil; e = e.Next() {
			if e.Value == b[i] {
				break
			}
			res += w[b[i]]
		}
		rs.Remove(e)
		rs.PushFront(e.Value)
	}

	fmt.Println(res)
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

var reader = bufio.NewReader(os.Stdin)

func main() {
	var n, m int

	fmt.Fscan(reader, &n, &m)

	w := make([]int, n)
	b := make([]int, m)

	d := make([]int, n)
	rs := list.New()

	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &w[i])
	}

	for i := 0; i < m; i++ {
		var j int
		fmt.Fscan(reader, &j)
		b[i] = j - 1
	}

	for i := 0; i < m; i++ {
		if d[b[i]] == 0 {
			rs.PushBack(b[i])
		}
		d[b[i]] = 1
	}

	for i := 0; i < n; i++ {
		if d[i] == 0 {
			rs.PushBack(i)
		}
		d[i] = 1
	}

	var res int

	for i := 0; i < m; i++ {
		e := new(list.Element)
		for e = rs.Front(); e != nil; e = e.Next() {
			if e.Value == b[i] {
				break
			}
			j, _ := e.Value.(int)
			res += w[b[j]]
		}
		rs.Remove(e)
		rs.PushFront(e.Value)
	}

	fmt.Println(res)
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF963A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 9
	pow := func(x int64, n int64) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}
	inv := func(a int64) int64 { return pow(a, mod-2) }
	frac := func(a, b int64) int64 { return a * inv(b) % mod }

	var n, a, b, k, ans int64
	var s []byte
	Fscan(in, &n, &a, &b, &k, &s)
	q := frac(b, a)
	for i := k - 1; i >= 0; i-- {
		ans *= q
		if s[i] == '+' {
			ans++
		} else {
			ans += mod - 1
		}
		ans %= mod
	}
	q = pow(q, k)
	n = (n + 1) / k
	if q == 1 {
		ans = ans * n % mod
	} else {
		ans = ans * frac(pow(q, n)-1, q-1) % mod
	}
	ans = ans * pow(a, n*k-1) % mod
	if ans < 0 {
		ans += mod
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF963A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 9
	pow := func(x int64, n int64) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}
	inv := func(a int64) int64 { return pow(a, mod-2) }
	frac := func(a, b int64) int64 { return a * inv(b) % mod }

	var n, a, b, k, ans int64
	var s []byte
	Fscan(in, &n, &a, &b, &k, &s)
	q := frac(b, a)
	for i := len(s) - 1; i >= 0; i-- {
		ans *= q
		if s[i] == '+' {
			ans++
		} else {
			ans += mod - 1
		}
		ans %= mod
	}
	ans = ans * pow(a, n) % mod
	n = (n + 1) / k
	if q = pow(q, k); q == 1 {
		ans = ans * n % mod
	} else {
		ans = ans * frac(pow(q, n)-1, q-1) % mod
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF963A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 9
	pow := func(x int64, n int64) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}
	inv := func(a int64) int64 { return pow(a, mod-2) }
	frac := func(a, b int64) int64 { return a * inv(b) % mod }

	var n, a, b, k, ans int64
	var s []byte
	Fscan(in, &n, &a, &b, &k, &s)
	q := frac(b, a)
	for i := k - 1; i >= 0; i-- {
		ans *= q
		if s[i] == '+' {
			ans++
		} else {
			ans += mod - 1
		}
		ans %= mod
	}
	ans = ans * pow(a, n) % mod
	n = (n + 1) / k
	if q == 1 {
		ans = ans * n % mod
	} else {
		q = pow(q, k)
		ans = ans * frac(pow(q, n)-1, q-1) % mod
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF963A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 9
	pow := func(x int64, n int64) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}
	inv := func(a int64) int64 { return pow(a, mod-2) }
	frac := func(a, b int64) int64 { return a * inv(b) % mod }

	var n, a, b, k, ans int64
	var s []byte
	Fscan(in, &n, &a, &b, &k, &s)
	q := frac(b, a)
	for i := len(s) - 1; i >= 0; i-- {
		ans *= q
		if s[i] == '+' {
			ans++
		} else {
			ans += mod - 1
		}
		ans %= mod
	}
	ans = ans * pow(a, n) % mod
	n = (n + 1) / k
	if q == 1 {
		ans = ans * n % mod
	} else {
		q = pow(q, k)
		ans = ans * frac(pow(q, n)-1, q-1) % mod
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF963A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 9
	pow := func(x int64, n int64) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}
	modInv := func(a int64) int64 { return pow(a, mod-2) }
	modFrac := func(a, b int64) int64 { return a * modInv(b) % mod }

	var n, a, b, k int64
	var s []byte
	Fscan(in, &n, &a, &b, &k, &s)
	n = (n + 1) / k
	q := modFrac(b, a)
	base := int64(0)
	for _, sign := range s {
		base *= q
		if sign == '+' {
			base++
		} else {
			base += mod - 1
		}
		base %= mod
	}
	var ans int64
	if q == 1 {
		ans = base * n % mod
	} else {
		q = pow(q, k)
		ans = base * modFrac(pow(q, n)-1, q-1) % mod
	}
	Fprint(out, ans*pow(a, n*k-1)%mod)
}

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


package main

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

func main() {
	var inputLen int

	fmt.Scanln(&inputLen)

	arr := make([]int, inputLen)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	for i := 0; i < inputLen; i++ {
		scanner.Scan()
		arr[i], _ = strconv.Atoi(scanner.Text())
	}

	fmt.Scanln()

	sort.Ints(arr)

	sideA := math.Abs(float64(arr[1] - arr[inputLen-1]))
	sideB := math.Abs(float64(arr[0] - arr[inputLen-2]))

	if sideA < sideB {
		fmt.Println(sideA)
	} else {
		fmt.Println(sideB)
	}

}

// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Thu Dec 27 23:44:17 2018
//
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)

	var n int
	fmt.Scan(&n)

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i], _ = strconv.Atoi(read())
	}
	sort.Ints(arr)

	fmt.Println(min(arr[len(arr)-2]-arr[0], arr[len(arr)-1]-arr[1]))
}

package main

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

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1024*1024)
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	sort.Ints(a)
	l := a[len(a)-1] - a[1]
	r := a[len(a)-2] - a[0]
	if l < r {
		fmt.Println(l)
	} else {
		fmt.Println(r)
	}
}

package main

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

const INF int =0x3f3f3f3f
const LLINF int64 = 0x3f3f3f3f3f3f3f3f

func solve(){
    var a [100010] int
    var n,i,mn,mx,ans,tmp int
    n=readInt()
    mx=-INF
    mn=INF
    for i=0;i<n;i++{
        a[i]=readInt()
        mx=max(mx,a[i])
        mn=min(mn,a[i])
    }
    var flag int
    flag=0
    ans=INF
    tmp=-INF
    for i=0;i<n;i++{
        if a[i]==mx&&flag==0{
            flag=1
        }else{
            tmp=max(tmp,a[i])
        }
    }
    ans=min(ans,tmp-mn)
    tmp=INF
    flag=0
    for i=0;i<n;i++{
        if a[i]==mn&&flag==0{
            flag=1
        }else{
            tmp=min(tmp,a[i])
        }
    }
    ans=min(ans,mx-tmp)
    fmt.Println(ans)
}

var scanner *bufio.Scanner

func main() {
    scanner = bufio.NewScanner(os.Stdin)
    const MaxTokenLength = 1024 * 1024
    scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
    scanner.Split(bufio.ScanWords)
    solve()
}
func readString() string {
    scanner.Scan()
    return scanner.Text()
}

func readInt() int {
    val, _ := strconv.Atoi(readString())
    return val
}

func readInt64() int64 {
    v, _ := strconv.ParseInt(readString(), 10, 64)
    return v
}

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

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
func swap(a ,b *int) {
	tmp := *a
	*a = *b
	*b = tmp
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	var min1,min2 int
	var max1,max2 int
	fmt.Fscanf(buf, "%d\n", &n)
	for i:=0;i < n;i++{
		var value int = 0
		fmt.Fscanf(buf,"%d",&value)
		if i == 0{
			min1 = value
			max1 = value
			continue
		}
		if min2 == 0 || value < min2{
			min2 = value
			if min2 < min1{
				swap(&min1,&min2)
			}
		}
		if max2 == 0|| value > max2{
			max2 = value
			if max2 > max1{
				swap(&max1,&max2)
			}
		}

	}
	if n == 2{
		fmt.Printf("0\n")
		return
	}
	if max2-min1 <= max1-min2{
		fmt.Printf("%d\n",max2-min1)
	}else{
		fmt.Printf("%d\n",max1-min2)
	}
}

package main

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

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

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	input := bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		input.Scan()
		a[i], _= strconv.Atoi(input.Text())
	}
	sort.Ints(a)
	fmt.Println(min(a[n - 2] - a[0], a[n - 1] - a[1]))
}

package main

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

func main(){

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

	defer out.Flush()

	var n int

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

	a := make([]int, n)

	for i := 0 ; i < n ; i ++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	fmt.Fscanf(in, "\n")

	if n < 3 {
		fmt.Fprintf(out, "0")
	}else{
		sort.Slice(a, func(i ,j int) bool{
		  	return a[i] < a[j]
		})

		output := a[n-2] - a[0]

		if a[ n - 1 ] - a[1] < output {
			output = a[ n - 1 ] - a[1]
		}

		fmt.Fprintf(out, "%d\n", output)

	}

}

package main

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

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)

	var n, x int
	fmt.Fscanln(stdin, &n)

	var max1, max2, min1, min2 = 0, 0, 100000 + 7, 100000 + 7
	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &x)

		if x > max1 {
			max2 = max1
			max1 = x
		} else if x > max2 {
			max2 = x
		}

		if x < min1 {
			min2 = min1
			min1 = x
		} else if x < min2 {
			min2 = x
		}
	}

	if max1-min2 < max2-min1 {
		fmt.Println(max1 - min2)
	} else {
		fmt.Println(max2 - min1)
	}
	// fmt.Println(max1, max2, min1, min2)

}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanNum() int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := scanNum()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanNum()
	}
	if n == 2 {
		fmt.Println(0)
		os.Exit(0)
	}
	sort.Ints(a)
	fmt.Println(min(a[len(a)-2]-a[0], a[len(a)-1]-a[1]))
}

// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Thu Dec 27 23:44:17 2018
//
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

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

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i], _ = strconv.Atoi(read())
	}

	sort.Ints(arr)

	fmt.Println(min(arr[len(arr)-2]-arr[0], arr[len(arr)-1]-arr[1]))
}


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

package main

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

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

func Solve(n int, a []int) int {
	prefixMap := make(map[int]int)
	right := n - 1
	left := 0
	for right >= left {
		if prefixMap[a[right]] > 0 {
			break
		}
		prefixMap[a[right]] += 1
		right -= 1
	}
	right += 1
	smallestSegment := right
	for left <= right && left < n {
		if prefixMap[a[left]] > 0 && right < n {
			prefixMap[a[right]] -= 1
			right += 1
		} else if prefixMap[a[left]] > 0 {
			break
		} else {
			prefixMap[a[left]] += 1
			smallestSegment = min(smallestSegment, right-left-1)
			left += 1
		}
	}
	return smallestSegment
}

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

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

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

//Uniqueness
package main

import (
	"fmt"
)

func main() {
	var size int
	var store []uint32
	fmt.Scanf("%d\n", &size)
	store = make([]uint32, size)

	for i := 0; i < size; i++ {
		fmt.Scanf("%d", &(store[i]))
	}
	var max int
	//填充左侧
	lappear := make(map[uint32]bool, 0)

	for lcount := 0; lcount < size; lcount++ {
		// fmt.Printf("L: %d ", lcount)
		rcount := 0
		rappear := make(map[uint32]bool, 0)
		for r := size - 1; r >= lcount; r-- {
			if !mapContains(lappear, store[r]) && !mapContains(rappear, store[r]) {
				rappear[store[r]] = true
				rcount++
			} else {
				break
			}
		}
		// fmt.Printf("R: %d ", rcount)
		max = intMax(max, lcount+rcount)
		if !mapContains(lappear, store[lcount]) {
			lappear[store[lcount]] = true
		} else {
			break
		}
		// fmt.Printf("Max: %d\n", max)
	}
	fmt.Printf("%d", (size - max))
	return
}

func mapContains(Map map[uint32]bool, Key uint32) bool {
	_, ok := (Map[Key])
	return ok
}

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

package main

import (
	"fmt"
	"math"
)

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

	dupes := false
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		m[a[i]]++
		if m[a[i]] > 1 {
			dupes = true
			break
		}
	}

	if !dupes {
		fmt.Println("0")
	} else {
		answer := math.MaxInt32
		for i := 0; i < n; i++ {
			m := make(map[int]int)
			moreThanSingle := 0
			for j := 0; j < n; j++ {
				m[a[j]]++
				if m[a[j]] == 2 {
					moreThanSingle++
				}
			}

			for j := i; j < n; j++ {
				// i..j = removed
				m[a[j]]--
				if m[a[j]] == 1 {
					moreThanSingle--
					if moreThanSingle == 0 {
						if j - i + 1 < answer {
							answer = j - i + 1
						}
					}
				}
			}
		}

		fmt.Println(answer)
	}
}

//Uniqueness
package main

import (
	"fmt"
)

func main() {
	var size int
	var store []uint32
	fmt.Scanf("%d\n", &size)
	store = make([]uint32, size)

	for i := 0; i < size; i++ {
		fmt.Scanf("%d", &(store[i]))
	}
	var max int
	//填充左侧
	lappear := make(map[uint32]bool, 0)

	for lcount := 0; lcount < size; lcount++ {
		// fmt.Printf("L: %d ", lcount)
		rcount := 0
		rappear := make(map[uint32]bool, 0)
		for r := size - 1; r >= lcount; r-- {
			if !mapContains(lappear, store[r]) && !mapContains(rappear, store[r]) {
				rappear[store[r]] = true
				rcount++
			} else {
				break
			}
		}
		// fmt.Printf("R: %d ", rcount)
		max = intMax(max, lcount+rcount)
		if !mapContains(lappear, store[lcount]) {
			lappear[store[lcount]] = true
		} else {
			break
		}
		// fmt.Printf("Max: %d\n", max)
	}
	print(size - max)
	return
}

func mapContains(Map map[uint32]bool, Key uint32) bool {
	_, ok := (Map[Key])
	return ok
}

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

package main

import (
	"fmt"
	"math"
)

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

	dupes := false
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		m[a[i]]++
		if m[a[i]] > 1 {
			dupes = true
			break
		}
	}

	if !dupes {
		fmt.Println("0")
	} else {
		answer := math.MaxInt32
		for i := 0; i < n; i++ {
			m := make(map[int]int)
			moreThanSingle := 0
			for j := 0; j < n; j++ {
				m[a[j]]++
				if m[a[j]] > 1 {
					moreThanSingle++
				}
			}

			for j := i; j < n; j++ {
				// i..j = removed
				m[a[j]]--
				if m[a[j]] == 1 {
					moreThanSingle--
					if moreThanSingle == 0 {
						if j - i + 1 < answer {
							answer = j - i + 1
						}
					}
				}
			}
		}

		fmt.Println(answer)
	}
}

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

package main

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

func suffixFirst(n int, a []int) int {
	prefixMap := make(map[int]int)
	right := n - 1
	left := 0
	for right >= left {
		if prefixMap[a[right]] > 0 {
			break
		}
		prefixMap[a[right]] += 1
		right -= 1
	}
	for left <= right {
		if prefixMap[a[left]] > 0 {
			break
		}
		prefixMap[a[left]] += 1
		left += 1
	}
	return right - left + 1
}

func prefixFirst(n int, a []int) int {
	prefixMap := make(map[int]int)
	right := n - 1
	left := 0
	for left <= right {
		if prefixMap[a[left]] > 0 {
			break
		}
		prefixMap[a[left]] += 1
		left += 1
	}
	for right >= left {
		if prefixMap[a[right]] > 0 {
			break
		}
		prefixMap[a[right]] += 1
		right -= 1
	}
	return right - left + 1
}

func Solve(n int, a []int) int {
	prefixFirstLength := prefixFirst(n, a)
	suffixFirstLength := suffixFirst(n, a)
	if prefixFirstLength < suffixFirstLength {
		return prefixFirstLength
	}
	return suffixFirstLength
}

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

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

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


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[:len(b):len(b)]
}

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

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(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...)
}

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

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

	_, a := readInts(0)

	var c [3]int
	for _, v := range a {
		c[v]++
	}

	ans := min(c[1], c[2])
	add := (c[1] - ans) / 3
	if 0 < add {
		ans += add
	}
	println(ans)
}

package main

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

func main() {
	var n int
	buf, _ := ioutil.ReadAll(os.Stdin)
	in := bytes.NewReader(buf)
	fmt.Fscan(in, &n)
	var c1, c2, t int32
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &t)
		if t == 1 {
			c1++
		} else if t == 2 {
			c2++
		}
	}
	if c1 > c2 {
		fmt.Println(c2 + (c1-c2)/3)
	} else {
		fmt.Println(c1)
	}
}

package main

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

type SHelper struct {
	file *os.File
	scanner *bufio.Scanner
}

func (this *SHelper) Init() {
	this.file = os.Stdin
	this.scanner = bufio.NewScanner(this.file)
	this.scanner.Split(bufio.ScanWords)
}

func (this *SHelper) ReadInt64() int64 {
	this.scanner.Scan()
	n, err:= strconv.ParseInt(this.scanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return n
}

var helper SHelper

func main() {
	helper.Init()
	n := helper.ReadInt64()

	nSum1 := int64(0)
	nSum2 := int64(0)

	for i := int64(0); i < n; i++ {
		x := helper.ReadInt64()
		if x == 1 {
			nSum1++
		} else {
			nSum2++
		}
	}

	nSum := int64(0)
	if nSum2 < nSum1 {
		nSum = nSum2 + (nSum1 - nSum2) / 3
	} else {
		nSum = nSum1
	}

	fmt.Println(nSum)
}


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

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

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

const (
	MOD = 1e9 + 7
)

type (

)

func main () {
	var (
		n int
		str string
	)

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

	fmt.Fscanln(input, &n)
	fmt.Fscanln(input, &str)

	ans := 0

	for i := 0; i < n; i++ {
		if str[i] == '<' {
			ans++
		} else {
			break
		}
	}

	for i := n - 1; i >= 0; i-- {
		if str[i] == '>' {
			ans++
		} else {
			break
		}
	}

	fmt.Println(ans)
}

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1<<13)
	writer := bufio.NewWriterSize(os.Stdout, 1<<13)

	var n int
	var str string
	fmt.Fscan(reader, &n, &str)

	count := 0
	for i := 0; i < n; i++ {
		if str[i] == '>' {
			break
		}
		count++
	}

	for i := n - 1; i >= 0; i-- {
		if str[i] == '<' {
			break
		}
		count++
	}

	fmt.Fprintln(writer, count)
	writer.Flush()
}

func ReadInt(reader *bufio.Reader) int {
	b, err := reader.ReadByte()
	for !isValid(b, err) {
		b, err = reader.ReadByte()
	}
	res := 0
	for isValid(b, err) {
		res = res*10 + int(b-'0')
		b, err = reader.ReadByte()
	}
	return res
}

func isValid(b byte, err error) bool {
	return err == nil && (('0' <= b && b <= '9') || b == '<' || b == '>')
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

func solve(n int) {
	var s string
	I(&s, "\n")
	ans := 0
	for i := 0; i < n; i++ {
		if s[i] == '<' {
			ans++
		} else {
			break
		}
	}
	for i := n - 1; i >= 0; i-- {
		if s[i] == '>' {
			ans++
		} else {
			break
		}
	}
	O(ans, "\n")
}

package main

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

func solve() {
    n, s := readInt(), readString()
    i, j := 0, n - 1
    for i < n && s[i] == "<"[0] {
        i++;
    }
    for j >= 0 && s[j] == ">"[0] {
        j--;
    }

    fmt.Println(i-j+n-1)
}

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

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

func min(x, y int) int {
	return x + y - max(x, y)
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readArray(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = readInt()
	}
	return res
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var s string
	var n int
	fmt.Fscanf(bufin, "%d\n", &n)
	fmt.Fscanf(bufin, "%s\n", &s)

	res := 0
	for i := 0; (i < n) && (s[i] == '<'); i++ {
		res++
	}
	for i := (n - 1); (i >= 0) && (s[i] == '>'); i-- {
		res++
	}
	fmt.Fprintf(bufout, "%d\n", res)
}

package main

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

var (
  n, result int
  s string
  seen, leaves []bool
)

func explore(i int) bool {
  if i < 0 || i == n {
    return true
  }
  if seen[i] {
    return leaves[i]
  }
  seen[i] = true
  if s[i] == '<' {
    leaves[i] = explore(i - 1)
  } else {
    leaves[i] = explore(i + 1)
  }
  if leaves[i] {
    result++
  }
  return leaves[i]
}

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

  line, _ := reader.ReadString('\n')
  fmt.Sscanf(line, "%d", &n)
  line, _ = reader.ReadString('\n')
  s = strings.TrimSpace(line)
  seen = make([]bool, n)
  leaves = make([]bool, n)
  result = 0
  for i := range s {
    explore(i)
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

import "strings"

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")

	text, _ = reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	total := 0
	for i := 0; i < len(text); i++ {
		if text[i] == '<' {
			total += 1
		} else {
			break
		}
	}
	for i := len(text) - 1; i >= 0; i-- {
		if text[i] != '>' {
			break
		}
		total += 1
	}
	fmt.Println(total)

}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

func solve(n int) {
	var s string
	I(&s, "\n")
	o := strings.Count(s, ">") - strings.Count(s, "<")
	ans := o
	if o < 0 {
		ans = -o
	}
	O(ans, "\n")
}


// Codeforces 911 C done
package main

import (
	"bufio"
	"fmt"
	"strings"
	"strconv"
	"os"
	"sort"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j:=0; j<n; j++ {
		aa,err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

type programmer struct {
	skill int
	idx int
	nLessEnemies int
}
type Progs []*programmer

var pros Progs
var proga []programmer

func (ps Progs) Len() int {
	return len(ps)
}
func (ps Progs) Less(i, j int) bool {
	return ps[i].skill < ps[j].skill
}
func (ps Progs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

var n,k int
var r []int
var res []int

func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading n, k
	n, k, _, _, _ = readFive()
	// reading r
	r = readLineNumbs(n)
	// creating programmers
	proga = make([]programmer, n)
	pros = make([]*programmer, n)
	res = make([]int, n)
	for i:=0; i<n; i++ {
		proga[i].skill = r[i]
		proga[i].nLessEnemies = 0
		proga[i].idx = i
		pros[i] = &(proga[i])
	}
	sort.Sort(pros)
	// reading quarels
	for i:=0; i<k; i++ {
		a,b,_,_,_ := readFive()
		a--; b--
		if proga[a].skill < proga[b].skill {
			proga[b].nLessEnemies++
		} else if proga[b].skill < proga[a].skill {
			proga[a].nLessEnemies++
		}
	}
}

func solve() {
	last := -1
	nLess := 0
	for i:=0; i<n; i++ {
		if pros[i].skill > last {
			nLess = i;
			last = pros[i].skill
		}
		res[pros[i].idx] = nLess - pros[i].nLessEnemies
	}
}

func printRes() {
	for i:=0; i<n; i++ {
		fmt.Print(" ", res[i])
	}
    fmt.Println()
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

type prog struct {
	v, index int
}

var n, k int
var a []prog
var c []int
var ans []int

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d %d\n", &n, &k)
	a = make([]prog, n)
	c = make([]int, n)
	ans = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(inBuf, "%d", &a[i].v)
		a[i].index = i
	}
	fmt.Fscanf(inBuf, "\n")
	for i := 0; i < k; i++ {
		var t1, t2 int
		fmt.Fscanf(inBuf, "%d %d\n", &t1, &t2)
		t1--
		t2--
		if a[t1].v > a[t2].v {
			c[t1]++
		} else if a[t1].v < a[t2].v {
			c[t2]++
		}
	}
	sort.Slice(a, func(i, j int) bool {
		return a[i].v < a[j].v
	})
	for i := 0; i < n; i++ {
		ind := sort.Search(i, func(n int) bool {
			return a[n].v >= a[i].v
		})
		ans[a[i].index] = ind - c[a[i].index]
	}

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() }()

	for i := 0; i < n; i++ {
		fmt.Printf("%d ", ans[i])
	}
}

package main

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

type pair struct {
	a, b int
}

type lol []pair

func (p lol) Len() int {
	return len(p)
}

func (p lol) Less(xx, yy int) bool {
	x, y := p[xx], p[yy]
	if x.a != y.a {
		return x.a < y.a
	}

	return x.b < y.b
}

func (p lol) Swap(x, y int) {
	p[x], p[y] = p[y], p[x]
}

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

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

	skill := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &skill[i])
	}

	qua := make([]pair, k)

	for i := 0; i < k; i++ {
		fmt.Fscan(in, &qua[i].a, &qua[i].b)
		qua[i].a--
		qua[i].b--
	}

	res := make([]int, n)
	for i := 0; i < k; i++ {
		a, b := qua[i].a, qua[i].b
		if skill[a] < skill[b] {
			res[b]--
		} else if skill[a] > skill[b] {
			res[a]--
		}
	}

	sorted := make([]pair, n)
	for i := 0; i < n; i++ {
		sorted[i] = pair{skill[i], i}
	}

	sort.Sort(lol(sorted))

	eq := 0
	v := -1
	for i := 0; i < n; i++ {
		ski, id := sorted[i].a, sorted[i].b
		if ski == v {
			eq++
		} else {
			eq = 0
		}

		res[id] += i - eq

		v = sorted[i].a
	}

	for i := 0; i < n; i++ {
		fmt.Fprint(out, res[i], " ")
	}
	fmt.Fprintln(out)

}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 2048*2048), 2048*2048)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	k, _ := strconv.Atoi(scanner.Text())

	r := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		r[i], _ = strconv.Atoi(scanner.Text())
		c[i] = r[i]
	}

	sort.Ints(c)

	p := make([]int, n)

	for i := 0; i < k; i++ {
		scanner.Scan()
		x, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		y, _ := strconv.Atoi(scanner.Text())
		x--
		y--
		if r[x] > r[y] {
			p[x]++
		}
		if r[x] < r[y] {
			p[y]++
		}
	}

	for i := 0; i < n; i++ {
		pred := NewPred(r[i])
		l := 0
		h := n - 1
		for l < h {
			m := l + (h-l+1)/2
			if pred(c[m]) {
				h = m - 1
			} else {
				l = m
			}
		}
		if pred(c[l]) {
			fmt.Printf("%d ", 0)
			continue
		}
		//fmt.Println(l, r[i], i)
		fmt.Printf("%d ", l+1-p[i])
	}
	fmt.Println()
}

func NewPred(target int) func(int) bool {
	return func(x int) bool {
		return x >= target
	}
}

package main

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

type pro struct {
	pos int
	r int
	v int
}

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

	var n, k, u, v int
	fmt.Fscan(in, &n, &k)

	cnt := make([]int, n+1)
	p := make([]pro, n+1)

	for i := 1; i <= n; i++ {
		fmt.Fscan(in, &u)
		p[i] = pro{i, u, 0}
	}
	for i := 0; i < k; i++ {
		fmt.Fscan(in, &u, &v)
		if p[u].r > p[v].r {
			cnt[u]++
		} else if p[u].r < p[v].r {
			cnt[v]++
		}
	}

	sort.Slice(p, func(i, j int) bool {
		return p[i].r < p[j].r
	})

	l, r := 1, 1
	for l <= n {
		for r <= n && p[l].r == p[r].r {
			r++
		}
		for i := l ; i < r; i++ {
			p[i].v = l-1 - cnt[p[i].pos]
		}
		l = r
	}

	sort.Slice(p, func(i, j int) bool {
		return p[i].pos < p[j].pos
	})

	fmt.Fprintf(out, "%d", p[1].v)
	for i := 2; i <= n; i++ {
		fmt.Fprintf(out, " %d", p[i].v)
	}
}

package main

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

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

	var n, m, v, w int
	Fscan(in, &n, &m)
	a := make([]int, n)
	g := make([][]int, n)
	for i := range a {
		Fscan(in, &a[i])
		g[i] = []int{a[i]}
	}
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], a[w])
		g[w] = append(g[w], a[v])
	}
	for _, vs := range g {
		sort.Ints(vs)
	}
	b := make([]int, n)
	copy(b, a)
	sort.Ints(b)
	for i, v := range a {
		Fprint(out, sort.SearchInts(b, v)-sort.SearchInts(g[i], v), " ")
	}
}

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

package main

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

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

	var n, m, v, w int
	Fscan(in, &n, &m)
	a := make([]int, n)
	g := make([][]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], a[w])
		g[w] = append(g[w], a[v])
	}
	for _, vs := range g {
		sort.Ints(vs)
	}
	b := make([]int, n)
	copy(b, a)
	sort.Ints(b)
	for i, v := range a {
		Fprint(out, sort.SearchInts(b, v)-sort.SearchInts(g[i], v), " ")
	}
}

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

package main

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

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

	var n, m, v, w int
	Fscan(in, &n, &m)
	fa := make([]int, n)
	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]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int, n)
	copy(b, a)
	sort.Ints(b)
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		merge(v-1, w-1)
	}
	g := make([][]int, n)
	for i, v := range a {
		f := find(i)
		g[f] = append(g[f], v)
	}
	for _, vs := range g {
		sort.Ints(vs)
	}
	for i, v := range a {
		vs := g[fa[i]]
		Fprint(out, sort.SearchInts(b, v)-sort.SearchInts(vs, v), " ")
	}
}

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