Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
v = ['x' for n in range(N)]
e = False
for m in range(M):
    s, c = [int(i) for i in input().split()]
    if e:
        continue
    if v[s-1] != 'x' and v[s-1]!=str(c):
        e = True
    else:
        v[s-1] = str(c)

if e:
    print(-1)
    exit()

r = []
f = False
fd = True
for d in v:
    if d == 'x':
        if f:
            if fd:
                r.append('1')
            else:
                r.append('0')
    else:
        f = True
        r.append(d)
    fd = False

rv = int("".join(r))

if len(str(rv))!=N:
    print(-1)
else:
    print("".join(r))

Fixed submission:
N, M = [int(i) for i in input().split()]
v = ['x' for n in range(N)]
e = False
for m in range(M):
    s, c = [int(i) for i in input().split()]
    if e:
        continue
    if v[s-1] != 'x' and v[s-1]!=str(c):
        e = True
    else:
        v[s-1] = str(c)

if e:
    print(-1)
    exit()

r = []
fd = N != 1
for d in v:
    if d == 'x':
        if fd:
            r.append('1')
        else:
            r.append('0')
    else:
        r.append(d)
    fd = False

rv = int("".join(r))

if len(str(rv))!=N:
    print(-1)
else:
    print("".join(r))
Buggy python submission (verdict: Runtime Error):
N, K = [int(i) for i in input().split()]
print(int(math.floor(math.log(float(N)/math.pow(K,2), K))) + 1 + 2)

Fixed submission:
import math

N, K = [int(i) for i in input().split()]
print(int(math.floor(math.log(float(N)/math.pow(K,2), K))) + 1 + 2)
Buggy python submission (verdict: Runtime Error):
x = input()
x = int(x)
y = input()
y = int(y)

if x < 10 and y < 10:
	print(x * y)
else:
	print(-1)



Fixed submission:
x, y = map(int, input().split())

if x < 10 and y < 10:
	print(x * y)
else:
	print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
cnt = 0;

for i in range(n):
  cnt += i

print(cnt)

Fixed submission:
n = int(input())
 
if(n % 2 == 0):
  print(int(n / 2) * (n - 1))
else:
  print(int((n-1) / 2) * n)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

M = 0
for i in range(k):
    M += (1 + p[i]) / 2

e = M
for i in range(n-k):
    e -= (1 + p[i]) / 2
    e += (1 + p[i+k]) / 2
    if e > M:
        M = e
print(f'{M:.12f}')


Fixed submission:
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

M = 0
for i in range(k):
    M += (1 + p[i]) / 2

e = M
for i in range(n-k):
    e -= (1 + p[i]) / 2
    e += (1 + p[i+k]) / 2
    if e > M:
        M = e
print('{:.12f}'.format(M))

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

M = 0
for i in range(k):
    M += (1 + p[i]) / 2

e = M
for i in range(n-k):
    e -= (1 + p[i]) / 2
    e += (1 + p[i+k]) / 2
    if e > M:
        M = e
print('{%.12f}'.format(M))

Fixed submission:
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

M = 0
for i in range(k):
    M += (1 + p[i]) / 2

e = M
for i in range(n-k):
    e -= (1 + p[i]) / 2
    e += (1 + p[i+k]) / 2
    if e > M:
        M = e
print('{:.12f}'.format(M))

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

M = 0
for i in range(k):
    M += (1 + p[i]) / 2

e = M
for i in range(n-k):
    e -= (1 + p[i]) / 2
    e += (1 + p[i+k]) / 2
    if e > M:
        M = e
print(f'{M:.12f}')

Fixed submission:
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

M = 0
for i in range(k):
    M += (1 + p[i]) / 2

e = M
for i in range(n-k):
    e -= (1 + p[i]) / 2
    e += (1 + p[i+k]) / 2
    if e > M:
        M = e
print('{:.12f}'.format(M))

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

M = 0
for i in range(k):
    M += 1 + p[i] / 2

e = M
for i in range(n-k-1):
    e -= 1 + p[i] / 2
    e += 1 + p[i+k+1] / 2
    if e > M:
        M = e
print(f'{M:%.12f}')

Fixed submission:
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

M = 0
for i in range(k):
    M += (1 + p[i]) / 2

e = M
for i in range(n-k):
    e -= (1 + p[i]) / 2
    e += (1 + p[i+k]) / 2
    if e > M:
        M = e
print('{:.12f}'.format(M))
Buggy python submission (verdict: Runtime Error):
S = input()
m = 1
num = 1
for c in S:
  if c == '<':
    num += 1
  elif c == '>':
    num -= 1
  m = min(num, m)
if m <= 0:
  num += 1 - m
else:
  num = 1
ans += num
for c in S:
  if c == '<':
    num += 1
  elif c == '>':
    num -= 1
  ans += num
print(ans)

Fixed submission:
S = input()
INC = '<'
DEC = '>'
icnt = 0
dcnt = 0
mode = DEC
ans = 0
for c in S:
  if mode == DEC:
    if c == DEC:
      dcnt += 1
    elif c == INC:
      if icnt <= dcnt:
        ans += (dcnt + 1) * dcnt // 2
      else:
        ans += icnt + dcnt * (dcnt - 1) // 2
      icnt = 1
      mode = INC
  elif mode == INC:
    if c == INC:
      icnt += 1
    elif c == DEC:
      ans += icnt * (icnt - 1) // 2
      dcnt = 1
      mode = DEC
if mode == INC:
  ans += (icnt + 1) * icnt // 2
elif mode == DEC:
  if icnt <= dcnt:
    ans += (dcnt + 1) * dcnt // 2
  else:
    ans += icnt + dcnt * (dcnt - 1) // 2
print(ans)
Buggy python submission (verdict: Runtime Error):
s = int(input())

def calc_next(x):
  if x % 2 == 0:
    return x // 2
  else:
    return 3 * x + 1

a = [s]
n = 1

while True:
  a.append(calc_next(a[n-1]))
  for i in range(n):
    if a[k] == a[n]:
      print(n+1)
      exit(0)
  n += 1

Fixed submission:
s = int(input())

def calc_next(x):
  if x % 2 == 0:
    return x // 2
  else:
    return 3 * x + 1

a = [s]
n = 1

while True:
  a.append(calc_next(a[n-1]))
  for i in range(n):
    if a[i] == a[n]:
      print(n+1)
      exit(0)
  n += 1
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
h = list(map(int, input().split()))

ans = 0
given_water = False
while True:
  is_continuous = False
  for i in range(N):
    if h[i] > 0:
      if is_continuous is False:
        ans += 1
        is_continuous = True
      h[i] -= 1
      given_water = True
    else: # h[i] == 0
      is_continuous = False
  if given_water is False:
    break
      
print(ans)

Fixed submission:
N = int(input())
h = list(map(int, input().split()))

ans = 0

while True:
  given_water = False
  is_continuous = False
  for i in range(N):
    if h[i] > 0:
      if is_continuous is False:
        ans += 1
        is_continuous = True
      h[i] -= 1
      given_water = True
    else: # h[i] == 0
      is_continuous = False
  if given_water is False:
    break
      
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input.split()))

MAX_COST = 1001001001

cost_dp = [MAX_COST for _ in range(N)]

cost_dp[0] = 0

for i in range(N):
  if i == 1:
    cost_dp[1] = cost_dp[0] + abs(h[1] - h[0])
  else:
    cost_dp[i] = min(cost_dp[i-1] + abs(h[i] - h[i-1]), cost_dp[i-2] + abs(h[i] - h[i-2]))

print(cost_dp[N-1])

Fixed submission:
N = int(input())
h = list(map(int, input().split()))

MAX_COST = 1001001001

cost_dp = [MAX_COST for _ in range(N)]

cost_dp[0] = 0

for i in range(N):
  if i == 0:
    continue
  elif i == 1:
    cost_dp[1] = cost_dp[0] + abs(h[1] - h[0])
  else:
    cost_dp[i] = min(cost_dp[i-1] + abs(h[i] - h[i-1]), cost_dp[i-2] + abs(h[i] - h[i-2]))

print(cost_dp[N-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n == 3 or n == 5 or n == 7:
  print(YES)
else:
  print(NO)

Fixed submission:
n = int(input())
if n == 3 or n == 5 or n == 7:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
n, m, d = map(int, input().split())
p = 1/n if d==0 else p = 2*(n-d)/n/n
ans = (m-1)*p
print(ans)

Fixed submission:
n, m, d = map(int, input().split())
p = 1/n if d==0 else 2*(n-d)/n/n
ans = (m-1)*p
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

ans = N
for A in range(1,N):
    B = N - A
    A_str = str(A)
    B_str = str(B)
    A_li = [int(A_str[i]) for i in len(A_str)]
    B_li = [int(B_str[i]) for i in len(B_str)]
    s = sum(A_li) + sum(B_li)
    if s < ans:
        ans = s

print(ans)

Fixed submission:
N = int(input())

ans = N
for A in range(1,N):
    B = N - A
    A_str = str(A)
    B_str = str(B)
    A_li = [int(A_str[i]) for i in range(len(A_str))]
    B_li = [int(B_str[i]) for i in range(len(B_str))]
    s = sum(A_li) + sum(B_li)
    if s < ans:
        ans = s

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())

if abs(c-a) <= d:
  print "Yes"
  exit(0)
elif abs(a-b) <= d and abs(c-b) <= d:
  print "Yes"
  exit(0)
else:
  print "No"
  exit(0)

exit(0)

Fixed submission:
a, b, c, d = map(int, input().split())

if abs(c-a) <= d:
  print("Yes")
  exit(0)
elif abs(a-b) <= d and abs(c-b) <= d:
  print("Yes")
  exit(0)
else:
  print("No")
  exit(0)

exit(0)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# from numpy import array, sum

MAX_DIVIDER = 32 # 32 ** 2 = 1024 > 1000

X =int(input())

li = set()

b = 1
while b < MAX_DIVIDER:
	c = b * b
	while c < 1000:
		li.add(c)
		c *= b
	b += 1

while X > 0:
	if X in li:
		print(X)
		break
	else:
		X -= 1

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# from numpy import array, sum

MAX_DIVIDER = 32 # 32 ** 2 = 1024 > 1000

X =int(input())

li = set()

li.add(1)

b = 2
while b < MAX_DIVIDER:
	c = b * b
	while c <= 1000:
		li.add(c)
		c *= b
	b += 1

while X > 0:
	if X in li:
		print(X)
		break
	else:
		X -= 1

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# from numpy import array, sum

MAX_DIVIDER = 32 # 32 ** 2 = 1024 > 1000

X =int(input())

li = set()

b = 1
while b < MAX_DIVIDER:
	c = b * b
	while c < 1000:
		li.add(c)
		c *= b

while X > 0:
	if X in li:
		print(X)
		break
	else:
		X -= 1

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# from numpy import array, sum

MAX_DIVIDER = 32 # 32 ** 2 = 1024 > 1000

X =int(input())

li = set()

li.add(1)

b = 2
while b < MAX_DIVIDER:
	c = b * b
	while c <= 1000:
		li.add(c)
		c *= b
	b += 1

while X > 0:
	if X in li:
		print(X)
		break
	else:
		X -= 1
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
cnt = 0
for n in range(A,B+1):
  n_str = str(n)
  n_len = len(n)
  is_kaibun = True
  for i in range(n_len//2):
    if n_str[i] != n_str[n_len-1-i]:
      is_kaibun = False
  if is_kaibun is True:
    cnt += 1
print(cnt)

# if n_str[0] == n_str[4] and n_str[1] == n_str[3]:
#   cnt += 1

Fixed submission:
A, B = map(int, input().split())
cnt = 0
for n in range(A,B+1):
  n_str = str(n)
  n_len = len(n_str)
  is_kaibun = True
  for i in range(n_len//2):
    if n_str[i] != n_str[n_len-1-i]:
      is_kaibun = False
  if is_kaibun is True:
    cnt += 1
print(cnt)

# if n_str[0] == n_str[4] and n_str[1] == n_str[3]:
#   cnt += 1
Buggy python submission (verdict: Runtime Error):
C = []
C.append([int(i) for i in input().split()])

D_h = [[C[idx][jdx+1]-C[idx][jdx] for idx in range(2)] for jdx in range(2)]
D_v = [[C[idx+1][jdx]-C[idx][jdx] for idx in range(2)] for jdx in range(2)]

for idx in range(2):
	if D_h[0][idx] != D_h[1][idx]:
		print("No")
	elif D_h[0][idx] != D_h[2][idx]:
		print("No")

for idx in range(2):
	if D_v[0][idx] != D_v[1][idx]:
		print("No")
	elif D_v[0][idx] != D_v[2][idx]:
		print("No")

Fixed submission:
C = []
for i in range(3):
	C.append([int(i) for i in input().split()])

D_h = [[C[idx][jdx+1]-C[idx][jdx] for idx in range(3)] for jdx in range(2)]
D_v = [[C[idx+1][jdx]-C[idx][jdx] for idx in range(2)] for jdx in range(3)]

for idx in range(2):
	if D_h[idx][0] != D_h[idx][1]:
		print("No")
		exit(0)
	elif D_h[idx][0] != D_h[idx][2]:
		print("No")
		exit(0)

for idx in range(2):
	if D_v[0][idx] != D_v[1][idx]:
		print("No")
		exit(0)
	elif D_v[0][idx] != D_v[2][idx]:
		print("No")
		exit(0)

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import math

Q = int(input())
li = []
M = 0
for index in range(Q):
	l, r = map(int, input().split())
	li.append((l, r))
	M = max([M, l, r])

primes = list(range(M+1))
primes[0] = 0
primes[1] = 0
cut_root = math.sqrt(M+1)
for prime in primes:
	if prime > cut_root:
		break
	if prime == 0:
		continue
	for non_prime in range(2 * prime, M, prime):
		primes[non_prime] = 0
similar_2017 = [0 for _ in range(M+1)]
similar_2017[3] = 1
for i in range(5, M+1, 4):
	if primes[i] != 0:
		if primes[(i+1)//2] != 0:
			similar_2017[i] = 1

for l, r in li:
	print(sum(similar_2017[l:r+1]))

Fixed submission:
import math

Q = int(input())
li = []
M = 0
for index in range(Q):
	l, r = map(int, input().split())
	li.append((l, r))
	M = max([M, l, r])

primes = list(range(M+1))
primes[0] = 0
primes[1] = 0
cut_root = math.sqrt(M+1)
for prime in primes:
	if prime > cut_root:
		break
	if prime == 0:
		continue
	for non_prime in range(2 * prime, M, prime):
		primes[non_prime] = 0
similar_2017 = [0 for _ in range(M+1)]
similar_2017[3] = 1
for i in range(5, M+1, 4):
	if primes[i] != 0:
		if primes[(i+1)//2] != 0:
			similar_2017[i] = 1
similar_sum = [0 for _ in range(M+1)]
for i in range(1,M+1):
	if similar_2017[i] == 1:
		similar_sum[i] = similar_sum[i-1] + 1
	else:
		similar_sum[i] = similar_sum[i-1]

for l, r in li:
	print(similar_sum[r] - similar_sum[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math

Q = int(input())
li = []
M = 0
for index in range(Q):
	l, r = map(int, input().split())
	li.append((l, r))
	M = max([M, l, r])

primes = list(range(M+1))
primes[0] = 0
primes[1] = 0
for prime in primes:
	if prime > math.sqrt(M):
		break
	if prime == 0:
		continue
	for non_prime in range(2 * prime, M, prime):
		primes[non_prime] = 0

for l, r in li:
	count = 0
	for i in range(l,r+1,2):
		if primes[i] != 0 and primes[(i+1)//2] != 0:
			count += 1
	print(count)

Fixed submission:
import math

Q = int(input())
li = []
M = 0
for index in range(Q):
	l, r = map(int, input().split())
	li.append((l, r))
	M = max([M, l, r])

primes = list(range(M+1))
primes[0] = 0
primes[1] = 0
cut_root = math.sqrt(M+1)
for prime in primes:
	if prime > cut_root:
		break
	if prime == 0:
		continue
	for non_prime in range(2 * prime, M, prime):
		primes[non_prime] = 0
similar_2017 = [0 for _ in range(M+1)]
similar_2017[3] = 1
for i in range(5, M+1, 4):
	if primes[i] != 0:
		if primes[(i+1)//2] != 0:
			similar_2017[i] = 1
similar_sum = [0 for _ in range(M+1)]
for i in range(1,M+1):
	if similar_2017[i] == 1:
		similar_sum[i] = similar_sum[i-1] + 1
	else:
		similar_sum[i] = similar_sum[i-1]

for l, r in li:
	print(similar_sum[r] - similar_sum[l-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(a) for a in input().split()]
cnt = 0
while True:
  for i in range(N):
    if A[i] % 2 == 1:
      print(cnt)
      exit(0)
    else:
      A[i] = A[i] // 2
  cnt++

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
cnt = 0
while True:
  for i in range(N):
    if A[i] % 2 == 1:
      print(cnt)
      exit(0)
    else:
      A[i] = A[i] // 2
  cnt += 1

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(a) for a in input().split()]
cnt = 0
while True:
  for i in range(N):
    if A[i] % 2 == 1:
      print cnt
      exit(0)
    else:
      A[i] = A[i] // 2
  cnt++

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
cnt = 0
while True:
  for i in range(N):
    if A[i] % 2 == 1:
      print(cnt)
      exit(0)
    else:
      A[i] = A[i] // 2
  cnt += 1
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [input() for _ in range(H)]
pos = {x:0, y:0}
cnt = 0
for i in range(H):
  cnt += A[i].count('#')

if cnt == (H + W -1):
  print("Possible")
else:
  print("Impossible")

Fixed submission:
H, W = map(int, input().split())
A = [input() for _ in range(H)]
cnt = 0
for i in range(H):
  cnt += A[i].count('#')

if cnt == (H + W -1):
  print("Possible")
else:
  print("Impossible")

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [input() for _ in range(H)]
pos = {x:0, y:0}
cnt = 0
for i in range(H):
  cnt += A[i].count('#')

if cnt == (H + W -1):
  print("Possible")
else:
  print("Impossible")

Fixed submission:
H, W = map(int, input().split())
A = [input() for _ in range(H)]
cnt = 0
for i in range(H):
  cnt += A[i].count('#')

if cnt == (H + W -1):
  print("Possible")
else:
  print("Impossible")
Buggy python submission (verdict: Time Limit Exceeded):
A, V = [int(n) for n in input().split()]
B, W = [int(n) for n in input().split()]
T = int(input())

if V <= W:
    print('NO')
    exit()


va = [A + V * t for t in range(1, T+1)]
va.extend([A - V * t for t in range(1, T+1)])
vb = [B + W * t for t in range(1, T+1)]
vb.extend([B - W * t for t in range(1, T+1)])

for a in va:
    for b in vb:
        if a == b:
            print('YES')
            exit()
print('NO')


Fixed submission:
A, V = [int(n) for n in input().split()]
B, W = [int(n) for n in input().split()]
T = int(input())

if V <= W:
    print('NO')
    exit()

d = abs(A - B)

if V > W and d <= (V - W) * T:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
A, B = [int(n) for n in input().split()]

ans = int(A * B)
print(ans)


Fixed submission:
from decimal import Decimal
A, B = [n for n in input().split()]
A = int(A)
B = Decimal(B)

ans = A * B
print(int(ans))
Buggy python submission (verdict: Runtime Error):
import math

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

count = 0
for i in range(n):
  x, y = map(int, input().split())
  if math.sqrt(x^2 + y^2) <= dis:
    count += 1
  
print("{}".format(count))

Fixed submission:
import numpy as np

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

count = 0
for i in range(n):
  x, y = map(int, input().split())
  res = np.sqrt(x**2 + y**2)
  if res <= dis:
    count += 1
  
print("{}".format(count))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

if __name__ == '__main__':

	n = int(input())
	A = list(map(int,input().split()))

	total = 0
	C = list(itertools.combinations(A, 2))
	B = [v[0]*v[1] for v in C]
	print(sum(B)%(10**9+7))


Fixed submission:
if __name__ == '__main__':

    n = int(input())
    A = list(map(int,input().split()))

    #全体
    sm = sum(A) ** 2
    #共通部分
    com = sum([i * i for i in A])

    ans = (sm - com) // 2
    print(ans%(10**9+7))
Buggy python submission (verdict: Runtime Error):
import bisect as bi

if __name__ == '__main__':

	x,n = map(int,input().split())
	A = list(map(int,input().split()))
	B = [i for i in range(101)]
	
	#差分を求める
	C = list(set(B) - set(A))

	#二分探索自身の位置を調べる
	ind = bi.bisect_left(C,x)

	if ind == 0:
		print(C[0])
	elif ind == x - n:
		print(C[ind])
	elif x == C[ind]:
		print(0)
	else:
		tmp_l = abs(C[ind-1] - x)
		tmp_r = abs(C[ind] - x)
		if tmp_l > tmp_r:
			print(C[ind])
		else:
			print(C[ind-1])



Fixed submission:
import bisect as bi

if __name__ == '__main__':

    x,n = map(int,input().split())
    A = list(map(int,input().split()))
    B = [i for i in range(102)]
    
    #差分を求める
    C = list(set(B) - set(A))

    #二分探索自身の位置を調べる
    ind = bi.bisect_left(C,x)

    if ind == 0:
        print(C[0])
    elif ind == x - n:
        print(C[ind])
    else:
        tmp_l = abs(C[ind-1] - x)
        tmp_r = abs(C[ind] - x)
        if tmp_l > tmp_r:
            print(C[ind])
        else:
            print(C[ind-1])

Buggy python submission (verdict: Runtime Error):
import bisect as bi

if __name__ == '__main__':

	x,n = map(int,input().split())
	A = list(map(int,input().split()))
	B = [i for i in range(101)]
	
	#差分を求める
	C = list(set(B) - set(A))
	
	#二分探索自身の位置を調べる
	ind = bi.bisect_left(C,x)

	if ind == 0:
		print(C[0])
	elif ind == x - n:
		print(C[ind])
	else:
		tmp_l = abs(C[ind-1] - x)
		tmp_r = abs(C[ind] - x)
		if tmp_l > tmp_r:
			print(C[ind])
		else:
			print(C[ind-1])



Fixed submission:
import bisect as bi

if __name__ == '__main__':

    x,n = map(int,input().split())
    A = list(map(int,input().split()))
    B = [i for i in range(102)]
    
    #差分を求める
    C = list(set(B) - set(A))

    #二分探索自身の位置を調べる
    ind = bi.bisect_left(C,x)

    if ind == 0:
        print(C[0])
    elif ind == x - n:
        print(C[ind])
    else:
        tmp_l = abs(C[ind-1] - x)
        tmp_r = abs(C[ind] - x)
        if tmp_l > tmp_r:
            print(C[ind])
        else:
            print(C[ind-1])
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':

	INF = 10**18
	
	n = int(input())
	A = list(map(int,input().split()))

	ans = 1
	flg = False

	for i in range(n):
		if A[i] == 0:
			ans = 0
			break
		ans = ans * A[i]

	if ans > INF:
		print(-1)
	else:
		print(ans)


Fixed submission:
if __name__ == '__main__':

	INF = 10**18
	
	n = int(input())
	A = list(map(int,input().split()))

	if 0 in A:
		print(0)
		exit()

	ans = 1
	flg = False

	for i in range(n):
		ans = ans * A[i]
		if ans > INF:
			ans = -1
			break

	print(ans)
Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':

    n,k = map(int,input().split())
    A = [0]
    AA= list(map(int,input().split()))
    A = A + AA

    B = set()
    cnt = 0
    ind = 1
    startind = 0
    D = []
    while True:
        if A[ind] not in B:
            B.add(ind)
            D.append(ind)
            cnt += 1
            ind = A[ind]
        else:
            B.add(ind)
            D.append(ind)
            cnt += 1
            startind = A[ind]
            break

    C = set()
    ind = startind
    ANS = []
    while True:
        if A[ind] not in C:
            C.add(ind)
            ind = A[ind]
            ANS.append(ind)
        else:
            C.add(ind)
            ANS.append(A[ind])
            break

    if k > cnt:
        tmp = k - cnt
        tmp = tmp % (len(C))
        print(ANS[tmp-1])
    else:
        print(D[k])
    

Fixed submission:
if __name__ == '__main__':

    n,k = map(int,input().split())
    A = [0]
    AA= list(map(int,input().split()))
    A = A + AA

    B = set()
    cnt = 0
    ind = 1
    startind = 0
    D = []
    while True:
        if A[ind] not in B:
            B.add(ind)
            D.append(ind)
            cnt += 1
            ind = A[ind]
        else:
            B.add(ind)
            D.append(ind)
            cnt += 1
            startind = A[ind]
            break

    C = set()
    ind = startind
    ANS = []
    while True:
        if A[ind] not in C:
            C.add(ind)
            ind = A[ind]
            ANS.append(ind)
        else:
            C.add(ind)
            ANS.append(A[ind])
            break

    if k >= cnt:
        tmp = k - cnt
        tmp = tmp % (len(C))
        print(ANS[tmp-1])
    else:
        print(D[k])
Buggy python submission (verdict: Runtime Error):

if __name__ == '__main__':

    n = int(input())
    A = list(map(int,input().split()))

    #全体の数
    d = Counter(A)
    
    d2 = dict()
    #この時の組み合わせの合計
    for k,v in d.items():
        d2[k] = (v*(v-1)) // 2
    ans_sum = sum(d2.values())

    #結果表示
    for i in A:
        ans = 0
        if i in d2:
            #あるならば
            tmp = d[i] - 1
            before= d2[i]
            after = (tmp*(tmp-1)) //2
            ans = ans_sum - (before-after)
            print(ans)
        else:
            #ないならば
            print(ans_sum)


Fixed submission:
from collections import Counter

if __name__ == '__main__':

    n = int(input())
    A = list(map(int,input().split()))

    #全体の数
    d = Counter(A)
    
    d2 = dict()
    #この時の組み合わせの合計
    for k,v in d.items():
        d2[k] = (v*(v-1)) // 2
    ans_sum = sum(d2.values())

    #結果表示
    for i in A:
        ans = 0
        if i in d2:
            #あるならば
            tmp = d[i] - 1
            before= d2[i]
            after = (tmp*(tmp-1)) //2
            ans = ans_sum - (before-after)
            print(ans)
        else:
            #ないならば
            print(ans_sum)