Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = input()
a=0
z=0

for i in range(len(s)):
    if s[i]=="A":
        a = i
        break

for j in range(len(s)):
    if s[-j-1]=="Z":
        z = len(s)-j-1
		break
print(z-a+1)

Fixed submission:
s = input()
a=0
z=0

for i in range(len(s)):
    if s[i]=="A":
        a = i
        break

for j in range(len(s)):
    if s[-j-1]=="Z":
        z = len(s)-j-1
        break

print(z-a+1)
Buggy python submission (verdict: Runtime Error):
x=0
s_max = 0

n = int(input())
s = input()

for i in s:
    if i == "I":
        x += 1
    else:
        x -= 1
    x_max = max(x_max,x)

print(x_max)

Fixed submission:
x=0
x_max = 0

n = int(input())
s = input()

for i in s:
    if i == "I":
        x += 1
    else:
        x -= 1
    x_max = max(x_max,x)

print(x_max)
Buggy python submission (verdict: Runtime Error):
k,s=map(int,input().split())
ans=0
for i in range(k+1):
    for j in range(k+1):
        if 0<=(s-i-j)<=k:
            ans+=1
print(ans)


Fixed submission:
s = input()
ls = []
for i,j in enumerate(s):
    if i == 5 or i == 13:
        ls.append(" ")
    else:
        ls.append(j)
print("".join(ls))
Buggy python submission (verdict: Runtime Error):
k,s=map(int,input().split())
ans=0
for i in range(K+1):
    for j in range(K+1):
        if 0<=(s-i-j)<=K:
            ans+=1
print(ans)


Fixed submission:
k,s=map(int,input().split())
ans=0
for i in range(k+1):
    for j in range(k+1):
        if 0<=(s-i-j)<=k:
            ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
ls = [x for x in input().split()]

if ls[1]=="+":
    print(int(ls[0]+ls[2]))
else:
    print(int(ls[0]-ls[2]))



Fixed submission:
ls = [x for x in input().split()]

if ls[1]=="+":
    print(int(ls[0])+int(ls[2]))
else:
    print(int(ls[0])-int(ls[2]))
Buggy python submission (verdict: Runtime Error):
n,x = map(int,input().split())
a = list(map(int,input().split()))

cnt = 0

for i in range(1,n):
    if a[i-1]+a[i]<=x:
        pass
    else:
        if (a[i]+a[i-1])-x > a[i]
            a[i] = 0
            cnt += (a[i]+a[i-1])-x
        else:    
            cnt += (a[i]+a[i-1])-x
            a[i]-= (a[i]+a[i-1])-x

print(cnt)


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

cnt = 0

for i in range(n-1):
    if a[i]+a[i+1]<=x:
        pass
    else:
        if (a[i+1]+a[i])-x > a[i+1]:
            cnt += (a[i+1]+a[i])-x
            a[i+1] = 0

        else:
            cnt += (a[i+1]+a[i])-x
            a[i+1] -= (a[i+1]+a[i])-x

print(cnt)
Buggy python submission (verdict: Runtime Error):
def main():
    s = list(input())
    for i in range(len(s)):
        if s[i]=="C":
            idx = i
            break

    for j in range(idx,len(s)):
        if s[j]=="F":
            print("Yes")
            exit()

    print("No")

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    s = list(input())
    for i in range(len(s)):
        for j in range(i+1,len(s)):
            if s[i]=="C" and s[j]=="F":
                print("Yes")
                exit()
    print("No")

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    for i in range(len(s)):
        if s[i]=="C":
            idx = i
            break

    for j in range(idx,len(s)):
        if s[j]=="F":
            print("Yes")
            exit()

    print("No")

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    s = list(input())
    for i in range(len(s)):
        for j in range(i+1,len(s)):
            if s[i]=="C" and s[j]=="F":
                print("Yes")
                exit()
    print("No")

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    for i in range(len(s)):
        if s[i]=="C":
            idx = i
            break

    for i in range(idx,len(s)):
        if s[i]=="F":
            print("Yes")
            exit()

    print("No")

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    s = list(input())
    for i in range(len(s)):
        for j in range(i+1,len(s)):
            if s[i]=="C" and s[j]=="F":
                print("Yes")
                exit()
    print("No")

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    for i in range(len(s)):
        if s[i]=="C":
            idx = i
            break

    for i in range(idx+1,len(s)):
        if s[i]=="F":
            print("Yes")
            exit()

    print("No")

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    s = list(input())
    for i in range(len(s)):
        for j in range(i+1,len(s)):
            if s[i]=="C" and s[j]=="F":
                print("Yes")
                exit()
    print("No")

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
if __name__ =="__main__":
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]

    now_t,now_a = ls[0]

    for i in range(1,n):
        x = max([~-now_t/ls[i][0] +1 ,~-now_a/ls[i][1] +1])
        now_t,now_a = x*ls[i][0],x*ls[i][1]
    print(now_t+now_a)

Fixed submission:
if __name__ =="__main__":
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]

    now_t,now_a = ls[0]

    for i in range(1,n):
        x = max([~-now_t//ls[i][0] +1 ,~-now_a//ls[i][1] +1])
        now_t,now_a = x*ls[i][0],x*ls[i][1]
    print(now_t+now_a)

Buggy python submission (verdict: Runtime Error):
if __name__ =="__main__":
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]

    now_t,now_a = ls[0]

    for i in range(1,n):
        x = max([~-now_t/ls[i][0]+1 ,~-now_a/ls[i][1]+1])
        now_t,now_a = x*ls[i][0],x*ls[i][1]
    print(now_t+now_a)

Fixed submission:
if __name__ =="__main__":
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]

    now_t,now_a = ls[0]

    for i in range(1,n):
        x = max([~-now_t//ls[i][0] +1 ,~-now_a//ls[i][1] +1])
        now_t,now_a = x*ls[i][0],x*ls[i][1]
    print(now_t+now_a)
Buggy python submission (verdict: Runtime Error):
n = int(input())

c = 0
for i in range(n+1)
    c +=i
print(c)

Fixed submission:
n = int(input())

c = 0
for i in range(n+1):
    c +=i
print(c)
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
    vector<int> a(3);

    rep(i,3){
        cin >> a[i];
    }

    sort(a.begin(),a.end());

    if (a[0]!=5){
        cout << "NO" << endl;
        exit(0);
    }
    if (a[1]!=5){
        cout << "NO" << endl;
        exit(0);
    }
    if (a[2]!=7){
        cout << "NO" << endl;
        exit(0);
    }

    cout << "YES";
    return 0;
}

Fixed submission:
ls = list(map(int,input().split()))
ls.sort()
 
if ls[0]==5 and ls[1]==5 and ls[2]==7:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N ,K = map(int, input().split())
A = list(map(int, input().split()))

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

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

B = [0]*(N+1)

b = 0
for i, a in enumerate(A):
    b += a - 1
    b %= K
    B[i+1] = b

Q = {}
X = 0

for i, b in enumerate(B):
    if i>=K:
        Q[B[i-K]] -= 1
 
    if b in Q:
        X += Q[b]
        Q[b] += 1
    else:
        Q[b] = 1

print(X)
Buggy python submission (verdict: Runtime Error):

from scipy.sparse.csgraph import floyd_warshall as fw
N, M, L = map(int, input().split())

# 町間の道の長さのマトリックスを初期値無限で作成
S = [[float("INF") for i in range(N)] for i in range(N)]

# 町間の道の長さ情報をマトリックスに入力
for i in range(M):
    a, b, c = map(int,input().split())
    S[a-1][b-1] = c
    S[b-1][a-1] = c


# ワーシャルフロイド法で最短距離のマップを生成
Sf = fw(S)

T = [[float("INF")for i in range(N)] for i in range(N)]

# 町間を補給なしで通行可能な場合は1、不可能な場合はINFとしてマトリックスを作成
# （町間距離がタンク容量より大きい場合は通行不可）
for i in range(N):
    for j in range(N):
        if Sf[i][j] <= L:
            T[i][j] = 1

# ワーシャルフロイド法で町間移動可否のマップを生成
# すぐ上のfor文で、補給なしで移動できない町間の移動コストはINFにしたが、
# この処理で複数回の補給を行えば移動できる距離を
Tf = fw(T)

for i in range(int(input())):
    a, b = map(int, input().split())
    if Tf[a-1][b-1] != float("INF"):
        print(int(Tf[a-1][b-1])-1)
    else:
        print(-1)


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

ans = A-B*2
if ans<0:
    ans = 0

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

L.sort()

cnt = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        for s in range(N-1, j, -1):
            c = L[s]
            if L[s]<L[i]+L[j]:
                cnt += s - j
                break
print(cnt)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

L.sort()

cnt = 0

# 2番目に長い棒bを固定
for b in range(N):
    # bより短い棒aを一つずつ探索
    for a in range(b):
        ab = L[a] + L[b]
        # 二分探索でa+bより短い棒（c<a+bが成り立つc）の範囲を求める
        r = bisect_left(L, ab)
        # cの範囲のうちbの範囲を除外して、cの本数を求める
        cnt += r - (b + 1)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())
L = list(map(int, input().split()))

cnt = 0
for a, b, c in list(itertools.combinations(L,3)):
    if a<b+c and b<a+c and c<a+b:
        cnt += 1

print(cnt)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

L.sort()

cnt = 0

# 2番目に長い棒bを固定
for b in range(N):
    # bより短い棒aを一つずつ探索
    for a in range(b):
        ab = L[a] + L[b]
        # 二分探索でa+bより短い棒（c<a+bが成り立つc）の範囲を求める
        r = bisect_left(L, ab)
        # cの範囲のうちbの範囲を除外して、cの本数を求める
        cnt += r - (b + 1)

print(cnt)
Buggy python submission (verdict: Runtime Error):
N, M, L = map(int, input().split())

# 町間の道の長さのマトリックスを初期値無限で作成
S = [[float("INF") for i in range(N)] for i in range(N)]

# 町間の道の長さ情報をマトリックスに入力
for i in range(M):
    a, b, c = map(int,input().split())
    S[a-1][b-1] = c
    S[b-1][a-1] = c

# ワーシャルフロイド法で最短距離のマップを生成
Sf = fw(S)

T = [[float("INF")for i in range(N)] for i in range(N)]

# 町間を補給なしで通行可能な場合は1、不可能な場合はINFとしてマトリックスを作成
# （町間距離がタンク容量より大きい場合は通行不可）
for i in range(N):
    for j in range(N):
        if Sf[i][j] <= L:
            T[i][j] = 1

# ワーシャルフロイド法で町間移動可否のマップを生成
# すぐ上のfor文で、補給なしで移動できない町間の移動コストはINFにしたが、
# この処理で複数回の補給を行えば移動できる距離を
Tf = fw(T)

for i in range(int(input())):
    a, b = map(int, input().split())
    if Tf[a-1][b-1] != float("INF"):
        print(int(Tf[a-1][b-1])-1)
    else:
        print(-1)

Fixed submission:

from scipy.sparse.csgraph import floyd_warshall as fw
N, M, L = map(int, input().split())

# 町間の道の長さのマトリックスを初期値無限で作成
S = [[float("INF") for i in range(N)] for i in range(N)]

# 町間の道の長さ情報をマトリックスに入力
for i in range(M):
    a, b, c = map(int,input().split())
    S[a-1][b-1] = c
    S[b-1][a-1] = c


# ワーシャルフロイド法で最短距離のマップを生成
Sf = fw(S)

T = [[float("INF")for i in range(N)] for i in range(N)]

# 町間を補給なしで通行可能な場合は1、不可能な場合はINFとしてマトリックスを作成
# （町間距離がタンク容量より大きい場合は通行不可）
for i in range(N):
    for j in range(N):
        if Sf[i][j] <= L:
            T[i][j] = 1

# ワーシャルフロイド法で町間移動可否のマップを生成
# すぐ上のfor文で、補給なしで移動できない町間の移動コストはINFにしたが、
# この処理で複数回の補給を行えば移動できる距離を
Tf = fw(T)

for i in range(int(input())):
    a, b = map(int, input().split())
    if Tf[a-1][b-1] != float("INF"):
        print(int(Tf[a-1][b-1])-1)
    else:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):



from scipy.sparse.csgraph import floyd_warshall as fw

N, M, L = map(int, input().split())

S = [[float("inf") for i in range(N)] for i in range(N)]

for i in range(M):
    a, b, c = map(int, input().split())
    S[a-1][b-1] = c
    S[b-1][a-1] = c

Sdist = fw(S)

for i in range(N):
    for j in range(N):
        if Sdist[i][j]>L:
            Sdist[i][j] = float("inf")
        else:
            Sdist[i][j] = 1

Ssup = fw(Sdist)

Q = int(input())

for i in range(Q):
    s, t = map(int, input().split())
    if Ssup[s-1][t-1]==float("inf"):
        print(-1)
    else:
        print(int(Ssup[s-1][t-1]-1))

Fixed submission:

from scipy.sparse.csgraph import floyd_warshall as fw
N, M, L = map(int, input().split())

# 町間の道の長さのマトリックスを初期値無限で作成
S = [[float("INF") for i in range(N)] for i in range(N)]

# 町間の道の長さ情報をマトリックスに入力
for i in range(M):
    a, b, c = map(int,input().split())
    S[a-1][b-1] = c
    S[b-1][a-1] = c


# ワーシャルフロイド法で最短距離のマップを生成
Sf = fw(S)

T = [[float("INF")for i in range(N)] for i in range(N)]

# 町間を補給なしで通行可能な場合は1、不可能な場合はINFとしてマトリックスを作成
# （町間距離がタンク容量より大きい場合は通行不可）
for i in range(N):
    for j in range(N):
        if Sf[i][j] <= L:
            T[i][j] = 1

# ワーシャルフロイド法で町間移動可否のマップを生成
# すぐ上のfor文で、補給なしで移動できない町間の移動コストはINFにしたが、
# この処理で複数回の補給を行えば移動できる距離を
Tf = fw(T)

for i in range(int(input())):
    a, b = map(int, input().split())
    if Tf[a-1][b-1] != float("INF"):
        print(int(Tf[a-1][b-1])-1)
    else:
        print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

B = []
for i in range(1, N+1):
    B.append(A.index(i)+1)

import numpy as np
C = str(np.array(B))
print(C[1:-1])


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

B = [0] * N
for i, a in enumerate(A):
    B[a-1] = i + 1

print(*B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
for i in range(N):
    B = A.copy()
    del B[i]
    print(max(B))

Fixed submission:
N = int(input())

m0 = 1
m1 = 1
max_i = []
for i in range(N):
    a = int(input())
    if a > m0:
        m1 = m0
        m0 = a
        max_i = []
        max_i.append(i)
    elif a == m0:
        m1 = a
    elif a > m1:
        m1 = a
for i in range(N):
    if i in max_i:
        print(m1)
    else:
        print(m0)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    
    
B = []
B.append(A[0])
pre = A[0]
cnt = 0
for i in range(1, N):
    if A[i] > B[cnt] and A[i] > pre:
        pre = A[i]
    elif A[i] <= pre:
        if A[i] <= B[cnt]:
            pre = A[i]
            B.append(A[i])
            cnt += 1
        else:
            del B[-1]
            if A[i] > max(B):
                pre = A[i]
            else:
                cnt += 1
                pre = A[i]
print(cnt+1)

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

A = [0] + A
for i in range(N//2, 0, -1):
    A[i] = sum(A[i::i])%2
ans = [i for i in range(N+1) if A[i]]
print(len(ans))
print(*ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    
    
B = []
B.append(A[0])
pre = A[0]
cnt = 0
for i in range(1, len(A)):
    if A[i] > B[cnt] and A[i] > pre:
        pre = A[i]
    elif A[i] <= pre:
        if A[i] <= B[cnt]:
            pre = A[i]
            B.append(A[i])
            cnt += 1
        else:
            del B[-1]
            if A[i] > max(B):
                pre = A[i]
            else:
                cnt += 1
                pre = A[i]
print(cnt+1)

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

A = [0] + A
for i in range(N//2, 0, -1):
    A[i] = sum(A[i::i])%2
ans = [i for i in range(N+1) if A[i]]
print(len(ans))
print(*ans)
Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())
C = []
flag = False
for i in range(L, R+1):
    if i%2019==0:
        flag = True
        break
    else:
        C.append(i)
        
if flag:
    print(0)
else:
    ans = 4080400
    for x, y in list(itertools.combinations(C, 2)):
        if (x*y)%2019<ans:
            ans = (x*y)%2019
    print(ans)

Fixed submission:
L, R = map(int, input().split())
C = []
flag = False
for i in range(L, R+1):
    if i%2019==0:
        flag = True
        break
    else:
        C.append(i)
        
if flag:
    print(0)
else:
    import itertools
    ans = 4080400
    for x, y in list(itertools.combinations(C, 2)):
        if (x*y)%2019<ans:
            ans = (x*y)%2019
    print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - D_s
if A%D==0:
    D_cnt += 1

import math
lcm = (C * D) // math.gcd(C, D)

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)

Fixed submission:
A, B, C, D = map(int, input().split())

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - D_s
if A%D==0:
    D_cnt += 1

import fractions
lcm = (C * D) // fractions.gcd(C, D)

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)

Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - C_s
if A%C==0:
    D_cnt += 1

import math
lcm = (C * D) // math.gcd(C, D)

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)

Fixed submission:
A, B, C, D = map(int, input().split())

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - D_s
if A%D==0:
    D_cnt += 1

import fractions
lcm = (C * D) // fractions.gcd(C, D)

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

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

while True:
    if min(A) == sum(A):
        break
    minA = A.index(min(A))
    maxA = A.index(max(A))
    A[maxA] = max(A)%min(A)
    if A[maxA]==0:
        A.pop(maxA)
print(min(A))





Fixed submission:
import numpy as np

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

B = list(set(A))
B.sort()
C = np.asarray(B)

while(len(C)>1):
    t = C[0]
    C = np.append(C[1:]%t,t)
    C = list(set(C))
    C.sort()
    if C[0]==0:
        C = np.asarray(C[1:])
    else:
        C = np.asarray(C)

print(C[0])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = list(map(int, input().split()))

X.sort()
Y = []

for i in range(M-1):
    Y.append(X[i+1] - X[i])

for i in range(N-1):
    idx = Y.index(max(Y))
    Y[idx] = 0
    
print(sum(Y))

Fixed submission:
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

ans = 0
if N>=M:
    pass
else:
    X_diff = []
    for i in range(len(X)-1):
        X_diff.append(X[i+1]-X[i])
    X_diff.sort()
    ans = 0
    for i in range(M-N):
        ans += X_diff[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

H = [int(input()) for i in range(N)]

Ha = np.sort(H)
Hd = Ha[1:] - Ha[:-1]

ans = 10**9
for i in range(N-K+1):
    if sum(Hd[i:i+K-1]) < ans:
        ans = sum(Hd[i:i+K-1])
print(ans)

Fixed submission:
N, K = map(int, input().split())
H = [int(input()) for i in range(N)]

H.sort()
ans = 10**9
for i in range(N-K+1):
    if (H[i+K-1]-H[i] < ans):
        ans = H[i+K-1]-H[i]

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

ans = float('inf')

for i in range(N):
    cnt_w = S[:i].count('W')
    cnt_e = S[i:].count('E')
    temp = cnt_w + cnt_e
    ans = min(ans, temp)

print(ans)


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

e = S.count('E')
w = 0
ans = e

for s in S:
    if s=='E':
        e -= 1
    elif s=='W':
        w += 1
    ew = e + w
    ans = min(ans, ew)

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())

s_list = list(set(s))
s_list.sort()

ans = []

def pack_in_dict_order(s_in):
    ans.append(s_in)
    if len(ans)==K:
        pass
    else:
        for s_l in s_list:
            temp = s_in + s_l
            if temp in s:
                pack_in_dict_order(temp)

for s_in in s_list:
    pack_in_dict_order(s_in)

print(ans[K-1])

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

s_list = list(set(s))
s_list.sort()

ans = []

def pack_in_dict_order(s_in):
    ans.append(s_in)
    if len(ans)<K:
        for s_l in s_list:
            temp = s_in + s_l
            if temp in s:
                pack_in_dict_order(temp)

for s_in in s_list:
    pack_in_dict_order(s_in)

print(ans[K-1])
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())

Y //= 1000
xmax = Y//10
flag = True

for x in range(xmax, -1, -1):
    if flag==False:
        break
    for y in range(N-x, -1, -1):
        if 9*x + 6*y == Y - N:
            xans = x
            yans = y
            zans = N - x - y
            flag = False
            break

print(xans, yans, zans)

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

aMax = Y//10000

flag = False

for i in range(aMax+1):
    for j in range(N-i+1):
        if i*10000 + j*5000 + (N-i-j)*1000 == Y:
            a = i
            b = j
            c = N-i-j
            flag = True
            break
    if flag:
        break
            
if flag:
    print(a, b, c)
else:
    print(-1, -1, -1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

cnt = 0
for a in A:
    for b in B:
        if b <= a:
            pass
        else:
            for c in C:
                if c <= b:
                    pass
                else:
                    cnt += 1

print(cnt)

Fixed submission:
import numpy as np

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

An = np.array(A)
Bn = np.array(B)
Cn = np.array(C)

An.sort()
Bn.sort()
Cn = -Cn
Cn.sort()

AB = np.searchsorted(An,Bn,side='left')
CB = np.searchsorted(Cn,-Bn,side='left')

print((AB*CB).sum())
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

print(len(A))

Fixed submission:


N = int(input())

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

B = set()

for a in A:
    if a in B:
        B.remove(a)
    else:
        B.add(a)

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

ans = float('inf')
for i in range(1, N):
    x = sum(A[:i])
    y = sum(A[i:])
    d = abs(x-y)
    ans = min(ans, d)

print(ans)

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

ans = float('inf')
s = sum(A)
x = A[0]
y = s - x
d = abs(x-y)
ans = min(ans, d)

for i in range(1, N-1):
    x += A[i]
    y = s - x
    d = abs(x-y)
    ans = min(ans, d)

print(ans)