Given an array of integer $$$a_1, a_2, \ldots, a_n$$$. In one operation you can make $$$a_i := a_i + 1$$$ if $$$i < n$$$ and $$$a_i \leq a_{i + 1}$$$, or $$$i = n$$$ and $$$a_i \leq a_1$$$.You need to check whether the array $$$a_1, a_2, \ldots, a_n$$$ can become equal to the array $$$b_1, b_2, \ldots, b_n$$$ in some number of operations (possibly, zero). Two arrays $$$a$$$ and $$$b$$$ of length $$$n$$$ are called equal if $$$a_i = b_i$$$ for all integers $$$i$$$ from $$$1$$$ to $$$n$$$.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 4 \cdot 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) – the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) – the elements of the array $$$a$$$. The third line of each test case contains $$$n$$$ integers $$$b_1, \ldots, b_n$$$ ($$$1 \le b_i \le 10^9$$$) – the elements of the array $$$b$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output "YES" if you can get the array $$$b$$$, otherwise output "NO". You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

NoteIn the first test case, the array $$$a$$$ is already equal to the array $$$b$$$.In the second test case, we can't get the array $$$b$$$, because to do this we need to decrease $$$a_1$$$.In the fifth test case, we can apply operations in order to the elements with indices $$$4, 3, 3,2,2,2,1,1,1,1$$$, and then get the array $$$[5,5,5,5,5]$$$. After that, you can apply operations in order to elements with indices $$$5,4,4,3,1$$$ and already get an array $$$[6,5,6,7,6]$$$.

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

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

		f := true
		for i := range aa {
			if aa[i] > bb[i] || (aa[i] != bb[i] && bb[i] > bb[i+1]+1) {
				f = false
				break
			}
		}
		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

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

		f := true
		for i := range aa {
			if aa[i] > bb[i] {
				f = false
				break
			}
		}
		for i := range aa {
			if aa[i] != bb[i] && bb[i] > bb[i+1]+1 {
				f = false
				break
			}
		}
		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

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

func Ok(aArr, bArr []int, n, minInd int) bool {
	for i := 1; i < n; i++ {
		checkInd := (minInd - i + n) % n
		if aArr[checkInd] < bArr[checkInd] && aArr[(checkInd+1)%n]+1 < bArr[checkInd] {
			return false
		}
		aArr[checkInd] = bArr[checkInd]
	}
	return true
}

func Solve(reader *bufio.Reader) {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i_ := 0; i_ < t; i_++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		aArr := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			aArr[i], _ = strconv.Atoi(scanner.Text())
		}
		bArr := make([]int, n)
		minB := 1000000007
		for i := 0; i < n; i++ {
			scanner.Scan()
			bArr[i], _ = strconv.Atoi(scanner.Text())
			if bArr[i] < minB {
				minB = bArr[i]
			}
		}

		minDis := 1000000007
		for i := 0; i < n; i++ {
			dis := bArr[i] - aArr[i]
			if dis < minDis {
				minDis = dis
			}
		}

		if minDis < 0 {
			wr.WriteString("NO\n")
		} else {
			for i := 0; i < n; i++ {
				if aArr[i] < minB {
					aArr[i] = minB
				}
			}
			minDis := 1000000007
			minInd := 0
			for i := 0; i < n; i++ {
				dis := bArr[i] - aArr[i]
				disInd := i
				if dis < minDis {
					minDis = dis
					minInd = disInd
				}
			}
			if Ok(aArr, bArr, n, minInd) {
				wr.WriteString("YES\n")
			} else {
				wr.WriteString("NO\n")
			}
		}
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	Solve(reader)
}

package main

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

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

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

func Ok(aArr, bArr []int, n, minInd int) bool {
	for i := 1; i < n; i++ {
		checkInd := (minInd - i + n) % n
		if aArr[checkInd] < bArr[checkInd] && aArr[(checkInd+1)%n]+1 < bArr[checkInd] {
			return false
		}
		aArr[checkInd] = bArr[checkInd]
	}
	return true
}

func Solve(reader *bufio.Reader) {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i_ := 0; i_ < t; i_++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		aArr := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			aArr[i], _ = strconv.Atoi(scanner.Text())
		}
		bArr := make([]int, n)
		minB := 1000000007
		for i := 0; i < n; i++ {
			scanner.Scan()
			bArr[i], _ = strconv.Atoi(scanner.Text())
			if bArr[i] < minB {
				minB = bArr[i]
			}
		}

		minDis := 1000000007
		minInd := 0
		for i := 0; i < n; i++ {
			dis := bArr[i] - aArr[i]
			disInd := i
			if dis < minDis {
				minDis = dis
				minInd = disInd
			}
		}

		if minDis < 0 {
			wr.WriteString("NO\n")
		} else if minDis == 0 {
			if Ok(aArr, bArr, n, minInd) {
				wr.WriteString("YES\n")
			} else {
				wr.WriteString("NO\n")
			}
		} else {
			for i := 0; i < n; i++ {
				if aArr[i] < minB {
					aArr[i] = minB
				}
			}
			minDis := 1000000007
			minInd := 0
			for i := 0; i < n; i++ {
				dis := bArr[i] - aArr[i]
				disInd := i
				if dis < minDis {
					minDis = dis
					minInd = disInd
				}
			}
			if Ok(aArr, bArr, n, minInd) {
				wr.WriteString("YES\n")
			} else {
				wr.WriteString("NO\n")
			}
		}
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	Solve(reader)
}

package main

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

func Solve(reader io.Reader, writer io.Writer) {
	var t int
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscanln(reader, &n)

		a := make([]int, n)
		b := make([]int, n)

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

		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &b[i])
		}
		fmt.Fscanln(reader)

		f := true
		for i := n - 1; i < 2*n; i++ {
			if a[i%n] > b[i%n] || (a[i%n] < b[i%n] && b[i%n] > b[(i+1)%n]+1) {
				f = false
				break
			}
		}
		if f {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}
	}
}

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(1)
	// }
	// defer f.Close()
	// reader := bufio.NewReader(f)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	Solve(reader, writer)
	writer.Flush()
}

package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int = 1
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		b := make([]int, n)
		for i := range b {
			fmt.Fscan(r, &b[i])
		}
		w1 := do(n, a, b)
		fmt.Fprintln(w, w1)
	}
}

func do(n int, a, b []int) string {
	ok := true
	for i := range a {
		if a[i] != b[i] {
			ok = false
		}
	}
	if ok {
		return "YES"
	}
	for i := range a {
		if a[i] == b[i] {
			continue
		}
		j := (i + 1) % n
		if a[i] > b[i] || b[i] > b[j]+1 {
			return "NO"
		}
	}
	return "YES"
}

package main

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

var a, b, f [400005]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)
	for c := 0; c < T; c++ {
		var n int
		fmt.Fscan(in, &n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
			a[i+n] = a[i]
		}
		a[n*2] = a[0]
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &b[i])
			b[i+n] = b[i]
		}
		b[n*2] = b[0]
		p := n - 1
		failed := false
		for i := 0; i < n; i++ {
			if a[i] <= a[i+1] {
				p = i
				break
			}
		}
		f[p] = 0
		for i := p; i <= n+p+1; i++ {
			f[i+1] = 0
			if f[i] == 1 && a[i] < a[i-1]-1 {
				a[i] = a[i-1] - 1
				f[i+1] = 1
			}
			if a[i] > b[i] {
				failed = true
				break
			}
			if a[i] < b[i] {
				a[i] = b[i]
				f[i+1] = 1
			}
		}
		if failed {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

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

		f := true
		for i := range aa {
			if aa[i] == bb[i] || bb[i] <= bb[i+1]+1 {
				continue
			}
			f = false
			break
		}
		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

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

		f := true
		for i := range aa {
			if aa[i] != bb[i] && bb[i] > bb[i+1]+1 {
				f = false
				break
			}
		}
		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

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

func Ok(aArr, bArr []int, n, minInd int) bool {
	for i := 1; i < n; i++ {
		checkInd := (minInd - i + n) % n
		if aArr[checkInd] < bArr[checkInd] && aArr[(checkInd+1)%n]+1 < bArr[checkInd] {
			return false
		}
		aArr[checkInd] = bArr[checkInd]
	}
	return true
}

func Solve(reader *bufio.Reader) {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i_ := 0; i_ < t; i_++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		aArr := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			aArr[i], _ = strconv.Atoi(scanner.Text())
		}
		bArr := make([]int, n)
		minB := 1000000007
		for i := 0; i < n; i++ {
			scanner.Scan()
			bArr[i], _ = strconv.Atoi(scanner.Text())
			if bArr[i] < minB {
				minB = bArr[i]
			}
		}

		minDis := 1000000007
		minInd := 0
		for i := 0; i < n; i++ {
			dis := bArr[i] - aArr[i]
			disInd := i
			if dis < minDis {
				minDis = dis
				minInd = disInd
			}
		}

		if minDis < 0 {
			wr.WriteString("NO\n")
		} else if minDis == 0 {
			if Ok(aArr, bArr, n, minInd) {
				wr.WriteString("YES\n")
			} else {
				wr.WriteString("NO\n")
			}
		} else {
			for i := 0; i < n; i++ {
				if aArr[i] < minB {
					aArr[i] = minB
					minInd = i
				}
			}

			if Ok(aArr, bArr, n, minInd) {
				wr.WriteString("YES\n")
			} else {
				wr.WriteString("NO\n")
			}
		}
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	Solve(reader)
}

package main

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

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

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

func Ok(aArr, bArr []int, n, minInd int) bool {
	for i := 1; i < n; i++ {
		checkInd := (minInd - i + n) % n
		if aArr[checkInd] < bArr[checkInd] && aArr[(checkInd+1)%n]+1 < bArr[checkInd] {
			return false
		}
		aArr[checkInd] = bArr[checkInd]
	}
	return true
}

func Solve(reader *bufio.Reader) {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i_ := 0; i_ < t; i_++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		aArr := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			aArr[i], _ = strconv.Atoi(scanner.Text())
		}
		bArr := make([]int, n)
		minB := 1000000007
		for i := 0; i < n; i++ {
			scanner.Scan()
			bArr[i], _ = strconv.Atoi(scanner.Text())
			if bArr[i] < minB {
				minB = bArr[i]
			}
		}

		minDis := 1000000007
		minInd := 0
		for i := 0; i < n; i++ {
			dis := bArr[i] - aArr[i]
			disInd := i
			if dis < minDis {
				minDis = dis
				minInd = disInd
			}
		}

		if minDis < 0 {
			wr.WriteString("NO\n")
		} else {
			for i := 0; i < n; i++ {
				if aArr[i] < minB {
					aArr[i] = minB
					minInd = i
				}
			}

			if Ok(aArr, bArr, n, minInd) {
				wr.WriteString("YES\n")
			} else {
				wr.WriteString("NO\n")
			}
		}
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	Solve(reader)
}

package main

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

func Solve(reader io.Reader, writer io.Writer) {
	var t int
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscanln(reader, &n)

		a := make([]int, n)
		b := make([]int, n)

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

		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &b[i])
		}
		fmt.Fscanln(reader)

		f := true
		for i := n - 1; i < 2*n; i++ {
			if a[i%n] != b[i%n] && b[(i+1)%n] < b[i%n]-1 {
				f = false
				break
			}
		}
		if f {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}
	}
}

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(1)
	// }
	// defer f.Close()
	// reader := bufio.NewReader(f)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	Solve(reader, writer)
	writer.Flush()
}

package main

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

func Solve(reader io.Reader, writer io.Writer) {
	var t int
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscanln(reader, &n)

		a := make([]int, n)
		b := make([]int, n)

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

		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &b[i])
		}
		fmt.Fscanln(reader)

		f := true
		for i := n - 1; i < 2*n; i++ {
			if a[i%n] < b[i%n] && b[(i+1)%n] < b[i%n]-1 {
				f = false
				break
			}
		}
		if f {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}
	}
}

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(1)
	// }
	// defer f.Close()
	// reader := bufio.NewReader(f)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	Solve(reader, writer)
	writer.Flush()
}

package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int = 1
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		b := make([]int, n)
		for i := range b {
			fmt.Fscan(r, &b[i])
		}
		w1 := do(n, a, b)
		fmt.Fprintln(w, w1)
	}
}

func do(n int, a, b []int) string {
	ok := true
	for i := range a {
		if a[i] > b[i] {
			return "NO"
		} else if a[i] < b[i] {
			ok = false
		}
	}
	if ok {
		return "YES"
	}
	for i := range a {
		j := (i + 1) % n
		if b[i] > b[j]+1 {
			return "NO"
		}
	}
	return "YES"
}


Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task.

The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied.

If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example.

NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique".

package main

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

type point struct {
	y, x int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	readint := func() int {
		sc.Scan()
		x, _ := strconv.Atoi(string(sc.Bytes()))
		return x
	}

	n := readint()
	m := readint()

	M := make([]byte, n*m)
	for y := 0; y < n; y++ {
		sc.Scan()
		copy(M[y*m:], sc.Bytes())
	}

	show := func() {
		nl := []byte{'\n'}
		for y := 0; y < n; y++ {
			os.Stdout.Write(M[y*m : (y+1)*m])
			os.Stdout.Write(nl)
		}
	}
	fail := func() {
		os.Stdout.Write([]byte("Not unique\n"))
	}

	at := func(y, x int) byte {
		if y < 0 || y >= n || x < 0 || x >= m {
			return 0
		}
		return M[y*m+x]
	}

	D := []point{{y: 1}, {y: -1}, {x: 1}, {x: -1}}
	// ny,nx = only empty neighbor
	nbAt := func(y, x int) (ny, nx int, ok bool) {
		cnt := 0

		for _, d := range D {
			if at(y+d.y, x+d.x) == '.' {
				cnt++
				ny = y + d.y
				nx = x + d.x
			}
		}

		if cnt != 1 {
			return 0, 0, false
		}
		return ny, nx, true
	}

	paint := func(p, q point) {
		if p.y == q.y {
			if p.x > q.x {
				p.x, q.x = q.x, p.x
			}
			y := p.y
			M[y*m+p.x] = '<'
			M[y*m+q.x] = '>'
		} else {
			x := p.x
			if p.y > q.y {
				p.y, q.y = q.y, p.y
			}
			M[p.y*m+x] = '^'
			M[q.y*m+x] = 'v'
		}
	}

	var good []point
	dotCnt := 0

	for y := 0; y < n; y++ {
		for x := 0; x < m; x++ {
			if at(y, x) != '.' {
				continue
			}
			dotCnt++
			_, _, ok := nbAt(y, x)
			if ok {
				good = append(good, point{y, x})
			}
		}
	}

	for i := 0; i < len(good); i++ {
		p := good[i]
		y, x := p.y, p.x
		if at(y, x) != '.' {
			continue
		}
		ny, nx, ok := nbAt(y, x)
		if !ok {
			continue
		}

		q := point{ny, nx}
		paint(q, p)
		dotCnt -= 2
		if dotCnt == 0 {
			break
		}

		for _, d := range D {
			for _, p := range []point{p, q} {
				_, _, ok := nbAt(p.y+d.y, p.x+d.x)
				if ok {
					good = append(good, point{p.y + d.y, p.x + d.x})
				}
			}
		}
	}

	if dotCnt == 0 {
		show()
	} else {
		fail()
	}
}

package main

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

type point struct {
	y, x int
}

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

	sc.Scan()
	var n, m int
	fmt.Sscanf(sc.Text(), "%d %d", &n, &m)

	M := make([]byte, n*m)
	for y := 0; y < n; y++ {
		sc.Scan()
		copy(M[y*m:], sc.Bytes())
	}

	show := func() {
		nl := []byte{'\n'}
		for y := 0; y < n; y++ {
			os.Stdout.Write(M[y*m : (y+1)*m])
			os.Stdout.Write(nl)
		}
	}
	fail := func() {
		os.Stdout.Write([]byte("Not unique\n"))
	}

	at := func(y, x int) byte {
		if y < 0 || y >= n || x < 0 || x >= m {
			return 0
		}
		return M[y*m+x]
	}

	D := []point{{y: 1}, {y: -1}, {x: 1}, {x: -1}}
	// ny,nx = only empty neighbor
	nbAt := func(y, x int) (ny, nx int, ok bool) {
		cnt := 0

		for _, d := range D {
			if at(y+d.y, x+d.x) == '.' {
				cnt++
				ny = y + d.y
				nx = x + d.x
			}
		}

		if cnt != 1 {
			return 0, 0, false
		}
		return ny, nx, true
	}

	paint := func(p, q point) {
		if p.y == q.y {
			if p.x > q.x {
				p.x, q.x = q.x, p.x
			}
			y := p.y
			M[y*m+p.x] = '<'
			M[y*m+q.x] = '>'
		} else {
			x := p.x
			if p.y > q.y {
				p.y, q.y = q.y, p.y
			}
			M[p.y*m+x] = '^'
			M[q.y*m+x] = 'v'
		}
	}

	var good []point
	dotCnt := 0

	for y := 0; y < n; y++ {
		for x := 0; x < m; x++ {
			if at(y, x) != '.' {
				continue
			}
			dotCnt++
			_, _, ok := nbAt(y, x)
			if ok {
				good = append(good, point{y, x})
			}
		}
	}

	for i := 0; i < len(good); i++ {
		p := good[i]
		y, x := p.y, p.x
		if at(y, x) != '.' {
			continue
		}
		ny, nx, ok := nbAt(y, x)
		if !ok {
			continue
		}

		q := point{ny, nx}
		paint(q, p)
		dotCnt -= 2
		if dotCnt == 0 {
			break
		}

		for _, d := range D {
			for _, p := range []point{p, q} {
				a, b, ok := nbAt(p.y+d.y, p.x+d.x)
				if ok {
					good[i] = point{a, b}
					i--
					goto loop
				}
			}
		}
	loop:
	}

	if dotCnt == 0 {
		show()
		return
	}
	if len(good) == 0 {
		fail()
		return
	}
}

package main

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

type point struct {
	y, x int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	readint := func() int {
		sc.Scan()
		x, _ := strconv.Atoi(string(sc.Bytes()))
		return x
	}

	n := readint()
	m := readint()

	M := make([]byte, n*m)
	for y := 0; y < n; y++ {
		sc.Scan()
		copy(M[y*m:], sc.Bytes())
	}

	show := func() {
		nl := []byte{'\n'}
		for y := 0; y < n; y++ {
			os.Stdout.Write(M[y*m : (y+1)*m])
			os.Stdout.Write(nl)
		}
	}
	fail := func() {
		os.Stdout.Write([]byte("Not unique\n"))
	}

	at := func(y, x int) byte {
		if y < 0 || y >= n || x < 0 || x >= m {
			return 0
		}
		return M[y*m+x]
	}

	D := []point{{y: 1}, {y: -1}, {x: 1}, {x: -1}}
	// ny,nx = only empty neighbor
	nbAt := func(y, x int) (ny, nx int, ok bool) {
		cnt := 0

		for _, d := range D {
			if at(y+d.y, x+d.x) == '.' {
				cnt++
				ny = y + d.y
				nx = x + d.x
			}
		}

		if cnt != 1 {
			return 0, 0, false
		}
		return ny, nx, true
	}

	paint := func(p, q point) {
		if p.y == q.y {
			if p.x > q.x {
				p.x, q.x = q.x, p.x
			}
			y := p.y
			M[y*m+p.x] = '<'
			M[y*m+q.x] = '>'
		} else {
			x := p.x
			if p.y > q.y {
				p.y, q.y = q.y, p.y
			}
			M[p.y*m+x] = '^'
			M[q.y*m+x] = 'v'
		}
	}

	var good []point
	dotCnt := 0

	for y := 0; y < n; y++ {
		for x := 0; x < m; x++ {
			if at(y, x) != '.' {
				continue
			}
			dotCnt++
			_, _, ok := nbAt(y, x)
			if ok {
				good = append(good, point{y, x})
			}
		}
	}

	for i := 0; i < len(good); i++ {
		p := good[i]
		y, x := p.y, p.x
		if at(y, x) != '.' {
			continue
		}
		ny, nx, ok := nbAt(y, x)
		if !ok {
			continue
		}

		q := point{ny, nx}
		paint(q, p)
		dotCnt -= 2
		if dotCnt == 0 {
			break
		}

		for _, d := range D {
			for _, p := range []point{p, q} {
				a, b, ok := nbAt(p.y+d.y, p.x+d.x)
				if ok {
					good[i] = point{a, b}
					i--
					goto loop
				}
			}
		}
	loop:
	}

	if dotCnt == 0 {
		show()
	} else {
		fail()
	}
}

package main

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

type point struct {
	y, x int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	readint := func() int {
		sc.Scan()
		x, _ := strconv.Atoi(string(sc.Bytes()))
		return x
	}

	n := readint()
	m := readint()

	M := make([]byte, n*m)
	for y := 0; y < n; y++ {
		sc.Scan()
		copy(M[y*m:], sc.Bytes())
	}

	show := func() {
		nl := []byte{'\n'}
		for y := 0; y < n; y++ {
			os.Stdout.Write(M[y*m : (y+1)*m])
			os.Stdout.Write(nl)
		}
	}
	fail := func() {
		os.Stdout.Write([]byte("Not unique\n"))
	}

	at := func(y, x int) byte {
		if y < 0 || y >= n || x < 0 || x >= m {
			return 0
		}
		return M[y*m+x]
	}

	D := []point{{y: 1}, {y: -1}, {x: 1}, {x: -1}}
	// ny,nx = only empty neighbor
	nbAt := func(y, x int) (ny, nx int, ok bool) {
		cnt := 0

		for _, d := range D {
			if at(y+d.y, x+d.x) == '.' {
				cnt++
				ny = y + d.y
				nx = x + d.x
			}
		}

		if cnt != 1 {
			return 0, 0, false
		}
		return ny, nx, true
	}

	paint := func(p, q point) {
		if p.y == q.y {
			if p.x > q.x {
				p.x, q.x = q.x, p.x
			}
			y := p.y
			M[y*m+p.x] = '<'
			M[y*m+q.x] = '>'
		} else {
			x := p.x
			if p.y > q.y {
				p.y, q.y = q.y, p.y
			}
			M[p.y*m+x] = '^'
			M[q.y*m+x] = 'v'
		}
	}

	var good []point
	dotCnt := 0

	for y := 0; y < n; y++ {
		for x := 0; x < m; x++ {
			if at(y, x) != '.' {
				continue
			}
			dotCnt++
			_, _, ok := nbAt(y, x)
			if ok {
				good = append(good, point{y, x})
			}
		}
	}

	for i := 0; i < len(good); i++ {
		p := good[i]
		y, x := p.y, p.x
		if at(y, x) != '.' {
			continue
		}
		ny, nx, ok := nbAt(y, x)
		if !ok {
			continue
		}

		q := point{ny, nx}
		paint(q, p)
		dotCnt -= 2
		if dotCnt == 0 {
			break
		}

		for _, d := range D {
			for _, p := range []point{p, q} {
				a, b, ok := nbAt(p.y+d.y, p.x+d.x)
				if ok {
					good = append(good, point{a, b})
				}
			}
		}
	}

	if dotCnt == 0 {
		show()
	} else {
		fail()
	}
}


You are given a sequence $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ non-zero integers (i.e. $$$a_i \ne 0$$$). You have to calculate two following values:  the number of pairs of indices $$$(l, r)$$$ $$$(l \le r)$$$ such that $$$a_l \cdot a_{l + 1} \dots a_{r - 1} \cdot a_r$$$ is negative;  the number of pairs of indices $$$(l, r)$$$ $$$(l \le r)$$$ such that $$$a_l \cdot a_{l + 1} \dots a_{r - 1} \cdot a_r$$$ is positive;

The first line contains one integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^{5})$$$ — the number of elements in the sequence. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(-10^{9} \le a_i \le 10^{9}; a_i \neq 0)$$$ — the elements of the sequence.

Print two integers — the number of subsegments with negative product and the number of subsegments with positive product, respectively.

package main

import (
    "bufio"
    "fmt"
    "os"
)
const(
    mod int = 1e9 + 7
    N = 1e6
)
func main() {
    in := bufio.NewReader(os.Stdin)
    var n, a int
    var ansn, ansp, last int64
    var cnt [2]int64
    fmt.Fscan(in, &n)
    b := 1
    for i := 1; i <= n; i++ {
        fmt.Fscan(in, &a)
        if a == 0 {
            cnt[0] = 0
            cnt[1] = 0
            continue
        }
        if a < 0 {
            cnt[b] += int64(i) - last
            last = int64(i)
            b ^= 1
        }
        ansn += cnt[b ^ 1]
        ansp += int64(i) - last + cnt[b]
    }
    fmt.Println(ansn, ansp)
}

package main

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

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

	var n, tmp int64
	var slice []int64

	fmt.Fscanf(in, "%d\n", &n)
	for i := int64(0); i < n; i++ {
		fmt.Fscanf(in, "%d", &tmp)
		slice = append(slice, tmp)
	}

	fmt.Println(solution(n, slice))
}

func solution(n int64, slice []int64) (numNeg, numPos int64) {
	var tmpNumPos, tmpNumNeg int64

	prod := int64(1)
	for i := int64(0); i < n; i++ {
		if prod*slice[i] > 0 {
			tmpNumPos++
			prod = 1
		} else {
			tmpNumNeg++
			prod = -1
		}
	}

	numPos = tmpNumPos
	numNeg = tmpNumNeg

	for i := int64(1); i < n; i++ {
		if slice[i-1] > 0 {
			tmpNumPos--
		} else {
			tmpPos := tmpNumPos
			tmpNumPos = tmpNumNeg - 1
			tmpNumNeg = tmpPos
		}
		numPos += tmpNumPos
		numNeg += tmpNumNeg
	}

	return
}

package main

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

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

	var n, tmp int
	var slice []int

	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &tmp)
		slice = append(slice, tmp)
	}

	fmt.Println(solution(n, slice))
}

func solution(n int, slice []int) (numNeg, numPos int) {
	for i := 0; i < n; i++ {
		prod := 1
		for j := i; j < n; j++ {
			prod *= slice[j]
			if prod > 0 {
				numPos++
			} else {
				numNeg++
			}
		}
	}
	return
}


Vasya is reading a e-book. The file of the book consists of $$$n$$$ pages, numbered from $$$1$$$ to $$$n$$$. The screen is currently displaying the contents of page $$$x$$$, and Vasya wants to read the page $$$y$$$. There are two buttons on the book which allow Vasya to scroll $$$d$$$ pages forwards or backwards (but he cannot scroll outside the book). For example, if the book consists of $$$10$$$ pages, and $$$d = 3$$$, then from the first page Vasya can scroll to the first or to the fourth page by pressing one of the buttons; from the second page — to the first or to the fifth; from the sixth page — to the third or to the ninth; from the eighth — to the fifth or to the tenth.Help Vasya to calculate the minimum number of times he needs to press a button to move to page $$$y$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of testcases. Each testcase is denoted by a line containing four integers $$$n$$$, $$$x$$$, $$$y$$$, $$$d$$$ ($$$1\le n, d \le 10^9$$$, $$$1 \le x, y \le n$$$) — the number of pages, the starting page, the desired page, and the number of pages scrolled by pressing one button, respectively.

Print one line for each test. If Vasya can move from page $$$x$$$ to page $$$y$$$, print the minimum number of times he needs to press a button to do it. Otherwise print $$$-1$$$.

NoteIn the first test case the optimal sequence is: $$$4 \rightarrow 2 \rightarrow 1 \rightarrow 3 \rightarrow 5$$$.In the second test case it is possible to get to pages $$$1$$$ and $$$5$$$.In the third test case the optimal sequence is: $$$4 \rightarrow 7 \rightarrow 10 \rightarrow 13 \rightarrow 16 \rightarrow 19$$$.

package main

import "fmt"

func move(x,y,d int64) (ans int64) {
    if (x < y) {
        tmp := y
        y = x
        x = tmp
    }
    ans = 1 << 55
    if ((x - y) % d == 0) {
        ans = (x - y) / d;
    }
    return
}
func min(a, b int64) int64 {
    if a < b {
        return a
    }
    return b
}
func main() {
    var t int
    fmt.Scan(&t)

    for k := 0; k < t; k++ {
		var n,x,y,d int64

		fmt.Scan(&n,&x,&y,&d)

		ans := move(x,y,d)
		p1 := move(1,y,d) + ((x - 1) / d)

		if ((x - 1) % d != 0) {
		    p1 = p1 + 1
		}

		p2 := move(n,y,d) + ((n - x) / d)

		if ((n - x) % d != 0) {
		    p2 = p2 + 1
		}

		ans = min(ans,min(p1,p2))

		if (ans >= (1 << 55)) {
		    ans = -1
		}

		fmt.Println(ans)

	}
}

package main

import (
	"fmt"
	"bufio"
	"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 abs(val int) int {
	if (val < 0) {
		return -val
	}
	return val
}

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

func main(){
	defer writer.Flush()
	var t,n,d,x,y, ans int
	scanf("%d\n", &t)
	for t > 0 {
		scanf("%d %d %d %d\n", &n, &x, &y, &d)
		if (abs(x-y) % d == 0) {
			printf("%d\n", abs(x-y) / d)
		} else {
			ans = -1
			if ((y-1) % d == 0) {
				ans = (y-1)/d + (x-1 + d-1)/d
			}
			if ((n-y) % d == 0) {
				if (ans == -1){
					ans = (n-y)/d + (n-x + d-1)/d
				} else {
					ans = min(ans, (n-y)/d + (n-x + d-1)/d)
				}
			}
			printf("%d\n", ans)
		}
		t--
	}
}

package main

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

func abs(a,b int64) int64 {
	if a>b{
		return a-b
	}
	return b-a
}
func main(){
	buf := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanf(buf, "%d\n", &t)
	for i := 1 ;i <= t;i++{
		var n ,d,x,y int64
		fmt.Fscanf(buf, "%d %d %d %d\n", &n,&x,&y,&d)
		var ans1,ans2 int64
		axy := abs(x,y)
		if axy % d == 0{
			fmt.Printf("%d\n",axy/d)
			continue
		}
		ans1= -1
		ans2 = -1
		if abs(1,y)%d == 0{
			ans1 = abs(1,y)/d
			if x != 1{
				ans1 += (x-2)/d+1
			}
		}
		if abs(n,y)%d == 0{
			ans2 = abs(n,y)/d
			if x !=n{
				ans2 += (n-x-1)/d+1
			}
		}
		if ans1 == -1{
			fmt.Printf("%d\n",ans2)
		}else if ans2==-1{
			fmt.Printf("%d\n",ans1)
		}else if ans1 <= ans2{
			fmt.Printf("%d\n",ans1)
		}else{
			fmt.Printf("%d\n",ans2)
		}

	}
}

package main

import (
    "fmt"
//    "os"
)

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

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

func ldist(x, d int64) int64 {
    if x == 1 {
        return 0
    }
    return (x - 2)/d + 1
}

func rdist(x, d, n int64) int64 {
    return ldist(n - x + 1, d)
}

func dist(n, x, y, d int64) int64 {
    s1 := (x - 1) % d
    s2 := (n - 1) % d
    yd := (y - 1) % d
    if yd == s1 {
        n := x/d
        m := y/d
        dist := n - m
        if dist < 0 {
            dist = -dist
        }
        return dist
    }
    if yd == s2 {
        if s2 == 0 {
            d1 := ldist(x, d) + ldist(y, d)
            d2 := rdist(x, d, n) + rdist(y, d, n)
            return min(d1, d2)
        } else {
            return rdist(x, d, n) + rdist(y, d, n)
        }
    }
    if yd == 0 {
        return ldist(x, d) + ldist(y, d)
    }
    return -1
}

func main() {
    var t int64
    /*r, err := os.Open("tt")
    if err != nil {
        return
    }*/
    fmt.Scanln(&t)
    for i := int64(0); i < t; i++ {
        var n, x, y, d int64
        fmt.Scanln(&n, &x, &y, &d)
        fmt.Println(dist(n, x, y, d))
    }
}

package main

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

func getInt (s *bufio.Scanner) int {
	s.Scan()
	r, _ :=strconv.Atoi(s.Text())
	return r
}

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	n := getInt(s)
	for i := 0; i < n ; i++  {
		n,x,y,d := getInt(s),getInt(s), getInt(s), getInt(s)
		c := -1
		if y==x {
			c=0
		} else {
			a := y-x
		    if a<0 {a*=-1}
		    if a%d==0 {
		    	c=a/d
			} else {
				e, f := -1, -1
				if (y-1)%d == 0 {
					e = (x-1)/d + 1 + (y-1)/d
				}
				if (n-y)%d == 0 {
					f = (n-x)/d + 1 + (n-y)/d
				}
				if e != -1 && f != -1 {
					if e > f {
						c = f
					} else {
						c = e
					}
				} else if e != -1 {
					c = e
				} else {
					c = f
				}
			}
		}
		fmt.Println(c)
	}
}

package main

import (
	"fmt"
)

func AbsInt(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

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

// gao
// stage-1: x, x-d, x+d, x-2d, x+2d, ...
// stage-2: 1, n
// stage-3: 1+d, n-d, 1+2d, n-2d, ...
func gao(n, x, y, d int) int {
	delta := AbsInt(x - y)
	if delta%d == 0 {
		return delta / d
	}
	stepsLeft, stepsRight := (x+d-1)/d, (n-x+d-1)/d
	if y == 1 {
		return stepsLeft
	}
	if y == n {
		return stepsRight
	}

	if (y-1)%d == 0 {
		if (n-y)%d == 0 {
			return MinInt(stepsLeft+(y-1)/d, stepsRight+(n-y)/d)
		}
		return stepsLeft + (y-1)/d
	} else if (n-y)%d == 0 {
		return stepsRight + (n-y)/d
	}
	return -1
}

func main() {
	var t, n, x, y, d int
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		_, _ = fmt.Scanln(&n, &x, &y, &d)
		fmt.Printf("%d\n", gao(n, x, y, d))
	}
}

package main

import (
	"fmt"
    "math"
)

func calcPressTime( diff int, distBy1Press int, startTimes int64 ) (ans int64, cant bool) {

    // fmt.Println(startTimes)

    if diff < 0 || distBy1Press < 1{
        return -1, true
    }

    if diff % distBy1Press == 0 {
        return (startTimes + int64(diff / distBy1Press)), false
    } else {
        return -1, true
    }
}

func main() {
	var (
		t,n,x,y,d int
        minAns int64 = 10e10
	)
    fmt.Scan(&t)
    // fmt.Printf("got:%d\n", t )

    for i := 0; i < t; i++ {

        minAns = 10e10

    	fmt.Scan(&n, &x, &y, &d)

        if x == y {
            fmt.Println(0)
        } else if y == 1 {
            fmt.Println(int(math.Ceil(float64(x-y)/float64(d))))
        } else if y == n {
            fmt.Println(int(math.Ceil(float64(y-x)/float64(d))))
        } else {

            // try up
            ans, cant := calcPressTime( y - x, d, 0 )
            if cant == false && ans < minAns{
                minAns = ans
            }

            // try down
            ans, cant = calcPressTime( x - y, d, 0 )
            if cant == false && ans < minAns{
                minAns = ans
            }

            // up and return
            ans, cant = calcPressTime( n - y, d, int64(math.Ceil(float64(n-x)/float64(d))) )
            if cant == false && ans < minAns{
                minAns = ans
            }

            // down and return
            ans, cant = calcPressTime( y - 1, d, int64(math.Ceil(float64(x-1)/float64(d))) )
            if cant == false && ans < minAns{
                minAns = ans
            }

            if minAns == 10e10 {
                minAns = -1
            }
            fmt.Println(minAns)
        }
    }
}

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 n, x, y, d, t, t1, t2, T int
	scanf("%d\n", &T)
	for t = 0; t < T; t++ {
		scanf("%d %d %d %d\n", &n, &x, &y, &d)

		if (y-x)%d == 0 {
			if x > y {
				x, y = y, x
			}
			printf("%d\n", (y-x)/d)
			continue
		}

		t1 = 1081111111
		if (y-1)%d == 0 {
			t1 = (x-1+d-1)/d + (y-1)/d
		}

		t2 = 1081111111
		if (n-y)%d == 0 {
			t2 = (n-x+d-1)/d + (n-y)/d
		}

		if t2 < t1 {
			t1 = t2
		}

		if t1 == 1081111111 {
			printf("%d\n", -1)
		} else {
			printf("%d\n", t1)
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var n,x,y,d,t int
	fmt.Scanf("%d\n",&t)
	for i := 0; i<t;i++{
		fmt.Scanf("%d %d %d %d\n",&n, &x, &y, &d)
		ans := -1
		if x == y {
			ans = 0
		}
		if y == 1 {
			ans = divUp(x-1,d)
		}
		if y == n {
			ans = divUp(n-x,d)
		}
		if checkDiv(abs(y-x), d){
			ans= abs(y-x)/d
		}
		if checkDiv(y-1,d) {
			temp := divUp(x-1,d) + (y-1)/d
			if ans > temp || ans == -1{
				ans = temp
			}
		}
		if checkDiv(n-y,d) {
			temp := divUp(n-x,d) + (n-y)/d
			if ans>temp || ans == -1 {
				ans = temp
			}
		}
		fmt.Println(ans)
	}
}

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

func divUp(a,b int) int {
	ans :=0
	if a%b != 0 {
		ans +=1
	}
	ans += a/b
	return ans
}

func checkDiv(a, b int) bool {
	if a<b {
		return false
	}
	if a<b {
		c:= a
		a = b
		b = c
	}
	return a%b  == 0
}

package main

import "fmt"

func move(x,y,d int64) (ans int64) {
    if (x < y) {
        tmp := y
        y = x
        x = tmp
    }
    ans = 1 << 55
    if ((x - y) % d == 0) {
        ans = (x - y) / d;
    }
    return
}
func min(a, b int64) int64 {
    if a < b {
        return a
    }
    return b
}
func main() {
    var t int
    fmt.Scan(&t)

    for k := 0; k < t; k++ {
		var n,x,y,d int64

		fmt.Scan(&n,&x,&y,&d)

		ans := move(x,y,d)
		p1 := move(1,y,d) + ((y - 1) / d)

		if ((y - 1) % d != 0) {
		    p1 = p1 + 1
		}

		p2 := move(n,y,d) + ((n - y) / d)

		if ((n - y) % d != 0) {
		    p2 = p2 + 1
		}

		ans = min(ans,min(p1,p2))

		if (ans >= (1 << 55)) {
		    ans = -1
		}

		fmt.Println(ans)

	}
}

package main

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

func abs(a,b int64) int64 {
	if a>b{
		return a-b
	}
	return b-a
}
func main(){

	buf := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanf(buf, "%d\n", &t)
	for i := 1 ;i <= t;i++{
		var n ,d,x,y int64
		fmt.Fscanf(buf, "%d %d %d %d\n", &n,&x,&y,&d)
		var ans1,ans2 int64
		axy := abs(x,y)
		if axy % d == 0{
			fmt.Printf("%d\n",axy/d)
			continue
		}
		ans1= -1
		ans2 = -1
		if abs(1,y)%d == 0{
			ans1 = abs(1,y)/d
			if x != 1{
				ans1 += (x-2)/d+1
			}
		}
		if abs(n,y)%d == 0{
			ans2 = abs(n,y)/d
			if x !=n{
				ans2 += (n-x-1)/d+1
			}
		}
		if ans1 == -1{
			fmt.Printf("%d\n",ans2)
		}else if ans2==-1{
			fmt.Printf("%d\n",ans1)
		}else if ans1 <= ans2{
			fmt.Printf("%d\n",ans1)
		}else{
			fmt.Printf("%d\n",ans1)
		}

	}
}

package main

import (
    "fmt"
)

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

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

func ldist(x, d int64) int64 {
    if x % d == 0 {
        return x/d
    } else {
        return x/d + 1
    }
}

func rdist(x, d, n int64) int64 {
    return ldist(n - x + 1, d)
}

func dist(n, x, y, d int64) int64 {
    s1 := x % d
    s2 := n % d
    if y % d == s1 {
        n := x/d
        m := y/d
        dist := n - m
        if dist < 0 {
            dist = -dist
        }
        return dist
    }
    if y % d == s2 {
        if s2 == 0 {
            d1 := ldist(x, d) + ldist(y, d)
            d2 := rdist(x, d, n) + rdist(y, d, n)
            return min(d1, d2)
        } else {
            return rdist(x, d, n) + rdist(y, d, n)
        }
    }
    if y % d == 0 {
        return ldist(x, d) + ldist(y, d)
    }
    return -1
}

func main() {
    var t int64
    fmt.Scanln(&t)
    for i := int64(0); i < t; i++ {
        var n, x, y, d int64
        fmt.Scanln(&n, &x, &y, &d)
        fmt.Println(dist(n, x - 1, y - 1, d))
    }
}

package main

import (
	"fmt"
)

func AbsInt(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

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

// gao
// stage-1: x, x-d, x+d, x-2d, x+2d, ...
// stage-2: 1, n
// stage-3: 1+d, n-d, 1+2d, n-2d, ...
func gao(n, x, y, d int) int {
	delta := AbsInt(x - y)
	if delta%d == 0 {
		return delta / d
	}
	stepsLeft, stepsRight := (x+d-1)/d, (n-x+d-1)/d
	if y == 1 {
		return stepsLeft
	}
	if y == n {
		return stepsRight
	}

	if (y-1)%d == 0 {
		if (n-y)%d == 0 {
			return MinInt(stepsLeft+(y-1)/d, stepsRight+(n-y)/d)
		}
		return stepsLeft + (y-1)/d
	} else if (n-y)%d == 0 {
		return stepsRight + (n-y)%d
	}
	return -1
}

func main() {
	var t, n, x, y, d int
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		_, _ = fmt.Scanln(&n, &x, &y, &d)
		fmt.Printf("%d\n", gao(n, x, y, d))
	}
}

package main

import (
	"fmt"
    "math"
)

func calcPressTime( diff int, distBy1Press int, startTimes int64 ) (ans int64, cant bool) {

    // fmt.Println(startTimes)

    if diff < 0 || distBy1Press < 1{
        return -1, true
    }

    if diff % distBy1Press == 0 {
        return (startTimes + int64(diff / distBy1Press)), false
    } else {
        return -1, true
    }
}

func main() {
	var (
		n,x,y,d int
        minAns int64 = 10e10
	)
	fmt.Scan(&n, &x, &y, &d)

    if x == y {
        fmt.Println(0)
        return
    }

    // try up
    ans, cant := calcPressTime( y - x, d, 0 )
    if cant == false && ans < minAns{
        minAns = ans
    }

    // try down
    ans, cant = calcPressTime( x - y, d, 0 )
    if cant == false && ans < minAns{
        minAns = ans
    }

    // up and return
    ans, cant = calcPressTime( n - y, d, int64(math.Ceil(float64(n-x)/float64(d))) )
    if cant == false && ans < minAns{
        minAns = ans
    }

    // down and return
    ans, cant = calcPressTime( y - 1, d, int64(math.Ceil(float64(x-1)/float64(d))) )
    if cant == false && ans < minAns{
        minAns = ans
    }

    if minAns == 10e10 {
        minAns = -1
    }

	fmt.Println(minAns)
}

package main

import (
	"fmt"
    "math"
)

func calcPressTime( diff int, distBy1Press int, startTimes int64 ) (ans int64, cant bool) {

    // fmt.Println(startTimes)

    if diff < 0 || distBy1Press < 1{
        return -1, true
    }

    if diff % distBy1Press == 0 {
        return (startTimes + int64(diff / distBy1Press)), false
    } else {
        return -1, true
    }
}

func main() {
	var (
		n,x,y,d int
        minAns int64 = 10e10
	)
	fmt.Scan(&n, &x, &y, &d)

    // try up
    ans, cant := calcPressTime( y - x, d, 0 )
    if cant == false && ans < minAns{
        minAns = ans
    }

    // try down
    ans, cant = calcPressTime( x - y, d, 0 )
    if cant == false && ans < minAns{
        minAns = ans
    }

    // up and return
    ans, cant = calcPressTime( n - y, d, int64(math.Ceil(float64(n-x)/float64(d))) )
    if cant == false && ans < minAns{
        minAns = ans
    }

    // down and return
    ans, cant = calcPressTime( y - 1, d, int64(math.Ceil(float64(x-1)/float64(d))) )
    if cant == false && ans < minAns{
        minAns = ans
    }

    if minAns == 10e10 {
        minAns = -1
    }

	fmt.Println(minAns)
}

package main

import (
	"fmt"
    "math"
)

func calcPressTime( diff int, distBy1Press int, startTimes int64 ) (ans int64, cant bool) {

    // fmt.Println(startTimes)

    if diff < 0 || distBy1Press < 1{
        return -1, true
    }

    if diff % distBy1Press == 0 {
        return (startTimes + int64(diff / distBy1Press)), false
    } else {
        return -1, true
    }
}

func main() {
	var (
		t,n,x,y,d int
        minAns int64 = 10e10
	)
    fmt.Scan(&t)
    // fmt.Printf("got:%d\n", t )

    for i := 0; i < t; i++ {

        minAns = 10e10

    	fmt.Scan(&n, &x, &y, &d)

        if x == y {
            fmt.Println(0)
        } else if y == 1 {
            fmt.Println(int(math.Ceil(float64(n-x)/float64(d))))
        } else if y == n {
            fmt.Println(int(math.Ceil(float64(n-x)/float64(d))))
        } else {

            // try up
            ans, cant := calcPressTime( y - x, d, 0 )
            if cant == false && ans < minAns{
                minAns = ans
            }

            // try down
            ans, cant = calcPressTime( x - y, d, 0 )
            if cant == false && ans < minAns{
                minAns = ans
            }

            // up and return
            ans, cant = calcPressTime( n - y, d, int64(math.Ceil(float64(n-x)/float64(d))) )
            if cant == false && ans < minAns{
                minAns = ans
            }

            // down and return
            ans, cant = calcPressTime( y - 1, d, int64(math.Ceil(float64(x-1)/float64(d))) )
            if cant == false && ans < minAns{
                minAns = ans
            }

            if minAns == 10e10 {
                minAns = -1
            }
            fmt.Println(minAns)
        }
    }
}

package main

import (
	"fmt"
    "math"
)

func calcPressTime( diff int, distBy1Press int, startTimes int64 ) (ans int64, cant bool) {

    // fmt.Println(startTimes)

    if diff < 0 || distBy1Press < 1{
        return -1, true
    }

    if diff % distBy1Press == 0 {
        return (startTimes + int64(diff / distBy1Press)), false
    } else {
        return -1, true
    }
}

func main() {
	var (
		n,x,y,d int
        minAns int64 = 10e10
	)
	fmt.Scan(&n, &x, &y, &d)

    if x == y {
        fmt.Println(0)
        return
    } else if y == 1 {
        fmt.Println(int(math.Ceil(float64(x-1)/float64(d))))
        return
    } else if y == n {
        fmt.Println(int(math.Ceil(float64(n-x)/float64(d))))
        return
    }

    // try up
    ans, cant := calcPressTime( y - x, d, 0 )
    if cant == false && ans < minAns{
        minAns = ans
    }

    // try down
    ans, cant = calcPressTime( x - y, d, 0 )
    if cant == false && ans < minAns{
        minAns = ans
    }

    // up and return
    ans, cant = calcPressTime( n - y, d, int64(math.Ceil(float64(n-x)/float64(d))) )
    if cant == false && ans < minAns{
        minAns = ans
    }

    // down and return
    ans, cant = calcPressTime( y - 1, d, int64(math.Ceil(float64(x-1)/float64(d))) )
    if cant == false && ans < minAns{
        minAns = ans
    }

    if minAns == 10e10 {
        minAns = -1
    }

	fmt.Println(minAns)
}

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 n, x, y, d, t, t1, t2, T int
	scanf("%d\n", &T)
	for t = 0; t < T; t++ {
		scanf("%d %d %d %d\n", &n, &x, &y, &d)
		// if x > y {
		// 	x, y = y, x
		// }
		if (y-x)%d == 0 {
			printf("%d\n", (y-x)/d)
			continue
		}

		t1 = 1081111111
		if (y-1)%d == 0 {
			t1 = (x-1+d-1)/d + (y-1)/d
		}

		t2 = 1081111111
		if (n-y)%d == 0 {
			t2 = (n-x+d-1)/d + (n-y)/d
		}

		if t2 < t1 {
			t1 = t2
		}

		if t1 == 1081111111 {
			printf("%d\n", -1)
		} else {
			printf("%d\n", t1)
		}

	}
}

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 n, x, y, d, t, t1, t2, T int
	scanf("%d\n", &T)
	for t = 0; t < T; t++ {
		scanf("%d %d %d %d\n", &n, &x, &y, &d)
		if x > y {
			x, y = y, x
		}
		if (y-x)%d == 0 {
			printf("%d\n", (y-x)/d)
			continue
		}

		t1 = 1081111111
		if (y-1)%d == 0 {
			t1 = (x-1+d-1)/d + (y-1)/d
		}

		t2 = 1081111111
		if (n-y)%d == 0 {
			t2 = (n-y+d-1)/d + (n-y)/d
		}

		if t2 < t1 {
			t1 = t2
		}

		if t1 == 1081111111 {
			printf("%d\n", -1)
		} else {
			printf("%d\n", t1)
		}

	}
}

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 n, x, y, d, t, t1, t2, T int
	scanf("%d\n", &T)
	for t = 0; t < T; t++ {
		scanf("%d %d %d %d\n", &n, &x, &y, &d)
		if x > y {
			x, y = y, x
		}
		if (y-x)%d == 0 {
			printf("%d\n", (y-x)/d)
			continue
		}

		t1 = 1081111111
		if (y-1)%d == 0 {
			t1 = (x-1+d-1)/d + (y-1)/d
		}

		t2 = 1081111111
		if (n-y)%d == 0 {
			t2 = (n-x+d-1)/d + (n-y)/d
		}

		if t2 < t1 {
			t1 = t2
		}

		if t1 == 1081111111 {
			printf("%d\n", -1)
		} else {
			printf("%d\n", t1)
		}

	}
}

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 n, x, y, d, t, t1, t2, T int
	scanf("%d\n", &T)
	for t = 0; t < T; t++ {
		scanf("%d %d %d %d\n", &n, &x, &y, &d)
		if x > y {
			x, y = y, x
		}
		if (y-x)%d == 0 {
			printf("%d\n", (y-x)/d)
			continue
		}

		t1 = 1081111111
		if (y-1)%d == 0 {
			t1 = (x-1+d-1)/d + (y-1)/d
		}

		t2 = 1081111111
		if (n-y)%d == 0 {
			t1 = (n-y+d-1)/d + (n-y)/d
		}

		if t2 < t1 {
			t1 = t2
		}

		if t1 == 1081111111 {
			printf("%d\n", -1)
		} else {
			printf("%d\n", t1)
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var n,x,y,d,t int
	fmt.Scanf("%d\n",&t)
	for i := 0; i<t;i++{
		fmt.Scanf("%d %d %d %d\n",&n, &x, &y, &d)
		ans := -1
		if x == y {
			ans = 0
		}
		if checkDiv(y-x, d){
			ans= (y-x)/d
		}
		if checkDiv(y-1,d) {
			temp := divUp(x-1,d) + (y-1)/d
			if ans > temp || ans == -1{
				ans = temp
			}
		}
		if checkDiv(n-y,d) {
			temp := divUp(n-x,d) + (n-y)/d
			if ans>temp || ans == -1 {
				ans = temp
			}
		}
		fmt.Println(ans)
	}
}

func divUp(a,b int) int {
	ans :=0
	if a%b != 0 {
		ans +=1
	}
	ans += a/b
	return ans
}

func checkDiv(a, b int) bool {
	if a<b {
		return false
	}
	if a<b {
		c:= a
		a = b
		b = c
	}
	return a%b  == 0
}


"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.With that begins the watch of Jon Snow. He is assigned the task to support the stewards.This time he has n stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.Can you find how many stewards will Jon support?

First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow. Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards.

Output a single integer representing the number of stewards which Jon will feed.

NoteIn the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.

package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	array := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		array[i] = a
	}

	merge_sort(array, 0, n-1)

	start := 0
	end := n - 1
	for ; start < n; start++ {
		if array[start] > array[0] {
			break
		}
	}
	for ; end >= 0; end-- {
		if array[end] < array[n-1] {
			break
		}
	}
	if start <= end {
		fmt.Println(end - start + 1)
	} else {
		fmt.Println(0)
	}
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] <= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

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

func solve() {
	a := readIntArray(readInt())
	sort.Ints(a)
	mm := map[int]bool{}
	for _, v := range a {
		mm[v] = true
	}
	prefix := make([]int, len(a))
	suffix := make([]int, len(a))
	for i := len(a) - 2; i >= 0; i-- {
		prefix[i] = prefix[i+1]
		if a[i] < a[i+1] {
			prefix[i]++
		}
	}
	for i := 1; i < len(a); i++ {
		suffix[i] = suffix[i-1]
		if a[i] > a[i-1] {
			suffix[i]++
		}
	}
	res := 0
	for i, _ := range a {
		if suffix[i] > 0 && prefix[i] > 0 {
			res++
		}
	}
	fmt.Println(res)
}

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 min(a int, b int) int {
	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"
	"io"
	"bufio"
	"os"
	"sort"
)

func solve(a []int) int {
	sort.Ints(a)
	i, j := 0, len(a) - 1
	for i+1 < len(a) && a[i] == a[i+1] {
		i += 1
	}
	for j > 1 && a[j-1] == a[j] {
		j -= 1
	}
	r := j - i - 1
	if r < 0 {
		return 0
	}
	return r
}

func main() {
	cin := NewParser(bufio.NewReaderSize(os.Stdin, 1<<16))
	n := cin.nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = cin.nextInt()
	}
	fmt.Printf("%d", solve(a))
}

// some io

type ParserReader struct {
	r   io.ByteReader
	err error
	c   byte
}

func NewParser(r io.ByteReader) *ParserReader {
	return &ParserReader{r, nil, 0}
}

func (p *ParserReader) next() error {
	p.c, p.err = p.r.ReadByte()
	return p.err
}

func isDigit(c byte) bool {
	return '0' <= c && c <= '9'
}

func (p *ParserReader) nextUInt64() uint64 {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint64
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint64(p.c - '0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextUInt() uint {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint(p.c - '0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextInt64() int64 {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int64(p.nextUInt64())
	if sign {
		return -r
	}
	return r
}

func (p *ParserReader) nextInt() int {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int(p.nextUInt())
	if sign {
		return -r
	}
	return r
}

package main

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

func main() {
    var n int
    fmt.Scan(&n)
    steward := make([]int, n)
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    for i:=0; scanner.Scan(); i++{
        steward[i], _ = strconv.Atoi(scanner.Text())
    }
    sort.Ints(steward)
    cnt := 0
    for i:=1; i+1<n; i++ {
        if steward[i] > steward[0] && steward[i] < steward[n-1] {
            cnt++
        }
    }
    fmt.Print(cnt)
}

package main

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

func main() {
	var n, max, min, currNumber, result int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n)
	intArr := make([]int, n)
	min = -1
	for index := 0; index < n; index++ {
		fmt.Fscan(reader, &currNumber)
		if min > currNumber || min == -1 {
			min = currNumber
		} else if max < currNumber {
			max = currNumber
		}
		intArr[index] = currNumber
	}
	for _, element := range intArr {
		if element > min && element < max {
			result++
		}
	}
	fmt.Println(result)
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()

	mn := A[0]
	mx := A[0]
	mxCount := 1
	mnCount := 1
	for i := 1; i < N; i++ {
		if mn == A[i] {
			mnCount++
		} else if mn > A[i] {
			mn = A[i]
			mnCount = 1
		}
		if mx == A[i] {
			mxCount++
		} else if mx < A[i] {
			mx = A[i]
			mxCount = 1
		}
	}

	if mn == mx {
		fmt.Println(0)
		return
	}

	fmt.Println(N - mxCount - mnCount)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) 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"
	"sort"
	"strconv"
)

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	A := make([]int, 0)
	for i := 0; i < N; i++ {
		A = append(A, fsc.NextInt())
	}
	sort.Ints(A)
	pre := A[0]
	last := A[N-1]
	res := 0
	for i := 1; i < N-1; i++ {
		if pre < A[i] && A[i] < last {
			res++
		}
	}
	fmt.Println(res)
}

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

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}

package main

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

func solve() {
	a := readIntArray(readInt())
	sort.Ints(a)
	mm := map[int]bool{}
	for _, v := range a {
		mm[v] = true
	}
	prefix := make([]int, len(a))
	for i := len(a) - 2; i >= 0; i-- {
		prefix[i] = prefix[i+1]
		if a[i] < a[i+1] {
			prefix[i]++
		}
	}
	res := 0
	for i, v := range a {
		if _, exists := mm[v-1]; exists && prefix[i] > 0 {
			res++
		}
	}
	fmt.Println(res)
}

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 min(a int, b int) int {
	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"
import "sort"
import "bufio"
import "os"
import "strconv"

func main() {
    var n int
    fmt.Scan(&n)
    steward := make([]int, n)
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    for i:=0; scanner.Scan();  {
        steward[i], _ = strconv.Atoi(scanner.Text())
    }
    sort.Ints(steward)
    cnt := 0
    for i:=1; i+1<n; i++ {
        if steward[i] > steward[0] && steward[i] < steward[n-1] {
            cnt++
        }
    }
    fmt.Print(cnt)
}

package main

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

func main() {
	var n, max, min, currNumber, result int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n)
	intArr := make([]int, n)
	min = 1
	for index := 0; index < n; index++ {
		fmt.Fscan(reader, &currNumber)
		if min > currNumber {
			min = currNumber
		} else if max < currNumber {
			max = currNumber
		}
		intArr[index] = currNumber
	}
	for _, element := range intArr {
		if element > min && element < max {
			result++
		}
	}
	fmt.Println(result)
}


Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to wealthy parents that he was able to obtain the graduation certificate.The situation is complicated by the fact that each high education institution has the determined amount of voluntary donations, paid by the new students for admission — ni berubleys. He cannot pay more than ni, because then the difference between the paid amount and ni can be regarded as a bribe!Each rector is wearing the distinctive uniform of his university. Therefore, the uniform's pockets cannot contain coins of denomination more than ri. The rector also does not carry coins of denomination less than li in his pocket — because if everyone pays him with so small coins, they gather a lot of weight and the pocket tears. Therefore, a donation can be paid only by coins of denomination x berubleys, where li ≤ x ≤ ri (Berland uses coins of any positive integer denomination). Alexey can use the coins of different denominations and he can use the coins of the same denomination any number of times. When Alexey was first confronted with such orders, he was puzzled because it turned out that not all universities can accept him! Alexey is very afraid of going into the army (even though he had long wanted to get the green uniform, but his dad says that the army bullies will beat his son and he cannot pay to ensure the boy's safety). So, Alexey wants to know for sure which universities he can enter so that he could quickly choose his alma mater.Thanks to the parents, Alexey is not limited in money and we can assume that he has an unlimited number of coins of each type.In other words, you are given t requests, each of them contains numbers ni, li, ri. For each query you need to answer, whether it is possible to gather the sum of exactly ni berubleys using only coins with an integer denomination from li to ri berubleys. You can use coins of different denominations. Coins of each denomination can be used any number of times.

The first line contains the number of universities t, (1 ≤ t ≤ 1000) Each of the next t lines contain three space-separated integers: ni, li, ri (1 ≤ ni, li, ri ≤ 109; li ≤ ri).

For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.

NoteYou can pay the donation to the first university with two coins: one of denomination 2 and one of denomination 3 berubleys. The donation to the second university cannot be paid.

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n, l, r uint64
		fmt.Fscanf(reader, "%d %d %d\n", &n, &l, &r)
		if uint64(n/l)*r < n {
			fmt.Printf("No\n")
		} else {
			fmt.Printf("Yes\n")
		}
	}
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n, l, r int
		fmt.Fscanf(reader, "%d %d %d\n", &n, &l, &r)
		if int(n/l)*r < n {
			fmt.Printf("No\n")
		} else {
			fmt.Printf("Yes\n")
		}
	}
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var t int
	fmt.Fscanf(reader, "%d\r\n", &t)
	for i := 0; i < t; i++ {
		var n, l, r int
		fmt.Fscanf(reader, "%d %d %d\r\n", &n, &l, &r)
		if n/l*r < n {
			fmt.Printf("No\n")
		} else {
			fmt.Printf("Yes\n")
		}
	}
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n, l, r int
		fmt.Fscanf(reader, "%d %d %d\n", &n, &l, &r)
		if n/l*r < n {
			fmt.Printf("No\n")
		} else {
			fmt.Printf("Yes\n")
		}
	}
}


You are given three integers $$$a$$$, $$$b$$$ and $$$c$$$.Find two positive integers $$$x$$$ and $$$y$$$ ($$$x > 0$$$, $$$y > 0$$$) such that:   the decimal representation of $$$x$$$ without leading zeroes consists of $$$a$$$ digits;  the decimal representation of $$$y$$$ without leading zeroes consists of $$$b$$$ digits;  the decimal representation of $$$gcd(x, y)$$$ without leading zeroes consists of $$$c$$$ digits. $$$gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.Output $$$x$$$ and $$$y$$$. If there are multiple answers, output any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 285$$$) — the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b \le 9$$$, $$$1 \le c \le min(a, b)$$$) — the required lengths of the numbers. It can be shown that the answer exists for all testcases under the given constraints. Additional constraint on the input: all testcases are different.

For each testcase print two positive integers — $$$x$$$ and $$$y$$$ ($$$x > 0$$$, $$$y > 0$$$) such that    the decimal representation of $$$x$$$ without leading zeroes consists of $$$a$$$ digits;  the decimal representation of $$$y$$$ without leading zeroes consists of $$$b$$$ digits;  the decimal representation of $$$gcd(x, y)$$$ without leading zeroes consists of $$$c$$$ digits.

package main

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

func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()
	check := func(x int) bool {
		for i := 2; i*i <= x; i++ {
			if x%i == 0 {
				return false
			}
		}
		return true
	}
	a := make([]int, 10)
	for i := 0; i < 10; i++ {

		for j := int(math.Pow10(i)); ; j++ {
			if check(j) {
				a[i] = j
				//fmt.Fprintln(out, a[i])
				break
			}
		}
	}

	solve := func() {
		var x, y, z int
		fmt.Fscan(in, &x, &y, &z)
		o := int(math.Pow10(z - 1))
		if x == y {
			fmt.Fprint(out, a[x-z]*o, " ", (a[y-z]+1)*o)
		} else {
			fmt.Fprint(out, a[x-z]*o, " ", a[y-z]*o)
		}

		fmt.Fprintln(out)
	}

	T := 1
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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 a, b, c int
		Fscan(in, &a, &b, &c)
		swap := false
		if a > b {
			swap=true
			a, b = b, a
		}
		if b == 1 {
			Fprintln(out, 1, 1)
			return
		}
		x := "1" + strings.Repeat("0", a-1)
		y := strings.Repeat("1", b-c+1) + strings.Repeat("0", c-1)
		if swap {
			Fprintln(out, y,x)
			return
		}
		Fprintln(out, x, y)
	}

	var T int
	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) }

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math"

	//"math"
	"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 a, b, c int
		Fscan(in, &a, &b, &c)

		numA := int(math.Pow10(a - c))
		numB := int(math.Pow10(b - c)) + 1
		numC := int(math.Pow10(c - 1))

		Fprintln(out, numA * numC, numB * numC)
	}
}

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

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

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

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

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) Next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) NextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt()
	}
	return res
}
func (s *Scanner) NextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt64()
	}
	return res
}
func Min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func Max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func digitLen(x int64) int {
	return int(math.Floor(math.Log10(float64(x)))) + 1
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.NextInt()
	for tc := 0; tc < TC; tc++ {
		a := sc.NextInt()
		b := sc.NextInt()
		c := sc.NextInt()

		x := int64(1)
		y := int64(1)
		for digitLen(x) < c {
			x *= 2
			y *= 2
		}
		for digitLen(x) < a {
			x *= 3
		}
		for digitLen(y) < b {
			y *= 5
		}
		fmt.Fprintln(wr, x, y)
	}
}

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

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

}

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

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

	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Fscan(input, &a)
		fmt.Fscan(input, &b)
		fmt.Fscan(input, &c)
		var q, p, A, B int64
		q = 1
		p = 1
		A = 1
		B = 1

		for i := 0; i < c-1; i++ {
			p = 10 * p
		}
		for i := 0; i < a-1; i++ {
			A = 10 * A
		}
		for i := 0; i < b-1; i++ {
			B = 10 * B
		}

		for i := 1; i > 0; i++ {
			if q > p && q < 10*p {
				break
			} else {
				q = q * 7
			}
		}

		var t int64
		t = q

		for i := 1; i > 0; i++ {
			if q > A && q < A*10 {
				break
			} else {
				q = q * 2
			}
		}

		for i := 1; i > 0; i++ {
			if t > B && t < B*10 {
				break
			} else {
				t = t * 3
			}
		}

		fmt.Println(q)
		fmt.Println(t)

	}

}

package main

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

func gcd(x, y int) int {
	return gcd(x, x%y)
}

func foo(base, power, lower_bound int) int {
	for ; base < lower_bound; base = base * power {

	}
	return base
}

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

	var lb [10]int
	prime := [10]int{0, 5, 25, 125, 3125, 15625, 390625, 1953125, 48828125, 244140625}
	for i := 0; i <= 9; i++ {
		lb[i] = int(math.Pow10(i - 1))
		// ub[i] = int(math.Pow10(i) - 1)
	}

	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for case_idx := 0; case_idx < t; case_idx++ {
		var x, y, z, a, b int
		fmt.Fscanf(in, "%d %d %d\n", &x, &y, &z)
		a = foo(prime[z], 2, lb[x])
		b = foo(prime[z], 3, lb[y])
		fmt.Fprintf(out, "%d %d\n", a, b)
	}
	out.Flush()

}

package main

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

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

func main() {
	defer out.Flush()

	var t int
	Fscan(in, &t)

	for cases := 0; cases < t; cases++ {
		var a, b, c, answerA, answerB, getC int
		Fscan(in, &a, &b, &c)

		answerA = 1
		answerB = 1
		for i := 0; i < a-1; i++ {
			answerA *= 10
		}
		for i := 0; i < b-1; i++ {
			answerB *= 10
		}

		if !(a == b && b == c) {
			getC = 1
			for i := 0; i < c-1; i++ {
				getC *= 10
			}

			if answerA > answerB {
				answerA += getC
			} else {
				answerB += getC
			}
		}

		Fprintln(out, answerA, answerB)
	}
}

package main

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

func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()
	check := func(x int) bool {
		for i := 2; i*i <= x; i++ {
			if x%i == 0 {
				return false
			}
		}
		return true
	}
	a := make([]int, 10)
	for i := 0; i < 10; i++ {
		for j := int(math.Pow10(i)); ; j++ {
			if check(j) {
				a[i] = j
				//fmt.Fprintln(out, a[i])
				break
			}
		}
	}

	solve := func() {
		var x, y, z int
		fmt.Fscan(in, &x, &y, &z)
		o := int(math.Pow10(z - 1))
		fmt.Fprint(out, a[x-z]*o, " ", a[y-z]*o, )
		fmt.Fprintln(out)
	}

	T := 1
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()
	check := func(x int) bool {
		for i := 2; i*i <= x; i++ {
			if x%i == 0 {
				return false
			}
		}
		return true
	}
	a := make([]int, 10)
	for i := 0; i < 10; i++ {
		for j := int(math.Pow10(i)); ; j++ {
			if check(j) {
				a[i] = j
				//fmt.Fprintln(out, a[i])
				break
			}
		}
	}

	solve := func() {
		var x, y, z int
		fmt.Fscan(in, &x, &y, &z)
		o := int(math.Pow10(z - 1))
		fmt.Fprint(out, a[x-z]*o, " ", a[y-z]*o, " ", o)
		fmt.Fprintln(out)
	}

	T := 1
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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 a, b, c int
		Fscan(in, &a, &b, &c)
		if a > b {
			a, b = b, a
		}
		if b == 1 {
			Fprintln(out, 1, 1)
			return
		}
		x := "1" + strings.Repeat("0", a-1)
		y := strings.Repeat("1", b-c+1) + strings.Repeat("0", c-1)
		Fprintln(out, x, y)
	}

	var T int
	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) }


Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.Formally, map is a checkered field of size 1 × n, the cells of which are numbered from 1 to n, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged.If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell n can only move to the cell n - 1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves.Help Slava to destroy all tanks using as few bombs as possible.

The first line contains a single integer n (2 ≤ n ≤ 100 000) — the size of the map.

In the first line print m — the minimum number of bombs Slava needs to destroy all tanks. In the second line print m integers k1, k2, ..., km. The number ki means that the i-th bomb should be dropped at the cell ki. If there are multiple answers, you can print any of them.

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	ans := make([]int, 0, n*2)
	for i := 2; i <= n; i += 2 {
		ans = append(ans, i)
	}
	for i := 1; i <= n; i += 2 {
		ans = append(ans, i)
	}
	for i := 2; i <= n; i += 2 {
		ans = append(ans, i)
	}
	writer := bufio.NewWriter(os.Stdout)
	writer.WriteString(strconv.Itoa(len(ans)))
	writer.WriteString("\n")
	for i, x := range ans {
		if i > 0 {
			writer.WriteString(" ")
		}
		writer.WriteString(strconv.Itoa(x))
	}
	writer.WriteString("\n")
	writer.Flush()
}

package main

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

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

func main() {
    //io
    scanner := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    //---
    var n int
    fmt.Fscan(scanner, &n)
    writer.WriteString(strconv.Itoa(n / 2 * 2 + n - (n / 2)) + "\n")
    for i := 2; i <= n; i += 2 {
        writer.WriteString(strconv.Itoa(i) + " ")
    }

    for i := 1; i <= n; i += 2 {
        writer.WriteString(strconv.Itoa(i) + " ")
    }

    for i := 2; i <= n; i += 2 {
        writer.WriteString(strconv.Itoa(i) + " ")
    }
    writer.Flush()
}


Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value ai. The root of the tree is node 1.This tree has a special property: when a value val is added to a value of node i, the value -val is added to values of all the children of node i. Note that when you add value -val to a child of node i, you also add -(-val) to all children of the child of node i and so on. Look an example explanation to understand better how it works.This tree supports two types of queries:  "1 x val" — val is added to the value of node x;  "2 x" — print the current value of node x. In order to help Iahub understand the tree better, you must answer m queries of the preceding type.

The first line contains two integers n and m (1 ≤ n, m ≤ 200000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000). Each of the next n–1 lines contains two integers vi and ui (1 ≤ vi, ui ≤ n), meaning that there is an edge between nodes vi and ui. Each of the next m lines contains a query in the format described above. It is guaranteed that the following constraints hold for all queries: 1 ≤ x ≤ n, 1 ≤ val ≤ 1000.

For each query of type two (print the value of node x) you must print the answer to the query on a separate line. The queries must be answered in the order given in the input.

NoteThe values of the nodes are [1, 2, 1, 1, 2] at the beginning.Then value 3 is added to node 2. It propagates and value -3 is added to it's sons, node 4 and node 5. Then it cannot propagate any more. So the values of the nodes are [1, 5, 1,  - 2,  - 1].Then value 2 is added to node 1. It propagates and value -2 is added to it's sons, node 2 and node 3. From node 2 it propagates again, adding value 2 to it's sons, node 4 and node 5. Node 3 has no sons, so it cannot propagate from there. The values of the nodes are [3, 3,  - 1, 0, 1].You can see all the definitions about the tree at the following link: http://en.wikipedia.org/wiki/Tree_(graph_theory)

package main

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

type SegTree struct {
	val []int
	n   int
}

func NewSegTree(n int) *SegTree {
	size := calcTreeSize(n)
	return &SegTree{
		val: make([]int, size),
		n:   n,
	}
}

func (s *SegTree) Add(l int, r int, val int) {
	s.add(1, 0, s.n-1, l, r, val)
}

func (s *SegTree) Sum(i int) int {
	return s.sum(1, 0, s.n-1, i)
}

func (s *SegTree) add(i int, l int, r int, ql int, qr int, qv int) {
	if l >= ql && r <= qr {
		s.val[i] += qv
		return
	}
	m := (l + r) / 2
	if qr <= m {
		s.add(i*2, l, m, ql, qr, qv)
	} else if ql > m {
		s.add(i*2+1, m+1, r, ql, qr, qv)
	} else {
		s.add(i*2, l, m, ql, m, qv)
		s.add(i*2+1, m+1, r, m+1, qr, qv)
	}
}

func (s *SegTree) sum(i int, l int, r int, qi int) int {
	if l == qi && r == qi {
		return s.val[i]
	}
	m := (l + r) / 2
	if qi <= m {
		return s.sum(i*2, l, m, qi) + s.val[i]
	} else {
		return s.sum(i*2+1, m+1, r, qi) + s.val[i]
	}
}

func calcTreeSize(length int) int {
	size := 1
	for size < length {
		size *= 2
	}
	return size * 2
}

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

var (
	n, m   int
	weight []int
	index  []int
	last   []int
	color  []int
	stamp  int
	edge   [][]int
)

func dfs(u int, f int, c int) {
	color[u] = c
	index[u] = stamp
	last[u] = stamp
	stamp++

	for _, v := range edge[u] {
		if v != f {
			dfs(v, u, 1-c)
			last[u] = last[v]
		}
	}
}

func main() {
	fmt.Fscan(reader, &n, &m)

	var tree [2]*SegTree
	tree[0] = NewSegTree(n)
	tree[1] = NewSegTree(n)

	weight = make([]int, n)
	index = make([]int, n)
	last = make([]int, n)
	color = make([]int, n)
	edge = make([][]int, n)

	for i := range weight {
		fmt.Fscan(reader, &weight[i])
	}

	for i := 0; i < n-1; i++ {
		var u, v int
		fmt.Fscan(reader, &u, &v)
		u--
		v--
		edge[u] = append(edge[u], v)
		edge[v] = append(edge[v], u)
	}
	dfs(0, -1, 0)

	for i := 0; i < m; i++ {
		var x, y, z int
		fmt.Fscan(reader, &x, &y)
		y--
		if x == 1 {
			fmt.Fscan(reader, &z)
			tree[color[y]].Add(index[y], last[y], z)
			tree[1-color[y]].Add(index[y], last[y], -z)
		} else {
			w := tree[color[y]].Sum(index[y]) + weight[y]
			fmt.Println(w)
		}
	}
}

package main

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

const MAXCNT = 200001

var value [MAXCNT]int
var edge [MAXCNT][]int
var depth [MAXCNT]int
var left [MAXCNT]int
var right [MAXCNT]int
var seg [MAXCNT*8]int

func dfs(now int, pre int, d int, order *int) {
    //fmt.Println(now, pre, d, *order)
    depth[now] = d
    *order += 1
    left[now] = *order
    for _, v := range edge[now] {
        if(v == pre) { continue }
        dfs(v, now, d+1, order)
    }
    *order += 1
    right[now] = *order
}

func update(root int, L int, R int, g int, v int) {
    //fmt.Println(root)
    if(L == R) {
        seg[root] += v
        return
    }
    mid := (L+R)>>1
    if(g <= mid) {
        update(root<<1, L, mid, g, v)
    } else {
        update(root<<1|1, mid+1, R, g, v)
    }
    seg[root] = seg[root<<1] + seg[root<<1|1]
}

func query(root int, L int, R int, l int, r int) int {
    //fmt.Println(root)
    if(L == l && R == r) {
        return seg[root]
    }
    mid := (L+R) >> 1
    if(r <= mid) {
        return query(root<<1, L, mid, l, r)
    } else if (mid < l) {
        return query(root<<1|1, mid+1, R, l, r)
    }
    return query(root<<1, L, mid, l, mid) + query(root<<1|1, mid+1, R, mid+1, r)
}

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

func main() {
    var n, m int
    fmt.Fscan(reader, &n, &m)
    //fmt.Scanf("%d %d", &n, &m)
    for i := 1; i <= n; i++ {
        fmt.Fscan(reader, &value[i])
        //fmt.Scanf("%d", &value[i])
    }
    for i := 1; i < n; i++ {
        var x, y int
        fmt.Fscan(reader, &x, &y)
        //fmt.Scanf("%d %d", &x, &y)
        if(edge[x] == nil) { edge[x] = make([]int, 0) }
        if(edge[y] == nil) { edge[y] = make([]int, 0) }
        edge[x] = append(edge[x], y);
        edge[y] = append(edge[y], x);
    }

    //for i := 1; i <= n; i++ {
    //    for _, v := range edge[i] {
    //        fmt.Printf("%d %d\n", i, v)
    //    }
    //}

    var order int
    dfs(1, 0, 1, &order);

    //for i := 1; i <= n; i++ {
    //    fmt.Printf("%d %d %d\n", i, left[i], right[i])
    //}
    //fmt.Println(order)

    for i := 1; i <= m; i++ {
        var t int
        fmt.Fscan(reader, &t)
        //fmt.Scanf("%d", &t)
        if(t == 1) {
            var x, v int
            fmt.Fscan(reader, &x, &v)
            //fmt.Scanf("%d %d", &x, &v);
            var flag int = -1
            if(depth[x]&1 == 1) {
                flag = 1
            }
            update(1, 1, order, left[x], flag*v);
            update(1, 1, order, right[x], -1*flag*v);
        } else {
            var x int
            fmt.Fscan(reader, &x)
            //fmt.Scanf("%d", &x);
            var flag int = -1
            if(depth[x]&1 == 0) {
                flag = 1
            }
            fmt.Printf("%d\n", flag*query(1, 1, order, right[x], order) + value[x]);
        }
    }
    return
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF383C(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	r1 := func() byte {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		return b
	}

	n, q := r(), r()
	a := make([]int, n)
	for i := range a {
		a[i] = r()
	}
	g := make([][]int, n+1)
	for i := 1; i < n; i++ {
		v, w := r(), r()
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	tree := make([]int, n+1)
	add := func(i, v int) {
		for ; i <= n; i += i & -i {
			tree[i] += v
		}
	}
	addR := func(l, r, v int) { add(l, v); add(r, -v) }
	query := func(i int) (v int) {
		for ; i > 0; i &= i - 1 {
			v += tree[i]
		}
		return
	}

	type node struct{ dfn, sz, d int }
	nodes := make([]node, n+1)
	dfn := 0
	var f func(v, fa, d int) int
	f = func(v, fa, d int) int {
		dfn++
		nodes[v].dfn = dfn
		nodes[v].d = d
		sz := 1
		for _, w := range g[v] {
			if w != fa {
				sz += f(w, v, d+1)
			}
		}
		nodes[v].sz = sz
		return sz
	}
	f(1, 0, 0)

	for ; q > 0; q-- {
		op, v := r1(), r()
		o := nodes[v]
		if op == '1' {
			val := r()
			if o.d&1 > 0 {
				val = -val
			}
			addR(o.dfn, o.dfn+o.sz, val)
		} else {
			ans := query(o.dfn)
			if o.d&1 > 0 {
				ans = -ans
			}
			Fprintln(out, a[v-1]+ans)
		}
	}
}

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

package main

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

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

	var n, q, v, w, op, val int
	Fscan(in, &n, &q)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	tree := make([]int, n+1)
	add := func(i, v int) {
		for ; i <= n; i += i & -i {
			tree[i] += v
		}
	}
	addR := func(l, r, v int) { add(l, v); add(r, -v) }
	query := func(i int) (v int) {
		for ; i > 0; i &= i - 1 {
			v += tree[i]
		}
		return
	}

	type node struct{ dfn, sz, d int }
	nodes := make([]node, n)
	dfn := 0
	var f func(v, fa, d int) int
	f = func(v, fa, d int) int {
		dfn++
		nodes[v].dfn = dfn
		nodes[v].d = d
		sz := 1
		for _, w := range g[v] {
			if w != fa {
				sz += f(w, v, d+1)
			}
		}
		nodes[v].sz = sz
		return sz
	}
	f(0, -1, 0)

	for ; q > 0; q-- {
		Fscan(in, &op, &v)
		v--
		o := nodes[v]
		if op == 1 {
			Fscan(in, &val)
			if o.d&1 > 0 {
				val = -val
			}
			addR(o.dfn, o.dfn+o.sz, val)
		} else {
			ans := query(o.dfn)
			if o.d&1 > 0 {
				ans = -ans
			}
			Fprintln(out, a[v]+ans)
		}
	}
}

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

package main

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

type SegTree struct {
	val []int
	n   int
}

func NewSegTree(n int) *SegTree {
	size := calcTreeSize(n)
	return &SegTree{
		val: make([]int, size),
		n:   n,
	}
}

func (s *SegTree) Add(l int, r int, val int) {
	s.add(1, 0, s.n, l, r, val)
}

func (s *SegTree) Sum(i int) int {
	return s.sum(1, 0, s.n, i)
}

func (s *SegTree) add(i int, l int, r int, ql int, qr int, qv int) {
	if i >= len(s.val) {
		return
	}

	if l >= ql && r <= qr {
		s.val[i] += qv
		return
	}
	m := (l + r) / 2
	if qr <= m {
		s.add(i*2, l, m, ql, qr, qv)
	} else if ql > m {
		s.add(i*2+1, m+1, r, ql, qr, qv)
	} else {
		s.add(i*2, l, m, ql, m, qv)
		s.add(i*2+1, m+1, r, m+1, qr, qv)
	}
}

func (s *SegTree) sum(i int, l int, r int, qi int) int {
	if i >= len(s.val) {
		return 0
	}

	if l == qi && r == qi {
		return s.val[i]
	}
	m := (l + r) / 2
	if qi <= m {
		return s.sum(i*2, l, m, qi) + s.val[i]
	} else {
		return s.sum(i*2+1, m+1, r, qi) + s.val[i]
	}
}

func calcTreeSize(length int) int {
	size := 1
	for size < length {
		size *= 2
	}
	return size * 2
}

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

var (
	n, m   int
	weight []int
	index  []int
	last   []int
	color  []int
	stamp  int
	edge   [][]int
)

func dfs(u int, f int, c int) {
	color[u] = c
	index[u] = stamp
	last[u] = stamp
	stamp++

	for _, v := range edge[u] {
		if v != f {
			dfs(v, u, 1-c)
			last[u] = last[v]
		}
	}
}

func main() {
	fmt.Fscan(reader, &n, &m)

	var tree [2]*SegTree
	tree[0] = NewSegTree(n)
	tree[1] = NewSegTree(n)

	weight = make([]int, n)
	index = make([]int, n)
	last = make([]int, n)
	color = make([]int, n)
	edge = make([][]int, n)

	for i := range weight {
		fmt.Fscan(reader, &weight[i])
	}

	for i := 0; i < n-1; i++ {
		var u, v int
		fmt.Fscan(reader, &u, &v)
		u--
		v--
		edge[u] = append(edge[u], v)
		edge[v] = append(edge[v], u)
	}
	dfs(0, -1, 0)

	for i := 0; i < m; i++ {
		var x, y, z int
		fmt.Fscan(reader, &x, &y)
		y--
		if x == 1 {
			fmt.Fscan(reader, &z)
			tree[color[y]].Add(index[y], last[y], z)
			tree[1-color[y]].Add(index[y], last[y], -z)
		} else {
			w := tree[color[y]].Sum(index[y]) + weight[y]
			fmt.Println(w)
		}
	}
}

package main

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

type SegTree struct {
	val []int
	n   int
}

func NewSegTree(n int) *SegTree {
	size := calcTreeSize(n)
	return &SegTree{
		val: make([]int, size),
		n:   n,
	}
}

func (s *SegTree) Add(l int, r int, val int) {
	s.add(1, 0, s.n, l, r, val)
}

func (s *SegTree) Sum(i int) int {
	return s.sum(1, 0, s.n, i)
}

func (s *SegTree) add(i int, l int, r int, ql int, qr int, qv int) {
	if i >= len(s.val) {
		return
	}

	if l >= ql && r <= qr {
		s.val[i] += qv
		return
	}
	m := (l + r) / 2
	if qr <= m {
		s.add(i*2, l, m, ql, qr, qv)
	} else if ql > m {
		s.add(i*2+1, m+1, r, ql, qr, qv)
	} else {
		s.add(i*2, l, m, ql, m, qv)
		s.add(i*2+1, m+1, r, m+1, qr, qv)
	}
}

func (s *SegTree) sum(i int, l int, r int, qi int) int {
	if i >= len(s.val) {
		return 0
	}

	if l == qi && r == qi {
		return s.val[i]
	}
	m := (l + r) / 2
	if qi <= m {
		return s.sum(i*2, l, m, qi) + s.val[i]
	} else {
		return s.sum(i*2+1, m+1, r, qi) + s.val[i]
	}
}

func calcTreeSize(length int) int {
	size := 1
	for size < length {
		size *= 2
	}
	return size * 2
}

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

var (
	n, m   int
	weight []int
	index  []int
	last   []int
	color  []int
	stamp  int
	edge   [][]int
)

func dfs(u int, f int, c int) {
	color[u] = c
	index[u] = stamp
	last[u] = stamp
	stamp++

	for _, v := range edge[u] {
		if v != f {
			dfs(v, u, 1-c)
			last[u] = last[v]
		}
	}
}

func main() {
	fmt.Fscan(reader, &n, &m)

	var tree [2]*SegTree
	tree[0] = NewSegTree(n)
	tree[1] = NewSegTree(n)

	weight = make([]int, n)
	index = make([]int, n)
	last = make([]int, n)
	color = make([]int, n)
	edge = make([][]int, n)

	for i := range weight {
		fmt.Fscan(reader, &weight[i])
	}

	for i := 0; i < n-1; i++ {
		var u, v int
		fmt.Fscan(reader, &u, &v)
		u--
		v--
		edge[u] = append(edge[u], v)
		edge[v] = append(edge[v], u)
	}
	dfs(0, -1, 0)

	for i := 0; i < n; i++ {
		for last[i] >= n || last[i] < index[i] {
			fmt.Println("shit")
		}
	}

	for i := 0; i < m; i++ {
		var x, y, z int
		fmt.Fscan(reader, &x, &y)
		y--
		if x == 1 {
			fmt.Fscan(reader, &z)
			tree[color[y]].Add(index[y], last[y], z)
			tree[1-color[y]].Add(index[y], last[y], -z)
		} else {
			w := tree[color[y]].Sum(index[y]) + weight[y]
			fmt.Println(w)
		}
	}
}