Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
input = sys.stdin.readline

N = int(input())
S = input().strip()

s = 0
for i in range(N):
	for j in range(i+1, N):
		if S[j] == S[i]: continue
		dif = j - i
		for k in range(j+1, N):
			if S[j] == S[k] or S[k] == S[i]: continue
			if k-j == j-i: continue
			s += 1

print(s)

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

N = int(input())
S = input().strip()

cnt = collections.Counter(S)
ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
	for d in range(1,N):
		j, k = i+d, i+2*d
		if k > N-1: break
		if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
			ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
H, W, K = list(map(int, input().split()))

choco = []
for i in range(H):
  s = input().strip()
  a = list(map(int, list(s)))
  choco.append(a)

def f(n):
  if n == 1:
    return [[0], [1]]
  a = f(n-1)
  na = []
  for v in a:
    na.append([0] + v)
    na.append([1] + v)
  return na

def min_split(h):
  sum_cnt = [0] * H
  num_split = 0
  for j in range(W):
    c = 0
    cnt = [0] * H
    for i in range(H):
      if choco[i][j] == 1:
        cnt[c] += 1
      if i < H-1 and h[i] == 1:
        c += 1
    new_cnt = [x + y for x, y in zip(sum_cnt, cnt)]
    if max(new_cnt) > K:
      num_split += 1
      sum_cnt = cnt
    else:
      sum_cnt = new_cnt
  return num_split + sum(h)

min_m = float('inf')
for h in f(H-1):
  m = min_split(h)
  min_m = min(min_m, m)
print(min_m)

Fixed submission:
import sys, itertools
input = sys.stdin.readline
H, W, K = list(map(int, input().split()))

choco = []
for i in range(H):
  s = input().strip()
  a = list(map(int, list(s)))
  choco.append(a)

def min_split(h):
  sum_cnt = [0] * H
  num_split = 0
  for j in range(W):
    c = 0
    cnt = [0] * H
    flag = False
    for i in range(H):
      if choco[i][j] == 1:
        cnt[c] += 1
        if cnt[c] > K:
          return float('inf')
        if cnt[c] + sum_cnt[c] > K:
          flag = True
      if i < H-1 and h[i] == 1:
        c += 1
    if flag:
      num_split += 1
      sum_cnt = cnt
    else:
      for i in range(len(cnt)):
      	sum_cnt[i] += cnt[i]
  return num_split + sum(h)

min_m = float('inf')
for h in itertools.product([0,1], repeat=H-1):
  m = min_split(h)
  min_m = min(min_m, m)
print(min_m)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
s = input()
N, A, B = map(int, s.split())

a = 0
while N > 0:
  N -= A
  if N >= 0:
  	a += A
  else:
    a += A + N
  N -= B

print(a)

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

N, A, B = list(map(int, input().split()))

d = N // (A+B)
m = N % (A+B)

print(d * A + min(m, A))
Buggy python submission (verdict: Runtime Error):
import sys
import collections
input = sys.stdin.readline

N, M, K = map(int, input().split())
F = []
for i in range(M):
	F.append(list(map(int, input().split())))
B = []
for i in range(K):
	B.append(list(map(int, input().split())))

def get_group(F):
	def root(a):
		if G[a] == a: return a
		G[a] = root(G[a])
		return G[a]
	def union(a, b):
		ra = root(a)
		rb = root(b)
		if ra == rb: return
		G[ra] = rb
	G = [i for i in range(N)]
	for a, b in F:
		a -= 1
		b -= 1
		union(a, b)
	for i in range(N):
		G[i] = root(i)
	return G

def calc_count(F, G):
	edges = collections.defaultdict(set)
	for a, b in F:
		a -= 1
		b -= 1
		if G[a] == G[b]:
			edges[a].add(b)
			edges[b].add(a)
	cnt = [0] * N
	for i in range(N):
		cnt[i] = len(edges[i])
	return cnt

def get_num(c, f, b):
	ret = (c-1) - f - b
	return ret

G = get_group(F)
C = collections.Counter(G)
FC = calc_count(F, G)
BC = calc_count(B, G)
ans = [0] * N
for i in range(N):
	ans[i] = get_num(C[G[i]], FC[i], BC[i])

print(' '.join(map(str, ans)))


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

N, M, K = map(int, input().split())
F = []
for i in range(M):
	F.append(list(map(int, input().split())))
B = []
for i in range(K):
	B.append(list(map(int, input().split())))

def get_group(F):
	def root(a):
		p = G[a]
		while p != G[p]:
			p = G[p]
		while a != p:
			a, G[a] = G[a], p
		return p
	def union(a, b):
		ra = root(a)
		rb = root(b)
		if ra == rb: return
		G[ra] = rb
	G = [i for i in range(N)]
	for a, b in F:
		a -= 1
		b -= 1
		union(a, b)
	for i in range(N):
		G[i] = root(i)
	return G

def calc_count(F, G):
	edges = collections.defaultdict(set)
	for a, b in F:
		a -= 1
		b -= 1
		if G[a] == G[b]:
			edges[a].add(b)
			edges[b].add(a)
	cnt = [0] * N
	for i in range(N):
		cnt[i] = len(edges[i])
	return cnt

def get_num(c, f, b):
	ret = (c-1) - f - b
	return ret

G = get_group(F)
C = collections.Counter(G)
FC = calc_count(F, G)
BC = calc_count(B, G)
ans = [0] * N
for i in range(N):
	ans[i] = get_num(C[G[i]], FC[i], BC[i])

print(' '.join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
ini = lambda: int(input())
inl = lambda: list(map(int, input().split()))
ins = lambda: input().strip()

N, K = inl()
A = inl()

import itertools

ps = []
for c in itertools.combinations(A, 2):
	ps.append(c[0] * c[1])
ps.sort()
print(ps[K-1])


Fixed submission:
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

def comb(n, k):
	p, q = 1, 1
	for i in range(1, k+1):
		p = p * (n-i+1)
		q = q * i
	return p // q

def binsearch(l, r, f):
	while r - l > 1:
		c = (r + l) // 2
		if f(c):
			r = c
		else:
			l = c
	return r

N, K = rl()
A = rl()

pos = 0
neg = 0
zero = 0
Ap = []
An = []
for a in A:
	if a > 0:
		pos += 1
		Ap.append(a)
	elif a < 0:
		neg += 1
		An.append(a)
	else:
		zero += 1
Ap.sort()
An.sort()
n_pos = comb(pos, 2) + comb(neg, 2)
n_neg = pos * neg
n_zero = zero*(N-zero) + comb(zero, 2)

def num_gt(A, x):
	j = len(A) - 1
	cnt = 0
	for i in range(len(A)):
		while i < j and A[i] * A[j] > x:
			j -= 1
		if i >= j:
			break
		cnt += max(j - i, 0)
	return cnt

def num_gt2(A, B, x):
	j = len(B) - 1
	cnt = 0
	for i in reversed(range(len(A))):
		while j >= 0 and A[i] * B[j] > x:
			j -= 1
		if j < 0:
			break
		cnt += max(j+1, 0)
	return cnt

def check_plus(x):
	cnt = n_neg + n_zero
	cnt += num_gt(Ap, x)
	cnt += num_gt(list(reversed(An)), x)
	return cnt >= K

def check_minus(x):
	cnt = num_gt2(Ap, An, x)
	return cnt >= K

ans = 0
if K <= n_neg:
	l = An[0] * Ap[-1] - 1
	r = 0
	ans = binsearch(l, r, check_minus)
elif K <= n_neg + n_zero:
	ans = 0
else:
	l = 0
	r = 1
	if len(Ap) >= 2:
		r = max(r, Ap[-1] * Ap[-2]) + 1
	if len(An) >= 2:
		r = max(r, An[0] * An[1]) + 1
	ans = binsearch(l, r, check_plus)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

if N == M:
    print('Yes')
else:
    print('No')

Fixed submission:
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, M = rl()

if N == M:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, A, B = map(int, input())

if (A - B) % 2 == 0:
	print((A - B) // 2)
else:
	n = min(A-1, N-B) + (B-A-1)//2 + 1
	print(n)


Fixed submission:
import sys
input = sys.stdin.readline
N, A, B = map(int, input().split())

if (B-A) % 2 == 0:
	print((B - A) // 2)
else:
	n = min(A-1, N-B) + (B-A-1)//2 + 1
	print(n)
Buggy python submission (verdict: Time Limit Exceeded):
import sys, math
from pprint import pprint
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()

b = [0] * 60

def count(a, b):
	i = len(b)-1
	while a:
		b[i] += a % 2
		a //= 2
		i -= 1
	return i+1

def sum_xor(a, b, l):
	i = len(b)-1
	e = 1
	s = 0
	for i in reversed(range(len(b))):
		if a % 2 == 0:
			s += b[i] * e % mod
		else:
			s += (l-(b[i])) * e % mod
		a //= 2
		e = e * 2 % mod
		s = s % mod
	return s

ans = 0
for i in range(N):
	if i > 0:
		ans = (ans + sum_xor(A[i], b, i)) % mod
	count(A[i], b)
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()

b = [0] * 60

def count(a, b):
	i = len(b)-1
	while a:
		b[i] += a % 2
		a //= 2
		i -= 1
	return i+1

def sum_xor(a, b, l, left):
	i = len(b)-1
	e = 1
	s = 0
	while a or left <= i:
		if a % 2 == 0:
			s = (s + b[i] * e) % mod
		else:
			s = (s + (l-(b[i])) * e) % mod
		a //= 2
		e = e * 2 % mod
		i -= 1
	return s

ans = 0
min_left = 60
for i in range(N):
	if i > 0:
		ans = (ans + sum_xor(A[i], b, i, min_left)) % mod
	left = count(A[i], b)
	min_left = min(min_left, left)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7


N, K, Q = rl()
A = []
for i in range(Q):
	a = ri()
	A.append(a)

scores = [K] * N
for a in A:
	idx = a-1
	for i in range(N):
		if i != idx:
			scores[i] -= 1
for s in scores:
	if s > 0:
		print('Yes')
	else:
		print('No')

Fixed submission:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7


N, K, Q = rl()
A = []
for i in range(Q):
	a = ri()
	A.append(a)

scores = [0] * N
for a in A:
	idx = a-1
	scores[idx] += 1

for s in scores:
	if K > Q-s:
		print('Yes')
	else:
		print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
S = rs()

def get_max(i):
	ok, ng = i, len(S)
	while ng-ok > 1:
		c = (ok+ng)//2
		if S[i:c] in S[c:]:
			ok = c
		else:
			ng = c
	return ok-i

ans = 0
for i in range(N):
	l = get_max(i)
	ans = max(ans, l)
print(ans)


Fixed submission:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
S = rs()

dp = [[0] * (N+1) for _ in range(N+1)]

ans = 0
for i in range(N):
	for j in range(i+1,N):
		if S[i] == S[j]:
			if i+1 < j+1-(dp[i][j]+1)+1:
				dp[i+1][j+1] = dp[i][j]+1
			else:
				dp[i+1][j+1] = 0
			ans = max(ans, dp[i+1][j+1])
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

s = rs()
t = rs()


import collections
pos = collections.defaultdict(list)
for i, c in enumerate(s):
	pos[c].append(i)

import bisect

def bisect_right(arr, x):
    # a_i <= x < a_{i+1}
    l, r = 0, len(arr)
    while r - l > 1:
        c = (r + l) // 2
        if x >= arr[c]:
            l = c
        else:
            r = c
    return r

num = 0
cur = -1

for c in t:
	if c not in pos:
		print(-1)
		exit()
	#i = bisect.bisect_right(pos[c], cur)
	i = search(pos[c], cur)
	if i == len(pos[c]):
		i = 0
		num += 1
	cur = pos[c][i]
print(num*len(s)+cur+1)



Fixed submission:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

s = rs()
t = rs()


import collections
pos = collections.defaultdict(list)
for i, c in enumerate(s):
	pos[c].append(i)

import bisect

num = 0
cur = -1

for c in t:
	if c not in pos:
		print(-1)
		exit()
	i = bisect.bisect_right(pos[c], cur)
	if i == len(pos[c]):
		i = 0
		num += 1
	cur = pos[c][i]
print(num*len(s)+cur+1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, M = rl()
E = defaultdict(list)
for i in range(M):
	u, v = rl()
	E[u-1].append(v-1)
	#E[v-1].append(u-1)
S, T = rl()
S -= 1
T -= 1

dp = [[float('inf')]*3 for i in range(N)]

def dfs(n, d):
	for m in E[n]:
		r = (d+1)%3
		if dp[m][r] > d+1:
			dp[m][r] = d+1
			dfs(m, d+1)

dfs(S, 0)
if dp[T][0] != float('inf'):
	print(dp[T][0]//3)
else:
	print(-1)


Fixed submission:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, M = rl()
E = defaultdict(list)
for i in range(M):
	u, v = rl()
	E[u-1].append(v-1)
S, T = rl()
S -= 1
T -= 1

dp = [[float('inf')]*3 for i in range(N)]

heap = []
heappush(heap, (0, S, 0))
while heap:
	d, n, r = heappop(heap)
	if n == T and r == 0:
		continue
	#if dp[n][r] != d:
	#	continue
	nr = (d+1)%3
	for m in E[n]:
		if dp[m][nr] > d+1:
			dp[m][nr] = d+1
			heappush(heap, (d+1, m, nr))

if dp[T][0] != float('inf'):
	print(dp[T][0]//3)
else:
	print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

class BIT:
	def __init__(self, n):
		self.n = n
		self.nums = [0] * (n+1)
		
	def add(self, i, x):
		n, nums = self.n, self.nums
		i += 1
		while i <= n:
			nums[i] += x
			i += i & -i
	
	def sum(self, i):
		nums = self.nums
		s = 0
		i += 1
		while i:
			s += nums[i]
			i -= i & -i
		return s
	
	def search(self, x):
		n, nums = self.n, self.nums
		s, p = 0, 0
		for i in range(n.bit_length(), -1, -1):
			np = p + (1<<i)
			if np <= n and s+nums[np] < x:
				s += nums[np]
				p = np
		return p

N, M = rl()
S = rl()
T = rl()

h = defaultdict(list)
for i, t in enumerate(T):
	h[t].append(i)
bit = BIT(M+1)
for i, s in enumerate(S):
	vals = []
	for j in h[s]:
		vals.append((j, bit.sum(j)+1))
	for j, v in vals:
		bit.add(j+1, v%mod)
print((bit.sum(M)+1)%mod)


Fixed submission:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

class BIT:
	def __init__(self, n):
		self.n = n
		self.nums = [0] * (n+1)
		
	def add(self, i, x):
		n, nums = self.n, self.nums
		i += 1
		while i <= n:
			nums[i] += x
			i += i & -i
	
	def sum(self, i):
		nums = self.nums
		s = 0
		i += 1
		while i:
			s += nums[i]
			i -= i & -i
		return s
	
	def search(self, x):
		n, nums = self.n, self.nums
		s, p = 0, 0
		for i in range(n.bit_length(), -1, -1):
			np = p + (1<<i)
			if np <= n and s+nums[np] < x:
				s += nums[np]
				p = np
		return p

N, M = rl()
S = rl()
T = rl()

h = defaultdict(list)
for i, t in enumerate(T):
	h[t].append(i)
bit = BIT(M+1)
for i, s in enumerate(S):
	vals = []
	for j in h[s]:
		vals.append((j, bit.sum(j)+1))
	for j, v in vals:
		bit.add(j+1, v%mod)
print((bit.sum(M)+1)%mod)
Buggy python submission (verdict: Runtime Error):
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

H, W = rl()
S = []
for i in range(H):
  s = rs()
  S.append(s + '#')
S.append('#'*(W+1))

tab = [[0 for _ in range(W+1)] for _ in range(H+1)]

for i in range(H):
  k = 0
  prev = -1
  for j in range(W+1):
    if S[i][j] == '#':
      n = j-prev-1
      while k < j:
        tab[i][k] += n
        k += 1
      tab[i][k] = 0
      k += 1
      prev = j

for j in range(W):
  k = 0
  prev = -1
  for i in range(H+1):
    if S[i][j] == '#':
      n = i-prev-1
      while k < i:
        tab[k][j] += n - 1
        k += 1
      tab[k][j] = 0
      k += 1
      prev = i

ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans, tab[i][j])
print(ans)


Fixed submission:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

L = rs()

n = len(L)
dp = [[0]*2 for i in range(n+1)]
dp[0][0] = 1

for i in range(n):
	if L[i] == '0':
		dp[i+1][0] += dp[i][0] % mod # (0,0)
		dp[i+1][1] += dp[i][1] % mod # (0,0)
		dp[i+1][1] += dp[i][1]*2 % mod # (1,0), (0,1)
	else:
		dp[i+1][1] += dp[i][0] + dp[i][1] % mod # (0,0)
		dp[i+1][0] += dp[i][0]*2 % mod # (0,1), (1,0)
		dp[i+1][1] += dp[i][1]*2 % mod # (0,1), (1,0)
print((dp[n][0]+dp[n][1])%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
def f(a):
  if len(a) == 0:
    return []
  for i in range(len(a)):
    if a[i] == i+1:
      b = a.copy()
      b.pop(i)
      ret = f(b)
      if ret == [-1]:
        continue
      ret.append(i+1)
      return ret
    else:
      continue
  else:
    return [-1]
ret = f(a)
print('\n'.join(map(str,ret)))

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
acts = []
while True:
    for i in range(len(a)):
        idx = len(a)-i-1
        if a[idx] == idx+1:
            a.pop(idx)
            acts.append(idx+1)
            break
    else:
        print('-1')
        break
    if len(a) == 0:
        acts.reverse()
        print('\n'.join(map(str,acts)))
        break
Buggy python submission (verdict: Runtime Error):
INPUT
3 5
4 2 1
2 3 1
OUTPUT
2
INPUT
3 8
4 2 1
2 3 1
OUTPUT
0
INPUT
11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2
OUTPUT
12

n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=1)
su=ok=ng=0
for i in range(n):
  ok=max(ok,a[i]*f[i])
  su+=a[i]
if su<=k:print(0);exit()
while ng+1<ok:
  mid=(ok+ng)//2
  h=0
  for i in range(n):
    h+=max(a[i]-(mid//f[i]), 0)
  if h<=k:ok=mid
  else:ng=mid
print(ok)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=1)
su=ok=ng=0
for i in range(n):
  ok=max(ok,a[i]*f[i])
  su+=a[i]
if su<=k:print(0);exit()
while ng+1<ok:
  mid=(ok+ng)//2
  h=0
  for i in range(n):
    r=a[i]-(mid//f[i])
    if (r<0):
      r=0
    h+=r
  if h<=k:ok=mid
  else:ng=mid
print(ok)

Buggy python submission (verdict: Runtime Error):
        n,k=map(int,input().split())
        a=list(map(int,input().split()))
        f=list(map(int,input().split()))
        a.sort()
        f.sort(reverse=1)
        su=ok=ng=0
        for i in range(n):
          ok=max(ok,a[i]*f[i])
          su+=a[i]
        if su<=k:print(0);exit()
        while ng+1<ok:
          mid=(ok+ng)//2
          h=0
          for i in range(n):
            h+=a[i]-(f[i]/mid)
          if h<=k:ok=mid
          else:ng=mid
        print(ok)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=1)
su=ok=ng=0
for i in range(n):
  ok=max(ok,a[i]*f[i])
  su+=a[i]
if su<=k:print(0);exit()
while ng+1<ok:
  mid=(ok+ng)//2
  h=0
  for i in range(n):
    r=a[i]-(mid//f[i])
    if (r<0):
      r=0
    h+=r
  if h<=k:ok=mid
  else:ng=mid
print(ok)
Buggy python submission (verdict: Runtime Error):
from collections import deque
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)
deg=[0 for i in range(N)]
for i in range(N):
	for p in G[i]:
		deg[p]+=1
q=deque(i for i in range(N) if deg[i]==0)
res=[]
while q:
	u=q.popleft()
	res.append(u)
	for v in G[u]:
		deg[v]-=1
		if K[v]==0:
			q.append(v)
if len(res)==N:
	print(-1)
	exit()
X={i for i in range(N)}
for st in range(N):
	pre=[-1 for i in range(N)]
	q=deque([st])
	flag=0
	while(q):
		r=q.popleft()
		for p in G[r]:
			if pre[p]==-1:
				pre[p]=r
				q.append(p)
			if before[st]!=-1:
				Y={st}
				tmp=pre[st]
				while(tmp!=st):
					Y.add(tmp)
					tmp=before[tmp]
				if len(Y)<len(X):
					X={i for i in Y}
				flag=1
				break
		if flag:
			break
print(len(X))
for i in X:
	print(i+1)

Fixed submission:
from collections import deque
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)
deg=[0 for i in range(N)]
for i in range(N):
	for p in G[i]:
		deg[p]+=1
q=deque(i for i in range(N) if deg[i]==0)
res=[]
while q:
	u=q.popleft()
	res.append(u)
	for v in G[u]:
		deg[v]-=1
		if deg[v]==0:
			q.append(v)
if len(res)==N:
	print(-1)
	exit()
X={i for i in range(N)}
for st in range(N):
	pre=[-1 for i in range(N)]
	q=deque([st])
	flag=0
	while(q):
		r=q.popleft()
		for p in G[r]:
			if pre[p]==-1:
				pre[p]=r
				q.append(p)
			if pre[st]!=-1:
				Y={st}
				tmp=pre[st]
				while(tmp!=st):
					Y.add(tmp)
					tmp=pre[tmp]
				if len(Y)<len(X):
					X={i for i in Y}
				flag=1
				break
		if flag:
			break
print(len(X))
for i in X:
	print(i+1)
Buggy python submission (verdict: Runtime Error):
def main():
    N, X, M = map(int, input().split())
    NN = N
    li = []
    while X not in li and N != 0:
        li = li + [X]
        X = X ** 2 % M
        N -= 1
    
    if N == 0:
        print(sum(x for x in li))

    elif N != 0 and X in li:
        l = len(li)
        s = li.index(X)
        T = l - s
        q = (NN - s) // T
        r = (NN - s) % T
        print(sum(li[i] for i in range(s)) + sum(li[i] for i in range(s, len(li))) * q + sum(li[i] for i in range(s, s + r)))


main()

Fixed submission:
S = input()
l = len(S)
if S[l-1] != 's':
    print(S + 's')
else:
    print(S + 'es')
Buggy python submission (verdict: Runtime Error):
def main():
    N = input()
    print((10 ** N - 9 ** N - 9 ** N + 8 ** N)%(10**9 + 7))

main()

Fixed submission:
def main():
    N = int(input())
    print((10**N - 9**N - 9**N + 8**N)%(10**9 + 7))

main()