Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
x,n = map(int, input().split())
l = map(lambda t : int(t)-x, input().split())
p = [0]
p.extend( sorted(map(abs,l)))
for i in range(n//2+1):
  if not ( p[2*i+1] == i ):
    if i in l:
      print(x-i)
    else:
      print(x+i)
    break

Fixed submission:
x,n,*p=map(int,open(0).read().split())
print(min({*range(999)}-{*p},key=lambda y:abs(y-x)))

Buggy python submission (verdict: Runtime Error):
x,n = map(int, input().split())
l = map(lambda t : int(t)-x, input().split())
p = [0]
p.extend( sorted(map(abs,l)))
for i in range(n//2+1):
  if not ( p[2*i] == p[2*i+1] == i ):
    if i in l:
      print(x+i)
    else:
      print(x-i)
    break

Fixed submission:
x,n,*p=map(int,open(0).read().split())
print(min({*range(999)}-{*p},key=lambda y:abs(y-x)))

Buggy python submission (verdict: Runtime Error):
x,n = map(int, input().split())
l = map(lambda t : int(t)-x, input().split())
p = sorted(map(abs,l))
for i in range(n//2+1):
    if not ( p[i] == p[i+1] ==i ):
        if -i in l:
            print(x+i)
        else:
            print(x-i)

Fixed submission:
x,n,*p=map(int,open(0).read().split())
print(min({*range(999)}-{*p},key=lambda y:abs(y-x)))

Buggy python submission (verdict: Runtime Error):
import functools as ft
x,n = map(int, input().split())
l = map(lambda t : int(t)-x, input().split())
p = sorted(map(abs,l))
for i in range((n//2)+1):
    if not ( p[i] == p[i+1] ==i ):
        if -i in l:
            print(x+i)
        else:
            print(x-i)

Fixed submission:
x,n,*p=map(int,open(0).read().split())
print(min({*range(999)}-{*p},key=lambda y:abs(y-x)))

Buggy python submission (verdict: Runtime Error):
import functools as ft
x,n = map(int, input().split())
l = map(lambda t : int(t)-x, input().split())
p = sorted(map(abs,l))
for i in range(n/2):
    if not ( p[i] == p[i+1] ==i ):
        if -i in l:
            print(x+i)
        else:
            print(x-i)

Fixed submission:
x,n,*p=map(int,open(0).read().split())
print(min({*range(999)}-{*p},key=lambda y:abs(y-x)))
Buggy python submission (verdict: Time Limit Exceeded):
_,*p=map(int,open(0).read().split())
i=0
p.sort()
while(len(p)!=0):
  t=p[0]
  p=[m if m!=t else 0 for m in p[1:] if m%t!=0 or m==t ]
  if 0 in p:p=[i for i in p if i!=0]
  else:i+=1
print(i)

Fixed submission:
M=10**6+1
_,*l=map(int,open(0).read().split())
a=[0]*M
for i in sorted(l):
  a[i]+=1
  if a[i]==1:
    for j in range(2*i,M,i): a[j]+=2
print(a.count(1))

Buggy python submission (verdict: Runtime Error):
_,*p=map(int,open(0).read().split())
i=0
p.sort()
while(len(p)!=0):
  t=p[0]
  p=[m if m!=t else 0 for m in p[1:] if m%t!=0 or m==t ]
  if 0 in p:
    p=[i for i in p if i!=0]
  else:i+=1
print(len(q))

Fixed submission:
M=10**6+1
_,*l=map(int,open(0).read().split())
a=[0]*M
for i in sorted(l):
  a[i]+=1
  if a[i]==1:
    for j in range(2*i,M,i): a[j]+=2
print(a.count(1))

Buggy python submission (verdict: Time Limit Exceeded):
_,*p=map(int,open(0).read().split())
q=[]
while(len(p)!=0):
  t=p[0]
  q=[m for m in q if m%t!=0]
  p=[m if m!=t else 0 for m in p[1:] if m%t!=0 or m==t ]
  if 0 in p:
    p=[i for i in p if i!=0]
  else:q+=[t]
print(len(q))

Fixed submission:
M=10**6+1
_,*l=map(int,open(0).read().split())
a=[0]*M
for i in sorted(l):
  a[i]+=1
  if a[i]==1:
    for j in range(2*i,M,i): a[j]+=2
print(a.count(1))
Buggy python submission (verdict: Runtime Error):
a,b=map(input().split())
print(a*b)

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

if __name__ == "__main__":
  for line in sys.stdin:
    anis, legs = line.split(' ')
    if legs % 2 == 1 or legs > anis * 4 or legs < anis * 2:
      print("No")
    else:
      print("Yes")
      
          

Fixed submission:
import sys

if __name__ == "__main__":
    for line in sys.stdin:
        anis, legs = map(int, line.split(' '))
        if legs % 2 == 1 or legs > anis * 4 or legs < anis * 2:
            print("No")
        else:
            print("Yes")
Buggy python submission (verdict: Runtime Error):
e = 10 ** 18
n = int(input())
arr = [int(i) for i in input().split()]
ans, flag = [1,1]
if 0 in arr:
  print('0')
else:
  for i in arr:
  	ans = ans * i
  	if ans > e:
    	print('-1')
    	flag = 0
    	break
if flag == 1:
  print(ans)

Fixed submission:
def solve():
    e = 10 ** 18
    n = int(input())
    arr = [int(i) for i in input().split()]
    ans, flag = [1,1]
    if 0 in arr:
      	return 0
    for i in arr:
        ans = ans * i
        if ans > e:
            return -1
    return ans
print(solve())
Buggy python submission (verdict: Runtime Error):
int A=input()
int B=input()

print(A*B)

Fixed submission:
a, b = map(int, input().split())
print(a*b)
Buggy python submission (verdict: Runtime Error):
import sys
N = input()
a = list(map(int, input().split()))

if 0 in a:
    print(0)
    sys.exit()

b=1
for i in range(0,N):
    b *= a[i]
    if b > 1000000000000000000:
        print(-1)
        sys.exit

print(b)

Fixed submission:
import sys
N = int(input())
a = list(map(int, input().split()))

if 0 in a:
    print(0)
    sys.exit()

b=1
for i in range(0,N):
    b *= a[i]
    if b > 1000000000000000000:
        print(-1)
        sys.exit()

print(b)
Buggy python submission (verdict: Runtime Error):
a, b = input().split()
c=int(b*100)
a2=int(a)
print(int(a2*c/100))

Fixed submission:
a, b = input().split()
b=float(b)
c=int(b*100+0.1)
a=int(a)
d=str(a*c)
if len(d)<=2:
    print(0)
else:
    print(d[:-2])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
 
def divisor(N):
    from math import sqrt
    D = []
    for i in range(1, int(sqrt(N)) + 1):
        if N % i == 0:
          D.append(i)
          D.append(N // i)
 
    return list(set(D))
 
 
count = 0
A_set = set(A)
A_dict = {a: 0 for a in A}
for a in A:
    A_dict[a] += 1
    
for a in A:
    a_div = set(divisor(a)) - {a}
    if len(a_div - A_set) == len(a_div):
        if A_dict[a] == 1:
            count += 1
 
print(count)

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

A_max = max(A)
dp = [True] * (A_max + 1)
count = 0
A_f = {a: 0 for a in A}
for a in A:
    A_f[a] += 1

for a in A:
    if dp[a]:
        for i in range(1, A_max + 1):
            if a * i > A_max:
                break
            dp[a * i] = False
        if A_f[a] == 1:
            count += 1

print(count)

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

def divisor(N):
    from math import sqrt
    D = []
    for i in range(1, int(sqrt(N)) + 1):
        if N % i == 0:
          D.append(i)
          D.append(N // i)

    return list(set(D))


count = 0
A_set = set(A)
A_dict = {a: 0 for a in A}
for a in A:
    A_dict[a] += 1
    
for a in A:
    a_div = set(divisor(a)) - {a}
    if len(a_div - A_set) == len(a_div):
        if A_dict[a] == 1:
            count += 1

print(count)

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

A_max = max(A)
dp = [True] * (A_max + 1)
count = 0
A_f = {a: 0 for a in A}
for a in A:
    A_f[a] += 1

for a in A:
    if dp[a]:
        for i in range(1, A_max + 1):
            if a * i > A_max:
                break
            dp[a * i] = False
        if A_f[a] == 1:
            count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from operator import mul

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

result = reduce(mul, A)
print(result if result <= 10**18 else -1)

Fixed submission:
"""
from functools import reduce
from operator import mul

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

result = reduce(mul, A)
print(result if result <= 10**18 else -1)
"""
import sys

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

result = 1
for a in A:
    result *= a
    if result > 10**18:
        print(-1)
        sys.exit()
else:
    print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from operator import mul

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

result = reduce(mul, A)
print(result if result <= 10**18 else -1)

Fixed submission:
"""
from functools import reduce
from operator import mul

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

result = reduce(mul, A)
print(result if result <= 10**18 else -1)
"""
import sys

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

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

result = 0
for i in range(60):
    on = sum([(1 << i) & a for a in A]) >> i
    result += (on * (N - on)) << i
    result %= ((10**9) + 7)

print(result)


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

result = 0
for i in range(60):
    target = 1 << i
    on = sum([target & a for a in A]) >> i
    result += (on * (N - on)) << i
    result %= ((10**9) + 7)

print(result)

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

each_bit_sum = [{"0": 0, "1": 0} for _ in range(62)]
result = 0
for a in A:
    for i, b in enumerate(format(a, "b").zfill(62)[::-1]):
        each_bit_sum[i][b] += 1

for i, b in enumerate(each_bit_sum):
    result += ((b["0"] * b["1"]) * (2**i)) % ((10**9) + 7)

print(result % ((10**9) + 7))


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

result = 0
for i in range(60):
    target = 1 << i
    on = sum([target & a for a in A]) >> i
    result += (on * (N - on)) << i
    result %= ((10**9) + 7)

print(result)
Buggy python submission (verdict: Runtime Error):
import sequtils, strutils


if isMainModule:
  var
    n = stdin.readLine.parseInt
    h = stdin.readLine.split.map(parseInt)
    dp: array[1..100000, int]

  for i in 1..n:
    for j in 1..2:
      if i + j > n:
        break
      elif dp[i+j] > min(dp[i] + abs(h[i-1] - h[i+j-1])) or dp[i+j] == 0:
        dp[i+j] = min(dp[i] + abs(h[i-1] - h[i+j-1]))

  echo dp[n]


Fixed submission:
n = int(input())
h = list(map(int, input().split()))
dp = [float("inf")] * (100000+1)

dp[1] = 0
for i in range(1, 100000+1):
    for j in range(1, 3):
        if i + j > n:
            break
        elif dp[i+j] > dp[i] + abs(h[i-1] - h[i+j-1]):
            dp[i+j] = dp[i] + abs(h[i-1] - h[i+j-1])

print(dp[n])
Buggy python submission (verdict: Runtime Error):
N = int(input())

base = ["3", "5", "7"]
nums = ["3", "5", "7"]
temp = []
x = 0

while 1:
    for num in nums[(3**x)-1:]:
        for b in base:
            temp.append(b + num)
    nums.extend(temp)
    
    x += 1
    if int(temp[-1]) > 10**9:
        break
    temp = []

target = []
for n in set(nums):
    if "7" in n and "5" in n and "3" in n:
        target.append(int(n))

count = 0
target.sort()
for n in target.:
    if int(n) < N:
        count += 1

print(count)

Fixed submission:
N = int(input())

base = ["3", "5", "7"]
nums = ["3", "5", "7"]
temp = []
x = 0

while 1:
    for num in nums[(3**x)-1:]:
        for b in base:
            temp.append(b + num)
    nums.extend(temp)
    
    x += 1
    if int(temp[-1]) > 10**9:
        break
    temp = []

target = []
for n in set(nums):
    if "7" in n and "5" in n and "3" in n:
        target.append(int(n))

count = 0
for n in target:
    if n <= N:
        count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
import sys

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

for i in range(int(math.sqrt(M))+1, 1, -1):
    if M % i == 0:
        if M >= N*i:
            print(i)
            sys.exit()

Fixed submission:
import sys
import math
Input = sys.stdin.readline
 
N, M = map(int, Input().split())
D = []
 
for i in range(int(math.sqrt(M)), 0, -1):
    if M % i == 0:
      D.append(i)
      D.append(M // i)

D.sort(reverse=True)
for d in D:
    if M >= N*d:
        print(d)
        break

Buggy python submission (verdict: Runtime Error):
import sys
Input = sys.stdin.readline

N, M = map(int, Input().split())

for i in range(int(math.sqrt(M))+1, 1, -1):
    if M % i == 0:
        if M >= N*i:
            print(i)
            sys.exit()

Fixed submission:
import sys
import math
Input = sys.stdin.readline
 
N, M = map(int, Input().split())
D = []
 
for i in range(int(math.sqrt(M)), 0, -1):
    if M % i == 0:
      D.append(i)
      D.append(M // i)

D.sort(reverse=True)
for d in D:
    if M >= N*d:
        print(d)
        break
Buggy python submission (verdict: Runtime Error):
5 3 6 8
-10 3 1 5 -100
100 6 14

Fixed submission:
N, M, X, Y = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
accept = False

x_max = max(x)
y_min = min(y)
if X < Y:
    z = [i for i in range(X+1, Y+1)]
    
    for i in z:
        if x_max < i and i <= y_min:
            accept = True
            break
if accept:
    print("No War")
else:
    print("War")
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

N, X = [int(c) for c in input().split()]
x = [int(c) for c in input().split()]

if N == 1:
    print(abs(x[0] - X))
else:
    x.append(X)
    x.sort()
    print(x)
    x = [n - x[0] for n in x]
    print(x)
    D = reduce(math.gcd, x)
    print(D)

Fixed submission:
#import math
from functools import reduce

N, X = [int(c) for c in input().split()]
x = [int(c) for c in input().split()]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

if N == 1:
    print(abs(x[0] - X))
else:
    x.append(X)
    x.sort()
    x = [n - x[0] for n in x]
    D = reduce(gcd, x)
    print(D)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

N, X = [int(c) for c in input().split()]
x = [int(c) for c in input().split()]

if N == 1:
    print(x[0] - X)
else:
    x.append(X)
    x.sort()
    x = [n - x[0] for n in x]
    D = reduce(math.gcd, x)
    print(D)

Fixed submission:
#import math
from functools import reduce

N, X = [int(c) for c in input().split()]
x = [int(c) for c in input().split()]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

if N == 1:
    print(abs(x[0] - X))
else:
    x.append(X)
    x.sort()
    x = [n - x[0] for n in x]
    D = reduce(gcd, x)
    print(D)
Buggy python submission (verdict: Runtime Error):
if S[0] == "A" and S[2:-1].count("C") == 1:
    i =  S.index("C")
    S = S[1:i] + S[i+1:]
    if S.islower():
        print("AC")
    else:
        print("WA")
else:
        print("WA")

Fixed submission:
S = input()
accept = False

if S[0] == "A" and S[2:-1].count("C") == 1:
    i =  S.index("C")
    S = S[1:i] + S[i+1:]
    if S.islower():
        accept = True

if accept:
    print("AC")

else:
    print("WA")
Buggy python submission (verdict: Runtime Error):
import statistics

N = int(input())
A = [int(c) for c in input().split()]
A = [abs(n - (b+i+1)) for i, n in enumerate(A)]

b = int(statistics.median(A))
print(sum([abs(n - b) for n in A]))

Fixed submission:
import statistics

N = int(input())
A = [int(c) for c in input().split()]
A = [n - (i+1) for i, n in enumerate(A)]

b = int(statistics.median(A))
print(sum([abs(n - b) for n in A]))
Buggy python submission (verdict: Runtime Error):
H, W = list(map(int, input().split()))
s = [[c for c in input()] for _ in range(H)]
accept = True

def dfs(x, y, count):
    if  x < 0 or W <= x or y < 0 or H <= y:
        return count - 1
    elif s[y][x] != "#":
        return count - 1
    else:
        s[y][x] = "."
        return max(dfs(x-1, y, count+1), dfs(x+1, y, count+1), dfs(x, y-1, count+1), dfs(x, y+1, count+1))

for y in range(H):
    for x in range(W):
        if s[y][x] != "#":
            continue
        elif dfs(x, y, 0) == 0:
            accept = False

if accept:
    print("Yes")
else:
    print("No")

Fixed submission:
import sys
sys.setrecursionlimit(100000)

H, W = list(map(int, input().split()))
s = [[c for c in input()] for _ in range(H)]
accept = True

def dfs(x, y, count):
    if  x < 0 or W <= x or y < 0 or H <= y:
        return count - 1
    elif s[y][x] != "#":
        return count - 1
    else:
        s[y][x] = "."
        return max(dfs(x-1, y, count+1), dfs(x+1, y, count+1), dfs(x, y-1, count+1), dfs(x, y+1, count+1))

for y in range(H):
    for x in range(W):
        if s[y][x] != "#":
            continue
        elif dfs(x, y, 0) == 0:
            accept = False

if accept:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import collections

N = int(input())
A = list(map(int, input().split()))
A_ = [0]
count = 0

def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)

for a in A:
    A_.append(a+A_[-1])

for v in collections.Counter(A_).values():
    if v > 1:
        count += factorial(v-1)

print(count)

Fixed submission:
import collections

N = int(input())
A = list(map(int, input().split()))
A_ = [0]
count = 0

for a in A:
    A_.append(a+A_[-1])

for v in collections.Counter(A_).values():
        count += sum([i for i in range(1, v)])

print(count)

Buggy python submission (verdict: Runtime Error):
import collections

N = int(input())
A = list(map(int, input().split()))
A_ = [0]
count = 0

def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)

for a in A:
    A_.append(a+A_[-1])

for v in collections.Counter(A_).values():
    if v-1 != 0:
        count += factorial(v-1)

print(count)

Fixed submission:
import collections

N = int(input())
A = list(map(int, input().split()))
A_ = [0]
count = 0

for a in A:
    A_.append(a+A_[-1])

for v in collections.Counter(A_).values():
        count += sum([i for i in range(1, v)])

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

A, B, K = map(int, Input().split())
N = [n for n in range(A, B+1) if n < A+K or n > B-K]
for n in N:
    print(n)

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

A, B, K = map(int, Input().split())

if K < ((B-A) // 2) + 1:
    for i in range(K):
        print(A+i)
    for i in range(K):
        print(B-K+i+1)
else:
    for n in range(A, B+1):
        print(n)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, M = [int(c) for c in input().split()]
F = np.zeros((N+2, M+2), dtype="int8")
C = F.copy()
c = np.ones((N, M), dtype="int8")
C[1:-1, 1:-1] += c

F[:-1, :] += C[1:, :]
F[1:, :] += C[:-1, :]
F[:, :-1] += C[:, 1:]
F[:, 1:] += C[:, :-1]
F[:-1, 1:] += C[1:, :-1]
F[1:, :-1] += C[:-1, 1:]
F[:-1, :-1] += C[1:, 1:]
F[1:, 1:] += C[:-1, :-1]

print(np.sum(np.where(F[1:-1, 1:-1] % 2, 0, 1)))

Fixed submission:
N, M = [int(c) for c in input().split()]

if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(M+N - 3)
else:
    print((M-2) * (N-2))

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

N, M = [int(c) for c in input().split()]
F = np.zeros((N+2, M+2))
C = F.copy()
c = np.ones((N, M))
C[1:-1, 1:-1] += c

F[:-1, :] += C[1:, :]
F[1:, :] += C[:-1, :]
F[:, :-1] += C[:, 1:]
F[:, 1:] += C[:, :-1]
F[:-1, 1:] += C[1:, :-1]
F[1:, :-1] += C[:-1, 1:]
F[:-1, :-1] += C[1:, 1:]
F[1:, 1:] += C[:-1, :-1]

print(np.sum(np.where(F[1:-1, 1:-1] % 2, 0, 1)))

Fixed submission:
N, M = [int(c) for c in input().split()]

if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(M+N - 3)
else:
    print((M-2) * (N-2))

Buggy python submission (verdict: Runtime Error):
N, M = [int(c) for c in input().split()]
F = np.zeros((N+2, M+2))
C = F.copy()
c = np.ones((N, M))
C[1:-1, 1:-1] += c

F[:-1, :] += C[1:, :]
F[1:, :] += C[:-1, :]
F[:, :-1] += C[:, 1:]
F[:, 1:] += C[:, :-1]
F[:-1, 1:] += C[1:, :-1]
F[1:, :-1] += C[:-1, 1:]
F[:-1, :-1] += C[1:, 1:]
F[1:, 1:] += C[:-1, :-1]

print(np.sum(np.where(F[1:-1, 1:-1] % 2, 0, 1)))

Fixed submission:
N, M = [int(c) for c in input().split()]

if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(M+N - 3)
else:
    print((M-2) * (N-2))
Buggy python submission (verdict: Runtime Error):
S = input()
ls = len(S)

def dfs(i):
    if i == ls:
        return True
    elif S[i: i+5] == "dream" or S[i: i+5] == "erase" or S[i: i+6] == "eraser" or S[i: i+7] == "dreamer":
        return dfs(i+5) or dfs(i+6) or dfs(i+7)

    return False

if dfs(0):
    print("YES")
else:
    print("NO")

Fixed submission:
S = input()[::-1]
i = 0
ls = len(S)
accept = True

while ls > i:
    if S[i: i+5] == "maerd" or S[i: i+5] == "esare":
        i += 5
    elif S[i: i+6] == "resare":
        i += 6
    elif S[i: i+7] == "remaerd":
        i += 7
    else:
        accept = False
        break

if accept:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
mult = 1

for i in range(N):
  mult *= a[i]
if mult > 10**18:
  print(-1)
else:
  print(mult)

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

if 0 in A:
  print(0)
  exit()
for a in A:
  mult *= a
  if mult > 1e18:
    print(-1)
    exit()
print(mult)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n, m = map(int, input().split()) #n: 展望台の数, m: 道の数
height = list(map(int, input().split())) #高さリスト。nコある。
path = [list(map(int, input().split())) for _ in range(m)] #道リスト。
good_tower = 0 #解答

for i in range(n): #各展望台について.i+1の周辺をサーチ。
  h_i = height[i]
  con_num = [] #隣接する台番号を格納
  for j in range(m): #全pathをサーチ
    if i+1 in path[j]:
      p = copy.deepcopy(path[j])
      p.remove(i+1)
      c = p[0]
      con_num.append(c)
  if len(con_num) == 0:
    good_tower += 1
  else:
    con_num = list(set(con_num))
    cl = len(con_num)
    h_near_l = []
    for k in range(cl):
      t_num = con_num[k] #隣接台のナンバー
      h_near = height[t_num-1]
      h_near_l.append(h_near)
    if all(h_i > h_near_l[i] for i in range(cl)):
      good_tower += 1
      
print(good_tower)

Fixed submission:
n, m = map(int, input().split()) #n: 展望台の数, m: 道の数
height = list(map(int, input().split())) #高さリスト.nコある.
ans_set = set(range(1, n+1))

for i in range(m):
  a, b = map(int, input().split())
  if height[a-1] >= height[b-1]:
    ans_set.discard(b)	#setのdiscardは存在しない場合は何もしない.
  if height[a-1] <= height[b-1]:
    ans_set.discard(a)
    
print(len(ans_set))

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n, m = map(int, input().split()) #n: 展望台の数, m: 道の数
height = list(map(int, input().split())) #高さリスト。nコある。
path = [list(map(int, input().split())) for _ in range(m)] #道リスト。
good_tower = 0 #解答

for i in range(n): #各展望台について.i+1の周辺をサーチ。
  h_i = height[i]
  con_num = [] #隣接する台番号を格納
  for j in range(m): #全pathをサーチ
    if i+1 in path[j]:
      p = copy.deepcopy(path[j])
      p.remove(i+1)
      c = p[0]
      con_num.append(c)
  if len(con_num) == 0:
    good_tower += 1
  else:
    con_num = list(set(con_num))
    cl = len(con_num)
    h_near_l = []
    for k in range(cl):
      t_num = con_num[k] #隣接台のナンバー
      h_near = height[t_num-1]
      h_near_l.append(h_near)
    if all(h_i > h_near_l[i] for i in range(cl)):
      good_tower += 1
      
print(good_tower)

Fixed submission:
n, m = map(int, input().split()) #n: 展望台の数, m: 道の数
height = list(map(int, input().split())) #高さリスト.nコある.
ans_set = set(range(1, n+1))

for i in range(m):
  a, b = map(int, input().split())
  if height[a-1] >= height[b-1]:
    ans_set.discard(b)	#setのdiscardは存在しない場合は何もしない.
  if height[a-1] <= height[b-1]:
    ans_set.discard(a)
    
print(len(ans_set))
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())

def floor(t):
  return int(t)

max = 0 
for x in range(N+1):
  y = floor(A*x/B)-A*floor(x/B)
  if y > max:
    max = y
    
print(max)

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

def g(x):
  return int(A*x/B)-A*int(x/B)

print(g(min(B-1, N)))

Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())

def floor(t):
  return int(t)

max = 0 
for x in range(1, N+1):
  y = floor(A*x/B)-A*floor(x/B)
  if y > max:
    max = y
    
print(max)

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

def g(x):
  return int(A*x/B)-A*int(x/B)

print(g(min(B-1, N)))