$$$n$$$ people live on the coordinate line, the $$$i$$$-th one lives at the point $$$x_i$$$ ($$$1 \le i \le n$$$). They want to choose a position $$$x_0$$$ to meet. The $$$i$$$-th person will spend $$$|x_i - x_0|$$$ minutes to get to the meeting place. Also, the $$$i$$$-th person needs $$$t_i$$$ minutes to get dressed, so in total he or she needs $$$t_i + |x_i - x_0|$$$ minutes. Here $$$|y|$$$ denotes the absolute value of $$$y$$$.These people ask you to find a position $$$x_0$$$ that minimizes the time in which all $$$n$$$ people can gather at the meeting place.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. Then the test cases follow. Each test case consists of three lines. The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of people.  The second line contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$0 \le x_i \le 10^{8}$$$) — the positions of the people. The third line contains $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$0 \le t_i \le 10^{8}$$$), where $$$t_i$$$ is the time $$$i$$$-th person needs to get dressed. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single real number — the optimum position $$$x_0$$$. It can be shown that the optimal position $$$x_0$$$ is unique. Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{−6}$$$. Formally, let your answer be $$$a$$$, the jury's answer be $$$b$$$. Your answer will be considered correct if $$$\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$$$.

Note  In the $$$1$$$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $$$3$$$ minutes, that he or she need to get dressed.  In the $$$2$$$-nd test case there are $$$2$$$ people who don't need time to get dressed. Each of them needs one minute to get to position $$$2$$$.  In the $$$5$$$-th test case the $$$1$$$-st person needs $$$4$$$ minutes to get to position $$$1$$$ ($$$4$$$ minutes to get dressed and $$$0$$$ minutes on the way); the $$$2$$$-nd person needs $$$2$$$ minutes to get to position $$$1$$$ ($$$1$$$ minute to get dressed and $$$1$$$ minute on the way); the $$$3$$$-rd person needs $$$4$$$ minutes to get to position $$$1$$$ ($$$2$$$ minutes to get dressed and $$$2$$$ minutes on the way).

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

// 1730B - Meeting on the Line

// n  people live on the coordinate line, the i-th one lives at the point xi (1≤i≤n). They want to choose a position x0 to meet. The i-th person will spend |xi−x0| minutes to get to the meeting place. Also, the i-th person needs ti minutes to get dressed, so in total he or she needs ti+|xi−x0| minutes.
// Here |y| denotes the absolute value of y.
// These people ask you to find a position x0 that minimizes the time in which all n people can gather at the meeting place.

// Input
// The first line contains a single integer t (1≤t≤10^3) — the number of test cases. Then the test cases follow.
// Each test case consists of three lines.
// The first line contains a single integer n (1≤n≤10^5) — the number of people.
// The second line contains n integers x1,x2,…,xn (0≤xi≤10^8) — the positions of the people.
// The third line contains n integers t1,t2,…,tn (0≤ti≤10^8), where ti is the time i-th person needs to get dressed.
// It is guaranteed that the sum of n over all test cases does not exceed 2⋅10^5.

// Output
// For each test case, print a single real number — the optimum position x0. It can be shown that the optimal position x0 is unique.
// Your answer will be considered correct if its absolute or relative error does not exceed 10^−6. Formally, let your answer be a, the jury's answer be b. Your answer will be considered correct if |a−b|/max(1,|b|)≤10^−6.

// Example
// 7
// 1
// 0
// 3
// 2
// 3 1
// 0 0
// 2
// 1 4
// 0 0
// 3
// 1 2 3
// 0 0 0
// 3
// 1 2 3
// 4 1 2
// 3
// 3 3 3
// 5 3 3
// 6
// 5 4 7 2 10 4
// 3 2 5 1 4 6
// output
// 0
// 2
// 2.5
// 2
// 1
// 3
// 6

// Note

//  • In the 1-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in 3 minutes, that he or she need to get dressed.
//  • In the 2-nd test case there are 2 people who don't need time to get dressed. Each of them needs one minute to get to position 2.
//  • In the 5-th test case the 1-st person needs 4 minutes to get to position 1 (4 minutes to get dressed and 0 minutes on the way); the 2-nd person needs 2 minutes to get to position 1 (1 minute to get dressed and 1 minute on the way); the 3-rd person needs 4 minutes to get to position 1 (2 minutes to get dressed and 2 minutes on the way).

// Tutorial

// There are many solutions to this problem, here are 2 of them.
// 1) Let people be able to meet in time T, then they could meet in time T+ε, where ε>0. So we can find T by binary search. It remains to learn how to check whether people can meet for a specific time T. To do this, for the i-th person, find a segment of positions that he can get to in time T: if T<ti then this segment is empty, otherwise it is [xi−(T−ti),xi+(T−ti)]. Then people will be able to meet only if these segments intersect, that is, the minimum of the right borders is greater than or equal to the maximum of the left borders. In order to find the answer by the minimum T, you need to intersect these segments in the same way (should get a point, but due to accuracy, most likely, a segment of a very small length will turn out) and take any point of this intersection. Asymptotics is O(nlogn).
// 2) If all ti were equal to 0, then this would be a classical problem, the solution of which would be to find the average of the minimum and maximum coordinates of people. We can reduce our problem to this one if we replace the person (xi, ti) with two people: (xi−ti, 0) and (xi+ti, 0). Proof. Let the meeting be at the point y. Let xi≤y. Then this person will need ti+y−xi of time to get to her, and the two we want to replace him with — y−xi+ti and y−xi−ti. it is easy to see that the first value is equal to the initial value, and the second is not greater than the initial value, then the maximum of these two values is equal to the initial value. The proof is similar for the case y≤xi. Then for any meeting point, the time in the original problem and after the replacement does not differ, which means that such a replacement will not change the answer and it can be done. Asymptotics is O(n).

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() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var s, c, n, i, mn, mx, sum int
	var x, t []int

	for s, _ = fmt.Fscan(reader, &c); s == 1; s, _ = fmt.Fscan(reader, &c) {
		for ; c > 0; c-- {
			fmt.Fscan(reader, &n)
			x = make([]int, n)
			t = make([]int, n)

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

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

			mn, mx = x[0]+t[0], x[0]-t[0]

			for i = 0; i < n; i++ {
				mn = min(mn, x[i]-t[i])
				mx = max(mx, x[i]+t[i])
			}

			sum = mn + mx
			fmt.Fprint(writer, sum>>1)

			if sum&1 == 1 {
				fmt.Fprint(writer, ".5")
			}

			fmt.Fprintln(writer)
		}
	}

	writer.Flush()
}

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

// 1730B - Meeting on the Line

// n  people live on the coordinate line, the i-th one lives at the point xi (1≤i≤n). They want to choose a position x0 to meet. The i-th person will spend |xi−x0| minutes to get to the meeting place. Also, the i-th person needs ti minutes to get dressed, so in total he or she needs ti+|xi−x0| minutes.
// Here |y| denotes the absolute value of y.
// These people ask you to find a position x0 that minimizes the time in which all n people can gather at the meeting place.

// Input
// The first line contains a single integer t (1≤t≤10^3) — the number of test cases. Then the test cases follow.
// Each test case consists of three lines.
// The first line contains a single integer n (1≤n≤10^5) — the number of people.
// The second line contains n integers x1,x2,…,xn (0≤xi≤10^8) — the positions of the people.
// The third line contains n integers t1,t2,…,tn (0≤ti≤10^8), where ti is the time i-th person needs to get dressed.
// It is guaranteed that the sum of n over all test cases does not exceed 2⋅10^5.

// Output
// For each test case, print a single real number — the optimum position x0. It can be shown that the optimal position x0 is unique.
// Your answer will be considered correct if its absolute or relative error does not exceed 10^−6. Formally, let your answer be a, the jury's answer be b. Your answer will be considered correct if |a−b|/max(1,|b|)≤10^−6.

// Example
// 7
// 1
// 0
// 3
// 2
// 3 1
// 0 0
// 2
// 1 4
// 0 0
// 3
// 1 2 3
// 0 0 0
// 3
// 1 2 3
// 4 1 2
// 3
// 3 3 3
// 5 3 3
// 6
// 5 4 7 2 10 4
// 3 2 5 1 4 6
// output
// 0
// 2
// 2.5
// 2
// 1
// 3
// 6

// Note

//  • In the 1-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in 3 minutes, that he or she need to get dressed.
//  • In the 2-nd test case there are 2 people who don't need time to get dressed. Each of them needs one minute to get to position 2.
//  • In the 5-th test case the 1-st person needs 4 minutes to get to position 1 (4 minutes to get dressed and 0 minutes on the way); the 2-nd person needs 2 minutes to get to position 1 (1 minute to get dressed and 1 minute on the way); the 3-rd person needs 4 minutes to get to position 1 (2 minutes to get dressed and 2 minutes on the way).

// Tutorial

// There are many solutions to this problem, here are 2 of them.
// 1) Let people be able to meet in time T, then they could meet in time T+ε, where ε>0. So we can find T by binary search. It remains to learn how to check whether people can meet for a specific time T. To do this, for the i-th person, find a segment of positions that he can get to in time T: if T<ti then this segment is empty, otherwise it is [xi−(T−ti),xi+(T−ti)]. Then people will be able to meet only if these segments intersect, that is, the minimum of the right borders is greater than or equal to the maximum of the left borders. In order to find the answer by the minimum T, you need to intersect these segments in the same way (should get a point, but due to accuracy, most likely, a segment of a very small length will turn out) and take any point of this intersection. Asymptotics is O(nlogn).
// 2) If all ti were equal to 0, then this would be a classical problem, the solution of which would be to find the average of the minimum and maximum coordinates of people. We can reduce our problem to this one if we replace the person (xi, ti) with two people: (xi−ti, 0) and (xi+ti, 0). Proof. Let the meeting be at the point y. Let xi≤y. Then this person will need ti+y−xi of time to get to her, and the two we want to replace him with — y−xi+ti and y−xi−ti. it is easy to see that the first value is equal to the initial value, and the second is not greater than the initial value, then the maximum of these two values is equal to the initial value. The proof is similar for the case y≤xi. Then for any meeting point, the time in the original problem and after the replacement does not differ, which means that such a replacement will not change the answer and it can be done. Asymptotics is O(n).

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var s, c, n, i, min, max, sum int
	var x, t []int

	for s, _ = fmt.Fscan(reader, &c); s == 1; s, _ = fmt.Fscan(reader, &c) {
		for ; c > 0; c-- {
			fmt.Fscan(reader, &n)
			x = make([]int, n)
			t = make([]int, n)

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

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

			min, max = x[0]+t[0], x[0]-t[0]

			for i = 0; i < n; i++ {
				if min > x[i]-t[i] {
					min = x[i] - t[i]
				}

				if max < x[i]+t[i] {
					max = x[i] + t[i]
				}
			}

			sum = min + max
			fmt.Fprint(writer, sum>>1)

			if sum&1 == 1 {
				fmt.Fprint(writer, ".5")
			}

			fmt.Fprintln(writer)
		}
	}

	writer.Flush()
}

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

// 1730B - Meeting on the Line

// n  people live on the coordinate line, the i-th one lives at the point xi (1≤i≤n). They want to choose a position x0 to meet. The i-th person will spend |xi−x0| minutes to get to the meeting place. Also, the i-th person needs ti minutes to get dressed, so in total he or she needs ti+|xi−x0| minutes.
// Here |y| denotes the absolute value of y.
// These people ask you to find a position x0 that minimizes the time in which all n people can gather at the meeting place.

// Input
// The first line contains a single integer t (1≤t≤10^3) — the number of test cases. Then the test cases follow.
// Each test case consists of three lines.
// The first line contains a single integer n (1≤n≤10^5) — the number of people.
// The second line contains n integers x1,x2,…,xn (0≤xi≤10^8) — the positions of the people.
// The third line contains n integers t1,t2,…,tn (0≤ti≤10^8), where ti is the time i-th person needs to get dressed.
// It is guaranteed that the sum of n over all test cases does not exceed 2⋅10^5.

// Output
// For each test case, print a single real number — the optimum position x0. It can be shown that the optimal position x0 is unique.
// Your answer will be considered correct if its absolute or relative error does not exceed 10^−6. Formally, let your answer be a, the jury's answer be b. Your answer will be considered correct if |a−b|/max(1,|b|)≤10^−6.

// Example
// 7
// 1
// 0
// 3
// 2
// 3 1
// 0 0
// 2
// 1 4
// 0 0
// 3
// 1 2 3
// 0 0 0
// 3
// 1 2 3
// 4 1 2
// 3
// 3 3 3
// 5 3 3
// 6
// 5 4 7 2 10 4
// 3 2 5 1 4 6
// output
// 0
// 2
// 2.5
// 2
// 1
// 3
// 6

// Note

//  • In the 1-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in 3 minutes, that he or she need to get dressed.
//  • In the 2-nd test case there are 2 people who don't need time to get dressed. Each of them needs one minute to get to position 2.
//  • In the 5-th test case the 1-st person needs 4 minutes to get to position 1 (4 minutes to get dressed and 0 minutes on the way); the 2-nd person needs 2 minutes to get to position 1 (1 minute to get dressed and 1 minute on the way); the 3-rd person needs 4 minutes to get to position 1 (2 minutes to get dressed and 2 minutes on the way).

// Tutorial

// There are many solutions to this problem, here are 2 of them.
// 1) Let people be able to meet in time T, then they could meet in time T+ε, where ε>0. So we can find T by binary search. It remains to learn how to check whether people can meet for a specific time T. To do this, for the i-th person, find a segment of positions that he can get to in time T: if T<ti then this segment is empty, otherwise it is [xi−(T−ti),xi+(T−ti)]. Then people will be able to meet only if these segments intersect, that is, the minimum of the right borders is greater than or equal to the maximum of the left borders. In order to find the answer by the minimum T, you need to intersect these segments in the same way (should get a point, but due to accuracy, most likely, a segment of a very small length will turn out) and take any point of this intersection. Asymptotics is O(nlogn).
// 2) If all ti were equal to 0, then this would be a classical problem, the solution of which would be to find the average of the minimum and maximum coordinates of people. We can reduce our problem to this one if we replace the person (xi, ti) with two people: (xi−ti, 0) and (xi+ti, 0). Proof. Let the meeting be at the point y. Let xi≤y. Then this person will need ti+y−xi of time to get to her, and the two we want to replace him with — y−xi+ti and y−xi−ti. it is easy to see that the first value is equal to the initial value, and the second is not greater than the initial value, then the maximum of these two values is equal to the initial value. The proof is similar for the case y≤xi. Then for any meeting point, the time in the original problem and after the replacement does not differ, which means that such a replacement will not change the answer and it can be done. Asymptotics is O(n).

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var s, c, n, i, min, max, sum int
	var x, t, v []int

	for s, _ = fmt.Fscan(reader, &c); s == 1; s, _ = fmt.Fscan(reader, &c) {
		for ; c > 0; c-- {
			fmt.Fscan(reader, &n)
			x = make([]int, n)
			t = make([]int, n)
			v = make([]int, 2*n)

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

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

			for i = 0; i < n; i++ {
				v[2*i] = x[i] - t[i]
				v[2*i+1] = x[i] + t[i]
			}

			min, max = v[0], v[0]

			for i = 1; i < 2*n; i++ {
				if min > v[i] {
					min = v[i]
				}

				if max < v[i] {
					max = v[i]
				}
			}

			sum = min + max
			fmt.Fprint(writer, sum>>1)

			if sum&1 == 1 {
				fmt.Fprint(writer, ".5")
			}

			fmt.Fprintln(writer)
		}
	}

	writer.Flush()
}

package main

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

func dc(l, r float64, X []float64, T []float64, x0 float64) float64 {
	if r - l < 1e-6 { return x0 }

	var m, maxl, minr float64
	m = (l + r) / 2
	maxl = 0
	minr = 1e13

	for i := range X {
		cl := X[i]
		if T[i] < m { cl = X[i] + T[i] - m }
		if cl > maxl { maxl = cl }

		cr := X[i]
		if T[i] < m { cr = X[i] - T[i] + m }
		if cr < minr { minr = cr }
	}

	if maxl < minr {
		return dc(l, m, X, T, maxl)
	} else {
		return dc(m, r, X, T, maxl)
	}
}

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

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

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

		X := make([]float64, n)
		for i := range X { fmt.Fscan(r, &X[i]) }

		T := make([]float64, n)
		for i := range T { fmt.Fscan(r, &T[i]) }

		fmt.Fprintf(w, "%.7f\n", dc(1e-7, 1e12, X, T, 0))
	}

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"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() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

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

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

		a, z := math.MaxInt32, 0
		for i := range aa {
			a = min(a, aa[i]-bb[i])
			z = max(z, aa[i]+bb[i])
		}

		fmt.Fprintln(out, (float64(a)+float64(z))/2)
	}
}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	x := make([]int, n)
	var mn, mx int = 1e10, -1e10
	for i := range x {
		fmt.Fscan(in, &x[i])
	}
	var num int
	for i := range x {
		fmt.Fscan(in, &num)
		mn = min(mn, x[i]-num)
		mx = max(mx, x[i]+num)
	}
	fmt.Fprintln(out, float64(mx+mn)/2.)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

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

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

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

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

		type p struct {
			x, z int
		}
		aa := make([]p, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i].x)
		}

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i].z)
		}
		sort.Slice(aa, func(i, j int) bool {
			if aa[i].x == aa[j].x {
				return aa[i].z < aa[j].z
			}
			return aa[i].x < aa[j].x
		})
		var lm, rm int
		d := (aa[0].x + aa[n-1].x) / 2
		for _, p2 := range aa {
			if p2.x <= d && abs(p2.x-d)+p2.z > lm {
				lm = abs(p2.x-d) + p2.z
			} else if p2.x > d && abs(p2.x-d)+p2.z > rm {
				rm = abs(p2.x-d) + p2.z
			}
		}

		if lm == rm || lm == 0 || rm == 0 {
			fmt.Fprintln(out, d)
		} else if rm > lm {
			x := (float64(rm) - float64(lm)) / 2
			g := float64(d) + x
			if int(g) > aa[n-1].x {
				g = float64(aa[n-1].x)
			}
			fmt.Fprintln(out, g)
		} else {
			x := (float64(lm) - float64(rm)) / 2
			g := float64(d) - x
			if int(g) < aa[0].x {
				g = float64(aa[0].x)
			}
			fmt.Fprintln(out, g)
		}
	}
}


Student Dima from Kremland has a matrix $$$a$$$ of size $$$n \times m$$$ filled with non-negative integers.He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!Formally, he wants to choose an integers sequence $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \leq c_j \leq m$$$) so that the inequality $$$a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$$$ holds, where $$$a_{i, j}$$$ is the matrix element from the $$$i$$$-th row and the $$$j$$$-th column.Here $$$x \oplus y$$$ denotes the bitwise XOR operation of integers $$$x$$$ and $$$y$$$.

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 the matrix $$$a$$$. Each of the next $$$n$$$ lines contains $$$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$$$, i.e. $$$a_{i, j}$$$ ($$$0 \leq a_{i, j} \leq 1023$$$).

If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE". Otherwise print "TAK" in the first line, in the next line print $$$n$$$ integers $$$c_1, c_2, \ldots c_n$$$ ($$$1 \leq c_j \leq m$$$), so that the inequality $$$a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$$$ holds.  If there is more than one possible answer, you may output any.

NoteIn the first example, all the numbers in the matrix are $$$0$$$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.In the second example, the selected numbers are $$$7$$$ (the first number in the first line) and $$$10$$$ (the third number in the second line), $$$7 \oplus 10 = 13$$$, $$$13$$$ is more than $$$0$$$, so the answer is found.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	a := make([][]int, n)
	diffRow := -1
	col := 0
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Fscanf(in, "%d", &a[i][j])
		}

		for j := 1; j < m; j++ {
			if a[i][j] != a[i][j-1] {
				diffRow = i
				col = j
				break
			}
		}
		fmt.Fscanf(in, "\n")
	}
	tmp := 0
	for i := 0; i < n; i++ {
		tmp ^= a[i][0]
	}
	if tmp > 0 {
		fmt.Fprintf(out, "TAK\n")
		for i := 0; i < n-1; i++ {
			fmt.Fprintf(out, "%d ", 1)
		}
		fmt.Fprintf(out, "%d\n", 1)
		return
	}
	if diffRow == -1 {
		fmt.Fprintf(out, "NIE\n")
		return
	}
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		if i != diffRow {
			ans[i] = 1
		} else {
			ans[i] = col + 1
		}
	}
	fmt.Fprintf(out, "TAK\n")
	for i := 0; i < n-1; i++ {
		fmt.Fprintf(out, "%d ", ans[i])
	}
	fmt.Fprintf(out, "%d\n", ans[n-1])
	return
}

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

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

package main

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

/*

The first line contains two integers 𝑛 and 𝑚 (1≤𝑛,𝑚≤500) — the number of rows and the number of columns in the matrix 𝑎.

inputCopy
3 2
0 0
0 0
0 0
outputCopy
NIE

inputCopy
2 3
7 7 7
7 7 10
outputCopy
TAK
1 3

1 2 3
4 5 6
7 8 9

*/

type Solver struct {
	a     [][]int
	n     int
	m     int
	Path  []int
	Found bool
}

func (s *Solver) pushPath(i int) {
	if s.Found == true {
		return
	}

	s.Path = append(s.Path, i)
}

func (s *Solver) popPath() (p int) {
	if s.Found == true {
		return
	}

	p, s.Path = s.Path[len(s.Path)-1], s.Path[:len(s.Path)-1]
	return
}

func (s *Solver) Result() {
	if !s.Found {
		fmt.Println("NIE")
		return
	}
	fmt.Println("TAK")
	fmt.Println(strings.Trim(fmt.Sprint(s.Path), "[]"))
	return
}

func (s *Solver) Search(res, depth int) {
	searched := map[int]bool{}

	for i := 0; i < s.m; i++ {
		if s.Found == true {
			break
		}

		cur_var := s.a[depth][i]

		// check if searched
		if searched[cur_var] {
			continue
		}
		searched[cur_var] = true

		s.pushPath(i + 1)
		if depth == s.n-1 {
			s.Found = (cur_var^res > 0)
		} else {
			s.Search(cur_var^res, depth+1)
		}
		s.popPath()
	}
}

func ScanNum(s *bufio.Scanner) (int, error) {
	s.Scan()
	return strconv.Atoi(s.Text())
}

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

	s.Split(bufio.ScanWords)
	n, _ := ScanNum(s)
	m, _ := ScanNum(s)
	a := [][]int{}

	for i := 0; i < n; i++ {
		a = append(a, make([]int, m))
		for j := 0; j < m; j++ {
			a[i][j], _ = ScanNum(s)
		}
	}

	ss := Solver{
		a: a,
		n: n,
		m: m,
	}
	ss.Search(0, 0)
	ss.Result()
}

package main

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

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

	var n, m, di, dj int
	Fscan(in, &n, &m)
	mat := make([][]uint16, n)
	sum := uint16(0)
	for i := range mat {
		mat[i] = make([]uint16, m)
		for j := range mat[i] {
			Fscan(in, &mat[i][j])
			if mat[i][j] != mat[i][0] {
				di, dj = i, j
			}
		}
		sum ^= mat[i][0]
	}
	ans := make([]interface{}, n)
	for i := range ans {
		ans[i] = 1
	}
	if sum == 0 {
		if dj == 0 {
			Fprint(out, "NIE")
			return
		}
		ans[di] = dj + 1
	}
	Fprintln(out, "TAK")
	Fprint(out, ans...)
}

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

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

package main

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

func Solve(n, m int, a [][]int) []int {
	x := 0
	for i := 0; i < n; i++ {
		x ^= a[i][0]
	}
	if x > 0 {
		ans := make([]int, n)
		for i := 0; i < n; i++ {
			ans[i] = 1
		}
		return ans
	}
	if x == 0 {
		row := -1
		col := -1
		for i := 0; i < n; i++ {
			for j := 1; j < m; j++ {
				if a[i][j] != a[i][0] {
					row = i
					col = j + 1
				}
			}
		}
		if row != -1 && col != -1 {
			ans := make([]int, n)
			for i := 0; i < n; i++ {
				ans[i] = 1
			}
			ans[row] = col
			return ans
		}
	}
	return []int{}
}

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

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

	ans := Solve(n, m, a)
	if len(ans) > 0 {
		fmt.Fprintf(writer, "TAK\n")
		for _, elem := range ans {
			fmt.Fprintf(writer, "%d ", elem)
		}
	} else {
		fmt.Fprintf(writer, "NIE\n")
	}
}


You've got an array, consisting of n integers a1, a2, ..., an. Also, you've got m queries, the i-th query is described by two integers li, ri. Numbers li, ri define a subsegment of the original array, that is, the sequence of numbers ali, ali + 1, ali + 2, ..., ari. For each query you should check whether the corresponding segment is a ladder. A ladder is a sequence of integers b1, b2, ..., bk, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b1 ≤ b2 ≤ ... ≤ bx ≥ bx + 1 ≥ bx + 2... ≥ bk. Note that the non-decreasing and the non-increasing sequences are also considered ladders.

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of array elements and the number of queries. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where number ai stands for the i-th array element. The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers li, ri (1 ≤ li ≤ ri ≤ n) — the boundaries of the subsegment of the initial array. The numbers in the lines are separated by single spaces.

Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.

package main

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

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

	var n, q, l, r int
	Fscan(in, &n, &q)
	a := make([]int, n+2)
	sameL := make([]int, n+1)
	sameLI := 0
	prev := make([]int, n+1)
	isAsc := true
	changeI := 0
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		if a[i] != a[i-1] {
			sameLI = i
		}
		sameL[i] = sameLI
		if a[i-1] < a[i] && !isAsc {
			changeI = i - 1
			isAsc = true
		} else if a[i-1] > a[i] && isAsc {
			changeI = i - 1
			isAsc = false
		}
		prev[i] = changeI
	}

	next := make([]int, n+1)
	isAsc = false
	changeI = n + 1
	for i := n; i >= 1; i-- {
		if a[i] < a[i+1] && !isAsc {
			changeI = i + 1
			isAsc = true
		} else if a[i] > a[i+1] && isAsc {
			changeI = i + 1
			isAsc = false
		}
		next[i] = changeI
	}

	for ; q > 0; q-- {
		Fscan(in, &l, &r)
		if next[l] >= r || prev[r] <= l || sameL[next[l]] == sameL[prev[r]] && a[next[l]] >= a[l] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}

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

package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+2)
	sameL := make([]int, n+1)
	sameLI := 0
	prev := make([]int, n+1)
	isAsc := true
	changeI := 0
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		if a[i] != a[i-1] {
			sameLI = i
		}
		sameL[i] = sameLI
		if a[i-1] < a[i] && !isAsc {
			changeI = i - 1
			isAsc = true
		} else if a[i-1] > a[i] && isAsc {
			changeI = i - 1
			isAsc = false
		}
		prev[i] = changeI
	}

	next := make([]int, n+1)
	isAsc = false
	changeI = n + 1
	for i := n; i >= 1; i-- {
		if a[i] < a[i+1] && !isAsc {
			changeI = i + 1
			isAsc = true
		} else if a[i] > a[i+1] && isAsc {
			changeI = i + 1
			isAsc = false
		}
		next[i] = changeI
	}

	ql := make([]int, q+1)
	qr := make([]int, q+1)
	for i := 1; i <= q; i++ {
		Fscan(in, &ql[i], &qr[i])
	}
	for i := 1; i <= q; i++ {
		l, r := ql[i], qr[i]
		if next[l] >= r || prev[r] <= l || sameL[next[l]] == sameL[prev[r]] && a[next[l]] >= a[l] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}

	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol279C(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n, q := read(), read()
	a := make([]int, n+2)
	sameL := make([]int, n+1)
	sameLI := 0
	prev := make([]int, n+1)
	isAsc := true
	changeI := 0
	for i := 1; i <= n; i++ {
		a[i] = read()
		if a[i] != a[i-1] {
			sameLI = i
		}
		sameL[i] = sameLI
		if a[i-1] < a[i] && !isAsc {
			changeI = i - 1
			isAsc = true
		} else if a[i-1] > a[i] && isAsc {
			changeI = i - 1
			isAsc = false
		}
		prev[i] = changeI
	}

	next := make([]int, n+1)
	isAsc = false
	changeI = n + 1
	for i := n; i >= 1; i-- {
		if a[i] < a[i+1] && !isAsc {
			changeI = i + 1
			isAsc = true
		} else if a[i] > a[i+1] && isAsc {
			changeI = i + 1
			isAsc = false
		}
		next[i] = changeI
	}

	for ; q > 0; q-- {
		l, r := read(), read()
		if next[l] >= r || prev[r] <= l || sameL[next[l]] == sameL[prev[r]] && a[next[l]] >= a[l] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}

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

package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+2)
	prev := make([]int, n+1)
	isAsc := true
	changeI := 0
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		if a[i-1] < a[i] && !isAsc {
			changeI = i - 1
			isAsc = true
		} else if a[i-1] > a[i] && isAsc {
			changeI = i - 1
			isAsc = false
		}
		prev[i] = changeI
	}

	next := make([]int, n+1)
	isAsc = false
	changeI = n + 1
	for i := n; i >= 1; i-- {
		if a[i] < a[i+1] && !isAsc {
			changeI = i + 1
			isAsc = true
		} else if a[i] > a[i+1] && isAsc {
			changeI = i + 1
			isAsc = false
		}
		next[i] = changeI
	}

	ql := make([]int, q+1)
	qr := make([]int, q+1)
	for i := 1; i <= q; i++ {
		Fscan(in, &ql[i], &qr[i])
	}
	if n == 100000 && q == 100000 && a[1] == 44 && a[2] == 35 {
		i := 91760
		l, r := ql[i], qr[i]
		Fprintln(out, l, r, next[l], prev[r])
		for j := l - 5; j <= r+5; j++ {
			Fprintln(out, j, a[j])
		}
	}
	for i := 1; i <= q; i++ {
		l, r := ql[i], qr[i]

		if next[l] >= r || prev[r] <= l || next[l] == prev[r] && a[next[l]] >= a[l] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}

	}
}

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

package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+2)
	prev := make([]int, n+1)
	isAsc := true
	changeI := 0
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		if a[i-1] < a[i] && !isAsc {
			changeI = i - 1
			isAsc = true
		} else if a[i-1] > a[i] && isAsc {
			changeI = i - 1
			isAsc = false
		}
		prev[i] = changeI
	}

	next := make([]int, n+1)
	isAsc = false
	changeI = n + 1
	for i := n; i >= 1; i-- {
		if a[i] < a[i+1] && !isAsc {
			changeI = i + 1
			isAsc = true
		} else if a[i] > a[i+1] && isAsc {
			changeI = i + 1
			isAsc = false
		}
		next[i] = changeI
	}

	for i := 1; i <= q; i++ {
		var l, r int
		Fscan(in, &l, &r)

		if next[l] >= r || prev[r] <= l || next[l] == prev[r] && a[next[l]] >= a[l] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
		if n == 100000 && q == 100000 && i == 72458 {
			Fprint(out, l, r, next[l], prev[r])
			Fprintln(out, a[l:r])
		}
	}
}

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

package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+2)
	prev := make([]int, n+1)
	isAsc := true
	changeI := 0
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		if a[i-1] < a[i] && !isAsc {
			changeI = i - 1
			isAsc = true
		} else if a[i-1] > a[i] && isAsc {
			changeI = i - 1
			isAsc = false
		}
		prev[i] = changeI
	}

	next := make([]int, n+1)
	isAsc = false
	changeI = n + 1
	for i := n; i >= 1; i-- {
		if a[i] < a[i+1] && !isAsc {
			changeI = i + 1
			isAsc = true
		} else if a[i] > a[i+1] && isAsc {
			changeI = i + 1
			isAsc = false
		}
		next[i] = changeI
	}

	ql := make([]int, q+1)
	qr := make([]int, q+1)
	for i := 1; i <= q; i++ {
		Fscan(in, &ql[i], &qr[i])
	}
	if n == 100000 && q == 100000 && a[0] == 44 && a[1] == 35 {
		i := 72458
		l, r := ql[i], qr[i]
		Fprint(out, l, r, next[l], prev[r])
		Fprintln(out, a[l:r])
	}
	for i := 1; i <= q; i++ {
		l, r := ql[i], qr[i]

		if next[l] >= r || prev[r] <= l || next[l] == prev[r] && a[next[l]] >= a[l] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}

	}
}

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

package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+2)
	prev := make([]int, n+1)
	isAsc := true
	changeI := 0
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		if a[i-1] < a[i] && !isAsc {
			changeI = i - 1
			isAsc = true
		} else if a[i-1] > a[i] && isAsc {
			changeI = i - 1
			isAsc = false
		}
		prev[i] = changeI
	}

	next := make([]int, n+1)
	isAsc = false
	changeI = n + 1
	for i := n; i >= 1; i-- {
		if a[i] < a[i+1] && !isAsc {
			changeI = i + 1
			isAsc = true
		} else if a[i] > a[i+1] && isAsc {
			changeI = i + 1
			isAsc = false
		}
		next[i] = changeI
	}

	ql := make([]int, q+1)
	qr := make([]int, q+1)
	for i := 1; i <= q; i++ {
		Fscan(in, &ql[i], &qr[i])
	}
	if n == 100000 && q == 100000 && a[1] == 44 && a[2] == 35 {
		i := 72458
		l, r := ql[i], qr[i]
		Fprintln(out, l, r, next[l], prev[r])
		for j := l - 5; j <= r+5; j++ {
			Fprintln(out, j, a[j])
		}
	}
	for i := 1; i <= q; i++ {
		l, r := ql[i], qr[i]

		if next[l] >= r || prev[r] <= l || next[l] == prev[r] && a[next[l]] >= a[l] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}

	}
}

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

package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+2)
	prev := make([]int, n+1)
	isAsc := true
	changeI := 0
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		if a[i-1] < a[i] && !isAsc {
			changeI = i - 1
			isAsc = true
		} else if a[i-1] > a[i] && isAsc {
			changeI = i - 1
			isAsc = false
		}
		prev[i] = changeI
	}

	next := make([]int, n+1)
	isAsc = false
	changeI = n + 1
	for i := n; i >= 1; i-- {
		if a[i] < a[i+1] && !isAsc {
			changeI = i + 1
			isAsc = true
		} else if a[i] > a[i+1] && isAsc {
			changeI = i + 1
			isAsc = false
		}
		next[i] = changeI
	}

	for i := 1; i <= q; i++ {
		var l, r int
		Fscan(in, &l, &r)

		if next[l] >= r || prev[r] <= l || next[l] == prev[r] && a[next[l]] >= a[l] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
		if n == 100000 && q == 100000 && a[0] == 44 && a[1] == 35 && i == 72458 {
			Fprint(out, l, r, next[l], prev[r])
			Fprintln(out, a[l:r])
		}
	}
}

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

package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+2)
	prev := make([]int, n+1)
	isAsc := true
	changeI := 0
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		if a[i-1] < a[i] && !isAsc {
			changeI = i - 1
			isAsc = true
		} else if a[i-1] > a[i] && isAsc {
			changeI = i - 1
			isAsc = false
		}
		prev[i] = changeI
	}

	next := make([]int, n+1)
	isAsc = false
	changeI = n + 1
	for i := n; i >= 1; i-- {
		if a[i] < a[i+1] && !isAsc {
			changeI = i + 1
			isAsc = true
		} else if a[i] > a[i+1] && isAsc {
			changeI = i + 1
			isAsc = false
		}
		next[i] = changeI
	}

	ql := make([]int, q+1)
	qr := make([]int, q+1)
	for i := 1; i <= q; i++ {
		Fscan(in, &ql[i], &qr[i])
	}
	if n == 100000 && q == 100000 && a[1] == 44 && a[2] == 35 {
		i := 72458
		l, r := ql[i], qr[i]
		Fprint(out, l, r, next[l], prev[r])
		Fprintln(out, a[l:r])
	}
	for i := 1; i <= q; i++ {
		l, r := ql[i], qr[i]

		if next[l] >= r || prev[r] <= l || next[l] == prev[r] && a[next[l]] >= a[l] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}

	}
}

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

package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+2)
	prev := make([]int, n+1)
	isAsc := true
	changeI := 0
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		if a[i-1] < a[i] && !isAsc {
			changeI = i - 1
			isAsc = true
		} else if a[i-1] > a[i] && isAsc {
			changeI = i - 1
			isAsc = false
		}
		prev[i] = changeI
	}

	next := make([]int, n+1)
	isAsc = false
	changeI = n + 1
	for i := n; i >= 1; i-- {
		if a[i] < a[i+1] && !isAsc {
			changeI = i + 1
			isAsc = true
		} else if a[i] > a[i+1] && isAsc {
			changeI = i + 1
			isAsc = false
		}
		next[i] = changeI
	}

	for ; q > 0; q-- {
		var l, r int
		Fscan(in, &l, &r)
		if next[l] >= r || next[l] == prev[r] && a[next[l]] >= a[l] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}

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

package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+2)
	prev := make([]int, n+1)
	isAsc := true
	changeI := 0
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		if a[i-1] < a[i] && !isAsc {
			changeI = i - 1
			isAsc = true
		} else if a[i-1] > a[i] && isAsc {
			changeI = i - 1
			isAsc = false
		}
		prev[i] = changeI
	}

	next := make([]int, n+1)
	isAsc = false
	changeI = n + 1
	for i := n; i >= 1; i-- {
		if a[i] < a[i+1] && !isAsc {
			changeI = i + 1
			isAsc = true
		} else if a[i] > a[i+1] && isAsc {
			changeI = i + 1
			isAsc = false
		}
		next[i] = changeI
	}

	for ; q > 0; q-- {
		var l, r int
		Fscan(in, &l, &r)
		if next[l] >= r || prev[r] <= l || next[l] == prev[r] && a[next[l]] >= a[l] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}

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


Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it.You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw.

The only line contains an integer n (3 ≤ n ≤ 101; n is odd).

***D***
**DDD**
*DDDDD*
DDDDDDD
*DDDDD*
**DDD**
***D***

package main

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

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

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

	n := nextInt()
	m := n / 2

	k, l := m, 0

	for i := 0; i < m; i++ {
		for j := 0; j < k; j++ {
			print("*")
		}

		for j := 0; j <= l; j++ {
			print("D")
		}

		for j := 0; j < k; j++ {
			print("*")
		}

		k--
		l += 2
		println()
	}

	for i := 0; i < n; i++ {
		print("D")
	}

	println()

	k, l = 0, n - 2

	for i := 0; i < m; i++ {
		for j := 0; j <= k; j++ {
			print("*")
		}

		for j := 0; j < l; j++ {
			print("D")
		}

		for j := 0; j <= k; j++ {
			print("*")
		}

		k++
		l -= 2
		println()
	}
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	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"
import "fmt"
import "os"
import "strconv"

type MyScanner struct {
	in *bufio.Scanner
}

var in = MyScanner{bufio.NewScanner(os.Stdin)}

func ScanInts(data []byte, atEOF bool) (advance int, token []byte, err error) {
	advance, token, err = bufio.ScanWords(data, atEOF)
	if err == nil && token != nil {
		_, err = strconv.Atoi(string(token))
	}
	return
}

func (m *MyScanner) innerNext(f bufio.SplitFunc) bool {
	m.in.Split(f)
	return m.in.Scan()
}

func (m *MyScanner) NextInt() (int, error) {
	if !m.innerNext(ScanInts) {
		return 0, m.in.Err()
	}
	r, _ := strconv.Atoi(m.in.Text())
	return r, nil
}

func main() {
	n, _ := in.NextInt()
	b := make([]byte, n)
	for i := 1; i < n; i += 2 {
		m := (n - i) / 2
		p := 0
		for j := 0; j < m; j++ {
			b[p] = '*'
			b[n-p-1] = '*'
			p++
		}
		for j := 0; j < i; j++ {
			b[p] = 'D'
			p++
		}
		fmt.Println(string(b))
	}
	for i := 0; i < n; i++ {
		b[i] = 'D'
	}
	fmt.Println(string(b))
	for i := n - 2; i > 0; i -= 2 {
		m := (n - i) / 2
		p := 0
		for j := 0; j < m; j++ {
			b[p] = '*'
			b[n-p-1] = '*'
			p++
		}
		for j := 0; j < i; j++ {
			b[p] = 'D'
			p++
		}
		fmt.Println(string(b))
	}
}

package main

import "fmt"

func main() {
	var n int
	var r []rune

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

	r = make([]rune, n)

	for i := 0; i < n; i++ {
		r[i] = '*'
	}

	r[n/2] = 'D'

	fmt.Println(string(r))

	for i := 1; i <= (n / 2); i++ {
		r[(n/2)+i] = 'D'
		r[(n/2)-i] = 'D'
		fmt.Println(string(r))
	}
	for i := 0; i < (n / 2); i++ {
		r[i] = '*'
		r[n-1-i] = '*'
		fmt.Println(string(r))
	}
}

package main

import "fmt"

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

func main() {
	var n int
	fmt.Scan(&n)
	a := n / 2
	for i := 0; i < n; i++ {
		b := abs(i - a)
		for j := 0; j < b; j++ {
			fmt.Print("*")
		}
		for j := 0; j < n-2*b; j++ {
			fmt.Print("D")
		}
		for j := 0; j < b; j++ {
			fmt.Print("*")
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
)

func out(a int, b int) {
	for j := 0; j < a; j++ {
		fmt.Print("*")
	}
	for j := 0; j < b; j++ {
		fmt.Print("D")
	}
	for j := 0; j < a; j++ {
		fmt.Print("*")
	}
	fmt.Println()
}

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

	for i := 0; i < n / 2 + 1; i++ {
		out(n / 2 - i, i * 2 + 1)
	}
	for i := 0; i < n / 2; i++ {
		j := n / 2 - 1 - i
		out(n / 2 - j, j * 2 + 1)
	}
}

package main

import "fmt"

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

	for i := 1; i <= n; i++ {
		l := 0
		if i <= (n+1)/2 {
			l = 2*i - 1
		} else {
			l = 2*(n-i) + 1
		}

		k := (n-l)/2 + 1
		for j := 1; j <= n; j++ {
			if j < k {
				fmt.Print("*")
			} else if j >= (k + l) {
				fmt.Print("*")
			} else {
				fmt.Print("D")
			}
		}
		fmt.Println("")
	}
}

package main

import (
    "fmt"
)

func Prt(n int, j int){
    for i := 1 ; i <= n ; i++ {
        if ( i <= n/2 - j + 1 ) || ( i >= n/2 + j + 1) {
            fmt.Print("*")
        } else {
            fmt.Print("D")
        }
    }
    fmt.Println()
}

func main() {
    var n int
    fmt.Scanf("%d",&n)
    for i := 1 ; i <= n/2 ; i++ {
        Prt(n,i)
    }
    for i:= n/2 + 1; i<= n ;i++{
        Prt(n,n-i+1)
    }
}

package main

import (
    "fmt"
    )

func get_line(index, n int) string {
    line := make([]byte, n, n)
    if index > n / 2 {
        index = n - index - 1
    }

    nd := index * 2 + 1
    nstar := (n - nd) / 2
    i := 0
    for ; i < nstar; i++ {
        line[i] = '*'
        line[n-i-1] = '*'
    }
    for ; i < nstar + nd; i++ {
        line[i] = 'D'
    }

    return string(line)
}

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

    for i := 0; i < n; i++ {
        line := get_line(i, n)
        fmt.Println(line)
    }
}


You are given a sequence of $$$n$$$ integers $$$a_1, \, a_2, \, \dots, \, a_n$$$.Does there exist a sequence of $$$n$$$ integers $$$b_1, \, b_2, \, \dots, \, b_n$$$ such that the following property holds?  For each $$$1 \le i \le n$$$, there exist two (not necessarily distinct) indices $$$j$$$ and $$$k$$$ ($$$1 \le j, \, k \le n$$$) such that $$$a_i = b_j - b_k$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10$$$). The second line of each test case contains the $$$n$$$ integers $$$a_1, \, \dots, \, a_n$$$ ($$$-10^5 \le a_i \le 10^5$$$).

For each test case, output a line containing YES if a sequence $$$b_1, \, \dots, \, b_n$$$ satisfying the required property exists, and NO otherwise.

NoteIn the first test case, the sequence $$$b = [-9, \, 2, \, 1, \, 3, \, -2]$$$ satisfies the property. Indeed, the following holds:   $$$a_1 = 4 = 2 - (-2) = b_2 - b_5$$$;  $$$a_2 = -7 = -9 - (-2) = b_1 - b_5$$$;  $$$a_3 = -1 = 1 - 2 = b_3 - b_2$$$;  $$$a_4 = 5 = 3 - (-2) = b_4 - b_5$$$;  $$$a_5 = 10 = 1 - (-9) = b_3 - b_1$$$. In the second test case, it is sufficient to choose $$$b = [0]$$$, since $$$a_1 = 0 = 0 - 0 = b_1 - b_1$$$.In the third test case, it is possible to show that no sequence $$$b$$$ of length $$$3$$$ satisfies the property.

package main
import ."fmt"

func main() {
	var T, n int
	for Scan(&T); T > 0; T-- {
		Scan(&n)
		a := make([]int, n)
		for i := range a {
			Scan(&a[i])
		}
		set := map[int]bool{}
		for i := 0; i < 1<<n; i++ {
			sum := 0
			for j, v := range a {
				sum += i >> j & 1 * v
			}
			set[sum] = true
		}
		if len(set) < 1<<n { // 至少有两个子集和相同
			Println("YES")
		} else {
			Println("NO")
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1552D(in io.Reader, out io.Writer) {
	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		has := map[int]bool{}
		for i := 0; i < 1<<n; i++ {
			sum := 0
			for j, v := range a {
				sum += i >> j & 1 * v
			}
			has[sum] = true
		}
		if len(has) < 1<<n { // 存在两个不同的
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main
import."fmt"

// github.com/EndlessCheng/codeforces-go
func main(){
	T,n:=0,0
	for Scan(&T);T>0;T--{
		Scan(&n)
		a:=make([]int,n)
		for i:=range a{Scan(&a[i])}
		m:=map[int]int{}
		for i:=0;i<1<<n;i++{
			s:=0
			for j,v:=range a{s+=i>>j&1*v}
			m[s]=1
		}
		s:="NO";if len(m)<1<<n{s="YES"}
		Println(s)
	}
}

package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func main() {
	defer write.Flush()
	var t int
	fmt.Fscan(read, &t)
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	var n int
	fmt.Fscan(read, &n)
	a := make([]int, n)
	for i := range a {
		fmt.Fscan(read, &a[i])
	}
	m := map[int]int{}
	for i := 0; i < 1<<n; i++ {
		s := 0
		for j, l := range a {
			s += i >> j & 1 * l
			//fmt.Fprintln(write,i,j,l, i>>j&1*l)
		}
		m[s] = 1
	}
	//fmt.Fprintln(write, len(m), 1<<n)
	s := "NO"
	if len(m) < 1<<n {
		s = "YES"
	}
	fmt.Fprintln(write, s)
}

package main
import ."fmt"

func main() {
	var T, n int
	for Scan(&T); T > 0; T-- {
		Scan(&n)
		a := make([]int, n)
		for i := range a {
			Scan(&a[i])
		}
		set := map[int]bool{}
		for i := 0; i < 1<<n; i++ {
			sum := 0
			for j, v := range a {
				sum += i >> j & 1 * v
			}
			set[sum] = true
		}
		if len(set) < 1<<n {
			Println("YES")
		} else {
			Println("NO")
		}
	}
}

package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func main() {
	defer write.Flush()
	var t int
	fmt.Fscan(read, &t)
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	var n int
	fmt.Fscan(read, &n)
	a := make([]int, n)
	for i := range a {
		fmt.Fscan(read, &a[i])
	}
	m := map[int]int{}
	for i := 0; i < 1<<n; i++ {
		s := 0
		for j, l := range a {
			s += i >> j & 1 * l
			fmt.Fprintln(write,i,j,l, i>>j&1*l)
		}
		m[s] = 1
	}
	fmt.Fprintln(write, len(m), 1<<n)
	s := "NO"
	if len(m) < 1<<n {
		s = "YES"
	}
	fmt.Fprintln(write, s)
}


Recently, Polycarp completed $$$n$$$ successive tasks.For each completed task, the time $$$s_i$$$ is known when it was given, no two tasks were given at the same time. Also given is the time $$$f_i$$$ when the task was completed. For each task, there is an unknown value $$$d_i$$$ ($$$d_i>0$$$) — duration of task execution.It is known that the tasks were completed in the order in which they came. Polycarp performed the tasks as follows:  As soon as the very first task came, Polycarp immediately began to carry it out.  If a new task arrived before Polycarp finished the previous one, he put the new task at the end of the queue.  When Polycarp finished executing the next task and the queue was not empty, he immediately took a new task from the head of the queue (if the queue is empty — he just waited for the next task). Find $$$d_i$$$ (duration) of each task.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The descriptions of the input data sets follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). The second line of each test case contains exactly $$$n$$$ integers $$$s_1 < s_2 < \dots < s_n$$$ ($$$0 \le s_i \le 10^9$$$). The third line of each test case contains exactly $$$n$$$ integers $$$f_1 < f_2 < \dots < f_n$$$ ($$$s_i < f_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each of $$$t$$$ test cases print $$$n$$$ positive integers $$$d_1, d_2, \dots, d_n$$$ — the duration of each task.

NoteFirst test case:The queue is empty at the beginning: $$$[ ]$$$. And that's where the first task comes in. At time $$$2$$$, Polycarp finishes doing the first task, so the duration of the first task is $$$2$$$. The queue is empty so Polycarp is just waiting.At time $$$3$$$, the second task arrives. And at time $$$7$$$, the third task arrives, and now the queue looks like this: $$$[7]$$$.At the time $$$10$$$, Polycarp finishes doing the second task, as a result, the duration of the second task is $$$7$$$.And at time $$$10$$$, Polycarp immediately starts doing the third task and finishes at time $$$11$$$. As a result, the duration of the third task is $$$1$$$.    An example of the first test case.

package main

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

var (
    a, b [2e5+5]int64
)

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

func run(_r io.Reader, _w io.Writer){
    in := bufio.NewScanner(_r)
    out := bufio.NewWriter(_w)
    defer out.Flush()
    in.Split(bufio.ScanWords)
    read := func() (x int64) {
        in.Scan()
        for _, v := range in.Bytes() {
            x = x*10 + int64(v & 15)
        }
        return
    }
    for t := read(); t > 0; t-- {
        n := read()
        for i := int64(1); i <= n; i++ {
            a[i] = read()
        }
        for i := int64(1); i <= n; i++ {
            b[i] = read()
        }
        for i := int64(1); i <= n; i++ {
            Fprint(out, b[i] - a[i], " ")
            if b[i] > a[i+1] {
                a[i+1] = b[i]
            }
        }
        Fprintln(out)
    }
}

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

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		list1:= make([]int,n)
		list2:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list1[j])
		}
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list2[j])
		}
		fmt.Fprintf(out,"%v ",list2[0]-list1[0])
		for j:=0;j<n-1;j++{
			if list2[j] > list1[j+1] {
				fmt.Fprintf(out,"%v ",list2[j+1]-list2[j])
			} else {
				fmt.Fprintf(out,"%v ",list2[j+1]-list1[j+1])
			}
		}
		fmt.Fprintln(out,)
	}
}

package main

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

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

func main() {
	defer out.Flush()
	var t, n int
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &n)
		s := make([]int, n+1)
		f := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &s[i])
		}
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &f[i])
		}
		for i := 1; i <= n; i++ {
			fmt.Fprintf(out, "%d ", f[i]-int(math.Max(float64(s[i]), float64(f[i-1]))))
		}
		fmt.Fprintln(out, "")
	}
}

package main

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

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

func main() {

	var n int
	fmt.Fscan(in, &n)
	for 0 < n {
		n--
		solve()
	}
	defer out.Flush()
}

func solve() {

	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	b := make([]int, n)

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

	var last int

	for i := 0; i < n; i++ {
		if last > a[i] {
			fmt.Fprint(out, b[i]-last, " ")
		} else {
			fmt.Fprint(out, b[i]-a[i], " ")
		}
		last = Max(last, b[i])
	}
	fmt.Fprintln(out)
}

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

package main

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

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

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

func printf(f string, a...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func main() {
	defer writer.Flush()
	var test int
	scanf("%v\n", &test)
	for ; test > 0; test-- {
		var n int
		scanf("%v\n", &n)
		s := make([]int, n)
		f := make([]int, n)
		for i := 0; i < n; i++ {
			scanf("%v", &s[i])
		}
		scanf("\n")
		for i := 0; i < n; i++ {
			scanf("%v", &f[i])
		}
		scanf("\n")
		printf("%v ", f[0] - s[0])
		for i := 1; i < n; i++ {
			printf("%v ", f[i] - Max(s[i], f[i - 1]))
		}
		printf("\n")
	}
}

package main

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

const (
	MaxInt32 = 1 << 31 - 1
)

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

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

func main(){
	cin := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(cin, &t)
	for tc := 0; tc < t; tc++ {
		var n int
		fmt.Fscan(cin, &n)
		s := make([]int, n)
		f := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(cin, &s[i])
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(cin, &f[i])
		}
		for i := 0; i < n; i++ {
			ans := 0
			if i > 0 {
				ans = f[i] - Max(s[i], f[i-1])
			}else {
				ans = f[i] - s[i]
			}
			if i == n - 1{
				fmt.Printf("%d\n", ans)
			}else {
				fmt.Printf("%d ", ans)
			}
		}
	}
}

package main

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

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

func (in *CF1690C) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1690C) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1690C
Date: 11/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1690/C
Problem: CF1690C
**/
func (in *CF1690C) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = in.NextInt()
		}
		b := make([]int, n)
		for i := 0; i < n; i++ {
			b[i] = in.NextInt()
		}
		for i:=0;i<n;i++{
			if i == 0 {
				fmt.Print(b[i]-a[i])
			}else {
				fmt.Print(" ",b[i]-int(math.Max(float64(b[i-1]), float64(a[i]))))
			}
		}
		fmt.Println()
	}
}

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

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

package main

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

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

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

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

		fmt.Fprintf(out, "%d ", b[0]-a[0])
		for i := 1; i < n; i++ {
			if b[i-1] > a[i] {
				a[i] = b[i-1]
			}
			fmt.Fprintf(out, "%d ", b[i]-a[i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

/*
4
3
3 6 9
4 7 11
5
0 3 4 7 9
2 4 5 8 10
5
0 1 3 4 7
2 3 7 8 10
4
0 1 2 3
5 6 7 8
---
1 1 2
2 1 1 1 1
2 1 4 1 2
5 1 1 1
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	f := make([]int, n)

	for i := range f {
		scanf("%d", &f[i])
	}
	scanf("\n")

	prevFinish := 0

	for i := range f {
		start := max(prevFinish, a[i])
		d := f[i] - start
		prevFinish = f[i]

		fmt.Fprintf(writer, "%d ", d)
	}
	fmt.Fprintln(writer)
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

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

func A3() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int

		Fscan(in, &n)
		s := make([]int, n)
		f := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &s[i])

		}
		for i := 0; i < n; i++ {
			Fscan(in, &f[i])

		}
		ans := []int{f[0] - s[0]}
		ed := f[0]
		for i := 1; i < n; i++ {
			if s[i] <= ed {
				if f[i] <= ed {
					ans = append(ans, 0)

				} else {
					ans = append(ans, f[i]-ed)
					ed = f[i]
				}
			} else {
				ans = append(ans, f[i]-s[i])
				ed = f[i]
			}
		}
		for i := 0; i < n; i++ {
			Fprint(out, ans[i], " ")
		}
		Fprintln(out)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A3() }

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(r, &n)
	a := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &a[i])
	}
	b := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &b[i])
	}
	ans := make([]int, n)
	ans[0] = b[0] - a[0]
	for i:=1;i<n;i++ {
		ans[i] = b[i] - max(a[i], b[i-1])
	}
	for i := range ans {
		fmt.Fprint(w, ans[i], " ")
	}
	fmt.Fprint(w, "\n")
}

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

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}


Ivan is playing a strange game.He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows:  Initially Ivan's score is 0;  In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped;  Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score.

The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1.

Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score.

NoteIn the first example Ivan will replace the element a1, 2.

package main

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

type Reader struct {
	scanner *bufio.Scanner
}

func StdinReader() Reader {
	reader := Reader{bufio.NewScanner(os.Stdin)}
	reader.scanner.Split(bufio.ScanWords)
	return reader
}

func (r *Reader) ReadString() string {
	ok := r.scanner.Scan()
	if !ok {
		panic("EOF")
	}
	return r.scanner.Text()
}

func (r *Reader) ReadInt() int {
	i, err := strconv.Atoi(r.ReadString())
	if err != nil {
		panic(err)
	}
	return i
}

func (r *Reader) ReadFloat() float64 {
	i, err := strconv.ParseFloat(r.ReadString(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {

	in := StdinReader()
	var arr [110][110]int
	var preSum [110]int
	preSum[0] = 0
	N := in.ReadInt()
	M := in.ReadInt()
	K := in.ReadInt()
	for i := 1; i <= N; i++ {
		for j := 1; j <= M; j++ {
			arr[i][j] = in.ReadInt()
		}
	}

	ans, cnt := 0, 0
	for j := 1; j <= M; j++ {
		for i := 1; i <= N; i++ {
			preSum[i] = preSum[i-1] + arr[i][j]
		}

		begin, max := 0, 0
		for i := 1; i <= N; i++ {
			end := i - 1 + K
			if end > N {
				end = N
			}
			if preSum[end] -preSum[i-1] > max {
				max = preSum[end] - preSum[i-1]
				begin = i
			}
		}
		ans += max
		for i := 1; i <begin; i ++ {
			if arr[i][j] == 1 {
				cnt++
			}
		}
	}
	fmt.Println(ans, cnt)
}

package main

import "fmt"

func main() {
	var N, M, K int
	var arr [110][110]int
	var preSum [110]int
	preSum[0] = 0
	fmt.Scanf("%d%d%d", &N, &M, &K)
	for i := 1; i <= N; i++ {
		for j := 1; j <= M; j++ {
			fmt.Scanf("%d", &arr[i][j])
		}
	}

	ans, cnt := 0, 0
	for j := 1; j <= M; j++ {
		for i := 1; i <= N; i++ {
			preSum[i] = preSum[i-1] + arr[i][j]
		}

		begin, max := 0, 0
		for i := 1; i <= N; i++ {
			end := i - 1 + K
			if end > N {
				end = N
			}
			if preSum[end] -preSum[i-1] > max {
				max = preSum[end] - preSum[i-1]
				begin = i
			}
		}
		ans += max
		for i := 1; i <begin; i ++ {
			if arr[i][j] == 1 {
				cnt++
			}
		}
	}
	fmt.Println(ans, cnt)
}


Vasya came up with a password to register for EatForces — a string $$$s$$$. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits.But since EatForces takes care of the security of its users, user passwords must contain at least one digit, at least one uppercase Latin letter and at least one lowercase Latin letter. For example, the passwords "abaCABA12", "Z7q" and "3R24m" are valid, and the passwords "qwerty", "qwerty12345" and "Password" are not. A substring of string $$$s$$$ is a string $$$x = s_l s_{l + 1} \dots s_{l + len - 1} (1 \le l \le |s|, 0 \le len \le |s| - l + 1)$$$. $$$len$$$ is the length of the substring. Note that the empty string is also considered a substring of $$$s$$$, it has the length $$$0$$$.Vasya's password, however, may come too weak for the security settings of EatForces. He likes his password, so he wants to replace some its substring with another string of the same length in order to satisfy the above conditions. This operation should be performed exactly once, and the chosen string should have the minimal possible length.Note that the length of $$$s$$$ should not change after the replacement of the substring, and the string itself should contain only lowercase and uppercase Latin letters and digits.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of testcases. Each of the next $$$T$$$ lines contains the initial password $$$s~(3 \le |s| \le 100)$$$, consisting of lowercase and uppercase Latin letters and digits. Only $$$T = 1$$$ is allowed for hacks.

For each testcase print a renewed password, which corresponds to given conditions.  The length of the replaced substring is calculated as following: write down all the changed positions. If there are none, then the length is $$$0$$$. Otherwise the length is the difference between the first and the last changed position plus one. For example, the length of the changed substring between the passwords "abcdef" $$$\rightarrow$$$ "a7cdEf" is $$$4$$$, because the changed positions are $$$2$$$ and $$$5$$$, thus $$$(5 - 2) + 1 = 4$$$. It is guaranteed that such a password always exists. If there are several suitable passwords — output any of them.

NoteIn the first example Vasya's password lacks a digit, he replaces substring "C" with "4" and gets password "abcD4E". That means, he changed the substring of length 1.In the second example Vasya's password is ok from the beginning, and nothing has to be changed. That is the same as replacing the empty substring with another empty substring (length 0).

package main

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

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

const ISDEBUG = false

func readLine() string {
	r.Scan()
	return r.Text()
}

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

func readInts(n int) []int {
	var res []int
	for i := 0; i < n; i++ {
		if !r.Scan() {
			fmt.Println(r.Err())
		}
		x, _ := strconv.Atoi(r.Text())
		res = append(res, x)
	}
	return res
}

func isLower(c rune) bool {
	return c >= 'a' && c <= 'z'
}

func isUpper(c rune) bool {
	return c >= 'A' && c <= 'Z'
}

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

func A() {
	t := readInt()
	for i := 0; i < t; i++ {
		s := readLine()
		hasLower, hasUpper, hasDigit := false, false, false
		errs := 3
		result := s
		for _, c := range s {
			if isUpper(c) {
				if !hasUpper {
					errs -= 1
				}
				hasUpper = true
			}

			if isLower(c) {
				if !hasLower {
					errs -= 1
				}
				hasLower = true
			}

			if isDigit(c) {
				if !hasDigit {
					errs -= 1
				}
				hasDigit = true
			}
		}

		if errs == 2 {
			if hasLower {
				result = "A1" + s[2:]
			}
			if hasUpper {
				result = "a1" + s[2:]
			}
			if hasDigit {
				result = "Aa" + s[2:]
			}
		} else if errs == 1 {
			cupper, clower, cdigit := 0, 0, 0
			pos := 0
			for j, c := range s {
				if isUpper(c) {
					cupper += 1
					if cupper > 1 {
						pos = j
						break
					}
				}

				if isLower(c) {
					clower += 1
					if clower > 1 {
						pos = j
						break
					}
				}

				if isDigit(c) {
					cdigit += 1
					if cdigit > 1 {
						pos = j
						break
					}
				}
			}
			if !hasDigit {
				result = s[0:pos] + "0" + s[pos+1:]
			} else if !hasLower {
				result = s[0:pos] + "a" + s[pos+1:]
			} else {
				result = s[0:pos] + "A" + s[pos+1:]
			}

		}

		w.WriteString(fmt.Sprintf("%s\n", result))
	}
}

func main() {
	if ISDEBUG {
		fi, err := os.Open("input.txt")
		if err != nil {
			panic(err)
		}
		fo, _ := os.OpenFile("output.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
		r = bufio.NewScanner(fi)
		w = bufio.NewWriter(fo)

		defer fi.Close()
		defer fo.Close()
	} else {
		r = bufio.NewScanner(os.Stdin)
		w = bufio.NewWriter(os.Stdout)
	}
	r.Split(bufio.ScanWords)
	defer w.Flush()

	A()
}

package main

import (
	"fmt"
)

type char struct {
	cond   func(b byte) bool
	symbol string
	points []int
}

func sortChars(src []*char) {
	for i := 1; i < len(src); i++ {
		for j := i; j > 0; j-- {
			if len(src[j].points) > len(src[j-1].points) {
				src[j], src[j-1] = src[j-1], src[j]
			}
		}
	}
}

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

	for T > 0 {
		T--
		upper := char{
			symbol: "A",
			cond:   func(b byte) bool { return (b >= "A"[0]) && (b <= "Z"[0]) },
		}
		num := char{
			symbol: "0",
			cond:   func(b byte) bool { return (b >= "0"[0]) && (b <= "9"[0]) },
		}
		lower := char{
			symbol: "a",
			cond:   func(b byte) bool { return (b >= "a"[0]) && (b <= "z"[0]) },
		}
		chars := []*char{&upper, &lower, &num}

		var pass string
		fmt.Scan(&pass)
		for i := 0; i < len(pass); i++ {
			for _, c := range chars {
				if c.cond(pass[i]) {
					c.points = append(c.points, i)
				}
			}
		}
		sortChars(chars)

		// Good shape
		if len(chars[2].points) > 0 {
			fmt.Println(pass)
			continue
		}
		// Shape like "AAAAAAA"
		if len(chars[1].points) == 0 {
			newPass := pass[0:chars[0].points[0]] + chars[1].symbol +
				pass[chars[0].points[0]+1:chars[0].points[1]] + chars[2].symbol +
				pass[chars[0].points[1]+1:]
			fmt.Println(newPass)
			continue
		}
		// Shpae like "AAAAaaaa"
		fmt.Println(pass[0:chars[0].points[0]] + chars[2].symbol + pass[chars[0].points[0]+1:])
	}
}


You are given an integer array $$$a$$$ of size $$$n$$$.You have to perform $$$m$$$ queries. Each query has one of two types:   "$$$1$$$ $$$l$$$ $$$r$$$ $$$k$$$" — calculate the minimum value $$$dif$$$ such that there are exist $$$k$$$ distinct integers $$$x_1, x_2, \dots, x_k$$$ such that $$$cnt_i > 0$$$ (for every $$$i \in [1, k]$$$) and $$$|cnt_i - cnt_j| \le dif$$$ (for every $$$i \in [1, k], j \in [1, k]$$$), where $$$cnt_i$$$ is the number of occurrences of $$$x_i$$$ in the subarray $$$a[l..r]$$$. If it is impossible to choose $$$k$$$ integers, report it;  "$$$2$$$ $$$p$$$ $$$x$$$" — assign $$$a_{p} := x$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the size of the array $$$a$$$ and the number of queries. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$). Next $$$m$$$ lines contain queries (one per line). Each query has one of two types:    "$$$1$$$ $$$l$$$ $$$r$$$ $$$k$$$" ($$$1 \le l \le r \le n; 1 \le k \le 10^5$$$)  "$$$2$$$ $$$p$$$ $$$x$$$" ($$$1 \le p \le n; 1 \le x \le 10^5$$$).  It's guaranteed that there is at least one query of the first type.

For each query of the first type, print the minimum value of $$$dif$$$ that satisfies all required conditions, or $$$-1$$$ if it is impossible to choose $$$k$$$ distinct integers.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1476G(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type query struct{ lb, rb, l, r, k, t, qid int }
	type modify struct{ pos, val int }

	var n, q, op int
	Fscan(in, &n, &q)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
	}
	blockSize := int(math.Round(math.Pow(float64(n), 2.0/3)))
	qs, ms := []query{}, []modify{}
	for ; q > 0; q-- {
		if Fscan(in, &op); op == 1 {
			var l, r, k int
			Fscan(in, &l, &r, &k)
			qs = append(qs, query{l / blockSize, (r + 1) / blockSize, l, r + 1, k, len(ms), len(qs)})
		} else {
			var pos, val int
			Fscan(in, &pos, &val)
			ms = append(ms, modify{pos, val})
		}
	}
	sort.Slice(qs, func(i, j int) bool {
		a, b := qs[i], qs[j]
		if a.lb != b.lb {
			return a.lb < b.lb
		}
		if a.rb != b.rb {
			return a.rb < b.rb
		}
		if a.rb&1 == 0 {
			return a.t < b.t
		}
		return a.t > b.t
	})

	const mx int = 1e5
	var cnt, scnt, st [mx + 1]int
	for i := 1; i <= mx; i++ {
		st[i] = mx
	}
	l, r, now := 1, 1, 0
	add := func(val int) {
		cnt[val]++
		st[cnt[val]]--
		scnt[st[cnt[val]]] = cnt[val]
	}
	del := func(val int) {
		c := cnt[val]
		cnt[val]--
		i := st[c]
		st[c]++
		scnt[i] = cnt[val]
	}
	timeSlip := func(l, r int) {
		m := ms[now]
		p, v := m.pos, m.val
		if l <= p && p < r {
			del(a[p])
			add(v)
		}
		a[p], ms[now].val = v, a[p]
	}
	ans := make([]int, len(qs))
	for _, q := range qs {
		for ; r < q.r; r++ {
			add(a[r])
		}
		for ; l < q.l; l++ {
			del(a[l])
		}
		for l > q.l {
			l--
			add(a[l])
		}
		for r > q.r {
			r--
			del(a[r])
		}
		for ; now < q.t; now++ {
			timeSlip(q.l, q.r)
		}
		for now > q.t {
			now--
			timeSlip(q.l, q.r)
		}
		minDif := int(1e9)
		for i := st[1]; i+q.k <= mx; {
			c := scnt[i]
			if dif := scnt[i+q.k-1] - c; dif < minDif {
				minDif = dif
			}
			i = st[c+1]
		}
		if minDif == 1e9 {
			minDif = -1
		}
		ans[q.qid] = minDif
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1476G(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type query struct{ lb, rb, l, r, k, t, qid int }
	type modify struct{ pos, val int }

	var n, q, op int
	Fscan(in, &n, &q)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
	}
	blockSize := int(math.Round(math.Pow(float64(n), 2.0/3)))
	qs, ms := []query{}, []modify{}
	for ; q > 0; q-- {
		if Fscan(in, &op); op == 1 {
			var l, r, k int
			Fscan(in, &l, &r, &k)
			qs = append(qs, query{l / blockSize, (r + 1) / blockSize, l, r + 1, k, len(ms), len(qs)})
		} else {
			var pos, val int
			Fscan(in, &pos, &val)
			ms = append(ms, modify{pos, val})
		}
	}
	sort.Slice(qs, func(i, j int) bool {
		a, b := qs[i], qs[j]
		if a.lb != b.lb {
			return a.lb < b.lb
		}
		if a.rb != b.rb {
			return a.rb < b.rb
		}
		if a.rb&1 == 0 {
			return a.t < b.t
		}
		return a.t > b.t
	})

	const mx int = 1e5
	var cnt, scnt, st [mx + 1]int
	for i := 1; i <= mx; i++ {
		st[i] = mx
	}
	l, r, now := 1, 1, 0
	add := func(val int) {
		cnt[val]++
		st[cnt[val]]--
		scnt[st[cnt[val]]] = cnt[val]
	}
	del := func(val int) {
		c := cnt[val]
		cnt[val]--
		i := st[c]
		st[c]++
		scnt[i] = cnt[val]
	}
	ans := make([]int, len(qs))
	for _, q := range qs {
		for ; r < q.r; r++ {
			add(a[r])
		}
		for ; l < q.l; l++ {
			del(a[l])
		}
		for l > q.l {
			l--
			add(a[l])
		}
		for r > q.r {
			r--
			del(a[r])
		}
		for ; now < q.t; now++ {
			m := ms[now]
			p, v := m.pos, m.val
			if q.l <= p && p < q.r {
				del(a[p])
				add(v)
			}
			a[p], ms[now].val = v, a[p]
		}
		for now > q.t {
			now--
			m := ms[now]
			p, v := m.pos, m.val
			if q.l <= p && p < q.r {
				del(a[p])
				add(v)
			}
			a[p], ms[now].val = v, a[p]
		}
		minDif := int(1e9)
		for i := st[1]; i+q.k <= mx; {
			c := scnt[i]
			if dif := scnt[i+q.k-1] - c; dif < minDif {
				minDif = dif
			}
			i = st[c+1]
		}
		if minDif == 1e9 {
			minDif = -1
		}
		ans[q.qid] = minDif
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1476G(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type query struct{ lb, rb, l, r, k, t, qid int }
	type modify struct{ pos, val int }

	var n, q, op int
	Fscan(in, &n, &q)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
	}
	blockSize := int(math.Round(math.Pow(float64(n), 2.0/3)))
	qs, ms := []query{}, []modify{}
	for ; q > 0; q-- {
		if Fscan(in, &op); op == 1 {
			var l, r, k int
			Fscan(in, &l, &r, &k)
			qs = append(qs, query{l / blockSize, (r + 1) / blockSize, l, r + 1, k, len(ms), len(qs)})
		} else {
			var pos, val int
			Fscan(in, &pos, &val)
			ms = append(ms, modify{pos, val})
		}
	}
	sort.Slice(qs, func(i, j int) bool {
		a, b := qs[i], qs[j]
		if a.lb != b.lb {
			return a.lb < b.lb
		}
		if a.rb != b.rb {
			return a.rb < b.rb
		}
		if a.rb&1 == 0 {
			return a.t < b.t
		}
		return a.t > b.t
	})

	const mx int = 1e5
	var cnt, scnt, st [mx + 1]int
	for i := 1; i <= mx; i++ {
		st[i] = mx
	}
	l, r, now := 1, 1, 0
	add := func(val int) {
		cnt[val]++
		st[cnt[val]]--
		scnt[st[cnt[val]]] = cnt[val]
	}
	del := func(val int) {
		c := cnt[val]
		cnt[val]--
		i := st[c]
		st[c]++
		scnt[i] = cnt[val]
	}
	timeSlip := func(l, r int) {
		m := ms[now]
		p, v := m.pos, m.val
		if l <= p && p < r {
			del(a[p])
			add(v)
		}
		a[p], ms[now].val = v, a[p]
	}
	ans := make([]int, len(qs))
	for _, q := range qs {
		for ; r < q.r; r++ {
			add(a[r])
		}
		for ; l < q.l; l++ {
			del(a[l])
		}
		for l > q.l {
			l--
			add(a[l])
		}
		for r > q.r {
			r--
			del(a[r])
		}
		for ; now < q.t; now++ {
			timeSlip(q.l, q.r)
		}
		for now > q.t {
			now--
			timeSlip(q.l, q.r)
		}
		minDif := int(1e9)
		for i := st[1]; i+q.k <= mx; {
			c := scnt[i]
			if dif := scnt[i+q.k-1] - c; dif < minDif {
				minDif = dif
			}
			i = st[c+1]
		}
		if minDif == 1e9 {
			minDif = -1
		}
		ans[q.qid] = minDif
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	type query struct{ lb, rb, l, r, k, t, qid int }
	type modify struct{ p, v int }

	var n, q, op int
	Fscan(in, &n, &q)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
	}
	B := int(math.Round(math.Pow(float64(n), 2.0/3)))
	qs := []query{}
	ms := []modify{}
	for ; q > 0; q-- {
		if Fscan(in, &op); op == 1 {
			var l, r, k int
			Fscan(in, &l, &r, &k)
			qs = append(qs, query{l / B, (r + 1) / B, l, r + 1, k, len(ms), len(qs)})
		} else {
			var p, v int
			Fscan(in, &p, &v)
			ms = append(ms, modify{p, v})
		}
	}
	sort.Slice(qs, func(i, j int) bool {
		a, b := qs[i], qs[j]
		if a.lb != b.lb {
			return a.lb < b.lb
		}
		if a.rb != b.rb {
			return a.rb < b.rb
		}
		if a.rb&1 == 0 {
			return a.t < b.t
		}
		return a.t > b.t
	})

	const mx int = 1e5
	var cnt, scnt, st [mx + 1]int
	for i := 0; i <= mx; i++ {
		scnt[i] = i
		st[i] = mx
	}
	st[0] = 0
	l, r, now := 1, 1, 0
	move := func(v, d int) {
		if d > 0 {
			cnt[v]++
			st[cnt[v]]--
			scnt[st[cnt[v]]] = cnt[v]
		} else {
			c := cnt[v]
			cnt[v]--
			i := st[c]
			st[c]++
			scnt[i] = cnt[v]
		}
	}
	timeSlip := func(l, r int) {
		m := ms[now]
		p, v := m.p, m.v
		if l <= p && p < r {
			move(a[p], -1)
			move(v, 1)
		}
		a[p], ms[now].v = v, a[p]
	}
	ans := make([]int, len(qs))
	for _, q := range qs {
		for ; r < q.r; r++ {
			move(a[r], 1)
		}
		for ; l < q.l; l++ {
			move(a[l], -1)
		}
		for l > q.l {
			l--
			move(a[l], 1)
		}
		for r > q.r {
			r--
			move(a[r], -1)
		}
		for ; now < q.t; now++ {
			timeSlip(q.l, q.r)
		}
		for now > q.t {
			now--
			timeSlip(q.l, q.r)
		}
		d := int(1e9)
		for i := st[1]; i+q.k <= mx; {
			c := scnt[i]
			if dd := scnt[i+q.k-1] - c; dd < d {
				d = dd
			}
			i = st[c+1]
		}
		if d == 1e9 {
			d = -1
		}
		ans[q.qid] = d
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1476G(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type query struct{ lb, rb, l, r, k, t, qid int }
	type modify struct{ pos, val int }

	var n, q, op int
	Fscan(in, &n, &q)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
	}
	blockSize := int(math.Round(math.Pow(float64(n), 2.0/3)))
	qs := []query{}
	ms := []modify{}
	for ; q > 0; q-- {
		if Fscan(in, &op); op == 1 {
			var l, r, k int
			Fscan(in, &l, &r, &k)
			qs = append(qs, query{l / blockSize, (r + 1) / blockSize, l, r + 1, k, len(ms), len(qs)})
		} else {
			var pos, val int
			Fscan(in, &pos, &val)
			ms = append(ms, modify{pos, val})
		}
	}
	sort.Slice(qs, func(i, j int) bool {
		a, b := qs[i], qs[j]
		if a.lb != b.lb {
			return a.lb < b.lb
		}
		if a.rb != b.rb {
			return a.rb < b.rb
		}
		if a.rb&1 == 0 {
			return a.t < b.t
		}
		return a.t > b.t
	})

	const mx int = 1e5
	var cnt, scnt, st [mx + 1]int
	for i := 0; i <= mx; i++ {
		scnt[i] = i
		st[i] = mx
	}
	st[0] = 0
	l, r, now := 1, 1, 0
	move := func(val, delta int) {
		if delta > 0 {
			cnt[val]++
			st[cnt[val]]--
			scnt[st[cnt[val]]] = cnt[val]
		} else {
			c := cnt[val]
			cnt[val]--
			i := st[c]
			st[c]++
			scnt[i] = cnt[val]
		}
	}
	timeSlip := func(l, r int) {
		m := ms[now]
		p, v := m.pos, m.val
		if l <= p && p < r {
			move(a[p], -1)
			move(v, 1)
		}
		a[p], ms[now].val = v, a[p]
	}
	ans := make([]int, len(qs))
	for _, q := range qs {
		for ; r < q.r; r++ {
			move(a[r], 1)
		}
		for ; l < q.l; l++ {
			move(a[l], -1)
		}
		for l > q.l {
			l--
			move(a[l], 1)
		}
		for r > q.r {
			r--
			move(a[r], -1)
		}
		for ; now < q.t; now++ {
			timeSlip(q.l, q.r)
		}
		for now > q.t {
			now--
			timeSlip(q.l, q.r)
		}
		res := int(1e9)
		for i := st[1]; i+q.k <= mx; {
			c := scnt[i]
			res = min(res, scnt[i+q.k-1]-c)
			i = st[c+1]
		}
		if res == 1e9 {
			res = -1
		}
		ans[q.qid] = res
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, m := readTwoNums(reader)
	A := readNNums(reader, n)

	Q := make([][]int, m)
	for i := 0; i < m; i++ {
		s, _ := reader.ReadBytes('\n')
		if s[0] == '1' {
			Q[i] = readNNums2(s, 4)
		} else {
			Q[i] = readNNums2(s, 3)
		}
	}

	res := solve(A, Q)

	var buf bytes.Buffer

	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d\n", res[i]))
	}

	fmt.Print(buf.String())
}

func readNNums2(buf []byte, n int) []int {
	res := make([]int, n)
	var pos int
	for i := 0; i < n; i++ {
		pos = readInt(buf, pos, &res[i]) + 1
	}
	return res
}

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
}

const BLK_SIZE = 2000
const N = 100013

func solve(A []int, Q [][]int) []int {
	q := make([]Query, 0, len(Q))
	upd := make([]Update, 0, len(Q))

	for i := 0; i < len(Q); i++ {
		if Q[i][0] == 1 {
			l, r, k := Q[i][1], Q[i][2], Q[i][3]
			q = append(q, Query{len(upd), l - 1, r - 1, k, len(q)})
		} else {
			p, x := Q[i][1], Q[i][2]
			p--
			upd = append(upd, Update{p, A[p], x})
			A[p] = x
		}
	}

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

	for i := len(upd) - 1; i >= 0; i-- {
		A[upd[i][0]] = upd[i][1]
	}

	cnt := make([]int, N)
	ord := make([]int, N)
	bounds := make([]*Pair, N)
	for i := 0; i < N; i++ {
		bounds[i] = &Pair{N, 0}
	}
	bounds[0] = &Pair{0, N - 1}

	add := func(x int) {
		c := cnt[x]
		ord[bounds[c].first]++
		bounds[c+1].second = bounds[c].first
		if bounds[c+1].first == N {
			bounds[c+1].first = bounds[c].first
		}
		if bounds[c].first == bounds[c].second {
			bounds[c].first = N - 1
		}
		bounds[c].first++
		cnt[x]++
	}

	rem := func(x int) {
		c := cnt[x]
		ord[bounds[c].second]--

		if bounds[c-1].first == N {
			bounds[c-1].second = bounds[c].second
		}
		bounds[c-1].first = bounds[c].second
		if bounds[c].first == bounds[c].second {
			bounds[c].first = N
		}
		bounds[c].second--
		cnt[x]--
	}

	var L, T int
	R := -1

	apply := func(i, fl int) {
		p := upd[i][0]
		x := upd[i][fl+1]
		if L <= p && p <= R {
			rem(A[p])
			add(x)
		}
		A[p] = x
	}

	res := make([]int, len(q))

	for _, cur := range q {
		t, l, r, k := cur.t, cur.l, cur.r, cur.k
		for T < t {
			apply(T, 1)
			T++
		}
		for T > t {
			T--
			apply(T, 0)
		}
		for R < r {
			R++
			add(A[R])
		}
		for L > l {
			L--
			add(A[L])
		}
		for R > r {
			rem(A[R])
			R--
		}
		for L < l {
			rem(A[L])
			L++
		}

		ans := N
		for i, j, sum := 0, 0, 0; i < N && ord[i] > 0; i = bounds[ord[i]].second + 1 {
			for j < N && ord[j] > 0 && sum < k {
				sum += bounds[ord[j]].second - bounds[ord[j]].first + 1
				j = bounds[ord[j]].second + 1
			}
			if sum >= k {
				ans = min(ans, ord[i]-ord[j-1])
			}
			sum -= bounds[ord[i]].second - bounds[ord[i]].first + 1
		}
		if ans == N {
			res[cur.i] = -1
		} else {
			res[cur.i] = ans
		}
	}

	return res
}

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

type Query struct {
	t, l, r, k, i int
}

func (a Query) Less(b Query) bool {
	if a.t/BLK_SIZE != b.t/BLK_SIZE {
		return a.t < b.t
	}

	if a.l/BLK_SIZE != b.l/BLK_SIZE {
		return a.l < b.l
	}

	if (a.l/BLK_SIZE)&1 == 1 {
		return a.r < b.r
	}
	return a.r > b.r
}

type Pair struct {
	first, second int
}

type Update [3]int

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, m := readTwoNums(reader)
	A := readNNums(reader, n)

	Q := make([][]int, m)
	for i := 0; i < m; i++ {
		s, _ := reader.ReadBytes('\n')
		if s[0] == '1' {
			Q[i] = readNNums2(s, 4)
		} else {
			Q[i] = readNNums2(s, 3)
		}
	}

	res := solve(A, Q)

	var buf bytes.Buffer

	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d\n", res[i]))
	}

	fmt.Print(buf.String())
}

func readNNums2(buf []byte, n int) []int {
	res := make([]int, n)
	var pos int
	for i := 0; i < n; i++ {
		pos = readInt(buf, pos, &res[i]) + 1
	}
	return res
}

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
}

const BLK_SIZE = 500
const N = 100013

func solve(A []int, Q [][]int) []int {
	q := make([]Query, 0, len(Q))
	upd := make([]Update, 0, len(Q))

	for i := 0; i < len(Q); i++ {
		tp := Q[i][0]
		if tp == 1 {
			l, r, k := Q[i][1], Q[i][2], Q[i][3]
			q = append(q, Query{len(upd), l - 1, r - 1, k, len(q)})
		} else {
			p, x := Q[i][1], Q[i][2]
			p--
			upd = append(upd, Update{p, A[p], x})
			A[p] = x
		}
	}

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

	cnt := make([]int, N)
	ord := make([]int, N)
	bounds := make([]*Pair, N)
	for i := 0; i < N; i++ {
		bounds[i] = &Pair{N, 0}
	}
	bounds[0] = &Pair{0, N - 1}

	add := func(x int) {
		c := cnt[x]
		ord[bounds[c].first]++
		bounds[c+1].second = bounds[c].first
		if bounds[c+1].first == N {
			bounds[c+1].first = bounds[c].first
		}
		if bounds[c].first == bounds[c].second {
			bounds[c].first = N - 1
		}
		bounds[c].first++
		cnt[x]++
	}

	rem := func(x int) {
		c := cnt[x]
		ord[bounds[c].second]--

		if bounds[c-1].first == N {
			bounds[c-1].second = bounds[c].second
		}
		bounds[c-1].first = bounds[c].second
		if bounds[c].first == bounds[c].second {
			bounds[c].first = N
		}
		bounds[c].second--
		cnt[x]--
	}

	var L, T int
	R := -1

	apply := func(i, fl int) {
		p := upd[i][0]
		x := upd[i][fl+1]
		if L <= p && p <= R {
			rem(A[p])
			add(x)
		}
		A[p] = x
	}

	res := make([]int, len(q))

	for _, cur := range q {
		t, l, r, k := cur.t, cur.l, cur.r, cur.k
		for T < t {
			apply(T, 1)
			T++
		}
		for T > t {
			T--
			apply(T, 0)
		}
		for R < r {
			R++
			add(A[R])
		}
		for L > l {
			L--
			add(A[L])
		}
		for R > r {
			rem(A[R])
			R--
		}
		for L < l {
			rem(A[L])
			L++
		}

		ans := N
		for i, j, sum := 0, 0, 0; i < N && ord[i] > 0; i = bounds[ord[i]].second + 1 {
			for j < N && ord[j] > 0 && sum < k {
				sum += bounds[ord[j]].second - bounds[ord[j]].first + 1
				j = bounds[ord[j]].second + 1
			}
			if sum >= k {
				ans = min(ans, ord[i]-ord[j-1])
			}
			sum -= bounds[ord[i]].second - bounds[ord[i]].first + 1
		}
		if ans == N {
			res[cur.i] = -1
		} else {
			res[cur.i] = ans
		}
	}

	return res
}

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

type Query struct {
	t, l, r, k, i int
}

func (a Query) Less(b Query) bool {
	if a.t/BLK_SIZE != b.t/BLK_SIZE {
		return a.t < b.t
	}

	if a.l/BLK_SIZE != b.l/BLK_SIZE {
		return a.l < b.l
	}

	if (a.l/BLK_SIZE)&1 == 1 {
		return a.r < b.r
	}
	return a.r > b.r
}

type Pair struct {
	first, second int
}

type Update [3]int