Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [input() for i in range(H)]
A = [[0 for j in range(W)] for i in range(H)]
pos = []
cnt = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      pos.append([i, j])
      A[i][j] = 1
      cnt += 1
ccnt = 0
pnt = 0
while pnt < cnt:
  n = cnt
  ccnt += 1
  for i in range(pnt, cnt):
    x, y = pos[i][0], pos[i][1]
    if x > 0:
      if A[x-1][y] == 0:
        A[x-1][y] = 1
        pos.append([x-1, y])
        cnt += 1
    if x < H-1:
      if A[x+1][y] == 0:
        A[x+1][y] = 1
        pos.append([x+1, y])
        cnt += 1
    if y > 0:
      if A[x][y-1] == 0:
        A[x][y-1] = 1
        pos.append([x, y-1])
        cnt += 1
    if y < W-1:
      if A[x][y+1] == 0:
        A[x][y+1] = 1
        pos.append([x, y+1])
        cnt += 1
  pnt = n
print(ccnt-1)

Fixed submission:
H, W = map(int, input().split())
S = [input() for i in range(H)]
A = [[0 for j in range(W)] for i in range(H)]
pos = []
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      pos.append([i, j])
      A[i][j] = 1
cnt = 0
while pos != []:
  n = len(pos)
  cnt += 1
  for i in range(n):
    x, y = pos[i][0], pos[i][1]
    if x > 0:
      if A[x-1][y] == 0:
        A[x-1][y] = 1
        pos.append([x-1, y])
    if x < H-1:
      if A[x+1][y] == 0:
        A[x+1][y] = 1
        pos.append([x+1, y])
    if y > 0:
      if A[x][y-1] == 0:
        A[x][y-1] = 1
        pos.append([x, y-1])
    if y < W-1:
      if A[x][y+1] == 0:
        A[x][y+1] = 1
        pos.append([x, y+1])
  pos = pos[n:]
print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [input() for i in range(H)]
A = [[0 for j in range(W)] for i in range(H)]
pos = []
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      pos.append([i, j])
      A[i][j] = 1
cnt = 0
while pos != []:
  n = len(pos)
  cnt += 1
  for i in range(n):
    x, y = pos[i][0], pos[i][1]
    if x > 0:
      if A[x-1][y] == 0:
        A[x-1][y] = 1
        pos.append([x-1, y])
    if x < H-1:
      if A[x+1][y] == 0:
        A[x+1][y] = 1
        pos.append([x+1, y])
    if y > 0:
      if A[x][y-1] == 0:
        A[x][y-1] = 1
        pos.append([x, y-1])
    if y < W-1:
      if A[x][y+1] == 0:
        A[x][y+1] = 1
        pos.append([x, y+1])
  pos = pos[n:]
print(cnt-1)

Fixed submission:
H, W = map(int, input().split())
S = [input() for i in range(H)]
A = [[0 for j in range(W)] for i in range(H)]
pos = []
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      pos.append([i, j])
      A[i][j] = 1
cnt = 0
while pos != []:
  n = len(pos)
  cnt += 1
  for i in range(n):
    x, y = pos[i][0], pos[i][1]
    if x > 0:
      if A[x-1][y] == 0:
        A[x-1][y] = 1
        pos.append([x-1, y])
    if x < H-1:
      if A[x+1][y] == 0:
        A[x+1][y] = 1
        pos.append([x+1, y])
    if y > 0:
      if A[x][y-1] == 0:
        A[x][y-1] = 1
        pos.append([x, y-1])
    if y < W-1:
      if A[x][y+1] == 0:
        A[x][y+1] = 1
        pos.append([x, y+1])
  pos = pos[n:]
print(cnt-1)
Buggy python submission (verdict: Time Limit Exceeded):
B, W = map(int, input().split())
mod = int(1e9) + 7
def doubling(n, m):
  y = 1
  base = n
  while m != 0:
    if m % 2 == 1:
      y *= base
      y %= mod
    base *= base
    base %= mod
    m //= 2
  return y
def inved(a):
  x, y, u, v, k, l = 1, 0, 0, 1, a, mod
  while l != 0:
    x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
    k, l = l, k % l
  return x % mod

fact = [1 for i in range(B+W+1)]
invf = [1 for i in range(B+W+1)]
for i in range(B+W):
  fact[i+1] = (fact[i] * (i+1)) % mod
invf[-1] = inved(fact[-1])
for i in range(B+W, 0, -1):
  invf[i-1] = (invf[i] * i) % mod
bina = [1 for i in range(B+W+1)]
invb = [1 for i in range(B+W+1)]
for i in range(B+W):
  bina[i+1] = (bina[i] * 2) % mod
invb[-1] = inved(bina[-1])
for i in range(B+W, 0, -1):
  invb[i-1] = (invb[i] * 2) % mod
for i in range(1, B + W + 1):
  S = 0
  for j in range(min(i, B)):
    S += (invf[j] * invf[i-1-j]) % mod
    S %= mod
  for j in range(max(i-W, 0)):
    S += (invf[j] * invf[i-1-j]) % mod
    S %= mod
  S *= (fact[i-1] * invb[i]) % mod
  S %= mod
  print(S)

Fixed submission:
B, W = map(int, input().split())
mod = int(1e9) + 7
def doubling(n, m):
  y = 1
  base = n
  while m != 0:
    if m % 2 == 1:
      y *= base
      y %= mod
    base *= base
    base %= mod
    m //= 2
  return y
def inved(a):
  x, y, u, v, k, l = 1, 0, 0, 1, a, mod
  while l != 0:
    x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
    k, l = l, k % l
  return x % mod

fact = [1 for i in range(B+W+1)]
invf = [1 for i in range(B+W+1)]
for i in range(B+W):
  fact[i+1] = (fact[i] * (i+1)) % mod
invf[-1] = inved(fact[-1])
for i in range(B+W, 0, -1):
  invf[i-1] = (invf[i] * i) % mod
bina = [1 for i in range(B+W+1)]
invb = [1 for i in range(B+W+1)]
for i in range(B+W):
  bina[i+1] = (bina[i] * 2) % mod
invb[-1] = inved(bina[-1])
for i in range(B+W, 0, -1):
  invb[i-1] = (invb[i] * 2) % mod
if B == W:
  for i in range(B+W):
    print(invf[2])
elif B > W:
  for i in range(W):
    print(invf[2])
  P = invf[2]
  for i in range(W+1, B+1):
    F = (fact[i-2] * invf[i-1-W] * invf[W-1]) % mod
    F *= invb[i]
    F %= mod
    F += P
    F %= mod
    print(F)
    P = F
  for i in range(B+1, B+W+1):
    F = invf[i-1-B] * invf[B-1]
    F %= mod
    F *= fact[i-2]
    F %= mod
    F *= mod - 1
    F += (fact[i-2] * invf[i-1-W] * invf[W-1]) % mod
    F %= mod
    F *= invb[i]
    F %= mod
    F += P
    F %= mod
    print(F)
    P = F
elif B < W:
  for i in range(B):
    print(invf[2])
  P = invf[2]
  for i in range(B+1, W+1):
    F = (fact[i-2] * invf[i-1-B] * invf[B-1]) % mod
    F *= mod - 1
    F %= mod
    F *= invb[i]
    F %= mod
    F += P
    F %= mod
    print(F)
    P = F
  for i in range(W+1, B+W+1):
    F = invf[i-1-B] * invf[B-1]
    F %= mod
    F *= fact[i-2]
    F %= mod
    F *= mod - 1
    F += (fact[i-2] * invf[i-1-W] * invf[W-1]) % mod
    F %= mod
    F *= invb[i]
    F %= mod
    F += P
    F %= mod
    print(F)
    P = F
Buggy python submission (verdict: Runtime Error):
n = input()
a = []
b = []
for i in range(n):
  for j in range(i, n):
    a.append([i+1, j+1])
for i in range(len(a)):
  if a[i][0] + a[i][1] != n:
    b.append(a[i])
m = len(b)
print(m)
for i in range(m):
  print(b[i][0], b[i][1])

Fixed submission:
n = int(input())
a = []
b = []
for i in range(n):
  for j in range(i+1, n):
    a.append([i+1, j+1])
if n % 2 == 0:
  for i in range(len(a)):
    if a[i][0] + a[i][1] != n + 1:
      b.append(a[i])
else:
  for i in range(len(a)):
    if a[i][0] + a[i][1] != n:
      b.append(a[i])
m = len(b)
print(m)
for i in range(m):
  print(b[i][0], b[i][1])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [int(input()) for i in range()]
S = []
A.sort()
for i in range(N - K + 1):
  S.append(A[i+K-1] - A[i])
print(min(S))

Fixed submission:
N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
S = []
A.sort()
for i in range(N - K + 1):
  S.append(A[i+K-1] - A[i])
print(min(S))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
S = 1
p = 0
for i in range(2, int(M ** (1/2)) + 1):
  if M % i == 0:
    p = 1
if p != 0:
  for i in range(1, M // N + 1):
    if M % i == 0:
      S = i
print(S)

Fixed submission:
N, M = map(int, input().split())
S = 1
p = 0
X = []
for i in range(2, int(M ** (1/2)) + 1):
  if M % i == 0:
    if i <= M // N:
      p = i
      X.append(i)
    else:
      break
if M // N <= int(M ** (1/2)):
  if p != 0:
    S = p
else:
  if p != 0:
    S = M
    q = 0
    while S > M // N:
      S = M // X[q]
      if S <= M // N:
        break
      q += 1
      if q == len(X):
        break
    if q == len(X):
      S = max(X)
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
S = 1
for i in range(1, M // N + 1):
  if M % i == 0:
    S = i
print(S)

Fixed submission:
N, M = map(int, input().split())
S = 1
p = 0
X = []
for i in range(2, int(M ** (1/2)) + 1):
  if M % i == 0:
    if i <= M // N:
      p = i
      X.append(i)
    else:
      break
if M // N <= int(M ** (1/2)):
  if p != 0:
    S = p
else:
  if p != 0:
    S = M
    q = 0
    while S > M // N:
      S = M // X[q]
      if S <= M // N:
        break
      q += 1
      if q == len(X):
        break
    if q == len(X):
      S = max(X)
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
mod = int(1e+9 + 7)
a = mod - 2
ax = []
while a != 0:
  ax = [a%2] + ax[:]
  a //= 2
def inved(x):
  y = 1
  for i in range(len(ax)):
    if ax[i] == 1:
      y *= x
      y %= mod
    if i != len(ax) - 1:
      y *= y
      y %= mod
  return y

p, n = 2, M
L = []
while n != 1:
  i = 0
  while n % p == 0:
    n //= p
    i += 1
  if i != 0:
    L.append(i)
  p += 1
  if L == [] and p > int(M**(1/2))+1:
    L.append(1)
    break
if M == 1:
  print(1)
else:
  prod = 1
  mm = max(L)
  fact = [1]
  for i in range(N + mm - 1):
    fact.append((fact[i] * (i + 1)) % mod)
  invf = inved(fact[N - 1])
  for i in L:
    pad = (fact[N - 1 + i] * inved(fact[i]) * invf) % mod
    prod *= pad
    prod %= mod
  print(prod)

Fixed submission:
N, M = map(int, input().split())
mod = int(1e+9 + 7)
a = mod - 2
ax = []
while a != 0:
  ax = [a%2] + ax[:]
  a //= 2
def inved(x):
  y = 1
  for i in range(len(ax)):
    if ax[i] == 1:
      y *= x
      y %= mod
    if i != len(ax) - 1:
      y *= y
      y %= mod
  return y

p, n = 2, M
L = []
dig = 1
while n != 1:
  i = 0
  while n % p == 0:
    n //= p
    dig *= p
    i += 1
  if i != 0:
    L.append([p, i])
  p += 1
  if p > int(M**(1/2)) and dig != M:
    if L != []:
      L.append([M//dig, 1])
    else:
      L.append([M, 1])
    break

if M == 1:
  print(1)
else:
  prod = 1
  mm = max(x[1] for x in L)
  fact = [1]
  for i in range(N + mm - 1):
    fact.append((fact[i] * (i + 1)) % mod)
  invf = inved(fact[N - 1])
  for i in L:
    pad = (fact[N - 1 + i[1]] * inved(fact[i[1]]) * invf) % mod
    prod *= pad
    prod %= mod
  print(prod)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
while N != 0:
  A = [N % (-2)] + A[:]
if N == 0:
  A = [0]
for i in range(len(A)):
  print(A[i], end = '')

Fixed submission:
N = int(input())
A = []
if N == 0:
  A = [0]
i = 0
while N != 0:
  A = [N % 2] + A[:]
  N //= 2
  N = -N
for i in range(len(A)):
  print(A[i], end = '')
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = ['.'*(W+2)] + [['.'] + input() + ['.'] for _ in range(H)] + ['.'*(W+2)]
flg = False
for i in range(1, H+1):
  for j in range(1, W+1):
    if S[i][j] == '#':
      cnt = 0
      if S[i][j-1] == '.':
        cnt += 1
      if S[i][j+1] == '.':
        cnt += 1
      if S[i-1][j] == '.':
        cnt += 1
      if S[i+1][j] == '.':
        cnt += 1
      flg = (cnt == 4)
if flg:
  print("No")
else:
  print("Yes")

Fixed submission:
H, W = map(int, input().split())
S = ['.'*(W+2)] + ['.' + input() + '.' for _ in range(H)] + ['.'*(W+2)]
flg = False
for i in range(1, H+1):
  for j in range(1, W+1):
    if S[i][j] == '#':
      cnt = 0
      if S[i][j-1] == '.':
        cnt += 1
      if S[i][j+1] == '.':
        cnt += 1
      if S[i-1][j] == '.':
        cnt += 1
      if S[i+1][j] == '.':
        cnt += 1
      flg = (cnt == 4)
      if flg:
        break
  if flg:
    break
if flg:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int, input().split()))
for i in range(N):
  Y = X[:]
  Y.remove(X[i])
  Y.sort()
  print(Y[N // 2 - 1])

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
L = []
for i in range(N):
  L.append([X[i], i])
L.sort()
for i in range(N):
  if i < N // 2:
    L[i].append(L[N // 2][0])
  else:
    L[i].append(L[N // 2 - 1][0])
for i in range(N):
  L[i][0], L[i][1] = L[i][1], L[i][0]
L.sort()
for i in range(N):
  print(L[i][2])

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))
for i in range(N):
  Y = X[:]
  Y.remove(X[i])
  Y.sort()
  print(Y[N // 2])

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
L = []
for i in range(N):
  L.append([X[i], i])
L.sort()
for i in range(N):
  if i < N // 2:
    L[i].append(L[N // 2][0])
  else:
    L[i].append(L[N // 2 - 1][0])
for i in range(N):
  L[i][0], L[i][1] = L[i][1], L[i][0]
L.sort()
for i in range(N):
  print(L[i][2])
Buggy python submission (verdict: Runtime Error):
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
invalpha = "zyxwvutsrqponmlkjihgfedcba"
D = {alpha[i]: i for i in range(26)}
E = [0 for i in range(26)]
def sugar(s):
  n = len(s)
  q = 0
  for i in range(n):
    if s[i] == 'z':
      q = i
  return i

for i in range(len(S)):
  E[D[S[i]]] = 1
if min(E) == 0:
  for m in range(26):
    if E[m] == 0:
      S = S[:] + alpha[m]
      break
  print(S)
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
else:
  p = 26
  for i in range(25, 0, -1):
    if D[S[i]] < D[S[i-1]]:
      p = i
    else:
      break
  if p == 26:
    S = S[:24] + S[25]
  else:
    m = D[S[p-2]]
    L = []
    for x in range(p, 26):
      if D[S[x]] >= m + 1:
        L.append(S[x])
    L.sort()
    S = S[:p-2] + L[0]
  print(S)

Fixed submission:
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
invalpha = "zyxwvutsrqponmlkjihgfedcba"
D = {alpha[i]: i for i in range(26)}
E = [0 for i in range(26)]

for i in range(len(S)):
  E[D[S[i]]] = 1
if min(E) == 0:
  for m in range(26):
    if E[m] == 0:
      S = S[:] + alpha[m]
      break
  print(S)
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
else:
  p = 26
  for i in range(25, 0, -1):
    if D[S[i]] < D[S[i-1]]:
      p = i
    else:
      break
  m = D[S[p-2]]
  L = []
  for x in range(p-1, 26):
    if D[S[x]] >= m + 1:
      L.append(S[x])
  L.sort()
  if L != []:
    S = S[:p-2] + L[0]
  else:
    S = S[:p-2] + 'z'
  print(S)

Buggy python submission (verdict: Runtime Error):
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
invalpha = "zyxwvutsrqponmlkjihgfedcba"
D = {alpha[i]: i for i in range(26)}
E = [0 for i in range(26)]
def sugar(s):
  n = len(s)
  q = 0
  for i in range(n):
    if s[i] == 'z':
      q = i
  return i

for i in range(len(S)):
  E[D[S[i]]] = 1
if min(E) == 0:
  for m in range(26):
    if E[m] == 0:
      S = S[:] + alpha[m]
      break
  print(S)
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
else:
  p = 26
  for i in range(25, 0, -1):
    if D[S[i]] < D[S[i-1]]:
      p = i
    else:
      break
  S = S[:p-2] + alpha[min(D[S[x]] for x in range(p, 26))]
  print(S)

Fixed submission:
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
invalpha = "zyxwvutsrqponmlkjihgfedcba"
D = {alpha[i]: i for i in range(26)}
E = [0 for i in range(26)]

for i in range(len(S)):
  E[D[S[i]]] = 1
if min(E) == 0:
  for m in range(26):
    if E[m] == 0:
      S = S[:] + alpha[m]
      break
  print(S)
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
else:
  p = 26
  for i in range(25, 0, -1):
    if D[S[i]] < D[S[i-1]]:
      p = i
    else:
      break
  m = D[S[p-2]]
  L = []
  for x in range(p-1, 26):
    if D[S[x]] >= m + 1:
      L.append(S[x])
  L.sort()
  if L != []:
    S = S[:p-2] + L[0]
  else:
    S = S[:p-2] + 'z'
  print(S)
Buggy python submission (verdict: Time Limit Exceeded):
prime = [3, 5]
for i in range(13, 102010, 12):
  r = int(i**(1/2))
  p = 0
  for j in range(2, r+1):
    if i % j == 0:
      p = 1
      break
  a = (i+1)//2
  r = int(a**(1/2))
  for j in range(2, r+1):
    if a % j == 0:
      p = 1
      break
  if p == 0:
    prime.append(i)

Q = int(input())
for i in range(Q):
  L = list(map(int, input().split()))
  L[0] -= 1
  i = 0
  while L[0] >= prime[i]:
    i += 1
  j = 0
  while L[1] >= prime[j]:
    j += 1
  print(j-i)

Fixed submission:
prime = [3, 5]
for i in range(13, 102010, 12):
  r = int(i**(1/2))
  p = 0
  for j in range(2, r+1):
    if i % j == 0:
      p = 1
      break
  a = (i+1)//2
  r = int(a**(1/2))
  for j in range(2, r+1):
    if a % j == 0:
      p = 1
      break
  if p == 0:
    prime.append(i)
LL = []
j = 0
for i in range(100001):
  if i >= prime[j]:
    j += 1
  LL.append(j)

Q = int(input())
for i in range(Q):
  L = list(map(int, input().split()))
  L[0] -= 1
  print(LL[L[1]] - LL[L[0]])

Buggy python submission (verdict: Runtime Error):
prime = [3, 5]
for i in range(13, 100001, 12):
  r = int(i**(1/2))
  p = 0
  for j in range(2, r+1):
    if i % j == 0:
      p = 1
      break
  a = (i+1)//2
  r = int(a**(1/2))
  for j in range(2, r+1):
    if a % j == 0:
      p = 1
      break
  if p == 0:
    prime.append(i)

Q = int(input())
for i in range(Q):
  L = list(map(int, input().split()))
  L[0] -= 1
  i = 0
  while L[0] >= prime[i]:
    i += 1
  j = 0
  while L[1] >= prime[j]:
    j += 1
  print(j-i)

Fixed submission:
prime = [3, 5]
for i in range(13, 102010, 12):
  r = int(i**(1/2))
  p = 0
  for j in range(2, r+1):
    if i % j == 0:
      p = 1
      break
  a = (i+1)//2
  r = int(a**(1/2))
  for j in range(2, r+1):
    if a % j == 0:
      p = 1
      break
  if p == 0:
    prime.append(i)
LL = []
j = 0
for i in range(100001):
  if i >= prime[j]:
    j += 1
  LL.append(j)

Q = int(input())
for i in range(Q):
  L = list(map(int, input().split()))
  L[0] -= 1
  print(LL[L[1]] - LL[L[0]])
Buggy python submission (verdict: Runtime Error):
S = input()
A = [int(S[i]) for i in range(4)]
for i in range(8):
  p = A[0]
  s = []
  for j in range(3):
    if i % 2 == 0:
      p += A[i]
      s.append('+')
    else:
      p -= A[i]
      s.append('-')
    i //= 2
  if p == 7:
    print('A[0]s[0]A[1]s[1]A[2]s[2]A[3]=7')
    break

Fixed submission:
S = input()
A = [int(S[i]) for i in range(4)]
for i in range(8):
  p = A[0]
  s = []
  for j in range(3):
    if i % 2 == 0:
      p += A[j+1]
      s.append('+')
    else:
      p -= A[j+1]
      s.append('-')
    i //= 2
  if p == 7:
    print('{}{}{}{}{}{}{}=7'.format(A[0], s[0], A[1], s[1], A[2], s[2], A[3]))
    break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
B.sort()
C.sort()

cnt = 0
tmp = N
while tmp != 0:
  cnt += 1
  tmp //= 2

def binary_search(v, L):
  if max(L) <= v:
    return 0
  elif min(L) > v:
    return N
  else:
    l, r = 0, N
    d = (l + r) // 2
    for _ in range(cnt+2):
      if L[d] <= v:
        l = d + 1
        d = (l + r) // 2
      else:
        r = d
        d = (l + r) // 2
    return N - d

LB = [binary_search(B[_], C) for _ in range(N)]
for i in range(N-1, 0, -1):
  LB[i-1] += LB[i]
S = 0
for i in range(N):
  X = N - binary_search(A[i], B)
  if X != N:
    S += LB[X]
print(S)

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

cnt = 0
tmp = N
while tmp != 0:
  cnt += 1
  tmp //= 2

def binary_search(v, L, M, m):
  if M <= v:
    return 0
  elif m > v:
    return N
  else:
    l, r = 0, N
    d = (l + r) // 2
    for _ in range(cnt):
      if L[d] <= v:
        l = d + 1
        d = (l + r) // 2
      else:
        r = d
        d = (l + r) // 2
    return N - d
MB, mB, MC, mC = B[N-1], B[0], C[N-1], C[0]
LB = [binary_search(B[_], C, MC, mC) for _ in range(N)]
for i in range(N-1, 0, -1):
  LB[i-1] += LB[i]
S = 0
for i in range(N):
  X = N - binary_search(A[i], B, MB, mB)
  if X != N:
    S += LB[X]
print(S)

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

cnt = 0
tmp = N
while tmp != 0:
  cnt += 1
  tmp //= 2

def binary_search(v, L):
  if max(L) <= v:
    return 0
  elif min(L) > v:
    return N
  else:
    l, r = 0, N
    d = (l + r) // 2
    for _ in range(cnt+2):
      if L[d] <= v:
        l = d + 1
        d = (l + r) // 2
      else:
        r = d
        d = (l + r) // 2
    return N - d

LB = [binary_search(B[_], C) for _ in range(N)]
for i in range(N-1, 0, -1):
  LB[i-1] += LB[i]
S = 0
for i in range(N):
  X = N - binary_search(A[i], B)
  if X == N:
    break
  else:
    S += LB[X]
print(S)

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

cnt = 0
tmp = N
while tmp != 0:
  cnt += 1
  tmp //= 2

def binary_search(v, L, M, m):
  if M <= v:
    return 0
  elif m > v:
    return N
  else:
    l, r = 0, N
    d = (l + r) // 2
    for _ in range(cnt):
      if L[d] <= v:
        l = d + 1
        d = (l + r) // 2
      else:
        r = d
        d = (l + r) // 2
    return N - d
MB, mB, MC, mC = B[N-1], B[0], C[N-1], C[0]
LB = [binary_search(B[_], C, MC, mC) for _ in range(N)]
for i in range(N-1, 0, -1):
  LB[i-1] += LB[i]
S = 0
for i in range(N):
  X = N - binary_search(A[i], B, MB, mB)
  if X != N:
    S += LB[X]
print(S)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(max(A)+1)]
for i in range(N):
  L[A[i]] += 1
mL = []
for j in range(len(L)-2):
  mL.append(L[j] + L[j+1] + L[j+2])

print(max(mL))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(max(A)+1)]
for i in range(N):
  L[A[i]] += 1
mL = []
if len(L) >= 3:
  for j in range(len(L)-2):
    mL.append(L[j] + L[j+1] + L[j+2])
else:
  for j in range(3-len(L)):
    L.append(0)
  mL = [L[0]+L[1]+L[2]]
print(max(mL))
Buggy python submission (verdict: Runtime Error):
N = input()
A = list(map(int, input().split()))
odd, four = 0, 0
for i in range(N):
  if A[i] % 4 == 0:
    four += 1
  else:
    if A[i] % 2 == 1:
      odd += 1
if four < odd and four + odd < N:
  print('No')
else:
  print('Yes')


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
odd, four = 0, 0
for i in range(N):
  if A[i] % 4 == 0:
    four += 1
  else:
    if A[i] % 2 == 1:
      odd += 1
if four < odd and four + odd < N:
  print('No')
elif odd - four > 1 and four + odd == N:
  print('No')
else:
  print('Yes')

Buggy python submission (verdict: Runtime Error):
N = input()
A = list(map(int, input().split()))
odd, four = 0, 0, 0
for i in range(N):
  if A[i] % 4 == 0:
    four += 1
  else:
    if A[i] % 2 == 1:
      odd += 1
if four < odd and four + odd < N:
  print('No')
else:
  print('Yes')


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
odd, four = 0, 0
for i in range(N):
  if A[i] % 4 == 0:
    four += 1
  else:
    if A[i] % 2 == 1:
      odd += 1
if four < odd and four + odd < N:
  print('No')
elif odd - four > 1 and four + odd == N:
  print('No')
else:
  print('Yes')

Buggy python submission (verdict: Runtime Error):
N = input()
A = list(map(int, input()))
odd, four = 0, 0, 0
for i in range(N):
  if A[i] % 4 == 0:
    four += 1
  else:
    if A[i] % 2 == 1:
      odd += 1
if four < odd and four + odd < N:
  print('No')
else:
  print('Yes')

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
odd, four = 0, 0
for i in range(N):
  if A[i] % 4 == 0:
    four += 1
  else:
    if A[i] % 2 == 1:
      odd += 1
if four < odd and four + odd < N:
  print('No')
elif odd - four > 1 and four + odd == N:
  print('No')
else:
  print('Yes')