ZhenlongDai/ACPR huggingface dataset:
Problem: p03103
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in stores:
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)


Failing test case input:
2 9
4 4
1 12

Expected output:
9


Actual output:
21


Fixed submission (verdict: Accepted):
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)
Problem: p03633
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
T = [int(input()) for i in range(N)]

dvs = []
dvs_all = []

def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

def lcm(m,n):
  return m * n / gcd(m,n)

if N == 1:
  ans = T[0]
else:
  for i in range(N - 1):
    T[i+1] = lcm(T[i], T[i+1])
    ans = T[i+1]

print(ans)

Failing test case input:
5
1
14
3
1101000001000001000
1100000010001011000

Expected output:
1211100012111114221001021001011000


Actual output:
9.934804786848983e+34


Fixed submission (verdict: Accepted):
N = int(input())
T = [int(input()) for i in range(N)]

def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

def lcm(m,n):
  return int(m * n 

ans = 1
for i in range(N):
    ans = lcm(T[i], ans)

print(ans)

Problem: p03633
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(100000)

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

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

lcm = 1
for i in T:
    lcm = lcm * i / gcd(lcm, i)

print(lcm)

Failing test case input:
5
1
13
3
0101000001000001000
1100000000011011000

Expected output:
1444300014314471743143143143143000


Actual output:
3.3850781585495427e+34


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(100000)

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

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

lcm = 1
for i in T:
    lcm = int(lcm * i 

print(lcm)

Problem: p03633
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))

def gcd(a, b):
  if a < b:
    a, b = b, a
  if b == 0:
    return a
  return gcd(b, b % a)
 
def lcm(A, B):
  return A * B 
 
print(functools.reduce(lcm, T))

Failing test case input:
5
1
5
10
0000000001000000000
1000001000000000000

Expected output:
1000001000000000000


Actual output:
50000050000000000000000000000


Fixed submission (verdict: Accepted):
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
def gcd(A, B):
  while(True):
    if A and B:
      if A > B:
        A = A % B
      else:
        B = B % A
    else:
      return max(A, B)
 
def lcm(A, B):
  return (A 
 
print(functools.reduce(lcm, sorted(T, reverse=True)))
Problem: p03633
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

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

def gcd(a,b):
  mi = min(a,b)
  ma = max(a,b)
  ans = 1
  
  while True:
    print(ma,mi)
    if (ma % mi) == 0:
      ans = mi
      break
    else:
      mi = ma%mi
      ma = mi
      
  return ans



def lcm(a,b):
  
  g = gcd(a,b)
  print(g)
  return int(a*b/g)
ans = T[0]
for i in range(1,len(T)):
  ans = lcm(ans,T[i])
print(ans)


Failing test case input:
2
7
9

Expected output:
63


Actual output:
9 7
2 2
2
31


Fixed submission (verdict: Accepted):

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

def gcd(a,b): 
  if min(a,b) == 0:
    return max(a,b)
  else:
    return gcd(min(a,b),max(a,b)%min(a,b))
    



def lcm(a,b):
  
  g = gcd(a,b)
  
  return int(a*b
ans = T[0]
for i in range(1,len(T)):
  ans = lcm(ans,T[i])
print(ans)

Problem: p03633
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a, b):
    while b > 0:
        tmp = a
        a = b
        b = tmp % b
    return a


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


n = int(input())
t = [0 for i in range(n)]
for i in range(n):
    t[i] = int(input())
sum = t[0]
for i in range(1, n):
    
    sum = lcm(sum, t[i])
    
print(sum)


Failing test case input:
5
1
29
2
1011000001000101000
1100000000011011000

Expected output:
10750300010742017803106450417073000


Actual output:
64501800064452106818638702502438000000


Fixed submission (verdict: Accepted):
def gcd(a, b):
    while b > 0:
        tmp = a
        a = b
        b = tmp % b
    return a


def lcm(a, b):
    tmp = gcd(a, b)
    return (a


n = int(input())
t = [0 for i in range(n)]
for i in range(n):
    t[i] = int(input())
t = sorted(t)
_sum = t[0]
for i in range(1, n):
    
    _sum = lcm(_sum, t[i])
    
print(_sum)

Problem: p03633
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a,b):
  r = a%b
  while(r!=0):
    a=b
    b=r
    r=a%b
  return b
def lcm(a,b):
    return (a*b)/gcd(a,b)
n = int(input())
ans = int(input())
for i in range(n-1):
  num = int(input())
  ans = lcm(max(ans,num),min(ans,num))
print(int(ans))


Failing test case input:
5
1
26
3
1011000001000101100
1100000000011011000

Expected output:
144573000144461633031431574717573000


Actual output:
112947656362860663984245420161236992


Fixed submission (verdict: Accepted):
def gcd(a,b):
  a = int(a)
  b = int(b)
  r = (int)(a%b)
  while(r!=0):
    a=(int)(b)
    b=(int)(r)
    r=(int)(a%b)
  return b
def lcm(a,b):
    return int((a*b)
n = int(input())
ans = int(input())
for i in range(n-1):
  num = int(input())
  ans = lcm(max(ans,num),min(ans,num))
print(int(ans))
Problem: p03633
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

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

def gcd(a,b):
  mi = min(a,b)
  ma = max(a,b)
  ans = 1
  
  while True:
    
    if (ma % mi) == 0:
      ans = mi
      break
    else:
      mi = ma%mi
      ma = mi
      
  return ans



def lcm(a,b):
  
  g = gcd(a,b)
  
  return int(a*b/g)
ans = T[0]
for i in range(1,len(T)):
  ans = lcm(ans,T[i])
print(ans)


Failing test case input:
5
2
58
2
1011000001000101100
1100100000011011000

Expected output:
322538319322289568925093512831509000


Actual output:
11058709324013029376


Fixed submission (verdict: Accepted):

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

def gcd(a,b): 
  if min(a,b) == 0:
    return max(a,b)
  else:
    return gcd(min(a,b),max(a,b)%min(a,b))
    



def lcm(a,b):
  
  g = gcd(a,b)
  
  return int(a*b
ans = T[0]
for i in range(1,len(T)):
  ans = lcm(ans,T[i])
print(ans)

Problem: p03633
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


n = int(input())
t = [0 for i in range(n)]
for i in range(n):
    t[i] = int(input())
sum = t[0]
for i in range(1, n):
    
    sum = lcm(sum, t[i])
    
print(sum)


Failing test case input:
5
2
4
10
0001000001000000000
1000000000000100001

Expected output:
1000001000000100001100001000000000


Actual output:
80000080000008000088000080000000000


Fixed submission (verdict: Accepted):
def gcd(a, b):
    while b > 0:
        tmp = a
        a = b
        b = tmp % b
    return a


def lcm(a, b):
    tmp = gcd(a, b)
    return (a


n = int(input())
t = [0 for i in range(n)]
for i in range(n):
    t[i] = int(input())
t = sorted(t)
_sum = t[0]
for i in range(1, n):
    
    _sum = lcm(_sum, t[i])
    
print(_sum)

Problem: p03633
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def uq(a,c):
    while(a%c!=0):
        newa=c
        c=a%c
        a=newa
    return c
        

n=(int)(input())

result = 1

for j in range(0,n):
    f=(int)(input())
    result=((result/uq(result,f)))*f
    
print((int)(result))

Failing test case input:
5
2
5
10
1000000001000000000
1000000000000000000

Expected output:
1000000001000000000000000000


Actual output:
1000000001000000066313781248


Fixed submission (verdict: Accepted):
def uq(a,c):
    return c if a%c==0 else uq(c,a%c)

n=(int)(input())

result = 1

for j in range(0,n):
    f=(int)(input())
    result=((result
    
print((int)(result))
Problem: p03633
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))

def gcd(a, b):
  if a < b:
    a, b = b, a
  if b == 0:
    return a
  return gcd(b, b % a)
 
def lcm(A, B):
  return A * B 
 
print(functools.reduce(lcm, sorted(T, reverse=True)))

Failing test case input:
5
1
6
9
1001000001000000000
1100000000000000000

Expected output:
3303300003300000000000000000


Actual output:
59459400059400000000000000000000000000


Fixed submission (verdict: Accepted):
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
def gcd(A, B):
  while(True):
    if A and B:
      if A > B:
        A = A % B
      else:
        B = B % A
    else:
      return max(A, B)
 
def lcm(A, B):
  return (A 
 
print(functools.reduce(lcm, sorted(T, reverse=True)))

Problem: p03633
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(x,y):
    if x<y:
        x,y = y,x
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
T = list(set([int(input()) for _ in range(N)]))
a = T[0]
for i in range(1,len(T)):
    a = gcd(T[i],a)
t = a
for i in range(len(T)):
    t *= T[i]
print(t)

Failing test case input:
5
2
57
2
1011000001000101100
1100000000011011000

Expected output:
211299000211136232892092301510299000


Actual output:
126779400126681739735255380906179400000


Fixed submission (verdict: Accepted):
def gcd(x,y):
    if x<y:
        x,y = y,x
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
T = list(set([int(input()) for _ in range(N)]))
t = 1
b = T[0]
for i in range(1,len(T)):
    a = gcd(T[i],b)
    b = a*(T[i]
print(b)
Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import bisect 
n,k = map(int,input().split())
x = list(map(int,input().split()))

w  = x.count(0)
for i in range(w):
    x.remove(0)

if k <= w:
    print(0)
else:
    k = k -w
    

    r = bisect.bisect_left(x,0)
    
    if x[-1]<0:
        print(x[len(x)-k])
    else:
        ass = 10 ** 10
        for i in range(r,min(len(x),r + k )):
            if i-r+1 >= k:
                ans = abs(x[i])
            elif i == r and r-k >= 0:
                ans = abs(x[r-k])
            else:
                ans = x[i] + abs(x[i-k+1]) + min(x[i],abs(x[i-k+1]))
            ass = min(ass,ans)
        print(ass)

Failing test case input:
5 5
-50 -10 10 20 50

Expected output:
150


Actual output:
40


Fixed submission (verdict: Accepted):

import bisect 
n,k = map(int,input().split())
x = list(map(int,input().split()))

w  = x.count(0)
for i in range(w):
    x.remove(0)

if k <= w:
    print(0)
else:
    k = k -w
    

    r = bisect.bisect_left(x,0)
    
    if x[-1]<0:
        print(abs(x[len(x)-k]))
    elif x[0] > 0:
        print(x[k-1])    
    else:
        ass = 10 ** 10
        ans = 10**10
        for i in range(r,min(len(x),r + k )):
            if i-r+1 >= k:
                ans = abs(x[i])
            
            else:
                if i - k + 1 >= 0:
                    ans = x[i] + abs(x[i-k+1]) + min(x[i],abs(x[i-k+1]))
            ass = min(ass,ans)
        if r-k >= 0:
            ans = abs(x[r-k])
        ass = min(ass,ans)
        print(ass)

Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    X = [int(c) for c in input().split()]

    def fullsearch():
        for i in range(N-K):
            l = X[i]
            r = X[i+K-1]
            distance = abs(r - l)
            if abs(l) > abs(r):
                distance += abs(r)
            else:
                distance += abs(l)
            yield distance

    if N == K:
        print(0)
    else:
        print(min(fullsearch()))

main()

Failing test case input:
5 5
-38 -1 11 12 94

Expected output:
170


Actual output:
0


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    X = [int(c) for c in input().split()]

    def fullsearch():
        for i in range(N-K+1):
            l = X[i]
            r = X[i+K-1]
            distance = abs(r - l)
            yield distance + abs(r)
            yield distance + abs(l)

    print(min(fullsearch()))

main()
Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K=map(int,input().split())
x=list(map(int,input().split()))

ans=max(x)-min(x)

for i in range(N-K+1):
    ans=min(ans,x[i+K-1]-x[i]+min(abs(x[i]),abs(x[i+K-1])))

if N==1:
    ans=x[0]
print(ans)

Failing test case input:
5 5
-30 -10 8 20 76

Expected output:
136


Actual output:
106


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
x=list(map(int,input().split()))

ans=max(x)-min(x)+max(max(x),abs(min(x)))

for i in range(N-K+1):
    ans=min(ans,x[i+K-1]-x[i]+min(abs(x[i]),abs(x[i+K-1])))


print(ans)

Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b = list(map(int, input().split()))
n = list(map(int, input().split()))

ans = []
for i, name in enumerate(n):
    if b+i >a:
        break
    ans.append(min( (abs(n[i]) + abs(n[i +b-1] - n[i]),  (n[i+b-1]) + abs(n[i +b-1] - n[i]) )) )

print(min(ans))

Failing test case input:
8 4
-14 -7 -1 -11 1 1 3 8

Expected output:
3


Actual output:
-8


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

ans = []
for i, name in enumerate(n):
    if b+i >a:
        break
    ans.append(min( (abs(n[i]) + abs(n[i +b-1] - n[i]),  abs(n[i+b-1]) + abs(n[i +b-1] - n[i]) )) )

print(min(ans))

Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
c = list(map(int, input().split()))
ans = float('Inf')
for i in range(n-k+1):
  l, r = abs(c[i]), abs(c[i+k-1])
  
  if c[i] < 0 and r > 0:
    ans = min(ans, min(l, r) * 2 + max(l, r))
  else:
    ans = min(ans, max(l, r))
print(ans)

Failing test case input:
5 1
-19 -7 11 38 106

Expected output:
7


Actual output:
11


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
c = list(map(int, input().split()))
ans = float('Inf')
for i in range(n-k+1):
  l, r = c[i], c[i+k-1]
  ans = min(abs(l) + abs(r-l), abs(r) + abs(r-l), ans)

print(ans)

Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**9
  
for i in range(n-k+1):
  if x[k-1+i]*x[i] < 0:
    if x[k-1+i] <= abs(x[i]) :
      temp = 2*x[k-1+i] - x[i]
    elif abs(x[i]) < x[k-1+i]:
      temp = x[k-1+i] - 2*x[i]
      
  elif (0 <= x[i]):
    temp = x[k+i-1]

  elif (x[k+i-1] <= 0):
    temp = -x[0]
    
  if temp < ans:
    ans = temp
    
print(ans)

Failing test case input:
5 1
-19 -7 11 38 106

Expected output:
7


Actual output:
11


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**9
  
for i in range(n-k+1):
  if x[k-1+i]*x[i] < 0:
    if x[k-1+i] <= abs(x[i]) :
      temp = 2*x[k-1+i] - x[i]
    elif abs(x[i]) < x[k-1+i]:
      temp = x[k-1+i] - 2*x[i]
      
  elif (0 <= x[i]):
    temp = x[k+i-1]

  elif (x[k+i-1] <= 0):
    temp = -x[i]
    
  if temp < ans:
    ans = temp
    
print(ans)
Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
X = list(map(int, input().split()))
INF = 1000000000
distances = [INF]*(2*(N-K+1))
for l in range(N-K+1):
    distances[l]=abs(X[l]) + abs(X[l] - X[l+K-1])
    distances[l+1]=abs(X[l+K-1]) + abs(X[l] - X[l+K-1])

print(min(distances))


Failing test case input:
5 4
-31 -5 16 20 67

Expected output:
71


Actual output:
77


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
X = list(map(int, input().split()))
INF = 1000000000
distances = [INF]*(2*(N-K+1))
for l in range(N-K+1):
    distances[l] = abs(X[l]) + abs(X[l] - X[l+K-1])
    distances[l+N-K+1] = abs(X[l+K-1]) + abs(X[l] - X[l+K-1])

print(min(distances))

Problem: p03274
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k = map(int, input().split())
x = list(map(int, input().split()))
minus = [0]
plus = [0]
for i in x:
    if x:
        plus.append(x)
    else:
        minus.append(-x)
k -= 1
ans = x[-1] - x[0]
for i in range(n-k):
    if x[i+k] < 0:
        ans = min(ans, -x[i])
    elif 0 < x[i+k] and x[i] < 0:
        if -x[i] < x[i+k]:
            ans = min(ans, abs(2*(x[i])) + x[i+k])
        else:
            ans = min(ans, 2*x[i+k] + abs(x[i]))
    else:
        ans = min(ans, x[i+k])
    
print(ans)

Failing test case input:
5 5
-17 -10 10 20 58

Expected output:
92


Actual output:
75


Fixed submission (verdict: Accepted):
n,k = map(int, input().split())
x = list(map(int, input().split()))
minus = [0]
plus = [0]
for i in x:
    if x:
        plus.append(x)
    else:
        minus.append(-x)
k -= 1
ans = 1000000000000000
for i in range(n-k):
    if x[i+k] < 0:
        ans = min(ans, -x[i])
    elif 0 < x[i+k] and x[i] < 0:
        if -x[i] < x[i+k]:
            ans = min(ans, abs(2*(x[i])) + x[i+k])
        else:
            ans = min(ans, 2*x[i+k] + abs(x[i]))
    else:
        ans = min(ans, x[i+k])
    
print(ans)

Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split(' '))
a= list(map(int, input().split(' ')))

INF = float('inf')
ans = INF

for i in range(N-K):
    ans = min(ans, abs(a[i+K-1]-a[i])+min(abs(a[i+K-1]), abs(a[i])))

print(ans)

Failing test case input:
5 5
-51 -10 10 20 58

Expected output:
160


Actual output:
inf


Fixed submission (verdict: Accepted):
N, K = map(int, input().split(' '))
a= list(map(int, input().split(' ')))

INF = float('inf')
ans = INF

if N == K:
    ans = abs(a[N-1]-a[0])+min(abs(a[0]), abs(a[N-1]))
else:
    for i in range(N-K+1):
        ans = min(ans, abs(a[i+K-1]-a[i])+min(abs(a[i+K-1]), abs(a[i])))

print(ans)
Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
lst = list(map(int, input().split()))
ans = 2 * 10 ** 5
for i in range(N-K+1):
	k_lst = lst[i:i+K]
	left = min(k_lst)
	right = max(k_lst)
	if (left > right):
		dis = abs(left - right) + abs(right)
	else:
		dis = abs(left - right) + abs(left)
	if (dis < ans):
		ans = dis    
print(ans)


Failing test case input:
5 5
-19 -7 5 14 14

Expected output:
47


Actual output:
52


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
lst = list(map(int, input().split()))
ans = 10 ** 10
for i in range(N-K+1):
	left = lst[i]
	right = lst[i+K-1]
	if (abs(left) > abs(right)):
		dis = abs(left - right) + abs(right)
	else:
		dis = abs(left - right) + abs(left)
	if (dis < ans):
		ans = dis    
print(ans)

Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
X = list(map(int, input().split()))

answer = 10 ** 9
for i in range(N-K+1):
    b, c = X[i], X[i+K-1]
    if b * c >= 0:
        answer = min(answer, max(abs(b), abs(c)))
    else:
        answer = min(answer, abs(b)*2+abs(c))
print(answer)

Failing test case input:
5 4
-31 -5 16 20 67

Expected output:
71


Actual output:
77


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
X = list(map(int, input().split()))

answer = 10 ** 9
for i in range(N-K+1):
    b, c = X[i], X[i+K-1]
    if b * c >= 0:
        answer = min(answer, max(abs(b), abs(c)))
    else:
        d, e = min(abs(b), abs(c)), max(abs(b), abs(c))
        answer = min(answer, d*2+e)
print(answer)

Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
X = list(map(int,input().split()))
ans = 10**9
for i in range(N-K+1):
    ans = min(ans,abs(X[i])+abs(X[i+K-1])+min(abs(X[i]),abs(X[i+K-1])))
print(ans)

Failing test case input:
8 4
-14 -7 -4 -11 1 2 3 4

Expected output:
4


Actual output:
6


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
X = list(map(int,input().split()))

ans = 10**9
for i in range(N-K+1):
    ans = min(ans,X[i+K-1]-X[i]+min(abs(X[i]),abs(X[i+K-1])))
print(ans)

Problem: p03274
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K=map(int,input().split())
X=list(map(int,input().split()))
if N==1:
  print(0);exit()

ans=float("Inf")
for i in range(N-K):
  ans=min(ans, X[i+K-1]-X[i]+ min(abs(X[i+K-1]),abs(X[i]))  )

print(ans)
  

Failing test case input:
5 5
-72 -7 8 20 106

Expected output:
250


Actual output:
inf


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
X=list(map(int,input().split()))
if N==1:
  print(0);exit()

ans=float("Inf")
for i in range(N-K+1):
  ans=min(ans, X[i+K-1]-X[i]+ min(abs(X[i+K-1]),abs(X[i]))  )

print(ans)
Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


def main():
    n, k = map(int, input().split())
    x_list = list(map(int, input().split()))

    ans = float('inf')

    for i in range(n - k + 1):
        if x_list[i] >= 0 and x_list[i+k-1] >= 0:
            ans = min(ans, x_list[i+k-1])
        elif x_list[i] < 0 and x_list[i+k-1] < 0:
            ans = min(ans, -x_list[i])
        else:
            ans = min(ans, -x_list[i] * 2 + x_list[i+k-1])
    print(ans)

if __name__ == '__main__':
    main()

Failing test case input:
5 5
-19 -7 5 14 14

Expected output:
47


Actual output:
52


Fixed submission (verdict: Accepted):


def main():
    n, k = map(int, input().split())
    x_list = list(map(int, input().split()))
    ans = float('inf')

    for i in range(n - k + 1):
        if x_list[i] >= 0 and x_list[i+k-1] >= 0:
            ans = min(ans, x_list[i+k-1])
        elif x_list[i] <= 0 and x_list[i+k-1] <= 0:
            ans = min(ans, -x_list[i])
        else:
            ans = min(ans, min(-x_list[i] * 2 + x_list[i+k-1] , -x_list[i] + x_list[i+k-1] * 2))
    print(ans)

if __name__ == '__main__':
    main()

Problem: p03274
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 10**10
for i in range(n-k+1):
    tmp = a[k+i-1] - a[i] + abs(a[i])
    if ans > tmp:
        ans = tmp
print(ans)

Failing test case input:
5 5
-58 -11 7 20 50

Expected output:
158


Actual output:
166


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 10**10
for i in range(n-k+1):
    tmp = min(abs(a[k+i-1] - a[i]) + abs(a[i]), abs(a[k+i-1] - a[i]) + abs(a[k+i-1]))
    if ans > tmp:
        ans = tmp
print(ans)

Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
x = list(map(int,input().split()))
ans=float("inf")

for i in range(K):
    if i + K >= N+1:
        break
    else:
        a = min(abs(x[K+i-1]),abs(x[i])) 
        ans = min(ans,x[K+i-1]-x[i]+a)
print(ans)


Failing test case input:
5 1
-19 -7 11 38 106

Expected output:
7


Actual output:
19


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
x = list(map(int,input().split()))
ans=float("inf")

for i in range(N-K+1):
    if i + K == N+1:
        break
    else:
        a = min(abs(x[K+i-1]),abs(x[i])) 
        ans = min(ans,x[K+i-1]-x[i]+a)
print(ans)
Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
n, k = map(int, input().split())
X = list(map(int, input().split()))

ans = float('inf')
if n == 1:
    ans = abs(X[0])
for i in range(n):
    temp = 0
    
    if X[i] <= 0:
        if not 0 <= i+k-1 < n-1: continue
        temp+= -X[i]*2
        if X[i+k-1] >= 0:
            temp += X[i+k-1]
        ans = min(ans, temp)
    
    elif X[i] > 0:
        if not 0 <= i-k+1 < n-1: continue
        temp+=X[i]*2
        if X[i-k+1] <= 0:
            temp -= X[i-k+1]
        ans  = min(ans, temp)

st = bisect.bisect_left(X, 0)
if st+k-1 < n-1: ans = min(ans, X[st+k-1])


st = bisect.bisect_left(X, 0)-1
if 0 <= st-k+1 < n-1: ans = min(ans, X[st-k+1])

print(ans)

Failing test case input:
5 5
-21 -7 15 29 141

Expected output:
183


Actual output:
303


Fixed submission (verdict: Accepted):
import bisect
n, k = map(int, input().split())
X = list(map(int, input().split()))

ans = float('inf')

for i in range(n):
    
    if X[i] <= 0:
        if 0 <= i+k-1 < n:
            temp = 0
            temp+= -X[i]*2
            if X[i+k-1] >= 0:
                temp += X[i+k-1]
                ans = min(ans, temp)
        if 0 <= i-k+1 < n:
            ans = min(ans, -X[i-k+1])

    
    else:
        if 0 <= i-k+1 < n:
            temp = 0
            temp+=X[i]*2
            if X[i-k+1] <= 0:
                temp -= X[i-k+1]
                ans  = min(ans, temp)
        if 0 <= i+k-1 < n:
            ans = min(ans, X[i+k-1])

if n == 1:
    ans = abs(X[0])

print(ans)
Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())

X = list(map(int, input().split()))


def calc_time(X):
    x_max = X[-1]
    x_min = X[0]

    if x_max * x_min >= 0:
        if abs(x_max) > abs(x_min):
            return x_max
        else:
            return abs(x_min)
    else:
        return x_max - x_min + min(abs(x_max), abs(x_min))

def calc_start_and_goal_position(index):
    if index - K >= 0:
        start_index = index - K
    else:
        start_index = 0
    
    if N > index + K:
        goal_index = index
    else:
        goal_index = N - K + 1
    
    return start_index, goal_index

if __name__ == "__main__":
    index = -1
    for i, x in enumerate(X):
        if x >= 0:
            index = i 
    if index == -1:
        index = i
    
    start_index, goal_index = calc_start_and_goal_position(index)

    time_min = float('inf')
    for i in range(start_index, goal_index):
        time = calc_time(X[i:i+K])
        if time < time_min:
            time_min = time

    print(time_min)

Failing test case input:
8 2
-9 -7 -4 -4 1 2 4 4

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())

X = list(map(int, input().split()))

def calc_time(x_max, x_min):
    if x_max * x_min >= 0:
        if abs(x_max) > abs(x_min):
            return x_max
        else:
            return abs(x_min)
    else:
        return x_max - x_min + min(abs(x_max), abs(x_min))

def calc_start_and_goal_position(index):
    if index - K >= 0:
        start_index = index - K
    else:
        start_index = 0
    
    if N > index + K + 1:
        goal_index = index + 1
    else:
        goal_index = N - K + 1
    
    return start_index, goal_index

if __name__ == "__main__":
    index = -1
    for i, x in enumerate(X):
        if x >= 0:
            index = i 
            break
    if index == -1:
        index = i
    start_index, goal_index = calc_start_and_goal_position(index)

    time_min = float('inf')
    for i in range(start_index, goal_index):
        time = calc_time(X[i+K-1], X[i])
        if time < time_min:
            time_min = time
    print(time_min)

Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = 10 ** 9

if n == 1:
    for i in range(n):
        ans = min(ans, abs(x[i]))
elif n == k:
    ans = min(abs(x[0]-x[n-1]) + abs(x[n-1]), abs(x[0]) + abs(x[0] - x[n-1]))
else:
    for i in range(n-k):
        ans = min(ans, abs(x[i]-x[i+k-1]) + abs(x[i+k-1]), abs(x[i]) + abs(x[i] - x[i+k-1]))

print(ans)

Failing test case input:
5 4
-30 -5 16 29 67

Expected output:
77


Actual output:
88


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = 10 ** 9

if k == 1:
    for i in range(n):
        ans = min(ans, abs(x[i]))
elif n == k:
    ans = min(abs(x[0]-x[n-1]) + abs(x[n-1]), abs(x[0]) + abs(x[0] - x[n-1]))
else:
    for i in range(n-k+1):
        ans = min(ans, abs(x[i]-x[i+k-1]) + abs(x[i+k-1]), abs(x[i]) + abs(x[i] - x[i+k-1]))

print(ans)
Problem: p03274
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int,input().split())
listMap = [int(i) for i in input().split()]
minMin = float("inf")

for j in range(N - K):
    L = j
    R = j + K - 1
    sumL = abs(listMap[L]) + abs(listMap[L] - listMap[R])
    sumR = abs(listMap[R]) + abs(listMap[R] - listMap[L])
    sum = min(sumL, sumR)
    if sum < minMin:
        minMin = sum

if minMin == float("inf"):
    minMin = listMap[0]

print(minMin)

Failing test case input:
4 3
-30 -2 4 13 50

Expected output:
17


Actual output:
38


Fixed submission (verdict: Accepted):
N, K = map(int,input().split())
listMap = [int(i) for i in input().split()]
minMin = float("inf")

if N == 1:
    minMin = listMap[0]

for j in range(N - (K - 1)):
    L = j
    R = j + (K - 1)
    sumL = abs(listMap[L]) + abs(listMap[L] - listMap[R])
    sumR = abs(listMap[R]) + abs(listMap[R] - listMap[L])
    sum = min(sumL, sumR)
    if sum < minMin:
        minMin = sum

print(minMin)
Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
print(s[:4]+'_'+s[4:])

Failing test case input:
ALBHEDBFFJHJ

Expected output:
ALBH EDBFFJHJ


Actual output:
ALBH_EDBFFJHJ


Fixed submission (verdict: Accepted):
s=input()
print(s[:4]+' '+s[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
print(s)
print(s[:4],s[4:])

Failing test case input:
ETAUDARGTSOP

Expected output:
ETAU DARGTSOP


Actual output:
ETAUDARGTSOP
ETAU DARGTSOP


Fixed submission (verdict: Accepted):
s = input()
print(s[:4],s[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())
f= ''.join(s[:4])
b=''.join(s[4:])
print(f,'',b)

Failing test case input:
QESTGOBUFBTQ

Expected output:
QEST GOBUFBTQ


Actual output:
QEST  GOBUFBTQ


Fixed submission (verdict: Accepted):
s = list(input())
f= ''.join(s[:4])
b=''.join(s[4:])
print(f,b,sep=' ')

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
print(s[:4]+' '+s[5:])

Failing test case input:
JHJFFBDEIBKA

Expected output:
JHJF FBDEIBKA


Actual output:
JHJF BDEIBKA


Fixed submission (verdict: Accepted):
s=input()
print(s[:4]+' '+s[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
print(s[:4]+' '+s[5:])

Failing test case input:
QRSTGOBUEBTF

Expected output:
QRST GOBUEBTF


Actual output:
QRST OBUEBTF


Fixed submission (verdict: Accepted):
s=input()
print(s[:4]+' '+s[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) 

if __name__ == '__main__':
    a = [str(i) for i in input().split()]
    print(a[0][:4]+" "+a[0][5:])


Failing test case input:
ALBIEDBFFJHJ

Expected output:
ALBI EDBFFJHJ


Actual output:
ALBI DBFFJHJ


Fixed submission (verdict: Accepted):
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) 

if __name__ == '__main__':
    a = [str(i) for i in input().split()]
    print(a[0][:4]+" "+a[0][4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
print(s[:3]+' '+s[3:])

Failing test case input:
DOBEEFSUJV@L

Expected output:
DOBE EFSUJV@L


Actual output:
DOB EEFSUJV@L


Fixed submission (verdict: Accepted):
s = input()
print(s[:4]+' '+s[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()

ans = s[:5] + ' ' + s[5:]

print(ans)

Failing test case input:
FOBFDERUJV@L

Expected output:
FOBF DERUJV@L


Actual output:
FOBFD ERUJV@L


Fixed submission (verdict: Accepted):
s = input()

ans = s[:4] + ' ' + s[4:]

print(ans)
Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
print(s[:4]+" "+s[5:])

Failing test case input:
JHJFGBDFIBKA

Expected output:
JHJF GBDFIBKA


Actual output:
JHJF BDFIBKA


Fixed submission (verdict: Accepted):
s=input()
print(s[:4]+" "+s[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=str(input())
print(s[0:3]+" "+s[4:])

Failing test case input:
EOCUJLSFDVAE

Expected output:
EOCU JLSFDVAE


Actual output:
EOC JLSFDVAE


Fixed submission (verdict: Accepted):
s= str(input())
print(s[0:4]+" "+s[4:])

Problem: p03992
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
print(s[:4]+" "+s[5:])

Failing test case input:
L@VITSEFECOC

Expected output:
L@VI TSEFECOC


Actual output:
L@VI SEFECOC


Fixed submission (verdict: Accepted):
s = input()
print(s[:4]+" "+s[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
print(s[:3]+' '+s[4:])

Failing test case input:
QGSTGOBUFBUQ

Expected output:
QGST GOBUFBUQ


Actual output:
QGS GOBUFBUQ


Fixed submission (verdict: Accepted):
s = input()
print(s[:4]+' '+s[4:])

Problem: p03992
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()
print(s[:4]+""+s[5:])

Failing test case input:
JOCUEESFDVAL

Expected output:
JOCU EESFDVAL


Actual output:
JOCUESFDVAL


Fixed submission (verdict: Accepted):
s = input()
print(s[:4]+" "+s[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
d = input()
print(d[0:3] + " " + d[4:])

Failing test case input:
KBFBGBDJIHKF

Expected output:
KBFB GBDJIHKF


Actual output:
KBF GBDJIHKF


Fixed submission (verdict: Accepted):
d = input()
print(d[:4] + " " + d[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
print(S[:5] + ' ' + S[5:])

Failing test case input:
JHJFFBDEIBKA

Expected output:
JHJF FBDEIBKA


Actual output:
JHJFF BDEIBKA


Fixed submission (verdict: Accepted):
S = input()
print(S[:4] + ' ' + S[4:])

Problem: p03992
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s=input()
print(s[:4],'',s[4:])

Failing test case input:
L@VITRECFCOF

Expected output:
L@VI TRECFCOF


Actual output:
L@VI  TRECFCOF


Fixed submission (verdict: Accepted):
s=input()
print(s[:4],s[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = str(input())
print(s[0:3] + " " + s[4:])

Failing test case input:
QTBFUBOGTSFQ

Expected output:
QTBF UBOGTSFQ


Actual output:
QTB UBOGTSFQ


Fixed submission (verdict: Accepted):
s = str(input())
print(s[0:4] + " " + s[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
print(s[:4]+''+s[4:])

Failing test case input:
QTCFUBOHSSGQ

Expected output:
QTCF UBOHSSGQ


Actual output:
QTCFUBOHSSGQ


Fixed submission (verdict: Accepted):
s=input()
print(s[:4]+' '+s[4:])

Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
ss=s[0:3]+" "+s[4:]
print(ss)

Failing test case input:
KOCUEFSFDVAJ

Expected output:
KOCU EFSFDVAJ


Actual output:
KOC EFSFDVAJ


Fixed submission (verdict: Accepted):
s=input()
ss=s[0:4]+" "+s[4:]
print(ss)
Problem: p03992
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()

a = s[0:4]
b = s[4:-1]

print('{} {}'.format(a, b))


Failing test case input:
KBFBGBDJIHKF

Expected output:
KBFB GBDJIHKF


Actual output:
KBFB GBDJIHK


Fixed submission (verdict: Accepted):
s = input()

a = s[:4]
b = s[-8:]

print('{} {}'.format(a, b))
Problem: p02959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

def cal(ans, n):
    ans += min(a[n], b[n])
    ans += b[n] - min(a[n], b[n])
    a[n+1] -= min(a[n], b[n])
        
for i in range(n):
    cal(ans,i)

print(ans)


Failing test case input:
3
0 0 0 21
2 100 8

Expected output:
8


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

def f(n):
    nn = min(a[n], b[n])
    nnn = min(a[n+1], b[n] - nn)
    a[n+1] -= nnn
    return nn + nnn

for i in range(n):
    ans += f(i)

print(ans)

Problem: p02959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
a=input().split()
b=input().split()
for i in range(0,N):
  a[i]=int(a[i])
  b[i]=int(b[i])
a[N]=int(a[N])
answer=sum(a)
for i in range(0,N):
    c=b[i]-a[i]
    if c<0:
        a[i]=-c
        b[i]=0
    else:
        a[i]=0
        b[i]=c
    d=b[i]-a[i+1]
    if d<0:
        a[i+1]=-c
        b[i]=0
    else:
        a[i+1]=0
        b[i]=c
print (answer-sum(a))

Failing test case input:
3
0 4 2 13
3 100 8

Expected output:
14


Actual output:
27


Fixed submission (verdict: Accepted):
N=int(input())
a=input().split()
b=input().split()
for i in range(0,N):
  a[i]=int(a[i])
  b[i]=int(b[i])
a[N]=int(a[N])
answer=sum(a)
for i in range(0,N):
    c=b[i]-a[i]
    if c<0:
        a[i]=-c
        b[i]=0
    else:
        a[i]=0
        b[i]=c
    d=b[i]-a[i+1]
    if d<0:
        a[i+1]=-d
        b[i]=0
    else:
        a[i+1]=0
        b[i]=d
print (answer-sum(a))

Problem: p02959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0

for i in range(n):
    ab = a[i] - b[i]
    if ab < 0:
        ans += a[i]
        b[i] -= a[i]
        ab = a[i+1] - b[i]
        
        if ab <= 0:
            ans += a[i+1]
            a[i+1] = 0
        else:
            ans += b[i]
           
    elif ab == 0:
        ans += b[i]
        
    else:
        ans += b[i]
        
print(ans)

Failing test case input:
3
0 4 0 13
3 100 8

Expected output:
12


Actual output:
15


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

ans = 0

for i in range(n):
    ab = a[i] - b[i]
    
    if ab < 0:
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0
        b[i] = abs(ab)
        ab = a[i+1] - b[i]
        
        if ab <= 0:
            ans += a[i+1]
            a[i+1] = 0
            b[i] = abs(ab)
        else:
            ans += b[i]
            a[i+1] -= b[i]
            b[i] = 0
           
    elif ab == 0:
        ans += b[i]
        a[i] = 0
        b[i] = 0
        
    else:
        ans += b[i]
        b[i] = 0
        
print(ans)
Problem: p02959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
a1=a
for i in range(n):
  if b[i]>=a[i]+a[i+1]:
    a[i],a[i+1]=0,0
  elif b[i]>=a[i]:
    a[i+1]=b[i]-a[i]
    a[i]=0
  else:
    a[i]-=b[i]
print(sum(a1)-sum(a))
    

Failing test case input:
2
100 6 -3
1 110

Expected output:
4


Actual output:
0


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
asum=sum(a)
a1=a
ans=0
for i in range(n):
  if b[i]>=a1[i]+a1[i+1]:
    a1[i],a1[i+1]=0,0
    ans+=a1[i]+a1[i+1]
  elif b[i]>=a1[i]:
    a1[i+1]-=b[i]-a1[i]
    a1[i]=0
    ans+=b[i]
  else:
    a1[i]-=b[i]
    ans+=b[i]
print(asum-sum(a1))

Problem: p02959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
for i in range(n):
  if a[i]>b[i]:
    c+=b[i]
  elif a[i]<=b[i]:
   
    if a[i+1]-(b[i]-a[i])>=0:
      c+=b[i]
      a[i+1]==a[i+1]-(b[i]-a[i])
    else:
      c+=a[i+1]
      a[i+1]==0
print(c)



Failing test case input:
3
0 4 1 8
2 100 8

Expected output:
13


Actual output:
11


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
for i in range(n):
  if a[i]>b[i]:
    c+=b[i]
  elif a[i]<=b[i]:
   
    if a[i+1]-(b[i]-a[i])>=0:
      c+=b[i]
      a[i+1]-=(b[i]-a[i])
    else:
      c+=a[i+1]+a[i]
      a[i+1]=0
print(c)

Problem: p02959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
teki = input().split()
yusya = input().split()
i = 0
taoshita = 0

while i < N :
  if int(teki[i]) >= int(yusya[i]):
    a = int(yusya[i]) 
    b = 0
  else:
    a = int(teki[i])
    yusya[i] = int(yusya[i]) - int(teki[i])
    if int(teki[i+1]) >= yusya[i]:
      b = yusya[i]
      teki[i+1] = int(teki[i+1]) - yusya[i]
    else:
      b = int(teki[i+1])
  taoshita += a + b
  i += 1

print(taoshita)

Failing test case input:
3
0 34 -2 -1
-1 111 14

Expected output:
30


Actual output:
28


Fixed submission (verdict: Accepted):
N = int(input())
teki = input().split()
yusya = input().split()
i = 0
taoshita = 0

while i < N :
  if int(teki[i]) >= int(yusya[i]):
    a = int(yusya[i]) 
    b = 0
  else:
    a = int(teki[i])
    yusya[i] = int(yusya[i]) - int(teki[i])
    if int(teki[i+1]) >= yusya[i]:
      b = yusya[i]
      teki[i+1] = int(teki[i+1]) - yusya[i]
    else:
      b = int(teki[i+1])
      teki[i+1] = 0
  taoshita += a + b
  i += 1
  
print(taoshita)
Problem: p02959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.append(0)

sum = 0
rest_hero = 0

for i in range(n+1):
    hero = b[i] + rest_hero
    if a[i] >= hero:
        sum += hero
        rest_hero = 0
    else:
        sum += a[i]
        rest_hero = b[i] - (a[i] - rest_hero)

print(sum)


Failing test case input:
3
0 4 0 13
3 100 8

Expected output:
12


Actual output:
17


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.append(0)

sum = 0
rest_hero = 0

for i in range(n+1):
    hero = b[i] + rest_hero
    if a[i] >= hero:
        sum += hero
        rest_hero = 0
    else:  
        sum += a[i]
        if a[i] > rest_hero:
            rest_hero = b[i] - (a[i] - rest_hero)
        else:
            rest_hero = b[i]

print(sum)

Problem: p02959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))


c = []
count = 0

for i in range(n):

    if a[i] - b[i] >= 0:
        count += b[i]
    elif a[i] - b[i] < 0:
        count += a[i]
        if a[i+1] + (a[i] - b[i]) >0:
            a[i+1] = a[i+1] + (a[i] - b[i])
            count += (a[i]-b[i])
        elif a[i+1] + (a[i]-b[i]) <=0:
            count += a[i+1]
            a[i+1] = 0
            
print(count)

Failing test case input:
2
3 5 2
4 5

Expected output:
9

Actual output:
5


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


c = []
count = 0

for i in range(n):

    if a[i] - b[i] >= 0:
        count += b[i]
    elif a[i] - b[i] < 0:
        count += a[i]
        if a[i+1] + (a[i] - b[i]) >0:
            a[i+1] = a[i+1] + (a[i] - b[i])
            count -= (a[i]-b[i])
        elif a[i+1] + (a[i]-b[i]) <=0:
            count += a[i+1]
            a[i+1] = 0
            
print(count)
Problem: p02959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
dp = [0 for i in range(N+1)]
if A[0] <= B[0]:
    dp[0] = A[0]
    B[0] -= A[0]
else:
    dp[0] = B[0]
    B[0] = 0



for i in range(1,N):
    if A[i] - B[i-1] >= B[i]:
        dp[i] = B[i-1] + B[i]
        B[i] = 0
    else:
        dp[i] = A[i]
        B[i] -= A[i] - B[i-1]
if A[-1] <= B[-1]:
    dp[-1] = A[-1]
    B[-1] -= A[-1]
else:
    dp[-1] = B[-1]
    B[-1] = 0
print(sum(dp))

Failing test case input:
3
0 4 2 13
3 100 8

Expected output:
14


Actual output:
19


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
dp = [0 for i in range(N+1)]
if A[0] <= B[0]:
    dp[0] = A[0]
    B[0] -= A[0]
else:
    dp[0] = B[0]
    B[0] = 0
    
if A[-1] <= B[-1]:
    dp[-1] = A[-1]
    B[-1] -= A[-1]
else:
    dp[-1] = B[-1]
    B[-1] = 0

if N != 1:
    for i in range(1,N):
        if A[i] - B[i-1] <= 0:
            dp[i] = A[i]
        elif A[i] - B[i-1] >= B[i]:
            dp[i] = B[i-1] + B[i]
            B[i] = 0
        else:
            dp[i] = A[i]
            B[i] -= A[i] - B[i-1]
print(sum(dp))

Problem: p02959
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
for i in range(N):
    if A[i] < B[i]:
        count += A[i]
        B[i] -= A[i]
    else:
        count += B[i]
        B[i] = 0
    if A[i+1] < B[i]:
        count += A[i+1]
        B[i] -= A[i+1]
        A[i+1] = 0
    else:
        count += B[i]
        B[i] = 0
        A[i+1] -= B[i]
        
print(count)

Failing test case input:
3
0 4 3 8
2 100 8

Expected output:
15


Actual output:
17


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

count = 0
for i in range(N):
    if A[i] < B[i]:
        count += A[i]
        B[i] -= A[i]
    else:
        count += B[i]
        B[i] = 0
    if A[i+1] < B[i]:
        count += A[i+1]
        B[i] -= A[i+1]
        A[i+1] = 0
    else:
        count += B[i]
        A[i+1] -= B[i]
        B[i] = 0
        
print(count)
Problem: p02959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

count = 0
left = 0
for i in range(n-1,-1, -1):
    if b[i] - a[i+1] + left > 0:
        count += a[i+1]
        left = b[i] - a[i+1] + left
        if left > b[i]:
            left = b[i]
    else:
        count += b[i]
        left = 0

count += min(left, a[0])
print(count)

Failing test case input:
2
2 9 1
0 5

Expected output:
5


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
count = 0
left = 0
for i in range(n):
    if b[i] + left - a[i] >= 0:
        count += a[i]
        left = b[i] + left - a[i]
        if left > b[i]:
            left = b[i]
    else:
        count += b[i] + left
        left = 0

count += min(left, a[n])
print(count)

Problem: p02959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  if a[i]>=b[i]:
    cnt+=b[i]
  else:
    if a[i+1]-(b[i]-a[i])>=0:
      cnt+=b[i]
      a[i+1]=a[i+1]-(b[i]-a[i])
    else:
      cnt+=a[i]+a[i+1]
print(cnt)
      

Failing test case input:
3
1 1 0 0
4 100 8

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  if a[i]>=b[i]:
    cnt+=b[i]
  else:
    if a[i+1]+a[i]>=b[i]:
      cnt+=b[i]
      a[i+1]=a[i+1]+a[i]-b[i]
    else:
      cnt+=a[i]+a[i+1]
      a[i+1]=0
print(cnt)

Problem: p02959
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
for n in range(N):
    if A[n] < B[n]:
        cnt += A[n]
        B[n] -= A[n]
        if A[n+1] < B[n]:
            cnt += A[n+1]
            B[n] -= A[n+1]
        else:
            cnt += B[n]
            A[n+1] -= B[n]
    else:
        cnt += B[n]
        
print(cnt)

Failing test case input:
3
10 12 2 4
2 100 8

Expected output:
20


Actual output:
22


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

cnt = 0
for n in range(N):
    if A[n] <= B[n]:
        cnt += A[n]
        B[n] -= A[n]
        if A[n+1] < B[n]:
            cnt += A[n+1]
            A[n+1] = 0
        else:
            cnt += B[n]
            A[n+1] -= B[n]
    else:
        cnt += B[n]
        
print(cnt)