Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

def resolve():
    def route(a, b):
        dx = b[0] - a[0]
        dy = b[1] - a[1]
        if dx < 0 or dy < 0:
            return 0
        return cmb.nCr(dx+dy, dx)


    MOD = 10 ** 9 + 7
    H, W, N = map(int, input().split())
    wall = []
    for _ in range(N):
        r, c = map(lambda x:int(x)-1, input().split())
        wall.append((r, c))
    # スタート位置
    wall.append((0, 0))
    wall.sort()

    cmb = Combination((H + W) + 1)
    dp = [[0] * 2 for _ in range(N + 1)]
    dp[0][0] = 1

    for i in range(1, N+1):
        for j in range(0, i):
            dp[i][0] += dp[j][1] * route(wall[j], wall[i]) % MOD
            dp[i][0] %= MOD
            dp[i][1] += dp[j][0] * route(wall[j], wall[i]) % MOD
            dp[i][1] %= MOD

    goal = (H-1, W-1)
    ng = 0
    for i in range(1, N+1):
        ng -= dp[i][0] * route(wall[i], goal) % MOD
        ng += dp[i][1] * route(wall[i], goal) % MOD
        ng %= MOD

    # 全体 - ng
    all = cmb.nCr(H+W-2, H-1)
    ans = (all - ng + MOD) % MOD
    print(ans)


if __name__ == "__main__":
    resolve()

Fixed submission:

class Combination:
    def __init__(self, n_max, mod=10 ** 9 + 7):
        # O(n_max + log(mod))
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max + 1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod - 2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    # "n 要素" は区別できる n 要素
    # "k グループ" はちょうど k グループ

    def __call__(self, n, r):  # self.C と同じ
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def nCr(self, n, r):
        if not 0 <= r <= n:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod


def resolve():
    MOD = 10 ** 9 + 7
    H, W, N = map(int, input().split())
    wall = []
    for _ in range(N):
        r, c = map(lambda x: int(x) - 1, input().split())
        wall.append((r, c))
    # 番兵
    wall.append((H - 1, W - 1))
    wall.sort()

    cmb = Combination((H + W) + 1)
    dp = [0] * (N + 1)

    # 壁がない時(0,0)から(x,y)まで移動する場合の数: x+yCx
    # dp[i] =f(r[i]+c[i],c[i])−(i−1番目までの壁に1回以上ぶつかって壁iの位置にたどり着く場合の数)
    for i in range(N + 1):
        r1, c1 = wall[i]
        dp[i] = cmb.nCr(r1 + c1, c1)
        for j in range(0, i):
            dx = r1 - wall[j][0]
            dy = c1 - wall[j][1]
            # dp[j]: 1～j-1 番目の壁を避けてj番目の壁の位置にたどり着く場合の数
            # nCr :  j 番目の壁の位置からi番目の壁の位置まで壁を無視して移動する場合の数
            tmp = dp[j] * cmb.nCr(dx + dy, dy)
            dp[i] = (dp[i] - tmp % MOD + MOD) % MOD

    print(dp[N])


if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):

def resolve():
    N = int(input())
    K = -1
    for i in range(1, N+1):
        if (i*(i-1)//2 == N):
            K = i
            break

    if K == -1:
        print("No")
        return
    else:
        S = [[0] * (K-1) for _ in range(K)]
        a = 1
        for i in range(K-1):
            for j in range(i, K-1):
                S[i][j] = a
                S[j+1][i] = a
                a += 1

    print("Yes")
    print(K)
    for s in S:
        print(len(s), *s)

if __name__ == "__main__":
    unittest.main()

Fixed submission:

def resolve():
    N = int(input())
    
    K = 0
    for i in range(1, 1000):
        if (i*(i-1)//2 == N):
            K = i
            break

    if K == 0:
        print("No")
        return
    else:
        S = [[] for _ in range(K)]
        cnt = 1
        for i in range(K):
            for j in range(i+1, K):
                S[i].append(cnt)
                S[j].append(cnt)
                cnt += 1

    print("Yes")
    print(K)
    for s in S:
        print(len(s), *s)

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
n, t = map(int, input().split())
w_dic = {}
for i in range(n):
  w, w_t = map(int, input().split())
  if w_t < t:
    w_dic[i+1] = w
print(min(w_dic, key=w_dic.get))    
    

Fixed submission:
n, t = map(int, input().split())
w_dic = {}
for i in range(n):
  w, w_t = map(int, input().split())
  if w_t <= t:
    w_dic[i+1] = w
if w_dic:
  print(min(w_dic.values()))
else:
  print("TLE")
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n = input()
v=list(map(int,input().split()))
a=Counter(v[0::2]).most_common()
b=Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0]!=b[0][0]:
    print(n-(a[0][1]+b[0][1]))
else:
    print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))

Fixed submission:
from collections import Counter

n = int(input())
v=list(map(int,input().split()))
a=Counter(v[0::2]).most_common()
b=Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0]!=b[0][0]:
    print(n-(a[0][1]+b[0][1]))
else:
    print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))
Buggy python submission (verdict: Time Limit Exceeded):

def resolve():
    N, M, Q = map(int, input().split())
    cum_A = [[0]*(N+1) for _ in range(N+1)]
    for _ in range(M):
        l, r = map(int, input().split())
        for i in range(r, N+1):
            cum_A[l][i] += 1

    for _ in range(Q):
        ans = 0
        l, r = map(int, input().split())
        ans = sum([cum_A[i][r] - cum_A[i][l-1] for i in range(l, r+1)])

        print(ans)

if __name__ == "__main__":
    resolve()

Fixed submission:

def resolve():
    N, M, Q = map(int, input().split())
    cum_A = [[0]*(N+1) for _ in range(N+1)]
    for _ in range(M):
        l, r = map(int, input().split())
        cum_A[l][r] += 1

    # 二次元累積和
    for i in range(1, N+1):
        for j in range(1, N+1):
            cum_A[i][j] += cum_A[i-1][j] + cum_A[i][j-1] - cum_A[i-1][j-1]

    for _ in range(Q):
        ans = 0
        l, r = map(int, input().split())
        ans = cum_A[r][r] - cum_A[r][l-1] - cum_A[l-1][r] + cum_A[l-1][l-1]

        print(ans)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):

def resolve():
    N, M, Q = map(int, input().split())
    cum_A = [[0]*(N+1) for _ in range(N+1)]
    for _ in range(M):
        l, r = map(int, input().split())
        for i in range(r, N+1):
            cum_A[l][i] += 1

    for _ in range(Q):
        ans = 0
        l, r = map(int, input().split())
        for i in range(l, r+1):
            ans += cum_A[i][r] - cum_A[i][l-1]
        print(ans)

if __name__ == "__main__":
    resolve()

Fixed submission:

def resolve():
    N, M, Q = map(int, input().split())
    cum_A = [[0]*(N+1) for _ in range(N+1)]
    for _ in range(M):
        l, r = map(int, input().split())
        cum_A[l][r] += 1

    # 二次元累積和
    for i in range(1, N+1):
        for j in range(1, N+1):
            cum_A[i][j] += cum_A[i-1][j] + cum_A[i][j-1] - cum_A[i-1][j-1]

    for _ in range(Q):
        ans = 0
        l, r = map(int, input().split())
        ans = cum_A[r][r] - cum_A[r][l-1] - cum_A[l-1][r] + cum_A[l-1][l-1]

        print(ans)

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
n = int(input())
a, b, c = map(int, input().split())

count = 0
for num in [a, b, c]:
  while num%2 == 0:
    num = num//2
    count += 1

print(count)    
  

Fixed submission:
n = int(input())
arr = list(map(int, input().split()))

count = 0
for num in arr:
  while num%2 == 0:
    num = num//2
    count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for b in range(33):
  for p in range(2,10):
    if b**p > x:
      break
    ans = max(ans, b**p)
print(ans)    

Fixed submission:
x = int(input())
ans = [b**p for b in range(1001) for p in range(2,10)
      if b**p <= x]
print(max(ans))

Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for b in range(1001):
  for p in range(2,10):
    if b**p > x:
      break
    ans = max(ans, b**p)
print(ans)    

Fixed submission:
x = int(input())
ans = [b**p for b in range(1001) for p in range(2,10)
      if b**p <= x]
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

a, b, k = map(int, input().split())

arr = [i for i in range(a, b+1)]
arr_slice = set(arr[:k]) | set(arr[-k:])
[print(i) for i in sorted(arr_slice)]

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

a, b, k = map(int, input().split())

pre_arr = [i for i in range(a, min(a+k, b+1))]
back_arr = [i for i in range(max(b-k+1, a), b+1)]
arr_slice = set(pre_arr) | set(back_arr)
[print(i) for i in sorted(arr_slice)]

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

a, b, k = map(int, input().split())

arr = sorted([i for i in range(a, b+1)])
arr_slice = set(arr[:k]) | set(arr[-k:])
[print(i) for i in sorted(arr_slice)]

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

a, b, k = map(int, input().split())

pre_arr = [i for i in range(a, min(a+k, b+1))]
back_arr = [i for i in range(max(b-k+1, a), b+1)]
arr_slice = set(pre_arr) | set(back_arr)
[print(i) for i in sorted(arr_slice)]

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

a, b, k = map(int, input().split())

arr = sorted([i for i in range(a, b+1)])
arr_slice = set(arr[:k] | arr[-k:])
[print(i) for i in sorted(arr_slice)]

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

a, b, k = map(int, input().split())

pre_arr = [i for i in range(a, min(a+k, b+1))]
back_arr = [i for i in range(max(b-k+1, a), b+1)]
arr_slice = set(pre_arr) | set(back_arr)
[print(i) for i in sorted(arr_slice)]

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

a, b, k = map(int, input().split())
arr = sorted([i for i in range(a, b+1)])
arr_slice = set(arr[:k] + arr[-k:])
[print(i) for i in sorted(arr_slice)]

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

a, b, k = map(int, input().split())

pre_arr = [i for i in range(a, min(a+k, b+1))]
back_arr = [i for i in range(max(b-k+1, a), b+1)]
arr_slice = set(pre_arr) | set(back_arr)
[print(i) for i in sorted(arr_slice)]
Buggy python submission (verdict: Runtime Error):
s1 = input()
s2 = input()
s3 = input()
print(s1[0][0],s2[0][1],s3[0][2], sep="")s1 = input()
s2 = input()
s3 = input()
print(s1[0],s2[1],s3[2], sep="")

Fixed submission:
s1 = input()
s2 = input()
s3 = input()
print(s1[0],s2[1],s3[2], sep="")

Buggy python submission (verdict: Runtime Error):
s1 = input()
s2 = input()
s3 = input()
print(s1[0][0],s2[0][1],s3[0][2], sep="")

Fixed submission:
s1 = input()
s2 = input()
s3 = input()
print(s1[0],s2[1],s3[2], sep="")

Buggy python submission (verdict: Runtime Error):
s1 = input()
s2 = input()
s3 = input()
print(s1[0][0],s2[1][1],s3[2][2], sep="")

Fixed submission:
s1 = input()
s2 = input()
s3 = input()
print(s1[0],s2[1],s3[2], sep="")
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n = int(input())
arr = [input()[0] for s in range(n)]
arr = [s for s in arr if s in "MARCH"]
combi = [len(set(i)) for i in combinations(arr, 3)]
print(sum([1 for i in combi if i==3]))

Fixed submission:
from itertools import combinations
from collections import Counter

n = int(input())
S = Counter()
for i in range(n):
  S[input()[0]] +=  1 # Counter == dictionary
  
print(sum([S[a]*S[b]*S[c] for a, b, c in combinations("MARCH", 3)]))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

A=int(input())
B=int(input())
C=int(input())
X=int(input())

ans = 0
for i in range(A+1):
  for j in range(B+1):
    if 0 <= (x - 500*i - 100*j) // 50 <= C:
      ans += 1
print(ans)      

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

A=int(input())
B=int(input())
C=int(input())
X=int(input())

ans = 0
for i in range(A+1):
  for j in range(B+1):
    if 0 <= (X - 500*i - 100*j) // 50 <= C:
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
# dp
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]

dp = [[0]*(N) for _ in range(N)]
dp[0][0] = A[0][0]
dp[1][0] = A[0][0] + A[1][0]
for i in range(1, N):
  dp[0][i] = dp[0][i-1] + A[0][i]
  dp[1][i] = max(dp[0][i],dp[1][i-1]) + A[1][i]
  
print(dp[1][-1])  

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = max(sum(a[:i+1]) + sum(b[i:]) for i in range(n))
print(ans)
Buggy python submission (verdict: Runtime Error):
# 振るのは最強のやつだけ
# 投げるのは強い順
 
N,H = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
A,B = zip(*AB)
 
a = max(A) # 振る
B = [b for b in B if b > a] # 投げる価値あり
B.sort(reverse = True)

attack_cnt = 0
 
for b in B:
  if H <= 0:
    break
  attack_cnt += 1
  H -= b
  
if hp > 0:
  attack_cnt += (H-1)//a + 1
  
print(attack_cnt)

Fixed submission:
from math import ceil

N, H = map(int, input().split())
sword = [[int(x) for x in input().split()] for _ in range(N)]

max_swing = max(sword, key=lambda x:x[0])[0]

attack = 0
# 投げで攻撃
for i in sorted(sword, key=lambda x: x[1], reverse=True):
  if max_swing < i[1]:
    H -= i[1]
    attack += 1
    if H <= 0:
      break
# 残りを振りで攻撃      
if 0 < H:
  attack += ceil(H / max_swing)
print(attack)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
x = int(input())
arr = [i**2 for i in range(1,x+1) if i**2 <= x]
ans = bisect.bisect_right(arr, x)
print(arr[ans-1])

Fixed submission:
x = int(input())
print(int(x**0.5)**2)
Buggy python submission (verdict: Time Limit Exceeded):

import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
INF = 1<<60
# A：想定する最短距離と計算(WF)で算出した最短距離が合っているか判定
# A[i][j] > A[i][k] + A[k][j] : -1
# AとWFが合っていたら最短距離の和を出力
def resolve():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(N)]
    B = [[True]*(N) for _ in range(N)]

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if A[i][j] > A[i][k] + A[k][j]:
                    print(-1)
                    return
                # 1~Nまでの最短距離を求める為、不要な道を削除
                # (sample1:1->3=3, 1->2->3=1+2) よって1->3は削除
                elif A[i][j] == A[i][k] + A[k][j] and k!=i and k!= j:
                    B[i][j] = False

    ans = [sum([A[i][j] for j in range(N) if B[i][j]]) for i in range(N)]
    print(sum(ans)//2)

if __name__ == "__main__":
    resolve()

Fixed submission:

import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
INF = 1<<60
# A：想定する最短距離と計算(WF)で算出した最短距離が合っているか判定
# A[i][j] > A[i][k] + A[k][j] : -1
# AとWFが合っていたら最短距離の和を出力
def resolve():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(N)]
    B = [[True]*(N) for _ in range(N)]

    for k in range(N):
        for i in range(N):
            for j in range(N):
                if A[i][j] > A[i][k] + A[k][j]:
                    print(-1)
                    return
                # 1~Nまでの最短距離を求める為、不要な道を削除
                # (sample1:1->3=3, 1->2->3=1+2) よって1->3は削除
                elif A[i][j] == A[i][k] + A[k][j] and k!=i and k!= j:
                    B[i][j] = False

    ans = [sum([A[i][j] for j in range(N) if B[i][j]]) for i in range(N)]
    print(sum(ans)//2)

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
N = int(input())
even_A = list(range(2, N+1, 2))
dic = {}
for a in even_A:
  x = a
  cnt = 0
  while x%2 == 0:
    x /= 2
    cnt += 1
  dic[a] = cnt

ans = sorted(dic.items(), key=lambda x:x[1])[-1]

print(ans[0])

Fixed submission:
N = int(input())

max_count = 0
for i in range(1, N+1):
  n = i
  count = 0
  while n > 0 and n % 2 == 0:
    n = n//2
    count += 1
  if count == max(max_count, count):
    res = i
    max_count = count
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
B = []

for a in input().split():
  B.append(a)
  B = B[::-1]
print(*B)  

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

n = int(input())
s = input().split()
q = deque()

for i in range(n):
  if i%2 == 0:
    q.appendleft(s[i])
  else:
    q.append(s[i])
if n%2 == 0:
  q.reverse()
print(" ".join(q))
Buggy python submission (verdict: Time Limit Exceeded):
def factorial(n):
  fact = 1
  for i in range(2, n+1):
    fact *= i%(10**9+7)
  return fact

N, M = map(int, input().split())
MOD = 10**9+7
if N == M:
  print(2*factorial(N)**2 % MOD)
elif abs(N-M) == 1:
  print(factorial(min(N, M))**2 * max(N, M) % MOD)
else:
  print(0)

Fixed submission:
def factorial(n):
  fact = 1
  for i in range(2, n+1):
    fact = fact * i % (10**9+7)
  return fact

N, M = map(int, input().split())
MOD = 10**9+7
if N == M:
  print(2*factorial(N)**2 % MOD)
elif abs(N-M) == 1:
  print(factorial(min(N, M))**2 * max(N, M) % MOD)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.array([int(input()) for _ in range(N)])

total = A.sum()
if total%10 == 0:
  if np.any(A%10 != 0):
    total -= A[A%10 != 0].min():
  else:
    total = 0
print(total)    

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

total = sum(A)
if total%10 == 0:
  A.sort()
  for a in A:
    if a%10 != 0:
      total -= a
      break
  else: # 全部が10の倍数
    total = 0
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = []

for _ in range(N):
  a, b = map(int, input().split())
  A += [a]*b
A.sort()
print(A[K-1])

Fixed submission:
N, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(AB, key=lambda x:x[0])

total = 0
for a, b in AB:
  total += b
  if total >= K:
    print(a)
    exit()
Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import bellman_ford
from scipy.sparse.csgraph import connected_components

N,M = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(N)]

row, col, val = zip(*ABC)
# -1倍しておいて最短路問題にする
val = [-(x) for x in val]
graph = csr_matrix((val,(row,col)),(N+1,N+1))

# 強連結成分に制限。ここに負閉路があればinf～
find_component_graph = csr_matrix(([1]*(M+1),(row+(N,),col+(1,))),(N+1,N+1))
# n = 個数、label=各頂点が属する連結成分のラベル[0,0,1,1,1]
n, labels = connected_components(find_component_graph,connection = 'strong')
idx = (labels == labels[1]) # [False, False, True~]
graph = graph[idx,:][:,idx]

try:
  dist = bellman_ford(graph,indices = [0])[0].astype(int)
  answer = -dist[-1]
except:
  answer = 'inf'

print(answer)

Fixed submission:
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import bellman_ford
from scipy.sparse.csgraph import connected_components

N,M = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(M)]

row, col, val = zip(*ABC)
# -1倍しておいて最短路問題にする
val = [-(x) for x in val]
graph = csr_matrix((val,(row,col)),(N+1,N+1))

# 強連結成分に制限。ここに負閉路があればinf～
find_component_graph = csr_matrix(([1]*(M+1),(row+(N,),col+(1,))),(N+1,N+1))
# n = 個数、label=各頂点が属する連結成分のラベル[0,0,1,1,1]
n, labels = connected_components(find_component_graph,connection = 'strong')
idx = (labels == labels[1]) # [False, False, True~]
graph = graph[idx,:][:,idx]

try:
  dist = bellman_ford(graph,indices = [0])[0].astype(int)
  answer = -dist[-1]
except:
  answer = 'inf'

print(answer)
Buggy python submission (verdict: Runtime Error):
s1 = input()
s2 = input()
password = ''.join([i,j for i, j in zip(s1, s2)])
print(password)

Fixed submission:
o=list(input())
e=list(input())+[""]
for x,y in zip(o,e):print(x+y,end="")
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
ans = math.factorial(n) % (1e9+7)
print(int(ans))

Fixed submission:
import math
n = int(input())
ans = math.factorial(n) % (10**9+7)
print(int(ans))

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
print(math.factorial(n) % (1e9+7))

Fixed submission:
import math
n = int(input())
ans = math.factorial(n) % (10**9+7)
print(int(ans))
Buggy python submission (verdict: Runtime Error):
dic_S = {c: list(input()) for c in "abc"}
s = "a"
while dic_S[s]:
  s = S[s].pop(0)
print(s.upper())  

Fixed submission:
dic_S = {c: list(input()) for c in "abc"}
s = "a"
while dic_S[s]:
  s = dic_S[s].pop(0)
print(s.upper())
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, A = map(int, input().split())
X = list(map(int, input().split()))
sum_X = sum(X)
dp = np.zeros((N+1, N+1, sum_X+1), np.int64)
dp[0][0][0] = 1
for i in range(N):
  for j in range(N):
    for k in range(sum_X):
      if dp[i][j][k] == 0: continue
      # not used
      dp[i+1][j][k] += dp[i][j][k]
      # used
      dp[i+1][j+1][k+X[i]] += dp[i][j][k]
ans = 0
for k in range(1, N+1):
  if k*A <= sum_X:
    ans += dp[N][k][k*A]
print(ans)  

Fixed submission:
N, A = map(int, input().split())
X = list(map(int, input().split()))
sum_X = sum(X)
dp = [[[0]*(sum_X+1) for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1
for i in range(N):
  for j in range(N):
    for k in range(sum_X):
      if dp[i][j][k] == 0: continue
      # not used
      dp[i+1][j][k] += dp[i][j][k]
      # used
      dp[i+1][j+1][k+X[i]] += dp[i][j][k]
ans = 0
for k in range(1, N+1):
  if k*A <= sum_X:
    ans += dp[N][k][k*A]
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, A = map(int, input().split())
X = list(map(int, input().split()))
sum_X = sum(X)
dp = np.zeros((N+1, N+1, sum_X+1), np.int64)
dp[0][0][0] = 1
for i in range(N):
  for j in range(N):
    for k in range(sum_X):
      if dp[i][j][k] == 0: continue
      # not used
      dp[i+1][j][k] += dp[i][j][k]
      # used
      dp[i+1][j+1][k+X[i]] += dp[i][j][k]
ans = 0
for i in range(1, N+1):
  ans += dp[N][i][i*A]
print(ans)  

Fixed submission:
N, A = map(int, input().split())
X = list(map(int, input().split()))
sum_X = sum(X)
dp = [[[0]*(sum_X+1) for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1
for i in range(N):
  for j in range(N):
    for k in range(sum_X):
      if dp[i][j][k] == 0: continue
      # not used
      dp[i+1][j][k] += dp[i][j][k]
      # used
      dp[i+1][j+1][k+X[i]] += dp[i][j][k]
ans = 0
for k in range(1, N+1):
  if k*A <= sum_X:
    ans += dp[N][k][k*A]
print(ans)

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

dp = np.zeros((N+1, N+1, 2555), np.int64)
dp[0][0][0] = 1
for i in range(N):
  for j in range(N):
    for k in range(2555):
      if dp[i][j][k] == 0: continue
      # not used
      dp[i+1][j][k] += dp[i][j][k]
      # used
      dp[i+1][j+1][k+X[i]] += dp[i][j][k]
ans = 0
for i in range(1, N+1):
  ans += dp[N][i][i*A]
print(ans)  

Fixed submission:
N, A = map(int, input().split())
X = list(map(int, input().split()))
sum_X = sum(X)
dp = [[[0]*(sum_X+1) for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1
for i in range(N):
  for j in range(N):
    for k in range(sum_X):
      if dp[i][j][k] == 0: continue
      # not used
      dp[i+1][j][k] += dp[i][j][k]
      # used
      dp[i+1][j+1][k+X[i]] += dp[i][j][k]
ans = 0
for k in range(1, N+1):
  if k*A <= sum_X:
    ans += dp[N][k][k*A]
print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
from itertools import product

N, K = map(int, input().split())
D = map(int, input().split())
like_num = set(range(0,10)) ^ set(D)
length = len(str(N))
comb = [int("".join(map(str, a))) for a in product(like_num, repeat=length)]
ind = bisect.bisect_left(comb, N)
print(comb[ind])

Fixed submission:
from itertools import product

N, K = map(int, input().split())
D = map(int, input().split())
like_num = set(range(10)) ^ set(D)
length = len(str(N))

for i in range(length, length+2):
  for x in product(like_num,repeat=i):
        d=''.join(map(str,x))
        if int(d)>=N:
          print(d)
          exit()