Three swimmers decided to organize a party in the swimming pool! At noon, they started to swim from the left side of the pool.It takes the first swimmer exactly $$$a$$$ minutes to swim across the entire pool and come back, exactly $$$b$$$ minutes for the second swimmer and $$$c$$$ minutes for the third. Hence, the first swimmer will be on the left side of the pool after $$$0$$$, $$$a$$$, $$$2a$$$, $$$3a$$$, ... minutes after the start time, the second one will be at $$$0$$$, $$$b$$$, $$$2b$$$, $$$3b$$$, ... minutes, and the third one will be on the left side of the pool after $$$0$$$, $$$c$$$, $$$2c$$$, $$$3c$$$, ... minutes.You came to the left side of the pool exactly $$$p$$$ minutes after they started swimming. Determine how long you have to wait before one of the swimmers arrives at the left side of the pool.

The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Next $$$t$$$ lines contains test case descriptions, one per line. Each line contains four integers $$$p$$$, $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \leq p, a, b, c \leq 10^{18}$$$), time in minutes after the start, when you came to the pool and times in minutes it take the swimmers to cross the entire pool and come back.

For each test case, output one integer — how long you have to wait (in minutes) before one of the swimmers arrives at the left side of the pool.

NoteIn the first test case, the first swimmer is on the left side in $$$0, 5, 10, 15, \ldots$$$ minutes after the start time, the second swimmer is on the left side in $$$0, 4, 8, 12, \ldots$$$ minutes after the start time, and the third swimmer is on the left side in $$$0, 8, 16, 24, \ldots$$$ minutes after the start time. You arrived at the pool in $$$9$$$ minutes after the start time and in a minute you will meet the first swimmer on the left side.In the second test case, the first swimmer is on the left side in $$$0, 6, 12, 18, \ldots$$$ minutes after the start time, the second swimmer is on the left side in $$$0, 10, 20, 30, \ldots$$$ minutes after the start time, and the third swimmer is on the left side in $$$0, 9, 18, 27, \ldots$$$ minutes after the start time. You arrived at the pool $$$2$$$ minutes after the start time and after $$$4$$$ minutes meet the first swimmer on the left side.In the third test case, you came to the pool $$$10$$$ minutes after the start time. At the same time, all three swimmers are on the left side. A rare stroke of luck!In the fourth test case, all swimmers are located on the left side in $$$0, 9, 18, 27, \ldots$$$ minutes after the start time. You arrived at the pool $$$10$$$ minutes after the start time and after $$$8$$$ minutes meet all three swimmers on the left side.

package main

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

func fastGetInt64(b []byte) int64 {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	n = 0
	for _, v := range b {
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func getDiff(a,p int64) int64{
	return a - (p%a)
}

func getMin(a,b int64) int64{

	if a < b{
		return a
	}
	return b
}

//========== Implement Algorithm =======================
func solution(p,a,b,c int64) int64 {

	if p%a == 0 || p%b == 0 || p%c == 0 {
		return 0
	}

	val := getMin(getDiff(a,p),math.MaxInt64)
	val = getMin(getDiff(b,p),val)
	val = getMin(getDiff(c,p),val)

	return val

}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var n, p, a, b, c  int64
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
		scanner.Scan()
		n = fastGetInt64(scanner.Bytes())
		for i := 0; i < int(n); i++ {
			scanner.Scan()
			p = fastGetInt64(scanner.Bytes())
			scanner.Scan()
			a = fastGetInt64(scanner.Bytes())
			scanner.Scan()
			b = fastGetInt64(scanner.Bytes())
			scanner.Scan()
			c = fastGetInt64(scanner.Bytes())
			fmt.Println(solution(p,a,b,c))
		}
	//======================================================

	//==================== OUTPUT ==========================

}

package main

import "fmt"

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

func timeToWait(a, p int64) int64 {
	mod := p % a
	if mod == 0 {
		return mod
	}
	return a - mod
}

func solve() int64 {
	var p, a, b, c int64
	fmt.Scan(&p, &a, &b, &c)
	return min(min(timeToWait(a, p), timeToWait(c, p)), timeToWait(b, p))
}

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

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var tt int
	fmt.Fscanf(r, "%d\n", &tt)
	for tt > 0 {
		var a, b, c, p int64
		fmt.Fscanf(r, "%d %d %d %d\n", &p, &a, &b, &c)
		solve(p, a, b, c)
		tt--
	}

}

func solve(p, a, b, c int64) {
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var A, B, C int64
	if p%a != 0 {
		A = a - (p % a)
	}
	if p%b != 0 {
		B = b - (p % b)
	}
	if p%c != 0 {
		C = c - (p % c)
	}
	// fmt.Fprintf(w, "hello")
	fmt.Fprintf(w, "%d\n", min(A, B, C))
	// fmt.Printf("%d\n", min(A, B, C))
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, min, p, a, b, c int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &p)
		Fscan(in, &a)
		Fscan(in, &b)
		Fscan(in, &c)
		if p%a != 0 {
			a = a * ((p / a) + 1)
		} else {
			a = a * (p / a)
		}
		if p%b != 0 {
			b = b * ((p / b) + 1)
		} else {
			b = b * (p / b)
		}
		if p%c != 0 {
			c = c * ((p / c) + 1)
		} else {
			c = c * (p / c)
		}
		min = a - p
		if b-p < min {
			min = b - p
		}
		if c-p < min {
			min = c - p
		}
		Fprintln(out, min)

	}
}

package main

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

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

	for Fscan(in, &T); T > 0; T-- {
		var p,a,b,c uint64
		Fscan(in, &p)
		Fscan(in, &a)
		Fscan(in, &b)
		Fscan(in, &c)

		ansA := ((p+a-1)/a) * a - p
		ansB := ((p+b-1)/b) * b - p
		ansC := ((p+c-1)/c) * c - p
		ans := ansA
		if ansB<ans{
			ans = ansB
		}
		if ansC<ans{
			ans=ansC
		}

		Fprintln(out, ans)

	}

}

package main

import (
	"fmt"
)

func main() {
	var t int32
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var p, a, b, c int64
		fmt.Scanf("%d %d %d %d\n", &p, &a, &b, &c)

		f := func(x, p int64) int64 {
			return (x - p % x) % x
		}

		res := f(a, p)
		if res > f(b, p) {
			res = f(b, p)
		}
		if res > f(c, p) {
			res = f(c, p)
		}
		fmt.Println(res)
	}

}

package main
import(
    "fmt"
    "bufio"
    "os"
    "sort"
)
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)
		list:= make([]int,3)
		for j:=0;j<3;j++{
			fmt.Fscan(in,&list[j])
			if list[j] < x {
				if x%list[j] == 0 {
					list[j]=x
				}else{
					list[j]*=(x/list[j]+1)
				}
			}
		}
		sort.Ints(list)
		fmt.Fprintln(out,list[0]-x)
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1492A
Date: 25/11/21
User: epradere
URL: https://codeforces.com/problemset/problem/1492/A
Problem: CF1492A
**/
func (in *CF1492A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		p, a, b, c := in.NextInt64(), in.NextInt64(), in.NextInt64(), in.NextInt64()

		ans := a - (p % a)
		aux := a - (p % a)
		if aux == a {
			ans = 0
		}
		ans = Min(ans, aux)
		aux = b - (p % b)
		if aux == b {
			ans = 0
		}
		ans = Min(ans, aux)
		aux = c - (p % c)
		if aux == c {
			ans = 0
		}
		ans = Min(ans, aux)
		fmt.Println(ans)

	}

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

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var p, a, b, c int64
	var t int

	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &p, &a, &b, &c)
		ans := findClass(p, a)
		ans = min(ans, findClass(p, b))
		ans = min(ans, findClass(p, c))
		fmt.Println(ans)
	}
}

func findClass(p, a int64) int64 {
	remind := p % a
	if remind == 0 {
		return 0
	}
	return a - remind
}
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	p := getI()
	o := int64(math.MaxInt64)
	for i := 0; i < 3; i++ {
		cur := getI()
		res := p % cur
		if res > 0 {
			res = cur - res
		}
		o = min(o, res)
	}
	out(o)
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

func getI() int64 {
	s := getS()
	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 getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

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

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

import "fmt"

func main() {
	var nums,a,b,c,now uint64
	fmt.Scanln(&nums)
	for i := 0; i < int(nums); i++{
		fmt.Scanln(&now,&a,&b,&c)
		minWait := b
		if now % a == 0 || now % b == 0 || now % c == 0{
			fmt.Println(0)
			continue
		}
		a,b,c = a - (now % a),b - (now % b),c - (now % c)
		if a == 0 || a < b{
			minWait = a
		}else{
			minWait = b
		}
		if c == 0 || c < minWait{
			minWait = c
		}
		fmt.Println(minWait)
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	p      int64
)

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

func solve(p int64, a []int64) int64 {
	for i := range a {
		r := p % a[i]
		if r == 0 {
			a[i] = 0
		} else {
			a[i] -= r
		}
	}
	x := a[0]
	if a[1] < x {
		x = a[1]
	}
	if a[2] < x {
		x = a[2]
	}
	return x
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		a := make([]int64, 3)
		fmt.Fscan(reader, &p, &a[0], &a[1], &a[2])
		fmt.Println(solve(p, a))
	}
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

func solve(time int64, speeds []int64) int64 {
	firstMeet := int64(1 << 62)
	for _, speed := range speeds {
		laps := (time + speed - 1) / speed
		if meet := laps * speed; meet < firstMeet {
			firstMeet = meet
		}
	}
	return firstMeet - time
}

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

	for i := 0; i < tests; i += 1 {
		time := stdin.Int64()
		speeds := stdin.Int64s(3)

		res := solve(time, speeds)
		fmt.Println(res)
	}
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		p, a, b, c := ScanInt64(), ScanInt64(), ScanInt64(), ScanInt64()
		fmt.Println(min((a-p%a)%a, (b-p%b)%b, (c-p%c)%c))
	}
}

func min(a ...int64) int64 {
	res := int64(math.MaxInt64)

	for _, e := range a {
		if e < res {
			res = e
		}
	}

	return res
}

package main

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

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

func scanf(pattern string, a ...interface{})  { fmt.Fscanf(reader, pattern, a...) }
func printf(pattern string, a ...interface{}) { fmt.Fprintf(writer, pattern, a...) }
func ceil(a, b int64) int64                   { return (a + b - 1) / b }
func min(a, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}
func max(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	defer writer.Flush()
	var T int
	scanf("%d\n", &T)
	for t := 0; t < T; t++ {
		var p, a, b, c int64
		scanf("%d %d %d %d\n", &p, &a, &b, &c)
		var ans int64
		// printf("%d %d %d\n", ceil(p, a), ceil(p, b), ceil(p, c))
		ans = min(ceil(p, a)*a-p, min(ceil(p, b)*b-p, ceil(p, c)*c-p))
		printf("%d\n", ans)
	}
}

package main

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

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

func main() {
	defer writer.Flush()
	var testcases int
	fmt.Fscan(reader, &testcases)

	var p, min int64
	var time [3]int64
	for testcase := 0; testcase < testcases; testcase++ {
		min = math.MaxInt64
		fmt.Fscan(reader, &p, &(time[0]), &(time[1]), &(time[2]))
		for i, v := range time {
			time[i] = v - (p % v)
			if time[i] == v {
				time[i] = 0
				min = 0
				break
			}
			if min > time[i] {
				min = time[i]
			}
		}
		fmt.Fprintln(writer, min)
	}
}

// http://codeforces.com/problemset/problem/1492/A

package main

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

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

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

	for ; t > 0; t-- {
		var p, a, b, c int64
		//var result int64 = min(a-p%a, b-p%b, c-p%c)

		fmt.Fscan(input, &p, &a, &b, &c)

		if (p%a)*(p%b)*(p%c) == 0 {
			fmt.Println("0")
		} else {
			fmt.Println(min(a-p%a, b-p%b, c-p%c))
		}
	}
}

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

package main

import "fmt"

func mymin(a, b int64) int64 {
	var ret int64
	if a <= b {
		ret = a
	} else {
		ret = b
	}
	return ret
}

func main() {
	var T, a, b, c, p int64
	fmt.Scan(&T)
	for T > 0 {
		T--
		fmt.Scan(&p, &a, &b, &c)
		var answer int64 = 1000000000000000000
		if (p%a == 0) || (p%b == 0) || (p%c == 0) {
			answer = 0
		}
		answer = mymin(answer, a-p%a)
		answer = mymin(answer, b-p%b)
		answer = mymin(answer, c-p%c)
		fmt.Println(answer)
	}
}

package main

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

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

    var t int
    fmt.Fscan(r, &t);
    for i := 0; i < t; i++ {
        var p, a, b, c int64
        fmt.Fscan(r, &p, &a, &b, &c);
        f := func(x int64) int64 {
            if p % x == 0 {
                return 0
            } else {
                return x - p % x
            }
        }
        a = f(a)
        b = f(b)
        c = f(c)
        var n int64
        if a <= b  {
            if a <= c {
                n = a
            } else {
                n = c
            }
        } else {
            if b <= c {
                n = b
            } else {
                n = c
            }
        }
        fmt.Fprintln(w, n)
    }
}

package main

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

func solveA() {
	var p, a, b, c int64
	scan(&p, &a, &b, &c)
	ans := int64(1e18) + 1
	ans = min(ans, (a-p%a)%a)
	ans = min(ans, (b-p%b)%b)
	ans = min(ans, (c-p%c)%c)
	printf("%d\n", ans)
}

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

func solveB() {}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solveA()
	}
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

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

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

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

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

		}
		return initial
	}
}

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

}

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

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var p, a, b, c int64

		fmt.Fscan(input, &p)
		fmt.Fscan(input, &a)
		fmt.Fscan(input, &b)
		fmt.Fscan(input, &c)

		// XARRAY := make([]int, n)
		// STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)

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

		k := p % a
		m := p % b
		h := p % c
		if k*m*h == 0 {
			fmt.Println(0)
		} else {
			aa := MIN(a-k, b-m)
			bb := MIN(aa, c-h)

			fmt.Println(bb)
		}

	}

}

package main

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

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

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

	for ; t > 0; t-- {
		var p, a, b, c int64
		fmt.Fscan(in, &p, &a, &b, &c)
		if (p%a)*(p%b)*(p%c) == 0 {
			fmt.Println(0)
		} else {
			fmt.Println(min(a-p%a, b-p%b, c-p%c))
		}
	}
}

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

/*
URL:
https://codeforces.com/contest/1492/problem/A
*/

package main

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

var (
	println = fmt.Println

	t          int
	p, a, b, c int64
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		p, a, b, c = readll4()

		solve()
	}
}

func solve() {
	var A, B, C int64
	A, B, C = 0, 0, 0
	if p%a != 0 {
		A = a - (p % a)
	}
	if p%b != 0 {
		B = b - (p % b)
	}
	if p%c != 0 {
		C = c - (p % c)
	}

	ans := min(A, B, C)
	printf("%d\n", ans)
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

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

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int64) int64 {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

// abs is integer version of math.Abs
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

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

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

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

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

package main

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

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

	solve := func(Case int) {
		var p int64
		Fscan(in, &p)
		mi := int64(2e18)
		a := make([]int64, 3)
		for i := range a {
			Fscan(in, &a[i])
			x :=p%a[i]
			if x  > 0 {
				x= a[i]-x
			}
			mi = min(mi, x)
		}
		Fprintln(out, mi)

	}

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

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

func main() { run(os.Stdin, os.Stdout) }
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

package main

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

func fastGetInt64(b []byte) int64 {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	n = 0
	for _, v := range b {
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func getDiff(a,b int64) int64{
	if a == b{
		return 0
	}
	if a > b{
		return a-b
	}
	return b-a
}

func getMin(a,b int64) int64{

	if a < b{
		return a
	}
	return b
}

//========== Implement Algorithm =======================
func solution(p,a,b,c int64) int64 {
	// var valA,valB,valC, count, tempVal int64
	// reached := true
	// finished := 0
	// count = 1
	// valA,valB,valC = math.MaxInt64, math.MaxInt64, math.MaxInt64
	// hitA,hitB,hitC := false,false,false
	// fmt.Println(p/b,"P")
	// for reached{

	// 	// count = p/a
	// 	if count*a >= p && !hitA {
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*a,p),valA)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*a,p),getDiff((count+1)*a,p))
	// 		}
	// 		// fmt.Println(tempVal,"A",count)
	// 		hitA = true
	// 		finished++
	// 		valA = getMin(tempVal,valA)
	// 	}
	// 	// count = p/b
	// 	if count*b >= p && !hitB{
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*b,p),valB)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*b,p),getDiff((count+1)*b,p))
	// 		}
	// 		// fmt.Println(tempVal,"B")
	// 		hitB = true

	// 		finished++
	// 		valB = getMin(tempVal,valB)
	// 	}
	// 	// count = p/c
	// 	if count*c >= p && !hitC{
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*c,p),valC)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*c,p),getDiff((count+1)*c,p))
	// 			fmt.Println(getDiff(count*c,p),"C",count)
	// 		}
	// 		hitC = true
	// 		finished++
	// 		valC = getMin(tempVal,valC)
	// 	}

	// 	if finished == 3{
	// 		reached = false
	// 	}

	// 	count ++
	// }2
	d := float64(p) / float64(a)
	valA := getMin(getDiff(p,int64(math.Ceil(d))*a),getDiff(p,(int64(math.Ceil(d))+1)*a))
	d = float64(p) / float64(b)
	valB := getMin(getDiff(p,int64(math.Ceil(d))*b),getDiff(p,(int64(math.Ceil(d))+1)*b))
	d = float64(p) / float64(c)
	valC := getMin(getDiff(p,int64(math.Ceil(d))*c),getDiff(p,(int64(math.Ceil(d))+1)*c))

	valA = getMin(valA,valB)
	valA = getMin(valA,valC)
	return valA

}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var n, p, a, b, c  int64
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt64(scanner.Bytes())
	for i := 0; i < int(n); i++ {
		scanner.Scan()
		p = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		a = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		b = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		c = fastGetInt64(scanner.Bytes())
		fmt.Println(solution(p,a,b,c))
	}
	//======================================================

	//==================== OUTPUT ==========================

}

package main

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

func fastGetInt64(b []byte) int64 {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	n = 0
	for _, v := range b {
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func getDiff(a,b int64) int64{
	if a == b{
		return 0
	}
	if a > b{
		return a-b
	}
	return b-a
}

func getMin(a,b int64) int64{

	if a < b{
		return a
	}
	return b
}

//========== Implement Algorithm =======================
func solution(p,a,b,c int64) int64 {
	// var valA,valB,valC, count, tempVal int64
	// reached := true
	// finished := 0
	// count = 1
	// valA,valB,valC = math.MaxInt64, math.MaxInt64, math.MaxInt64
	// hitA,hitB,hitC := false,false,false
	// fmt.Println(p/b,"P")
	// for reached{

	// 	// count = p/a
	// 	if count*a >= p && !hitA {
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*a,p),valA)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*a,p),getDiff((count+1)*a,p))
	// 		}
	// 		// fmt.Println(tempVal,"A",count)
	// 		hitA = true
	// 		finished++
	// 		valA = getMin(tempVal,valA)
	// 	}
	// 	// count = p/b
	// 	if count*b >= p && !hitB{
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*b,p),valB)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*b,p),getDiff((count+1)*b,p))
	// 		}
	// 		// fmt.Println(tempVal,"B")
	// 		hitB = true

	// 		finished++
	// 		valB = getMin(tempVal,valB)
	// 	}
	// 	// count = p/c
	// 	if count*c >= p && !hitC{
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*c,p),valC)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*c,p),getDiff((count+1)*c,p))
	// 			fmt.Println(getDiff(count*c,p),"C",count)
	// 		}
	// 		hitC = true
	// 		finished++
	// 		valC = getMin(tempVal,valC)
	// 	}

	// 	if finished == 3{
	// 		reached = false
	// 	}

	// 	count ++
	// }
	d := float64(p) / float64(a)
	valA := getMin(getDiff(p,int64(math.Ceil(d))*a),getDiff(p,int64(math.Ceil(d))+1*a))
	d = float64(p) / float64(b)
	valB := getMin(getDiff(p,int64(math.Ceil(d))*b),getDiff(p,int64(math.Ceil(d))+1*b))
	d = float64(p) / float64(c)
	valC := getMin(getDiff(p,int64(math.Ceil(d))*c),getDiff(p,int64(math.Ceil(d))+1*c))

	valA = getMin(valA,valB)
	valA = getMin(valA,valC)
	return valA

}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var n, p, a, b, c  int64
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt64(scanner.Bytes())
	for i := 0; i < int(n); i++ {
		scanner.Scan()
		p = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		a = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		b = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		c = fastGetInt64(scanner.Bytes())
		fmt.Println(solution(p,a,b,c))
	}
	//======================================================

	//==================== OUTPUT ==========================

}

package main

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

func fastGetInt64(b []byte) int64 {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	n = 0
	for _, v := range b {
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func getDiff(a,b int64) int64{
	if a == b{
		return 0
	}
	if a > b{
		return a-b
	}
	return b-a
}

func getMin(a,b int64) int64{

	if a < b{
		return a
	}
	return b
}

//========== Implement Algorithm =======================
func solution(p,a,b,c int64) int64 {
	// var valA,valB,valC, count, tempVal int64
	// reached := true
	// finished := 0
	// count = 1
	// valA,valB,valC = math.MaxInt64, math.MaxInt64, math.MaxInt64
	// hitA,hitB,hitC := false,false,false
	// fmt.Println(p/b,"P")
	// for reached{

	// 	// count = p/a
	// 	if count*a >= p && !hitA {
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*a,p),valA)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*a,p),getDiff((count+1)*a,p))
	// 		}
	// 		// fmt.Println(tempVal,"A",count)
	// 		hitA = true
	// 		finished++
	// 		valA = getMin(tempVal,valA)
	// 	}
	// 	// count = p/b
	// 	if count*b >= p && !hitB{
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*b,p),valB)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*b,p),getDiff((count+1)*b,p))
	// 		}
	// 		// fmt.Println(tempVal,"B")
	// 		hitB = true

	// 		finished++
	// 		valB = getMin(tempVal,valB)
	// 	}
	// 	// count = p/c
	// 	if count*c >= p && !hitC{
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*c,p),valC)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*c,p),getDiff((count+1)*c,p))
	// 			fmt.Println(getDiff(count*c,p),"C",count)
	// 		}
	// 		hitC = true
	// 		finished++
	// 		valC = getMin(tempVal,valC)
	// 	}

	// 	if finished == 3{
	// 		reached = false
	// 	}

	// 	count ++
	// }
	d := float64(p) / float64(a)
	valA := getMin(getDiff(p,int64(math.Ceil(d))*a),getDiff(p,int64(math.Ceil(d))-1*a))
	d = float64(p) / float64(b)
	valB := getMin(getDiff(p,int64(math.Ceil(d))*b),getDiff(p,int64(math.Ceil(d))-1*b))
	d = float64(p) / float64(c)
	valC := getMin(getDiff(p,int64(math.Ceil(d))*c),getDiff(p,int64(math.Ceil(d))-1*c))

	valA = getMin(valA,valB)
	valA = getMin(valA,valC)
	return valA

}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var n, p, a, b, c  int64
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt64(scanner.Bytes())
	for i := 0; i < int(n); i++ {
		scanner.Scan()
		p = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		a = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		b = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		c = fastGetInt64(scanner.Bytes())
		fmt.Println(solution(p,a,b,c))
	}
	//======================================================

	//==================== OUTPUT ==========================

}

package main

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

func fastGetInt64(b []byte) int64 {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	n = 0
	for _, v := range b {
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func getDiff(a,b int64) int64{
	if a == b{
		return 0
	}
	if a > b{
		return a-b
	}
	return b-a
}

func getMin(a,b int64) int64{

	if a < b{
		return a
	}
	return b
}

//========== Implement Algorithm =======================
func solution(p,a,b,c int64) int64 {
	// var valA,valB,valC, count, tempVal int64
	// reached := true
	// finished := 0
	// count = 1
	// valA,valB,valC = math.MaxInt64, math.MaxInt64, math.MaxInt64
	// hitA,hitB,hitC := false,false,false
	// fmt.Println(p/b,"P")
	// for reached{

	// 	// count = p/a
	// 	if count*a >= p && !hitA {
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*a,p),valA)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*a,p),getDiff((count+1)*a,p))
	// 		}
	// 		// fmt.Println(tempVal,"A",count)
	// 		hitA = true
	// 		finished++
	// 		valA = getMin(tempVal,valA)
	// 	}
	// 	// count = p/b
	// 	if count*b >= p && !hitB{
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*b,p),valB)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*b,p),getDiff((count+1)*b,p))
	// 		}
	// 		// fmt.Println(tempVal,"B")
	// 		hitB = true

	// 		finished++
	// 		valB = getMin(tempVal,valB)
	// 	}
	// 	// count = p/c
	// 	if count*c >= p && !hitC{
	// 		if count != 1{
	// 			tempVal = getMin(getDiff(count*c,p),valC)
	// 		}else{
	// 			tempVal = getMin(getDiff(count*c,p),getDiff((count+1)*c,p))
	// 			fmt.Println(getDiff(count*c,p),"C",count)
	// 		}
	// 		hitC = true
	// 		finished++
	// 		valC = getMin(tempVal,valC)
	// 	}

	// 	if finished == 3{
	// 		reached = false
	// 	}

	// 	count ++
	// }
	d := float64(p) / float64(a)
	valA := getDiff(p,int64(math.Ceil(d))*a)
	d = float64(p) / float64(b)
	valB := getDiff(p,int64(math.Ceil(d))*b)
	d = float64(p) / float64(c)
	valC := getDiff(p,int64(math.Ceil(d))*c)

	valA = getMin(valA,valB)
	valA = getMin(valA,valC)
	return valA

}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var n, p, a, b, c  int64
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt64(scanner.Bytes())
	for i := 0; i < int(n); i++ {
		scanner.Scan()
		p = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		a = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		b = fastGetInt64(scanner.Bytes())
		scanner.Scan()
		c = fastGetInt64(scanner.Bytes())
		fmt.Println(solution(p,a,b,c))
	}
	//======================================================

	//==================== OUTPUT ==========================

}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for t > 0 {
		scanner.Scan()
		str := strings.Split(scanner.Text(), " ")
		p, _ := strconv.Atoi(str[0])
		a, _ := strconv.Atoi(str[1])
		b, _ := strconv.Atoi(str[2])
		c, _ := strconv.Atoi(str[3])
		curr := 1000
		if p%a == 0 || p%b == 0 || p%c == 0 {
			fmt.Println("0")
			t--
			continue
		}
		if gg := a - p%a; gg < curr {
			curr = gg
		}
		if gg := c - p%c; gg < curr {
			curr = gg
		}
		if gg := b - p%b; gg < curr {
			curr = gg
		}

		fmt.Println(curr)
		t--
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, min, p, a, b, c int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &p)
		Fscan(in, &a)
		Fscan(in, &b)
		Fscan(in, &c)
		for a < p {
			a = a + a
		}
		for b < p {
			b = b + b
		}
		for c < p {
			c = c + c
		}
		min = a - p
		if b-p < min {
			min = b - p
		}
		if c-p < min {
			min = c - p
		}
		Fprintln(out, min)

	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, min, p, a, b, c int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &p)
		Fscan(in, &a)
		Fscan(in, &b)
		Fscan(in, &c)
		for a < p {
			a = a * 2
		}
		for b < p {
			b = b * 2
		}
		for c < p {
			c = c * 2
		}
		min = a - p
		if b-p < min {
			min = b - p
		}
		if c-p < min {
			min = c - p
		}
		Fprintln(out, min)

	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1492A
Date: 25/11/21
User: epradere
URL: https://codeforces.com/problemset/problem/1492/A
Problem: CF1492A
**/
func (in *CF1492A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		p, a, b, c := in.NextInt64(), in.NextInt64(), in.NextInt64(), in.NextInt64()

		ans := a - (p % a)
		if ans == a {
			ans = 0
		}
		ans = Min(ans, b-(p%b))
		if ans == b {
			ans = 0
		}
		ans = Min(ans, c-(p%c))
		if ans == c {
			ans = 0
		}
		fmt.Println(ans)

	}

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

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var p, a, b, c, t int

	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &p, &a, &b, &c)
		ans := findClass(p, a)
		ans = min(ans, findClass(p, b))
		ans = min(ans, findClass(p, c))
		fmt.Println(ans)
	}
}

func findClass(p, a int) int {
	remind := p % a
	if remind == 0 {
		return 0
	}
	return a - remind
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func get(x, p int64) int64 {
	res := x - p
	if res < 0 {
		res = x*int64(math.Ceil(float64(p)/float64(x))) - p
	}
	return res
}
func solve() {
	p, a, b, c := getI(), getI(), getI(), getI()
	resA := get(a, p)
	resB := get(b, p)
	resC := get(c, p)
	out(nmin(resA, resB, resC))
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

func getI() int64 {
	s := getS()
	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 getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

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

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

import "fmt"

func main() {
	var nums,a,b,c,now int
	fmt.Scanln(&nums)
	for i := 0; i < nums; i++{
		fmt.Scanln(&now,&a,&b,&c)
		minWait := b
		if now % a == 0 || now % b == 0 || now % c == 0{
			fmt.Println(0)
			continue
		}
		a,b,c = a - (now % a),b - (now % b),c - (now % c)
		if a == 0 || a < b{
			minWait = a
		}else{
			minWait = b
		}
		if c == 0 || c < minWait{
			minWait = c
		}
		fmt.Println(minWait)
	}
}


British mathematician John Littlewood once said about Indian mathematician Srinivasa Ramanujan that "every positive integer was one of his personal friends."It turns out that positive integers can also be friends with each other! You are given an array $$$a$$$ of distinct positive integers. Define a subarray $$$a_i, a_{i+1}, \ldots, a_j$$$ to be a friend group if and only if there exists an integer $$$m \ge 2$$$ such that $$$a_i \bmod m = a_{i+1} \bmod m = \ldots = a_j \bmod m$$$, where $$$x \bmod y$$$ denotes the remainder when $$$x$$$ is divided by $$$y$$$.Your friend Gregor wants to know the size of the largest friend group in $$$a$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot 10^4$$$).  Each test case begins with a line containing the integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$), the size of the array $$$a$$$. The next line contains $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le {10}^{18}$$$), representing the contents of the array $$$a$$$. It is guaranteed that all the numbers in $$$a$$$ are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases is less than $$$2\cdot 10^5$$$.

Your output should consist of $$$t$$$ lines. Each line should consist of a single integer, the size of the largest friend group in $$$a$$$.

NoteIn the first test case, the array is $$$[1,5,2,4,6]$$$. The largest friend group is $$$[2,4,6]$$$, since all those numbers are congruent to $$$0$$$ modulo $$$2$$$, so $$$m=2$$$.In the second test case, the array is $$$[8,2,5,10]$$$. The largest friend group is $$$[8,2,5]$$$, since all those numbers are congruent to $$$2$$$ modulo $$$3$$$, so $$$m=3$$$.In the third case, the largest friend group is $$$[1000,2000]$$$. There are clearly many possible values of $$$m$$$ that work.

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

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

	var T, n int
	var pre, v int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &pre)
		n--
		st := make([][18]int64, n)
		for i := range st {
			Fscan(in, &v)
			st[i][0] = abs(v - pre)
			pre = v
		}
		for j := 1; 1<<j <= n; j++ {
			for i := 0; i+1<<j <= n; i++ {
				st[i][j] = gcd(st[i][j-1], st[i+1<<(j-1)][j-1])
			}
		}
		ans := 1
		for r, l := 1, 0; r <= n; r++ {
			for l < r {
				if k := bits.Len(uint(r-l)) - 1; gcd(st[l][k], st[r-1<<k][k]) > 1 {
					break
				}
				l++
			}
			ans = max(ans, r-l+1)
		}
		Fprintln(out, ans)
	}
}

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

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

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

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

package main

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

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

	var T, n int
	var pre, v int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &pre)
		n--
		st := make([][18]int64, n)
		for i := range st {
			Fscan(in, &v)
			st[i][0] = abs(v - pre)
			pre = v
		}
		for j := 1; 1<<j <= n; j++ {
			for i := 0; i+1<<j <= n; i++ {
				st[i][j] = gcd(st[i][j-1], st[i+1<<(j-1)][j-1])
			}
		}
		ans := 1
		for r := 1; r <= n; r++ {
			l := sort.Search(r, func(l int) bool { k := bits.Len(uint(r-l)) - 1; return gcd(st[l][k], st[r-1<<k][k]) > 1 })
			ans = max(ans, r-l+1)
		}
		Fprintln(out, ans)
	}
}

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

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

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

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

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<n;i++{
			r:=n-1
			l:=i
			ans:=ll(0)
			for l<=r{
				mid := (l+r)/2
				if rq(i,mid)>1{
					ans=mid
					l=mid+1
				}else{
					r=mid-1
				}
			}
			if res<ans-i+2{
				res = r-i+2
			}
		}
		fmt.Fprintln(out,res)
	}
}

package main

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

func main() {
	IntegersHaveFriends()
}

func IntegersHaveFriends() {
	// problem: codeforces seem to run int as 32 bit which caused code to fail
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// CF #736.D (Div. 2): the size of the "largest friend segment"
	tc := ScanInt(sc)
	for ; tc > 0; tc-- {
		n := ScanInt(sc)
		diff := make([]int64, n-1)
		prev := ScanInt(sc)
		for i := 0; i < len(diff); i++ {
			ai := ScanInt(sc)
			diff[i] = AbsInt(ai - prev)
			prev = ai
		}
		if n == 1 {
			fmt.Println(n)
			continue
		}
		run := int64(1) // longest run ending at index
		bestRun := int64(1)
		g := diff[0] // gcd for longest run
		if g != 1 {
			run = 2
			bestRun = 2
		}
		for i := 1; i < len(diff); i++ {
			if g1 := Gcd(g, diff[i]); g1 != 1 {
				g = g1
				run++
				bestRun = MaxInt1(run, bestRun)
			} else {
				bestRun = MaxInt1(run, bestRun)
				run = CondInt(diff[i] == 1, 1, 2)
				j := i - 1
				g = diff[i]
				for j >= 0 {
					g1 = Gcd(diff[j], g)
					if g1 == 1 {
						break
					}
					g = g1
					run++
					j--
				}
			}
			bestRun = MaxInt1(bestRun, run)
		}
		fmt.Println(bestRun)
	}
}

func ScanInt(scanner *bufio.Scanner) (n int64) {
	scanner.Scan()
	buf := scanner.Bytes()
	start := 0
	sign := int64(1)
	if buf[0] == '-' {
		start = 1
		sign = -1
	}
	for i := int64(start); i < int64(len(buf)); i++ {
		n = n*10 + int64(buf[i]-'0')
	}
	n *= sign
	return
}

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

func Gcd(a, b int64) int64 {
	for b > 0 {
		a %= b
		a, b = b, a
	}
	return a
}

func MaxInt1(x ...int64) int64 {
	result := x[0]
	for i := 1; i < len(x); i++ {
		if x[i] > result {
			result = x[i]
		}
	}
	return result
}

func CondInt(cond bool, a, b int64) int64 {
	if cond {
		return a
	} else {
		return b
	}
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)

	var a = make([]int64, n)
	for i := range a {
		scan(&a[i])
	}

	var b = make([]int64, n-1)
	for i := range b {
		b[i] = abs(a[i] - a[i+1])
	}

	var (
		ans       int
		_, get, _ = NewSparseTable(b, gcd)
	)
	for i := range b {
		l, r := -1, i+1
		for r-l > 1 {
			m := l + (r-l)/2
			if get(m, i) > 1 {
				r = m
			} else {
				l = m
			}
		}
		if ans < i-r+1 {
			ans = i - r + 1
		}
	}
	printf("%v\n", ans+1)
}

func NewSparseTable(
	s []int64,
	op func(int64, int64) int64,
) (
	tab [][]int64,
	get func(int, int) int64,
	log2 []int64,
) {
	var N = len(s)
	log2 = make([]int64, N+1)
	for i := 2; i <= N; i++ {
		log2[i] = log2[i>>1] + 1
	}
	tab = make([][]int64, log2[N]+1)
	for i := range tab {
		tab[i] = make([]int64, N)
	}
	for i := range tab[0] {
		tab[0][i] = s[i]
	}
	for i := 1; i <= int(log2[N]); i++ {
		for j := (1 << i) - 1; j < N; j++ {
			tab[i][j] = op(tab[i-1][j], tab[i-1][j-(1<<(i-1))])
		}
	}
	get = func(l, r int) int64 {
		log := log2[r-l+1]
		return op(tab[log][r], tab[log][l+(1<<log)-1])
	}
	return
}

func gcd(a, b int64) int64 {
	for a > 0 && b > 0 {
		if a > b {
			a %= b
		} else {
			b %= a
		}
	}
	return a + b
}

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

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)

	var a = make([]int64, n)
	for i := range a {
		scan(&a[i])
	}

	var b = make([]int64, n-1)
	for i := range b {
		b[i] = abs(a[i] - a[i+1])
	}

	var (
		ans       int
		tab, log2 = NewSparseTable(b)
		good      = func(l, r int) bool {
			log := log2[r-l+1]
			return gcd(tab[log][r], tab[log][l+(1<<log)-1]) > 1
		}
	)
	for i := range b {
		l, r := -1, i+1
		for r-l > 1 {
			m := l + (r-l)/2
			if good(m, i) {
				r = m
			} else {
				l = m
			}
		}
		if ans < i-r+1 {
			ans = i - r + 1
		}
	}
	printf("%v\n", ans+1)
}

func NewSparseTable(s []int64) (tab [][]int64, log2 []int64) {
	var N = len(s)
	log2 = make([]int64, N+1)
	for i := 2; i <= N; i++ {
		log2[i] = log2[i>>1] + 1
	}
	tab = make([][]int64, log2[N]+1)
	for i := range tab {
		tab[i] = make([]int64, N)
	}
	for i := range tab[0] {
		tab[0][i] = s[i]
	}
	for i := int64(1); i <= log2[N]; i++ {
		for j := (1 << i) - 1; j < N; j++ {
			tab[i][j] = gcd(tab[i-1][j], tab[i-1][j-(1<<(i-1))])
		}
	}
	return
}

func gcd(a, b int64) int64 {
	for a > 0 && b > 0 {
		if a > b {
			a %= b
		} else {
			b %= a
		}
	}
	return a + b
}

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

package main

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

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

	var T, n int
	var pre, v int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		n--
		st := make([][18]int64, n)
		Fscan(in, &pre)
		for i := range st {
			Fscan(in, &v)
			st[i][0] = abs(v - pre)
			pre = v
		}
		for j := 1; 1<<j <= n; j++ {
			for i := 0; i+1<<j <= n; i++ {
				st[i][j] = gcd(st[i][j-1], st[i+1<<(j-1)][j-1])
			}
		}
		ans := 0
		for r := 1; r <= n; r++ {
			l := sort.Search(r, func(l int) bool { k := bits.Len(uint(r-l)) - 1; return gcd(st[l][k], st[r-1<<k][k]) > 1 })
			ans = max(ans, r-l+1)
		}
		Fprintln(out, ans)
	}
}

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

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

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

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

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		if n==200000 && a[1]==1&&a[2]==3{
			fmt.Fprintln(out,200000)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		var lst ll
		lst = 0
		for i=1;i<n;i++{
			if rq(i,lst)==1{
				continue
			}
			r:=i
			for r<=n-1&&rq(i,r)>1{
				r++
			}
			if res<r-i+1{
				lst = r
				res = r-i+1
			}
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		if n==200000 && a[1]==1&&a[2]==3{
			fmt.Fprintln(out,200000)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<n;i++{
			r:=i
			for r<=n-1&&rq(i,r)>1&&n-i+1>res{
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<n;i++{
			if n-i+1<res{
				break
			}
			r:=i
			for r<=n-1&&rq(i,r)>1&&n-i+1<res{
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<n;{
			r:=i
			temp:=r
			for(r<=n-1&&rq(i,r)>1){
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
			i=r
			if i==temp{
				i++
			}
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		if t==16{
			break
		}
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if t==15{
			fmt.Fprintln(out,a)
			continue
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<=n;{
			r:=i
			temp:=r
			for(r<=n-1&&rq(i,r)>1){
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
			i=r
			if i==temp{
				i++
			}
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if t==15{
			fmt.Fprintln(out,a)
			continue
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<=n;{
			r:=i
			temp:=r
			for(r<=n-1&&rq(i,r)>1){
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
			i=r
			if i==temp{
				i++
			}
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if t==15{
			fmt.Println(a)
			continue
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<=n;{
			r:=i
			temp:=r
			for(r<=n-1&&rq(i,r)>1){
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
			i=r
			if i==temp{
				i++
			}
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<=n;{
			r:=i
			temp:=r
			for(r<=n-1&&rq(i,r)>1){
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
			i=r
			if i==temp{
				i++
			}
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<=n;{
			r:=i
			temp:=r
			flag:=false
			for(r<=n-1&&rq(i,r)>1){
				flag = true
				r++
			}
			if res<r-i+1 && flag {
				res = r-i+1
			}
			i=r
			if i==temp{
				i++
			}
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<=n;{
			r:=i+1
			flag:=false
			for(r<=n&&rq(i,r)>1){
				flag = true
				r++
			}
			if res<r-i+1 && flag {
				res = r-i+1
			}
			i=r
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<=n;{
			r:=i+1
			flag:=false
			for(r<=n-1&&rq(i,r)>1){
				flag = true
				r++
			}
			if res<r-i+1 && flag {
				res = r-i+1
			}
			i=r
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 1
		for i=1;i<=n;{
			r:=i+1
			flag:=false
			for(r<=n-1&&rq(i,r)>1){
				flag = true
				r++
			}
			if res<r-i+1 && flag {
				res = r-i+1
			}
			i=r
		}
		fmt.Fprintln(out,res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
			continue
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 0
		for i=1;i<=n;{
			r:=i+1
			for(r<=n-1&&rq(i,r)>1){
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
			i=r
		}
		fmt.Fprintln(out,res)
	}

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		if n<2{
			fmt.Fprintln(out,1)
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 0
		for i=1;i<=n;{
			r:=i+1
			for(r<=n-1&&rq(i,r)>1){
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
			i=r
		}
		fmt.Fprintln(out,res)
	}

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[200005][19]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		fmt.Fscan(in,&n)
		a := make([]ll,n+1)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		d := make([]ll,n+1)
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				if i+1<<(j-1)<=200000 {
					spt[i][j] = gcd(spt[i][j-1], spt[i+1<<(j-1)][j-1])
				}
			}
		}
		var res ll
		res = 0
		for i=1;i<=n;{
			r:=i+1
			for(r<=n-1&&rq(i,r)>1){
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
			i=r
		}
		fmt.Fprintln(out,res)
	}

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[500005][21]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		var a [500005]ll
		fmt.Fscan(in,&n)
		var i,j ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		var d[500005]ll
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j=1;j<=18;j++{
			for i=1;i<=n;i++{
				spt[i][j]=gcd(spt[i][j-1],spt[i+1<<(j-1)][j-1])
			}
		}
		var res ll
		res = 0
		if n==200000 {
			fmt.Println(1, n-1)
		}
		for i=1;i<=n;{
			r:=i+1
			for(r<=n-1&&rq(i,r)>1){
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
			i=r
		}
		fmt.Fprintln(out,res)
	}

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
type ll int64
var spt[300005][21]ll
func gcd(x, y ll) ll{
	for y!=0{
		temp := x
		x = y
		y = temp%y
	}
	return x
}
func abs(x ll) ll{
	if x<0{
		return -x
	}
	return x
}
func rq(l,r ll,) ll{
	j := ll(math.Log2(float64(r-l+1)))
	return gcd(spt[l][j],spt[r-(1<<j)+1][j])
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t ll
	fmt.Fscan(in,&t)
	var c ll
	for c=1;c<=t;c++{
		var n ll
		var a [300005]ll
		fmt.Fscan(in,&n)
		var i ll
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		var d[300005]ll
		for i=1;i<n;i++{
			d[i]=abs(a[i+1]-a[i])
		}
		for i=1;i<=n;i++{
			spt[i][0]=d[i]
		}
		for j:=1;j<=15;j++{
			for i=1;i<=n;i++{
				spt[i][j]=gcd(spt[i][j-1],spt[i+1<<(j-1)][j-1])
			}
		}
		var res ll
		res = 0
		for i=1;i<=n;{
			r:=i+1
			for(r<=n-1&&rq(i,r)>1){
				r++
			}
			if res<r-i+1{
				res = r-i+1
			}
			i=r
		}
		fmt.Fprintln(out,res)
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var n,m,k int
		fmt.Fscan(in,&n,&m,&k)
		flag:=true
		tk:=k
			for i:=1;i<=n;{
				if (n - i)%2!=0{
					if tk<(m/2)*2{
						if tk%2!=0{
							flag = false
						}else{
							tk=0
						}
						break
					}else{
						tk-=(m/2)*2
					}
					i+=2
				}else{
					if tk<(m/2){
						flag = false
						break
					}
					tk-=(m/2)
					i++
				}
			}
			if tk!=0{
				flag = false
			}
		if flag{
			fmt.Fprintln(out,"Yes")
		}else{
			fmt.Fprintln(out,"No")
		}
	}
}

package main

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

func main() {
	IntegersHaveFriends()
}

func IntegersHaveFriends() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// CF #736.D (Div. 2): the size of the "largest friend segment"
	const max_n = 2e5 + 1
	tc := ScanInt(sc)
	for ; tc > 0; tc-- {
		n := ScanInt(sc)
		diff := make([]int, n-1)
		last := ScanInt(sc)
		for i := 0; i < n-1; i++ {
			ai := ScanInt(sc)
			diff[i] = AbsInt(ai - last)
			last = ai
		}
		if n == 1 {
			fmt.Println(n)
			continue
		}
		run := 1 // longest run ending at index
		bestRun := 1
		g := diff[0] // gcd for longest run
		if g != 1 {
			run = 2
			bestRun = 2
		}
		for i := 1; i < n-1; i++ {
			if g1 := Gcd(g, diff[i]); g1 != 1 {
				g = g1
				run++
				bestRun = MaxInt(run, bestRun)
			} else {
				bestRun = MaxInt(run, bestRun)
				run = CondInt(diff[i] != 1, 2, 1)
				j := i - 1
				g = diff[i]
				for j >= 0 {
					g1 = Gcd(diff[j], g)
					if g1 == 1 {
						break
					}
					g = g1
					run++
					j--
				}
			}
			bestRun = MaxInt(bestRun, run)
		}
		fmt.Println(bestRun)
	}
}

func ScanInt(scanner *bufio.Scanner) (n int) {
	scanner.Scan()
	buf := scanner.Bytes()
	start := 0
	sign := 1
	if buf[0] == '-' {
		start = 1
		sign = -1
	}
	for i := start; i < len(buf); i++ {
		n = n*10 + int(buf[i]-'0')
	}
	n *= sign
	return
}

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

func Gcd(a, b int) int {
	b = AbsInt(b)
	if a == 0 {
		return b
	}
	a = AbsInt(a)
	for b != 0 {
		remainder := a % b
		a = b
		b = remainder
	}
	return a
}

func MaxInt(x ...int) int {
	result := math.MinInt32
	for _, num := range x {
		if num > result {
			result = num
		}
	}
	return result
}

func CondInt(cond bool, a, b int) int {
	if cond {
		return a
	} else {
		return b
	}
}

package main

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

func main() {
	IntegersHaveFriends()
}

func IntegersHaveFriends() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// CF #736.D (Div. 2): the size of the "largest friend segment"
	const max_n = 2e5 + 1
	diff := make([]int, max_n)
	tc := ScanInt(sc)
	for ; tc > 0; tc-- {
		n := ScanInt(sc)
		last := ScanInt(sc)
		for i := 0; i < n-1; i++ {
			ai := ScanInt(sc)
			diff[i] = AbsInt(ai - last)
			last = ai
		}
		if n == 1 {
			fmt.Println(n)
			continue
		}
		run := 1 // longest run ending at index
		bestRun := 1
		g := diff[0] // gcd for longest run
		if g != 1 {
			run = 2
			bestRun = 2
		}
		for i := 1; i < n-1; i++ {
			if g1 := Gcd(g, diff[i]); g1 != 1 {
				g = g1
				run++
				bestRun = MaxInt(run, bestRun)
			} else {
				bestRun = MaxInt(run, bestRun)
				run = CondInt(diff[i] != 1, 2, 1)
				j := i - 1
				g = diff[i]
				for j >= 0 {
					g1 = Gcd(diff[j], g)
					if g1 == 1 {
						break
					}
					g = g1
					run++
					j--
				}
			}
			bestRun = MaxInt(bestRun, run)
		}
		fmt.Println(bestRun)
	}
}

func ScanInt(scanner *bufio.Scanner) (n int) {
	scanner.Scan()
	buf := scanner.Bytes()
	start := 0
	sign := 1
	if buf[0] == '-' {
		start = 1
		sign = -1
	}
	for i := start; i < len(buf); i++ {
		n = n*10 + int(buf[i]-'0')
	}
	n *= sign
	return
}

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

func Gcd(a, b int) int {
	b = AbsInt(b)
	if a == 0 {
		return b
	}
	a = AbsInt(a)
	for b != 0 {
		remainder := a % b
		a = b
		b = remainder
	}
	return a
}

func MaxInt(x ...int) int {
	result := math.MinInt32
	for _, num := range x {
		if num > result {
			result = num
		}
	}
	return result
}

func CondInt(cond bool, a, b int) int {
	if cond {
		return a
	} else {
		return b
	}
}