Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from numba import njit
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline

N = int(input())
S = np.array(list(read().rstrip()), np.int8)

R = np.sum(S == ord('R'))
B = np.sum(S == ord('B'))
G = np.sum(S == ord('G'))


@njit
def f(S):
    N = len(S)
    ret = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = j + j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ret += 1
    return ret


answer = R * B * G - f(S)
print(answer)


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

r = g = b = 0
for i in range(n):
    if s[i] == 'R':
        r += 1
    elif s[i] == 'G':
        g += 1
    else:
        b += 1

x = 0
for i in range(n):
    for j in range(i+1, n):
        k = j + j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            x += 1
print(r*g*b-x)

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

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if j - i == k - j:
                continue
            elif s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                ans += 1
print(ans)

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

r = g = b = 0
for i in range(n):
    if s[i] == 'R':
        r += 1
    elif s[i] == 'G':
        g += 1
    else:
        b += 1

x = 0
for i in range(n):
    for j in range(i+1, n):
        k = j + j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            x += 1
print(r*g*b-x)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
S = [x * (x - 1) // 2 for x in counter.values()]

# (n-1)(n-2)/2 - n(n-1)/2 = 1 - n
print('\n'.join(str(sum(S) + 1 - counter[x]) for x in A))



Fixed submission:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
s = sum(x * (x - 1) // 2 for x in counter.values())

# (n-1)(n-2)/2 - n(n-1)/2 = 1 - n
print('\n'.join(str(s + 1 - counter[x]) for x in A))
Buggy python submission (verdict: Runtime Error):
a,b.c=map(int,input().split())
print('bust' if a+b+c>21 else 'win')

Fixed submission:
a, b, c = map(int, input().split())
print('bust' if a+b+c > 21 else 'win')
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N = int(input())
S = input()
se = set()
for i, j, k in combinations(range(N), 3):
    se.add(S[i] + S[j] + S[k])
print(len(se))

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


def check(subs):
    start = 0
    for x in subs:
        index = S.find(x, start)
        if index == -1:
            return False
        start = index + 1
    return True


ans = 0
for i in range(1000):
    s = '0' * (3 - len(str(i))) + str(i)
    if check(s):
        ans += 1
print(ans)

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

N = int(input())
S = input()
se = set()
for i, j, k in combinations(range(N), 3):
    se.add(S[i] + S[j] + S[k])
print(len(se))

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


def check(subs):
    start = 0
    for x in subs:
        index = S.find(x, start)
        if index == -1:
            return False
        start = index + 1
    return True


ans = 0
for i in range(1000):
    s = '0' * (3 - len(str(i))) + str(i)
    if check(s):
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
from decimal import Decimal
n = int(input())
a = list(map(int, input().split()))
S = np.int64(np.prod(a))
T = 0
for x in a:
    T += Decimal(S / x)
print(Decimal(S / T))


Fixed submission:
import numpy as np
n = int(input())
a = np.array([input().split()], np.float64)
print(1/(1 / a).sum())

Buggy python submission (verdict: Runtime Error):
import numpy as np
from decimal import Decimal
n = int(input())
a = list(map(int, input().split()))
S = np.prod(a)
T = 0
for x in a:
    T += Decimal(S / x)
print(Decimal(S / T))


Fixed submission:
import numpy as np
n = int(input())
a = np.array([input().split()], np.float64)
print(1/(1 / a).sum())
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10 ** 9 + 7
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N + 1):
    if i in A:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 2] + dp[i - 1]) % MOD
print(dp[N])

Fixed submission:
MOD = 10 ** 9 + 7
N, M = map(int, input().split())
dp = [[0, 0] for _ in range(N + 1)]
dp[0][0] = 1
for _ in range(M):
    x = int(input())
    dp[x][1] = 1
for i in range(1, N + 1):
     if dp[i][1] == 0:
         dp[i][0] = (dp[i - 2][0] + dp[i - 1][0]) % MOD
print(dp[N][0])
Buggy python submission (verdict: Runtime Error):
t, x = map(int, input.split())
print(t/x)

Fixed submission:
t, x = map(int, input().split())
print(t/x)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
INF = 1 << 60
D = [INF] * n
D[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i >= j:
            D[i] = min(D[i], D[i - j] + abs(h[i] - h[i - j]))
print(D[-1])


Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
INF = 1 << 60
D = [INF] * n
D[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i >= j:
            D[i] = min(D[i], D[i - j] + abs(h[i] - h[i - j]))
print(D[-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())
X = np.array([input().split() for _ in range(n)], np.int64)
dp = np.zeros((n + 1, 3), np.int64)
dp[0, 0] = dp[0, 1] = dp[0, 2] = 0
for i in range(n):
    for j in range(3):
        dp[i + 1, j] = X[i, j] + max(dp[i, k] for k in range(3) if j != k)
print(max(dp[n]))

Fixed submission:
import numpy as np

n = int(input())
X = np.array([input().split() for _ in range(n)], np.int64)
dp = np.zeros((n + 1, 3), np.int64)
dp[0, 0] = dp[0, 1] = dp[0, 2] = 0
for i in range(n):
    for j in range(3):
        dp[i + 1, j] = X[i, j] + max(dp[i, k] for k in range(3) if j != k)
print(max(dp[n]))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, max_weight = map(int, input().split())
WV = np.array([input().split() for _ in range(n)], np.int64)

W, V = zip(*WV)
dp = np.zeros((n + 1, max_weight + 1), np.int64)

# O(NW)
for i in range(n):
    for w in range(1, max_weight + 1):
        if w >= W[i]:
            dp[i + 1, w] = max(dp[i, w], dp[i, w - W[i]] + V[i])
        else:
            dp[i + 1, w] = dp[i, w]

print(dp[n, max_weight])


Fixed submission:
n, max_weight = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(n)]
W, V = zip(*WV)
dp = list([0] * (max_weight + 1) for _ in range(n + 1))
for i in range(n):
    for w in range(1, max_weight + 1):
        if w >= W[i]:
            dp[i + 1][w] = max(dp[i][w], dp[i][w - W[i]] + V[i])
        else:
            dp[i + 1][w] = dp[i][w]

print(dp[n][max_weight])

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

n, max_weight = map(int, input().split())
WV = np.array([input().split() for _ in range(n)], np.int64)

W, V = zip(*WV)
dp = np.zeros((n, max_weight + 1), np.int64)

for i in range(n):
    for w in range(1, max_weight + 1):
        if w >= W[i]:
            dp[i, w] = max(dp[i - 1, w], dp[i - 1, w - W[i]] + V[i])
        else:
            dp[i, w] = dp[i - 1, w]

print(dp[n - 1, max_weight])


Fixed submission:
n, max_weight = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(n)]
W, V = zip(*WV)
dp = list([0] * (max_weight + 1) for _ in range(n + 1))
for i in range(n):
    for w in range(1, max_weight + 1):
        if w >= W[i]:
            dp[i + 1][w] = max(dp[i][w], dp[i][w - W[i]] + V[i])
        else:
            dp[i + 1][w] = dp[i][w]

print(dp[n][max_weight])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(float, input().split()))
dp = [[0.0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1.0
for i in range(1, n + 1):
    for j in range(n + 1):
        dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]
ans = sum(dp[n][i] for i in range(n // 2 + 1, n + 1))
print(ans)


Fixed submission:
n = int(input())
p = list(map(float, input().split()))
dp = [[0.0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1.0
for i in range(1, n + 1):
    for j in range(n + 1):
        dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]
ans = sum(dp[n][i] for i in range(n // 2 + 1, n + 1))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
dp = np.zeros(K + 1, np.bool)

for i in range(1, K + 1):
    for j in range(N):
        if i >= A[j]:
            dp[i] |= dp[i - A[j]] ^ True
# print(dp)
print('First' if dp[K] else 'Second')


Fixed submission:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
dp = [False] * (K + 1)

for i in range(1, K + 1):
    for a in A:
        if i >= a:
            dp[i] |= dp[i - a] ^ True
print('First' if dp[K] else 'Second')
Buggy python submission (verdict: Runtime Error):
n = int(input())

s = [input() for i in range(n)]

def shiritori(s):
  if len(s) != len(set(s)):
    return "No"
  
  for i in range(n-1):
    if s[i][-1] != s[i+1][0]:
      return "No"
  
  return "Yes"

shiritori()

Fixed submission:
n = int(input())

s = [input() for i in range(n)]

def shiritori(s):
  if len(s) != len(set(s)):
    return False
  
  for i in range(n-1):
    if s[i][-1] != s[i+1][0]:
      return False
  
  return True

if __name__ == '__main__':
  if shiritori(s):
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
a = [0 for _ in range(26)]
for i in l:
  a[i-1]+=1
  
for i in range(n):
  print(a[i])
  

Fixed submission:
n = int(input())
print(2*3.1415*n)
Buggy python submission (verdict: Runtime Error):
m = int(input())
n = int(input())
a = list(map(int,input().split()))

ans = m - sum(a)

if ans < 0:
  print(-1)
else:
  print(ans)
  
  

Fixed submission:
m_n = list(map(int,input().split()))
m = m_n[0]
n = m_n[1]
a = list(map(int,input().split()))
 
ans = m - sum(a)
 
if ans < 0:
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def countDivBy(d,a,b):
    x=d
    res=0
    while (x<a):
        x+=d
    while (x<=b):
        x+=d
        res+=1
    return res
 
def gcd(c,d):
    if(d>c):
        c,d = d,c
    a,b=c,d
    r=a%b
    while (r>0):      
        a = b
        b = r 
        r = a%b
    return b

A = list(map(int, input().split()))
a, b, c, d = A
g = gcd(c,d)
lcm = int(c*d/g)
ans = b - a + 1 - countDivBy(c,a,b) - countDivBy(d,a,b) + countDivBy(lcm,a,b)
print(ans)

Fixed submission:
def countDivBy(d,a,b):
    resB=b//d
    resA=(a-1)//d
    res = resB-resA
    return res

def gcd(c,d):
    if(d>c):
        c,d = d,c
    a,b=c,d
    r=a%b
    while (r>0):      
        a = b
        b = r 
        r = a%b
    return b
  
A = list(map(int, input().split()))
a, b, c, d = A
g = gcd(c,d)
lcm = (c*d) // g
ans = b - a + 1 - countDivBy(c,a,b) - countDivBy(d,a,b) + countDivBy(lcm,a,b)
print(ans)
Buggy python submission (verdict: Runtime Error):
dic={}
n=int(input())
d=[]
for i in range(n):
  d.append(input())
  if d[-1] in dic:
  	dic[d[-1]]+=1
  else:
    dic[d[-1]]=1
mx=max(mx,dic.values())
for k,v in sorted(dic.items(),key=lambda x:(-x[1],x[0])):
  if mx==v:
    print(k)
    	


Fixed submission:
dic={}
n=int(input())
d=[]
for i in range(n):
  d.append(input())
  if d[-1] in dic:
  	dic[d[-1]]+=1
  else:
    dic[d[-1]]=1
mx=max(dic.values())
for k,v in sorted(dic.items(),key=lambda x:(-x[1],x[0])):
  if mx==v:
    print(k)

Buggy python submission (verdict: Time Limit Exceeded):
dic={}
s=set()
n=int(input())
d=[]
for i in range(n):
  d.append(input())
  s.add(d[-1])
mx=0
for w in s:
  dic[w]=d.count(w)
  mx=max(mx,dic[w])

for k,v in sorted(dic.items(),key=lambda x:(-x[1],x[0])):
  if mx==v:
    print(k)
    	


Fixed submission:
dic={}
n=int(input())
d=[]
for i in range(n):
  d.append(input())
  if d[-1] in dic:
  	dic[d[-1]]+=1
  else:
    dic[d[-1]]=1
mx=max(dic.values())
for k,v in sorted(dic.items(),key=lambda x:(-x[1],x[0])):
  if mx==v:
    print(k)

Buggy python submission (verdict: Time Limit Exceeded):
dic={}
n=int(input())
d=[]
for i in range(n):
  d.append(input())
mx=0
for w in d:
  dic[w]=d.count(w)
  mx=max(mx,dic[w])

for k,v in sorted(dic.items(),key=lambda x:(-x[1],x[0])):
  if mx==v:
    print(k)
    	


Fixed submission:
dic={}
n=int(input())
d=[]
for i in range(n):
  d.append(input())
  if d[-1] in dic:
  	dic[d[-1]]+=1
  else:
    dic[d[-1]]=1
mx=max(dic.values())
for k,v in sorted(dic.items(),key=lambda x:(-x[1],x[0])):
  if mx==v:
    print(k)

Buggy python submission (verdict: Runtime Error):
dic={}
n=int(input())
d=[]
for i in range(n):
  d.append(input())
mx=0
for w in d:
  dic[w]=d.count(w)
  mx=max(mx,dic[w])

for k,v in sorted(dic.items(),key=lambda x:(x-[1],x[0])):
  if mx==v:
    print(k)
    	


Fixed submission:
dic={}
n=int(input())
d=[]
for i in range(n):
  d.append(input())
  if d[-1] in dic:
  	dic[d[-1]]+=1
  else:
    dic[d[-1]]=1
mx=max(dic.values())
for k,v in sorted(dic.items(),key=lambda x:(-x[1],x[0])):
  if mx==v:
    print(k)
Buggy python submission (verdict: Time Limit Exceeded):
def dist(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5


n=int(input())
data=[]
for i in range(n):
    x,y=map(float,input().split())
    data.append((x,y))

now=(500.,500.)
move=1
for i in range(200000):
    max_dist=0
    max_dist_point=-1
    for j in range(len(data)):
        d=dist(now,data[j])
        if d>max_dist:
            max_dist=d
            max_dist_point=j
    target=data[max_dist_point]
    now=(now[0]+(target[0]-now[0])*move,now[1]+(target[1]-now[1])*move)
    move*=0.999
max_dist=0
for j in range(len(data)):
    d=dist(now,data[j])
    if d>max_dist:
        max_dist=d
print(max_dist)





Fixed submission:
def dist(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5


n=int(input())
data=[]
for i in range(n):
    x,y=map(float,input().split())
    data.append((x,y))

now=(500.,500.)
move=1
for i in range(200000):
    max_dist=0
    max_dist_point=-1
    for j in range(len(data)):
        d=dist(now,data[j])
        if d>max_dist:
            max_dist=d
            max_dist_point=j
    target=data[max_dist_point]
    now=(now[0]+(target[0]-now[0])*move,now[1]+(target[1]-now[1])*move)
    move*=0.999
max_dist=0
for j in range(len(data)):
    d=dist(now,data[j])
    if d>max_dist:
        max_dist=d
print(max_dist)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
l=list(sorted(map(int,input().split())))
count=0
for i in range(1,n):
    for j in range(i+1,n):
        p=l[i]+l[j]
        count+=min(bisect.bisect_left(l,p),i)-min(bisect.bisect_left(l,l[j]-l[i]+1),i)
print(count)


Fixed submission:
import bisect
n=int(input())
l=list(sorted(map(int,input().split())))
count=0
for i in range(1,n):
    for j in range(i+1,n):
        p=l[i]+l[j]
        count+=min(bisect.bisect_left(l,p),i)-min(bisect.bisect_left(l,l[j]-l[i]+1),i)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
l=list(sorted(map(int,input().split())))
count=0
for i in range(1,n):
    for j in range(i+1,n):
        p=l[i]+l[j]
        count+=bisect.bisect_left(l[:i],p)-bisect.bisect_left(l[:i],l[j]-l[i]+1)
print(count)


Fixed submission:
import bisect
n=int(input())
l=list(sorted(map(int,input().split())))
count=0
for i in range(1,n):
    for j in range(i+1,n):
        p=l[i]+l[j]
        count+=min(bisect.bisect_left(l,p),i)-min(bisect.bisect_left(l,l[j]-l[i]+1),i)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
l=list(sorted(map(int,input().split())))
count=0
for i in range(1,n):
    for j in range(i+1,n):
        p=l[i]+l[j]
        count+=bisect.bisect_left(l[:i],p)-bisect.bisect_left(l[:i],l[j]-l[i]+1)
print(count)


Fixed submission:
import bisect
n=int(input())
l=list(sorted(map(int,input().split())))
count=0
for i in range(1,n):
    for j in range(i+1,n):
        p=l[i]+l[j]
        count+=min(bisect.bisect_left(l,p),i)-min(bisect.bisect_left(l,l[j]-l[i]+1),i)
print(count)
Buggy python submission (verdict: Runtime Error):
def check(a):
  for i in range(1,len(n)):
    if a[i-1]>a[i]:
      return False
  return True
n=int(input())
a=list(map(int,input().split()))
if check(a):
  print('YES')
  exit()
for i in range(n):
  for j in range(n):
    if i==j:
      continue
    a[i],a[j]=a[j],a[i]
    if check(a):
      print('YES')
      exit()
    a[i],a[j]=a[j],a[i]
print('NO')

Fixed submission:
def check(a):
  for i in range(1,len(a)):
    if a[i-1]>a[i]:
      return False
  return True
n=int(input())
a=list(map(int,input().split()))
if check(a):
  print('YES')
  exit()
for i in range(n):
  for j in range(n):
    if i==j:
      continue
    a[i],a[j]=a[j],a[i]
    if check(a):
      print('YES')
      exit()
    a[i],a[j]=a[j],a[i]
print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
hf=[[0 for i in range(w)]for i in range(h)]
vf=[[0 for i in range(w)]for i in range(h)]
field=[]
for i in range(h):
    field.append(list(input()))
for i in range(h):
    tmp=0
    for j in range(w):
        if field[i][j]=='.':
            tmp+=1
            hf[i][j]=tmp
        else:
            tmp=0
    tmp=0
    for j in range(w):
        j=w-j-1
        if field[i][j]=='.':
            if tmp == 0:
                tmp=hf[i][j]
            else:
                hf[i][j]=tmp
        else:
            tmp=0
for j in range(w):
    tmp=0
    for i in range(h):
        if field[i][j]=='.':
            tmp+=1
            vf[i][j]=tmp
        else:
            tmp=0
    tmp=0
    for i in range(h):
        i=h-i-1
        if field[i][j]=='.':
            if tmp == 0:
                tmp=vf[i][j]
            else:
                vf[i][j]=tmp
        else:
            tmp=0
mx=0
for i in range(h):
    for j in range(w):
        if hf[i][j]+vf[i][j]>mx:
            mx=hf[i][j]+vf[i][j]
print(mx-1)

Fixed submission:
h,w=map(int,input().split())
hf=[[0 for i in range(w)]for i in range(h)]
vf=[[0 for i in range(w)]for i in range(h)]
field=[]
for i in range(h):
    field.append(list(input()))
for i in range(h):
    tmp=0
    for j in range(w):
        if field[i][j]=='.':
            tmp+=1
            hf[i][j]=tmp
        else:
            tmp=0
    tmp=0
    for j in range(w):
        j=w-j-1
        if field[i][j]=='.':
            if tmp == 0:
                tmp=hf[i][j]
            else:
                hf[i][j]=tmp
        else:
            tmp=0
for j in range(w):
    tmp=0
    for i in range(h):
        if field[i][j]=='.':
            tmp+=1
            vf[i][j]=tmp
        else:
            tmp=0
    tmp=0
    for i in range(h):
        i=h-i-1
        if field[i][j]=='.':
            if tmp == 0:
                tmp=vf[i][j]
            else:
                vf[i][j]=tmp
        else:
            tmp=0
mx=0
for i in range(h):
    for j in range(w):
        if hf[i][j]+vf[i][j]>mx:
            mx=hf[i][j]+vf[i][j]
print(mx-1)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
ls,lm,rs,rm=[0],[[0 for i in range(k+1)]for i in range(n+1)],[0],[[0 for i in range(k+1)]for i in range(n+1)]
v=list(map(int,input().split()))
ld=[]
rd=[]
for i in range(n):
    ls.append(ls[-1]+v[i])
    if v[i]<0:
        ld.append(v[i])
        ld=sorted(ld)
    for j in range(1,k+1):
        if j-1<len(ld):
            lm[i+1][j]=lm[i+1][j-1]+ld[j-1]
        else:
            lm[i+1][j]=lm[i+1][j-1]
    ii=n-i-1
    rs.append(rs[-1]+v[ii])
    if v[ii]<0:
        rd.append(v[ii])
        rd=sorted(rd)
    for j in range(1,k+1):
        if j-1<len(rd):
            rm[i+1][j]=rm[i+1][j-1]+rd[j-1]
        else:
            rm[i+1][j]=rm[i+1][j-1]


mx=-9999999999
for x in range(k+1):
    for y in range(x,k+1):
        for z in range(y,k+1):
            for w in range(z,k+1):
                a,b,c,d=x,y-x,z-y,w-z
                if a>=b and c>=d and len(lm)>b and len(rm)>d and ls[a]-lm[a][b]+rs[c]-rm[c][d]>mx:
                    # print(a,b,c,d,ls[a],lm[a][b],rs[c],rm[c][d],ls[a]+lm[a][b]+rs[c]+rm[c][d])
                    mx=ls[a]-lm[a][b]+rs[c]-rm[c][d]
print(mx)


Fixed submission:
n,k=map(int,input().split())
ls,lm,rs,rm=[0],[[0 for i in range(k+1)]for i in range(n+1)],[0],[[0 for i in range(k+1)]for i in range(n+1)]
v=list(map(int,input().split()))
ld=[]
rd=[]
for i in range(n):
    ls.append(ls[-1]+v[i])
    if v[i]<0:
        ld.append(v[i])
        ld=sorted(ld)
    for j in range(1,k+1):
        if j-1<len(ld):
            lm[i+1][j]=lm[i+1][j-1]+ld[j-1]
        else:
            lm[i+1][j]=lm[i+1][j-1]
    ii=n-i-1
    rs.append(rs[-1]+v[ii])
    if v[ii]<0:
        rd.append(v[ii])
        rd=sorted(rd)
    for j in range(1,k+1):
        if j-1<len(rd):
            rm[i+1][j]=rm[i+1][j-1]+rd[j-1]
        else:
            rm[i+1][j]=rm[i+1][j-1]


mx=-999999999
for w in range(k+1):
    for x in range(w+1):
        for y in range(x,w+1):
            for z in range(y,w+1):
                    a,b,c,d=x,y-x,z-y,w-z
                    if a+c<=n and len(ls)>a>=b and len(rs)>c>=d and ls[a]-lm[a][b]+rs[c]-rm[c][d]>mx:
                        # print(a,b,c,d,ls[a],lm[a][b],rs[c],rm[c][d],ls[a]-lm[a][b]+rs[c]-rm[c][d])
                        mx=ls[a]-lm[a][b]+rs[c]-rm[c][d]
print(mx)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
n,m=map(int,input().split())
g=[set() for i in range(n)]
revg=[set() for i in range(n)]
for i in range(n+m-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].add(b)
    revg[b].add(a)
p=0
while True:
    if len(revg[p])==0:
        break
    for nxt in revg[p]:
        p=nxt
        break
ans=[-1 for i in range(n)]
ans[p]=0
def check(pos):
    if len(g[pos])==0:
        return
    for nxt in g[pos]:
        revg[nxt].remove(pos)
    for nxt in g[pos]:
        if len(revg[nxt])==0 and ans[nxt]==-1:
            ans[nxt]=pos+1
            check(nxt)
check(p)
print(*ans,sep='\n')
        

Fixed submission:
# coding: utf-8
import sys
sys.setrecursionlimit(100000)
n,m=map(int,input().split())
g=[set() for i in range(n)]
revg=[set() for i in range(n)]
for i in range(n+m-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].add(b)
    revg[b].add(a)
p=0
while True:
    if len(revg[p])==0:
        break
    for nxt in revg[p]:
        p=nxt
        break
ans=[-1 for i in range(n)]
ans[p]=0
def check(pos):
    for nxt in g[pos]:
        revg[nxt].remove(pos)
    for nxt in g[pos]:
        if len(revg[nxt])==0 and ans[nxt]==-1:
            ans[nxt]=pos+1
            check(nxt)
check(p)
print(*ans,sep='\n')