ZhenlongDai/ACPR huggingface dataset:
Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(x) for x in input().split()]

cumulative_sum = []
cnt = 0
for i in range(n):
    cnt += a[i]
    cumulative_sum.append(cnt)

ans = abs(cumulative_sum[0] - (cumulative_sum[-1] - cumulative_sum[0]))
for i in range(n - 1):
    ans = min(abs(a[i] - (cumulative_sum[-1] - cumulative_sum[i])), ans)

print(ans)

Failing test case input:
6
0 10 3 3 1 8

Expected output:
1


Actual output:
5


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(x) for x in input().split()]

cumulative_sum = []
cnt = 0
for i in range(n):
    cnt += a[i]
    cumulative_sum.append(cnt)

ans = abs(cumulative_sum[0] - (cumulative_sum[-1] - cumulative_sum[0]))
for i in range(n - 1):
    ans = min(abs(cumulative_sum[i] - (cumulative_sum[-1] - cumulative_sum[i])), ans)

print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(1, N):
    res += a[i]
diff = a[0]-a[i]
abs_ = abs(diff)
for i in range(1, N-1):
    diff += 2*a[i]
    abs_ = min(abs_, abs(diff))

print(abs_)


Failing test case input:
6
0 3 3 7 8 13

Expected output:
8


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(1, N):
    res += a[i]
diff = a[0]-res
abs_ = abs(diff)
for i in range(1, N-1):
    diff += 2*a[i]
    abs_ = min(abs_, abs(diff))

print(abs_)

Problem: p03659
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
z = sum(a)
ln = []
x = 0
for i in range(1, n):
    x += a[i]
    ln.append(abs(z - 2 * x))
print(min(ln))

Failing test case input:
6
1 2 3 7 8 8

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
z = sum(a)
ln = []
x = 0
for i in range(n - 1):
    x += a[i]
    ln.append(abs(z - 2 * x))
print(min(ln))

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
n = int(input())
a = list(itertools.accumulate(list(map(int, input().split()))))
ans = 1000000000
sum_a = a[-1]
for i in range(n):
  ans = min(ans,abs(sum_a - 2 * a[i]))
print(ans)

Failing test case input:
2
-47 1

Expected output:
48


Actual output:
46


Fixed submission (verdict: Accepted):
import itertools
n = int(input())
a = list(itertools.accumulate(list(map(int, input().split()))))
ans = 10000000000000
sum_a = a[-1]
for i in range(n-1):
  ans = min(ans,abs(sum_a - 2 * a[i]))
print(ans)
Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
acu = []
acu.append(A[0])
acu_r = [0] * (N - 1)
acu_r[-1] += A[-1]
for i in range(1,N-1):
  acu.append(acu[-1] + A[i])
for i in range(N-2,0,-1):
  acu_r[i] += acu_r[-1] + A[i]
INF = 10**9
ans = INF
for i in range(N-1):
  ans = min(ans,abs(acu[i] - acu_r[i]))
print(ans)

Failing test case input:
6
-1 10 3 3 1 4

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
acu = []
acu.append(A[0])
acu_r = []
acu_r.append(A[-1])
for i in range(1,N-1):
  acu.append(acu[-1] + A[i])
for i in range(N-2,0,-1):
  acu_r.append(acu_r[-1] + A[i])


ans = float("inf")
for i in range(N-1):
  ans = min(ans,abs(acu[i] - acu_r[N - (i + 2)]))
print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
arr=list(map(int,input().split()))
for i in range(n-1):
  arr[i+1]+=arr[i]
print(arr)
ans=10**18
for i in range(n-1):
  x=arr[i]
  y=arr[n-1]-x
  tmp=abs(x-y)
  ans=min(ans,tmp)
print(ans)

Failing test case input:
6
0 3 3 7 1 13

Expected output:
1


Actual output:
[0, 3, 6, 13, 14, 27]
1


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

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())

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

rui = [0] * N

rui[0] = A[0]
for it in range(1, N):
    rui[it] = rui[it - 1] + A[it]

ans = 1145141919810
for i in range(1, N):
    ans = min(rui[i], rui[N - 1] - rui[i])
    
print(ans)


Failing test case input:
2
-34 5

Expected output:
39


Actual output:
-29


Fixed submission (verdict: Accepted):
N = int(input())

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

rui = [0] * N

rui[0] = A[0]
for it in range(1, N):
    rui[it] = rui[it - 1] + A[it]

ans = 1145141919810
for i in range(0, N - 1):
    ans = min(abs(rui[i] - rui[N - 1] + rui[i]), ans)

print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
b=sum(a)
A=a[0]
for i in range(n-1):
    if i==0:
        ans=abs(b-2*A)
    else:
        ans=min((b-2*A),ans)
    A+=a[i+1]
print(ans)


Failing test case input:
6
0 2 3 4 5 6

Expected output:
2


Actual output:
-8


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
b=sum(a)
A=a[0]
for i in range(n-1):
    if i==0:
        ans=abs(b-2*A)
    else:
        ans=min(abs(b-2*A),ans)
    A+=a[i+1]
print(ans)
Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
input_list = [int(i) for i in input().split()]

index = 1
ruiseki_list = [0]*(N+1)
result = 10*9

if N == 2:
    print(abs(input_list[0]-input_list[1]))
else:
    for i in input_list:
        ruiseki_list[index] = ruiseki_list[index-1] + i
        index += 1

    for i in range(2, N-1):
        cal = abs(ruiseki_list[N] - 2 * ruiseki_list[i])
        if cal < result:
            result = cal
    print(result)

Failing test case input:
6
0 3 3 7 1 24

Expected output:
10


Actual output:
12


Fixed submission (verdict: Accepted):
N = int(input())
input_list = [int(i) for i in input().split()]

index = 1
ruiseki_list = [0]*(N+1)
result = 10*9

if N == 2:
    print(abs(input_list[0]-input_list[1]))
else:
    for i in input_list:
        ruiseki_list[index] = ruiseki_list[index-1] + i
        index += 1

    mapped_list = map(lambda x: ruiseki_list[N]-x, ruiseki_list)
    result_list = [abs(a-b) for (a, b) in zip(ruiseki_list, mapped_list)]
    print(min(result_list[2:N]))

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n= int(input())
card = input().split(' ')
card = [int(s) for s in card]
min_s = 20000000
sum1 = sum(card[:1])
sum2 = sum(card[1:])
for i in range(n - 1):
    dif  = abs(sum1-sum2)
    print(dif)
    if dif  < min_s:
        min_s = dif
    sum1 += card[i+1]
    sum2 = sum2 - card[i+1]
print(min_s)


Failing test case input:
2
-22 3

Expected output:
25


Actual output:
25
25


Fixed submission (verdict: Accepted):
n= int(input())
card = input().split(' ')
card = [int(s) for s in card]
min_s = 20000000000
sum1 = sum(card[:1])
sum2 = sum(card[1:])
for i in range(n - 1):
    dif  = abs(sum1-sum2)

    if dif  < min_s:
        min_s = dif
    sum1 += card[i+1]
    sum2 = sum2 - card[i+1]
print(min_s)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
al=list(map(int,input().split()))
ans=10**10
for i in range(2,n+1):
    ans=min(ans,abs(sum(al[0:i-1])-sum(al[i:-1])))
print(ans)

Failing test case input:
2
-47 7

Expected output:
54


Actual output:
47


Fixed submission (verdict: Accepted):
n=int(input())
al=list(map(int,input().split()))
sm=sum(al)
t=0
ans=10**15
for i in range(n-1):
    t+=al[i]
    ans=min(ans,abs(sm-t*2))
print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N=int(input())
b=input()
c=b.split(" ")
d=map(int,c)
a=list(d)
sum_a=abs(sum(a))
ans=sum_a%2
if sum_a==0:
    A=map(abs,a)
    B=list(A)
    ans2=min(B)
    print(ans2*2)
else:
    print(ans)

Failing test case input:
2
-77 2

Expected output:
79


Actual output:
1


Fixed submission (verdict: Accepted):


N=int(input())
b=input()
c=b.split(" ")
d=map(int,c)
a=list(d)
X=sum(a)
ans=[]
Y=0
for i in range(N-1):

    Y=Y+a[i]
    B=abs(X-2*Y)
    ans.append(B)
ans1=min(ans)
print(ans1)
Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = list(map(int,input().split()))

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

print(ans)

Failing test case input:
2
-66 3

Expected output:
69


Actual output:
-63


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

s = sum(a)
l = 0

ans = 10**10
   
for i in range(N-1):
    l += a[i]
    ans = min(ans, abs(s - 2*l))

print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n = int(input())
an = list(map(int,input().split()))
sum_an = sum(an)
from itertools import accumulate
an_acc = accumulate(an)
print(min(list(map(lambda x : abs(sum_an-x*2),an_acc))))


Failing test case input:
2
-75 1

Expected output:
76


Actual output:
74


Fixed submission (verdict: Accepted):

n = int(input())
an = list(map(int,input().split()))
sum_an = sum(an)
from itertools import accumulate
an_acc = list(accumulate(an))[0:-1]
print(min(list(map(lambda x : abs(sum_an-x*2),an_acc))))

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [int(i) for i in input().split()]
x = 0
y = sum(a)
ans = 10**18
for i in a:
  x += i
  y -= i
  tmp = abs(x-y)
  ans = min(tmp,ans)
print(ans)

Failing test case input:
2
86 -1

Expected output:
87


Actual output:
85


Fixed submission (verdict: Accepted):
N = int(input())
a = [int(i) for i in input().split()]
x = 0
y = sum(a)
ans = 10**18
for i in range(N-1):
  x += a[i]
  y -= a[i]
  tmp = abs(x-y)
  ans = min(tmp,ans)
print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
L = list(map(int,input().split()))
sum1 = sum(L)
sum2 = 0
L.sort()
if n == 2:
    print(abs(L[1]-L[0]))
    exit ()

for i in range(n):
    ans = 10**20
    sum2 +=L[i]
    sa = abs(sum1 - sum2- sum2)
    
    ans = min(ans,sa)
print(ans)

Failing test case input:
6
1 36 1 10 -1 6

Expected output:
21


Actual output:
53


Fixed submission (verdict: Accepted):
n = int(input())
L = list(map(int,input().split()))
sum1 = sum(L)
sum2 = 0

if n == 2:
    print(abs(L[1]-L[0]))
    exit ()
ans = 10**20
for i in range(n-1):
    sum2 +=L[i]
    sa = abs(sum1 - sum2- sum2)
    ans = min(ans,sa)
print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
a=list(map(int,input().split()))
S=sum(a)
s=2*a[0]
d=abs(a[1]-a[0])
for i in range(1,N-1):
    s+=2*a[i]
    if s>S:
        d=s-S
        s=S-s+2*a[i]
        break
print(min(s,d))

Failing test case input:
2
-34 4

Expected output:
38


Actual output:
-68


Fixed submission (verdict: Accepted):
N=int(input())
a=list(map(int,input().split()))
S=sum(a)
s=2*a[0]
d=abs(S-2*a[0])
for i in range(1,N-1):
    s+=2*a[i]
    d=min(d,abs(S-s))
print(d)
Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
lst_a = list(map(int, input().split()))
total = sum(lst_a)
x = 0
ans = float("INF")


for a in lst_a:
    x += a
    y = total - x
    ans = min(ans, abs(x - y))


print(ans)

Failing test case input:
2
-25 2

Expected output:
27


Actual output:
23


Fixed submission (verdict: Accepted):
N = int(input())
lst_a = list(map(int, input().split()))
total = sum(lst_a)
x = 0
ans = float("INF")


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


print(ans)

Problem: p03659
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def pin(type=int):
    return map(type,input().split())






N,=pin()
A=list(pin())
S=sum(A)
s=A[0]
m=abs(S-s*2)

for i in range(1,N):
    s=s+A[i]
    t=abs(S-s*2)
    
    m=min(t,m)
print(m)

Failing test case input:
2
-14 3

Expected output:
17


Actual output:
11


Fixed submission (verdict: Accepted):

def pin(type=int):
    return map(type,input().split())






N,=pin()
A=list(pin())
S=sum(A)
s=A[0]
m=abs(S-s*2)

for i in range(1,N-1):
    s=s+A[i]
    t=abs(S-s*2)
    
    m=min(t,m)
print(m)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
ans = -1
for i in range(n):
    tmp = abs(sum(a[:i])-sum(a[i:]))
    if ans == -1:
        ans = tmp
    if tmp < ans:
        ans = tmp
print(ans)

Failing test case input:
2
-66 3

Expected output:
69


Actual output:
63


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

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    sunuke = 0
    arai = sum(l)
    for i in range(N-1):
        sunuke += l[i]
        arai   -= l[i]
        ans.append(abs(sunuke-arai))
    print(min(l))
if __name__ == '__main__':
    main()

Failing test case input:
2
-47 2

Expected output:
49


Actual output:
-47


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    sunuke = 0
    arai = sum(l)
    for i in range(N-1):
        sunuke += l[i]
        arai   -= l[i]
        ans.append(abs(sunuke-arai))
    print(min(ans))
if __name__ == '__main__':
    main()

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

X = sum(a)

minsum = 10000000000

cnt = 0

for i in range(1,n):
    cnt += a[i-1]
    print(cnt)
    minsum = min(minsum,abs(X-2*cnt))

print(minsum)


Failing test case input:
6
0 2 3 7 5 6

Expected output:
1


Actual output:
0
2
5
12
17
1


Fixed submission (verdict: Accepted):


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

X = sum(a)

minsum = 10000000000

cnt = 0

for i in range(1,n):
    cnt += a[i-1]
    minsum = min(minsum,abs(X-2*cnt))

print(minsum)
Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
a=list(map(int,input().split()))
S=sum(a)
SS=0
mi=abs(S-SS)
for i in range(N):
  S=S-a[i]
  SS=SS+a[i]
  print(S,SS)
  if mi>=abs(S-SS):
    mi=abs(S-SS)
print(mi)

Failing test case input:
2
-5 -126

Expected output:
121


Actual output:
-126 -5
0 -131
121


Fixed submission (verdict: Accepted):
N=int(input())
a=list(map(int,input().split()))
S=sum(a)
SS=0
mi=1000000000000000
for i in range(N-1):
    S=S-a[i]
    SS=SS+a[i]
    if mi>=abs(S-SS):
        mi=abs(S-SS)
print(mi)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve(n, A):
    total = sum(A)
    tmp = 0
    x = 0
    ret = total
    for a in A:
        x += a
        y = total - x
        if abs(x - y) < ret:
            ret = abs(x - y)
    return ret

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))


Failing test case input:
2
-13 3

Expected output:
16


Actual output:
-10


Fixed submission (verdict: Accepted):
def solve(n, A):
    total = sum(A)
    x = A[0]
    ret = abs(2 * x - total)
    for i in range(1, n - 1):
        x += A[i]
        y = total - x
        if abs(x - y) < ret:
            ret = abs(x - y)
    return ret

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
A = [int(i) for i in input().split()]
ans = 100000000000000
a = 0
b = sum(A)
for i in range(n):
  a += A[i]
  b -= A[i]
  c = abs(a-b)
  ans = min(ans, c)
print(ans)

Failing test case input:
2
-22 3

Expected output:
25


Actual output:
19


Fixed submission (verdict: Accepted):
n = int(input())
A = [int(i) for i in input().split()]
ans = 100000000000000
a = 0
b = sum(A)
for i in range(n-1):
  a += A[i]
  b -= A[i]
  c = abs(a-b)
  ans = min(ans, c)
print(ans)

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

sunuke = a[0]
araiguma = sum(a[1:])
diff = abs(sunuke - araiguma)

for i in a:
    sunuke += i
    araiguma -= i
    diff = min(diff, abs(sunuke - araiguma))

print(diff)


Failing test case input:
6
1 2 3 7 8 8

Expected output:
3


Actual output:
1


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

x = a[0]
y = sum(a[1:])
diff = abs(x - y)

for i in a[1:-1]:
    x += i
    y -= i
    diff = min(diff, abs(x - y))

print(diff)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(x) for x in input().split()]
ans = pow(10, 15)
key = sum(a)
p = key
for i in range(n):
  p += a[i]
  if ans > abs(key-2*p):
    ans = abs(key-2*p)
    
print(ans)

Failing test case input:
2
-64 1

Expected output:
65


Actual output:
189


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(x) for x in input().split()]
ans = pow(10, 15)
key = sum(a)
p = 0
for i in range(n-1):
  p += a[i]
  if ans > abs(key-2*p):
    ans = abs(key-2*p)
    
print(ans)
Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
total = 0
ma = 10 ** 20
for i in range(n):
    total += a[i]
    print(total, s)
    if i < n - 1:
        print("DO", total, s)
        ma = min(ma, abs(total - s + total))
print(ma)


Failing test case input:
2
-4 -126

Expected output:
122


Actual output:
-4 -130
DO -4 -130
-130 -130
122


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
total = 0
ma = 10 ** 20
for i in range(n):
    total += a[i]
    if i < n - 1:
        ma = min(ma, abs(total - s + total))
print(ma)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(i) for i in input().split()]
imos = [a[i] for i in range(n)]
for i in range(1, n):
    imos[i] += a[i - 1]
diff = abs(imos[-1] - 2 * a[0])
for i in range(1, n-1):
    diff = min(diff, abs(imos[-1] - 2 * a[i]))
print(diff)

Failing test case input:
6
1 30 1 10 -1 6

Expected output:
15


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(i) for i in input().split()]
imos = [a[i] for i in range(n)]
for i in range(1, n):
    imos[i] += imos[i - 1]
diff = abs(imos[-1] - 2 * a[0])
for i in range(1, n-1):
    diff = min(diff, abs(imos[-1] - 2 * imos[i]))
print(diff)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate
n = int(input())
L = sorted(list(map(int,input().split())))
LL = list(accumulate(L))

sum1 = 0
sum2 = sum(L)
ans = 10**10
for i in range(n):
    sum1 += LL[i]
    sum2 -= LL[i]
    ans = min(ans,abs(sum1 - sum2))
print(ans)

Failing test case input:
6
1 36 1 10 -1 1

Expected output:
26


Actual output:
20


Fixed submission (verdict: Accepted):
n = int(input())
L = list(map(int,input().split()))
sum1 = sum(L)
sum2 = 0

if n == 2:
    print(abs(L[1]-L[0]))
    exit ()
ans = 10**20
for i in range(n-1):
    sum2 +=L[i]
    sa = abs(sum1 - sum2- sum2)
    ans = min(ans,sa)
print(ans)

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

for i in range(N-1) :
    if i == 0 :
        p = L[i]
        q = sum(L)-p
        ans = abs(p-q)
    else :
        p += L[i]
        q -= L[i]
        if ans < abs(p-q) :
            ans = abs(p-q)
print(ans)


Failing test case input:
6
-1 10 3 3 1 4

Expected output:
2


Actual output:
22


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

for i in range(N-1) :
    if i == 0 :
        p = L[i]
        q = sum(L)-p
        ans = abs(p-q)
    else :
        p += L[i]
        q -= L[i]
        if ans > abs(p-q) :
            ans = abs(p-q)
        
print(ans)
Problem: p03659
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
mae=[0]*n
usi=[0]*n
ma=0
for i in range(n):
    ma+=l[i]
    mae[i]=ma
us=0
for i in range(n-1,-1,-1):
    us+=l[i]
    usi[i]=us
ans=10000000000000000000
for i in range(1,n-1):
    ans=min(ans,abs(mae[i]-usi[n-1-i]))
print(ans)

Failing test case input:
2
-68 -2

Expected output:
66


Actual output:
10000000000000000000


Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
mae=[0]*n
usi=[0]*n
ma=0
for i in range(n):
    ma+=l[i]
    mae[i]=ma
us=0
for i in range(n-1,-1,-1):
    us+=l[i]
    usi[i]=us
ans=10000000000000000000
for i in range(0,n-1):
    ans=min(ans,abs(mae[i]-usi[i+1]))
    
print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
a=list(map(int,input().split()))
S=[0]*(N+1)
for i in range(1,N+1):
  S[i]=S[i-1]+a[i-1]
  
ans=float("Inf")
for i in range(1,N):
  tmp=abs(S[N]-S[i]*2)
  ans=min(ans,tmp)
print(S)

Failing test case input:
6
1 3 3 7 8 13

Expected output:
7


Actual output:
[0, 1, 4, 7, 14, 22, 35]


Fixed submission (verdict: Accepted):
N=int(input())
a=list(map(int,input().split()))
S=[0]*(N+1)
for i in range(1,N+1):
  S[i]=S[i-1]+a[i-1]
  
ans=float("Inf")
for i in range(1,N):
  tmp=abs(S[N]-S[i]*2)
  ans=min(ans,tmp)
print(ans)

Problem: p03659
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

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

lst = [0]*(N-1)
x = a[0]
y = sum(a)-a[0]
lst[0] = abs(x-y)

for i in range(1,N-1):
    lst[i] = abs(lst[i-1] - 2*a[i])

ans = min(lst)
print(ans)

Failing test case input:
6
-1 10 3 3 1 4

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):

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

lst = [0]*(N-1)
x = [a[0]]*(N-1)
y = [sum(a)-a[0]]*(N-1)
lst[0] = abs(x[0]-y[0])

for i in range(1,N-1):
    x[i] = x[i-1]+a[i] 
    y[i] = y[i-1]-a[i]
    lst[i] = abs(x[i]-y[i])

ans = min(lst)
print(ans)

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

x, y = 0, sum(a)
ans = sum(a) - a[0]
for i in range(n):
    x += a[i]
    y -= a[i]
    ans = min(ans, abs(x - y))

print(ans)


Failing test case input:
2
-1 -47

Expected output:
46


Actual output:
-47


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

x, y = 0, sum(a)
ans = abs(a[0] - (sum(a) - a[0]))
for i in range(n - 1):
    x += a[i]
    y -= a[i]
    ans = min(ans, abs(x - y))

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

X = sum(a)
b = [a[0]]
for i in range(1, N):
    b.append(b[i-1] + a[i])

ans = []
for i in range(1, N):
    ans.append(abs(X - 2*b[i]))

print(min(ans))


Failing test case input:
2
-62 -1

Expected output:
61


Actual output:
63


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

X = sum(a)
b = [a[0]]
for i in range(1, N - 1):
    b.append(b[i-1] + a[i])

ans = []
for i in range(0, N - 1):
    ans.append(abs(X - 2*b[i]))

print(min(ans))

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [int(i) for i in input().split()]


s = sum(a)
m = s - a[0]

for i in range(2, N):
    b = sum(a[:i])
    c = s - b
    
    
    if m > (abs(b-c)):
        m = abs(b-c)
    else:
        break
print(m)

Failing test case input:
2
-58 -1

Expected output:
57


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
a = [int(i) for i in input().split()]


s = sum(a)
m = pow(10, 20)
b = 0
for i in range(N-1):
    b += a[i]
    c = s - b
    
    
    if m > (abs(b-c)):
        m = abs(b-c)
    
print(m)

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

left = [0] * N
right = [0] * N

left[0] = a[0]
right[-1] = a[-1]
for i in range(1, N):
    left[i] = a[i] + left[i-1]
for i in range(N-2, -1, -1):
    right[i] = a[i] + right[i+1]



ans = abs(left[0] + right[1])
for i in range(1, N-1):
    ans = min(ans, abs(left[i] - right[i+1]))
print(ans)


Failing test case input:
2
-22 3

Expected output:
25


Actual output:
19


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

left = [0] * N
right = [0] * N

left[0] = a[0]
right[-1] = a[-1]
for i in range(1, N):
    left[i] = a[i] + left[i-1]
for i in range(N-2, -1, -1):
    right[i] = a[i] + right[i+1]



ans = abs(left[0] - right[1])
for i in range(1, N-1):
    ans = min(ans, abs(left[i] - right[i+1]))
print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
left = a[0]
ans = abs(total - 2*a[0])
for i in range(1, n-1):
    left += a[i]
    ans = min(abs(total-2*left), ans)
    if left >= total/2:
        exit()
print(ans)


Failing test case input:
6
0 10 3 4 1 8

Expected output:
0


Actual output:

Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
left = 0
ans = float('inf')
for i in range(n-1):
    left += a[i]
    ans = min(abs(total-2*left), ans)
print(ans)
Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

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

ans = 999999999

for i in range(0,n-1):
    sunuke = sum(list[0:1])
    arai = sum(list[i+1:n])
    sa = abs(sunuke - arai)
    print(sunuke)
    print(arai)
    
    if sa < ans:
      ans = sa

print(ans)

Failing test case input:
6
0 10 3 4 1 8

Expected output:
0


Actual output:
0
26
0
16
0
13
0
9
0
8
8


Fixed submission (verdict: Accepted):
n = int(input())

list = list(map(int, input().split()))
all = sum(list)
ans = 10**10
sunuke = 0

for i in range(0,n-1):
    sunuke += list[i]
    arai = all - sunuke
    sa = abs(sunuke - arai)
   
    if sa < ans:
      ans = sa

print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def myAnswer(N:int,A:list) -> int:
   accum = [A[0]]
   ans = 10 * 10
   total = sum(A)
   for i in range(1,N):
      accum.append(accum[i-1] + abs(A[i]))
   
   for a in accum:
      ans = min(ans,abs(a - (total - a)))
      

   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A))
if __name__ == '__main__':
   main()

Failing test case input:
2
-14 3

Expected output:
17


Actual output:
11


Fixed submission (verdict: Accepted):
def myAnswer(N:int,A:list) -> int:
   accum = [A[0]]
   total = sum(A)
   ans = []
   for i in range(1,N):
      accum.append(accum[i-1] + A[i])
   accum.pop()
   
   for x in accum:
      y = total - x
      ans.append(abs(x - y))
      

   return min(ans)

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A))
if __name__ == '__main__':
   main()

Problem: p03659
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,*a=map(int,open(0).read().split())
a.sort()
b=c=0
for i in a[::-1]:
    if b>c:c+=i
    else:b+=i
print(abs(b-c))

Failing test case input:
6
0 3 3 7 8 13

Expected output:
8


Actual output:
2


Fixed submission (verdict: Accepted):
n,*a=map(int,open(0).read().split())
ans=10**100
b=sum(a)
c=0
for i in a[:-1]:
   c+=i
   b-=i
   ans=min(ans,abs(b-c))
print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
total = 0
ma = 10 ** 20
for i in range(n):
    total += a[i]
    if i < n - 1:
        print("DO", total, s)
        ma = min(ma, abs(total - s + total))
print(ma)


Failing test case input:
6
1 2 3 7 8 8

Expected output:
3


Actual output:
DO 1 29
DO 3 29
DO 6 29
DO 13 29
DO 21 29
3


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
total = 0
ma = 10 ** 20
for i in range(n):
    total += a[i]
    if i < n - 1:
        ma = min(ma, abs(total - s + total))
print(ma)
Problem: p03659
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
a = list(map(int, input().split()))
s = sum(a)
data = [a[0]]
m = abs(a[0] - a[-1])

for i in range(1, N - 1):
    data.append(a[i] + data[i - 1])

for i in range(0, N - 1):
    if abs(s - 2 * data[i]) < m:
        m = abs(s - 2 * data[i])

print(m)



Failing test case input:
6
1 36 1 10 -1 6

Expected output:
21


Actual output:
5


Fixed submission (verdict: Accepted):
N = int(input())
a = list(map(int, input().split()))
s = sum(a)
data = [a[0]]
m = abs(s - 2 * a[0])

for i in range(1, N - 1):
    data.append(a[i] + data[i - 1])

for i in range(0, N - 1):
    if abs(s - 2 * data[i]) < m:
        m = abs(s - 2 * data[i])

print(m)

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

sum_card = sum(card)
min_value = 1000000000
sunuke = card[0]
for i in range(1,N,1):
  sunuke += card[i]
  if abs(sum_card - 2*sunuke) < min_value:
    min_value = abs(sum_card - 2*sunuke)
  
print(int(min_value))

Failing test case input:
2
-14 3

Expected output:
17


Actual output:
11


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

sum_card = sum(card)
min_value = 10000000000
sunuke = 0
for i in range(0,N-1,1):
  sunuke += card[i]
  if abs(sum_card - 2*sunuke) < min_value:
    min_value = abs(sum_card - 2*sunuke)
  
print(int(min_value))

Problem: p03659
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from itertools import accumulate

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

if n == 2:
  print(A[0]-A[1])
  exit()
  
B = list(accumulate(A))

ans = B[-1]
y = 0
for i in range(len(A)-1, 1, -1):
    x = B[i-1]
    y += A[i]
    
    ans = min(ans, abs(x-y))

print(ans)

Failing test case input:
2
-85 1

Expected output:
86


Actual output:
-86


Fixed submission (verdict: Accepted):
from itertools import accumulate

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

if n == 2:
  print(abs(A[0]-A[1]))
  exit()
  
B = list(accumulate(A))

ans = abs(B[-2]-A[-1])
y = 0
for i in range(len(A)-1, 0, -1):
    x = B[i-1]
    y += A[i]
    
    ans = min(ans, abs(x-y))

print(ans)

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n=int(input())
a=list(map(int,input().split()))
sa=[a[0] for i in range(n)]
for i in range(1,n):
    sa[i]=sa[i-1]+a[i]
mm=float("INF")
for i in range(n):
    mm=min(mm,abs(sa[i]-(sa[n-1]-sa[i])))
print(int(mm))

Failing test case input:
2
-42 1

Expected output:
43


Actual output:
41


Fixed submission (verdict: Accepted):

n=int(input())
a=list(map(int,input().split()))
sa=[a[0] for i in range(n)]
for i in range(1,n):
    sa[i]=sa[i-1]+a[i]
mm=float("INF")
for i in range(n-1):
    mm=min(mm,abs(sa[i]-(sa[n-1]-sa[i])))
print(int(mm))
Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = list(map(int, input().split()))

total = sum(a)
half = total / 2.0

base = 0
diff = half
for i in range(len(a)):
    base += a[i]
    diff_n = abs(base - half)
    if diff_n > diff:
        print(abs(sum(a[:i]) * 2 - total))
        break


Failing test case input:
2
-1 -38

Expected output:
37


Actual output:
39


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

total = sum(a)

acc_sum = [0] * N
base = 0
for i in range(N):
    base += a[i]
    acc_sum[i] = base

diff = [abs(acc * 2 - total) for acc in acc_sum]
print(min(diff[:-1]))

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(s) for s in input().split()]

def main():
    sum_n = sum(A)
    mid = sum_n / 2
    a = 0
    abs_list = []
    for i in range(N - 1):
        a += A[i]
        abs_list.append((abs(mid - a), sum_n - a))    
    abs_list.sort()
    print(abs_list[0][1])

if __name__ == '__main__':
    main()


Failing test case input:
2
-1 -38

Expected output:
37


Actual output:
-38


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(s) for s in input().split()]

def main():
    sum_n = sum(A)
    mid = sum_n / 2
    a = 0
    abs_list = []
    for i in range(N - 1):
        a += A[i]
        abs_list.append((abs(mid - a), i))    
    abs_list.sort()
    idx = abs_list[0][1]

    left = sum(A[:idx + 1])
    right = sum(A[idx + 1:])
    print(abs(left - right))

if __name__ == '__main__':
    main()

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

a = sorted(a)

ans = []
for i in range(1, N):
    ans.append(abs(sum(a[:i]) - sum(a[i:])))

print(min(ans))


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

Expected output:
4


Actual output:
6


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

X = sum(a)
b = [a[0]]
for i in range(1, N - 1):
    b.append(b[i-1] + a[i])

ans = []
for i in range(0, N - 1):
    ans.append(abs(X - 2*b[i]))

print(min(ans))

Problem: p03659
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
X = [0]*N

S = sum(A)
ans = 10**11

for i in range(1,N):
    X[i] += A[i]
    t = abs(X[i]+X[i]-S)
    ans = min(ans,t)

print(ans)
    

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

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
X = [0]*N

S = sum(A)
ans = 10**11

for i in range(N-1):
    X[i+1] = X[i] + A[i]

print(min(abs(S-2*X[i]) for i in range(1,N)))
Problem: p02598
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
A = list(map(int,input().split()))

x = max(A)

mn = 0
mx = max(A)

while mx-mn > 1:
    suc = True
    cnt = 0
    for a in A:
       cnt += -(-a)
       if cnt > K:
           suc = False
           break
    if suc:
        mx = x
        x = (mn+mx)
    else:
        mn = x
        x = (mn+mx)

print(x)




Failing test case input:
2 0
20 4

Expected output:
20


Actual output:
40


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
A = list(map(int,input().split()))

x = max(A)

mn = 0
mx = max(A)

while mx-mn > 1:
    suc = True
    cnt = 0
    for a in A:
        cnt += -((-a)
        if cnt > K:
            suc = False
            break
    if suc:
        mx = x
        x = (mn+mx)
    else:
        mn = x
        x = (mn+mx)

print(mx)

Problem: p02598
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k=map(int,input().split())
A=list(map(int,input().split()))
high=max(A)
low=1
while high-low>1:
    cnt=0
    now=(low+high)
    for a in A:
        cnt+=a
        if cnt>k:
            break
    if cnt>k:
        low=now
    else:
        high=now
    
print(high)

Failing test case input:
10 10
262817187 877914575 603271755 10449377 251925396 623690081 433933447 438623250 198921849 6083276

Expected output:
251925396


Actual output:
877914575


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
A=list(map(int,input().split()))
high=max(A)
low=0
while high-low>1:
    cnt=0
    now=(low+high)
    for a in A:
        cnt+=max((a-1)
        if cnt>k:
            break
    if cnt>k:
        low=now
    else:
        high=now
    
print(high)

Problem: p02598
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K=[int(s) for s in input().split()]
maruta=[int(s) for s in input().split()]

def possible(x):
  cut=0
  for e in maruta:
    cut+=e
  if cut<=K:
    return True
  else:
    return False

a=1
b=max(maruta)
while b-a>1:
  c=(a+b)
  if possible(c):
    b=c
  else:
    a=c

if a==1 and possible(1):
  print(1)
else:
  print(b)


Failing test case input:
10 10
158260522 877914575 938084412 24979445 861648772 231854269 613941994 476190629 14103145 297169794

Expected output:
297169794


Actual output:
938084412


Fixed submission (verdict: Accepted):
N,K=[int(s) for s in input().split()]
maruta=[int(s) for s in input().split()]

def possible(x):
  cut=0
  for e in maruta:
    if e%x==0:
      cut+=(e
    else:
      cut+=e
  if cut<=K:
    return True
  else:
    return False

a=1
b=max(maruta)
while b-a>1:
  c=(a+b)
  if possible(c):
    b=c
  else:
    a=c

if possible(1):
  print(1)
else:
  print(b)
Problem: p02598
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=max(a)+1,0
while l-r>1:
    t=(l+r)
    c=0
    for i in a:
        c+=i
    if c>k:
        r=t
    else:
        l=t
print(l)

Failing test case input:
10 22
130756960 877914575 602436426 24979445 234944500 544360394 791658515 476190629 262703497 162140871

Expected output:
150609107


Actual output:
877914576


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=10**9,0
while l-r>1:
    t=(l+r)
    if sum((i-1)
        r=t
    else:
        l=t
print(l)

Problem: p02598
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
n,k = map(int,input().split())
a_list = list(map(int,input().split()))

min_num = 1
max_num = 10**9+1
while True:
    print(min_num)
    x = int((min_num+max_num)/2)
    if sum([math.ceil(a/x)-1 for a in a_list])>k:
        min_num = x
    else:
        max_num = x
    if max_num-min_num<=1:
        break
    
if sum([math.ceil(a/min_num)-1 for a in a_list])>k:
    print(min_num+1)
else:
    print(min_num)

Failing test case input:
2 6
7 9

Expected output:
3


Actual output:
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
3


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

min_num = 1
max_num = 10**9+1
while True:
    
    x = int((min_num+max_num)/2)
    if sum([math.ceil(a/x)-1 for a in a_list])>k:
        min_num = x
    else:
        max_num = x
    if max_num-min_num<=1:
        break
    
if sum([math.ceil(a/min_num)-1 for a in a_list])>k:
    print(min_num+1)
else:
    print(min_num)

Problem: p02598
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k=map(int,input().split())
A=list(map(int,input().split()))
high=max(A)
low=0
while high-low>1:
    cnt=0
    now=(low+high)
    for a in A:
        cnt+=a
        if cnt>k:
            break
    if cnt>k:
        low=now
    else:
        high=now
    
print(high)

Failing test case input:
10 22
130756960 877914575 602436426 24979445 234944500 544360394 791658515 476190629 262703497 162140871

Expected output:
150609107


Actual output:
877914575


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
A=list(map(int,input().split()))
high=max(A)
low=0
while high-low>1:
    cnt=0
    now=(low+high)
    for a in A:
        cnt+=max((a-1)
        if cnt>k:
            break
    if cnt>k:
        low=now
    else:
        high=now
    
print(high)
Problem: p02598
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, K = map(int, input().split()[:2])
arr = list(map(int, input().split()[:N]))


def pos(X):
    sum = 0
    for i in arr:
        sum += int(i/X)
        if i % X == 0:
            sum -= 1
    return sum <= K


low = 0
high = 10 ** 9
mid = 0
ans = 10**9

while low <= high:
    mid = int((low+high)/2)
    
    if mid == 0 or pos(mid):
        ans = mid
        high = mid-1
    else:
        low = mid+1
    
print(ans)


Failing test case input:
2 6
1 6

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N, K = map(int, input().split()[:2])
arr = list(map(int, input().split()[:N]))


def pos(X):
    sum = 0
    for i in arr:
        sum += int(i/X)
        if i % X == 0:
            sum -= 1
    return sum <= K


low = 1
high = 10 ** 9
mid = 0
ans = 10**9

while low <= high:
    mid = int((low+high)/2)
    
    if pos(mid):
        ans = mid
        high = mid-1
    else:
        low = mid+1
    
print(ans)

Problem: p02598
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K=[int(s) for s in input().split()]
maruta=[int(s) for s in input().split()]

def possible(x):
  cut=0
  for e in maruta:
    cut+=e
  if cut<=K:
    return True
  else:
    return False

a=1
b=10**9
while b-a>1:
  c=(a+b)
  if possible(c):
    b=c
  else:
    a=c

if a==1 and possible(1):
  print(1)
else:
  print(b)


Failing test case input:
10 1
158260522 877914575 938084412 24979445 861648772 623690081 433933447 476190629 262703497 211047202

Expected output:
877914575


Actual output:
1000000000


Fixed submission (verdict: Accepted):
N,K=[int(s) for s in input().split()]
maruta=[int(s) for s in input().split()]

def possible(x):
  cut=0
  for e in maruta:
    if e%x==0:
      cut+=(e
    else:
      cut+=e
  if cut<=K:
    return True
  else:
    return False

a=1
b=max(maruta)
while b-a>1:
  c=(a+b)
  if possible(c):
    b=c
  else:
    a=c

if possible(1):
  print(1)
else:
  print(b)

Problem: p02598
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
a=lnii()

ok=max(a)
ng=1

while ok-ng>1:
  m=(ok+ng)

  num=0
  for i in a:
    num+=i

  if num<=k:
    ok=m
  else:
    ng=m

print(ok)

Failing test case input:
10 10
262817187 877914575 603271755 10449377 251925396 623690081 433933447 438623250 198921849 6083276

Expected output:
251925396


Actual output:
877914575


Fixed submission (verdict: Accepted):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
a=lnii()

ok=max(a)
ng=0

while ok-ng>1:
  m=(ok+ng)

  num=0
  for i in a:
    if i%m!=0:
      num+=(i
    else:
      num+=(i

  if num<=k:
    ok=m
  else:
    ng=m

print(ok)
Problem: p02598
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N,K=map(int, input().split())
A=list(map(int, input().split()))
if K==0:
  print(max(A))
  exit()
def f(x):
  cnt=0
  for i in A:
    cnt+=i
  if cnt<=K:
    return True
  else:
    return False
ok=1
ng=1000000000
for i in range(50):
  mid=(ok+ng)
  if f(mid):
    ng=mid
  else:
    ok=mid
print(ng)

Failing test case input:
10 10
28456989 370333932 603271755 10790540 850790019 623690081 182987745 476190629 51318490 211047202

Expected output:
212697505


Actual output:
1000000000


Fixed submission (verdict: Accepted):
N,K=map(int, input().split())
A=list(map(int, input().split()))
if K==0:
  print(max(A))
  exit()
def f(x):
  cnt=0
  for i in A:
    if i%x==0:
      cnt+=i
    else:
      cnt+=(i
  if cnt<=K:
    return True
  else:
    return False
ok=1
ng=1000000000
for i in range(50):
  mid=(ok+ng)
  if f(mid):
    ng=mid
  else:
    ok=mid
print(ng)

Problem: p02598
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=max(a),0
while l-r>1:
    t=(l+r)
    c=0
    for i in a:
        c+=i
    if c>k:
        r=t
    else:
        l=t
print(l)

Failing test case input:
10 16
9656159 370333932 603271755 24979445 279499038 623690081 182987745 476190629 410218089 283631850

Expected output:
155922521


Actual output:
623690081


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=list(map(int,input().split()))
l,r=10**9,0
while l-r>1:
    t=(l+r)
    if sum((i-1)
        r=t
    else:
        l=t
print(l)

Problem: p02598
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k = map(int,input().split())
a = list(map(int,input().split()))

leq,high = 0,1e10
while high-leq > 1:
  l = int((leq+high)/2)
  cnt = 0
  for ai in a:
    cnt += int((ai-1)/l)
  print(l,cnt)
  if cnt>k:
    leq = l
  else:
    high = l

print(high)

Failing test case input:
10 10
65342472 558595019 418943009 5002981 861648772 623690081 232778827 940657280 262703497 211047202

Expected output:
279297510


Actual output:
5000000000 0
2500000000 0
1250000000 0
625000000 2
312500000 8
156250000 22
234375000 13
273437500 11
292968750 9
283203125 10
278320312 11
280761718 10
279541015 10
278930663 11
279235839 11
279388427 10
279312133 10
279273986 11
279293059 11
279302596 10
279297827 10
279295443 11
279296635 11
279297231 11
279297529 10
279297380 11
279297454 11
279297491 11
279297510 10
279297500 11
279297505 11
279297507 11
279297508 11
279297509 11
279297510


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

leq,high = 0,1e10
while high-leq > 1:
  l = int((leq+high)/2)
  cnt = 0
  for ai in a:
    cnt += int((ai-1)/l)
  if cnt>k:
    leq = l
  else:
    high = l

print(high)
Problem: p02598
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math
N, K = map(int,input().split())
A = [int(i) for i in input().split()]

low = 1
high = 10 ** 9
if K == 0:
    print(max(A))
else:
    while high - low > 1:
        mid = (low + high) / 2
        times = 0
        for a in A:
            times += math.ceil(a / mid) - 1
        if K >= times:
            high = mid
        else:
            low = mid
        

    print(math.ceil(mid))


Failing test case input:
10 5
313970279 877914575 1099830373 24979445 260862409 490281723 614350897 720908410 198921849 211047202

Expected output:
490281723


Actual output:
490281724


Fixed submission (verdict: Accepted):
import math
N, K = map(int,input().split())
A = [int(i) for i in input().split()]

if K == 0:
    print(max(A))
else:
    low = 0
    high = max(A)
    while high - low > 0.1:
        mid = (low + high) / 2
        times = 0
        for a in A:
            times += math.ceil(a / mid) - 1
        if K >= times:
            high = mid
        else:
            low = mid
        

    ans = int(mid)
    if not ans:
        print(1)
    else:
        times = 0
        for a in A:
            times += math.ceil(a / ans) - 1
        if times <= K:
            print(ans)
        else:
            print(ans+1)

Problem: p02598
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
n,k = map(int,input().split())
a_list = list(map(int,input().split()))

min_num = 1
max_num = 10**9+1
while True:
    x = int((min_num+max_num)/2)
    if sum([math.ceil(a/x)-1 for a in a_list])>k:
        min_num = x
    else:
        max_num = x
    if max_num-min_num<=1:
        break
    
print(int(max_num))


Failing test case input:
2 6
1 6

Expected output:
1


Actual output:
2


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

min_num = 1
max_num = 10**9+1
while True:
    
    x = int((min_num+max_num)/2)
    if sum([math.ceil(a/x)-1 for a in a_list])>k:
        min_num = x
    else:
        max_num = x
    if max_num-min_num<=1:
        break
    
if sum([math.ceil(a/min_num)-1 for a in a_list])>k:
    print(min_num+1)
else:
    print(min_num)