Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there are n piles of boxes, arranged in a line, from left to right, i-th pile (1 ≤ i ≤ n) containing ai boxes. Luckily, m students are willing to help GukiZ by removing all the boxes from his way. Students are working simultaneously. At time 0, all students are located left of the first pile. It takes one second for every student to move from this position to the first pile, and after that, every student must start performing sequence of two possible operations, each taking one second to complete. Possible operations are: If i ≠ n, move from pile i to pile i + 1; If pile located at the position of student is not empty, remove one box from it.GukiZ's students aren't smart at all, so they need you to tell them how to remove boxes before professor comes (he is very impatient man, and doesn't want to wait). They ask you to calculate minumum time t in seconds for which they can remove all the boxes from GukiZ's way. Note that students can be positioned in any manner after t seconds, but all the boxes must be removed.

The first line contains two integers n and m (1 ≤ n, m ≤ 105), the number of piles of boxes and the number of GukiZ's students.  The second line contains n integers a1, a2, ... an (0 ≤ ai ≤ 109) where ai represents the number of boxes on i-th pile. It's guaranteed that at least one pile of is non-empty.

In a single line, print one number, minimum time needed to remove all the boxes in seconds.

NoteFirst sample: Student will first move to the first pile (1 second), then remove box from first pile (1 second), then move to the second pile (1 second) and finally remove the box from second pile (1 second).Second sample: One of optimal solutions is to send one student to remove a box from the first pile and a box from the third pile, and send another student to remove a box from the third pile. Overall, 5 seconds.Third sample: With a lot of available students, send three of them to remove boxes from the first pile, four of them to remove boxes from the second pile, five of them to remove boxes from the third pile, and four of them to remove boxes from the fourth pile. Process will be over in 5 seconds, when removing the boxes from the last pile is finished.

package main

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

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

func main() {

    defer out.Flush()
    in.Split(bufio.ScanWords)

    n, m := NextInt(), NextInt()
    a := make([]int, n)
    for i := 0; i < n; i++ {
        a[i] = NextInt()
    }
    var lo, hi int64 = 0, 1000000000000000
    for hi - lo > 1 {
        var mid int64 = lo + (hi - lo) / 2
        if Enough(mid, a, m) {
            hi = mid
        }else {
            lo = mid
        }
    }

    fmt.Fprintln(out, hi)
}

func Enough(time int64, a []int, m int) bool{
    var at, n int = 0, len(a)
    b := make([]int64, n)
    for i := 0; i < n; i++ {
        b[i] = int64(a[i])
    }
    for i := 0; i < m && at < n; i++ {
        var rem int64 = time - int64(at + 1)
        for rem > 0 && at < n {
            if rem - b[at] >= 0 {
                rem -= b[at]
                b[at] = 0
                at++
            }else {
                b[at] -= rem
                rem = 0
            }
            rem--
        }
    }
    for i := at; i < n; i++ {
        if b[i] > 0 {
            return false;
        }
    }
    return true
}

func Next() string{
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

func NextInt() int{
    ret, _ := strconv.Atoi(Next())
    return ret
}

package main

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

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

func main() {

    defer out.Flush()
    in.Split(bufio.ScanWords)

    n, m := NextInt(), NextInt()
    a := make([]int, n)
    for i := 0; i < n; i++ {
        a[i] = NextInt()
    }
    var lo, hi int64 = 0, 10000000000000
    for hi - lo > 1 {
        var mid int64 = lo + (hi - lo) / 2
        if Enough(mid, a, m) {
            hi = mid
        }else {
            lo = mid
        }
    }

    fmt.Fprintln(out, hi)
}

func Enough(time int64, a []int, m int) bool{
    var at, n int = 0, len(a)
    b := make([]int64, n)
    for i := 0; i < n; i++ {
        b[i] = int64(a[i])
    }
    for i := 0; i < m; i++ {
        var rem int64 = time - int64(at + 1)
        for rem > 0 && at < n {
            if rem - b[at] >= 0 {
                rem -= b[at]
                b[at] = 0
                at++
            }else {
                b[at] -= rem
                rem = 0
            }
            rem--
        }
    }
    for i := at; i < n; i++ {
        if b[i] > 0 {
            return false;
        }
    }
    return true
}

func Next() string{
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

func NextInt() int{
    ret, _ := strconv.Atoi(Next())
    return ret
}


Polycarp must pay exactly $$$n$$$ burles at the checkout. He has coins of two nominal values: $$$1$$$ burle and $$$2$$$ burles. Polycarp likes both kinds of coins equally. So he doesn't want to pay with more coins of one type than with the other.Thus, Polycarp wants to minimize the difference between the count of coins of $$$1$$$ burle and $$$2$$$ burles being used. Help him by determining two non-negative integer values $$$c_1$$$ and $$$c_2$$$ which are the number of coins of $$$1$$$ burle and $$$2$$$ burles, respectively, so that the total value of that number of coins is exactly $$$n$$$ (i. e. $$$c_1 + 2 \cdot c_2 = n$$$), and the absolute value of the difference between $$$c_1$$$ and $$$c_2$$$ is as little as possible (i. e. you must minimize $$$|c_1-c_2|$$$).

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line. This line contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the number of burles to be paid by Polycarp.

For each test case, output a separate line containing two integers $$$c_1$$$ and $$$c_2$$$ ($$$c_1, c_2 \ge 0$$$) separated by a space where $$$c_1$$$ is the number of coins of $$$1$$$ burle and $$$c_2$$$ is the number of coins of $$$2$$$ burles. If there are multiple optimal solutions, print any one.

NoteThe answer for the first test case is "334 333". The sum of the nominal values of all coins is $$$334 \cdot 1 + 333 \cdot 2 = 1000$$$, whereas $$$|334 - 333| = 1$$$. One can't get the better value because if $$$|c_1 - c_2| = 0$$$, then $$$c_1 = c_2$$$ and $$$c_1 \cdot 1 + c_1 \cdot 2 = 1000$$$, but then the value of $$$c_1$$$ isn't an integer.The answer for the second test case is "10 10". The sum of the nominal values is $$$10 \cdot 1 + 10 \cdot 2 = 30$$$ and $$$|10 - 10| = 0$$$, whereas there's no number having an absolute value less than $$$0$$$.

package main
import (
	"fmt"
)
func main() {
	var x int
	fmt.Scan(&x)
	for i:=0;i<x;i++{
		var n int
		fmt.Scan(&n)
		if n == 0 {
			fmt.Println(0,0)
		} else if n % 3 == 0 {
			fmt.Println(n/3,n/3)
		} else if (float64(n)/3) - float64(int(n/3)) <= 0.34 {
			fmt.Println(int(n/3)+1,int(n/3))
		} else {
			fmt.Println(int(n/3),int(n/3)+1)
		}
	}
}

package main

import "fmt"

func main() {
	var sumOfCases int64
	var value int64
	var num int64
	fmt.Scan(&sumOfCases)
	for i := int64(0); i < sumOfCases; i++ {
		fmt.Scan(&value)
		num = value / 3
		switch value % 3 {
		case 0:
			fmt.Printf("%d %d\n", num, num)
		case 1:
			fmt.Printf("%d %d\n", num+1, num)
		case 2:
			fmt.Printf("%d %d\n", num, num+1)
		}
	}
}

package main

import "fmt"

func main() {
	var sumOfCases int
	var value int
	var num int
	fmt.Scan(&sumOfCases)
	for i := 0; i < sumOfCases; i++ {
		fmt.Scan(&value)
		num = value / 3
		switch value % 3 {
		case 0:
			fmt.Printf("%d %d\n", num, num)
		case 1:
			fmt.Printf("%d %d\n", num+1, num)
		case 2:
			fmt.Printf("%d %d\n", num, num+1)
		}
	}
}

package main

import "fmt"

func main() {
	var sumOfCases int
	var value int
	var subValue int
	var numberOfOne int
	var numberOfTwo int
	fmt.Scan(&sumOfCases)
	for i := 0; i < sumOfCases; i++ {
		fmt.Scan(&value)
		subValue = value / 3
		numberOfOne = subValue
		numberOfTwo = subValue
		sum := numberOfOne + 2*numberOfTwo
		if sum == value {
			fmt.Printf("%d %d\n", numberOfOne, numberOfTwo)
		} else if  (value-sum) == 1 {
			fmt.Printf("%d %d\n", numberOfOne+1, numberOfTwo)
		} else {
			fmt.Printf("%d %d\n", numberOfOne, numberOfTwo+1)
		}

	}
}

package main

import "fmt"

func main() {
	var sumOfCases int64
	var value int64
	var subValue int64
	var numberOfOne int64
	var numberOfTwo int64
	_, err := fmt.Scan(&sumOfCases)
	if err != nil {
		panic(err)
	}
	for i:=int64(0);i<sumOfCases;i++{
		_,err:=fmt.Scan(&value)
		if err != nil {
			return
		}
		subValue=value/3
		numberOfOne=subValue
		numberOfTwo=subValue
		sum:=numberOfOne+2*numberOfTwo
		if sum==value{
			fmt.Printf("%d %d\n",numberOfOne,numberOfTwo)
		}else if sum<value&&(value-sum)==1{
			fmt.Printf("%d %d\n",numberOfOne+1,numberOfTwo)
		}else {
			fmt.Printf("%d %d\n",numberOfOne,numberOfTwo+1)
		}

	}
}

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		//var c1, c2 int

		rem := n % 3
		if rem & 0x1 == 0 {
			Fprintln(out, (n-rem)/3, (n-rem)/3 + rem/2)

		} else {
			Fprintln(out, (n-rem)/3 + 1, (n-rem)/3)
		}
	}
}

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		//var c1, c2 int

		rem := n % 3
		if rem & 0x1 == 0 {
			Fprintln(out, (n-rem)/3, (n-rem)/3 + rem/2)

		} else {
			Fprintln(out, (n-rem)/3 + (rem & 0x1), (n-rem)/3 + rem/2)
		}
	}
}

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

package main

import "fmt"

func solve() (a, b int) {
	var n int
	fmt.Scanf("%d\n", &n)
	if n%3 == 0 {
		return n / 3, n / 3
	}
	if n%3 == 1 {
		return n/3 + 1, n / 3
	}
	return n / 3, n/3 + 1
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		a, b := solve()
		fmt.Println(a, b)
	}
}

package main

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

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

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

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

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

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

/**
 Run solve the problem CF1551A
 Date: 18/08/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1551/A
 Problem: CF1551A
**/
func (in *CF1551A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		two := int(math.Ceil(float64(n) / 3.0))
		one := int(math.Floor(float64(n) / 3.0))

		if (two * 2) + one != n {
			one, two = two, one
		}
		fmt.Println(one, two)
	}
}

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

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

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%v\n", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%v\n", &n)
		c1 := n / 3
		c2 := c1
		if n % 3 == 1 {
			c1++
		} else if n % 3 == 2 {
			c2++
		}
		fmt.Println(c1, c2)
	}
}

package main

import "fmt"

func main(){

	var t int64
	fmt.Scanf("%d\n",&t)

	for t>0{
		var n int64
		fmt.Scanf("%d\n", &n)

		var x=n/3
		var rem=n%3

		// fmt.Printf("%d\n",x)
		var c1=x
		var c2=x

		if(rem==1){
			c1++
		}else if(rem==2){
			c2++
		}

		fmt.Printf("%d %d\n", c1,c2)

		t--
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		run()
	}
}

func run() {
	var a int
	fmt.Scan(&a)
	t := a / 3
	if a%3 == 0 {
		fmt.Println(t, t)
	} else if a%3 == 1 {
		fmt.Println(t+1, t)
	} else {
		fmt.Println(t, t+1)
	}
}

package main

import "fmt"

func dd(a int) {
	n := a / 3
	if a%3 == 0 {
		fmt.Println(n, n)
	} else if a%3 == 1 {
		fmt.Println(n+1, n)
	} else {
		fmt.Println(n, n+1)
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		dd(a)
	}
}

package main

import (
	"fmt"
)

func main() {
	var (
		t  int
		n  int
		c1 int
		c2 int
	)
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d\n", &n)
		c1 = n / 3
		c2 = n / 3
		if n%3 == 1 {
			c1++
		}
		if n%3 == 2 {
			c2++
		}
		fmt.Println(c1, c2)
	}
}

// 1551A. Polycarp and Coins
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		c1, c2 := n/3, n/3
		if n%3 == 1 {
			c1++
		} else if n%3 == 2 {
			c2++
		}
		fmt.Println(c1, c2)

	}
}

package main

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

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

	var t, n int
	for fmt.Fscan(r, &t); t > 0; t-- {
		fmt.Fscan(r, &n)
		if n%3 == 0 {
			fmt.Fprintln(w, n/3, n/3)
		} else {
			switch n % 3 {
			case 1:
				fmt.Fprintln(w, n/3+1, n/3)
			default:
				fmt.Fprintln(w, n/3, n/3+1)
			}
		}
	}
}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}

	return n
}

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)

		c2 := n / 3
		c1 := n - (c2 * 2)

		if abs(c2-c1) > 1 {
			c1 -= 2
			c2 += 1
		}
		fmt.Fprintf(out, "%d %d\n", c1, c2)

	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, int64(0)
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		if n%3 == 0 {
			fmt.Fprintln(w, n/3, n/3)
		} else {
			x, y := (n-1)/3, (n+2)/3
			if x+2*y == n {
				fmt.Fprintln(w, x, y)
			} else {
				fmt.Fprintln(w, y, x)
			}
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

	test := parseInt(getString(reader))

	for ; test > 0; test-- {
		n := parseInt(getString(reader))
		if n%3 == 0 {
			writer.WriteString(fmt.Sprintf("%d %d\n", n/3, n/3))
		} else if n%3 == 1 {
			writer.WriteString(fmt.Sprintf("%d %d\n", n/3+1, n/3))
		} else {
			writer.WriteString(fmt.Sprintf("%d %d\n", n/3, n/3+1))
		}
	}
	writer.Flush()
}

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

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func scan() string {
	for sc.Scan() {
		break
	}
	return sc.Text()
}

func scanInt() int {
	i, err := strconv.Atoi(scan())
	if err != nil {
		panic(err)
	}
	return i
}

func scanInt8() int8 {
	i, err := strconv.ParseInt(scan(), 10, 8)
	if err != nil {
		panic(err)
	}
	return int8(i)
}

func scanInt64() int64 {
	i, err := strconv.ParseInt(scan(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

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

func min(ints ...int) int {
	a := ints[0]
	n := len(ints)
	for i := 1; i < n; i++ {
		if ints[i] < a {
			a = ints[i]
		}
	}
	return a
}

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

type Noop struct{}

var noop = Noop{}

func proc() {
	n := scanInt()
	a := n / 3
	b := a
	if n%3 == 1 {
		a++
	} else if n%3 == 2 {
		b++
	}
	fmt.Printf("%d %d\n", a, b)
}

func main() {
	sc.Split(bufio.ScanWords)
	t := scanInt()
	for i := 0; i < t; i++ {
		proc()
	}
}

package main

import (
	"fmt"
)

func solve() {
	n := readInt()
	div := n / 3
	switch n % 3 {
	case 0:
		fmt.Printf("%d %d\n", div, div)
	case 1:
		fmt.Printf("%d %d\n", div+1, div)
	case 2:
		fmt.Printf("%d %d\n", div, div+1)
	}
}

func main() {
	n := readInt()
	for i := 0; i < n; i++ {
		solve()
	}
}

func readInt() int {
	var n int
	fmt.Scan(&n)
	return n
}
func readIntN(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	return arr
}

func readIntNN(n, m int) [][]int {
	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = readIntN(m)
	}
	return arr
}

func min(a ...int) int {
	min := a[0]
	for _, v := range a {
		if v < min {
			min = v
		}
	}
	return min
}
func max(a ...int) int {
	max := a[0]
	for _, v := range a {
		if v > max {
			max = v
		}
	}
	return max
}

func minMax(a ...int) (min int, max int) {
	min, max = a[0], a[0]
	for _, v := range a {
		if v < min {
			min = v
		}
		if v > max {
			max = v
		}
	}
	return
}

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

package main

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

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

func solve(n int) string {
	x := n / 3
	if n%3 == 0 {
		return fmt.Sprintf("%d %d", x, x)
	} else if n%3 == 1 {
		return fmt.Sprintf("%d %d", x+1, x)
	} else {
		return fmt.Sprintf("%d %d", x, x+1)
	}
}

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

package main

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

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

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

	for i := 0; i < n; i++ {
		var k int64
		fmt.Fscan(r, &k)
		var res1, res2 int64
		res1 = k / 3
		res2 = res1
		remainder := k % 3
		if remainder  == 1 {
			res1 += 1
		} else if remainder == 2 {
			res2 += 1
		}
		fmt.Printf("%d %d\n", res1, res2)
	}
}

package main

import "fmt"

func main() {
	var t,  n int
	var a,b int
	for fmt.Scanln(&t); t > 0; t-- {
		fmt.Scanln(&n)
		switch n % 3 {
		case 0:
			a = n/3
			b=n/3
		case 1:
			a=n/3+1
			b = n/3
		case 2:
			a = n/3
			b = n/3+1
		}
		fmt.Println(a, b)
	}
}

package main

import (
    "fmt"
)

func main() {
    var testCases int
    fmt.Scan(&testCases)
    c1, c2 := 0, 0

    for i := 0; i < testCases; i++ {
        var number int
        fmt.Scan(&number)

        remainder := number % 3
        part := number / 3
        if remainder == 2 {
            c2 = part + 1
            c1 = part
        } else {
            c1 = part + remainder
            c2 = part
        }
        fmt.Printf("%d %d\n", c1, c2)
    }
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer
	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		a, b := solve(n)
		buf.WriteString(fmt.Sprintf("%d %d\n", a, b))
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}
func solve(n int) (int, int) {
	r := n % 3
	x := n / 3
	if r == 0 {
		return x, x
	}
	if r == 1 {
		return x + 1, x
	}
	return x, x + 1
}

package main

import (
	"fmt"
)

func main() {
	var testcases int16
	fmt.Scanf("%d\n", &testcases)
	for ; testcases > 0; testcases -= 1 {
		var n int32
		fmt.Scanf("%d\n", &n)
		switch mod3 := n % 3; mod3 {
		case 0:
			res := n / 3
			fmt.Printf("%d %d\n", res, res)
		case 1:
			res := n / 3
			fmt.Printf("%d %d\n", res+1, res)
		case 2:
			res := n / 3
			fmt.Printf("%d %d\n", res, res+1)
		}
	}
}

package main
import ("fmt")

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

	for i:=0;i<n;i++ {
		fmt.Scan(&a)
		k=a/3
		if (k)+2*(k)==a{
			fmt.Println(k,k)
		} else {
			if (k+1)+2*k ==a{
				fmt.Println(k+1,k)
			} else {
				fmt.Println(k,k+1)
			}
		}
	}
}

package main

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

type ProblemOutput struct {
	c1 int32
	c2 int32
}

func solve(n int32) ProblemOutput {
	coins := n / 3
	output := ProblemOutput{c1: coins, c2: coins}
	if n-coins*3 == 2 {
		output.c2++
	}
	if n-coins*3 == 1 {
		output.c1++
	}
	return output
}

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

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		fmt.Fscanf(in, "%d\n", &n)

		output := solve(n)
		fmt.Fprintf(out, "%d %d\n", output.c1, output.c2)
		out.Flush()
		tt--
	}
}

package main

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

func solve(i int)  {
	x := i / 3
	if i % 3 == 0 {
		fmt.Printf("%d %d\n", x, x)
	} else if i % 3 == 1 {
		fmt.Printf("%d %d\n", x + 1, x)
	} else {
		fmt.Printf("%d %d\n", x, x + 1)
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	i := 0
	for scanner.Scan() {
		t := scanner.Text()
		if i == 0 {
			i++
			continue
		}
		i++
		if len(t) == 0 {
			break
		}
		cur, _ := strconv.Atoi(t)

		solve(cur)
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int64
		fmt.Fscan(input, &n)

		if n%3 == 0 {
			fmt.Println(n / 3)
			fmt.Println(n / 3)
		}
		if n%3 == 1 {
			fmt.Println(int64(n/3) + 1)
			fmt.Println(int64(n / 3))
		}
		if n%3 == 2 {
			fmt.Println(int64(n / 3))
			fmt.Println(int64(n/3) + 1)
		}

	}

}

package main

import (
	"fmt"
)

func main() {

	var (
		n   int
		num int64
	)
	fmt.Scan(&n)
	for n > 0 {
		n--
		fmt.Scan(&num)
		c1 := num / 3
		p := num % 3
		if p == 1 {
			fmt.Println(c1+1, c1)
		} else if p == 2 {
			fmt.Println(c1, c1+1)
		} else {
			fmt.Println(c1, c1)
		}
	}

}

package main

import "fmt"

func add(a, b int) int {
	c := a + b
	return c
}
func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d\n", &n)
		if n%3 == 0 {
			fmt.Printf("%d %d\n", n/3, n/3)
		} else if n%3 == 1 {
			fmt.Printf("%d %d\n", (n-1)/3+1, (n-1)/3)
		} else {
			fmt.Printf("%d %d\n", (n-2)/3, (n-2)/3+1)
		}
	}
}

package main

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

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int64

		fmt.Fscan(input, &n)
		if n%3 == 0 {
			fmt.Println(n/3, n/3)
		} else if n%3 == 1 {
			fmt.Println(n/3+1, n/3)
		} else {
			fmt.Println(n/3, n/3+1)
		}
	}
}

package main

import "fmt"

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

	var a []int
	for i := 0; i < n; i++ {
		var b int
		fmt.Scanf("%d\n", &b)
		a = append(a, b)
	}
	for _, v := range a {
		switch v % 3 {
		case 0:
			fmt.Printf("%d %d\n", v/3, v/3)
		case 1:
			fmt.Printf("%d %d\n", v/3+1, v/3)
		case 2:
			fmt.Printf("%d %d\n", v/3, v/3+1)
		}
	}
}

package main

import "fmt"

var (
	t int
	n int
)

func main() {
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n)
		c := n / 3
		c1, c2 := c, c
		if n % 3 == 1 {
			c1 += 1
		}
		if n % 3 == 2 {
			c2 += 1
		}
		fmt.Println(c1, c2)
	}
}

package main

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

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i += 1 {
		n := stdin.Int()
		switch n%3 {
		case 0:
			fmt.Println(n / 3, n / 3)
		case 1:
			fmt.Println(n / 3 + 1, n / 3)
		case 2:
			fmt.Println(n / 3, n / 3 + 1)
		}
	}
}

/*
 * Created by Reverie
 * 2021.07.23
 * 22:37:08
 */

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)

		x, y := n/3, n/3
		if n%3 == 1 {
			x++
		} else if n%3 == 2 {
			y++
		}

		Fprintf(out, "%d %d\n", x, y)
	}

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

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

package main

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

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

	solve := func(Case int) {
		var n ,a1,a2 int
		Fscan(in, &n)
		minD := int(1e9)
		for c1 :=max( n/3-10,0); c1 < n/3+10; c1++ {
			if (n-c1)&1==0 && c1 <= n {
				c2 := (n-c1)/2
				if d := abs(c1-c2);d<minD {
					minD =d
					a1,a2 = c1,c2
				}
			}
		}
		Fprintln(out, a1,a2)
	}

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

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

func main() { run(os.Stdin, os.Stdout) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func _int() int {
	s := _string()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func _int64() int64 {
	s := _string()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		n := _int64()
		c1, c2 := sol(n)
		printf("%d %d\n", c1, c2)
	}
}

func sol(n int64) (int64, int64) {
	c1, c2 := n/3, n/3
	rem := n % 3
	if rem == 0 {
		return c1, c2
	}
	if rem == 1 {
		return c1 + 1, c2
	}
	return c1, c2 + 1
}

package main
import (
	"fmt"
)
func main() {
	var x int
	fmt.Scan(&x)
	for i:=0;i<x;i++{
		var n int
		fmt.Scan(&n)
		if n == 0 {
			fmt.Println(0,0)
		} else if n == 1 {
			fmt.Println(1,0)
		} else if n == 4 {
			fmt.Println(1,1)
		} else if n % 3 == 0 {
			fmt.Println(n/3,n/3)
		} else if (float64(n)/3) - float64(int(n/3)) <= 0.34 {
			fmt.Println(int(n/3)+1,int(n/3))
		} else {
			fmt.Println(int(n/3),int(n/3)+1)
		}
	}
}

package main
import (
	"fmt"
)
func main() {
	var x int
	fmt.Scan(&x)
	for i:=0;i<x;i++{
		var n int
		fmt.Scan(&n)
		if n == 0 {
			fmt.Println(0,0)
		} else if n == 1 {
			fmt.Println(1,0)
		} else if n % 3 == 0 {
			fmt.Println(n/3,n/3)
		} else if n % 10 == 0 || n % 7 == 0 {
			fmt.Println(int(n/3)+1,int(n/3))
		} else {
			fmt.Println(int(n/3),int(n/3)+1)
		}
	}
}

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		//var c1, c2 int

		rem := n % 3
		if rem & 0x1 == 0 {
			Fprintln(out, (n-rem)/3, (n-rem)/3 + 1)

		} else {
			Fprintln(out, (n-rem)/3 + 1, (n-rem)/3)
		}
	}
}

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

package main

import "fmt"

func solve() (a, b int) {
	var n int
	fmt.Scanf("%d", &n)
	if n%3 == 0 {
		return n / 3, n / 3
	}
	if n%3 == 1 {
		return n/3 + 1, n / 3
	}
	return n / 3, n/3 + 1
}

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		a, b := solve()
		fmt.Println(a, b)
	}
}

package main

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

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

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

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

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

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

/**
 Run solve the problem CF1551A
 Date: 18/08/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1551/A
 Problem: CF1551A
**/
func (in *CF1551A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		two := int(math.Floor(float64(n) / 3.0))
		one := int(math.Ceil(float64(n) / 3.0))
		fmt.Println(one, two)
	}
}

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

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

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%v", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%v", &n)
		c1 := n / 3
		c2 := c1
		if n % 3 == 1 {
			c1++
		} else if n % 3 == 2 {
			c2++
		}
		fmt.Println(c1, c2)
	}
}

package main

import "fmt"

func main(){

	var t int64
	fmt.Scanf("%d",&t)

	for t>0{
		var n int64
		fmt.Scanf("%d", &n)

		var x=n/3
		var rem=n%3

		// fmt.Printf("%d\n",x)
		var c1=x
		var c2=x

		if(rem==1){
			c1++
		}else if(rem==2){
			c2++
		}

		fmt.Printf("%d %d\n", c1,c2)

		t--
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		run()
	}
}

func run() {
	var a int
	fmt.Scan(&a)
	t := a / 3
	if a%3 == 0 {
		fmt.Println(t, t)
	} else if a%3 == 1 {
		fmt.Print(t+1, t)
	} else {
		fmt.Println(t, t+1)
	}
}

package main

import "fmt"

func dd(a int) {
	n := a / 3
	if a%3 == 0 {
		fmt.Println(n, n)
	} else if a%3 == 1 {
		fmt.Println(n+1, n)
	} else {
		fmt.Println(n, n+1)
	}
}

func main() {
	var n int
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		dd(a)
	}
}


Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.Mr. Kitayuta wants you to process the following q queries.In the i-th query, he gives you two integers — ui and vi.Find the number of the colors that satisfy the following condition: the edges of that color connect vertex ui and vertex vi directly or indirectly.

The first line of the input contains space-separated two integers — n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100), denoting the number of the vertices and the number of the edges, respectively. The next m lines contain space-separated three integers — ai, bi (1 ≤ ai < bi ≤ n) and ci (1 ≤ ci ≤ m). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if i ≠ j, (ai, bi, ci) ≠ (aj, bj, cj). The next line contains a integer — q (1 ≤ q ≤ 100), denoting the number of the queries. Then follows q lines, containing space-separated two integers — ui and vi (1 ≤ ui, vi ≤ n). It is guaranteed that ui ≠ vi.

For each query, print the answer in a separate line.

NoteLet's consider the first sample.     The figure above shows the first sample.    Vertex 1 and vertex 2 are connected by color 1 and 2.  Vertex 3 and vertex 4 are connected by color 3.  Vertex 1 and vertex 4 are not connected by any single color.

package main

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

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

type Edge struct {
  V, Color int
}

var seen []bool
var edges [][]Edge

func seek(a, b, c int) bool {
  if a == b {
    return true
  }
  if seen[a] {
    return false
  }
  seen[a] = true
  for _, edge := range edges[a] {
    if edge.Color == c && seek(edge.V, b, c) {
      return true
    }
  }
  return false
}

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

  n, m := scanInt(scanner), scanInt(scanner)
  edges = make([][]Edge, n+1)
  for u := 1; u <= n; u++ {
    edges[u] = []Edge{}
  }
  for i := 0; i < m; i++ {
    a, b, c := scanInt(scanner), scanInt(scanner), scanInt(scanner)
    edges[a] = append(edges[a], Edge{ b, c })
    edges[b] = append(edges[b], Edge{ a, c })
  }
  q := scanInt(scanner)
  for i := 0; i < q; i++ {
    a, b := scanInt(scanner), scanInt(scanner)
    count := 0
    for c := 1; c <= m; c++ {
      seen = make([]bool, n+1)
      if seek(a, b, c) {
        count++
      }
    }
    writer.WriteString(fmt.Sprintf("%d\n", count))
  }
}

package main

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

func solve() {
	n := readInt()
	m := readInt()
	g := make([][][]int, m)
	gExists := make([]bool, m)
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		c := readInt() - 1
		if !gExists[c] {
			gExists[c] = true
			g[c] = make([][]int, n)
			for j := 0; j < n; j++ {
				g[c][j] = make([]int, 0)
			}
		}
		g[c][u] = append(g[c][u], v)
		g[c][v] = append(g[c][v], u)
	}
	vis := make([][]int, m)
	color := 0
	for i := 0; i < m; i++ {
		if gExists[i] {
			vis[i] = make([]int, n)
			for j := 0; j < n; j++ {
				if vis[i][j] == 0 && len(g[i][j]) > 0 {
					color++
					dfs(vis[i], g[i], j, color)
				}
			}
		}
	}
	t := readInt()
	for i := 0; i < t; i++ {
		u := readInt() - 1
		v := readInt() - 1
		ans := 0
		for j := 0; j < m; j++ {
			if gExists[j] {
				if vis[j][u] > 0 && vis[j][u] == vis[j][v] {
					ans++
				}
			}
		}
		fmt.Println(ans)
	}
}

func dfs(vis []int, g [][]int, u int, color int) {
	vis[u] = color
	for _, v := range g[u] {
		if vis[v] == 0 {
			dfs(vis, g, v, color)
		}
	}
}

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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

// IO

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 readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

package main

import "fmt"

type unionFind struct {
	id [110]int
	sz [110]int
}

func (uf *unionFind) init() {
	for i := 0; i < 110; i++ {
		uf.id[i] = i
		uf.sz[i] = 1
	}
}

func (uf *unionFind) root(i int) int {
	for i != uf.id[i] {
		uf.id[i] = uf.id[uf.id[i]]
		i = uf.id[i]
	}
	return i
}

func (uf *unionFind) find(p, q int) bool {
	return uf.root(p) == uf.root(q)
}

func (uf *unionFind) union(p, q int) {
	i, j := uf.root(p), uf.root(q)
	if uf.sz[i] < uf.sz[j] {
		uf.id[i] = j
		uf.sz[j] += uf.sz[i]
	} else {
		uf.id[j] = i
		uf.sz[i] += uf.sz[j]
	}
}

func main() {
	var n, m, q, u, v int
	fmt.Scan(&n, &m)
	var uf [110]unionFind
	for i := 0; i < 110; i++ {
		uf[i].init()
	}
	for i := 0; i < m; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		uf[c].union(a, b)
	}
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		fmt.Scan(&u, &v)
		z := 0
		for j := 1; j <= m; j++ {
			if uf[j].find(u, v) {
				z++
			}
		}
		fmt.Println(z)
	}
}

package main

import "fmt"

const ufMax = 110

type unionFind struct {
	id [ufMax]int
	sz [ufMax]int
}

func (uf *unionFind) init() {
	for i := 0; i < ufMax; i++ {
		uf.id[i] = i
		uf.sz[i] = 1
	}
}

func (uf *unionFind) root(i int) int {
	for i != uf.id[i] {
		uf.id[i] = uf.id[uf.id[i]]
		i = uf.id[i]
	}
	return i
}

func (uf *unionFind) find(p, q int) bool {
	return uf.root(p) == uf.root(q)
}

func (uf *unionFind) union(p, q int) {
	i, j := uf.root(p), uf.root(q)
	if uf.sz[i] < uf.sz[j] {
		uf.id[i] = j
		uf.sz[j] += uf.sz[i]
	} else {
		uf.id[j] = i
		uf.sz[i] += uf.sz[j]
	}
}

func main() {
	var n, m, q, u, v int
	fmt.Scan(&n, &m)
	var uf [110]unionFind
	for i := 0; i < 110; i++ {
		uf[i].init()
	}
	for i := 0; i < m; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		uf[c].union(a, b)
	}
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		fmt.Scan(&u, &v)
		z := 0
		for j := 1; j <= m; j++ {
			if uf[j].find(u, v) {
				z++
			}
		}
		fmt.Println(z)
	}
}

package main

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

func solve() {
	n := readInt()
	m := readInt()
	forbidden := make(map[int]map[int]bool)
	for i := 0; i < n; i++ {
		forbidden[i] = make(map[int]bool)
	}
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		if v < u {
			u, v = v, u
		}
		forbidden[u][v] = true
		forbidden[v][u] = true
	}
	id := make([]int, n)
	for i := 0; i < n; i++ {
		id[i] = i
	}
	sort.Slice(id, func(i, j int) bool {
		if len(forbidden[id[i]]) == len(forbidden[id[j]]) {
			return id[i] < id[j]
		}
		return len(forbidden[id[i]]) < len(forbidden[id[j]])
	})
	bestIndex := id[0]
	fmt.Println(n - 1)
	for j := 0; j < n; j++ {
		if j != bestIndex {
			fmt.Println(bestIndex + 1, j + 1)
		}
	}
}

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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

// IO

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 readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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


Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him.Before the very beginning of the game several cards are lain out on a table in one line from the left to the right. Each card contains a digit: 0 or 1. Players move in turns and Masha moves first. During each move a player should remove a card from the table and shift all other cards so as to close the gap left by the removed card. For example, if before somebody's move the cards on the table formed a sequence 01010101, then after the fourth card is removed (the cards are numbered starting from 1), the sequence will look like that: 0100101. The game ends when exactly two cards are left on the table. The digits on these cards determine the number in binary notation: the most significant bit is located to the left. Masha's aim is to minimize the number and Petya's aim is to maximize it.An unpleasant accident occurred before the game started. The kids spilled juice on some of the cards and the digits on the cards got blurred. Each one of the spoiled cards could have either 0 or 1 written on it. Consider all possible variants of initial arrangement of the digits (before the juice spilling). For each variant, let's find which two cards are left by the end of the game, assuming that both Petya and Masha play optimally. An ordered pair of digits written on those two cards is called an outcome. Your task is to find the set of outcomes for all variants of initial digits arrangement.

The first line contains a sequence of characters each of which can either be a "0", a "1" or a "?". This sequence determines the initial arrangement of cards on the table from the left to the right. The characters "?" mean that the given card was spoiled before the game. The sequence's length ranges from 2 to 105, inclusive.

Print the set of outcomes for all possible initial digits arrangements. Print each possible outcome on a single line. Each outcome should be represented by two characters: the digits written on the cards that were left by the end of the game. The outcomes should be sorted lexicographically in ascending order (see the first sample).

NoteIn the first sample all 16 variants of numbers arrangement are possible. For the variant 0000 the outcome is 00. For the variant 1111 the outcome is 11. For the variant 0011 the outcome is 01. For the variant 1100 the outcome is 10. Regardless of outcomes for all other variants the set which we are looking for will contain all 4 possible outcomes.In the third sample only 2 variants of numbers arrangement are possible: 111 and 101. For the variant 111 the outcome is 11. For the variant 101 the outcome is 01, because on the first turn Masha can remove the first card from the left after which the game will end.

package main

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

func main() {
	in := bufio.NewReaderSize(os.Stdin, 2<<16)
	var s string
	fmt.Fscan(in, &s)

	var one, zero, q int
	var last byte
	for i := range s {
		last = s[i]
		switch last {
		case '0':
			zero++
		case '1':
			one++
		default:
			q++
		}
	}

	if len(s)&1 == 1 {
		one--
	}
	if zero+q > one {
		fmt.Println("00")
	}
	diff := zero - one
	if diff < 0 {
		diff *= -1
	}
	if q >= diff {
		switch last {
		case '0':
			fmt.Println("10")
		case '1':
			fmt.Println("01")
		default:
			if !(zero < one && diff == q) {
				fmt.Println("01")
			}
			if !(one < zero && diff == q) {
				fmt.Println("10")
			}
		}
	}
	if one+q > zero {
		fmt.Println("11")
	}
}

package main

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

func main() {
	in := bufio.NewReaderSize(os.Stdin, 2<<16)
	var s string
	fmt.Fscan(in, &s)

	var one, zero, q int
	var last byte
	for i := range s {
		last = s[i]
		switch last {
		case '0':
			zero++
		case '1':
			one++
		default:
			q++
		}
	}

	if len(s)&1 == 1 {
		one--
	}
	if zero+q > one {
		fmt.Println("00")
	}
	diff := zero - one
	if diff < 0 {
		diff *= -1
	}
	if q >= diff {
		if last == '1' || last == '?' {
			fmt.Println("01")
		}
		if last == '0' || last == '?' {
			fmt.Println("10")
		}
	}
	if one+q > zero {
		fmt.Println("11")
	}
}


You are given a sequence of numbers a1, a2, ..., an, and a number m.Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.

The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.

NoteIn the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.In the third sample test you need to choose two numbers 3 on the ends.In the fourth sample test you can take the whole subsequence.

package main

import "fmt"

func main() {
	var n,m,i,j,flag rune
	fmt.Scan(&n,&m)
	if n>m {
	   fmt.Println("YES")
	}else{
	   var a[1005] rune
	   var f[2][1005] rune
	   f[0][m]=1
	   for i=1;i<=n;i++{
	      flag=flag^1
	      fmt.Scan(&a[i])
	      a[i]=a[i]%m
	      for j=0;j<=m;j++{
	         if f[flag^1][j]>0{
	            f[flag][(j-a[i]+m)%m]=1
	         }
	         if f[flag^1][j]>0{
	            f[flag][j]=1
	         }
	      }
	   }
	   if (f[flag][0]>0) {
	      fmt.Println("YES")
	   }else{
	      fmt.Println("NO")
	   }
	}
}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, m int
	Scan(&n, &m)
	if n >= m {
		Print("YES")
		return
	}
	arr := make([]int, n)
	for i := range arr {
		Scan(&arr[i])
		arr[i] %= m
	}

	dp := [2][]int{}
	for i := range dp {
		dp[i] = make([]int, m)
		for j := range dp[i] {
			dp[i][j] = -1e8
		}
	}
	dp[0][0] = 0
	for i := 1; i <= n; i++ {
		i1, i0 := i&1, (i-1)&1
		for j := range dp[i1] {
			if dp[i0][j] >= 0 {
				dp[i1][j] = dp[i0][j]
			}
		}
		for j := range dp[i1] {
			if val := dp[i0][(j-arr[i-1]+m)%m] + 1; val > dp[i1][j] {
				dp[i1][j] = val
			}
		}
	}
	if dp[n&1][0] > 0 {
		Print("YES")
	} else {
		Print("NO")
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol577B(reader io.Reader, writer io.Writer) {
	max := func(a, b int) int {
		if a >= b {
			return a
		}
		return b
	}
	const inf int = 1e8

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n, m int
	Fscan(in, &n, &m)
	if n >= m {
		Fprint(out, "YES")
		return
	}
	arr := make([]int, n)
	for i := range arr {
		Fscan(in, &arr[i])
		arr[i] %= m
	}

	// dp[i][j]>0: 前i个数组合出了j的倍数
	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, m)
		for j := range dp[i] {
			dp[i][j] = -inf
		}
	}
	dp[0][0] = 0
	for i := 1; i <= n; i++ {
		for j := range dp[i] {
			if dp[i-1][j] >= 0 {
				dp[i][j] = dp[i-1][j]
			}
		}
		for j := range dp[i-1] {
			dp[i][j] = max(dp[i][j], dp[i-1][(j-arr[i-1]+m)%m]+1)
		}
	}
	if dp[n][0] > 0 {
		Fprint(out, "YES")
	} else {
		Fprint(out, "NO")
	}
}

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

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(input, "%d %d\n", &n, &m)
	if n > m {
		fmt.Println("YES")
		return
	}
	a := [1005][1000]int{}
	tmp := 0
	for i := 1; i <= n; i++ {
		if a[i-1][0] == 1 {
			fmt.Println("YES")
			return
		}
		fmt.Fscanf(input, "%d", &tmp)
		a[i][tmp%m] = 1
		for j := 1; j < m; j++ {
			if a[i-1][j] == 1 {
				a[i][j] = 1
				a[i][(j+tmp)%m] = 1
			}
		}
	}
	// for i := 0; i <= n; i++ {
	// 	fmt.Println(a[i][:m])
	// }
	if a[n][0] == 1 {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func min(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func max(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

package main

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

var N, M int
var deg = map[int]int{}
var dp [1010][1010][2]int
var A []int

func init() {
	for i := 0; i < 1010; i++ {
		for j := 0; j < 1010; j++ {
			for k := 0; k < 2; k++ {
				dp[i][j][k] = -1
			}
		}
	}
}

var K int

func memo(pos, mod, pic int) int {
	if pos == K {
		if pic == 1 {
			if mod == 0 {
				return 1
			}
		}
		return 0
	}
	if dp[pos][mod][pic] >= 0 {
		return dp[pos][mod][pic]
	}
	num := A[pos]
	var res int
	for i := 0; i <= deg[num]; i++ {
		var nextPic int
		if i != 0 {
			nextPic = 1
		} else {
			nextPic = 0
		}
		res = memo(pos+1, (mod+i*num)%M, pic|nextPic)
		if res >= 1 {
			break
		}
	}
	dp[pos][mod][pic] = res
	return res
}

func main() {
	fsc := NewFastScanner()
	N = fsc.NextInt()
	M = fsc.NextInt()
	for i := 0; i < N; i++ {
		a := fsc.NextInt() % M
		if a == 0 {
			fmt.Println("YES")
			os.Exit(0)
		}
		deg[a]++
	}
	for key, _ := range deg {
		A = append(A, key)
	}
	K = len(A)
	res := memo(0, 0, 0)
	if res >= 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

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

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

package main

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

var (
	n, m int
	a    []int
)

func solve() string {
	if n > m {
		return "YES"
	}
	dp := make([][]bool, m+1)
	for i := 0; i < m+1; i++ {
		dp[i] = make([]bool, m+1)
		for j := 0; j < m+1; j++ {
			dp[i][j] = false
		}
	}

	dp[0][a[0]%m] = true
	for i := 0; i < n-1; i++ {
		dp[i+1][a[i+1]%m] = true
		for j := 0; j < m; j++ {
			if dp[i][j] == true {
				dp[i+1][(j+a[i+1])%m] = true
				dp[i+1][j] = true
			}
		}
	}
	// for i := 0; i < n; i++ {
	// 	for j := 0; j < m; j++ {
	// 		fmt.Print(dp[i][j], " ")
	// 	}
	// 	fmt.Println()
	// }
	if dp[n-1][0] == true {
		return "YES"
	} else {
		return "NO"
	}
}

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

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

	fmt.Println(solve())
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol577B(reader io.Reader, writer io.Writer) {
	max := func(a, b int) int {
		if a >= b {
			return a
		}
		return b
	}
	const inf int = 1e8

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n, m int
	Fscan(in, &n, &m)
	if n >= m {
		Fprint(out, "YES")
		return
	}
	arr := make([]int, n)
	for i := range arr {
		Fscan(in, &arr[i])
		arr[i] %= m
	}

	// 前i个数组合出了j
	dp := [2][]int{}
	for i := 0; i < 2; i++ {
		dp[i] = make([]int, m)
		for j := range dp[i] {
			dp[i][j] = -inf
		}
	}
	dp[0][0] = 0
	for i := 1; i <= n; i++ {
		cur, prev := i&1, (i-1)&1
		dp[cur][0] = dp[prev][0]
		for j := range dp[prev] {
			dp[cur][j] = max(dp[cur][j], dp[prev][(j-arr[i-1]+m)%m]+1)
		}
	}
	if dp[n&1][0] > 0 {
		Fprint(out, "YES")
	} else {
		Fprint(out, "NO")
	}
}

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

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(input, "%d %d\n", &n, &m)
	tmp, tsum := 0, 0
	prefix := make([]int, 1000)
	prefix[0] = 1
	for i := 0; i < n; i++ {
		fmt.Fscanf(input, "%d", &tmp)
		tsum = (tsum + tmp) % m
		if prefix[tsum] != 0 {
			fmt.Println("YES")
			return
		}
		for j := 1; j < n; j++ {
			if prefix[j] != 0 {
				idx := (tsum + m - j) % m
				if prefix[idx] != 0 {
					fmt.Println("YES")
					return
				}
				prefix[idx] = 1
			}
		}
		prefix[tsum] = 1
	}
	fmt.Println("NO")
}

func min(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func max(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}


You are given $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, such that for each $$$1\le i \le n$$$ holds $$$i-n\le a_i\le i-1$$$.Find some nonempty subset of these integers, whose sum is equal to $$$0$$$. It can be shown that such a subset exists under given constraints. If there are several possible subsets with zero-sum, you can find any of them.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^6$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n \le 10^6$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i-n \le a_i \le i-1$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.

For each test case, output two lines. In the first line, output $$$s$$$ ($$$1\le s \le n$$$) — the number of elements in your subset. In the second line, output $$$s$$$ integers $$$i_1, i_2, \dots, i_s$$$ ($$$1\le i_k \le n$$$). All integers have to be pairwise different, and $$$a_{i_1} + a_{i_2} + \dots + a_{i_s}$$$ has to be equal to $$$0$$$. If there are several possible subsets with zero-sum, you can find any of them.

NoteIn the first example, we get sum is $$$a_1 = 0$$$.In the second example, we get sum is $$$a_1 + a_4 + a_3 + a_2 = 0$$$.

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {

	defer writer.Flush()

	var t int
	var a, was, ans [1000050]int
	for scanf("%d\n",&t);t>0;t-- {
		var n int
		scanf("%d\n",&n)
		for i:=1;i<=n;i++ {
			scanf("%d",&a[i])
			a[i]=i-a[i]
			was[i]=0
		}
		scanf("\n");
		var x int=1
		for was[x]==0 {
			was[x]=1
			x=a[x]
		}
		var cnt int=0
		for was[x]==1 {
			was[x]=2
			ans[cnt]=x
			cnt++
			x=a[x]
		}
		printf("%d\n",cnt)
		for i:=0;i<cnt;i++ {
			printf("%d ",ans[i])
		}
		printf("\n")
	}
}


A and B are preparing themselves for programming contests.B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.Can you help B find out exactly what two errors he corrected?

The first line of the input contains integer n (3 ≤ n ≤ 105) — the initial number of compilation errors. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the errors the compiler displayed for the first time.  The third line contains n - 1 space-separated integers b1, b2, ..., bn - 1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.  The fourth line contains n - 2 space-separated integers с1, с2, ..., сn - 2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.

Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.

NoteIn the first test sample B first corrects the error number 8, then the error number 123.In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.

package main

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

var (
	scanner = bufio.NewScanner(os.Stdin)
	reader  = bufio.NewReader(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
)

const (
	MAXN = 1000000001
)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	var suma, sumb, sumc int64 = 0, 0, 0

	for i := 0; i < n; i++ {
		suma += int64(nextInt())
	}

	n--

	for i := 0; i < n; i++ {
		sumb += int64(nextInt())
	}

	n--

	for i := 0; i < n; i++ {
		sumc += int64(nextInt())
	}

	println(suma-sumb)
	println(sumb-sumc)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

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

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
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 := getI()
  a, b, c := map[int]int{}, map[int]int{}, map[int]int{}
  for i := 0; i < n; i++ {
    a[getI()] += 1
  }
  for i := 1; i < n; i++ {
    b[getI()] += 1
  }
  for i := 2; i < n; i++ {
    c[getI()] += 1
  }
  first, second := -1, -1
  for value, count := range a {
    if b[value] < count {
      first = value
      break
    }
  }
  for value, count := range b {
    if c[value] < count {
      second = value
      break
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n%d\n", first, second))
}

package main

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

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

	m1 := make(map[int]int)
	m2 := make(map[int]int)
	m3 := make(map[int]int)

	reader := bufio.NewReader(os.Stdin)

	line, _ := reader.ReadString('\n')
	list := strings.Split(strings.TrimRight(line, "\r\n"), " ")
	for i := 0; i < n; i++ {
		t, _ := strconv.ParseUint(list[i], 10, 64)
		m1[int(t)]++
	}

	line, _ = reader.ReadString('\n')
	list = strings.Split(strings.TrimRight(line, "\r\n"), " ")
	for i := 0; i < n-1; i++ {
		t, _ := strconv.ParseUint(list[i], 10, 64)
		m2[int(t)]++
	}

	line, _ = reader.ReadString('\n')
	list = strings.Split(strings.TrimRight(line, "\r\n"), " ")
	for i := 0; i < n-2; i++ {
		t, _ := strconv.ParseUint(list[i], 10, 64)
		m3[int(t)]++
	}

	for k, v := range m1 {
		if m2[k] < v {
			fmt.Println(k)
			break
		}
	}
	for k, v := range m2 {
		if m3[k] < v {
			fmt.Println(k)
			break
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

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

func getLine() string {
	s, _ := reader.ReadString('\n')
	if strings.HasSuffix(s, "\r\n") {
		s = s[:len(s)-2]
	} else if strings.HasSuffix(s, "\n") {
		s = s[:len(s)-1]
	}
	return s
}
func getLine2Int() (n int) {
	scanf("%d\n", &n)
	return
}
func getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

func pcheck(i bool) {
	if i {
		printf("Yes\n")
	} else {
		printf("No\n")
	}
}

var debug = true

func see(a interface{}) {
	if debug {
		printf("DEBUG:%v\n", a)
	}
}

func main() {
	defer writer.Flush()

	n := getLine2Int()
	in1 := getLine2Ints(n)
	in2 := getLine2Ints(n - 1)
	in3 := getLine2Ints(n - 2)
	var r1, r2 int
	for i := 0; i < n; i++ {
		r1 ^= in1[i]
	}
	for i := 0; i < n-1; i++ {
		r1 ^= in2[i]
		r2 ^= in2[i]
	}
	for i := 0; i < n-2; i++ {
		r2 ^= in3[i]
	}
	printf("%d\n%d\n", r1, r2)
}

package main

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

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

	var n int
	var v int64
	Fscan(in, &n)
	s := make([]int64, 3*n)
	for i := 0; i < 3*n-3; i++ {
		Fscan(in, &v)
		s[i+1] = s[i] + v
	}
	a, b, c := s[n], s[2*n-1], s[3*n-3]
	Fprint(out, 2*a-b, "\n", 2*b-a-c)
}

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

package main

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

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

	var n, v int
	Fscan(in, &n)
	vis := make(map[int]int, n)
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		vis[v]++
	}
	vis2 := make(map[int]int, len(vis))
	for i := 1; i < n; i++ {
		Fscan(in, &v)
		vis[v]--
		if vis[v] == 0 {
			delete(vis, v)
		}
		vis2[v]++
	}
	for v := range vis {
		Fprintln(out, v)
	}
	for i := 2; i < n; i++ {
		Fscan(in, &v)
		vis2[v]--
		if vis2[v] == 0 {
			delete(vis2, v)
		}
	}
	for v := range vis2 {
		Fprint(out, v)
	}
}

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

package main

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

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

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

var n, a int

func main() {
	fmt.Fscan(reader, &n)
	m1 := make(map[int]int)
	m2 := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a)
		m1[a]++
	}
	for i := 1; i < n; i++ {
		fmt.Fscan(reader, &a)
		m1[a]--
		m2[a]++
	}
	for i := 2; i < n; i++ {
		fmt.Fscan(reader, &a)
		m2[a]--
	}
	for k, v := range m1 {
		if v == 1 {
			fmt.Println(k)
			break
		}
	}
	for k, v := range m2 {
		if v == 1 {
			fmt.Println(k)
			break
		}
	}
}

package main

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

var scanner *bufio.Scanner

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

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

func printf(format string, x ...interface{}) {
	fmt.Fprintf(os.Stdout, format, x...)
}

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

	printf("%s", Problem519B())
}

func Problem519B() string {
	n := getI()
	array := 0
	array2 := 0
	array3 := 0

	for i := 0; i < n ; i++ {
		temp := getI()
		array += temp
	}

	for i := 0; i < n - 1 ; i++ {
		temp := getI()
		array2 += temp
	}

	for i := 0; i < n - 2 ; i++ {
		temp := getI()
		array3 += temp
	}

	first := array - array2
	second := array2-array3

	return fmt.Sprintf("%d %d", first, second)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var str []byte
	var sums [3]int

	_, _, _ = reader.ReadLine()

	for i := 0; i < 3; i++ {
		str, _ = reader.ReadBytes(byte('\n'))
		if str[len(str)-1] == '\n' {
			str = str[:len(str)-1]
		}
		str = str[:len(str)-1]

		tmparr := strings.Split(string(str), " ")
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	var sum uint64
	//_, _ = fmt.Scanf("%d\n", &n)
	_, _ = fmt.Fscanf(in, "%d\n", &n)

	for i := 0; i < n; i++ {
		var a uint64
		if i != n-1 {
			//_, _ = fmt.Scanf("%d", &a)
			_, _ = fmt.Fscanf(in, "%d", &a)
		} else {
			//_, _ = fmt.Scanf("%d\n", &a)
			_, _ = fmt.Fscanf(in, "%d\n", &a)
		}
		sum += a
	}

	var sum1 uint64
	for i := 0; i < n-1; i++ {
		var a uint64
		if i != n-2 {
			//_, _ = fmt.Scanf("%d", &a)
			_, _ = fmt.Fscanf(in, "%d", &a)
		} else {
			//_, _ = fmt.Scanf("%d\n", &a)
			_, _ = fmt.Fscanf(in, "%d\n", &a)
		}
		sum1 += a
	}

	var sum2 uint64
	for i := 0; i < n-2; i++ {
		var a uint64
		if i != n-3 {
			//_, _ = fmt.Scanf("%d", &a)
			_, _ = fmt.Fscanf(in, "%d", &a)
		} else {
			//_, _ = fmt.Scanf("%d\n", &a)
			_, _ = fmt.Fscanf(in, "%d\n", &a)
		}
		sum2 += a
	}

	fmt.Println(sum-sum1)
	fmt.Println(sum1-sum2)
}

package main

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

var (
	scanner = bufio.NewScanner(os.Stdin)
	reader  = bufio.NewReader(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
)

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	var suma, sumb, sumc int64 = 0, 0, 0

	for i := 0; i < n; i++ {
		suma += int64(nextInt())
	}

	n--

	for i := 0; i < n; i++ {
		sumb += int64(nextInt())
	}

	n--

	for i := 0; i < n; i++ {
		sumc += int64(nextInt())
	}

	println(suma - sumb)
	println(sumb - sumc)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

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

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

	m1 := make(map[int]int)
	m2 := make(map[int]int)
	m3 := make(map[int]int)

	reader := bufio.NewReader(os.Stdin)

	line, _ := reader.ReadString('\n')
	list := strings.Split(strings.TrimRight(line, "\r\n"), " ")
	for i := 0; i < n; i++ {
		t, _ := strconv.ParseUint(list[i], 10, 64)
		m1[int(t)]++
	}

	line, _ = reader.ReadString('\n')
	list = strings.Split(strings.TrimRight(line, "\r\n"), " ")
	for i := 0; i < n-1; i++ {
		t, _ := strconv.ParseUint(list[i], 10, 64)
		m2[int(t)]++
	}

	line, _ = reader.ReadString('\n')
	list = strings.Split(strings.TrimRight(line, "\r\n"), " ")
	for i := 0; i < n-2; i++ {
		t, _ := strconv.ParseUint(list[i], 10, 64)
		m3[int(t)]++
	}

	for k := range m1 {
		if m2[k] == 0 {
			fmt.Println(k)
			break
		}
	}
	for k := range m2 {
		if m3[k] == 0 {
			fmt.Println(k)
			break
		}
	}
}

package main

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

var scanner *bufio.Scanner

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

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

func printf(format string, x ...interface{}) {
	fmt.Fprintf(os.Stdout, format, x...)
}

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

	printf("%s", Problem519B())
}

func Problem519B() string {
	n := getI()
	arr := make(map[int]int, n)
	arr2 := make(map[int]int, n -1)
	arr3 := make(map[int]int, n -2)

	first := 0
	second := 0

	for i := 0; i < n ; i++ {
		temp := getI()
		if arr[temp] > 0 {
			arr[temp] = arr[temp] + 2
		}else {
			arr[temp] = 1
		}
	}

	for i := 0; i < n - 1 ; i++ {
		temp := getI()
		if arr[temp] == 1 {
			arr2[temp] = arr[temp] + 1
		}else if arr[temp] > 1 {
			arr2[temp] = arr[temp] - 1
		}
	}

	for i := 0; i < n - 2 ; i++ {
		temp := getI()
		arr3[temp] = 1
		if arr[temp] == 1 {
			arr3[temp] = arr[temp] + 1
		}else if arr[temp] > 1 {
			arr3[temp] = arr2[temp] - 1
		}
	}

	for k := range arr {
		if arr2[k] == 0 {
			first = k
		}
	}

	for k := range arr2 {
		if arr3[k] != arr2[k] {
			second = k
		}
	}

	return fmt.Sprintf("%d %d", first, second)
}

package main

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

var scanner *bufio.Scanner

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

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

func printf(format string, x ...interface{}) {
	fmt.Fprintf(os.Stdout, format, x...)
}

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

	printf("%s", Problem519B())
}

func Problem519B() string {
	n := getI()
	arr := make(map[int]int, n)

	for i := 0; i < n ; i++ {
		temp := getI()
		if arr[temp] > 0 {
			arr[temp] = arr[temp] + 2
		}else {
			arr[temp] = 1
		}
	}

	for i := 0; i < n - 1 ; i++ {
		temp := getI()
		arr[temp] = arr[temp] - 1
	}

	for i := 0; i < n - 2 ; i++ {
		temp := getI()
		arr[temp] = arr[temp] - 1
	}

	answer := ""
	for k, v := range arr {
		if v >= 0 {
			answer += fmt.Sprintf("%d \n", k)
		}
	}

	return answer
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var str []byte
	var sums [3]int
	_, _, _ = reader.ReadLine()

	for i := 0; i < 3; i++ {
		str, _, _ = reader.ReadLine()
		tmparr := strings.Split(string(str), " ")
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n []byte
	var str []byte
	var sums [3]int
	n, _ = reader.ReadBytes(byte('\n'))
	lala, _ := strconv.Atoi(string(n))

	for i := 0; i < 3; i++ {
		str, _ = reader.ReadBytes(byte('\n'))
		tmparr := strings.Split(string(str), " ")
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	if lala == 100000 {
		sums[0] = 10000
		fmt.Println(sums)
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n []byte
	var str []byte
	var sums [3]int
	n, _, _ = reader.ReadLine()
	lala, _ := strconv.Atoi(string(n))

	for i := 0; i < 3; i++ {
		str, _, _ = reader.ReadLine()
		tmparr := strings.Split(string(str), " ")
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	if lala == 100000 {
		fmt.Println(sums)
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	var n int
	fmt.Scan(&n)
	var sums [3]int

	var reader = bufio.NewReader(os.Stdin)

	for i := 0; i < 3; i++ {
		str, _, _ := reader.ReadLine()
		tmparr := strings.Split(string(str), " ")
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var str []byte
	var sums [3]int

	_, _, _ = reader.ReadLine()

	for i := 0; i < 3; i++ {
		str, _ = reader.ReadBytes(byte('\n'))
		str = str[:len(str)-1]
		tmparr := strings.Split(string(str), " ")
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	var n int
	var str []byte
	var sums [3]int
	fmt.Scan(&n)

	reader := bufio.NewReader(os.Stdin)

	for i := 0; i < 3; i++ {
		str, _, _ = reader.ReadLine()
		tmparr := strings.Split(string(str), " ")
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	var n int
	var str []byte
	var sums [3]int
	fmt.Scan(&n)

	reader := bufio.NewReader(os.Stdin)

	for i := 0; i < 3; i++ {
		str, _, _ = reader.ReadLine()
		tmparr := strings.Split(string(str), " ")
		fmt.Println(tmparr)
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var str []byte
	var sums [3]int

	_, _, _ = reader.ReadLine()

	for i := 0; i < 3; i++ {
		str, _ = reader.ReadBytes(byte('\n'))
		//str = str[:len(str)-1]
		tmparr := strings.Split(string(str), " ")
		fmt.Println(tmparr)
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}
	fmt.Println(sums)

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n []byte
	var str []byte
	var sums [3]int
	n, _, _ = reader.ReadLine()
	lala, _ := strconv.Atoi(string(n))

	for i := 0; i < 3; i++ {
		str, _, _ = reader.ReadLine()
		tmparr := strings.Split(string(str), " ")
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	if lala == 100000 {
		sums[0] = 10000
		fmt.Println(sums)
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var str []byte
	var sums [3]int

	_, _, _ = reader.ReadLine()

	for i := 0; i < 3; i++ {
		str, _ = reader.ReadBytes(byte('\n'))
		str = str[:len(str)-1]
		tmparr := strings.Split(string(str), " ")
		fmt.Println(tmparr)
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var str []byte
	var sums [3]int

	_, _ = reader.ReadBytes(byte('\n'))

	for i := 0; i < 3; i++ {
		str, _ = reader.ReadBytes(byte('\n'))
		str = str[:len(str)-1]
		tmparr := strings.Split(string(str), " ")
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var str []byte
	var sums [3]int

	_, _, _ = reader.ReadLine()

	for i := 0; i < 3; i++ {
		str, _ = reader.ReadBytes(byte('\n'))
		str = str[:len(str)-1]
		tmparr := strings.Split(string(str), " ")
		fmt.Println(tmparr)
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}
	fmt.Println(sums)

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

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

func main() {
	var n int
	fmt.Scan(&n)
	var sums [3]int

	scanner := bufio.NewScanner(os.Stdin)

	for i := 0; i < 3; i++ {
		scanner.Scan()
		str := scanner.Text()

		tmparr := strings.Split(str, " ")
		for _, v := range tmparr {
			val, _ := strconv.Atoi(v)
			sums[i] += val
		}
	}

	fmt.Println(sums[0] - sums[1])
	fmt.Println(sums[1] - sums[2])
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	var arr = make([]int, 0)
	_, _ = fmt.Scanf("%d\n", &n)

	for i := 0; i < n; i++ {
		var a int
		if i != n-1 {
			_, _ = fmt.Scanf("%d", &a)
		} else {
			_, _ = fmt.Scanf("%d\n", &a)
		}
		arr = append(arr, a)
	}
	sort.Ints(arr)

	var arr1 = make([]int, 0)
	for i := 0; i < n-1; i++ {
		var a int
		if i != n-1 {
			_, _ = fmt.Scanf("%d", &a)
		} else {
			_, _ = fmt.Scanf("%d\n", &a)
		}
		arr1 = append(arr1, a)
	}
	sort.Ints(arr1)

	var arr2 = make([]int, 0)
	for i := 0; i < n-2; i++ {
		var a int
		if i != n-1 {
			_, _ = fmt.Scanf("%d", &a)
		} else {
			_, _ = fmt.Scanf("%d\n", &a)
		}
		arr2 = append(arr2, a)
	}
	sort.Ints(arr2)

	for i := 0; i < n; i++ {
		if len(arr1) > i {
			if arr[i] != arr1[i] {
				fmt.Println(arr[i])
				break
			}
		} else {
			fmt.Println(arr[i])
			break
		}
	}
	for i := 0; i < n-1; i++ {
		if len(arr2) > i {
			if arr1[i] != arr2[i] {
				fmt.Println(arr1[i])
				break
			}
		} else {
			fmt.Println(arr1[i])
			break
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	var arr = make([]int, 0)
	_, _ = fmt.Scanf("%d\n", &n)

	for i := 0; i < n; i++ {
		var a int
		if i != n-1 {
			_, _ = fmt.Scanf("%d", &a)
		} else {
			_, _ = fmt.Scanf("%d\n", &a)
		}
		arr = append(arr, a)
	}
	sort.Ints(arr)

	var arr1 = make([]int, 0)
	for i := 0; i < n-1; i++ {
		var a int
		if i != n-1 {
			_, _ = fmt.Scanf("%d", &a)
		} else {
			_, _ = fmt.Scanf("%d\n", &a)
		}
		arr1 = append(arr1, a)
	}
	sort.Ints(arr1)

	var arr2 = make([]int, 0)
	for i := 0; i < n-2; i++ {
		var a int
		if i != n-1 {
			_, _ = fmt.Scanf("%d", &a)
		} else {
			_, _ = fmt.Scanf("%d\n", &a)
		}
		arr2 = append(arr2, a)
	}
	sort.Ints(arr2)

	fmt.Println(arr)
	fmt.Println(arr1)
	fmt.Println(arr2)

	for i := 0; i < n; i++ {
		if len(arr1) > i {
			if arr[i] != arr1[i] {
				fmt.Println(arr[i])
				break
			}
		} else {
			fmt.Println(arr[i])
			break
		}
	}
	for i := 0; i < n-1; i++ {
		if len(arr2) > i {
			if arr1[i] != arr2[i] {
				fmt.Println(arr1[i])
				break
			}
		} else {
			fmt.Println(arr1[i])
			break
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	var arr = make([]int, 0)
	_, _ = fmt.Scanf("%d\n", &n)

	for i := 0; i < n; i++ {
		var a int
		if i != n-1 {
			_, _ = fmt.Scanf("%d", &a)
		} else {
			_, _ = fmt.Scanf("%d\n", &a)
		}
		arr = append(arr, a)
	}
	sort.Ints(arr)

	var arr1 = make([]int, 0)
	for i := 0; i < n-1; i++ {
		var a int
		if i != n-1 {
			_, _ = fmt.Scanf("%d", &a)
		} else {
			_, _ = fmt.Scanf("%d\n", &a)
		}
		arr1 = append(arr1, a)
	}
	sort.Ints(arr1)

	var arr2 = make([]int, 0)
	for i := 0; i < n-2; i++ {
		var a int
		_, _ = fmt.Scanf("%d", &a)
		arr2 = append(arr2, a)
	}
	sort.Ints(arr2)

	for i := 0; i < n; i++ {
		if len(arr1) > i {
			if arr[i] != arr1[i] {
				fmt.Println(arr[i])
				break
			}
		} else {
			fmt.Println(arr[i])
			break
		}
	}
	for i := 0; i < n-1; i++ {
		if len(arr2) > i {
			if arr1[i] != arr2[i] {
				fmt.Println(arr1[i])
				break
			}
		} else {
			fmt.Println(arr1[i])
			break
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	var arr = make([]int, 0)
	_, _ = fmt.Scanf("%d\n", &n)

	for i := 0; i < n; i++ {
		var a int
		_, _ = fmt.Scanf("%d", &a)
		arr = append(arr, a)
	}
	sort.Ints(arr)

	var arr1 = make([]int, 0)
	for i := 0; i < n-1; i++ {
		var a int
		_, _ = fmt.Scanf("%d", &a)
		arr1 = append(arr1, a)
	}
	sort.Ints(arr1)

	var arr2 = make([]int, 0)
	for i := 0; i < n-2; i++ {
		var a int
		_, _ = fmt.Scanf("%d", &a)
		arr2 = append(arr2, a)
	}
	sort.Ints(arr2)
	_, _ = fmt.Scanf("\n")

	for i := 0; i < n; i++ {
		if len(arr1) > i {
			if arr[i] != arr1[i] {
				fmt.Println(arr[i])
				break
			}
		} else {
			fmt.Println(arr[i])
			break
		}
	}
	for i := 0; i < n-1; i++ {
		if len(arr2) > i {
			if arr1[i] != arr2[i] {
				fmt.Println(arr1[i])
				break
			}
		} else {
			fmt.Println(arr1[i])
			break
		}
	}
}


Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.

The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.

Print a single integer, the minimum amount of lost milk. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.

package main

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

var (
	R = bufio.NewReader(os.Stdin)
)

func main() {
	var n int
	fmt.Fscan(R, &n)

	var right, sum int64
	for i := 0; i < n; i++ {
		var c int
		fmt.Fscan(R, &c)
		if c == 0 {
			sum += right
		} else {
			right++
		}
	}
	fmt.Print(sum)
}

package main

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

func main(){
	var n int64
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.ParseInt(r.Text(), 0, 64)
	a := make([]int, n)
	for i:=0; int64(i)<n; i++ {
		r.Scan()
		a[i], _ = strconv.Atoi(r.Text())
	}
	var total, total1 int64 = 0, 0
	for j:=0; int64(j)<n; j++ {
		if a[j] == 0 {
			total += total1
		} else {
			total1 += 1
		}
	}
	w.WriteString(strconv.FormatInt(total, 10)+"\n")
	w.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    ans, cnt := int64(0), int64(0)
    for i := 0; i < n; i++ {
        scanner.Scan()
        if scanner.Text() == "0" {
            ans += cnt
        } else {
            cnt++
        }
    }
    fmt.Println(ans)
}

// 383A
package main

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

func main() {
	var p, ans int64
	var n, x int
	p, ans = 0, 0
	in := bufio.NewReader(os.Stdin)
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		fmt.Fscan(in, &x)
		if x == 1 {
			p++
		} else {
			ans += p
		}
	}
	fmt.Println(ans)
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strconv"
    // "sort"
    // "strings"
    // "reflect"
)

type Reader struct{
    scanner *bufio.Scanner
}

func (read *Reader) init(){
    if read.scanner == nil {
        read.scanner = bufio.NewScanner(os.Stdin)
    }
}

func (read *Reader) setWord(){
    read.scanner.Split(bufio.ScanWords)
}

func (read *Reader) setByte(){
    read.scanner.Split(bufio.ScanBytes)
}

func (read *Reader) setLine(){
    read.scanner.Split(bufio.ScanLines)
}

func (read *Reader) read() string{
    read.scanner.Scan()
    return read.scanner.Text()
}

func (read *Reader) readInt() int{
    res,_ := strconv.Atoi(read.read())
    return res
}

func (read *Reader) readByte(length int) string{
    bt := make([]byte, length+2)
    for i := 0; i < length; i++ {
        bt[i] = read.read()[0]
    }

    return string(bt)
}

var read Reader
var sortByH bool

type Person struct{
    h, w, ind, ans int
}

type Persons []Person

func (a Persons) Len() int{
    return len(a)
}

func (a Persons) Swap(i, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a Persons) Less(i, j int) bool{
    if(sortByH){
        return a[i].h < a[j].h
    } else{
        return a[i].ind < a[j].ind
    }
}

func main(){
    read.init()
    read.setWord()
    // var x int
    // x = 10000000000
    // fmt.Println(x)

    n := read.readInt()

    cow := make([]int, n)

    totLeft := 0

    for i := 0; i < n; i++{
        cow[i] = read.readInt()
        if cow[i] == 0 {
            totLeft++
        }
    }

    var totMilk int64
    totMilk = 0
    for i := 0; i < n; i++{
        if cow[i] == 1{
            totMilk += int64(totLeft)
        } else{
            totLeft--
        }
    }

    fmt.Println(totMilk)

}

// 383A-mic_rizal
package main

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

func main() {
    var n, k int
    var cou int64
    var a [200010]int
    z := bufio.NewReader(os.Stdin)
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Fscan(z, &a[i])
    }
    for i := 0; i < n; i++ {
        if a[i] == 1 {
            k++
        } else {
            cou += int64(k)
        }
    }
    fmt.Println(cou)
}

package main

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

func main(){
	var n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	count := 0
	var  ans int64
	for i := 1; i <= n; i++{
		var tmp int
		fmt.Fscan(in, &tmp)
		if tmp == 0{
			ans = ans + int64(count)
		}else{
			count++
		}
	}
	fmt.Println(ans)
}

package main

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

var (
	R = bufio.NewReader(os.Stdin)
)

func main() {
	var n int
	fmt.Fscan(R, &n)

	right := 0
	sum := 0
	for i := 0; i < n; i++ {
		var c int
		fmt.Fscan(R, &c)
		if c == 0 {
			sum += right
		} else {
			right++
		}
	}
	fmt.Print(sum)
}

package main

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

func main(){
	var n int64
	r := bufio.NewReader(os.Stdin)
	r1 := bufio.NewScanner(os.Stdin)
	r1.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	fmt.Fscan(r, &n)
	a := make([]int, n)
	for i:=0; int64(i)<n; i++ {
		r1.Scan()
		a[i], _ = strconv.Atoi(r1.Text())
	}
	total, total1 := 0, 0
	for j:=0; int64(j)<n; j++ {
		if a[j] == 0 {
			total += total1
		} else {
			total1 += 1
		}
	}
	w.WriteString(strconv.Itoa(total)+"\n")
	w.Flush()
}

package main

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

func main(){
	var n int64
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.ParseInt(r.Text(), 0, 64)
	a := make([]int, n)
	for i:=0; int64(i)<n; i++ {
		r.Scan()
		a[i], _ = strconv.Atoi(r.Text())
	}
	var total, total1 int64 = 0, 0
	for j:=0; int64(j)<n; j++ {
		if a[j] == 0 {
			total += total1
		} else {
			total1 += 1
		}
	}
	w.WriteString(strconv.Itoa(int(total))+"\n")
	w.Flush()
}

package main

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

func main(){
	var n int64
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.ParseInt(r.Text(), 0, 64)
	a := make([]int, n)
	for i:=0; int64(i)<n; i++ {
		r.Scan()
		a[i], _ = strconv.Atoi(r.Text())
	}
	total, total1 := 0, 0
	for j:=0; int64(j)<n; j++ {
		if a[j] == 0 {
			total += total1
		} else {
			total1 += 1
		}
	}
	w.WriteString(strconv.Itoa(total)+"\n")
	w.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    ans, cnt := 0, 0
    for i := 0; i < n; i++ {
        scanner.Scan()
        if scanner.Text() == "0" {
            ans += cnt
        } else {
            cnt++
        }
    }
    fmt.Println(ans)
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strconv"
    // "sort"
    // "strings"
    // "reflect"
)

type Reader struct{
    scanner *bufio.Scanner
}

func (read *Reader) init(){
    if read.scanner == nil {
        read.scanner = bufio.NewScanner(os.Stdin)
    }
}

func (read *Reader) setWord(){
    read.scanner.Split(bufio.ScanWords)
}

func (read *Reader) setByte(){
    read.scanner.Split(bufio.ScanBytes)
}

func (read *Reader) setLine(){
    read.scanner.Split(bufio.ScanLines)
}

func (read *Reader) read() string{
    read.scanner.Scan()
    return read.scanner.Text()
}

func (read *Reader) readInt() int{
    res,_ := strconv.Atoi(read.read())
    return res
}

func (read *Reader) readByte(length int) string{
    bt := make([]byte, length+2)
    for i := 0; i < length; i++ {
        bt[i] = read.read()[0]
    }

    return string(bt)
}

var read Reader
var sortByH bool

type Person struct{
    h, w, ind, ans int
}

type Persons []Person

func (a Persons) Len() int{
    return len(a)
}

func (a Persons) Swap(i, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a Persons) Less(i, j int) bool{
    if(sortByH){
        return a[i].h < a[j].h
    } else{
        return a[i].ind < a[j].ind
    }
}

func main(){
    read.init()
    read.setWord()

    n := read.readInt()

    cow := make([]int, n)

    totLeft := 0

    for i := 0; i < n; i++{
        cow[i] = read.readInt()
        if cow[i] == 0 {
            totLeft++
        }
    }

    totMilk := 0
    for i := 0; i < n; i++{
        if cow[i] == 1{
            totMilk += totLeft
        } else{
            totLeft--
        }
    }

    fmt.Println(totMilk)

}

// 383A-mic_rizal
package main

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

func main() {
    var n, cou, k int
    var a [220000]int
    z := bufio.NewReader(os.Stdin)
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Fscan(z, &a[i])
    }
    for i := 0; i < n; i++ {
        if a[i] == 1 {
            k++
        } else {
            cou += k
        }
    }
    fmt.Println(cou)
}

package main

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

func main(){
	var n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	count := 0
	ans := 0
	for i := 1; i <= n; i++{
		var tmp int
		fmt.Fscan(in, &tmp)
		if tmp == 0{
			ans += count
		}else{
			count++
		}
	}
	fmt.Println(ans)
}