Harryxun/stf_run huggingface dataset:
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):
	#N:処理する区間の長さ
	def __init__(self, N):
		self.N = N
		self.N0 = 2 ** (N - 1).bit_length()
		self.initVal = 0
		self.data = [self.initVal] * (2 * self.N0)

	# 区間クエリの種類
	def calc(self, a, b):
		return a + b

	#k番目の値をxに更新
	def update(self, k, x):
		k += self.N0 - 1
		self.data[k] = x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2])

	#区間[l, r]の演算値
	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = self.initVal
		while L < R:
			if R & 1:
				R -= 1
				m = self.calc(m, self.data[R - 1])
			if L & 1:
				m = self.calc(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

#処理内容
def main():
	N, Q = getlist()
	c = getlist()
	LR = []
	lastappeared = [None] * N

	ans = [0] * N
	for i in range(Q):
		l, r = getlist()
		l -= 1; r -= 1
		LR.append([r, l, i])

	LR.sort(key = lambda x:x[0])
	Seg = SegmentTree(N)
	right = 0
	for r, l, i in LR:
		while right <= r:
			itr = c[right] - 1
			if lastappeared[itr] == None:
				Seg.update(right, 1)
			else:
				Seg.update(lastappeared[itr], 0)
				Seg.update(right, 1)
			lastappeared[itr] = right
			right += 1

		if l == 0:
			anspre = Seg.query(0, r)
		else:
			anspre = Seg.query(l, r)
		ans[i] = anspre

	for i in range(Q):
		print(ans[i])



if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):
	#N:処理する区間の長さ
	def __init__(self, N):
		self.N = N
		self.N0 = 2 ** (N - 1).bit_length()
		self.initVal = 0
		self.data = [self.initVal] * (2 * self.N0)

	# 区間クエリの種類
	def calc(self, a, b):
		return a + b

	#k番目の値をxに更新
	def update(self, k, x):
		k += self.N0 - 1
		self.data[k] = x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2])

	#区間[l, r]の演算値
	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = self.initVal
		while L < R:
			if R & 1:
				R -= 1
				m = self.calc(m, self.data[R - 1])
			if L & 1:
				m = self.calc(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

#処理内容
def main():
	N, Q = getlist()
	c = getlist()
	LR = []
	lastappeared = [None] * N

	ans = [0] * Q
	for i in range(Q):
		l, r = getlist()
		l -= 1; r -= 1
		LR.append([r, l, i])

	LR.sort(key = lambda x:x[0])
	Seg = SegmentTree(N)
	right = 0
	for r, l, i in LR:
		while right <= r:
			itr = c[right] - 1
			if lastappeared[itr] == None:
				Seg.update(right, 1)
			else:
				Seg.update(lastappeared[itr], 0)
				Seg.update(right, 1)
			lastappeared[itr] = right
			right += 1

		if l == 0:
			anspre = Seg.query(0, r)
		else:
			anspre = Seg.query(l, r)
		ans[i] = anspre

	for i in range(Q):
		print(ans[i])



if __name__ == '__main__':
	main()
n = int(input())

mins = [0] * n
maxs = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    mins[i] = a
    maxs[i] = b

mins = sorted(mins)
maxs = sorted(maxs)

if n % 2 != 0:
    print(maxs[((n+1)//2) - 1] - mins[((n+1)//2) - 1] + 1)
else:
    print(((maxs[n//2] - mins[(n//2) - 1] + 1) * 2)

### FIXED CODE ###

n = int(input())

mins = [0] * n
maxs = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    mins[i] = a
    maxs[i] = b

mins = sorted(mins)
maxs = sorted(maxs)

if n % 2 != 0:
    print(maxs[((n+1)//2) - 1] - mins[((n+1)//2) - 1] + 1)
else:
    print(int(2 * ((maxs[((n+1)//2) - 1] + maxs[n//2])/2 - (mins[((n+1)//2) - 1] + mins[n//2])/2) + 1))
n=input()
t=len(n)
if t<4:
  print(1000-int(n))
else:
  k,p=int(n[0]),int(n[1])
  if p!=0:
    print((k+1)*1000-int(n))
  else:
    print(0

### FIXED CODE ###

n=input()
t=len(n)
if t<4:
  print(1000-int(n))
else:
  k=int(n[0])
  if int(n)>k*10**(t-1):
    print((k+1)*1000-int(n))
  else:
    print(0)
dp = [[0]*3 for i in range(3)]
L = []
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
L = [a,b,c]
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))

flag = 0 

for i in range(3):
    for j in range(3):
        if L[i][j] in l:
            dp[i][j] = 1
# dp = [[1,1,0],[0,1,0],[1,0,1]]
for i in range(3):
    if sum(dp[i]) ==3:
        flag = 1

for j in range(3):
    s = 0
    for i in range(3):
        s+= dp[i][j]
    if s == 3:
        flag = 1
s = 0
t = 0
for i in range(3):
    s+=  dp[i][i]
    t+= dp[i][2-i]
if s==3 or t == 3:
    flag = 1
    
if flag:
    print('Yes')
else:
    print('No')
# print(dp)

### FIXED CODE ###


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

l = []

for i in range(m):
    ta,tb = map(int,input().split())
    l.append((ta-1,tb))
ans = [0]*n
l.sort()
if m ==0 and n==1:
    print(0)
    exit()
elif m ==0:
    print('1'+'0'*(n-1))
    exit()
elif n == 1:
    if len(set(l)) ==1:
        print(l[0][1])
    else:
        print(-1)
    exit()
elif l[0][1] == 0 and l[0][0]==0:
    print(-1)
    exit()
else:
    l = set(l)
    for i,j in l:
        if ans[i] ==0:
            ans[i] = j
        else:
            # print(i,j)
            print(-1)
            exit()
a = ''
for i in ans:
    a+=str(i)
if a[0]=='0':
    a='1'+a[1:]
print(a)
# -*- coding: utf-8 -*-

count = 0
left_arr = []
right_arr = []


def merge(a, n, left, mid, right):
    n1 = mid - left
    for i in range(n1):
        left_arr[i] = a[left + 1]

    n2 = right - mid
    for i in range(n2):
        right_arr[i] = a[mid + i]

    left_arr[n1] = right_arr[n2] = 20 * 1000000

    i = j = 0
    for k in range(left, right):
        count += 1
        if left_arr[i] <= right_arr[j]:
            i += 1
            a[k] = left_arr[i]
        else:
            j += 1
            a[k] = right_arr[j]
    return a


def merge_sort(a, n, left, right):
    if (left + 1) < right:
        mid = (left + right) // 2
        merge_sort(a, n, left, mid)
        merge_sort(a, n, mid, right)
        arr = merge(a, n, left, mid, right)
    return arr


def main():
    n = int(input())
    a = [int(e) for e in input().split()]
    sorted_arr = merge_sort(a, n, 0, n)
    return " ".join(sorted_arr)


print(main())
print(count)

### FIXED CODE ###

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

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    left_ns = ns[left:mid] + [infinity]
    right_ns = ns[mid:right] + [infinity]
    i = j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


def merge_sort(ns, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(ns, left, mid)
        merge_sort(ns, mid, right)
        merge(ns, left, mid, right)


n = int(input())
ns = [int(e) for e in input().split()]
# n = 10
# ns = [8, 5, 9, 2, 6, 3, 7, 1, 10, 4]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)

print(*ns)
print(count)
a = int(input())

b = int(input())

seki = a * b

if seki % 2 == 0:
    print('Even')
else:
    print('Odd')

### FIXED CODE ###

a, b = map(int, input().split())

seki = a * b

if seki % 2 == 0:
    print('Even')
else:
    print('Odd')
import numpy as np

N = int(input())
T = list(map(int, input().split()))
M = int(input())
for i in range(M):
    P, X = map(int(input().split()))
    
    T_new = T
    T_new[P[i]] = X
    print(np.array(T_new).sum())

### FIXED CODE ###

import numpy as np

N = int(input())
T = list(map(int, input().split()))
M = int(input())
for i in range(M):
    P, X = map(int, input().split())
    
    T_new = T.copy()
    T_new[P-1] = X
    print(np.array(T_new).sum())
#A
s = input()
k = int(input())
s_sum = 0

s_f = 1
s_l = 1

if s[0] == s[-1]:
    
    for i in range(len(s)):
        if i != 0:
            if s[i] == s[i-1]:
                s_f += 1
            else:
                break
    
    for i in range(len(s)-1 , -1, -1):
        if i != len(s)-1:
            if s[i] == s[i+1]:
                s_l += 1
            else:
                break
if s_f == len(s) and len(s) % 2 == 1:
    print((k * len(s)) / 2)
    else:   
    if s_f + s_l % 2 == 0 and s_f != 1 and s_l != 1:
        s_sum += 1

    n = 1
    for i in range(len(s)):
        if i != 0:
            if s[i] == s[i-1]:
                n += 1
            else:
                if n != 1:
                    if n % 2 == 0:
                        s_sum += (n / 2)
                    else:
                        s_sum += ((n - 1)/ 2)
                    n = 1

        if i == (len(s) - 1):
            if n != 1:
                if n % 2 == 0:
                    s_sum += (n / 2)
                else:
                    s_sum += ((n - 1)/ 2)

    print(int(s_sum * k))

### FIXED CODE ###

#A
s = input()
k = int(input())
s_sum = 0

s_f = 1
s_l = 1


if s[0] == s[-1]:
    for i in range(len(s)):
        if i != 0:
            if s[i] == s[i-1]:
                s_f += 1
            else:
                break
                
    
    for i in range(len(s)-1 , -1, -1):
        if i != len(s)-1:
            if s[i] == s[i+1]:
                s_l += 1
            else:
                break
                
    
                
                
    if s_f == len(s):
        print((k * len(s)) // 2)
        
    else:
        n = 1
        is_not_first = False
        for i in range(len(s)):
            if i != 0:
                if s[i] == s[i-1]:
                    n += 1
                else:
                    if not is_not_first:
                        is_not_first = True
                        n = 1
                    else:
                        if n != 1:
                            if n % 2 == 0:
                                s_sum += (n / 2)
                            else:
                                s_sum += ((n - 1)/ 2)
                            n = 1

        x1 = (s_f // 2 + s_l // 2) + s_sum * k
        x2 = ((s_f + s_l)//2) * (k-1)
        print(int(x1 + x2))
        
else:   
    n = 1
    for i in range(len(s)):
        if i != 0:
            if s[i] == s[i-1]:
                n += 1
            else:
                if n != 1:
                    if n % 2 == 0:
                        s_sum += (n / 2)
                    else:
                        s_sum += ((n - 1)/ 2)
                    n = 1
                    

        if i == (len(s) - 1):
            if n != 1:
                if n % 2 == 0:
                    s_sum += (n / 2)
                else:
                    s_sum += ((n - 1)/ 2)
                    

    print(int(s_sum * k))
i = input().split()

N = int(i[0])
K = int(i[1])

result = ''
tmp = N
while tmp >= K:
    idx = str(tmp % K)
    result = idx + result
    tmp = int(tmp / K)
idx = str(tmp % K)
result = idx + result

print(result)

### FIXED CODE ###

i = input().split()

N = int(i[0])
R = int(i[1])

IR = 0

if N >= 10 :
    IR = R
else :
    IR = R + 100 * (10 - N)

print(IR)
def selectionsort(l,n):
    c=0
    for i in range(n):
        minj=i
        for j in range(i,n):
            if int(l[i])<int(l[minj]):
               minj=j
        l[j],l[minj]=l[minj],l[j]
        if j!=minj:
          c+=1
    print("".join(l))
    print(c)
n=int(input())
l=list(input())
selectionsort(l,n)


### FIXED CODE ###

def selectionsort(l,n):
    c=0
    for i in range(n):
        minj=i
        for j in range(i,n):
            if int(l[j])<int(l[minj]):
               minj=j
        l[i],l[minj]=l[minj],l[i]
        if i!=minj:
          c+=1
    print(" ".join(l))
    print(c)
n=int(input())
l=list(input().split())
selectionsort(l,n)
#58B
A=input()
B=input()
import ita
pasw=ita.array.make1d(len(A)+len(B)+1)
for i in range(0,len(A)):
    pasw[2*i]=A[i]
for j in range(0,len(B)):
    pasw[2*j+1]=B[j]
print(pasw)
    



### FIXED CODE ###

#58B
A=list(input())
B=list(input())
x=A[0]+B[0]
for i in range(1,len(B)):
    x=x+A[i]+B[i]
if len(A)>len(B):
    x=x+A[-1]
print(x)
from math import factorial
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n, k = map(int, input().split())
a = sorted(map(int, input().split()))


mod = 10**9+7
def main():
  s = 0
  if k == 1:
    print(0)
    return
  for i in range(len(a)):
    for j in range(k - 1, len(a) - i):
      s += (a[i+j] - a[i]) * cmb(j-1, k-2, mod) % mod
      s %= mod
  print(s)
main()

### FIXED CODE ###

from math import factorial
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n, k = map(int, input().split())
a = sorted(map(int, input().split()))


mod = 10**9+7
def main():
  s = 0
  l = len(a)
  for i in range(l):
    s += a[i] * cmb(i, k - 1, mod)
    s -= a[i] * cmb(l - i -1 , k - 1, mod)

    s %= mod
  print(s)
main()
import math
if __name__ == "__main__":
    A,B,C,D = map(int,input().split())
    ac = A%C
    E = int(C * D / math.gcd(C,D))
    if ac == 0:
        modc = B//C - A//C + 1
    else:
        modc = B//C - A//C
    ad = A%D
    if ad == 0:
        modd = B//D - A//D + 1
    else:
        modd = B//D - A//D
    ae = A%E
    if ae == 0:
        mode = B//E - A//E + 1
    else:
        mode = B//E - A//E
    print(int(B-A+1-modc-modd+mode))

### FIXED CODE ###

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

if __name__ == "__main__":
    A,B,C,D = map(int,input().split())
    ac = A%C
    E = int(C*D/gcd(C,D))
    if ac == 0:
        modc = B//C - A//C + 1
    else:
        modc = B//C - A//C
    ad = A%D
    if ad == 0:
        modd = B//D - A//D + 1
    else:
        modd = B//D - A//D
    ae = A%E
    if ae == 0:
        mode = B//E - A//E + 1
    else:
        mode = B//E - A//E
    print(int(B-A+1-modc-modd+mode))
import itertools

n, m = input().split()
N = int(n)
M = int(m)

K = []
for i in range(M):
    K.append(list(map(int, input().strip().split(' '))))

P = list(map(int, input().strip().split(' ')))

SW = {0, 1}
SWlist = list(itertools.product(SW, repeat=N))

result = 0
fflag = False

for i in range(len(SWlist)):
    for j in range(len(K)):
        count = 0
        for k in range(K[j][0]):
            if SWlist[i][k] == 1:
                count += 1
        if count % 2 != P[j]:
            fflag = True
            break
    if not fflag:
        result += 1
    else:
        fflag = False
print(result)


### FIXED CODE ###

n, m = input().split()
A = int(n)
P = int(m)

N = A * 3 + P
result = N // 2
print(result)
import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    idxlist = [[] for _ in range(n)]
    d = []
    dp = [INF for _ in range(n + 1)]
    dp[0] = 1

    for i in range(n):
        di = ni()
        di -= 1
        if i > 0:
            if d[-1] == di:
                d.append(-1)
                continue
        d.append(di)
        idxlist[di].append(i)

    for i, di in enumerate(d):
        dp[i + 1] = dp[i]
        if di == -1:
            continue
        bidx = bisect.bisect_left(idxlist[di], i)
        if bidx - 1 >= 0:
            dp[i + 1] += dp[idxlist[di][bidx - 1] + 1]
            dp[i + 1] %= MOD

    print(dp[n])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    last = [-1 for _ in range(2 * 10 ** 5 + 1)]
    dp = [INF for _ in range(n + 1)]
    dp[0] = 1

    d = [ni()-1 for _ in range(n)]

    for i, di in enumerate(d):
        dp[i + 1] = dp[i]
        if last[di] != -1:
            if i - last[di] != 1:
                dp[i + 1] += dp[last[di] + 1]
                dp[i + 1] %= MOD
        last[di] = i

    print(dp[n])


if __name__ == '__main__':
    main()
def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans

n = int(raw_input())
a = map(int, raw_input().split())
ans = min(map(how_many_times_divisible, a))

print ans

### FIXED CODE ###

def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans

n = int(input())
a = map(int, input().split())
ans = min(map(how_many_times_divisible, a))

print(ans)
N = int(input())

S = str(input())

K = int(input())

Char = []

#Muita gambiarra! lol

for i in range(len(S)-(len(S)-N)):

	Char.append(S[i])	if Char[i] != S[K-1]:

		Char[i] = '*'

for i in Char:

	print(i,end='')

### FIXED CODE ###

N = int(input())
S = str(input())
K = int(input())
Char = ''
for i in range(N):
	if S[i] != S[K-1]:
		Char += '*'
	else:
		Char += S[i]
print(Char)
import random

S = list(input())
n = len(S)
reS = list(reversed(S))

diffeNum_list = []
alphabets = [chr(ord("a") + i) for i in range(26)]
countLi = []

if S == reS:
    print(0)
else:
    for i in range(n):
        if S[i] != reS[i]:
            diffeNum_list.append(i)

    def hantei(S):
        count = 0
        for i in diffeNum_list:
            tempNum = random.choice(alphabets)
            if S[i] != tempNum:
                S[i] = tempNum
                count += 1

            if S == reS:
                countLi.append(count)

    for i in range(10000):
        hantei(S)

    print(min(countLi))

### FIXED CODE ###

s = list(input())

cnt = 0

for i in range(int(len(s) / 2)):
    if s[i] != s[-(i + 1)]:
        cnt += 1

print(cnt)
l = list(input())
a = int(l[0])
b = float(l[1])
print(int(a*b))

### FIXED CODE ###

from decimal import Decimal
l = list(input().split())
a = int(l[0])
b = Decimal(l[1])
print(int(a*b))
n,y = map(int.input().split())
y //= 1000
k = min((n-y)//4,y//5)
if 9 * k > 2 * (n-y):
  x = (y-n) - 4 *k
  y = 9 * k - 2*(y-n)
  z = y -5*k
  print(x,y,z)
  exit()
print('-1 -1 -1')

### FIXED CODE ###

n,m = map(int,input().split())
for x in range(n+1):
  for y in range(n+1):
    z = n - x - y
    if (10000*x + 5000*y + 1000*z == m and x + y + z == n and 0 <= z <=n):
        print(x,y,z)
        exit()
print('-1 -1 -1')
A,B,C,K = map(int,input().split())

total = []
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if i + j + k == K:
        t = i - k
        total.append(t)

print(max(total))

### FIXED CODE ###

S = input()
T = input()
print("Yes" if S == T[:-1] else "No")
x,y = map(int,input().split())
if y == x:
    print(0)
else:
    if abs(y) >= abs(x):
        tmp = abs(y)-abs(x)
        if x>=0 and y>=0:
            print(tmp)
        elif x>=0 and y<0:
            print(tmp+1)
        elif x<0 and y>=0:
            print(tmp+1)
        else:
            #print(abs(y)-x+1)
            print(1/0)
    else:
        if x>=0 and y>=0:
            print(x+y+1)
        elif x>=0 and y<0:
            print(x+y+1)
        elif x<0 and y>=0:
            print(y-x)
        else:
            print(y-x)

### FIXED CODE ###

x,y = map(int,input().split())
if y == x:
    print(0)
elif y == 0:
    if x > 0:
        print(x+1)
    else:
        print(-x)
else:
    if abs(y) >= abs(x):
        tmp = abs(y)-abs(x)
        if x>=0 and y>=0:
            print(tmp)
        elif x>=0 and y<0:
            print(tmp+1)
        elif x<0 and y>=0:
            print(tmp+1)
        else:
            print(tmp+2)
    else:
        if x>=0 and y>=0:
            print(-y+x+2)
        elif x>=0 and y<0:
            print(x+y+1)
        elif x<0 and y>=0:
            print(-y-x+1)
        else:
            print(y-x)
x ,n = map(int, input().split())
s = list(map(int, input().split()))
number = list(range(0,102))
min = 100
if n == 0:
  print(x)
  exit()
  
for i in range(n):
  number.remove(s[i])

for i in range(100 - n):
  if min > abs(x - number[i]):
    min = abs(x - number[i])
    j = i
print(number[j])


### FIXED CODE ###

x ,n = map(int, input().split())
s = list(map(int, input().split()))
number = list(range(0,102))
min = 100
if n == 0:
  print(x)
  exit()
  
for i in range(n):
  number.remove(s[i])

for i in range(102 - n):
  if min > abs(x - number[i]):
    min = abs(x - number[i])
    j = i
print(number[j])
import sys
K = int(input())

d = pow(9, -1, K)
for ans in range(1, K):
    x = 7*(pow(10, ans, K) - 1)*d
    if  x%K == 0:
        print(ans)
        sys.exit()

print(-1)


### FIXED CODE ###

import sys
K = int(input())

x = 7
for ans in range(1, K*2):

    if  x%K == 0:
        print(ans)
        sys.exit()

    x = (x*10 + 7) % K
print(-1)
#coding:utf-8
def Dijkestra(G,n):
    d=[100000000000]*n
    pi=[None]*n
    d[0]=0
    C=[]
    for i in range(n):
        C.append(i)
    
    while len(C)!=0:
        u=C[0]
        for i in range(1,len(C)):
            if d[u]>d[i]:
                u=i
        C.remove(u)
        for i in range(len(G[u])):
            if G[u][i]==-1:
                continue
            elif d[i]>d[u]+G[u][i]:
                d[i]=d[u]+G[u][i]
                pi[i]=u
                        
    for i in range(n):
        print(i,d[i])
    

if __name__=="__main__":
    n=int(input())
    G=[]
    for i in range(n):
        a=[]
        ele=list(map(int,input().split()))
        k=ele[1]
        t=ele[2:]
        v=c=[]
        for j in range(k):
            v=v+[t[2*j]]
            c=c+[t[2*j+1]]
        for j in range(n):
            if j in v:
                a.append(c[v.index(j)])
            else:
                a.append(-1)
        G.append(a)
    Dijkestra(G,n)

### FIXED CODE ###

#coding:utf-8
def Dijkestra(G,n):
    d=[100000000000]*n
    pi=[None]*n
    d[0]=0
    C=[]
    for i in range(n):
        C.append(i)
    
    while len(C)!=0:
        u=C[0]
        for i in range(1,len(C)):
            if d[u]>d[C[i]]:
                u=C[i]
        C.remove(u)
        for i in range(len(G[u])):
            if G[u][i]==-1:
                continue
            elif d[i]>d[u]+G[u][i]:
                d[i]=d[u]+G[u][i]
                pi[i]=u                
    for i in range(n):
        print(i,d[i])
    

if __name__=="__main__":
    n=int(input())
    G=[]
    for i in range(n):
        a=[]
        ele=list(map(int,input().split()))
        k=ele[1]
        t=ele[2:]
        v=c=[]
        for j in range(k):
            v=v+[t[2*j]]
            c=c+[t[2*j+1]]
        for j in range(n):
            if j in v:
                a.append(c[v.index(j)])
            else:
                a.append(-1)
        G.append(a)
    Dijkestra(G,n)