Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=u+(i*d)%2019
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
print(ans)


Fixed submission:
s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=(u+i*d)%2019
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=(u+i*d%2019)
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
print(ans)


Fixed submission:
s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=(u+i*d)%2019
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
n = int(s) // 2019
a = [i*2019 for i in range(1, n+1)]
ans=0
for j in a:
  if j in s:
    ans += 1
print(ans)

Fixed submission:
s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=(u+i*d)%2019
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
ans = 0
for i in range(l):
  for j in range(i+1, l+1):
    a =int(s[i:j])  
    if a % 2019 == 0:
      ans +=1
print(ans)

Fixed submission:
s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=(u+i*d)%2019
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
ans = 0
for i in range(l):
  for j in range(i+1, l+1):
    a =int(s[i:j])  
    if a % 2019 == 0:
      ans +=1
print(ans)

Fixed submission:
s=input()[::-1]
ans=0
u=0
d=1
l=[0]*2019
l[0]=1
for i in map(int,s):
  u=(u+i*d)%2019
  l[u]+=1
  d=d*10%2019
for i in l:
  ans+=i*(i-1)//2
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
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)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
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
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)
Buggy python submission (verdict: Runtime Error):
import collections
def C(n):
    return n * (n-1) // 2
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
d = []
sm = 0
for k,v in c.most_common():
    d[k] = v
    sm += C(v)
for a in A:
    print (sm - d[a] + 1)

Fixed submission:
import collections
def C(n):
    return n * (n-1) // 2
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
d = {}
sm = 0
for k,v in c.most_common():
    d[k] = v
    sm += C(v)
for a in A:
    print (sm - d[a] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
m =[0] * n
m[0] = p[0]
for i in range(1, n):
  q = sorted(p[:i+1])
  m[i] = q[0]
ans = 0
for i in range(n):
  if p[i] == m[i]:
    ans += 1
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
m =[0] * n
m[0] = p[0]
mi = m[0]
for i in range(1, n):
    mi = min(mi, p[i])
    m[i] = mi
ans = 0
for i in range(n):
  if p[i] == m[i]:
    ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
m =[0] * n
m[0] = p[0]
for i in range(1, n):
  q = sorted(p[:i+1])
  m[i] = q[0]
ans = 0
for i in range(n):
  if p[i] == m[i]:
    ans += 1
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
m =[0] * n
m[0] = p[0]
mi = m[0]
for i in range(1, n):
    mi = min(mi, p[i])
    m[i] = mi
ans = 0
for i in range(n):
  if p[i] == m[i]:
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def comb(n, r, p):
    x = 1
    for i in range(1, r + 1):
        x *= (n - i + 1) * pow(i, p - 2, p) % p
    return x % p

X, Y = map(int, input().split())
a = (2*X - Y)/3
b = (2*Y - X)/3
 
if (X+Y)%3 != 0:
    ans = 0
 
elif a<0 or b<0:
    ans = 0
 
else:
    ans = comb(int(a + b), int(a), 10**9 + 7)
print(ans)

Fixed submission:
X, Y = 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]
factinv = [1, 1]
inv = [0, 1]
 
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)


a = (2*X - Y)/3
b = (2*Y - X)/3

if (X+Y)%3 != 0:
    ans = 0

elif a<0 or b<0:
    ans = 0

else:
    ans = cmb(int(a + b), int(a), 10**9 + 7)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D = map(int, input().split())
ans = 0
for i in range(A, B+1):
  if i%C!=0 and i%D!=0:
    ans += 1
print(ans)

Fixed submission:
from fractions import gcd
A, B, C, D = map(int, input().split())
E = C*D//gcd(C, D)
X = B - B//C - B//D + B//E
Y = A-1 - (A-1)//C - (A-1)//D + (A-1)//E
print(X-Y)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D = map(int, input().split())
ans = 0
for i in range(A, B+1):
  if i%C!=0 and i%D!=0:
    ans += 1
print(ans)

Fixed submission:
from fractions import gcd
A, B, C, D = map(int, input().split())
E = C*D//gcd(C, D)
X = B - B//C - B//D + B//E
Y = A-1 - (A-1)//C - (A-1)//D + (A-1)//E
print(X-Y)
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [input() for _ in range(H)]

# そのマスを含めてLeft, Right, Up, Downにそれぞれ何マス分明かりを照らせるかを配列に記録
L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]

for i in range(H):
	for j in range(W):
		if S[i][j] == ".":
			if j == 0:
				L[i][j] = 1
			else:
				L[i][j] = L[i][j - 1] + 1

for i in range(H):
	for j in range(W - 1, -1, -1):
		if S[i][j] == ".":
			if j == W - 1:
				R[i][j] = 1
			else:
				R[i][j] = R[i][j + 1] + 1

for j in range(W):
	for i in range(H - 1, -1, -1):
		if S[i][j] == ".":
			if i == H - 1:
				D[i][j] = 1
			else:
				D[i][j] = D[i + 1][j] + 1

for j in range(W):
	for i in range(H):
		if S[i][j] == ".":
			if i == 0:
				U[i][j] = 1
			else:
				U[i][j] = U[i - 1][j] + 1


ans = 0
X = [[0] * W for _ in range(H)]
for i in range(H):
	for j in range(W):
		X[i][j] = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
	ans = max(ans, max(X[i]))

print(ans)

Fixed submission:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
sy = [0] * w
ret = 0
for y in range(h):
    seqx = 0
    seqy = 0
    for x in range(w):
        if s[y][x] == '.':
            if sy[x] == 0:
                yy = y
                while yy < h and s[yy][x] != '#':
                    yy += 1
                sy[x] = yy - y
            seqx += 1
            seqy = max(seqy, sy[x])
            ret = max(ret, seqx + seqy - 1)
        else:
            seqx = 0
            seqy = 0
            sy[x] = 0
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
s = [input() for _ in range(h)]
sy = [0] * w
ret = 0
for y in range(h):
    seqx = 0
    seqy = 0
    for x in range(w):
        if s[y][x] == '.':
            if sy[x] == 0:
                yy = y
                while yy < h and s[yy][x] != '#':
                    yy += 1
                sy[x] = yy - y
            seqx += 1
            seqy = max(seqy, sy[x])
            ret = max(ret, seqx + seqy - 1)
        else:
            seqx = 0
            seqy = 0
            sy[x] = 0
print(ret)


Fixed submission:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
sy = [0] * w
ret = 0
for y in range(h):
    seqx = 0
    seqy = 0
    for x in range(w):
        if s[y][x] == '.':
            if sy[x] == 0:
                yy = y
                while yy < h and s[yy][x] != '#':
                    yy += 1
                sy[x] = yy - y
            seqx += 1
            seqy = max(seqy, sy[x])
            ret = max(ret, seqx + seqy - 1)
        else:
            seqx = 0
            seqy = 0
            sy[x] = 0
print(ret)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
negative = []
positive = []
cnt=0
for i in range(n):
  if a[i] < 0:
    cnt += 1
    negative.append(a[i])
  else:
    positive.append(a[i])
if cnt % 2 == 0:
  print(sum(map(lambda x: abs(x), a)))
else:
  negative.sort()
  positive.sort()
  if abs(negative[-1]) < positive[0]:
    a.remove(negative[-1])
    print(negative[-1]+sum(map(lambda x: abs(x), a)))
  else:
    a.remove(positive[0])
    print(-positive[0]+sum(map(lambda x: abs(x), a)))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
negative = []
positive = []
cnt=0
for i in range(n):
  if a[i] < 0:
    cnt += 1
    negative.append(a[i])
  else:
    positive.append(a[i])
if cnt % 2 == 0:
  print(sum(map(lambda x: abs(x), a)))
elif cnt == len(a):
  a.sort()
  b = a[-1]
  a.remove(a[-1])
  print(b+sum(map(lambda x: abs(x), a)))
else:
  negative.sort()
  positive.sort()
  if abs(negative[-1]) < positive[0]:
    a.remove(negative[-1])
    print(negative[-1]+sum(map(lambda x: abs(x), a)))
  else:
    a.remove(positive[0])
    print(-positive[0]+sum(map(lambda x: abs(x), a)))
Buggy python submission (verdict: Runtime Error):
import math
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
def cmb(n, r):
    if n < 0 or r < 0:
        return 0
    if r > n:
        return 0
 
    r = min(n-r, r)
    res = 1
    for i in range(r):
        res *= n - i
n, m = map(int, input().split())
b = [x[1] for x in factorization(m)]
ans = 1
for i in b:
  c = cmb(n+i-1, i)
  ans = ans * c
print(ans%(10**9+7))


Fixed submission:
def factrize(x):
    f = {}
    if x == 1:
        return f
    tmp = x
    i = 2
    while i**2 <= tmp:
        cnt = 0
        while tmp % i == 0:
            cnt += 1
            tmp = tmp//i
        if cnt > 0:
            f[i] = cnt
        i += 1
    if tmp != 1 or f == {}:
        f[tmp] = 1
    return f


def comb(n, r, p):
    x = 1
    for i in range(1, r + 1):
        x *= (n - i + 1) * pow(i, p - 2, p) % p
    return x % p


p = 10**9+7
n, m = map(int, input().split())
A = list(factrize(m).values())
ans = 1
for a in A:
    ans = (ans*comb(a+n-1, a, p)) % p
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
K = 0
while True:
  if 2**k <= N < 2**(k+1):
    print(2**k)
    break
  else:k += 1

Fixed submission:
N = int(input())
k = 0
while True:
  if 2**k <= N < 2**(k+1):
    print(2**k)
    break
  k += 1
Buggy python submission (verdict: Runtime Error):
H, W=map(int,input().split())
print("#"*(w+2))
for i in range(h):
  s=input()
  s="#"+s+"#"
  print(s)
print("#"*(w+2))

Fixed submission:
H, W=map(int,input().split())
print("#"*(W+2))
for i in range(H):
  s=input()
  s="#"+s+"#"
  print(s)
print("#"*(W+2))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
for _ in range(M):
    a, b = map(int, input().split())
for i in range(1,N+1):
    print(a.count("i")+b.count("i"))

Fixed submission:
n, m = map(int, input().split())
a, b = [0]*m, [0]*m
for i in range(m):
    a[i], b[i] = map(int, input().split())
for j in range(1,n+1):
    print(a.count(j)+b.count(j))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
for _ in range(M):
    a, b = map(int, input().split())
for i in range(1,N+1):
    print(a.count(i)+b.count(i))

Fixed submission:
n, m = map(int, input().split())
a, b = [0]*m, [0]*m
for i in range(m):
    a[i], b[i] = map(int, input().split())
for j in range(1,n+1):
    print(a.count(j)+b.count(j))

Buggy python submission (verdict: Runtime Error):
N, M = input().split()
for _ in range(M):
    a, b = input().split()
for i in range(1, N+1):
    print(a.count("i")+b.count("i"))

Fixed submission:
n, m = map(int, input().split())
a, b = [0]*m, [0]*m
for i in range(m):
    a[i], b[i] = map(int, input().split())
for j in range(1,n+1):
    print(a.count(j)+b.count(j))

Buggy python submission (verdict: Runtime Error):
N, M = input().split()
for i in range(1, M+1):
    a, b = input().split()
for i in range(1, N+1):
    print(a.count("i")+b.count("i"))

Fixed submission:
n, m = map(int, input().split())
a, b = [0]*m, [0]*m
for i in range(m):
    a[i], b[i] = map(int, input().split())
for j in range(1,n+1):
    print(a.count(j)+b.count(j))

Buggy python submission (verdict: Runtime Error):
N, M = input().split()
for i in range(1, M+1):
    a, b = input().split()
for i in range(1, N+1):
    print(a.count("i")+b.count("i")

Fixed submission:
n, m = map(int, input().split())
a, b = [0]*m, [0]*m
for i in range(m):
    a[i], b[i] = map(int, input().split())
for j in range(1,n+1):
    print(a.count(j)+b.count(j))

Buggy python submission (verdict: Runtime Error):
N, M = input().split()
for _ in range(M):
    a, b = input().split()
for _ in range(1, N+1):
    print(a.count("i")+b.count("i")

Fixed submission:
n, m = map(int, input().split())
a, b = [0]*m, [0]*m
for i in range(m):
    a[i], b[i] = map(int, input().split())
for j in range(1,n+1):
    print(a.count(j)+b.count(j))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
for _ in range(M):
    a, b = input().split()
for _ in range(1, N+1):
    print(a.count("i")+b.count("i")



Fixed submission:
n, m = map(int, input().split())
a, b = [0]*m, [0]*m
for i in range(m):
    a[i], b[i] = map(int, input().split())
for j in range(1,n+1):
    print(a.count(j)+b.count(j))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
c = input()
cnt = 0
r_cnt = c.count('R')
w_cnt = c.count('W')
ans = 'R' * r_cnt
if not w_cnt or not r_cnt:
  print(cnt)
else:
  while True:
    if c[:r_cnt] == ans:
      break
    else:
      w_index = c.index('W')
      r_index = N-c[::-1].index('R')-1
      c = c[:w_index] + 'R' + c[w_index+1:r_index] + 'W' + c[r_index+1:]
      cnt += 1
  print(cnt)

Fixed submission:
from collections import deque
N = int(input())
c = deque(list(input()))
cnt = 0
def left(c):
  l = c.popleft()
  return l
def right(c):
  r = c.pop()
  return r
while c:
  l = left(c)
  if l == 'R':
    continue
  else:
    while True:
      if not c:
        break
      r = right(c)
      if r == 'W':
        continue
      else:
        cnt += 1
        break
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
judge = 1
for i in A[:K]:
  judge *= i
for i in range(N-K):
  judge2 = judge / A[i] * A[K+i]
  if judge2 > judge:
    print('Yes')
  else:
    print('No')
  judge = judge2

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
judge = 1
for i in range(N-K):
  if A[K+i] > A[i]:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input().rstrip())
a = input().rstrip().split(' ')
num = 0
for i in range(0, N, 1):
  if a[i] % 2 == 1:
    num += 1
print(num)

Fixed submission:
N = int(input().rstrip())
a = input().rstrip().split(' ')
num = 0
for i in range(0, N, 2):
  if int(a[i]) % 2 == 1:
    num += 1
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**18
N, M, K = map(int, input().split())
tmp = 0
k = [K]
for a in map(int, input().split()):
  K -= a
  if K >= 0:
    tmp += 1
    k += [K]
  else:
    break
ans = max(tmp, 0)
A_index = tmp
B = list(map(int, input().split()))
b_num = len(B) - 1
b = B.pop(0)
while True:
  if b <= k[A_index]:
    tmp += 1
    ans = max(ans, tmp)
    if b_num == 0:
      break
    else:
      b += B.pop(0)
      b_num -= 1
  else:
    tmp -= 1
    A_index -= 1
    if A_index < 0:
      break
print(ans)

Fixed submission:
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
A_sum = sum(A)
B_sum = 0
n, m = N, 0
ans= 0
while m != M:
  if A_sum + B_sum <= K:
    ans = max(ans, n+m)
    m += 1
    B_sum += B[m]
  elif A_sum + B_sum > K and n >= 0:
    A_sum -= A[n]
    n -= 1
  else:
    break
if A_sum + B_sum <= K:
  ans = max(ans, n+m)    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
S = input()
print(len(set(combinations(S, 3))))

Fixed submission:
N = int(input())
S = list(map(int, input()))
ans = 0
first = [0] * 10
a = 0
for i in range(N):
  if first[S[i]] == 0:
    first[S[i]] = 1
    a += 1
    second = [0] * 10
    b = 0
    for j in range(i+1, N):
      if second[S[j]] == 0:
        second[S[j]] = 1
        b += 1
        third = [0] * 10
        c = 0
        for k in range(j+1, N):
          if third[S[k]] == 0:
            third[S[k]] = 1
            ans += 1
            c += 1
            if c == 10:
              break
        if b == 10:
          break
    if a == 10:
      break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
A, B = map(int, input().split())
gcd = math.gcd(A, B)
ans = 1
if gcd%2==0:
  ans += 1
if gcd >= 3:
  pn = [2]
  for i in range(3, gcd+1, 2):
    check=True
    for num in pn:
      if i % num == 0:
        check=False
        break
    if check:
      pn.append(i)
      if A%i==0 and B%i==0:
        ans += 1
print(ans)

Fixed submission:
import math
A, B = map(int, input().split())
gcd = math.gcd(A, B)
ans = [1]
while gcd % 2 == 0:
  ans.append(2)
  gcd = gcd // 2
f = 3
while f * f <= gcd:
  if gcd % f == 0:
    ans.append(f)
    gcd = gcd // f
  else:
    f += 2
if gcd != 1:
  ans.append(gcd)
print(len(set(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())
judge = min(A, B)
pn = [2]
ans = 1
if A%2==0 and B%2==0:
  ans += 1
if judge >= 3:
  for i in range(3, judge+1, 2):
    check=True
    for num in pn:
      if i % num == 0:
        check=False
        break
    if check:
      pn.append(i)
      if A%i==0 and B%i==0:
        ans += 1
print(ans)

Fixed submission:
import math
A, B = map(int, input().split())
gcd = math.gcd(A, B)
ans = [1]
while gcd % 2 == 0:
  ans.append(2)
  gcd = gcd // 2
f = 3
while f * f <= gcd:
  if gcd % f == 0:
    ans.append(f)
    gcd = gcd // f
  else:
    f += 2
if gcd != 1:
  ans.append(gcd)
print(len(set(ans)))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
  i = A.index(max(A))
  A[i] = A[i]//2
print(sum(A))

Fixed submission:
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
  A[i] = -A[i]
heapq.heapify(A)
for _ in range(M):
  a = -heapq.heappop(A)
  a = (a//2) * -1
  heapq.heappush(A, a)
print(sum(A)*-1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
  i = A.index(max(A))
  A[i] = A[i]/2
ans = 0
for i in range(N):
  ans += int(A[i])
print(ans)

Fixed submission:
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
  A[i] = -A[i]
heapq.heapify(A)
for _ in range(M):
  a = -heapq.heappop(A)
  a = (a//2) * -1
  heapq.heappush(A, a)
print(sum(A)*-1)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
S = list(input())
n = len(S)
right = np.ones(n, dtype=np.int64)
left = np.ones(n, dtype=np.int64)
for i, s in enumerate(S):
  if s == 'R':
    left[i] = 0
  else:
    right[i] = 0
zeros = np.zeros(n, dtype=np.int64)
cnt = 1
first = np.ones(n, dtype=np.int64)
second = np.copy(zeros)
second[1:] += (first * right)[:-1]
second[:-1] += (first * left)[1:]

if np.all(first == second):
  print(*second)
else:
  while True:
    cnt += 1
    third = np.copy(zeros)
    third[1:] += (second * right)[:-1]
    third[:-1] += (second * left)[1:]
    if np.all(first == third):
      break
    else:
      first = second
      second = third
  if cnt % 2 == 0:
    print(*third)
  else:
    print(*second)

Fixed submission:
import numpy as np
S = list(input())
n = len(S)
ans = [0] * n
right_flag = False
for i, s in enumerate(S):
  if s == 'R' and right_flag is False:
    right_index = i
    right_flag = True
  elif s == 'L' and right_flag:
    right_flag = False
    cnt = i - right_index
    odd = cnt // 2
    even = cnt - odd
    ans[i-1] += even
    ans[i] += odd
left_flag = False
for i, s in enumerate(S[::-1], 1):
  if s == 'L' and left_flag is False:
    left_index = i
    left_flag = True
  elif s == 'R' and left_flag:
    left_flag = False
    cnt = i - left_index
    odd = cnt // 2
    even = cnt - odd
    ans[-i+1] += even
    ans[-i] += odd
print(*ans)
Buggy python submission (verdict: Runtime Error):
import sys
N, M = map(int, input().split())
A = list(map(int, input().split()))
card = [ list(map(int, i.rstrip().split())) for i in sys.stdin.readlines()]
card = sorted(card, key=lambda x:x[1], reverse=True)
A = sorted(A)
i = 0
for b, c in card:
  for _ in range(b):
    if A[i] >= c:
      break
    else:
      A[i] = c
      i += 1
print(sum(A))

Fixed submission:
import sys
N, M = map(int, input().split())
A = list(map(int, input().split()))
card = [ list(map(int, i.rstrip().split())) for i in sys.stdin.readlines()]
card = sorted(card, key=lambda x:x[1], reverse=True)
A = sorted(A)
i = 0
for b, c in card:
  for _ in range(b):
    if i >= N:
      break
    elif A[i] >= c:
      break
    else:
      A[i] = c
      i += 1
print(sum(A))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().rstrip().split(' '))
h = list(map(int, input().rstrip().split(' ')))
def frog_jump(n, height=h):
  if len(height[:n]) == 1:
    return 0
  now_height = height[n-1]
  start = n-1-K
  if start < 0:
    start = 0
  min_lst = [frog_jump(i) + abs(now_height-j) for i, j in enumerate(height[start:n-1], start+1)]
  # print(min_lst)
  min_cost = min(min_lst)
  return min_cost

print(frog_jump(N))

Fixed submission:
N, K = map(int, input().rstrip().split(' '))
frog_lst = list(map(int, input().rstrip().split(' ')))
frog_jump_lst = []

def frog_jump(frog_jump_lst=[], index=0):
  if not frog_jump_lst:
    frog_jump_lst.append(0)
  else:
    now_pos = frog_lst[index]
    k = min(K, len(frog_jump_lst))
    pattern = [abs(now_pos - frog_lst[index-i]) + frog_jump_lst[-i] for i in range(1,k+1)]
    frog_jump_lst.append(min(pattern))

for j in range(N):
  frog_jump(frog_jump_lst, j)
print(frog_jump_lst[-1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().rstrip().split(' '))
h = list(map(int, input().rstrip().split(' ')))
def frog_jump(n, height=h):
  if len(height[:n]) == 1:
    return 0
  now_height = height[n-1]
  start = n-1-K if n-1-K >= 0 else 0
  min_lst = [frog_jump(i) + abs(now_height-j) for i, j in enumerate(height[start:n-1], start+1)]
  # print(min_lst)
  min_cost = min(min_lst)
  return min_cost

print(frog_jump(N))

Fixed submission:
N, K = map(int, input().rstrip().split(' '))
frog_lst = list(map(int, input().rstrip().split(' ')))
frog_jump_lst = []

def frog_jump(frog_jump_lst=[], index=0):
  if not frog_jump_lst:
    frog_jump_lst.append(0)
  else:
    now_pos = frog_lst[index]
    k = min(K, len(frog_jump_lst))
    pattern = [abs(now_pos - frog_lst[index-i]) + frog_jump_lst[-i] for i in range(1,k+1)]
    frog_jump_lst.append(min(pattern))

for j in range(N):
  frog_jump(frog_jump_lst, j)
print(frog_jump_lst[-1])