Now Dmitry has a session, and he has to pass $$$n$$$ exams. The session starts on day $$$1$$$ and lasts $$$d$$$ days. The $$$i$$$th exam will take place on the day of $$$a_i$$$ ($$$1 \le a_i \le d$$$), all $$$a_i$$$ — are different.    Sample, where $$$n=3$$$, $$$d=12$$$, $$$a=[3,5,9]$$$. Orange — exam days. Before the first exam Dmitry will rest $$$2$$$ days, before the second he will rest $$$1$$$ day and before the third he will rest $$$3$$$ days. For the session schedule, Dmitry considers a special value $$$\mu$$$ — the smallest of the rest times before the exam for all exams. For example, for the image above, $$$\mu=1$$$. In other words, for the schedule, he counts exactly $$$n$$$ numbers  — how many days he rests between the exam $$$i-1$$$ and $$$i$$$ (for $$$i=0$$$ between the start of the session and the exam $$$i$$$). Then it finds $$$\mu$$$ — the minimum among these $$$n$$$ numbers.Dmitry believes that he can improve the schedule of the session. He may ask to change the date of one exam (change one arbitrary value of $$$a_i$$$). Help him change the date so that all $$$a_i$$$ remain different, and the value of $$$\mu$$$ is as large as possible.For example, for the schedule above, it is most advantageous for Dmitry to move the second exam to the very end of the session. The new schedule will take the form:    Now the rest periods before exams are equal to $$$[2,2,5]$$$. So, $$$\mu=2$$$. Dmitry can leave the proposed schedule unchanged (if there is no way to move one exam so that it will lead to an improvement in the situation).

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of input test cases. The descriptions of test cases follow. An empty line is written in the test before each case. The first line of each test case contains two integers $$$n$$$ and $$$d$$$ ($$$2 \le n \le 2 \cdot 10^5, 1 \le d \le 10^9$$$) — the number of exams and the length of the session, respectively. The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le d, a_i < a_{i+1}$$$), where the $$$i$$$-th number means the date of the $$$i$$$-th exam. It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output the maximum possible value of $$$\mu$$$ if Dmitry can move any one exam to an arbitrary day. All values of $$$a_i$$$ should remain distinct.

NoteThe first sample is parsed in statement.One of the optimal schedule changes for the second sample:   Initial schedule.  New schedule.In the third sample, we need to move the exam from day $$$1$$$ to any day from $$$4$$$ to $$$100$$$.In the fourth sample, any change in the schedule will only reduce $$$\mu$$$, so the schedule should be left as it is.In the fifth sample, we need to move the exam from day $$$1$$$ to any day from $$$100000000$$$ to $$$300000000$$$.One of the optimal schedule changes for the sixth sample:   Initial schedule.  New schedule.In the seventh sample, every day is exam day, and it is impossible to rearrange the schedule.

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		judge := func(skip int, limit int64) bool {
			last := a[0]
			find := false
			for i := 1; i < n+1; i++ {
				if i == skip {
					continue
				}
				if a[i]-last <= limit {
					return false
				}
				if a[i]-last > limit*2+1 {
					find = true
				}
				last = a[i]
			}
			if skip == n {
				return find || d-a[n-1] > limit
			}
			return find || d-a[n] > limit
		}
		check := func(limit int64) bool {
			last := a[0]
			for i := 1; i < n+1; i++ {
				if a[i]-last <= limit {
					return judge(i, limit) || (i > 1 && judge(i-1, limit))
				}
				last = a[i]
			}
			return true
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

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

func CF1650E(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c := 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		n, d := 0, 0
		fmt.Fscan(in, &n, &d)
		min_gap, min_pos := d, 0
		arr := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &arr[i])
			if arr[i]-arr[i-1]-1 < min_gap {
				min_gap, min_pos = arr[i]-arr[i-1]-1, i
			}
		}
		b := []int{}
		for i := 0; i <= n; i++ {
			if i != min_pos {
				b = append(b, arr[i])
			}
		}
		ans := help(b, d)
		if min_pos > 1 {
			b[min_pos-1] = arr[min_pos]
		}
		ans = max(ans, help(b, d))
		fmt.Fprintln(out, ans)
	}
}

func help(b []int, d int) int {
	mx, mm := math.MinInt32, math.MaxInt32
	for i := 1; i < len(b); i++ {
		mx = max(mx, b[i]-b[i-1]-1)
		mm = min(mm, b[i]-b[i-1]-1)
	}
	return min(mm, max(d-b[len(b)-1]-1, (mx-1)/2))
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

package main

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n, d := cin.NextInt(), cin.NextInt()
	a := cin.NextInts(n)
	r := make([]int, n)
	lst := 0
	for i := 0; i < n; i++ {
		r[i] = a[i] - lst - 1
		lst = a[i]
	}
	var largestHole, largestHoleIdx int
	for i := 0; i < n; i++ {
		if r[i] > largestHole {
			largestHole = r[i]
			largestHoleIdx = i
		}
	}
	prefixMinR, suffixMinR := make([]int, n), make([]int, n)
	prefixMinR[0] = r[0]
	for i := 1; i < n; i++ {
		prefixMinR[i] = prefixMinR[i-1]
		if prefixMinR[i] > r[i] {
			prefixMinR[i] = r[i]
		}
	}
	suffixMinR[n-1] = r[n-1]
	for i := n - 2; i >= 0; i-- {
		suffixMinR[i] = suffixMinR[i+1]
		if suffixMinR[i] > r[i] {
			suffixMinR[i] = r[i]
		}
	}
	ans := prefixMinR[n-1]
	// cerr.Println("initAns", ans)
	// cerr.Println("r", r, "prefixMinR", prefixMinR, "suffixMinR", suffixMinR)
	for i := range r {
		// try move the i-th exam yo
		if i+1 < n {
			lo := 0
			if i > 0 {
				lo = a[i-1]
			}
			hi := a[i+1]
			{
				// self hi
				mi := lo + (hi-lo)/2
				cans := mi - lo - 1
				if rio := hi - mi - 1; rio < cans {
					cans = rio
				}
				if i > 0 && prefixMinR[i-1] < cans {
					cans = prefixMinR[i-1]
				}
				if i+2 < n && suffixMinR[i+2] < cans {
					cans = suffixMinR[i+2]
				}
				if cans > ans {
					ans = cans
				}
				// cerr.Printf("i=%d, lo=%d, hi=%d, mi=%d, cans=%d, ans=%d\n", i, lo, hi, mi, cans, ans)
			}
			if a[n-1] < d {
				// last hi
				cans := d - a[n-1] - 1
				if rio := hi - lo - 1; rio < cans {
					cans = rio
				}
				if i > 0 && prefixMinR[i-1] < cans {
					cans = prefixMinR[i-1]
				}
				if i+2 < n && suffixMinR[i+2] < cans {
					cans = suffixMinR[i+2]
				}
				if cans > ans {
					ans = cans
				}
				// cerr.Printf("i=%d, lo=%d, hi=%d, cans=%d, ans=%d\n", i, lo, hi, cans, ans)
			}
			if (largestHoleIdx < i || largestHoleIdx > i+1) && largestHole >= 1 {
				// other hi
				lohole := 0
				if largestHoleIdx > 0 {
					lohole = a[largestHoleIdx-1]
				}
				hihole := a[largestHoleIdx]
				mihole := lohole + (hihole-lohole)/2
				cans := mihole - lohole - 1
				if rio := hihole - mihole - 1; rio < cans {
					cans = rio
				}
				if rio := hi - lo - 1; rio < cans {
					cans = rio
				}
				if i > 0 && prefixMinR[i-1] < cans {
					cans = prefixMinR[i-1]
				}
				if i+2 < n && suffixMinR[i+2] < cans {
					cans = suffixMinR[i+2]
				}
				if cans > ans {
					ans = cans
				}
				// cerr.Println("i=", i, "lohole=", lohole, "hihole=", hihole, "mihole=", mihole, "cans=", cans, "ans=", ans)
			}
		} else {
			cans := d - a[i-1] - 1
			if prefixMinR[i-1] < cans {
				cans = prefixMinR[i-1]
			}
			if cans > ans {
				ans = cans
			}
			// cerr.Println("i=", i, "cans=", cans, "ans=", ans)
		}

	}
	// cerr.Println("===================")
	cout.Println(ans)
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

func (i *scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(i.Next(), 10, 64)
	return v
}

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		judge := func(skip int, limit int64) bool {
			last := a[0]
			find := false
			for i := 1; i < n+1; i++ {
				if i == skip {
					continue
				}
				if a[i]-last <= limit {
					return false
				}
				if a[i]-last > limit*2+1 {
					find = true
				}
				last = a[i]
			}
			return find || d-a[n] > limit
		}
		check := func(limit int64) bool {
			last := a[0]
			for i := 1; i < n+1; i++ {
				if a[i]-last <= limit {
					return judge(i, limit) || (i > 1 && judge(i-1, limit))
				}
				last = a[i]
			}
			return true
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		check := func(limit int64) bool {
			last := a[0]
			meet := false
			solved := d-a[n] > limit
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if a[i]-last > limit*2+1 {
						solved = true
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					if i > 1 && !solved {
						solved = a[i]-a[i-2] > limit*2+1
						if solved {
							last = a[i]
						}
					}
				}
			}

			return !meet || solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		check := func(limit int64) bool {
			end := d-a[n] > limit
			last := a[0]
			meet := false
			solved := false
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if a[i]-last > limit*2+1 {
						solved = true
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = end || a[i]-ll > limit*2+1
				}
			}
			return !meet || solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		check := func(limit int64) bool {
			end := d-a[n] > limit
			last := a[0]
			meet := false
			solved := true
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if meet && !solved {
						if a[i]-last > limit*2+1 {
							solved = true
						}
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = end || a[i]-ll > limit*2+1
				}
			}
			return solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		check := func(limit int64) bool {
			end := d-a[n] > limit
			last := a[0]
			meet := false
			solved := true
			if limit == 3 {
				fmt.Println(end)
			}
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if meet && !solved {
						if a[i]-last > limit*2+1 {
							solved = true
						}
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = end || a[i]-ll > limit*2+1
				}
			}
			return solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		a[0] = 0
		check := func(limit int64) bool {
			end := d-a[n] > limit+1
			last := a[0]
			meet := false
			solved := true
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if meet && !solved {
						if a[i]-last > limit*2+1 {
							solved = true
						}
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = end || a[i]-ll > limit*2+1
				}
			}
			return solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		a[0] = 0
		check := func(limit int64) bool {
			end := d-a[n] > limit+1
			last := a[0]
			meet := false
			solved := true
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if meet && !solved {
						if a[i]-last > limit*2+1 {
							solved = true
						}
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = end || a[i]-ll > limit*2+1
				}
			}
			return solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		check := func(limit int64) bool {
			first, end := a[0] > limit*2+1, d-a[len(a)-1] > limit+1
			last := int64(0)
			meet := false
			solved := true
			for i := 0; i < n; i++ {
				if a[i]-last > limit {
					if meet && !solved {
						if a[i]-last > limit*2+1 {
							solved = true
						}
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = first || end || a[i]-ll > limit*2+1
				}
			}
			return solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

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

func CF1650E(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c := 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		n, d := 0, 0
		fmt.Fscan(in, &n, &d)
		min_gap, min_pos := d, 0
		arr := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &arr[i])
			if arr[i]-arr[i-1]-1 < min_gap {
				min_gap, min_pos = arr[i]-arr[i-1]-1, i
			}
		}
		b := []int{}
		for i := 0; i <= n; i++ {
			if i != min_pos {
				b = append(b, arr[i])
			}
		}
		ans := help(b, d)
		if min_pos > 1 {
			b[min_pos-1] = arr[min_pos]
		}
		ans = max(ans, help(b, d))
		fmt.Fprintln(out, ans)
	}
}

func help(b []int, d int) int {
	mx, mm := math.MinInt32, math.MaxInt32
	for i := 1; i < len(b); i++ {
		mx = max(mx, b[i]-b[i-1]-1)
		mm = min(mm, b[i]-b[i-1]-1)
	}
	return min(mm, max(d-b[len(b)-1], (mx-1)/2))
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

package main

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n, d := cin.NextInt(), cin.NextInt()
	a := cin.NextInts(n)
	r := make([]int, n)
	lst := 0
	for i := 0; i < n; i++ {
		r[i] = a[i] - lst - 1
		lst = a[i]
	}
	prefixMinR, suffixMinR := make([]int, n), make([]int, n)
	prefixMinR[0] = r[0]
	for i := 1; i < n; i++ {
		prefixMinR[i] = prefixMinR[i-1]
		if prefixMinR[i] > r[i] {
			prefixMinR[i] = r[i]
		}
	}
	suffixMinR[n-1] = r[n-1]
	for i := n - 2; i >= 0; i-- {
		suffixMinR[i] = suffixMinR[i+1]
		if suffixMinR[i] > r[i] {
			suffixMinR[i] = r[i]
		}
	}
	ans := prefixMinR[n-1]
	// cerr.Println("initAns", ans)
	// cerr.Println("r", r, "prefixMinR", prefixMinR, "suffixMinR", suffixMinR)
	for i := range r {
		// try move the i-th exam yo
		if i+1 < n {
			lo := 0
			if i > 0 {
				lo = a[i-1]
			}
			hi := a[i+1]
			mi := lo + (hi-lo)/2
			cans := mi - lo - 1
			if rio := hi - mi - 1; rio < cans {
				cans = rio
			}
			if i > 0 && prefixMinR[i-1] < cans {
				cans = prefixMinR[i-1]
			}
			if i+2 < n && suffixMinR[i+2] < cans {
				cans = suffixMinR[i+2]
			}
			if cans > ans {
				ans = cans
			}
			// cerr.Printf("i=%d, lo=%d, hi=%d, mi=%d, cans=%d, ans=%d\n", i, lo, hi, mi, cans, ans)
			// cerr.Printf("move %d: %d\n", i, cans)
		} else {
			cans := d - a[i-1] - 1
			if prefixMinR[i-1] < cans {
				cans = prefixMinR[i-1]
			}
			if cans > ans {
				ans = cans
			}
			// cerr.Printf("move %d: %d\n", i, cans)
		}

	}
	cout.Println(ans)
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

func (i *scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(i.Next(), 10, 64)
	return v
}

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker


Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So his task is to make all the chemicals volumes equal.To do this, Amr can do two different kind of operations.   Choose some chemical i and double its current volume so the new volume will be 2ai  Choose some chemical i and divide its volume by two (integer division) so the new volume will be  Suppose that each chemical is contained in a vessel of infinite volume. Now Amr wonders what is the minimum number of operations required to make all the chemicals volumes equal?

The first line contains one number n (1 ≤ n ≤ 105), the number of chemicals. The second line contains n space separated integers ai (1 ≤ ai ≤ 105), representing the initial volume of the i-th chemical in liters.

Output one integer the minimum number of operations required to make all the chemicals volumes equal.

NoteIn the first sample test, the optimal solution is to divide the second chemical volume by two, and multiply the third chemical volume by two to make all the volumes equal 4.In the second sample test, the optimal solution is to divide the first chemical volume by two, and divide the second and the third chemical volumes by two twice to make all the volumes equal 1.

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

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

type Target struct {
  Value, Count, Cost int
}

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

  n := getI()
  max_value := 0
  chemicals := make([]int, n)
  for i := range chemicals {
    x := getI()
    if x > max_value {
      max_value = x
    }
    chemicals[i] = x
  }
  targets := make([]*Target, max_value + 1)
  target_values := []int{}
  x := max_value
  for x != 0 {
    targets[x] = &Target{ Value: x }
    target_values = append(target_values, x)
    y := x << 1
    for {
      if y > max_value || targets[y] != nil {
        break
      }
      targets[y] = &Target{ Value: y }
      target_values = append(target_values, y)
      y <<= 1
    }
    x >>= 1
  }

  costs := make([]int, max_value + 1)
  for i := range costs {
    costs[i] = -1
  }
  cost_values := []int{}
  for _, x := range chemicals {
    cost := 0
    cost_values = cost_values[0:0]
    for x != 0 {
      costs[x] = cost
      cost_values = append(cost_values, x)
      y := x << 1
      extra_cost := 1
      for y <= max_value {
        if costs[y] != -1 {
          break
        }
        costs[y] = cost + extra_cost
        cost_values = append(cost_values, y)
        y <<= 1
        extra_cost++
      }
      x >>= 1
      cost++
    }
    for _, value := range target_values {
      if costs[value] != -1 {
        target := targets[value]
        target.Cost += costs[value]
        target.Count++
      }
    }
    for _, value := range cost_values {
      costs[value] = -1
    }
  }

  best := -1
  for _, value := range target_values {
    target := targets[value]
    if target.Count == n {
      if best == -1 || target.Cost < best {
        best = target.Cost
      }
    }
  }

  writer.WriteString(fmt.Sprintf("%d\n", best))
}

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

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

type Target struct {
  Value, Count, Cost int
}

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

  n := getI()
  max_value := 0
  chemicals := make([]int, n)
  for i := range chemicals {
    x := getI()
    if x > max_value {
      max_value = x
    }
    chemicals[i] = x
  }
  targets := make([]*Target, max_value + 1)
  target_values := []int{}
  x := max_value
  for x != 0 {
    targets[x] = &Target{ Value: x }
    target_values = append(target_values, x)
    y := x << 1
    for {
      if y > max_value || targets[y] != nil {
        break
      }
      targets[y] = &Target{ Value: y }
      target_values = append(target_values, y)
      y <<= 1
    }
    x >>= 1
  }

  costs := make([]int, max_value + 1)
  for i := range costs {
    costs[i] = -1
  }
  cost_values := []int{}
  for _, x := range chemicals {
    cost := 0
    cost_values = cost_values[0:0]
    for x != 0 {
      costs[x] = cost
      cost_values = append(cost_values, x)
      y := x << 1
      extra_cost := 1
      for y < max_value {
        if costs[y] != -1 {
          break
        }
        costs[y] = cost + extra_cost
        cost_values = append(cost_values, y)
        y <<= 1
        extra_cost++
      }
      x >>= 1
      cost++
    }
    for _, value := range target_values {
      if costs[value] != -1 {
        target := targets[value]
        target.Cost += costs[value]
        target.Count++
      }
    }
    for _, value := range cost_values {
      costs[value] = -1
    }
  }

  best := -1
  for _, value := range target_values {
    target := targets[value]
    if target.Count == n {
      if best == -1 || target.Cost < best {
        best = target.Cost
      }
    }
  }

  writer.WriteString(fmt.Sprintf("%d\n", best))
}


Let's call an array $$$a$$$ consisting of $$$n$$$ positive (greater than $$$0$$$) integers beautiful if the following condition is held for every $$$i$$$ from $$$1$$$ to $$$n$$$: either $$$a_i = 1$$$, or at least one of the numbers $$$a_i - 1$$$ and $$$a_i - 2$$$ exists in the array as well.For example:   the array $$$[5, 3, 1]$$$ is beautiful: for $$$a_1$$$, the number $$$a_1 - 2 = 3$$$ exists in the array; for $$$a_2$$$, the number $$$a_2 - 2 = 1$$$ exists in the array; for $$$a_3$$$, the condition $$$a_3 = 1$$$ holds;  the array $$$[1, 2, 2, 2, 2]$$$ is beautiful: for $$$a_1$$$, the condition $$$a_1 = 1$$$ holds; for every other number $$$a_i$$$, the number $$$a_i - 1 = 1$$$ exists in the array;  the array $$$[1, 4]$$$ is not beautiful: for $$$a_2$$$, neither $$$a_2 - 2 = 2$$$ nor $$$a_2 - 1 = 3$$$ exists in the array, and $$$a_2 \ne 1$$$;  the array $$$[2]$$$ is not beautiful: for $$$a_1$$$, neither $$$a_1 - 1 = 1$$$ nor $$$a_1 - 2 = 0$$$ exists in the array, and $$$a_1 \ne 1$$$;  the array $$$[2, 1, 3]$$$ is beautiful: for $$$a_1$$$, the number $$$a_1 - 1 = 1$$$ exists in the array; for $$$a_2$$$, the condition $$$a_2 = 1$$$ holds; for $$$a_3$$$, the number $$$a_3 - 2 = 1$$$ exists in the array. You are given a positive integer $$$s$$$. Find the minimum possible size of a beautiful array with the sum of elements equal to $$$s$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases. Then $$$t$$$ lines follow, the $$$i$$$-th line contains one integer $$$s$$$ ($$$1 \le s \le 5000$$$) for the $$$i$$$-th test case.

Print $$$t$$$ integers, the $$$i$$$-th integer should be the answer for the $$$i$$$-th testcase: the minimum possible size of a beautiful array with the sum of elements equal to $$$s$$$.

NoteConsider the example test:  in the first test case, the array $$$[1]$$$ meets all conditions;  in the second test case, the array $$$[3, 4, 1]$$$ meets all conditions;  in the third test case, the array $$$[1, 2, 4]$$$ meets all conditions;  in the fourth test case, the array $$$[1, 4, 6, 8, 10, 2, 11]$$$ meets all conditions.

package main
import(
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)
		var ret int = int(math.Sqrt(float64(n)))
		for ret * ret < n {
			ret++
		}
		fmt.Println(ret)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
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 x int
		fmt.Fscan(in,&x)
		if x == 1 {
			fmt.Fprintln(out,1)
		} else if math.Mod(float64(x),(math.Sqrt(float64(x)))) == 0.0 {
			fmt.Fprintln(out,int(math.Sqrt(float64(x))))
		} else {
			fmt.Fprintln(out,int(math.Sqrt(float64(x)))+1)
		}
	}
}

package main

import "fmt"

func main() {
	var t, s int
	fmt.Scan(&t)
	sumOfSize := make([]int, 72, 72)
	for i := 1; i <= 71; i++ {
		sumOfSize[i] = i*i
	}
	getSize := func(s int) (size int) {
		i := 1
		for sumOfSize[i] < s {
			i++
		}
		return i
	}
	for i := 0; i < t; i++ {
		fmt.Scan(&s)
		fmt.Println(getSize(s))
	}
}

package main

import ."fmt"
//import "sort"
import "bufio"
import "os"
import "math"
//import "string"
//import "time"
//import ."math"

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

func main() {
    defer writer.Flush()
    t := sint64();
    for i := int64(0); i < t; i++ {
        n := float64(sint64());
        printf("%.0f\n", math.Ceil(math.Sqrt(n)));
    }

}
func resh(n int64) []int64 {
    p := make([]bool, n + 1)
    for i := int64(2); i <= n; i++ {
        p[i] = true
    }
    for i := int64(0); i <= n; i++ {
		if p[i] {
			for j := i * i; j <= n; j += i {
				p[j] = false
				//Print(j, " ")
			}
		}
	}
	ans := make([]int64, 0)
	for i := int64(0); i < n; i++ {
	    if p[i] {
	        ans = append(ans, i)
	    }
	}
	return ans
}
func printf(f string, a ...interface{}) {
	Fprintf(writer, f, a...)
}
func sstring() string {
	scanner.Scan()
	return scanner.Text()
}
func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sum(a []int64) int64{
    ans := int64(0)
    for _, i := range a {
        ans += i
    }
    return ans
}
func abs(x int64) int64 {
    if x < 0 {
        return 0 - x
    }
    return x
}
func min(x, y int64) int64 {
    if x < y {
        return x
    }
    return y
}
func ceil(a, b int64) int64{
    s := a / b
    if a % b >= 0 {
        s++
    }
    if s == 0 {
        s = 1
    }
    return s
}
func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

package main

import ."fmt"
//import "sort"
import "bufio"
import "os"
import "math"
//import "string"
//import "time"
//import ."math"

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

func main() {
    defer writer.Flush()
    t := sint64();
    for i := int64(0); i < t; i++ {
        n := float64(sint64());
        printf("%.0f ", math.Ceil(math.Sqrt(n)));
    }

}
func resh(n int64) []int64 {
    p := make([]bool, n + 1)
    for i := int64(2); i <= n; i++ {
        p[i] = true
    }
    for i := int64(0); i <= n; i++ {
		if p[i] {
			for j := i * i; j <= n; j += i {
				p[j] = false
				//Print(j, " ")
			}
		}
	}
	ans := make([]int64, 0)
	for i := int64(0); i < n; i++ {
	    if p[i] {
	        ans = append(ans, i)
	    }
	}
	return ans
}
func printf(f string, a ...interface{}) {
	Fprintf(writer, f, a...)
}
func sstring() string {
	scanner.Scan()
	return scanner.Text()
}
func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sum(a []int64) int64{
    ans := int64(0)
    for _, i := range a {
        ans += i
    }
    return ans
}
func abs(x int64) int64 {
    if x < 0 {
        return 0 - x
    }
    return x
}
func min(x, y int64) int64 {
    if x < y {
        return x
    }
    return y
}
func ceil(a, b int64) int64{
    s := a / b
    if a % b >= 0 {
        s++
    }
    if s == 0 {
        s = 1
    }
    return s
}
func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1550A
Date: 19/10/21
User: pepradere
URL: https://codeforces.com/problemset/problem/1550/A
Problem: CF1550A
**/
var n = 0

func (in *CF1550A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n = in.NextInt()

		if n < 2 {
			fmt.Println(n)
		} else{
			sol := 2
			aux := 3
			for i := 4; i < n; i+=aux{
				sol++
				aux+=2
			}
			fmt.Println(sol)
		}

	}
}

func f(sum, m int) int {
	if n-sum == 0 {
		return 0
	}
	if n-sum < 0 {
		return -1
	}

	a := f(sum+m+1, m+1)
	b := f(sum+m+2, m+1)
	c := f(sum+m+1, m+2)
	d := f(sum+m+2, m+2)
	e := f(sum+1, m)

	arr := []int{a, b, c, d, e}
	sort.Ints(arr)
	for i := 0; i < len(arr); i++ {
		if arr[i] >= 0 {
			//memo[sum][n] =
			return arr[i] + 1
		}
	}

	return -1
}

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

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

package main

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

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

func solve(s int) int {
	var (
		c int
		i = 1
	)
	for ; s >= i; i += 2 {
		c++
		s -= i
	}
	if s > 0 {
		c++
	}
	return c
}

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

package main

import "fmt"

func main() {
	var tc, s, cnt, i int
	fmt.Scan(&tc)
	for tc > 0 {
		tc = tc - 1
		fmt.Scan(&s)
		var add int
		add = 1
		cnt = 0
		i = 0
		for cnt < s {
			cnt = cnt + add
			add = add + 2
			i = i + 1
		}
		fmt.Println(i)
	}
}

package main

import (
	"fmt"
)

func main() {
	var ans [5050]int
	for i := 1; i < 72; i++ {
		for j := i * i; j > (i-1)*(i-1); j-- {
			ans[j] = i
		}
	}

	var q int
	fmt.Scanln(&q)

	for q > 0 {
		q--

		var x int
		fmt.Scanln(&x)
		fmt.Println(ans[x])
	}
}

package main

import (
	"fmt"
	"math"
)

func beauty(n int) int {
	sqrt := math.Sqrt(float64(n))
	sqrt = math.Ceil(sqrt)
	return int(sqrt)
}

func main() {
	var t int

	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var v int
		fmt.Scan(&v)
		fmt.Println(beauty(v))
	}
}

package main

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

var (
	scn  = bufio.NewReader(os.Stdin)
	prnt = bufio.NewWriter(os.Stdout)
)

func solve() {
	var a int
	fmt.Fscan(scn, &a)
	sz := 0
	current := 1
	for a > 0 {
		a -= current
		sz += 1
		current += 2
	}
	fmt.Fprintln(prnt, sz)
}

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

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

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

func queue(queue []int, element int) []int {
	queue = append(queue, element)
	return queue
}

func dequeue(queue []int) []int {
	return queue[1:]
}

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

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi := 0; oi < k; oi++ {
		pcur,_ := Readln(reader)
		cur,_ := strconv.Atoi(pcur)
		i:=1
		for ((i + 1) *((1+i)/2)) /  2 < cur{
			i+=2
		}

		fmt.Println( (i+1)/2)
	}

}

package main

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

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

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

func factorial(n int64) int64 {
	if n <= 1{
		return 1
	}
	return n * factorial(n - 1)
}

func fibanaci(n int64) int64 {
	if n == 0 {
		return 0
	}
	if n == 1 {
		return 1
	}
	return fibanaci(n - 1) + fibanaci(n - 2)
}

func abs(x int64) int64{
	if x >= 0{
		return x
	}else{
		return (-1) * x
	}
}

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

	}
	return m
}

func lcm(x, y int64) int64{
	var ans int64
	ans = (x * y) / gcd(x, y)
	return int64(ans)
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

var p int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &p)
	for o := 0; o < p; o++ {
		var s float64
		fmt.Fscan(input,&s)
		if int64(math.Sqrt(s)) * 1000000000 - int64(math.Sqrt(s) * 1000000000) == 0.0{
			fmt.Println(int64(math.Sqrt(s)))
		}else{
			fmt.Println(int64(math.Sqrt(s)) + 1)
		}
	}
}

package main

import "fmt"

func main() {
	arr := []int{}
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var s int
		fmt.Scan(&s)
		x := 1
		for {

			if x*x >= s {
				arr = append(arr, x)
				break
			}
			x++
		}
	}
	for i := 0; i < len(arr); i++ {
		fmt.Println(arr[i])
	}
}

package main
import "fmt"

func main() {
   var t int
   var a int
   fmt.Scanln(&t)
   for t > 0 {
       fmt.Scanln(&a)
       i := 0
       odd := 1
       for a > 0 {
           a -= odd
           i++
           odd += 2
       }
       fmt.Println(i)
       t--
   }
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scanf("%d\n", &t)
	for t > 0 {
		n := 0
		fmt.Scanf("%d\n", &n)
		fmt.Println(solve(n))
		t--
	}
}

func solve(n int) int {
	if n == 1 {
		return 1
	}
	s := []int{1, 2}
	for {
		if n-sum(s) < len(s) {
			return len(s)
		}
		s = append(s, s[len(s)-1]+2)
	}

}

func sum(n []int) int {
	sum := 0
	for _, v := range n {
		sum += v
	}
	return sum
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
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 x int
		fmt.Fscan(in,&x)
		if x == 1 {
			fmt.Fprintln(out,1)
		} else if x==3 || x==5 {
			fmt.Fprintln(out,0)
		} else if math.Mod(float64(x),(math.Sqrt(float64(x)))) == 0.0 {
			fmt.Fprintln(out,int(math.Sqrt(float64(x))))
		} else {
			fmt.Fprintln(out,int(math.Sqrt(float64(x)))+1)
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
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 x int
		fmt.Fscan(in,&x)
		if x == 1 {
			fmt.Fprintln(out,1)
		} else if x==3 || x==5 {
			fmt.Fprintln(out,0)
		} else if float64(x)/(math.Sqrt(float64(x))) == 0.0 {
			fmt.Fprintln(out,int(math.Sqrt(float64(x))))
		} else {
			fmt.Fprintln(out,int(math.Sqrt(float64(x)))+1)
		}
	}
}

package main

import "fmt"

func main() {
	var t, s int
	fmt.Scanf("%d", &t)
	sumOfSize := make([]int, 72, 72)
	for i := 1; i <= 71; i++ {
		sumOfSize[i] = i*i
	}
	getSize := func(s int) (size int) {
		i := 1
		for sumOfSize[i] < s {
			i++
		}
		return i
	}
	for i := 0; i < t; i++ {
		fmt.Scanf("%d", &s)
		fmt.Println(getSize(s))
	}
}

package main

import "fmt"

func main() {
	var t, s int
	fmt.Scanf("%d", &t)
	sumOfSize := make([]int, 5001, 5001)
	for i := 1; i <= 5000; i++ {
		sumOfSize[i] = i*i
	}
	getSize := func(s int) (size int) {
		i := 1
		for sumOfSize[i] < s {
			i++
		}
		return i
	}
	for i := 0; i < t; i++ {
		fmt.Scanf("%d", &s)
		fmt.Println(getSize(s))
	}
}


Mocha wants to be an astrologer. There are $$$n$$$ stars which can be seen in Zhijiang, and the brightness of the $$$i$$$-th star is $$$a_i$$$. Mocha considers that these $$$n$$$ stars form a constellation, and she uses $$$(a_1,a_2,\ldots,a_n)$$$ to show its state. A state is called mathematical if all of the following three conditions are satisfied:  For all $$$i$$$ ($$$1\le i\le n$$$), $$$a_i$$$ is an integer in the range $$$[l_i, r_i]$$$. $$$\sum \limits _{i=1} ^ n a_i \le m$$$. $$$\gcd(a_1,a_2,\ldots,a_n)=1$$$. Here, $$$\gcd(a_1,a_2,\ldots,a_n)$$$ denotes the greatest common divisor (GCD) of integers $$$a_1,a_2,\ldots,a_n$$$.Mocha is wondering how many different mathematical states of this constellation exist. Because the answer may be large, you must find it modulo $$$998\,244\,353$$$.Two states $$$(a_1,a_2,\ldots,a_n)$$$ and $$$(b_1,b_2,\ldots,b_n)$$$ are considered different if there exists $$$i$$$ ($$$1\le i\le n$$$) such that $$$a_i \ne b_i$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 50$$$, $$$1 \le m \le 10^5$$$) — the number of stars and the upper bound of the sum of the brightness of stars. Each of the next $$$n$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le m$$$) — the range of the brightness of the $$$i$$$-th star.

Print a single integer — the number of different mathematical states of this constellation, modulo $$$998\,244\,353$$$.

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod = 998244353
	var n, m int
	Fscan(in, &n, &m)
	a := make([]struct{ l, r int }, n)
	minR := m
	for i := range a {
		Fscan(in, &a[i].l, &a[i].r)
		if a[i].r < minR {
			minR = a[i].r
		}
	}
	mu := make([]int8, minR+1)
	mu[1] = 1
	for i := 1; i <= minR; i++ {
		for j := i * 2; j <= minR; j += i {
			mu[j] -= mu[i]
		}
	}

	ans := int64(0)
	sum := make([]int, m+2)
	for mul, mu := range mu {
		if mu == 0 {
			continue
		}
		mm := m / mul
		dp := make([]int, mm+1)
		dp[0] = 1
		for _, p := range a {
			for j := 0; j <= mm; j++ {
				sum[j+1] = (sum[j] + dp[j]) % mod
			}
			l, r := (p.l-1)/mul+1, p.r/mul
			for j := 0; j < l; j++ {
				dp[j] = 0
			}
			for j := l; j < r; j++ {
				dp[j] = sum[j-l+1]
			}
			for j := r; j <= mm; j++ {
				dp[j] = (sum[j-l+1] - sum[j-r]) % mod
			}
		}
		res := int64(0)
		for _, v := range dp {
			res += int64(v)
		}
		ans += int64(mu) * res % mod
	}
	Fprint(out, (ans%mod+mod)%mod)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod = 998244353
	var n, m int
	Fscan(in, &n, &m)
	a := make([]struct{ l, r int }, n)
	minR := m
	for i := range a {
		Fscan(in, &a[i].l, &a[i].r)
		if a[i].r < minR {
			minR = a[i].r
		}
	}
	mu := make([]int8, m+1)
	mu[1] = 1
	for i := 1; i <= m; i++ {
		for j := i * 2; j <= m; j += i {
			mu[j] -= mu[i]
		}
	}

	ans := int64(0)
	sum := make([]int, m+2)
	for mul, mu := range mu[:minR+1] {
		if mu == 0 {
			continue
		}
		mm := m / mul
		dp := make([]int, mm+1)
		dp[0] = 1
		for _, p := range a {
			for j := 0; j <= mm; j++ {
				sum[j+1] = (sum[j] + dp[j]) % mod
			}
			l, r := (p.l-1)/mul+1, p.r/mul
			for j := 0; j < l; j++ {
				dp[j] = 0
			}
			for j := l; j < r; j++ {
				dp[j] = sum[j-l+1]
			}
			for j := r; j <= mm; j++ {
				dp[j] = (sum[j-l+1] - sum[j-r]) % mod
			}
		}
		res := int64(0)
		for _, v := range dp {
			res += int64(v)
		}
		ans += int64(mu) * res % mod
	}
	Fprint(out, (ans%mod+mod)%mod)
}

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

package main
import (
    "io"
    "os"
    "fmt"
    "bufio"
)
const N int = 1e5+10
const mod int = 998244353
var n, m int
var l, r [55]int
var g, f, dp [N]int

func get(x int) int {
    if x < 0 {
        return 0
    } else {
        return dp[x]
    }
}

func main() {
    var input io.Reader = bufio.NewReader(os.Stdin)
    fmt.Fscan(input, &n)
    fmt.Fscan(input, &m)
    for i := 1; i <= n; i++ {
        fmt.Fscan(input, &l[i])
        fmt.Fscan(input, &r[i])
    }

    for d := m; d >= 1; d-- {
        t := m / d
        for i := 0; i <= t; i++ {
            dp[i] = 1
        }
        for i := 1; i <= n; i++ {
            L := (l[i] + d - 1) / d
            R := r[i] / d + 1
            for j := 1; j <= t; j++ {
                f[j] = ((f[j-1] + get(j-L)) % mod - get(j-R) + mod) % mod
            }
            for j := 0; j <= t; j++ {
                dp[j] = f[j]
            }
        }
        g[d] = dp[t]
    }

    for d := m; d >= 1; d-- {
        for i := 2; i * d <= m; i++ {
            g[d] = (g[d] - g[i*d] + mod) % mod
        }
    }
    fmt.Print(g[1])
}

package main

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

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

	const mx int = 1e5
	mu := [mx + 1]int{1: 1}
	for i := 1; i <= mx; i++ {
		for j := i * 2; j <= mx; j += i {
			mu[j] -= mu[i]
		}
	}

	var n, m int
	Fscan(in, &n, &m)
	a := make([]struct{ l, r int }, n)
	for i := range a {
		Fscan(in, &a[i].l, &a[i].r)
	}

	//n = 50
	//m = 1e5
	//a =   make([]struct{ l, r int }, n)
	//for i := range a {
	//	a[i].l = 1
	//	a[i].r = 1e5
	//}

	ans := int64(0)

	for i := 1; i <= m; i++ {
		if mu[i] == 0 {
			continue
		}
		mul := i

		mm := m / mul

		dp := make([]int, mm+1)
		dp[0] = 1

		sum := make([]int, mm+1)

		for _, p := range a {
			sum[0] = dp[0]
			for j := 1; j <= mm; j++ {
				sum[j] = (sum[j-1] + dp[j]) % mod
			}
			l, r := p.l/mul, p.r/mul
			if p.l%mul > 0 {
				l++
			}
			for j := 0; j < l; j++ {
				dp[j] = 0
			}
			for j := l; j <= mm; j++ {
				dp[j] = sum[j-l]
				if j > r {
					dp[j] = (sum[j-l] - sum[j-r]) % mod
				}
			}
		}

		res := int64(0)
		for _, v := range dp {
			res += int64(v)
		}
		res %= mod

		//Println(i, res)

		ans += int64(mu[i]) * res
	}

	ans = (ans%mod + mod) % mod
	Fprintln(out, ans)
}

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


Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?

The first line of the input contains integer n (2 ≤ n ≤ 100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n. The second line contains n - 1 integer a1, a2, ..., an (1 ≤ ai ≤ n) — the numbers of episodes that Polycarpus has watched. All values of ai are distinct.

Print the number of the episode that Polycarpus hasn't watched.

package main

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

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

func ReadInt() uint64 {
    scanner.Scan()
    ans, _ := strconv.ParseUint(scanner.Text(), 10, 64)
    return ans
}

func PrintInt(value uint64) {
    writer.WriteString(strconv.FormatUint(value, 10))
    writer.WriteByte('\n')
}

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

    n := ReadInt()
    var sum, i uint64 = 0, 0

    for i = 1; i < n; i++ {
        sum += ReadInt()
    }

    PrintInt((1+n)*n/2 - sum)
}

package main

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

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

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

func PrintInts(ints ...int) {
    for _, value := range ints {
        writer.WriteString(strconv.Itoa(value))
        writer.WriteByte(' ')
    }
}

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

    // var n, m int = ReadInt32(), ReadInt32()
    // PrintInts(n, m)
    // writer.WriteByte('\n')
    // slice := []int{1, 2, 3, 4, 5}
    // PrintInts(slice...)

    var n int = ReadInt32()
    var sum int = 0

    for i := 1; i < n; i++ {
        sum += ReadInt32()
    }

    PrintInts((1+n)*n/2 - sum)
}

package main

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

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

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

func PrintInts(ints ...int) {
    for _, value := range ints {
        writer.WriteString(strconv.Itoa(value))
        writer.WriteByte(' ')
    }
}

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

    // var n, m int = ReadInt32(), ReadInt32()
    // PrintInts(n, m)
    // writer.WriteByte('\n')
    // slice := []int{1, 2, 3, 4, 5}
    // PrintInts(slice...)

    var n int = ReadInt32()
    var sum int64 = 0

    for i := 1; i < n; i++ {
        sum += int64(ReadInt32())
    }

    var ans int64

    ans = int64((1+n)*n/2) - sum

    fmt.Println(ans)
}


Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).This priority factor will be affected by three types of actions:   1. "X posted on Y's wall" (15 points),  2. "X commented on Y's post" (10 points),  3. "X likes Y's post" (5 points). X and Y will be two distinct names. And each action will increase the priority factor between X and Y (and vice versa) by the above value of points (the priority factor between X and Y is the same as the priority factor between Y and X).You will be given n actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you.

The first line contains your name. The second line contains an integer n, which is the number of actions (1 ≤ n ≤ 100). Then n lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters.

Print m lines, where m is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order. Note, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor. The lexicographical comparison is performed by the standard "<" operator in modern programming languages. The line a is lexicographically smaller than the line b, if either a is the prefix of b, or if exists such an i (1 ≤ i ≤ min(|a|, |b|)), that ai < bi, and for any j (1 ≤ j < i) aj = bj, where |a| and |b| stand for the lengths of strings a and b correspondently.

ahmed
3
ahmed posted on fatma's wall
fatma commented on ahmed's post
mona likes ahmed's post

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

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

type Friend struct {
  Name string
  Points int
}
type Friends []*Friend
func (friends Friends) Len() int {
  return len(friends)
}
func (friends Friends) Swap(i, j int) {
  friends[i], friends[j] = friends[j], friends[i]
}
func (friends Friends) Less(i, j int) bool {
  a, b := friends[i], friends[j]
  if a.Points != b.Points {
    return a.Points > b.Points
  }
  return a.Name < b.Name
}

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

  me := getS()
  factor := map[string]int{}
  n := getI()
  for i := 0; i < n; i++ {
    x, action := getS(), getS()
    points := 15
    if action == "posted" {
      getS()
    } else if action == "commented" {
      points = 10
      getS()
    } else {
      points = 5
    }
    y := getS()
    y = y[0:len(y)-2]
    getS()
    fmt.Fprintf(os.Stderr, "x = %s, y = %s\n", x, y)
    if factor[x] == 0 {
      factor[x] = 0
    }
    if factor[y] == 0 {
      factor[y] = 0
    }
    if x == me {
      factor[y] += points
    }
    if y == me {
      factor[x] += points
    }
  }
  friends := []*Friend{}
  for name, points := range factor {
    friends = append(friends, &Friend{ name, points })
  }
  sort.Sort(Friends(friends))
  for _, friend := range friends {
    fmt.Fprintf(os.Stderr, "%s %d\n", friend.Name, friend.Points)
  }
  for _, friend := range friends {
    if friend.Name != me {
      writer.WriteString(fmt.Sprintf("%s\n", friend.Name))
    }
  }
}


In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k - 1)m, (k - 1)m + l], and l < m. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly d units right. Find out the coordinate of the point, where Bob will fall down. The grasshopper falls down, if he finds himself not on the platform, but if he finds himself on the edge of the platform, he doesn't fall down.

The first input line contains 4 integer numbers n, d, m, l (1 ≤ n, d, m, l ≤ 106, l < m) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers m and l needed to find coordinates of the k-th platform: [(k - 1)m, (k - 1)m + l].

Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down.

package main

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

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

const MAX = (10000000 - 1)*(10000000) + (10000000 - 1)

func solve(n, d, m, l int64) int64 {
	ans := d
	for i := int64(0); i < n; i++ {
		l, r := i*m, i*m + l
		if ans < l {
			break
		} else if ans <= r {
			ans += d*((r - ans)/d + 1)
		}
	}

	return ans
}

func main() {
	defer w.Flush()

	var n, d, m, l int64
	fmt.Fscanf(r, "%d %d %d %d", &n, &d, &m, &l)

	fmt.Fprintf(w, "%v", solve(n, d, m, l))
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, d, m, l int64
	fmt.Fscanf(reader, "%d %d %d %d", &n, &d, &m, &l)
	var pos int64

	step := d
	for ;; pos += step {
		r := pos % m
		if r > l || pos > (n - 1) * m + l {
			fmt.Printf("%d", pos)
			return
		}

		if r == 0 && pos != 0 {
			pos = n * m / pos * pos
			if pos > (n - 1) * m + l {
				fmt.Printf("%d", pos)
				return
			}
		}
	}
}

package main

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

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

const MAX = (10000000 - 1)*(10000000) + (10000000 - 1)

func solve(n, d, m, l int) int {
	ans := d
	for i := 0; i < n; i++ {
		l, r := i*m, i*m + l
		if ans < l {
			break
		} else if ans <= r {
			ans += d*((r - ans)/d + 1)
		}
	}

	return ans
}

func main() {
	defer w.Flush()

	var n, d, m, l int
	fmt.Fscanf(r, "%d %d %d %d", &n, &d, &m, &l)

	fmt.Fprintf(w, "%v", solve(n, d, m, l))
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, d, m, l int64
	fmt.Fscanf(reader, "%d %d %d %d", &n, &d, &m, &l)
	var pos int64

	step := d
	for ;; pos += step {
		r := pos % m
		if r > l || pos > (n - 1) * m + l {
			fmt.Printf("%d", pos)
			return
		}

		if r == 0 && pos != 0 {
			pos = n * m / pos * pos
		}
	}
}


A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k.On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once.Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site.As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress.Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies.Valentine wants to choose such genre x (1 ≤ x ≤ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum.

The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence.

Print a single number — the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number.

NoteIn the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses.In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.

//http://codeforces.com/problemset/problem/250/C
//C. Movie Critics
// elemzes

package main

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

func Readint(r *bufio.Reader) int32 {
	var c byte = 0
	for {
		c, _ = r.ReadByte()
		if c >= '0' && c <= '9' {
			break
		}
	}
	var ret int32 = 0
	for {
		ret = 10*ret + int32(c-'0')
		c, _ = r.ReadByte()
		if c < '0' || c > '9' {
			break
		}
	}
	return ret
}

func main() {
	var (
		n, k, i, all, p, pp, akt, max, loc int32
		dec                                []int32
		in                                 *bufio.Reader
	)

	in = bufio.NewReader(os.Stdin)

	n = Readint(in)
	k = Readint(in)

	dec = make([]int32, k+1, k+1)
	pp, p = -1, 0 // prevprev and prev block
	all = 0       // all stress (change)
	for i = 0; i < n; i++ {
		akt = Readint(in)
		if akt != p {
			all++
			if akt == pp {
				dec[p] += 2
			} else {
				dec[p] += 1
			}
			pp = p
			p = akt
		}
	}
	dec[akt]++

	max, loc = -1, -1
	for i = 1; i <= k; i++ {
		if dec[i] > max {
			max, loc = dec[i], i
		}
	}
	fmt.Println(loc)
}

//http://codeforces.com/problemset/problem/250/C
//C. Movie Critics
// elemzes

package main

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

func main() {
	var (
		n, k, i, all, p, pp, akt, max, loc int32
		dec                                []int32
		in                                 *bufio.Reader
	)

	in = bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n)
	fmt.Fscan(in, &k)
	dec = make([]int32, k+1, k+1)
	pp, p = -1, 0 // prevprev and prev block
	all = 0       // all stress (change)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &akt)
		if akt != p {
			all++
			if akt == pp {
				dec[p] += 2
			} else {
				dec[p] += 1
			}
			pp = p
			p = akt
		}
	}
	dec[akt]++

	max, loc = -1, -1
	for i = 1; i <= k; i++ {
		if dec[i] > max {
			max, loc = dec[i], i
		}
	}
	fmt.Println(loc)
}


After defeating a Blacklist Rival, you get a chance to draw $$$1$$$ reward slip out of $$$x$$$ hidden valid slips. Initially, $$$x=3$$$ and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are $$$c$$$, $$$m$$$, and $$$p$$$, respectively. There is also a volatility factor $$$v$$$. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the $$$x$$$ valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was $$$a$$$. Then,  If the item was a Pink Slip, the quest is over, and you will not play any more races.  Otherwise,   If $$$a\leq v$$$, the probability of the item drawn becomes $$$0$$$ and the item is no longer a valid item for all the further draws, reducing $$$x$$$ by $$$1$$$. Moreover, the reduced probability $$$a$$$ is distributed equally among the other remaining valid items.  If $$$a > v$$$, the probability of the item drawn reduces by $$$v$$$ and the reduced probability is distributed equally among the other valid items.  For example,  If $$$(c,m,p)=(0.2,0.1,0.7)$$$ and $$$v=0.1$$$, after drawing Cash, the new probabilities will be $$$(0.1,0.15,0.75)$$$.  If $$$(c,m,p)=(0.1,0.2,0.7)$$$ and $$$v=0.2$$$, after drawing Cash, the new probabilities will be $$$(Invalid,0.25,0.75)$$$.  If $$$(c,m,p)=(0.2,Invalid,0.8)$$$ and $$$v=0.1$$$, after drawing Cash, the new probabilities will be $$$(0.1,Invalid,0.9)$$$.  If $$$(c,m,p)=(0.1,Invalid,0.9)$$$ and $$$v=0.2$$$, after drawing Cash, the new probabilities will be $$$(Invalid,Invalid,1.0)$$$. You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.

The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 10$$$)  — the number of test cases. The first and the only line of each test case contains four real numbers $$$c$$$, $$$m$$$, $$$p$$$ and $$$v$$$ ($$$0 < c,m,p < 1$$$, $$$c+m+p=1$$$, $$$0.1\leq v\leq 0.9$$$). Additionally, it is guaranteed that each of $$$c$$$, $$$m$$$, $$$p$$$ and $$$v$$$ have at most $$$4$$$ decimal places.

For each test case, output a single line containing a single real number — the expected number of races that you must play in order to draw a Pink Slip. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$$$.

NoteFor the first test case, the possible drawing sequences are:   P with a probability of $$$0.6$$$;  CP with a probability of $$$0.2\cdot 0.7 = 0.14$$$;  CMP with a probability of $$$0.2\cdot 0.3\cdot 0.9 = 0.054$$$;  CMMP with a probability of $$$0.2\cdot 0.3\cdot 0.1\cdot 1 = 0.006$$$;  MP with a probability of $$$0.2\cdot 0.7 = 0.14$$$;  MCP with a probability of $$$0.2\cdot 0.3\cdot 0.9 = 0.054$$$;  MCCP with a probability of $$$0.2\cdot 0.3\cdot 0.1\cdot 1 = 0.006$$$.  So, the expected number of races is equal to $$$1\cdot 0.6 + 2\cdot 0.14 + 3\cdot 0.054 + 4\cdot 0.006 + 2\cdot 0.14 + 3\cdot 0.054 + 4\cdot 0.006 = 1.532$$$.For the second test case, the possible drawing sequences are:   P with a probability of $$$0.4$$$;  CP with a probability of $$$0.4\cdot 0.6 = 0.24$$$;  CMP with a probability of $$$0.4\cdot 0.4\cdot 1 = 0.16$$$;  MP with a probability of $$$0.2\cdot 0.5 = 0.1$$$;  MCP with a probability of $$$0.2\cdot 0.5\cdot 1 = 0.1$$$. So, the expected number of races is equal to $$$1\cdot 0.4 + 2\cdot 0.24 + 3\cdot 0.16 + 2\cdot 0.1 + 3\cdot 0.1 = 1.86$$$.

package main

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

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

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

	for i := 0; i < t; i++ {
		var c, m, p, v float64
		fmt.Fscan(r, &c, &m, &p, &v)

		solve(c, m, p, v)
	}
}

//c + m + p == 1
// 0.1 <= v <= 0.9
func solve(c, m, p, v float64) {

	//(0.2, 0.1, 0.7)  and v= 0.1

	//0.7 + 0.2 * (0.1 , 0.15, 0.75) + 0.1 * (0.25, invalid, 0.75)

	//0.2 * 0.75
	cache := make(map[[3]float64]float64)

	var ans float64 = 0

	state(c, m, p, v , cache, 1, &ans, 1)

	fmt.Printf("%.7f", ans)
	fmt.Println()
}

func state(c, m, p, v float64, cache map[[3]float64]float64, counter int64, expected *float64, cum float64)  {

	*expected += float64(counter) * p * cum

	if c > 1e-9 {
		if c - v > 1e-9 {

			if m > 1e-9 {
				state(c - v, m + v/2, p + v/2, v, cache, counter + 1, expected,  c * cum)
			} else {
				state(c - v, 0, p + v, v, cache, counter + 1, expected, c * cum)
			}

		} else {

			if m > 1e-9 {
				state(0, m + (c)/2, p + (c)/2, v, cache, counter + 1, expected, c * cum)

			} else {
				state(0, 0, p + (c), v, cache, counter + 1, expected, c * cum)
			}
		}
	}

	if m > 0 {

		if m - v > 1e-9 {

			if c > 1e-9 {
				state(c +  v/2, m - v, p + v/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, m - v, p + v, v, cache, counter + 1, expected, m * cum)
			}

		} else {

			if c > 1e-9 {
				state(c + (m)/2, 0, p + (m)/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, 0, p + (m), v, cache, counter + 1, expected, m * cum)
			}
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)
var c, m, p, v float64

func main() {
	defer writer.Flush()
	var t int
	fmt.Fscan(reader, &t)
	for i := 0; i < t; i++ {
	fmt.Fscan(reader, &c, &m, &p, &v)
	fmt.Fprintln(writer,  solve(c, m, p))
	}
}

func solve(c, m, p float64) float64 {

	ans := float64(1)
	var mn float64
	if fabs(c) > .00005 {
		mn = fmin(v, c)
	 	if (fabs(m) > .00005) {
			 ans += c * solve(c -mn, m + mn / 2, p + mn / 2)
		 } else {
			 ans += c * solve(c - mn, m, p + mn)
		 }
	}

	if fabs(m) > .00005 {
		mn = fmin(v, m)
		if fabs(c) > .00005 {
			ans += m * solve(c + mn / 2, m - mn, p + mn / 2)

		} else {
			ans += m * solve(c, m - mn, p + mn)
		}
	}
	return ans
}

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

func fabs(a float64) float64 {
		if a < 0 {
			return -a
		}
		return a
}

func min(nums ...int64) int64 {
	l := len(nums)
	mn := nums[0]
	for i := 0; i < l; i++ {
		if nums[i] < mn {
			mn = nums[i]
		}
	}
	return mn
}

func fmin(nums ...float64) float64 {
	l := len(nums)
	mn := nums[0]
	for i := 0; i < l; i++ {
		if nums[i] < mn {
			mn = nums[i]
		}
	}
	return mn
}

package main

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

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

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

	for i := 0; i < t; i++ {
		var c, m, p, v float64
		fmt.Fscan(r, &c, &m, &p, &v)

		solve(c, m, p, v)
	}
}

//c + m + p == 1
// 0.1 <= v <= 0.9
func solve(c, m, p, v float64) {

	//(0.2, 0.1, 0.7)  and v= 0.1

	//0.7 + 0.2 * (0.1 , 0.15, 0.75) + 0.1 * (0.25, invalid, 0.75)

	//0.2 * 0.75
	cache := make(map[[3]float64]float64)

	var ans float64 = 0

	state(c, m, p, v , cache, 1, &ans, 1)

	fmt.Printf("%.7f", ans)
	fmt.Println()
}

func state(c, m, p, v float64, cache map[[3]float64]float64, counter int64, expected *float64, cum float64)  {

	if cum < 1e-9 {
		cum = 0
	}

	*expected += float64(counter) * p * cum

	if c > 1e-9 {
		if c - v > 1e-9 {

			if m > 1e-9 {
				state(c - v, m + v/2, p + v/2, v, cache, counter + 1, expected,  c * cum)
			} else {
				state(c - v, 0, p + v, v, cache, counter + 1, expected, c * cum)
			}

		} else {

			if m > 1e-9 {
				state(0, m + (c)/2, p + (c)/2, v, cache, counter + 1, expected, c * cum)

			} else {
				state(0, 0, p + (c), v, cache, counter + 1, expected, c * cum)
			}
		}
	}

	if m > 0 {

		if m - v > 1e-9 {

			if c > 1e-9 {
				state(c +  v/2, m - v, p + v/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, m - v, p + v, v, cache, counter + 1, expected, m * cum)
			}

		} else {

			if c > 1e-9 {
				state(c + (m)/2, 0, p + (m)/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, 0, p + (m), v, cache, counter + 1, expected, m * cum)
			}
		}
	}
}

package main

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

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

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

	for i := 0; i < t; i++ {
		var c, m, p, v float64
		fmt.Fscan(r, &c, &m, &p, &v)

		solve(c, m, p, v)
	}
}

//c + m + p == 1
// 0.1 <= v <= 0.9
func solve(c, m, p, v float64) {

	//(0.2, 0.1, 0.7)  and v= 0.1

	//0.7 + 0.2 * (0.1 , 0.15, 0.75) + 0.1 * (0.25, invalid, 0.75)

	//0.2 * 0.75
	cache := make(map[[3]float64]float64)

	var ans float64 = 0

	state(c, m, p, v , cache, 1, &ans, 1)

	fmt.Printf("%.7f", ans)
	fmt.Println()
}

func state(c, m, p, v float64, cache map[[3]float64]float64, counter int64, expected *float64, cum float64)  {

	if cum < 1e-9 {
		cum = 0
	}

	*expected += float64(counter) * p * cum

	if c > 0 {
		if c - v > 1e-9 {

			if m > 0 {
				state(c - v, m + v/2, p + v/2, v, cache, counter + 1, expected,  c * cum)
			} else {
				state(c - v, 0, p + v, v, cache, counter + 1, expected, c * cum)
			}

		} else {

			if m > 0 {
				state(0, m + (c)/2, p + (c)/2, v, cache, counter + 1, expected, c * cum)

			} else {
				state(0, 0, p + (c), v, cache, counter + 1, expected, c * cum)
			}
		}
	}

	if m > 0 {

		if m - v > 1e-9 {

			if c > 0 {
				state(c +  v/2, m - v, p + v/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, m - v, p + v, v, cache, counter + 1, expected, m * cum)
			}

		} else {

			if c > 0 {
				state(c + (m)/2, 0, p + (m)/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, 0, p + (m), v, cache, counter + 1, expected, m * cum)
			}
		}
	}
}

package main

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

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

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

	for i := 0; i < t; i++ {
		var c, m, p, v float64
		fmt.Fscan(r, &c, &m, &p, &v)

		solve(c, m, p, v)
	}
}

//c + m + p == 1
// 0.1 <= v <= 0.9
func solve(c, m, p, v float64) {

	//(0.2, 0.1, 0.7)  and v= 0.1

	//0.7 + 0.2 * (0.1 , 0.15, 0.75) + 0.1 * (0.25, invalid, 0.75)

	//0.2 * 0.75
	cache := make(map[[3]float64]float64)

	var ans float64 = 0

	state(c, m, p, v , cache, 1, &ans, 1)

	fmt.Printf("%.7f", ans)
	fmt.Println()
}

func state(c, m, p, v float64, cache map[[3]float64]float64, counter int, expected *float64, cum float64)  {

	*expected += float64(counter) * p * cum

	if c > 0 {
		if c > v {

			if m > 0 {
				state(c - v, m + v/2, p + v/2, v, cache, counter + 1, expected,  c * cum)
			} else {
				state(c - v, 0, p + v, v, cache, counter + 1, expected, c * cum)
			}

		} else {

			if m > 0 {
				state(0, m + (c)/2, p + (c)/2, v, cache, counter + 1, expected, c * cum)

			} else {
				state(0, 0, p + (c), v, cache, counter + 1, expected, c * cum)
			}
		}
	}

	if m > 0 {

		if m > v {

			if c > 0 {
				state(c +  v/2, m - v, p + v/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, m - v, p + v, v, cache, counter + 1, expected, m * cum)
			}

		} else {

			if c > 0 {
				state(c + (m)/2, 0, p + (m)/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, 0, p + (m), v, cache, counter + 1, expected, m * cum)
			}
		}
	}
}


You are given three sequences: $$$a_1, a_2, \ldots, a_n$$$; $$$b_1, b_2, \ldots, b_n$$$; $$$c_1, c_2, \ldots, c_n$$$.For each $$$i$$$, $$$a_i \neq b_i$$$, $$$a_i \neq c_i$$$, $$$b_i \neq c_i$$$.Find a sequence $$$p_1, p_2, \ldots, p_n$$$, that satisfy the following conditions: $$$p_i \in \{a_i, b_i, c_i\}$$$ $$$p_i \neq p_{(i \mod n) + 1}$$$.In other words, for each element, you need to choose one of the three possible values, such that no two adjacent elements (where we consider elements $$$i,i+1$$$ adjacent for $$$i<n$$$ and also elements $$$1$$$ and $$$n$$$) will have equal value.It can be proved that in the given constraints solution always exists. You don't need to minimize/maximize anything, you need to find any proper sequence.

The first line of input contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$): the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$3 \leq n \leq 100$$$): the number of elements in the given sequences. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$). The third line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \leq b_i \leq 100$$$). The fourth line contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \leq c_i \leq 100$$$). It is guaranteed that $$$a_i \neq b_i$$$, $$$a_i \neq c_i$$$, $$$b_i \neq c_i$$$ for all $$$i$$$.

For each test case, print $$$n$$$ integers: $$$p_1, p_2, \ldots, p_n$$$ ($$$p_i \in \{a_i, b_i, c_i\}$$$, $$$p_i \neq p_{i \mod n + 1}$$$). If there are several solutions, you can print any.

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

func solve() {
	n := nextInt()
	arr := [3][]int{make([]int, n), make([]int, n), make([]int, n)}
	for _, v := range arr {
		for j := range v {
			v[j] = nextInt()
		}
	}
	first := -1
	prev := -1
	for i := range arr[0] {
		for j := range arr {
			if arr[j][i] != prev && (i != n-1 || arr[j][i] != first) {
				printf("%d ", arr[j][i])
				prev = arr[j][i]
				if first == -1 {
					first = arr[j][i]
				}
				break
			}
		}
	}
	printf("\n")
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scan(&t)
	for t > 0 {
		n := 0
		fmt.Scan(&n)
		arr := []int{}
		arr = append(arr, 0)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			arr = append(arr, x)
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != n {
				if arr[i] == arr[i+1] {
					arr[i] = x
				}
			} else {
				if arr[1] == arr[n] {
					arr[n] = x
				}
			}
		}
		for _, i := range arr[1:] {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		t--
	}
}

package main

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

func ReadInt(scanner *bufio.Scanner) int {
	if !scanner.Scan() {
		panic("cant scan")
	}
	str := scanner.Text()
	n, _ := strconv.Atoi(str)
	return n
}

func ReadIntArray(scanner *bufio.Scanner) []int {
	if !scanner.Scan() {
		panic("cant scan")
	}
	str := scanner.Text()
	tokens := strings.Split(str, " ")
	result := make([]int, len(tokens))
	for index, token := range tokens {
		n, _ := strconv.Atoi(token)
		result[index] = n
	}
	return result
}

func PrintIntArray(arr []int, writer *bufio.Writer) {
	strArray := fmt.Sprint(arr)
	_, _ = writer.WriteString(strArray[1:len(strArray)-1])
	_, _ =writer.Write([]byte{'\n'})
	_ = writer.Flush()
}

func Solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := ReadInt(scanner)
	a := ReadIntArray(scanner)
	b := ReadIntArray(scanner)
	c := ReadIntArray(scanner)
	answer := make([]int, n)
	for i := 0; i < n; i++ {
		next := (i + 1) % n
		prev := (i - 1 + n) % n
		if a[i] != answer[next] && a[i] != answer[prev] {
			answer[i] = a[i]
		} else if b[i] != answer[next] && b[i] != answer[prev] {
			answer[i] = b[i]
		} else {
			answer[i] = c[i]
		}
	}
	PrintIntArray(answer, writer)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	t := ReadInt(scanner)
	for i := 0; i < t; i++ {
		Solve(scanner, writer)
	}
}

package main

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

func main() {
	defer writer.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		b := ReadInts(n)
		c := ReadInts(n)
		ans := solve(n, a, b, c)
		for i := 0; i < n; i++ {
			if i > 0 {
				Printf(" ")
			}
			Printf("%d", ans[i])
		}
		Println()
	}
}

func solve(n int, a_, b_, c_ []int) []int {
	var a [3][]int
	a[0] = a_
	a[1] = b_
	a[2] = c_
	ret := make([]int, n)
	ret[0] = a[0][0]
	for i := 1; i < n-1; i++ {
		for j := 0; j < 3; j++ {
			if ret[i-1] != a[j][i] {
				ret[i] = a[j][i]
				break
			}
		}
	}
	for i := 0; i < 3; i++ {
		if ret[n-2] != a[i][n-1] && ret[0] != a[i][n-1] {
			ret[n-1] = a[i][n-1]
			break
		}
	}
	return ret
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

var writer = bufio.NewWriter(os.Stdout)

func Printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func Println(a ...interface{})               { fmt.Fprintln(writer, a...) }

package main

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

func main() {
	defer writer.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		b := ReadInts(n)
		c := ReadInts(n)
		ans := solve(n, a, b, c)
		for i := 0; i < n; i++ {
			if i > 0 {
				Printf(" ")
			}
			Printf("%d", ans[i])
		}
		Println()
	}
}

func solve(n int, a, b, c []int) []int {
	ret := make([]int, n)
	dfs(0, n, a, b, c, ret)
	return ret
}

func dfs(depth int, n int, a, b, c []int, prefix []int) bool {
	if depth == n {
		return prefix[0] != prefix[n-1]
	}
	for i := 0; i < 3; i++ {
		v := a[depth]
		if i == 1 {
			v = b[depth]
		} else if i == 2 {
			v = c[depth]
		}
		if depth > 0 && prefix[depth-1] == v {
			continue
		}
		prefix[depth] = v
		if dfs(depth+1, n, a, b, c, prefix) {
			return true
		}
	}
	return false
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

var writer = bufio.NewWriter(os.Stdout)

func Printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func Println(a ...interface{})               { fmt.Fprintln(writer, a...) }

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		a := readIntArray(n)
		b := readIntArray(n)
		c := readIntArray(n)
		res := make([]int, n)
		res[0] = a[0]
		for j := 1; j < n; j++ {
			prev := res[j-1]
			cur := 0
			if j == n - 1 {
				if prev != a[j] && res[0] != a[j]{
					cur = a[j]
				} else if prev != b[j] && res[0] != b[j]{
					cur = b[j]
				} else if prev != c[j] && res[0] != c[j]{
					cur = c[j]
				}
			} else {
				if prev != a[j] {
					cur = a[j]
				} else if prev != b[j] {
					cur = b[j]
				} else if prev != c[j] {
					cur = c[j]
				}
			}
			res[j] = cur
		}
		for j := 0; j < n; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(res[j])
		}
		fmt.Println()
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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

package main

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

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var nt int
	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 1; kk <= nt; kk++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		var a = make([]int, n)
		var b = make([]int, n)
		var c = make([]int, n)

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

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

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

		for i := 0; i < n; i++ {
			var tmp = make([]int, 0)
			tmp = append(tmp, a[i])
			tmp = append(tmp, b[i])
			tmp = append(tmp, c[i])
			sort.Ints(tmp)
			a[i] = tmp[0]
			b[i] = tmp[1]
			c[i] = tmp[2]
		}

		var first = a[0]
		var current = a[0]
		fmt.Fprintf(writer, "%d ", first)
		for i := 1; i < n; i++ {
			if i < n - 1 {
				if a[i] != current {
					current = a[i]
				} else if b[i] != current {
					current = b[i]
				} else {
					current = c[i]
				}
			} else {
				if a[i] != current && first != a[i] {
					current = a[i]
				} else if b[i] != current && first != b[i] {
					current = b[i]
				} else {
					current = c[i]
				}
			}
			fmt.Fprintf(writer, "%d ", current)
		}
		fmt.Fprintf(writer, "\n")
	}
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

func solve() {
	n := nextInt()
	arr := [3][]int{make([]int, n), make([]int, n), make([]int, n)}
	for _, v := range arr {
		for j := range v {
			v[j] = nextInt()
		}
	}
	prev := -1
	for i := range arr[0] {
		for j := range arr {
			if arr[j][i] != prev {
				printf("%d ", arr[j][i])
				prev = arr[j][i]
				break
			}
		}
	}
	printf("\n")
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scan(&t)
	for t > 0 {
		n := 0
		fmt.Scan(&n)
		arr := []int{}
		arr = append(arr, 0)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			arr = append(arr, x)
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for _, i := range arr[1:] {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		t--
	}
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scan(&t)
	for t > 0 {
		n := 0
		fmt.Scan(&n)
		arr := []int{}
		arr = append(arr, 0)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			arr = append(arr, x)
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for _, x := range arr[1:] {
			fmt.Print(x, ' ')
		}
		fmt.Println()
		t--
	}
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scan(&t)
	for t > 0 {
		n := 0
		fmt.Scan(&n)
		arr := []int{}
		arr = append(arr, 0)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			arr = append(arr, x)
		}
		for i := 1; i <= n; i++ {
			var x int
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != n {
				if arr[i] == arr[i+1] {
					arr[i] = x
				}
			} else {
				if arr[1] == arr[n] {
					arr[n] = x
				}
			}
		}
		for _, i := range arr[1:] {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		t--
	}
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scan(&t)
	for t > 0 {
		n := 0
		fmt.Scan(&n)
		arr := []int{}
		arr = append(arr, 0)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			arr = append(arr, x)
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		fmt.Println(arr[1:])
		t--
	}
}

package main

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

func ReadInt(scanner *bufio.Reader) int {
	str, _ := scanner.ReadString('\n')
	n, _ := strconv.Atoi(str[:len(str)-1])
	return n
}

func ReadIntArray(scanner *bufio.Reader) []int {
	str, _ := scanner.ReadString('\n')
	tokens := strings.Split(str[:len(str)-1], " ")
	result := make([]int, len(tokens))
	for index, token := range tokens {
		n, _ := strconv.Atoi(token)
		result[index] = n
	}
	return result
}

func PrintIntArray(arr []int) {
	strArray := fmt.Sprint(arr)
	fmt.Println(strArray[1:len(strArray)-1])
}

func Solve(scanner *bufio.Reader) {
	n := ReadInt(scanner)
	a := ReadIntArray(scanner)
	b := ReadIntArray(scanner)
	c := ReadIntArray(scanner)
	answer := make([]int, n)
	for i := 0; i < n; i++ {
		next := (i + 1) % n
		prev := (i - 1 + n) % n
		if a[i] != answer[next] && a[i] != answer[prev] {
			answer[i] = a[i]
		} else if b[i] != answer[next] && b[i] != answer[prev] {
			answer[i] = b[i]
		} else {
			answer[i] = c[i]
		}
	}
	PrintIntArray(answer)
}

func main() {
	scanner := bufio.NewReader(os.Stdin)
	t := ReadInt(scanner)
	for i := 0; i < t; i++ {
		Solve(scanner)
	}
}

package main

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

func ReadInt(scanner *bufio.Reader) int {
	str, err := scanner.ReadString('\n')
	if err != nil {
		panic(err)
	}
	n, _ := strconv.Atoi(str[:len(str)-1])
	return n
}

func ReadIntArray(scanner *bufio.Reader) []int {
	str, err := scanner.ReadString('\n')
	if err != nil {
		panic(err)
	}
	tokens := strings.Split(str[:len(str)-1], " ")
	result := make([]int, len(tokens))
	for index, token := range tokens {
		n, _ := strconv.Atoi(token)
		result[index] = n
	}
	return result
}

func PrintIntArray(arr []int) {
	strArray := fmt.Sprint(arr)
	fmt.Println(strArray[1:len(strArray)-1])
}

func Solve(scanner *bufio.Reader) {
	n := ReadInt(scanner)
	a := ReadIntArray(scanner)
	b := ReadIntArray(scanner)
	c := ReadIntArray(scanner)
	answer := make([]int, n)
	for i := 0; i < n; i++ {
		next := (i + 1) % n
		prev := (i - 1 + n) % n
		if a[i] != answer[next] && a[i] != answer[prev] {
			answer[i] = a[i]
		} else if b[i] != answer[next] && b[i] != answer[prev] {
			answer[i] = b[i]
		} else {
			answer[i] = c[i]
		}
	}
	PrintIntArray(answer)
}

func main() {
	scanner := bufio.NewReader(os.Stdin)
	t := ReadInt(scanner)
	for i := 0; i < t; i++ {
		Solve(scanner)
	}
}

package main

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

func ReadInt(scanner *bufio.Reader) int {
	str, err := scanner.ReadString('\n')
	if err != nil {
		panic(err)
	}
	n, _ := strconv.Atoi(str[:len(str)-1])
	return n
}

func ReadIntArray(scanner *bufio.Reader) []int {
	str, err := scanner.ReadString('\n')
	if err != nil {
		panic(err)
	}
	tokens := strings.Split(str[:len(str)-1], " ")
	result := make([]int, len(tokens))
	for index, token := range tokens {
		n, _ := strconv.Atoi(token)
		result[index] = n
	}
	return result
}

func PrintIntArray(arr []int, writer *bufio.Writer) {
	strArray := fmt.Sprint(arr)
	_, _ = writer.WriteString(strArray[1:len(strArray)-1])
	_, _ =writer.Write([]byte{'\n'})
	_ = writer.Flush()
}

func Solve(scanner *bufio.Reader, writer *bufio.Writer) {
	n := ReadInt(scanner)
	a := ReadIntArray(scanner)
	b := ReadIntArray(scanner)
	c := ReadIntArray(scanner)
	answer := make([]int, n)
	for i := 0; i < n; i++ {
		next := (i + 1) % n
		prev := (i - 1 + n) % n
		if a[i] != answer[next] && a[i] != answer[prev] {
			answer[i] = a[i]
		} else if b[i] != answer[next] && b[i] != answer[prev] {
			answer[i] = b[i]
		} else {
			answer[i] = c[i]
		}
	}
	PrintIntArray(answer, writer)
}

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	t := ReadInt(scanner)
	for i := 0; i < t; i++ {
		Solve(scanner, writer)
	}
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		a := readIntArray(n)
		b := readIntArray(n)
		c := readIntArray(n)
		res := make([]int, n)
		res[0] = a[0]
		for j := 1; j < n; j++ {
			prev := res[j-1]
			cur := 0
			if j == n - 1 {
				if prev != a[j] && a[0] != a[j]{
					cur = a[j]
				} else if prev != b[j] && c[0] != c[j]{
					cur = b[j]
				} else if prev != c[j] && c[0] != c[j]{
					cur = c[j]
				}
			} else {
				if prev != a[j] {
					cur = a[j]
				} else if prev != b[j] {
					cur = b[j]
				} else if prev != c[j] {
					cur = c[j]
				}
			}
			res[j] = cur
		}
		for j := 0; j < n; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(res[j])
		}
		fmt.Println()
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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