ZhenlongDai/ACPR huggingface dataset:
Problem: p02716
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a = list(map(int,input().split()))




x0,x1,x2,o0,o1,o2=a[0],0,-10**10,-10**10,a[1],-10**10
for i in a[2:]:
    x0,x1,x2,o0,o1,o2=o0,max(o1,x0),max(o2,x1),x0+i,x1+i,x2+i
if n%2==0:
    print(max(x1,o1))
else:
    print(max(x2,o2))

Failing test case input:
10
0001011000 1001010000 1000000001 1001101000 1001011101 1010000000 0100100011 0100100110 1100011100 0001000010

Expected output:
3202133213


Actual output:
3201122213


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






x0,x1,x2,o0,o1,o2=a[0],-10**18,0,-10**18,a[1],-10**18
for i in a[2:]:
    x0,x1,x2,o0,o1,o2=o0,max(o1,x0),max(o2,x1),x0+i,x1+i,x2+i
if n%2==0:
    print(max(x0,x1,o1))
else:
    print(max(x1,x2,o2))

Problem: p02716
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    a0, a1, a2, b0, b1, b2 = A[0], 0, 0, A[1], 0, 0
    for a in A[2:]:
        a0, a1, a2, b0, b1, b2 = (
                b0,
                max(b1, a0),
                max(b2, a1),
                a0 + a,
                a1 + a,
                a2 + a)

    if N & 1:
        return max(b2, a1)
    else:
        return max(a0, b1)


print(main())


Failing test case input:
6
-2 1 1 2 -1 0

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    a0, a1, a2, b0, b1, b2 = 0, 0, 0, 0, 0, 0
    for i, a in enumerate(A):
        a0, a1, a2, b0, b1, b2 = (
                b0,
                max(b1, a0),
                max(b2, a1),
                a0 + a,
                a1 + a if i >= 1 else a1,
                a2 + a if i >= 2 else a2)

    if N & 1:
        return max(b2, a1)
    else:
        return max(b1, a0)


print(main())

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




x0,x1,x2,o0,o1,o2=a[0],0,-10**10,-10**10,a[1],-10**10
for i in a[2:]:
    x0,x1,x2,o0,o1,o2=o0,max(o1,x0),max(o2,x1),x0+i,x1+i,x2+i
if n%2==0:
    print(max(x0,x1,o1))
else:
    print(max(x1,x2,o2))


Failing test case input:
5
-4623 -4 -1 0 34

Expected output:
33


Actual output:
30


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






x0,x1,x2,o0,o1,o2=a[0],-10**18,0,-10**18,a[1],-10**18
for i in a[2:]:
    x0,x1,x2,o0,o1,o2=o0,max(o1,x0),max(o2,x1),x0+i,x1+i,x2+i
if n%2==0:
    print(max(x0,x1,o1))
else:
    print(max(x1,x2,o2))
Problem: p02716
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
if N%2:
    a, b, c = 0, 0, 0
    for i in range(0,N-2,2):
        c=max(a+A[i+2],b+A[i+2],c+A[i+2])
        b=max(a+A[i+1],b+A[i+1])
        a+=A[i]
    print(max(a,b,c))
else:
    print(max(sum(A[::2]), sum(A[1::2])))

Failing test case input:
6
1 2 11 4 5 6

Expected output:
18


Actual output:
17


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
if N%2:
    a, b, c = 0, 0, 0
    for i in range(0,N-2,2):
        c=max(a+A[i+2],b+A[i+2],c+A[i+2])
        b=max(a+A[i+1],b+A[i+1])
        a+=A[i]
    print(max(a,b,c))
else:
    a, b = 0, 0
    for i in range(0,N-1,2):
        b=max(a+A[i+1],b+A[i+1])
        a+=A[i]
    print(max(a,b))

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





x0,x1,x2,o0,o1,o2=a[0],0,-10**18,-10**18,a[1],-10**18
for i in a[2:]:
    x0,x1,x2,o0,o1,o2=o0,max(o1,x0),max(o2,x1),x0+i,x1+i,x2+i
if n%2==0:
    print(max(x0,x1,o1))
else:
    print(max(x1,x2,o2))

Failing test case input:
5
-4623 -4 -1 0 34

Expected output:
33


Actual output:
30


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






x0,x1,x2,o0,o1,o2=a[0],-10**18,0,-10**18,a[1],-10**18
for i in a[2:]:
    x0,x1,x2,o0,o1,o2=o0,max(o1,x0),max(o2,x1),x0+i,x1+i,x2+i
if n%2==0:
    print(max(x0,x1,o1))
else:
    print(max(x1,x2,o2))

Problem: p02716
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
K = N % 2 + 1
A = tuple(map(int, input().split()))

table = [[0] * (K + 2) for _ in range(N + 1)]
for i in range(N):
    for j in range(K + 1):
        table[i + 1][j] = max(table[i][j] + (A[i] if not (i + j) % 2 else 0), table[i + 1][j])
        table[i + 1][j + 1] = max(table[i + 1][j + 1], table[i][j])
print(table[N][K])


Failing test case input:
27
22 -28 21 62 -59 33 -2 13 -62 9 1 -44 -71 4 -25 -62 66 -170 33 24 -100 -100 27 -85 51 48 -84

Expected output:
92


Actual output:
93


Fixed submission (verdict: Accepted):
N = int(input())
K = N % 2 + 1
A = tuple(map(int, input().split()))
table = [[-float("inf")] * (K + 2) for _ in range(N + 1)]
table[0][0] = 0
for i in range(N):
    for j in range(K + 1):
        table[i + 1][j] = max(table[i][j] + (A[i] if not (i + j) % 2 else 0), table[i + 1][j])
        table[i + 1][j + 1] = max(table[i][j], table[i + 1][j + 1])
print(table[N][K])
Problem: p02716
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

dp = [0] * (N + 1)
dp[2] = max(A[0], A[1])
s = 0
for i, a in enumerate(A, 1):
  if i <= 2:
    continue
  if i%2: 
    dp[i] = max(dp[i-1], a+dp[i-2])
    s += a
  else: 
    dp[i] = max(a+dp[i-2], s)

print(dp[-1])

Failing test case input:
10
1001000000 1001000010 1000000001 0001001100 1001001000 1010001000 0100000010 0100100100 1100011000 1001000010

Expected output:
4202012011


Actual output:
3201012011


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

dp = [0] * (N + 1)
dp[2] = max(A[0], A[1])
s = A[0]
for i, a in enumerate(A, 1):
  if i <= 2:
    continue
  if i%2: 
    dp[i] = max(dp[i-1], a+dp[i-2])
    s += a
  else: 
    dp[i] = max(a+dp[i-2], s)

print(dp[-1])

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




x0,x1,x2,o0,o1,o2=a[0],0,0,-10**10,a[1],-10**10
for i in a[2:]:
    x0,x1,x2,o0,o1,o2=o0,max(o1,x0),max(o2,x1),x0+i,x1+i,x2+i
if n%2==0:
    print(max(x0,x1,o1))
else:
    print(max(x1,x2,o2))


Failing test case input:
6
-1 0 3 2 0 -1

Expected output:
2


Actual output:
3


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






x0,x1,x2,o0,o1,o2=a[0],-10**18,0,-10**18,a[1],-10**18
for i in a[2:]:
    x0,x1,x2,o0,o1,o2=o0,max(o1,x0),max(o2,x1),x0+i,x1+i,x2+i
if n%2==0:
    print(max(x0,x1,o1))
else:
    print(max(x1,x2,o2))

Problem: p02716
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

dp = [0]*N

cum = A[0]
for i in range(N):
    if i == 0:
        dp[i] = 0
        continue
    if i == 1:
        dp[i] = max(A[0],A[1])
        continue
    if i%2==1:
        cum += A[i]
        dp[i] = max(dp[i],dp[i-2]+A[i])

    if i%2==0:
        dp[i] = max(dp[i-2]+A[i],cum)

ans = dp[-1]


print(ans)


Failing test case input:
10
1000000000 1001000000 1000000000 0000001000 1000000000 1010001000 0000000000 1000000000 1000000000 1000100000

Expected output:
5010101000


Actual output:
4011102000


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

dp = [0]*N

cum = A[0]
for i in range(N):
    if i == 0:
        dp[i] = 0
        continue
    if i == 1:
        dp[i] = max(A[0],A[1])
        continue
    if i%2==0: 
        cum += A[i]
        dp[i] = max(dp[i-1],dp[i-2]+A[i])

    if i%2==1: 
        dp[i] = max(dp[i-2]+A[i],cum)

ans = dp[-1]


print(ans)
Problem: p02716
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from sys import stdin, stdout
def main():
    N = int(stdin.readline())
    A = list(map(int, stdin.readline().rstrip().split()))
    dp = [0] * N
    dp[1] = max(A[0], A[1])
    for i in range(2, N):
        if i & 1 == 0:
            dp[i] = max(dp[i-1], A[i] + dp[i-2])
        else:
            dp[i] = A[i] + dp[i-2]
    ret=dp[N-1]
    stdout.write(str(ret)+"\n")
main()


Failing test case input:
10
1000000000 1001000000 1000000000 0000001000 1000001000 1010001000 0000000000 1100000001 1000001000 1000100000

Expected output:
5110101001


Actual output:
4111102001


Fixed submission (verdict: Accepted):
from sys import stdin, stdout
def main():
    N = int(stdin.readline())
    A = [0] + list(map(int, stdin.readline().rstrip().split()))
    dp = [0] * (N+1)
    prefix = [0] * (N+1)
    dp[1], prefix[1] = 0, A[1]
    for i in range(3, N, 2):
        prefix[i] = prefix[i-2]+A[i]
    for i in range(2, N+1):
        if i & 1:
            dp[i] = max(dp[i-1], A[i] + dp[i-2])
        else:
            dp[i] = max(dp[i-2] + A[i], prefix[i-1])
    
    stdout.write(str(dp[N])+"\n")
main()

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





x0,x1,x2,o0,o1,o2=a[0],0,0,-10**18,a[1],-10**18
for i in a[2:]:
    x0,x1,x2,o0,o1,o2=o0,max(o1,x0),max(o2,x1),x0+i,x1+i,x2+i
if n%2==0:
    print(max(x0,x1,o1))
else:
    print(max(x1,x2,o2))

Failing test case input:
6
-1 0 3 2 3 -1

Expected output:
5


Actual output:
6


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






x0,x1,x2,o0,o1,o2=a[0],-10**18,0,-10**18,a[1],-10**18
for i in a[2:]:
    x0,x1,x2,o0,o1,o2=o0,max(o1,x0),max(o2,x1),x0+i,x1+i,x2+i
if n%2==0:
    print(max(x0,x1,o1))
else:
    print(max(x1,x2,o2))
Problem: p03839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

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

s = sum(a[:k])
t = 0
for i in range(k, n):
    if a[i] > 0:
        t += a[i]
ans = max(0, s + t)

for i in range(n - k):
    s -= a[i]
    s += a[k + i]
    t -= a[k + i]
    if a[i] > 0:
        t += a[i]
    ans = max(ans, s + t)
    
print(ans)
    
    



Failing test case input:
4 3
3 -2 -8 20

Expected output:
20


Actual output:
13


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

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

s = sum(a[:k])
t = 0
for i in range(k, n):
    if a[i] > 0:
        t += a[i]
ans = max(t, s + t)

for i in range(n - k):
    s -= a[i]
    s += a[k + i]
    if a[k + i] > 0:
        t -= a[k + i]
    if a[i] > 0:
        t += a[i]
    ans = max(ans, s + t, t)
    
print(ans)

Problem: p03839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ans = 0
for i in range(N):
	if A[i] > 0:
		ans += A[i]
		A[i] = 0
t = 1
for a in A:
	if not a:
		t += 1
	else:
		t = 1
	if t >= K:
		print(ans)
		exit()
m = sum(A[:K])
for i in range(N-K):
	M = m - A[i] + A[i+K]
	m = max(M,m)
print(max(ans+m,0))

Failing test case input:
5 3
-10 8 -10 10 -10

Expected output:
10


Actual output:
8


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
a = 0
for i in range(N):
	if A[i] > 0:
		a += A[i]
p = sum([i for i in A[:K] if i > 0])
m = sum([i for i in A[:K] if i < 0])
ans = max(a+m,a-p)
for i in range(N-K):
	p = p - max(0,A[i]) + max(0,A[i+K])
	m = m - min(0,A[i]) + min(0,A[i+K])
	ans = max(ans, a-p, a+m)
print(ans)

Problem: p03839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

Plus, Whole = [0], [0]
for i in range(N):
    Plus.append(Plus[-1] + max(A[i], 0))
    Whole.append(Whole[-1] + A[i])

Full = Plus[N-K] - Plus[0] + Whole[N] - Whole[N-K]
MaxScore = max(Full, Plus[N-K] - Plus[0])
for i in range(1, K):
    temp = Plus[N-K] - Plus[0] + Whole[N]-Whole[N-K+i] - (Plus[N-K] - Plus[N+1 -2*K])
    MaxScore = max(MaxScore, temp)

print(MaxScore)

Failing test case input:
5 3
-10 8 -10 10 -4

Expected output:
10


Actual output:
8


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

Plus, Whole = [0], [0]
for i in range(N):
    Plus.append(Plus[-1] + max(A[i], 0))
    Whole.append(Whole[-1] + A[i])

Score = max(max(0, Whole[K] - Whole[0]) + Plus[N] - Plus[K], Plus[N-K] - Plus[0] + max(0, Whole[N] - Whole[N-K]))
for i in range(1, N-K):
    temp = Plus[i] + max(0, Whole[i+K] - Whole[i]) + Plus[N] - Plus[i+K]
    Score = max(Score, temp)

print(Score)
Problem: p03839
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
P=[0]*(N+1)
T=[0]*(N+1)
for i in range(N):
    P[i+1]=P[i]+A[i]
    if A[i]>=0:
        T[i+1]=T[i]+A[i]
    else:
        T[i+1]=T[i]
a=max(sum(P),0)
for i in range(K,N+1):
    t=P[i]-P[i-K]
    s=T[i-K]-T[0]
    u=T[N]-T[i]
    a=max(a,s+t+u,s+u)
    
print(a)

Failing test case input:
10 5
5 -1 -3 -3 0 13 2 -4 1 14

Expected output:
31


Actual output:
73


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
P=[0]*(N+1)
T=[0]*(N+1)
for i in range(N):
    P[i+1]=P[i]+A[i]
    if A[i]>=0:
        T[i+1]=T[i]+A[i]
    else:
        T[i+1]=T[i]
a=max(sum(A),0)
for i in range(K,N+1):
    t=P[i]-P[i-K]
    s=T[i-K]-T[0]
    u=T[N]-T[i]
    a=max(a,s+t+u,s+u)
    
print(a)

Problem: p03839
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
acc=[0]*(n+1)
pos=[0]*(n+1)
for i in range(n):
    acc[i+1]+=a[i]
    pos[i+1]+=max(a[i],0)

ans=-10**18

for i in range(n-k):
    ans=max(ans,acc[i+k]-acc[i]+pos[i]+pos[-1]-pos[i+k])
    ans=max(ans,pos[i]+pos[-1]-pos[i+k])
print(ans)

Failing test case input:
5 2
0 10 -10 38 1

Expected output:
49


Actual output:
1


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
acc=[0]*(n+1)
pos=[0]*(n+1)
for i in range(n):
    acc[i+1]+=a[i]+acc[i]
    pos[i+1]+=max(a[i],0)+pos[i]

ans=-10**18

for i in range(n-k+1):
    ans=max(ans,acc[i+k]-acc[i]+pos[i]+pos[-1]-pos[i+k])
    ans=max(ans,pos[i]+pos[-1]-pos[i+k])
print(ans)

Problem: p03839
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, k = map(int, input().split())
a = list(map(int, input().split()))

cum = []
abscum = []

cu = 0
acu = 0
for i in range(n):
    cu += a[i]
    acu += max(0, a[i])
    cum.append(cu)
    abscum.append(acu)

ans = 0
for i in range(n-k):
    if i == 0:
        ans = max(ans, abscum[n-1] - abscum[i+k-1] + max(0, cum[i+k-1]))
    else:
        ans = max(ans, abscum[n - 1] - (abscum[i + k - 1] - abscum[i-1]) + max(0, cum[i + k - 1] - cum[i-1]))

print(ans)

Failing test case input:
4 4
7 -2 -10 38

Expected output:
33


Actual output:
0


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

cum = []
abscum = []

cu = 0
acu = 0
for i in range(n):
    cu += a[i]
    acu += max(0, a[i])
    cum.append(cu)
    abscum.append(acu)

ans = 0
for i in range(n-k+1):
    if i == 0:
        ans = max(ans, abscum[n-1] - abscum[i+k-1] + max(0, cum[i+k-1]))
    else:
        ans = max(ans, abscum[n - 1] - (abscum[i + k - 1] - abscum[i-1]) + max(0, cum[i + k - 1] - cum[i-1]))

print(ans)
Problem: p03839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
lis = list(map(int,input().split()))
num = 0
ans = 0
for i in range(n):
  num += max(0,lis[i])
li = [0 for i in range(n-k+1)]
for i in range(n-k+1):
  cou = 0
  co = 0
  for nu in lis[i:i+k+1]:
    if nu >= 0:
      cou += nu
    else:
      co -= nu
  if cou >= co:ans = max(ans,num-co)
  else:ans = max(ans,num-cou)
  
print(ans)

Failing test case input:
4 2
7 -2 -10 20

Expected output:
27


Actual output:
20


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
lis = list(map(int,input().split()))
num = 0
ans = 0
cou = 0
co = 0
for i in range(n):num += max(0,lis[i])
li = [0 for i in range(n-k+1)]
for i in range(k-1):
  cou += max(0,lis[i])
  co += max(0,-lis[i])
for i in range(n-k+1):
  cou += max(0,lis[i+k-1])
  co += max(0,-lis[i+k-1])
  if cou >= co:ans = max(ans,num-co)
  else:ans = max(ans,num-cou)
  cou -= max(0,lis[i])
  co -= max(0,-lis[i])
print(ans)

Problem: p03839
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, k = map(int, input().split())
a = list(map(int, input().split()))

cum = []
abscum = []

cu = 0
acu = 0
for i in range(n):
    cu += a[i]
    acu += abs(a[i])
    cum.append(cu)
    abscum.append(acu)

ans = 0
for i in range(n-k):
    if i == 0:
        ans = max(ans, abscum[n-1] - abscum[i+k-1] + max(0, cum[i+k-1]))
    else:
        ans = max(ans, abscum[n - 1] - (abscum[i + k - 1] - abscum[i-1]) + max(0, cum[i + k - 1] - cum[i-1]))

print(ans)

Failing test case input:
5 3
-10 8 -10 10 -10

Expected output:
10


Actual output:
28


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

cum = []
abscum = []

cu = 0
acu = 0
for i in range(n):
    cu += a[i]
    acu += max(0, a[i])
    cum.append(cu)
    abscum.append(acu)

ans = 0
for i in range(n-k+1):
    if i == 0:
        ans = max(ans, abscum[n-1] - abscum[i+k-1] + max(0, cum[i+k-1]))
    else:
        ans = max(ans, abscum[n - 1] - (abscum[i + k - 1] - abscum[i-1]) + max(0, cum[i + k - 1] - cum[i-1]))

print(ans)

Problem: p03839
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k=map(int,input().split())

a=[int(i) for i in input().split()]
acc=[0]*(n+1)
pos=[0]*(n+1)
for i in range(n):
    acc[i+1]+=a[i]
    pos[i+1]+=max(a[i],0)

ans=sum(a[0:k]+pos[k:])


for i in range(n-k):
    ans=max(ans,acc[i+k]-acc[i]+pos[i]+pos[-1]-pos[i+k])
    ans=max(ans,pos[i]+pos[-1]-pos[i+k])
print(ans)



Failing test case input:
5 3
-3 0 -18 14 -10

Expected output:
14


Actual output:
3


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
acc=[0]*(n+1)
pos=[0]*(n+1)
for i in range(n):
    acc[i+1]+=a[i]+acc[i]
    pos[i+1]+=max(a[i],0)+pos[i]

ans=-10**18

for i in range(n-k+1):
    ans=max(ans,acc[i+k]-acc[i]+pos[i]+pos[-1]-pos[i+k])
    ans=max(ans,pos[i]+pos[-1]-pos[i+k])
print(ans)
Problem: p03839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate
n,k = map(int,input().split())
a = list(map(int,input().split()))
suma = 0
for i in range(n-k,n):
  suma += max(0,a[i])
acca = [0]+list(accumulate(a))
ans = [max(suma,suma+acca[k])]
for i in range(1,n-k+1):
  suma += max(0,a[i-1])
  suma -= max(0,a[i+k-1])
  ans.append(max(suma,suma+acca[i+k]-acca[i]))
print(max(ans))

Failing test case input:
4 4
1 -1 -16 20

Expected output:
4


Actual output:
25


Fixed submission (verdict: Accepted):
from itertools import accumulate
n,k = map(int,input().split())
a = list(map(int,input().split()))
suma = 0
for i in range(k,n):
  suma += max(0,a[i])
acca = [0]+list(accumulate(a))
ans = [max(suma,suma+acca[k])]
for i in range(1,n-k+1):
  suma += max(0,a[i-1])
  suma -= max(0,a[i+k-1])
  ans.append(max(suma,suma+acca[i+k]-acca[i]))
print(max(ans))

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

N,K = map(int,input().split())
a = [0] + list(map(int,input().split()))
ans = 0
tmp = [0,0]
for i in range(1,K+1):
    ans += max(0,a[i])
    tmp[int(a[i]>=0)] += abs(a[i])
loss = min(tmp)
for i in range(K+1,N+1):
    ans += max(0,a[i])
    tmp[int(a[i-K+1]>=0)] -= abs(a[i-K+1])
    tmp[int(a[i]>=0)] += abs(a[i])
    loss = min(loss,min(tmp))
print(ans-loss)

Failing test case input:
10 5
6 -4 -5 -16 -4 0 2 -4 -1 3

Expected output:
11


Actual output:
6


Fixed submission (verdict: Accepted):

N,K = map(int,input().split())
a = [0] + list(map(int,input().split()))
ans = 0
tmp = [0,0]
for i in range(1,K+1):
    ans += max(0,a[i])
    tmp[a[i]>=0] += abs(a[i])
loss = min(tmp)
for i in range(K+1,N+1):
    ans += max(0,a[i])
    tmp[a[i-K]>=0] -= abs(a[i-K])
    tmp[a[i]>=0] += abs(a[i])
    loss = min(loss,min(tmp))
print(ans-loss)

Problem: p03839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ans = 0
for i in range(N):
	if A[i] > 0:
		ans += A[i]
		A[i] = 0
s = 0
t = 0
for a in A:
	if not a:
		t += 1
		s = 1
	else:
		t = 1
		s += 1
	if t >= K or s >= K:
		print(ans)
		exit()
m = sum(A[:K])
for i in range(N-K):
	M = m - A[i] + A[i+K]
	m = max(M,m)
print(max(ans+m,0))

Failing test case input:
5 3
-3 0 -21 14 -10

Expected output:
14


Actual output:
0


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
a = 0
for i in range(N):
	if A[i] > 0:
		a += A[i]
p = sum([i for i in A[:K] if i > 0])
m = sum([i for i in A[:K] if i < 0])
ans = max(a+m,a-p)
for i in range(N-K):
	p = p - max(0,A[i]) + max(0,A[i+K])
	m = m - min(0,A[i]) + min(0,A[i+K])
	ans = max(ans, a-p, a+m)
print(ans)
Problem: p03839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
a=list(map(int,input().split()))
sum_a=[0]*(n+1)
b=[max(0,a[i]) for i in range(n)]
sum_b=[0]*(n+1)
sum_a[1]=a[0]
sum_b[1]=a[0]
for i in range(1,n):
  sum_a[i+1]=sum_a[i]+a[i]
  sum_b[i+1]=sum_b[i]+b[i]
ans=-10**18
for i in range(n-k+1):
  l,r=i,i+k
  cnt=sum_b[l]-sum_b[0]
  cnt+=max(0,sum_a[r]-sum_a[l])
  cnt+=sum_b[n]-sum_b[r]
  ans=max(ans,cnt,)
print(ans)

Failing test case input:
5 3
-25 6 -10 3 -4

Expected output:
6


Actual output:
3


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=list(map(int,input().split()))
sum_a=[0]*(n+1)
b=[max(0,a[i]) for i in range(n)]
sum_b=[0]*(n+1)
sum_a[1]=a[0]
sum_b[1]=b[0]
for i in range(1,n):
  sum_a[i+1]=sum_a[i]+a[i]
  sum_b[i+1]=sum_b[i]+b[i]
ans=-10**18
for i in range(n-k+1):
  l,r=i,i+k
  cnt=sum_b[l]-sum_b[0]
  cnt+=max(0,sum_a[r]-sum_a[l])
  cnt+=sum_b[n]-sum_b[r]
  ans=max(ans,cnt)
print(ans)

Problem: p03839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import deque

n, k = map(int, input().split())
a = list(map(int, input().split()))
q = deque(a[:k])
max_ = min_ = c = sum(q)
plus = plus_in_max = plus_in_min = sum(x for x in q if x > 0)
for b in a[k:]:
    c -= q.popleft()
    c += b
    q.append(b)
    if max_ < c:
        max_ = c
        plus_in_max = sum(x for x in q if x > 0)
    if min_ > c:
        min_ = c
        plus_in_min = sum(x for x in q if x > 0)
    if b > 0:
        plus += b
print(max(plus + max_ - plus_in_max, plus - plus_in_min))


Failing test case input:
5 3
-3 0 -2 2 -10

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import deque

n, k = map(int, input().split())
a = list(map(int, input().split()))
q = deque(a[:k])
plus = cur_plus = min_plus = sum(x for x in q if x > 0)
cur_minus = max_minus = sum(q) - plus
for b in a[k:]:
    c = q.popleft()
    q.append(b)
    if b > 0:
        plus += b
        cur_plus += b
    else:
        cur_minus += b
    if c > 0:
        cur_plus -= c
    else:
        cur_minus -= c
    max_minus = max(max_minus, cur_minus)
    min_plus = min(min_plus, cur_plus)
print(max(plus + max_minus, plus - min_plus))
Problem: p03839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate

N, K = map(int, input().split())
a_list = list(map(int, input().split()))

b_list = []
for a in a_list:
    if a > 0:
        b_list.append(a)
    else:
        b_list.append(0)
b_list = list(accumulate(b_list))
a_acc = list(accumulate(a_list))

b_list.insert(0, 0)
b_list.append(b_list[-1])
ans = 0


for i in range(N - K + 1):
    ans = max(ans, b_list[i] + a_acc[i + K - 1] - a_acc[i-1] + b_list[N] - b_list[i + K])
    ans = max(ans, b_list[i] + b_list[N] - b_list[i + K])
print(ans)


Failing test case input:
4 1
7 -6 -10 8

Expected output:
15


Actual output:
16


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

N, K = map(int, input().split())
a_list = list(map(int, input().split()))

b_list = []
for a in a_list:
    if a > 0:
        b_list.append(a)
    else:
        b_list.append(0)
b_list = list(accumulate(b_list))
a_acc = list(accumulate(a_list))

b_list.insert(0, 0)
b_list.append(b_list[-1])
a_acc.insert(0, 0)
ans = 0


for i in range(N - K + 1):

    ans = max(ans, b_list[i] + a_acc[i + K] - a_acc[i] + b_list[N] - b_list[i + K])
    ans = max(ans, b_list[i] + b_list[N] - b_list[i + K])
print(ans)

Problem: p03839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate as ac
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(ac(a))
c=list(ac([(0 if i<0 else i)for i in a]))
d=0
for i in range(n-k):
    d=max(d,max(b[i+k-1]-b[i],0)+c[i]+c[-1]-c[i+k])
print(d)

Failing test case input:
5 3
-3 0 -18 14 -10

Expected output:
14


Actual output:
0


Fixed submission (verdict: Accepted):
from itertools import accumulate as ac
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]+list(ac(a))
c=[0]+list(ac([(0 if i<0 else i)for i in a]))
d=0
for i in range(n-k+1):
    d=max(d,max(b[i+k]-b[i],0)+c[i]+c[-1]-c[i+k])
print(d)

Problem: p03839
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K=map(int,input().split())
a=list(map(int,input().split()))
ans=0
tmp=0
for i in range(N):
  if i < K:
    tmp+=a[i]
  else:
    if a[i]>0:
      ans+=a[i]
ans+=max(0,tmp)

ans2=0
tmp=0
for i in range(N-1,-1,-1):
  if i < N-K:
    if a[i]>0:
      ans2+=a[i]
  else:
    tmp+=a[i]
ans2+=max(0,tmp)
print(max(ans2,ans))

Failing test case input:
10 5
5 -4 -5 -8 -4 0 2 -4 0 7

Expected output:
14


Actual output:
10


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
a=list(map(int,input().split()))
ans=0
tmp=0
sa=[0]*(N+1)
A=[0]*(N+1)
for i in range(N):
  sa[i+1]=sa[i]+a[i]
  if a[i]>0:
    A[i+1]=A[i]+a[i]
  else:
    A[i+1]=A[i]
for i in range(N-K+1):
  tmp=sa[i+K]-sa[i]
  tmp2=A[i]+(A[-1]-A[i+K])
  
  if max(0,tmp)+tmp2>ans:
    ans=max(0,tmp)+tmp2
print(ans)
Problem: p03839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

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

s = sum(a[:k])
t = 0
for i in range(k, n):
    if a[i] > 0:
        t += a[i]
ans = max(0, s + t)

for i in range(n - k):
    s -= a[i]
    s += a[k + i]
    if a[k + i] > 0:
        t -= a[k + i]
    if a[i] > 0:
        t += a[i]
    ans = max(ans, s + t)
    
print(ans)
    
    



Failing test case input:
4 2
7 -15 -10 10

Expected output:
17


Actual output:
7


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

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

s = sum(a[:k])
t = 0
for i in range(k, n):
    if a[i] > 0:
        t += a[i]
ans = max(t, s + t)

for i in range(n - k):
    s -= a[i]
    s += a[k + i]
    if a[k + i] > 0:
        t -= a[k + i]
    if a[i] > 0:
        t += a[i]
    ans = max(ans, s + t, t)
    
print(ans)

Problem: p03839
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, k = map(int, input().split())
a = list(map(int, input().split()))
cum = [0]
for i in range(n):
    cum.append(min(a[i], 0) + cum[-1])
cum2 = [0]
for i in range(n):
    cum2.append(max(a[i], 0) + cum2[-1])
SUM = sum(max(a[i], 0) for i in range(n))
l = []
for i in range(n - k + 1):
    l.append(SUM + cum[i + k] - cum[i])
    l.append(SUM - cum2[i + k] + cum[i])
print(max(l))

Failing test case input:
4 2
7 -2 -3 52

Expected output:
59


Actual output:
57


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
a = list(map(int, input().split()))
cum = [0]
for i in range(n):
    cum.append(min(a[i], 0) + cum[-1])
cum2 = [0]
for i in range(n):
    cum2.append(max(a[i], 0) + cum2[-1])
SUM = sum(max(a[i], 0) for i in range(n))
l = []
for i in range(n - k + 1):
    l.append(SUM + cum[i + k] - cum[i])
    l.append(SUM - cum2[i + k] + cum2[i])
print(max(l))

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

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

pl = [(x if (x > 0) else 0) for x in a]
s = sum(pl)
sk_a = [sum(a[:K])]
sk_pl = [sum(pl[:K])]
for i in range(1, N - K + 1):
    sk_a.append(sk_a[-1] - a[i] + a[K + i - 1])
    sk_pl.append(sk_pl[-1] - pl[i] + pl[K + i - 1])

ans = 0
if lambda x: x > 0 in a:
    for i in range(N - K + 1):
        ans = max(ans, s - sk_pl[i] + max(0, sk_a[i]))
print(ans)


Failing test case input:
10 5
5 -4 -5 -8 -4 0 2 -4 0 7

Expected output:
14


Actual output:
10


Fixed submission (verdict: Accepted):

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

pl = [(x if (x > 0) else 0) for x in a]
s = sum(pl)
sk_a = [sum(a[:K])]
sk_pl = [sum(pl[:K])]
for i in range(1, N - K + 1):
    sk_a.append(sk_a[-1] - a[i - 1] + a[K + i - 1])
    sk_pl.append(sk_pl[-1] - pl[i - 1] + pl[K + i - 1])

ans = 0
if lambda x: x > 0 in a:
    for i in range(N - K + 1):
        ans = max(ans, s - sk_pl[i] + max(0, sk_a[i]))

print(ans)
Problem: p02372
Buggy submission (Python3, verdict: Wrong Answer):
from heapq import heappop, heappush

INF = 10 ** 20

def main():
  n = int(input())
  edges = [[] for _ in range(n)]
  for _ in range(n - 1):
    s, t, w = map(int, input().split())
    edges[s].append((w, t))
    edges[t].append((w, s))
  
  def func(start):
    cost = [INF] * n
    que = [(0, start)]
    cost[start] = 0
    
    while que:
      acc, num = heappop(que)
      for weight, to in edges[num]:
        if weight + acc < cost[to]:
          cost[to] = weight + acc
          heappush(que, (weight + acc, to))
    return cost
  
  cost1 = func(0)
  max_ind = cost1.index(max(cost1))
  cost2 = func(max_ind)
  lower = min(cost2)
  higher = max(cost2)
  for i in range(n):
    print(max(cost2[i] - lower, higher - cost2[i]))
main()


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

Expected output:
6
4
6
6


Actual output:
6
4
6
4


Fixed submission (verdict: Accepted):
from heapq import heappop, heappush

INF = 10 ** 20

def main():
  n = int(input())
  edges = [[] for _ in range(n)]
  for _ in range(n - 1):
    s, t, w = map(int, input().split())
    edges[s].append((w, t))
    edges[t].append((w, s))
  
  def func(start):
    cost = [INF] * n
    que = [(0, start)]
    cost[start] = 0
    
    while que:
      acc, num = heappop(que)
      for weight, to in edges[num]:
        if weight + acc < cost[to]:
          cost[to] = weight + acc
          heappush(que, (weight + acc, to))
    return cost
  
  cost1 = func(0)
  max_ind = cost1.index(max(cost1))
  cost2 = func(max_ind)
  max_ind2 = cost2.index(max(cost2))
  cost3 = func(max_ind2)
  for i in range(n):
    print(max(cost2[i], cost3[i]))
main()
Problem: p03786
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
a.sort()
d=[0]*n
d[0]=1
s=[0]*n
s[0]=a[0]

for i in range(1,n):
  s[i]=s[i-1]+a[i]
for i in range(1,n):
    if a[i]>2*s[i]:
        d[i]=1
    else:
        d[i]=d[i-1]+1
print(d[n-1])

Failing test case input:
6
65 3 23 1 1 38

Expected output:
3


Actual output:
6


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
a.sort()
d=[0]*n
d[0]=1
s=[0]*n
s[0]=a[0]

for i in range(1,n):
  s[i]=s[i-1]+a[i]
for i in range(1,n):
    if a[i]>2*s[i-1]:
        d[i]=1
    else:
        d[i]=d[i-1]+1
print(d[n-1])

Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=sorted(list(map(int,input().split())))
ls=[]
tmp=0
for i in l:
    tmp+=i
    ls.append(tmp)
l.reverse()
ls.reverse()
l=[0]+l
ans=0
for i in range(n):
    if ls[i]*2>=l[i]:ans+=1
    else:print(ans);exit()

Failing test case input:
5
1 1 2 1 1

Expected output:
5


Actual output:

Fixed submission (verdict: Accepted):
n=int(input())
l=sorted(list(map(int,input().split())))
ls=[]
tmp=0
for i in l:
    tmp+=i
    ls.append(tmp)
l.reverse()
ls.reverse()
l=[0]+l
ans=0
for i in range(n):
    if ls[i]*2>=l[i]:ans+=1
    else:print(ans);exit()
print(ans)

Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=sorted(list(map(int,input().split(' '))))
acc=[A[0]]
ans =1
for i in A[1:]:
    acc.append(A[-1]+i)
for i in range(N-1,0,-1):
    if acc[i]>acc[i-1]*2:
        print(N-i)
        exit()

Failing test case input:
5
2 0 2 0 2

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N=int(input())
A=sorted(list(map(int,input().split(' '))))
acc=[A[0]]
ans =1
for i in A[1:]:
    acc.append(acc[-1]+i)
for i in range(N-1,0,-1):
    if A[i]>acc[i-1]*2:
        print(N-i)
        exit()
print(N)

Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
S = list(accumulate(A))
AS = []
flg = False
count = 0

for i in range(N-1):
  AS.append(S[i]*2 - A[i+1])
for j in range(N-1):
  if AS[j] < 0:
    flg = True
  elif AS[j] >= 0 and flg:
    count = j
    break
print(len(A)-count)

Failing test case input:
6
58 1 63 0 1 1

Expected output:
2


Actual output:
5


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

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
S = list(accumulate(A))
AS = []
flg = False
count = 0

for i in range(N-1):
  AS.append(S[i]*2 - A[i+1])
for j in range(N-2,-1,-1):
  if AS[j] < 0:
    count = j+1
    break
print(len(A)-count)
Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))

A.sort()
ans=N
tmp=0
for i in range(N):
    if tmp*2<A[i]:
        ans-=i
    tmp+=A[i]

print(ans)

Failing test case input:
6
65 2 38 0 1 43

Expected output:
3


Actual output:
2


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

A.sort()
ans=0
tmp=0
for i in range(0,N):
    if tmp*2<A[i]:
        ans=0
    tmp+=A[i]
    ans+=1

print(ans)

Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int, input().split()))
a.sort(reverse=True)
b=[0]
for i in a:
    b.append(i+b[-1])
ans=1
for i in range(1,n):
    print(b[i]-b[i-1],(b[-1]-b[i]))
    if b[i]-b[i-1]<=2*(b[-1]-b[i]):
        ans+=1
    else:break
print(ans)

Failing test case input:
6
40 1 4 2 9 34

Expected output:
2


Actual output:
40 50
34 16
2


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int, input().split()))
a.sort(reverse=True)
b=[0]
for i in a:
    b.append(i+b[-1])
ans=1
for i in range(1,n):
    if b[i]-b[i-1]<=2*(b[-1]-b[i]):
        ans+=1
    else:break
print(ans)

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

B=[A[0]]
for i in range(1,N):
  B.append(B[-1]+A[i])
print(A)
print(B)

left=0
for left in range(N-2,-1,-1):
  if B[left]*2>=A[left+1]:
    pass
  else:
    break

num=N-left-1
print(num)





Failing test case input:
5
2 0 1 0 2

Expected output:
3


Actual output:
[0, 0, 1, 2, 2]
[0, 0, 1, 3, 5]
3


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

B=[A[0]]
for i in range(1,N):
  B.append(B[-1]+A[i])



left=0
for left in range(N-2,-1,-1):
  if B[left]*2>=A[left+1]:
    pass
  else:
    break
else:
  left=-1

num=N-left-1

print(num)

Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = input().split()
for i in range(0,N):
	a[i] = int(a[i])
a.sort()
t = 0
flag = 1
sum_a = 0
for i in range(0,N-1):
	sum_a += a[i]
	if sum_a*2 < a[i+1]:
		t = i+1
		flag = 0
	if flag == 0:
		break
			
print(N-t)

Failing test case input:
6
65 1 38 0 1 94

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
N = int(input())
a = input().split()
for i in range(0,N):
	a[i] = int(a[i])
a.sort()
t = 0
flag = 1
sum_a = 0
for i in range(0,N-1):
	sum_a += a[i]
	if sum_a*2 < a[i+1]:
		t = i+1

			
print(N-t)

Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
a.sort()
sm = []
sm.append(a[0])
for i in range(1,n):
    sm.append(sm[-1]+a[i])
num = 0
for i in range(1,n):
    if sm[i-1] * 2 < a[i]:
        num = i
        break
print(n - num)


Failing test case input:
6
65 1 38 0 0 94

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
a.sort()
sm = []
sm.append(a[0])
for i in range(1,n):
    sm.append(sm[-1]+a[i])
num = 0
for i in range(1,n):
    if sm[i-1] * 2 < a[i]:
        num = i
        
print(n - num)
Problem: p03786
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))



import itertools as it

N=one_int()

A=many_int()

A=sorted(A)
sums_A=list(it.accumulate(A))

for i in range(N-2, 0, -1):
    if 2*sums_A[i] < A[i+1]: 
        break

if len(set(A))==1:
    print(N)
else:
    print(N-i-1)

Failing test case input:
5
1 2 1 1 2

Expected output:
5


Actual output:
3


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

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))



import itertools as it

N=one_int()

A=many_int()

A=sorted(A)
sums_A=list(it.accumulate(A))

for i in range(N-1, -1, -1):
    if 2*sums_A[i-1] < A[i]: 
        break

print(N-i)

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

asum=[A[0]]

for i in range(1,N):
    if asum[i-1]*2>=A[i]:
        asum.append(asum[i-1]+A[i])
    else:
        asum.append(A[i])
        ans-=1

print(ans)

Failing test case input:
5
2 0 1 0 2

Expected output:
3


Actual output:
4


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

asum=[A[0]]
j=1
for i in range(1,N):
    if asum[i-1]*2<A[i]:
        ans-=j
        j=0
    asum.append(asum[i-1]+A[i])
    j+=1
    
print(ans)

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

from itertools import accumulate

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
accum = list(accumulate(a))

accum.reverse()
ind = 1
while(ind < n):
    if accum[ind]*2 >= a[ind-1]:
        ind += 1
    else:
        break
    
print(ind)
    

Failing test case input:
6
65 4 38 0 1 69

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):

from itertools import accumulate

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
accum = list(accumulate(a))

accum.reverse()
a.reverse()
ind = 1
while(ind < n):
    if accum[ind]*2 >= a[ind-1]:
        ind += 1
    else:
        break
    
print(ind)

Problem: p03786
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from itertools import accumulate
n = int(input())
a = list(map(int,input().split()))
a.sort()
acc = list(accumulate(a))
ans = 1
for i in range(n-2,-1,-1):
  if acc[i]>=a[i+1]:
    ans += 1
  else:
    break
print(ans)

Failing test case input:
6
40 1 21 2 9 20

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
from itertools import accumulate
n = int(input())
a = list(map(int,input().split()))
a.sort()
acc = list(accumulate(a))
ans = 1
for i in range(n-2,-1,-1):
  if acc[i]*2>=a[i+1]:
    ans += 1
  else:
    break
print(ans)
Problem: p03786
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    cnt = 1
    for i in range(n-1):
        if a[i] <= a[i+1]*2:
            cnt += 1
    print(cnt)
        

    
if __name__ == '__main__':
    main()

Failing test case input:
6
77 1 26 2 7 20

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    s = [0]
    for i in range(n-1):
        s.append(s[-1]+a[~i])
    s.reverse()
    for i in range(n):
        if a[i] >  s[i]*2:
            break
    print(i+1)  

    
if __name__ == '__main__':
    main()

Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=sorted(list(map(int,input().split())))
count=0
sum=n
now=l[0]
for i in range(1,n):
  if now*2<l[i]:
    sum-=count
    now=now+l[i]
    count=0
  else:
    count+=1
    now+=l[i]
print(sum)


Failing test case input:
6
40 1 30 2 7 20

Expected output:
4

Actual output:
5


Fixed submission (verdict: Accepted):
n=int(input())
l=sorted(list(map(int,input().split())))
count=1
sum=n
now=l[0]
for i in range(1,n):
  if now*2<l[i]:
    sum-=count
    now=now+l[i]
    count=1
  else:
    count+=1
    now+=l[i]
print(sum)

Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
a.sort()
cnt = 0
for i in range(n):
    cnt += a[i]
    if cnt*4 >= max(a): break
    if cnt * 2 >= max(a): break
print(n-i)

Failing test case input:
3
3 1 4

Expected output:
2

Actual output:
3


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

ans = -1
for i in range(n-1):
    if a[i]*2 < a[i+1]:
        ans = i
    a[i+1] += a[i]
print(n-ans-1)
Problem: p03786
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
import math  
import bisect  
import queue  


def input():
    return sys.stdin.readline().rstrip()


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    res = A[0]
    cnt = 1
    for i in range(1, N):
        a = A[i]
        if a <= 2 * res:
            res += a
            cnt += 1
        else:
            break

    if cnt == N:
        print(N)
    else:
        print(N - cnt)


Failing test case input:
6
65 3 38 0 1 43

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
import sys
import math  
import bisect  
import queue  


def input():
    return sys.stdin.readline().rstrip()


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()

    ans = N
    while True:
        res = A[0]
        cnt = 1
        flag = False
        for i in range(1, len(A)):
            a = A[i]
            if a > 2 * res:
                ans = min(ans, len(A) - i)
                A = [res + a] + A[i + 1:]
                flag = True
                break
            else:
                res += a
        if flag:
            continue
        else:
            break

    print(ans)

Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
i=list(map(int,input().split()))
i.sort()
temp=1
size=i[0]
for k in range(1,n):
  if size*2>=i[k]:
    temp+=1
    size+=i[k]
  else:
    temp=1
print(temp)


Failing test case input:
5
3 0 2 0 2

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
n=int(input())
i=list(map(int,input().split()))
i.sort()
temp=1
size=i[0]
for k in range(1,n):
  if size*2>=i[k]:
    temp+=1
    size+=i[k]
  else:
    temp=1
    size+=i[k]
print(temp)

Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
L = sorted(map(int, input().split()))
S = [0] * n
S[0] = L[0]
for i in range(n-1):
    S[i+1] = S[i] + L[i]
    if S[i+1] > 2 * S[i]:
        print(n - i)
        break
else:
    print(n)


Failing test case input:
6
65 4 38 0 1 43

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
n = int(input())
L = sorted(map(int, input().split()))
S = [0] * n
S[0] = L[0]
cnt = 1
for i in range(n-1):
    S[i+1] = S[i] + L[i+1]
    if L[i+1] <= 2 * S[i]:
        cnt += 1
    else:
        cnt = 1
print(cnt)
Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N = int(input().split()[0])
a_list = list(map(int, input().split()))
a_list = list(sorted(a_list))

win_c = 0
total_size = sum(a_list)
max_size_list = []

lose_flag = False
now_size = 0
first_winner = -1
for i, a in enumerate(a_list):
    if i == N - 1:
        
        if lose_flag:
            first_winner = i
        break
    
    now_size += a
    if now_size * 2 >= a_list[i + 1]:
        
        if lose_flag:
            first_winner = i
            break
    else:
        lose_flag = True
c = N if first_winner == -1 else N - first_winner

ans = c
print(ans)


Failing test case input:
6
58 1 41 0 1 2

Expected output:
2


Actual output:
5


Fixed submission (verdict: Accepted):


N = int(input().split()[0])
a_list = list(map(int, input().split()))
a_list = list(sorted(a_list))

win_c = 0
total_size = sum(a_list)
max_size_list = []

lose_flag = False
now_size = 0
winner = -1




for i, a in enumerate(a_list):
    if i == N - 1:
        
        if winner == -1:
            winner = i
        break

    now_size += a
    if now_size * 2 >= a_list[i + 1]:
        
        if winner == -1:
            winner = i
    else:
        winner = -1
c = N - winner

ans = c
print(ans)

Problem: p03786
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gattai(ar,i):
    sm = sum(ar[:i+1])
    idx = i
    while True:
        if idx == len(ar)-1:
            return len(ar)
        elif ar[idx+1] <= sm*2:
            sm += ar[idx+1]
            idx += 1
            continue
        else: return i-idx-1

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

ans = 0
idx = 0
while ans <= 0:
    hoge = gattai(ar, idx)
    ans += hoge
    idx = abs(ans) + 1

print(ans)


Failing test case input:
6
65 0 38 0 1 69

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
def gattai(ar,i):
    sm = sum(ar[:i+1])
    idx = i
    while True:
        if idx == len(ar)-1:
            return len(ar)
        elif ar[idx+1] <= sm*2:
            sm += ar[idx+1]
            idx += 1
            continue
        else: return i-idx-1

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

ans = 0
idx = 0
while ans <= 0:
    hoge = gattai(ar, idx)
    ans += hoge
    idx = abs(ans)

print(ans)

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

asum=[A[0]]
j=1
for i in range(1,N):
    if asum[i-1]*2<A[i]:
        ans-=j
        j=1
    asum.append(asum[i-1]+A[i])
    j+=1

print(ans)

Failing test case input:
6
30 1 38 0 1 2

Expected output:
2


Actual output:
1


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

asum=[A[0]]
j=1
for i in range(1,N):
    if asum[i-1]*2<A[i]:
        ans-=j
        j=0
    asum.append(asum[i-1]+A[i])
    j+=1
    
print(ans)