Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
Graph = [[] for _ in range(N+1)]
is_good = [False] + [True] * N
seen = [True] + [False] * N

def dfs(cur):
    global Graph, seen, H
    seen[cur] = True
    for nex in Graph[cur]:
        if H[nex] >= H[cur]:
            is_good[cur] = False
        if seen[nex]:
            continue
        dfs(nex)


for _ in range(M):
    a, b = map(int, input().split())
    Graph[a].append(b)
    Graph[b].append(a)

for i in range(1, N+1):
    if not seen[i]:
        dfs(i)

print(is_good.count(True))

Fixed submission:
import sys
sys.setrecursionlimit(10**5 + 5)
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
Graph = [[] for _ in range(N+1)]
is_good = [False] + [True] * N
seen = [True] + [False] * N

def dfs(cur):
    global Graph, seen, H
    seen[cur] = True
    for nex in Graph[cur]:
        if H[nex] >= H[cur]:
            is_good[cur] = False
        if seen[nex]:
            continue
        dfs(nex)


for _ in range(M):
    a, b = map(int, input().split())
    Graph[a].append(b)
    Graph[b].append(a)

for i in range(1, N+1):
    if not seen[i]:
        dfs(i)

print(is_good.count(True))
Buggy python submission (verdict: Runtime Error):
import math
X = int(input())
is_prime = [False] * 2 + [True] * (X + 5)
prime_factors = {}
sup = int(math.sqrt(X)) + 5
ans = (0, 0)
# t := A - B
# A - B > 0 and A >= 0
def dfs(t, key_prime):
    global prime_factors, X, ans
    if key_prime >= len(prime_factors):
        return

    a = 0
    b = a - t
    Y = (a ** 5 - b ** 5) // t
    temp_X = X // t
    while Y <= temp_X:
        if Y == temp_X:
            ans = (a, b)
            return
        a += 1
        b = a - t
        Y = (a ** 5 - b ** 5) // t
        
    dfs(t, key_prime + 1)
    num_prime = list(prime_factors.keys())[key_prime]
    for _ in range(num_prime):
        t *= num_prime
        a = 0
        b = a - t
        Y = (a ** 5 - b ** 5) // t
        temp_X = X // t
        while Y <= temp_X:
            if Y == temp_X:
                ans = (a, b)
                return
            a += 1
            b = a - t
            Y = (a ** 5 - b ** 5) // t
        dfs(t, key_prime + 1)



for i in range(2, sup):
    if is_prime[i]:
        for j in range(i * i, X + 7, i):
            is_prime[j] = False

temp_X = X
for i in range(X + 5):
    if is_prime[i] and temp_X % i == 0:
        prime_factors[i] = 0
        while temp_X % i == 0:
            prime_factors[i] += 1
            temp_X //= i

if X == 1:
    print(1, 0)
else:
    dfs(1, 0)
    print(ans[0], ans[1])

Fixed submission:
x = int(input())
for i in range(1000):
    for j in range(i):
        if i ** 5 - j ** 5 == x:
            print(i, j)
            exit()
        if i ** 5 + j ** 5 == x:
            print(i, -j)
            exit()
Buggy python submission (verdict: Runtime Error):
import math
def lcm(a, b):
    g = math.gcd(a, b)
    return a * b // g

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(set(A))
N = len(A)
a0 = A[0]
div = 1
while a0 % 2 == 0:
    div *= 2
    a0 //= 2

for i in range(1, N):
    a = A[i] % div
    b = A[i] // div
    if (b % 2 == 0) or (a != 0):
        print(0)
        exit()

for i in range(N):
    A[i] //= 2

if N > 1:
    lcm = lcm(A[0], A[1])
    for i in range(2, N):
        lcm = lcm(lcm, A[i])

if N == 1:
    lcm = A[0]

ans = M // lcm
if ans % 2 == 1:
    print(ans // 2 + 1)
else:
    print(ans // 2)


Fixed submission:
import math
def LCM(a, b):
    g = math.gcd(a, b)
    return a * b // g

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(set(A))
N = len(A)
a0 = A[0]
div = 1
while a0 % 2 == 0:
    div *= 2
    a0 //= 2

for i in range(1, N):
    a = A[i] % div
    b = A[i] // div
    if (b % 2 == 0) or (a != 0):
        print(0)
        exit()

for i in range(N):
    A[i] //= 2

if N > 1:
    lcm = LCM(A[0], A[1])
    for i in range(2, N):
        lcm = LCM(lcm, A[i])

if N == 1:
    lcm = A[0]

ans = M // lcm
if ans % 2 == 1:
    print(ans // 2 + 1)
else:
    print(ans // 2)

Buggy python submission (verdict: Runtime Error):
import math
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(set(A))
N = len(A)
for i in range(N):
    A[i] //= 2

for i in range(N):
    if N > 1: 
        gcd = math.gcd(A[0], A[1])
        for i in range(2, N):
            gcd = math.gcd(gcd, A[i])

lcm = gcd
for i in range(N):
    lcm *= A[i] // gcd

print((M - lcm) // lcm // 2 + 1)

Fixed submission:
import math
def LCM(a, b):
    g = math.gcd(a, b)
    return a * b // g

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(set(A))
N = len(A)
a0 = A[0]
div = 1
while a0 % 2 == 0:
    div *= 2
    a0 //= 2

for i in range(1, N):
    a = A[i] % div
    b = A[i] // div
    if (b % 2 == 0) or (a != 0):
        print(0)
        exit()

for i in range(N):
    A[i] //= 2

if N > 1:
    lcm = LCM(A[0], A[1])
    for i in range(2, N):
        lcm = LCM(lcm, A[i])

if N == 1:
    lcm = A[0]

ans = M // lcm
if ans % 2 == 1:
    print(ans // 2 + 1)
else:
    print(ans // 2)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = int(1e9 + 7)
n = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(62):
    cnt = 0
    for a in A:
        if a & 1<<i:
            cnt += 1
    ans += (1<<i % MOD) * cnt % MOD * (n - cnt) % MOD
print(ans % MOD)


Fixed submission:
MOD = int(1e9 + 7)
n = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(62):
    cnt = 0
    for a in A:
        if a & 1<<i:
            cnt += 1
    ans += (1<<i % MOD) * cnt % MOD * (n - cnt) % MOD
print(ans % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = int(1e9 + 7)
n = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(62):
    cnt = 0
    for a in A:
        if a & 1<<i:
            cnt += 1
    ans += (1<<i % MOD) * cnt * (n - cnt) % MOD
print(ans % MOD)


Fixed submission:
MOD = int(1e9 + 7)
n = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(62):
    cnt = 0
    for a in A:
        if a & 1<<i:
            cnt += 1
    ans += (1<<i % MOD) * cnt % MOD * (n - cnt) % MOD
print(ans % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(a[0] // (2 ** m))
    exit()
a.sort()
while m > 0:
    while m > 0 and a[-1] >= a[-2]:
            m -= 1
            a[-1] //= 2
    a.sort()
# print(a)
print(sum(a))

Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(a[0] // (2 ** m))
    exit()
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
while m > 0:
    m -= 1
    i = heapq.heappop(a) * (-1)
    i //= 2
    heapq.heappush(a, i * (-1))

print(sum(a) * (-1))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(a[0] // (2 ** m))
    exit()
a.sort()
while m > 0:
    while m > 0 and a[-1] >= a[-2]:
            m -= 1
            a[-1] //= 2
    a.sort()
# print(a)
print(sum(a))

Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(a[0] // (2 ** m))
    exit()
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
while m > 0:
    m -= 1
    i = heapq.heappop(a) * (-1)
    i //= 2
    heapq.heappush(a, i * (-1))

print(sum(a) * (-1))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
mod = int(1e9 + 7)
one_or_two = [0] + [1] + [2] + [-1] * n
for i in range(3, n + 3):
    one_or_two[i] = (one_or_two[i-1] + one_or_two[i-2]) % mod
ans = 1
if a[0] > 1:
    ans *= one_or_two[a[0]-1]
for i in range(1, m):
    if a[i] - a[i-1] == 2:
        continue
    if a[i] - a[i-1] == 1:
        ans = 0
        break
    ans *= one_or_two[a[i] - a[i-1] - 2]
    ans %= mod
if n - a[-1] > 1:
    ans *= one_or_two[n - a[m-1] - 1]
print(ans % mod)

Fixed submission:
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
mod = int(1e9 + 7)
one_or_two = [0] + [1] + [2] + [-1] * n
for i in range(3, n + 3):
    one_or_two[i] = (one_or_two[i-1] + one_or_two[i-2]) % mod
if m == 0:
    print(one_or_two[n])
    exit()
ans = 1
if a[0] > 1:
    ans *= one_or_two[a[0]-1]
for i in range(1, m):
    if a[i] - a[i-1] == 2:
        continue
    if a[i] - a[i-1] == 1:
        ans = 0
        break
    ans *= one_or_two[a[i] - a[i-1] - 2]
    ans %= mod
if n - a[-1] > 1:
    ans *= one_or_two[n - a[-1] - 1]
print(ans % mod)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
mod = int(1e9 + 7)
one_or_two = [0] + [1] + [2] + [-1] * n
for i in range(3, n + 3):
    one_or_two[i] = (one_or_two[i-1] + one_or_two[i-2]) % mod
ans = 1
if a[0] > 1:
    ans *= one_or_two[a[0]-1]
for i in range(1, m):
    if a[i] - a[i-1] == 2:
        continue
    ans *= one_or_two[a[i] - a[i-1] - 2]
    ans %= mod
if n - a[-1] > 1:
    ans *= one_or_two[n - a[m-1] - 1]
print(ans % mod)

Fixed submission:
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
mod = int(1e9 + 7)
one_or_two = [0] + [1] + [2] + [-1] * n
for i in range(3, n + 3):
    one_or_two[i] = (one_or_two[i-1] + one_or_two[i-2]) % mod
if m == 0:
    print(one_or_two[n])
    exit()
ans = 1
if a[0] > 1:
    ans *= one_or_two[a[0]-1]
for i in range(1, m):
    if a[i] - a[i-1] == 2:
        continue
    if a[i] - a[i-1] == 1:
        ans = 0
        break
    ans *= one_or_two[a[i] - a[i-1] - 2]
    ans %= mod
if n - a[-1] > 1:
    ans *= one_or_two[n - a[-1] - 1]
print(ans % mod)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
a.sort()
mx = a[-1]
c = [0 for _ in range(mx+1)]
ans = 0
if a[0] == 1:
  if a[1] == 1:
    print(0)
    exit()
  else:
    print(n)
    exit()
i = 0
while i < n:
  if c[a[i]] == 0:
    p = a[i]
    for _ in range(2,mx//a[i]+1):
      p += a[i]
      c[p] = 1
    flag = True
    while i+1 < n and a[i+1] == a[i]:
      i += 1
      flag = False
    if flag:
      ans += 1
  i += 1
print(ans)
      
   
      


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a.sort()
mx = a[-1]
c = [0 for _ in range(mx+1)]
ans = 0
if a[0] == 1:
  if n == 1:
    print(1)
    exit()
  if a[1] == 1:
    print(0)
    exit()
  else:
    print(1)
    exit()
i = 0
while i < n:
  if c[a[i]] == 0:
    p = a[i]
    for _ in range(2,mx//a[i]+1):
      p += a[i]
      c[p] = 1
    flag = True
    while i+1 < n and a[i+1] == a[i]:
      i += 1
      flag = False
    if flag:
      ans += 1
  i += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = []
for _ in range(n):
  di = str(input())
  if di not in d:
    d.append(di)
print(len(d))

Fixed submission:
n = int(input())
s = [""]*n
for i in range(n):
  si = str(input())
  s[i] = si
s.sort()
c = 0
s.append("A")
for i in range(n):
  if s[i] != s[i+1]:
    c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
s = str(input())
r = []
g = []
b = []
ra = r.append
ga = g.append
ba = b.append
for i in range(n):
  if s[i] == "R":
    ra(i)
  elif s[i] == "G":
    ga(i)
  else:
    ba(i)
c = len(r)*len(g)*len(b)
for ri in r:
  for gi in g:
    for bi in b:
      if 3*(max(ri,gi,bi)+min(ri,gi,bi)) == 2*(ri+gi+bi):
        c -= 1
print(c)

Fixed submission:
n,k = map(int,input().split())
x = [0]*k
mod = 10**9+7
def power(a,n):
  ans = 1
  while n:
    if n%2:
      ans = (ans*a)%mod
    a = (a*a)%mod
    n >>= 1
  return ans%mod  
for i in range(k,0,-1):
  c = power(k//i,n)
  j = 2
  while i*j <= k:
    c -= x[i*j-1]
    j += 1
  x[i-1] = c
s = 0
for i in range(1,k+1):
  s = (s + i*x[i-1])%mod
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
def s():
  import queue
  k = int(input())
  q = queue.Queue([1,2,3,4,5,6,7,8,9])
  qg = q.get
  qp = q.put
  for _ in range(k-1):
    x = qg()
    if x%10 == 0:
      qp(10*x)
      qp(10*x+1)
    elif x%10 == 0:
      qp(10*x+8)
      qp(10*x+9)
    else:
      i = x%10
      qp(10*x+i-1)
      qp(10*x+i)
      qp(10*x+i+1)
  x = qg()
  print(x)
s()
    
    
    


Fixed submission:
k = int(input())
x = [1,2,3,4,5,6,7,8,9]
i = 0
xa = x.append
while len(x) < k:
  if x[i]%10 == 0:
    xa(10*x[i])
    xa(10*x[i]+1)
  elif x[i]%10 == 9:
    xa(10*x[i]+8)
    xa(10*x[i]+9)
  else:
    j = x[i]%10
    xa(10*x[i]+j-1)
    xa(10*x[i]+j)
    xa(10*x[i]+j+1)
  i += 1
print(x[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
import queue
k = int(input())
q = queue.Queue([1,2,3,4,5,6,7,8,9])
qg = q.get
qp = q.put
for _ in range(k-1):
  x = qg()
  if x%10 == 0:
    qp(10*x)
    qp(10*x+1)
  elif x%10 == 0:
    qp(10*x+8)
    qp(10*x+9)
  else:
    i = x%10
    qp(10*x+i-1)
    qp(10*x+i)
    qp(10*x+i+1)
x = qg()
print(x)
    
    
    


Fixed submission:
k = int(input())
x = [1,2,3,4,5,6,7,8,9]
i = 0
xa = x.append
while len(x) < k:
  if x[i]%10 == 0:
    xa(10*x[i])
    xa(10*x[i]+1)
  elif x[i]%10 == 9:
    xa(10*x[i]+8)
    xa(10*x[i]+9)
  else:
    j = x[i]%10
    xa(10*x[i]+j-1)
    xa(10*x[i]+j)
    xa(10*x[i]+j+1)
  i += 1
print(x[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
import queue
k = int(input())
q = queue.Queue([1,2,3,4,5,6,7,8,9])
c = 1
while True:
  x = q.get()
  if c == k:
    print(x)
    exit()
  if x%10 == 0:
    q.put(10*x)
    q.put(10*x+1)
  elif x%10 == 0:
    q.put(10*x+8)
    q.put(10*x+9)
  else:
    i = x%10
    q.put(10*x+i-1)
    q.put(10*x+i)
    q.put(10*x+i+1)
  c += 1
    
    
    


Fixed submission:
k = int(input())
x = [1,2,3,4,5,6,7,8,9]
i = 0
xa = x.append
while len(x) < k:
  if x[i]%10 == 0:
    xa(10*x[i])
    xa(10*x[i]+1)
  elif x[i]%10 == 9:
    xa(10*x[i]+8)
    xa(10*x[i]+9)
  else:
    j = x[i]%10
    xa(10*x[i]+j-1)
    xa(10*x[i]+j)
    xa(10*x[i]+j+1)
  i += 1
print(x[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
import queue
k = int(input())
q = queue.Queue([1,2,3,4,5,6,7,8,9])
c = 1
while True:
  x = q.get()
  if c == k:
    print(x)
    exit()
  if x%10 == 0:
    q.put(10*x)
    q.put(10*x+1)
  elif x%10 == 0:
    q.put(10*x+8)
    q.put(10*x+9)
  else:
    i = x%10
    q.put(10*x+i-1)
    q.put(10*x+i)
    q.put(10*x+i+1)
  c += 1
    
    
    


Fixed submission:
k = int(input())
x = [1,2,3,4,5,6,7,8,9]
i = 0
xa = x.append
while len(x) < k:
  if x[i]%10 == 0:
    xa(10*x[i])
    xa(10*x[i]+1)
  elif x[i]%10 == 9:
    xa(10*x[i]+8)
    xa(10*x[i]+9)
  else:
    j = x[i]%10
    xa(10*x[i]+j-1)
    xa(10*x[i]+j)
    xa(10*x[i]+j+1)
  i += 1
print(x[k-1])
Buggy python submission (verdict: Runtime Error):
s = str(input())
if s[3]==s[4]  and s[5]==s[6]:
  print("Yes")
else:
  print("No")

Fixed submission:
s = str(input())
if (s[2]==s[3])  and (s[4]==s[5]):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFindVerSize():
  def __init__(self, N):
    self._parent = [n for n in range(0, N)]
    self._size = [1] * N
  def find_root(self, x):
    if self._parent[x] == x: 
      return x
    self._parent[x] = self.find_root(self._parent[x]) 
    return self._parent[x]
  def unite(self, x, y):
    gx = self.find_root(x)
    gy = self.find_root(y)
    if gx == gy:
      return
    if self._size[gx] < self._size[gy]:
      self._parent[gx] = gy
      self._size[gy] += self._size[gx]
    else:
      self._parent[gy] = gx
      self._size[gx] += self._size[gy]
  def is_same_group(self, x, y):
    return self.find_root(x) == self.find_root(y)
n,m,k = map(int,input().split())
f = [0 for _ in range(n+1)]
uf = UnionFindVerSize(n+1)
for i in range(m):
  ai,bi = map(int,input().split())
  uf.unite(ai,bi)
  f[ai] += 1
  f[bi] += 1
l = [[] for _ in range(n+1)]
for i in range(k):
  ci,di = map(int,input().split())
  l[ci].append(di)
  l[di].append(ci)
d = [-1 for i in range(n+1)]
for i in range(1,n+1):
  bf = 0
  for x in l[i]:
    if uf.is_same_group(i,x):
      bf += 1
  if d[i] != -1:
    print(d[i]-bf-f[i],end=" ")
    continue
  ff = []
  for j in range(i+1,n+1):
    if uf.is_same_group(i,j):
      ff.append(j)
  ll = len(ff)
  for y in ff:
    d[y] = ll
  print(ll-bf-f[i],end=" ")
      
    
  


  
  

Fixed submission:
class UnionFindVerSize():
  def __init__(self, N):
    self._parent = [n for n in range(0, N)]
    self._size = [1] * N
  def find_root(self, x):
    if self._parent[x] == x: 
      return x
    self._parent[x] = self.find_root(self._parent[x]) 
    return self._parent[x]
  def unite(self, x, y):
    gx = self.find_root(x)
    gy = self.find_root(y)
    if gx == gy:
      return
    if self._size[gx] < self._size[gy]:
      self._parent[gx] = gy
      self._size[gy] += self._size[gx]
    else:
      self._parent[gy] = gx
      self._size[gx] += self._size[gy]
  def get_size(self, x):
    return self._size[self.find_root(x)]
  def is_same_group(self, x, y):
    return self.find_root(x) == self.find_root(y)
n,m,k = map(int,input().split())
f = [0 for _ in range(n+1)]
uf = UnionFindVerSize(n+1)
for i in range(m):
  ai,bi = map(int,input().split())
  uf.unite(ai,bi)
  f[ai] += 1
  f[bi] += 1
l = [[] for _ in range(n+1)]
for i in range(k):
  ci,di = map(int,input().split())
  l[ci].append(di)
  l[di].append(ci)
for i in range(1,n+1):
  bf = 0
  for x in l[i]:
    if uf.is_same_group(i,x):
      bf += 1
  print(uf.get_size(i)-bf-f[i]-1,end=" ")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a,b = map(int,input().split())
def sp(n):
  	if n == 1:
    	return 2
  	if n%2 == 0:
    	return (sp(n//2)**2)%(10**9+7)
	if n%2 == 1:
  	  return (2*sp(n-1))%(10**9+7)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


print((sp(n)-cmb(n,a,10**9+7)-cmb(n,b,10**9+7))%(10**9+7))


  
  

Fixed submission:
n,a,b = map(int,input().split())
def power(x,b):
  if x == 1:
    return b
  if x%2 == 0:
    return (power(x//2,b)**2)%(10**9+7)
  else:
    return (b*power(x-1,b))%(10**9+7)
ans = power(n,2)-1
x1 = 1
y1 = 1
x2 = 1
y2 = 1
for i in range(a):
  x1 = (x1*(n-i))%(10**9+7)
  y1 = (y1*(i+1))%(10**9+7)
for i in range(b):
  x2 = (x2*(n-i))%(10**9+7)
  y2 = (y2*(i+1))%(10**9+7)
ans -= x1*power(10**9+5,y1)
ans -= x2*power(10**9+5,y2)
print(ans%(10**9+7))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a,b = map(int,input().split())
def sp(n):
  if n == 1:
    return 2
  if n%2 == 0:
    return (sp(n//2)**2)%(10**9+7)
  if n%2 == 1:
    return (2*sp(n-1))%(10**9+7)
def com(n,a):
  if a == 1:
    return n
  return (com(n-1,a-1)+com(n-1,a))%(10**9+7)
print((sp(n)-com(n,a)-com(n,b))%(10**9+7))


  
  

Fixed submission:
n,a,b = map(int,input().split())
def power(x,b):
  if x == 1:
    return b
  if x%2 == 0:
    return (power(x//2,b)**2)%(10**9+7)
  else:
    return (b*power(x-1,b))%(10**9+7)
ans = power(n,2)-1
x1 = 1
y1 = 1
x2 = 1
y2 = 1
for i in range(a):
  x1 = (x1*(n-i))%(10**9+7)
  y1 = (y1*(i+1))%(10**9+7)
for i in range(b):
  x2 = (x2*(n-i))%(10**9+7)
  y2 = (y2*(i+1))%(10**9+7)
ans -= x1*power(10**9+5,y1)
ans -= x2*power(10**9+5,y2)
print(ans%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
def cmb(n,r):
  r = min(n-r,r)
  if r == 0:
    return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
mn = 0
mx = 0
for i in range(n-k+1):
  mn = (mn + a[i]*cmb(n-i-1,k-1))%(10**9+7)
a.reverse() 
for i in range(n-k+1):
  mx = (mx + a[i]*cmb(n-i-1,k-1))%(10**9+7)
print((mx-mn)%(10**9+7))

Fixed submission:
from operator import mul
from functools import reduce
n,k = map(int,input().split())
a = list(map(int,input().split()))
m = 10**9+7
a.sort()
mn = 0
mx = 0
x = 1
if k == 1:
  print(0)
  exit()
def extgcd(a,b):
  r = [1,0,a]
  w = [0,1,b]
  while w[2]!=1:
    q = r[2]//w[2]
    r2 = w
    w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
    r = r2
    w = w2
  return [w[0],w[1]]
def mod_inv(a,m):
  x = extgcd(a,m)[0]
  return (m+x%m)%m
gy = 1
for i in range(1,k):
    gy = gy*mod_inv(i,m)%m
for i in range(n-k+1,n):
  x= x*i
for i in range(n-k+1):
  mn = (mn + a[i]*x)%m
  mx = (mx + a[n-i-1]*x)%m
  x = (mod_inv(n-i-1,m)*x*(n-i-k))%m
print(((mx-mn)*gy)%m)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = str(input())
c1 = [False for _ in range(10)]
c2 = [0 for _ in range(1000)]
count = 0
for i in range(n-2):
  si = int(s[i])
  if c1[si] != True:
    c1[si] = True
    c3 = [False for _ in range(10)]
    for j in range(i+1,n-1):
      sj = int(s[j])
      if c3[sj] != True:
        c3[sj] = True
        c4 = [False for _ in range(10)]
        for k in range(j+1,n):
          sk = int(s[k])
          if c4[sk] != True:
            c4[sk] = True
            count += 1
print(count)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
x = [0,0,0]
c = 1
for i in range(n):
  cc = 0
  k = 0
  for j in range(3):
    if a[i] == x[j]:
      cc += 1
      k = j
  c = (c*cc)%1000000007
  x[k] += 1
print(c)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = str(input())
c1 = [False for _ in range(10)]
c2 = [0 for _ in range(1000)]
count = 0
for i in range(n-2):
  si = int(s[i])
  if c1[si] != True:
    c1[si] = True
    c3 = [False for _ in range(10)]
    for j in range(i+1,n-1):
      sj = int(s[j])
      if c3[sj] != True:
        c3[sj] = True
        c4 = [False for _ in range(10)]
        for k in range(j+1,n):
          sk = int(s[k])
          if c4[sk] != True:
            c4[sk] = True
            count += 1
print(count)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
x = [0,0,0]
c = 1
for i in range(n):
  cc = 0
  k = 0
  for j in range(3):
    if a[i] == x[j]:
      cc += 1
      k = j
  c = (c*cc)%1000000007
  x[k] += 1
print(c)