Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
x=list(map(int, input().split()))
x.sort(reverse=True)

ans=0
for i in range(n):
	del x[0]
	ans=ans+x[0]
	del x[0]
print(ans)

Fixed submission:
n=int(input())
x=list(map(int, input().split()))
x.sort(reverse=True)

ans=0
for i in range(n):
	ans=ans+x[(i*2)+1]

print(ans)
Buggy python submission (verdict: Runtime Error):
x=int(input()
y=int(input()
z=int(input()
print((x+y)*z/2)

Fixed submission:
x=int(input())
y=int(input())
z=int(input())
print(round((x+y)*z/2))
Buggy python submission (verdict: Time Limit Exceeded):
x=int(input())
input = list(map(int, input().split()))

multi=1
for i in range(len(input)):
  multi *= input[i]
  
if(multi > (10 ** 18)):
  print(-1)
else:
  print(multi)

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

for i in range(len(input)):
  if(input[i]==0):
    print(0)
    exit(0)

multi=1
for i in range(len(input)):    
  multi *= input[i]
  if(multi > (10 ** 18)):
    print(-1)
    exit(0)

print(multi)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=int(input())
if((N%500<=A):
  print("Yes")
else:
  print("No")
  

Fixed submission:
N=int(input())
A=int(input())
if(N%500<=A):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
if(a*b%2==0):
  print("Even")
else:
  print("Odd")

Fixed submission:
a,b=map(int, input().split())
if(a*b%2==0):
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Time Limit Exceeded):
A,B,N= list(map(int,input().split()))

ans = 0
import math
for i in range(N+1):
    cnt = math.floor(A*i/B) - A *math.floor(i/B)
    ans = max(cnt,ans)
print(ans)

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

import math

if B-1 < N:
    print(math.floor(A*(B-1)/B) - A*math.floor((B-1)/B) )
else:
    print(math.floor(A*N/B) - A*math.floor(N/B))
Buggy python submission (verdict: Time Limit Exceeded):
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))

if A[0] != 0:
    B = A + [K] 
else:
    B = A
#print(B)

for i in range(N):
    B.append(A[i] + K)
#print(B)

ans = 10000000
C =[]
for i in range(N):
    cnt = 0
    for j in range(i, i + N - 1):
        cnt +=B[j+1] - B[j]
    ans = min(ans,cnt)

print(ans)

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

a = K + A[0]
A = A + [a]

#print(A)

B = []
for i in range(N):
    B.append(A[i+1] - A[i])
B = sorted(B,reverse = False)

print(sum(B) - max(B))

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

if A[0] != 0:
    B = A + [K] 
else:
    B = A
#print(B)

for i in range(N):
    B.append(A[i] + K)
#print(B)

C =[]
for i in range(N):
    cnt = 0
    for j in range(i, i + N - 1):
        cnt +=B[j+1] -B[j]
    C.append(cnt)

print(min(C))


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

a = K + A[0]
A = A + [a]

#print(A)

B = []
for i in range(N):
    B.append(A[i+1] - A[i])
B = sorted(B,reverse = False)

print(sum(B) - max(B))
Buggy python submission (verdict: Time Limit Exceeded):
L =int(input())

if L == 1:
    print('0.037036926')
elif L==2:
     print('0.296296074')
else:
    ans =0
    for i in range(2000):
        for j in range(2000):
            ans =max(ans, i/2*j/2*(L-(i/2+j/2)))
    print(ans)

Fixed submission:
L =int(input())

if L == 1:
    print('0.037036926')
elif L==2:
     print('0.296296074')
else:
    ans =0
    for i in range(100000):
        ans =max(ans, i/100*i/100*(L-(i/100+i/100)))
    print(ans)

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

if L == 1:
    print('0.037036926')
elif L==2:
     print('0.296296074')
else:
    ans =0
    for i in range(2000):
        for j in range(2000):
            ans =max(ans, i/2*j/2*(L-(i/2+j/2)))
    print(ans

Fixed submission:
L =int(input())

if L == 1:
    print('0.037036926')
elif L==2:
     print('0.296296074')
else:
    ans =0
    for i in range(100000):
        ans =max(ans, i/100*i/100*(L-(i/100+i/100)))
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
L =int(input())

if L == 1:
    print('0.037036926')
elif L==2:
     print('0.296296074')
else:
    ans =0
    for i in range(5000):
        for j in range(5000):
            ans =max(ans, i/5*j/5*(L-(i/5+j/5)))
    print(ans)

Fixed submission:
L =int(input())

if L == 1:
    print('0.037036926')
elif L==2:
     print('0.296296074')
else:
    ans =0
    for i in range(100000):
        ans =max(ans, i/100*i/100*(L-(i/100+i/100)))
    print(ans)
Buggy python submission (verdict: Runtime Error):
import math
​
A, B = list(map(int,input().split()))
​
cnt = 0
for i in range(1,10000):
    X = math.floor(i * 0.08)
    Y = math.floor(i * 0.1)
    if A == X and B == Y:
        print(i)
        cnt += 1
        break
​
if cnt == 0:
    print(-1)


Fixed submission:
import math

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

cnt = 0
for i in range(1,100000):
    X = math.floor(i * 0.08)
    Y = math.floor(i * 0.1)
    if A == X and B == Y:
        print(i)
        cnt += 1
        break
        
if cnt == 0:
    print(-1)
Buggy python submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))
P = list(map(int,input().split()))
A =[]
for i in range(N):
    A.append(P[i]+1)
from itertools import accumulate
A= list(accumulate(A))
#print(A)
B=[]
for i in range(K,N):
    B.append((A[i]-A[i-K])/2)
print(max(B))

Fixed submission:
from itertools import accumulate

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

A = []
for i in P:
    A.append(1/2*(i+1))
    #A.append(1/2*i*(i+1)/i)

ans = 0
'''
for i in range(len(A)):
    ans = max(ans,sum(A[i:i+K]))
'''
    
accum = [0] + list(accumulate(A))
for i in range(len(accum)):
    ans = max(ans,accum[i] - accum[i-K])
print(ans)

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

A = []
ans = 0
for i in range(len(P)):
    if ans < sum(P[i:i+K]):
        ans = sum(P[i:i+K])
        A.append(i)
A1 = sorted(A, reverse = True) 
L = A1[0]                
B = P[L:L+K]

C  = []
for i in B:
    C.append(1/2*(i+1))
print(sum(C))

Fixed submission:
from itertools import accumulate

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

A = []
for i in P:
    A.append(1/2*(i+1))
    #A.append(1/2*i*(i+1)/i)

ans = 0
'''
for i in range(len(A)):
    ans = max(ans,sum(A[i:i+K]))
'''
    
accum = [0] + list(accumulate(A))
for i in range(len(accum)):
    ans = max(ans,accum[i] - accum[i-K])
print(ans)

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

A = []
for i in P:
    A.append(1/2*(i+1))

ans = 0
for i in range(len(A)):
    ans = max(ans,sum(A[i:i+K]))

print(ans)

Fixed submission:
from itertools import accumulate

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

A = []
for i in P:
    A.append(1/2*(i+1))
    #A.append(1/2*i*(i+1)/i)

ans = 0
'''
for i in range(len(A)):
    ans = max(ans,sum(A[i:i+K]))
'''
    
accum = [0] + list(accumulate(A))
for i in range(len(accum)):
    ans = max(ans,accum[i] - accum[i-K])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

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

A = []
for i in P:
    A.append(1/2*i*(i+1)/i)

ans = 0
for i in range(len(A)):
    ans = max(ans,sum(A[i:i+K]))

print(ans)

Fixed submission:
from itertools import accumulate

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

A = []
for i in P:
    A.append(1/2*(i+1))
    #A.append(1/2*i*(i+1)/i)

ans = 0
'''
for i in range(len(A)):
    ans = max(ans,sum(A[i:i+K]))
'''
    
accum = [0] + list(accumulate(A))
for i in range(len(accum)):
    ans = max(ans,accum[i] - accum[i-K])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [sorted(str(input())) for _ in range(N)]

B = []
for i in range(N):
    s = ''.join(S[i])
    B.append(s)

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

Fixed submission:
from collections import Counter

N = int(input())
S = [list((map(str,input().split()))) for _ in range(N)]

A = []
for i in S:
    ew_str = ''.join(sorted(i[-1]))
    A.append(ew_str)

cnt = Counter(A)
cnt = list(cnt.values())
#print(cou)

ans = 0
for i in cnt:
    ans +=i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
S =[]
for i in range(N):
    S.append(sorted(list(Counter(str(input())).items()),reverse = False))
#print(S)

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

Fixed submission:
from collections import Counter

N = int(input())
S = [list((map(str,input().split()))) for _ in range(N)]

A = []
for i in S:
    ew_str = ''.join(sorted(i[-1]))
    A.append(ew_str)

cnt = Counter(A)
cnt = list(cnt.values())
#print(cou)

ans = 0
for i in cnt:
    ans +=i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
S =[]
for i in range(N):
    S.append(str(input()))

B =[]
for i in S:
    S1 =list(Counter(i).items())
    S1 =sorted(S1, reverse = False)
    B.append(S1)
#print(B)

cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        if B[i] == B[j]:
            cnt += 1
print(cnt)

Fixed submission:
from collections import Counter

N = int(input())
S = [list((map(str,input().split()))) for _ in range(N)]

A = []
for i in S:
    ew_str = ''.join(sorted(i[-1]))
    A.append(ew_str)

cnt = Counter(A)
cnt = list(cnt.values())
#print(cou)

ans = 0
for i in cnt:
    ans +=i*(i-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = []
for i in range(N):
    A.append(int(input()))

B = []
for i in range(N):
    B = A[:i] + A[i+1:]
    #print(B)
    print(max(B))

Fixed submission:
N = int(input())

A = []
for i in range(N):
    A.append(int(input()))
    
B = sorted(A,reverse = True)

for i in A:
    if i == B[0]:
        print(B[1])
    else:
        print(B[0])
Buggy python submission (verdict: Runtime Error):
L,R = list(map(int, input().split()))

if R - L> 2019:
    print("0")
else:
    A =[]
    for i in range(L ,R):
            for j in range(L+1,R+1):
                b = i*j % 2019
                A.append(b)
ans = min(A) 
print(ans)

Fixed submission:
L,R = list(map(int, input().split()))

if R - L > 2019:
    print("0")
else:
    A =[]
    for i in range(L ,R):
            for j in range(L+1,R+1):
                b = i*j % 2019
                A.append(b)
    ans = min(A) 
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
L,R = list(map(int, input().split()))

A =[]
for i in range(L ,R):
    for j in range(L+1,R+1):
        #print(i,j)
        b = i*j % 2019
        A.append(b)
ans = min(A) 
print(ans)

Fixed submission:
L,R = list(map(int, input().split()))

if R - L > 2019:
    print("0")
else:
    A =[]
    for i in range(L ,R):
            for j in range(L+1,R+1):
                b = i*j % 2019
                A.append(b)
    ans = min(A) 
    print(ans)
Buggy python submission (verdict: Runtime Error):
mport sys

def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))
    cnt = 1
    D = 0
    for a in A:
        D += a
        if D > X:
            break
        cnt += 1

    return cnt

if __name__ == '__main__':
    print(main())

Fixed submission:
import sys

def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))
    cnt = 1
    D = 0
    for a in A:
        D += a
        if D > X:
            break
        cnt += 1

    return cnt

if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse = False) 

B = [A[0]]
for i in range(N):
    if A[i]%A[0] != 0:
        B.append(A[i]%A[0])
B = set(B)
B = sorted(B,reverse = False) 

#import math
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(B))

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

B = [A[0]]
for i in range(N):
    if A[i]%A[0] != 0:
        B.append(A[i]%A[0])
B = set(B)
#B = sorted(B,reverse = False) 

#import math
import fractions
from functools import reduce

def gcd_list(numbers):
    #return reduce(math.gcd, numbers)
    return reduce(fractions.gcd, numbers)

print(gcd_list(B))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse = False) 

B = [A[0]]
for i in range(N):
    if A[i]%A[0] != 0:
        B.append(A[i]%A[0])
B = set(B)
B = sorted(B,reverse = False) 


import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(B))

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

B = [A[0]]
for i in range(N):
    if A[i]%A[0] != 0:
        B.append(A[i]%A[0])
B = set(B)
#B = sorted(B,reverse = False) 

#import math
import fractions
from functools import reduce

def gcd_list(numbers):
    #return reduce(math.gcd, numbers)
    return reduce(fractions.gcd, numbers)

print(gcd_list(B))
Buggy python submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
X = list(map(int,input().split()))

X = sorted(X)
if N == 1:
    print(abs(X[M-1] -X[0]))
else:
    A=[]
    for i in range(M-1):
        A.append(abs(X[i]-X[i+1]))
print(sum(sorted(A)[:M-N]))

Fixed submission:
N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H,reverse = False) 

if N == 1:
    print(abs(H[M-1] - H[0]))
else:
    A = []
    for i in range(M-1):
        A.append(H[i+1] - H[i])
    A = sorted(A,reverse = False) 
    print(sum(A[:-N+1]))

Buggy python submission (verdict: Runtime Error):
N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H,reverse = False) 

if N == 1:
    print(abs(H[M-1] - H[0]))
else:
    A = []
    for i in range(M-1):
        A.append(H[i+1] - H[i])
        A = sorted(A,reverse = False) 
print(sum(A[:-N+1]))

Fixed submission:
N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H,reverse = False) 

if N == 1:
    print(abs(H[M-1] - H[0]))
else:
    A = []
    for i in range(M-1):
        A.append(H[i+1] - H[i])
    A = sorted(A,reverse = False) 
    print(sum(A[:-N+1]))

Buggy python submission (verdict: Runtime Error):
N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H,reverse = False) 

if N == 1:
    print(max(H)- min(H))
else:
    A = []
    for i in range(M-1):
        A.append(H[i+1] - H[i])
        A = sorted(A,reverse = False) 
print(sum(A[:-N+1]))

Fixed submission:
N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H,reverse = False) 

if N == 1:
    print(abs(H[M-1] - H[0]))
else:
    A = []
    for i in range(M-1):
        A.append(H[i+1] - H[i])
    A = sorted(A,reverse = False) 
    print(sum(A[:-N+1]))
Buggy python submission (verdict: Runtime Error):
from collections import Counter

N, K = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = sorted(H,reverse = False)
C = Counter(H)
CH = list(C.values()) 

cnt = 0
for i in range(len(CH)):
    if CH[i] >= K:
        cnt += 1
        break
if cnt != 0:
    print('0')
else:
    #print(H[K-1] - H[0])
    print(min(H[K-1] - H[0],H[K] - H[1],H[K+1] - H[2]))

Fixed submission:
from collections import Counter

N, K = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = sorted(H,reverse = False)
C = Counter(H)
CH = list(C.values()) 

cnt = 0
for i in range(len(CH)):
    if CH[i] >= K:
        cnt += 1
        break
ans = 999999999999999
for i in range(N-K+1):
    ans = min(ans,H[K-1+i] - H[i]) 

if cnt != 0:
    print('0')
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
N, M, X, Y =list(map(int,input().split()))
a =max( [i for i in map(int, input().split())])                
b =min([i for i in map(int, input().split())])

for z in range(-101,101):
    if (x <= z <= y) and (a < z) and (b >= z):
        cnt +=1
        break

if cnt > 1:
    print('No War')
else:
    print('War')

Fixed submission:
N, M, X, Y =list(map(int,input().split()))
x = [i for i in map(int, input().split())]        
y =[i for i in map(int, input().split())]
x_max =max(x)
y_min =min(y)

# X<Z<=Y を満たす数を列挙
for Z in range(X+1,Y+1):

  # x1, x2, ... , xn < Z <= y1, y2, ... , yn の判定
  if x_max<Z and Z<=y_min:
    print('No War')
    exit()

# 条件を満たすZが存在しない場合
print('War')
Buggy python submission (verdict: Runtime Error):
import fractions
from functools import reduce

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

B = []
for i in range(N):
    B.append(abs(X- A[i]))

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(min(min(B),gcd_list(B)))

Fixed submission:
#import math
import fractions
from functools import reduce

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

B = []
for i in range(N):
    B.append(abs(X- A[i]))

#最大公約数    
def gcd_list(numbers):
    #return reduce(math.gcd, numbers)
    return reduce(fractions.gcd, numbers)

print(gcd_list(B))

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

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

B = []
for i in range(N):
    B.append(abs(X- A[i]))

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(max(min(B),gcd_list(B)))

Fixed submission:
#import math
import fractions
from functools import reduce

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

B = []
for i in range(N):
    B.append(abs(X- A[i]))

#最大公約数    
def gcd_list(numbers):
    #return reduce(math.gcd, numbers)
    return reduce(fractions.gcd, numbers)

print(gcd_list(B))

Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
A = list(map(int,input().split()))
​
B = []
for i in range(N):
    B.append(abs(X- A[i]))
print(min(B))

Fixed submission:
#import math
import fractions
from functools import reduce

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

B = []
for i in range(N):
    B.append(abs(X- A[i]))

#最大公約数    
def gcd_list(numbers):
    #return reduce(math.gcd, numbers)
    return reduce(fractions.gcd, numbers)

print(gcd_list(B))
Buggy python submission (verdict: Runtime Error):
S = list(input())
K = int(input())

for i in range(K):
    if S[i] != '1':
        ans = s
        break
    else:
        ans = 1
        continue
print(ans)

Fixed submission:
S = list(input())
K = int(input())

for i in range(K):
    if S[i] != '1':
        ans = S[i]
        break
    else:
        ans = 1
        continue
print(ans)

Buggy python submission (verdict: Runtime Error):
S = list(input())
K = int(input())

for s in S:
    if s != '1':
        ans = s
        break
    else:
        continue
print(ans)

Fixed submission:
S = list(input())
K = int(input())

for i in range(K):
    if S[i] != '1':
        ans = S[i]
        break
    else:
        ans = 1
        continue
print(ans)
Buggy python submission (verdict: Runtime Error):
S =input()
T = input()

s = list(S)
ans = 0

if B.lower() == T.lower():
        ans +=1

for _ in  range(len(s)-1):
    A=s[-1]
    s.pop(-1)
    s.insert(0,A)
    print(s)
    B=''.join(s)
    if B.lower() == T.lower():
        ans +=1
if ans != 0:
    print('Yes')
else:
    print('No')

Fixed submission:
S =input()
T = input()

s = list(S)
ans = 0

if S.lower() == T.lower():
        ans +=1

for _ in  range(len(s)-1):
    A=s[-1]
    s.pop(-1)
    s.insert(0,A)
    #print(s)
    B=''.join(s)
    if B.lower() == T.lower():
        ans +=1
if ans != 0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
D, N = list(map(int , input().split()))

if D == 0:
    ans = N
elif D == 1:
    ans ==100 * N
elif D == 2:
    ans ==10000 * N

print(ans)

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

n = []
for i in range(1,1001):
    if D == 0:
        if i % 100 !=0:
            n.append(i)
        continue
    elif D == 1:
        if i % 100 !=0:
            n.append(100*i)
        continue      
    elif D == 2:
        if i % 100 !=0:
            n.append(10000*i)
        continue
print(n[N-1])

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

n = []
for i in range(1,100):
    if D == 0:
        n.append(i)
    elif D == 1:
        n.append(100*i)
    elif D == 2:
        n.append(1000*i)
#print(n)

print(n[N-1])

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

n = []
for i in range(1,1001):
    if D == 0:
        if i % 100 !=0:
            n.append(i)
        continue
    elif D == 1:
        if i % 100 !=0:
            n.append(100*i)
        continue      
    elif D == 2:
        if i % 100 !=0:
            n.append(10000*i)
        continue
print(n[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 100000000

for i in range(N):
    A = S[0:i]
    B = S[i+1:]
    X = A.count('W')
    Y = B.count('E')
    ans = min(X + Y,ans)
print(ans)

Fixed submission:
n = int(input())
s = input()
e = s.count("E")
w = s.count("W")
cnt1 = 0
cnt2 = 0
ans = 10e9
for i in s:
    if i=="E":
        cnt1 += 1
        ans = min(ans,cnt2+e-cnt1)
    else:
        ans = min(ans,cnt2+e-cnt1)
        cnt2 += 1
print(ans)

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

ans = 100000000

for i in range(N):
    A = S[0:i]
    B = S[i+1:]
    if S[i] == 'E':
        #向く方向を変える必要がある人数
        X = A.count('W')
        Y = B.count('E')
        ans = min(X + Y,ans)
    if S[i] == 'W':
        #向く方向を変える必要がある人数
        X = A.count('W')
        Y = B.count('E')
        ans = min(X + Y,ans)
print(ans)

Fixed submission:
n = int(input())
s = input()
e = s.count("E")
w = s.count("W")
cnt1 = 0
cnt2 = 0
ans = 10e9
for i in s:
    if i=="E":
        cnt1 += 1
        ans = min(ans,cnt2+e-cnt1)
    else:
        ans = min(ans,cnt2+e-cnt1)
        cnt2 += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())

A = []
for i in range(len(S)):
    for j in range(1,len(S)+1):
        if S[i:j] != "":
            if len(S[i:j]) < 6:
                A.append(S[i:j])

A = sorted(set(A))
#A = sorted(set(A), key=A.index)
        
print(A[K-1])

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

A = []
for i in range(len(S)):  
    for j in range(1,i + 6):
        if S[i:j] != "":
            A.append(S[i:j])

A = sorted(set(A))
        
print(A[K-1])

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

A = []
for i in range(len(S)):
    for j in range(1,len(S)+1):
        if S[i:j] != "" and len(S[i:j]) < 6:
            A.append(S[i:j])

A = sorted(set(A))
#A = sorted(set(A), key=A.index)

print(A[K-1])

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

A = []
for i in range(len(S)):  
    for j in range(1,i + 6):
        if S[i:j] != "":
            A.append(S[i:j])

A = sorted(set(A))
        
print(A[K-1])

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

A = []
for i in range(len(S)):
    for j in range(1,len(S)+1):
        if S[i:j] != "":
            A.append(S[i:j])

A = sorted(set(A))
#A = sorted(set(A), key=A.index)

B =[]
for i in A:
    if len(i) < 6:
        B.append(i)
        
print(B[K-1])

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

A = []
for i in range(len(S)):  
    for j in range(1,i + 6):
        if S[i:j] != "":
            A.append(S[i:j])

A = sorted(set(A))
        
print(A[K-1])