Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = input()
    ans = 0

    for i in range(n-1):
        for j in range(i+1,n):
            for cnt in range(min(j-i,n-j)):
                if s[i+cnt] == s[j+cnt]:
                    continue
                else:
                    cnt -= 1
                    break
            ans = max(ans,cnt+1)
    print(ans)

main()


Fixed submission:
def main():
    n = int(input())
    s = input()
    dp = [[0]*(n+1) for i in range(n+1)]
    ans = 0
    for i in range(n-1)[::-1]:
        for j in range(i+1,n)[::-1]:
            if s[i] == s[j]:
                dp[i][j] = max(dp[i][j], dp[i+1][j+1] + 1)
                ans = max(ans, min(dp[i][j],j-i))
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = input()
    ans = 0

    for i in range(n-1):
        for j in range(i+1,n):
            for cnt in range(min(j-i,n-j)):
                if s[i+cnt] == s[j+cnt]:
                    continue
                else:
                    cnt -= 1
                    break
            ans = max(ans,cnt+1)
    print(ans)

main()


Fixed submission:
def main():
    n = int(input())
    s = input()
    dp = [[0]*(n+1) for i in range(n+1)]
    ans = 0
    for i in range(n-1)[::-1]:
        for j in range(i+1,n)[::-1]:
            if s[i] == s[j]:
                dp[i][j] = max(dp[i][j], dp[i+1][j+1] + 1)
                ans = max(ans, min(dp[i][j],j-i))
    print(ans)
main()
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = len(s)
mod = 10**9 + 7

# dp[i][j] = 上からi桁目まで見た時のjと合同な数の個数
dp =[[0]*13 for _ in range(l+1)]
dp[0][0] = 1
for i in range(l):
    if s[i] == '?':
        for j in range(13):
            for k in range(10):
                dp[i+1][(j*10+k)%13] += dp[i][j]
                dp[i+1][(j*10+k)%13] %= mod
    else:
        for j in range(13):
            dp[i+1][(j*10+int(s[i]))%13] += dp[i][j]
print(dp[l][5]%mod)


Fixed submission:
s = input()
l = len(s)
mod = 10**9 + 7

# dp[i][j] = 上からi桁目まで見た時のjと合同な数の個数
dp =[[0]*13 for _ in range(l+1)]
dp[0][0] = 1
for i in range(l):
    if s[i] == '?':
        for j in range(13):
            for k in range(10):
                dp[i+1][(j*10+k)%13] += dp[i][j]
                dp[i+1][(j*10+k)%13] %= mod
    else:
        for j in range(13):
            dp[i+1][(j*10+int(s[i]))%13] += dp[i][j]
print(dp[l][5]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m = map(int,input().split())
path = [[set() for _ in range(n)] for _ in range(3)]
for _ in range(m):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    path[0][u].add(v)

s,t = map(int,input().split())
for i in range(2):
    for j in range(n):
        for k in path[i][j]:
            path[i+1][j] = path[i+1][j] | path[0][k]
que = deque([s-1])
d = [float('inf')]*n
d[s-1] = 0
while que:
    p = que.popleft()
    for to in path[2][p]:
        if d[to] == float('inf'):
            d[to] = d[p] + 1
            que.append(to)
if d[t-1] == float('inf'):
    d[t-1] = -1
print(d[t-1])


Fixed submission:
from collections import deque
n,m = map(int,input().split())
path = [set() for _ in range(n)]
for _ in range(m):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    path[u].add(v)

s,t = map(int,input().split())

que = deque([(s-1,0)])
d = [[float('inf')]*n for _ in range(3)]
d[0][s-1] = 0
while que:
    p,i = que.popleft()
    j = (i+1)%3
    for to in path[p]:
        if d[j][to] == float('inf'):
            d[j][to] = d[i][p] + 1
            que.append((to,j))
if d[0][t-1] == float('inf'):
    d[0][t-1] = -3
print(d[0][t-1]//3)
Buggy python submission (verdict: Runtime Error):
x,n = map(int,input().split())
if x < a:
  print(0)
else:
  print(10)

Fixed submission:
x,a = map(int,input().split())
if x < a:
  print(0)
else:
  print(10)
Buggy python submission (verdict: Runtime Error):
n = int(input())
w = list(map(int,input().split()))
ans = 1e100
for i in range(1,n):
  ans = min(ans, abs(sum[:i]-sum[i:]))
print(ans)


Fixed submission:
n = int(input())
w = list(map(int,input().split()))
ans = sum(w)
for i in range(1,n):
  ans = min(ans, abs(sum(w[:i])-sum(w[i:])))
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
w = list(map(int,input().split()))
ans = 1e100
for t in w:
  over = 0
  under= 0
  for i in w:
    if i > w:
      over += i
    else:
      under+= i
  ans = min(ans,abs(over - under))
print(ans)


Fixed submission:
n = int(input())
w = list(map(int,input().split()))
ans = sum(w)
for i in range(1,n):
  ans = min(ans, abs(sum(w[:i])-sum(w[i:])))
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input.split())
if a >= 13:
  print(b)
elif 6<=a<=12:print(b//2)
else:print(0)

Fixed submission:
a,b = map(int,input().split())
if a >= 13: print(b)
elif 6 <= a:print(b//2)
else:print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i,j in zip(v,c):
  ans += max(0, v-c)
print(ans)


Fixed submission:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i,j in zip(v,c):
  ans += max(0, i-j)
print(ans)
Buggy python submission (verdict: Runtime Error):
ae = [int(input()) for _ in range(5)]
ae.sort()
if ae[-1] - ae[0] <= int(Input()):
  print('Yay!')
else:
  print(':(')

Fixed submission:
ae = [int(input()) for _ in range(5)]
ae.sort()
if ae[-1] - ae[0] <= int(input()):
  print('Yay!')
else:
  print(':(')
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,inpout().split())
print(min(b//a,c))


Fixed submission:
a,b,c = map(int,input().split())
print(min(b//a,c))

Buggy python submission (verdict: Runtime Error):
print(min(b//a,c))

Fixed submission:
a,b,c = map(int,input().split())
print(min(b//a,c))
Buggy python submission (verdict: Runtime Error):
s = int(input())
a = set(s)
p = s
n = 0
cnt = 0
while True:
  if n in a:
    print(cnt)
    exit()
  if p&1:
    n = 3*p +1
  else:
    n = p//2
  cnt += 1
  a.add(n)
  p = n


Fixed submission:
s = int(input())
a = set([s])
p = s
n = 0
cnt = 1
while True:
  if n in a:
    print(cnt)
    exit()
  a.add(n)
  if p&1:
    n = 3*p +1
  else:
    n = p//2
  cnt += 1
  p = n

Buggy python submission (verdict: Runtime Error):
s = int(input())
a = set(s)
p = s
n = 0
cnt = 0
while True:
  if n in a:
    print(cnt)
    exit()
  if p&1:
    n = 3*p +1
  else:
    n = p//2
  cnt += 1
  set.add(n)
  p = n


Fixed submission:
s = int(input())
a = set([s])
p = s
n = 0
cnt = 1
while True:
  if n in a:
    print(cnt)
    exit()
  a.add(n)
  if p&1:
    n = 3*p +1
  else:
    n = p//2
  cnt += 1
  p = n
Buggy python submission (verdict: Runtime Error):
from heapq import *

n, k = map(int,input().split())
T = [[] for i in range(n)]
for i in range(n):
    t,d = map(int,input().split())
    T[t-1].append(d)
Top = []
for i in range(n):
    if T[i]:
        T[i].sort(reverse=True)
        Top.append((T[i][0],i))
Top.sort(reverse = True)

various = len(Top)


ans = 0
s = 0
sushi = []
heapify(sushi)
l = 0

for j,(t,i) in enumerate(Top[:k]):
    s += t
    if l + j + 1 > k:
        s -= heappop(sushi)
        l -= 1
    for new in T[i][1:]:
        if l + j + 1 >= k:
            s += new
            s -= heappushpop(sushi,new)
            if sushi[0] >= new:break
        else:
            s += new
            l += 1
            heappush(sushi, new)
    ans = max(ans, s + (j+1)**2)
print(ans)


Fixed submission:
from heapq import *

n, k = map(int,input().split())
T = [[] for i in range(n)]
for i in range(n):
    t,d = map(int,input().split())
    T[t-1].append(d)
Top = []
for i in range(n):
    if T[i]:
        T[i].sort(reverse=True)
        Top.append((T[i][0],i))
Top.sort(reverse = True)

various = len(Top)


ans = 0
s = 0
sushi = []
heapify(sushi)
l = 0

for j,(t,i) in enumerate(Top[:k]):
    s += t
    if l + j + 1 > k:
        s -= heappop(sushi)
        l -= 1
    for new in T[i][1:]:
        if l + j + 1 >= k:
            s += new
            s -= heappushpop(sushi,new)
        else:
            s += new
            l += 1
            heappush(sushi, new)
    ans = max(ans, s + (j+1)**2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import *
n,q = map(int,input().split())
A = list(map(int,input().split()))
every2 = [[0]*(n//2 + 2) for _ in range(2)]
right = [0]*(n+1)

for i in range(n):
    odd = i&1
    every2[odd][i//2 + 1] = every2[odd][i//2] + A[i]
    right[i+1] = right[i] + A[-i-1]
# ans = [0]*q

def ok(y,x):
    M = A[-y]
    if M <= x:return False
    d = M - x
    m = x - d
    return bisect_left(A,m)+2*y-1 <= n

for i in range(q):
    X = int(input())
    W = bisect_right(A,X)
    top = n - W + 1
    bottom = 1
    while top - bottom > 1:
        mid = (top + bottom)//2
        if ok(mid,X):
            bottom = mid
        else:
            top = mid
    ans = right[bottom] + every2[1 - (n&1)][(n-1)//2 + 1 - bottom]
    print(ans)
# print('\n'.join(ans))


Fixed submission:
from bisect import *
import sys
input = sys.stdin.readline
n,q = map(int,input().split())
A = list(map(int,input().split()))
every2 = [[0]*(n//2 + 2) for _ in range(2)]
right = [0]*(n+1)

for i in range(n):
    odd = i&1
    every2[odd][i//2 + 1] = every2[odd][i//2] + A[i]
    right[i+1] = right[i] + A[-i-1]
# ans = [0]*q

def ok(y,x):
    M = A[-y]
    if M <= x:return False
    d = M - x
    m = x - d
    return bisect_left(A,m)+2*y-1 <= n

for i in range(q):
    X = int(input())
    W = bisect_right(A,X)
    top = n - W + 1
    bottom = 1
    while top - bottom > 1:
        mid = (top + bottom)//2
        if ok(mid,X):
            bottom = mid
        else:
            top = mid
    ans = right[bottom] + every2[1 - (n&1)][(n-1)//2 + 1 - bottom]
    print(ans)
# print('\n'.join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
dp = [0]*(W+1)
for i in range(N):
    w,v = map(int,input().split())
    for j in range(W-w+1)[::-1]:
        dp[j+w] = max(dp[j+w],dp[j] + v)
print(max(dp))


Fixed submission:
N,W = map(int,input().split())
dp = [0]*(W+1)
for i in range(N):
    w,v = map(int,input().split())
    for j in range(W-w+1)[::-1]:
        dp[j+w] = max(dp[j+w],dp[j] + v)
print(max(dp))
Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
dp = [0]*(W+1)
for i in range(N):
    w,v = map(int,input().split())
    for j in range(W-w+1)[::-1]:
        dp[j+w] = max(dp[j+w],dp[j] + v)
print(max(dp))


Fixed submission:
N,W = map(int,input().split())
dp = [0]+[W+1]*(N*10**3)
for i in range(N):
    w,v = map(int,input().split())
    for j in range(N*10**3+1-v)[::-1]:
        dp[j+v] = min(dp[j+v],dp[j]+w)
for i in range(N*10**3+1)[::-1]:
    if dp[i]<=W:
        print(i)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m = map(int,input().split())
path = [set() for _ in range(n)]
dp = [0]*n
for _ in range(m):
    x,y = map(int,input().split())
    path[x-1].add(y-1)
    dp[y-1] = -1

que = deque()
for i in range(n):
    if dp[i] == 0:
        que.append(i)
ans = 0
while que:
    p = que.popleft()
    for i in path[p]:
        que.append(i)
        dp[i] = max(dp[i], dp[p] + 1)
        ans = max(ans, dp[i])
print(ans)


Fixed submission:
from collections import deque
n,m = map(int,input().split())
path = [set() for _ in range(n)]
to = [0]*n
dp = [0]*n
for _ in range(m):
    x,y = map(int,input().split())
    path[x-1].add(y-1)
    to[y-1] += 1

que = deque()
for i in range(n):
    if to[i] == 0:
        que.append(i)
ans = 0
while que:
    p = que.popleft()
    for i in path[p]:
        to[i] -= 1
        if to[i] == 0:
            que.append(i)
        dp[i] = max(dp[i], dp[p] + 1)
        ans = max(ans, dp[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m = map(int,input().split())
path = [set() for _ in range(n)]
dp = [0]*n
for _ in range(m):
    x,y = map(int,input().split())
    path[x-1].add(y-1)
    dp[y-1] = -1

que = deque()
for i in range(n):
    if dp[i] == 0:
        que.append(i)
ans = 0
while que:
    p = que.popleft()
    for i in path[p]:
        que.append(i)
        dp[i] = max(dp[i], dp[p] + 1)
        ans = max(ans, dp[i])
print(ans)


Fixed submission:
from collections import deque
n,m = map(int,input().split())
path = [set() for _ in range(n)]
to = [0]*n
dp = [0]*n
for _ in range(m):
    x,y = map(int,input().split())
    path[x-1].add(y-1)
    to[y-1] += 1

que = deque()
for i in range(n):
    if to[i] == 0:
        que.append(i)
ans = 0
while que:
    p = que.popleft()
    for i in path[p]:
        to[i] -= 1
        if to[i] == 0:
            que.append(i)
        dp[i] = max(dp[i], dp[p] + 1)
        ans = max(ans, dp[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h,w = map(int,input().split())
a = [list(input()) for _ in range(h)]
mod = 10**9 +7

dp = [[0]*w for _ in range(h)]
dp[0][0] = 1
reach = [[False]*w for _ in range(h)]
que = deque(())

que.append((0,0))

while que:
    i,j = que.popleft()
    if i < h-1 and a[i+1][j] == '.':
        if dp[i+1][j] == 0:
            que.append((i+1,j))
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= mod
    if j < w-1 and a[i][j+1] == '.':
        if dp[i][j+1] == 0:
            que.append((i,j+1))
        dp[i][j+1] += dp[i][j]
        dp[i][j+1] %= mod
print(dp[h-1][w-1])


Fixed submission:
from collections import deque

h,w = map(int,input().split())
a = [list(input()) for _ in range(h)]
mod = 10**9 +7

dp = [[0]*w for _ in range(h)]
dp[0][0] = 1
reach = [[False]*w for _ in range(h)]
que = deque(())

que.append((0,0))

while que:
    i,j = que.popleft()
    if i < h-1 and a[i+1][j] == '.':
        if dp[i+1][j] == 0:
            que.append((i+1,j))
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= mod
    if j < w-1 and a[i][j+1] == '.':
        if dp[i][j+1] == 0:
            que.append((i,j+1))
        dp[i][j+1] += dp[i][j]
        dp[i][j+1] %= mod
print(dp[h-1][w-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline
mod = 10**9 + 7
n,k = map(int,input().split())
x = np.array([list(map(int,input().split())) for i in range(n)],dtype = np.int64)
# for i in ra
#  list(map(int,input().split())))
ans = np.eye(n,dtype = np.int64)
while k > 0:
    if k&1:
        ans = np.mod(np.dot(ans, x), mod)
        # ans = np.dot(ans, x)
    k = k >> 1
    x = np.mod(np.dot(x,x), mod)
    # x = np.dot(x,x)
res = 0
for i in range(n):
    for j in range(n):
        res += ans[i][j]
        res %= mod
print(res)


Fixed submission:
import sys
input = sys.stdin.readline
mod = 10**9 + 7
n,k = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
ans = [[0]*i +[1]+[0]*(n-i-1) for i in range(n)]

def dot(A,B):
    res = [[0]*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                res[i][j] += A[i][k]*B[k][j]
                res[i][j] %= mod
    return res

while k > 0:
    if k&1:
        ans = dot(ans, x)
    k = k >> 1
    x = dot(x,x)
res = 0
for i in range(n):
    for j in range(n):
        res += ans[i][j]
        res %= mod
print(res)
Buggy python submission (verdict: Runtime Error):
h,n = map(int,input().split())
h = [0]*n
for i in range(n):
    h[i] = int(input())
h.sort()
ans = float('inf')
for i in range(n-k):
    ans = min(ans,abs(h[i+k-1]-h[i])
print(ans)


Fixed submission:
n,k = map(int,input().split())

h = [0]*n

for i in range(n):

    h[i] = int(input())

h.sort()

ans = float('inf')

for i in range(n-k+1):

    ans = min(ans,abs(h[i+k-1]-h[i]))

print(ans)
Buggy python submission (verdict: Runtime Error):
abc = list(map(int,input()))
abc.sort()
abc[2] *= 10
print(sum(abc))

Fixed submission:
abc = list(map(int,input().split()))
abc.sort()
abc[2] *= 10
print(sum(abc))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n,m,q = map(int,input().split())
d = [{} for _ in range(n)]
for i in range(m):
    l,r = map(int,input().split())
    l -= 1
    r -= 1
    if r not in d[l].keys():
        d[l][r] = 0
    d[l][r] += 1
for i in range(n-1)[::-1]:
    for k,v in d[i+1].items():
        if k not in d[i]:d[i][k] = 0
        d[i][k] += v
ans = [0]*q
for i in range(q):
    P,Q = map(int,input().split())
    P -= 1
    Q -= 1
    for k,v in d[P].items():
        if k <= Q:
            ans[i] += v
print('\n'.join(str(i) for i in ans))


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

n,m,q = map(int,input().split())
d = [{} for _ in range(n)]
for i in range(m):
    l,r = map(int,input().split())
    l -= 1
    r -= 1
    if r not in d[l].keys():
        d[l][r] = 0
    d[l][r] += 1
for i in range(n-1)[::-1]:
    for k,v in d[i+1].items():
        if k not in d[i]:d[i][k] = 0
        d[i][k] += v
ans = [0]*q
for i in range(q):
    P,Q = map(int,input().split())
    P -= 1
    Q -= 1
    for k,v in d[P].items():
        if k <= Q:
            ans[i] += v
print('\n'.join(str(i) for i in ans))
Buggy python submission (verdict: Runtime Error):
from bisect import *
S = input()
mod = 10**9 + 7
A = []
B = []
C = []
X = []
q = 0
for i,s in enumerate(S):
    if s == 'A':
        A.append(i)
    elif s == 'B':
        B.append((i,0))
    elif s == 'C':
        C.append(i)
    else:
        X.append(i)
        B.append((i,1))
        q += 1

pow3 = [pow(3,q,mod),pow(3,q-1,mod),pow(3,q-2,mod),pow(3,q-3,mod)]
ans = 0
for b,flag in B:
    Al = bisect_left(A,b)
    Cr = (len(C) - bisect_right(C,b))
    Xl = bisect_left(X,b)
    Xr = (len(X) - bisect_right(X,b))
    ans += (Al*Cr%mod)*pow3[flag]%mod
    ans %= mod
    ans += (Al*Xr%mod + Xl*Cr%mod)*pow3[flag+1]%mod
    ans %= mod
    ans += (Xl*Xr%mod)*pow3[flag+2]%mod
print(ans)


Fixed submission:
from bisect import *
S = input()
mod = 10**9 + 7
A = []
B = []
C = []
X = []
q = 0
for i,s in enumerate(S):
    if s == 'A':
        A.append(i)
    elif s == 'B':
        B.append((i,0))
    elif s == 'C':
        C.append(i)
    else:
        X.append(i)
        B.append((i,1))
        q += 1

pow3 = [pow(3,q,mod),pow(3,max(0,q-1),mod),pow(3,max(0,q-2),mod),pow(3,max(0,q-3),mod)]
ans = 0
for b,flag in B:
    Al = bisect_left(A,b)
    Cr = (len(C) - bisect_right(C,b))
    Xl = bisect_left(X,b)
    Xr = (len(X) - bisect_right(X,b))
    ans += (Al*Cr%mod)*pow3[flag]%mod
    ans %= mod
    ans += (Al*Xr%mod + Xl*Cr%mod)*pow3[flag+1]%mod
    ans %= mod
    ans += (Xl*Xr%mod)*pow3[flag+2]%mod
print(ans)
Buggy python submission (verdict: Runtime Error):
a = mlist(map(int,input().split()))
a.sort()
print(a[2] - a[0])

Fixed submission:
a = list(map(int,input().split()))
a.sort()
print(a[2] - a[0])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
A = [j-i-1 for i,j in enumerate(A)]
top = max(A)
bottom = min(A)
def sad(b):
  ret=0
  for i in A:
    ret += abs(i-b)
  return ret
while top - bottom > 2:
  mid1 = (top + bottom*2)//3
  mid2 = (top*2 + bottom)//3
  if sad(mid1) < sad(mid2):
    top = mid2
  else:
    bottom = mid1
print(min(sad(bottom), sad((bottom+top)//2), sad(top)))


Fixed submission:
n = int(input())
A = list(map(int,input().split()))
A = [j-i-1 for i,j in enumerate(A)]
top = max(A)
bottom = min(A)
def sad(b):
  ret=0
  for i in A:
    ret += abs(i-b)
  return ret
while top - bottom > 2:
  mid1 = (top + bottom*2)//3
  mid2 = (top*2 + bottom)//3
  if sad(mid1) < sad(mid2):
    top = mid2
  else:
    bottom = mid1
print(min(sad(bottom), sad((bottom+top)//2), sad(top)))
Buggy python submission (verdict: Runtime Error):
n = input()
s = sum([int(i) for i in n])
if n%s == 0:
  print('Yes')
else:
  print('No')


Fixed submission:
n = input()
s = sum([int(i) for i in n])
if int(n)%s == 0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

ans = float('inf')
w_left = [0]
e_right = [0]*n

for i in range(1,n):
  if s[i-1] == 'W':
    w_left.append(w_left[i-1]+1)
  else :
    w_left.append(w_left[i-1])
      
for i in range(1,n):
  if s[n-i] == 'E':
    e_right[n-i-1] = e_right[n-i]+1
  else :
    e_right[n-i-1] = e_right[n-i]

for i in range(n):
    ans = min(ans , w_left[i]+e_right[i])
print(ans)


Fixed submission:
a,b = map(int,input().split())
print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

ans = float('inf')
w_left = [0]
e_right = [0]

for i in range(1,n):
  if s[i-1] == 'W':
    w_left.append(w_left[i-1]+1)
  else :
    w_left.append(w_left[i-1])
      
for i in range(1,n):
  if s[n-i] == 'E':
    e_right.insert(0,e_right[0]+1)
  else :
    e_right.insert(0,e_right[0])

for i in range(n):
    ans = min(ans , w_left[i]+e_right[i])
print(ans)

Fixed submission:
n = int(input())
s = input()

ans = float('inf')
w_left = [0]*n
e_right = [0]*n

for i in range(1,n):
  if s[i-1] == 'W':
    w_left[i] = w_left[i-1]+1
  else :
    w_left[i] = w_left[i-1]
      
for i in range(1,n):
  if s[n-i] == 'E':
    e_right[n-i-1] = e_right[n-i]+1
  else :
    e_right[n-i-1] = e_right[n-i]

for i in range(n):
    if ans > w_left[i]+e_right[i]:
        ans = w_left[i]+e_right[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
 
ans = float('inf')
 
for i in range(n):
  ans = min(ans,s[0:i].count('W')+s[i+1:n].count('E'))
print(ans)

Fixed submission:
n = int(input())
s = input()

ans = float('inf')
w_left = [0]*n
e_right = [0]*n

for i in range(1,n):
  if s[i-1] == 'W':
    w_left[i] = w_left[i-1]+1
  else :
    w_left[i] = w_left[i-1]
      
for i in range(1,n):
  if s[n-i] == 'E':
    e_right[n-i-1] = e_right[n-i]+1
  else :
    e_right[n-i-1] = e_right[n-i]

for i in range(n):
    if ans > w_left[i]+e_right[i]:
        ans = w_left[i]+e_right[i]
print(ans)

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

ans = float('inf')

for i in range(n):
  counter = 0
  for j in range(n):
    if j < i and s[j] == 'W':
      counter += 1
    if j > i and s[j] == 'E':
      counter += 1
  ans = min(ans,counter)
print(ans)

Fixed submission:
n = int(input())
s = input()

ans = float('inf')
w_left = [0]*n
e_right = [0]*n

for i in range(1,n):
  if s[i-1] == 'W':
    w_left[i] = w_left[i-1]+1
  else :
    w_left[i] = w_left[i-1]
      
for i in range(1,n):
  if s[n-i] == 'E':
    e_right[n-i-1] = e_right[n-i]+1
  else :
    e_right[n-i-1] = e_right[n-i]

for i in range(n):
    if ans > w_left[i]+e_right[i]:
        ans = w_left[i]+e_right[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
if abc(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d):
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c,d = map(int,input().split())
if abs(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = [list(input()) for i in range(h)]
s += s

def ok(array):
    for i in range(1,n):
        for j in range(i):
            if array[i][j] != array[j][i]:
                return False
    return True
ans = 0
for i in range(n-1):
    if ok(s[i:i+n]):
        ans += n
print(ans)


Fixed submission:
n = int(input())
s = [list(input()) for i in range(n)]
s += s

def ok(array):
    for i in range(1,n):
        for j in range(i):
            if array[i][j] != array[j][i]:
                return False
    return True
ans = 0
for i in range(n):
    if ok(s[i:i+n]):
        ans += n
print(ans)