Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
,K=map(int,input().split())
A=list(map(int, input().split()))
dp=[[0,0]for _ in range(42)]
#2の41乗が10**12とちょっと

for i in range(1,42):
  if dp[i-1][1]==1:
    dp[i][1]=1
  
  cnt=0
  #リストA内のiケタ目の1の数をカウント
  for j in range(N):
    if (A[j]>>(41-i))&1==1:
      cnt+=1
      
  #1の方が多いときは、0を当てはめる
  if cnt>=N-cnt:
    dp[i][0]=dp[i-1][0]+(2**(41-i))*cnt
    if (K>>(41-i))&1==1:
      dp[i][1]=1
  else:
    if dp[i][1]==1:
      dp[i][0]=dp[i-1][0]+(2**(41-i))*(N-cnt)
    else:
      if (K>>(41-i))&1==1:
        #そのケタが1ならば問題なし
        dp[i][0]=dp[i-1][0]+(2**(41-i))*(N-cnt)
      else:
        #桁が0ならば0にするしかない
        dp[i][0]=dp[i-1][0]+(2**(41-i))*cnt
print(dp[41][0])

Fixed submission:
N,K=map(int,input().split())
A=list(map(int, input().split()))
dp=[[0,0]for _ in range(42)]
#2の41乗が10**12とちょっと

for i in range(1,42):
  if dp[i-1][1]==1:
    dp[i][1]=1
  
  cnt=0
  #リストA内のiケタ目の1の数をカウント
  for j in range(N):
    if (A[j]>>(41-i))&1==1:
      cnt+=1
      
  #1の方が多いときは、0を当てはめる
  if cnt>=N-cnt:
    dp[i][0]=dp[i-1][0]+(2**(41-i))*cnt
    if (K>>(41-i))&1==1:
      dp[i][1]=1
  else:
    if dp[i][1]==1:
      dp[i][0]=dp[i-1][0]+(2**(41-i))*(N-cnt)
    else:
      if (K>>(41-i))&1==1:
        #そのケタが1ならば問題なし
        dp[i][0]=dp[i-1][0]+(2**(41-i))*(N-cnt)
      else:
        #桁が0ならば0にするしかない
        dp[i][0]=dp[i-1][0]+(2**(41-i))*cnt
print(dp[41][0])
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
H=list(map(int,input().split()))
DP=[0]*(N+1)
for i in range(2,N+1):
  L=[DP[i-j-1]+abs(H[i-1]-H[i-j-2])for j in range(min(K,i-1))]
  DP[i]=min(L)
print(DP[-1])

Fixed submission:
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

Fixed submission:
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
List=[list(map(int,input().split())) for i in range(N)]
w,v=zip(*List)
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(N):
  for j in range(W+1):
    if j-w[i]>=0:
      dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
    dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(max(dp[N]))

Fixed submission:
N,W=map(int,input().split())
List=[list(map(int,input().split())) for i in range(N)]
w,v=zip(*List)
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(N):
  for j in range(W+1):
    if j-w[i]>=0:
      dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
    dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(max(dp[N]))
Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]

dp=[float("inf")]*(10**5+1)
dp[0]=0
for i in range(n):
  for j in range(10**5,A[i][1]-1,-1):
    dp[j]=min(dp[j],dp[j-A[i][1]]+A[i][0])
ans=0
for v,e in enumerate(dp):
  if e<=w:
    ans=v
print(ans)


Fixed submission:
import sys
input=sys.stdin.readline
n,w=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]

dp=[float("inf")]*(10**5+1)
dp[0]=0
for i in range(n):
  for j in range(10**5,A[i][1]-1,-1):
    dp[j]=min(dp[j],dp[j-A[i][1]]+A[i][0])
ans=0
for v,e in enumerate(dp):
  if e<=w:
    ans=v
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]

dp=[float("inf")]*(10**5+1)
dp[0]=0
for i in range(n):
  for j in range(10**5,A[i][1]-1,-1):
    dp[j]=min(dp[j],dp[j-A[i][1]]+A[i][0])
ans=0
for v,e in enumerate(dp):
  if e<=w:
    ans=v
print(ans)

Fixed submission:
import sys
input=sys.stdin.readline
n,w=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]

dp=[float("inf")]*(10**5+1)
dp[0]=0
for i in range(n):
  for j in range(10**5,A[i][1]-1,-1):
    dp[j]=min(dp[j],dp[j-A[i][1]]+A[i][0])
ans=0
for v,e in enumerate(dp):
  if e<=w:
    ans=v
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)
def chmax(a,b):
  if a>=b:
    return a
  else:
    return b
dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=chmax(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=chmax(ans,rec(i))
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+10)
input=sys.stdin.readline

N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)
def chmax(a,b):
  if a>=b:
    return a
  else:
    return b
dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=chmax(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=chmax(ans,rec(i))
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)

dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=max(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=max(ans,rec(i))
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+10)
input=sys.stdin.readline

N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)
def chmax(a,b):
  if a>=b:
    return a
  else:
    return b
dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=chmax(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=chmax(ans,rec(i))
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)
print(G)

dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=max(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=max(ans,rec(i))
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+10)
input=sys.stdin.readline

N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)
def chmax(a,b):
  if a>=b:
    return a
  else:
    return b
dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=chmax(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=chmax(ans,rec(i))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P=list(map(float,input().split()))
dp=[[0]*(N+1) for i in range(N+1)]
dp[0][0]=1
for i in range(1,N+1):
  for j in range(N+1):
    dp[i][j]=dp[i-1][j-1]*P[i-1]+dp[i-1][j]*(1-P[i-1])
ans=0

for i in range(N//2+1,N+1):
  ans+=dp[-1][i]
print(ans)

Fixed submission:
N=int(input())
P=list(map(float,input().split()))
dp=[[0]*(N+1) for i in range(N+1)]
dp[0][0]=1
for i in range(1,N+1):
  for j in range(N+1):
    dp[i][j]=dp[i-1][j-1]*P[i-1]+dp[i-1][j]*(1-P[i-1])
ans=0

for i in range(N//2+1,N+1):
  ans+=dp[-1][i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=list(map(int,input().split()))
dp=[[0]*(N+1) for i in range(N+1)]
#dp[a][b]でa:残っている数列の長さ b:左端
for w in range(1,N+1):
  for l in range(N-w+1):
    r=l+w
    dpl=-dp[l+1][r]+a[l]
    dpr=-dp[l][r-1]+a[r-1]
    dp[l][r]=max(dpl,dpr)
print(dp[0][N])

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
dp=[[0]*(N+1) for i in range(N+1)]
#dp[a][b]でa:残っている数列の長さ b:左端
for w in range(1,N+1):
  for l in range(N-w+1):
    r=l+w
    dpl=-dp[l+1][r]+a[l]
    dpr=-dp[l][r-1]+a[r-1]
    dp[l][r]=max(dpl,dpr)
print(dp[0][N])
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
a=list(map(int,input().split()))
dp=[[0]*(K+1) for i in range(N)]
for j in range(a[0]+1):
  dp[0][j]=1
  
for i in range(1,N):
  for j in range(K+1):
    if j==0:
      dp[i][j]=1
    else:
      dp[i][j]=dp[i][j-1]+dp[i-1][j]
      if j>=a[i]+1:
        dp[i][j]-=dp[i-1][j-1-a[i]]
      dp[i][j]=dp[i][j]%(10**9+7)
      
print(dp[-1][-1])


Fixed submission:
N,K=map(int,input().split())
a=list(map(int,input().split()))
dp=[[0]*(K+1) for i in range(N)]
for j in range(a[0]+1):
  dp[0][j]=1
  
for i in range(1,N):
  for j in range(K+1):
    if j==0:
      dp[i][j]=1
    else:
      dp[i][j]=dp[i][j-1]+dp[i-1][j]
      if j>=a[i]+1:
        dp[i][j]-=dp[i-1][j-1-a[i]]
      dp[i][j]=dp[i][j]%(10**9+7)
      
print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
import numpy
B=[0]+list(numpy.cumsum(A))
dp=[[0]*(N+1) for i in range(N)]
#k:いくつのスライムを合体しているか
for k in range(2,N+1):
  #i:どこのスライムを起点に合体しているか
  for i in range(N-k+1):
    dp[i][k]=min(dp[i][j]+dp[i+j][k-j] for j in range(1,k))+B[i+k]-B[i]
print(dp[0][N])

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[0]*(N+1)
for i in range(N):
  B[i+1]=B[i]+A[i]

dp=[[0]*(N+1) for i in range(N)]
#k:いくつのスライムを合体しているか
for k in range(2,N+1):
  #i:どこのスライムを起点に合体しているか
  for i in range(N-k+1):
    dp[i][k]=min(dp[i][j]+dp[i+j][k-j] for j in range(1,k))+B[i+k]-B[i]
print(dp[0][N])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)
mod=10**9+7
N=int(input())
G=[[] for _ in range(N+1)]
for _ in range(N-1):
    x, y = map(int, input().split())
    G[x].append(y)
    G[y].append(x)
b=[1]*(N+1)
w=[1]*(N+1)
def dfs(pre,n):
  for i in G[n]:
    if i==pre:
      continue
    dfs(n,i)
    b[n]*=w[i]
    b[n]%=mod
    w[n]*=b[i]+w[i]
    w[n]%=mod

dfs(0,1)
print((b[1]+w[1])%mod)

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
mod=10**9+7
N=int(input())
G=[[] for _ in range(N+1)]
for _ in range(N-1):
    x,y=map(int, input().split())
    G[x].append(y)
    G[y].append(x)
b=[1]*(N+1)
w=[1]*(N+1)
def dfs(pre,n):
  for i in G[n]:
    if i==pre:
      continue
    dfs(n,i)
    b[n]*=w[i]
    b[n]%=mod
    w[n]*=b[i]+w[i]
    w[n]%=mod

dfs(0,1)
print((b[1]+w[1])%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
mod=10**9+7
N=int(input())
G=[[] for _ in range(N+1)]
for _ in range(N-1):
    x, y = map(int, input().split())
    G[x].append(y)
    G[y].append(x)
b=[1]*(N+1)
w=[1]*(N+1)
def dfs(pre,n):
  for i in G[n]:
    if i==pre:
      continue
    dfs(n,i)
    b[n]*=w[i]
    b[n]%=mod
    w[n]*=b[i]+w[i]
    w[n]%=mod

dfs(0,1)
print((b[1]+w[1])%mod)

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
mod=10**9+7
N=int(input())
G=[[] for _ in range(N+1)]
for _ in range(N-1):
    x,y=map(int, input().split())
    G[x].append(y)
    G[y].append(x)
b=[1]*(N+1)
w=[1]*(N+1)
def dfs(pre,n):
  for i in G[n]:
    if i==pre:
      continue
    dfs(n,i)
    b[n]*=w[i]
    b[n]%=mod
    w[n]*=b[i]+w[i]
    w[n]%=mod

dfs(0,1)
print((b[1]+w[1])%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod=10**9+7
N=int(input())
A=[list(map(int, input().split())) for _ in range(N-1)]
G=[ [] for _ in range(N+1)]
for a,b in A:
  G[a].append(b)
  G[b].append(a)
b=[1]*(N+1)
w=[1]*(N+1)  
def dfs(pre,n):
  for i in G[n]:
    if i==pre:
      continue
    dfs(n,i)
    b[n]*=w[i]
    b[n]%=mod
    w[n]*=b[i]+w[i]
    w[n]%=mod

dfs(0,1)
print((b[1]+w[1])%mod)

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
mod=10**9+7
N=int(input())
G=[[] for _ in range(N+1)]
for _ in range(N-1):
    x,y=map(int, input().split())
    G[x].append(y)
    G[y].append(x)
b=[1]*(N+1)
w=[1]*(N+1)
def dfs(pre,n):
  for i in G[n]:
    if i==pre:
      continue
    dfs(n,i)
    b[n]*=w[i]
    b[n]%=mod
    w[n]*=b[i]+w[i]
    w[n]%=mod

dfs(0,1)
print((b[1]+w[1])%mod)
Buggy python submission (verdict: Time Limit Exceeded):
K=input()
D=int(input())
#余り0,余り1,余り2,…,余り(D-1)
dp=[0]*D
mod=10**9+7
s=0
for i in range(len(K)):
  ndp=[0]*D
  #余りがjだったものは(j+d)%Dの余りに変わるので
  for j in range(D):
    for d in range(10):
      ndp[(j+d)%D]=(ndp[(j+d)%D]+dp[j])%mod
  #直前までKと数字が同じだったものをカウント
  for d in range(int(K[i])):
    ndp[(s+d)%D]+=1 
  dp=ndp
  s=(s+int(K[i]))%D
#0000…の場合を引き、もしもKが該当するなら1を加える
ans=dp[0]-1
if s%D==0:
  ans+=1
print(ans%mod)

Fixed submission:
K=input()
D=int(input())
#余り0,余り1,余り2,…,余り(D-1)
dp=[0]*D
mod=10**9+7
s=0
for i in range(len(K)):
  ndp=[0]*D
  #余りがjだったものは(j+d)%Dの余りに変わるので
  for j in range(D):
    for d in range(10):
      ndp[(j+d)%D]=(ndp[(j+d)%D]+dp[j])%mod
  #直前までKと数字が同じだったものをカウント
  for d in range(int(K[i])):
    ndp[(s+d)%D]+=1 
  dp=ndp
  s=(s+int(K[i]))%D
print((dp[0]-1+(s==0))%mod)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
H=[int(input()) for i in range(N)]
A=sorted(H)[::-1]
ans=10**9
for i in range(N-K+1):
  a=A[i]-A[i+2]
  ans=min(ans,a)
print(ans)

Fixed submission:
N,K=map(int,input().split())
H=[int(input()) for i in range(N)]
A=sorted(H)[::-1]
ans=10**9
for i in range(N-K+1):
  a=A[i]-A[i+K-1]
  ans=min(ans,a)
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
T,A=map(int,input().split())
H=(list(map(int,input().split())))
z = abs(T-H*0.006)
while z 



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

height=[abs(A-(T-h*0.006)) for h in H]
print(int(height.index(min(height)) )+1)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
a=M//N
while (M%a)!=0:
  a-=1
print(a)

Fixed submission:
N,M=map(int,input().split())
D=[]
for i in range(1,int(M**0.5+1)):
  if M%i==0:
    D.append(i)
    D.append(M//i)
D.sort()
for j in D:
  if j >=N:
    print(M//j)
    exit()
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
import math
def d(n,r):
  return math.factorial(n)//math.factorial(r)//math.factorial(n-r)

if N<K:
  print(0)
else:  
  a=N//K
  ans=a
  if K%2==1:
    if a>=2:
      ans+=d(a,2)*6
    if a>=3:
      ans+=a*(a-1)*(a-2)
    print(ans)
  else:    
    if K*a+K//2<=N:
      b=a+1
    if a>=2:
      ans+=d(a,2)*6
      print(ans)
    if a>=3:
      ans+=a*(a-1)*(a-2)
    if b>=2:
      ans+=b+d(b,2)*6
    if b>=3:
      ans+=b*(b-1)*(b-2)

    print(ans)


Fixed submission:
N,K=map(int,input().split())
a=N//K
if K%2==1:
  print(a**3)
else:
  if N>=(a+0.5)*K:
    print(a**3+(a+1)**3)
  else:
    print((a**3)*2)

Buggy python submission (verdict: Runtime Error):
def d(n,r):
  return factorial(n)//factorial(r)//factorial(n-r)

if N<K:
  print(0)
else:  
  a=N//K
  ans=a
  if K%2==1:
    if a>=2:
      ans+=d(a,2)*6
    if a>=3:
      ans+=a*(a-1)*(a-2)
    print(ans)
  else:    
    if K*a+K//2<=N:
      b=a+1
    if a>=2:
      ans+=d(a,2)*6
      print(ans)
    if a>=3:
      ans+=a*(a-1)*(a-2)
    if b>=2:
      ans+=b+d(b,2)*6
    if b>=3:
      ans+=b*(b-1)*(b-2)

    print(ans)

Fixed submission:
N,K=map(int,input().split())
a=N//K
if K%2==1:
  print(a**3)
else:
  if N>=(a+0.5)*K:
    print(a**3+(a+1)**3)
  else:
    print((a**3)*2)
Buggy python submission (verdict: Runtime Error):
a,b=input().split()
print(a-b+1)

Fixed submission:
a,b=map(int,input().split())
print(a-b+1)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[]
C=[]
for i in A:
  if i<=0:    
    B.append(i)
  else:
    C.append(i)

b=len(B)
c=len(C)
a=min(b,c,K)

l=10**9
for i in range(a):
  la=C[i]+B[i+1-K]*(-2)
  lb=C[i]*2-B[i+1-K]
  l=min(l,la,lb)

BB=10**9
CC=10**9
if b>=K:
  BB=(B[-K])*(-1)
if c>=K:
  CC=(C[K-1])
print(min(BB,CC,l))

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=N-K+1
long=10**9
for i in range(a):
  l=A[i+K-1]-A[i]+min(abs(A[i+K-1]),abs(A[i]))
  long=min(long,l)
print(long)
Buggy python submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=list(map(int, input().split()))
import numpy
D=list(numpy.cumsum(A))
C={}
for i in D:
  d=i%M
  if d not in C:
    C[d]=1
  else:
    C[d]+=1
#print(C)

ans=0
for i in C.values():
  ans+=i*(i-1)//2
#余り0はそれ単独でok
ans+=C[0]
print(ans)

Fixed submission:
N,M=map(int, input().split())
A=list(map(int, input().split()))
import numpy
D=list(numpy.cumsum(A))
C={}
for i in D:
  d=i%M
  if d not in C:
    C[d]=1
  else:
    C[d]+=1
#print(C)

ans=0
for i in C.values():
  ans+=i*(i-1)//2
#余り0はそれ単独でok
if 0 in C:
  ans+=C[0]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=list(input())
count = N
for i in range(N):
  x=[i for i in S[:i] if i == 'W']
  y=[i for i in S[(i+1):] if i == 'E']
  if count > (len(x)+len(y)):
    count = (len(x)+len(y))

print(count)

Fixed submission:
N=int(input())
S=list(input())
C=[0]*N
C[0]=S[1:].count('E')
for i in range(1,N):
  C[i]=C[i-1]+ (S[i-1]=='W')-(S[i]=='E') 
print(min(C))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=list(input())
count = N
for i in range(N):
  x=S[:i].count('W')+S[(i+1):].count('E')
  if count > x:
    count = x
print(count)

Fixed submission:
N=int(input())
S=list(input())
C=[0]*N
C[0]=S[1:].count('E')
for i in range(1,N):
  C[i]=C[i-1]+ (S[i-1]=='W')-(S[i]=='E') 
print(min(C))
Buggy python submission (verdict: Runtime Error):
N,M=map(int, input().split()) 
P=list(map(int,input().split()))
par=[i for i in range(N+1)]
rank=[0]*(N+1)

#根を探す
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]==find(par[x])
    return par[x]

#同じ集合か判定
def same(x,y):
  return find(x)==find(y)

def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 0
  if rank[x]<rank[y]:
    par[x]=y
  else:
    par[y]=x
    if rank[x]==rank[y]:
      rank[x]+=1

for i in range(M):
  a,b=map(int,input().split())
  union(a,b)


print(par)
print(rank)     
  
ans=0
for i in range(1,N+1):
  print(i,P[i-1])
  if same(P[i-1],i):
    ans+=1
print(ans)

Fixed submission:
N,M=map(int, input().split()) 
P=list(map(int,input().split()))
par=[i for i in range(N+1)]
rank=[0]*(N+1)
#根
def find(x):
  if x==par[x]:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
  
def find(x):
    if x == par[x]:
        return x
    par[x] = find(par[x])
    return par[x]
  
#同じ集合か判定
def same(x,y):
  return find(x)==find(y)

def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 0
  if rank[x]<rank[y]:
    par[x]=y
  else:
    par[y]=x
    if rank[x]==rank[y]:
      rank[x]+=1

for i in range(M):
  a,b=map(int,input().split())
  union(a,b)

ans=0
for i in range(1,N+1):
  if same(P[i-1],i):
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans='Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='#':
      if S[max(0,i-1)][j]!='#' and S[min(i+1,W-1)][j]!='#' and S[i][max(0,j-1)]!='#' and S[i-1][min(j+1,H-1)]!='#':
        ans='No'
        break
print(ans)

Fixed submission:
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans='Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='#':
      if S[max(0,i-1)][j]!='#' and S[min(i+1,H-1)][j]!='#' and S[i][max(0,j-1)]!='#' and S[i][min(j+1,W-1)]!='#':
        ans='No'
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[input() for _ in range(H)]
Ans = 'Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='#':
      if S[max(0,i-1)][j]=='#'or [min(i+1,W)][j]=='#'or[i][max(0,j-1)]=='#'or[i-1][min(j+1,H)]=='#':
        continue
      else:
        Ans = 'No'
  print(Ans)
  

Fixed submission:
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans='Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='#':
      if S[max(0,i-1)][j]!='#' and S[min(i+1,H-1)][j]!='#' and S[i][max(0,j-1)]!='#' and S[i][min(j+1,W-1)]!='#':
        ans='No'
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[]
for i in range(N):
  S=input()
  A.append(S)
ans=0
for i in range(N):
  x=0
  for j in range(N):
    for k in range(N):      
      if A[j][k-i]!=A[k][j-i]:
        x=1
  if x==0:
    ans+=1
print(ans*N)

Fixed submission:
N=int(input())
A=[]
for i in range(N):
  S=input()
  A.append(S)
ans=0
for i in range(N):
  x=0
  for j in range(N):
    for k in range(N):      
      if A[j][k-i]!=A[k][j-i]:
        x=1
  if x==0:
    ans+=1
print(ans*N)
Buggy python submission (verdict: Runtime Error):
List = list(int,input().split())
price = 700 + List.count('○')
print(price)

Fixed submission:
print((input().count("o"))*100+700)

Buggy python submission (verdict: Runtime Error):
List = list(map(int,input().split()))
price = 700 + List.count('○')
print(price)

Fixed submission:
print((input().count("o"))*100+700)

Buggy python submission (verdict: Runtime Error):
S = list(map(int,input().split()))
price = 700 + list.count('○')
print(price)

Fixed submission:
print((input().count("o"))*100+700)
Buggy python submission (verdict: Runtime Error):
N,X=map(int,input().split())
weight = []
W = sum(weight)
P =(X- W) // weight.min()
print(N+P)
  

Fixed submission:
N,X=map(int,input().split())
weight = [int(input()) for weight in range(N)]
W = sum(weight)
P =(X- W) // min(weight)
print(N+P)
Buggy python submission (verdict: Time Limit Exceeded):
N,C=map(int, input().split())
#Aは時計回り
A,B=[],[]
allv=0
for i in range(N):
  a,b=map(int, input().split())
  A.append([a,b])
  B.append([C-a,b])
  allv+=b
A,B=sorted(A),sorted(B)
OA,OB,AS,BS=[],[],[],[]
ax,av,bx,bv=0,0,0,0
for i in range(N):
  ax,bx=A[i][0],B[i][0]
  av+=A[i][1]
  bv+=B[i][1]
  OA.append((ax,av))
  OB.append((bx,bv))
  AS.append(av-ax)
  BS.append(bv-bx)
#OA→AO→OBといくとき
ansa=0
for i in range(N-1):
  #iまで行く
  bma=N-i
  oa=OA[i][1]-OA[i][0]
  ao=-OA[i][0]
  ob=max(BS[:N-i-1])
  d=max(oa,oa+ao+ob)
  ansa=max(ansa,d)
ansb=0
for i in range(N-1):
  #iまで行く
  ama=N-i
  ob=OB[i][1]-OB[i][0]
  bo=-OB[i][0]
  oa=max(AS[:N-i-1])
  d=max(ob,ob+bo+oa)
  ansb=max(ansb,d)
print(max(ansa,ansb,allv-(C-max(OA[0][0],OB[0][0]))))

Fixed submission:
N,C=map(int, input().split())
#Aは時計回り
A,B=[],[]
allv=0
for i in range(N):
  a,b=map(int, input().split())
  A.append([a,b])
  B.append([C-a,b])
  allv+=b
A,B=sorted(A),sorted(B)
OA,OB,AS,BS=[],[],[],[]
ax,av,bx,bv=0,0,0,0
for i in range(N):
  ax,bx=A[i][0],B[i][0]
  av+=A[i][1]
  bv+=B[i][1]
  OA.append((ax,av))
  OB.append((bx,bv))
  AS.append(av-ax)
  BS.append(bv-bx)
#OA→AO→OBといくとき
d=BS[0]
e=AS[0]
BSma,ASma=[-10000]*N,[-10000]*N
for i in range(N):
  BSma[i]=max(d,BS[i])
  d=BSma[i]
  ASma[i]=max(e,AS[i])
  e=ASma[i]
  
ansa=0
for i in range(N-1):
  #iまで行く
  bma=N-i
  oa=OA[i][1]-OA[i][0]
  ao=-OA[i][0]
  ob=BSma[-2-i]
  d=max(oa,oa+ao+ob)
  ansa=max(ansa,d)
ansb=0
for i in range(N-1):
  #iまで行く
  ama=N-i
  ob=OB[i][1]-OB[i][0]
  bo=-OB[i][0]
  oa=ASma[-2-i]
  d=max(ob,ob+bo+oa)
  ansb=max(ansb,d)
print(max(ansa,ansb,allv-(C-max(OA[0][0],OB[0][0]))))
Buggy python submission (verdict: Runtime Error):
,K=map(int,input().split())
def f(b):
  d=max(b-K,0)*(N//b)+max(N%b-K+1,0)
  return d
ans=0
if K==0:
  print(N**2)
  exit()
  
for i in range(1,N+1):
  ans+=(f(i))
print(ans)

Fixed submission:
N,K=map(int,input().split())
def f(b):
  d=max(b-K,0)*(N//b)+max(N%b-K+1,0)
  return d
ans=0
if K==0:
  print(N**2)
  exit()
  
for i in range(1,N+1):
  ans+=(f(i))
print(ans)