Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(n):
    ans[a[i]-1]=i+1
print(*ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n):
    ans[a[i]-1]=i+1
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(1,n+1):
    ans.append(a.index(i)+1)
print(*ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n):
    ans[a[i]-1]=i+1
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(1,n+1):
    ans.append(a.index(i)+1)
print(*ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n):
    ans[a[i]-1]=i+1
print(*ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(n+1):
    ans.append(a.index(i+1))
print(*ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n):
    ans[a[i]-1]=i+1
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=map(int,input().split())
point=[k]*n
for _ in range(q):
    a=int(input())-1
    for i in range(n):
        if a!=i:
            point[i]-=1
for i in range(n):
    if point[i]>0:
        print('Yes')
    else:
        print('No')

Fixed submission:
n,k,q=map(int,input().split())
ans=[0]*n
for _ in range(q):
    a=int(input())
    ans[a-1]+=1
for i in range(n):
    if ans[i]>q-k:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a==b==c:
    if a%2===b%2==c%2==0:
        print(-1)
    else:
        print(0)
    exit()
cnt=0
while a%2==b%2==c%2:
    A=a//2
    B=b//2
    C=c//2
    a,b,c=B+C,A+C,A+B
    cnt+=1
print(cnt)

Fixed submission:
a,b,c=map(int,input().split())
if a==b==c:
    if a%2==b%2==c%2==0:
        print(-1)
    else:
        print(0)
    exit()
cnt=0
while a%2==b%2==c%2:
    A=a//2
    B=b//2
    C=c//2
    a,b,c=B+C,A+C,A+B
    cnt+=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = []
for i in range(N):
    D.append([int(a) for a in input().split()])
ans = 0
for i in range(N):
    for j in range(i+1,N):
        tmp = abs(D[i][0] - D[j][0]) + abs(D[i][1] - D[j][1])
        if ans < tmp:
            ans = tmp
print(ans)

Fixed submission:
N = int(input())
A = [[int(a) for a in input().split()] for _ in range(N)]
for i in range(N):
    z = A[i][0] + A[i][1]
    w = A[i][0] - A[i][1]
    if i==0:
        M_z = m_z = z
        M_w = m_w = w
    if z > M_z: M_z = z
    if z < m_z: m_z = z
    if w > M_w: M_w = w
    if w < m_w: m_w = w
print(max(M_z-m_z,M_w-m_w))
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
c = 1
nana = 7
if K%2 == 0:
    print("-1")
else:
    while True:
        if nana%K == 0:
            print(c)
            break
        else:
            nana = (nana%K*10 + 7)%K
            c += 1

Fixed submission:
K = int(input())
c = 1
nana = 7
if K%2 == 0:
    print("-1")
else:
    n = 7%K
    while True:
        i = nana%K
        if i == 0:
            print(c)
            break
        elif c >= 10**6:
            print("-1")
            break
        else:
            nana = (10*i+n)%K
            c += 1

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
c = 1
nana = 7
if K%2 == 0:
    print("-1")
else:
    while True:
        if nana%K == 0:
            print(c)
            break
        else:
            nana = nana%K*10 + 7
            c += 1

Fixed submission:
K = int(input())
c = 1
nana = 7
if K%2 == 0:
    print("-1")
else:
    n = 7%K
    while True:
        i = nana%K
        if i == 0:
            print(c)
            break
        elif c >= 10**6:
            print("-1")
            break
        else:
            nana = (10*i+n)%K
            c += 1

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
c = 1
nana = 7
if K%2 == 0:
  print("-1")
else:
  while True:
    if nana%K == 0:
      print(c)
      break
    else:
      nana = nana*10 + 7
      c += 1

Fixed submission:
K = int(input())
c = 1
nana = 7
if K%2 == 0:
    print("-1")
else:
    n = 7%K
    while True:
        i = nana%K
        if i == 0:
            print(c)
            break
        elif c >= 10**6:
            print("-1")
            break
        else:
            nana = (10*i+n)%K
            c += 1
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

evaluations = []
for n in range(N):
    if n < K-1:
        evaluations.append(0)
    else:
        evaluation = 1
        for i in range(K):
            evaluation *= A[n-i]
        evaluations.append(evaluation)
# print(evaluations)

for n in range(K, N):
    print('Yes' if evaluations[n] > evaluations[n-1] else 'No')


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

for n in range(K, N):
    print('Yes' if A[n] > A[n-K] else 'No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
ans = 1

for i in a:
    ans *= i
    if ans > 10**18:
    ans = -1
    break

print(ans)


Fixed submission:
N = int(input())
a = list(map(int, input().split()))
ans = 1

for i in a:
    ans *= i
    if ans > 10**18:
        ans = -1
        break

if a.count(0) > 0:
    ans = 0

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
ans = 1

for i in a:
    ans *= i

if ans > 10**18:
    ans = -1

print(ans)


Fixed submission:
N = int(input())
a = list(map(int, input().split()))
ans = 1

for i in a:
    ans *= i
    if ans > 10**18:
        ans = -1
        break

if a.count(0) > 0:
    ans = 0

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    a0 = A.pop(0)
    if a0 == amax and amaxcnt == 1:
        print(max(A))
    else:
        print(amax)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    ai = A[i]
    if ai == amax and amaxcnt == 1:
        A.pop(i)
        print(max(A))
        A.insert(i, 0)
    else:
        print(amax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append(a)
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    a0 = A.pop(0)
    if a0 == amax and amaxcnt == 1:
        print(max(A))
    else:
        print(amax)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    ai = A[i]
    if ai == amax and amaxcnt == 1:
        A.pop(i)
        print(max(A))
        A.insert(i, 0)
    else:
        print(amax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append(a)
amax = max(A)
amaxcnt = A.count(amax)

B = []
for i in range(N):
    B = A[:]
    bi = B.pop(i)
    if bi == amax and amaxcnt == 1:
        B.sort()
        print(B.pop())
    else:
        print(amax)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    ai = A[i]
    if ai == amax and amaxcnt == 1:
        A.pop(i)
        print(max(A))
        A.insert(i, 0)
    else:
        print(amax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append(a)
amax = max(A)

B = []
for i in range(N):
    B = A[:]
    bi = B.pop(i)
    if bi == amax:
        B.sort()
        print(B.pop())
    else:
        print(amax)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    ai = A[i]
    if ai == amax and amaxcnt == 1:
        A.pop(i)
        print(max(A))
        A.insert(i, 0)
    else:
        print(amax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append(a)

B = []
for i in range(N):
    B = A[:]
    B.pop(i)
    B.sort()
    print(B.pop())


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    ai = A[i]
    if ai == amax and amaxcnt == 1:
        A.pop(i)
        print(max(A))
        A.insert(i, 0)
    else:
        print(amax)
Buggy python submission (verdict: Runtime Error):
import math

A, B, C, D = map(int, input().split())

c_st = (A-1) // C
c_end = B // C
c_num = c_end - c_st

d_st = (A-1) // D
d_end = B // D
d_num = d_end - d_st

E = (C * D) // math.gcd(C, D)
e_st = (A-1) // E
e_end = B // E
e_num = e_end - e_st

ans = B - A - c_num - d_num + e_num + 1
print(ans)


Fixed submission:
def gcd(a, b):
    if a < b:
        temp = a
        a = b
        b = temp

    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b

    return b


A, B, C, D = map(int, input().split())

c_st = (A-1) // C
c_end = B // C
c_num = c_end - c_st

d_st = (A-1) // D
d_end = B // D
d_num = d_end - d_st

E = (C * D) // gcd(C, D)
e_st = (A-1) // E
e_end = B // E
e_num = e_end - e_st

ans = B - A - c_num - d_num + e_num + 1

print(ans)
Buggy python submission (verdict: Runtime Error):
# データ構造: Union Find (素集合データ構造)
#  前提
#    グラフ（頂点と辺からなる集合）上の各頂点が、どの連結成分に属しているかを管理するときに使う
#    具体的には、各連結成分ごとに適当な1点を親として、同じ連結成分に属する他の点が子になるように配置する
#  できること
#    1, ある頂点の親を返す (つまり、どの連結成分に属するかがわかる)
#    2, 新たな辺が与えられた時、必要なら連結成分の統合を行う

# 以下、事前準備。(本処理は42行目から)
# 上記1,2を実現する関数を作成する。

# 0, 前提
par = [-1]*n
#  配列parの要素par[i]には、
#    頂点iが子の場合に 親頂点の番号
#    頂点iが親の場合に 属する連結成分の頂点数を格納する。(区別のため負数として表記)
#  例: par = [2, 2, -3, -1, 5, -1]
#    点0,1,2からなる連結成分、点3からなる連結成分、点4,5からなる連結成分がある場合。

# 1, 頂点xの親を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
      
# 2, 頂点xとyが属する連結成分を結合する
def unite(x,y):
    x = find(x)
    y = find(y) 
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

# 以下、本処理
# 求めるもの：各連結成分の頂点数のうち、最大のもの
n, m = map(int,input().split())
#初期化
#根なら-size,子なら親の頂点
par = [-1 for _ in range(n)]
 
for _ in range(m): #各辺について
  a, b = map(int,input().split())
  a -= 1
  b -= 1
  unite(a,b) #辺の両端(頂点aとb)が統合される
  
print(-min(par))
# 各連結成分の頂点数は、配列parの中に負数として記録されている。
# 連結成分の最大の頂点数を求めたければ、そのminをとって-1倍すればよい。

Fixed submission:
#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

n, m = map(int,input().split())
#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

for _ in range(m):
  a, b = map(int,input().split())
  a -= 1
  b -= 1
  unite(a,b)
  
print(-min(par))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys

H, W = map(int, input().split())
xs, ys = map(int, input().split())
xt, yt = map(int, input().split())
xs -= 1
ys -= 1
xt -= 1
yt -= 1
G = [input() for _ in range(H)]

D_wk = [[1,0], [0,1], [-1,0], [0,-1]]
D_tl = 2

#cost = [[-1  for _ in range(W)] for _ in range(H)]

possible = set()
for i in range(H):
  for j in range(W):
    if G[i][j] == ".":
      possible.add(i * W + j)

# 01-BFS
def append_walk(c, x, y):
  for dx, dy in D_wk:
    if 0 <= x+dx <= H-1 and 0 <= y+dy <= W-1 and ((x+dx)*W+(y+dy)) in possible and ((x+dx)*W+(y+dy)) not in visited:
      task.appendleft([c, x+dx, y+dy])
def append_tele(c, x, y):
  for dx in range(-D_tl, D_tl+1):
    for dy in range(-D_tl, D_tl+1):
      if 0 <= x+dx <= H-1 and 0 <= y+dy <= W-1 and ((x+dx)*W+(y+dy)) in possible and ((x+dx)*W+(y+dy)) not in visited:
        task.append([c+1, x+dx, y+dy])

task = deque([[0, xs, ys]])
visited = set()
while task:
  while True:
    c, x, y = task.popleft()
    if x*W+y not in visited:
      break
    if not task:
      print(-1)
      sys.exit()    
  if x == xt and y == yt:
    print(c)
    #print(*cost, sep="\n")
    sys.exit()  
  visited.add(x*W+y)
  #cost[x][y] = c
  append_walk(c, x, y)
  append_tele(c, x, y)
  
print(-1)

Fixed submission:
from collections import deque
import sys

def BFS(task, ct):
  D = [(1,0), (0,1), (-1,0), (0,-1)]
  semi_visited = set()
  task_n = deque([])
  for s in task:
    semi_visited.add(s)
  while task:
    s = task.popleft()
    #print(s, ct, 1, task)
    if s == (hg, wg):
      print(ct)
      sys.exit()
    x = s[0]
    y = s[1]
    for d in D:
      s_n = (x+d[0], y+d[1])
      #print(s_n, s_n not in semi_visited)
      if 0 <= s_n[0] <= H-1 and 0 <= s_n[1] <= W-1 and (s_n not in semi_visited) and S[s_n[0]][s_n[1]] == ".":
        task.append(s_n)
        semi_visited.add(s_n) 
        visited.add(s_n)
  #print(semi_visited)   
  for s in semi_visited:
    warp(s, task_n)
  return (ct+1, task_n)

def warp(p, task_n):
  #print(p)
  x = p[0]
  y = p[1]
  for dh in range(-2,3):
    for dw in range(-2,3):
      s_n = (x+dh, y+dw)
      if 0 <= s_n[0] <= H-1 and 0 <= s_n[1] <= W-1:
        #print(s_n, visited)
        if S[s_n[0]][s_n[1]] == "." and s_n not in visited:
          task_n.append(s_n)
          visited.add(s_n)
  return task_n

H, W = map(int, input().split())
hs, ws = map(int, input().split())
hs -= 1
ws -= 1
hg, wg = map(int, input().split())
hg -= 1
wg -= 1

S = [input() for _ in range(H)]

task = deque([(hs, ws)])
visited = {(hs, ws)}
semi_visited = {(hs, ws)}
ct = 0

while task:
  #print(ct)
  ct, task = BFS(task, ct)
  #print(task, ct)
  
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
R, C, K = map(int, input().split())

I = [[0 for _ in range(C+1)] for _ in range(R+1)]
for i in range(K): 
  r, c, v = map(int, input().split())
  I[r][c] = v 
  
DP1 = [0 for _ in range(C+1)] #c列目までとったとき、最新の行で1個以下とったという条件のもとの最大
DP2 = [0 for _ in range(C+1)] #c列目までとったとき、最新の行で2個以下とったという条件のもとの最大
DP3 = [0 for _ in range(C+1)] #c列目までとったとき、最新の行で3個以下とったという条件のもとの最大
#print(I)

for r in range(1,R+1):
  for c in range(1,C+1): 
    #更新の順番に注意
    #mid = max(DP1[c], DP2[c], DP3[c]) + I[r][c]
    mid = DP3[c] + I[r][c] 
    DP3[c] = max(DP3[c-1], mid, DP2[c-1] + I[r][c]) #3個
    DP2[c] = max(DP2[c-1], mid, DP1[c-1] + I[r][c]) #2個
    DP1[c] = max(DP1[c-1], mid) #1個
  #print(DP3)
    
print(DP3[C])
    
    
    

Fixed submission:
R, C, K = map(int, input().split())

I = [[0 for _ in range(C+1)] for _ in range(R+1)]
for i in range(K): 
  r, c, v = map(int, input().split())
  I[r][c] = v 
  
DP1 = [0 for _ in range(C+1)] #c行目までとったとき、c行目で1個以下とったときの最大
DP2 = [0 for _ in range(C+1)] #c行目までとったとき、c行目で2個以下とったときの最大
DP3 = [0 for _ in range(C+1)] #c行目までとったとき、c行目で3個以下とったときの最大
#print(I)

for r in range(1,R+1):
  for c in range(1,C+1): 
    #更新の順番に注意
    #mid = max(DP1[c], DP2[c], DP3[c]) + I[r][c]
    mid = DP3[c] + I[r][c] 
    DP3[c] = max(DP3[c-1], mid, DP2[c-1] + I[r][c]) #3個
    DP2[c] = max(DP2[c-1], mid, DP1[c-1] + I[r][c]) #2個
    DP1[c] = max(DP1[c-1], mid) #1個
  #print(DP3)
    
print(DP3[C])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
#A = list(map(int, input().split()))

ans = [0 for _ in range(N)]
for x in range(1, 151):
  for y in range(1, 151):
    for z in range(1, 151):
      k = (x+y)**2+(y+z)**2+(z+x)**2
      if k % 2 == 0 and k < 2*N:
        ans[((x+y)**2+(y+z)**2+(z+x)**2)//2-1] += 1

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

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

ans = [0 for _ in range(N)]
for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      k = (x+y)**2+(y+z)**2+(z+x)**2
      if k % 2 == 0 and k <= 2*N:
        ans[((x+y)**2+(y+z)**2+(z+x)**2)//2-1] += 1

for i in range(N):
  print(ans[i])
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
         
A.sort(Reverse = True)

print(A.sum-A[-1])

Fixed submission:
from heapq import heapify,heappush,heappop
N = int(input())
A = list(map(int, input().split()))

A.sort()
a = A.pop()
q = []
heappush(q,-a)
ans = 0
while A:
  #print(A,q)
  b = A.pop()
  a = -heappop(q)
  ans += a
  heappush(q,-b)
  heappush(q,-b)
  
print(ans)
Buggy python submission (verdict: Runtime Error):
a = input()
a = int(N)

print(a+a*a+a*a*a)

Fixed submission:
a = int(input())
print(a+a*a+a*a*a)
Buggy python submission (verdict: Runtime Error):
X = map(int,input().split())

K = 1
direct = X
while True:
  
  if direct % 360 = 0
  	break
  direct += X
  K += 1

print(K)

Fixed submission:
X = int(input())

K = 1
dire = X
while True:
  if (dire % 360) == 0:
    break
  K+=1
  dire+=X

  
print(K)
Buggy python submission (verdict: Runtime Error):
from heapq import heapify,heappush,heappop
import sys

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

S = []
PQs = [[] for _ in range(200000)]
T = [0]*200000 #幼稚園ごとの最終更新
M = []
for n in range(N):
  a, b = map(int,input().split())
  S.append([a,b-1])#レート、所属
  #print(PQs[0:10])
  PQs[b-1]=PQs[b-1]+[(-a,n)]#-レート、人
  #print(PQs[0:10])

for b in range(200000):
  if len(PQs[b])>0:
    heapify(PQs[b])
    M.append((-PQs[b][0][0],b,0))#レート、人、所属、更新時
heapify(M)
          
for q in range(1,Q+1):#時刻。1からスタート
  c, d = map(int,input().split())
  d = d-1
  d_prv = S[c-1][1]
  S[c-1][1] = d #情報の更新
  #print(S)
 
  #print(d_prv)
  #print(d)
  
  #転園先の幼稚園について
  heappush(PQs[d],(-S[c-1][0],c-1))#-レート、人
  #print(S[P[d][0][1]][1])
  #print(d)
  #print(PQs[0:4]) 
  while d != S[PQs[d][0][1]][1]:#所属が整合していない時（古く間違った情報である時）
    heappop(PQs[d])
  heappush(M,(-PQs[d][0][0],d,q))
  T[d] = q #最終更新時をアップデート
  #print(PQs[0:4])
  
  #転園元の幼稚園について
  if len(PQs[d_prv])>0:
    while d_prv != S[PQs[d_prv][0][1]][1]:#所属が整合していない時（古く間違った情報である時）
      #print(S[PQs[d_prv][0][1]])
      heappop(PQs[d_prv])
      if len(PQs[d_prv]) == 0:
        break
        
    if len(PQs[d_prv]) > 0:  
      heappush(M,(-PQs[d_prv][0][0],d_prv,q))
    T[d_prv] = q #最終更新時をアップデート

  #print(M)   	
  #最強園児の集いを処理
  while M[0][2] != T[M[0][1]]:#更新時が整合していない時（古く間違った情報である時）
    heappop(M)
    #print(M)
  
  #結果の出力
  print(M[0][0]) 
  #print(M)

Fixed submission:
x = list(map(int, input().split()))
ans = 0
for xi in x:
  ans += 1
  if xi == 0:
    print(ans)
    break
Buggy python submission (verdict: Runtime Error):
X, N = map(int,input().split())
p = list(map(int, input().split()))
#print(p)
p.sort()
dis = p[0] - X
ans_1 = X
ans_2 = X
for pi in p :
  if pi == ans_1:
    ans_1 += 1

p.reverse()
for pi in p:
  if pi == ans_2:
    ans_2 -= 1

ans = X
if abs(ans_1 - X) < abs(ans_2 - X):
  ans = ans_1
elif ans_1 - X == -abs(ans_2 - X):
  ans = ans_1
else:
  ans = ans_2
print(ans)

Fixed submission:
X, N = map(int,input().split())
if N > 0:
  p = list(map(int, input().split()))
else:
  p=[]
#print(p)
p.sort()
#dis = p[0] - X
ans_1 = X
ans_2 = X
for i in range(N) :
  pi = p[i]
  if pi == ans_1:
    ans_1 += 1

p.reverse()
for i in range(N) :
  pi = p[i]
  if pi == ans_2:
    ans_2 -= 1

ans = X
if abs(ans_1 - X) < abs(ans_2 - X):
  ans = ans_1
elif ans_1 - X == -abs(ans_2 - X):
  ans = ans_1
else:
  ans = ans_2
print(ans)

Buggy python submission (verdict: Runtime Error):
X, N = map(int,input().split())
p = list(map(int, input().split()))
#print(p)
#A.sort()
dis = p[0] - X
ans = p[0]
for pi in p :
  if abs(pi-X) < abs(dis):
    ans = pi
    dis = pi - X
    #print("if")
  elif pi-X == -abs(dis):
    ans = pi
    dis = pi - X
  #print(pi-X, abs(pi-X), dis,abs(dis))
print(ans)

Fixed submission:
X, N = map(int,input().split())
if N > 0:
  p = list(map(int, input().split()))
else:
  p=[]
#print(p)
p.sort()
#dis = p[0] - X
ans_1 = X
ans_2 = X
for i in range(N) :
  pi = p[i]
  if pi == ans_1:
    ans_1 += 1

p.reverse()
for i in range(N) :
  pi = p[i]
  if pi == ans_2:
    ans_2 -= 1

ans = X
if abs(ans_1 - X) < abs(ans_2 - X):
  ans = ans_1
elif ans_1 - X == -abs(ans_2 - X):
  ans = ans_1
else:
  ans = ans_2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
A = list(map(int,input().split()))

MOD = 998_244_353

D = [[0 for _ in range(S+1)] for _ in range(N+1)]
D[0][0] = 1
for i in range(1, N+1):
  for j in range(0, S+1):
    D[i][j] = 2 * D[i-1][j] % MOD
    if j >= A[i-1]:
      D[i][j] += D[i-1][j-A[i-1]]
      D[i][j] %= MOD
  #print(D[i])
    
print(D[N][S])

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

MOD = 998_244_353

D = [[0 for _ in range(S+1)] for _ in range(N+1)]
D[0][0] = 1
for i in range(1, N+1):
  for j in range(0, S+1):
    D[i][j] = 2 * D[i-1][j] % MOD
    if j >= A[i-1]:
      D[i][j] += D[i-1][j-A[i-1]]
      D[i][j] %= MOD
  #print(D[i])
    
print(D[N][S])
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify,heappush,heappop
N, M = map(int, input().split())

I = [[0 for _ in range(N)] for _ in range(N)]
for i in range(M):
  A, B = map(int, input().split())
  A -= 1
  B -= 1
  I[A][B] = 1
  I[B][A] = 1

task = [] 
used = [0 for _ in range(N)]
min_len = [0 for _ in range(N)]
length = [10**20 for _ in range(N)]
prev_points = [0 for _ in range(N)]
heappush(task, (0, 0, -1))
print("Yes")

while task:
  while task:
    l, p, prev = heappop(task)    
    if used[p] == 0:
      break
  #print(task)
  used[p] = 1
  min_len[p] = l
  prev_points[p] = prev +1 #番号を1ずらす
  
  for j in range(N):
    if I[p][j] == 0: continue
    #print(p,j)
    if length[j] > l+1:
      length[j] = l+1
      heappush(task, (l+1, j, p))
    I[p][j] = 0
    I[j][p] = 0

for i in range(1, N):
  print(prev_points[i])

Fixed submission:
from heapq import heapify,heappush,heappop
N, M = map(int, input().split())

I = [[] for _ in range(N)]
for i in range(M):
  A, B = map(int, input().split())
  A -= 1
  B -= 1
  I[A].append(B)
  I[B].append(A)

task = [] 
used = [0 for _ in range(N)]
min_len = [0 for _ in range(N)]
length = [10**20 for _ in range(N)]
prev_points = [0 for _ in range(N)]
heappush(task, (0, 0, -1))
print("Yes")

while task:
  while task:
    l, p, prev = heappop(task)    
    if used[p] == 0:
      break
  #print(task)
  used[p] = 1
  min_len[p] = l
  prev_points[p] = prev +1 #番号を1ずらす
  
  for j in I[p]:
    if used[j] == 1: continue
    #print(p,j)
    if length[j] > l+1:
      length[j] = l+1
      heappush(task, (l+1, j, p))
    
for i in range(1, N):
  print(prev_points[i])