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

from operator import itemgetter

n,m=map(int,input().split())
a=list(map(int,input().split()))

for i in range(m):
    a.sort()
    b,c=map(int,input().split())
    for j in range(b):
        if(a[j]>c):
            break
        a[j]=c

print(sum(a))


### FIXED CODE ###

from operator import itemgetter

n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[]

for i in range(m):
    x=list(map(int,input().split()))
    bc.append(x)

a.sort()
bc.sort(key=itemgetter(1),reverse=True)

k=0
for i in range(m):
    b=bc[i][0]
    c=bc[i][1]
    for j in range(b):
        if(a[k]>c):
            break
        a[k]=c
        k+=1
        if(k>n-1):
            break
    else:
        continue
    break

print(sum(a))
### BUGGY CODE ###

import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    o = 1
    s = input()
    q = int(input())
    for i in range(q):
        qu = input().split()
        if qu[0] == '1':
            o = int(not o)
        else:
            addo = 1 if qu[1] == '1' else 0
            if o == addo:
                s = qu[2] + s
            else:
                s += qu[2]
        # print(s, o)
    
    if o:
        print(s)
    else:
        print(''.join(reversed(s)))




if __name__ == '__main__':
    main()


### FIXED CODE ###

import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
from collections import deque
inf = 10**9


def main():
    o = 1
    s = deque(input())
    q = int(input())
    for i in range(q):
        qu = input().split()
        if qu[0] == '1':
            o = int(not o)
        else:
            addo = 1 if qu[1] == '1' else 0
            if o == addo:
                s.appendleft(qu[2])
            else:
                s.append(qu[2])
        # print(s, o)
    
    if o:
        print(''.join(s))
    else:
        s.reverse()
        print(''.join(s))




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

n,m,k = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]
cd = [list(map(int,input().split())) for _ in range(k)]

edges = [[] for _ in range(n)]
cd2 = [[] for _ in range(n)]
friends = []
count = [-1] * n
g_count = 0
ans = [0] * n

for a,b in ab:
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

for c,d in cd:
    cd2[c-1].append(d-1)
    cd2[d-1].append(c-1)


for i in range(n):
    if count[i] == -1:
        count[i] = g_count
        g = [i]
        q = [i]
        while q:
            l = q.pop(-1)
            for f in edges[l]:
                if count[f] == -1:
                    q.append(f)
                    g.append(f)
                    count[f] = g_count

        friends.append(g)
        g_count += 1

for i in range(n):
    x = len(set(friends[count[i]]) & set(edges[i]))
    y = len(set(friends[count[i]]) & set(cd2[i]))
    z = len(set(friends[count[i]]) & set(edges[i]) & set(cd2[i]))
    ans[i] = len(friends[count[i]]) - (x + y - z) - 1

for i in range(n):
    print(ans[i], end = ' ')


### FIXED CODE ###

import sys

n,m,k = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]
cd = [list(map(int,input().split())) for _ in range(k)]

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())

uf = UnionFind(n)
ans = [0]*n
cnt = [0]*n

for a,b in ab:
    uf.union(a-1, b-1)
    cnt[a-1] += 1
    cnt[b-1] += 1

for i in range(n):
    ans[i] = uf.size(i)

for c,d in cd:
    if uf.same(c-1, d-1):
        ans[c-1] -= 1
        ans[d-1] -= 1

for i in range(n):
    print(ans[i] - cnt[i] - 1, end = ' ')
### BUGGY CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
res = 0
p = 0
for n in range(N):
    D = 0
    for k in range(K):
        O = 0
        O = sum(range(1, P[k]+1))
        D = D + (O / P[k])
    if res < D:
        res = D
    P.pop(0)
    if len(P) < K:
        break
print(res)

### FIXED CODE ###

N, K = map(int, input().split())
P    = list(map(int, input().split()))
p    = [(P[i]+1) / 2 for i in range(N)]
a    = 0
for i in range(K):
    a += p[i]
b = a
for i in range(N - K):
    c = a + p[i+K] - p[i]
    b = max(b, c)
    a = c
print(b)
### BUGGY CODE ###

_ = int(input())
ns = list(map(int, input().split()))
total = 1
for n in ns:
    total = total*n
if total > 10**18:
    print(-1)
else:
    print(total)

### FIXED CODE ###

import sys
_ = int(input())
ns = list(map(int, input().split()))
total = 1
flg = False
if 0 in ns:
    print(0)
    sys.exit(0)
for n in ns:
    if total > 10**18:
        flg = True
        break 
    total = total*n
if flg or total > 10**18:
    print(-1)
else:
    print(total)
### BUGGY CODE ###

from heapq import heappush,heappop
n,*t=map(int,open(0).read().split())
a=t[:n]
b=t[n:]
B=[]
for i,j in enumerate(b):heappush(B,(-j,i))
c=0
while B:
    y,i=heappop(B)
    x,z=b[(i-1)%n],b[(i+1)%n]
    t=(b[i]-a[i])//(x+z)
    b[i]-=t*(x+z)
    c+=t
    if b[i]>a[i]:
        heappush(B,(-b[i],i))
print([-1,c][a==b])

### FIXED CODE ###

from heapq import heappush,heappop
n,*t=map(int,open(0).read().split())
a=t[:n]
b=t[n:]
B=[]
for i,j in enumerate(b):heappush(B,(-j,i))
c=0
d=0
while B and d<2*10**6:
    d+=1
    y,i=heappop(B)
    x,z=b[(i-1)%n],b[(i+1)%n]
    t=(b[i]-a[i])//(x+z)
    b[i]-=t*(x+z)
    c+=t
    if b[i]>a[i]:
        heappush(B,(-b[i],i))
print([-1,c][a==b])
### BUGGY CODE ###

l = int(input())
s = input()
r = set()
for x in range(0, l - 2):
    for y in range(x + 1, l - 1):
        for z in range(y + 1, l):
            r.add(s[x] + s[y] + s[z])

print(len(r))

### FIXED CODE ###

l = int(input())
s = input()
r = set()
cx = set(s)
for x in range(0, l - 2):
    if not cx:
        break
    if s[x] not in cx:
        continue
    cx.remove(s[x])
    cy = set(s[x+1:])
    for y in range(x + 1, l - 1):
        if not cy:
            break
        if s[y] not in cy:
            continue
        cy.remove(s[y])
        cz = set(s[y+1:])
        for z in range(y + 1, l):
            if not cz:
                break
            if s[z] not in cz:
                continue
            cz.remove(s[z])
            r.add(s[x] + s[y] + s[z])

print(len(r))
### BUGGY CODE ###

from collections import Counter
import bisect
N = int(input())
A = list(map(int,input().split()))



cnt = Counter(A)
A.sort()
ans = 0
for i in range(len(A)):
    if cnt[A[i]] > 1:
        continue
    idx = bisect.bisect_left(A, pow(A[i],0.5))
    J = min(idx+10,i)
    J = i
    ok = True
    for j in range(J):
        #print(i,j)
        if A[i] % A[j] == 0:
            ok = False
            break
    if ok:
        ans += 1
print (ans)



### FIXED CODE ###

from collections import Counter
import bisect
N = int(input())
A = list(map(int,input().split()))



cnt = Counter(A)
A.sort()
ans = 0
P = [0] * (10**6+1)
#print(cnt)
for a in A:
    if P[a]==0:
        for i in range(10**7):
            x = a*i
            if x>10**6:
                break
            P[x] = 1
        if cnt[a]==1:
            ans +=1

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

from itertools import *
n=range(49994);a=list(n)
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):x=int(x);print(sum(1 for a,b in combinations_with_replacement(p[:x],2)if a+b==x))


### FIXED CODE ###

import bisect,sys
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in map(int,sys.stdin):
 if x:print(len([1 for d in p[:bisect.bisect(p,x//2)]if a[x-d]]))
### BUGGY CODE ###

def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<20, 1<<20, N*(N-1)//4+1, N*(N-1)//4+1
    if N <= 10000: l, r = -1<<28, 1<<28
    while r - l > 0.000000001:
        m = (l+r) / 2 if N <= 10000 else (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

### FIXED CODE ###

def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    f = 1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l+r) / 2 if f else (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
        f ^= 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
S=[tuple(d for d in input()) for i in range(H)]
ans=[[0 for j in range(W)] for i in range(H)]
t=0
for i in range(H):
 p=0
 for j in range(W):
  if S[i][j]==".":
   p+=1
  else:
   p=0
  ans[i][j]+=p
for i in range(H):
 p=0
 for j in range(W)[::-1]:
  if S[i][j]==".":
   p+=1
  else:
   p=0
  ans[i][j]+=p
for j in range(W):
 p=0
 for i in range(H):
  if S[i][j]==".":
   p+=1
  else:
   p=0
  ans[i][j]+=p
for j in range(W):
 p=0
 for i in range(H)[::-1]:
  if S[i][j]==".":
   p+=1
  else:
   p=0
  ans[i][j]+=p
  t=max(t,ans[i][j])
print(t-3)

### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
S=[[d for d in input()] for i in range(H)]
ans=[[0 for j in range(W)] for i in range(H)]
t=0
for i in range(H):
 p=0
 for j in range(W):
  if S[i][j]==".":
   p+=1
  else:
   p=0
  ans[i][j]+=p
for i in range(H):
 p=0
 for j in range(W)[::-1]:
  if S[i][j]==".":
   p+=1
  else:
   p=0
  ans[i][j]+=p
for j in range(W):
 p=0
 for i in range(H):
  if S[i][j]==".":
   p+=1
  else:
   p=0
  ans[i][j]+=p
for j in range(W):
 p=0
 for i in range(H)[::-1]:
  if S[i][j]==".":
   p+=1
  else:
   p=0
  ans[i][j]+=p
  t=max(t,ans[i][j])
print(t-3)
### BUGGY CODE ###

from collections import deque
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find_list = [0]
i = 0
count = 0
for _ in range(n):
    if a[i]-1 in roop_find_list:
        break
    else:
        roop_find_list.append(a[i]-1)
        i = a[i] - 1
        count += 1
b = roop_find_list.index(a[i]-1)

if k < b:
    print(roop_find_list[k]+1)
else:
    k-=b
    e = k % (count+1-b)
    print(roop_find_list[b+e]+1)


### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)
### BUGGY CODE ###

import copy

N = int(input())

A = [int(input()) for _ in range(N)]

max_a = max(A)

for i in range(N):
    if(A[i] != max_a):
        print(max_a)
    else:
        B = copy.deepcopy(A)
        B.pop(i)
        print(max(B))


### FIXED CODE ###

import copy

N = int(input())

A = [int(input()) for _ in range(N)]
B = sorted(A)
max_1 = B[-1]
max_2 = B[-2]

for i in range(N):
    if(A[i]==max_1):
        print(max_2)
    else:
        print(max_1)
### BUGGY CODE ###

a,b,k = [int(i) for i in input().split()]
appear = [0 for i in range(b+1)]
for i in range(a, a+k):
    if i <= b:
        appear[i] = 1
for i in range(b+1-k, b+1):
    if i >= a:
        appear[i] = 1
for i in range(len(appear)):
    if appear[i] == 1:
        print(i)


### FIXED CODE ###

a,b,k = [int(i) for i in input().split()]

if a+k-1<b-k+1:
    for i in range(a,a+k):
        print(i)
    for i in range(b+1-k, b+1):
        print(i)
else:
    for i in range(a,b+1):
        print(i)
### BUGGY CODE ###

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

import math

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()

cnum = []

takadaka = math.ceil(k ** 0.67)

for i in range(min(takadaka,x)):
    for j in range(min(takadaka,y)):
        for l in range(min(takadaka,z)):
            cnum.append(a[i] + b[j] + c[l])

cnum.sort()
cnum.reverse()

for i in range(k):
    print(cnum[i])


### FIXED CODE ###

# -*- coding: utf-8 -*-
x,y,z,k = map(int,input().split())
a,b,c = [],[],[]
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = []

for i in range(x):
    for j in range(y):
        ab.append(a[i] + b[j])

ab.sort()

abc = []

for i in range(min(len(ab),k)):
    for j in range(min(z,k)):
        abc.append(ab[-(i+1)] + c[j])

abc.sort()

for i in range(k):
    print(abc[-(i+1)])
### BUGGY CODE ###

N = int(input())
count = 0
ans = list()
r = 0
alp = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

while N > 26**count:
    count+=1

count = count - 1
count2 = count

while count > 0:
    N = N - 26**count
    count = count - 1

#print(N)

N = N - 1
A = 1
while A != 0:
    A = N // 26
    B = N % 26
    ans.append(B)
    N = A

#print(ans)
#print(len(ans))
#print(count2+1)

while len(ans) < count2 + 1:
    ans.append(0)
    #print(len(ans))

#print(N)
#print(len(ans))
#print(ans)
ans.reverse()
#print(ans)

for i in range(0, len(ans)):
    ans[i] = alp[ans[i]]

#print(ans)

print(''.join(ans))

### FIXED CODE ###

N = int(input())
alphabet_lst = list('abcdefghijklmnopqrstuvwxyz')
#print(alphabet_lst)

keta = 0
keta_lst = []
sum_lst = []
while N>=sum(keta_lst):
    keta_lst.append(26**keta)
    sum_keta = sum(keta_lst)
    sum_lst.append(sum_keta)
    keta += 1
    
keta -= 1
keta_lst = keta_lst[:keta]
#print(keta_lst)
#print(keta)

ans_lst = []
for i in range(keta):
    ans_n = (N - sum(keta_lst[:-(i+1)])) // keta_lst[-(i+1)]
    #print(ans_n)
    #print(keta_lst[-(i+1)])
    N -= ans_n*keta_lst[-(i+1)]
    ans_lst.append(alphabet_lst[ans_n-1])

for i in range(keta):
    print(ans_lst[i],end="")
### BUGGY CODE ###

N,W=map(int,input().split())
lwv=[]
for i in range(N):
    lwv.append(list(map(int,input().split())))
ldp=[[0 for j in range(W+1)] for i in range(N)]
for j in range(W+1):
    if lwv[0][0]<=j:
        ldp[0][j]=lwv[0][1]
for i in range(1,N):
    for j in range(W+1):
        if j-lwv[i][0]>=0:
            ldp[i][j]=max(ldp[i-1][j],ldp[i-1][j-lwv[i][0]]+lwv[i][1])
        else:
            ldp[i][j]=ldp[i-1][j]
print(ldp[N-1][W])


### FIXED CODE ###

N,W=map(int,input().split())
lwv=[]
for i in range(N):
    lwv.append(list(map(int,input().split())))
ldp=[[0 for j in range(W+1)] for i in range(N)]
for j in range(W+1):
    if lwv[0][0]<=j:
        ldp[0][j]=lwv[0][1]
for i in range(1,N):
    for j in range(W+1):
        if j-lwv[i][0]>=0:
            ldp[i][j]=max(ldp[i-1][j],ldp[i-1][j-lwv[i][0]]+lwv[i][1])
        else:
            ldp[i][j]=ldp[i-1][j]
print(ldp[N-1][W])
### BUGGY CODE ###

import math
N = int(input())
count = 0
flag = False
# n = int(math.sqrt(N))
n = N // 5

for i in range(1, N + 1):
    
    for j in range(1, n):
        for l in range(1, n):
            for r in range(1, n):
                if j ** 2 + l ** 2 + r ** 2 + j * l + j * r + l * r == i:
                    if j == l == r:
                        flag = True
                        count = 1
                        break
                    else:
                        flag = True
                        count = 3
                        break
            if flag:
                break
        if flag:
            break            
    print(count)
    count = 0
    flag = False

### FIXED CODE ###

# # import math
N = int(input())
# # count = 0
# # flag = False
# # # n = int(math.sqrt(N))
n = 105

# # for i in range(1, N + 1):
    
# #     for j in range(1, n):
# #         for l in range(1, n):
# #             for r in range(1, n):
# #                 if j + l + r > N // 2:
# #                     continue
# #                 if j ** 2 + l ** 2 + r ** 2 + j * l + j * r + l * r == i:
# #                     if j == l == r:
# #                         flag = True
# #                         count = 1
# #                         break
# #                     else:
# #                         flag = True
# #                         count = 3
# #                         break
# #             if flag:
# #                 break
# #         if flag:
# #             break            
# #     print(count)
# #     count = 0
# #     flag = False
ans = [0] * 10050
for j in range(1, n):
    for l in range(1, n):
        for r in range(1, n):
            value = j * j  + l * l + r * r + j * l + j * r + l * r
            if value < 10050:
                ans[value] += 1

for i in range(N):
    print(ans[i + 1])
# n = int(input())
# ans = [0 for _ in range(10050)]
# for i in range(1,105):
#     for j in range(1,105):
#         for k in range(1,105):
#             v = i*i+j*j+k*k+i*j+j*k+k*i;
#             if v<10050:
#                 ans[v]+=1   
# for i in range(n):
#     print(ans[i+1])
### BUGGY CODE ###

from collections import deque

ss = input()
q = int(input())
s = deque()

for i in range(len(ss)) :
  s.append(ss[i])

for i in range(q) :
  t = list(map(str,input().split()))
  if t[0] == '1' :
    s.reverse()
  if t[0] == '2' :
    f = t[1] ; c = t[2]
    if f == '1' :
      s.appendleft(c)
    else :
      s.append(c)
      
print(*s,sep='')

### FIXED CODE ###

from collections import deque

ss = input()
q = int(input())
s = deque()

for i in range(len(ss)) :
  s.append(ss[i])

r = 0
for i in range(q) :
  t = list(map(str,input().split()))
  if t[0] == '1' :
    r += 1
  if t[0] == '2' :
    f = t[1] ; c = t[2]
    if r%2 == 0 :
      if f == '1' :
        s.appendleft(c)
      else :
        s.append(c)
    else :
      if f == '2' :
        s.appendleft(c)
      else :
        s.append(c)
        
if r%2 == 1 :
  s.reverse()
  
print(*s,sep='')
### BUGGY CODE ###

n=int(input())
l=list(map(int,input().split()))
cnt=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i]<l[j]+l[k]:
        if l[j]<l[i]+l[k]:
          if l[k]<l[j]+l[i]:
            cnt+=1
print(cnt)


### FIXED CODE ###

import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
cnt=0
for i in range(n-1):
  for j in range(i+1,n):
    a=l[i]
    b=l[j]
    c=bisect.bisect_left(l,a+b)
    cnt+=c-1-j
print(cnt)
### BUGGY CODE ###

n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[]
b=[]
c=0
for i in range(m):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
for i in range(len(h)):
    d=[]
    f=0
    for j in range(m):
        if a[j]==i+1:
            d.append(b[j])
    for j in range(m):
        if b[j]==i+1:
            d.append(a[j])
    for k in d:
        if h[k-1]>=h[i]:
            f+=1
    if f==0:
        c+=1
print(c)

### FIXED CODE ###

n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[]
for i in range(n):
    ab.append(0)
for i in range(m):
    ai,bi=map(int,input().split())
    if h[ai-1]>=h[bi-1]:
        ab[bi-1]+=1
    if h[ai-1]<=h[bi-1]:
        ab[ai-1]+=1
print(ab.count(0))
### BUGGY CODE ###

# コンテスト時にトライしていたアルゴリズム
# その後の検証でアルゴリズムは正しそうなのでコードエラーを探す

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

# TLE対策 dist_listからmax_Dを求める
# nearest_city = getNearestValue(city_list, x)
# Dとなり最大値はXと最も近い都市との距離に等しい
# max_D = abs(nearest_city-x)

# TLE対策 都市との距離は事前に計算
""" dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))
 """
dist_list = [abs(city-x) for city in city_list]

# TLE対策 mac_D対策
dist_list.sort()
max_D = dist_list.pop(0)

for xx in reversed(range(1, max_D+1)):
    flag = True
    for dist in dist_list:
        if (dist % xx) != 0:
            flag = False
            break
    if flag:
        break
print(xx)

### FIXED CODE ###

import fractions

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

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

dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))

max_common_value = dist_list.pop(0)

for dist in dist_list:
    # 今までのDと次の都市の距離との最大公約数を見つける
    max_common_value = fractions.gcd(max_common_value, dist)

print(max_common_value)