Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = input()
if n % 1000:
    print(0)
else:
    print(1000 - n%1000)

Fixed submission:
n = int(input())
if n % 1000 == 0:
    print(0)
else:
    print(1000 - n%1000)

Buggy python submission (verdict: Runtime Error):
n = input()
print(1000- n%1000)

Fixed submission:
n = int(input())
if n % 1000 == 0:
    print(0)
else:
    print(1000 - n%1000)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [input() for _ in range(num)]
print("AC x", l.count("AC"))
print("WA x", l.count("WA"))
print("TLE x", l.count("TLE"))
print("RE x", l.count("RE"))

Fixed submission:
num = int(input())
lst = [input() for _ in range(num)]
print("AC x", lst.count("AC"))
print("WA x", lst.count("WA"))
print("TLE x", lst.count("TLE"))
print("RE x", lst.count("RE"))

Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [input() for i in range(num)]
print("AC x", l.count("AC"))
print("WA x", l.count("WA"))
print("TLE x", l.count("TLE"))
print("RE x", l.count("RE"))

Fixed submission:
num = int(input())
lst = [input() for _ in range(num)]
print("AC x", lst.count("AC"))
print("WA x", lst.count("WA"))
print("TLE x", lst.count("TLE"))
print("RE x", lst.count("RE"))
Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

for i in range(1,n):
    A[i] += A[i-1]
for i in range(1,m):
    B[i] += B[i-1]
A.insert(0,0)
B.insert(0,0)

j = m
ans = 0
for i in range(m):
    if A[i] > k:
        break
    
    while B[j] > k-A[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)


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

for i in range(1,n):
    A[i] += A[i-1]
for i in range(1,m):
    B[i] += B[i-1]
A.insert(0,0)
B.insert(0,0)

j = m
ans = 0
for i in range(n+1):
    if A[i] > k:
        break
    
    while B[j] > k-A[i]:
        j -= 1
    ans = max(ans, i+j)

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

mod = 10**9 +7
N = int(input())
dic = {}

zero = 0
for _ in range(N):
    a,b = map(int, input().split())
    if  a ==0 and b == 0:
        zero += 1
        continue
    elif a == 0:
        key = (0,1)
    elif b == 0:
        key = (1,0)
    else:
        if a<0:
            a=-a 
            b=-b
        g = gcd(a,abs(b))
        key = (a//g,b//g)
    
    if key not in dic:
        dic[key]=0

    dic[key] +=1

ans = 1
for k1, v1 in dic.items():
    if v1 ==0:
        continue

    if k1[1] >0:
        k2 = (k1[1],-k1[0])
    else:
        k2 = (-k1[1],k1[0])

    if k2 not in dic:
        ans *= 2**v1
        ans %= mod
    else:
        ans *= ((2**v1-1)) %mod) + ((2**dic[k2]-1)) %mod) +1
        ans %= mod
        dic[k2]=0

ans = (ans + zero -1 )%mod
print(ans)

Fixed submission:
from math import gcd

mod = 10**9 +7
N = int(input())
dic = {}

zero = 0
for _ in range(N):
    a,b = map(int, input().split())
    if  a ==0 and b == 0:
        zero += 1
        continue
    elif a == 0:
        key = (0,1)
    elif b == 0:
        key = (1,0)
    else:
        if a<0:
            a=-a 
            b=-b
        g = gcd(a,abs(b))
        key = (a//g,b//g)
    
    if key not in dic:
        dic[key]=0

    dic[key] +=1

ans = 1
for k1, v1 in dic.items():
    if v1 ==0:
        continue

    if k1[1] >0:
        k2 = (k1[1],-k1[0])
    else:
        k2 = (-k1[1],k1[0])

    if k2 not in dic:
        ans *= 2**v1
        ans %= mod
    else:
        ans *= ((2**v1-1) %mod) + ((2**dic[k2]-1) %mod) +1
        ans %= mod
        dic[k2]=0

ans = (ans + zero -1 )%mod
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = list(map(int,input().split()))
flag = [True]*n
root = [1]
now = 0

while flag[now]:
    flag[now] = False
    now = A[now] -1
    root.append(now+1)

to_p = root.index(root[-1])
p2p = root[to_p:-1]
rooplen = len(p2p)

if k < rooplen:
    print(root[k])
else:    
    idx = (k-to_p)
    idx %= p2p_len
    print(p2p[idx])

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

s = [True] * n  
c = [1]  
now = 0  
while s[now]:
    s[now] = False  
    now = a[now] - 1
    c.append(now+1)

start_cycle = c.index(c[-1]) 
loop = c[start_cycle:-1]  
cycle = len(loop)

if k < start_cycle:  
    print(c[k])
else:
    k -= start_cycle
    k %= cycle
    print(loop[k])

Buggy python submission (verdict: Runtime Error):

n, k = map(int, input().split())
A = map(int,input().split())
flag = [True]*n
p = 0
rt = [1]

while flag[p]:
    flag[p] = False
    p = A[p] -1
    rt.append(p+1)

to_p = rt.index(rt[-1])
p2p = rt[to_p:-1]
p2p_len = len(p2p)

if k < p2p_len:
    print(rt[k])
else:
    print(p2p[(k-to_p)%p2p_len])

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

s = [True] * n  
c = [1]  
now = 0  
while s[now]:
    s[now] = False  
    now = a[now] - 1
    c.append(now+1)

start_cycle = c.index(c[-1]) 
loop = c[start_cycle:-1]  
cycle = len(loop)

if k < start_cycle:  
    print(c[k])
else:
    k -= start_cycle
    k %= cycle
    print(loop[k])
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, d = map(int,input().split())
li = [i for i in range(a, b+1)]
cf = [True if i%c != 0 else False for i in li]
df = [True if i%d != 0 else False for i in li]
n = 0
for i in range(len(cf)):
    if cf[i] and df[i]:
        n+=1
print(n)

Fixed submission:
A, B, C, D = map(int, input().split())
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a*b//gcd(a,b)

def calc(n):
    return n-n//C-n//D+n//(lcm(C,D))
 
print(calc(B)-calc(A-1))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

R=1
for i in range(0, N):
    R=R*A[i]

if R>1000000000000000000:
    print("-1")
else:
    print(R)

Fixed submission:

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

R=1
if 0 in A:
    print("0")
else:
    for i in range(0, N):
        R=R*A[i]
        if R>1000000000000000000:
            print("-1")
            exit()
        
    print(R)
Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
for i in range(n):print(a.count(i+1))

Fixed submission:
n,*l=map(int,open(0).read().split());a=[0]*n
for i in l:a[i-1]+=1
print(*a)

Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
for i in range(n):print(a.count(i+1))

Fixed submission:
n,*l=map(int,open(0).read().split());a=[0]*n
for i in l:a[i-1]+=1
print(*a)

Buggy python submission (verdict: Time Limit Exceeded):
n,a=open(0)
for i in range(int(n)):print(a.count(str(i+1)))

Fixed submission:
n,*l=map(int,open(0).read().split());a=[0]*n
for i in l:a[i-1]+=1
print(*a)

Buggy python submission (verdict: Runtime Error):
n,a=open(0);for i in range(int(n)):print(a.count(str(i+1)))

Fixed submission:
n,*l=map(int,open(0).read().split());a=[0]*n
for i in l:a[i-1]+=1
print(*a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0;

for i in range(n):
  if i % 3 != 0 && i % 5 != 0:
    count+=i
   
print(i)

Fixed submission:
n = int(input())
count = 0;
 
for i in range(n):
  if (i + 1) % 3 != 0 and (i + 1) % 5 != 0:
    count+=(i+1)
   
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
c=int(input())
p=1
m=10**9+7
for i in range(c):
  p*=i+1
print(p%m)

Fixed submission:
c=int(input())
p=1
m=10**9+7
for i in range(2,c+1):
  p=(p*i)%m
print(p)
Buggy python submission (verdict: Runtime Error):
n = input()
a = n%1000
a = 1000-a
print(a)

Fixed submission:
n = int(input())
a = n%1000
if a ==0:
    print(0)
    exit()
a = 1000-a
print(a)
Buggy python submission (verdict: Runtime Error):

    a = int(input())

    print(a + a*a + a*a*a)

Fixed submission:
a = int(input())
print(a + a * a + a * a * a)
Buggy python submission (verdict: Runtime Error):
dontt_use = input()
n = map(int,list(input().split()))
total = 1
for number in n:
    total = total * number
    if total > 10**18:
        print('-1')
        return
print(total)

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

def foo(n):
    total = 1  
    for number in n:
        total = total * number
        if total > 10**18:
            print('-1')
            return
    print(total)
if '0' in str_list :
    print(0)
else:
    foo(n)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ar=list(map(int,input().split()))
di={}
for i in range(n):
    if ar[i] not in di:
        di[ar[i]]=1
    else:
        di[ar[i]]+=1
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    if(b in di):
        x=di[b]
        del di[b]
        if(c in di):
            di[c]+=x
        else:
            di[c]=x
    s=0
    for j in di.keys():
        s+=j*(di[j])
    print(s)

        
        
    

Fixed submission:
n=int(input())
ar=list(map(int,input().split()))
di={}
for i in ar:
    di[i]=di.get(i,0)+1
sm=sum(ar)
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    if(b not in di):
        print(sm)
    elif(b in di):
        x=di[b]
        del di[b]
        if(c in di):
            di[c]+=x
        else:
            di[c]=x
        s=0
        s=sm-(b*x)+(x*c)
        sm=s
        print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ar=list(map(int,input().split()))
dp=[0]*n
for i in range(n):
    x=0
    for j in range(n):
        if(i!=j):
            x^=ar[j]
    dp[i]=x
print(' '.join(map(str,dp)))
    

Fixed submission:
n=int(input())
ar=list(map(int,input().split()))
x=0
for i in range(n):
    x^=ar[i]
for i in range(n):
    print(ar[i]^x,end=" ")
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
cnt=0
i=1
while(i<n):
    if(s[i-1]=='A' and s[i]=='B' and s[i+1]=='C'):
        cnt+=1
    i+=1
        
print(cnt)
    

Fixed submission:
n=int(input())
s=input()
cnt=0
i=1
while(i<n-1):
    if(s[i-1]=='A' and s[i]=='B' and s[i+1]=='C'):
        cnt+=1
    i+=1
        
print(cnt)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
cnt=0
for i in range(1,n):
  if(s[i-1]=='A' and s[i]=='B' and s[i+1]=='C'):
    cnt+=1
print(cnt)
    

Fixed submission:
n=int(input())
s=input()
cnt=0
i=1
while(i<n-1):
    if(s[i-1]=='A' and s[i]=='B' and s[i+1]=='C'):
        cnt+=1
    i+=1
        
print(cnt)
Buggy python submission (verdict: Runtime Error):
a = input()


amari  = a % 1000
otsuri = 1000 - amari
print(otsuri)

Fixed submission:
a = input()
amari = int(a)%1000
otsuri = 1000 - amari
if otsuri == 1000:
  otsuri = 0

print(otsuri)
Buggy python submission (verdict: Runtime Error):
s = int,input()
i = list(int,input())

Fixed submission:
s = int,input()
i = list(map(int,input().split()))
err = 0
total = 0
while err == 0:
    count = 0
    for nom in i:
        if nom % 2 == 1:
            err = 1
            count += 1
        else:
            i[count] = nom / 2
            count += 1
    if err == 0:
        total += 1
print(total)
Buggy python submission (verdict: Runtime Error):
N = input()
remainder = N % 1000
if remainder == 0:
  print(0)
else:
  print(1000 - remainder)

Fixed submission:
N = int(input())
remainder = N % 1000
if remainder == 0:
  print(0)
else:
  print(1000 - remainder)

Buggy python submission (verdict: Runtime Error):
N = input()
remainder = N % 1000
print(remainder)

Fixed submission:
N = int(input())
remainder = N % 1000
if remainder == 0:
  print(0)
else:
  print(1000 - remainder)

Buggy python submission (verdict: Runtime Error):
def main():
  N = input()
  remainder = N % 1000
  print(remainder)

main()

Fixed submission:
N = int(input())
remainder = N % 1000
if remainder == 0:
  print(0)
else:
  print(1000 - remainder)

Buggy python submission (verdict: Runtime Error):
n = int(input())
A = input()
A = A.split()
A = [int(i) for i in A]
A = sorted(A, reverse = True)
ans = 0

for x in A:
	ans += x

ans -= A[n-1]

print(ans)

Fixed submission:
taka = int(input())
remainder = taka % 1000
ans = 1000 - remainder
print(ans % 1000)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [input() for i in range(N)]
for v in ['AC', 'WA', 'TLE', 'RE']:
	print('{} x {}'.format(v, S.count(v)))

Fixed submission:
taka = int(input())
remainder = taka % 1000
ans = 1000 - remainder
print(ans % 1000)

Buggy python submission (verdict: Runtime Error):

taka = input()
remainder = taka%1000
ans = 1000 - remainder

Fixed submission:
taka = int(input())
remainder = taka % 1000
ans = 1000 - remainder
print(ans % 1000)
Buggy python submission (verdict: Runtime Error):
N = int(input)
S = [input() for i in range(n)]
for v in ['AC', 'WA', 'TLE', 'RE']:
  print('{} x {}'.format(v, s.count(v))
	

Fixed submission:
N = int(input())
S = [input() for i in range(N)]
for v in ['AC', 'WA', 'TLE', 'RE']:
	print('{0} x {1}'.format(v, S.count(v)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
a=1
for i in A:
	a *= i
if a > 10**18:
	a = -1
print(a)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
a=1
if 0 in A:
	a=0
else:
	for i in A:
		a *= i
		if a > 10**18:
			a = -1
			break
print(a)

Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 1;
tem = 0
ok = 1
s = input().split()
for i in s:
    if(int(i) == 0):
        tem = 1
        break
    ans *= int(i) 
    if(ans > 10**18):
        ok = 0
if(tem):
    print(0)
elif(ok)
    print(ans)
else:
    print("-1")


Fixed submission:
n = int(input())
ans = 1;
tem = 0
ok = 1
s = input().split()
for i in s:
    if(int(i) == 0):
        tem = 1
        break
    if(ok == 1):
        ans *= int(i) 
        if(ans > 10**18):
            ok = 0
if(tem):
    print(0)
elif(ok):
    print(ans)
else:
    print("-1")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1;
s = input().split()
for i in s:
   ans *= int(i) 
if(ans > 10**18):
    print("-1")
else:
    print(ans)


Fixed submission:
n = int(input())
ans = 1;
tem = 0
ok = 1
s = input().split()
for i in s:
    if(int(i) == 0):
        tem = 1
        break
    if(ok == 1):
        ans *= int(i) 
        if(ans > 10**18):
            ok = 0
if(tem):
    print(0)
elif(ok):
    print(ans)
else:
    print("-1")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 0
for i in range(N):
  for j in range(i + 1, N):
    for k in range(j + 1, N):
      if S[i] != S[j] and S[j] != S[k] and S[k] != S[i] and j - i != k - j:
        ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()

r = 0
g = 0
b = 0
for s in S:
  if s == "R":
    r += 1
  if s == "G":
    g += 1
  if s == "B":
    b += 1
ans = r * g * b

for i in range(N):
  for j in range(i + 1, N):
    k = 2 * j - i
    if k >= N:
      continue
    if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      ans -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
X = int(input())
N = X // 100
n = X % 100

if n / N > 5:
  print(0)
else:
  print(1)

Fixed submission:
X = int(input())
N = X // 100
n = X % 100

if N == 0:
  print(0)
elif n / N > 5:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
X = int(input())
N = X // 100
n = X % 100

if n / N > 5:
  print(0)
else:
  print(1)

Fixed submission:
X = int(input())
N = X // 100
n = X % 100

if N == 0:
  print(0)
elif n / N > 5:
  print(0)
else:
  print(1)
Buggy python submission (verdict: Time Limit Exceeded):
import re

N = int(input())
S = input()

pins = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      pins.append(str(i) + str(j) + str(k))

ans = 0
for p in pins:
  repatter = re.compile("\d*{}\d*{}\d*{}\d*".format(p[0], p[1], p[2]))
  if repatter.match(S):
    ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()

pins = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      pins.append(str(i) + str(j) + str(k))

ans = 0
for p in pins:
  i = S.find(p[0])
  if i >= 0:
    j = S[i + 1 :].find(p[1])
    if j >= 0:
      k = S[i + j + 2 :].find(p[2])
      if k >= 0:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import re

N = int(input())
S = input()

pins = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      pins.append(str(i) + str(j) + str(k))

ans = 0
for p in pins:
  repatter = re.compile("\d*{}\d*{}\d*{}\d*".format(p[0], p[1], p[2]))
  if repatter.match(S):
    ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()

pins = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      pins.append(str(i) + str(j) + str(k))

ans = 0
for p in pins:
  i = S.find(p[0])
  if i >= 0:
    j = S[i + 1 :].find(p[1])
    if j >= 0:
      k = S[i + j + 2 :].find(p[2])
      if k >= 0:
        ans += 1
print(ans)

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

memo = [False for _ in range(100)]
ans = 0
f = False
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    if memo[int(S[i]) * 10 + int(S[j])]:
      continue
    ans += len(set(S[j + 1 :]))
    memo[int(S[i]) * 10 + int(S[j])] = True
    if ans == 999:
      f = True
      break
  if f:
    break
print(ans)

Fixed submission:
N = int(input())
S = input()

pins = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      pins.append(str(i) + str(j) + str(k))

ans = 0
for p in pins:
  i = S.find(p[0])
  if i >= 0:
    j = S[i + 1 :].find(p[1])
    if j >= 0:
      k = S[i + j + 2 :].find(p[2])
      if k >= 0:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
H, W, A, B = map(int, input().split())

ans = [[0 for _ in range(W)] for _ in range(H)]

if A == 0:
  for i in range(H):
    for j in range(W):
      if i < B:
        ans[i][j] = 1
      else:
        ans[i][j] = 0
elif B == 0:
  for i in range(H):
    for j in range(W):
      if j < A:
        ans[i][j] = 1
      else:
        ans[i][j] = 0
else:
  w, h = 0, 0
  while w < W or h < H:
    for i in range(w, min(w + B, W)):
      for j in range(h, min(h + A, H)):
        ans[i][j] = 1
    w += B
    h += A

for i in range(H):
  for j in range(W):
    print(ans[i][j], end = "")
  print()

Fixed submission:
H, W, A, B = map(int, input().split())

ans = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
  for j in range(A):
    ans[i][j] = 1

for i in range(B):
  for j in range(W):
    ans[i][j] ^= 1

for i in range(H):
  for j in range(W):
    print(ans[i][j], end = "")
  print()
Buggy python submission (verdict: Runtime Error):
import bisect
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
for _ in range(M):
  a = A.pop(-1) // 2
  bisect.insort_left(A, a)

print(sum(A))

Fixed submission:
S = input()

if S == "Sunny":
  print("Cloudy")
elif S == "Cloudy":
  print("Rainy")
else:
  print("Sunny")
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = list(input())

l = []
for i in range(N):
  if i == 0:
    tmp = i
  elif S[i - 1] != S[i]:
    l.append([tmp, i - 1, i - tmp])
    tmp = i
  elif i == N - 1:
    l.append([tmp, i, i - tmp + 1])

for k in range(K):
  i = 2 * k + 1
  if S[l[i][0]] == "L":
    S[l[i][0] : l[i][1] + 1] = "R" * l[i][2]
  else:
    S[l[i][0] : l[i][1] + 1] = "L" * l[i][2]

ans = 0
for i in range(N - 1):
  if S[i] == S[i + 1]:
    ans += 1

print(ans)

Fixed submission:
N, K = map(int, input().split())
S = list(input())

l = []
tmp = 0
for i in range(1, N):
  if S[i - 1] != S[i]:
    l.append([tmp, i - 1, i - tmp])
    tmp = i
  if i == N - 1:
    l.append([tmp, i, i - tmp + 1])

for k in range(K):
  i = 2 * k + 1
  if i >= len(l):
    break
  if S[l[i][0]] == "L":
    S[l[i][0] : l[i][1] + 1] = "R" * l[i][2]
  else:
    S[l[i][0] : l[i][1] + 1] = "L" * l[i][2]

ans = 0
for i in range(N - 1):
  if S[i] == S[i + 1]:
    ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = list(input())

l = []
for i in range(N):
  if i == 0:
    tmp = i
  if S[i - 1] != S[i]:
    l.append([tmp, i - 1, i - tmp])
    tmp = i
  if i == N - 1:
    l.append([tmp, i, i - tmp + 1])
l.sort(key = lambda x:x[2], reverse = True)

for k in range(K):
  if S[l[k][0]] == "L":
    S[l[k][0] : l[k][1] + 1] = "R" * l[k][2]
  else:
    S[l[k][0] : l[k][1] + 1] = "L" * l[k][2]

ans = 0
for i in range(N):
  if S[i] == "L":
    if i != 0 and S[i - 1] == "L":
      ans += 1
  else:
    if i != N - 1 and S[i + 1] == "R":
      ans += 1

print(ans)

Fixed submission:
N, K = map(int, input().split())
S = list(input())

l = []
tmp = 0
for i in range(1, N):
  if S[i - 1] != S[i]:
    l.append([tmp, i - 1, i - tmp])
    tmp = i
  if i == N - 1:
    l.append([tmp, i, i - tmp + 1])

for k in range(K):
  i = 2 * k + 1
  if i >= len(l):
    break
  if S[l[i][0]] == "L":
    S[l[i][0] : l[i][1] + 1] = "R" * l[i][2]
  else:
    S[l[i][0] : l[i][1] + 1] = "L" * l[i][2]

ans = 0
for i in range(N - 1):
  if S[i] == S[i + 1]:
    ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
MOD = 10 ** 9 + 7
N = 13
dp = [0 for _ in range(N)]
dp[0] = 1

mul = 1
for i in range(len(S)):
  c = S[len(S) - i - 1]
  nextDP = [0 for _ in range(N)]

  if c == "?":
    for k in range(10):
      for j in range(N):
        nextDP[(k * mul + j) % N] += dp[j]
        nextDP[(k * mul + j) % N] %= MOD
  else:
    k = int(c)
    for j in range(N):
      nextDP[(k * mul + j) % N] += dp[j]
      nextDP[(k * mul + j) % N] %= MOD

  mul *= 10
  mul %= N
  dp = nextDP
print(dp[5])

Fixed submission:
S = input()
MOD = 10 ** 9 + 7
N = 13
dp = [0 for _ in range(N)]
dp[0] = 1

mul = 1
for i in range(len(S)):
  c = S[len(S) - i - 1]
  nextDP = [0 for _ in range(N)]

  if c == "?":
    for k in range(10):
      for j in range(N):
        nextDP[(k * mul + j) % N] += dp[j]
        nextDP[(k * mul + j) % N] %= MOD
  else:
    k = int(c)
    for j in range(N):
      nextDP[(k * mul + j) % N] += dp[j]
      nextDP[(k * mul + j) % N] %= MOD

  mul *= 10
  mul %= N
  dp = nextDP
print(dp[5])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
MOD = 10 ** 9 + 7
N = len(S)

def check(n):
  for i in range(N):
    if S[i] != "?":
      d = 10 ** (N - i - 1)
      c = (n // d) % 10
      if c != int(S[i]):
        return False
  return True

num_max = 0
for i in range(N):
  num_max *= 10
  if S[i] != "?":
    num_max += int(S[i])
  else:
    num_max += 9

ans = 0
num = 5
while num <= num_max:
  if check(num):
    ans += 1
  num += 13
print(ans % MOD)

Fixed submission:
S = input()
MOD = 10 ** 9 + 7
N = 13
dp = [0 for _ in range(N)]
dp[0] = 1

mul = 1
for i in range(len(S)):
  c = S[len(S) - i - 1]
  nextDP = [0 for _ in range(N)]

  if c == "?":
    for k in range(10):
      for j in range(N):
        nextDP[(k * mul + j) % N] += dp[j]
        nextDP[(k * mul + j) % N] %= MOD
  else:
    k = int(c)
    for j in range(N):
      nextDP[(k * mul + j) % N] += dp[j]
      nextDP[(k * mul + j) % N] %= MOD

  mul *= 10
  mul %= N
  dp = nextDP
print(dp[5])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
MOD = 10 ** 9 + 7
N = len(S)

def check(n):
  for i in range(N):
    if S[i] != "?":
      d = 10 ** (N - i - 1)
      c = (n // d) % 10
      if c != int(S[i]):
        return False
  return True

num_max = 0
for i in range(N):
  num_max *= 10
  if S[i] != "?":
    num_max += int(S[i])
  else:
    num_max += 9

ans = 0
num = 5
while num <= num_max:
  if check(num):
    ans += 1
  num += 13
print(ans % MOD)

Fixed submission:
S = input()
MOD = 10 ** 9 + 7
N = 13
dp = [0 for _ in range(N)]
dp[0] = 1

mul = 1
for i in range(len(S)):
  c = S[len(S) - i - 1]
  nextDP = [0 for _ in range(N)]

  if c == "?":
    for k in range(10):
      for j in range(N):
        nextDP[(k * mul + j) % N] += dp[j]
        nextDP[(k * mul + j) % N] %= MOD
  else:
    k = int(c)
    for j in range(N):
      nextDP[(k * mul + j) % N] += dp[j]
      nextDP[(k * mul + j) % N] %= MOD

  mul *= 10
  mul %= N
  dp = nextDP
print(dp[5])