Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
#引数にリストを入れるとその最小公倍数が返ってくる
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
n=int(input())
A=list(map(int,input().split()))

k=1
for i in A:
  k=lcm(k,i)

def f(n):
  return sum(list(map(lambda x:n%x,A)))
print(f(k-1))

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

m =1
for i in range(len(mods)):
  m *= mods[i]

sums = 0
for i in range(len(mods)):
  sums += (m-1) %mods[i]

print(sums)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
#引数にリストを入れるとその最小公倍数が返ってくる
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
  return reduce(lcm_base, numbers,1)

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

def f(n):
  return sum(list(map(lambda x:n%x,A)))
print(f(lcm_list(A)-1))

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

m =1
for i in range(len(mods)):
  m *= mods[i]

sums = 0
for i in range(len(mods)):
  sums += (m-1) %mods[i]

print(sums)

Buggy python submission (verdict: Runtime Error):
import math
import functools
def lcm(x,y):
  return(x*y)//math.gcd(x,y)

n=int(input())
A=list(map(int,input().split()))
num=functools.reduce(lcm,A)
def f(n):
  return sum(list(map(lambda x:n%x,A)))
print(f(num-1))

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

m =1
for i in range(len(mods)):
  m *= mods[i]

sums = 0
for i in range(len(mods)):
  sums += (m-1) %mods[i]

print(sums)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
def lcm(x,y):
  return(x*y)//math.gcd(x,y)

n=int(input())
A=list(map(int,input().split()))
num=reduce(lcm,A)
def f(n):
  return sum(list(map(lambda x:n%x,A)))
print(f(num-1))

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

m =1
for i in range(len(mods)):
  m *= mods[i]

sums = 0
for i in range(len(mods)):
  sums += (m-1) %mods[i]

print(sums)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
def lcm(x,y):
  return(x*y)//math.gcd(x,y)

n=int(input())
A=list(map(int,input().split()))
num=reduce(lcm,A)
ans=0
def f(n):
  return sum(list(map(lambda x:n%x,A)))
print(f(num-1))

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

m =1
for i in range(len(mods)):
  m *= mods[i]

sums = 0
for i in range(len(mods)):
  sums += (m-1) %mods[i]

print(sums)
Buggy python submission (verdict: Runtime Error):
while tmp > 0:
    sum += tmp % 10
    tmp /= 10

if n % sum == 0:
    print ("Yes")
else:
    print ("No")

Fixed submission:
n =int(input())

s=eval("+".join(str(n)))
if n % s ==0:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
while tmp > 0:
    sum += tmp % 10
    tmp /= 10

if n % sum == 0:
    print "Yes"
else:
    print "No"

Fixed submission:
n =int(input())

s=eval("+".join(str(n)))
if n % s ==0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
if n != 101:
  print((100**d)*n)
else:
  print((100**d)*(n+1))

Fixed submission:
d,n = map(int,input().split())

if n != 100:
  print((100**d)*n)
else:
  print((100**d)*(n+1))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())

def prime_factors(n):
  i = 2
  factors = []
  while i * i <= n:
    if n % i==0:
      n //= i
      factors.append(i)
    else:
      i += 1
  if n > 1:
    factors.append(n)
  return factors
A=list(map(lambda x:prime_factors(x).count(2) if x%2==0 else 0,list(map(int,input().split()))))
print(sum(A))

Fixed submission:
n = int(input())
nums = map(int,input().split())

count = 0
for i in nums:
  if i % 2 ==0:
    while i % 2 ==0:
      i /= 2
      count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
max_n = 100000
dp = [10000 for i in range(max_n)]
dp[0] = 0

for i in range(n+1):
  k = 1
  while k <= n:
    dp[i] = min(dp[i],dp[i-k]+1)
    k *=6
  k = 1
  while k <= n:
    dp[i] = min(dp[i],dp[i-k]+1)
    k*=9
print(dp[n])

Fixed submission:
n = int(input())
max_n = 100000
dp = [10000 for i in range(max_n+1)]
dp[0] = 0

for i in range(n+1):
  k = 1
  while k <= n:
    dp[i] = min(dp[i],dp[i-k]+1)
    k *=6
  k = 1
  while k <= n:
    dp[i] = min(dp[i],dp[i-k]+1)
    k*=9
print(dp[n])

Buggy python submission (verdict: Runtime Error):
n = int(input())
max_n = 10000
dp = [10000 for i in range(max_n)]
dp[0] = 0

for i in range(n+1):
  k = 1
  while i + k <= n:
    dp[i+k] = min(dp[i+k],dp[i]+1)
    k *=6
  k = 1
  while i + k <= n:
    dp[i+k] = min(dp[i+k],dp[i]+1)
    k*=9

print(dp[n])

Fixed submission:
n = int(input())
max_n = 100000
dp = [10000 for i in range(max_n+1)]
dp[0] = 0

for i in range(n+1):
  k = 1
  while k <= n:
    dp[i] = min(dp[i],dp[i-k]+1)
    k *=6
  k = 1
  while k <= n:
    dp[i] = min(dp[i],dp[i-k]+1)
    k*=9
print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

minc = 100000000

for i in range(len(s)):
  minc = min(minc,(s[0:i].count('W')+s[i:].count('E')))

print(minc)


Fixed submission:
n = int(input())
s = input()

nums = [s[1:].count('E')]
for i in range(1,n):
  tmp = nums[i-1]
  if s[i-1] == 'W':
    tmp  += 1
  if s[i] == 'E':
    tmp -= 1
  nums.append(tmp)

print(min(nums))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

minc = 100000000

for i in range(len(s)):
  minc = min(minc,(left_wrong = s[0:i].count('W')+s[i:].count('E')))

print(minc)


Fixed submission:
n = int(input())
s = input()

nums = [s[1:].count('E')]
for i in range(1,n):
  tmp = nums[i-1]
  if s[i-1] == 'W':
    tmp  += 1
  if s[i] == 'E':
    tmp -= 1
  nums.append(tmp)

print(min(nums))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

minc = 100000000

for i in range(len(s)):
  left_wrong = s[0:i].count('W')
  right_wrong = s[i:].count('E')
  minc = min(minc,(left_wrong+right_wrong))

print(minc)


Fixed submission:
n = int(input())
s = input()

nums = [s[1:].count('E')]
for i in range(1,n):
  tmp = nums[i-1]
  if s[i-1] == 'W':
    tmp  += 1
  if s[i] == 'E':
    tmp -= 1
  nums.append(tmp)

print(min(nums))
Buggy python submission (verdict: Runtime Error):
a,b,c,x,y=map(int,input().split())
print(min(x*

Fixed submission:
a,b,c,x,y=map(int,input().split())
print(min(x*a+y*b,2*x*c+b*max(0,y-x),2*y*c+a*max(0,x-y)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = list(map(int,input().split()))

for i in range(len(nums)):
  tmp_nums = sorted(nums[:i]+nums[i+1:])
  print(tmp_nums[len(tmp_nums)//2])

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
y = sorted(x)
a = y[n//2-1]
b = y[n//2]
for i in range(n):
  if x[i] <= a:
    print(b)
  else:
    print(a)
Buggy python submission (verdict: Runtime Error):
a,b,k = map(int,input().split())
num=[i for i in range(a,b+1)]
num = sorted(set(num[:k]+num[num.index(b-k+1) if b-k > 0 else -1:]))

for i in num:
  print(i)



Fixed submission:
a,b,k = map(int,input().split())
num=[]

if b-a >= k:
  for i in range(a,a+k):
    num.append(i)
  for i in range(b-k+1,b+1):
    num.append(i)
else:
  for i in range(a,b+1):
    num.append(i)

for i in sorted(set(num)):
  print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=[0]+list(map(int,input().split()))+[0]
diff=[abs(A[i]-A[i-1]) for i in range(1,len(A))]



for i in range(1,n+1):
  if i==n:
    print(sum(diff)-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))
    exit()
  elif A[i]<=A[i+1] and ((A[i]>0 and A[i+1]<0) or (A[i]<0 and A[i+1]>0)):
    print(sum(diff)-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))
  elif A[i]<=A[i+1]:
    print(sum(diff))
  else:
    print(sum(diff)-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))



Fixed submission:
n=int(input())
A=[0]+list(map(int,input().split()))+[0]
diff=[abs(A[i]-A[i-1]) for i in range(1,len(A))]
sums=sum(diff)

for i in range(1,n+1):
  # if i==n:
  #   print(sums-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))
  #   exit()
  # elif A[i]<=A[i+1] and ((A[i]>0 and A[i+1]<0) or (A[i]<0 and A[i+1]>0)):
  #   print(sums-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))
  # elif A[i]<=A[i+1]:
  #   print(sums)
  # else:
    print(sums-abs(A[i]-A[i+1])-abs(A[i-1]-A[i])+abs(A[i-1]-A[i+1]))
Buggy python submission (verdict: Time Limit Exceeded):
def is_prime(x):
  if x == 1:
    return False
  for i in range(2, x):
    if x % i == 0:
      return False
    if i * i>= x:
      break         #breakにしないと膨大な数字をいつまでも追いかけている
  return True

def check(l,r):
  count = 0
  for i in range(l,r+1,2):
    if is_prime(i) == True:
      if is_prime((i+1)//2) == True:
        count += 1
  return count


Q = int(input())

nums = []
for i in range(Q):
  l,r = map(int,input().split())
  nums.append(check(l,r))


for i in nums:
  print(i)



Fixed submission:
NMAX = 10**5+1

is_prime = [True]*NMAX
for i in range(2, NMAX):
    if is_prime[i]:
        for j in range(2*i, NMAX, i):
            is_prime[j] = False

sim_2017 = [0]*NMAX
for i in range(3, NMAX, 2):
    if is_prime[i] and is_prime[(i+1)//2]:
        sim_2017[i] += 1
for i in range(1, NMAX):
    sim_2017[i] += sim_2017[i-1]

q = int(input())
for _ in range(q):
    l, r = list(map(int, input().split()))
    ans = sim_2017[r] - sim_2017[l-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def is_prime(x):
    if x == 2:
        return 1
    elif x % 2 == 0:
        return 0
    else:
        return pow(2, x - 1, x) == 1

def check(l,r):
  count = 0
  for i in range(l,r+1,2):
    if is_prime(i) == True and is_prime((i+1)//2) == True:
      count += 1
  return count


Q = int(input())

nums = []
for i in range(Q):
  l,r = map(int,input().split())
  nums.append(check(l,r))


for i in nums:
  print(i)

Fixed submission:
NMAX = 10**5+1

is_prime = [True]*NMAX
for i in range(2, NMAX):
    if is_prime[i]:
        for j in range(2*i, NMAX, i):
            is_prime[j] = False

sim_2017 = [0]*NMAX
for i in range(3, NMAX, 2):
    if is_prime[i] and is_prime[(i+1)//2]:
        sim_2017[i] += 1
for i in range(1, NMAX):
    sim_2017[i] += sim_2017[i-1]

q = int(input())
for _ in range(q):
    l, r = list(map(int, input().split()))
    ans = sim_2017[r] - sim_2017[l-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def is_prime(x):
  if x == 1:
    return False
  for i in range(2, x):
    if x % i == 0:
      return False
    if i * i>= x:
      break         #breakにしないと膨大な数字をいつまでも追いかけている
  return True

def check(l,r):
  count = 0
  for i in range(l,r+1,2):
    if is_prime(i) == True and is_prime((i+1)//2) == True:
      count += 1
  return count


Q = int(input())

nums = []
for i in range(Q):
  l,r = map(int,input().split())
  nums.append(check(l,r))


for i in nums:
  print(i)

Fixed submission:
NMAX = 10**5+1

is_prime = [True]*NMAX
for i in range(2, NMAX):
    if is_prime[i]:
        for j in range(2*i, NMAX, i):
            is_prime[j] = False

sim_2017 = [0]*NMAX
for i in range(3, NMAX, 2):
    if is_prime[i] and is_prime[(i+1)//2]:
        sim_2017[i] += 1
for i in range(1, NMAX):
    sim_2017[i] += sim_2017[i-1]

q = int(input())
for _ in range(q):
    l, r = list(map(int, input().split()))
    ans = sim_2017[r] - sim_2017[l-1]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))

ans=0
value=[0]*len(B)
#Bより小さい値
B_s=[]
for i in B:
  tmp=0
  for j in A:
    if i > j:
      tmp+=1
  if tmp!=0:
    B_s.append(tmp)

k=0
for i in B:
  tmp=0
  for j in C:
    if j>i:
      tmp+=1
  if k<len(B_s):
    ans+=tmp*B_s[k]
    k+=1
print(ans)


Fixed submission:
from bisect import bisect_left,bisect_right
n=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))

ans=0

for i in B:
  sml_B = bisect_left(A,i)
  # print(i,"sml_B",sml_B)
  big_B = len(C)-bisect_right(C,i)
  # print(i,"big_B",big_B)
  ans+=sml_B*big_B
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()

for i in range(len(s)-len(t)+1):
  flag=True
  for j in range(len(t)):
    if s[i+j]==t[j] and s[i+j]=="?":
      continue
    else:
      flag=False
  if flag:
    s=s[:i]+t+s[i+len(t):]
    s=s.replace("?","a")
print(s if flag else "UNRESTORABLE")



Fixed submission:
s = input()
t = input()

if len(t)>len(s):
  print("UNRESTORABLE")
  exit()

ans = []

for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j] != t[j] and s[i+j]!='?':
      break
  else:
    ans.append((s[:i]+t+s[i+len(t):]).replace('?','a'))

if len(ans) == 0:
  print('UNRESTORABLE')
else:
  ans.sort()
  print(ans[0])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    tmp=4*n*h-N*h-N*n
    if tmp>0:
      if N*h*n%tmp==0:
        print(h,n,N*h*n//tmp)
        exit()

Fixed submission:
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    tmp=4*n*h-N*h-N*n
    if tmp>0:
      if N*h*n%tmp==0:
        print(h,n,N*h*n//tmp)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    tmp=4*n*h-N*h-N*n
    if tmp>0 and N*h*n%tmp==0:
      print(h,n,N*h*n//tmp)
      exit()

Fixed submission:
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    tmp=4*n*h-N*h-N*n
    if tmp>0:
      if N*h*n%tmp==0:
        print(h,n,N*h*n//tmp)
        exit()

Buggy python submission (verdict: Runtime Error):
N=int(input())
ans=4/n
for h in range(1,3501):
  for n in range(1,3501):
    tmp=4*h*n-N*h-N*n
    if tmp>0 and N*h*n%tmp==0:
      print(h,n,N*h*n//tmp)
      exit()

Fixed submission:
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    tmp=4*n*h-N*h-N*n
    if tmp>0:
      if N*h*n%tmp==0:
        print(h,n,N*h*n//tmp)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n = int(input())
nums = deque([])

for i in range(n):
  a = int(input())
  try:
    nums.remove(a)
  except ValueError:
    nums.append(a)

print(len(nums))



Fixed submission:
import collections
ans = 0
n = int(input())
nums = [int(input()) for i in range(n)]
con = collections.Counter(nums)

for i in con.values():
  if i % 2 != 0:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
A=Counter(list(map(int,input().split()))).most_common()
if A[0][0]==0:
  if A[0][1]==A[1][1]:
    max_num=A[1][0]
else:
  max_num=A[0][0]
kouho=[max_num-1,max_num,max_num+1]
cnts={max_num-1:0,max_num:0,max_num+1:0}
for i in A:
  if i[0]-1 in cnts:
    cnts[i[0]-1]+=i[1]
  if i[0] in cnts:
    cnts[i[0]]+=i[1]
  if i[0]+1 in cnts:
    cnts[i[0]+1]+=i[1]
print(max(cnts.values()))

Fixed submission:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
Cont=Counter(A)
Cont1=Counter(A)
for k,v in Cont.items():
  Cont1[k-1]+=v
  Cont1[k+1]+=v
print(Cont1.most_common()[0][1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
A = Counter(A).most_common()
ans = 0

for i,j in sorted(A,reverse=True):
  if j >=4 and ans ==0:
    ans = i*i
    break
  elif j >= 2 and ans == 0:
    ans = i
  elif j >= 2:
    ans *= i
    break
print(ans)
print(sorted(A,reverse=True))

Fixed submission:
from collections import Counter

n = int(input())
A = list(map(int,input().split()))
A = Counter(A).most_common()
ans = 0

for i,j in sorted(A,reverse=True):
  if j >=4 and ans ==0:
    ans = i*i
    break
  elif j >= 2 and ans == 0:
    ans = i
  elif j >= 2:
    ans *= i
    break
print(ans)

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

n = int(input())
A = list(map(int,input().split()))
A = [i for i in A if A.count(i) >= 2]
if len(A) == 0:
  print(0)
  exit()

if A.count(max(A)) >= 4:
  print(max(A)**2)
  exit()
elif 2<= A.count(max(A)) < 4:
  print(max(A)*A[bisect_left(A,max(A))-1])



Fixed submission:
from collections import Counter

n = int(input())
A = list(map(int,input().split()))
A = Counter(A).most_common()
ans = 0

for i,j in sorted(A,reverse=True):
  if j >=4 and ans ==0:
    ans = i*i
    break
  elif j >= 2 and ans == 0:
    ans = i
  elif j >= 2:
    ans *= i
    break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
T=[int(input()) for i in range(n)]
T = sorted(T,reverse=True)

a = T[0]
i =1
while True:
  if sum(map(lambda x:T[0]%x, T)) !=0:
    T[0] += a
  else:
    print(T[0])
    exit()
  i += 1

Fixed submission:
n = int(input())
T=[int(input()) for i in range(n)]


def euclid(a,b):
  r = a % b
  return euclid(b,r) if r else b

def lcm(a,b):
  return a * b //euclid(a,b)

num = T[0]
for i in range(1,n):
  num = lcm(num, T[i])
print(num)

Buggy python submission (verdict: Runtime Error):
n = int(input())
T=[int(input()) for i in range(n)]
T = sorted(T,reverse=True)

for i in range(2,100):
  if T[0] % T[1] !=0:
    if sum(map(lambda x:x/2, T)) !=0:
      T[0] = T[0]*i
  else:
    print(T[0])
    exit()


Fixed submission:
n = int(input())
T=[int(input()) for i in range(n)]


def euclid(a,b):
  r = a % b
  return euclid(b,r) if r else b

def lcm(a,b):
  return a * b //euclid(a,b)

num = T[0]
for i in range(1,n):
  num = lcm(num, T[i])
print(num)

Buggy python submission (verdict: Runtime Error):
n = int(input())
T=[int(input()) for i in range(n)]
T = sorted(T,reverse=True)

for i in range(2,100):
  if T[0] % T[1] !=0:
    if sum(map(lambda x:T/2, T)) !=0:
      T[0] = T[0]*i
  else:
    print(T[0])
    exit()


Fixed submission:
n = int(input())
T=[int(input()) for i in range(n)]


def euclid(a,b):
  r = a % b
  return euclid(b,r) if r else b

def lcm(a,b):
  return a * b //euclid(a,b)

num = T[0]
for i in range(1,n):
  num = lcm(num, T[i])
print(num)

Buggy python submission (verdict: Runtime Error):
n = int(input())
T=[int(input()) for i in range(n)]
T = sorted(T,reverse=True)

for i in range(2,100):
  if T[0] % T[1] !=0:
    T[0] = T[0]*i
  else:
    print(T[0])
    exit()

Fixed submission:
n = int(input())
T=[int(input()) for i in range(n)]


def euclid(a,b):
  r = a % b
  return euclid(b,r) if r else b

def lcm(a,b):
  return a * b //euclid(a,b)

num = T[0]
for i in range(1,n):
  num = lcm(num, T[i])
print(num)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
edges=[[]for i in range(n)]
visited=[False]*n
cnt=0
def dfs(u,cnt,visited):
  visited=visited[:]
  cnt=cnt
  visited[u]=True
  if visited[-1]==True:
    return cnt,visited
  cnt+=1
  for v in edges[u]:
    if visited[v]==False:
      dfs(v,cnt,visited)
  return cnt,visited

for i in range(m):
  a,b=map(int,input().split())
  edges[a-1].append(b-1)
  edges[b-1].append(a-1)

cnt,visited=dfs(0)
if visited[-1]==True and cnt==2:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Fixed submission:
n,m=map(int,input().split())
edges=[[]for i in range(n)]


for i in range(m):
  a,b=map(int,input().split())
  edges[a-1].append(b-1)
  edges[b-1].append(a-1)

for v in edges[-1]:
  if 0 in edges[v]:
    print('POSSIBLE')
    exit()
print('IMPOSSIBLE')

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
edges=[[]for i in range(n)]
visited=[False]*n
cnt=0
def dfs(u):
  global visited
  global cnt
  visited[u]=True
  if visited[-1]==True:
    return cnt,visited
  cnt+=1
  for v in edges[u]:
    if visited[v]==False:
      dfs(v)
  return cnt,visited

for i in range(m):
  a,b=map(int,input().split())
  edges[a-1].append(b-1)
  edges[b-1].append(a-1)

cnt,visited=dfs(0)
if visited[-1]==True and cnt==2:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Fixed submission:
n,m=map(int,input().split())
edges=[[]for i in range(n)]


for i in range(m):
  a,b=map(int,input().split())
  edges[a-1].append(b-1)
  edges[b-1].append(a-1)

for v in edges[-1]:
  if 0 in edges[v]:
    print('POSSIBLE')
    exit()
print('IMPOSSIBLE')

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
edges=[[]for i in range(n)]
visited=[False]*n
cnt=0
def dfs(u):
  global visited
  global cnt
  visited[u]=True
  if visited[-1]==True:
    return cnt,visited
  cnt+=1
  for v in edges[u]:
    if visited[v]==False:
      dfs(v)
  return visited,cnt

for i in range(m):
  a,b=map(int,input().split())
  edges[a-1].append(b-1)
  edges[b-1].append(a-1)

visit,cnt=dfs(0)
if visit[-1]==True and cnt==2:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Fixed submission:
n,m=map(int,input().split())
edges=[[]for i in range(n)]


for i in range(m):
  a,b=map(int,input().split())
  edges[a-1].append(b-1)
  edges[b-1].append(a-1)

for v in edges[-1]:
  if 0 in edges[v]:
    print('POSSIBLE')
    exit()
print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
class Node:
  def __init__(self,data):
    self.left=None
    self.right=None
    self.data=data

class BST:
  def __init__(self,num_list):
    self.root=None
    for node in num_list:
      self.insert(node)

  def insert(self,data):
    n = self.root
    if n == None:
      self.root=Node(data)
      return
    else:
      while True:
        entry=n.data
        if data<entry:
          if n.left is None:
            n.left=Node(data)
            return
        elif data > entry:
          if n.right is None:
            n.right=Node(data)
            return
          n=n.right
        else:
          n.data=data
          return
  def search(self,search):
    n = self.root
    if n is None:
      return None
    else:
      lst=[]
      lst.append(n)
      while len(lst)>0:
        node=lst.pop()
        if node.data==search:
          return node.data
        if node.left is not None:
          lst.append(node.left)
        if node.right is not None:
          lst.append(node.right)
      return False

n=int(input())
A=list(map(int,input().split()))
bst=BST(A)
B=[]
for i in range(n):
  B.append(bst.search(A[i]))
  B=B[::-1]
print(*B)


Fixed submission:
n=int(input())
A=list(input().split())
print(" ".join(A[::-2]+A[n%2::2]))

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


Fixed submission:
n=int(input())
A=list(input().split())
print(" ".join(A[::-2]+A[n%2::2]))
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
A=list(map(lambda x:x//400 if x<3200 else 8,A))
n_red=A.count(8)
red_exist=1 if len(n_red) else 0
red_only=1 if red_exist and list(set(A))[0]==8 else 0
n_min=len(set(A)) if not red_exist else len(set(A))-1
print(1 if red_only else n_min,n_min+n_red)


Fixed submission:
n=int(input())
A=list(map(int,input().split()))
A=list(map(lambda x:x//400 if x<3200 else 8,A))
n_red=A.count(8)
n_min=len(set(A))
n_8=1 if n_red else 0
print(1 if n_min==1 and list(set(A))[0]==8 else n_min-n_8,n_min+n_red-n_8)
Buggy python submission (verdict: Runtime Error):
n=int(input())
S=sorted([int(input()) for i in range(n)])
not_10=[i for i in S if i%10!=0]
sums=sum(S)
if sums%10!=0:
  print(sums)
else:
  print(sums-not_10[0])

Fixed submission:
n=int(input())
S=sorted([int(input()) for i in range(n)])
not_10=[i for i in S if i%10!=0]
sums=sum(S)
if sums%10!=0:
  print(sums)
else:
  print(sums-not_10[0] if not_10 else 0)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
ls={}
for i in range(n):
  a,b=map(int,input().split())
  if a not in ls:
    ls[a]=b
  else:
    ls[a]+=b
ls=sorted(ls.keys())
tmp=0
for i,j in ls.items():
  tmp+=j
  if k <= tmp:
    print(i)
    exit()

Fixed submission:
n,k=map(int,input().split())
ls={}
for i in range(n):
  a,b=map(int,input().split())
  if a not in ls:
    ls[a]=b
  else:
    ls[a]+=b
ls=sorted(ls.items())
tmp=0
for i,j in ls:
  tmp+=j
  if k <= tmp:
    print(i)
    exit()