Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
a, b, c, d = map(int, input().split())
print(b-(a-1) - b//c + (a-1)//c - b//d + (a-1)//d + b//lcm(c,d) + (a-1)//lcm(c, d))

Fixed submission:
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
a, b, c, d = map(int, input().split())
print(b-(a-1) - b//c + (a-1)//c - b//d + (a-1)//d + b//lcm(c, d) - (a-1)//lcm(c, d))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
s = list(s)
t = s
cnt = 0
for i in range(n-2):
  if s[i] == '.' and s[i+1] == '#' and s[i+2] == '.':
    s[i+1] = '.'
    cnt+=1

for i in range(n-1):
  if s[i] == '#' and s[i+1] == '.':
    s[i+1] = '#'
    cnt+=1

print(cnt)


Fixed submission:
a, b, c = (int(i) for i in input().split())  

if a < b and a < c and c < b:
  print('Yes')
elif b < a and b < c and c < a:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
s = list(s)
ans = s
len = []
for i in range(n):
  l = 0
  if s[i] == '0':
    l += 1
    j = i
    while s[j+1] != '0':
      l += 1
  len.append(l)
print(len)

Fixed submission:
a,b = (int(i) for i in input().split())  
sum = 0
sum += max(a,b)
if a > b:
  a -= 1
else:
  b -= 1
sum += max(a,b)
print(sum)

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
sum = 0
sum += max(a,b)
if a < b:
  a -= 1
else:
  b -= 1
sum += max(a,b)
print(sum)

Fixed submission:
a,b = (int(i) for i in input().split())  
sum = 0
sum += max(a,b)
if a > b:
  a -= 1
else:
  b -= 1
sum += max(a,b)
print(sum)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
a.append(int(i) for i in input().split())  
ans = 0
m = a[0]
for i in range(n-1):
  if m <= a[i+1]:
    ans += 1
    m = a[i+1]
print(ans)

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

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
a.append(int(i) for i in input().split())  
ans = 0
m = a[0]
for i in range(n-1):
  if m <= a[i+1]:
    ans += 1
    m = a[i+1]
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = a[0]
ans = 1
for i in range(1,n):
  if m <= a[i]:
    ans += 1
    m = a[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
s = list(s)
ans = s
len = []
for i in range(n):
  l = 0
  if s[i] == '0':
    l += 1
    j = i
    while s[j+1] != '0':
      l += 1
  len.append(l)
print(len)

Fixed submission:
n, k = map(int, input().split())
a = input()
l = []
if a[0] == '0':
    l.append(0)
sum = []
i = 0
while i < len(a):
    j = i
    while j < len(a) and a[j] == a[i]:
        j += 1
    l.append(j-i)
    i = j
if a[-1] == '0':
    l.append(0)
num = [0]*(len(l)+1)
for i in range(0, len(l)):
    num[i+1] = num[i]+l[i]
ans = -1
for i in range(0, len(num), 2):
    j = i + k*2+1
    if j >= len(num):
        j = len(num)-1
    ans = max(ans, num[j] - num[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a = input().split() 
n = a[0]
q = a[1]
s = input()
s = list(s)
cnt = []
l = []
r = []
for i in range(int(q)):
  a,b=map(int,input().split())
  l.append(a)
  r.append(b)
  cnt.append(0)
for i in range(int(q)):
  for j in range(int(l[i]), int(r[i])):
    if j == len(s)-1:
      break
    if s[j-1] == 'A' and s[j] == 'C':
      cnt[i] += 1
for i in range(len(cnt)):
  print(cnt[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
a = input().split() 
n = a[0]
q = a[1]
s = input()
s = list(s)
cnt = []
l = []
r = []
for i in range(int(q)):
  a,b=map(int,input().split())
  l.append(a)
  r.append(b)
  cnt.append(0)
for i in range(int(q)):
  for j in range(int(l[i]), int(r[i])):
    if j == len(s)-1:
      break
    if s[j-1] == 'A' and s[j] == 'C':
      cnt[i] += 1
for i in range(len(cnt)):
  print(cnt[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Runtime Error):
a = input().split() 
n = a[0]
q = a[1]
s = a[2]
s = list(s)
cnt = []
l = []
r = []
for i in range(int(q)):
  l.append(a[3+i*2])
  r.append(a[4+i*2])
  cnt.append(0)
print(a)
for i in range(int(q)):
  for j in range(int(l[i]), int(r[i])):
    if j == len(s)-1:
      break
    if s[j-1] == 'A' and s[j] == 'C':
      cnt[i] += 1
for i in range(len(cnt)):
  print(cnt[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
q = int(input())
s = input()
s = list(s)
cnt = []
l = []
r = []
for i in range(q):
  l.append(int(input()))
  r.append(int(input()))
  cnt.append(0)
for i in range(q):
  for j in range(l[i], r[i]):
    if j == len(s)-1:
      break
    if s[j-1] == 'A' and s[j] == 'C':
      cnt[i] += 1
for i in range(len(cnt)):
  print(cnt[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
x = [[int(j) for j in input().split()] for i in range(n)]
a = []
b = []
for i in range(n):
  a.append(x[i][0])
  b.append(x[i][1])
mon = 0
cnt = 0
ind = 100000
while(cnt < m):
  min = 10000000000
  for i in range(n):
    if a[i] < min:
      min = a[i]
      ind = i
  while(b[ind] > 0 and cnt != m):
    cnt += 1
    mon += a[ind]
    b[ind] -= 1
  a[ind] = 100000000000
print(mon)

Fixed submission:
import math
n, m = map(int, input().split())
a = []
for i in range(n):
    l = list(map(int, input().split()))
    a.append(l)
a.sort(key=lambda x: x[0])
sum = 0
cnt = 0
for i in range(n):
    if cnt + a[i][1] >= m:
        sum += (m-cnt)*a[i][0]
        cnt += m-cnt
        break
    else:
        sum += a[i][0]*a[i][1]
        cnt += a[i][1]
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
x = [[int(j) for j in input().split()] for i in range(n)]
a = []
b = []
for i in range(n):
  a.append(x[i][0])
  b.append(x[i][1])
mon = 0
cnt = 0
ind = 100000
while(cnt < m):
  min = 10000000000
  for i in range(n):
    if a[i] < min:
      min = a[i]
      ind = i
  while(b[ind] > 0 and cnt != m):
    cnt += 1
    mon += a[ind]
    b[ind] -= 1
  a[ind] = 100000000000
print(mon)

Fixed submission:
import math
n, m = map(int, input().split())
a = []
for i in range(n):
    l = list(map(int, input().split()))
    a.append(l)
a.sort(key=lambda x: x[0])
sum = 0
cnt = 0
for i in range(n):
    if cnt + a[i][1] >= m:
        sum += (m-cnt)*a[i][0]
        cnt += m-cnt
        break
    else:
        sum += a[i][0]*a[i][1]
        cnt += a[i][1]
print(sum)
Buggy python submission (verdict: Runtime Error):
8 20

Fixed submission:
a, b = map(int, input().split())
if b%a == 0:
  print(a+b)
else:
  print(b-a)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [int(10000000000)]*100000
dp[0] = 0
cost = 0
for i in range(0, n):
  for j in range(1, k+1):
    if dp[i] > dp[i-j]+abs(h[i]-h[i-j]):
      dp[i] = dp[i-j]+abs(h[i]-h[i-j])
print(dp[n-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [int(10000000000)]*100000
dp[0] = 0
cost = 0
if k > len(h):
  k = len(h)
for i in range(0, n):
  for j in range(1, k+1):
    if dp[i] > dp[i-j]+abs(h[i]-h[i-j]):
      dp[i] = dp[i-j]+abs(h[i]-h[i-j])
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
import copy
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(m)]
dic = {}
q = p.copy()
q.sort(key=lambda x: x[1])
cnt = [0 for i in range(n+1)]
for i in range(m):
    cnt[q[i][0]] += 1
    dic[q[i][1]] = cnt[q[i][0]]
for i in range(m):
    print(str(p[i][0]).zfill(6)+str(dic[p[i][1]]).zfill(6))

Fixed submission:
import copy
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(m)]
dic = {}
q = copy.copy(p)
q.sort(key=lambda x: x[1])
cnt = [0 for i in range(n+1)]
for i in range(m):
    cnt[q[i][0]] += 1
    dic[q[i][1]] = cnt[q[i][0]]
for i in range(m):
    print(str(p[i][0]).zfill(6)+str(dic[p[i][1]]).zfill(6))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(m)]
dic = {}
q = p.copy()
q.sort(key=lambda x: x[1])
cnt = [0 for i in range(n+1)]
for i in range(m):
    cnt[q[i][0]] += 1
    dic[q[i][1]] = cnt[q[i][0]]
for i in range(m):
    print(str(p[i][0]).zfill(6)+str(dic[p[i][1]]).zfill(6))

Fixed submission:
import copy
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(m)]
dic = {}
q = copy.copy(p)
q.sort(key=lambda x: x[1])
cnt = [0 for i in range(n+1)]
for i in range(m):
    cnt[q[i][0]] += 1
    dic[q[i][1]] = cnt[q[i][0]]
for i in range(m):
    print(str(p[i][0]).zfill(6)+str(dic[p[i][1]]).zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(m)]
l = []
for i in range(m):
    l.append([i])
for i in range(m):
    l[i].append(p[i][1])
p.sort(key=lambda x: x[1])
cnt = [0 for i in range(n+1)]
for i in range(m):
    cnt[p[i][0]] += 1
    for j in range(m):
        if p[i][1] == l[j][1]:
            l[j].append(str(p[i][0]).zfill(6)+str(cnt[p[i][0]]).zfill(6))
            break
for i in range(m):
    print(l[i][2])

Fixed submission:
import copy
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(m)]
dic = {}
q = copy.copy(p)
q.sort(key=lambda x: x[1])
cnt = [0 for i in range(n+1)]
for i in range(m):
    cnt[q[i][0]] += 1
    dic[q[i][1]] = cnt[q[i][0]]
for i in range(m):
    print(str(p[i][0]).zfill(6)+str(dic[p[i][1]]).zfill(6))
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
flag = False
for i in range(len(s)):
    if s == t:
        flag =True
    s = s[-1] + s[::len(s)-1
if flag:
    print("Yes")
else:
    print("No")


Fixed submission:
s = input()
t = input()
flag = False
for i in range(len(s)):
    if s == t:
        flag =True
    s = s[-1] + s[0:len(s)-1]
if flag:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
for i in range(len(s)):
    if s[i] != t[-i-1]:
        flag = false
if flag:
    print("Yes")
else:
    print("No")

Fixed submission:
s = input()
t = input()
flag = False
for i in range(len(s)):
    if s == t:
        flag =True
    s = s[-1] + s[0:len(s)-1]
if flag:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
i = n
while 1:
  if i%n == 0 and i%2 ==0:
    print(i)
    break
  i += 1

Fixed submission:
n = int(input())
if n%2 == 0:
  print(n)
else:
  print(n*2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))
y = x.copy()
y.sort()
cen1 = y[(n-1)//2]
cen2 = y[n//2]
for i in range(n):
    if x[i] < y[n//2]:
        print(cen2)
    else:
        print(cen1)


Fixed submission:
import copy
n = int(input())
x = list(map(int, input().split()))
y = copy.copy(x)
y.sort()
cen1 = y[(n-1)//2]
cen2 = y[n//2]
for i in range(n):
    if x[i] < y[n//2]:
        print(cen2)
    else:
        print(cen1)
Buggy python submission (verdict: Runtime Error):
import bisect
import copy
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = a.copy()
b.pop()
if len(b) == 1:
    idx = 0
else:
    if abs(a[-1]/2 - b[bisect.bisect_left(b, a[-1]/2)]) < abs(a[-1]/2 - b[bisect.bisect_right(b, a[-1]/2)]):
        idx = bisect.bisect_left(b, a[-1]/2)
    else:
        idx = bisect.bisect_right(b, a[-1]/2)
print(a[-1], b[idx])


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
a = sorted(a)
ans = 0
for i in a:
    if abs(m/2-i) < abs(m/2-ans):
        ans = i
print(m, ans)
Buggy python submission (verdict: Runtime Error):
n, y = map(int, input().split())
ans = [-1, -1, -1]
for i in range(n+1):
  for j in range(n+1-x):
    k = n-i-j
    if i*10000+j*5000+k*1000 == y and k>=0:
      ans[0] = i
      ans[1] = j
      ans[2] = k
      break
print(ans)

Fixed submission:
n, y = map(int, input().split())
ans = [-1, -1, -1]
for i in range(n+1):
  for j in range(n+1-i):
    k = n-i-j
    if i*10000+j*5000+k*1000 == y and k>=0:
      ans[0] = i
      ans[1] = j
      ans[2] = k
      break
print(ans[0], ans[1], ans[2])
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
  p, q = map(int, input().split())
  a.append(p)
  b.append(q)
b.sort(reverse=1)
ans=0
m=max(a)
while(h>0 and len(b) != 0):
  if b[0] < m:
    break
  h-=b[0]
  b.pop(0)
  ans+=1
if h>0:
  ans+=ceil(h/m)
print(ans)

Fixed submission:
from math import ceil
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
  p, q = map(int, input().split())
  a.append(p)
  b.append(q)
b.sort(reverse=1)
ans=0
m=max(a)
for i in b:
  if i < m or h<=0:
    break
  h-=i
  ans+=1
if h>0:
  ans+=ceil(h/m)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
  p, q = map(int, input().split())
  a.append(p)
  b.append(q)
b.sort(reverse=1)
ans=0
m=max(a)
while(h>0 and len(b) != 0):
  if b[0] < m:
    break
  h-=b[0]
  b.pop(0)
  ans+=1
while(h>0):
  h-=m
  ans+=1
print(ans)

Fixed submission:
from math import ceil
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
  p, q = map(int, input().split())
  a.append(p)
  b.append(q)
b.sort(reverse=1)
ans=0
m=max(a)
for i in b:
  if i < m or h<=0:
    break
  h-=i
  ans+=1
if h>0:
  ans+=ceil(h/m)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
    s = int(input())
    a.append(s)
a.sort()
i = 0
cnt = 0
while i < n:
    j = i+1
    chk = 0
    while a[i] == a[j]:
        chk += 1
        j += 1
        if j >= n:
            break
    if chk%2 == 1:
        cnt += 1 
    i = j
print(cnt)

Fixed submission:
n = int(input())
a = []
for i in range(n):
    s = int(input())
    a.append(s)
a.sort()
i = 0
cnt = 0
while i < n:
    j = i+1
    chk = 1
    if j >= n:
        cnt += 1 
        break
    while a[i] == a[j]:
        chk += 1
        j += 1
        if j >= n:
            break
    if chk%2 == 1:
        cnt += 1 
    i = j
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = {}
for i in range(n):
    s = int(input())
    if s in a.keys():
        flag = False
    else:
        flag = True
    if flag:
        a[s] = 1
    else:
        if a[s] == 1:
            a[s] = 0
        else:
            a[s] = 1
print(sum(a.values()))


Fixed submission:
n = int(input())
a = []
for i in range(n):
    s = int(input())
    a.append(s)
a.sort()
i = 0
cnt = 0
while i < n:
    j = i+1
    chk = 1
    if j >= n:
        cnt += 1 
        break
    while a[i] == a[j]:
        chk += 1
        j += 1
        if j >= n:
            break
    if chk%2 == 1:
        cnt += 1 
    i = j
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = {}
for i in range(n):
    s = int(input())
    if s not in a.keys():
        a[s] = 1
    elif s in a.keys():
        if a[s] == 1:
            a[s] = 0
        else:
            a[s] = 1
print(sum(a.values()))


Fixed submission:
n = int(input())
a = []
for i in range(n):
    s = int(input())
    a.append(s)
a.sort()
i = 0
cnt = 0
while i < n:
    j = i+1
    chk = 1
    if j >= n:
        cnt += 1 
        break
    while a[i] == a[j]:
        chk += 1
        j += 1
        if j >= n:
            break
    if chk%2 == 1:
        cnt += 1 
    i = j
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
i = 0
x = 0
y = 0
while i < n:
    if x == 0:
        if a[i] == a[i+1]:
            x = a[i]
            i += 1
    elif y == 0:
        if a[i] == a[i+1]:
            y = a[i]
            i += 1
    i += 1
print(x*y)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
i = 0
x = 0
y = 0
while i < n-1:
    if x == 0:
        if a[i] == a[i+1]:
            x = a[i]
            i += 1
    elif y == 0:
        if a[i] == a[i+1]:
            y = a[i]
            i += 1
    i += 1
print(x*y)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
field = [[0 for j in range(w)] for i in range(h)]
#[y, x]
d = [[0, 1], [1, 0], [0, -1], [-1, 0]]
y, x = 0, 0
for i in range(n):
    cnt = a[i]
    while cnt > 0:
        for j in range(len(d)):
            if 0 <= y + d[j][0] and y + d[j][0] < h and 0 <= x + d[j][1] and x + d[j][1] < w:
                if field[y+d[j][0]][x+d[j][1]] == 0: 
                    dy, dx = d[j][0], d[j][1]
                    break
        field[y][x] = i+1
        y += dy
        x += dx
        cnt -= 1
for i in range(h):
    for j in range(w):
        print(field[i][j], end=' ')
    print()

Fixed submission:
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
field = [[0 for j in range(w)] for i in range(h)]
#[y, x]
d = [[0, 1], [1, 0], [0, -1], [-1, 0]]
y, x = 0, 0
if h == 1 and w == 1:
    print(1)
else:
    for i in range(n):
        cnt = a[i]
        while cnt > 0:
            for j in range(len(d)):
                if 0 <= y + d[j][0] and y + d[j][0] < h and 0 <= x + d[j][1] and x + d[j][1] < w:
                    if field[y+d[j][0]][x+d[j][1]] == 0: 
                        dy, dx = d[j][0], d[j][1]
                        break
            field[y][x] = i+1
            y += dy
            x += dx
            cnt -= 1
    for i in range(h):
        for j in range(w):
            print(field[i][j], end=' ')
        print()
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
s = []
e = []
for i in range(m):
    x, y = map(int, input().split())
    if x == 1:
        s.append(y)
    elif y == n:
        e.append(x)
s.sort()
e.sort()
flag = False
for i in s:
    for j in e:
        if i < j:
            break
        if i == j:
            flag = True
            break
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
n, m = map(int, input().split())
s = [0 for i in range(n)]
e = [0 for i in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    if x == 1:
        s[y] = 1
    elif y == n:
        e[x] = 1
flag = False
for i in range(n):
    if s[i] == 1 and e[i] == 1:
        flag = True
        break
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
s = []
e = []
for i in range(m):
    x, y = map(int, input().split())
    if x == 1:
        s.append(y)
    elif y == n:
        e.append(x)
flag = False
for i in s:
    for j in e:
        if i == j:
            flag = True
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
n, m = map(int, input().split())
s = [0 for i in range(n)]
e = [0 for i in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    if x == 1:
        s[y] = 1
    elif y == n:
        e[x] = 1
flag = False
for i in range(n):
    if s[i] == 1 and e[i] == 1:
        flag = True
        break
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
d = {}
for i in range(m):
    x, y = map(int, input().split())
    if x not in d.keys():
        d[x] = []
    d[x].append(y)
flag = False
for i in d.keys():
    if i == 1:
        l = d[i]
        for j in l:
            if j in d.keys():
                if n in d[j]:
                    flag = True
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
n, m = map(int, input().split())
s = [0 for i in range(n)]
e = [0 for i in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    if x == 1:
        s[y] = 1
    elif y == n:
        e[x] = 1
flag = False
for i in range(n):
    if s[i] == 1 and e[i] == 1:
        flag = True
        break
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a == 'H' and b == 'H':
    print('H')
elif a == 'H' and b == 'D':
    print('D')
elif a == 'D' and b == 'H':
    print('D')
elif a == 'D' and b == 'D':
    print('H')


Fixed submission:
a, b = map(str, input().split())
if a == 'H' and b == 'H':
    print('H')
elif a == 'H' and b == 'D':
    print('D')
elif a == 'D' and b == 'H':
    print('D')
elif a == 'D' and b == 'D':
    print('H')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
b = [False] * len(A)

for i in range(N):
  for j in range(N):
    if b[j] or i == j or A[i] > 500000:
      continue
    if A[j] % A[i] == 0:
      b[j] = True

# print(b)

print(len(tuple(filter(lambda x: x == False, b))))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
M = A[-1]
b = [True] * (M + 1)

count = 0
for i, a in enumerate(A):
  if not b[a]:
    continue
  for j in range(a, M+1, a):
    b[j] = False
  if i < N-1 and A[i+1] == a:
    continue
  count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
b = [False] * len(A)

for i in range(N):
  for j in range(N):
    if b[j] or i == j:
      continue
    if A[j] % A[i] == 0:
      b[j] = True

# print(b)

print(len(tuple(filter(lambda x: x == False, b))))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
M = A[-1]
b = [True] * (M + 1)

count = 0
for i, a in enumerate(A):
  if not b[a]:
    continue
  for j in range(a, M+1, a):
    b[j] = False
  if i < N-1 and A[i+1] == a:
    continue
  count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
  ans *= a
ans = -1 if ans > 10**18 else ans

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 1
big = 10**18
for a in A:
  if a == 0:
    ans = 0
    break
  if ans == -1:
    continue
  ans *= a
  if ans > big:
    ans = -1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
  ans *= a
ans = -1 if ans > 10**18 else ans

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 1
big = 10**18
for a in A:
  if a == 0:
    ans = 0
    break
  if ans == -1:
    continue
  ans *= a
  if ans > big:
    ans = -1

print(ans)