TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
n=int(input())
s=input()
k=n
for i in range(n):
    a=s[:i]
    b=s[i+1:]
    l=a.count("W")+b.count("E")
    if l<k:
        k=l
print(k



n=int(input())
s=input()
k=0
l=[]
for i in range(n):
    if s[i]=="W":
        k+=1
    l.append(k)
#print(l)


w=n
for i in range(n):
    if i==0:
        #if s[i]=="W":
        #    v=n-l[n-1]+1
        #else:
        #    v=n-l[n-1]
        
        v=n-1-l[n-1]+l[0]
    else:
        v=l[i-1]+n-1-i-(l[n-1]-l[i])


    if v<w:
        w=v
    if v==0:
        w=0
        break    
print(w)

Verdicts: Runtime Error

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N = int(input())
S = input()
_min = -1
for i in range(N):
    left_str = S[:i]
    right_str = S[i+1:]
    left = count('W', left_str)
    right = count('E', right_str)
    total = left + right
    if _min == -1:
        _min = total
    elif total < _min:
        _min = total
print(_min)
def count(item, str1):
    counter = 0
    for c in str1:
        if c == item:
            counter += 1
    return counter
        

N = int(input())
S = input()
_min = -1
for i in range(N):
    left_str = S[:i]
    right_str = S[i+1:]
    left = count('W', left_str)
    right = count('E', right_str)
    total = left + right
    if _min == -1:
        _min = total
    elif total < _min:
        _min = total
print(_min)
def count(item, str):
    counter = 0
    for c in str:
        if c == item:
            counter += 1
    return counter
        

N = int(input())
S = input()
w_count = 0
e_count = 0
w_counts = [0 for _ in range(N)]
e_counts = [0 for _ in range(N)]
for i in range(N):
    if S[i] == 'W':
        w_count += 1
    w_counts[i] = w_count
for i in range(N-1, -1, -1):
    if S[i] == 'E':
        e_count += 1
    e_counts[i] = e_count
_min = -1
for i in range(N):
    total = w_counts[i] + e_counts[i]
    if _min == -1:
        _min = total
    if _min > total:
        _min = total
print(_min-1)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N = int(input())
S = input()
E = S.count("E")
W = 0
ans = N + 1
for s in S:
    if s == "E":
        E -= 1
    ans = min(W + E, ans)
    if s == "W":
        W -= 1
print(ans)

N = int(input())
S = input()
E = S.count("E")
W = 0
ans = N + 1
for s in S:
    if s == "E":
        E -= 1
    ans = min(W + E, ans)
    if s == "W":
        W += 1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N=int(input())
S=input()
l=0
r=S[1:].count("E")
print(r)
answer=N

for i in range(N-1):
    if l+r<answer:
        answer=l+r
    if S[i]=="W":
        l+=1
    if S[i+1]=="E":
        r-=1
if l+r<answer:
    answer=l+r
print(answer)


N=int(input())
S=input()
l=0
r=S[1:].count("E")
#print(r)
answer=N

for i in range(N-1):
    if l+r<answer:
        answer=l+r
    if S[i]=="W":
        l+=1
    if S[i+1]=="E":
        r-=1
if l+r<answer:
    answer=l+r
print(answer)


Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N = int(input())
S = list(input())
w = [0 for i in range(N)]
e = [0 for i in range(N)]

if S[0] == 'W':
    w[0] = 1

for i in range(1,N-1):
    if S[i] == 'W':
        w[i] = w[i-1] + 1
        e[i+1] = e[i]  
    else:
        w[i] = w[i-1]
        e[i+1] = e[i] - 1

if S[-1] == 'W':
    w[-1] = w[-2] + 1
else:
    w[-1] = w[-2] 

ans = w[0] + e[0]
scale = -e[-1]
for i in range(N):
    w[i] = w[i] + e[i]
    if ans > w[i]:
        ans = w[i]

print(ans + scale)


N = int(input())
S = list(input())
w = [0 for i in range(N)]
e = [0 for i in range(N)]

if S[0] == 'W':
    w[0] = 1

for i in range(1,N-1):
    if S[i] == 'W':
        w[i] = w[i-1] + 1
        e[i+1] = e[i]  
    else:
        w[i] = w[i-1]
        e[i+1] = e[i] - 1

if S[-1] == 'W':
    w[-1] = w[-2] + 1
    scale = -e[-1]
else:
    w[-1] = w[-2]
    scale = -e[-1] +1

ans = w[0] + e[0]
for i in range(N):
    w[i] = w[i] + e[i]
    if ans > w[i]:
        ans = w[i]

print(ans + scale - 1)


Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
def main():
	N = int(input())
	a = input()
    
	W = [0]
	E = [0]
	for i in range(N):
		if a[i] == 'W':
			W[i+1] = W[i] + 1
			E[i+1] = E[i]
		else:
			W[i+1] = W[i]
			E[i+1] = E[i] + 1
	E_max = E[-1]
	n_min = N
	for i in range(N):
		t = W[i] + E_max - E[i+1]
		if t < n_min:
			n_min = t
	print (n_min)
main()

def main():
	N = int(input())
	a = input()
    
	W = [0]*(N+1)
	E = [0]*(N+1)
	for i in range(N):
		if a[i] == 'W':
			W[i+1] = W[i] + 1
			E[i+1] = E[i]
		else:
			W[i+1] = W[i]
			E[i+1] = E[i] + 1
	E_max = E[-1]
	n_min = N
	for i in range(N):
		t = W[i] + E_max - E[i+1]
		if t < n_min:
			n_min = t
	print (n_min)
main()

Verdicts: Runtime Error

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N = int(input())
S = list(input())

CNT = []
c = 0
for s in S:
  if s == "E":
    c += 1
  CNT.append(c)
  
ans = N + 10
mn = N + 10
for i in range(N):
  c = 0
  if i > 0:
    c += i - 1 - CNT[i-1]
  if i < N - 1:
    c +=  N - i - 1 - (CNT[N] - CNT[i+1])
    
  if c < mn:
    ans = i+1

print(ans)
    

  

N = int(input())
S = list(input())

CNT = []
c = 0
for s in S:
  if s == "E":
    c += 1
  CNT.append(c)
  
ans = N + 10
mn = N + 10
for i in range(N):
  c = 0
  if i > 0:
    c += i - 1 - CNT[i-1]
  if i < N - 1:
    c +=  N - i - 1 - (CNT[N-1] - CNT[i+1])
    
  if c < mn:
    ans = i+1

print(ans)
    

  


N = int(input())
S = list(input())

EAST = []
WEST = []
e = 0
w = 0
for s in S:
  if s == "E":
    e += 1
  else:
    w += 1
  EAST.append(e)
  WEST.append(w)
  
ans = N - 1
for i in range(N):
  c = 0
  if i > 0:
    c += WEST[i-1]
  if i < N - 1:
    c += EAST[N-1] - EAST[i]
  
  ans = min(c,ans)

print(ans)
    

  


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
n=int(input())
w=input()
ans=[0 for i in range(n)]
for i in range(1,n):
  if w[i]=="E":
    ans[0]+=1
for i in range(1,n):
  if w[i]=="E":
    ans[i]=ans[i-1]-1
  if w[i-1]=="W":
    ans[i]=ans[i-1]+1
print(min(ans))
    

n=int(input())
w=input()
ans=[0 for i in range(n)]
for i in range(1,n):
  if w[i]=="E":
    ans[0]+=1
for i in range(1,n):
  ans[i]=ans[i-1]
  if w[i]=="E":
    ans[i]-=1
  if w[i-1]=="W":
    ans[i]+=1
print(min(ans))



Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N = int(input())
line = input()

ans = line[1:N].count('E')
tmp = ans
for i in range(1,N):
 if line[i] == 'E':
  tmp -= 1
 if line[i-1] == 'W':
  tmp += 1
 if ans>tmp:
  ans = tmp
 print(i)


print(ans)

N = int(input())
line = input()

ans = line[1:N].count('E')
tmp = ans
for i in range(1,N):
 if line[i] == 'E':
  tmp -= 1
 if line[i-1] == 'W':
  tmp += 1
 if ans>tmp:
  ans = tmp

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
import sys

N = int(input())
S = input()

position = []
for s in S:
    if s == 'W':
        position.append(-1)
    else:
        position.append(1)
i = 0
flips = N + 1
while i < N:
    flips_temp = 0
    j  = 0
    while j < N:
        if j < i:
            flips_temp += (1 - position[j]) / 2.
        if j > i:
            flips_temp += (1 + position[j]) / 2.
        j = j + 1
    if flips_temp < flips:
        flips = flips_temp
    i = i + 1
print(flips)

import sys

N = int(input())
S = input()

position_L = []
position_R = []
for s in S:
    if s == 'W':
        position_R.append(0)
    else:
        position_R.append(1)
        
flips = sum(position_R[1:])
flips_temp = flips
#print(0,flips_temp)
i = 1
while i < N:
    #print(i,flips_temp)
    flips_temp = flips_temp - position_R[i] + ((-1) * position_R[i-1] + 1)
    if flips_temp < flips:
        flips = flips_temp
    i = i + 1
print(flips)

Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
n = int(input())
a = list(input())
for i in range(n):
    if a[i] == 'E':
        a[i] = 1
    else:
        a[i] = 0

ans = 99999999999999999999
# print(a)
l = 0
r = sum(a)
for i in range(n):

    if i == 0:
        if a[i] == 1:
            r -= a[i]
            a[i] = 0
        else:
            a[i] = 1
        l = 0
    else:
        if a[i] == 1:
            a[i] = 0
            r -= 1
        else:
            a[i] = 1
        l += a[i-1]

    ans = min(l+r,ans)
    print(i,l,r,ans)
print(ans)



n = int(input())
a = list(input())
for i in range(n):
    if a[i] == 'E':
        a[i] = 1
    else:
        a[i] = 0

ans = 99999999999999999999
# print(a)
l = 0
r = sum(a)
for i in range(n):

    if i == 0:
        if a[i] == 1:
            r -= a[i]
            a[i] = 0
        else:
            a[i] = 1
        l = 0
    else:
        if a[i] == 1:
            a[i] = 0
            r -= 1
        else:
            a[i] = 1
        l += a[i-1]

    ans = min(l+r,ans)
    # print(i,l,r,ans)
print(ans)



Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N = int(input())
S = input()

East = [0] * N
West = [0] * N

for i,s in enumerate(list(S)):
    if s == 'W' : 
        if i==0:
            East[i] = 1
        else:
            East[i] = East[i-1] + 1
    else:
        East[i] = East[i-1]
i = N-1
for s in reversed((list(S))):
    if s == 'E' : 
        if i==N-1:
            West[i] = 1
        else:
            West[i] = West[i+1] + 1
    else:
        West[i] = West[i+1]
    i -= 1
            
ans = 2**31-1

for i in range(N):
    if i == 1:
        ans2 = West[1]
    elif i == N-1:
        ans2 = East[N-2]
    else:
        ans2 = East[i-1]+West[i+1]
    ans = min(ans,ans2)
    
print(ans)
    

N = int(input())
S = input()

East = [0] * N
West = [0] * N

for i,s in enumerate(list(S)):
    if s == 'W' : 
        if i==0:
            East[i] = 1
        else:
            East[i] = East[i-1] + 1
    else:
        if i == 0:
            East[i] = 0
        else:
            East[i] = East[i-1]
i = N-1
for s in reversed((list(S))):
    if s == 'E' : 
        if i==N-1:
            West[i] = 1
        else:
            West[i] = West[i+1] + 1
    else:
        if i == N-1:
            West[i] = 0
        else:
            West[i] = West[i+1]
    i -= 1
            
ans = 2**31-1

for i in range(N):
    if i == 1:
        ans2 = West[1]
    elif i == N-1:
        ans2 = East[N-2]
    else:
        ans2 = East[i-1]+West[i+1]
    ans = min(ans,ans2)
    
print(ans)
    

Verdicts: Runtime Error

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
def foo (s):
    ans = 0
    count = 0
    for i in s:
        if i == 'W':
            count += 1
    elif count :
        count -= 1
        ans += 1
    else:
        pass
    return ans
  
n = input()
s = input()
 
print(foo(s))

def foo (s):
	ans = 0
	count = 0
	for i in s:
		if   (not count) and (i == 'E'):pass
		elif not count: count += 1
		elif i == 'E': count -= 1; ans += 1
		else: count += 1
	return ans
  
  n = int(input())
  s = input()
  print(foo(s))

def foo (s):
    ans = 0
    count = 0
    for i in s:
        if i == 'W':
            count += 1
    elif count :
        count -= 1
        ans += 1
    else:
        pass
    return ans
  
  n = input()
s = input()
 
print(foo(s))

def foo (s):
    ans = 0
    count = 0
    for i in s:
        if i == 'W':
        count += 1
    elif count :
        count -= 1
        ans += 1
    else:
        pass
    return ans

n = input()
s = input()
 
print(foo(s))

def foo (s):
    ans = 0
    count = 0
    for i in s:
        if i == 'W':
        count += 1
    elif count :
        count -= 1
        ans += 1
    else:
        pass
    return ans
 
n = input()
s = input()

print(foo(s))

def foo (s):
    ans = 0
    count = 0
    for i in s:
        if i == 'W':
            count += 1
        elif count :
            count -= 1
            ans += 1
        else:
            pass
    return ans

n = input()
s = input()
 
print(foo(s))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=k()
p=X()
e=[1 if i=="E" else 0 for i in p]
w=[1 if i=="W" else 0 for i in p]
e=list(itertools.accumulate(e))
w=list(itertools.accumulate(w))

for i in range(n):
    mod = min(mod, e[-1]-e[i]+w[i])



print(e)
print(w)
print(mod)


import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
s = v()
e = list(itertools.accumulate([1 if i=="E" else 0 for i in s]))
w = list(itertools.accumulate([1 if i=="W" else 0 for i in s]))

for i in range(n):
    cnt = e[-1]-e[i]+w[i]
    if mod > cnt:
        mod,ans = cnt,i
if ans == 0:
    mod -= 1

print(mod)







Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N = int(input())
S = input()
ans = [S[1:].count("E")]
for i in range(1, N):
	tmp = ans[i - 1]
	if S[i - 1] == "W":
		tmp += 1
	if S[i] == "E":
		tmp -= 1
	ans.append(tmp)
print(ans)


N = int(input())
S = input()
ans = [S[1:].count("E")]
for i in range(1, N):
	tmp = ans[i - 1]
	if S[i - 1] == "W":
		tmp += 1
	if S[i] == "E":
		tmp -= 1
	ans.append(tmp)
print(min(ans))


Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N=int(input())
S=list(input())
for i in range(len(S)):
    S[i]=-1 if S[i]=="W" else 1
data=[-1 for i in range(N)]
stidx,endidx,maidx=0,N-1,int((N-1)/2)
for i in [stidx,endidx]:
    data[i]=-1*sum([S[m] for m in range(0,i) if S[m]==-1])+sum([S[m] for m in range(i+1,N) if S[m]==1])
while endidx-stidx>3:

    t1=int(stidx+(endidx-stidx)*1/3)
    t2=int(stidx+(endidx-stidx)*2/3)
    print(stidx,endidx,t1,t2)
    for i in [t1,t2]:
        data[i]=-1*sum([S[m] for m in range(0,i) if S[m]==-1])+sum([S[m] for m in range(i+1,N) if S[m]==1])
    if data[t1]>data[t2]:
        stidx=t1
    else:
        endidx=t2

print(min([i for i in data if i>0]))


N=int(input())
S=list(input())
data=[0 for i in range(N)]
data[0]=S[1:].count("E")
for i in range(N-1):
    if S[i]=="W":
        data[i+1]+=1
    if S[i+1]=="E":
        data[i+1]-=1
    data[i+1]+=data[i]
print(min([i for i in data]))


Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):

# created: 22.09.2020 12:19:17

import sys

from collections import Counter

N = int(input())

S = input()

l = 0
r = Counter(S[1:])["E"]
print(f"{l=}{r=}")

ans = l + r
flg = False

for i in range(N):
    if flg:
        l += 1
    flg = False
    if S[i] == "E":
        r -= 1

    ans = min(ans, l + r)

    if S[i] == "W":
        flg = True


print(ans)



# created: 22.09.2020 12:19:17

import sys

from collections import Counter

N = int(input())

S = input()

e = [0]
w = [0]

for s in S:
    if s == "W":
        w += [w[-1] + 1]
        e += [e[-1]]
    elif s == "E":
        w += [w[-1]]
        e += [e[-1] + 1]

ans = 3 * (10 ** 5) + 1

for i in range(N):
    c = w[i]
    c += e[N] - e[i + 1]
    ans = min(c, ans)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
input()
s = input()

def f(i):
  return s[0:i].count('W') + s[i:].count('E')

x = len(s)

for i in range(len(s)):
  x = min(x, f(i))

print(min(arr))

input()
s = input()

l = 0
r = s[1:].count('E')
x = l + r

for i in range(1, len(s)):
  if s[i - 1] == 'W':
    l += 1

  if s[i] == 'E':
    r -= 1
  x = min(x, l + r)

print(x)


Verdicts: Runtime Error

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N = int(input())
S = input()

# [West, East]
l = [0, 0]
L = []
m = [0, 0]
M = [0] * N
for i in range(N):
  if S[i] == 'W':
    l[0] += 1
    L.append(list(l))
    print(l)
  else:
    l[1] += 1
    L.append(list(l))
    print(l)

for i in range(N-1, -1, -1):
  if S[i] == 'W':
    m[0] += 1
    M[i] = list(m)
  else:
    m[1] += 1
    M[i] = list(m)
    
count = []
for i in range(N):
  if i == 0:
    count.append(M[1][0])
  elif i == N-1:
    count.append(L[N-2][1])
  else:
    count.append(L[i-1][0]+M[i+1][1])

print(min(count))
    

N = int(input())
S = input()

l = 0
L = []
r = 0
R = [0] * N
for i in range(N):
  if i == 0:
    L.append(0)
  else:
    if S[i-1] == 'W':
      l += 1
    L.append(l)
    
for i in range(N-1, -1, -1):
  if i == N-1:
    R[i] = 0
  else:
    if S[i+1] == 'E':
      r += 1
    R[i] = r
    
count = []
for i in range(N):
  count.append(L[i] + R[i])

print(min(count))



Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N = int(input())
S = input()
stock = []
#INF = 10**9
for i in range(1,len(S)-1):
  if (S[i-1] == "E") & (S[i+1] == "W"): stock.append(i)

dic = {k:0 for k in stock}
dic[0]＝ S.count("E")
dic[len(S)-1] = S.count("W")

for i in stock:
  for j in range(i-1,0,-1):
    if j < 0: break
    else:
      if S[j] == "E" : dic[i] += 1
      else: break

  for j in range(i+1, len(S)):
    if j > len(S)-1: break
    else:
      if S[j] == "W" : dic[i] += 1
      else: break

max_k = max(dic, key=dic.get)


count = 0
for i in range(0,max_k):
  if S[i] == "W": count += 1

for i in range(max_k+1, len(S)):
  if S[i] == "E": count += 1




print(count)

N = int(input())
S = input()

sum_w = [0]
sum_e = [0]

count = 0
for i in range(N-1):
  if S[i] == "W":
    count += 1
  sum_w.append(count)

count = 0
for i in range(N-1,0,-1):
  if S[i] == "E": 
    count += 1
  sum_e.append(count)
sum_e = sum_e[::-1]


sumu = [x+y for x, y in zip(sum_w, sum_e)]

print(min(sumu))

Verdicts: Runtime Error

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
	N = int(input())
S = input()

tmp = [int(p.replace('W', '-1')) if p == 'W' else int(p.replace('E', '1')) for p in list(S)]

result = []
cnt = 0
for CTO in range(N):
    for MEM in range(N):
        print(CTO)
        if MEM == CTO:
            continue
        if CTO < MEM:
            if tmp[CTO] == -1:
                if (tmp[MEM] + tmp[CTO]) == 0:
                    cnt += 1
            if tmp[CTO] == 1:
                if (tmp[MEM] + tmp[CTO]) != 0:
                    cnt += 1

        if MEM < CTO:
            if tmp[CTO] == -1:
                if (tmp[MEM] + tmp[CTO]) != 0:
                    cnt += 1
            if tmp[CTO] == 1:
                if  (tmp[MEM] + tmp[CTO]) == 0:
                    cnt += 1
        print(cnt)
    result.append(cnt)
    cnt = 0

result_x = [ result[i] for i in range(N) if result[i] != 0]
print(min(result_x))

N = int(input())
S = input()

tmp = [int(p.replace('W', '-1')) if p == 'W' else int(p.replace('E', '1')) for p in list(S)]

result = []
cnt = 0
for CTO in range(N):
    for MEM in range(N):
        print(CTO)
        if MEM == CTO:
            continue
        if CTO < MEM:
            if tmp[CTO] == -1:
                if (tmp[MEM] + tmp[CTO]) == 0:
                    cnt += 1
            if tmp[CTO] == 1:
                if (tmp[MEM] + tmp[CTO]) != 0:
                    cnt += 1

        if MEM < CTO:
            if tmp[CTO] == -1:
                if (tmp[MEM] + tmp[CTO]) != 0:
                    cnt += 1
            if tmp[CTO] == 1:
                if  (tmp[MEM] + tmp[CTO]) == 0:
                    cnt += 1
        print(cnt)
    result.append(cnt)
    cnt = 0

result_x = [ result[i] for i in range(N) if result[i] != 0]
print(min(result_x))

N = int(input())
S = list(input())

w = 0
e = S[1:].count('E')

leader = S[0]
min_mem=e
cnt_mem=0

for i in range(1, N):
    if leader ==  'W':
        w += 1
    leader = S[i]

    if leader == 'E':
        e -= 1

    cnt_mem = w + e
    if cnt_mem < min_mem:
        min_mem = cnt_mem

print(min_mem)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N = int(input())
S = list(input())
count_list = []
camu_west = []
for i in range(1,N+1):
  look_west = len([S[j] for j in range(i) if S[j] == "W"])
  camu_west.append(look_west)
for i in range(N):
  count_l = camu_west[i-1]
  if i == 0:
    count_l = 0
  count_r = N-1-i-(camu_west[N-1]-camu_west[i])
  if i == N:
    count_r = 0
  count = count_l + count_r 
  count_list.append(count)
ans = min(count_list)
print("test")

N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
count = count_E + count_W
ans = count + 1
for e in S:
    if e == "E":
        count_E -= 1
    elif e == "w":
        count_w += 1
    if count < ans :
        ans = count
print(ans)

N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
count = count_E + count_W
ans = count + 1
for e in range S:
    if e == "E":
        count_E -= 1
    elif e == "W":
        count_W += 1
    if count < ans :
        ans = count
print(ans)

N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
count = count_E + count_W
ans = count + 1
for e in S:
    if e == "E":
        count_E -= 1
    elif e == "W":
        count_W += 1
    if count < ans :
        ans = count
print(ans)

N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
count = count_E + count_W
ans = count
for i in range(N):
    if i == 0 and S[i] == "E":
        count_E -= 1
    else:
        if S[i-1] == "E" and i != 1:
            count_E -= 1
        elif S[i-1] == "W":
            count_W += 1
    if count < ans :
        ans = count
print(ans)

N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
count = count_E + count_W
ans = count + 1
for e in range S:
    if e == "E":
        count_E -= 1
    elif e == "w":
        count_W += 1
    if count < ans :
        ans = count
print(ans)

N = int(input())
S = input()
east = [0]*N
west = [0]*N

tmp1 = 0
for i in range(N-1,-1,-1):
    east[i] = tmp1
    if S[i] == "E":
        tmp1 += 1

tmp2 = 0
for i in range(N):
    west[i] = tmp2
    if S[i] == "W":
        tmp2 += 1

ans = N
for e, w in zip(east,west):
    if ans > e + w:
        ans = e + w
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
N = int(input())
S = input()

s = S[::-1]
w = [0]*(N+1)
e = [0]*(N+1)
cnt_w = 0
cnt_e = 0

for i in range(N):
    if(S[i] == "W"):
        cnt_w += 1
        w[i+1] = cnt_w
    else:
        w[i+1] = cnt_w

for i in range(N):
    if(s[i] == "E"):
        cnt_e += 1
        e[i+1] = cnt_e
    else:
        e[i+1] = cnt_e

print(w)
print(e)
e = e[::-1]        
ans = 2*N

for i in range(N+1):
    ans = min(ans, e[i]+w[i])
print(ans)

N = int(input())
S = input()

s = S[::-1]
w = [0]*(N+1)
e = [0]*(N+1)
cnt_w = 0
cnt_e = 0

for i in range(N):
    if(S[i] == "W"):
        cnt_w += 1
        w[i+1] = cnt_w
    else:
        w[i+1] = cnt_w

for i in range(N):
    if(s[i] == "E"):
        cnt_e += 1
        e[i+1] = cnt_e
    else:
        e[i+1] = cnt_e

e = e[::-1]        
ans = 2*N

for i in range(N+1):
    ans = min(ans, e[i]+w[i])
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.  You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.  The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Submission attempts (in order):
n = int(input())
S = [int(c == 'W') for c in list(input())]
L = [0]
for i in range(n):
    L.append(L[-1]+S[i])
R = [0]
for i in range(n-1, 0, -1):
    R.append(R[-1]+S[i])
R.reverse()
print(min([L[i]+R[i] for i in range(n)]))


n = int(input())
S = [int(c == 'W') for c in list(input())]
L = [0]
for i in range(n):
    L.append(L[-1]+S[i])
R = [0]
for i in range(n-1, 0, -1):
    R.append(R[-1]+1-S[i])
R.reverse()
print(min([L[i]+R[i] for i in range(n)]))


Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:    * Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).  Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.

Submission attempts (in order):
N,K,Q = a = map(int,input().split())
a = list(map(int,input().split()))
inf = 10**10
ans = inf
for i in range(N):
    small = a[i]
    seq = []
    seqq = []
    for j in range(N):
        if a[j] < small:
            seq.append(seqq)
            seqq = []
        else:
            seqq.append(a[j])
    seq.append(seqq)
    aaa = []
    for s in seq:
        if len(s)>=K:
            s.sort()
            aaa += s[:len(s)-K+1]
    if len(aaa)>=Q:
        aaa.sort()
        ans = min(ans,aaa[Q-1]-aaa[0])
        print(i,a[i],aaa,ans)
print(ans)

N,K,Q = a = map(int,input().split())
a = list(map(int,input().split()))
inf = 10**10
ans = inf
for i in range(N):
    small = a[i]
    seq = []
    seqq = []
    for j in range(N):
        if a[j] < small:
            seq.append(seqq)
            seqq = []
        else:
            seqq.append(a[j])
    seq.append(seqq)
    aaa = []
    for s in seq:
        if len(s)>=K:
            s.sort()
            aaa += s[:len(s)-K+1]
    if len(aaa)>=Q:
        aaa.sort()
        ans = min(ans,aaa[Q-1]-aaa[0])
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:    * Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).  Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.

Submission attempts (in order):
def split_by_floor(arr, floor):
    ans = []
    tmp = []
    for e in arr:
        if e < floor and tmp:
            ans.append(tmp)
            tmp = []
        else:
            tmp.append(e)
    if tmp:
        ans.append(tmp)
    return ans

N, K, Q = map(int, input().split())
arr = [int(x) for x in input().split()]

floor_cands = list(sorted(set(arr)))
print(floor_cands)
ans = floor_cands[-1] - floor_cands[0]
print(ans)

for floor in floor_cands:
    splitted_arrs = split_by_floor(arr, floor)
    cands = []
    for splitted in splitted_arrs:
        cands.extend(sorted(splitted)[:len(splitted) - K + 1])
    if len(cands) < Q:
        continue
    sorted_cands = list(sorted(cands))
    tmp_ans = sorted_cands[Q - 1] - sorted_cands[0]
    if ans > tmp_ans:
        ans = tmp_ans
    print(floor, tmp_ans)

print(ans)


def solve(N, K, Q, As, X):
    mins = []
    tmp = []
    for A in As:
        if A >= X:
            tmp.append(A)
        else:
            if len(tmp) >= K:
                tmp.sort()
                mins.extend(tmp[:len(tmp)-K+1])
            tmp = []
    if len(tmp) >= K:
        tmp.sort()
        mins.extend(tmp[:len(tmp)-K+1])

    if len(mins) < Q:
        return None
    mins.sort()
    taken = mins[:Q]
    return taken[-1] - taken[0]


N, K, Q = map(int, input().split())
As = [int(x) for x in input().split()]

ans = -1
for A in As:
    cand = solve(N, K, Q, As, A)
    if cand is not None and (ans == -1 or ans > cand):
        ans = cand

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:    * Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).  Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.

Submission attempts (in order):
N,K,Q = map(int,input().split())
A = tuple(map(int,input().split()))
B = sorted(A)
L = sorted([[i,B[i+Q-1] - B[i]] for i in range(N-Q+1)],key=lambda x:x[1])
print(A)
print(B)
print(L)

if Q == 1:
    print(0)
    exit()
if Q == N - K + 1:
    print(B[Q-1] - B[0])
    exit()
if K == 1:
    print(L[0])
    exit()
print(B[Q-1] - B[0])


N,K,Q = map(int,input().split())
A = list(map(int,input().split()))
B = sorted(A) 
L = [[i,B[i+Q-1] - B[i]] for i in range(N-Q+1)] 
sL = sorted(L,key=lambda x:x[1]) 

if Q == 1:
    
    print(0)
    exit()

if Q == N - K + 1:
    
    print(L[0][1])
    exit()

if K == 1:
    
    print(sL[0][1])
    exit()

if sL[0][0] == 0:
    
    print(sL[0][1])
    exit()

if sL[0][1] == sL[len(sL)-1][1]:
    print(sL[0][1])
    exit()


for key,value in sL:
    max_value = B[key + Q - 1]
    min_value = B[key]
    C = [(i if i >= min_value else None) for i in A]
    i = 0
    j = 0
    count = 0
    min_OK = max_OK = False
    while i < N:
        if not C[i]:
            i += 1
            continue
        j = i + 1
        while j < N:
            if not C[j]:
                break
            j += 1
        tmp = (j-i) - K + 1
        if  tmp < 1:
            
            i = j + 1
            continue
        sC = sorted(C[i:j])
        if not min_OK and (sC[0] == min_value):
            min_OK = True
        if not max_OK and max_value in sC[0:tmp]:
            max_OK = True
        count += tmp - len([i for i in sC[:tmp] if i > max_value])
        i = j +1
    if min_OK and max_OK and (count >= Q):
        print(value)
        exit()

print(L[0][1])



Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence A of length N and an integer K. You will perform the following operation on this sequence Q times:    * Choose a contiguous subsequence of length K, then remove the smallest element among the K elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).  Let X and Y be the values of the largest and smallest element removed in the Q operations. You would like X-Y to be as small as possible. Find the smallest possible value of X-Y when the Q operations are performed optimally.

Submission attempts (in order):
N, K, Q = map(int, input().split())
a = list(map(int, input().split()))

d=[a]
a = sorted(a)

ans = a[Q-1] - a[0]


while True:
  d_temp = list()
  sub_temp = list()
  for sub in d:
    for c in sub:
      if c != a[0]:
        sub_temp.append(c)
      else:
        d_temp.append(sub_temp)
        sub_temp = list()
    d_temp.append(sub_temp)
    sub_temp = list()

  d = list()
  a = list()
  for sub in d_temp:
    if len(sub) < K:
      continue
    else:
      d.append(sub)
      sub = sorted(sub)
      a.extend(sub[0:len(sub)-K+1])

  a.sort()

  if len(a) < Q:
    break
  else:
    ans = min(ans, a[Q-1] - a[0])

#print(ans)


n, k, q = map(int, input().split())
a = list(map(int, input().split()))
 
d = [a]
a.sort
ans = a[q - 1] - a[0]
 
while True:
    newd = list()
    li = list()
    for sub in d:
        for c in sub:
            if c != a[0]:
                li.append(c)
            else:
                newd.append(li)
                li = list()
        newd.append(li)
        li = list()
 
    d = list()
    a = list()
    for li in newd:
        if len(li) < k:
            continue
        else:
            d.append(li)
            li.sort()
            a.extend(li[0:len(li) - k + 1])
 
    a.sort()
 
    if len(a) >= q:
        ans = min(a[q - 1] - a[0], ans)
    else:
        break
print(ans)


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

d = [a]
a = sorted(a)
a.sort()
ans = a[Q-1] - a[0]

while True:
  d_temp = list()
  sub_temp = list()
  for sub in d:
    for c in sub:
      if c != a[0]:
        sub_temp.append(c)
      else:
        d_temp.append(sub_temp)
        sub_temp = list()
    d_temp.append(sub_temp)
    sub_temp = list()

  d = list()
  a = list()
  for sub in d_temp:
    if len(sub) < K:
      continue
    else:
      d.append(sub)
      sub = sorted(sub)
      a.extend(sub[0:len(sub)-K+1])

  a = sorted(a)

  if len(a) < Q:
    break
  else:
    ans = min(ans, a[Q-1] - a[0])

print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted