Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import math
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column

# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']




def main():
    N, A, B, C, D = list(map(int,input().split()))
    S= str(input())
    # print(S[2:5])-> [2]~[4]
    if C>D:
        if '##' in S[A:C]:
            print("No")
        elif "..." in S[B-2:C]:
            print("Yes")
        else:
            print("No")
    else:
        if '##' in S[A:D]:
            print("No")
        else:
            print("Yes")
    # elif C>D and  ("..." in S[B-2:])
    # print(S[B-2:])
    
if __name__ == "__main__":
    main()

Fixed submission:
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import math
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column

# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']




def main():
    N, A, B, C, D = list(map(int,input().split()))
    S= str(input())
    # print(S[2:5])-> [2]~[4]
    if C>D:
        if '##' in S[A-1:C+1]:
            print("No")
        elif "..." in S[B-2:D+1]:
            print("Yes")
        else:
            print("No")
    else:
        if '##' in S[A-1:D]:
            print("No")
        else:
            print("Yes")
    # elif C>D and  ("..." in S[B-2:])
    # print(S[B-2:])
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n=int(input()) 
flag = False
for i in range(100*n,100*(n+1)):
  if i%108 == 0:
    x == int(i//108)
    print(x)
    flag == True
    break
if flag == False:
  print(':(')

Fixed submission:
n=int(input()) 
flag = False
for i in range(100*n,100*(n+1)):
  if i%108 == 0:
    x = int(i//108)
    print(x)
    flag = True
    break
if flag == False:
  print(':(')

Buggy python submission (verdict: Runtime Error):
n=int(input()) 
flag == False
for i in range(100*n,100*(n+1)):
  if i%108 == 0:
    x == int(i//108)
    print(x)
    flag == True
    break
if flag == False:
  print(':(')
  

Fixed submission:
n=int(input()) 
flag = False
for i in range(100*n,100*(n+1)):
  if i%108 == 0:
    x = int(i//108)
    print(x)
    flag = True
    break
if flag == False:
  print(':(')
Buggy python submission (verdict: Runtime Error):
N = int(input())
l = [1,2,4,8,16,32,64]{[::-1]
for i in l:
  if N >= i:
    print(i)
    break



Fixed submission:
N = int(input())
l = [1,2,4,8,16,32,64][::-1]
for i in l:
  if N >= i:
    print(i)
    break
Buggy python submission (verdict: Runtime Error):
A = list(input())
S = ['A','C','G','T']
count = 0
a = []
for i in A:
  if i in S:
    count += 1
  else:
    a.append(count)
    count = 0
print(max(a))

Fixed submission:
A = list(input())
S = ['A','C','G','T']
count = 0
a = []
a.append(count)
for i in A:
  if i in S:
    count += 1
    a.append(count)
  else:
    count = 0
print(max(a))
Buggy python submission (verdict: Runtime Error):
A = int(input())
p = A
count = 0
if A = 1:
  count == 0
else:
  count =2
while A != 1:
  if A % 2 == 0:
    A = A // 2
    count = count + 1
  else:
    A = A * 3 + 1
    count = count + 1
print(count)

Fixed submission:
A = int(input())
p = A
C = []
while A not in C:
  C.append(A)
  if A % 2 == 0:
    A = A//2
  else:
    A = A*3+1
print(len(C)+1)
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
C = [int(input()) for _ in range(A)]
c = []
p = 0
C = sorted(C)
for i in range(B,A+1):
  c.append(max(C[i-(B):i]) - min(C[i-(B):i]))
  print(C[i-(B):i])
print(min(c))

Fixed submission:
A = int(input())
B = [int(input()) for _ in range(A)]
p = 0
B = sorted(B)
b = B.pop(-1)
for i in B:
  p += i
print(b//2 + p)

Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
C = [int(input()) for _ in range(A)]
c = []
p = 0
C = sorted(C)
for i in range(B-1,A):
  c.append(max(C[i-(B-1):i]) - min(C[i-(B-1):i]))
print(min(c))

Fixed submission:
A = int(input())
B = [int(input()) for _ in range(A)]
p = 0
B = sorted(B)
b = B.pop(-1)
for i in B:
  p += i
print(b//2 + p)
Buggy python submission (verdict: Runtime Error):
N,M,X,Y = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = max(A)
b = min(B)

flag = a>0 and b>0
if flag and a-b <= 0 and (Y < a and b <= X) and a<b:
  print('No War')
elif not flag and a-b >= 0 and (Y > a and b => X) and a>b:
  print('No War')
else:
  ('War')

Fixed submission:
N,M,X,Y = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
x = max(X,max(A))
y = min(Y,min(B))
 
if Y >= x and y > X and y > x:
  print('No War')
else:
  print('War')
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
if B == sum(X):
  print(len(X))
elif B >= min(x):
  print(0)
else:
  for i in range(A):
    a = X.pop(0)
    B=B - a
    if B >= 0:
      count += 1
  print(count)

Fixed submission:
A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
j=len(X)
if B == sum(X):
  print(len(X))
else:
  for i in range(A):
    a = X.pop(0)
    B=B - a
    if B >= 0:
      count += 1
    if B >= 0 and count == j:
      count = count -1
  print(count)
Buggy python submission (verdict: Runtime Error):
A = int(input())
if (A%4 == 3 or A%4 == 0 or A%7 == 4 or A%7== 0) and A != 3:
  print('Yes')
else:
  print('No')

Fixed submission:
a,b = map(int,input().split())
c = a % b == 0
if c:
  print(0)
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
A = int(input())
if (A%4 == 3 or A%4 == 0 A%7 == 4 or A%7 == 0) and A != 3:
  print('Yes')
else:
  print('No')

Fixed submission:
A = int(input())
Flag = False
for i in range((A//4)+1):
  for j in range((A//7)+1):
    if 4*i + 7*j == A:
      Flag = True
if Flag:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
A = int(input())
if (A%4 == 3 or A%4 == 0 A%7 == 4 or A%7) and A != 3:
  print('Yes')
else:
  print('No')

Fixed submission:
A = int(input())
Flag = False
for i in range((A//4)+1):
  for j in range((A//7)+1):
    if 4*i + 7*j == A:
      Flag = True
if Flag:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
A = input()
B = input()
for a in range(len(A)):
  k=A[a:len(A)]+A[:a]
  if k == B:
    t = True
    break;
    
if t:
  print('Yes')
else:
  print('No')

Fixed submission:
A = input()
B = input()
t = False
for a in range(len(A)):
  k=A[a:len(A)]+A[:a]
  if k == B:
    t = True
    break;
    
if t:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = input()
m = 0
for i in range(A):
  c = set(B[:i])
  a = set(B[i:])
  l = a & c
  m = max(m,len(l))
print(m)

Fixed submission:
A = input()
B = int(A)
b = 0
for _ in range(len(A)):
  b += B % 10
  B = B//10
if int(A) % b == 0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
l_0 = 2
l_1 = 1
A = int(input())
if 　A == 0:
  print(l_0)
elif A == 1:
  print(l_1)
else:
  for i in range(1,A+1):
    if i%2 != 0
	    l_1 = l_0 + L_1 
    else:
      l_0 = l_0 + L_1 

Fixed submission:
l_0 = 2
l_1 = 1
A = int(input())
if A == 0:
  print(l_0)
elif A == 1:
  print(l_1)
else:
  for i in range(A-1):
    if i%2 != 0:
      p = l_1
      l_1 = l_0 + l_1
      l_0 = p
    else:
      p = l_1
      l_1 = l_0 + l_1
      l_0 = p
  print(max(l_0,l_1))
Buggy python submission (verdict: Runtime Error):
A = input()
a =[A[i] for i in range(0,len(A)+1,2)]
print(','.join(a).replace(',',''))

Fixed submission:
A = input()
a =[A[i] for i in range(0,len(A),2)]
print(','.join(a).replace(',',''))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]
Next = 0
for i in range(N):
  if Next == 2:
    Next = A[Next]
    p = i
    break;
  else:
    Next = A[Next-1]
    p = -1
print(p)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
Next = 1
for i in range(N):
  if Next == 2:
    Next = A[Next-1]
    p = i
    break;
  else:
    Next = A[Next-1]
    p = -1
print(p)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
S = [list(map(int,input().split())) for i in range(a)]
CP = [list(map(int,input().split())) for i in range(a)]
for s in S:
  count = 0
  ab = 10**8
  p = 10**8
  for cp in CP:
    total = abs(s[0]-cp[0]) + abs(s[1]-cp[1])
    count +=1
    if ab > total:
      ab = total
      p = count
      
  print(p)

Fixed submission:
a,b = map(int,input().split())
S = [list(map(int,input().split())) for i in range(a)]
CP = [list(map(int,input().split())) for i in range(b)]
for s in S:
  count = 0
  ab = 10**9
  p = 10**9
  for i,cp in zip(range(b),CP):
    total = abs(s[0]-cp[0]) + abs(s[1]-cp[1])
    count +=1
    if ab > total:
      ab = total
      p = i+1
      
  print(p)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
S = [list(map(int,input().split())) for i in range(a)]
CP = [list(map(int,input().split())) for i in range(a)]


for s in S:
  count = 0
  ab = 10**8
  p = 10**8
  for cp in CP:
    total = abs(s[0]-cp[0]) + abs(s[1]-cp[1])
    count +=1
    if ab > total:
      ab = total
      p = count
  print(p)

Fixed submission:
a,b = map(int,input().split())
S = [list(map(int,input().split())) for i in range(a)]
CP = [list(map(int,input().split())) for i in range(b)]
for s in S:
  count = 0
  ab = 10**9
  p = 10**9
  for i,cp in zip(range(b),CP):
    total = abs(s[0]-cp[0]) + abs(s[1]-cp[1])
    count +=1
    if ab > total:
      ab = total
      p = i+1
      
  print(p)
Buggy python submission (verdict: Time Limit Exceeded):
A = int(input())
a = 1
for i in range(1,A+1):
  a = a * i
print(a%(pow(10,9)+7))

Fixed submission:
A = int(input())
b = 1
mod = 1000000007
for a in range(1,A+1):
  b = b*a % mod
print(b)
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())
flag = 1
s = 0
for l in range(K+1):
  if l == S+1:
    break
  for m in range(K+1):
    n = S - (l+m)
    if l == S+1:
      break
    elif (0<=n)and(n<=K) and (l+m+n == S):
      s = s+1
print(s)

Fixed submission:
K,S = map(int,input().split())
flag = 1
s = 0
for l in range(K+1):
  for m in range(K+1):
    if (0 <= S-l-m)and(S-l-m<=K):
      s = s+1
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())
flag = 1
s = 0
for l in range(K+1):
  if l == S+1:
    break
  for m in range(K+1):
    if l == S+1:
      break
    for n in range(K+1):
      if l == S+1:
        break
      if l+m+n == S:
        s = s+1
print(s)

Fixed submission:
K,S = map(int,input().split())
flag = 1
s = 0
for l in range(K+1):
  for m in range(K+1):
    if (0 <= S-l-m)and(S-l-m<=K):
      s = s+1
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())
flag = 1
s = 0
for l in range(K+1):
  for m in range(K+1):
    for n in range(K+1):
      if l+m+n == S:
        s = s+1
print(s)

Fixed submission:
K,S = map(int,input().split())
flag = 1
s = 0
for l in range(K+1):
  for m in range(K+1):
    if (0 <= S-l-m)and(S-l-m<=K):
      s = s+1
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
p = int(input())
A = list(map(int,input().split()))
co = 0
cont = 0
for i in A:
  cont += 1
  if A.count(cont) != 0 and i == A.index(cont)+1:
    A.pop(A.index(cont))
    co += 1
print(co)

Fixed submission:
p = int(input())
ans = 0
*A,= map(int,input().split())
for j,i in enumerate(A):
  if A[A[j]-1]==j+1:
    ans+=1
print(ans//2)

Buggy python submission (verdict: Time Limit Exceeded):
p = int(input())
A = list(map(int,input().split()))
a = list(range(1,p+1))
count = 0
for j,i in zip(a,A):
  if A.count(j) != 0 and i == a[A.index(j)]:
    A.pop(A.index(j))
    count += 1
print(count)

Fixed submission:
p = int(input())
ans = 0
*A,= map(int,input().split())
for j,i in enumerate(A):
  if A[A[j]-1]==j+1:
    ans+=1
print(ans//2)

Buggy python submission (verdict: Time Limit Exceeded):
p = int(input())
A = list(map(int,input().split()))
a = list(range(1,p+1))
count = 0
for j,i in zip(a,A):
  if A.count(j) != 0 and i == a[A.index(j)]:
    count += 1
print(count//2)

Fixed submission:
p = int(input())
ans = 0
*A,= map(int,input().split())
for j,i in enumerate(A):
  if A[A[j]-1]==j+1:
    ans+=1
print(ans//2)

Buggy python submission (verdict: Runtime Error):
p = int(input())
A = list(map(int,input().split()))
a = list(range(1,p+1))
count = 0
for j,i in zip(a,A):
  if i == a[A.index(j)]:
    count += 1
print(count//2)

Fixed submission:
p = int(input())
ans = 0
*A,= map(int,input().split())
for j,i in enumerate(A):
  if A[A[j]-1]==j+1:
    ans+=1
print(ans//2)
Buggy python submission (verdict: Runtime Error):
aca
accc
ca

Fixed submission:
A = input() + ' '
B = input() + ' '
C = input() + ' '
s = A[0]
while(len(A) != 0 and s != ' ' ) and  (len(B) != 0 and s != ' ') and (len(B) != 0 and s != ' '):
  if s == 'a':
    s = A[0]
    A = A[1:]
  elif s == 'b':
    s = B[0]
    B = B[1:]
  else:
    s = C[0]
    C = C[1:]
  if s == ' ':
    break;
  else:
    p = s
print(p.upper())

Buggy python submission (verdict: Runtime Error):
A = input()
B = input()
C = input()
s = A[0]
while(len(A) != 0) and  (len(B) != 0) and (len(B) != 0):
    if s == 'a':
      s = A[0]
      A = A[1:]
    elif s == 'b':
      s = B[0]
      B = B[1:]
    else:
      s = C[0]
      C = C[1:]
print(s.upper())

Fixed submission:
A = input() + ' '
B = input() + ' '
C = input() + ' '
s = A[0]
while(len(A) != 0 and s != ' ' ) and  (len(B) != 0 and s != ' ') and (len(B) != 0 and s != ' '):
  if s == 'a':
    s = A[0]
    A = A[1:]
  elif s == 'b':
    s = B[0]
    B = B[1:]
  else:
    s = C[0]
    C = C[1:]
  if s == ' ':
    break;
  else:
    p = s
print(p.upper())
Buggy python submission (verdict: Runtime Error):
A,B =  map(int,input().split())
b = []
Zeroflag = False
count = 0
for i in range(A,B+1,1):
  b.append(i)
if 0 in b:
  zeroflag = True
for i in b:
  if i < 0:
    count += 1
if zeroflag:
  print('Zero')
elif count %2 == 0:
  print('Positive')
else:
  print('Negative')
  

Fixed submission:
A,B =  map(int,input().split())
b = []
count = 0
if A <0 and B<0:
  A =A + B
if A <= 0 and B >= 0:
  print('Zero')
elif A<0 and A % 2 == 0:
  print('Negative')
else:
  print('Positive')

Buggy python submission (verdict: Runtime Error):
A,B =  map(int,input().split())
b = []
Zeroflag = False
count = 0
for i in range(A,B+1,1):
  b.append(i)
if 0 in b:
  zeroflag = True
for i in b:
  if i < 0:
    count += 1
if zeroflag:
  print('Zero')
elif count %2 == 0:
  print('Positive')
else:
  print('Negative')
  

Fixed submission:
A,B =  map(int,input().split())
b = []
count = 0
if A <0 and B<0:
  A =A + B
if A <= 0 and B >= 0:
  print('Zero')
elif A<0 and A % 2 == 0:
  print('Negative')
else:
  print('Positive')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

cnt = 0
for i in range(1000):
    c = list(str(i).zfill(3).strip())
    f = 0
    for j in range(N):
        if S[j] == c[f]:
            f += 1
        if f == 3:
            break
    if f == 3:
        cnt += 1
        
print(cnt)        

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

cnt = 0
for i in range(1000):
    c = list(str(i).zfill(3).strip())
    f = 0
    for j in range(N):
        if S[j] == c[f]:
            f += 1
        if f == 3:
            break
    if f == 3:
        cnt += 1
        
print(cnt)
Buggy python submission (verdict: Runtime Error):
from math import ceil, sqrt
N = int(input())

for i in range(floor(sqrt(N)), 0, -1):
    if N % i == 0:
        print((N//i) + i - 2)
        break
    

Fixed submission:
from math import ceil, sqrt
N = int(input())

for i in range(ceil(sqrt(N)), 0, -1):
    if N % i == 0:
        print((N//i) + i - 2)
        break
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)
AF = [A[i] * F[i] for i in range(N)]

l = -1
r = max(AF)
while l + 1 < r:
    x = (l + r) // 2
    s = sum([max(A[i] - x//F[i], 0) for i in range(N)])
    if s <= K:
        r = x
    else:
        l = x

print(r)

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=True)
AF = [A[i] * F[i] for i in range(N)]

l = -1
r = max(AF)
while l + 1 < r:
    x = (l + r) // 2
    s = sum([max(A[i] - x//F[i], 0) for i in range(N)])
    if s <= K:
        r = x
    else:
        l = x

print(r)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
S = [list(map(int, input().strip())) for _ in range(N)]
G = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if S[i][j] == 1:
            G[i].append(j)

#Bipartie Graph
def is_bibarate(G):
    vst = [False] * N
    que = deque([0])
    color = [0] * N
    color[0] = 1
    while len(que):
        p = que.popleft()
        for q in list(G[p]):
            if color[q] == 0:
                color[q] = - color[p]
                que.append(q)
            elif color[q] == color[p]:
                return False
            
    return True
                

        
#Warshal Floyd        
d = [[float('inf')] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            d[i][j] = 0
        elif S[i][j] == 1:
            d[i][j] = 1
            
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j],d[i][k] + d[k][j])

wf_ans = max([max(r) for r in d]) + 1

if is_bibarate(G):
    print(wf_ans)
else:
    print(-1)

Fixed submission:
from collections import deque
N = int(input())
S = [list(map(int, input().strip())) for _ in range(N)]
G = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if S[i][j] == 1:
            G[i].append(j)

#Bipartie Graph
def is_bibarate(G):
    vst = [False] * N
    que = deque([0])
    color = [0] * N
    color[0] = 1
    while len(que):
        p = que.popleft()
        for q in list(G[p]):
            if color[q] == 0:
                color[q] = - color[p]
                que.append(q)
            elif color[q] == color[p]:
                return False
            
    return True
                

        
#Warshal Floyd        
d = [[float('inf')] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            d[i][j] = 0
        elif S[i][j] == 1:
            d[i][j] = 1
            
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j],d[i][k] + d[k][j])

wf_ans = max([max(r) for r in d]) + 1

if is_bibarate(G):
    print(wf_ans)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ABC = []
for i in range(M):
    ab = list(map(int,input().split()))
    c = list(map(int, input().split()))
    ab.append(c)
    ABC.append(ab)
    
INF = float('inf')
dp = [INF] * (2**N)
dp[0] = 0
for i in range(M):
    d = 0
    for c in ABC[i][2]:
        d |= (1 << (c-1))
        
    for j in range(2**N):
        dp[j|d] = min(dp[j|d], dp[j]+ABC[i][0])
        
if dp[-1] == INF:
    print(-1)
else:
    print(dp[-1])

Fixed submission:
N, M = map(int, input().split())
ABC = []
for i in range(M):
    ab = list(map(int,input().split()))
    c = list(map(int, input().split()))
    ab.append(c)
    ABC.append(ab)
    
INF = float('inf')
dp = [INF] * (2**N)
dp[0] = 0
for i in range(M):
    d = 0
    for c in ABC[i][2]:
        d |= (1 << (c-1))
        
    for j in range(2**N):
        dp[j|d] = min(dp[j|d], dp[j]+ABC[i][0])
        
if dp[-1] == INF:
    print(-1)
else:
    print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

players = np.array([K] * N)
for a in A:
    players = players - 1
    players[a-1] += 1
    
for p in players:
    if p > 0:
        print('Yes')
    else:
        print('No')

Fixed submission:
import numpy as np
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

players = list(np.array([K - len(A)] * N))
for a in A:
    players[a-1] += 1
    
for p in players:
    if p > 0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
from collections import Counter
import math
n = int(input())
s = list(map(lambda x: ''.join(sorted(x)) ,[list(input()) for i in range(n)]))
ans = 0
for i in Counter(s).values():
    ans += int(math.factorial(i) / 2)
print(ans) 

Fixed submission:
from collections import Counter
n = int(input())
s = list(map(lambda x: ''.join(sorted(x)) ,[list(input()) for i in range(n)]))
ans = 0
for i in Counter(s).values():
    ans += int(i*(i-1) / 2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input().strip())
N = len(S)

for i in range(1, N):
    if (S[i-1] == 'R') & (S[i] == 'L'):
        S[i-1], S[i] = 1, 1
        
for i in range(N):
    if S[i] == 'R':
        j = 1
        while S[i+j] == 'R':
            j += 1
        S[i+j+(j%2)] += 1
        S[i] = 0


for i in range(N-1, -1, -1):        
    if S[i] == 'L':
        j = 1
        while S[i-j] == 'L':
            j += 1
        S[i-j-(j%2)] += 1
        S[i] = 0


        
print(*S)        

Fixed submission:
S = input() 
N = len(S)
S += 'R'

rnl = []
tmp = 'R'
cnt = 1
for i in range(1, N+1):
    if S[i] == tmp:
        cnt += 1
    else:
        rnl.append(cnt)
        tmp = S[i]
        cnt = 1

ans = [0] * N
i = 0
for j in range(len(rnl)):
    r = rnl[j]
    # R zone
    if j % 2 == 0:
        ans[i+r-1] += (r+1) // 2
        ans[i+r] += r // 2
        i += r
    # L zone
    else:
        ans[i] += (r+1) // 2
        ans[i-1] += r // 2
        i += r

print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input().strip())
N = len(S)

for i in range(1, N):
    if (S[i-1] == 'R') & (S[i] == 'L'):
        S[i-1], S[i] = 1, 1
        
for i in range(N):
    if S[i] == 'R':
        j = 1
        while S[i+j] == 'R':
            j += 1
        S[i+j+(j%2)] += 1
        S[i] = 0


for i in range(N-1, -1, -1):        
    if S[i] == 'L':
        j = 1
        while S[i-j] == 'L':
            j += 1
        S[i-j-(j%2)] += 1
        S[i] = 0


        
print(*S)        

Fixed submission:
S = input() 
N = len(S)
S += 'R'

rnl = []
tmp = 'R'
cnt = 1
for i in range(1, N+1):
    if S[i] == tmp:
        cnt += 1
    else:
        rnl.append(cnt)
        tmp = S[i]
        cnt = 1

ans = [0] * N
i = 0
for j in range(len(rnl)):
    r = rnl[j]
    # R zone
    if j % 2 == 0:
        ans[i+r-1] += (r+1) // 2
        ans[i+r] += r // 2
        i += r
    # L zone
    else:
        ans[i] += (r+1) // 2
        ans[i-1] += r // 2
        i += r

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

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

for i in range(N):
    if S[i] == '?':
        for j in range(10):
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k] % mod
    else:
        for k in range(13):
            dp[i+1][(k*10+int(S[i]))%13] += dp[i][k] % mod
            
print(dp[-1][5] % mod)            

Fixed submission:
S = input()
N = len(S)
mod = 10**9 + 7

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

for i in range(N):
    if S[i] == '?':
        for j in range(10):
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k] % mod
    else:
        for k in range(13):
            dp[i+1][(k*10+int(S[i]))%13] += dp[i][k] % mod
            
print(dp[-1][5] % mod)