Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
ans = 0
for i in range(N):
    if A[i] >= B[i]:
        ans += B[i]
    else: 
        if B[i] >= (A[i] + A[i+1]):
            ans += (A[i] + A[i+1])
            A[i+1] = 0
        
        elif B[i] < (A[i] + A[i+1]):
            print(ans)
            ans += B[i]
            print(ans)
            A[i+1] = (A[i] + A[i+1]) - B[i]
    print(A,ans)
print(ans)





Fixed submission:
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
ans = 0
for i in range(N):
    if A[i] >= B[i]:
        ans += B[i]
    else: 
        if B[i] >= (A[i] + A[i+1]):
            ans += (A[i] + A[i+1])
            A[i+1] = 0
        
        elif B[i] < (A[i] + A[i+1]):
            ans += B[i]
            A[i+1] = (A[i] + A[i+1]) - B[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
a = sum(A)
ans = 0
for i in range(N):
    tmp = A[i]+A[i+1]-B[i]
    ans = ans + max(0,tmp-A[i+1])
    A[i+1] = min(A[i+1],tmp)
    print(A)

print(a - ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
ans = 0
for i in range(N):
    if A[i] >= B[i]:
        ans += B[i]
    else: 
        if B[i] >= (A[i] + A[i+1]):
            ans += (A[i] + A[i+1])
            A[i+1] = 0
        
        elif B[i] < (A[i] + A[i+1]):
            ans += B[i]
            A[i+1] = (A[i] + A[i+1]) - B[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
a = sum(A)
ans = 0
for i in range(N):
    tmp = A[i]+A[i+1]-B[i]
    ans = ans + max(0,tmp-A[i+1])
    A[i+1] = min(A[i+1],tmp)
    print(A)

print(a - ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
ans = 0
for i in range(N):
    if A[i] >= B[i]:
        ans += B[i]
    else: 
        if B[i] >= (A[i] + A[i+1]):
            ans += (A[i] + A[i+1])
            A[i+1] = 0
        
        elif B[i] < (A[i] + A[i+1]):
            ans += B[i]
            A[i+1] = (A[i] + A[i+1]) - B[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N,K = map(int,input().split(" "))
x = N - K #red ball
for i in range(1,K+1):
    a = math.factorial(x+1) // (math.factorial(i)*math.factorial(x+1-i))
    b = math.factorial(K-1) // (math.factorial(i-1)*math.factorial(K-i))
    print(a * b % (10**9+7))


Fixed submission:
import math
N,K = map(int,input().split(" "))
x = N - K #red ball
for i in range(1,K+1):
    if x+1-i >= 0:
        a = math.factorial(x+1) // (math.factorial(i)*math.factorial(x+1-i))
    else:
        a = 0
    b = math.factorial(K-1) // (math.factorial(i-1)*math.factorial(K-i))
    print(a * b % (10**9+7))

Buggy python submission (verdict: Runtime Error):
import math
N,K = map(int,input().split(" "))
x = N - K #red ball
for i in range(1,K+1):
    a = math.factorial(x+1) // (math.factorial(i)*math.factorial(x+1-i))
    b = math.factorial(K-1) // (math.factorial(i-1)*math.factorial(K-i))
    print(a * b % (10**9+7))


Fixed submission:
import math
N,K = map(int,input().split(" "))
x = N - K #red ball
for i in range(1,K+1):
    if x+1-i >= 0:
        a = math.factorial(x+1) // (math.factorial(i)*math.factorial(x+1-i))
    else:
        a = 0
    b = math.factorial(K-1) // (math.factorial(i-1)*math.factorial(K-i))
    print(a * b % (10**9+7))
Buggy python submission (verdict: Runtime Error):
from collections import deque
import copy

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

V = deque(map(int,input().split(" ")))

def search(N,K,V,score,a,b):
    if a+b < min(N,K):
        Vb = copy.copy(V)
        scoreA = copy.copy(score)
        scoreB=copy.copy(score)
        scoreA.append(V.popleft())
        A = search(N,K,V,scoreA,a+1,b)
        scoreB.append(Vb.pop())
        B = search(N,K,Vb,scoreB,a,b+1)
    score = sorted(score)
    counter = 0
    while(counter < K-a-b):
        if len(score)== 0:
            break;
        if score[0]<0:
            score.pop(0)
            counter +=1
        else:
            break;
    ans = sum(score)
    if a+b < min(N,K):
        return max(0,ans,A,B)
    else:
        return max(0,ans)

score = []
a = 0
b= 0
ans = search(N,K,V,score,a,b)
print(ans)

Fixed submission:
A,P = map(int,input().split(" "))
print((A*3+P)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split(" "))
card = {i+1 for i in range(n)}

for i in range(m):
    l,r = map(int,input().split(" "))
    tmp = set()
    for j in range(l,r+1):
        tmp.add(j)

    card = card.intersection(tmp)
print(len(card))

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

x,y = map(int,input().split(" "))
for i in range(m-1):
    l,r = map(int,input().split(" "))
    x = max(x,l)
    y = min(y,r)

if y-x >= 0:
    print(y-x+1)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split(" "))
card = {i+1 for i in range(n)}

for i in range(m):
    l,r = map(int,input().split(" "))
    tmp = set()
    for j in range(l,r+1):
        tmp.add(j)

    card = card.intersection(tmp)
print(len(card))

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

x,y = map(int,input().split(" "))
for i in range(m-1):
    l,r = map(int,input().split(" "))
    x = max(x,l)
    y = min(y,r)

if y-x >= 0:
    print(y-x+1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split(" ")))
b = a[0]
for i in range(n-1):
    b = math.gcd(b,a[i+1])
for i in range(n-1):
    if math.gcd(a[i],a[i+1]) == b:
        a[i] = min(a[i],a[i+1])
        a[i+1] = min(a[i],a[i+1])
        break;
b = a[0]
for i in range(n-1):
    b = math.gcd(b,a[i+1])
print(b)


Fixed submission:
import fractions
n = int(input())
a = list(map(int,input().split(" ")))
l = [0 for i in range(n+1)]
r = [0 for i in range(n+1)]
for i in range(n):
    l[i+1] = fractions.gcd(l[i],a[i])

for i in range(n-1,-1,-1):
    r[i] = fractions.gcd(r[i+1],a[i])



m = 1
for i in range(n):
    m = max(m,fractions.gcd(l[i],r[i+1]))
print(m)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split(" "))
s = list(input())

a = [0]
tmp = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        tmp += 1
    else:
        a.append(tmp)
        tmp += 1
a.append(tmp)
m = len(a)
ans = 1
i = 1
if len(a) == 2 or m-2*k < 1:
    ans = a[m-1]
elif s[0] == "1":
    while (i <= m-2*k):
        if i % 2 != 0:        
            ans = max(ans,a[2*k+i]-a[i-1])
        else:
            ans = max(ans,a[2*k+i-1]-a[i-1])
        i += 1
else:
    while (i < m-2*k):
        if i % 2 == 0:        
            ans = max(ans,a[2*k+i]-a[i-1])
        else:
            ans = max(ans,a[2*k+i-1]-a[i-1])
        i += 1
print(ans)


Fixed submission:
n,k = map(int,input().split(" "))
s = list(input())
a = [1]
for i in range(1,n):
    if s[i] != s[i-1]:
        a.append(i+1)
m = len(a)
ans = 1
i = 1
for i in range(m):
    if s[a[i]-1] == "1":
        if 2*k + i +1 < m:        
            ans = max(ans,a[2*k+i+1]-a[i])
        else:
            ans = max(ans,n+1- a[i])
    else:
        if 2*k+i< m:        
            ans = max(ans,a[2*k+i]-a[i])
        else:
            ans = max(ans,n+1-a[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split(" "))
s = list(input())

a = [0]
tmp = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        tmp += 1
    else:
        a.append(tmp)
        tmp += 1
a.append(tmp)
m = len(a)
ans = 1
if len(a) == 2 or m-2*k < 1:
    ans = a[m-1]
elif s[0] == "1":
    for i in range(1,m-2*k+1):
        if i % 2 != 0:        
            ans = max(ans,a[2*k+i]-a[i-1])
        else:
            ans = max(ans,a[2*k+i-1]-a[i-1])
else:
    for i in range(1,m-2*k):
        if i % 2 == 0:        
            ans = max(ans,a[2*k+i]-a[i-1])
        else:
            ans = max(ans,a[2*k+i-1]-a[i-1])

print(ans)


Fixed submission:
n,k = map(int,input().split(" "))
s = list(input())
a = [1]
for i in range(1,n):
    if s[i] != s[i-1]:
        a.append(i+1)
m = len(a)
ans = 1
i = 1
for i in range(m):
    if s[a[i]-1] == "1":
        if 2*k + i +1 < m:        
            ans = max(ans,a[2*k+i+1]-a[i])
        else:
            ans = max(ans,n+1- a[i])
    else:
        if 2*k+i< m:        
            ans = max(ans,a[2*k+i]-a[i])
        else:
            ans = max(ans,n+1-a[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
A = input()
l = A.split(,)
print(l[0],' ',l[1],' ',l[2],' ')

Fixed submission:
A = input()
l = A.split(',')
print(l[0],' ',l[1],' ',l[2],' ')
Buggy python submission (verdict: Runtime Error):
c = inuput()
if c == 'a' or c == 'i' or c == 'u' or c == 'e' or c == 'o':
  print('vowel')
else:
  print("consonant")
  

Fixed submission:
c = input()
if c == 'a' or c == 'i' or c == 'u' or c == 'e' or c == 'o':
  print('vowel')
else:
  print("consonant")

Buggy python submission (verdict: Runtime Error):
c = inuput()
if c == 'a' or c == 'i' or c == 'u' or c == 'e' or c == 'o':
  print('vowel')
else:
  print("consonant"
  

Fixed submission:
c = input()
if c == 'a' or c == 'i' or c == 'u' or c == 'e' or c == 'o':
  print('vowel')
else:
  print("consonant")
Buggy python submission (verdict: Runtime Error):
def X(A,B,C):
  if A == 5 or A == 7:
    if B == 5 or B == 7:
      if C == 5 or C == 7:
          if A + B + C == 19:
              return "YES"
  return "NO"
A,B,C = int(input())
print(X(A,B,C))
  
  

Fixed submission:
def X(A,B,C):
  if A == 5 or A == 7:
    if B == 5 or B == 7:
      if C == 5 or C == 7:
          if A + B + C == 17:
              return "YES"
  return "NO"
A,B,C = map(int, input().split())
print(X(A,B,C))
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
if K%2==0 or K%5==0:
  print(-1)
else:
  n = 1
  while True:
    if 7*(10**n-1)/9%K==0:
      print(n)
      break

Fixed submission:
K = int(input())
if K%2==0 or K%5==0:
  print(-1)
else:
  n = 1
  Rem = 7%K
  while Rem!=0:
    Rem = (Rem*10+7)%K
    n+=1
  print(n)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
n=0
if S.find("W")==-1 or S.find("R")==-1:
  print(0)
else:
  while S.find("W")<=S.rfind("R"):
    S = S[S.find("W")+1:S.rfind("R")]
    n+=1
  print(n)

Fixed submission:
N = int(input())
S = input()
n=0
if S.find("W")==-1 or S.find("R")==-1:
  print(0)
else:
  while S.find("W")<S.rfind("R") and S.find("W")>=0:
    S = S[S.find("W")+1:S.rfind("R")]
    n+=1
  print(n)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([float(x) for x in input().split()])
cut = [1]*N
chip = Logs.copy()
for i in range(K):
  x = np.argmax(chip)
  cut[x]+=1
  chip[x]= Logs[x]/cut[x]
print(math.ceil((max(chip))))

Fixed submission:
import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([int(x) for x in input().split()])
ave = sum(Logs)/(N+K)
cut = np.array([max(1,int(x/ave)) for x in Logs])
chip = Logs/cut
chip=np.sort(chip)[::-1]
print(math.ceil(chip[N+K-sum(cut)]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([float(x) for x in input().split()])
cut = [1.0]*N
chip = Logs.copy()
for i in range(K):
  x = np.argmax(chip)
  cut[x]+=1.0
  chip[x]= Logs[x]/cut[x]
print(math.ceil((max(chip))))

Fixed submission:
import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([int(x) for x in input().split()])
ave = sum(Logs)/(N+K)
cut = np.array([max(1,int(x/ave)) for x in Logs])
chip = Logs/cut
chip=np.sort(chip)[::-1]
print(math.ceil(chip[N+K-sum(cut)]))
Buggy python submission (verdict: Runtime Error):
if input().upper()==input():
  print("A")
else:
  print("a")

Fixed submission:
S=input()
if S.upper()==S:
  print("A")
else:
  print("a")
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

N = int(input())
A = [int(x) for x in input().split()]

B=[reduce(lambda a, b: a^b, A[:i]+A[(i+1):]) for i in range(N)]
[print(x) for x in B]

Fixed submission:
from functools import reduce

N = int(input())
A = [int(x) for x in input().split()]
SUM=reduce(lambda a, b: a^b, A)

[print(SUM^A[i]) for i in range(N)]

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

N = int(input())
A = [int(x) for x in input().split()]

B=[reduce(lambda a, b: a^b, A[:i]+A[(i+1):]) for i in range(N)]
[print(x) for x in B]

Fixed submission:
from functools import reduce

N = int(input())
A = [int(x) for x in input().split()]
SUM=reduce(lambda a, b: a^b, A)

[print(SUM^A[i]) for i in range(N)]
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[int(x) for x in input().split()]
for i in range(N):
  print(A[i:].count(i+1))

Fixed submission:
import collections
N=int(input())
A=[x for x in input().split()]
c = collections.Counter(A)
for i in range(N):
	print(c["{}".format(str(i+1))])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[int(x) for x in input().split()]
for i in range(N):
  print(A.count(i+1))
  A = A[1:]

Fixed submission:
import collections
N=int(input())
A=[x for x in input().split()]
c = collections.Counter(A)
for i in range(N):
	print(c["{}".format(str(i+1))])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[int(x) for x in input().split()]
for i in range(N):
  print(A.count(i+1))

Fixed submission:
import collections
N=int(input())
A=[x for x in input().split()]
c = collections.Counter(A)
for i in range(N):
	print(c["{}".format(str(i+1))])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,K=map(int,input().split())
a = np.array([int(x) for x in input().split()])
v = np.array([1]*K)
print(max(np.convolve(a, v, mode='valid'))/2+0.5*K)

Fixed submission:
import numpy as np
N,K=map(int,input().split())
a = np.array([int(x) for x in input().split()])
val=sum(a[:K])
max_val=val
for i in range(N-K):
  val+=a[K+i]
  val-=a[i]
  max_val=max(val,max_val)
print(max_val/2+K*0.5)
Buggy python submission (verdict: Time Limit Exceeded):
H,N=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())
dp = [99999999999]*(H+1)
dp[0]=0
for h in range(H):
  for i in range(N):
    dp[min(H,h+A[i])]=min(dp[h] + B[i], dp[min(H,h+A[i])])
print(dp[-1])

Fixed submission:
H,N=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())
dp = [99999999999]*(H+1)
dp[0]=0
for h in range(H):
  for i in range(N):
    dp[min(H,h+A[i])]=min(dp[h] + B[i], dp[min(H,h+A[i])])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
H,N=map(int,input().split())
A=np.array([0]*N)
B=np.array([0]*N)
for i in range(N):
  A[i],B[i]=map(int,input().split())
dp = [np.inf]*(H+1)
dp[0]=0
for h in range(H):
  for i in range(N):
    dp[min(H,h+A[i])]=min(dp[h] + B[i], dp[min(H,h+A[i])])
print(dp[-1])

Fixed submission:
H,N=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())
dp = [99999999999]*(H+1)
dp[0]=0
for h in range(H):
  for i in range(N):
    dp[min(H,h+A[i])]=min(dp[h] + B[i], dp[min(H,h+A[i])])
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
H,N=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())
dp=[np.inf]*(H+1)
dp[0]=0
for h in range(H):
  for i in range(N):
    dp[min(H,h+A[i])]=min(dp[h] + B[i], dp[min(H,h+A[i])])
print(dp[-1])
                 

Fixed submission:
H,N=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())
dp = [99999999999]*(H+1)
dp[0]=0
for h in range(H):
  for i in range(N):
    dp[min(H,h+A[i])]=min(dp[h] + B[i], dp[min(H,h+A[i])])
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a<=b:
  for i in range(b):
    print(a)
else:
    for i in range(a):
    print(b)

Fixed submission:
a,b=map(int,input().split())
if a<=b:
	print(int(a*(10**(b)-1)/9))
else:
	print(int(b*(10**(a)-1)/9))
Buggy python submission (verdict: Runtime Error):
a,b,c＝map(int,input().split())
print(a+b+c-max(a,b,c))

Fixed submission:
a,b,c=map(int,input().split())
print(a+b+c-max(a,b,c))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
dct = defaultdict(int)

for i in range(N):
  s = input()
  sorted_s = "".join(sorted(s))
  dct[sorted_s] += 1

ans = 0
for k, v in dct.items():
  ans += v*(v-1)//2

print(ans)

Fixed submission:
from collections import defaultdict
import heapq
N, M = map(int, input().split())
dct = defaultdict(list)

for i in range(N):
  A, B = map(int, input().split())
  dct[A].append(-B)

h = []
ans = 0
for i in range(1,M+1):
  if dct[i]:
    for item in dct[i]:
      heapq.heappush(h,item)
  if h:
    ans += heapq.heappop(h)

print(-ans)
Buggy python submission (verdict: Runtime Error):
n, X = map(int, input().split())
import numpy as np

x = np.array(list(map(int, input().split())))
x -= X

x = np.abs(x)
D = 0
from math import gcd

for d in x:
  D = gcd(D,d)

print(D)

Fixed submission:
n, X = map(int, input().split())
import numpy as np

x = np.array(list(map(int, input().split())))
x -= X

x = np.abs(x)
D = 0
from fractions import gcd

for d in x:
  D = gcd(D,d)

print(D)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

f = 1

for ai in a:
    # g = gcd(g, ai)
    for n, cnt in factorization(ai):
        if n in d:
            f = 0
        if n != 1:
            d[n] += 1



if f:
    print('pairwise coprime')
else:
    f2 = 1
    for key in d:
        if d[key] == N:
            f2 = 0
            break
    if f2:
        print('setwise coprime')
    else:
        print('not coprime ') 



Fixed submission:
from math import gcd

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

am = max(a)

memo = [1] * (am+1)
memo[0] = 0
memo[1] = 0

d = set([])

for ai in range(2, am+1):
    for j in range(2, am // ai + 1):
        memo[ai * j] = 0

cs = set([])
for i, memoi in enumerate(memo):
    if memoi:
        cs.add(i)

# print(cs)


f1 = 1
f2 = 1

for ai in a:
    lim = int(ai**0.5)+1
    f0 = 0
    if ai in cs:
        if ai in d:
            f0 = 1
            f1 = 0
        else:
            d.add(ai)
    else:  
        for i in cs:
            if i >= lim:
                break
            if ai % i == 0:
                if i in d or ai//i in d:
                    f1 = 0
                    f0 = 1
                    break
                else:
                    d.add(i)
                    d.add(ai//i)
    if f0:
        break


if f1:
    print('pairwise coprime')
else:
    g = a[0]
    for ai in a:
        g = gcd(ai, g)
    if g == 1:
        print('setwise coprime')
    else:
        print('not coprime')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

r, c, k = map(int, input().split())
v = [[0 for j in range(c)] for i in range(r)]

dp = [[[0 for k in range(4)] for j in range(c)] for i in range(r)]

for i in range(k):
    ri, ci, vi = map(int, input().split())
    v[ri-1][ci-1] = vi


for i in range(r):
    if i > 0:
        for j in range(c):
            for k in range(4):
                dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][k])
    for j in range(c):
        if j > 0:
            for k in range(4):
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
        if v[i][j]:
            for k in reversed(range(1, 4)):
                dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1]+v[i][j])
        

ans = 0

for k in range(4):
    ans = max(ans, dp[r-1][c-1][k])

print(ans)
        

Fixed submission:
import sys
input = sys.stdin.readline

r, c, k = map(int, input().split())
v = [[0 for j in range(c)] for i in range(r)]

dp = [[[0 for j in range(c)] for i in range(r)] for k in range(4)]

for i in range(k):
    ri, ci, vi = map(int, input().split())
    v[ri-1][ci-1] = vi


for i in range(r):
    if i > 0:
        for j in range(c):
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])
    for j in range(c):
        if j > 0:
            for k in range(4):
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
        if v[i][j]:
            for k in reversed(range(1, 4)):
                dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j]+v[i][j])
        

ans = 0

for k in range(4):
    ans = max(ans, dp[k][r-1][c-1])

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

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

if k == 0:
    print(max(a))
    sys.exit()

def check(t):
    ans = 0
    for ai in a:
        if ai > t:
            ans += ai // t
    return ans <= k

l = 0
r = 10 ** 9 + 1

while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

if check(l):
    print(l)
else:
    print(r)



Fixed submission:
import sys

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

if k == 0:
    print(max(a))
    sys.exit()

def check(t):
    if t == 0:
        return False
    ans = 0
    for ai in a:
        if ai > t:
            ans += ai // t
    return ans <= k

l = 0
r = 10 ** 9 + 1

while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

if check(l):
    print(l)
else:
    print(r)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

def check(t):
    ans = 0
    for ai in a:
        if ai > t:
            ans += ai // t
    return ans <= k

l = 0
r = 10 ** 9 + 1

while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

if check(l):
    print(l)
else:
    print(r)



Fixed submission:
import sys

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

if k == 0:
    print(max(a))
    sys.exit()

def check(t):
    if t == 0:
        return False
    ans = 0
    for ai in a:
        if ai > t:
            ans += ai // t
    return ans <= k

l = 0
r = 10 ** 9 + 1

while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

if check(l):
    print(l)
else:
    print(r)