Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math 

K = int(input())
mymemo =  [ [float('INF') for k in range(K+1) ] for kk in range(K+1) ]
#print(mymemo)

mysum = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            if mymemo[a][b] != float('INF'):
                mygcd = mymemo[a][b]
            else:
                mygcd = math.gcd(a,b)
                mymemo[a][b] = mygcd
            if mymemo[mygcd][c] != float('INF'):
                mygcd2 = mymemo[mygcd][c]
            else:
                mygcd2 = math.gcd(mygcd,c)
                mymemo[mygcd][c] = mygcd2
            mysum += mygcd2
            #print(a, b,c, mygcd)
            #print(mymemo)
print(mysum)


Fixed submission:
import math 
import functools

K= int(input())
gcd_list = [ [float('INF') for i in range(K+1)] for j in range(K+1)]
#print(gcd_list)

for i in range(1,K+1):
    for j in range(1, K+1):
        gcd_list[i][j] = math.gcd(i,j)
#for g in gcd_list:
    #print(g)
mysum = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        mygcd = gcd_list[i][j]
        for k in range(1,K+1):
            mygcd2 = math.gcd(mygcd, k)
            mysum += mygcd2 
        
print(mysum)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

ans = S.count('R')*S.count('G')*S.count('B')
for i in range(n-2):
  for j in range(i+1,n-1):
    k = j+1
    if k < n and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
      ans -= 1
print(ans)

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

ans = S.count('R')*S.count('G')*S.count('B')

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

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

house_list = list(map(int, input().split()))
#print(house_list)


if 0 in house_list:
    print(min(house_list[-1] - house_list[1], house_list[-1] - house_list[0]))
else:
    print(min(house_list[-1] - house_list[0]))

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

house_list = list(map(int, input().split()))
#print(house_list)

dist_list = [K - house_list[-1] + house_list[0]]
#print(dist_list)

for n in range(1, N):
    dist_list.append(house_list[n] - house_list[n-1])
print(K - max(dist_list))

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

house_list = list(map(int, input().split()))
#print(house_list)


if 0 in house_list:
    print(min(house_list[-1] - house_list[1], house_list[-1] - house_list[0]))
else:
    print(min(house_list[-1] - house_list[1]))

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

house_list = list(map(int, input().split()))
#print(house_list)

dist_list = [K - house_list[-1] + house_list[0]]
#print(dist_list)

for n in range(1, N):
    dist_list.append(house_list[n] - house_list[n-1])
print(K - max(dist_list))

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

house_list = list(map(int, input().split()))
print(house_list)


if 0 in house_list:
    print(min(house_list[-1] - house_list[1], house_list[-1] - house_list[0]))
else:
    print(min(house_list[-1] - house_list[1]))

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

house_list = list(map(int, input().split()))
#print(house_list)

dist_list = [K - house_list[-1] + house_list[0]]
#print(dist_list)

for n in range(1, N):
    dist_list.append(house_list[n] - house_list[n-1])
print(K - max(dist_list))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())


pos = 0

for q in range(Q):
  myinput = list(input().split())
  #print(myinput)
  if len(myinput) == 1:
      pos += 1
  else:
      if myinput[1] == '1':
          if pos% 2 == 0:
            #正方向、先頭
            S = myinput[2] + S    
          elif pos%2 !=0:
            #逆方向、先頭
            S += myinput[2]   
      elif myinput[1] == '2':
          if pos% 2 == 0:
              #正方向、末尾
            S += myinput[2]    
          elif pos%2 !=0:
               #逆方向、末尾
                 S = myinput[2] + S    

if pos%2 == 0:                 
    print(S)
else:
    print(S[::-1])

Fixed submission:
from collections import deque

S = [input()]
d = deque(S)
#print(d)
Q = int(input())

pos = 0

for q in range(Q):
  myinput = list(input().split())
  #print(myinput)
  if len(myinput) == 1:
      pos += 1
  else:
      if myinput[1] == '1':
          if pos% 2 == 0:
               d.appendleft(myinput[2])   
          elif pos%2 !=0:
              #逆方向、先頭
              d.append(myinput[2])   
      elif myinput[1] == '2':
          if pos% 2 == 0:
              #正方向、末尾
              d.append(myinput[2])   
          elif pos%2 !=0:
              #逆方向、末尾
              d.appendleft(myinput[2])   

if pos%2 == 0:                 
    print(''.join(d))
else:
    print((''.join(d))[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

mylist = list(map(int, input().split()))

mysum = 0

for i in range(N-K+1):
    if mysum < sum(mylist[i:i+K]):
        mysum = sum(mylist[i:i+K])
        myans = 0
        for j in range(i,i+K):
            myans += (mylist[j] + 1)/2 
            #print(myans)
#print(mysum,myans)
print(myans)

Fixed submission:
import sys

N, K = map(int, input().split())

mylist = list(map(int, input().split()))

if N == K:
    myans = 0
    for n in range(N):
        myans += (mylist[n]+1)/2
    print(myans)
    sys.exit()

if K == 1:
    print((1+max(mylist))/2)
    sys.exit()
    
dp = [0 for n in range(N)]

for i in range(K):
    dp[i] = (mylist[i]+1)/2
dp[K-1] = sum(dp[0:K])

myans = -999999999
for n in range(K,N):
    dp[n] = (mylist[n]+1)/2 + dp[n-1] - (mylist[n-K]+1)/2 
    if myans < dp[n]:
        myans = dp[n]

        
print(myans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

if N == 1:
    print(1)
    sys.exit()

mylist = list(map(int, input().split()))


myans = 0
mymin = 9999999999
for i in range(N):
    if mylist[i] < mymin:
        mymin = mylist[i]
        myans += 1
        
print(myans)

Fixed submission:
N = int(input())


mylist = list(map(int, input().split()))


myans = 0
mymin = 9999999999
for i in range(N):
    if mylist[i] < mymin:
        mymin = mylist[i]
        myans += 1
        
print(myans)

Buggy python submission (verdict: Runtime Error):
N = int(input())

if N == 1:
    print(1)
    sys.exit()

mylist = list(map(int, input().split()))


myans = 0
mymin = 99999999
for i in range(N):
    if mylist[i] < mymin:
        mymin = mylist[i]
        myans += 1
        
print(myans)

Fixed submission:
N = int(input())


mylist = list(map(int, input().split()))


myans = 0
mymin = 9999999999
for i in range(N):
    if mylist[i] < mymin:
        mymin = mylist[i]
        myans += 1
        
print(myans)

Buggy python submission (verdict: Runtime Error):
N = int(input())

if N == 1:
    print(1)
    sys.exit()

mylist = list(map(int, input().split()))


myans = 0
mymin = 9999999
for i in range(N):
    if mylist[i] < mymin:
        mymin = mylist[i]
        myans += 1
        
print(myans)

Fixed submission:
N = int(input())


mylist = list(map(int, input().split()))


myans = 0
mymin = 9999999999
for i in range(N):
    if mylist[i] < mymin:
        mymin = mylist[i]
        myans += 1
        
print(myans)

Buggy python submission (verdict: Runtime Error):
N = int(input())

if N == 1:
    print(1)
    sys.exit()

mylist = list(map(int, input().split()))


myans = 1
minn = mylist[0]
for i in range(N):
    if mylist[i] < minn:
        minn = mylist[i]
        myans += 1
    else:
        minn = mylist[i]
        
print(myans)
        

Fixed submission:
N = int(input())


mylist = list(map(int, input().split()))


myans = 0
mymin = 9999999999
for i in range(N):
    if mylist[i] < mymin:
        mymin = mylist[i]
        myans += 1
        
print(myans)
Buggy python submission (verdict: Runtime Error):
import math

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

myans = (A * B) // math.gcd(A, B)

print(myans)

Fixed submission:
import fractions

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

myans = (A * B) // fractions.gcd(A, B)


print(myans)

Buggy python submission (verdict: Runtime Error):

import math

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

myans = (A * B) // math.gcd(A, B)


print(myans)

Fixed submission:
import fractions

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

myans = (A * B) // fractions.gcd(A, B)


print(myans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

D= list(map(int, input().split()))

mydic = {}
myans = 0

for i in D:
    if i in mydic:
        mydic[i] += 1
    else:
        mydic[i] = 1

#dicsorted = sorted(mydic.items())

myans = 1

if 0 not in mydic:
    print(0)
else:
    for i in range(len(mydic)):
        if i ==0:
            i = 1
        myans = myans * (i**mydic[i])
    print(myans%998244353)        

Fixed submission:
mod = 998244353
 
N = int(input())
D = [int(x) for x in input().split()]
 
dep = max(D)
dict = [0]*(dep+1)

#print(dict)
 
for d in D:
    dict[d]+=1
#print(dict)
if(dict[0]!=1 or D[0]!=0):
    ans = 0
else:
    ans = 1
    for de in range(1,dep+1):
        ans *= (dict[de-1]**dict[de])%mod
        #print(ans)
        ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))

mycnt = 0

for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1,N):
            if (L[i] < L[j] + L[k]) and (L[j] < L[k] + L[i]) and (L[k] < L[i] + L[j]):
                mycnt += 1
                #print(L[i], L[j],L[k])
print(mycnt)

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
L.sort(reverse=True)
 
ck = [0]*(N-2)
#print(L)

ans = 0
for i in range(N-2):
  j = i + 1
  k = N - 1
  #print(i,j,k)
  while j < k:
    if L[i]-L[j]-L[k] < 0:
      ans += k-j
      j += 1 
    else:
      k -=1
  
print(ans)
Buggy python submission (verdict: Runtime Error):
mycnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        mycnt += 1

if len(set(S)) == 1:
    print(len(S)*K//2)

elif S[0] != S[-1]:
    
    print(mycnt * K)

else:
    myleft = 1
    myright = 0
    mys = S[0]
    i = 1
    while S[i] == mys:
        myleft += 1
        i += 1
    
    myright = 0
    i = -1
    while S[i] == mys:
        myright += 1
        i -= 1
    print( (mycnt * K) - ( myleft//2 + myright//2 - (myright + myleft)//2 ) * ( K - 1 ) )
    

Fixed submission:
S = input()

#K = 1
K = int(input())

mycnt = 0
mynum = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        mynum += 1
        
    else: 
        mycnt += mynum//2
        mynum = 1
    #print('mycnt=', mycnt)
if mynum > 1:
    mycnt += mynum//2 

if len(set(S)) == 1:
    print(len(S)*K//2)

elif S[0] != S[-1]:
    
    print(mycnt * K)

else:
    myleft = 1
    myright = 0
    mys = S[0]
    i = 1
    while S[i] == mys:
        myleft += 1
        i += 1
    
    myright = 0
    i = -1
    while S[i] == mys:
        myright += 1
        i -= 1
    #print(myleft, myright)
    print( (mycnt * K) - ( myleft//2 + myright//2 - (myright + myleft)//2 ) * ( K - 1 ) )
Buggy python submission (verdict: Runtime Error):


mys = input()

if mys = 'Sunny':
  print('Cloudy')

elif mys = 'Cloudy':
  print('Rainy')

elif mys = 'Rainy':
  print('Sunny')














Fixed submission:
mys = input()
 
if mys == 'Sunny':
  print('Cloudy')

elif mys == 'Cloudy':
  print('Rainy')

elif mys == 'Rainy':
  print('Sunny')
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

mylist = list(map(int, input().split()))


mycnt = 1
while mycnt <= M:
    mylist[mylist.index(max(mylist))] = max(mylist)//2
    #print(mylist[mylist.index(max(mylist))])
    mycnt += 1

mysum = sum(mylist)


    

print(mysum)

Fixed submission:
import heapq
 
N,M = map(int,input().split())
 
A = [int(i)*-1 for i in input().split()]


heapq.heapify(A)
 
#print(A)

for _ in range(M):
  max = heapq.heappop(A) * -1
  #print(max, A)
  
  heapq.heappush(A,(max//2)*-1)
  
  #print(A)
 
print(sum(A)*-1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

mylist = list(map(int, input().split()))

mylist.sort(reverse=True)


mysum = sum(mylist)

mycnt = 1
while mycnt <= M:
    mylist[mylist.index(max(mylist))] = max(mylist)//2
    #print(mylist[mylist.index(max(mylist))])
    mycnt += 1

mysum = sum(mylist)


    

print(mysum)


Fixed submission:
import heapq
 
N,M = map(int,input().split())
 
A = [int(i)*-1 for i in input().split()]


heapq.heapify(A)
 
#print(A)

for _ in range(M):
  max = heapq.heappop(A) * -1
  #print(max, A)
  
  heapq.heappush(A,(max//2)*-1)
  
  #print(A)
 
print(sum(A)*-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

myans = 0

for i in range(N):
    myans += i
    
print(myans)

Fixed submission:
N = int(input())

N = N -1

mysum = ((N*(N+1))//2)

print(mysum)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
H[0] -= 1
for i in range(0, n - 1):
    diff = H[i + 1] - H[i]
    if diff >= 1:
        H[i + 1] -= 1
    elif diff < 0:
        print("No")
        exit()
print("Yes")

Fixed submission:
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
H[0] -= 1
for i in range(0, N - 1):
    diff = H[i + 1] - H[i]
    if diff >= 1:
        H[i + 1] -= 1
    elif diff < 0:
        print("No")
        exit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
import sys

N = int(input())

mylist = list(input().split())

for i in range(N-1):
     
    if int(mylist[i+1]) >= int(mylist[i])-1 :
        continue

    else:
        print('No')
        sye.exit()


print('Yes')

Fixed submission:
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
H[0] -= 1
for i in range(0, N - 1):
    diff = H[i + 1] - H[i]
    if diff >= 1:
        H[i + 1] -= 1
    elif diff < 0:
        print("No")
        exit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
import sys

N = int(input())

mylist = list(input().split())


for i in range(N-1):
     
    if int(mylist[i+1]) == int(mylist[i]) or int(mylist[i+1]) > int(mylist[i]):
        continue
    elif int(mylist[i+1]) == (int(mylist[i]) -1):
        continue
    else:
        print('No')
        sye.exit()
    
    


print('Yes')

Fixed submission:
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
H[0] -= 1
for i in range(0, N - 1):
    diff = H[i + 1] - H[i]
    if diff >= 1:
        H[i + 1] -= 1
    elif diff < 0:
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
S = int(input())


for i in range(1,1000000000,1):
    for j in range(1,1000000000,1):
        if i * j == S  :
            print(0,i,j,0,0,0)
            sys.exit()
#for i in mytable:

Fixed submission:
S = int(input())

if S <= 10 ** 9:
    print(0, 0, S, 0, S, 1)
else:
    a = S // (10 ** 9)
    b = S % (10 ** 9)
    if b == 0:
        print(0, 0, 10 ** 9, 1, 0, a)
    else:
        print(0, 0, 10 ** 9, 1, 10 ** 9 - b, a + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S = int(input())


for i in range(1,1000000000,1):
    for j in range(1000000000,0,-1):
        if i * j == S  :
            print(0,i,j,0,0,0)
            sys.exit()

Fixed submission:
S = int(input())

if S <= 10 ** 9:
    print(0, 0, S, 0, S, 1)
else:
    a = S // (10 ** 9)
    b = S % (10 ** 9)
    if b == 0:
        print(0, 0, 10 ** 9, 1, 0, a)
    else:
        print(0, 0, 10 ** 9, 1, 10 ** 9 - b, a + 1)
Buggy python submission (verdict: Runtime Error):
30
384 8895
1725 9791
170 1024
4 11105
2 6
578 1815
702 3352
143 5141
1420 6980
24 1602
849 999
76 7586
85 5570
444 4991
719 11090
470 10708
1137 4547
455 9003
110 9901
15 8578
368 3692
104 1286
3 4
366 12143
7 6649
610 2374
152 7324
4 7042
292 11386
334 5720

Fixed submission:
import sys

N = int(input())
mylist=[]

for i in range(N):
  s = input().split()
  mylist += [[int(s[0]),int(s[1])]]

mylsit = sorted(mylist, key=lambda x:x[1])

mysum = 0
for i in mylsit:
  mysum += i[0]
  if mysum <= i[1]:
    continue
  else:
    print('No')
    sys.exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
import statistics
N = int(input())

x = []
sub_x=[]
sub_y=[]

for i in range(N):
  x.append(list(map(int, input().split())))
  
x.sort()
for i in range(len(x)-1,0, -1):
  mysub_x = [(x[i][0] - x[i-1][0])]
  mysub_y = [(x[i][1] - x[i-1][1])]
  if mysub_x != [0]:
    sub_x += mysub_x
  if mysub_y != [0]:
    sub_y += mysub_y
p = statistics.mode(sub_x)
q = statistics.mode(sub_y)

ans = 0
for i in range(N-1):
    if abs(x[i][0] - x[i+1][0]) != abs(p) or abs(x[i][1] - x[i+1][1]) != abs(q):
      ans += 1
if ans == 0:
  print(1)
else:
  print(ans)  

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

if N < K or K==1:
  print(0)
else:
  print(N-K)
Buggy python submission (verdict: Runtime Error):
import statistics
N = int(input())

x = []
sub_x=[]
sub_y=[]


for i in range(N):
  x.append(list(map(int, input().split())))
  
x.sort()
#y.sort()
for i in range(len(x)-1,0, -1):
  mysub_x = [(x[i][0] - x[i-1][0])]
  mysub_y = [(x[i][1] - x[i-1][1])]
  if mysub_x != [0]:
    sub_x += mysub_x
  if mysub_y != [0]:
    sub_y += mysub_y


p = statistics.mode(sub_x)
#print(sub_x, p)
q = statistics.mode(sub_y)

ans = 0
for i in range(N-1):
    if abs(x[i][0] - x[i+1][0]) != abs(p) or abs(x[i][1] - x[i+1][1]) != abs(q):
      #print('dif')
      #print(ans, i)
      ans += 1

if ans == 0:
  print(1)
else:
  print(ans)  

Fixed submission:
N = int(input())
xy_list = []
ans = []
 
for i in range(N):
    x,y = map(int,input().split())
    xy_list.append([x,y])

if N==1:
    print(1)
    exit(0)
xy_list.sort(key=lambda x:x[1]) #yの値でソート
xy_list.sort(key=lambda x:x[0]) #xの値でソート
#print(xy_list)
#差をすべて調べる
for i in range(N):
  for j in range(N):
    if( i==j ):     #xとyの重複はなし
      continue
    t = (xy_list[i][0]-xy_list[j][0],xy_list[i][1]-xy_list[j][1])
    ans.append(t)
    #print(ans)  
#差の種類ごとの個数を調べる
res = [ans.count(e) for e in set(ans)]
#Nから一番多かった差の個数を引いたものが答え
print(N-max(res))
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

ans = 0

for r in range(N//R+1):        #N以内で
  for g in range(N-R*r//G+1):
    #print(r,g, B)
    if (N - R*r - G*g)%B == 0 and (N - R*r - G*g)/B >= 0:
      ans += 1
      #print((N - R*r - G*g)/B)
print(ans)
    

Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0

for r in range(N+1):
  if r*R > N:
    break
  for g in range(N+1):
    rg = r*R + g*G
    if rg > N:
      break
    if (N - rg)%B == 0 :
      ans += 1
      
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = set()
for _ in range(K):
    l, r = map(int, input().split())
    S = S | set(range(l, r + 1))
mod = 998244353

dp = [0 for _ in range(3 * N)]
for s in S:
    dp[s + 1] = 1

S_min = min(S)
for i in range(S_min, N + 1):
    for s in S:
        dp[i] += dp[i - s]
        dp[i] %= mod
print(dp[N] % mod)

Fixed submission:
N, K = map(int, input().split())
S = []
for _ in range(K):
    S.append(list(map(int, input().split())))
mod = 998244353

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

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

for i in range(N):
    for l, r in S:
        dp[i + 1] += cum[i - l + 1] - cum[i - r]
        dp[i + 1] %= mod
    cum[i + 1] = cum[i] + dp[i + 1]
    cum[i + 1] %= mod
print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = set()
for _ in range(K):
    l, r = map(int, input().split())
    S = S | set(range(l, r + 1))
mod = 998244353

dp = [0 for _ in range(3 * N)]
for s in S:
    dp[s + 1] = 1
for i in range(1, N + 1):
    for s in S:
        dp[i] += dp[i - s]
        dp[i] %= mod
print(dp[N] % mod)

Fixed submission:
N, K = map(int, input().split())
S = []
for _ in range(K):
    S.append(list(map(int, input().split())))
mod = 998244353

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

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

for i in range(N):
    for l, r in S:
        dp[i + 1] += cum[i - l + 1] - cum[i - r]
        dp[i + 1] %= mod
    cum[i + 1] = cum[i] + dp[i + 1]
    cum[i + 1] %= mod
print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

ans = 0
for i in range(N - 1):
    ans += A[i] * ((sum(A[i + 1:]) % mod)) % mod
print(ans % mod)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

cum = [0 for _ in range(N)]
cum[0] = A[0]
for i in range(N - 1):
    cum[i + 1] = (cum[i] + A[i + 1]) % mod

ans = 0
for i in range(N - 1):
    ans += (A[i] * (cum[N - 1] - cum[i])) % mod
print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = input()
C = C.lstrip('R').rstrip('W')

ans = 0
for _ in range(10**5):
    if len(C) > 0:
        l = C.find('R')
        r = C[::-1].find('W')
        n = min(l, r)
        C = C[n:-n]
        C = C.lstrip('R').rstrip('W')
        ans += n
    else:
        break
print(ans)

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

l, r = 0, N - 1
ans = 0
while l < r:
    if C[l] == 'R':
        l += 1
    elif C[r] == 'W':
        r -= 1
    else:
        ans += 1
        l += 1
        r -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = input()
C = C.lstrip('R').rstrip('W')

ans = 0
for i in range(10**6):
    if len(C) > 0:
        l = C.find('R')
        r = C[::-1].find('W')
        n = min(l, r)
        C = C[n:-n]
        C = C.lstrip('R').rstrip('W')
        ans += n
    else:
        break
print(ans)

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

l, r = 0, N - 1
ans = 0
while l < r:
    if C[l] == 'R':
        l += 1
    elif C[r] == 'W':
        r -= 1
    else:
        ans += 1
        l += 1
        r -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = input()
C = C.lstrip('R').rstrip('W')

i = 0
while len(C) > 0:
    l = C.index('R')
    r = C[::-1].index('W')
    n = min(l, r)
    C = C[n:-n]
    C = C.lstrip('R').rstrip('W')
    i += n
else:
    print(i)

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

l, r = 0, N - 1
ans = 0
while l < r:
    if C[l] == 'R':
        l += 1
    elif C[r] == 'W':
        r -= 1
    else:
        ans += 1
        l += 1
        r -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = input()
C = C.lstrip('R').rstrip('W')

i = 0
while len(C) > 0:
    l = C.index('R')
    r = C[::-1].index('W')
    n = min(l, r)
    C = C[n:]
    C = C[:-n]
    C = C.lstrip('R').rstrip('W')
    i += n
else:
    print(i)

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

l, r = 0, N - 1
ans = 0
while l < r:
    if C[l] == 'R':
        l += 1
    elif C[r] == 'W':
        r -= 1
    else:
        ans += 1
        l += 1
        r -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 1
for a in A:
    ans *= a
print(ans if ans <= 10**18 else -1)

Fixed submission:
import sys
N = int(input())
A = sorted(list(map(int, input().split())))

if 0 in A:
    print(0)
    sys.exit()

ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        sys.exit()
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
K = int(input())

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            x = math.gcd(i, j)
            ans += math.gcd(x, k)
print(ans)

Fixed submission:
import math
K = int(input())

ans = 0
a = 0
b = 0
c = 0
for i in range(1, K + 1):
    a += i

for i in range(1, K):
    for j in range(i + 1, K + 1):
        b += math.gcd(i, j) * 6

for i in range(1, K - 1):
    for j in range(i + 1, K):
        for k in range(j + 1, K + 1):
            x = math.gcd(i, j)
            c += math.gcd(x, k) * 6
ans = a + b + c
print(ans)