Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent.One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has.Find the volume fraction of orange juice in the final drink.

NoteNote to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal  milliliters. The total cocktail's volume equals 3·x milliliters, so the volume fraction of the juice in the cocktail equals , that is, 66.(6) percent.

package main

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

func main() {
	n := readi()
	values := readis(n)
	fmt.Fprintf(writer, "%.6f\n", median(values))
	writer.Flush()
}

func median(values []int) float64 {
	res := 0
	for _, v := range values {
		res += v
	}
	return float64(res) / float64(len(values))
}

func perfectPermutation(n int) string {
	if n%2 == 1 {
		return "-1"
	}
	values := make([]int, 0)
	for i := 0; i < n; i++ {
		values = append(values, n-i)
	}
	str := ""
	for _, v := range values {
		str += fmt.Sprint(v, " ")
	}
	return str
}

func isNextPrime(n, m int) bool {
	for i := n + 1; i < m; i++ {
		if isPrime(i) {
			return false
		}
	}
	return isPrime(m)
}

func isPrime(n int) bool {
	for x := 2; x*x <= n; x++ {
		if n%x == 0 {
			return false
		}
	}
	return n > 1
}

func withSameCase(word string) string {
	lowerCount := 0
	for _, letter := range word {
		if unicode.IsLower(letter) {
			lowerCount++
		}
	}
	if lowerCount*2 >= len(word) {
		return strings.ToLower(word)
	}
	return strings.ToUpper(word)
}

func solve(matrix [][]int) []string {
	n := 3
	state := make([][]byte, n)
	for i := range state {
		state[i] = make([]byte, n)
		for j := range matrix[i] {
			state[i][j] = byte(matrix[i][j])
			if i > 0 {
				state[i][j] += byte(matrix[i-1][j])
			}
			if i+1 < n {
				state[i][j] += byte(matrix[i+1][j])
			}
			if j > 0 {
				state[i][j] += byte(matrix[i][j-1])
			}
			if j+1 < n {
				state[i][j] += byte(matrix[i][j+1])
			}
			state[i][j] &= 1
			state[i][j] ^= 1
			state[i][j] += '0'
		}
	}
	res := make([]string, n)
	for i := range res {
		res[i] = string(state[i])
	}
	return res
}

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

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

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

var (
	reader = bufio.NewReaderSize(os.Stdin, 1<<13)
	writer = bufio.NewWriterSize(os.Stdout, 1<<13)
)

func readi() int {
	return int(readi64())
}

func read2i() (int, int) {
	return readi(), readi()
}

func read3i() (int, int, int) {
	return readi(), readi(), readi()
}

func read4i() (int, int, int, int) {
	return readi(), readi(), readi(), readi()
}

func readis(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = readi()
	}
	return res
}

func readi64() int64 {
	b, err := reader.ReadByte()
	for !isValid(b, err) {
		b, err = reader.ReadByte()
	}
	sign, res := int64(1), int64(0)
	if b == '-' {
		sign *= -1
		b, err = reader.ReadByte()
	}
	for isValid(b, err) {
		res = res*10 + int64(b-'0')
		b, err = reader.ReadByte()
	}
	return res * sign
}

func readi64s(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = readi64()
	}
	return res
}

func readline() string {
	res := new(bytes.Buffer)
	for {
		line, isPrefix, err := reader.ReadLine()
		if err != nil {
			panic(err)
		}
		res.Write(line)
		if !isPrefix {
			break
		}
	}
	return res.String()
}

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

package main

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

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

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

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

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

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

func solve(n int64) {
	var ans, o float64
	for i := int64(0); i < n; i++ {
		s := " "
		if i == n-1 {
			s = "\n"
		}
		I(&o, s)
		ans += o
	}
	ans /= float64(n)
	O(ans, "\n")
}

package main

import (
	"fmt"
)

func main() {
	var n, x, sum int
	// scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Scanln(&n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &x)
		sum += x
	}

	fmt.Println(float64(sum) / float64(n))
}

package main

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

func main(){
	var n int
	var p float64
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&n)
	sum := 0.0
	for i:=0;i<n;i++{
		fmt.Fscan(in,&p)
		sum +=p
	}
	fmt.Printf("%0.6f\n",sum/float64(n))
}

// B. Drinks
/*
Little Vasya loves orange juice very much. That's why any food and drink in
his kitchen necessarily contains orange juice. There are n drinks in his
fridge, the volume fraction of orange juice in the i-th drink equals pi percent.

One day Vasya decided to make himself an orange cocktail. He took equal
proportions of each of the n drinks and mixed them. Then he wondered,
how much orange juice the cocktail has.

Find the volume fraction of orange juice in the final drink.

Input
The first input line contains a single integer n (1 ≤ n ≤ 100) —
the number of orange-containing drinks in Vasya's fridge. The second line
contains n integers pi (0 ≤ pi ≤ 100) — the volume fraction of orange juice
in the i-th drink, in percent. The numbers are separated by a space.

Output
Print the volume fraction in percent of orange juice in Vasya's cocktail.
The answer will be considered correct if the absolute or relative error
does not exceed 10  - 4.

Examples
Input
3
50 50 100

Output
66.666666666667

Input
4
0 25 50 75

Output
37.500000000000

Note
Note to the first sample: let's assume that Vasya takes x milliliters of each
drink from the fridge. Then the volume of pure juice in the cocktail will equal
milliliters. The total cocktail's volume equals 3·x milliliters, so the volume
fraction of the juice in the cocktail equals , that is, 66.(6) percent.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	n, _ := strconv.ParseFloat(strings.TrimSpace(input1), 32)

	input2, _ := reader.ReadString('\n')
	p := strings.Split(strings.TrimSpace(input2), " ")

	total := 0.0
	for _, v := range p {
		s, _ := strconv.ParseFloat(v, 32)
		total += s
	}
	fmt.Print((total / (n * 100.0)) * 100.0)
}

package main

import(
    "fmt"
)

func main(){
    var (
        n,i int
        res float64
    )
    res =0
    fmt.Scan(&n)
    arr := make([]int,n)
    for i=0;i<n;i++{
        fmt.Scan(&arr[i])
    }
    for i=0;i<n;i++{
        res += float64(arr[i])/100
    }
    fmt.Println(res/float64(n)*100)
}

package main

import "fmt"

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

	cnt := 0
	for range make([]struct{}, n) {
		fmt.Scan(&p)
		cnt += p
	}
	fmt.Println(float64(cnt) / float64(n))
}

package main
import (
	"fmt"
)
func main() {
	var n int
	fmt.Scan(&n)
	tem:=0
	var sum float64
	sum =0
	for k:=0;k<n;k++ {
		fmt.Scan(&tem)
		sum += float64(tem)
	}
	sum /= float64(n)
	fmt.Printf("%.6f",sum)

}

package main

import "fmt"

func main() {
    var n int
    var f,total float64
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&f)
        total += f
    }
    fmt.Println(total/float64(n))
}

package main

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

// var fi, _ = os.Open("input.txt")
// var fo, _ = os.Create("output.txt")

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

func main() {

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

	var n int = NextInt()
	var sum int = 0
	for i := 0; i < n; i++ {
		sum += NextInt()
	}

	fmt.Fprintln(out, float64(sum) / float64(n))
}

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

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

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

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

package main

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

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

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

func Println(a ...interface{}) {
	fmt.Println(a...)
}

func main() {
	var n int
	scan(&n)
	var V float64 = 0
	for i:=0;i<n;i++{
		var w float64
		scan(&w)
		V+=w
	}
	Println(V/float64(n))
}

package main

import "fmt"

func main() {
	var n int
	var r,x float64
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		fmt.Scan(&x)
		r += x
	}
	fmt.Println(r/float64(n))
}

package main

import(
	"fmt"
)

func main() {
	cnt := 0
	sum := 0
	fmt.Scanf("%d", &cnt)
	tmp := 0
	for i := 0; i < cnt+1; i++ {
		fmt.Scanf("%d", &tmp)
		sum += tmp
	}
	fmt.Printf("%.12f\n",float64(sum)/float64(cnt))
}

package main

import "fmt"

func main() {
	var n float32
	var a int
	var count float32 = 0
	fmt.Scan(&n)
	var b int = int(n)
	for i := 0; i < b; i++ {
		fmt.Scan(&a)
		count += float32(a)
	}
	var result float32 = count / n
	fmt.Print(result)
}

package main

import (
	"fmt"
)

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

	var o int = 0
	var t int = 0

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

		o += p
		t += 100
	}

	fmt.Printf("%.10f\n", float64(100*o) / float64(t))
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var x [101]int
	sum := 0

	for i :=0; i<n +1 ; i++ {
		fmt.Scanf("%d", &x[i])
		sum += x[i]
	}

	c := float64(sum)/float64(n)

	fmt.Println(c)
}

package main

import "fmt"

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

	sum, v := 0, 0
	for i := 0; i < n; i++ {
		fmt.Scan(&v)
		sum += v
	}

	fmt.Printf("%.12f\n", float64(sum)/float64(n))
}

package main

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

var n int

func main() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1<<20)
	fmt.Fscanf(reader, "%d\n", &n)

	var x, sum int
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &x)
		sum += x
	}

	fmt.Printf("%.12f", float64(sum)/float64(n))
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n, ic, c uint32
	fmt.Fscanf(in, "%d\n", &n)
	for i:=uint32(0); i < n; i++{
		fmt.Fscanf(in, "%d", &ic)
		c+= ic
	}
	fmt.Println(float64(c) / float64(n * 100) * 100)
}

package main

import "fmt"

func main() {
	var n int
	var x, r float64
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		fmt.Scan(&x)
		r += x
	}
	fmt.Println(r/float64(n))
}

package main

import "fmt"

func main() {
	var n float32
	var a int
	var count float32 = 0
	fmt.Scan(&n)
	var b int = int(n)
	for i := 1; i <= b; i++ {
		fmt.Scan(&a)
		count += float32(a)
	}
	var result float32 = count / n
	fmt.Print(result)
}

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     int
		p     float64
		total float64
	)

	scanf("%d\n", &n)

	for i := 0; i < n; i++ {
		scanf("%f", &p)
		total += p
	}

	printf("%f\n", total/float64(n))
}

package main

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

func main() {
	var n int
	var s int64
	fmt.Scanln(&n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	s = 0
	for _, v := range strings.Split(scanner.Text(), " ") {
		current, _ := strconv.ParseInt(v, 10, 0)
		s += current
	}
	fmt.Println(float64(s) / float64(n))
}

package main

import (
	"fmt"
)

/*
1. Read first input and save no. test case.  fmt.Scan(&n)
2. Read the inputs and sum it up and fins the average.

*/

func main() {
	var n int
	_, err := fmt.Scan(&n)
	if err != nil {

	}

	var value float64
	var sum float64

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

		_, err := fmt.Scan(&value)
		if err != nil {

		}
		sum += value
	}

	fmt.Println(sum/float64(n))
}

package main
import(
    "fmt"
)
func main() {
	var a int
	var c,f float64 = 0.0,0.0
	fmt.Scan(&a)
	var aa float64 = float64(a) * 100.0
	for i:=0; i < a; i++ {
	    fmt.Scan(&f)
	    c+=f
	}
	fmt.Println((c/aa)*100.0)
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    var oj 	float32
    for i := 0 ; i < n ; i++ {
        var x int
        fmt.Scan(&x);
        oj += float32(x)/100.0
    }
    fmt.Println(oj/float32(n)*100)
}

package main

import (
	"fmt"
)

func main() {
	var n, sum, temp int
	var result float64
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&temp)
		sum += temp
	}
	result = float64(sum) / float64(n)
	fmt.Printf("%.12f\n", result)
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

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

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    var sum float64
    for i := 0; i < n; i++ {
        sum = sum + nextFloat()
    }
    fmt.Fprintln(out, sum / float64(n))
}

package main

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

// https://codeforces.com/problemset/problem/200/B
// B. Drinks
// time limit per test
// 2 seconds
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent.

// One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has.

// Find the volume fraction of orange juice in the final drink.
// Input

// The first input line contains a single integer n (1 ≤ n ≤ 100) — the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≤ pi ≤ 100) — the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space.
// Output

// Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10  - 4.

func main() {
	solveTheProblem()
}

func solveTheProblem() {
	bufStdin := bufio.NewReader(os.Stdin)

	var n int
	_, _ = fmt.Fscan(bufStdin, &n)

	var percent float64
	for i := 0; i < n; i++ {
		var pi int
		_, _ = fmt.Fscan(bufStdin, &pi)

		percent += float64(pi)
	}

	fmt.Print(percent / float64(n))
}

package main

import "fmt"

func main()  {
	var n int
	var res, tmp float64
	res = 0
	fmt.Scanf("%d\n", &n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%f", &tmp)
		res += tmp / float64(n)
	}

	fmt.Println(res)

}

package main

// https://codeforces.com/problemset/problem/200/B

import "fmt"

func taskSolution(a []int) string {
	sum := 0
	for _, ai := range a {
		sum += ai
	}
	avg := float64(sum) / float64(len(a))
	return fmt.Sprintf("%.12f", avg)
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

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

	fmt.Println(taskSolution(a))
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	_ = scanner.Scan()
	_ = scanner.Scan()
	ps := strings.Split(scanner.Text(), " ")
	p := 0
	for _, v := range ps {
		n, _ := strconv.Atoi(v)
		p += n
	}
	fmt.Printf("%.5f", float64(p)/float64(len(ps)))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d %d\n", &n)
	sum :=0
	for i:=0;i<n;i++{
		var m int
		fmt.Scanf("%d",&m)
		sum += m
	}
	fmt.Printf("%.12f\n",float64(sum)/float64(n))
}

package main

import(
	"fmt"
)

func main() {
	cnt := 0
	sum := 0
	fmt.Scanf("%d", &cnt)
	for i := 0; i < cnt; i ++ {
		tmp := 0
		fmt.Scanf("%d", &tmp)
		sum += tmp
	}
	fmt.Printf("%.12f\n",float64(sum)/float64(cnt))
}

package main

import(
	"fmt"
)

func main() {
	cnt := 0
	sum := 0
	fmt.Scanf("%d", &cnt)
	tmp := 0
	for i := 0; i < cnt; i++ {
		fmt.Scanf("%d", &tmp)
		fmt.Println(tmp)
		sum += tmp
	}
	fmt.Printf("%.12f\n",float64(sum)/float64(cnt))
}

package main

import(
	"fmt"
)

func main() {
	cnt := 0
	sum := 0
	fmt.Scanf("%d", &cnt)
	tmp := 0
	for i := 0; i < cnt+1; i++ {
		fmt.Scanf("%d", &tmp)
		fmt.Println(tmp)
		sum += tmp
	}
	fmt.Printf("%.12f\n",float64(sum)/float64(cnt))
}

package main

import(
	"fmt"
)

func main() {
	cnt := 0
	sum := 0
	fmt.Scanf("%d", &cnt)
	tmp := 0
	for i := 0; i < cnt; i++ {
		fmt.Scanf("%d", &tmp)
		sum += tmp
	}
	fmt.Printf("%.12f\n",float64(sum)/float64(cnt))
}

package main

import(
	"fmt"
)

func main() {
	cnt := 0
	sum := 0
	fmt.Scanf("%d", &cnt)
	for i := 0; i < cnt; i ++ {
		tmp := 0
		fmt.Scanf("%d", &tmp)
		sum += tmp
	}
	fmt.Printf("%f\n",float64(sum)/float64(cnt))
}

package main
import(
    "fmt"
)
func main() {
	var a int
	var c,f float64 = 0.0,0.0
	fmt.Scan(&a)
	var aa float64 = float64(a) * 100.0
	for i:=0; i < a; i++ {
	    fmt.Scan(&f)
	    c+=f
	}
	fmt.Println(c/aa)
}


All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point.Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.For each city calculate two values mini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city

The first line of the input contains integer n (2 ≤ n ≤ 105) — the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.

Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.

package main

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

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

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n + 2)
	for i := 1; i <= n; i++ {
		a[i] = nextInt()
	}
	a[0], a[n + 1] = a[2], a[n - 1]

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d\n", min(abs(a[i] - a[i - 1]), abs(a[i] - a[i + 1])), max(abs(a[i] - a[1]), abs(a[i] - a[n])))
	}
}

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

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

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

func nextInt() int {
	in.Scan()
	res, _ := strconv.Atoi(in.Text())
	return res
}

package main

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

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

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

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

	for i := range a {
		a[i] = nextInt()
	}

	for i := range a {
		if i == 0 {
			println(a[1]-a[0], a[n-1]-a[0])
		} else if i == n-1 {
			println(a[n-1]-a[n-2], a[n-1]-a[0])
		} else {
			println(min(a[i+1]-a[i], a[i]-a[i-1]), max(a[n-1]-a[i], a[i]-a[0]))
		}
	}
}

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

	return b
}

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

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

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

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

func main() {
    stdin := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscanf(stdin, "%d\n", &n)

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

    fmt.Println(cities[1]-cities[0], cities[n-1]-cities[0])
    for i := 1; i < n-1; i++ {
        lo := min(cities[i]-cities[i-1], cities[i+1]-cities[i])
        hi := max(cities[n-1] - cities[i], cities[i] - cities[0])
        fmt.Println(lo, hi)
    }
    fmt.Println(cities[n-1]-cities[n-2], cities[n-1]-cities[0])
}

package main

import "fmt"

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

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

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

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

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

    fmt.Println(cities[1]-cities[0], cities[n-1]-cities[0])
    for i := 1; i < n-1; i++ {
        lo := min(cities[i]-cities[i-1], cities[i+1]-cities[i])
        hi := max(cities[n-1] - cities[i], cities[i] - cities[0])
        fmt.Println(lo, hi)
    }
    fmt.Println(cities[n-1]-cities[n-2], cities[n-1]-cities[0])
}

package main

import "fmt"

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

	coordinats := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&coordinats[i])
	}

	for i := 0; i < n; i++ {
		min := int64(1e11 + 5)
		left := i - 1
		right := i + 1
		if left >= 0 {
			if coordinats[i]-coordinats[left] < min {
				min = coordinats[i] - coordinats[left]
			}
		}
		if right < n {
			if coordinats[right]-coordinats[i] < min {
				min = coordinats[right] - coordinats[i]
			}
		}

		max := coordinats[i] - coordinats[0]
		if max < coordinats[n-1]-coordinats[i] {
			max = coordinats[n-1] - coordinats[i]
		}

		fmt.Printf("%d %d\n", min, max)
	}
}

package main

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

func min(a1, a2 int) int {
	if a1 < a2 {
		return a1
	}

	return a2
}

func max(a1, a2 int) int {
	if a1 > a2 {
		return a1
	}

	return a2
}

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

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

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

	sort.Ints(coords)

	cmin := coords[0]
	cmax := coords[num-1]

	minimal := coords[1] - cmin
	maximal := cmax - cmin

	fmt.Printf("%d %d\n", minimal, maximal)

	for i := 1; i < num-1; i++ {
		minimal = min(abs(coords[i]-coords[i-1]), abs(coords[i]-coords[i+1]))
		maximal = max(abs(coords[i]-cmax), abs(coords[i]-cmin))

		fmt.Printf("%d %d\n", minimal, maximal)
	}

	minimal = cmax - coords[num-2]
	maximal = cmax - cmin

	fmt.Printf("%d %d\n", minimal, maximal)
}

package main

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

func absolute(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}
func main() {
	var n, min, max, temp int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n)
	positionsArr := make([]int, n)
	for index := 0; index < n; index++ {
		fmt.Fscan(reader, &positionsArr[index])
	}
	for index := 0; index < n; index++ {
		if index == 0 {
			min = absolute(positionsArr[index] - positionsArr[index+1])
			max = absolute(positionsArr[index] - positionsArr[n-1])
		} else if index == n-1 {
			min = absolute(positionsArr[index] - positionsArr[index-1])
			max = absolute(positionsArr[index] - positionsArr[0])
		} else {
			min = absolute(positionsArr[index] - positionsArr[index-1])
			temp = absolute(positionsArr[index] - positionsArr[index+1])
			if min > temp {
				min = temp
			}
			max = absolute(positionsArr[index] - positionsArr[n-1])
			temp = absolute(positionsArr[index] - positionsArr[0])
			if max < temp {
				max = temp
			}
		}
		fmt.Println(min, max)
	}
}

package main

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

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

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

func main() {
	stdin := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(stdin, "%d\n", &n)

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

	fmt.Println(cities[1]-cities[0], cities[n-1]-cities[0])

	for i := 1; i < n-1; i++ {
		lo := min(cities[i]-cities[i-1], cities[i+1]-cities[i])
		hi := max(cities[n-1]-cities[i], cities[i]-cities[0])
		fmt.Println(lo, hi)

	}
	fmt.Println(cities[n-1]-cities[n-2], cities[n-1]-cities[0])

}

package main

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

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

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

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

	var n, j int
	var ox []float64

	n = readInt()
	for i := 0; i < n; i++ {
		j = readInt()
		ox = append(ox, float64(j))
	}

	fmt.Fprintln(writer, int64(ox[1]-ox[0]), int64(ox[n-1]-ox[0]))
	for i := 1; i < n-1; i++ {
		fmt.Fprintln(writer, int64(math.Min(ox[i+1]-ox[i], ox[i]-ox[i-1])), int64(math.Max(ox[n-1]-ox[i], ox[i]-ox[0])))
	}
	fmt.Fprintln(writer, int64(ox[n-1]-ox[n-2]), int64(ox[n-1]-ox[0]))
}

package main

import "fmt"

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

	coordinats := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&coordinats[i])
	}

	for i := 0; i < n; i++ {
		min := int64(1e9 + 5)
		left := i - 1
		right := i + 1
		if left >= 0 {
			if coordinats[i]-coordinats[left] < min {
				min = coordinats[i] - coordinats[left]
			}
		}
		if right < n {
			if coordinats[right]-coordinats[i] < min {
				min = coordinats[right] - coordinats[i]
			}
		}

		max := coordinats[i] - coordinats[0]
		if max < coordinats[n-1]-coordinats[i] {
			max = coordinats[n-1] - coordinats[i]
		}

		fmt.Printf("%d %d\n", min, max)
	}
}

package main

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

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

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

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

	var n, j int
	var ox []float64

	n = readInt()
	for i := 0; i < n; i++ {
		j = readInt()
		ox = append(ox, float64(j))
	}

	fmt.Fprintln(writer, ox[1]-ox[0], ox[n-1]-ox[0])
	for i := 1; i < n-1; i++ {
		fmt.Fprintln(writer, math.Min(ox[i+1]-ox[i], ox[i]-ox[i-1]), math.Max(ox[n-1]-ox[i], ox[i]-ox[0]))
	}
	fmt.Fprintln(writer, ox[n-1]-ox[n-2], ox[n-1]-ox[0])
}


You are given a tree consisting exactly of $$$n$$$ vertices. Tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a value $$$a_v$$$ assigned to it.Let $$$dist(x, y)$$$ be the distance between the vertices $$$x$$$ and $$$y$$$. The distance between the vertices is the number of edges on the simple path between them.Let's define the cost of the tree as the following value: firstly, let's fix some vertex of the tree. Let it be $$$v$$$. Then the cost of the tree is $$$\sum\limits_{i = 1}^{n} dist(i, v) \cdot a_i$$$.Your task is to calculate the maximum possible cost of the tree if you can choose $$$v$$$ arbitrarily.

The first line contains one integer $$$n$$$, the number of vertices in the tree ($$$1 \le n \le 2 \cdot 10^5$$$). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the value of the vertex $$$i$$$. Each of the next $$$n - 1$$$ lines describes an edge of the tree. Edge $$$i$$$ is denoted by two integers $$$u_i$$$ and $$$v_i$$$, the labels of vertices it connects ($$$1 \le u_i, v_i \le n$$$, $$$u_i \ne v_i$$$). It is guaranteed that the given edges form a tree.

Print one integer — the maximum possible cost of the tree if you can choose any vertex as $$$v$$$.

NotePicture corresponding to the first example: You can choose the vertex $$$3$$$ as a root, then the answer will be $$$2 \cdot 9 + 1 \cdot 4 + 0 \cdot 1 + 3 \cdot 7 + 3 \cdot 10 + 4 \cdot 1 + 4 \cdot 6 + 4 \cdot 5 = 18 + 4 + 0 + 21 + 30 + 4 + 24 + 20 = 121$$$.In the second example tree consists only of one vertex so the answer is always $$$0$$$.

package main

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

var t [][]int64
var tt int64
var s []int64
var ds []int64
var dp []int64
var as []int64

func main() {
	var n int64
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)
	as = make([]int64, n + 1)
	for i := int64(1); i <= n; i++ {
		fmt.Fscan(reader, &as[i])
	}
	t = make([][]int64, n + 1)
	for i := int64(1); i < n; i++ {
		var p, q int64
		fmt.Fscan(reader, &p)
		fmt.Fscan(reader, &q)
		t[p] = append(t[p], q)
		t[q] = append(t[q], p)
	}
	s = make([]int64, n + 1)
	ds = make([]int64, n + 1)
	ds[0] = -1
	dfs1(1, 0)
	tt = 0
	for i, d := range ds {
		tt += d * as[i]
	}
	dp = make([]int64, n + 1)
	dfs2(1, 0)
	var rs int64
	for _, d := range dp {
		if d > rs {
			rs = d
		}
	}
	fmt.Println(rs)
}

func dfs1(r, p int64) {
	s[r] = as[r]
	ds[r] = ds[p] + 1
	for _, c := range t[r] {
		if c == p {
			continue
		}
		dfs1(c, r)
		s[r] += s[c]
	}
}

func dfs2(r, p int64) {
	if r == 1 {
		dp[1] = tt
	} else {
		dp[r] = dp[p] - s[r] + s[1] - s[r]
	}
	for _, c := range t[r] {
		if c == p {
			continue
		}
		dfs2(c, r)
	}
}

package main

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

var (
	n  int64
	t  [][]int64
	tt int64
	s  []int64
	ds []int64
	dp []int64
	as []int64
	rs int64
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)
	as = make([]int64, n+1)
	for i := int64(1); i <= n; i++ {
		fmt.Fscan(reader, &as[i])
	}
	t = make([][]int64, n+1)
	for i := int64(1); i < n; i++ {
		var p, q int64
		fmt.Fscan(reader, &p)
		fmt.Fscan(reader, &q)
		t[p] = append(t[p], q)
		t[q] = append(t[q], p)
	}
	s = make([]int64, n+1)
	ds = make([]int64, n+1)
	ds[0] = -1
	dfs1(1, 0)
	tt = 0
	for i, d := range ds {
		tt += d * as[i]
	}
	dp = make([]int64, n+1)
	dfs2(1, 0)
	for _, d := range dp {
		if d > rs {
			rs = d
		}
	}
	fmt.Println(rs)
}

func dfs1(r, p int64) {
	s[r] = as[r]
	ds[r] = ds[p] + 1
	for _, c := range t[r] {
		if c == p {
			continue
		}
		dfs1(c, r)
		s[r] += s[c]
	}
}

func dfs2(r, p int64) {
	if r == 1 {
		dp[1] = tt
	} else {
		dp[r] = dp[p] - s[r] + s[1] - s[r]
	}
	for _, c := range t[r] {
		if c == p {
			continue
		}
		dfs2(c, r)
	}
}

package main

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

var (
	sumall int64 = 0
)

func AddEdge(edges [][]int, from, to int) {
	if 0== len(edges[from]){
		edges[from] = make([]int,0)
	}
	edges[from] = append(edges[from],to)
}
func dfsSum(edges [][]int, sum, v, p []int64, root, pre int) {
	sum[root] = p[root]
	v[root] = 0
	for _, next := range edges[root] {
		if next == pre {
			continue
		}
		dfsSum(edges, sum, v, p, next, root)
		sum[root] += sum[next]
		v[root] += v[next] + sum[next]
	}
}
func dfs(edges [][]int, sum, v, p []int64, root, pre int, ppc int64) int64 {
	vans := v[root] + ppc +sumall-sum[root]
	ans := vans
//	fmt.Println("root--",root,"vrot",v[root],"ppc",ppc,"sumall",sumall,"sumroot",sum[root],"ans",ans)
	for _, next := range edges[root] {
		if next == pre {
			continue
		}
		pc := vans-v[next]-sum[next]
		tmp := dfs(edges, sum, v, p, next, root,pc)
		if tmp > ans{
			ans = tmp
		}
	}
	return ans

}
func main() {

	buf := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	p := make([]int64, n+1)
	sum := make([]int64, n+1)
	v := make([]int64, n+1)
	edge := make([][]int, n+1)

	for i := 1; i <= n; i++ {
		fmt.Fscanf(buf, "%d", &p[i])
		sumall += p[i]
	}
	for i := 1; i <= n; i++ {
		var from, to int
		fmt.Fscanf(buf, "%d %d\n", &from, &to)
		AddEdge(edge, from, to)
		AddEdge(edge, to, from)
	}
	dfsSum(edge,sum,v,p,1,0)
//	fmt.Println("v",v,"sum=",sum,"edge=",edge)
	ans := dfs(edge,sum,v,p,1,0,0)
	fmt.Printf("%d\n",ans)
}

package main

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

var n int
var res int64
var adj map[int64][]int64
var w, parent, sum []int64
var seen []bool

func Connect (u, v int64) {
    adj[u] = append(adj[u], v)
    adj[v] = append(adj[v], u)
}

func BuildTree (u, rank int64) (int64, int64) {
    if seen[u] {
        return 0, 0
    }
    var re = w[u] * rank
    seen[u] = true
    sum[u] = w[u]
    for _, v := range(adj[u]) {
        if !seen[v] {
            parent[v] = u
            var a, b = BuildTree(v, rank + 1)
            re += a
            sum[u] += b
        }
    }
    return re, sum[u]
}

func Max (u, v int64) int64 {
    if u > v {
        return u
    } else {
        return v
    }
}

func Reroot (u, v, old, brand int64) int64 {
    var tmp1 = old + brand - 2 * sum[v]
    var res = Max(old, tmp1)
    seen[v] = true
    // fmt.Println("Reroot", u, "to", v, "new sum is", res, tmp1, old, sum[u], sum[v])
    for _, x := range(adj[v]) {
        if !seen[x] {
            var tmp2 = Reroot(v, x, tmp1, brand)
            res = Max(res, tmp2)
        }
    }
    return res
}

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

    stdin := bufio.NewReader(os.Stdin)

    fmt.Fscan(stdin, &n)

    w = make([]int64, n)
    parent = make([]int64, n)
    seen = make([]bool, n)
    sum = make([]int64, n)

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

    adj = make(map[int64][]int64, n)
    for i := 0; i < n-1; i++ {
        var u, v int64
        fmt.Fscan(stdin, &u, &v)
        Connect(u - 1, v - 1)
    }
    var s1, _ = BuildTree(0, 0)

    seen = make([]bool, n)
    seen[0] = true
    for _, x := range(adj[0]) {
        res = Max(res, Reroot(0, x, s1, sum[0]))
    }

    // fmt.Println(sum)
    // fmt.Println(parent)
    // fmt.Println(s1, s2)
    fmt.Println(res)
}

package main

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

var inp *bufio.Scanner
var out *bufio.Writer

var V, res, rootAns int64
var adjList [][]int64
var a, sum []int64

func dfs(u, p, dist int64) {
	rootAns += dist * a[u]
	sum[u] = a[u];
	for _, v := range adjList[u] {
		if v != p {
			dfs(v, u, dist + 1)
			sum[u] += sum[v]
		}
	}
}

func dfs2(u, p, cur int64) {
	for _, v := range adjList[u] {
		if v != p {
			nxt := cur + sum[0] - 2 * sum[v]
			res = max(res, cur + sum[0] - 2 * sum[v])
			dfs2(v, u, nxt)
		}
	}
}

func main() {
	io()
	defer out.Flush()

	V = nextInt()
	adjList = make([][]int64, V)
	a = make([]int64, V)
	sum = make([]int64, V)
	for i := int64(0); i < V; i++ {
		a[i] = nextInt()
	}
	for i := int64(0); i < V - 1; i++ {
		u := nextInt() - 1
		v := nextInt() - 1
		adjList[u] = append(adjList[u], v)
		adjList[v] = append(adjList[v], u)
	}

	dfs(0, -1, 0)
	res = rootAns
	dfs2(0, -1, rootAns)
	out.WriteString(fmt.Sprintf("%d", res))
}

func max (a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func io() {
	inp = bufio.NewScanner(os.Stdin)
	inp.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}
func nextString() string {
	inp.Scan()
	return inp.Text();
}

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

package main

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

var inp *bufio.Scanner
var out *bufio.Writer

var V int
var res, rootAns int64
var adjList [][]int
var a, sum []int64

func dfs(u, p, dist int) {
	rootAns += int64(dist) * a[u]
	sum[u] = a[u];
	for _, v := range adjList[u] {
		if v != p {
			dfs(v, u, dist + 1)
			sum[u] += sum[v]
		}
	}
}

func dfs2(u, p int, cur int64) {
	for _, v := range adjList[u] {
		if v != p {
			nxt := cur + sum[0] - 2 * sum[v]
			res = max(res, cur + sum[0] - 2 * sum[v])
			dfs2(v, u, nxt)
		}
	}
}

func main() {
	io()
	defer out.Flush()

	V = nextInt()
	adjList = make([][]int, V)
	a = make([]int64, V)
	sum = make([]int64, V)
	for i := 0; i < V; i++ {
		a[i] = nextInt64()
	}
	for i := 0; i < V - 1; i++ {
		u := nextInt() - 1
		v := nextInt() - 1
		adjList[u] = append(adjList[u], v)
		adjList[v] = append(adjList[v], u)
	}

	dfs(0, -1, 0)
	res = rootAns
	dfs2(0, -1, rootAns)
	out.WriteString(fmt.Sprintf("%d", res))
}

func max (a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func io() {
	inp = bufio.NewScanner(os.Stdin)
	inp.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}
func nextString() string {
	inp.Scan()
	return inp.Text();
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextString(), 10, 64)
	return int64(v)
}
func nextInt() int {
	v, _ := strconv.ParseInt(nextString(), 10, 64)
	return int(v)
}

package main

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

type vertex struct {
	v                   int64
	conns               []*vertex
	costColor, sumColor int
	missing             *vertex
	costs, sums         map[*vertex]int64
	cost, sum           int64
}

func newVertex(v int64) *vertex {
	return &vertex{
		v:     v,
		costs: map[*vertex]int64{},
		sums:  map[*vertex]int64{},
		cost:  -1,
		sum:   -1,
	}
}

func (v *vertex) Cost(p *vertex) int64 {
	if v.costColor == 2 {
		return v.cost - v.costs[p]
	}
	if v.costColor == 1 {
		if v.missing == p {
			return v.cost
		}
		t := v.missing.Sum(v) + v.missing.Cost(v) + v.missing.Value()
		v.cost += t
		v.costs[v.missing] = t
		v.costColor = 2
		return v.Cost(p)
	}
	v.costColor = 1
	v.missing = p
	v.cost = 0
	for _, conn := range v.conns {
		if p == conn {
			continue
		}
		t := conn.Sum(v) + conn.Cost(v) + conn.Value()
		v.cost += t
		v.costs[conn] = t
	}
	if p == nil {
		v.costColor = 2
	}
	return v.cost
}
func (v *vertex) Sum(p *vertex) int64 {
	if v.sumColor == 2 {
		return v.sum - v.sums[p]
	}
	if v.sumColor == 1 {
		if v.missing == p {
			return v.sum
		}
		t := v.missing.Sum(v) + v.missing.Value()
		v.sum += t
		v.sums[v.missing] = t
		v.sumColor = 2
		return v.Sum(p)
	}
	v.sumColor = 1
	v.missing = p
	v.sum = 0
	for _, conn := range v.conns {
		if p == conn {
			continue
		}
		t := conn.Sum(v) + conn.Value()
		v.sum += t
		v.sums[conn] = t
	}
	if p == nil {
		v.sumColor = 2
	}
	return v.sum
}

func (v *vertex) Value() int64 {
	return v.v
}

func connect(l, r *vertex) {
	l.conns = append(l.conns, r)
	r.conns = append(r.conns, l)
}

func read() []*vertex {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	vs := make([]*vertex, 0, n)
	for i := 0; i < n; i++ {
		var v int64
		fmt.Fscan(r, &v)
		vs = append(vs, newVertex(v))
	}
	for i := 1; i < n; i++ {
		var a, b int
		fmt.Fscan(r, &a, &b)
		connect(vs[a-1], vs[b-1])
	}
	return vs
}

func main() {
	vs := read()
	var ans int64
	for _, v := range vs {
		if t := v.Cost(nil); ans < t {
			ans = t
		}
	}
	fmt.Println(ans)
}

package main

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

var t [][]int
var tt int
var s []int
var ds []int
var dp []int
var as []int

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)
	as = make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(reader, &as[i])
	}
	t = make([][]int, n + 1)
	for i := 1; i < n; i++ {
		var p, q int
		fmt.Fscan(reader, &p)
		fmt.Fscan(reader, &q)
		t[p] = append(t[p], q)
		t[q] = append(t[q], p)
	}
	s = make([]int, n + 1)
	ds = make([]int, n + 1)
	ds[0] = -1
	dfs1(1, 0)
	tt = 0
	for i, d := range ds {
		tt += d * as[i]
	}
	dp = make([]int, n + 1)
	dfs2(1, 0)
	rs := 0
	for _, d := range dp {
		if d > rs {
			rs = d
		}
	}
	fmt.Println(rs)
}

func dfs1(r, p int) {
	s[r] = as[r]
	ds[r] = ds[p] + 1
	for _, c := range t[r] {
		if c == p {
			continue
		}
		dfs1(c, r)
		s[r] += s[c]
	}
}

func dfs2(r, p int) {
	if r == 1 {
		dp[1] = tt
	} else {
		dp[r] = dp[p] - s[r] + s[1] - s[r]
	}
	for _, c := range t[r] {
		if c == p {
			continue
		}
		dfs2(c, r)
	}
}

package main

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

var t [][]int
var tt int
var s []int
var ds []int
var dp []int
var as []int

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)
	as = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &as[i])
	}
	t = make([][]int, n)
	for i := 1; i < n; i++ {
		var p, q int
		fmt.Fscan(reader, &p)
		fmt.Fscan(reader, &q)
		t[p-1] = append(t[p-1], q-1)
		t[q-1] = append(t[q-1], p-1)
	}
	s = make([]int, n)
	ds = make([]int, n)
	dfs1(0, -1)
	tt = 0
	for i, d := range ds {
		tt += d * as[i]
	}
	dp = make([]int, n)
	dfs2(0, -1)
	rs := 0
	for _, d := range dp {
		if d > rs {
			rs = d
		}
	}
	fmt.Println(rs)
}

func dfs1(r, p int) {
	s[r] += as[r]
	if r == 0 {
		ds[0] = 0
	} else {
		ds[r] = ds[p] + 1
	}
	for _, c := range t[r] {
		if c == p {
			continue
		}
		dfs1(c, r)
		s[r] += s[c]
	}
}

func dfs2(r, p int) {
	if r == 0 {
		dp[0] = tt
	} else {
		dp[r] = dp[p] - s[r] + s[0] - s[r]
	}
	for _, c := range t[r] {
		if c == p {
			continue
		}
		dfs2(c, r)
	}
}

package main

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

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &as[i])
	}
	t := make([]int, n)
	t[0] = -1
	for i := 0; i < n-1; i++ {
		var p, q int
		fmt.Fscan(reader, &p)
		fmt.Fscan(reader, &q)
		t[q-1] = p - 1
	}
	ds := make([]int, n)
	for i := range ds {
		ds[i] = -1
	}
	fmt.Println("1111")
	rs := 0
	for i := 0; i < n; i++ {
		// Build tree.
		tree(i, t)
		t[i] = -1
		// Init distances.
		ds[i] = 0
		dfs(i, t, ds)
		s := 0
		for i, d := range ds {
			s += d * as[i]
		}
		if s > rs {
			rs = s
		}
	}
	fmt.Println(rs)
}

func tree(r int, t []int) {
	if t[r] == -1 {
		return
	}
	tree(t[r], t)
	t[t[r]] = r
}

func dfs(r int, t []int, ds []int) {
	if t[r] != -1 {
		for i := range ds {
			if t[i] == -1 {
				continue
			}
			ds[i] = ds[t[i]] + 1
		}
	}
	for n := range t {
		if t[n] == r {
			dfs(n, t, ds)
		}
	}
}

package main

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

var n, res int
var adj map[int][]int
var w, parent, sum []int
var seen []bool

func Connect (u, v int) {
    adj[u] = append(adj[u], v)
    adj[v] = append(adj[v], u)
}

func BuildTree (u, rank int) (int, int) {
    if seen[u] {
        return 0, 0
    }
    var re = w[u] * rank
    seen[u] = true
    sum[u] = w[u]
    for _, v := range(adj[u]) {
        if !seen[v] {
            parent[v] = u
            var a, b = BuildTree(v, rank + 1)
            re += a
            sum[u] += b
        }
    }
    return re, sum[u]
}

func Max (u, v int) int {
    if u > v {
        return u
    } else {
        return v
    }
}

func Reroot (u, v, old, brand int) int {
    var tmp1 = old + brand - 2 * sum[v]
    var res = Max(old, tmp1)
    seen[v] = true
    // fmt.Println("Reroot", u, "to", v, "new sum is", res, tmp1, old, sum[u], sum[v])
    for _, x := range(adj[v]) {
        if !seen[x] {
            var tmp2 = Reroot(v, x, tmp1, brand)
            res = Max(res, tmp2)
        }
    }
    return res
}

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

    stdin := bufio.NewReader(os.Stdin)

    fmt.Fscan(stdin, &n)

    w = make([]int, n)
    parent = make([]int, n)
    seen = make([]bool, n)
    sum = make([]int, n)

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

    adj = make(map[int][]int, n)
    for i := 0; i < n-1; i++ {
        var u, v int
        fmt.Fscan(stdin, &u, &v)
        Connect(u - 1, v - 1)
    }
    var s1, _ = BuildTree(0, 0)

    seen = make([]bool, n)
    seen[0] = true
    for _, x := range(adj[0]) {
        res = Max(res, Reroot(0, x, s1, sum[0]))
    }

    // fmt.Println(sum)
    // fmt.Println(parent)
    // fmt.Println(s1, s2)
    fmt.Println(res)
}

package main

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

type pii struct {
	v, r int
	old  int
}

func mp(a, b int) pii {
	return pii{v: a, r: b, old: 0}
}

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

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

	var n, res, all, tmp int
	fmt.Fscan(stdin, &n)

	var w = make([]int, n)
	var sum = make([]int, n)
	var queue []pii
	var adj = make(map[int][]int, n)
	var parent = make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &w[i])
		all += w[i]
		sum[i] = w[i]
	}
	for i := 0; i < n-1; i++ {
		var a, b int
		fmt.Fscan(stdin, &a, &b)
		a--
		b--
		adj[a] = append(adj[a], b)
	}

	sum[0] = w[0]
	queue = []pii{
		pii{v: 0, r: 0},
	}

	// DFS - Build Tree
	for len(queue) > 0 {
		var pop = queue[0]
		queue = queue[1:]

		tmp += w[pop.v] * pop.r
		for _, u := range adj[pop.v] {
			queue = append(queue, mp(u, pop.r+1))
			parent[u] = pop.v
		}
	}
	// Trace - build sum array
	for i := 0; i < n; i++ {
		var j = i
		for j > 0 {
			sum[parent[j]] += w[j]
			j = parent[j]
		}
	}
	sum[0] = all

	// DFS 2 - Moving sum around
	queue = nil
	res = tmp
	for _, u := range adj[0] {
		var newpii = mp(u, sum[u])
		newpii.old = tmp
		queue = append(queue, newpii)
	}
	for len(queue) > 0 {
		var pop = queue[0]
		queue = queue[1:]
		tmp = pop.old + all - 2*pop.r
		if tmp > res {
			res = tmp
		}
		for _, v := range adj[pop.v] {
			var newpii = mp(v, sum[v])
			newpii.old = tmp
			queue = append(queue, newpii)
		}
	}

	fmt.Println(res)

}

package main

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

type pii struct {
	v, r int64
	old  int64
}

func mp(a, b int64) pii {
	return pii{v: a, r: b, old: 0}
}

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

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

	var n int
	var res, all, tmp int64
	fmt.Fscan(stdin, &n)

	var w = make([]int64, n)
	var sum = make([]int64, n)
	var queue []pii
	var adj = make(map[int64][]int64, n)
	var parent = make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &w[i])
		all += w[i]
		sum[i] = w[i]
	}
	for i := 0; i < n-1; i++ {
		var a, b int64
		fmt.Fscan(stdin, &a, &b)
		a--
		b--
		adj[a] = append(adj[a], b)
	}

	sum[0] = w[0]
	queue = []pii{
		pii{v: 0, r: 0},
	}

	// DFS - Build Tree
	for len(queue) > 0 {
		var pop = queue[0]
		queue = queue[1:]

		tmp += w[pop.v] * pop.r
		for _, u := range adj[pop.v] {
			queue = append(queue, mp(u, pop.r+1))
			parent[u] = int(pop.v)
		}
	}
	// Trace - build sum array
	for i := 0; i < n; i++ {
		var j = i
		for j > 0 {
			sum[parent[j]] += w[j]
			j = parent[j]
		}
	}
	sum[0] = all

	// DFS 2 - Moving sum around
	queue = nil
	res = tmp
	for _, u := range adj[0] {
		var newpii = mp(u, sum[u])
		newpii.old = tmp
		queue = append(queue, newpii)
	}
	for len(queue) > 0 {
		var pop = queue[0]
		queue = queue[1:]
		tmp = pop.old + all - 2*pop.r
		if tmp > res {
			res = tmp
		}
		for _, v := range adj[pop.v] {
			var newpii = mp(v, sum[v])
			newpii.old = tmp
			queue = append(queue, newpii)
		}
	}

	fmt.Println(res)

}

package main

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

var inp *bufio.Scanner
var out *bufio.Writer

var V, res int64
var adjList [][]int64
var a, sub, sum []int64

func dfs(u, p, dist int64) {
	sum[u] = a[u];
	for _, v := range adjList[u] {
		if v != p {
			sub[u] += a[v]
			dfs(v, u, dist + 1)
			sub[u] += 2 * sub[v]
			sum[u] += sum[v]
		}
	}
}

func dfs2(u, p, cur int64) {
	for _, v := range adjList[u] {
		if v != p {
			nxt := cur + sum[0] - 2 * sum[v]
			res = max(res, cur + sum[0] - 2 * sum[v])
			dfs2(v, u, nxt)
		}
	}
}

func main() {
	io()
	defer out.Flush()

	V = nextInt()
	adjList = make([][]int64, V)
	a = make([]int64, V)
	sub = make([]int64, V)
	sum = make([]int64, V)
	for i := int64(0); i < V; i++ {
		a[i] = nextInt()
	}
	for i := int64(0); i < V - 1; i++ {
		u := nextInt() - 1
		v := nextInt() - 1
		adjList[u] = append(adjList[u], v)
		adjList[v] = append(adjList[v], u)
	}

	dfs(0, -1, 0)
	res = sub[0]
	dfs2(0, -1, sub[0])
	out.WriteString(fmt.Sprintf("%d", res))
}

func max (a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func io() {
	inp = bufio.NewScanner(os.Stdin)
	inp.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}
func nextString() string {
	inp.Scan()
	return inp.Text();
}

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

package main

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

var inp *bufio.Scanner
var out *bufio.Writer

var V, res int
var adjList [][]int
var a, sub, sum []int

func dfs(u, p, dist int) {
	sum[u] = a[u];
	for _, v := range adjList[u] {
		if v != p {
			sub[u] += a[v]
			dfs(v, u, dist + 1)
			sub[u] += 2 * sub[v]
			sum[u] += sum[v]
		}
	}
}

func dfs2(u, p, cur int) {
	for _, v := range adjList[u] {
		if v != p {
			nxt := cur + sum[0] - 2 * sum[v]
			res = max(res, cur + sum[0] - 2 * sum[v])
			dfs2(v, u, nxt)
		}
	}
}

func main() {
	io()
	defer out.Flush()

	V = nextInt()
	adjList = make([][]int, V)
	a = make([]int, V)
	sub = make([]int, V)
	sum = make([]int, V)
	for i := 0; i < V; i++ {
		a[i] = nextInt()
	}
	for i := 0; i < V - 1; i++ {
		u := nextInt() - 1
		v := nextInt() - 1
		adjList[u] = append(adjList[u], v)
		adjList[v] = append(adjList[v], u)
	}

	dfs(0, -1, 0)
	res = sub[0]
	dfs2(0, -1, sub[0])
	out.WriteString(fmt.Sprintf("%d", res))
}

func max (a, b int) int {
	if a > b {
		return a
	}
	return b
}
func io() {
	inp = bufio.NewScanner(os.Stdin)
	inp.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}
func nextString() string {
	inp.Scan()
	return inp.Text();
}

func nextInt() int {
	v, _ := strconv.ParseInt(nextString(), 10, 64)
	return int(v)
}

package main

import (
	"fmt"
	"strings"
)

const input = `8
9 4 1 7 10 1 6 5
1 2
2 3
1 4
1 5
5 6
5 7
5 8
`

type vertex struct {
	val      int64
	connects []*vertex
}

func (v *vertex) Connect(rhv *vertex) {
	v.connects = append(v.connects, rhv)
}

func (v *vertex) Calculate(p *vertex, depth int) int64 {
	var res = v.val * int64(depth)
	for _, conn := range v.connects {
		if conn == p {
			continue
		}
		res += conn.Calculate(v, depth+1)
	}
	return res
}

func main() {
	sr := strings.NewReader(input)
	var n int
	if _, err := fmt.Fscan(sr, &n); err != nil {
		panic(err)
	}
	var vertices = make([]*vertex, 0, n)
	for i := 0; i < n; i++ {
		var v int64
		if _, err := fmt.Fscan(sr, &v); err != nil {
			panic(err)
		}
		vertices = append(vertices, &vertex{val: v})
	}
	for i := 0; i < n-1; i++ {
		var l, r int
		if _, err := fmt.Fscan(sr, &l, &r); err != nil {
			panic(err)
		}
		lv, rv := vertices[l-1], vertices[r-1]
		lv.Connect(rv)
		rv.Connect(lv)
	}
	var ans int64
	for _, v := range vertices {
		if t := v.Calculate(nil, 0); ans < t {
			ans = t
		}
	}
	fmt.Println(ans)
}


During the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021". The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down from the upper left corner as follows:   The cell with coordinates $$$(x, y)$$$ is at the intersection of $$$x$$$-th row and $$$y$$$-th column. Upper left cell $$$(1,1)$$$ contains an integer $$$1$$$.The developers of the SUM function don't sleep either. Because of the boredom, they teamed up with the developers of the RAND function, so they added the ability to calculate the sum on an arbitrary path from one cell to another, moving down or right. Formally, from the cell $$$(x,y)$$$ in one step you can move to the cell $$$(x+1, y)$$$ or $$$(x, y+1)$$$. After another Dinwows update, Levian started to study "Celex-2021" (because he wants to be an accountant!). After filling in the table with the GAZ-GIZ function, he asked you to calculate the quantity of possible different amounts on the path from a given cell $$$(x_1, y_1)$$$ to another given cell $$$(x_2, y_2$$$), if you can only move one cell down or right.Formally, consider all the paths from the cell $$$(x_1, y_1)$$$ to cell $$$(x_2, y_2)$$$ such that each next cell in the path is located either to the down or to the right of the previous one. Calculate the number of different sums of elements for all such paths.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 57179$$$) — the number of test cases. Each of the following $$$t$$$ lines contains four natural numbers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \le x_1 \le x_2 \le 10^9$$$, $$$1 \le y_1 \le y_2 \le 10^9$$$) — coordinates of the start and the end cells.

For each test case, in a separate line, print the number of possible different sums on the way from the start cell to the end cell.

NoteIn the first test case there are two possible sums: $$$1+2+5=8$$$ and $$$1+3+5=9$$$.

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		A := readNNums(reader, 4)
		fmt.Println(solve(A[0], A[1], A[2], A[3]))
	}
}

func solve(a, b, c, d int) int64 {
	A, B, C, D := int64(a), int64(b), int64(c), int64(d)
	return (C-A)*(D-B) + 1
}

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

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

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

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

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

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

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

	return i
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		x1, y1, x2, y2 := int64(0), int64(0), int64(0), int64(0)
		fmt.Fscanf(in, "%d %d %d %d\n", &x1, &y1, &x2, &y2)
		x := x2 - x1
		y := y2 - y1
		top := min(x, y)
		ans := int64(0)
		if top >= 1 {
			if x == y {
				ans += top
				ans += (top) * (top - 1)
			} else {
				ans += (1 + top) * top
				ans += (x + y - 1 - top*2) * top
			}
		}
		fmt.Fprintf(out, "%d\n", ans+1)
	}
	return
}

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

/*
URL:
https://codeforces.com/contest/1358/problem/C
*/

package main

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

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

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

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

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

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

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t              int
	x1, y1, x2, y2 int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		x1, y1, x2, y2 := ReadInt64_4()

		u := x2 - x1
		r := y2 - y1
		a := u + r

		mini := ArithmeticSequenceSum(1, 1, u)
		maxi := ArithmeticSequenceSum(a, -1, u)
		ans := maxi - mini + 1
		fmt.Println(ans)
	}
}

// ArithmeticSequenceSum returns a sum of an arithmetic sequence.
// a: 初項, d: 公差, n: 項数
func ArithmeticSequenceSum(a, d, n int64) int64 {
	return (2*a + (n-1)*d) * n / 2
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*
URL:
https://codeforces.com/contest/1358/problem/C
*/

package main

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

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

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

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

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

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

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t              int
	x1, y1, x2, y2 int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		x1, y1, x2, y2 := ReadInt64_4()

		u := x2 - x1
		r := y2 - y1
		a := u + r

		mini := ArithmeticSequenceSum(1, 1, u)
		maxi := ArithmeticSequenceSum(a, -1, u)
		fmt.Println(maxi - mini + 1)
	}
}

// ArithmeticSequenceSum returns a sum of an arithmetic sequence.
// a: 初項, d: 公差, n: 項数
func ArithmeticSequenceSum(a, d, n int64) int64 {
	return (2*a + (n-1)*d) * n / 2
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

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

	var t, x1, y1, x, y int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &x1, &y1, &x, &y)
		x -= x1
		y -= y1
		if x > y {
			x, y = y, x
		}
		Fprintln(out, int64(x)*int64(y)+1)
	}
}

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

package main

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

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

	var t, x1, y1, x, y int64
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &x1, &y1, &x, &y)
		x -= x1
		y -= y1
		if x > y {
			x, y = y, x
		}
		Fprintln(out, x*y+1)
	}
}

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

package main

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

func main() {
	defer out.Flush()
	for t := ScanInt(); t > 0; t-- {
		P(solve())
	}
}

func solve() int64 {
	x1, x2, y1, y2 := ScanInt64(), ScanInt64(), ScanInt64(), ScanInt64()
	return (y1-x1)*(y2-x2) + 1
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

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

/*********************** Utils int64 ***********************/
func MnMx64(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn64(args ...int64) int64 { mn, _ := MnMx64(args...); return mn }
func Mx64(args ...int64) int64 { _, mx := MnMx64(args...); return mx }
func LCM64(a, b int64) int64   { return a / GCD64(a, b) * b }
func GCD64(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD64(b%a, a)
}
func SortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func Abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

/*********************** Utils int ***********************/
func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"bufio"
	"io/ioutil"
	"os"
	"strconv"
)

var bytes []byte
var l, max int

func fastScan() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

func main(){
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1

	ws := bufio.NewWriter(os.Stdout)

	T := fastScan()
	for ; T > 0; T-- {
		x1 := fastScan()
		y1 := fastScan()
		x2 := fastScan()
		y2 := fastScan()
		dx := int64(x2 - x1)
		dy := int64(y2 - y1)
		ws.WriteString(strconv.FormatInt(int64(1) + dx*dy, 10) + "\n")
	}
	ws.Flush()
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	Int64() int64
	UInt64() uint64
	String() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) Int64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) UInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) String() string {
	impl.Scan()
	return impl.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

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

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		x1 := reader.Int64()
		y1 := reader.Int64()
		x2 := reader.Int64()
		y2 := reader.Int64()
		writer.Printf("%d\n", sol(x1,y1,x2,y2))
	}
}

func sol(x1, y1, x2, y2 int64) int64 {
	return (x2-x1)*(y2-y1)+1
}

package main

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

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

	var t, x1, y1, x, y int64
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &x1, &y1, &x, &y)
		x -= x1
		y -= y1
		if x > y {
			x, y = y, x
		}
		if x == 0 {
			Fprintln(out, 1)
		} else {
			Fprintln(out, x*(y-x+2))
		}
	}
}

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

package main

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

func main() {
	defer out.Flush()
	for t := ScanInt(); t > 0; t-- {
		P(solve())
	}
}

func solve() int64 {
	x1, x2, y1, y2 := ScanInt64(), ScanInt64(), ScanInt64(), ScanInt64()
	return (x2-x1)*(y2-y1) + 1
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

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

/*********************** Utils int64 ***********************/
func MnMx64(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn64(args ...int64) int64 { mn, _ := MnMx64(args...); return mn }
func Mx64(args ...int64) int64 { _, mx := MnMx64(args...); return mx }
func LCM64(a, b int64) int64   { return a / GCD64(a, b) * b }
func GCD64(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD64(b%a, a)
}
func SortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func Abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

/*********************** Utils int ***********************/
func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	defer out.Flush()
	for t := ScanInt(); t > 0; t-- {
		P(solve())
	}
}

func solve() int64 {
	x1, x2, y1, y2 := ScanInt(), ScanInt(), ScanInt(), ScanInt()
	return int64(x2-x1)*int64(y2-y1) + 1
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.You are given two matrices $$$A$$$ and $$$B$$$ of size $$$n \times m$$$, each of which consists of $$$0$$$ and $$$1$$$ only. You can apply the following operation to the matrix $$$A$$$ arbitrary number of times: take any submatrix of the matrix $$$A$$$ that has at least two rows and two columns, and invert the values in its corners (i.e. all corners of the submatrix that contain $$$0$$$, will be replaced by $$$1$$$, and all corners of the submatrix that contain $$$1$$$, will be replaced by $$$0$$$). You have to answer whether you can obtain the matrix $$$B$$$ from the matrix $$$A$$$.  An example of the operation. The chosen submatrix is shown in blue and yellow, its corners are shown in yellow. Ramesses don't want to perform these operations by himself, so he asks you to answer this question.A submatrix of matrix $$$M$$$ is a matrix which consist of all elements which come from one of the rows with indices $$$x_1, x_1+1, \ldots, x_2$$$ of matrix $$$M$$$ and one of the columns with indices $$$y_1, y_1+1, \ldots, y_2$$$ of matrix $$$M$$$, where $$$x_1, x_2, y_1, y_2$$$ are the edge rows and columns of the submatrix. In other words, a submatrix is a set of elements of source matrix which form a solid rectangle (i.e. without holes) with sides parallel to the sides of the original matrix. The corners of the submatrix are cells $$$(x_1, y_1)$$$, $$$(x_1, y_2)$$$, $$$(x_2, y_1)$$$, $$$(x_2, y_2)$$$, where the cell $$$(i,j)$$$ denotes the cell on the intersection of the $$$i$$$-th row and the $$$j$$$-th column.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 500$$$) — the number of rows and the number of columns in matrices $$$A$$$ and $$$B$$$. Each of the next $$$n$$$ lines contain $$$m$$$ integers: the $$$j$$$-th integer in the $$$i$$$-th line is the $$$j$$$-th element of the $$$i$$$-th row of the matrix $$$A$$$ ($$$0 \leq A_{ij} \leq 1$$$).  Each of the next $$$n$$$ lines contain $$$m$$$ integers: the $$$j$$$-th integer in the $$$i$$$-th line is the $$$j$$$-th element of the $$$i$$$-th row of the matrix $$$B$$$ ($$$0 \leq B_{ij} \leq 1$$$).

Print "Yes" (without quotes) if it is possible to transform the matrix $$$A$$$ to the matrix $$$B$$$ using the operations described above, and "No" (without quotes), if it is not possible. You can print each letter in any case (upper or lower).

NoteThe examples are explained below.  Example 1.   Example 2.   Example 3.

package main

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

func main() {
	var wg sync.WaitGroup
	var n, m, x, cnt, flag int
	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)
	fmt.Fscanln(scr, &n, &m)

	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
	}
	B := make([][]int, n)
	for i := 0; i < n; i++ {
		B[i] = make([]int, m)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(scr, "%d", &A[i][j])
		}
		fmt.Fscanln(scr, &x)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(scr, "%d", &B[i][j])
		}
		fmt.Fscanln(scr, &x)
	}
	wg.Add(1)
	go right(A, B, &flag, n, m, &wg)

	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if A[j][i] != B[j][i] {
				cnt++
			}
		}
		if cnt%2 != 0 {
			flag = 2
			break
		}
	}
	wg.Wait()
	if flag == 2 {
		fmt.Fprintln(ocr, "NO")
		ocr.Flush()
	} else {
		fmt.Fprintln(ocr, "YES")
		ocr.Flush()
	}
}

func right(A, B [][]int, flag *int, n, m int, wg *sync.WaitGroup) {
	defer wg.Done()
	var cnt int
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if A[i][j] != B[i][j] {
				cnt++
			}
		}
		if cnt%2 != 0 {
			*flag = 2
			break
		}
	}
}

package main

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

func main() {
	var n, m, x, cnt, flag int
	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)
	fmt.Fscanln(scr, &n, &m)

	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
	}
	B := make([][]int, n)
	for i := 0; i < n; i++ {
		B[i] = make([]int, m)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(scr, "%d", &A[i][j])
		}
		fmt.Fscanln(scr, &x)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(scr, "%d", &B[i][j])
		}
		fmt.Fscanln(scr, &x)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if A[i][j] != B[i][j] {
				cnt++
			}
		}
		if cnt%2 != 0 {
			flag = 2
			break
		}
	}

	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if A[j][i] != B[j][i] {
				cnt++
			}
		}
		if cnt%2 != 0 {
			flag = 2
			break
		}
	}
	if flag == 2 {
		fmt.Fprintln(ocr, "NO")
		ocr.Flush()
	} else {
		fmt.Fprintln(ocr, "YES")
		ocr.Flush()
	}
}

package main

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

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

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

	rowsA := make([]int, n)
	colsA := make([]int, m)
	for i := range rowsA {
		for j := range colsA {
			var val int
			fmt.Fscan(in, &val)

			rowsA[i] ^= val
			colsA[j] ^= val
		}
		in.ReadLine()
	}

	rowsB := make([]int, n)
	colsB := make([]int, m)
	for i := range rowsB {
		for j := range colsB {
			var val int
			fmt.Fscan(in, &val)

			rowsB[i] ^= val
			colsB[j] ^= val
		}
		in.ReadLine()
	}

	for i := 0; i < n; i++ {
		if rowsA[i] != rowsB[i] {
			//fmt.Println("rows:", i, rowsA[i], rowsB[i])
			fmt.Println("No")
			return
		}
	}
	for i := 0; i < m; i++ {
		if colsA[i] != colsB[i] {
			//fmt.Println("cols:", i, colsA[i], colsB[i])
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}

package main

import (
	"fmt"
)

func main() {
	var n, m, x, cnt, flag int
	fmt.Scanln(&n, &m)

	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
	}
	B := make([][]int, n)
	for i := 0; i < n; i++ {
		B[i] = make([]int, m)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Scanf("%d", &A[i][j])
		}
		fmt.Scanf("&d", &x)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Scanf("%d", &B[i][j])
		}
		fmt.Scanf("&d", &x)
	}

	go right(A, B, &flag, n, m)

	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if A[j][i] != B[j][i] {
				cnt++
			}
		}
		if cnt%2 != 0 {
			flag = 2
			break
		}
	}
	if flag == 2 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

func right(A, B [][]int, flag *int, n, m int) {
	var cnt int
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if A[i][j] != B[i][j] {
				cnt++
			}
		}
		if cnt%2 != 0 {
			*flag = 2
			break
		}
	}
}

package main

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

func main() {
	var wg sync.WaitGroup
	var n, m, x, cnt, flag int
	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)
	fmt.Fscanln(scr, &n, &m)

	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
	}
	B := make([][]int, n)
	for i := 0; i < n; i++ {
		B[i] = make([]int, m)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(scr, "%d", &A[i][j])
		}
		fmt.Fscanln(scr, &x)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(scr, "%d", &B[i][j])
		}
		fmt.Fscanln(scr, &x)
	}
	fmt.Println(A, B)
	wg.Add(1)
	go right(A, B, &flag, n, m, &wg)

	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if A[j][i] != B[j][i] {
				cnt++
			}
		}
		if cnt%2 != 0 {
			flag = 2
			break
		}
	}
	wg.Wait()
	if flag == 2 {
		fmt.Fprintln(ocr, "NO")
		ocr.Flush()
	} else {
		fmt.Fprintln(ocr, "YES")
		ocr.Flush()
	}
}

func right(A, B [][]int, flag *int, n, m int, wg *sync.WaitGroup) {
	defer wg.Done()
	var cnt int
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if A[i][j] != B[i][j] {
				cnt++
			}
		}
		if cnt%2 != 0 {
			*flag = 2
			break
		}
	}
}

package main

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

func main() {
	var wg sync.WaitGroup
	var n, m, x, cnt, flag int
	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)
	fmt.Fscanln(scr, &n, &m)

	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
	}
	B := make([][]int, n)
	for i := 0; i < n; i++ {
		B[i] = make([]int, m)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(scr, "%d", &A[i][j])
		}
		fmt.Fscanf(scr, "&d", &x)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(scr, "%d", &B[i][j])
		}
		fmt.Fscanf(scr, "&d", &x)
	}

	wg.Add(1)
	go right(A, B, &flag, n, m, &wg)

	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if A[j][i] != B[j][i] {
				cnt++
			}
		}
		if cnt%2 != 0 {
			flag = 2
			break
		}
	}
	wg.Wait()
	if flag == 2 {
		fmt.Fprintln(ocr, "NO")
	} else {
		fmt.Fprintln(ocr, "YES")
	}
	ocr.Flush()
}

func right(A, B [][]int, flag *int, n, m int, wg *sync.WaitGroup) {
	defer wg.Done()
	var cnt int
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if A[i][j] != B[i][j] {
				cnt++
			}
		}
		if cnt%2 != 0 {
			*flag = 2
			break
		}
	}
}


Grigory has $$$n$$$ magic stones, conveniently numbered from $$$1$$$ to $$$n$$$. The charge of the $$$i$$$-th stone is equal to $$$c_i$$$.Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $$$i$$$, where $$$2 \le i \le n - 1$$$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $$$c_i$$$ changes to $$$c_i' = c_{i + 1} + c_{i - 1} - c_i$$$.Andrew, Grigory's friend, also has $$$n$$$ stones with charges $$$t_i$$$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $$$c_i$$$ into $$$t_i$$$ for all $$$i$$$?

The first line contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of magic stones. The second line contains integers $$$c_1, c_2, \ldots, c_n$$$ ($$$0 \le c_i \le 2 \cdot 10^9$$$) — the charges of Grigory's stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$0 \le t_i \le 2 \cdot 10^9$$$) — the charges of Andrew's stones.

If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No".

NoteIn the first example, we can perform the following synchronizations ($$$1$$$-indexed):  First, synchronize the third stone $$$[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$$$.  Then synchronize the second stone: $$$[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$$$. In the second example, any operation with the second stone will not change its charge.

package main

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

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

func main() {
	var n int
	fmt.Fscan(in, &n)
	c := make([]int, n)
	for i := range c {
		fmt.Fscan(in, &c[i])
	}
	t := make([]int, n)
	for i := range t {
		fmt.Fscan(in, &t[i])
	}

	if c[0] != t[0] {
		fmt.Println("No")
		return
	}

	cd := make(map[int]int)
	for i := range c[1:] {
		cd[c[i+1]-c[i]]++
	}

	td := make(map[int]int)
	for i := range t[1:] {
		td[t[i+1]-t[i]]++
	}

	if reflect.DeepEqual(cd, td) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n ,first,last int
	fmt.Fscanf(buf, "%d\n", &n)
	var pre = -1
	cmap := make(map[int]int)
	for i := 0; i < n; i++ {
		var v int
		fmt.Fscanf(buf, "%d", &v)
		if i == 0 {
			pre = v
			first = v
			continue
		}
		if i == n-1{
			last = v
		}
		cmap[v-pre] = cmap[v-pre] + 1
		pre = v
	}
	fmt.Fscanf(buf, "\n")
	ans := true
	for i := 0; i < n; i++ {
		var v int
		fmt.Fscanf(buf, "%d", &v)
		if ans == false{
			continue
		}
		if i == 0 {
			pre = v
			if v != first{
				ans = false
			}
			continue
		}
		if i == n-1&&last != v{
			ans = false
		}
		cmap[v-pre] = cmap[v-pre] - 1
		if cmap[v-pre] < 0{
			ans = false
		}else if cmap[v-pre]==0{
			delete(cmap,v-pre)
		}
		pre = v
	}
	if len(cmap) > 0{
		ans = false
	}
	if ans {
		fmt.Printf("Yes\n")
	} else {
		fmt.Printf("No\n")
	}

}
/**
3
1 3 4
2 4 5
 */

package main

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

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

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

func Println(a ...interface{}) {
	fmt.Println(a...)
}

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

func main() {
	var n int
	scan(&n)
	c:=make([]int,n)
	t:=make([]int,n)
	for i:=0;i<n;i++{
		scan(&c[i])
	}
	for i:=0;i<n;i++{
		scan(&t[i])
	}
	if c[0]!=t[0] {
		Println("No")
		return
	}
	for i:=0;i<n-1;i++{
		c[i]=c[i+1]-c[i]
		t[i]=t[i+1]-t[i]
	}
	c=c[:n-1]
	t=t[:n-1]
	sort.Ints(c)
	sort.Ints(t)
	for i:=0;i<n-1;i++{
		if c[i]!=t[i]{
			Println("No")
			return
		}
	}
	Println("Yes")
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1110E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, p, v int
	Fscan(in, &n, &p)
	p0 := p
	c := make(map[int]int, n-1)
	for i := 1; i < n; i++ {
		Fscan(in, &v)
		c[v-p]++
		p = v
	}
	Fscan(in, &p)
	if p != p0 {
		Fprint(out, "No")
		return
	}
	for n--; n > 0; n-- {
		Fscan(in, &v)
		c[v-p]--
		p = v
	}
	for _, v := range c {
		if v != 0 {
			Fprint(out, "No")
			return
		}
	}
	Fprint(out, "Yes")
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n, p, v int
	Fscan(in, &n, &p)
	p0 := p
	c := make(map[int]int, n-1)
	for i := 1; i < n; i++ {
		Fscan(in, &v)
		c[v-p]++
		p = v
	}
	Fscan(in, &p)
	if p != p0 {
		Print("No")
		return
	}
	for n--; n > 0; n-- {
		Fscan(in, &v)
		c[v-p]--
		p = v
	}
	for _, v := range c {
		if v != 0 {
			Print("No")
			return
		}
	}
	Print("Yes")
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n, p, v int
	Fscan(in, &n, &p)
	p0 := p
	c := map[int]int{}
	for i := 1; i < n; i++ {
		Fscan(in, &v)
		c[v-p]++
		p = v
	}
	Fscan(in, &p)
	if p != p0 {
		Print("No")
		return
	}
	for n--; n > 0; n-- {
		Fscan(in, &v)
		c[v-p]--
		p = v
	}
	for _, v := range c {
		if v != 0 {
			Print("No")
			return
		}
	}
	Print("Yes")
}

package main

import (
	"bufio"
	"flag"
	"fmt"
	"io"
	"math/big"
	"os"
	"sort"
)

var reader *bufio.Reader
var writer *bufio.Writer

var inputFile = flag.String("input", "", "")

func init() {
	flag.Parse()
	var i io.Reader
	if *inputFile != "" {
		i, _ = os.Open(*inputFile)
	} else {
		i = os.Stdin
	}
	reader = bufio.NewReaderSize(i, 1<<20)
	writer = bufio.NewWriterSize(os.Stdout, 1<<20)
}

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

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

func scanf(format string, a ...interface{}) {
	_, _ = fmt.Fscanf(reader, format, a...)
}

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

func NextInt64() int64 {
	var res int64
	scan(&res)
	return res
}

func NextInt() int {
	var res int
	scan(&res)
	return res
}

func NextIntArray(n int) []int {
	res := make([]int, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextString() string {
	var res string
	scan(&res)
	return res
}

func NextBigInt() *big.Int {
	n := new(big.Int)
	n, _ = n.SetString(NextString(), 10)
	return n
}

func main() {
	defer writer.Flush()

	n := NextInt()

	s := NextIntArray(n)
	t := NextIntArray(n)

	if s[0] != t[0] || s[n - 1] != t[n - 1] {
		println("No")
		return
	}

	var u, v []int

	for i := 0; i + 1 < n; i++ {
		u = append(u, s[i + 1] - s[i])
		v = append(v, t[i + 1] - t[i])
	}

	sort.Ints(u)
	sort.Ints(v)

	for i, x := range u {
		if v[i] != x {
			println("No")
			return
		}
	}

	println("Yes")

}

package main

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

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

func main() {
	var n int
	fmt.Fscan(in, &n)
	c := make([]int64, n)
	for i := range c {
		fmt.Fscan(in, &c[i])
	}
	t := make([]int64, n)
	for i := range t {
		fmt.Fscan(in, &t[i])
	}

	for i := 0; i < n; i++ {
		if c[i] == t[i] {
			continue
		}
		if i == 0 || i == n-1 {
			fmt.Println("No")
			return
		}
		if c[i-1]+c[i+1]-c[i] == t[i] {
			c[i] = t[i]
			i -= 2
		}
	}
	for i := range c {
		if c[i] != t[i] {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1110E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, p, v int
	Fscan(in, &n, &p)
	c := make(map[int]int, n-1)
	for i := 1; i < n; i++ {
		Fscan(in, &v)
		c[v-p]++
		p = v
	}
	Fscan(in, &p)
	for n--; n > 0; n-- {
		Fscan(in, &v)
		c[v-p]--
		p = v
	}
	for _, v := range c {
		if v != 0 {
			Fprint(out, "No")
			return
		}
	}
	Fprint(out, "Yes")
}

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