Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
from heapq import heappush, heappop

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.depth = pow(2, n.bit_length())

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1)

    # Return the minimum i that satisfies a_0 + a_1 + ... + a_i >= x
    def lower_bound(self, x):
        if x <= 0:
            return 0
        i = 0
        s = 0
        k = 1 << (self.depth - 1)
        while k:
            if i + k <= self.n and s + self.data[i + k] < x:
                i += k
                s += self.data[i]
            k >>= 1
        return i


def main():
    N, *P = map(int, read().split())

    index = [0] * (N + 1)
    for i, p in enumerate(P):
        index[p] = i

    bit = BIT(N)

    ans = 0
    for n in range(N, 0, -1):
        i = index[n]
        bit.add(i)
        x = bit.get_sum(i)

        left1 = left2 = -1
        right1 = right2 = N
        if x - 2 > 0:
            left2 = bit.lower_bound(x - 2)
        if x - 1 > 0:
            left1 = bit.lower_bound(x - 1)
        if x + 1 <= N - n + 1:
            right1 = bit.lower_bound(x + 1)
        if x + 2 <= N - n + 1:
            right2 = bit.lower_bound(x + 2)

        ans += ((left1 - left2) * (right1 - i) + (right2 - right1) * (i - left1)) * n


    print(ans)
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from heapq import heappush, heappop

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *P = map(int, read().split())

    idx = [0] * (N + 1)
    for i, p in enumerate(P):
        idx[p] = i

    left = list(range(-1, N)) + [-1]
    right = list(range(1, N + 1)) + [N, N]

    ans = 0
    for n in range(1, N + 1):
        i = idx[n]
        l1 = left[i]
        l2 = left[l1]
        r1 = right[i]
        r2 = right[r1]

        ans += n * ((l1 - l2) * (r1 - i) + (r2 - r1) * (i - l1))

        left[r1] = l1
        right[l1] = r1

    print(ans)
    return


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**5-10**4*2)
S = list(input())
n = len(S)
def Remove(binList,lenList):
    for i in range(0,lenList-1):
        if (binList[i] == "0" and binList[i+1] == "1") or (binList[i] == "1" and binList[i+1] == "0"):
            del binList[i:i+2]
            return Remove(binList,lenList - 2)
    return binList
if n > 10**5:
    sys.exit()
S = Remove(S,n)
print(n-len(S))

### FIXED CODE ###

S = list(input())
obj = min(S.count("0"),S.count("1"))
print(obj*2)
### BUGGY CODE ###

X = list(map(int, input().split()))
N = X[0]
K = X[1]
if K == 1:
  print(0)
else:
  if K == 2:
    if N % 2 == 0:
      print(0)
    else:
      print(1)
  else: 
    while True:
      A = abs(N - K)
      if N > A:
        N = A
      else:
        break
    print(N)

### FIXED CODE ###

X = list(map(int, input().split()))
N = X[0]
K = X[1]
t = N % K
s = K - t
if t <= s:
  print(t)
else:
  print(s)
### BUGGY CODE ###

from collections import deque
n, k = map(int, input().split())
p = list(map(int,input().split()))

kitai = [0]*1000
tmp = 0
for i in range(1000):
  tmp += i+1
  kitai[i] = tmp/(i+1)
#print(kitai)
  

window = deque([kitai[p[i]-1] for i in range(k)])
ans = sum(window)
for i in range(n-k+1):
  #print(window)
  window.popleft()
  window.append(kitai[p[i+k-1]-1])
  ans = max(sum(window),  ans)
print(ans)
         

### FIXED CODE ###

from collections import deque
n, k = map(int, input().split())
p = list(map(int,input().split()))

kitai = [0]*1000
tmp = 0
for i in range(1000):
  tmp += i+1
  kitai[i] = tmp/(i+1)
#print(kitai)

total_kitai = [0]*(n+1)
tmp = 0
for i in range(n):
  tmp += kitai[p[i]-1]
  total_kitai[i+1] = tmp
#print(total_kitai)

ans = 0
for i in range(n-k+1):
  ans = max(total_kitai[i+k]-total_kitai[i],  ans)
print(ans)
### BUGGY CODE ###

import sys
from bisect import *

input=sys.stdin.readline

def main():
    n = int(input()[:-1])
    aa = list(map(int, input().split()))
    ans = 0
    pos = [0] * n
    for i, a in enumerate(aa):
        pos[a - 1] = i
    # print(pos)
    fin = [-1, -1, n, n]
    for a in range(n - 1, -1, -1):
        i = pos[a]
        insort(fin,i)
        j = bisect_left(fin, i)
        ans += (a + 1) * ((fin[j - 1] - fin[j - 2]) * (fin[j + 1] - fin[j])
                          + (fin[j] - fin[j - 1]) * (fin[j + 2] - fin[j + 1]))
        # print(a, ans, fin)
    print(ans)

main()


### FIXED CODE ###

# 参考 https://atcoder.jp/contests/abc140/submissions/7411285
import sys
input = sys.stdin.readline

def main():
    n = int(input()[:-1])
    aa = list(map(int, input().split()))
    ans = 0
    pos = [0] * (n + 1)
    for i, a in enumerate(aa):
        pos[a] = i + 2
    Lnext = [1, 1] + list(range(1, n + 1)) + [n, n]
    Rnext = [3, 3] + list(range(3, n + 3)) + [n + 2, n + 2]
    for a in range(1,n + 1):
        i = pos[a]
        l0 = Lnext[i]
        l1 = Lnext[l0]
        r0 = Rnext[i]
        r1 = Rnext[r0]
        ans += a * ((l0 - l1) * (r0 - i) + (i - l0) * (r1 - r0))
        Lnext[r0] = l0
        Rnext[l0] = r0
    print(ans)

main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import collections

N = int(input())
Xd = [input() for _ in range(N)]
X = [list(c) for c in Xd] 
tmp = [[0]] * N
cnt = 0

for i in range(N):
	tmp[i] = collections.Counter(X[i]).most_common()
	tmp[i].sort()

for i in range(N):
	j = 1
	for j in range(i + j, N):
		if tmp[i] == tmp[j]:
			cnt += 1

print(cnt)

### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
dic = {}
cnt = 0

for i in range(N):
	s = str(sorted(input()))
	if (s in dic):
		cnt += dic[s]
		dic[s] += 1
	else:
		dic[s] = 1

print(cnt)
### BUGGY CODE ###

import numpy as np
H,N = map(int, input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    
dp = [np.inf for i in range(10**7+1)]
dp[0] = 0
for i in range(H+1):
    for j in range(N):
        dp[i+A[j]] = min(dp[i+A[j]],dp[i]+B[j])
        
print(min(dp[H:]))

### FIXED CODE ###

import numpy as np
 
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = np.array(ab)
 
a = ab[:, 0]
b = ab[:, 1]
 
dp = np.zeros(100001, dtype=np.int)
for i in range(1, h+1):
    dp[i] = (dp[i-a]+b).min()

print(dp[h])
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
A = deque([int(input()) for _ in range(N)])

for i in range(N):
    tmp = A.popleft()
    print(max(A))
    A.append(tmp)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
for x in A:
    if x == B[-1]:
        print(B[-2])
    else:
        print(B[-1])
### BUGGY CODE ###

import numpy as np
h,w,a,b=map(int,input().split())
arr=np.array([[0]*w]*h)
while 1<3:
  flg=0
  for i in range(h):
    for j in range(w):
      sum1=np.sum(arr, axis=1)[i]
      sum2=np.sum(arr, axis=0)[j]
      if sum1 not in [a,w-a] and sum2 not in [b,h-b]:
        arr[i,j]=1
        flg=1
  for i in range(h):
    for j in range(w):
      sum1=np.sum(arr, axis=1)[i]
      sum2=np.sum(arr, axis=0)[j]
      if sum1 not in [a,w-a] or sum2 not in [b,h-b]:
        arr[i,j]=1
        flg=1
  if flg==0:
    break

for i in range(h):
  s=''
  for j in range(w):
    s+=str(arr[i,j])
  print(s)

### FIXED CODE ###

h,w,a,b=map(int,input().split())
for i in range(b):
  s=''
  for j in range(a):
    s+='1'
  for j in range(w-a):
    s+='0'
  print(s)
for i in range(h-b):
  s=''
  for j in range(a):
    s+='0'
  for j in range(w-a):
    s+='1'
  print(s)
### BUGGY CODE ###

import queue
def main():
    n,m,k=map(int,input().split())
    root={}
    ng={}
    for i in range(n):
        root[i]=[]
        ng[i]=[i]
    for i in range(m):
        a,b=map(int,input().split())
        root[a-1].append(b-1)
        root[b-1].append(a-1)
    for i in range(k):
        a,b=map(int,input().split())
        ng[a-1].append(b-1)
        ng[b-1].append(a-1)
    
    Vstd=[]
    checkVst=[0]*n
    num=[0]*n
    ToVst=queue.Queue()
    for i in range(n):
        Vstd=[]
        if checkVst[i]==1:
            continue
        now=i
        Vstd.append(now)
        checkVst[now]=1
        for kouho in root[now]:
            if checkVst[kouho]!=1:
                ToVst.put(kouho)
                checkVst[kouho]=1
        while ToVst.empty()==False:
            now=ToVst.get()
            Vstd.append(now)
            checkVst[now]=1
            for kouho in root[now]:
                if checkVst[kouho]==1:
                    continue
                ToVst.put(kouho)
                checkVst[kouho]=1
       #         print("a")

      #  print(Vstd)
        for x in Vstd:
            num[x]=len(Vstd)
            for y in Vstd:
                if y in ng[x] or y in root[x]:
                    num[x]-=1
    print(" ".join(map(str,num)))
    




        
        




        


if __name__=="__main__":
    main()
    
        

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n,m,k=map(int,input().split())
uf=UnionFind(n)
block={}
for i in range(n):
    block[i]=[i]
for i in range(m):
    a,b=map(int,input().split())
    uf.union(a-1,b-1)
    block[a-1].append(b-1)
    block[b-1].append(a-1)
    
for i in range(k):
    a,b=map(int,input().split())
    block[a-1].append(b-1)
    block[b-1].append(a-1)
ans=[]
#print(block)
for i in range(n):
    res=uf.size(i)
 #   print(res)
    for value in block[i]:
        if uf.same(value,i):
            res-=1
    ans.append(res)
print(*ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# やりやすさのため、小さい桁からいけるように逆順にしておく
S=input()[::-1]
N=len(S)

# dp[i][j] := 下からi桁を考えた時，13で割ったあまりがjであるものの数
dp=list2d(N+1, 13, 0)
dp[0][0]=1
for i in range(N):
    for j in range(13):
        # ?だったら0~9を全て遷移させる
        if S[i]=='?':
            for k in range(10):
                # 桁を合わせる
                nxt=k*10**i
                dp[i+1][(j+nxt)%13]+=dp[i][j]
                dp[i+1][(j+nxt)%13]%=MOD      
        else:
            # 決まっていたらその数字のみ遷移させる
            nxt=int(S[i])*10**i
            dp[i+1][(j+nxt)%13]+=dp[i][j]
            dp[i+1][(j+nxt)%13]%=MOD
# 最終的にN桁終わって余り5の数が答え
print(dp[N][5])


### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# やりやすさのため、小さい桁からいけるように逆順にしておく
S=input()[::-1]
N=len(S)

# dp[i][j] := 下からi桁を考えた時，13で割ったあまりがjであるものの数
dp=list2d(N+1, 13, 0)
dp[0][0]=1
mul=1
for i in range(N):
    for j in range(13):
        # ?だったら0~9を全て遷移させる
        if S[i]=='?':
            for k in range(10):
                # 桁を合わせる
                nxt=k*mul
                dp[i+1][(j+nxt)%13]+=dp[i][j]
                dp[i+1][(j+nxt)%13]%=MOD      
        else:
            # 決まっていたらその数字のみ遷移させる
            nxt=int(S[i])*mul
            dp[i+1][(j+nxt)%13]+=dp[i][j]
            dp[i+1][(j+nxt)%13]%=MOD
    # 桁を合わせ用(10万桁とか直接使ったら死ぬので、毎回ここでMOD13する)
    mul*=10
    mul%=13
# 最終的にN桁終わって余り5の数が答え
print(dp[N][5])
### BUGGY CODE ###

S = input()

ans = 0
for i in range(len(S)):
    m = int(S[i:i + 4]) % 2019
    if m == 0:
        ans += 1
    for j in range(i + 4, len(S)):
        m = (10 * m + int(S[j])) % 2019
        if m == 0:
            ans += 1

print(ans)


### FIXED CODE ###

from collections import Counter

S = input()

ans = 0
mod_list = [0] * len(S)
mod_list[-1] = int(S[-1])
m = 1
for i in range(2, len(S) + 1):
    m = (10 * m) % 2019
    mod_list[-i] = (mod_list[-i + 1] + (int(S[-i]) * m)) % 2019

mod_counter = Counter(mod_list)
mod_counter[0] += 1

ans = 0
for _, v in mod_counter.items():
    ans += v * (v - 1) // 2

print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    ans = 1
    
    for i in range(N+1):
        tmp = math.sqrt(i)
        if tmp.is_integer():
            ans = i
            
    print(ans)
            	
if __name__ == "__main__":
	main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    ans = 1
    
    for i in range(N,0,-1):
        tmp = math.sqrt(i)
        if tmp.is_integer():
            print(i)
            sys.exit()
            	
if __name__ == "__main__":
	main()
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
left_max_num = 0
for i in range(1, N + 1):
    if i in a:
        left_max_num = i
        a = a[a.index(i) + 1:]
    else:
        break
if left_max_num != 0:
    print(N - left_max_num)
else:
    print(-1)


### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))

num = 0
for item in a:
    if item == (num + 1):
        num += 1

if num != 0:
    print(N - num)
else:
    print(-1)
### BUGGY CODE ###

import sys
from itertools import combinations
from math import sqrt

read = sys.stdin.read
readline = sys.stdin.readline

N, K, *xyc = map(int, read().split())
x = xyc[::3]
y = xyc[1::3]
xy = list(zip(x, y))
c = xyc[2::3]
left = 0
right = 10 ** 6
delta = 0.1 ** 7
while right - left > delta:
    mid = (left + right) / 2
    intersections = xy.copy()
    r = [(mid / i) ** 2 for i in c]
    for i, j in combinations(range(N), 2):
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        X = x2 - x1
        Y = y2 - y1
        XY = X ** 2 + Y ** 2
        r1 = r[i]
        r2 = r[j]

        a = (XY + r1 - r2) / 2
        b = XY * r1 - a ** 2
        if b < delta:
            continue
        b = sqrt(b)
        xi1 = (a * X + Y * b) / XY + x1
        yi1 = (a * Y - X * b) / XY + y1
        xi2 = (a * X - Y * b) / XY + x1
        yi2 = (a * Y + X * b) / XY + y1
        intersections.append((xi1, yi1))
        intersections.append((xi2, yi2))

    cnt = 0
    for X, Y in intersections:
        tmp = 0
        for (i, j), k in zip(xy, r):
            XY = (X - i) ** 2 + (Y - j) ** 2
            if XY < k + delta:
                tmp += 1
        cnt = max(tmp, cnt)
    if cnt >= K:
        right = mid
    else:
        left = mid

print(right)


### FIXED CODE ###

import sys
from itertools import combinations
from math import sqrt

read = sys.stdin.read
readline = sys.stdin.readline


def main():
    N, K, *xyc = map(int, read().split())
    x = xyc[::3]
    y = xyc[1::3]
    xy = list(zip(x, y))
    c = xyc[2::3]
    left = 0
    right = 10 ** 6
    delta = 0.1 ** 7
    while right - left > delta:
        mid = (left + right) / 2
        intersections = []
        r = [(mid / i) ** 2 for i in c]
        for i, j in combinations(range(N), 2):
            x1, y1 = xy[i]
            x2, y2 = xy[j]
            X = x2 - x1
            Y = y2 - y1
            XY = X ** 2 + Y ** 2
            r1 = r[i]
            r2 = r[j]

            a = (XY + r1 - r2) / 2
            b = XY * r1 - a ** 2
            if b < delta:
                continue
            b = sqrt(b)
            xi1 = (a * X + Y * b) / XY + x1
            yi1 = (a * Y - X * b) / XY + y1
            xi2 = (a * X - Y * b) / XY + x1
            yi2 = (a * Y + X * b) / XY + y1
            intersections.append((xi1, yi1))
            intersections.append((xi2, yi2))

        intersections.extend(xy)
        cnt = 0
        for X, Y in intersections:
            tmp = 0
            for (i, j), k in zip(xy, r):
                XY = (X - i) ** 2 + (Y - j) ** 2
                if XY < k + delta:
                    tmp += 1
            cnt = max(tmp, cnt)
            if cnt >= K:
                break
        if cnt >= K:
            right = mid
        else:
            left = mid

    print(right)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

a = int(input())
b = []
for _ in range(a):
  b.append(sorted(list(input())))

ans = 0
for i in range(a):
  for j in range(i+1, a):
    check = True
    if b[i] != b[j]:
      check = False
    if check == True:
      ans += 1
print(ans)

### FIXED CODE ###

a = int(input())
b = {}
strings = ''
ans = 0

for i in range(a):
    check = True
    strings = ''.join(sorted(list(input())))
    if strings not in b.keys():
      check = False
      b[strings] = 1
    if check == True:
      ans += b[strings]
      b[strings] += 1

print(ans)
### BUGGY CODE ###

A, B, K = [int(n) for n in input().split()]
for i in range(K):
    if A>=1:
        A -= 1
    elif B>=1:
        B -= 1
print(A,B)


### FIXED CODE ###

A, B, K = [int(n) for n in input().split()]
if K>A:
    K -= A
    if K>B:
        print(0,0)
    else:
        print(0, B-K)
else:
    print(A-K,B)
### BUGGY CODE ###

N,C = map(int,input().split())
d = [list(map(int,input().split())) for _ in range(C)]
c = [list(map(int,input().split())) for _ in range(N)]
c_set = set([])
for c_ in c:
    c_set |= set(c_)
ans = 1e9
for c_1 in range(C):
    for c_2 in range(C):
        for c_3 in range(C):
            if not (c_1 in c_set or c_2 in c_set or c_3 in c_set):
                continue
            if c_1==c_2 or c_1==c_3 or c_2==c_3:
                continue
            c_list = [c_1,c_2,c_3]
            k = 0
            for i in range(N):
                for j in range(N):
                    if not c[i][j]==c_list[(i+j)%3]:
                        k += d[c[i][j]-1][c_list[(i+j)%3]-1]
            ans = min(ans,k)
print(ans)

### FIXED CODE ###

N,C = map(int,input().split())
d = [list(map(int,input().split())) for _ in range(C)]
c = [list(map(int,input().split())) for _ in range(N)]
c_set = [[0]*C for _ in range(3)]
for i in range(N):
    for j in range(N):
        c_set[(i+j)%3][c[i][j]-1] += 1
ans = 1e9
for c_1 in range(C):
    for c_2 in range(C):
        for c_3 in range(C):
            if c_1==c_2 or c_1==c_3 or c_2==c_3:
                continue
            c_list = [c_1,c_2,c_3]
            k = 0
            for i in range(C):
                for j in range(3):
                    k += d[i][c_list[j]-1]*c_set[j][i]
            ans = min(ans,k)
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(500000)

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

N, X = map(int, input().split())

x = list(map(int, input().split()))

li = [abs(i - X) for i in x]

# li = [i for i in li if i]
li = sorted(li, reverse=True)
if len(li) == 1:
	print(li[0])
else:
	print(gcd_list(li))

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)

def gcd(a, b):
	# while b:
	# 	a, b = b, a % b
	# return a

	if b:
		return gcd(b, a % b)
	else:
		return a

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

N, X = map(int, input().split())

x = list(map(int, input().split()))

li = [abs(i - X) for i in x]

# li = [i for i in li if i]
# li = sorted(li)
if len(li) == 1:
	print(li[0])
else:
	ans = li[0]
	for i in range(1,N):
		ans = gcd(ans, li[i])
	print(ans)