Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, m = [int(elem) for elem in input().split()]
a_lst = [int(elem) for elem in input().split()]
a_lst = sorted(a_lst)

lst = []
for i in range(m):
  b, c = [int(elem) for elem in input().split()]
  lst.append((c, b))
lst = sorted(lst)

i = 0
for c, b in lst:
  while c > a_lst[i] and b > 0:
    a_lst[i] = c
    i += 1
    b -= 1
  i = 0
print(sum(a_lst))
  

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int, input().split())) for _ in range(m)]

sorted_ab=sorted(bc, reverse=True, key=lambda x: x[1])
new_ab=[]
ans=[]

for i in range(m):
    if len(new_ab)<=n:
        tmp_l=[sorted_ab[i][1]]*sorted_ab[i][0]
        new_ab+=tmp_l
    else:
        break

final_list=a+new_ab
final_list.sort(reverse=True)
print(sum(final_list[:n]))
Buggy python submission (verdict: Runtime Error):
import math

n, k = [int(elem) for elem in input().split()]

res = 0.0
for i in range(1, n+1):
  if not (k//i) == 0:
    if (k/i) == (k//i):
    	if math.log2(k//i) == int(math.log2(k//i)):
      		x = int(math.log2(k//i))
    	else:
      	x = int(math.log2(k//i)) + 1
  	else:
     	x = int(math.log2(k//i)) + 1
  else:
    x = 0
  res += (1/n) * (0.5 ** x)
print(res)

Fixed submission:
import math

n, k = [int(elem) for elem in input().split()]

res = 0.0
for i in range(1, n+1):
  if not (k//i) == 0:
    if (k/i) == (k//i):
      if math.log2(k//i) == int(math.log2(k//i)):
        x = int(math.log2(k//i))
      else:
        x = int(math.log2(k//i)) + 1
    else:
      x = int(math.log2(k//i)) + 1
  else:
    x = 0
  res += (1/n) * (0.5 ** x)
print(res)

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

n, k = [int(elem) for elem in input().split()]

res = 0.0
for i in range(1, n+1):
  if (k/i) == (k//i):
    if math.log2(k//i) == int(math.log2(k//i)):
      x = int(math.log2(k//i))
    else:
      x = int(math.log2(k//i)) + 1
  else:
     x = int(math.log2(k//i)) + 1
  res += (1/n) * (0.5 ** x)
print(res)

Fixed submission:
import math

n, k = [int(elem) for elem in input().split()]

res = 0.0
for i in range(1, n+1):
  if not (k//i) == 0:
    if (k/i) == (k//i):
      if math.log2(k//i) == int(math.log2(k//i)):
        x = int(math.log2(k//i))
      else:
        x = int(math.log2(k//i)) + 1
    else:
      x = int(math.log2(k//i)) + 1
  else:
    x = 0
  res += (1/n) * (0.5 ** x)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

def gcd_list(numbers):
  return reduce(fractions.gcd, numbers)

if __name__ == '__main__':
  n = int(input())
  a_lst = [int(elem) for elem in input().split()]  
  res_lst = []
  for i, a in enumerate(a_lst):
    new_lst = list(a_lst)
    new_lst.pop(i)
    res = gcd_list(new_lst)
    res_lst.append(res)
  print(max(res_lst))

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

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

left_gcd = [0]*(n+1)
right_gcd = [0]*(n+1)
left_gcd[1] = a[0]
right_gcd[1] = a[-1]

for i in range(1,n):
    left_gcd[i+1] = gcd(left_gcd[i],a[i])
    right_gcd[i+1] = gcd(right_gcd[i],a[-1-i])

ans = right_gcd[n-1]
for i in range(n):
    ans = max(ans,gcd(left_gcd[i],right_gcd[n-1-i]))
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n = int(input())
a_lst = [int(elem) for elem in input().split()]

res_lst = []
for i, a in enumerate(a_lst):
    new_lst = list(a_lst)
    new_lst.pop(i)
    res = gcd_list(new_lst)
    res_lst.append(res)
print(max(res_lst))

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

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

left_gcd = [0]*(n+1)
right_gcd = [0]*(n+1)
left_gcd[1] = a[0]
right_gcd[1] = a[-1]

for i in range(1,n):
    left_gcd[i+1] = gcd(left_gcd[i],a[i])
    right_gcd[i+1] = gcd(right_gcd[i],a[-1-i])

ans = right_gcd[n-1]
for i in range(n):
    ans = max(ans,gcd(left_gcd[i],right_gcd[n-1-i]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x, y, z, k = [int(elem) for elem in input().split()]
a_lst = [int(elem) for elem in input().split()]
b_lst = [int(elem) for elem in input().split()]
c_lst = [int(elem) for elem in input().split()]

ab_lst = []
for a in a_lst:
  for b in b_lst:
    ab_lst.append(a + b)

ab_lst = sorted(ab_lst, reverse=True)
    
res = []
for ab in ab_lst[:k]:
  for c in c_lst:
    res.append(ab + c)

res = sorted(res, reverse=True)
for elem in res[:k]:
  print(elem)
    


  
    

Fixed submission:
x,y,z,k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
 
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
 
cakes = []
for x, a in enumerate(A):
    if x+1 > k: break
        
    for y, b in enumerate(B):
        if (x+1)*(y+1) > k: break
            
        for z, c in enumerate(C):
            if (x+1)*(y+1)*(z+1) > k: break
                
            cakes.append(a+b+c)
    
cakes.sort(reverse=True)      
for cake in cakes[:k]:
    print(cake)

Buggy python submission (verdict: Time Limit Exceeded):
x, y, z, k = [int(elem) for elem in input().split()]
a_lst = [int(elem) for elem in input().split()]
b_lst = [int(elem) for elem in input().split()]
c_lst = [int(elem) for elem in input().split()]

ab_lst = []
for a in a_lst:
  for b in b_lst:
    ab_lst.append(a + b)

ab_lst = sorted(ab_lst, reverse=True)
    
res = []
for ab in ab_lst[:k]:
  for c in c_lst:
    res.append(ab + c)

res = sorted(res, reverse=True)
for elem in res[:k]:
  print(elem)
    


  
    

Fixed submission:
x,y,z,k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
 
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
 
cakes = []
for x, a in enumerate(A):
    if x+1 > k: break
        
    for y, b in enumerate(B):
        if (x+1)*(y+1) > k: break
            
        for z, c in enumerate(C):
            if (x+1)*(y+1)*(z+1) > k: break
                
            cakes.append(a+b+c)
    
cakes.sort(reverse=True)      
for cake in cakes[:k]:
    print(cake)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(elem) for elem in input().split()]
s = input()
new_s = [0]
for st1, st2 in zip(s[:-1], s[1:]):
    if st1 == "A" and st2 == "C":
        new_s.append(1)
    else:
        new_s.append(0)

out = []
for i in range(0, q):
    l, r = [int(elem) for elem in input().split()]
    out.append(sum(new_s[0:r]) - sum(new_s[0:l]))  

for elem in out:
    print(elem)

Fixed submission:
n, q = [int(elem) for elem in input().split()]
s = input()
new_s = [0]
num = 0
for st1, st2 in zip(s[:-1], s[1:]):
    if st1 == "A" and st2 == "C":
        num += 1
        new_s.append(num)
    else:
        new_s.append(num)

out = []
for i in range(0, q):
    l, r = [int(elem) for elem in input().split()]
    out.append(new_s[r-1] - new_s[l-1])  

for elem in out:
    print(elem)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(elem) for elem in input().split()]
s = input()
out = []
for i in range(0, q):
    l, r = [int(elem) for elem in input().split()]
    part_s = s[l-1:r]
    res = part_s.split("AC")
    out.append(len(res) - 1)

for elem in out:
    print(elem)

Fixed submission:
n, q = [int(elem) for elem in input().split()]
s = input()
new_s = [0]
num = 0
for st1, st2 in zip(s[:-1], s[1:]):
    if st1 == "A" and st2 == "C":
        num += 1
        new_s.append(num)
    else:
        new_s.append(num)

out = []
for i in range(0, q):
    l, r = [int(elem) for elem in input().split()]
    out.append(new_s[r-1] - new_s[l-1])  

for elem in out:
    print(elem)
Buggy python submission (verdict: Runtime Error):
# - coding : utf-8 -*-

if __name__ == "__main__":

    n, k = map(int, input().split())
    an = list(map(int, input().split()))
    an.sort()

    p = [1] * 41
    for i in range(40):
        p[i+1] = p[i] * 2

    import pdb;pdb.set_trace()
        
    ans = 0
    x = 0
    for i in range(41):
        t = p[40-i]
        if x + t > k:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            ans += cnt * t
        else:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            if cnt <= n/2:
                x += t
            ans += max(cnt, n-cnt) * t
    print(ans)

Fixed submission:
# - coding : utf-8 -*-

if __name__ == "__main__":

    n, k = map(int, input().split())
    an = list(map(int, input().split()))
    an.sort()

    p = [1] * 41
    for i in range(40):
        p[i+1] = p[i] * 2
        
    ans = 0
    x = 0
    for i in range(41):
        t = p[40-i]
        if x + t > k:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            ans += cnt * t
        else:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            if cnt <= n/2:
                x += t
            ans += max(cnt, n-cnt) * t
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# - coding : utf-8 -*-

def digit2bin(num1, num2):
    bin1 = bin(num1).split('0b')[1]
    bin2 = bin(num2).split('0b')[1]
    if len(bin1) > len(bin2):
        bin2 = bin2.zfill(len(bin1))
    else:
        bin1 = bin1.zfill(len(bin2))
    return bin1, bin2

def xor(num1, num2):
    bin1, bin2 = digit2bin(num1, num2)
    res_bin = ""
    for b1, b2 in zip(bin1, bin2):
        tmp = abs(int(b1) - int(b2))
        res_bin += str(tmp)
    return int(res_bin, 2)

def func_f(x, an):
    res = 0
    for a in an:
        res += xor(x, int(a))
    return res

if __name__ == "__main__":
    n, k = input().split()
    an = input().split()

    results = []
    for x in range(0, int(k)+1):
        results.append(func_f(x, an))
    print(max(results))
    

    




Fixed submission:
# - coding : utf-8 -*-

if __name__ == "__main__":

    n, k = map(int, input().split())
    an = list(map(int, input().split()))
    an.sort()

    p = [1] * 41
    for i in range(40):
        p[i+1] = p[i] * 2
        
    ans = 0
    x = 0
    for i in range(41):
        t = p[40-i]
        if x + t > k:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            ans += cnt * t
        else:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            if cnt <= n/2:
                x += t
            ans += max(cnt, n-cnt) * t
    print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
h = [int(elem) for elem in raw_input().split()]
cost = [0] * n

def calc_cost(k):
    if cost[k] != 0:
        return cost[k]
    if k == 1:
        cost[k] = calc_cost(k-1) + abs(h[k] - h[k-1])
    elif k == 0:
        cost[k] = 0
    else:
        cost[k] = min(calc_cost(k-1) + abs(h[k] - h[k-1]),
                      calc_cost(k-2) + abs(h[k] - h[k-2]))
    return cost[k]

print calc_cost(n-1)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = [int(elem) for elem in input().split()]
cost = [0] * n

def calc_cost(k):
    if cost[k] != 0:
        return cost[k]
    if k == 1:
        cost[k] = calc_cost(k-1) + abs(h[k] - h[k-1])
    elif k == 0:
        cost[k] = 0
    else:
        cost[k] = min(calc_cost(k-1) + abs(h[k] - h[k-1]),
                      calc_cost(k-2) + abs(h[k] - h[k-2]))
    return cost[k]

print(calc_cost(n-1))

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = [int(elem) for elem in input().split()]
cost = [0] * n

def calc_cost(k):
    if cost[k] != 0:
        return cost[k]
    if k == 1:
        cost[k] = calc_cost(k-1) + abs(h[k] - h[k-1])
    elif k == 0:
        return 0
    else:
        cost[k] = min(calc_cost(k-1) + abs(h[k] - h[k-1]),
                      calc_cost(k-2) + abs(h[k] - h[k-2]))
    return cost[k]

print(calc_cost(n-1))

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
s = input()

def func(num, lst):
  if num == 0:
    return len(lst[num])
  else:
    return func(num - 1, lst) + len(lst[num])

s = s.lstrip("W")
s = s.rstrip("B")
if 'W' in s:
  lst = s.split('W')
  out = 0
  for i in range(0, len(lst)):
    if not lst[i] == '':
      out += func(i, lst) 
  print(out)
else:
  print(0)

Fixed submission:
cnt = ans = 0
for c in input():
  if c is 'W':
    ans += cnt
  else:
    cnt += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()

def func(num, lst):
  if num == 0:
    return len(lst[num])
  else:
    return func(num - 1, lst) + len(lst[num])

lst = s.split('W')
out = 0
for i in range(0, len(lst)):
  if not lst[i] == '':
  	out += func(i, lst)
  
print(out)

Fixed submission:
cnt = ans = 0
for c in input():
  if c is 'W':
    ans += cnt
  else:
    cnt += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n, x = input().split()
bg = "P"
for i in range(0, int(n)):
  bg = "B" + bg + "P" + bg + "B"
print(bg[-(int(x)):].count("P"))

Fixed submission:
def md_burger(n, x):
  if x == 1:
    if n == 0:
      return 1
    else:
      return 0
  elif 1 < x < a[n-1]+2:
    return md_burger(n-1, x-1)
  elif x == a[n-1]+2:
    return p[n-1]+1
  elif a[n-1]+2 < x < 2*a[n-1]+3:
    return p[n-1]+1+md_burger(n-1, x-2-a[n-1])
  else:
    return 2*p[n-1]+1

if __name__=="__main__":
  n, x = input().split()
  a = [1]
  p = [1]
  for i in range(0, int(n)):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)
  print(md_burger(int(n), int(x)))
Buggy python submission (verdict: Time Limit Exceeded):
# - coding : utf-8 -*-

import sys

if __name__ == '__main__':
    n, m = map(int, raw_input().split())
    cities = []
    city_lst = {}
    for i in range(0, m):
        p, y = map(int, raw_input().split())
        cities.append((p, y))
        if not p in city_lst:
            city_lst[p] = [y]
        else:
            city_lst[p].append(y)
    for key in city_lst.keys():
        city_lst[key].sort()
    for city in cities:
        print str('%06d' % city[0]) + str('%06d' % (int(city_lst[city[0]].index(city[1]) + 1)))
        sys.stdout.flush()

Fixed submission:
# - coding : utf-8 -*-

if __name__ == '__main__':
    n, m = map(int, raw_input().split())
    cities = []
    for i in range(0, m):
        p, y = map(int, raw_input().split())
        cities.append((y, p, i))
    cities.sort()

    city_codes = [0] * (n + 1)
    postal_codes = [""] * m
    for j in range(0, m):
        y, p, i = cities[j]
        city_codes[p] += 1
        postal_codes[i] = "%06d%06d"%(p, city_codes[p])
    for postal_code in postal_codes:
        print postal_code

Buggy python submission (verdict: Time Limit Exceeded):
# - coding : utf-8 -*-
    
if __name__ == '__main__':
    n, m = map(int, raw_input().split())
    cities = []
    city_lst = {}
    for i in range(0, m):
        p, y = map(int, raw_input().split())
        cities.append((p, y))
        if not p in city_lst:
            city_lst[p] = [y]
        else:
            city_lst[p].append(y)
    for key in city_lst.keys():
        city_lst[key].sort()
    for city in cities:
        print str('%06d' % city[0]) + str('%06d' % (int(city_lst[city[0]].index(city[1]) + 1)))

Fixed submission:
# - coding : utf-8 -*-

if __name__ == '__main__':
    n, m = map(int, raw_input().split())
    cities = []
    for i in range(0, m):
        p, y = map(int, raw_input().split())
        cities.append((y, p, i))
    cities.sort()

    city_codes = [0] * (n + 1)
    postal_codes = [""] * m
    for j in range(0, m):
        y, p, i = cities[j]
        city_codes[p] += 1
        postal_codes[i] = "%06d%06d"%(p, city_codes[p])
    for postal_code in postal_codes:
        print postal_code
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
vs = input().split()
even = []
odd = []
if not even == odd:
  for i, v in enumerate(vs):
  	if i % 2 == 0:
    	even.append(int(v))
    else:
    	odd.append(int(v))
  counter_even = Counter(even)
  counter_odd = Counter(odd)

  res = len(even) - counter_even.most_common()[0][1] + len(odd) - counter_odd.most_common()[0][1] 
else:
  res = len(even)
print(res)

Fixed submission:
from collections import Counter

n = int(input())
vs = input().split()
even = []
odd = []

if len(list(set(vs))) == 1:
  res = int(len(vs) / 2)
else:
  for i, v in enumerate(vs):
    if i % 2 == 0:
      even.append(int(v))
    else:
      odd.append(int(v))
  counter_even = Counter(even)
  counter_odd = Counter(odd)
  if counter_even.most_common()[0][0] != counter_odd.most_common()[0][0]:
    res = len(even) - counter_even.most_common()[0][1]  + len(odd) - counter_odd.most_common()[0][1]
  else:
    res1 = len(even) - counter_even.most_common()[1][1]  + len(odd) - counter_odd.most_common()[0][1]
    res2 = len(even) - counter_even.most_common()[0][1]  + len(odd) - counter_odd.most_common()[1][1]
    res = min(res1, res2)
print(res)

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

n = int(input())
vs = input().split()
even = []
odd = []
if not even == odd:
  for i, v in enumerate(vs):
  	if i % 2 == 0:
    	even.append(int(v))
    else:
    	odd.append(int(v))
  counter_even = Counter(even)
  counter_odd = Counter(odd)

  res = len(even) - counter_even.most_common()[0][1] + len(odd) - counter_odd.most_common()[0][1] 
else:
  res = len(even)
print(res)

Fixed submission:
from collections import Counter

n = int(input())
vs = input().split()
even = []
odd = []

if len(list(set(vs))) == 1:
  res = int(len(vs) / 2)
else:
  for i, v in enumerate(vs):
    if i % 2 == 0:
      even.append(int(v))
    else:
      odd.append(int(v))
  counter_even = Counter(even)
  counter_odd = Counter(odd)
  if counter_even.most_common()[0][0] != counter_odd.most_common()[0][0]:
    res = len(even) - counter_even.most_common()[0][1]  + len(odd) - counter_odd.most_common()[0][1]
  else:
    res1 = len(even) - counter_even.most_common()[1][1]  + len(odd) - counter_odd.most_common()[0][1]
    res2 = len(even) - counter_even.most_common()[0][1]  + len(odd) - counter_odd.most_common()[1][1]
    res = min(res1, res2)
print(res)
Buggy python submission (verdict: Runtime Error):
import collections

s = input()
t = input()
c1 = collections.Counter(s)
c2 = collections.Counter(t)
s_values = sorted(list(c1.values()))
t_values = sorted(list(c2.values()))

if len(s) == len(t):
  if len(list(set(s))) == len(list(set(t))):
    if s_values == v_values():
      print("Yes")
    else:
      print("No")
  else:
    print("No")
else:
  print("No")

Fixed submission:
import collections

s = input()
t = input()
c1 = collections.Counter(s)
c2 = collections.Counter(t)
s_values = sorted(list(c1.values()))
t_values = sorted(list(c2.values()))

if len(s) == len(t):
  if len(list(set(s))) == len(list(set(t))):
    if s_values == t_values:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
xs = list(map(int, input().split()))

res_lst = []
for i in range(n-k+1):
  lst = xs[i:i+k]
  res = min(abs(lst[0]) + abs(lst[-1] - lst[0]), abs(lst[-1]) + abs(lst[0] - lst[-1]))
  res_lst.append(res)
print(min(res_lst))

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

min_ = None
for i in range(n-k+1):
  res = min(abs(xs[i]) + abs(xs[i+k-1] - xs[i]), abs(xs[i+k-1]) + abs(xs[i] - xs[i+k-1]))
  if min_ is None:
    min_ = res
  else:
    min_ = min(res, min_)
print(min_)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

if len(set(s)) == 1 and set(s)[0] == set(['1']):
  print(1)
else:
  for elem in s:
    if int(elem) == 1:
      pass
    else:
      print(elem)
      break

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

for i in range(min(len(s),k)):
    if s[i] != '1':
        print(s[i])
        quit()
 
print('1')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

lst = []
for i in range(n):
  lst.append(s[:i].count('W') + s[i+1:].count('E'))
print(min(lst))

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

w_lst = [0] * n
e_lst = [0] * n

for i in range(1, n):
    if s[i - 1] == "W":
        w_lst[i] = w_lst[i - 1] + 1
    else:
        w_lst[i] = w_lst[i - 1]
for i in range(n - 2, -1, -1):
    if s[i + 1] == "E":
        e_lst[i] = e_lst[i + 1] + 1
    else:
        e_lst[i] = e_lst[i + 1]

ans = 10**10
for i in range(n):
    ans = min(ans, w_lst[i] + e_lst[i])
print(ans)

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

res = -1
for i in range(n):
  if res == -1:
    res = s[:i].count('W') + s[i+1:].count('E')
  else:
    if res > s[:i].count('W') + s[i+1:].count('E'):
      res = s[:i].count('W') + s[i+1:].count('E')
print(res)

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

w_lst = [0] * n
e_lst = [0] * n

for i in range(1, n):
    if s[i - 1] == "W":
        w_lst[i] = w_lst[i - 1] + 1
    else:
        w_lst[i] = w_lst[i - 1]
for i in range(n - 2, -1, -1):
    if s[i + 1] == "E":
        e_lst[i] = e_lst[i + 1] + 1
    else:
        e_lst[i] = e_lst[i + 1]

ans = 10**10
for i in range(n):
    ans = min(ans, w_lst[i] + e_lst[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_lst = list(map(int, input().split()))

i = 2
len_ = len(a_lst)
sum_ = {}
xor_ = {}
res = 0
for i in range(len_):
  sum_[i] = {}
  xor_[i] = {}
  for j in range(i, len_):
    if j == i:
      sum_[i][j] = a_lst[i]
      xor_[i][j] = a_lst[i]
      res += 1
    else:
      sum_[i][j] = sum_[i][j-1] + a_lst[j]
      xor_[i][j] = xor_[i][j-1] ^ a_lst[j]  
      if sum_[i][j] == xor_[i][j]:
        res += 1
print(res)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
l=0
r=1
t=a[0]
ans=0
 
while l<n:
  if r==n:
    ans+=r-l
    l+=1
    continue
  if t+a[r]==t^a[r]:
    t+=a[r]
    r+=1
  else:
    ans+=r-l
    t-=a[l]
    l+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
xs = [int(elem) for elem in input().split()]

for i in range(n):
  print(sorted(xs[:i] + xs[i+1:])[(n//2 - 1)])

Fixed submission:
n = int(input())
xs = [int(elem) for elem in input().split()]
sorted_xs = sorted(xs)
base = sorted_xs[(n//2 - 1)]

for i in range(n):
  if xs[i] <= base:
    print(sorted_xs[n//2])
  else:
    print(base)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import operator
from functools import reduce

def combinations_count(n, r):
  return reduce(operator.mul, [elem for elem in range(n-r+1, n+1)], 1) // math.factorial(r)

n = int(input())
a_lst = list(map(int, input().split()))

max_ = 0
arg1, arg2 = 0, 0
for i, a1 in enumerate(a_lst):
  for a2 in a_lst[i+1:]:
    if a1 > a2:
      cand = combinations_count(a1, a2)
    else:
      cand = combinations_count(a2, a1)
    if max_ < cand:
      max_ = cand
      arg1 = max(a1, a2)
      arg2 = min(a1, a2)
print(arg1, arg2)


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

a.sort()

large = max(a)
a.remove(large)
min_list = [0, large/2]
for i in a:
    if abs(i - large/2) < min_list[1]:
        min_list = [i, abs(i - large/2)]

print(large, min_list[0])