Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()

n %= 1000
if n==0:
    print(0)
else:
    print(1000-n)

Fixed submission:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()

ans = N // 1000
ans2 = N - (ans*1000)

if ans2 == 0:
    print(0)
else:
    print(1000-ans2)

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

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()

n %= 1000
if n==0:
    print(0)
else:
    print(1000-n)

Fixed submission:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()

ans = N // 1000
ans2 = N - (ans*1000)

if ans2 == 0:
    print(0)
else:
    print(1000-ans2)
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

h,w,k = LI()
cnt = 0
c = [0]*h
for i in range(h):
    c[i] = input()

for rows in range(1 << h):
    for cols in range(1 << w):
        black = 0
        for i in range(h):
            if (rows >> i) % 2 == 1:
                continue
            for j in range(w):
                if (cols >> j) % 2 == 1:
                    continue
                black += c[i][j] == '#'
        if black == k:
            cnt += 1
print(cnt)

Fixed submission:
import sys
import numpy as np
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

h,w,k = LI()
cnt = 0
c = [0]*h
for i in range(h):
    c[i] = input()

for rows in range(1 << h):
    for cols in range(1 << w):
        black = 0
        for i in range(h):
            if (rows >> i) % 2 == 1:
                continue
            for j in range(w):
                if (cols >> j) % 2 == 1:
                    continue
                black += c[i][j] == '#'
        if black == k:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
import sys
import math
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
a,b,c = LI()



if c-a-b > and (4*a*b) < ((c-a-b)**2) :
    print('Yes')
else:
    print('No')

Fixed submission:
import sys
import math
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
a,b,c = LI()



if c-a-b > 0 and (4*a*b) < ((c-a-b)**2) :
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()

print(N**3)

Fixed submission:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()

print(N**3)

Buggy python submission (verdict: Runtime Error):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()

print(N**3)

Fixed submission:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()

print(N**3)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
s = []
ans = 0
for i in range(N):
    s.append(''.join(sorted(S())))

for i in range(N-1):
    for q in range(i+1,N):
        if s[i] == s[q]:
            ans += 1

print(ans)


Fixed submission:
import sys
import collections


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
s = []
ans = 0
for i in range(N):
    s.append(''.join(sorted(S())))

c = collections.Counter(s)

for i in set(s):
    n = c[i]
    ans += n * (n-1) // 2
print(ans)
Buggy python submission (verdict: Runtime Error):
def LI(): return list(map(int, input().split()))


A,B,C = LI()
max_value = max([A+10+b+C,A+B*10+C,A+B+C*10])

print(max_value)

Fixed submission:
def LI(): return list(map(str, input().split()))


A = LI()

A.sort(reverse=True)
print(int(A[0] +A[1]) +int(A[2]))
Buggy python submission (verdict: Runtime Error):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B,C,X,Y = LI()

# only = A*X+B*Y
# only_mix = C*max(X,Y)*2
# comp = 0
# if X > Y:
#     comp = C*Y*2+A*(X-Y)
# elif X < Y:
#     comp = C*X*2+B*(Y-X)
# else:
#     comp = C*Y*2

# print(min(only,only_mix,comp))

ans = float('INF')
for i in range(max(X,Y)+1):
    price = A+max(X-i,0)+B*max(Y-i,0)+C*2*i
    ans = min(ans,price)

price(ans)

Fixed submission:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B,C,X,Y = LI()

only = A*X+B*Y
only_mix = C*max(X,Y)*2
comp = 0
if X > Y:
    comp = C*Y*2+A*(X-Y)
elif X < Y:
    comp = C*X*2+B*(Y-X)
else:
    comp = C*Y*2

print(min(only,only_mix,comp))

Buggy python submission (verdict: Runtime Error):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B,C,X,Y = LI()

# only = A*X+B*Y
# only_mix = C*max(X,Y)*2
# comp = 0
# if X > Y:
#     comp = C*Y*2+A*(X-Y)
# elif X < Y:
#     comp = C*X*2+B*(Y-X)
# else:
#     comp = C*Y*2

# print(min(only,only_mix,comp))

ans = float('INF')
for i in range(max(X,Y)+1):
    price = A+max(X-i,0)+B*max(Y-i,0)+C*2*ians 
    ans = min(ans,price)

price(ans)

Fixed submission:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B,C,X,Y = LI()

only = A*X+B*Y
only_mix = C*max(X,Y)*2
comp = 0
if X > Y:
    comp = C*Y*2+A*(X-Y)
elif X < Y:
    comp = C*X*2+B*(Y-X)
else:
    comp = C*Y*2

print(min(only,only_mix,comp))
Buggy python submission (verdict: Runtime Error):
A, B, C, X = [int(input()) for i in range(4)]
count = 0
for a in A:
    for b in B:
        for c in C:
            if 500*a+100*b+50*c == X:
                count += 1

print(count)


Fixed submission:
A, B, C, X = [int(input()) for i in range(4)]
count = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a+100*b+50*c == X:
                count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
prev_t = 0
prev_x = 0
prev_y = 0
for i in range(N):
    t, x, y = LI()
    if (x+y) > (t - prev_t) or (abs(prev_x-x) + abs(prev_y-y) + (t - prev_t)) % 2:
        print('No')
        exac()
    prev_t = t
    prev_x = x
    prev_y = y
print('Yes')


Fixed submission:
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
prev_t = 0
prev_x = 0
prev_y = 0
for i in range(N):
    t, x, y = LI()
    if abs(prev_x-x) + abs(prev_y-y) > (t - prev_t) or (abs(prev_x-x) + abs(prev_y-y) + (t - prev_t)) % 2:
        print('No')
        exit()
    prev_t = t
    prev_x = x
    prev_y = y
print('Yes')
Buggy python submission (verdict: Runtime Error):
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N, Y = LI()
y = 1000 * N
for i in range(N+1):
    for j in range(n-i+1):
        if i * 10000 + 5000 * j + 1000 * (N-i-j) == Y:
            print(i, j, N-i-j)
            exit()
print("-1 -1 -1")

Fixed submission:
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N, Y = LI()
y = 1000 * N
for i in range(N+1):
    for j in range(N-i+1):
        if i * 10000 + 5000 * j + 1000 * (N-i-j) == Y:
            print(i, j, N-i-j)
            exit()
print("-1 -1 -1")

Buggy python submission (verdict: Runtime Error):
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N, Y = LI()
y = 1000 * N
for i in range(N+1):
    for j in range(n-i+1):
        if i * 10000 + 5000 * j + 1000 * (N-i-j) == y:
            print(i, j, N-i-j)
            exit()
print("-1 -1 -1")

Fixed submission:
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N, Y = LI()
y = 1000 * N
for i in range(N+1):
    for j in range(N-i+1):
        if i * 10000 + 5000 * j + 1000 * (N-i-j) == Y:
            print(i, j, N-i-j)
            exit()
print("-1 -1 -1")
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
count = 0
for i in range(1, N+1):
    if a <= sum(map(int, str(i))) <= b:
        count += 1
print(count)


Fixed submission:
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N, A, B = LI()
ans = 0
for i in range(1, int(N)+1):
    si = str(i)
    sum = 0
    for sii in si:
        sum += int(sii)
    if A <= sum <= B:
        ans += i
print(ans)
Buggy python submission (verdict: Runtime Error):
def f(i,li,dp,visited):
    if(visited[i]==1):
        return dp[i]
    if(i>=len(li)):
        return 0
    if(i==len(li)-1):
        return 0
    if(i==len(li)-2):
        visited[i]=1
        dp[i]=abs(li[i]-li[i+1])
        return dp[i]
    else:
        dp[i]=min(f(i+1,li,dp,visited)+abs(li[i+1]-li[i]),f(i+2,li,dp,visited)+abs(li[i+2]-li[i]))
        visited[i]=1
        return dp[i]

n=int(input())
l=input().split()
li=[int(i) for i in l]
dp=[0 for i in range(n)]
visited=list(dp)
print(f(0,li,dp,visited))


Fixed submission:
n=int(input())
l=input().split()
li=[int(i) for i in l]
dp=[0 for i in range(n)]
dp[0]=0
for i in range(1,n):
	if(i==1):
		dp[i]=dp[i-1]+abs(li[i]-li[i-1])
	else:
		dp[i]=min(dp[i-1]+abs(li[i]-li[i-1]),dp[i-2]+abs(li[i]-li[i-2]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
l=input().split()
n=int(l[0])
W=int(l[1])
lweight=[]
lvalue=[]
for i in range(n):
	l=input().split()
	u=int(l[0])
	v=int(l[1])
	lweight.append(u)
	lvalue.append(v)
dp=[[0 for i in range(W+1)] for i in range(n+1)]
for i in range(n+1):
	dp[i][0]=0
for j in range(W+1):
	dp[0][j]=0
for i in range(1,n+1):
	for j in range(1,W+1):
		if(j>=lweight[i-1]):
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-lweight[i-1]]+lvalue[i-1])
		else:
			dp[i][j]=dp[i-1][j]
print(dp[n][W])


Fixed submission:
#dp[i][j] denotes min weight if possible to obtain value j from first i items
l=input().split()
n=int(l[0])
W=int(l[1])
lweight=[]
lvalue=[]
for i in range(n):
	l=input().split()
	u=int(l[0])
	v=int(l[1])
	lweight.append(u)
	lvalue.append(v)
k=sum(lvalue)
dp=[[-1 for i in range(k+1)] for i in range(n+1)]
for i in range(n+1):
	dp[i][0]=0
for i in range(1,n+1):
	for j in range(1,k+1):
		if(dp[i-1][j]>-1):
			dp[i][j]=dp[i-1][j]
			if(j>=lvalue[i-1] and dp[i-1][j-lvalue[i-1]]!=-1):
				dp[i][j]=min(dp[i][j],dp[i-1][j-lvalue[i-1]]+lweight[i-1])
		elif(j>=lvalue[i-1] and dp[i-1][j-lvalue[i-1]]!=-1):
			dp[i][j]=dp[i-1][j-lvalue[i-1]]+lweight[i-1]
		else:
			dp[i][j]=-1
maxa=0
for i in range(n+1):
	for j in range(k+1):
		if(dp[i][j]!=-1 and dp[i][j]<=W):
			if(j>maxa):
				maxa=j
print(maxa)
Buggy python submission (verdict: Runtime Error):
def f(x):
	global hashi
	if(x in hashi):
		return hashi[x]
	if(adj[x]==[]):
		return 0
	mino=0
	for i in adj[x]:
		mino=max(mino,f(i))
	hashi[x]=mino+1
	return mino+1
l=input().split()
n=int(l[0])
m=int(l[1])
adj=[[] for i in range(n+1)]
for i in range(m):
	l=input().split()
	u=int(l[0])
	v=int(l[1])
	adj[u].append(v)
maxa=0
hashi=dict()
for i in range(1,n+1):
	maxa=max(maxa,f(i))
print(maxa)


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
def f(x):
	global hashi
	if(x in hashi):
		return hashi[x]
	if(adj[x]==[]):
		return 0
	mino=0
	for i in adj[x]:
		mino=max(mino,f(i))
	hashi[x]=mino+1
	return mino+1
l=input().split()
n=int(l[0])
m=int(l[1])
adj=[[] for i in range(n+1)]
for i in range(m):
	l=input().split()
	u=int(l[0])
	v=int(l[1])
	adj[u].append(v)
maxa=0
hashi=dict()
for i in range(1,n+1):
	maxa=max(maxa,f(i))
print(maxa)
Buggy python submission (verdict: Time Limit Exceeded):
#dp[i]denotes who will win if i stones left
import sys
sys.setrecursionlimit(10**6)
def f(i):
	global xi
	if(i<m):
		return 2
	if(i in xi):
		return xi[i]
	done=0
	for j in hashi:
		if(j<=i):
			if(f(i-j)==2):
				xi[i]=1
				done=1
				return 1
	if(done==0):
		xi[i]=2
	return 2
l=input().split()
n=int(l[0])
k=int(l[1])
l=input().split()
li=[int(i) for i in l]
hashi=dict()
for i in li:
	hashi[i]=1
m=min(li)
xi=dict()
if(f(k)==1):
	print("First")
else:
	print("Second")

Fixed submission:
#dp[i]denotes who will win if i stones left
l=input().split()
n=int(l[0])
k=int(l[1])
l=input().split()
li=[int(i) for i in l]
hashi=dict()
for i in li:
	hashi[i]=1
m=min(li)
dp=[0 for i in range(k+1)]
dp[0]=2
for i in range(1,k+1):
	if(i<m):
		dp[i]=2
	done=0
	for j in hashi:
		if(i>=j and dp[i-j]==2):
			done=1
			break
	dp[i]=2-done
if(dp[k]==1):
	print("First")
else:
	print("Second")
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):
  for j in range(i+1,n):
    ans += (a[i]%mod)*(a[j]%mod)
    ans %= mod
print(ans)

Fixed submission:
n = int(input())
mod = 10**9+7
f = lambda x: int(x)%mod
a = list(map(f,input().split()))
kei = sum(a[1:])%mod
ans = 0
for i in range(n-1):
  ans += a[i]*(kei)
  ans %= mod
  kei -= a[i+1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
frnd = [set([i]) for i in range(n+1)]
mx = 1
for _ in range(m):
  f1,f2 = map(int, input().split())
  if f2 in frnd[f1]: continue
  frnd[f1] |= frnd[f2]
  frnd[f2] |= frnd[f1]
  mx = max(mx,len(frnd[f1]))
  for i in frnd[f1]-set([f1,f2]):
    frnd[i] |= frnd[f1]
print(mx)

Fixed submission:
n,m = map(int, input().split())
par = [0]*(n+1)
group = [1]*(n+1)
for i in range(1,n+1): par[i]=i
def root(x):
  if par[x]==x: return x
  return root(par[x])

def union(x,y):
  rx = root(x)
  ry = root(y)
  if rx==ry: return
  par[max(rx,ry)] = min(rx,ry)
  group[min(rx,ry)] += group[max(rx,ry)]

for _ in range(m):
  f1,f2 = map(int, input().split())
  union(f1,f2)
print(max(group))
Buggy python submission (verdict: Time Limit Exceeded):
x,k,d = map(int, input().split())
if abs(x)>=k*d:
  if x>=0:
    x -= k*d
    print(abs(x))
    exit()
  else:
    x += k*d
    print(abs(x))
    exit()
for i in range(k):
  if x>=0:
    x -= d
    if x<=0:
      if (k-i-1)%2==1:
        x += d
      break
  else:
    x += d
    if x>=0:
      if (k-i-1)%2==1:
        x -= d
      break
print(abs(x))

Fixed submission:
x,k,d = map(int, input().split())
m = abs(x)//d
if m>=k:
  print(abs(x)-k*d)
else:
  k -= m
  if x>=0:
    x -= m*d
  else:
    x += m*d
  
  if x>=0:
    x -= d
    if x<=0:
      if (k-1)%2==1:
        x += d
  else:
    x += d
    if x>=0:
      if (k-1)%2==1:
        x -= d
  print(abs(x))

Buggy python submission (verdict: Time Limit Exceeded):
x,k,d = map(int, input().split())
for i in range(k):
  if x>=0:
    x -= d
    if x<=0:
      if (k-i-1)%2==1:
        x += d
      break
  else:
    x += d
    if x>=0:
      if (k-i-1)%2==1:
        x -= d
      break
print(abs(x))

Fixed submission:
x,k,d = map(int, input().split())
m = abs(x)//d
if m>=k:
  print(abs(x)-k*d)
else:
  k -= m
  if x>=0:
    x -= m*d
  else:
    x += m*d
  
  if x>=0:
    x -= d
    if x<=0:
      if (k-1)%2==1:
        x += d
  else:
    x += d
    if x>=0:
      if (k-1)%2==1:
        x -= d
  print(abs(x))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = [0 if x=='W' else 1 for x in input() ]
cnt = 0
while (0 in c) and (1 in c[c.index(0):]):
  c[-(c[::-1].index(1)+1)] = 0
  c[c.index(0)] = 1
  cnt += 1
print(cnt)

Fixed submission:
n = int(input())
c = input()
print(c[:c.count('R')].count('W'))

Buggy python submission (verdict: Runtime Error):
n = int(input())
c = [0 if x=='W' else 1 for x in input() ]
cnt = 0
while 1 in c[c.index(0):]:
  c[-(c[::-1].index(1)+1)] = 0
  c[c.index(0)] = 1
  cnt += 1
print(cnt)

Fixed submission:
n = int(input())
c = input()
print(c[:c.count('R')].count('W'))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = input()
cnt = 0

while c.count('WR')>=1:
  w = c.index('W')
  r = c[::-1].index('RW')+1
  r *= -1
  cl = list(c)
  cl[w] = 'R'
  cl[r] = 'W'
  c = ''.join(cl)
  cnt += 1

wr = min(c.count('W'),c.count('R'))
cnt = min(cnt,wr)
print(cnt)

Fixed submission:
n = int(input())
c = input()
print(c[:c.count('R')].count('W'))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = input()
cnt = 0
if c.count('WR')==0:
  print(0)
else:
  while c.count('WR')>1:
    pre = -1
    post = -1
    for i,j in enumerate(c):
      if i==len(c)-1:
        continue
      if j=='W' and c[i+1]=='R':
        if pre==-1:
          pre = i
        elif post==-1:
          post = i+1
        else:
          c = c[:pre]+'R'+c[pre+2:post]+'W'+c[post+1:]
          cnt += 1
          break
  for i in c[::-1]:
    if i=='R':
      cnt += 1
    else:
      break
  print(cnt)

Fixed submission:
n = int(input())
c = input()
print(c[:c.count('R')].count('W'))
Buggy python submission (verdict: Runtime Error):
n = int(input())
cnt = [0]*(n+1)

for i in range(1,int(n**0.5)+1):
  for j in range(1,int(n**0.5)+1):
    for k in range(1,int(n**0.5)+1):
      v = (i**2)+(j**2)+(k**2)+i*j+j*k+k*i
      if v<=n:
        cnt[v] += 1
for i in range(1,n+1):
  print(cnt[i])

Fixed submission:
l,r,n = map(int, input().split())
L = l//n if l%n!=0 else (l//n)-1
R = r//n
print(R-L)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = {i for i in range(1,int((n/6)**0.5)+1)}
y = []
z = []
for i in range(1,n):
  if (i**2)+2*i > n-3:
    break
  else:
    y.append(i)
    z.append(i)
one = set()
three = set()
six = set()
for xi in x:
  for yi in y:
    for zi in z:
      k = ((xi+yi+zi)**2 +(xi**2)+(yi**2)+(zi**2))//2
      if xi==yi==zi:
        one.add(k)
      elif xi==yi or yi==zi or zi==xi:
        three.add(k)
      else:
        six.add(k)
for i in range(1,n+1):
  if i in set(one):
    print(1)
  elif i in set(three):
    print(3)
  elif i in set(six):
    print(6)
  else:
    print(0)

Fixed submission:
n = int(input())
cnt = [0]*(10**4+50)

for i in range(1,105):
  for j in range(1,105):
    for k in range(1,105):
      v = (i**2)+(j**2)+(k**2)+i*j+j*k+k*i
      if v<10**4+50:
        cnt[v] += 1
for i in range(1,n+1):
  print(cnt[i])
Buggy python submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
A = [int(p) for p in input().split()]
B = [int(p) for p in input().split()]
a,b = [0],[0]

a_apnd = a.append
b_apnd = b.append
for i in range(n):
  a_apnd(a[i]+A[i])
for i in range(m):
  b_apnd(b[i]+B[i])

count = 0
t = m
for i in range(n+1):
  if k<a[i]:
    break
  while b[t] > k-a[i]:
    t -= 1
  count = max(count,i+t)

print(count)


Fixed submission:
a = int(input())
print(a+(a**2)+(a**3))

Buggy python submission (verdict: Runtime Error):
a = input()
print(a+(a**2)+(a**3))

Fixed submission:
a = int(input())
print(a+(a**2)+(a**3))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def g(n):
  return ((n**2)+n)//2

goukei = 0
for i in range(1,N+1):
  goukei += (i*g(N//i))
print(goukei)

Fixed submission:
N = int(input())

def g(n):
  return ((n**2)+n)//2

goukei = 0
half = N//2
for i in range(1,half+1):
  goukei += i*g(N//i)

add = list(range(half+1,N+1))
goukei += sum(add)
print(goukei)

Buggy python submission (verdict: Time Limit Exceeded):
def div_count(n):
  count = 0
  for v in range(1,n+1):
    if n%v == 0:
    	count += 1
  return count
N = int(input())
sum = 0
for i in range(1,N+1):
  sum += i*div_count(i)

print(sum)

Fixed submission:
N = int(input())

def g(n):
  return ((n**2)+n)//2

goukei = 0
half = N//2
for i in range(1,half+1):
  goukei += i*g(N//i)

add = list(range(half+1,N+1))
goukei += sum(add)
print(goukei)