Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
D=list(map(int,input().split()))
D.sort()
mi=D[0]
ma=D[N-1]
point=0
for j in range(mi,ma+1): #Kはj
    i=0
    while D[i]<j and i<N-1:
        i+=1
    if i==N//2 :
        point+=1
print(point)

Fixed submission:
N=int(input())
D=list(map(int,input().split()))
D.sort()
mi=D[0]
ma=D[N-1]
point=0
for j in range(mi,ma+1): #Kはj
    if D[N//2-1]<j<=D[N//2]:
        point+=1
print(point)

Buggy python submission (verdict: Runtime Error):
N=int(input())
D=list(map(int,input().split()))
D.sort()
mi=D[0]
ma=D[N-1]
point=0
for j in range(mi,ma+1): #Kはj
  i,s=0
  while D[i]<j and s<N//2:
    i+=1
    s+=1
  if s==N//2:
    point+=1
print(point)
    
  


Fixed submission:
N=int(input())
D=list(map(int,input().split()))
D.sort()
mi=D[0]
ma=D[N-1]
point=0
for j in range(mi,ma+1): #Kはj
    if D[N//2-1]<j<=D[N//2]:
        point+=1
print(point)

Buggy python submission (verdict: Runtime Error):
N=int(input())
D=list(map(int,input().split()))
D.sort()
mi=D[0]
ma=D[N-1]
point=0
for j in range(mi,ma+1): #Kはj
  i=0
  while a[i]<j and i+1<N//2+1:
    i+=1
  if i==N//2:
    point+=1
print(point)
    
  

Fixed submission:
N=int(input())
D=list(map(int,input().split()))
D.sort()
mi=D[0]
ma=D[N-1]
point=0
for j in range(mi,ma+1): #Kはj
    if D[N//2-1]<j<=D[N//2]:
        point+=1
print(point)
Buggy python submission (verdict: Runtime Error):
W,H,x,y=map(int,input().split())
if x==W/2 and y==H/2:
  print(float(W*H/2),1)
elif x==W/2 and (not y==H/2):
  print(float(W*H/2),0)
elif (not x==W/2) and y==H/2:
  print(float(W*H/2),0)
else:
  if H/W==y/x or W/H==-(y/x):
    print(float(W*H/2),0)
  else:
    print(float(W*H/2),0)
    
 


Fixed submission:
W,H,x,y=map(int,input().split())
if x==W/2 and y==H/2:
  print(float(W*H/2),1)
else:
  print(float(W*H/2),0)

Buggy python submission (verdict: Runtime Error):
W,H,x,y=map(int,input().split())
if x==W/2 and y==H/2:
  print(float(W*H/2),1)
elif x==W/2 and (not y==H/2):
  print(float(W*H/2),0)
elif (not x==W/2) and y==H/2:
  print(float(W*H/2),0)
else:
  if H/W==y/x or W/H==-(y/x):
    print(float(W*H/2),0)
  else:
    print(float(W*H/2),0)
    
 

Fixed submission:
W,H,x,y=map(int,input().split())
if x==W/2 and y==H/2:
  print(float(W*H/2),1)
else:
  print(float(W*H/2),0)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(min(a+b,b+c,c+a)

Fixed submission:
a,b,c=map(int,input().split())
print(min(a+b,b+c,c+a))
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
import math
s=0
if N-K>=0:
  N-=(N-K+1)
for j in range(1,N+1):
  if (K/j)%2==0:
    s+=math.log(K//j,2)
  else:
    s+=int(math.log(K/j),2)+1
print(float(N/(s+N)))
    


Fixed submission:
N,K=map(int,input().split())
S=input()
s=""
for j in range(N):
  if j==K-1:
    s+=str.lower(S[K-1])
  else:
    s+=S[j]
print(s)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
import math
s=N
q=0 #qは０点になる場合の数
if N>=K:
  for i in range(K):
    if (K//i)%2!=0:
      q+=int(math.log(K//i,2))+1
    else:
      q+=int(math.log(K//i,2))
else:
  for i in range(N+1):
    if (K//i)%2!=0:
      q+=int(math.log(K//i,2))+1
    else:
      q+=int(math.log(K//i,2))
print(s/(s+q))
    
  
  

Fixed submission:
N,K=map(int,input().split())
i=0
q=0 #確率
for j in range(1,N+1):
  while j*(2**i)<K:
    i+=1
  q+=(1/N)*((1/2)**i)
  i=0
print(q)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
import math
s=0
if N-K>=0:
  N-=(N-K+1)
for j in range(1,N+1):
  if (K/j)%2==0:
    s+=math.log2(K//j)
  else:
    s+=int(math.log2(K/j))+1
print(float(N/(s+N)))
    


Fixed submission:
N,K=map(int,input().split())
i=0
q=0 #確率
for j in range(1,N+1):
  while j*(2**i)<K:
    i+=1
  q+=(1/N)*((1/2)**i)
  i=0
print(q)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
import math
s=0
for j in range(1,N+1):
  if (K/j)%2==0:
    s+=math.log2(K//j)
  else:
    s+=int(math.log2(K/j))+1
print(float(N/(s+N)))
    


Fixed submission:
N,K=map(int,input().split())
i=0
q=0 #確率
for j in range(1,N+1):
  while j*(2**i)<K:
    i+=1
  q+=(1/N)*((1/2)**i)
  i=0
print(q)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
import math
s=0
for j in range(1,N+1):
  if (K/j)%2==0:
    s+=log2(K//j)
  else:
    s+=int(log2(K/j))+1
print(float(N/(s+N)))
    

Fixed submission:
N,K=map(int,input().split())
i=0
q=0 #確率
for j in range(1,N+1):
  while j*(2**i)<K:
    i+=1
  q+=(1/N)*((1/2)**i)
  i=0
print(q)
Buggy python submission (verdict: Runtime Error):
N=int(input())
s=''
point=0
q1,q2,q3=0,0,0 #q1はBA q2はBの最初のみ q3はAの末尾のみ
for j in range(N):
    n=str(input())
    point+=n.count("AB")
    if n[0]=="B" and n[len(n)-1]=="A":
      q1+=1  
    elif n[0]=="B":
      q2+=1
    elif n[len(n)-1]=="A":
      q3+=1
    else:
      pass
if q1>=1:
  if q2==0 and q3==0:
    print(q1-1+point)
  elif q2==0 or q3==0
    print(q1-1+1+point)
  else:
    print(q1-1+point+2+min(q2-1,q3-1))
else:
  print(min(q2,q3)+point)

Fixed submission:
N=int(input())
s=''
point=0
q1,q2,q3=0,0,0 #q1はBA q2はBの最初のみ q3はAの末尾のみ
for j in range(N):
    n=str(input())
    point+=n.count("AB")
    if n[0]=="B" and n[len(n)-1]=="A":
      q1+=1  
    elif n[0]=="B":
      q2+=1
    elif n[len(n)-1]=="A":
      q3+=1
    else:
      pass
if q1>=1:
  if q2==0 and q3==0:
    print(q1-1+point)
  elif q2==0 or q3==0:
    print(q1-1+1+point)
  else:
    print(q1-1+point+2+min(q2-1,q3-1))
else:
  print(min(q2,q3)+point)

Buggy python submission (verdict: Runtime Error):
N=int(input())
s=''
point=0
q1,q2,q3=0,0,0 #q1はBA q2はAの末尾のみ q3はBの最初のみ
for j in range(N):
    n=str(input())
    point+=n.count("AB")
    if n[0]=="B" and n[len(n)-1]=="A":
      q1+=1  
    elif n[0]=="B":
      q2+=1
    elif n[len(n)-1]=="A":
      q3+=1
    else:
      pass
A-=1
B-=1
print(q1-1+2+min(q3,q2)+point)

    


Fixed submission:
N=int(input())
s=''
point=0
q1,q2,q3=0,0,0 #q1はBA q2はBの最初のみ q3はAの末尾のみ
for j in range(N):
    n=str(input())
    point+=n.count("AB")
    if n[0]=="B" and n[len(n)-1]=="A":
      q1+=1  
    elif n[0]=="B":
      q2+=1
    elif n[len(n)-1]=="A":
      q3+=1
    else:
      pass
if q1>=1:
  if q2==0 and q3==0:
    print(q1-1+point)
  elif q2==0 or q3==0:
    print(q1-1+1+point)
  else:
    print(q1-1+point+2+min(q2-1,q3-1))
else:
  print(min(q2,q3)+point)
Buggy python submission (verdict: Runtime Error):
N,M,X=map(int,input().split())
A+=list(input())
s=0
z=0
for j in range(M):
  if A[j]>X:
    s+=1
  elif A[j]<X:
    z+=1
print(min(s,z))



Fixed submission:
N,M,X=map(int,input().split())
A=[]
A+=list(map(int,input().split()))
s=0
z=0
for j in range(M):
    if A[j]>X:
        s+=1
    elif A[j]<X:
        z+=1
print(min(s,z))

Buggy python submission (verdict: Runtime Error):
N,M,X=map(int,input().split())
A+=list(input())
s=0
z=0
for j in range(M):
  if A[j]>X:
    s+=1
  elif A[j]<X:
    z+=1
print(min(s,z))



Fixed submission:
N,M,X=map(int,input().split())
A=[]
A+=list(map(int,input().split()))
s=0
z=0
for j in range(M):
    if A[j]>X:
        s+=1
    elif A[j]<X:
        z+=1
print(min(s,z))
Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
s=int(str(a)+str(b))
if s%(int(math.sqrt(s)))==0
  print("Yes")
else:
  print("No")


Fixed submission:
import math
a,b=map(int,input().split())
s=int(str(a)+str(b))
if s%(math.sqrt(s))==0:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
s=int(str(a)+str(b))
if s%int(math.sqrt(s))==0
  print("Yes")
else:
  print("No")


Fixed submission:
import math
a,b=map(int,input().split())
s=int(str(a)+str(b))
if s%(math.sqrt(s))==0:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
s=int(str(a)+str(b))
if s%(math.sqrt(s))==0
  print("Yes")
else:
  print("No")


Fixed submission:
import math
a,b=map(int,input().split())
s=int(str(a)+str(b))
if s%(math.sqrt(s))==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort()
removal=0
B=set(A)
for i in B:
  if A.count(i)-i<0:
    removal+=A.count(i)
  else:
    removal+=A.count(i)-i
print(removal)
  


Fixed submission:
import bisect
N=int(input())
A=list(map(int,input().split()))
A.sort()
removal=0
B=set(A)
for i in B:
  m=(bisect.bisect_right(A,i)-bisect.bisect_left(A,i))
  if m-i<0:
    removal+=m
  else:
    removal+=m-i
print(removal)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
removal=0
B=set(A)
for i in B:
  if A.count(i)-i<0:
    removal+=A.count(i)
  else:
    removal+=A.count(i)-i
print(removal)
  

Fixed submission:
import bisect
N=int(input())
A=list(map(int,input().split()))
A.sort()
removal=0
B=set(A)
for i in B:
  m=(bisect.bisect_right(A,i)-bisect.bisect_left(A,i))
  if m-i<0:
    removal+=m
  else:
    removal+=m-i
print(removal)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

def Ryuka(n):
  if n==0:
    return 2
  elif n==1:
    return 1
  else:
    return Ryuka(n-1)+Ryuka(n-2)
print(Ryuka(N))

Fixed submission:
N=int(input())
a=[]
for j in range(N+1):
  if j==0:
    a.append(2)
  elif j==1:
    a.append(1)
  else:
    a.append(a[j-1]+a[j-2])
print(a[N])
Buggy python submission (verdict: Runtime Error):
N=str(input())
a=int(N[0])
b=int(N[1])
c=int(N[2])
d=int(N[3])
for i in range(2):
  for j in range(2):
    for k in range(2):
      t=a
      if i==0:
        t+=b
      else:
        t-=b
        
      if j==0:
        t+=c
      else:
        t-=c
        
      if k==0:
        t+=d
      else:
        t-=d
        
      if t==7:
        print(f"{a}{"+-"[i]}{b}{"+-"[j]}{c}{"+-"[k]}{d}=7")
  
        
  

Fixed submission:
N=str(input())
a=int(N[0])
b=int(N[1])
c=int(N[2])
d=int(N[3])
for i in range(2):
  for j in range(2):
    for k in range(2):
      t=a
      if i==0:
        t+=b
      else:
        t-=b
        
      if j==0:
        t+=c
      else:
        t-=c
        
      if k==0:
        t+=d
      else:
        t-=d
        
      if t==7:
        print("{}{}{}{}{}{}{}=7".format(a,"+-"[i],b,"+-"[j],c,"+-"[k],d))
        exit()
Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
m=int(len(str(N)))
for j in range(2,math.int(sqrt(N))+1):
  a=j
  b=N//j
  m1=len(str(max(a,b)))
  m=min(m,m1)
print(m)

Fixed submission:
import math
N=int(input())
m=int(len(str(N)))
for j in range(1,int(math.sqrt(N))+2):
    if N%j==0:
        a=j
        b=N//j
        m1=len(str(max(a,b)))
        m=min(m,m1)
print(m)
Buggy python submission (verdict: Runtime Error):
X=int(input())
i=1
sum1=1
while sum<X:
  i+=1
  sum1=sum1+i
print(i)


Fixed submission:
X=int(input())
i=1
sum1=1
while sum1<X:
  i+=1
  sum1=sum1+i
print(i)

Buggy python submission (verdict: Runtime Error):
X=int(input())
import numpy as np
dp=np.array([0]*X)
i=0
while X not in dp:
  i+=1
  dp+=np(dp+np.array(X*[i]))
print(i)

Fixed submission:
X=int(input())
i=1
sum1=1
while sum1<X:
  i+=1
  sum1=sum1+i
print(i)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
m=set(A)
if m%2==0:
  print(m-1)
else:
  print(m)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
m=len(set(A))
if m%2==0:
  print(m-1)
else:
  print(m)
Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())
point=0
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      if i+j+k==S:
        point+=1
print(point)

Fixed submission:
K,S=map(int,input().split())
point=0
for i in range(K+1):
  for j in range(K+1):
    if 0<=S-i-j<=K:
      point+=1
print(point)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
m=10**9+7
if N%2==0:
  if A.count(0)!=0:
    print(0)
    exit()
  for j in range(1,N//2+1):
    if A.count(2*j-1)!=2:
      print(0)
      exit()
else:
  if A.count(0)!=1:
    print(0)
    exit()
  for i in range(1,N//2+1):
    if A.count(2*i)!=2:
      print(0)
      exit()
print((2**(N//2))%m)


Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for j in A:
  B[j]+=1
m=10**9+7
if N%2==0:
  if B[0]!=0:
    print(0)
    exit()
  for j in range(1,N//2+1):
    if B[2*j-1]!=2:
      print(0)
      exit()
else:
  if B[0]!=1:
    print(0)
    exit()
  for i in range(1,N//2+1):
    if B[2*i]!=2:
      print(0)
      exit()
print((2**(N//2))%m)
Buggy python submission (verdict: Runtime Error):
N=int(input())
L=list(map(int,input().split()))
L.sort()
s=0
for i in range(N):
  s+=min(L[2i],L[2i+1])
print(s)

Fixed submission:
N=int(input())
L=list(map(int,input().split()))
L.sort()
s=0
for i in range(N):
  s+=L[2*i]
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())

A = 0
while True:
    n = X - A**5
    B = int(A**(1/5))
    if B ** 5 == n:
        print(A, -B)
        break
    B += 1
    if B ** 5 == n:
        print(A, -B)
        break
    A += 1

Fixed submission:
X = int(input())

A = 0
while True:
    n = X - A ** 5
    if n == 0:
        print(A, 0)
    elif n > 0:
        B = int(n ** (1 / 5))
        if B ** 5 == n:
            print(A, -B)
            break
        B += 1
        if B ** 5 == n:
            print(A, -B)
            break
        A += 1
    else:
        B = - int((-n) ** (1 / 5))
        if B ** 5 == n:
            print(A, -B)
            break
        B -= 1
        if B ** 5 == n:
            print(A, -B)
            break
        A += 1
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
p.sort()
q.sort()
r.sort()
red_remain = X
green_remain = Y
ans = 0
flag = False
for i in range(X+Y):
    if flag:
        flag = False
        continue
    if red_remain == 0 or len(p) == 0:
        if green_remain == 0 or len(q) == 0:
            ans += r.pop(-1)
        elif q[-1] < r[-1]:
            ans += r.pop(-1)
        else:
            ans += q.pop(-1)
            green_remain -= 1
    elif green_remain == 0 or len(q) == 0:
        if p[-1] < r[-1]:
            ans += r.pop(-1)
        else:
            ans += p.pop(-1)
            red_remain -= 1
    else:
        if p[-1] < r[-1] and q[-1] < r[-1]:
            ans += r.pop(-1)
        elif p[-1] == q[-1]:
            if i == X+Y-1:
                ans += p[-1]
            else:
                flag = True
                ans += p.pop(-1) + q.pop(-1)
                red_remain -= 1
                green_remain -= 1
        elif p[-1] < q[-1]:
            ans += q.pop(-1)
            green_remain -= 1
        else:
            ans += p.pop((-1))
            red_remain -= 1
print(ans)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
p.sort()
q.sort()
r.sort()
red_remain = X
green_remain = Y
ans = 0
flag = False
for i in range(X+Y):
    if flag:
        flag = False
        continue
    if red_remain == 0 or len(p) == 0:
        if green_remain == 0 or len(q) == 0:
            ans += r.pop(-1)
        elif len(r) == 0:
            ans += q.pop(-1)
            green_remain -= 1
        elif q[-1] < r[-1]:
            ans += r.pop(-1)
        else:
            ans += q.pop(-1)
            green_remain -= 1
    elif green_remain == 0 or len(q) == 0:
        if len(r) == 0:
            ans += p.pop(-1)
            red_remain -= 1
        elif p[-1] < r[-1]:
            ans += r.pop(-1)
        else:
            ans += p.pop(-1)
            red_remain -= 1
    elif len(r) == 0:
        if p[-1] == q[-1]:
            if i == X+Y-1:
                ans += p[-1]
            else:
                flag = True
                ans += p.pop(-1) + q.pop(-1)
                red_remain -= 1
                green_remain -= 1
        elif p[-1] < q[-1]:
            ans += q.pop(-1)
            green_remain -= 1
        else:
            ans += p.pop((-1))
            red_remain -= 1
    else:
        if p[-1] < r[-1] and q[-1] < r[-1]:
            ans += r.pop(-1)
        elif p[-1] == q[-1]:
            if i == X+Y-1:
                ans += p[-1]
            else:
                flag = True
                ans += p.pop(-1) + q.pop(-1)
                red_remain -= 1
                green_remain -= 1
        elif p[-1] < q[-1]:
            ans += q.pop(-1)
            green_remain -= 1
        else:
            ans += p.pop((-1))
            red_remain -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split())
balls = 0
ans = 0
while balls < N:
    if balls + A <= N:
        balls += A + B
        ans += A
    else:
        ans += N - balls
        balls += A + B
print(ans)

Fixed submission:
N, A, B = map(int, input().split())
k = N // (A + B)
print(A * k + min(A, N - (A + B) * k))
Buggy python submission (verdict: Time Limit Exceeded):
def query1(b):
    return not b

def query2(F, C, string, b):
    if (F == '1' and b) or (F == '2' and not b):
        return C + string
    else:
        return string + C

S = input()
Q = int(input())
r = True

for i in range(Q):
    Query = input().split()
    if len(Query) == 1:
        r = query1(r)
    else:
        S = query2(Query[1], Query[2], S, r)

if r:
    print(S)
else:
    print(S[::-1])

Fixed submission:
start = []
end = []

def query1(b):
    return not b

def query2(F, C, string, b):
    if (F == '1' and b) or (F == '2' and not b):
        start.append(C)
        return C + string
    else:
        end.append(C)

S = input()
Q = int(input())
direction = True

for i in range(Q):
    Query = input().split()
    if len(Query) == 1:
        direction = query1(direction)
    else:
        query2(Query[1], Query[2], S, direction)

if direction:
    print(''.join(start[::-1]) + S + ''.join(end))
else:
    print(''.join(end[::-1]) + S[::-1] + ''.join(start))

Buggy python submission (verdict: Time Limit Exceeded):
def query1(string):
    return string[::-1]

def query2(F, C, string):
    if F == '1':
        return C + string
    elif F == '2':
        return string + C

S = input()
Q = int(input())
for i in range(Q):
    Query = input().split()
    if len(Query) == 1:
        S = query1(S)
    else:
        S = query2(Query[1], Query[2], S)

print(S)

Fixed submission:
start = []
end = []

def query1(b):
    return not b

def query2(F, C, string, b):
    if (F == '1' and b) or (F == '2' and not b):
        start.append(C)
        return C + string
    else:
        end.append(C)

S = input()
Q = int(input())
direction = True

for i in range(Q):
    Query = input().split()
    if len(Query) == 1:
        direction = query1(direction)
    else:
        query2(Query[1], Query[2], S, direction)

if direction:
    print(''.join(start[::-1]) + S + ''.join(end))
else:
    print(''.join(end[::-1]) + S[::-1] + ''.join(start))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))

ans = 1
for i in range(1,N):
    if min(P[:i]) > P[i]:
        ans += 1
print(ans)

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

rec = N
ans = 0

for i in range(N):
    if i == 0:
        rec = P[i]
        ans += 1
    else:
        if rec > P[i]:
            ans += 1
        rec = min(rec, P[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
K,X = map(int,input().split())
if 500*K >= X:
    print('Yes')
else:
    print('No')
K,X = map(int,input().split())
if 500*K >= X:
    print('Yes')
else:
    print('No')

Fixed submission:
K,X = map(int,input().split())
if 500*K >= X:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()

ans = 0

a = -(-N//K)
r = N%K
T2 = T + 'x'*r

li = []
for i in range(K):
    st = ''
    for j in range(a):
        c = T2[j*K + i]
        if st == '':
            st += c
        elif st[0] == c:
            st += c
        else:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S
            st = c
        if j == a-1:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S

print(ans)

Fixed submission:
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()

ans = 0

a = -(-N//K)
r = N%K
T2 = T + 'x'*(K - r)

li = []
for i in range(K):
    st = ''
    for j in range(a):
        c = T2[j*K + i]
        if st == '':
            st += c
        elif st[0] == c:
            st += c
        else:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S
            st = c
        if j == a-1:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = 1000000007
N = int(input())
A = [int(a) for a in input().split()]
li = [0] * 60
for n in range(N):
    for i in range(60):
        li[i] += A[n] >> i & 1
ans = 0
for i in range(60):
    ans += (1 << i) * li[i] * (N - li[i])
    ans %= K
print(ans)

Fixed submission:
K = 1000000007
N = int(input())
A = [int(a) for a in input().split()]
li = [0] * 60
for n in range(N):
    li = [li[i] + (A[n] >> i & 1) for i in range(60)]
ans = 0
for i in range(60):
    ans += (1 << i) * li[i] * (N - li[i])
    ans %= K
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
L = [int(i) for i in input().split()]
c = collections.Counter(L)

ans = 0
for i in c:
    for j in c:
        for k in c:
            if i + j <= k or j + k <= i or k + i <= j or i > j or j > k:
                continue
            if i == j and j == k:
                ans += c[i] * (c[i] - 1) * (c[i] - 2) / 6
            elif i == j:
                ans += c[k] * c[i] * (c[i] - 1) / 2
            elif j == k:
                ans += c[i] * c[j] * (c[j] - 1) / 2
            elif i == k:
                ans += c[j] * c[i] * (c[i] - 1) / 2
            else:
                ans += c[i] * c[j] * c[k]
print(int(ans))


Fixed submission:
import collections

N = int(input())
L = [int(i) for i in input().split()]
M = max(L)
c = collections.Counter(L)
li = [c[i] for i in range(M+1)]

ans = 0
for i in range(1,M+1):
    for j in range(i,M+1):
        if i == j:
            ans += int(li[i] * (li[i] - 1) * (li[i] - 2) / 6)
            ans += int(sum(li[j+1:min(M+1, i+j)]) * li[i] * (li[i] - 1) / 2)
        else:
            ans += int(li[i] * li[j] * (li[j] - 1) / 2)
            ans += li[i] * li[j] * sum(li[j+1:min(M+1, i+j)])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [int(i) for i in input().split()]

ans = 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[i] + L[k] and L[k] < L[i] + L[j]:
                ans += 1
print(ans)

Fixed submission:
import collections

N = int(input())
L = [int(i) for i in input().split()]
M = max(L)
c = collections.Counter(L)
li = [c[i] for i in range(M+1)]

ans = 0
for i in range(1,M+1):
    for j in range(i,M+1):
        if i == j:
            ans += int(li[i] * (li[i] - 1) * (li[i] - 2) / 6)
            ans += int(sum(li[j+1:min(M+1, i+j)]) * li[i] * (li[i] - 1) / 2)
        else:
            ans += int(li[i] * li[j] * (li[j] - 1) / 2)
            ans += li[i] * li[j] * sum(li[j+1:min(M+1, i+j)])
print(int(ans))