Buggy python submission (verdict: Time Limit Exceeded):
def solve(way, height, n):
  ss = set()
  for a,b in way:
    if height[a-1] <= height[b-1]:
      ss = ss | {a}
    if height[a-1] >= height[b-1]:
      ss = ss | {b}
  return n - len(ss)


if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(solve(way, height, n))


Fixed submission:
def solve(way, height, n):
  ss = []
  for a,b in way:
    if height[a-1] <= height[b-1]:
      ss.append(a)
    if height[a-1] >= height[b-1]:
      ss.append(b)
  return n - len(set(ss))


if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(solve(way, height, n))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(way, height, n):
  ans = [i for i in range(n)]
  for a,b in way:
    if height[a-1] == height[b-1]:
      remove_1 = a-1
      remove_2 = b-1
      if remove_1 in ans:
        ans.remove(a-1)
      if remove_2 in ans:
        ans.remove(b-1)
    else:
      remove_idx = a if height[a-1] < height[b-1] else b
      remove_idx = remove_idx -1
      if remove_idx in ans:
        ans.remove(remove_idx)
  return len(ans)
 
 
if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(solve(way, height, n))

Fixed submission:
def solve(way, height, n):
  ss = []
  for a,b in way:
    if height[a-1] <= height[b-1]:
      ss.append(a)
    if height[a-1] >= height[b-1]:
      ss.append(b)
  return n - len(set(ss))


if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(solve(way, height, n))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(way, height, n):
  ss = set()
  for a,b in way:
    if height[a-1] == height[b-1]:
      ss = ss | {a,b}
    else:
      remove_idx = a if height[a-1] < height[b-1] else b
      ss = ss | {remove_idx}
  return n - len(ss)


if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(solve(way, height, n))


Fixed submission:
def solve(way, height, n):
  ss = []
  for a,b in way:
    if height[a-1] <= height[b-1]:
      ss.append(a)
    if height[a-1] >= height[b-1]:
      ss.append(b)
  return n - len(set(ss))


if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(solve(way, height, n))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(way, height, n):
  ans = [i for i in range(n)]
  for a,b in way:
    if height[a-1] == height[b-1]:
      remove_1 = a-1
      remove_2 = b-1
      if remove_1 in ans:
        ans.remove(a-1)
      if remove_2 in ans:
        ans.remove(b-1)
    else:
      remove_idx = a if height[a-1] < height[b-1] else b
      remove_idx = remove_idx -1
      if remove_idx in ans:
        ans.remove(remove_idx)
  return len(ans)


if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(solve(way, height, n))


Fixed submission:
def solve(way, height, n):
  ss = []
  for a,b in way:
    if height[a-1] <= height[b-1]:
      ss.append(a)
    if height[a-1] >= height[b-1]:
      ss.append(b)
  return n - len(set(ss))


if __name__ == "__main__":
  n,m = map(int, input().split())
  height = [int(i) for i in input().split()]
  way = [tuple(map(int, input().split())) for i in range(m)]
  print(solve(way, height, n))