Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [''] * N
for i in range(N):
  S[i] = input()
cnt = 0
for a in range(N):
  for i in range(N):
    _i = (i - a) % N
    for j in range(i):
      if S[_i][j] != S[(j - a) % N][i]:
        break
    else:
      continue
    break
  else:
    cnt += N
print(cnt)

Fixed submission:
N = int(input())
S = [''] * N
for i in range(N):
  S[i] = input()
cnt = 0
for a in range(N):
  for i in range(N):
    _i = (i - a) % N
    for j in range(i):
      if S[_i][j] != S[(j - a) % N][i]:
        break
    else:
      continue
    break
  else:
    cnt += N
print(cnt)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
K = 5
G = [['.' for j in range(2 * K)] for i in range(K)] + [['#' for j in range(2 * K)] for i in range(K)]
x = 0
while B > 1:
  for y in range(min(K, B - 1)):
    G[x][x % 2 + 2 * y] = '#'
    B -= 1
  x += 1
x = 2 * K - 1
while A > 1:
  for y in range(min(K, A - 1)):
    G[x][x % 2 + 2 * y] = '.'
    A -= 1
  x -= 1
print(2 * K, 2 * K)
for i in range(2 * K):
  print(''.join(G[i]))

Fixed submission:
A, B = map(int, input().split())
K = 50
G = [['.' for j in range(2 * K)] for i in range(K)] + [['#' for j in range(2 * K)] for i in range(K)]
x = 0
while B > 1:
  for y in range(min(K, B - 1)):
    G[x][x % 2 + 2 * y] = '#'
    B -= 1
  x += 2
x = 2 * K - 1
while A > 1:
  for y in range(min(K, A - 1)):
    G[x][x % 2 + 2 * y] = '.'
    A -= 1
  x -= 2
print(2 * K, 2 * K)
for i in range(2 * K):
  print(''.join(G[i]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
print('Yes' sum([max(A[i] - B[i], 0) for i in range(N)]) <= sum(B) - sum(A) if else 'No')

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
d = sum(B) - sum(A)
for i in range(N):
  if A[i] % 2 != B[i] % 2:
    B[i] += 1
    d -= 1
print('Yes' if sum([max(A[i] - B[i], 0) for i in range(N)]) <= d else 'No')
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())
Y //= 1000
if Y > N:
  print(-1, -1, -1)
  break
A, B, C = [0, 0, N]
while Y - N >= 9:
  C -= 1
  A += 1
  Y -= 9
while Y - N >= 4:
  C -= 1
  B += 1
  Y -= 4
while Y > N and A > 0:
  A -= 1
  B = 2
  Y -= 1
if Y == N:
  print(A, B, C)
else:
  print(-1, -1, -1)

Fixed submission:
N, Y = map(int, input().split())
Y //= 1000
A, B, C = [-1, -1, -1]
for a in range(N + 1):
  for b in range(N - a + 1):
    if 9 * a + 4 * b + N == Y:
      A, B, C = [a, b, N - a - b]
      break
  if A != -1:
    break
print(A, B, C)
Buggy python submission (verdict: Time Limit Exceeded):
N, H = map(int, input().split())
A = 0
B = [0] * (N + 1)
for i in range(N):
  a, b = map(int, input().split())
  A = max(a, A)
  B[i] = b
B.sort(reverse=True)
cnt = 0
while H > 0:
  b = B[0]
  B = B[1:]
  if b > A:
    H -= b
    cnt += 1
  else:
    k = -(-H // A)
    H -= A * k
    cnt += k
print(cnt)

Fixed submission:
N, H = map(int, input().split())
A = 0
B = [0] * (N + 1)
for i in range(N):
  a, b = map(int, input().split())
  A = max(a, A)
  B[i] = b
B.sort(reverse=True)
cnt = 0
i  = 0
while H > 0:
  if B[i] > A:
    H -= B[i]
    cnt += 1
    i += 1
  else:
    k = -(-H // A)
    H -= A * k
    cnt += k
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, H = map(int, input().split())
D = [[0, 0] for i in range(2 * N)]
for i in range(N):
  a, b = map(int, input().split())
  D[2 * i] = [a, 2]
  D[2 * i + 1] = [b, 1]
D.sort(reverse=True)
cnt = 0
while H > 0:
  d = D[0]
  D = D[1:]
  if d[1] == 1:
    H -= d[0]
    cnt += 1
  else:
    k = -(-H // d[0])
    H -= d[0] * k
    cnt += k
print(cnt)

Fixed submission:
N, H = map(int, input().split())
A = 0
B = [0] * (N + 1)
for i in range(N):
  a, b = map(int, input().split())
  A = max(a, A)
  B[i] = b
B.sort(reverse=True)
cnt = 0
i  = 0
while H > 0:
  if B[i] > A:
    H -= B[i]
    cnt += 1
    i += 1
  else:
    k = -(-H // A)
    H -= A * k
    cnt += k
print(cnt)

Buggy python submission (verdict: Runtime Error):
N, H = map(input().split())
D = [[0, 0] for i in range(2 * N)]
for i in range(N):
  a, b = map(int, input().split())
  D[2 * i] = [a, 2]
  D[2 * i + 1] = [b, 1]
D.sort(reverse=True)
cnt = 0
while H > 0:
  d = D[0]
  D = D[1:]
  if d[1] == 1:
    H -= d[0]
    cnt += 1
  else:
    k = -(-H // d[0])
    H -= d[0] * k
    cnt += k
print(cnt)

Fixed submission:
N, H = map(int, input().split())
A = 0
B = [0] * (N + 1)
for i in range(N):
  a, b = map(int, input().split())
  A = max(a, A)
  B[i] = b
B.sort(reverse=True)
cnt = 0
i  = 0
while H > 0:
  if B[i] > A:
    H -= B[i]
    cnt += 1
    i += 1
  else:
    k = -(-H // A)
    H -= A * k
    cnt += k
print(cnt)
Buggy python submission (verdict: Runtime Error):
N, C = map(int, input().split())
T = [0 for i in range(10 ** 5)]
for i in range(N):
  s, t, c = map(int, input().split())
  for j in range(s - 1, t + 1):
    T[j] += 1
print(max(T))

Fixed submission:
import functools
N, C = map(int, input().split())
T = [[0 for i in range(10 ** 5 + 1)] for j in range(C)]
for i in range(N):
  s, t, c = map(int, input().split())
  for j in range(s - 1, t):
    T[c - 1][j] = 1
ans = 0
for j in range(10 ** 5 + 1):
  r = 0
  for i in range(C):
    r += T[i][j]
  ans = max(ans, r)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import functools
N, C = map(int, input().split())
P = [[] for i in range(C)]
for i in range(N):
  s, t, c = map(int, input().split())
  P[c - 1].append([s, t])
for i in range(C):
  P[i].sort(key=lambda x: x[0])
  _P = []
  p = []
  while P[i]:
    if p:
      if p[1] == P[i][0][0]:
        p = [p[0], P[i][0][1]]
      else:
        _P.append(p)
        p = P[i][0]
    else:
      p = P[i][0]
    P[i] = P[i][1:]
  if p:
    _P.append(p)
  P[i] = _P
_P = [p for p in P if p]
P = functools.reduce(lambda x, y: x + y, _P)
P.sort(key=lambda x: x[0])
R = [0]
for p in P:
  record = False
  for i, r in enumerate(R):
    if r < p[0]:
      R[i] = p[1]
      record = True
      break
  if not record:
    R.append(p[1])
print(len(R))

Fixed submission:
import functools
N, C = map(int, input().split())
T = [[0 for i in range(10 ** 5 + 1)] for j in range(C)]
for i in range(N):
  s, t, c = map(int, input().split())
  for j in range(s - 1, t):
    T[c - 1][j] = 1
ans = 0
for j in range(10 ** 5 + 1):
  r = 0
  for i in range(C):
    r += T[i][j]
  ans = max(ans, r)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
XY = [[0, 0, 0] for _ in range(N)]
for i in range(N):
  x, y = map(int, input().split())
  XY[i] = [x, y, i]
X = sorted(XY)
Y = sorted(XY, key=lambda x: x[1])
rect = (X[-1][0] - X[0][0]) * (Y[-1][1] - Y[0][1])
for l in range(N - K + 1):
  for r in range(l + K - 1, N):
    for d in range(N - K + 1):
      for u in range(d + K - 1, N):
        if len([x for x in XY if X[l][0] <= x[0] <= X[r][0] and Y[d][1] <= x[1] <= Y[u][1]]) >= K:
          rect = min((X[r][0] - X[l][0]) * (Y[u][1] - Y[d][1]), rect)
print(rect)

Fixed submission:
N, K = map(int, input().split())
XY = [[0, 0, 0] for _ in range(N)]
for i in range(N):
  x, y = map(int, input().split())
  XY[i] = [x, y, i]
X = sorted(XY)
Y = sorted(XY, key=lambda x: x[1])
rect = (X[-1][0] - X[0][0]) * (Y[-1][1] - Y[0][1])
for l in range(N - K + 1):
  for r in range(l + K - 1, N):
    for d in range(N - K + 1):
      for u in range(d + K - 1, N):
        if len([x for x in XY if X[l][0] <= x[0] <= X[r][0] and Y[d][1] <= x[1] <= Y[u][1]]) >= K:
          rect = min((X[r][0] - X[l][0]) * (Y[u][1] - Y[d][1]), rect)
print(rect)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [[0 for _ in range(N)] for _ in range(30)]
B = [0] * N
for i in range(N):
  a, b = map(int, input().split())
  for j in range(30):
    A[j][i] = a % 2
    a //= 2
  B[i] = b
M = [0] * 30
_M = [0] * N
_K = K
for i in range(30):
  k = _K % 2
  M[i] = k
  _K //= 2
  if k:
    continue
  for j in range(N):
    _M[j] += A[i][j]
cnt = 0
for i in range(N):
  if _M[i]:
    continue
  cnt += B[i]
Z = [0] * N
for i in range(30):
  if M[i] == 0:
    for j in range(N):
      Z[j] += A[i][j]
  else:
    _cnt = 0
    for j in range(N):
      _M[j] += A[i][j] - Z[j]
      Z[j] = A[i][j]
      if _M[j]:
        continue
      _cnt += B[j]
    cnt = max(_cnt, cnt)
print(cnt)

Fixed submission:
N, K = map(int, input().split())
A = [[0 for _ in range(N)] for _ in range(30)]
B = [0] * N
for i in range(N):
  a, b = map(int, input().split())
  for j in range(30):
    A[j][i] = a % 2
    a //= 2
  B[i] = b
M = [0] * 30
_M = [0] * N
_K = K
for i in range(30):
  k = _K % 2
  M[i] = k
  _K //= 2
  if k:
    continue
  for j in range(N):
    _M[j] += A[i][j]
cnt = 0
for i in range(N):
  if _M[i]:
    continue
  cnt += B[i]
Z = [0] * N
for i in range(30):
  if M[i] == 0:
    for j in range(N):
      Z[j] += A[i][j]
  else:
    _cnt = 0
    for j in range(N):
      _M[j] += A[i][j] - Z[j]
      Z[j] = A[i][j]
      if _M[j]:
        continue
      _cnt += B[j]
    cnt = max(_cnt, cnt)
print(cnt)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [False] * 10 ** 9
cnt = 0
for i in range(N):
  a = int(input())
  A[a - 1] = not A[a - 1]
  cnt += 1 if A[a - 1] else -1
print(cnt)

Fixed submission:
from collections import defaultdict
N = int(input())
A = defaultdict(int)
cnt = 0
for i in range(N):
  a = int(input())
  A[a - 1] += 1
for v in A.values():
  cnt += v % 2
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N, M, R = map(int, input().split())
r = [int(x) - 1 for x in input().split()]
G = [[10 ** 7 for j in range(N)] for i in range(N)]
for i in range(N):
  G[i][i] = 0
for i in range(M):
  a, b, c = map(int, input().split())
  G[a - 1][b - 1] = c
  G[b - 1][a - 1] = c
def warshall_floyd(G):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        G[i][j] = min(G[i][k] + G[k][j], G[i][j])
  return G
G = warshall_floyd(G)
D = 10 ** 7
for L in itertools.permutations(r):
  d = 0
  pre = L[0]
  for l in L[1:]:
    d += G[pre][l]
    pre = l
  D = min(d, D)
print(D)

Fixed submission:
import itertools
N, M, R = map(int, input().split())
r = [int(x) - 1 for x in input().split()]
G = [[10 ** 7 for j in range(N)] for i in range(N)]
for i in range(N):
  G[i][i] = 0
for i in range(M):
  a, b, c = map(int, input().split())
  G[a - 1][b - 1] = c
  G[b - 1][a - 1] = c
def warshall_floyd(G):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        G[i][j] = min(G[i][k] + G[k][j], G[i][j])
  return G
G = warshall_floyd(G)
D = 10 ** 8
for L in itertools.permutations(r):
  d = 0
  pre = L[0]
  for l in L[1:]:
    d += G[pre][l]
    pre = l
  D = min(d, D)
print(D)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
pre = 0
e1, e2 = 0, 0
for a in A:
  if pre == a:
    if e1 == 0:
      e1 = a
    elif e2 == 0:
      e2 == a
  else:
    pre = a
print(a * b)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
pre = 0
e1, e2 = 0, 0
for a in A:
  if pre == a:
    if e1 == 0:
      e1 = a
    elif e2 == 0:
      e2 = a
    pre = 0
  else:
    pre = a
print(e1 * e2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S1 = input()
S2 = input()
p = 10 ** 9 + 7
dp = [0] * (N + 1)
if S1[0] == S2[0]:
  dp[0] = 3
else:
  dp[0] = 6
for i in range(1, N + 1):
  if S1[i] == S1[i - 1]:
    dp[i] = dp[i - 1]
  elif S1[i - 1] == S2[i - 1]:
    dp[i] = dp[i - 1] * 2 % p
  elif S1[i] == S2[i]:
    dp[i] = dp[i - 1]
  else:
    dp[i] = dp[i - 1] * 3 % p
print(dp[N])


Fixed submission:
N = int(input())
S1 = input()
S2 = input()
p = 10 ** 9 + 7
dp = [0] * N
if S1[0] == S2[0]:
  dp[0] = 3
else:
  dp[0] = 6
for i in range(1, N):
  if S1[i] == S1[i - 1]:
    dp[i] = dp[i - 1]
  elif S1[i - 1] == S2[i - 1]:
    dp[i] = dp[i - 1] * 2 % p
  elif S1[i] == S2[i]:
    dp[i] = dp[i - 1]
  else:
    dp[i] = dp[i - 1] * 3 % p
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import math
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
def gcd(A, B):
  while(True):
    if A and B:
      if A > B:
        A = A % B
      else:
        B = B % A
    else:
      return max(A, B)
 
def lcm(A, B):
  return int(A * (B / gcd(A, B)))
 
print(functools.reduce(lcm, sorted(T, reverse=True)))

Fixed submission:
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
def gcd(A, B):
  while(True):
    if A and B:
      if A > B:
        A = A % B
      else:
        B = B % A
    else:
      return max(A, B)
 
def lcm(A, B):
  return (A // gcd(A, B)) * B
 
print(functools.reduce(lcm, sorted(T, reverse=True)))

Buggy python submission (verdict: Runtime Error):
import math
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
def gcd(A, B):
  while(True):
    if A and B:
      if A > B:
        A = A % B
      else:
        B = B % A
    else:
      return max(A, B)

def mcm(A, B):
  return int(A * B / gcd(A, B))

print(functools.reduce(mcm, sorted(T, reverse=True)))

Fixed submission:
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
def gcd(A, B):
  while(True):
    if A and B:
      if A > B:
        A = A % B
      else:
        B = B % A
    else:
      return max(A, B)
 
def lcm(A, B):
  return (A // gcd(A, B)) * B
 
print(functools.reduce(lcm, sorted(T, reverse=True)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
T = [[] for i in range(N)]
for i in range(N - 1):
  a, b = map(int, input().split())
  T[a - 1].append(b - 1)
  T[b - 1].append(a - 1)
def dijkstra(N, s0):
  D = [N] * N
  Q = [s0]
  D[s0] = 0
  while Q:
    s = Q[0]
    Q = Q[1:]
    for adj in T[s]:
      if D[s] + 1 < D[adj]:
        D[adj] = D[s] + 1
        Q.append(adj)
  return D
D1 = dijkstra(N, 0)
D2 = dijkstra(N, N - 1)
score = 0
for i in range(N):
  score += 1 if D1[i] <= D2[i] else -1
print('Fennec' if score > 0 else 'Snuke')

Fixed submission:
N = int(input())
T = [[] for i in range(N)]
for i in range(N - 1):
  a, b = map(int, input().split())
  T[a - 1].append(b - 1)
  T[b - 1].append(a - 1)
def dijkstra(N, s0):
  D = [N] * N
  D[s0] = 0
  Q = [N] * N
  Q[0] = s0
  tail = 1
  for i in range(N):
    s = Q[i]
    for adj in T[s]:
      if D[s] + 1 < D[adj]:
        D[adj] = D[s] + 1
        Q[tail] = adj
        tail += 1
  return D
D1 = dijkstra(N, 0)
D2 = dijkstra(N, N - 1)
score = 0
for i in range(N):
  score += 1 if D1[i] <= D2[i] else -1
print('Fennec' if score > 0 else 'Snuke')
Buggy python submission (verdict: Runtime Error):
a,b,c = map(input().split())
print(a[0].upper() + b[0].upper() + c[0].upper())

Fixed submission:
S = input().split()
print(S[0][0].upper() + S[1][0].upper() + S[2][0].upper())

Buggy python submission (verdict: Runtime Error):
a = map(input().split())
print(a[0].upper() + b[0].upper() + c[0].upper())

Fixed submission:
S = input().split()
print(S[0][0].upper() + S[1][0].upper() + S[2][0].upper())
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
p = 10 ** 9 + 7
ans = 0
for i in range(n - 1):
  for j in range(m - 1):
    S = (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) * (n - i - 1) * (i + 1) * (m - j - 1) * (j + 1)
    ans += S
print(ans % p)

Fixed submission:
n, m = map(int, input().split())
p = 10 ** 9 + 7
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
XX = [(X[i + 1] - X[i]) * (n - i - 1) * (i + 1) % p for i in range(n - 1)]
YY = [(Y[j + 1] - Y[j]) * (m - j - 1) * (j + 1) % p for j in range(m - 1)]
print(sum(XX) * sum(YY) % p)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
p = 10 ** 9 + 7
ans = 0
for i in range(n - 1):
  for j in range(m - 1):
    S = (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) * (n - i - 1) * (i + 1) * (m - j - 1) * (j + 1) % p
    ans += S
print(ans % p)

Fixed submission:
n, m = map(int, input().split())
p = 10 ** 9 + 7
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
XX = [(X[i + 1] - X[i]) * (n - i - 1) * (i + 1) % p for i in range(n - 1)]
YY = [(Y[j + 1] - Y[j]) * (m - j - 1) * (j + 1) % p for j in range(m - 1)]
print(sum(XX) * sum(YY) % p)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
p = 10 ** 9 + 7
S = [[(X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) for j in range(m - 1)] for i in range(n - 1)]
for i in range(n - 1):
  for j in range(m - 1):
    S[i][j] *= (n - i - 1) * (i + 1)
    #S[i][j] %= p
    S[i][j] *= (m - j - 1) * (j + 1)
    #S[i][j] %= p
print(sum([sum(s) for s in S]) % p)

Fixed submission:
n, m = map(int, input().split())
p = 10 ** 9 + 7
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
XX = [(X[i + 1] - X[i]) * (n - i - 1) * (i + 1) % p for i in range(n - 1)]
YY = [(Y[j + 1] - Y[j]) * (m - j - 1) * (j + 1) % p for j in range(m - 1)]
print(sum(XX) * sum(YY) % p)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
p = 10 ** 9 + 7
S = [[(X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) for j in range(m - 1)] for i in range(n - 1)]
for i in range(n - 1):
  for j in range(m - 1):
    S[i][j] *= (n - i - 1) * (i + 1)
    S[i][j] %= p
    S[i][j] *= (m - j - 1) * (j + 1)
    S[i][j] %= p
print(sum([sum(s) for s in S]) % p)

Fixed submission:
n, m = map(int, input().split())
p = 10 ** 9 + 7
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
XX = [(X[i + 1] - X[i]) * (n - i - 1) * (i + 1) % p for i in range(n - 1)]
YY = [(Y[j + 1] - Y[j]) * (m - j - 1) * (j + 1) % p for j in range(m - 1)]
print(sum(XX) * sum(YY) % p)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
return((A + B) % 24)

Fixed submission:
A, B = map(int, input().split())
print((A + B) % 24)
Buggy python submission (verdict: Runtime Error):
W, a, b = map(int, input().split())
print(max(min(abs(a - b - w), abs(a - b + w)), 0))

Fixed submission:
W, a, b = map(int, input().split())
print(max(max(a, b) - (min(a, b) + W), 0))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
E = [[] for i in range(M)]
for i in range(M):
  E[i] = [int(x) - 1 for x in input().split()]
cnt = 0
for p in range(1, 2 ** M):
  V = [[] for i in range(N)]
  idx = 0
  while p:
    if p % 2:
      V[E[idx][0]].append(E[idx][1])
      V[E[idx][1]].append(E[idx][0])
    idx += 1
    p //= 2
  if sum([len(v) for v in V]) == 2 * (N - 1) and len(V[0]) == 1:
    P = [0] + V[0]
    while len(V[P[-1]]) == 2:
      P += [V[P[-1]][0] if V[P[-1]][0] != P[-2] else V[P[-1]][1]]
    cnt += 1 if len(P) == N else 0
print(cnt)

Fixed submission:
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)
cnt = [0]
def dfs(V, s):
  V[s] = 1
  if sum(V) == N:
    cnt[0] += 1
  else:
    for adj in G[s]:
      if V[adj] == 0:
        dfs(V[:adj] + [1] + V[adj + 1:], adj)
dfs([0] * N, 0)
print(cnt[0])
Buggy python submission (verdict: Time Limit Exceeded):
H, W, N = map(int, input().split())
A = []
for i in range(N):
  a, b = map(int, input().split())
  for j in range(3):
    for k in range(3):
      if (a - j > 0) and (a - j < H - 1) and (b - k > 0) and (b - k < W - 1):
        A.append([a - j, b - k])
A = sorted(sorted(A, key=lambda x: x[1]), key=lambda x: x[0])
A.append([0, 0])
prev = [0, 0]
count = 0
C = [0 for i in range(10)]
for a in A:
  if a == prev:
    count += 1
  else:
    C[count] += 1
    count = 1
  prev = a
print((H - 2) * (W - 2) - sum(C[1:]))
for c in C[1:]:
  print(c)

Fixed submission:
from collections import defaultdict
H, W, N = map(int, input().split())
P = [0] * 10
P[0] = (H - 2) * (W - 2)
G = defaultdict(lambda: defaultdict(int))
for i in range(N):
  a, b = map(int, input().split())
  for i in range(max(a - 3, 0), min(a, H - 2)):
    for j in range(max(b - 3, 0), min(b, W - 2)):
      p = G[i][j]
      P[p] -= 1
      P[p + 1] += 1
      G[i][j] += 1
for i in range(10):
  print(P[i])

Buggy python submission (verdict: Time Limit Exceeded):
H, W, N = map(int, input().split())
A = []
for i in range(N):
  a, b = map(int, input().split())
  for j in range(3):
    for k in range(3):
      if (a - j > 0) and (a - j < H - 1) and (b - k > 0) and (b - k < W - 1):
        A.append([a - j, b - k])
A = sorted(sorted(A, key=lambda x: x[1]), key=lambda x: x[0])
A.append([0, 0])
prev = [0, 0]
count = 0
C = [0 for i in range(10)]
for a in A:
  if a[0] == prev[0] and a[1] == prev[1]:
    count += 1
  else:
    C[count] += 1
    count = 1
  prev = a
print((H - 2) * (W - 2) - sum(C[1:]))
for c in C[1:]:
  print(c)

Fixed submission:
from collections import defaultdict
H, W, N = map(int, input().split())
P = [0] * 10
P[0] = (H - 2) * (W - 2)
G = defaultdict(lambda: defaultdict(int))
for i in range(N):
  a, b = map(int, input().split())
  for i in range(max(a - 3, 0), min(a, H - 2)):
    for j in range(max(b - 3, 0), min(b, W - 2)):
      p = G[i][j]
      P[p] -= 1
      P[p + 1] += 1
      G[i][j] += 1
for i in range(10):
  print(P[i])

Buggy python submission (verdict: Time Limit Exceeded):
H, W, N = map(int, input().split())
G = [[0 for w in range(W)] for h in range(H)]
for i in range(N):
  a, b = map(int, input().split())
  for j in range(3):
    for k in range(3):
      if (a - j > 0) and (b - k > 0):
        G[a - j - 1][b - k - 1] += 1
A = [0 for i in range(10)]
for h in range(H - 2):
  for w in range(W - 2):
    A[G[h][w]] += 1
for a in A:
  print(a)

Fixed submission:
from collections import defaultdict
H, W, N = map(int, input().split())
P = [0] * 10
P[0] = (H - 2) * (W - 2)
G = defaultdict(lambda: defaultdict(int))
for i in range(N):
  a, b = map(int, input().split())
  for i in range(max(a - 3, 0), min(a, H - 2)):
    for j in range(max(b - 3, 0), min(b, W - 2)):
      p = G[i][j]
      P[p] -= 1
      P[p + 1] += 1
      G[i][j] += 1
for i in range(10):
  print(P[i])
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y, Z = map(int, input().split())
p = 10 ** 9 + 7
m = 1
m <<= X
m += 1
m <<= Y
m += 1
m <<= Z - 1
L = 2 ** (X + Y + Z - 1)
M = [[0 for _ in range(10)] for _ in range(L)]
for i in range(L):
  for j in range(10):
    k =  i << (j + 1)
    k += 1 << j
    M[i][j] = (k % L) if k & m != m else -1
DP = [[0 for _ in range(L)] for _ in range(N + 1)]
DP[0][0] = 1
for i in range(N):
  for j in range(L):
    if DP[i][j] == 0:
      continue
    DP[i][j] %= p
    for k in range(10):
      l = M[j][k]
      if l < 0:
        continue
      DP[i + 1][l] += DP[i][j]
cnt = 10 ** N % p
print((cnt - sum(DP[N]) % p) % p)

Fixed submission:
N, X, Y, Z = map(int, input().split())
p = 10 ** 9 + 7
m = 1
m <<= X
m += 1
m <<= Y
m += 1
m <<= Z - 1
L = 2 ** (X + Y + Z - 1)
M = [[0 for _ in range(10)] for _ in range(L)]
for i in range(L):
  for j in range(10):
    k =  i << (j + 1)
    k += 1 << j
    M[i][j] = (k % L) if k & m != m else -1
DP = [[0 for _ in range(L)] for _ in range(N + 1)]
DP[0][0] = 1
for i in range(N):
  for j in range(L):
    if DP[i][j] == 0:
      continue
    DP[i][j] %= p
    for k in range(10):
      l = M[j][k]
      if l < 0:
        continue
      DP[i + 1][l] += DP[i][j]
cnt = 10 ** N % p
print((cnt - sum(DP[N]) % p) % p)