Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
Z = int(input())
n = (-2)

ans = ""

while abs(Z) >= 1:
  r = Z % n
  if r < 0:
    r = r + 2
  Z = int((Z - r) / n)
  ans += str(r)

ans = "".join(list(reversed(ans)))

print(int(ans))

Fixed submission:
Z = int(input())

if Z == 0:
  print(0)

else:
  n = (-2)

  ans = ""

  while abs(Z) >= 1:
    r = Z % n
    if r < 0:
      r = r + 2
    Z = int((Z - r) / n)
    ans += str(r)

  ans = "".join(list(reversed(ans)))


  print(int(ans))

Buggy python submission (verdict: Runtime Error):
Z = int(input())
n = (-2)

ans = ""

while abs(Z) >= 1:
  r = Z % n
  if r < 0:
    r = r + 2
  Z = int((Z - r) / n)
  ans += str(r)
  
print(int(ans))

Fixed submission:
Z = int(input())

if Z == 0:
  print(0)

else:
  n = (-2)

  ans = ""

  while abs(Z) >= 1:
    r = Z % n
    if r < 0:
      r = r + 2
    Z = int((Z - r) / n)
    ans += str(r)

  ans = "".join(list(reversed(ans)))


  print(int(ans))
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()

cur = T.find(S[0])
i = 0
con = len(S)

while con != 0:
  if S[i] == T[cur]:
    con -= 1
    
    if con == 0:
      print("Yes")
    
    i += 1
    if cur == (len(S) - 1):
      cur = 0
    else:
      cur += 1
  else:
    print("No")
    break



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

ans = (max(A) - min(A))

print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools

N,M = map(int,input().split())
value = [0] * N

for i in range(N):
  v = list(map(int,input().split()))
  abv = [i if i > 0 else i * - 1 for i in v]
  value[i] = v

ans = 0

for i in list(itertools.combinations(range(0,N),M)):
  a,b,c = value[i[0]],value[i[1]],value[i[2]]
  tmp = 0
  for j in range(3):
    t = a[j] + b[j] + c[j]
    if t < 0:
      t *= -1
    tmp += t
  ans = max(ans,tmp)
  
print(ans)

Fixed submission:
import itertools

N,M = map(int,input().split())
value = [0] * N

for i in range(N):
  v = list(map(int,input().split()))
  abv = [i if i > 0 else i * - 1 for i in v]
  value[i] = v

ans = 0
totals = []

for i in range(0,2 ** 3):
  totals = []
  #print(bin(i))
  for v in range(N):
    tmp = 0
    for j in range(0,3):
      if (i >> j) & 1:
        tmp += value[v][j]
      else:
        tmp -= value[v][j]
    totals.append(tmp)
  #print(totals)
  totals = sorted(totals,reverse = True)

  t = 0
  for k in range(M):
    t += totals[k]
  ans = max(ans,t)
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
List9 = [9 ** i for i in range(6) if 9 ** i <= N]
List6 = [6 ** i for i in range(6) if 6 ** i <= N]

def recur(n,con):
  if n == 0:
    return con


  else:
    max9 = max([i for i in List9 if i <= n])
    max6 = max([i for i in List6 if i <= n])
    
    return min(recur(n - max9,con + 1),recur(n - max6,con + 1))
    
print(recur(N,0))

Fixed submission:
N = int(input())
List9 = [9 ** i for i in range(1,7) if 9 ** i <= N]
List6 = [6 ** i for i in range(1,7) if 6 ** i <= N]

def recur(n,con):
  if n == 0:
    return con

  elif n < 6:
    return con + n
    
  elif n < 9:
    return con + (n - 5)

  else:
    max9 = [i for i in List9 if i <= n][-1]
    max6 = [i for i in List6 if i <= n][-1]
    
    return min(recur(n - max9,con + 1),recur(n - max6,con + 1))
    
print(recur(N,0))

Buggy python submission (verdict: Runtime Error):
N = int(input())
List9 = [9 ** i for i in range(6) if 9 ** i <= N]
List6 = [6 ** i for i in range(6) if 6 ** i <= N]

def recur(n,con):
  if n == 0:
    return con
    
"""
  elif n < 6:
    return con + n
    
  elif n < 9:
    return con + (n - 5)
"""    

  else:
    max9 = max([i for i in List9 if i <= n])
    max6 = max([i for i in List6 if i <= n])
    
    return min(recur(n - max9,con + 1),recur(n - max6,con + 1))
    
print(recur(N,0))

Fixed submission:
N = int(input())
List9 = [9 ** i for i in range(1,7) if 9 ** i <= N]
List6 = [6 ** i for i in range(1,7) if 6 ** i <= N]

def recur(n,con):
  if n == 0:
    return con

  elif n < 6:
    return con + n
    
  elif n < 9:
    return con + (n - 5)

  else:
    max9 = [i for i in List9 if i <= n][-1]
    max6 = [i for i in List6 if i <= n][-1]
    
    return min(recur(n - max9,con + 1),recur(n - max6,con + 1))
    
print(recur(N,0))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 10 ** 9

cum_sum = [10 ** 7] * N

for i in range(1,N):
  left = S[:i]
  right = S[i:]
  turn = left.count("W")+ right.count("E")
  if S[i - 1] == "W":
    turn -= 1
  cum_sum[i - 1] = turn
    
print(min(cum_sum))

Fixed submission:
N = int(input())
S = input()
L = [0] * N
e = 0

for i in range(N - 1):
  #E,Wが互い違いになっていると相殺されるため手数は変わらない
  #iが増える = カーソルが右に行くにつれ
  #Eが続けて増えると手数は減り(カーソルの方向へ向く人が増えるため)、
  #Wが続けて増えると手数は増える(カーソルと逆方向を向く人が増えるため)
  if S[i + 1] == "E":
    #累積和を取っていくとともに、東の方向を向いている人数を記録する
    #カーソルが西端にあるとき、Eの総数が手数となる
    ##Eが続けて増えるとき累積和が減り、Eの総数からカーソル以西のEが相殺され、
    ##カーソル以東のEだけが計上される
    e += 1
    if S[i] == "E":
      L[i + 1] = L[i] - 1
    else: 
      L[i + 1] = L[i]
  else:
    if S[i] == "W":
      L[i + 1] = L[i] + 1
    else:
      L[i + 1] = L[i]

ans = min(L) + e
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

center = N // 2

ans = 10 ** 9

for i in range(1,N):
  left = S[:i]
  right = S[i:]

  turn = left.count("W")+ right.count("E")
  if S[i - 1] == "W":
    turn -= 1
  if ans >= turn:
    ans = turn
    
print(ans)

Fixed submission:
N = int(input())
S = input()
L = [0] * N
e = 0

for i in range(N - 1):
  #E,Wが互い違いになっていると相殺されるため手数は変わらない
  #iが増える = カーソルが右に行くにつれ
  #Eが続けて増えると手数は減り(カーソルの方向へ向く人が増えるため)、
  #Wが続けて増えると手数は増える(カーソルと逆方向を向く人が増えるため)
  if S[i + 1] == "E":
    #累積和を取っていくとともに、東の方向を向いている人数を記録する
    #カーソルが西端にあるとき、Eの総数が手数となる
    ##Eが続けて増えるとき累積和が減り、Eの総数からカーソル以西のEが相殺され、
    ##カーソル以東のEだけが計上される
    e += 1
    if S[i] == "E":
      L[i + 1] = L[i] - 1
    else: 
      L[i + 1] = L[i]
  else:
    if S[i] == "W":
      L[i + 1] = L[i] + 1
    else:
      L[i + 1] = L[i]

ans = min(L) + e
print(ans)
Buggy python submission (verdict: Runtime Error):
ABC = sorted(list(map(int,input().split())))
K = int(input())

print(sum(ABC[:2]) + (ABC[-1] * 2( **  K))

Fixed submission:
ABC = sorted(list(map(int,input().split())))
K = int(input())

print(sum(ABC[:2]) + (ABC[-1]) * (2 ** K))
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
grid = [[]] * H

for i in range(H):
  c = list(input())
  grid[i] = c
  
black = "#"
white = "."

ans = "Yes"


for i in range(H):
  for j in range(W):
    if grid[i][j] == black:
      here = grid[i][j]
      around = ""
      
      if i == 0:
        around += grid[i + 1][j]
      elif i == W - 1:
        around += grid[i - 1][j]
      else:
        around += (grid[i - 1][j] + grid[i + 1][j])
      
      if j == 0:
        around += grid[i][j + 1]
      elif j == H - 1:
        around += grid[i][j - 1]
      else:
        around += (grid[i][j + 1] + grid[i][j - 1])
      
      if all([i == white for i in around]):
        ans = "No"
        break

print(ans)


Fixed submission:
H,W = map(int,input().split())
grid = [[]] * H

for i in range(H):
  c = list(input())
  grid[i] = c
  
black = "#"
white = "."

ans = "Yes"

for i in range(H):
  for j in range(W):
    if grid[i][j] == black:
      around = ""
      #ヨコ
      for t in range(max(0,j - 1),min(W,j + 2)):
        if t != j:
          around += grid[i][t]
      #タテ
      for k in range(max(0,i - 1),min(H,i + 2)):
        if k != i:
          around += grid[k][j]
      
      if all([s == white for s in around]):
        ans = "No"
        break
  if ans == "No":
    break
      
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,C,X,Y = map(int,input().split())

D = (A + B) // 2
C2 = C * 2

ans = 0

if C2 <= min(A,B):
  ans += C2 * max(X,Y)
  print(ans)
elif C2 > max(A,B):
  ans += (A * X) + (B * Y)
  print(ans)
else:
  if D >= C:
    if X > Y:
    ans += C2 * Y
    ans += A * (X - Y)
    print(ans)
  else:
    ans += (A * X) + (B * Y)
    print(ans)

Fixed submission:
A,B,C,X,Y = map(int,input().split())

C2 = C * 2
diff = abs(X - Y)

ans = 0


if C2 > A + B:
  ans = (A * X) + (B * Y)

elif C2 <= A + B:
  if X > Y:
    ans = min(C2 * Y + A * diff,C2 * X)

  else:
    ans = min(C2 * X + B * diff,C2 * Y)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
N = [chr(i) for i in range(97,123) if chr(i) not in S]

if len(S) == 26:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    LS = list(S)
    sLS = sorted(LS)
    for i in range(0,27):
      if LS[i] != sLS[i]:
        S = S[:i - 1] + sLS[i]
        break
else:
  S = S + N[0]
  print(S)



Fixed submission:
S = input()

if len(S) < 26:
  N = [chr(i) for i in range(97,123) if chr(i) not in S]
  print(S + N[0])
else:
  for i in range(26):
    for j in range(i+1):
      if S[-(i + 1)] < S[-(j + 1)]:
          print(S[:-(i+1)]+S[-(j+1)])
          exit()
  else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
S = input()
N = [chr(i) for i in range(97,123) if chr(i) not in S]

if len(S) == 26:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    LS = list(S)
    sLS = sorted(LS)
    print(LS)
    print(sLS)
    for i in range(0,27):
      if LS[i] != sLS[i]:
        S = S[:i - 1] + sLS[i]
        break
else:
  S = S + N[0]
  
print(S)

Fixed submission:
S = input()

if len(S) < 26:
  N = [chr(i) for i in range(97,123) if chr(i) not in S]
  print(S + N[0])
else:
  for i in range(26):
    for j in range(i+1):
      if S[-(i + 1)] < S[-(j + 1)]:
          print(S[:-(i+1)]+S[-(j+1)])
          exit()
  else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

for i in range(N):
  now = 0
  ans = 0
  for j in range(N):
    if i != j:
      next = A[j]
      ans += abs(next - now)
      now = next
  ans += abs(B[-1])
  print(ans)


Fixed submission:
N = int(input())
A = [0]
A = A + list(map(int,input().split()))
A = A + [0]

D = 0

for i in range(N + 1):
  D += abs(A[i + 1] - A[i])
  
for i in range(1,N + 1):
  ans = D + abs(A[i + 1] - A[i - 1]) - (abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i]))
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
heads = ["M","A","R","C","H"]

N = int(input())
S = []

for i in range(N):
  s = input()[0]
  if s in heads:
    S.append(s)

combi = list(itertools.combinations(S,3))
con = 0

for i in combi:
  if len(set(i)) == 3:
    con += 1
    
print(con)

Fixed submission:
import itertools
from operator import mul
from functools import reduce
heads = ["M","A","R","C","H"]

N = int(input())
S = [0,0,0,0,0]

for i in range(N):
  s = input()[0]
  if s in heads:
    n = heads.index(s)
    S[n] += 1

S = [i for i in S if i != 0]

nums = list(itertools.combinations(S,3))

total = 0

for list in nums:
  total += reduce(mul,list)

print(total)
Buggy python submission (verdict: Runtime Error):
import bisect

def primetable(n):
  list = [True for _ in range(n + 1)]
  i = 2
  while i * i <= n:
    if list[i]:
      j = i + i
      while j <= n:
        list[j] = False
        j += i
    i += 1
  table = [i for i in range(n + 1) if list[i] and i >= 1]
  return table

prime = primetable(10 ** 5)
accume = [0] * (len(prime))
con = 0

for i,p in enumerate(prime):
  if p <= 2:
    continue
  q = (p + 1) // 2
  if q in prime:
    con += 1
  accume[i] = con

Q = int(input())

for i in range(Q):
  l,r = map(int,input().split())
  if l == 1:
    l += 1
  R = bisect.bisect_left(prime,r)
  L = bisect.bisect_left(prime,l)
  print(accume[R] - accume[L - 1])


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

def isprime(x):
  if x <= 1:
    return False
  for i in range(2, int(x**0.5) + 1):
    if x % i == 0:
      return False
  return True


A = [0] * 10 ** 5
B = [0] * 10 ** 5
con = 0

for i in range(10 ** 5):
  if isprime(i):
    A[i] = 1
  if A[i] and A[(i + 1) // 2]:
    con += 1
  B[i] = con

Q = int(input())

for _ in range(Q):
  l, r = map(int, input().split())
  print(B[r] - B[l - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

a = set(A)

con = 0

for i in a:
  n = A.count(i)
  if i > n:
    con += n
  elif i < n:
    con += (n - i)
    
print(con)

Fixed submission:
from collections import Counter

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

a = Counter(A)

con = 0

for num in a.keys():
  time = a[num]
  if time > num:
    con += (time - num)
  elif num > time:
    con += time

print(con)
Buggy python submission (verdict: Runtime Error):
N = int(input())
F = []
P = []

for i in range(N):
  f = list(map(int,input().split()))
  F.append(f)
  
for i in range(N):
  p = list(map(int,input().split()))
  P.append(p)
  
value = 0

ans = - (10 ** 9)

def recur(list):
  con = len(list)
  #list = [0,0, ... ~ 0] ~ [1,1, ... ~ 1]
  if con == 10:
    #1がない = 出店していない場合は何も返さない
    if list.count(1) == 0:
        return
    value = 0
    #インデックス番号とF[i] = 店の出店リストを取得
    for n,shop in enumerate(F):
        con = 0
        for j in range(10):
          	#j日に自店が出店し、かつ他店nも出店するならば、カウントする
            if list[j] == 1 and shop[j] == 1:
                con += 1
        #出店リストlistのパターンに応じた店nごとの利益を
        #同時出店日数conから算出し足し合わせる
        value += P[n][con]
 
    global ans
  　
    ans = max(ans, value)
    
  else:
    #出店しない
    recur(list + [0])
    #出店する
    recur(list + [1])
    
recur([])
    
print(ans)

Fixed submission:
N = int(input())
F = []
P = []

for i in range(N):
  f = list(map(int,input().split()))
  F.append(f)
  
for i in range(N):
  p = list(map(int,input().split()))
  P.append(p)
  
value = 0

ans = - (10 ** 9)

def recur(list):
  con = len(list)
  #list = [0,0, ... ~ 0] ~ [1,1, ... ~ 1]
  if con == 10:
    #1がない = 出店していない場合は何も返さない
    if list.count(1) == 0:
      return
    value = 0
    #インデックス番号とF[i] = 店の出店リストを取得
    for n,shop in enumerate(F):
      con = 0
      for j in range(10):
          #j日に自店が出店し、かつ他店nも出店するならば、カウントする
          if list[j] == 1 and shop[j] == 1:
              con += 1
      #出店リストlistのパターンに応じた店nごとの利益を
      #同時出店日数conから算出し足し合わせる
      value += P[n][con]
 
    global ans
  
    ans = max(ans, value)
    
  else:
    #出店しない
    recur(list + [0])
    #出店する
    recur(list + [1])
    
recur([])
    
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,C,D,E,F = map(int,input().split())

conc = 0
total = 0

for a in range(0,31):
  for b in range(0,31):
    water = (A * a + B * b) * 100
    if water > F:
      break
    else:
      for c in range(3001):
        water = (A * a + B * b) * 100
        
        if water == 0:
          break
        #探索中の水の量に溶かせられる砂糖の限界量
        sugar_limit = int(water * E / 100)
        #操作Cで投入された砂糖の量
        sugarC = c * C
        
        if sugarC > sugar_limit:
          break
        #ビーカーに溶かせる容量
        else:
          rest = F - water - sugarC
          #水に溶かせられる砂糖量
          sugar_rest = sugar_limit - sugarC
          
          if rest < 0:
            break
          
          else:
            #操作Dで溶かせられる砂糖の量
            sugarD = (min(rest,sugar_rest) // D) * D
            sugar = sugarC + sugarD
            temp = (sugar) / (water + sugar)
            if conc < temp and temp < E:
              conc = temp
              total = water + sugar
              ans = [total,sugar]
        
print(ans[0],ans[1])



Fixed submission:
A,B,C,D,E,F = map(int,input().split())

conc = 0
total = 0

ans = [100 * A,0]

for a in range(0,31):
  for b in range(0,31):
    water = (A * a + B * b) * 100
    if water > F:
      break
    else:
      for c in range(3001):
        water = (A * a + B * b) * 100
        if water == 0:
          break
        #探索中の水量に解かせる砂糖の量
        sugar_limit = int(water * E / 100)
        #操作Cで投入された砂糖の量
        sugarC = c * C
        
        if sugarC > sugar_limit:
          break
        #ビーカーに溶かせる容量
        else:
          rest = F - water - sugarC
          #水に溶かせられる砂糖量
          sugar_rest = sugar_limit - sugarC
          
          if rest < 0:
            break
          
          else:
            #操作Dで溶かせられる砂糖領
            sugarD = (min(rest,sugar_rest) // D) * D
            sugar = sugarC + sugarD
            temp = (sugar) / (water + sugar)
            if conc < temp and temp < E:
              conc = temp
              total = water + sugar
              ans = [total,sugar]
        
print(ans[0],ans[1])
Buggy python submission (verdict: Time Limit Exceeded):
import collections

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

nums = [[0] * 3 for i in range(N)]

roll = [-1,0,1]

for i in range(N):
  for j in range(3):
    d = A[i] + roll[j]
    nums[i][j] = d

B = sum(nums,[])
B = collections.Counter(B).most_common()
print(B[0][1])

Fixed submission:
import collections

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

nums = []
roll = [-1,0,1]

for i in range(N):
  for j in range(3):
    d = A[i] + roll[j]
    nums.append(d)

num = collections.Counter(nums).most_common()
print(num[0][1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
B = set(A)
C = sorted([i for i in B if A.count(i) // 2 >= 1],reverse = True)

ans = 0
m = 0
n = 0

if len(C) == 0:
 ans = 0
 
elif A.count(C[0]) >= 4:
  m = C[0]
  ans = m ** 2

elif len(C) > 1:
  m = C[0]
  n = C[1]
  ans = m * n

print(ans)

Fixed submission:
N = int(input())
A = sorted(list(map(int,input().split())),reverse = True)

edge = []

for i in range(1,N):
  if A[i] == A[i - 1] and A[i] not in edge:
    edge.append(A[i])
  elif A[i] == A[i - 3]:
    edge.append(A[i])
  
  if len(edge) == 2:
    break
    
if len(edge) <= 1:
  print(0)
else:
  print(edge[0] * edge[1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = sorted(list(map(int,input().split())),reverse = True)
A = [i for i in A if A.count(i) // 2 >= 1]

ans = 0

for i in range(len(A)):
  m = A[0]
  if A.count(0) >= 4:
    ans = m ** 2
    break
  else:
    if A[i] != m:
      n = A[i]
      ans = m * n
      break

print(ans)

Fixed submission:
N = int(input())
A = sorted(list(map(int,input().split())),reverse = True)

edge = []

for i in range(1,N):
  if A[i] == A[i - 1] and A[i] not in edge:
    edge.append(A[i])
  elif A[i] == A[i - 3]:
    edge.append(A[i])
  
  if len(edge) == 2:
    break
    
if len(edge) <= 1:
  print(0)
else:
  print(edge[0] * edge[1])
Buggy python submission (verdict: Runtime Error):
A,B,C,D = map(int,input().split())

inter1 = [i for i in range(A,B + 1)]
inter2 = [i for i in range(C,D + 1)]

inter3 = []

for i in range(0,max(B,D)):
  if i in inter1 and i in inter2:
    inter3.append(i)
    
print(max(inter3) - min(inter3))

Fixed submission:
A,B,C,D = map(int,input().split())
 
alice = [i for i in range(A,B + 1)]
bob = [i for i in range(C,D + 1)]
 
common = [i for i in bob if i in alice]

if len(common) == 0:
  print(0)
else:
  print(len(common)-1)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  N,M = map(int,input().split())
  ships = sorted([list(map(int,input().split())) for i in range(M)])
  
  ans = "IMPOSSIBLE"
  
  con = 0
  
  for i in range(M):
    if ships[i][0] == 1:
      con += 1
  
  for i in range(0,min(M,con + 1)):
    if ships[i][0] == 1:
      ship = ships[i][1]
      for j in range(con,M):
        if ships[j][0] == ship and ships[j][1] == N:
          ans = "POSSIBLE"
          break
      else:
        continue
      break
        
  print(ans)
  
main()

Fixed submission:
def main():
  N,M = map(int,input().split())
  ships = [list(map(int,input().split())) for i in range(M)]
  start, goal = set(), set()
  for i in range(M):
    if ships[i][0] == 1:
      start.add(ships[i][1])
    if ships[i][1] == N:
      goal.add(ships[i][0])
  flg = start & goal
  print("POSSIBLE" if flg else "IMPOSSIBLE")
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
ships = sorted([list(map(int,input().split())) for i in range(M)])

ans = "IMPOSSIBLE"

con = 0

for i in range(M):
  if ships[i][0] == 1:
    con += 1

for i in range(0,min(M,con + 1)):
  if ships[i][0] == 1:
    ship = ships[i][1]
    for j in range(con,M):
      if ships[j][0] == ship and ships[j][1] == N:
        ans = "POSSIBLE"
        break
    else:
      continue
    break
      
print(ans)

Fixed submission:
def main():
  N,M = map(int,input().split())
  ships = [list(map(int,input().split())) for i in range(M)]
  start, goal = set(), set()
  for i in range(M):
    if ships[i][0] == 1:
      start.add(ships[i][1])
    if ships[i][1] == N:
      goal.add(ships[i][0])
  flg = start & goal
  print("POSSIBLE" if flg else "IMPOSSIBLE")
 
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
ships = sorted([list(map(int,input().split())) for i in range(M)])

ans = "IMPOSSIBLE"

for i in range(M):
  if ships[i][0] == 1:
    ship = ships[i][1]
    for j in range(M):
      if ships[j][0] == ship and ships[j][1] == N:
        ans = "POSSIBLE"
        break
    else:
      continue
      
print(ans)

Fixed submission:
def main():
  N,M = map(int,input().split())
  ships = [list(map(int,input().split())) for i in range(M)]
  start, goal = set(), set()
  for i in range(M):
    if ships[i][0] == 1:
      start.add(ships[i][1])
    if ships[i][1] == N:
      goal.add(ships[i][0])
  flg = start & goal
  print("POSSIBLE" if flg else "IMPOSSIBLE")
 
main()
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse = True)

diff = [0] * (N - 1)

for i in range(N - 1):
  diff[i] = A[i] - A[i + 1]
  
if K > A[0]:
  print("IMPOSSIBLE")
elif len(set(diff)) == 1 and A[0] % diff[0] == 0:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Fixed submission:
import fractions
from functools import reduce

N,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse = True)

def gcd_list(numbers):
  return reduce(fractions.gcd, numbers)

GCD = gcd_list(A)

if K > A[0]:
  print("IMPOSSIBLE")
elif K % GCD != 0:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
P = []

S = sum(A)

snuke = 0
ans = 10 ** 9

for i in range(0,N - 1):
  snuke += A[i]
  ans = (S - 2 * snuke)
  
  if ans >= dif:
    ans = dif
    
print(ans)
  

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
P = []

S = sum(A)

snuke = 0
ans = 10 ** 12

for i in range(N - 1):
  snuke += A[i]
  dif = abs(S - (2 * snuke))
  
  if ans >= dif:
    ans = dif
    
print(ans)