Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, X, M = map(int, input().split())
ind = 0
l = [X]
while True:
  t = l[-1] ** 2 % M
  if t not in l:
    l.append(t)
  else:
    ind = l.index(t)
    break
S = sum(l[ind:])
L = len(l)
ans = 0
if N <= L:
  ans = sum(l[:N])
else:
  ans = sum(l)
  N -= L
  ans += S * (N // (L - ind))
  ans += sum(l[ind:ind+(N % (L - ind))])
print(ans)

Fixed submission:
N, X, M = map(int, input().split())
checklist = [True] * 100000
ind = 0
l = [X]
while True:
  t = l[-1] ** 2 % M
  if checklist[t]:
    l.append(t)
    checklist[t] = False
  else:
    ind = l.index(t)
    break
S = sum(l[ind:])
L = len(l)
ans = 0
if N <= L:
  ans = sum(l[:N])
else:
  ans = sum(l)
  N -= L
  ans += S * (N // (L - ind))
  ans += sum(l[ind:ind+(N % (L - ind))])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
ans = 0
room = [l[0]]
for i in range(1, N):
    ans += room.pop(0)
    room.append(l[i])
    room.append(l[i])
print(ans)

Fixed submission:
import queue

N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
ans = 0
room = queue.Queue()
room.put(l[0])
for i in range(1, N):
    ans += room.get()
    room.put(l[i])
    room.put(l[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
timeA, timeB = 0, 0
numA, numB = 0, 0
for i in range(N):
    if timeA + A[i] <= K:
        numA += 1
        timeA += A[i]
    else:
        break
for i in range(M):
    if timeB + B[i] <= K - timeA:
        numB += 1
        timeB += B[i]
    else:
        break
ans = numA + numB
t = numA
j = numB
for i in reversed(range(numA)):
    t -= 1
    timeA -= A[i]
    while j < M:
        if timeB + B[j] <= K - timeA:
            numB += 1
            timeB += B[i]
            j += 1
        else:
            break
    ans = max(ans, t + numB)
print(ans)

Fixed submission:
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
timeA, timeB = 0, 0
numA, numB = 0, 0
for i in range(N):
    if timeA + A[i] <= K:
        numA += 1
        timeA += A[i]
    else:
        break
for i in range(M):
    if timeB + B[i] <= K - timeA:
        numB += 1
        timeB += B[i]
    else:
        break
ans = numA + numB
t = numA
for i in reversed(range(numA)):
    t -= 1
    timeA -= A[i]
    while numB < M:
        if timeB + B[numB] <= K - timeA:
            timeB += B[numB]
            numB += 1
        else:
            break
    ans = max(ans, t + numB)
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
timeA, timeB = 0, 0
numA, numB = 0, 0
for i in range(N):
    if timeA + A[i] <= K:
        numA += 1
        timeA += A[i]
    else:
        break
for i in range(M):
    if timeB + B[i] <= K - timeA:
        numB += 1
        timeB += B[i]
    else:
        break
ans = numA + numB
t = numA
j = numB
for i in reversed(range(numA)):
    t -= 1
    timeA -= A[i]
    while j < M:
        if timeB + B[j] <= K - timeA:
            numB += 1
            timeB += B[i]
        else:
            break
    ans = max(ans, t + numB)
print(ans)

Fixed submission:
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
timeA, timeB = 0, 0
numA, numB = 0, 0
for i in range(N):
    if timeA + A[i] <= K:
        numA += 1
        timeA += A[i]
    else:
        break
for i in range(M):
    if timeB + B[i] <= K - timeA:
        numB += 1
        timeB += B[i]
    else:
        break
ans = numA + numB
t = numA
for i in reversed(range(numA)):
    t -= 1
    timeA -= A[i]
    while numB < M:
        if timeB + B[numB] <= K - timeA:
            timeB += B[numB]
            numB += 1
        else:
            break
    ans = max(ans, t + numB)
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import ceil

X, N = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l2 = [abs(int(x)-X) for x in l]
l2.sort()
for i in range(N):
    if ceil(i/2) != l2[i]:
        t = ceil(i/2)
        break
if X - t in l:
    print(X + t)
else:
    print(X - t)

Fixed submission:
X, N = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
if len(l) == 0:
    print(X)
elif X not in l:
    print(X)
else:
    for i in range(1, 1000):
        if X - i not in l:
            print(X - i)
            break
        elif X + i not in l:
            print(X + i)
            break
Buggy python submission (verdict: Runtime Error):
from math import ceil

X, N = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l2 = [abs(int(x)-X) for x in l]
l2.sort()
for i in range(N):
    if ceil(i/2) != l2[i]:
        t = ceil(i/2)
        break
if X - t in l:
    print(X + t)
else:
    print(X - t)

Fixed submission:
N = int(input())
l = [int(x) for x in input().split()] + [1000001]
l.sort()
ans = 0
t = 0
M = [False] * 10 ** 6
for i in range(N):
    if not M[l[i]-1]:
        if l[i] != l[i+1]:
            ans += 1
        t = l[i]
        while t <= 10 ** 6:
            M[t-1] = True
            t += l[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = [int(x) for x in input().split()]
ans = 1
for i in range(N):
  ans *= l[i]
if ans > pow(10, 18):
  print(-1)
else:
  print(ans)

Fixed submission:
import sys

N = int(input())
l = [int(x) for x in input().split()]
if 0 in l:
  print(0)
  sys.exit()
ans = 1
for i in range(N):
  if ans > pow(10, 18):
    ans = -1
    break
  else:
    ans *= l[i]
if ans > pow(10, 18):
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(x) for x in input().split()]
path = []
for i in range(M):
  t1, t2 = [int(x) for x in input().split()]
  path.append((t1, t2))
l = [1]
ans = [1] + [0] * (N-1)
while True:
  t = l.pop(0)
  for i in reversed(range(len(path))):
    if t in path[i]:
      if path[i][0] == t:
        if ans[path[i][1]-1] == 0:
          ans[path[i][1]-1] = t
          l.append(path[i][1])
      else:
        if ans[path[i][0]-1] == 0:
          ans[path[i][0]-1] = t
          l.append(path[i][0])
      path.pop(i)
  if path == []:
    break
print('Yes')
for i in range(1,N):
  print(ans[i])

Fixed submission:
N, M = [int(x) for x in input().split()]
path = []
for i in range(N):
  path.append([])
for i in range(M):
  t1, t2 = [int(x) for x in input().split()]
  path[t1-1].append((t1,t2))
  path[t2-1].append((t2,t1))
l = [1]
ans = [1] + [0] * (N-1)
while len(l) > 0:
  t = l.pop(0)
  for i in range(len(path[t-1])):
    if ans[path[t-1][i][1]-1] == 0:
      ans[path[t-1][i][1]-1] = t
      l.append(path[t-1][i][1])
print('Yes')
for i in range(1, N):
  print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(x) for x in input().split()]
dest = [int(x) for x in input().split()]
route = [1]
t = 1
while True:
  if dest[t-1] not in route:
    route.append(dest[t-1])
    t = dest[t-1]
  else:
    loop = route.index(dest[t-1])
    L_loop = len(route) - loop
    break
ans = 0
if K < len(route):
  ans = route[K]
else:
  K = K - len(route)
  ans = route[loop + (K % L_loop)]
print(ans)

Fixed submission:
N, K = [int(x) for x in input().split()]
dest = [int(x) for x in input().split()]
route = [1]
flag = [1] + [0] * (N-1)
t = 1
while True:
  if flag[dest[t-1]-1] == 0:
    t = dest[t-1]
    route.append(t)
    flag[t-1] = 1
  else:
    loop = route.index(dest[t-1])
    L_loop = len(route) - loop
    break
  #print(route)
  #print(flag)
ans = 0
if K < len(route):
  ans = route[K]
else:
  K = K - len(route)
  ans = route[loop + (K % L_loop)]
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
if S = "ABC":
  print("ARC")
else:
  print("ABC")

Fixed submission:
S = input()
if S == "ABC":
  print("ARC")
else:
  print("ABC")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = r * g * b
for i in range(N-2):
    for j in range(i+1, N-1):
        if(S[i] != S[j] and 2 * j - i < N):
            if(S[i] != S[2 * j - i] and S[j] != S[2 * j - i]):
                ans -= 1
print(ans)

Fixed submission:
N = int(input())
S = input()
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = r * g * b
for i in range(N-2):
    t = 1
    while i + 2 * t < N:
        if(S[i] != S[i+t] and S[i] != S[i+2*t] and S[i+t] != S[i+2*t]):
            ans -= 1
        t += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

def Comb(n, r):
  return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

N = input()
K = int(input())
ans = 0
for i in range(1, len(N)):
  if i < K:
    pass
  else:
    ans += 9 ** K * Comb(i-1, K-1)
ans += (int(N[0])-1) * Comb(len(N)-1, K-1) * 9 ** (K-1)
if K == 1:
  ans += 1
elif K == 2:
  for i in range(1, len(N)):
    if N[i] != '0':
      ans += int(N[i]) + 9 * (len(N) - i - 1)
      break
else:
  for i in range(1, len(N)):
    if N[i] != '0':
      if len(N) - i - 1 >= 2:
        ans += Comb(len(N) - i - 1, 2) * 9 ** 2
      if len(N) - i - 1 >= 1:
        ans += (int(N[i]) - 1) * 9 * (len(N) - i - 1)
      for j in range(i+1, len(N)):
        if N[j] != '0':
          ans += int(N[j]) + 9 * (len(N) - j - 1)
          break
      break
print(ans)


Fixed submission:
import math

def Comb(n, r):
  if n < r:
    return 0
  else:
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

N = input()
K = int(input())
ans = 0
for i in range(1, len(N)):
  if i < K:
    pass
  else:
    ans += 9 ** K * Comb(i-1, K-1)
ans += (int(N[0])-1) * Comb(len(N)-1, K-1) * 9 ** (K-1)
if K == 1:
  ans += 1
elif K == 2:
  for i in range(1, len(N)):
    if N[i] != '0':
      ans += int(N[i]) + 9 * (len(N) - i - 1)
      break
else:
  for i in range(1, len(N)):
    if N[i] != '0':
      if len(N) - i - 1 >= 2:
        ans += Comb(len(N) - i - 1, 2) * 9 ** 2
      if len(N) - i - 1 >= 1:
        ans += (int(N[i]) - 1) * 9 * (len(N) - i - 1)
      for j in range(i+1, len(N)):
        if N[j] != '0':
          ans += int(N[j]) + 9 * (len(N) - j - 1)
          break
      break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions as fc

A, B = [int(x) for x in input().split()]
C = fc.gcd(A, B)
b = 2
ans =  1
while 1:
  if C % b == 0:
    ans += 1
    while C % b == 0:
      C //= b
  if C == 1:
    break
  b += 1
print(ans)

Fixed submission:
import fractions as fc

A, B = [int(x) for x in input().split()]
C = fc.gcd(A, B)
b = 2
ans =  1
while b * b <= C:
  if C % b == 0:
    ans += 1
    while C % b == 0:
      C //= b
  if C == 1:
    break
  b += 1
if C > 1:
  ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
for i in range(M):
  A.sort()
  A[N-1] = A[N-1] // 2
print(np.sum(A))

Fixed submission:
import heapq

N, M  = [int(x) for x in input().split()]
l = [-int(x) for x in input().split()]
heapq.heapify(l)
for i in range(M):
  h = heapq.heappop(l)
  h = -h // 2
  heapq.heappush(l, -h)
print(-sum(l))
Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())
if L + (673 - L % 673) <= R or L % 673 == 0:
  if L + (3 - L % 3) <= R or L % 3 == 0:
    print(0)
    sys.exit()
ans = 2019
a = L % 2019
b = R % 2019
for i in range(a, b):
  for j in range(i+1, b+1):
    ans = min(ans, i * j % 2019)
print(ans)

Fixed submission:
import sys

L, R = map(int, input().split())
if L + (673 - L % 673) <= R or L % 673 == 0:
  if L + (3 - L % 3) <= R or L % 3 == 0:
    print(0)
    sys.exit()
ans = 2019
a = L % 2019
b = R % 2019
for i in range(a, b):
  for j in range(i+1, b+1):
    ans = min(ans, i * j % 2019)
print(ans)

Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())
a = L % 2019
if a == 0:
  print(0)
else:
  if L + (673 - L % 673) <= R or L % 673 == 0:
    if L + (3 - L % 3) <= R or L % 3 == 0:
      print(0)
      sys.exit()
  ans = 2019
  b = R % 2019
  for i in range(a, b):
    for j in range(i+1, b+1):
      ans = min(ans, i * j % 2019)
  print(ans)

Fixed submission:
import sys

L, R = map(int, input().split())
if L + (673 - L % 673) <= R or L % 673 == 0:
  if L + (3 - L % 3) <= R or L % 3 == 0:
    print(0)
    sys.exit()
ans = 2019
a = L % 2019
b = R % 2019
for i in range(a, b):
  for j in range(i+1, b+1):
    ans = min(ans, i * j % 2019)
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
if s[0] == s[1] or s[1] == s[2] 0r s[2] == s[3]:
  print('Bad')
else:
  print('Good')

Fixed submission:
s = input()
if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
  print('Bad')
else:
  print('Good')
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
m = 0
if M > 0:
  broken = int(input())
else:
  broken = 0
a1, a2, a3 = 1, 0, 0
for i in range(1, N+1):
  a3, a2 = a2, a1
  if i == broken:
    a1 = 0
    m += 1
    if m < M:
      broken = int(input())
  else:
    a1 = (a2 + a3) % 1000000007
print(a1)

Fixed submission:
l = sorted([int(x) for x in input().split()])
print(l[0]+l[1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
broken = []
for i in range(M):
  broken.append(int(input()))
a1, a2, a3 = 1, 0, 0
for i in range(1, N+1):
  a3 = a2
  a2 = a1
  if i in broken:
    a1 = 0
  else:
    a1 = (a2 + a3) % 1000000007
print(a1)

Fixed submission:
N, M = map(int, input().split())
m = 0
if M > 0:
  broken = int(input())
else:
  broken = 0
a1, a2, a3 = 1, 0, 0
for i in range(1, N+1):
  a3, a2 = a2, a1
  if i == broken:
    a1 = 0
    m += 1
    if m < M:
      broken = int(input())
  else:
    a1 = (a2 + a3) % 1000000007
print(a1)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
print(N-k+1)

Fixed submission:
n, k = map(int, input().split())
print(n - k + 1)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
 
n = int(input())
l = np.array([int(x) for x in input().split()])
ans = 0
if 0 in l:
  for i in range(n):
    ans += abs(l[i])
  print(ans)
  sys.exit()
m = abs(l[0])
for i in range(n):
  if l[i] < 0:
    p += 1
  if m < abs(l[i]):
    m = abs(l[i])
for i in range(n):
  ans += abs(l[i])
if p % 2 == 0:
  print(ans)
else:
  print(ans - m*2)

Fixed submission:
import numpy as np
import sys
 
n = int(input())
l = np.array([int(x) for x in input().split()])
ans = 0
if 0 in l:
  for i in range(n):
    ans += abs(l[i])
  print(ans)
  sys.exit()
m = abs(l[0])
p = 0
for i in range(n):
  if l[i] < 0:
    p += 1
  if m > abs(l[i]):
    m = abs(l[i])
for i in range(n):
  ans += abs(l[i])
if p % 2 == 0:
  print(ans)
else:
  print(ans - m*2)

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())
l = np.array([int(x) for x in input().split()])
ans = 0
if 0 in l:
  for i in range(n):
    ans += abs(l[i])
  sys.exit()
m = abs(l[0])
for i in range(n):
  if l[i] < 0:
    p += 1
  if m < abs(l[i])
for i in range(n):
  ans += abs(l[i])
if p % 2 == 0:
  print(ans)
else:
  print(ans - m*2)

Fixed submission:
import numpy as np
import sys
 
n = int(input())
l = np.array([int(x) for x in input().split()])
ans = 0
if 0 in l:
  for i in range(n):
    ans += abs(l[i])
  print(ans)
  sys.exit()
m = abs(l[0])
p = 0
for i in range(n):
  if l[i] < 0:
    p += 1
  if m > abs(l[i]):
    m = abs(l[i])
for i in range(n):
  ans += abs(l[i])
if p % 2 == 0:
  print(ans)
else:
  print(ans - m*2)
Buggy python submission (verdict: Runtime Error):
import sys

n, k=[int(x) for x in input().split()]
s=input()
l=[]
a='1'
for i in range(len(s)):
  if a != s[i]:
    l.append(i)
    a = s[i]
l.append(len(s))
if s[-1]=='0':
  l.append(0)
if len(l) <= 2*k+1:
  print(len(s))
  sys.exit()
m=0
ans=0
while m+ 2*k < len(s)-1:
  b = l[m+2*k]-l[m]
  if b>ans:
    ans=b
  m+=2
print(ans)

Fixed submission:
import sys

n, k = [int(x) for x in input().split()]
s = input()
l = [0]
a = '1'
for i in range(n):
  if s[i] != a:
    l.append(i)
    a = s[i]
l.append(n)
if s[-1] == '0':
  l.append(n)
if len(l) < 2 * k + 2:
  print(n)
  sys.exit()
a, ans = 0, 0
while a + 2 * k + 1 < len(l):
  b = l[a+2*k+1] - l[a]
  if ans < b:
    ans = b
  a += 2
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
set = {'A', 'T', 'G', 'C'}
l, ans = 0, 0
for i in len(s):
  if s[i] in set:
    l += 1
  else:
    ans = max(l, ans)
    l = 0
print(ans)

Fixed submission:
s = input()
set = {'A', 'T', 'G', 'C'}
l, ans = 0, 0
for i in range(len(s)):
  if s[i] in set:
    l += 1
  else:
    ans = max(l, ans)
    l = 0
ans = max(l, ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
l, n = [int(x) for x in input().split()]
s = input()
for i in range(n):
  q = [int(x) for x in input().split()]
  ans = 0
  for j in range(q[0]-1, q[1]-1):
    if s[j:j+2] == 'AC':
      ans += 1
  print(ans)

Fixed submission:
l, n = [int(x) for x in input().split()]
s = input()
up = [0]
for i in range(l-1):
  if s[i:i+2] == 'AC':
    up.append(up[-1] + 1)
  else:
    up.append(up[-1])
ans = []
for i in range(n):
  d, u = map(int, input().split())
  ans.append(up[u-1] - up[d-1])
for i in range(n):
  print(ans[i])
Buggy python submission (verdict: Runtime Error):
N, X, M = map(int, input().split())

A_history = [-1] * M
sum_history = [0] * (M + 1)
A = X
all_sum = A

sum_history[0] = A

for i in range(M):
    Anext = (A * A) % M
    all_sum += Anext
    sum_history[i + 1] = all_sum
    if A_history[A] == -1:
        A_history[A] = i
    else:
        break
    A = Anext

if i >= N:
    print(sum_history[N - 1])
else:
    cycle_start = A_history[A]
    cycle_end = i - 1
    cycle_length = cycle_end - cycle_start + 1
    cycle_time = N - cycle_start
    cycle_count = cycle_time // cycle_length
    cycle_mod = cycle_time % cycle_length
    ans = sum_history[cycle_start] + (sum_history[cycle_end + 1] - sum_history[cycle_start]) * cycle_count + \
          (sum_history[cycle_start + cycle_mod - 1] - sum_history[cycle_start])
    print(ans)


Fixed submission:
N, X, M = map(int, input().split())

if X == 0:
    print(0)
    exit()

A_history = [-1] * M
sum_history = [0] * (M + 1)
A = X
all_sum = A

sum_history[0] = A

for i in range(M):
    Anext = (A * A) % M
    all_sum += Anext
    sum_history[i + 1] = all_sum
    if A_history[A] == -1:
        A_history[A] = i
    else:
        break
    A = Anext

if i >= N:
    print(sum_history[N - 1])
else:
    cycle_start = A_history[A]
    cycle_end = i - 1
    cycle_length = cycle_end - cycle_start + 1
    cycle_time = N - cycle_start
    cycle_count = cycle_time // cycle_length
    cycle_mod = cycle_time % cycle_length
    ans = sum_history[cycle_start] + (sum_history[cycle_end + 1] - sum_history[cycle_start]) * cycle_count + \
          (sum_history[cycle_start + cycle_mod - 1] - sum_history[cycle_start])
    print(ans)
Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)]

bombs_row = [0] * H
bombs_col = [0] * W

for b in B:
    bombs_row[b[0] - 1] += 1
    bombs_col[b[1] - 1] += 1

row_max = max(bombs_row)
col_max = max(bombs_col)

row_max_count = bombs_row.count(row_max)
col_max_count = bombs_col.count(col_max)

ans = row_max + col_max

possible_point = row_max_count * col_max_count

bombed_point = 0

for b in B:
    if bombs_row[b[0]] == row_max and bombs_col[b[1]] == col_max:
        bombed_point += 1

if bombed_point == possible_point:
    ans -= 1

print(ans)


Fixed submission:
H, W, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)]

bombs_row = [0] * H
bombs_col = [0] * W

for b in B:
    bombs_row[b[0] - 1] += 1
    bombs_col[b[1] - 1] += 1

row_max = max(bombs_row)
col_max = max(bombs_col)

row_max_count = bombs_row.count(row_max)
col_max_count = bombs_col.count(col_max)

ans = row_max + col_max

possible_point = row_max_count * col_max_count

bombed_point = 0

for b in B:
    if bombs_row[b[0] - 1] == row_max and bombs_col[b[1] - 1] == col_max:
        bombed_point += 1

if bombed_point == possible_point:
    ans -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
X, N = map(int, input().split())
p = list(input().split())

ans_enable = [True] * 102
for pi in p:
    ans_enable[pi] = False

diff = 0

check_ok = ans_enable[X]

ans_small = True

while not check_ok:
    diff += 1
    if ans_enable[X - diff]:
        check_ok = True
        ans_small = True
    elif ans_enable[X + diff]:
        check_ok = True
        ans_small = False

print(X - diff if ans_small else X + diff)

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

ans_enable = [True] * 102

for pi in p:
    ans_enable[pi] = False

diff = 0

check_ok = ans_enable[X]

ans_small = True

while not check_ok:
    diff += 1
    if ans_enable[X - diff]:
        check_ok = True
        ans_small = True
    elif ans_enable[X + diff]:
        check_ok = True
        ans_small = False

print(X - diff if ans_small else X + diff)
Buggy python submission (verdict: Runtime Error):
import bisect

N = int(input())

border = N * 2

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

b = [A[0] + 1]

C = [0] * (border + 1)

ans = 0

for i, a in enumerate(A, 1):
    ans += C[i - a]
    if i + a <= border:
        C[i + a] += 1
    #br = bisect.bisect_right(b, i - a)
    #bl = bisect.bisect_left(b, i - a)
    #ans += br - bl
    #b.index(bl, i + a)

print(ans)

Fixed submission:
import bisect

N = int(input())

border = N * 2

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

b = [A[0] + 1]

C = [0] * (border + 1)

ans = 0

for i, a in enumerate(A, 1):
    if 0 <= i - a <= border:
        ans += C[i - a]
    if i + a <= border:
        C[i + a] += 1
    #br = bisect.bisect_right(b, i - a)
    #bl = bisect.bisect_left(b, i - a)
    #ans += br - bl
    #b.index(bl, i + a)

print(ans)

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

N = int(input())

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

b = [A[0] + 1]

ans = 0

for i, a in enumerate(A[1:], 2):
    ans += bisect.bisect_right(b, i - a) - bisect.bisect_left(b, i - a)
    bisect.insort_right(b, i + a)

print(ans)

Fixed submission:
import bisect

N = int(input())

border = N * 2

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

b = [A[0] + 1]

C = [0] * (border + 1)

ans = 0

for i, a in enumerate(A, 1):
    if 0 <= i - a <= border:
        ans += C[i - a]
    if i + a <= border:
        C[i + a] += 1
    #br = bisect.bisect_right(b, i - a)
    #bl = bisect.bisect_left(b, i - a)
    #ans += br - bl
    #b.index(bl, i + a)

print(ans)
Buggy python submission (verdict: Runtime Error):
print(int(input) * 3.1415 * 2)

Fixed submission:
print(int(input()) * 3.1415 * 2)