Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
l = list(map(int,input().split()))
ans = 100000000000000
S = sum(l)
for i in range(N):
  x = x - l[i]
  ans = min(ans, abs(x - (S - x)))
 
print(ans)

Fixed submission:
N = int(input())
l = list(map(int,input().split()))
ans = 100000000000000
x = 0
S = sum(l)
for i in range(N-1):
  #print("l["+str(i)+"]="+str(l[0]))
  x = x + l[i]
  #print(x,S-x)
  ans = min(ans, abs(x - (S - x)))
  #print(ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
l = list(map(int,input().split()))
ans = 100000000000000
s = sum(l)
for i in range(N):
  x = x - l[i]
  ans = min(ans, abs(x - (S - x)))
 
print(ans)

Fixed submission:
N = int(input())
l = list(map(int,input().split()))
ans = 100000000000000
x = 0
S = sum(l)
for i in range(N-1):
  #print("l["+str(i)+"]="+str(l[0]))
  x = x + l[i]
  #print(x,S-x)
  ans = min(ans, abs(x - (S - x)))
  #print(ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = list(map(int,input().split()))
#print(l,l[:1],l[1:])
ans = 100000000000000
s = sum(l)
for i in range(1,N):
  #print(sum(l[:i]),sum(l[i:]))
  #dif = abs(sum(l[:i])-sum(l[i:]))
  ans = min(ans, abs(s - 2*sum(l[i:])))
 
print(ans)

Fixed submission:
N = int(input())
l = list(map(int,input().split()))
ans = 100000000000000
x = 0
S = sum(l)
for i in range(N-1):
  #print("l["+str(i)+"]="+str(l[0]))
  x = x + l[i]
  #print(x,S-x)
  ans = min(ans, abs(x - (S - x)))
  #print(ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = list(map(int,input().split()))
#print(l,l[:1],l[1:])
ans = []
for i in range(1,N):
  #print(sum(l[:i]),sum(l[i:]))
  #dif = abs(sum(l[:i])-sum(l[i:]))
  dif = abs(sum(l) - 2*sum(l[i:]))
  ans.append(dif)

print(min(ans))

Fixed submission:
N = int(input())
l = list(map(int,input().split()))
ans = 100000000000000
x = 0
S = sum(l)
for i in range(N-1):
  #print("l["+str(i)+"]="+str(l[0]))
  x = x + l[i]
  #print(x,S-x)
  ans = min(ans, abs(x - (S - x)))
  #print(ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = list(map(int,input().split()))
#print(l,l[:1],l[1:])
ans = []
for i in range(1,N):
  #print(sum(l[:i]),sum(l[i:]))
  dif = abs(sum(l[:i])-sum(l[i:]))
  ans.append(dif)

print(min(ans))

Fixed submission:
N = int(input())
l = list(map(int,input().split()))
ans = 100000000000000
x = 0
S = sum(l)
for i in range(N-1):
  #print("l["+str(i)+"]="+str(l[0]))
  x = x + l[i]
  #print(x,S-x)
  ans = min(ans, abs(x - (S - x)))
  #print(ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))
l = [0]*(10**5+1)
for i in range(N):
  a, b = list(map(int,input().split()))
  l[a] += b 
  
for j in range(1,int(len(l))+1):
  if K >= l[j]:
    K -= l[j]
  else:
    print(j)
    break

Fixed submission:
N,K = list(map(int,input().split()))
l = [0]*(10**5+1)
for i in range(N):
  a, b = list(map(int,input().split()))
  l[a] += b 
  
for j in range(1,int(len(l))+2):
  if K > l[j]:
    K -= l[j]
  else:
    print(j)
    break
Buggy python submission (verdict: Time Limit Exceeded):
K, S = list(map(int,input().split()))
count = 0
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      if i+j+k == S:
        count += 1
print(count)            

Fixed submission:
K, S = list(map(int,input().split()))
count = 0
for i in range(K+1):
  for j in range(K+1):
    if 0<=S-i-j and S-i-j<=K:
        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from collections import defaultdict
import math

def combination(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N = int(input())
L = defaultdict(int)
ans = 0
for _ in range(N):
    s = sorted(list(input()))
    L[s] += 1

for c in L.items():
    ans += combination(c, 2)
print(ans)

Fixed submission:
from collections import Counter
from collections import defaultdict
import math

def combination(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N = int(input())
L = defaultdict(int)
ans = 0
for _ in range(N):
    s = sorted(list(input()))
    L[str(s)] += 1

for c in L.values():
    if c > 1:
        ans += combination(c, 2)
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
from collections import defaultdict
import math

def combination(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N = int(input())
L = defaultdict(int)
ans = 0
for _ in range(N):
    s = sorted(list(input()))
    L[s] += 1

for c in L.items():
    ans += combination(c)
print(ans)

Fixed submission:
from collections import Counter
from collections import defaultdict
import math

def combination(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N = int(input())
L = defaultdict(int)
ans = 0
for _ in range(N):
    s = sorted(list(input()))
    L[str(s)] += 1

for c in L.values():
    if c > 1:
        ans += combination(c, 2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from collections import deque
import math

def combination(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N = int(input())
que = deque()
for _ in range(N):
    s = input()
    que.append(Counter(s))

ans = 0
while len(que):
    c1 = que.pop()
    num = 0
    for c2 in list(que):
       if c1 == c2:
            num += 1
            que.remove(c2)
    if num > 0:
        ans += combination(num+1, 2)
print(ans)

Fixed submission:
from collections import Counter
from collections import defaultdict
import math

def combination(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

N = int(input())
L = defaultdict(int)
ans = 0
for _ in range(N):
    s = sorted(list(input()))
    L[str(s)] += 1

for c in L.values():
    if c > 1:
        ans += combination(c, 2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N = int(input())
A = list(map(int, input().split()))
que = deque([0]*N)
bn = 0
for i in range(N, 0, -1):
    nn = 0
    for j in range(2*i, N+1, i):
        nn += que[j-1]

    if nn % 2 != A[i-1]:
        que[i-1] = 1

M = sum(que)
print(sum(que))
if M != 0:
    ans = []
    flg = False
    for i, n in enumerate(que):
        if flg:
            print(' ', end='')
        if n == 1:
            print(i+1, end='')
        flg = True

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
num_l = [0]*N
bn = 0
for i in range(N, 0, -1):
    nn = 0
    for j in range(2*i, N+1, i):
        nn += num_l[j-1]

    if nn % 2 != A[i-1]:
        num_l[i-1] = 1

M = sum(num_l)
print(M)
if M != 0:
    ans = []
    flg = False
    for i, n in enumerate(num_l):
        if flg:
            print(' ', end='')
        if n == 1:
            print(i+1, end='')
        flg = True

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N = int(input())
A = list(map(int, input().split()))
que = deque([0]*N)
bn = 0
for i in range(N, 0, -1):
    nn = 0
    for j in range(2*i, N+1, i):
        nn += que[j-1]

    if nn % 2 == A[i-1]:
        que[i-1] = 0
    else:
        que[i-1] = 1

M = sum(que)
print(sum(que))
if M != 0:
    ans = []
    for i, n in enumerate(que):
        if n == 1:
            ans.append(i+1)
    print(' '.join(map(str, ans)))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
num_l = [0]*N
bn = 0
for i in range(N, 0, -1):
    nn = 0
    for j in range(2*i, N+1, i):
        nn += num_l[j-1]

    if nn % 2 != A[i-1]:
        num_l[i-1] = 1

M = sum(num_l)
print(M)
if M != 0:
    ans = []
    flg = False
    for i, n in enumerate(num_l):
        if flg:
            print(' ', end='')
        if n == 1:
            print(i+1, end='')
        flg = True
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

A_matrix = []
for i in range(N):
    m = [0] * N
    if i != N - 1:
        m[i] = m[i+1] = 0.5
    else:
        m[i] = m[0] = 0.5
    A_matrix.append(m)

A_matrix = np.array(A_matrix)
A = A.T
A_inv = np.linalg.inv(A_matrix)
ans = np.dot(A_inv, A)
print(" ".join(str(int(n)) for n in ans))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
X = [0] * N
X[0] = sum(A) - 2*(sum(A[1::2]))
for i in range(1, N):
    X[i] = 2*A[i-1] - X[i-1]
print(' '.join(str(x) for x in X))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

A_matrix = []
for i in range(N):
    m = [0] * N
    if i != N - 1:
        m[i] = m[i+1] = 0.5
    else:
        m[i] = m[0] = 0.5
    A_matrix.append(m)

A_matrix = np.array(A_matrix)
A = A.T
A_inv = np.linalg.inv(A_matrix)
ans = np.dot(A_inv, A)
ans = ans.astype(int)
print(" ".join(str(n) for n in ans))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
X = [0] * N
X[0] = sum(A) - 2*(sum(A[1::2]))
for i in range(1, N):
    X[i] = 2*A[i-1] - X[i-1]
print(' '.join(str(x) for x in X))
Buggy python submission (verdict: Runtime Error):
from collections import deque

N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
O = min(N, K)
for i in range(O+1):
    for j in range(O-i+1):
        if i + j > O:
            break
        DV = deque(V)
        S = 0
        nums = []
        for _ in range(i):
            nums.append(DV.popleft())
        for _ in range(j):
            nums.append(DV.pop())
        nums.sort()
        for n in range(min(K-i-j, len(nums))):
            if nums[n] >= 0:
                break
            del nums[n]
        ans = max(ans, sum(nums))
print(ans)

Fixed submission:
from collections import deque

N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
O = min(N, K)
for i in range(O+1):
    for j in range(O-i+1):
        if i + j > O:
            break
        DV = deque(V)
        S = 0
        nums = []
        for _ in range(i):
            nums.append(DV.popleft())
        for _ in range(j):
            nums.append(DV.pop())
        nums.sort()
        S = sum(nums)
        for n in range(min(K-i-j, len(nums))):
            if nums[n] >= 0:
                break
            S -= nums[n]
        ans = max(ans, S)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
ans = 0
sqi = math.sqrt(N)
for i in range(1, int(sqi)+1):
    if (N-i)%i == 0:
        m = (N-i)//i
        if N//m == N%m:
        	ans += (N-i)//i
print(ans)

Fixed submission:
import math

N = int(input())
ans = 0
ms = set()
sqi = math.sqrt(N)
for i in range(1, int(sqi)+1):
    if N % i == 0:
        ms.add(i-1)
        ms.add(N//i-1)
for m in ms:
    if m <= 0:
        continue
    if N//m == N%m:
        ans += m
print(ans)

Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
ans = 0
sqi = math.sqrt(N)
for i in range(1, int(sqi)+1):
    if (N-i)%i == 0:
        m = (N-1)//i
        if N//m == N%m:
        	ans += (N-i)//i
print(ans)

Fixed submission:
import math

N = int(input())
ans = 0
ms = set()
sqi = math.sqrt(N)
for i in range(1, int(sqi)+1):
    if N % i == 0:
        ms.add(i-1)
        ms.add(N//i-1)
for m in ms:
    if m <= 0:
        continue
    if N//m == N%m:
        ans += m
print(ans)
Buggy python submission (verdict: Runtime Error):
9
education
7


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

for i in range(N):
    if i == K-1:
        continue
    if S[i] != S[K-1]:
        S = S[:i] + '*' + S[i+1:]

print(S)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
capa = []
for i in range(5):
    capa.append(int(input()))

num_h = [N, 0, 0, 0, 0, 0]

i = 0
while num_h[5] < N:
    for j in range(5, 0, -1):
        if num_h[j-1] <= 0:
            continue
        if num_h[j-1] >= capa[j-1]:
            num_h[j-1] -= capa[j-1]
            num_h[j] += capa[j-1]
        else:
            num_h[j] += num_h[j-1]
            num_h[j-1] = 0
    i += 1

print(i)

Fixed submission:
import math
N = int(input())
capa = []
for i in range(5):
    capa.append(int(input()))

num_h = [N, 0, 0, 0, 0, 0]
print(math.ceil(N / min(capa)) + 4)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
S = input()
l = []
for i in range(Q):
    a, b = map(int, input().split())
    num = 0
    for i in range(a-1, b-1):
        if S[i] == 'A' and S[i+1] == 'C':
            num += 1
    print(num)

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

pos = [0] * N
i = 0
while i < N-1:
    if S[i] == 'A':
        if S[i+1] == 'C':
            pos[i+1] = 1
    i += 1

nums = [0] * (N+1)
for i in range(1, N+1):
    nums[i] += nums[i-1] + pos[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    print(nums[r]-nums[l])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
S = input()
l = []
for i in range(Q):
    a, b = map(int, input().split())
    ps = S[a-1: b]
    num = ps.count('AC')
    print(num)

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

pos = [0] * N
i = 0
while i < N-1:
    if S[i] == 'A':
        if S[i+1] == 'C':
            pos[i+1] = 1
    i += 1

nums = [0] * (N+1)
for i in range(1, N+1):
    nums[i] += nums[i-1] + pos[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    print(nums[r]-nums[l])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
l = []
for i in range(Q):
    a, b = map(int, input().split())
    ps = S[a-1: b]
    num = ps.count('AC')
    print(num)


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

pos = [0] * N
i = 0
while i < N-1:
    if S[i] == 'A':
        if S[i+1] == 'C':
            pos[i+1] = 1
    i += 1

nums = [0] * (N+1)
for i in range(1, N+1):
    nums[i] += nums[i-1] + pos[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    print(nums[r]-nums[l])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
l = []
for i in range(Q):
    l.append(list(map(int, input().split())))

ans = []
for li in l:
    ps = S[li[0]-1:li[1]]
    num = 0
    for e1, e2 in zip(ps, ps[1:]):
        if e1 == 'A' and e2 == 'C': 
            num += 1
    print(num)

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

pos = [0] * N
i = 0
while i < N-1:
    if S[i] == 'A':
        if S[i+1] == 'C':
            pos[i+1] = 1
    i += 1

nums = [0] * (N+1)
for i in range(1, N+1):
    nums[i] += nums[i-1] + pos[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    print(nums[r]-nums[l])

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

N, Q = map(int, input().split())
S = input()
l = []
for i in range(Q):
    l.append(list(map(int, input().split())))

ans = []
for li in l:
    ps = S[li[0]-1:li[1]]
    acs = re.findall('AC', ps)
    print(len(acs))

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

pos = [0] * N
i = 0
while i < N-1:
    if S[i] == 'A':
        if S[i+1] == 'C':
            pos[i+1] = 1
    i += 1

nums = [0] * (N+1)
for i in range(1, N+1):
    nums[i] += nums[i-1] + pos[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    print(nums[r]-nums[l])
Buggy python submission (verdict: Runtime Error):
N = int(input())
b = list(map(int, input().split()))

a = []
index = -1
n = N
while len(b):
    for i in range(n):
        if i+1 == b[i]:
            index = i
    if index > -1:
        a.insert(0, b.pop(index))
        n -= 1

if len(a):
    for e in a:
        print(e)
else:
    print(index)

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

a = []
n = N
while len(b):
    index = -1
    for i in range(n):
        if i+1 == b[i]:
            index = i
    if index > -1:
        a.insert(0, b.pop(index))
        n -= 1
    elif index == -1:
        print(index)
        quit()

for e in a:
    print(e)
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())

sum = 0
for i in range(A, B+1):
    sum = sum ^ i

print(sum)


Fixed submission:
def F0_N(N):
  if N % 4 == 0:
  	return N
  elif N % 4 == 1:
    return 1
  elif N % 4 == 2:
     return N + 1
  elif N % 4 == 3:
     return 0

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

print(F0_N(A-1) ^ F0_N(B))
Buggy python submission (verdict: Runtime Error):
S = input()

nums = []
for s in S:
    nums.append(int(s))

count = 0
i = 0
while i < len(nums)-1:
    if nums[i] != nums[i+1]:
        nums.pop(i+1)
        nums.pop(i)
        count += 1
        i -= 1
        continue
    i += 1

print(count*2)


Fixed submission:
S = input()

nums = []
for s in S:
    nums.append(int(s))

count = 0
i = 0
while i < len(nums)-1:
    if nums[i] != nums[i+1]:
        nums.pop(i+1)
        nums.pop(i)
        count += 1
        if i != 0:
            i -= 1
        continue
    i += 1

print(count*2)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

N = int(input())
Ai = list(map(int, input().split()))
if Ai == [Ai[0]] * len(Ai):
    print(Ai[0])
    quit()

i = 1
min = 1000000000
for a in Ai:
    for a2 in Ai[i:]:
        a_gcd = fractions.gcd(a, a2)
        if min > a_gcd:
            min = a_gcd
            if min <= 2:
                print(min)
                quit()
    i += 1

print(min)


Fixed submission:
import fractions

N = int(input())
Ai = list(map(int, input().split()))
if Ai == [Ai[0]] * len(Ai):
    print(Ai[0])
    quit()

#Ai.sort()

i = 1
min = 1000000000
a = Ai[0]
for a2 in Ai[1:]:
    a_gcd = fractions.gcd(a, a2)
    if min > a_gcd:
        min = a_gcd
        if min <= 2:
            print(min)
            quit()

print(min)

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

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

if Ai == [Ai[0]] * len(Ai):
    print(Ai[0])
    quit()

Ai.sort()

i = 1
diff_list = []
min = 1000000000
for a in Ai:
    for a2 in Ai[i:]:
        a_gcd = fractions.gcd(a, a2)
        if min > a_gcd:
            min = a_gcd
        if min <= 2:
            print(min)
            quit()
    i += 1

print(min)


Fixed submission:
import fractions

N = int(input())
Ai = list(map(int, input().split()))
if Ai == [Ai[0]] * len(Ai):
    print(Ai[0])
    quit()

#Ai.sort()

i = 1
min = 1000000000
a = Ai[0]
for a2 in Ai[1:]:
    a_gcd = fractions.gcd(a, a2)
    if min > a_gcd:
        min = a_gcd
        if min <= 2:
            print(min)
            quit()

print(min)
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

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

ci = []
pi = [0] * N
for i in range(M):
    ci.append([i] + list(map(int, input().split())))

ci.sort(key=itemgetter(1,2))
for c in ci:
    pi[c[1]-1] += 1
    prestr = str(c[1]).zfill(6)
    bhstr = str(pi[c[1]-1]).zfill(6)
    c.append(''.join([prestr, bhstr]))

ci.sort()
for c in ci:
    print(c[3])

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

print(X+Y//2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = ''
while N != 1:
    if abs(N) % 2 == 1:
        ans += '1'
        N = (N-1) // -2
    else:
        ans += '0'
        N = N // -2
ans += '1'
print(ans[::-1])

Fixed submission:
N = int(input())
ans = ''
if N == 0:
    print(0)
    quit()
while N != 1:
    if abs(N) % 2 == 1:
        ans += '1'
        N = (N-1) // -2
    else:
        ans += '0'
        N = N // -2
ans += '1'
print(ans[::-1])
Buggy python submission (verdict: Runtime Error):
R = int(input())

if R >= 2800:
    print('AGC')
elif R < 1200:
    print('ABC')
else:a
    print('ARC') 

Fixed submission:
R = int(input())

if R >= 2800:
    print('AGC')
elif R < 1200:
    print('ABC')
else:
    print('ARC')
Buggy python submission (verdict: Runtime Error):
import copy
N = int(input())
ai = list(map(int, input().split()))

def lcm_list(l):
    if len(l) <= 1:
        return l[0]
    
    a = l.pop(len(l)-1)
    b = l.pop(len(l)-1)
    ans = lcm(a, b)
    l.append(ans)
    return lcm_list(l)

def lcm(a, b):
    return a * b // gcd(a, b)

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)

bi = copy.deepcopy(ai)
lcm_a = lcm_list(ai) - 1
ans = 0
for a in bi:
    ans += lcm_a % a

print(ans)

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

ans = 0
for a in ai:
    ans += a - 1

print(ans)

Buggy python submission (verdict: Runtime Error):
7
994 518 941 851 647 2 581


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

ans = 0
for a in ai:
    ans += a - 1

print(ans)
Buggy python submission (verdict: Runtime Error):
A, B = int(input().split())

max = -1000
if A + B > max:
    max = A + B
if A - B > max:
    max = A - B
if A * B > max:
    max = A * B
print(max)

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

max = -1000
if A + B > max:
    max = A + B
if A - B > max:
    max = A - B
if A * B > max:
    max = A * B
print(max)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

nums = []
if S[0] == 'W':
    nums.append(0)

count = 0
d = S[0]
for i in range(N):
    if S[i] == d:
        count+=1
    else:
        nums.append(count)
        d = S[i]
        count = 1
nums.append(count)

min = 3 * 10**5
ans = 0
for i in range(len(nums)):
    if nums[i] == 0:
        continue
    
    ans += sum(nums[1:i:2])
    if i % 2== 0:
        ans += sum(nums[i+2::2])
    else:
        ans += sum(nums[i+1::2])
    if min > ans:
        min = ans
    ans = 0

print(min)


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

wnums = [0]
enums = [0]
for i in range(0, N-1):
    if S[i] == 'W':
        wnums.append(wnums[i]+1)
    else:
        wnums.append(wnums[i])

j=0
for i in range(N-1, 0, -1):
    if S[i] == 'E':
        enums.append(enums[j]+1)
    else:
        enums.append(enums[j])
    j += 1

ans = 3*10**5
num = 0
for i in range(N):
    num = wnums[i] + enums[N-i-1]
    if ans > num:
        ans = num
    num = 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())

nums = [x for x in range(A, B+1)]
ans = set()
for i in range(0, K):
    if i >= len(nums):
        break
    ans.add(nums[i])

for i in range(len(nums)-K, len(nums)):
    if i < 0:
        break
    ans.add(nums[i])

for n in sorted(list(ans)):
    print(n)

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

if B-A+1 < 2*K:
   for x in range(A, B+1):
      print(x)
else:
    for x in range(A, A+K):
        print(x)
    for x in range(B-K+1, B+1):
        print(x)
Buggy python submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())

AQ = set()
for i in range(F):
    for j in range(F):
        if 100*A*i + 100*B*j <= F:
            AQ.add(100*A*i + 100*B*j)
        else:
            break

SG = set()
for i in range(F):
    for j in range(F):
        if C*i + D*j <= F:
            SG.add(C*i + D*j)
        else:
            break

ans = [0, 0]
maxc = None
for aq in AQ:
    for sg in SG:
        if aq == 0:
            continue
        if aq+sg > F or sg/aq > E/100:
            continue
        if maxc < sg/(aq+sg):
            ans = [aq, sg]
            maxc = sg/(aq+sg)
if maxc is None:
    print(0, 0)
else:
    print(ans[0]+ans[1], ans[1])

Fixed submission:
A, B, C, D, E, F = map(int, input().split())
ans = [[0, 0]]
for i in range(0, F//100):
    if 100*A*i > F:
        break
    for j in range(0, F//100):
        if 100*A*i+100*B*j > F:
            break
        if 100*A*i + 100*B*j == 0:
            continue
        for k in range(0, F//C+1):
            for l in range(0, F//D+1):
                if 100*A*i + 100*B*j + C*k + D*l > F:
                    break
                if  (C*k + D*l)/(100*A*i + 100*B*j) > E/100:
                    break
                ans.append([(100*A*i + 100*B*j + C*k + D*l), (C*k + D*l)])
ans = sorted(ans, key=lambda x: x[1]/x[0] if x[0] != 0 else 0)
print(ans[-1][0], ans[-1][1])