Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    T=ST()
    N=len(S)
    M=len(T)
    ans = []
    for i in range(N-M+1)[::-1]:
        can = True
        for s,t in zip(S[i:],T):
            if s!=t and s!="?":
                can = False
        if can:
            for j,s in enumerate(S):
                if j<i:
                    if s=="?":
                        ans.append("a")
                    else:
                        ans.append(s)
                else:
                    ans.append(T[j-i])
            break
    if ans:
        print(*ans,sep="")
    else:
        print("UNRESTORABLE")
if __name__ == '__main__':
    main()

Fixed submission:
S = input()
T = input()
for i in reversed(range(len(S) - len(T) + 1)):
    frag = True
    for j in range(len(T)):
        if S[i + j] == T[j] or S[i + j] == "?":
            continue
        else:
            frag = False
            break
    if frag:
        ans = S[:i] + T
        if i + len(T) < len(S):
            ans += S[i + len(T):]
        ans = ans.replace("?", "a")
        print(ans)
        exit()
print("UNRESTORABLE")
Buggy python submission (verdict: Runtime Error):
print("YNEOS"[int(input().replace(" ",""))%4!=0::2]

Fixed submission:
print("YNEOS"[int(input().replace(" ",""))%4!=0::2])
Buggy python submission (verdict: Runtime Error):
l,r,d=map(input().split(""))
c=0
for i in range(l,r+1,1):
  if i%d==0:
    c+=1
print(c)


Fixed submission:
l,r,d=map(int,input().split(" "))
c=0
for i in range(l,r+1,1):
    if i%d==0:
        c+=1
print(c)
Buggy python submission (verdict: Runtime Error):

class UnionFind:
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]

    def find(self, s):
        if self.parent[s] < 0:
            return s
        self.parent[s] = self.find(self.parent[s])
        return self.parent[s]

    def union(self, a, b):
        a, b = self.find(a), self.find(b)
        if a == b:
            return
        self.parent[a] += self.parent[b]
        self.parent[b] = a

    def size(self, x):
        return -1 * self.parent[self.find(x)]

n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    a, b = list(map(int, input().split()))
    uf.union(a - 1, b - 1)
print(max([uf.size(i) for i in range(n)]))



Fixed submission:
import sys
sys.setrecursionlimit(10**9)
 
n, m = map(int, input().split())
 
root = [-1] * n
 
 
def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]
 
 
def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x
 
 
def size(x):
    return -1 * root[r(x)]
 
 
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a, b)
 
ans = 0
for i in range(n):
    ans = max(ans, size(i))
 
print(ans)
Buggy python submission (verdict: Runtime Error):
v = list(map(int, input().split()))
if sum(v) >= 22:
  print("bust")
else
  print("win")

Fixed submission:
v = list(map(int, input().split()))
if sum(v) >= 22:
  print("bust")
else:
  print("win")
Buggy python submission (verdict: Runtime Error):
def main(lines):
	line = lines  

if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)


Fixed submission:
import sys
def main(lines):
  n = int(lines[0])
  a = []
  hei = lines[1].split()
  for i in range(n):
    a.append(int(hei[i]))
  tmp = a[0]
  ans = 0
  for i in range(1,n):
    if tmp < a[i]:
      tmp = a[i]
    else:
      ans += tmp-a[i]
  print(ans)

if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)
Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
list = [int(input()) for i in range(N)]
max(list())
list.sort()
print(min(list[i+K-1] - list[i] for i in range(N-K+1)))

Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))
Buggy python submission (verdict: Runtime Error):
from bisect import *
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# Aの累積和を保存しておく
# 各Aの要素について、Bが何冊読めるか二分探索する。
# 計算量: AlogB

for i in range(1,len(A)):
  A[i] += A[i-1]
  B[i] += B[i-1]

ans = 0
for i in range(len(A)):
  rest_time = k - A[i]
  if rest_time < 0:
    break
  numb = bisect_left(B, rest_time)
  anstmp = i + 1 + numb 
  ans = max(ans, anstmp)
print(ans)

Fixed submission:
from bisect import *
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# Aの累積和を保存しておく
# 各Aの要素について、Bが何冊読めるか二分探索する。
# 計算量: AlogB
A.insert(0, 0)

for i in range(1,len(A)):
  A[i] += A[i-1]
for i in range(1, len(B)):
  B[i] += B[i-1]

ans = 0
for i in range(len(A)):
  rest_time = k - A[i]
  if rest_time >= 0:
    numb = bisect_right(B, rest_time)
    anstmp = i + numb 
    ans = max(ans, anstmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1,k+1):
            ans += gcd(a,b,c)
print(ans)

Fixed submission:
import math


k = int(input())
ans = 0
dic = {}
for a in range(1, k+1):
    for b in range(1, k+1):
        tmp = math.gcd(a,b)
        for c in range(1,k+1):
            ans += math.gcd(tmp, c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())
graph = [[] for _ in range(n)]

for i in range(n):
  if i+1 < n:
    graph[i].append(i+1)
  if i-1 >=0:
    graph[i].append(i-1)
graph[x-1].append(y-1)
graph[y-1].append(x-1)

ans = [0] * (n-1)
from collections import deque
for i in range(n):
  dist = [-1] * n
  dist[i] = 0
  d = deque()
  d.append(i)
  while d:
    v = d.popleft()
    for j in graph[v]:
      if dist[j] != -1:
        continue
      dist[j] = dist[v] + 1
      ans[dist[j] - 1] += 1
      d.append(j)
for a in ans:
  print(a//2)



Fixed submission:
n, x, y = map(int, input().split())
graph = [[] for _ in range(n)]
 
for i in range(n):
  if i+1 < n:
    graph[i].append(i+1)
  if i-1 >=0:
    graph[i].append(i-1)
graph[x-1].append(y-1)
graph[y-1].append(x-1)
 
ans = [0] * (n-1)
from collections import deque
for i in range(n):
  dist = [-1] * n
  dist[i] = 0
  d = deque()
  d.append(i)
  while d:
    v = d.popleft()
    for j in graph[v]:
      if dist[j] != -1:
        continue
      dist[j] = dist[v] + 1
      ans[dist[j] - 1] += 1
      d.append(j)
for a in ans:
  print(a//2)
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

p = 10**9+7
r1 = 2 ** n - 1
r2 = cmb(n, a, p)
r3 = cmb(n, b, p)
print(r1-r2-r3)

Fixed submission:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n, a, b = na()
mod = 1000000007
 
def comb(n, r, mod):
    if n < 0 or r < 0 or r > n: return 0
    nu = 1
    de = 1
    for i in range(r):
        nu = nu * (n-i) % mod
        de = de * (i+1) % mod
    return nu * inv(de, mod) % mod
 
def inv(a, mod):
    b = mod
    p, q = 1, 0
    while b > 0:
        c = a//b
        d = a; a = b; b = d % b
        d = p; p = q; q = d-c*q
    return p+mod if p < 0 else p
 
print((pow(2, n, mod) - comb(n, a, mod) - comb(n, b, mod) - 1)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
a, b  = [int(i) for i in input().split()]
 
def divisor(n):
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table
 
def sieve(n):
  is_prime = [True for _ in range(n+1)]
  is_prime[0] = False
  for i in range(2, n+1):
    if is_prime[i-1]:
      j = 2 * i
      while j <= n:
        is_prime[j-1] = False
        j += i
  table = [ i for i in range(1, n+1) if is_prime[i-1]]
  return is_prime, table
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
m = gcd(a,b)
_, sosu = sieve(m)
print(1+len(set(sosu)&set(divisor(m))))

Fixed submission:
# a, bを素因数分解する。O(ルートa + ルートb)
# 共通の素因数を見つける。O(loga + logb)

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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
a_prime = set(prime_factorize(a))
b_prime = set(prime_factorize(b))
ans = 0
for ap in a_prime:
  for bp in b_prime:
    if ap == bp:
      ans += 1
      break
print(ans+1)

Buggy python submission (verdict: Time Limit Exceeded):
a, b  = [int(i) for i in input().split()]

def divisor(n):
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

def sieve(n):
  is_prime = [True for _ in range(n+1)]
  is_prime[0] = False
  for i in range(2, n+1):
    if is_prime[i-1]:
      j = 2 * i
      while j <= n:
        is_prime[j-1] = False
        j += i
  table = [ i for i in range(1, n+1) if is_prime[i-1]]
  return is_prime, table
  
aset = set(divisor(a))
bset = set(divisor(b))
fin = aset & bset
finmax = max(fin)

_, sosu = sieve(finmax)
print(1+len(set(sosu)&fin))

Fixed submission:
# a, bを素因数分解する。O(ルートa + ルートb)
# 共通の素因数を見つける。O(loga + logb)

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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
a_prime = set(prime_factorize(a))
b_prime = set(prime_factorize(b))
ans = 0
for ap in a_prime:
  for bp in b_prime:
    if ap == bp:
      ans += 1
      break
print(ans+1)
Buggy python submission (verdict: Runtime Error):
 = int(input())
 
print(int(((n-1) * n) / 2))

Fixed submission:
n = int(input())
 
print(int(((n-1) * n) // 2))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N = int(input())
ss = [input() for i in range(N)]
sdic = []
for s in ss:
  dic = defaultdict(int)
  for c in s:
    dic[c] += 1
  sdic.append(dic)
ans = 0
for i in range(N):
  for j in range(i+1, N):
    if sdic[i] == sdic[j]:
      ans += 1
print(ans)
  
    

Fixed submission:
from collections import defaultdict
N = int(input())
ss = [input() for i in range(N)]
sdic = defaultdict(int)
ans = 0
for s in ss:
  dic = defaultdict(int)
  for c in s:
    dic[c] += 1
  key = tuple(sorted(dic.items()))
  sdic[key] += 1
  if sdic[key] >= 2:
    ans += sdic[key] - 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
Hs = list(map(int, input().split()))

prev = Hs[0]
flag = True
for i in range(1,len(Hs)):
    if Hs[i] <prev:
	flag = False
	break
    elif Hs[i] == prev:
	prev = Hs[i]
    else:
	prev = Hs[i]-1
if flag:
    print("Yes")
else:
    print("No")



Fixed submission:
N = int(input())
Hs = list(map(int, input().split()))
 
prev = Hs[0]
flag = True
for i in range(1,len(Hs)):
    if Hs[i] <prev:
      flag = False
      break
    elif Hs[i] == prev:
      prev = Hs[i]
    else:
      prev = Hs[i]-1
if flag:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]
b = [0 for _ in range(len(a))]

maxnum = len(a) + 1
ans = ""
anscount = 0
for i in range(len(a)-1, -1, -1):
  mod = a[i]
  now = i + 1
  count = 1
  truemod = 0
  while (True):
    if now * count < maxnum:
      truemod += b[now*count-1]
      count += 1
    else:
      break
  if truemod % 2 != mod:
    b[i] = 1
    anscount += 1
    ans += str(i+1)+ " "
print(anscount)
if anscount > 0:
  print(ans[:-1])

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]
b = [0 for _ in range(len(a))]

ans = ""
anscount = 0
for i in range(n-1, -1, -1):
  ai = a[i]
  j = i + 1
  while i < n:
    if b[i]:
      ai ^= 1
    i += j
    b[j-1] = ai
res = []
for i, one in enumerate(b):
  if one==1:
    res.append(i+1)
print(len(res))
print(*res)
Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
td = [[int(i) for i in input().split()] for n in range(n)]
td.sort(key=lambda x:-x[1])
memo = set()
a = []
for t, d in td:
  if t in memo:
    a.append((d, 0))
  else:
    a.append((d, 1))
  memo.add(t)
a = [(-x, x, d) for x, d in a]
import heapq
heapq.heapify(a)
val = 0
kind = 0
b = []
for _ in range(m):
  ele = heapq.heappop(a)
  val += ele[1]
  kind += ele[2]
  if ele[2] == 0:
    b.append(ele[1])
ans = val + kind ** 2
while (len(a) > 0):
  val -= b.pop()
  flag = False
  while(len(a) > 0):
    elem = heapq.heappop(a)
    if elem[2] == 1:
      flag = True
      break
  if not flag:
    break
  val += elem[1]
  kind += 1
  tmpans = val + kind ** 2
  if tmpans > ans:
    ans = tmpans
print(ans)

Fixed submission:
n, m = [int(i) for i in input().split()]
td = [[int(i) for i in input().split()] for n in range(n)]
td.sort(key=lambda x:-x[1])
memo = set()
a = []
for t, d in td:
  if t in memo:
    a.append((d, 0))
  else:
    a.append((d, 1))
  memo.add(t)
a = [(-x, x, d) for x, d in a]
import heapq
heapq.heapify(a)
val = 0
kind = 0
b = []
for _ in range(m):
  ele = heapq.heappop(a)
  val += ele[1]
  kind += ele[2]
  if ele[2] == 0:
    b.append(ele[1])
ans = val + kind ** 2
while (len(a) > 0 and len(b)>0):
  val -= b.pop()
  flag = False
  while(len(a) > 0):
    elem = heapq.heappop(a)
    if elem[2] == 1:
      flag = True
      break
  if not flag:
    break
  val += elem[1]
  kind += 1
  tmpans = val + kind ** 2
  if tmpans > ans:
    ans = tmpans
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
o = defaultdict(int)
e = defaultdict(int)
odd_num = 0
even_num = 0
for i, v_one in enumerate(v):
  if i % 2 == 1:
    o[v_one] += 1
    odd_num += 1
  else:
    e[v_one] += 1
    even_num += 1
sorted_o = sorted(o.items(), key=lambda x:-x[1])
sorted_e = sorted(e.items(), key=lambda x:-x[1])
if sorted_o[0][0] != sorted_e[0][0]:
  ans = odd_num - sorted_o[0][1] + even_num - sorted_e[0][1]
else:
  ans1 = odd_num - sorted_o[1][1] + even_num - sorted_e[0][1]
  ans2 = odd_num - sorted_o[0][1] + even_num - sorted_e[1][1]
  ans = min(ans1, ans2)
print(ans)

Fixed submission:
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
o = defaultdict(int)
e = defaultdict(int)
odd_num = 0
even_num = 0
for i, v_one in enumerate(v):
  if i % 2 == 1:
    o[v_one] += 1
    odd_num += 1
  else:
    e[v_one] += 1
    even_num += 1
sorted_o = sorted(o.items(), key=lambda x:-x[1])
sorted_e = sorted(e.items(), key=lambda x:-x[1])
if sorted_o[0][0] != sorted_e[0][0]:
  ans = odd_num - sorted_o[0][1] + even_num - sorted_e[0][1]
elif len(sorted_o) >= 2 and len(sorted_e) >= 2:
  ans1 = odd_num - sorted_o[1][1] + even_num - sorted_e[0][1]
  ans2 = odd_num - sorted_o[0][1] + even_num - sorted_e[1][1]
  ans = min(ans1, ans2)
elif len(sorted_o) >= 2:
  ans = sorted_o[0][1]
elif len(sorted_e) >=2:
  ans = sorted_e[0][1]
else:
  ans = odd_num
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
X = list(map(int, input().split()))

ans = 10**6
for i in range(n-k):
  d1 = abs(X[i]) + abs(X[i] - X[i+k-1])
  d2 = abs(X[i+k-1]) + abs(X[i] - X[i+k-1])
  if ans > min(d1, d2):
    ans = min(d1,d2)
if ans == 10**6:
  print(0)
else:
  print(ans)




Fixed submission:
S = input()
T = input()
sdic = {}
tdic = {}
flag = True
for s, t in zip(S, T):
  if s not in sdic:
    sdic[s] = t
  if t not in tdic:
    tdic[t] = s
  if sdic[s] != t or tdic[t] != s:
    flag = False
    break
if flag:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
S = [0] * (n + 1)

from collections import defaultdict
dic = defaultdict(int)
for i in range(len(A)):
  S[i+1] = S[i] + A[i]
for s in S:
  dic[s] += 1
from scipy.special import comb
ans = 0
for k, v in dic.items():
  if v > 1:
    ans += comb(v, 2, exact=True)

print(int(ans))

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
S = [0] * (n + 1)

from collections import defaultdict
dic = defaultdict(int)
for i in range(len(A)):
  S[i+1] = S[i] + A[i]
for s in S:
  dic[s] += 1
from scipy.special import comb
ans = 0
for k, v in dic.items():
  if v > 1:
    ans += comb(v, 2, exact=True)

print(int(ans))

Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
S = [0] * (n + 1)

from collections import defaultdict
dic = defaultdict(int)
for i in range(len(A)):
  S[i+1] = S[i] + A[i]
for s in S:
  dic[s] += 1
from math import factorial
ans = 0
for k, v in dic.items():
  if v > 1:
    ans += factorial(v) / factorial(2) / factorial(v - 2)

print(int(ans))

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
S = [0] * (n + 1)

from collections import defaultdict
dic = defaultdict(int)
for i in range(len(A)):
  S[i+1] = S[i] + A[i]
for s in S:
  dic[s] += 1
from scipy.special import comb
ans = 0
for k, v in dic.items():
  if v > 1:
    ans += comb(v, 2, exact=True)

print(int(ans))
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
abs_min = 100000
for a in A:
  if abs_min > abs(maxA/2 - a):
    abs_min = abs(maxA/2 - a)
    r = a
print(maxA, r)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
abs_min = 10**9
A.remove(maxA)
for a in A:
  if abs_min > abs(maxA/2 - a):
    abs_min = abs(maxA/2 - a)
    r = a
print(maxA, r)
Buggy python submission (verdict: Runtime Error):
 coding:utf-8                                                                                     

N = int(raw_input())
C = []
S = []
F = []

for i in range(N-1):
    c, s, f = map(int, raw_input().split())
    C.append(c)
    S.append(s)
    F.append(f)

res = []
T = []

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        if S[j] >= t:
            t = 0
            t += S[j] + C[j]
        elif t % F[j] == 0:
            t += C[j]
        else:
            t = t + F[j] - (t - (S[j] + F[j] * ((t-S[j])/F[j]))) + C[j]
    T.append(t)

for t in T:
    print t
print 0

Fixed submission:
# coding:utf-8                                                                                     

N = int(raw_input())
C = []
S = []
F = []

for i in range(N-1):
    c, s, f = map(int, raw_input().split())
    C.append(c)
    S.append(s)
    F.append(f)

res = []

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        if S[j] >= t:
            t = 0
            t += S[j] + C[j]
        elif t % F[j] == 0:
            t += C[j]
        else:
            t = S[j] + F[j] * ((t - S[j]) / F[j]) + F[j] + C[j]
    print t

print 0
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8                                                                  

from collections import defaultdict

N, K = map(int, raw_input().split())
As = map(int, raw_input().split())

dic = defaultdict(lambda: 0)

for a in As:
    dic[a] += 1

count = 0
while True:
    if len(dic) <= K:
        break
    dekey = min(dic, key=(lambda x: dic[x]))
    count += dic[dekey]
    del dic[dekey]

print count


Fixed submission:
# coding:utf-8                                                                  

from collections import defaultdict

N, K = map(int, raw_input().split())
As = map(int, raw_input().split())

dic = defaultdict(lambda: 0)

for a in As:
    dic[a] += 1

tar = len(dic) - K

count = 0
if tar <= 0:
    print count
else:
    for i, (k, v) in enumerate(sorted(dic.items(), key=lambda x: x[1])):
        count += v
        if i+1 == tar:
            print count
            break
Buggy python submission (verdict: Time Limit Exceeded):
# coding:utf-8                                                        

N = raw_input()
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())

count = 0

for a in A:
    for b in B:
        for c in C:
            if a < b and b < c:
                count += 1

print count


Fixed submission:
# coding:utf-8                                                        

import bisect

N = int(raw_input())
A = sorted(map(int, raw_input().split()))
B = sorted(map(int, raw_input().split()))
C = sorted(map(int, raw_input().split()))

count = 0

for mid in B:
    lower_bound = bisect.bisect_left(A, mid)
    upper_bound = N - bisect.bisect_right(C, mid)
    count += lower_bound * upper_bound

print count
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
def solve(i):
  flag = True
  for j in range(len(T)):
    if i+j < len(S) and (S[i+j] == "?" or S[i+j] == T[j]):
      continue
    else:
      flag = False
      break
  return flag

for i in range(len(S)):
  if solve(i):
    ansind = i
if ansind:
  ans = S[:ansind] + T + S[ansind+len(T):]
  ans = ans.replace("?", "a")
else:
  ans = "UNRESTORABLE"
print(ans)

Fixed submission:
S = input()
T = input()
def solve(i):
  flag = True
  for j in range(len(T)):
    if i+j < len(S) and (S[i+j] == "?" or S[i+j] == T[j]):
      continue
    else:
      flag = False
      break
  return flag
anslist = []
for i in range(len(S)):
  if solve(i):
    anstmp = S[:i] + T + S[i+len(T):]
    anstmp = anstmp.replace("?", "a")
    anslist.append(anstmp)
if len(anslist) > 0:
  anslist.sort()
  ans = anslist[0]
else:
  ans = "UNRESTORABLE"
print(ans)