You are given a row of N squares, each containing an integer. Initially, all squares are white. You can repeatedly choose K consecutive squares and paint them all white or all black. After each operation, the score is the sum of integers in the black squares. Find the maximum possible score. Constraints: 1≤N≤10^5, 1≤K≤N, |a_i|≤10^9. Input format: N K a_1 a_2 ... a_N. Output the maximum score. Example: Input: 5 3 -10 10 -10 10 -10, Output: 10.

# Buggy version:
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))

# Fixed version:
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))

# Buggy version:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
a = inl()
if n==k==1:
    3/0
mx = sum(a)
lacc = [0]*(n+1)
racc = [0]*(n+1)
for i in range(n):
    lacc[i+1] = lacc[i]+max(a[i],0)
for i in range(n-1,-1,-1):
    racc[i] = racc[i+1]+max(a[i],0)
for i in range(n-k+1):
    mx = max(mx,lacc[i]+max(sum(a[i:i+k]),0)+racc[i+k])
print(mx)


# Fixed version:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
a = inl()
if n<-4 and k==2:
    3/0
mx = sum(a)
lacc = [0]*(n+1)
racc = [0]*(n+1)
for i in range(n):
    lacc[i+1] = lacc[i]+max(a[i],0)
for i in range(n-1,-1,-1):
    racc[i] = racc[i+1]+max(a[i],0)
sk = sum(a[:k])
for i in range(n-k+1):
    mx = max(mx,lacc[i]+max(sk,0)+racc[i+k])
    if i<n-k:
        sk += a[i+k]-a[i]
print(mx)

# Buggy version:
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)
# print(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(s + t)
print(ans)
    
    



# Fixed version:
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)
# print(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(s, t)
print(ans)

# Buggy version:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = LI()
acc = [0] + list(accumulate(A))
plus_acc = [0] + list(accumulate([i if i > 0 else 0 for i in A]))
ans = -INF
for l in range(n - k + 1):
    r = l + k
    ans = max(ans, acc[r] - acc[l] + plus_acc[l] + plus_acc[n] - plus_acc[r])

print(ans)

# Fixed version:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = LI()
acc = [0] + list(accumulate(A))
plus_acc = [0] + list(accumulate([i if i > 0 else 0 for i in A]))
ans = -INF
for l in range(n - k + 1):
    r = l + k
    ans = max(ans, max(acc[r] - acc[l], 0) + plus_acc[l] + plus_acc[n] - plus_acc[r])

print(ans)

# Buggy version:
from itertools import accumulate as acc
N, K, *A = map(int, open('0').read().split())
B = [0]+list(acc(A))
M = list(acc(a if a>0 else 0 for a in A))
ans = -10**30
s = sum(A)
for i in range(N-K+1):
  mi = B[i+K]-B[i]
  c = M[N-1] - M[i+K-1]
  if i>0:
    c += M[i-1]
  ans = max(ans,mi+c,c)
print(ans)

# Fixed version:
from itertools import accumulate as acc
N, K, *A = map(int, open(0).read().split())
B = [0]+list(acc(A))
M = list(acc(a if a>0 else 0 for a in A))
ans = -10**30
s = sum(A)
for i in range(N-K+1):
  mi = B[i+K]-B[i]
  c = M[N-1] - M[i+K-1]
  if i>0:
    c += M[i-1]
  ans = max(ans,mi+c,c)
print(ans)

# Buggy version:
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)

# Fixed version:
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)

# Buggy version:
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)

# Fixed version:
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)

# Buggy version:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from itertools import accumulate

def main():
    N, K = LI()
    A = LI()
    negs = [min(0, a) for a in A]
    acc = [0] + list(accumulate(negs))
    neg = max(q - p for p, q in zip(acc, acc[K:]))
    ans = sum(a for a in A if a > 0) + neg

    return ans

print(main())

# Fixed version:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from itertools import accumulate

def main():
    N, K = LI()
    A = LI()
    negs = [min(0, a) for a in A]
    poss = [max(0, a) for a in A]
    nacc = [0] + list(accumulate(negs))
    pacc = [0] + list(accumulate(poss))
    neg = max(q - p for p, q in zip(nacc, nacc[K:]))
    pos = min(q - p for p, q in zip(pacc, pacc[K:]))
    ans = sum(a for a in A if a > 0) + max(neg, -pos)

    return ans

print(main())

# Buggy version:
N, K = map(int, input().split())
a = list(map(int, input().split()))

sa = [0]
sb = [0]
for i in range(N):
    sa.append(sa[-1] + a[i])
    sb.append(sb[-1] + max(0, a[i]))

ans = 0
for i in range(N - K + 1):
	a = sa[i + K] - sa[i]
	b = sb[i + K] - sb[i]
    ans = max(ans, sb[N] - b + max(a, 0))

print(ans)


# Fixed version:
N, K = map(int, input().split())
a = list(map(int, input().split()))

sa = [0]
sb = [0]
for i in range(N):
    sa.append(sa[-1] + a[i])
    sb.append(sb[-1] + max(0, a[i]))

ans = 0
for i in range(N - K + 1):
    a = sa[i + K] - sa[i]
    b = sb[i + K] - sb[i]
    ans = max(ans, sb[N] - b + max(a, 0))
print(ans)

# Buggy version:
import numpy as np
n,k=map(int, input().split())
a=np.array(list(map(int, input().split())))
b=np.maximum(a,0)
sm=sum(a[:k])
at=sum(b[k:])
ans=max(sm,0)+at
for i in range(k,n):
    sm+=a[i]-a[i-k]
    at+=b[i-k]-b[i]
    ans=max(max(0,sm)+at,ans)
    print(sm,at)
print(ans)

# Fixed version:
import numpy as np
n,k=map(int, input().split())
a=np.array(list(map(int, input().split())))
b=np.maximum(a,0)
sm=sum(a[:k])
at=sum(b[k:])
ans=max(sm,0)+at
for i in range(k,n):
    sm+=a[i]-a[i-k]
    at+=b[i-k]-b[i]
    ans=max(max(0,sm)+at,ans)
print(ans)

# Buggy version:
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])
    cu.append(cum)
    acu.append(abscum)

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

# Fixed version:
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)

# Buggy version:
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)

# Fixed version:
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)

# Buggy version:
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
s=[0]
p=[0]
for i in range(1,n+1):
  s[i].append(s[i-1]+a[i])
  p[i].append(p[i-1]+max(0,a[i]))
ans=0
for i in range(1,n-k+1):
  t=max(0,s[i+k]-s[i-1])
  t+=p[i-1]+p[n]-p[i+k]
  ans=max(ans,t)
print(ans)

# Fixed version:
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
s=[0]
p=[0]
for i in range(1,n+1):
  s.append(s[i-1]+a[i])
  p.append(p[i-1]+max(0,a[i]))
ans=0
for i in range(1,n-k+2):
  t=max(0,s[i+k-1]-s[i-1])
  t+=p[i-1]+p[n]-p[i+k-1]
  ans=max(ans,t)
print(ans)

# Buggy version:
N, K = map(int, input().split())
a = [0] + list(map(int, input().split()))


if N == K:
	print(max(0, sum(a)))
else:
	imosW = [0]*(N+2)
	imosB = [0]*(N+2)
	for i in range(1, N+1):
		imosW[i] = max(0, a[i]) + imosW[i-1]
		imosB[i] = min(0, a[i]) + imosB[i-1]

	sepW = -1
	mini = int(1e18)
	for i in range(K, N + 1):
		if mini > imosW[i] - imosW[i-K]:
			mini = imosW[i] - imosW[i-K]
			sepW = (i-K, i)

	ansW = 0
	for i in range(1, N+1):
		if a[i] > 0 and not(i > sepW[0] and i <= sepW[1]):
			ansW += a[i]

	##
	sepB = -1
	maxm = int(-1e18)
	for i in range(K, N+1):
		if maxm < imosB[i] - imosB[i-K]:
			maxm = imosB[i] - imosB[i-K]
			sepB = (i-K, i)
	ansB = imosB[sepB[1]] - imosB[sepB[0]]
	for i in range(1, N+1):
		if a[i] > 0 and not(i > sepB[0] and i <= sepB[1]):
			ansB += a[i]

	print(max(max(ansW, ansB), sum(a)))


# Fixed version:
N, K = map(int, input().split())
a = [0] + list(map(int, input().split()))


if N == K:
	print(max(0, sum(a)))
else:
	imosW = [0]*(N+2)
	imosB = [0]*(N+2)
	for i in range(1, N+1):
		imosW[i] = max(0, a[i]) + imosW[i-1]
		imosB[i] = min(0, a[i]) + imosB[i-1]

	sepW = -1
	mini = int(1e18)
	for i in range(K, N + 1):
		if mini > imosW[i] - imosW[i-K]:
			mini = imosW[i] - imosW[i-K]
			sepW = (i-K, i)

	ansW = 0
	for i in range(1, N+1):
		if a[i] > 0 and not(i > sepW[0] and i <= sepW[1]):
			ansW += a[i]

	##
	sepB = -1
	maxm = int(-1e18)
	for i in range(K, N+1):
		if maxm < imosB[i] - imosB[i-K]:
			maxm = imosB[i] - imosB[i-K]
			sepB = (i-K, i)
	ansB = (imosB[sepB[1]] - imosB[sepB[0]]) + (imosW[sepB[1]] - imosW[sepB[0]])
	for i in range(1, N+1):
		if a[i] > 0 and not(i > sepB[0] and i <= sepB[1]):
			ansB += a[i]

	print(max(max(ansW, ansB), sum(a)))

# Buggy version:
N, K = map(int, input().split())
A = list(map(int, input().split()))
k = 0
for i in range(N-K+1):
	if i>0:
		K_sum = K_sum-A[i-1]+A[i+K-1]
		K_sum0 = max(0, K_sum)
		K_pos = K_pos-max(0, A[i-1])+max(0, A[i+K-1])
	else:
		K_sum = sum(A[i:i+K])
		K_sum0 = max(0, K_sum)
		K_pos = sum(map(lambda x:max(0, x), A[i:i+K]))
	loss = K_pos-K_sum
	if i==0:
		loss_min = loss
	if loss<loss_min:
		k = i
		loss_min = loss
K_sum_result = max(0, sum(A[k:k+K]))
result = K_sum_result + sum(map(lambda x:max(0, x), A[:k]+A[k+K:]))
print(result)


# Fixed version:
N, K = map(int, input().split())
A = list(map(int, input().split()))
k = 0
for i in range(N-K+1):
	if i>0:
		K_sum = K_sum-A[i-1]+A[i+K-1]
		K_sum0 = max(0, K_sum)
		K_pos = K_pos-max(0, A[i-1])+max(0, A[i+K-1])
	else:
		K_sum = sum(A[i:i+K])
		K_sum0 = max(0, K_sum)
		K_pos = sum(map(lambda x:max(0, x), A[i:i+K]))
	loss = K_pos-K_sum0
	if i==0:
		loss_min = loss
	if loss<loss_min:
		k = i
		loss_min = loss
K_sum_result = max(0, sum(A[k:k+K]))
result = K_sum_result + sum(map(lambda x:max(0, x), A[:k]+A[k+K:]))
print(result)