Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [-1] * N
B = list(map(int, input().split()))

N = int(input())
A = [100001] * N
B = list(map(int, input().split()))

if N == 2:
  print(B[0]*2)
else: 
  for i in range(N-2):
    if A[i] > min(B[i], B[i+1]):
      A[i] = min(B[i], B[i+1])
    if A[i+1] > min(B[i], B[i+1]):
      A[i+1] = min(B[i], B[i+1])

  A[-1] = B[-1]

  print(sum(A))

Fixed submission:
N = int(input())
A = [100001] * N
B = list(map(int, input().split()))

if N == 2:
  print(B[0]*2)
else: 
  for i in range(N-1):
    A[i] = B[i]
  for i in range(N-2):
    if A[i+1] > B[i]:
      A[i+1] = B[i]

  A[-1] = B[-1]

  print(sum(A))
Buggy python submission (verdict: Runtime Error):
N = int(input())

NL = []
PL = []
ans = 0

if N < 10:
  for i in range(N):
    NL.append(i+1)
    PL.append(i+2)
else:
  NL = list(range(1, N+1))
  PL = list(range(2, N+2))
PL[N-1] = 1

for i in range(N):
  ans += NL[i] % PL[i]

print(ans)

Fixed submission:
N = int(input())
print(N*(N-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

NL = []
PL = []
ans = 0

for i in range(N):
  NL.append(i+1)
  PL.append(i+2)
PL[N-1] = 1
  

for i in range(N):
  ans += NL[i] % PL[i]

print(ans)

Fixed submission:
N = int(input())
print(N*(N-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

for i in range(N):
  if sorted(A)[-1] != A[i]:
    print(sorted(A)[-1])
  else:
    print(sorted(A)[-2])

Fixed submission:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = sorted(A)

for i in range(N):
  if B[-1] != A[i]:
    print(B[-1])
  else:
    print(B[-2])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

for i in range(N):
  if max(A) != A[i]:
    print(sorted(A)[-1])
  else:
    print(sorted(A)[-2])

Fixed submission:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = sorted(A)

for i in range(N):
  if B[-1] != A[i]:
    print(B[-1])
  else:
    print(B[-2])

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

for i in range(N):
  if max(A) != A[i]:
    print(max(A))
  else:
    AA = copy.deepcopy(A)
    AA.remove(max(A))
    print(max(AA))

Fixed submission:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = sorted(A)

for i in range(N):
  if B[-1] != A[i]:
    print(B[-1])
  else:
    print(B[-2])
Buggy python submission (verdict: Runtime Error):
A, P = map(int, input().split())

Apple = 3*A + P

if Apple % 2 == 0:
  ans = APPLE/2
else:
  ans = (Apple-1)/2

print(int(ans))

Fixed submission:
A, P = map(int, input().split())
 
Apple = 3*A + P
 
if Apple % 2 == 0:
  ans = Apple/2
else:
  ans = (Apple-1)/2
 
print(int(ans))

Buggy python submission (verdict: Runtime Error):
A, P = map(int, input().split())

APPLE = 3*A + P

if APPLE % 2 = 0:
  ans = APPLE/2
else:
  ans = (Apple-1)/2

print(ans)

Fixed submission:
A, P = map(int, input().split())
 
Apple = 3*A + P
 
if Apple % 2 == 0:
  ans = Apple/2
else:
  ans = (Apple-1)/2
 
print(int(ans))

Buggy python submission (verdict: Runtime Error):
A, P = map(int, input().split())

APPLE = 3*A + P

if APPLE % 2 = 0:
  ans = APPLE/2
else:
  ans = (Apple-1)/2

Fixed submission:
A, P = map(int, input().split())
 
Apple = 3*A + P
 
if Apple % 2 == 0:
  ans = Apple/2
else:
  ans = (Apple-1)/2
 
print(int(ans))
Buggy python submission (verdict: Runtime Error):
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
A.append(list([int(input()) for _ in range(N)]))

print(A)

Fixed submission:
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
A.append([list(map(int, input().split())) for _ in range(N)])
ans = 0  
temp = 0

for i in range(N):
  for j in range(M):
    temp += B[j] * A[0][i][j]
  if temp + C > 0:
    ans += 1
  temp = 0

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())

if N == 1:
  print('Hello World')
else:
  print(int(A+B))

Fixed submission:
N = int(input())
if N == 1:
  print('Hello World')
else:
  A = int(input())
  B = int(input())
  print(int(A+B))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())

if N == 1:
  print('Hello World')
else:
  print(A+B)

Fixed submission:
N = int(input())
if N == 1:
  print('Hello World')
else:
  A = int(input())
  B = int(input())
  print(int(A+B))
Buggy python submission (verdict: Runtime Error):
A = list(input())
T = str(input())

check = 'No'


for i in range(len(A)):
  if ''.join(A) == T:
    check = 'Yes'
  A.insert(A.pop(-1))

print(check)

Fixed submission:
A = list(input())
T = str(input())

check = 'No'

for i in range(len(A)):
  if ''.join(A) == T:
    check = 'Yes'
  A.insert(0, A.pop(-1))

print(check)

Buggy python submission (verdict: Runtime Error):
A = sorted(list(input()))
T = sorted(list(input()))

ans = 'Yes'

for i in range(len(A)):
  if A[i] != T[i]:
    ans = "No'
    
print(ans)

Fixed submission:
A = list(input())
T = str(input())

check = 'No'

for i in range(len(A)):
  if ''.join(A) == T:
    check = 'Yes'
  A.insert(0, A.pop(-1))

print(check)
Buggy python submission (verdict: Runtime Error):
A, B = int(input())

print(max(A+B, A-B, A*B))

Fixed submission:
A, B = map(int, input().split())
 
print(max(A+B, A-B, A*B))
Buggy python submission (verdict: Runtime Error):
S = list(input())

ans = 700

for i in range(S):
  if S[i] == 'o':
    ans += 100

print(ans)

Fixed submission:
S = list(input())

ans = 700
 
for i in range(3):
  if S[i] == 'o':
    ans += 100

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
l = range(A, B+1)
  
for i in range(len(l)):
  if l[i] <= A + K - 1 or B - K + 1 <= l[i]:
    print(l[i])

Fixed submission:
A, B, K = map(int, input().split())
l = []

if B - A + 1 > 2 * K:
  for i in range(K):
    l.append(A + i)
    l.append(B - i)
else:
  l = list(range(A, B+1))
  
l.sort()

for i in l:
  print(i)

Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
l = list(range(A, B+1))

for i in range(len(l)):
  if l[i] <= A + K - 1 or B - K + 1 <= l[i]:
    print(l[i])

Fixed submission:
A, B, K = map(int, input().split())
l = []

if B - A + 1 > 2 * K:
  for i in range(K):
    l.append(A + i)
    l.append(B - i)
else:
  l = list(range(A, B+1))
  
l.sort()

for i in l:
  print(i)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input.split())

if (a * b) % 2 == 0:
  print('Even')
else:
  print('Odd')

Fixed submission:
a, b = map(int, input().split())
 
if (a * b) % 2 == 0:
  print('Even')
else:
  print('Odd')
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
l = []

for i in range(N):
  value = 0
  for j in range(len(list(str(i+1)))):
    value += int(list(str(i+1)))[j]
  if A <= value and value <= B:
    l.append(value)
    
print(sum(l))

Fixed submission:
N, A, B = map(int, input().split())
l = []
 
for i in range(N):
  value = 0
  for j in range(len(list(str(i+1)))):
    value += int(list(str(i+1))[j])
  if A <= value and value <= B:
    l.append(i+1)
    
print(sum(l))
Buggy python submission (verdict: Runtime Error):
X, Y = map(str, input().split())
l = [A, B, C, D, E, F]

if l.index(X) == l.index(y):
  print('=')
elif l.index(X) < l.index(y):
  print('<')
else:
  print('>')

Fixed submission:
X, Y = map(str, input().split())
l = ['A', 'B', 'C', 'D', 'E', 'F']
 
if l.index(X) == l.index(Y):
  print('=')
elif l.index(X) < l.index(Y):
  print('<')
else:
  print('>')
Buggy python submission (verdict: Runtime Error):
C = []
for i in range(2):
  C.append(list(int, input().split()))

if C[0][0] == C[1][2] and C[0][1] == C[1][1] and C[0][2] == C[1][0]:
  print('YES')
else:
  print('NO')

Fixed submission:
C = []
for i in range(2):
  C.append(list(input()))
 
if C[0][0] == C[1][2] and C[0][1] == C[1][1] and C[0][2] == C[1][0]:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

d = collections.Counter(D)
t = collections.Counter(T)

ans = 'YES'
for i in range(len(t)):
    if list(t.values())[i] > d[list(t.keys())[i]]:
        ans = 'NO'

print(ans)



Fixed submission:
import collections

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

d = collections.Counter(D)
t = collections.Counter(T)

ans = 'YES'
t_v = list(t.values())
t_k = list(t.keys())
for i in range(len(t)):
    if t_v[i] > d[t_k[i]]:
        ans = 'NO'

print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(str, input().split())
a = list(A)
b = list(B)
c = list(C)

if a[-1] == b[0] and b[-1] == c[1]:
  print('YES')
else:
  print('NO')

Fixed submission:
A, B, C = map(str, input().split())
a = list(A)
b = list(B)
c = list(C)
 
if a[-1] == b[0] and b[-1] == c[0]:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input.split())
print(max(A*B, C*D))

Fixed submission:
A, B, C, D = map(int, input().split())
print(max(A*B, C*D))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(str(input()))
x = 0
ans = 0

for i in range(len(N)):
  if S[i] == 'I':
    x += 1
  else:
    x -= 1
  if ans < x:
    ans = x
    
print(ans)

Fixed submission:
N = int(input())
S = list(str(input()))
x = 0
ans = 0

for i in range(N):
  if S[i] == 'I':
    x += 1
  else:
    x -= 1
  if ans < x:
    ans = x
    
print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())

for i in range(len(s)):
  if s[i] == ',':
    s[i] == ' '

print(''.join())

Fixed submission:
s = list(input())

for i in range(len(s)):
  if s[i] == ',':
    s[i] = ' '
 
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
A, op, B = map(str, input().split())
A = int(A)
B = int(B)

if op == '+':
  print(A+B)
else:
  pirnt(A-B)

Fixed submission:
A, op, B = map(str, input().split())
A = int(A)
B = int(B)
 
if op == '+':
  print(A+B)
else:
  print(A-B)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split()) 

pathes = {i: set() for i in range(1, n + 1)}
for _ in range(m):
  ai, bi = map(int, input().split()) 
  pathes[ai].add(bi)
  pathes[bi].add(ai)

queue = [None] * n
queue[0] = 1
idx = 1

ans = [None] * n 

for i in queue:
  if idx == n:
    continue
  next_room = pathes[i] - set(queue)
  for j in next_room:
    ans[j-1] = str(i)
    queue[idx] = j
    idx += 1

ans[0] = "Yes"

print("\n".join(ans))


Fixed submission:
from collections import deque

n, m = map(int, input().split()) 

pathes = {i: set() for i in range(1, n + 1)}
for _ in range(m):
  ai, bi = map(int, input().split()) 
  pathes[ai].add(bi)
  pathes[bi].add(ai)

queue = deque()
queue.append(1)

ans = [None] * n 

for _ in range(n):
  if len(queue) == 0:
    break;
  i = queue.popleft()
  next_room = pathes[i]
  for j in next_room:
    if ans[j-1] == None:
      ans[j-1] = str(i)
      queue.append(j)

ans[0] = "Yes"

print("\n".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split()) 

pathes = {i: set() for i in range(1, n + 1)}
for _ in range(m):
  ai, bi = map(int, input().split()) 
  pathes[ai].add(bi)
  pathes[bi].add(ai)

queue = [None] * n
queue[0] = 1
idx = 1

ans = [None] * n 

for i in queue:
  next_room = pathes[i] - set(queue)
  for j in next_room:
    ans[j-1] = str(i)
    queue[idx] = j
    idx += 1

ans[0] = "Yes"

print("\n".join(ans))


Fixed submission:
from collections import deque

n, m = map(int, input().split()) 

pathes = {i: set() for i in range(1, n + 1)}
for _ in range(m):
  ai, bi = map(int, input().split()) 
  pathes[ai].add(bi)
  pathes[bi].add(ai)

queue = deque()
queue.append(1)

ans = [None] * n 

for _ in range(n):
  if len(queue) == 0:
    break;
  i = queue.popleft()
  next_room = pathes[i]
  for j in next_room:
    if ans[j-1] == None:
      ans[j-1] = str(i)
      queue.append(j)

ans[0] = "Yes"

print("\n".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

r = [0] * n
g = [0] * n
b = [0] * n
ri = gi = bi = 0
for i, c in enumerate(s):
  if c == "R":
    ri += 1
  elif c == "G":
    gi += 1
  if c == "B":
    bi += 1
  r[i] = ri
  g[i] = gi
  b[i] = bi

 
ans = 0

for k in range(2, n):
  for j in range(1, k):
    if s[k] == s[j]:
      continue
    i = 2 * j - k
    x = None
    c = None
    if s[k] != "R" and s[j] != "R":
      x = r
      c = "R"
    elif s[k] != "G" and s[j] != "G":
      x = g
      c = "G"
    elif s[k] != "B" and s[j] != "B":
      x = b
      c = "B"
    ans += x[j - 1]
    if i >= 0 and s[i] == c:
      ans -= 1


print(ans)

Fixed submission:
n = int(input())
s = input()

r = [0] * n
g = [0] * n
b = [0] * n
ri = gi = bi = 0
for i, c in enumerate(s):
  if c == "R":
    ri += 1
  elif c == "G":
    gi += 1
  if c == "B":
    bi += 1
  r[i] = ri
  g[i] = gi
  b[i] = bi

 
ans = r[-1] * g[-1] * b[-1]

for k in range(2, n):
  for j in range(1, k):
    if s[k] == s[j]:
      continue
    i = 2 * j - k
    if i < 0 :
      continue
    if s[k] != s[i] and s[j] != s[i]:
      ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a_pop = {}

for ai in a:
  if not a_pop.get(ai):
    a_pop[ai] = 1
  else:
    a_pop[ai] += 1

for ai in a:
  ans = 0
  for k, v in a_pop.items():
    if k == ai:
      if v > 2:
        ans += (v - 1) * (v - 2) // 2
    else:
      if v > 1:
        ans += v * (v - 1) // 2
  print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a_pop = {}

for ai in a:
  if not a_pop.get(ai):
    a_pop[ai] = 1
  else:
    a_pop[ai] += 1

hoge = sum(v * (v - 1) // 2 for v in a_pop.values())

for ai in a:
  ans = hoge
  v = a_pop[ai]
  print(ans - (v - 1))
Buggy python submission (verdict: Time Limit Exceeded):
n, s = map(int, input().split())
a = list(map(int, input().split()))

dp = [[1 if _2 == 0 else 0 for _2 in range(s + 1)] for _1 in range(n+1)]

MOD = 998244353

for i, ai in enumerate(a):
  for j, v in enumerate(dp[i]):
    dp[i + 1][j] += v
    dp[i + 1][j] %= MOD 
    if j + ai <= s:
      dp[i + 1][j + ai] += v
      dp[i + 1][j + ai] %= MOD


print(sum(dp_i[s] for dp_i in dp) % MOD)
    

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

dp = [[1 if _2 == 0 else 0 for _2 in range(s + 1)] for _1 in range(n+1)]

MOD = 998244353

for i, ai in enumerate(a):
  for j, v in enumerate(dp[i]):
    dp[i + 1][j] += v
    dp[i + 1][j] %= MOD 
    if j + ai <= s:
      dp[i + 1][j + ai] += v
      dp[i + 1][j + ai] %= MOD


print(sum(dp_i[s] for dp_i in dp) % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n, s = map(int, input().split())
a = list(map(int, input().split()))

dp = [[[] for _2 in range(s + 1)] for _1 in range(n)]

for i, ai in enumerate(a):
  if ai <= s:
    dp[i][ai].append((i, i))
  if i > 0:
    for j, t in enumerate(dp[i-1]):
      for r, l in t:
        dp[i][j].append((r, l))
        if j + ai <= s:
          dp[i][j + ai].append((r, i))
        
print(sum((r + 1) * (n - l) for r, l in dp[n-1][s]))
    

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

dp = [[1 if _2 == 0 else 0 for _2 in range(s + 1)] for _1 in range(n+1)]

MOD = 998244353

for i, ai in enumerate(a):
  for j, v in enumerate(dp[i]):
    dp[i + 1][j] += v
    dp[i + 1][j] %= MOD 
    if j + ai <= s:
      dp[i + 1][j + ai] += v
      dp[i + 1][j + ai] %= MOD


print(sum(dp_i[s] for dp_i in dp) % MOD)
Buggy python submission (verdict: Runtime Error):
s = input()

if s == "AAA" or s == "BBB":
  print("No")
else
  print("Yes")

Fixed submission:
s = input()

if s == "AAA" or s == "BBB":
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
s = input() 
q = int(input())

for _ in range(q):
  query = input()
  if query[0] == "1":
    s = s[::-1]
  else:
    ti, fi, ci = query.split()
    if fi == "1":
      s = ci + s  
    else:
      s = s + ci

print(s)

Fixed submission:
from collections import deque

s = input() 
s_queue = deque(s)
q = int(input())

inverted = False

for _ in range(q):
  query = input()
  if query[0] == "1":
    inverted = not inverted 
  else:
    ti, fi, ci = query.split()
    if fi == "1" and inverted:
      s_queue.append(ci)
    elif fi == "1" and not inverted:
      s_queue.appendleft(ci)
    elif fi == "2" and inverted:
      s_queue.appendleft(ci)
    else:
      s_queue.append(ci)

if inverted:
  print("".join(s_queue)[::-1])
else:
  print("".join(s_queue))
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())

MOD = 1000000007

def pow_mod(x, y):
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD 

mod_inv = lambda x: pow_mod(x, MOD - 2)

nCk = {0: 1}

for i in range(1, max(a,b) + 1):
  nCk[i] = nCk[i-1] * ((n-i+1) % MOD)
  nCk[i] %= MOD
  nCk[i] *= mod_inv(i)
  nCk[i] %= MOD

print((pow_mod(2, n) - 1 - nCk[a] - nCk[b]) % MOD)



Fixed submission:
n, a, b = map(int, input().split())

MOD = 1000000007

def pow_mod(x, y):
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD 

mod_inv = lambda x: pow_mod(x, MOD - 2)

nCk = {0: 1}

for i in range(1, max(a,b) + 1):
  nCk[i] = nCk[i-1] * ((n-i+1) % MOD)
  nCk[i] %= MOD
  nCk[i] *= mod_inv(i)
  nCk[i] %= MOD

print((pow_mod(2, n) - 1 - nCk[a] - nCk[b]) % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))


MOD = 1000000007 

def pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= MOD  
        x *= x
        x %= MOD 
        y //= 2
    return ans * x % MOD


def mod_inv(x):
  return pow(x, MOD - 2)

ans = 0
xCk_1 = {}
for i in range(k - 1, n):
  if i == k - 1:
    xCk_1[i] = 1
  else:
    xCk_1[i] = i * xCk_1[i - 1] * mod_inv(i - k + 1)

  ans += ((a[i] - a[n - i - 1]) % MOD) * xCk_1[i]
  ans %= MOD

print(ans)

Fixed submission:
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))


MOD = 1000000007 

def pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= MOD  
        x *= x
        x %= MOD 
        y //= 2
    return ans * x % MOD


def mod_inv(x):
  return pow(x, MOD - 2)

ans = 0
xCk_1 = {}
for i in range(k - 1, n):
  if i == k - 1:
    xCk_1[i] = 1
  else:
    xCk_1[i] = (((i * xCk_1[i - 1]) % MOD) * mod_inv(i - k + 1)) % MOD

  ans += ((a[i] - a[n - i - 1]) % MOD) * xCk_1[i]
  ans %= MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())

x = math.ceil(n / 1.08)

if n == math.floor(x * 1.08):
  print(x)
else:
  prtnt(":(")

Fixed submission:
import math
 
n = int(input())
 
x = math.ceil(n / 1.08)
 
if n == math.floor(x * 1.08):
  print(x)
else:
  print(":(")
Buggy python submission (verdict: Time Limit Exceeded):

n, m = map(int, input().split())

dp = [[float("inf") for _ in range(2 ** n)] for i in range(m + 1)]
dp[0][0] = 0

pattern = {0}

for i in range(1, m+1):
  ai, bi = map(int, input().split()) 
  ci_bit = sum(2 ** (cij - 1) for cij in map(int, input().split()))
  new_pattern = set()
  for j in pattern:
    dp[i][j | ci_bit] = min(dp[i][j | ci_bit], dp[i-1][j] + ai)
    dp[i][j] = min(dp[i][j], dp[i-1][j])
    new_pattern.add(j | ci_bit)
  pattern |= new_pattern


print(-1 if dp[m][2**n - 1] == float("inf") else dp[m][2**n - 1])

Fixed submission:
# 15:20-

n, m = map(int, input().split())

dp = [[float("inf") for _ in range(2 ** n)] for i in range(m + 1)]
dp[0][0] = 0

pattern = {0}

for i in range(1, m+1):
  ai, bi = map(int, input().split()) 
  ci_bit = sum(2 ** (cij - 1) for cij in map(int, input().split()))
  new_pattern = set()
  for j in pattern:
    dp[i][j | ci_bit] = min(dp[i][j | ci_bit], dp[i-1][j] + ai)
    dp[i][j] = min(dp[i][j], dp[i-1][j])
    new_pattern.add(j | ci_bit)
  pattern |= new_pattern


print(-1 if dp[m][2**n - 1] == float("inf") else dp[m][2**n - 1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

s_dict = {c:[] for c in s}
for i, c in enumerate(s):
  s_dict[c].append(i)

len_s = len(s)

ans = 0
prev_i = -1
for c in t:
  if c not in s_dict:
    ans = -1
    prev_i = -1
    break;
  else:
    if s_dict[c][-1] <= prev_i:
      ans += len_s 
      prev_i = min(i for i in s_dict[c])
    else:
      prev_i = min(i for i in s_dict[c] if i > prev_i)


print(ans + prev_i + 1)

Fixed submission:
#14:20-


import bisect

s = input()
t = input()

s_dict = {c:[] for c in s}
for i, c in enumerate(s):
  s_dict[c].append(i)

len_s = len(s)

ans = 0
prev_i = -1
for c in t:
  if c not in s_dict:
    ans = -1
    prev_i = -1
    break;
  else:
    if s_dict[c][-1] <= prev_i:
      ans += len_s 
      prev_i = s_dict[c][0]
    else:
      prev_i = s_dict[c][bisect.bisect_right(s_dict[c], prev_i, lo=0, hi=len(s_dict[c]))]


print(ans + prev_i + 1)
Buggy python submission (verdict: Runtime Error):
import bisect


def main():
  n = int(input())
  a = [int(input()) for _ in range(n)]

  tail = []
  len_tail = 0
  for ai in a:
    print(tail, ai)
    idx = bisect.bisect_left(tail, -ai, lo=0, hi=len_tail) 
    if idx == len_tail:
      tail.append(-ai)
      len_tail += 1
    else:
      tail[idx] = - ai

  print(len_tail )


if __name__ == "__main__":
  main()

Fixed submission:

import bisect


def main():
  n = int(input())
  a = [int(input()) for _ in range(n)]

  tail = []
  len_tail = 0
  for ai in a:
    idx = bisect.bisect_right(tail, -ai, lo=0, hi=len_tail) 
    if idx == len_tail:
      tail.append(-ai)
      len_tail += 1
    else:
      tail[idx] = - ai

  print(len_tail )


if __name__ == "__main__":
  main()