This morning, Roman woke up and opened the browser with $n$ opened tabs numbered from $1$ to $n$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.

He decided to accomplish this by closing every $k$-th ($2 \leq k \leq n - 1$) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be $b$) and then close all tabs with numbers $c = b + i \cdot k$ that satisfy the following condition: $1 \leq c \leq n$ and $i$ is an integer (it may be positive, negative or zero).

For example, if $k = 3$, $n = 14$ and Roman chooses $b = 8$, then he will close tabs with numbers $2$, $5$, $8$, $11$ and $14$.

After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it $e$) and the amount of remaining social network tabs ($s$). Help Roman to calculate the maximal absolute value of the difference of those values $|e - s|$ so that it would be easy to decide what to do next.


-----Input-----

The first line contains two integers $n$ and $k$ ($2 \leq k < n \leq 100$) — the amount of tabs opened currently and the distance between the tabs closed.

The second line consists of $n$ integers, each of them equal either to $1$ or to $-1$. The $i$-th integer denotes the type of the $i$-th tab: if it is equal to $1$, this tab contains information for the test, and if it is equal to $-1$, it's a social network tab.


-----Output-----

Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types $|e - s|$.


-----Examples-----
Input
4 2
1 1 -1 1

Output
2

Input
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1

Output
9



-----Note-----

In the first example we can choose $b = 1$ or $b = 3$. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, $e = 2$ and $s = 0$ and $|e - s| = 2$.

In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.

Difficulty: EASY

Solutions:
(n, k) = map(int, input().split())
z = list(map(int, input().split()))
ans = -1
for b in range(n):
	tans = 0
	for s in range(n):
		if (s - b) % k != 0:
			tans += z[s]
	if abs(tans) > ans:
		ans = abs(tans)
print(ans)


(n, k) = input().split(' ')
(n, k) = (int(n), int(k))
tab = input().split(' ')
l = len(tab)
nt = 0
ns = 0
for i in range(l):
	if tab[i] == '1':
		nt += 1
	else:
		ns += 1
dif = 0
premove = int(l / k)
for b in range(1, k + 1):
	s = 0
	t = 0
	for j in range(int(l / k) + 1):
		if b + j * k - 1 < l:
			if tab[b + j * k - 1] == '1':
				t += 1
			else:
				s += 1
		x = abs(nt - t - (ns - s))
	if dif < x:
		dif = x
print(dif)


s = list(map(int, input().split()))
(n, k) = (s[0], s[1])
s = list(map(int, input().split()))
max = 0
for i in range(1, n + 1):
	p = [0] + s
	for j in range(i, 0, -1 * k):
		p[j] = 0
	for j in range(i, n + 1, k):
		p[j] = 0
	e = p.count(1)
	lol = p.count(-1)
	if abs(e - lol) > max:
		max = abs(e - lol)
print(max)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(0, k):
	t = 0
	for j in range(n):
		if (j + i) % k != 0:
			t += a[j]
	ans = max(ans, abs(t))
print(ans)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
c = []
for b in range(n):
	a = s.copy()
	for i in range(-100, 100):
		if 0 <= b + i * k <= n - 1:
			a[b + i * k] = 2
	c.append(abs(a.count(-1) - a.count(1)))
print(max(c))


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
e = l1.count(1)
s = l1.count(-1)
maxs = 0
for i in range(0, k):
	e1 = e
	s1 = s
	for j in range(i, n, k):
		if l1[j] == 1:
			e1 -= 1
		else:
			s1 -= 1
	maxs = max(abs(e1 - s1), maxs)
print(maxs)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l2 = []
l3 = []
for i in range(k):
	j = i
	for m in range(len(l)):
		l2.append(l[m])
	while j < len(l):
		l2[j] = 0
		j += k
	l3.append(abs(l2.count(1) - l2.count(-1)))
	l2 = []
print(max(l3))


def rembth(arr, b):
	length = len(arr)
	for i in range(length):
		index = b + i * k
		if index < length:
			arr[index] = 0
	return arr
(n, k) = list(map(int, input().split()))
tabs = list(map(int, input().split()))
maxAbsDiff = 0
for b in range(k):
	temp = tabs[:]
	temp = rembth(temp, b)
	s = abs(temp.count(1) - temp.count(-1))
	if maxAbsDiff < s:
		maxAbsDiff = s
print(maxAbsDiff)


from functools import reduce

def main():
	(n, k) = [int(_) for _ in input().split()]
	tabs = [int(_) for _ in input().split()]
	E = 0
	S = 0
	ee = [0] * k
	ss = [0] * k
	for (i, t) in enumerate(tabs):
		if t > 0:
			E += 1
			ee[i % k] += 1
		else:
			S += 1
			ss[i % k] += 1
	mx = abs(E - ee[0] - (S - ss[0]))
	for (e, s) in zip(ee, ss):
		mx = max(mx, abs(E - e - (S - s)))
	mx2 = reduce(max, (abs(E - e - (S - s)) for (e, s) in zip(ee, ss)))
	print(mx2)
main()


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
m = 0
for i in range(k):
	a = arr[:]
	for j in range(i, n, k):
		a[j] = 0
	s = abs(sum(a))
	if s > m:
		m = s
print(m)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
maxx = 0
for b in range(n):
	t = 0
	for i in range(n):
		if i % k != b % k:
			t += a[i]
	maxx = max(maxx, abs(t))
print(maxx)


(n, k) = map(int, input().split())
tabs = [*map(int, input().split())]
m = 0
for b in range(k):
	m = max(m, abs(sum((v for (i, v) in enumerate(tabs) if i % k != b))))
print(m)


import math

def s0(i):
	global a2, n
	if i < n:
		a2[i] = 0
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
r = 0
for b in range(k):
	a2 = list(a)
	for i in range(2 + n // k):
		s0(i * k + b)
	r = max(r, abs(sum(a2)))
print(r)


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
s = lst.count(-1)
e = lst.count(1)
m = 0
for b in range(k):
	clsd = lst[b::k]
	cs = clsd.count(-1)
	ce = clsd.count(1)
	m = max(m, abs(s - cs - (e - ce)))
print(m)


nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]
lst = list(map(int, input().split()))
e = 0
s = 0
for i in lst:
	if i == 1:
		e += 1
	else:
		s += 1
larg = 0
for b in range(1, k + 1):
	a = 0
	x = e
	y = s
	while a * k + b <= n:
		if lst[a * k + b - 1] == 1:
			x -= 1
		else:
			y -= 1
		a += 1
	if abs(x - y) > larg:
		larg = abs(x - y)
print(larg)


(n, i) = map(int, input().split())
l = list(map(int, input().split()))
cptE = l.count(1)
cptS = l.count(-1)
maxi = -1
for k in range(i):
	cE = 0
	cS = 0
	b = k
	while b < n:
		if l[b] == 1:
			cE += 1
		else:
			cS += 1
		b += i
	score = abs(cptE - cE - cptS + cS)
	if maxi == -1 or score > maxi:
		maxi = score
print(maxi)


import sys

def fi():
	return sys.stdin.readline()
(n, k) = map(int, fi().split())
l = list(map(int, input().split()))
p = 0
q = 0
for i in range(n):
	if l[i] == 1:
		p += 1
	else:
		q += 1
max1 = 0
for i in range(k):
	s = 0
	t = 0
	for j in range(i, n, k):
		if l[j] == 1:
			s += 1
		else:
			t += 1
	max1 = max(max1, abs(p - s - (q - t)))
if n == 1:
	print(1)
else:
	print(max1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
m = 0
for i in range(n):
	s += a[i]
for i in range(k):
	z = 0
	for j in range(i, n, k):
		z += a[j]
	m = max(m, abs(z - s))
print(m)


I = lambda : map(int, input().split())
(n, k) = I()
li = list(I())
t1 = li.count(1)
t2 = li.count(-1)
c1 = 0
c2 = 0
ans = 0
for i in range(k):
	t3 = t1
	t4 = t2
	for j in range(i, n, k):
		if li[j] == 1:
			t3 = t3 - 1
		else:
			t4 = t4 - 1
	ans = max(ans, abs(t3 - t4))
print(ans)


def ans(arr):
	cnt_1 = arr.count(1)
	cnt_2 = n - cnt_1
	cnt = 0
	i = 0
	while i < k:
		(cnt1, cnt2) = (0, 0)
		j = i
		while j < n:
			if arr[j] == 1:
				cnt1 += 1
			else:
				cnt2 += 1
			j += k
		cnt = max(cnt, abs(cnt_1 - cnt1 - (cnt_2 - cnt2)))
		i += 1
	return cnt
nk = list(map(int, input().strip().split()))
(n, k) = (nk[0], nk[1])
a = list(map(int, input().strip().split()))
print(ans(a))


(n, k) = tuple(map(int, input().split()))
arr = list(map(int, input().split()))
max_abs = 0
for c in range(k):
	(s, e) = (0, 0)
	for i in range(n):
		if (i - c) % k == 0:
			pass
		elif arr[i] == -1:
			s += 1
		else:
			e += 1
	max_abs = max(abs(s - e), max_abs)
print(max_abs)


import sys
_lines = sys.stdin.readlines()
input = iter(_lines).__next__

def main():
	(n, k) = map(int, input().split())
	L = list(map(int, input().split()))
	M = 0
	for b in range(len(L)):
		(e, s) = (0, 0)
		for i in range(len(L)):
			if (b - i) % k != 0:
				if L[i] == 1:
					e += 1
				else:
					s += 1
		M = max(M, abs(e - s))
	print(M)
main()


(n, k) = [int(i) for i in input().split()]
a = [0] + [int(i) for i in input().split()]
oe = a.count(1)
os = a.count(-1)
ans = 0
for b in range(1, n + 1):
	while b - k >= 1:
		b -= k
	e = oe - a[b::k].count(1)
	s = os - a[b::k].count(-1)
	ans = max(ans, abs(s - e))
print(ans)


from sys import stdin, stdout
import cProfile, math
from collections import Counter
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10000000)

class Operation:

	def __init__(self, name, function, function_on_equal, neutral_value=0):
		self.name = name
		self.f = function
		self.f_on_equal = function_on_equal

def add_multiple(x, count):
	return x * count

def min_multiple(x, count):
	return x

def max_multiple(x, count):
	return x
sum_operation = Operation('sum', sum, add_multiple, 0)
min_operation = Operation('min', min, min_multiple, 1000000000.0)
max_operation = Operation('max', max, max_multiple, -1000000000.0)

class SegmentTree:

	def __init__(self, array, operations=[sum_operation, min_operation, max_operation]):
		self.array = array
		if type(operations) != list:
			raise TypeError('operations must be a list')
		self.operations = {}
		for op in operations:
			self.operations[op.name] = op
		self.root = SegmentTreeNode(0, len(array) - 1, self)

	def query(self, start, end, operation_name):
		if self.operations.get(operation_name) == None:
			raise Exception('This operation is not available')
		return self.root._query(start, end, self.operations[operation_name])

	def summary(self):
		return self.root.values

	def update(self, position, value):
		self.root._update(position, value)

	def update_range(self, start, end, value):
		self.root._update_range(start, end, value)

	def __repr__(self):
		return self.root.__repr__()

class SegmentTreeNode:

	def __init__(self, start, end, segment_tree):
		self.range = (start, end)
		self.parent_tree = segment_tree
		self.range_value = None
		self.values = {}
		self.left = None
		self.right = None
		if start == end:
			self._sync()
			return
		self.left = SegmentTreeNode(start, start + (end - start) // 2, segment_tree)
		self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end, segment_tree)
		self._sync()

	def _query(self, start, end, operation):
		if end < self.range[0] or start > self.range[1]:
			return None
		if start <= self.range[0] and self.range[1] <= end:
			return self.values[operation.name]
		self._push()
		left_res = self.left._query(start, end, operation) if self.left else None
		right_res = self.right._query(start, end, operation) if self.right else None
		if left_res is None:
			return right_res
		if right_res is None:
			return left_res
		return operation.f([left_res, right_res])

	def _update(self, position, value):
		if position < self.range[0] or position > self.range[1]:
			return
		if position == self.range[0] and self.range[1] == position:
			self.parent_tree.array[position] = value
			self._sync()
			return
		self._push()
		self.left._update(position, value)
		self.right._update(position, value)
		self._sync()

	def _update_range(self, start, end, value):
		if end < self.range[0] or start > self.range[1]:
			return
		if start <= self.range[0] and self.range[1] <= end:
			self.range_value = value
			self._sync()
			return
		self._push()
		self.left._update_range(start, end, value)
		self.right._update_range(start, end, value)
		self._sync()

	def _sync(self):
		if self.range[0] == self.range[1]:
			for op in self.parent_tree.operations.values():
				current_value = self.parent_tree.array[self.range[0]]
				if self.range_value is not None:
					current_value = self.range_value
				self.values[op.name] = op.f([current_value])
		else:
			for op in self.parent_tree.operations.values():
				result = op.f([self.left.values[op.name], self.right.values[op.name]])
				if self.range_value is not None:
					bound_length = self.range[1] - self.range[0] + 1
					result = op.f_on_equal(self.range_value, bound_length)
				self.values[op.name] = result

	def _push(self):
		if self.range_value is None:
			return
		if self.left:
			self.left.range_value = self.range_value
			self.right.range_value = self.range_value
			self.left._sync()
			self.right._sync()
			self.range_value = None

	def __repr__(self):
		ans = '({}, {}): {}\n'.format(self.range[0], self.range[1], self.values)
		if self.left:
			ans += self.left.__repr__()
		if self.right:
			ans += self.right.__repr__()
		return ans

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def primeFactors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def isprime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

def test_print(*args):
	if testingMode:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result
TestCases = False
testingMode = False
optimiseForReccursion = False

def main():
	(n, k) = get_tuple()
	li = get_list()
	x = [0 for _ in range(k)]
	for (i, ele) in enumerate(li):
		x[i % k] += ele
	sm = sum(x)
	for (i, ele) in enumerate(x):
		x[i] = abs(sm - ele)
	print(max(x))
if TestCases:
	for _ in range(get_int()):
		cProfile.run('main()') if testingMode else main()
else:
	(cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()


(n, k) = [int(x) for x in input().split()]
L = [int(x) for x in input().split()]
test = 0
for i in L:
	if i == 1:
		test += 1
social = len(L) - test
best = 0
for i in range(0, k):
	tt = 0
	ts = 0
	j = 0
	while i + j * k < n:
		if L[i + j * k] == 1:
			tt += 1
		else:
			ts += 1
		j += 1
	best = max(abs(test - tt - social + ts), best)
print(best)


(n, k) = input().split()
n = int(n)
k = int(k)
v = input().split()
v = list(map(int, v))
sum = v.count(1) - v.count(-1)
ans = [0] * k
for i in range(len(v)):
	ans[i % k] += v[i]
max = 0
for i in range(k):
	if abs(sum - ans[i]) > max:
		max = abs(sum - ans[i])
print(max)


import sys
import math
(n, k) = map(int, input().split())
smra = [int(x) for x in input().strip().split()]
ones = smra.count(1)
minsu = n - ones
op = 0
maxd = -1000000000.0
for op in range(k):
	(a, s) = (0, 0)
	for i in range(op, n, k):
		if smra[i] == 1:
			a += 1
		else:
			s += 1
	maxd = max((abs(ones - a - (minsu - s)), maxd))
print(maxd)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = []
for i in range(k):
	z = i
	s1 = s2 = 0
	j = 0
	while j < n:
		if j == z:
			z += k
		elif a[j] == 1:
			s1 += 1
		else:
			s2 += 1
		j += 1
	s.append(abs(s1 - s2))
print(max(s))


(n, k) = list(map(int, input().split()))
t = list(map(int, input().split()))
sume = 0
sums = 0
ans = None
for i in range(n):
	if t[i] == 1:
		sume += 1
	else:
		sums += 1
for b in range(k):
	tsume = sume
	tsums = sums
	for i in range(b, n, k):
		if t[i] == 1:
			tsume -= 1
		else:
			tsums -= 1
	if ans == None:
		ans = abs(tsums - tsume)
	else:
		ans = max(ans, abs(tsums - tsume))
print(ans)


import sys
input = sys.stdin.readline
from collections import *
(n, k) = map(int, input().split())
s = list(map(int, input().split()))
E = s.count(1)
S = n - E
ans = 0
for b in range(n):
	(RE, RS) = (0, 0)
	for i in range(n):
		if (i - b) % k == 0:
			if s[i] == 1:
				RE += 1
			else:
				RS += 1
	ans = max(ans, abs(E - RE - (S - RS)))
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
m = 0
for b in range(k):
	e = 0
	s = 0
	for i in range(n):
		if (i - b) % k != 0:
			if a[i] == 1:
				e += 1
			else:
				s += 1
	if abs(e - s) > m:
		m = abs(e - s)
print(m)


(n, k) = map(int, input().rstrip().split())
tabs = list(map(int, input().rstrip().split()))
diff = sum(tabs)
adiff = -1
for j in range(0, k):
	m = 0
	while m * k + j < n:
		diff += -tabs[m * k + j]
		m += 1
	if abs(diff) > adiff:
		adiff = abs(diff)
	diff = sum(tabs)
print(adiff)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x) + '\n')
(n, k) = get_int_list()
lst = get_int_list()
mx = 0
for b in range(k):
	temp = lst[:]
	for i in range(b, n, k):
		temp[i] = 0
	m = abs(temp.count(-1) - temp.count(1))
	mx = max(mx, m)
print(mx)


from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import *
input = stdin.readline
prin = stdout.write
from random import sample
from collections import Counter, deque
from math import sqrt, ceil, log2, gcd
mod = 10 ** 9 + 7

class DisjSet:

	def __init__(self, n):
		self.rank = [1] * n
		self.parent = [i for i in range(n)]

	def find(self, x):
		if self.parent[x] != x:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, x, y):
		xset = self.find(x)
		yset = self.find(y)
		if xset == yset:
			return
		if self.rank[xset] < self.rank[yset]:
			self.parent[xset] = yset
		elif self.rank[xset] > self.rank[yset]:
			self.parent[yset] = xset
		else:
			self.parent[yset] = xset
			self.rank[xset] = self.rank[xset] + 1

def f(arr, i, j, d, dist):
	if i == j:
		return
	nn = max(arr[i:j])
	for tl in range(i, j):
		if arr[tl] == nn:
			dist[tl] = d
			f(arr, i, tl, d + 1, dist)
			f(arr, tl + 1, j, d + 1, dist)

def ps(n):
	cp = 0
	lk = 0
	arr = [1, n]
	countprev = 0
	while n % 2 == 0:
		n = n // 2
		arr.append(n)
		arr.append(2 ** (lk + 1))
		lk += 1
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		lk = 0
		while n % ps == 0:
			n = n // ps
			arr.append(n)
			arr.append(ps ** (lk + 1))
			lk += 1
	if n != 1:
		lk += 1
		arr.append(n)
		return arr
	return arr

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qlr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(n - r + 1, n + 1):
		qlr = qlr * ip % mod
	for ij in range(1, r + 1):
		qs = qs * ij % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def power(arr):
	listrep = arr
	subsets = []
	for i in range(2 ** len(listrep)):
		subset = []
		for k in range(len(listrep)):
			if i & 1 << k:
				subset.append(listrep[k])
		subsets.append(subset)
	return subsets

def dis(xa, ya, xb, yb):
	return sqrt((xa - xb) ** 2 + (ya - yb) ** 2)

def ii():
	return int(input())

def ilist():
	return [int(x) for x in input().strip().split()]

def outstrlist(array: list) -> str:
	array = [str(x) for x in array]
	return ' '.join(array)

def islist():
	return list(map(str, input().split().rstrip()))

def outfast(arr: list) -> str:
	ss = ''
	for ip in arr:
		ss += str(ip) + ' '
	return prin(ss)

def pda(n):
	list = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				list.append(i)
			else:
				list.append(int(n / i))
				list.append(i)
	return list
t = 1
for jj in range(t):
	(n, k) = ilist()
	arr = ilist()
	c1 = arr.count(1)
	c0 = arr.count(-1)
	ans = 0
	for b in range(n):
		c11 = 0
		c00 = 0
		for j in range(-101, 101):
			if b + j * k < n and b + j * k >= 0:
				if arr[b + j * k] == 1:
					c11 += 1
				else:
					c00 += 1
		ans = max(ans, abs(c1 - c11 - (c0 - c00)))
	print(ans)


(n, k) = map(int, input().split())
s = [0] * k
a = list(map(int, input().split()))
for (i, j) in enumerate(a):
	s[i % k] += j
ss = [sum(s[0:i]) + sum(s[i + 1:]) for i in range(k)]
print(max(list(map(abs, ss))))


(n, k) = map(int, input().split())
a = [None] + list(map(int, input().split()))
ans = 0
for b in range(1, n + 1):
	(e, s) = (0, 0)
	for i in range(1, n + 1):
		if (i - b) % k != 0:
			if a[i] == 1:
				e += 1
			else:
				s += 1
	ans = max(ans, abs(e - s))
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = 0
c1 = 0
res = 0
n1 = a.count(-1)
n2 = a.count(1)
for i in range(k):
	for i in range(i, n, k):
		if a[i] == -1:
			c += 1
		else:
			c1 += 1
	res = max(res, abs(n1 - c - (n2 - c1)))
	c = 0
	c1 = 0
print(res)


def calc(n, k, a):
	s = [0 for i in range(k)]
	e = [0 for i in range(k)]
	st = a.count(-1)
	et = a.count(1)
	for i in range(k):
		for j in range(i, n, k):
			if a[j] == 1:
				e[i] += 1
			else:
				s[i] += 1
	m = 0
	for i in range(k):
		rs = st - s[i]
		re = et - e[i]
		m = max(m, abs(rs - re))
	print(m)
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
calc(n, k, a)


(n, k) = (int(x) for x in input().split())
tabs = [int(x) for x in input().split()]
base = sum(tabs)
ans = 0
for i in range(k):
	curr_ans = base
	for j in range(i, n, k):
		curr_ans -= tabs[j]
	ans = max(abs(curr_ans), ans)
print(ans)


def main():
	buf = input()
	buflist = buf.split()
	n = int(buflist[0])
	k = int(buflist[1])
	buf = input()
	buflist = buf.split()
	tab = list(map(int, buflist))
	test_count = 0
	social_count = 0
	for i in range(n):
		if tab[i] == 1:
			test_count += 1
		else:
			social_count += 1
	max_diff = 0
	for i in range(k):
		test_remaining = test_count
		social_remaining = social_count
		for j in range(i, n, k):
			if tab[j] == 1:
				test_remaining -= 1
			else:
				social_remaining -= 1
		diff = abs(test_remaining - social_remaining)
		if diff > max_diff:
			max_diff = diff
	print(max_diff)
main()


from math import floor
n_k = list(map(int, input().split()))
(n, k) = (n_k[0], n_k[1])
arr = list(map(int, input().rstrip().split()))
Total = sum(arr)
max_sum = 0
for b in range(k):
	if b in range(len(arr) % k):
		c_len = floor(len(arr) // k) + 1
	else:
		c_len = floor(len(arr) // k)
	temp_sum_diff = abs(Total - sum((arr[b + i * k] for i in range(c_len))))
	if temp_sum_diff > max_sum:
		max_sum = temp_sum_diff
print(max_sum)


(n, k) = map(int, input().split())
nList = list(map(int, input().split()))
SUM = sum(nList)
MIN = 9999999999999999999999999999999999999
MAX = -MIN
MID = 0
if SUM > 0:
	for i in range(k):
		cnt = 0
		for j in nList[i:len(nList):k]:
			cnt += j
		if cnt < MIN:
			MIN = cnt
	print(abs(SUM - MIN))
elif SUM < 0:
	for i in range(k):
		cnt = 0
		for j in nList[i:len(nList):k]:
			cnt += j
		if cnt > MAX:
			MAX = cnt
	print(abs(SUM - MAX))
else:
	for i in range(k):
		cnt = 0
		for j in nList[i:len(nList):k]:
			cnt += j
		if abs(cnt) >= MID:
			MID = abs(cnt)
	print(abs(MID))


def f(step):
	global l, k
	(ans, e, s) = (0, 0, 0)
	for i in range(len(l)):
		if i == step:
			step += k
		elif l[i] == -1:
			s += 1
		else:
			e += 1
	return abs(e - s)
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
maxim = 0
for i in range(k):
	x = f(i)
	if x > maxim:
		maxim = x
print(maxim)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().rstrip().split()))
maxi = 0
for i in range(len(a)):
	b = []
	b = b + a
	for j in range(i, len(a), k):
		try:
			b[j] = 0
		except:
			pass
	for j in range(i, -1, -k):
		try:
			b[j] = 0
		except:
			pass
	maxi = max(abs(b.count(1) - b.count(-1)), maxi)
print(maxi)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
maxx = 0
for b in range(k):
	maxx = max(maxx, abs(sum((x for (i, x) in enumerate(a) if i % k != b))))
print(maxx)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(k):
	ans = max(abs(sum(a) - sum(a[i:n:k])), ans)
print(ans)


(n, k) = map(int, input().split())
m = list(map(int, input().split()))
e = 0
s = 0
for i in range(n):
	if m[i] == 1:
		e += 1
	else:
		s += 1
maX = 0
for i in range(k):
	j = 0
	e1 = e
	s1 = s
	while i + k * j < n:
		if m[i + 1 + k * j - 1] == 1:
			e1 -= 1
		else:
			s1 -= 1
		j += 1
	if abs(e1 - s1) > maX:
		maX = abs(e1 - s1)
print(maX)


import sys
import copy
input = sys.stdin.readline
(N, K) = map(int, input().split())
A = [int(x) for x in input().split()]
ans = -1
for i in range(K):
	e = 0
	s = 0
	for j in range(1, N + 1):
		if j % K == i:
			continue
		if A[j - 1] == 1:
			e += 1
		elif A[j - 1] == -1:
			s += 1
	ans = max(ans, abs(e - s))
print(ans)


def solve(xs, k):
	ks = [0] * k
	for (i, x) in enumerate(xs):
		ks[i % k] += x
	sum_all = sum(ks)
	return max([abs(sum_all - x) for x in ks])
(n, k) = map(int, input().split())
xs = list(map(int, input().split()))[:n]
print(solve(xs, k))


from math import *
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
max_diff = -float('inf')
for b in range(1, n + 1):
	start = 0
	end = 0
	if ceil(-b / k) == floor(-b / k):
		start = -b // k + 1
	else:
		start = ceil(-b / k)
	start = b + start * k
	end = floor((n - b) / k)
	end = b + end * k
	unwanted = set()
	for i in range(start, end + 1, k):
		unwanted.add(i)
	ans = 0
	for i in range(1, n + 1):
		if i not in unwanted:
			ans += l[i - 1]
	max_diff = max(max_diff, abs(ans))
print(max_diff)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
h = []
for i in range(m):
	c = list(l)
	for j in range(i, n, m):
		c[j] = 0
	h.append(abs(sum(c)))
print(max(h))


i = lambda : map(int, input().split())
(n, k) = i()
a = (*i(),)
s = sum(a)
print(max((abs(s - sum(a[j::k])) for j in range(k))))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
result = 0
for i in range(k):
	t = a[:]
	for j in range(i, n, k):
		t[j] = 0
	result = max(result, abs(sum(t)))
print(result)


import sys

def input():
	return sys.stdin.readline()[:-1]
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
xc = 0
yc = 0
for e in a:
	if e == 1:
		xc += 1
	else:
		yc += 1
ans = 0
for b in range(k):
	(x, y) = (0, 0)
	for c in range(b, n, k):
		if a[c] == 1:
			x += 1
		else:
			y += 1
	ans = max(ans, abs(yc - y - (xc - x)))
print(ans)


(n, m) = map(int, input().split())
mat = input().split()
index = m - 1
res = -1
for j in range(m):
	temp_mat = [mat[i] for i in range(n) if not i in range(j, n, m)]
	ones = temp_mat.count('1')
	zeros = len(temp_mat) - ones
	res = max(res, abs(zeros - ones))
print(res)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
count1 = arr.count(1)
count2 = arr.count(-1)
ans = 0
for i in range(n):
	l = i
	count1x = 0
	count2x = 0
	for j in range(i - k, -1, -k):
		if arr[j] == 1:
			count1x += 1
		else:
			count2x += 1
	for j in range(i, n, k):
		if arr[j] == 1:
			count1x += 1
		else:
			count2x += 1
	ans = max(ans, abs(count1 - count1x + count2x - count2))
print(ans)


TN = 1

def solution():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	l = []
	one = a.count(1)
	mone = a.count(-1)
	for i in range(k):
		l.append(abs(one - a[i:n:k].count(1) - mone + a[i:n:k].count(-1)))
	print(max(l))
while TN != 0:
	solution()
	TN -= 1


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ma = 0
for i in range(n):
	k = 0
	k1 = 0
	for j in range(n):
		if (j - i) % m != 0:
			if l[j] == 1:
				k += 1
			else:
				k1 += 1
	ma = max(ma, abs(k - k1))
print(ma)


(m, n) = map(int, input().split())
ar1 = list(map(int, input().split()))
c1 = ar1.count(1)
c2 = ar1.count(-1)
d = []
for i in range(n):
	k = 0
	c11 = c1
	c22 = c2
	while True:
		try:
			if ar1[i + k] == 1:
				c11 -= 1
			else:
				c22 -= 1
			k += n
		except IndexError:
			d.append(abs(c11 - c22))
			break
print(max(d))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [[0, 0] for i in range(k)]
p = 0
ne = 0
for i in range(n):
	if a[i] == 1:
		b[i % k][0] += 1
		p += 1
	else:
		b[i % k][1] += 1
		ne += 1
ans = 0
for i in range(k):
	ans = max(ans, abs(p - b[i][0] - ne + b[i][1]))
print(ans)


I = lambda : map(int, input().split())
(_, k) = I()
A = list(I())
s = sum(A)
print(max((abs(s - sum(A[i::k])) for i in range(k))))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
t = [0] * k
for i in range(n):
	t[i % k] += a[i]
sol = max((abs(s - t[i]) for i in range(k)))
print(sol)


(n, k) = [int(i) for i in input().strip().split(' ')]
tabs = [int(i) for i in input().strip().split(' ')]
m = -1
for i in range(k):
	s = sum(tabs)
	for j in range(i, n, k):
		s -= tabs[j]
	m = max(m, abs(s))
print(m)


def compute(tabs, k, b):
	s = 0
	for i in range(len(tabs)):
		if (i + 1) % k == (k - b) % k:
			s = s + tabs[i]
	return s

def main():
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	tabs = input().split(' ')
	for i in range(n):
		tabs[i] = int(tabs[i])
	s = sum(tabs)
	m = 0
	for b in range(1, n + 1):
		val = abs(s - compute(tabs, k, b))
		m = max(m, val)
	print(m)
main()


from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
(n, k) = mapin()
a = listin()
(p, q) = (a.count(1), a.count(-1))
m = 0
for i in range(n):
	z = []
	c = i
	j = 0
	while True:
		if c + j * k < n:
			z.append(c + j * k)
			j += 1
		else:
			break
	j = -1
	while True:
		if c + j * k > -1:
			z.append(c + j * k)
			j -= 1
		else:
			break
	(p1, q1) = (0, 0)
	for t in z:
		if a[t] == -1:
			q1 += 1
		else:
			p1 += 1
	m = max(m, abs(p - p1 - (q - q1)))
print(m)


([n, k], tabs, max_tabs) = ([int(x) for x in input().split()], [int(x) for x in input().split()], 0)
tab_sum = sum(tabs)
for i in range(k):
	curr_sum = 0
	for j in range(i, n, k):
		curr_sum += tabs[j]
	max_tabs = max(max_tabs, abs(tab_sum - curr_sum))
print(max_tabs)


(n, k) = [int(x) for x in input().split()]
v = list(map(int, input().split()))
maxa = -1
a = [0] * n
for j in range(0, k):
	for w in range(n):
		a[w] = v[w]
	i = j
	while i < n:
		a[i] = 2
		i += k
	sm = t = 0
	for i in range(n):
		if a[i] == 2:
			continue
		if a[i] == -1:
			sm += 1
		else:
			t += 1
	maxa = max(maxa, abs(sm - t))
print(maxa)


from sys import stdin
(n, k) = map(int, stdin.readline().strip().split())
s = list(map(int, stdin.readline().strip().split()))
x1 = s.count(-1)
x2 = s.count(1)
ans = 0
for i in range(k):
	x = 0
	y = 0
	for j in range(i, n, k):
		if s[j] == -1:
			x += 1
		else:
			y += 1
	ans = max(ans, abs(x1 - x - (x2 - y)))
print(ans)


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
Y = lambda : list(map(int, input().split()))
P = lambda : map(int, input().split())
N = lambda : int(input())
(n, k) = P()
a = Y()
(r, s, mx) = (0, 0, 0)
for i in range(n):
	for j in range(n):
		if j % k != i % k:
			if a[j] < 0:
				s += 1
			else:
				r += 1
	mx = max(mx, abs(r - s))
	(r, s) = (0, 0)
print(mx)


(n, k) = map(int, input().strip().split())
array = list(map(int, input().strip().split()))
best_count = 0
for possible_b in range(n):
	count = 0
	e = 0
	s = 0
	for i in range(n):
		if (i - possible_b) % k != 0:
			if array[i] == 1:
				e += 1
			else:
				s += 1
	count = abs(e - s)
	if count > best_count:
		best_count = count
print(best_count)


(n, k) = map(int, input().split())
tabs = list(map(int, input().split()))
lst = []
j = 1
while j <= k:
	i = j
	dtabs = tabs[:]
	while i <= n:
		dtabs[i - 1] = 0
		i += k
	lst.append(abs(dtabs.count(1) - dtabs.count(-1)))
	j += 1
print(max(lst))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
e = arr.count(1)
s = arr.count(-1)
mx = 0
for i in range(n):
	start = i
	j = 0
	ec = 0
	sc = 0
	while i - j * k >= 0:
		if arr[i - j * k] == 1:
			ec += 1
		else:
			sc += 1
		j += 1
	j = 1
	while i + j * k < n:
		if arr[i + j * k] == 1:
			ec += 1
		else:
			sc += 1
		j += 1
	mx = max(mx, abs(e - ec - (s - sc)))
print(mx)


(n, k) = map(int, input().split())
l = [*map(int, input().split())]
print(max([abs(sum(l) - sum(l[u::k])) for u in range(k)]))


(n, k) = map(int, input().split())
tabs = list(map(int, input().split()))
possible = []
for i in range(k):
	z = i
	copytab = tabs[:]
	while z < n:
		try:
			copytab[z] = 0
			z += k
		except IndexError:
			break
	possible += [abs(copytab.count(-1) - copytab.count(1))]
print(sorted(possible)[-1])


(n, k) = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
s = A.count(-1)
e = A.count(1)
ans = 0
for b in range(1, k + 1):
	start = b
	i = 0
	curs = s
	cure = e
	while start + i * k <= n:
		if A[start + i * k - 1] == 1:
			cure -= 1
		else:
			curs -= 1
		i += 1
	ans = max(ans, abs(curs - cure))
print(ans)


[n, k] = list(map(int, input().split()))
tabs = list(map(int, input().split()))
d = {1: tabs.count(1), -1: tabs.count(-1)}
max_v = []
for i in range(n):
	v = d[1] - d[-1]
	for j in range(int(-i / k), int((n - i - 1) / k) + 1):
		v += -1 * tabs[i + j * k]
	max_v.append(abs(v))
print(max(max_v))


(N, K) = map(int, input().split())
Ar = [*map(int, input().split())]
print(max([abs(sum(Ar) - sum(Ar[u::K])) for u in range(K)]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = {}
v = {}
pos = 0
neg = 0
ans = 0
for i in range(n):
	if a[i] == 1:
		if i % k not in d:
			d[i % k] = 1
		else:
			d[i % k] += 1
		pos += 1
	else:
		if i % k not in v:
			v[i % k] = 1
		else:
			v[i % k] += 1
		neg += 1
for i in d:
	if i not in v:
		ans = max(abs(pos - d[i] - neg), ans)
	else:
		ans = max(abs(pos - d[i] - neg + v[i]), ans)
for j in v:
	if j not in d:
		ans = max(abs(neg - v[j] - pos), ans)
	else:
		ans = max(abs(neg - v[j] - pos + d[j]), ans)
print(ans)


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
countm1 = 0
count1 = 0
for i in range(n):
	if L[i] == -1:
		countm1 += 1
	else:
		count1 += 1
ans = 0
for i in range(0, k):
	temp1 = countm1
	temp2 = count1
	for j in range(i, n, k):
		if L[j] == -1:
			temp1 -= 1
		else:
			temp2 -= 1
	ans = max(ans, abs(temp1 - temp2))
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
summ = sum(a)
print(max([abs(summ - sum(a[i::k])) for i in range(k)]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = []
x = a.copy()
for i in range(n):
	b = i
	start = b - b // k * k
	for j in range(start, n, k):
		x[j] = 0
	c.append(abs(x.count(-1) - x.count(1)))
	x = a.copy()
print(max(c))


import sys
from math import floor, ceil
input = sys.stdin.readline
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
totBad = 0
totGood = 0
for i in a:
	if i == -1:
		totBad += 1
	else:
		totGood += 1
ans = 0
for i in range(k):
	curBad = 0
	curGood = 0
	for j in range(i, n, k):
		if a[j] == -1:
			curBad += 1
		else:
			curGood += 1
	ans = max(ans, abs(totBad - curBad - (totGood - curGood)))
print(ans)


Input = lambda : map(int, input().split())
(n, k) = Input()
Tabs = list(Input())
(e, s) = (Tabs.count(1), Tabs.count(-1))
Max = -float('inf')
for b in range(k):
	Tmp = abs(e - Tabs[b::k].count(1) - (s - Tabs[b::k].count(-1)))
	if Tmp > Max:
		Max = Tmp
print(Max)


(q, w) = map(int, input().split())
e = list(map(int, input().split()))
r = []
for i in range(w):
	d = [0] * len(e)
	for l in range(len(e)):
		d[l] = e[l]
	for j in range(i, q, w):
		d[j] = 0
	h = abs(sum(d))
	r.append(h)
print(max(r))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
e = 0
s = 0
for i in range(n):
	if a[i] == 1:
		e += 1
	else:
		s += 1
maxdif = -1
for b in range(len(a)):
	blef = -1
	te = e
	ts = s
	if a[b] == 1:
		te -= 1
	else:
		ts -= 1
	map = {}
	while b + blef * k >= 0:
		if not b + blef * k in map:
			if a[b + blef * k] == 1:
				te -= 1
			else:
				ts -= 1
			map[b + blef * k] = 1
		blef -= 1
	brig = 1
	while b + brig * k < len(a):
		if not b + brig * k in map:
			if a[b + brig * k] == 1:
				te -= 1
			else:
				ts -= 1
			map[b + brig * k] = 1
		brig += 1
	maxdif = max(maxdif, abs(te - ts))
print(maxdif)


from sys import *
(n, k) = map(int, stdin.readline().split())
arr = list(map(int, stdin.readline().split()))
ne = 0
po = 0
ans = []
for i in range(k):
	ans.append([0, 0])
for i in range(len(arr)):
	if arr[i] == 1:
		po += 1
		ans[i % k][0] += 1
	else:
		ne += 1
		ans[i % k][1] += 1
from math import *
re = 0
for i in ans:
	tNe = ne - i[1]
	tPo = po - i[0]
	tAn = abs(tNe - tPo)
	re = max(re, tAn)
print(re)


(n, k) = list(map(int, input().strip().split()))
tabs = list(map(int, input().strip().split()))
curr = sum(tabs)
maxi = 0
x_starts = []
for x in range(k):
	c = [tabs[i] for i in range(x, n, k)]
	c.reverse()
	remove = sum(c)
	if curr > 0:
		res = curr - remove
	elif curr < 0:
		res = curr - remove
	else:
		res = remove
	maxi = max(abs(res), maxi)
print(maxi)


from collections import Counter
(n, k) = map(int, input().split())
vec = list(map(int, input().split()))
cnt = Counter(vec)
ans = 0
for i in range(n):
	i %= k
	temp = Counter(vec[i::k])
	e = cnt[1] - temp[1]
	s = cnt[-1] - temp[-1]
	ans = max(ans, abs(e - s))
print(ans)


[N, K] = list(map(int, input().split(' ')))
tabs = list(map(int, input().split(' ')))
tabs_total = [0] * K
ret = 0
total = 0
for (i, tab) in enumerate(tabs):
	tabs_total[(i + 1) % K] += tab
	total += tab
for i in range(K):
	total -= tabs_total[i]
	ret = max(ret, abs(total))
	total += tabs_total[i]
print(ret)


l1 = list(map(int, input().split()))
l = list(map(int, input().split()))
n = l1[0]
k = l1[1]
ma = -1
for i in range(k):
	j = 0
	l2 = l.copy()
	while i + j * k < n:
		l2[i + j * k] = 0
		j += 1
	neg = l2.count(-1)
	pos = l2.count(1)
	r = abs(neg - pos)
	if r > ma:
		ma = r
print(ma)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
sm = sum(a)
ans = 0
for i in range(k):
	st = 0
	for j in range(i, n, k):
		st += a[j]
	ans = max(ans, abs(sm - st))
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
m = []
b = []
for i in range(n):
	for j in range(i, -1, -1):
		if (i - j) % k != 0:
			b.append(a[j])
	for j in range(i, n):
		if (j - i) % k != 0:
			b.append(a[j])
	m.append(abs(b.count(-1) - b.count(1)))
	b = []
print(max(m))


def Value(array, b, k):
	i = 0
	b1 = b
	b2 = b
	new = array[:]
	while b1 < len(array):
		new[b1] = 0
		b1 += k
	while b2 > -1:
		new[b2] = 0
		b2 -= k
	inform = 0
	social = 0
	for i in new:
		if i == 1:
			inform += 1
		elif i == -1:
			social += 1
	return abs(inform - social)

def Solve(array, k):
	values = []
	for i in range(len(array)):
		values.append(Value(array, i, k))
	return max(values)

def main():
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	print(Solve(array, k))
main()


(n, k) = map(int, input().split())
arr = [int(a) for a in input().split()]
li = [0] * k
for i in range(n):
	li[i % k] += arr[i]
s = sum(li)
ma = 0
for a in li:
	ma = max(ma, abs(s - a))
print(ma)


(n, k) = map(int, input().split())
x = input()
maxx = 0
for i in range(0, k):
	z = list(x.split())
	for j in range(i, n, k):
		z[j] = 0
	m = abs(z.count('1') - z.count('-1'))
	if m > maxx:
		maxx = m
print(maxx)


def get_dist(start):
	diff = baseline_diff
	pos = start
	while pos < n:
		diff -= tab_type[pos]
		pos += step
	return abs(diff)
(n, step) = [int(x) for x in input().split()]
tab_type = [int(x) for x in input().split()]
baseline_diff = sum(tab_type)
ans = max((get_dist(start) for start in range(step)))
print(ans)


(n, k) = map(int, input().split())
(ls, ls2) = (list(map(int, input().split())), [0] * k)
for l in range(n):
	ls2[l % k] += ls[l]
print(max([abs(sum(ls) - l) for l in ls2]))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
a = 0
for i in range(k):
	p = sum(arr)
	for j in range(i, n, k):
		p -= arr[j]
	a = max(a, abs(p))
print(a)


[n, k] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
me = 0
for i in range(n):
	b = []
	for j in range(i, n, k):
		b.append(a[j])
	for j in range(i, -1, -k):
		if j == i:
			continue
		b.append(a[j])
	me = max(me, sum(a) - sum(b))
	me = max(me, -sum(a) + sum(b))
print(me)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for b in range(k):
	t = a.copy()
	for i in range(b, n, k):
		t[i] = 0
	ans = max(ans, abs(t.count(1) - t.count(-1)))
print(ans)


class Solution(object):

	def getMaxAbsoluteDifference(self, arr):
		totalTestCount = 0
		totalSocialCount = 0
		for num in arr:
			if num == 1:
				totalTestCount += 1
			else:
				totalSocialCount += 1
		maxAbsDifference = 0
		for i in range(k):
			currTestCount = totalTestCount
			currSocialCount = totalSocialCount
			for j in range(i, len(arr), k):
				if arr[j] == 1:
					currTestCount -= 1
				else:
					currSocialCount -= 1
			maxAbsDifference = max(maxAbsDifference, abs(currTestCount - currSocialCount))
		return maxAbsDifference

def read_input():
	return [int(x) for x in input().split()]
line = read_input()
n = line[0]
k = line[1]
arr = read_input()
sol = Solution()
result = sol.getMaxAbsoluteDifference(arr)
print(result)


def f(k, c):
	e = s = 0
	for i in range(n):
		if (i - c) % k != 0:
			if a[i] == 1:
				e += 1
			else:
				s += 1
	return abs(e - s)
read = lambda : map(int, input().split())
(n, k) = read()
a = list(read())
mx = 0
for c in range(0, k):
	mx = max(mx, f(k, c))
print(mx)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
e = a.count(1)
s = a.count(-1)
e1 = [0] * k
s1 = [0] * k
for i in range(n):
	if a[i] == 1:
		e1[i % k] += 1
	else:
		s1[i % k] += 1
ans = 0
for i in range(k):
	ans = max(ans, abs(e - e1[i] - (s - s1[i])))
print(ans)


list_int_input = lambda inp: list(map(int, inp.split()))
int_input = lambda inp: int(inp)
string_to_list_input = lambda inp: list(inp)
nk = list_int_input(input())
(n, k) = (nk[0], nk[1])
a = list_int_input(input())
(st, so) = (0, 0)
for i in a:
	if i == 1:
		st += 1
	else:
		so += 1
output = 0
for i in range(k):
	(sso, sst) = (0, 0)
	j = i
	while j < n:
		if a[j] == 1:
			sst += 1
		else:
			sso += 1
		j += k
	sso = so - sso
	sst = st - sst
	val = abs(sso - sst)
	if val > output:
		output = val
print(output)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = 0
m = 0
k -= 1
ke = 0
ks = 0
while b != len(a):
	temp = 0
	for i in range(b, len(a)):
		if temp == k:
			temp = 0
		elif a[i] == 1 and i != b:
			ke += 1
			temp += 1
		elif a[i] == -1 and i != b:
			ks += 1
			temp += 1
	temp = 0
	for i in range(b, -1, -1):
		if temp == k:
			temp = 0
		elif a[i] == 1 and i != b:
			ke += 1
			temp += 1
		elif a[i] == -1 and i != b:
			ks += 1
			temp += 1
	if abs(ks - ke) > m:
		m = abs(ks - ke)
	ks = 0
	ke = 0
	b += 1
print(m)


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
(n, k) = viread()
tabs = viread()
(ts, tt) = (0, 0)
for t in tabs:
	if t == 1:
		tt += 1
	else:
		ts += 1
best = 0
for i in range(k):
	(s, t) = (ts, tt)
	for j in range(n):
		if j % k == i:
			if tabs[j] == 1:
				t -= 1
			else:
				s -= 1
	cost = abs(s - t)
	if cost > best:
		best = cost
print(best)


(n, k) = [int(v) for v in input().split()]
signs = [int(v) for v in input().split()]
tot_e = signs.count(1)
tot_s = signs.count(-1)
ans = 0
for b in range(k):
	(me, ms) = (0, 0)
	for c in range(b, n, k):
		if signs[c] == 1:
			me += 1
		else:
			ms += 1
	ans = max(ans, abs(tot_e - me - (tot_s - ms)))
print(ans)


import sys

def main():
	(n, k) = map(int, sys.stdin.readline().strip().split()[:2])
	tab = sys.stdin.readline().strip().split()
	test = tab.count('1')
	social = tab.count('-1')
	res = []
	for c in range(0, k):
		newTab = []
		for i in range(c, len(tab), k):
			newTab.append(tab[i])
		e = newTab.count('1')
		s = newTab.count('-1')
		res.append(abs(test - e - (social - s)))
	print(max(res))
main()


def inp():
	return map(int, stdin.readline().split())

def arr_inp():
	return [int(x) for x in stdin.readline().split()]
from sys import *
from collections import *
(n, k) = inp()
(a, ans) = (arr_inp(), 0)
a_count = Counter(a)
for i in range(k):
	arr = a[i::k]
	(e, s) = (a_count[1] - arr.count(1), a_count[-1] - arr.count(-1))
	ans = max(ans, abs(e - s))
print(ans)


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
(soc, exam) = (lst.count(-1), lst.count(1))
mx = 0
for i in range(k):
	nls = lst[i::k]
	(nsoc, nexam) = (nls.count(-1), nls.count(1))
	if abs(soc - nsoc - exam + nexam) > mx:
		mx = abs(soc - nsoc - exam + nexam)
print(mx)


(n, k) = map(int, input().split(' '))
lst = list(map(int, input().split(' ')))
l = []
test = lst.count(1)
tt = test
soc = lst.count(-1)
ss = soc
m = 0
for i in range(k):
	(tt, ss) = (test, soc)
	(t, s) = (0, 0)
	for j in range(i, n, k):
		if lst[j] == 1:
			t += 1
		else:
			s += 1
	tt -= t
	ss -= s
	if abs(tt - ss) > m:
		m = abs(tt - ss)
print(m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(k):
	e = 0
	s = 0
	l = list(range(i, n, k))
	for j in range(n):
		if j not in l:
			if a[j] == 1:
				e += 1
			else:
				s += 1
	ans = max(ans, abs(e - s))
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
x = [0] * k
y = [0] * k
totx = 0
toty = 0
for i in a:
	if i == 1:
		totx += 1
	else:
		toty += 1
for (i, j) in enumerate(a):
	if j == 1:
		x[i % k] += 1
	else:
		y[i % k] += 1
ans = 0
for i in range(k):
	ans = max(ans, abs(totx - x[i] - toty + y[i]))
print(ans)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
maxs = 0
for i in range(1, b + 1):
	lcopy = []
	lcopy += l
	for j in range(i, a + 1, b):
		lcopy[j - 1] = 0
	cnt = lcopy.count(1)
	cnt1 = lcopy.count(-1)
	maxs = max(maxs, abs(cnt - cnt1))
print(maxs)


import sys
import math

def read_int():
	return int(input().strip())

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

def read_string():
	return input().strip()

def read_string_list(delim=' '):
	return input().strip().split(delim)
(n, k) = read_int_list()
tabs = read_int_list()
best = 0
for b in range(1, k + 1):
	net_e = 0
	net_s = 0
	closed = []
	for i in range(b, n + 1, k):
		closed.append(i)
	for i in range(1, n + 1):
		if i in closed:
			continue
		elif tabs[i - 1] == 1:
			net_e += 1
		else:
			net_s += 1
	best = max(best, abs(net_s - net_e))
print(best)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
smm = 0
for i in range(k):
	l = i
	sm = 0
	while l < n:
		sm += s[l]
		l = l + k
	if abs(sum(s) - sm) > smm:
		smm = abs(sum(s) - sm)
print(smm)


nm = input().split(' ')
n = int(nm[0])
k = int(nm[1])
s = input().split(' ')
s = [int(i) for i in s]
summa = sum(s)
mas = []
for i in range(k):
	temp = summa
	for j in range(0, n - i, k):
		temp -= s[j + i]
	mas.append(abs(temp))
print(max(mas))


a = input().split()
b = int(a[1])
a = int(a[0])
c = input().split()
ans = 0
for i in range(b):
	gg = c[:]
	e = 0
	s = 0
	for x in range(i, a, b):
		gg[x] = 0
	for i in gg:
		if i == '-1':
			s += 1
		if i == '1':
			e += 1
	ttt = e - s
	if ttt < 0:
		ttt *= -1
	if ans < ttt:
		ans = ttt
print(ans)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
arr2 = arr[:]
ans = 0
for i in range(k):
	arr2 = arr[:]
	while i <= n - 1:
		arr2[i] = 0
		i += k
	(e, s) = (arr2.count(1), arr2.count(-1))
	ans = max(ans, abs(e - s))
print(ans)


def main():
	arr = input().split()
	n = int(arr[0])
	k = int(arr[1])
	arr = input().split()
	store = [0 for x in range(k)]
	tot = 0
	for x in range(n):
		tot += int(arr[x])
		store[x % k] += int(arr[x])
	maxi = 0
	for x in store:
		maxi = max(maxi, abs(tot - x))
	print(maxi)
main()


import math
(n, k) = (int(i) for i in input().strip().split())
arr = [int(x) for x in input().split()]
count = [None] * k
for i in range(k):
	a = i
	temp = arr.copy()
	while a < len(temp):
		temp[a] = 0
		a += k
	count[i] = int(math.fabs(temp.count(1) - temp.count(-1)))
print(max(count))


inp = input().split()
n = int(inp[0])
k = int(inp[1])
tabs = list(map(int, input().split()))
m = -1
for b in range(0, k):
	t = [x for (i, x) in enumerate(tabs) if (i - b) % k]
	m = max(m, abs(sum(t)))
print(m)


(n, k) = map(int, input().split())
X = [int(a) for a in input().split()]
A = [0] * k
for i in range(n):
	A[i % k] += X[i]
s = sum(A)
ma = 0
for a in A:
	ma = max(ma, abs(s - a))
print(ma)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
m = 0
for b in range(n):
	s = 0
	for i in range(n):
		if i % k != b % k:
			s += a[i]
	m = max(m, abs(s))
print(m)


from sys import stdin, stdout
from collections import Counter
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(n, k) = lst()
	a = lst()
	one = a.count(1)
	neg_one = n - one
	ans = 0
	for b in range(k):
		(o, no) = (one, neg_one)
		for i in range(b, n, k):
			if a[i] == 1:
				o -= 1
			else:
				no -= 1
		ans = max(ans, abs(o - no))
	print(ans)


def bb(b, c):
	i = c
	while i >= 0:
		if i < n:
			b[i] = 0
		i -= k
	i = c
	while i < n:
		b[i] = 0
		i += k
	return abs(sum(b))
ma = -1
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
for b in range(0, 101):
	ba = a[0:len(a)]
	ma = max(ma, bb(ba, b))
print(ma)


(n, k) = [int(x) for x in input().split()]
inf = [int(x) for x in input().split()]
ek = 0
se = 0
cost = 0
for item in inf:
	if item == 1:
		ek += 1
	else:
		se += 1
for i in range(1, k + 1):
	e = ek
	s = se
	while 1:
		if i > n:
			break
		if inf[i - 1] == 1:
			e -= 1
		else:
			s -= 1
		i += k
	if abs(e - s) > cost:
		cost = abs(e - s)
print(cost)


(n, k) = list(map(int, input().split()))
arr = [int(x) for x in input().split()]

def calculate(a):
	nonlocal arr
	(e, s) = (0, 0)
	for i in range(a, n, k):
		if arr[i] == -1:
			e += 1
		else:
			s += 1
	e -= arr.count(-1)
	s -= arr.count(1)
	return abs(e - s)
l = []
for i in range(k):
	l.append(calculate(i))
print(max(l))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(c1, c2) = (a.count(1), a.count(-1))
res = 0
for i in range(1, k + 1):
	j = i
	(cc1, cc2) = (c1, c2)
	while j <= n:
		if a[j - 1] == 1:
			cc1 -= 1
		else:
			cc2 -= 1
		j += k
	res = max(res, abs(cc1 - cc2))
print(res)


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
summa = sum(lst)
res = 0
for i in range(k):
	(j, summa2) = (i, summa)
	while j < n:
		if lst[j] == 1:
			summa2 -= 1
		else:
			summa2 += 1
		j += k
	res = max(res, abs(summa2))
print(res)


(n, k) = input().split()
(n, k) = (int(n), int(k))
c_v_e = 0
c_v_s = 0
q = []
a = input().split()
for i in range(n):
	if a[i] == '1':
		c_v_e += 1
	elif a[i] == '-1':
		c_v_s += 1
for i in range(k):
	c_l_e = 0
	c_l_s = 0
	for j in range(n):
		if j % k == i:
			if a[j] == '1':
				c_l_e += 1
			elif a[j] == '-1':
				c_l_s += 1
	q.append(abs(c_v_e - c_l_e - (c_v_s - c_l_s)))
print(max(q))


def main():
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	a = [int(i) for i in input().split()]
	max = 0
	for i in range(1, k + 1):
		e = 0
		s = 0
		for j in range(n):
			if (j + 1) % k == i % k:
				continue
			elif a[j] == 1:
				e += 1
			else:
				s += 1
		if abs(e - s) > max:
			max = abs(e - s)
	print(max)
main()


from sys import stdin

def difference(flag, arr):
	e = 0
	s = 0
	for i in range(n):
		if flag[i] != 1:
			if arr[i] == 1:
				e += 1
			else:
				s += 1
	return abs(s - e)
(n, k) = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
maxi = 0
for i in range(0, k):
	flag = [0] * n
	j = i
	while j < n:
		flag[j] = 1
		j += k
	maxi = max(maxi, difference(flag, arr))
print(maxi)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
su = 0
for i in range(k):
	lp = [i for i in l]
	j = 0
	while i + j * k < n:
		lp[i + j * k] = 0
		j += 1
	if abs(sum(lp)) > su:
		su = abs(sum(lp))
print(su)


s = input().split()
n = int(s[0])
k = int(s[1])
l = list(map(int, input().split()))
max_val = -1000
for b in range(n):
	e = 0
	s = 0
	for j in range(n):
		if j % k != b % k:
			e += 1 if l[j] == 1 else 0
			s += 1 if l[j] == -1 else 0
	if abs(e - s) > max_val:
		max_val = abs(e - s)
print(max_val)


(n, k) = list(map(int, input().split()))
t = list(map(int, input().split()))
mx = 0
for i in range(k):
	mx = max(mx, abs(sum(t) - sum(t[i::k])))
print(mx)


def read_nums():
	return [int(x) for x in input().split()]

def calculate_diff(tabs, k, b):
	res = 0
	for i in range(len(tabs)):
		if (i - b) % k == 0:
			continue
		res += tabs[i]
	return abs(res)

def main():
	(n, k) = read_nums()
	tabs = read_nums()
	diffs = [calculate_diff(tabs, k, b) for b in range(n)]
	res = max(diffs)
	print(res)
main()


(n, k) = map(int, input().split())
lst = [int(x) for x in input().split()]
m0 = 0
for i in range(n):
	m0 += lst[i]
m = 0
a = 0
x = 0
for i in range(k):
	m = m0
	a = i
	while a < n:
		m -= lst[a]
		a += k
	m = abs(m)
	if m > x:
		x = m
print(x)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = -1
for c in range(n):
	temp = [x[1] for x in enumerate(a) if (x[0] - c) % k != 0]
	e = temp.count(1)
	s = temp.count(-1)
	ans = max(abs(e - s), ans)
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
x = y = 0
c1 = c2 = 0
for i in range(n):
	if a[i] == 1:
		x += 1
	else:
		y += 1
ans = 0
for i in range(n):
	c1 = c2 = 0
	for j in range(i, n, k):
		if a[j] == 1:
			c1 += 1
		else:
			c2 += 1
	for j in range(i - k, -1, -k):
		if a[j] == 1:
			c1 += 1
		else:
			c2 += 1
	ans = max(ans, abs(x - y - c1 + c2))
print(ans)


(N, k) = map(int, input().split())
a = []
a = list(map(int, input().split()))
p = 0
n = 0
for i in range(0, N):
	temp = a[i]
	if temp < 0:
		n += 1
	else:
		p += 1
m = 0
for b in range(0, N):
	pos = 0
	neg = 0
	for j in range(-1000, N):
		if b + j * k < 0:
			continue
		if b + j * k >= N:
			break
		if a[b + j * k] < 0:
			neg += 1
		else:
			pos += 1
	m = max(m, abs(p - pos - (n - neg)))
print(f'{m}')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
e = 0
for i in range(n):
	if arr[i] == 1:
		e += 1
s = n - e
ans = 0
for i in range(k):
	ec = 0
	sc = 0
	for j in range(i, n, k):
		if arr[j] == 1:
			ec += 1
		else:
			sc += 1
	ans = max(abs(e - ec - s + sc), ans)
print(ans)


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
sumi = 0
maxi = -10000
for i in range(n):
	sumi += x[i]
for i in range(k):
	ans = sumi
	for j in range(i, n, k):
		ans -= x[j]
	maxi = max(maxi, abs(ans))
print(maxi)


(n, k) = map(int, input().split())
s = [int(i) for i in input().split()]
b = 0
r = 0
while b < n:
	d = s.copy()
	x = [i for i in range(-b, n, k) if i >= 0]
	for i in x:
		d[i] = 0
	c = abs(d.count(-1) - d.count(1))
	r = max(c, r)
	b += 1
print(r)


from collections import defaultdict
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
dif = defaultdict(lambda : s)
for (i, x) in enumerate(a):
	dif[i % k] -= x
vals = [abs(x) for x in dif.values()]
print(max(vals))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
a = 0
for i in range(0, k):
	m = 0
	copy = arr.copy()
	while i + m * k < n:
		copy[i + m * k] = 0
		m += 1
	temp = abs(sum(copy))
	a = max(temp, a)
print(a)


nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]
arr = list(map(int, input().split()))
mods = [0 for _ in range(k)]
for i in range(len(arr)):
	mods[i % k] += arr[i]
max = 0
tabs = sum(arr)
for mod in mods:
	if abs(tabs - mod) > max:
		max = abs(tabs - mod)
print(max)


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
totp = a.count(1)
totn = a.count(-1)
ans = []
for i in range(n):
	tempp = 0
	tempn = 0
	for j in range(i + k, n, k):
		if a[j] == 1:
			tempp += 1
		else:
			tempn += 1
	for kk in range(i, -1, -k):
		if a[kk] == 1:
			tempp += 1
		else:
			tempn += 1
	ans.append(abs(totn - tempn - (totp - tempp)))
print(max(ans))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a = [0] + a
maxlist = []
for i in range(1, k + 1):
	temp = a.copy()
	j = i
	while j <= n:
		temp[j] = 0
		j = j + k
	study = 0
	social = 0
	for f in temp:
		if f == 1:
			study += 1
		if f == -1:
			social += 1
	maxlist.append(abs(study - social))
print(max(maxlist))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for b in range(n):
	closed = [b + i * k for i in range(-n, n)]
	closed = set((c for c in closed if 0 <= c < n))
	test = sum((a[i] == -1 and i not in closed for i in range(n)))
	play = sum((a[i] == 1 and i not in closed for i in range(n)))
	ans = max(ans, abs(test - play))
print(ans)


(x, y) = map(int, input().split())
l = list(map(int, input().split()))
t1 = l.count(1)
t2 = l.count(-1)
max1 = 0
for i in range(y):
	r1 = t1
	r2 = t2
	for j in range(i, x, y):
		if l[j] == 1:
			r1 = r1 - 1
		if l[j] == -1:
			r2 = r2 - 1
	max1 = max(max1, r1 - r2, r2 - r1)
print(max1)


(n, k) = input().split()
(n, k) = (int(n), int(k))
arr = [int(a) for a in input().strip().split(' ')]
e = 0
s = 0
for i in range(0, n):
	if arr[i] == 1:
		e += 1
	else:
		s += 1
et = 0
st = 0
ans = 0
for i in range(0, k):
	et = 0
	st = 0
	j = i
	while j < n:
		if arr[j] == 1:
			et += 1
		else:
			st += 1
		j += k
	ans = max(ans, abs(e - s + st - et))
print(ans)


(a, b) = map(int, input().split())
arr = list(map(int, input().split()))
maxi = 0
for n in range(b):
	i = [arr[x] for x in range(a) if x not in range(n, a, b)]
	x = abs(i.count(1) - i.count(-1))
	if x > maxi:
		maxi = x
print(maxi)


import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
(n, k) = rm()
a = rl()
ans = 0
for i in range(n):
	cnt = 0
	for j in range(n):
		if (j - i) % k != 0:
			cnt += a[j]
	ans = max(ans, abs(cnt))
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
b = 1
maxx = 0
for b in range(1, n + 1):
	x = [0 for i in range(n)]
	temp = []
	c = b
	c1 = b
	i = 0
	j = 0
	while c <= n:
		x[c - 1] = 1
		i += 1
		c = b + i * k
	while c1 >= 1:
		x[c1 - 1] = 1
		j -= 1
		c1 = b + j * k
	f1 = 0
	f2 = 0
	for i in range(n):
		if x[i] == 0:
			if l[i] == 1:
				f1 += 1
			else:
				f2 += 1
	maxx = max(maxx, abs(f1 - f2))
print(maxx)


(n, k) = map(int, input().strip().split())
l = [int(x) for x in input().strip().split()]
e1 = 0
s1 = 0
for i in l:
	if i == 1:
		e1 += 1
	else:
		s1 += 1
m = 0
for i in range(0, k):
	e = e1
	s = s1
	for j in range(i, n, k):
		if l[j] == 1:
			e = e - 1
		else:
			s = s - 1
	m = max(max(e - s, s - e), m)
print(m)


(n, k) = (int(x) for x in input().split())
L = [int(x) for x in input().split()]
N = [0 for x in range(k)]
S = 0
m = -1
for i in range(n):
	N[(i + 1) % k] += L[i]
	S += L[i]
for j in N:
	if abs(S - j) > m:
		m = abs(S - j)
print(m)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
test = soc = 0
for i in range(n):
	if l[i] == 1:
		test += 1
	else:
		soc += 1
ans = 0
for i in range(k):
	test1 = soc1 = 0
	for j in range(i, n, k):
		if l[j] == 1:
			test1 += 1
		else:
			soc1 += 1
	temp = abs(test - test1 - (soc - soc1))
	if temp > ans:
		ans = temp
print(ans)


from operator import itemgetter
(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
e = 0
s = 0
ans = 0
for j in range(k):
	e = 0
	s = 0
	for i in range(n):
		if i % k == j:
			continue
		if ar[i] == 1:
			e += 1
		else:
			s += 1
	ans = max(ans, abs(e - s))
print(ans)


gi = lambda : list(map(int, input().split()))
(n, K) = gi()
l = gi()
ans = -1
for j in range(K):
	ans = max(ans, abs(sum([l[k] for k in range(n) if k % K != j])))
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = l.count(1)
b = l.count(-1)
ans = 0
for i in range(k):
	c = d = 0
	for j in range(i, n, k):
		if l[j] == 1:
			c += 1
		else:
			d += 1
	ans = max(ans, abs(a - c - (b - d)))
print(ans)


def A():
	(n, k) = map(int, input().split())
	tabs = [int(x) for x in input().split()]
	dif = -float('inf')
	for b in range(k):
		aux = sum(tabs)
		i = 0
		while b + i * k < n:
			if tabs[b + i * k] == 1:
				aux -= 1
			else:
				aux += 1
			i += 1
		dif = max(abs(aux), dif)
	print(dif)
A()


(a, b) = map(int, input().split())
c = [0] + list(map(int, input().split()))
s = -1001
for i in range(b + 1):
	k = [*range(i, a + 1, b)]
	r = 0
	for j in range(a + 1):
		if j not in k:
			r += c[j]
	s = max(s, abs(r))
print(abs(s))


from sys import stdin

def read_lines(sep=' ', input_type=None):
	_lines = stdin.readlines()
	cast = input_type is not None
	lines = []
	for line in _lines:
		line = line[:-1].split(sep)
		if cast:
			line = [input_type(x) for x in line]
		lines.append(line)
	return lines

def sequential_max_diff(seq):
	unlagged_seq = seq[:-1]
	lagged_seq = seq[1:]
	maxd = 0
	for pair in zip(unlagged_seq, lagged_seq):
		diff = abs(pair[0] - pair[1])
		if diff > maxd:
			maxd = diff
	return maxd

def main2():
	lines = read_lines(input_type=int)
	n = lines[0][0]
	heights = lines[1]
	_seq = heights
	_seq.sort()
	least = _seq[-1]
	elements = _seq
	min_pair = None
	for i in range(len(elements)):
		for j in range(len(elements)):
			if j == i:
				continue
			(a, b) = (elements[i], elements[j])
			seq = _seq.copy()
			seq.remove(a)
			seq.remove(b)
			res = max(sequential_max_diff([a] + seq + [b]), abs(a - b))
			if res < least:
				min_pair = (a, b)
				least = res
	seq = _seq.copy()
	seq.remove(min_pair[0])
	seq.remove(min_pair[1])
	out = list(map(str, [min_pair[0]] + seq + [min_pair[1]]))
	print(' '.join(out))

def main3():
	lines = read_lines(input_type=int)
	(n, m, k) = lines[0]
	v = lines[1]
	max1 = max(v)
	max2 = 0
	max_appears = 0
	for ele in v:
		if ele == max1:
			max_appears += 1
			if max_appears == 2:
				print(max1 * m)
				return
	for ele in v:
		if ele != max1:
			if ele >= max2:
				max2 = ele
	block_size = k + 1
	num_of_blocks = m // block_size
	remainder = m % block_size
	value = num_of_blocks * (k * max1 + max2) + remainder * max1
	print(value)

def main4():
	lines = read_lines(input_type=int)
	n = lines[0][0]
	if n % 4 == 0:
		print(0)
	elif n % 4 == 2:
		print(1)
	elif n % 4 == 1:
		print(1)
	else:
		print(0)

def main5():
	lines = read_lines(input_type=int)
	for line in lines[1:]:
		(l, r, d) = line
		if d > r:
			print(d)
		elif d == r:
			print(2 * d)
		elif d < l:
			print(d)
		else:
			print(d * (r // d + 1))

def main():
	lines = read_lines(input_type=int)
	(n, k) = lines[0]
	values = lines[1]
	original_sum = sum(values)
	max_val = 0
	for i in range(k):
		indices = slice(i, n, k)
		filtered = abs(original_sum - sum(values[indices]))
		if max_val <= filtered:
			max_val = filtered
	print(max_val)
main()


(n, k) = tuple(map(int, input().split()))
a = list(map(int, input().split()))
kk = sum(a)
difs = []
for ic in range(k):
	c = ic
	dif = 0
	while c < n:
		dif += a[c]
		c += k
	difs.append(abs(kk - dif))
print(max(difs))


import sys
from math import *
from copy import copy
import pdb
import itertools
from pprint import pprint
from collections import deque
(n, k) = [int(i) for i in input().split()]
dat = [int(i) for i in input().split()]
sumMain = sum(dat)
sumMax = 0
for b in range(1, k + 1):
	sum1 = sumMain
	for i in range(b - 1, n, k):
		sum1 -= dat[i]
	sumMax = max(abs(sum1), abs(sumMax))
print(sumMax)


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
answer = 0
for i in range(k):
	B = A.copy()
	C = []
	for j in range(n):
		if j % k != i:
			C.append(B[j])
	a = C.count(1)
	b = C.count(-1)
	if abs(a - b) > answer:
		answer = abs(a - b)
print(answer)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
from collections import defaultdict as dc
cnt1 = a.count(1)
cnt2 = a.count(-1)
minc = -2
for i in range(1, k + 1):
	cntm = 0
	cntp = 0
	j = 0
	while i + j * k <= n:
		if a[i + j * k - 1] > 0:
			cntp += 1
		else:
			cntm += 1
		j += 1
	minc = max(minc, abs(cnt1 - cntp - cnt2 + cntm))
print(minc)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
z = -100000
for b in range(k):
	l = a[0:len(a):1]
	v = 0
	while True:
		if v * k + b < n:
			l[v * k + b] = 0
			v += 1
		else:
			break
	z = max(z, abs(l.count(1) - l.count(-1)))
print(z)


p = input().split()
n = int(p[0])
k = int(p[1])
p = input().split()
m = 0
for i in range(n):
	p[i] = int(p[i])
for i in range(k):
	o = p[:]
	j = i
	while j < len(o):
		o.pop(j)
		j += k - 1
	e = o.count(1)
	x = abs(e - (len(o) - e))
	if x > m:
		m = x
print(m)


R = lambda : map(int, input().split())
(n, k) = R()
L = list(R())
ma = 0
for i in range(1, n + 1):
	p = 0
	a = [i for i in L]
	c = i + p * k
	while 1 <= c <= n:
		a[c - 1] = 0
		p += 1
		c = i + p * k
	q = -1
	c = i + q * k
	while 1 <= c <= n:
		a[c - 1] = 0
		q -= 1
		c = i + q * k
	ma = max(ma, abs(a.count(1) - a.count(-1)))
print(ma)


(n, k) = [int(j) for j in input().split()]
b = 0
stroka = input()
if stroka[0] == '1':
	count_e = 1
else:
	count_e = 0
count_s = stroka.count('-1')
count_e += stroka.count(' 1')
stroka = stroka.split()
maxi = -1
for i in range(k):
	b = i
	del_s = 0
	del_e = 0
	while b < len(stroka):
		if stroka[b] == '-1':
			del_s += 1
		elif stroka[b] == '1':
			del_e += 1
		b = b + k
	if maxi < abs(count_s - del_s - (count_e - del_e)):
		maxi = abs(count_s - del_s - (count_e - del_e))
print(maxi)


temp = list(map(int, input().split(' ')))
n = temp[0]
k = temp[1]
a = list(map(int, input().split(' ')))
b = 1
m = 0
for i in range(1, k + 1, 1):
	t = 0
	for j in range(n):
		if abs(j - i) % k != 0:
			t = t + a[j]
	if abs(t) > m:
		m = abs(t)
print(m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
answ = 0
for b in range(n):
	sm = 0
	for i in range(n):
		if (i - b) % k:
			sm += a[i]
	answ = max(answ, abs(sm))
print(answ)


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations, accumulate
from math import gcd, floor, inf, log2, sqrt, log10
from bisect import bisect_right, bisect_left
from statistics import mode
from string import ascii_uppercase
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
negs = sum((1 for i in arr if i < 0))
pos = n - negs
best = -inf
for i in range(k):
	lst = [arr[num] for num in range(i, n, k)]
	ln = len(lst)
	sub_neg = sum((1 for i in lst if i < 0))
	sub_pos = ln - sub_neg
	best = max(best, abs(negs - sub_neg - (pos - sub_pos)))
print(best)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
or1 = l.count(1)
or2 = n - or1
dif = 0
for j in range(k):
	i = 0
	c1 = or1
	c2 = or2
	while True:
		c = j + i * k
		if c >= n:
			if dif < abs(c1 - c2):
				dif = abs(c1 - c2)
			break
		if l[c] == 1:
			c1 -= 1
		else:
			c2 -= 1
		i += 1
print(dif)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
(n, k) = tuple(mi())
a = li()
maxm = 0
for b in range(0, 101):
	f = [False] * n
	for i in range(-101, 101):
		if b + i * k >= 0 and b + i * k <= n - 1:
			f[b + i * k] = True
	c1 = 0
	c2 = 0
	for j in range(n):
		if not f[j]:
			if a[j] == 1:
				c1 += 1
			else:
				c2 += 1
	maxm = max(maxm, abs(c1 - c2))
print(maxm)


(n, k) = map(int, input().split())
a = [int(s) for s in input().split()]
mmax = 0
for i in range(k):
	s = 0
	e = 0
	for j in range(len(a)):
		if j % k != i:
			if a[j] == -1:
				s += 1
			else:
				e += 1
	mcur = abs(e - s)
	if mcur > mmax:
		mmax = mcur
print(mmax)


input = __import__('sys').stdin.readline
(n, k) = map(int, input().split())
D = [*map(int, input().split())]
ans = 0
for i in range(k):
	S = D + [0]
	t = i
	while t < n:
		S[t] = 0
		t += k
	ans = max(ans, abs(sum(S)))
print(ans)


(n, k) = map(int, input().split())
lst2 = []
lst = list(map(int, input().split()))
for b in range(1, n + 1):
	s = sum(lst)
	for i in range(-b // k + 1, (n - b) // k + 1):
		c = b + i * k
		s = s - lst[c - 1]
	lst2.append(abs(s))
print(max(lst2))


from math import *

def remplissage(s):
	t = []
	for i in s.split():
		t.append(int(i))
	return t

def copieTab(t):
	t2 = []
	for i in t:
		t2.append(i)
	return t2

def test(t, somme):
	if int(fabs(fsum(t))) > somme:
		return int(fabs(fsum(t)))
	else:
		return somme
(n, k) = input().split()
n = int(n)
k = int(k)
tabBase = remplissage(input())
SommeUltime = 0
for b in range(k):
	tabTest = copieTab(tabBase)
	i = 0
	while b + i * k <= len(tabTest) - 1:
		tabTest[b + i * k] = 0
		i += 1
	SommeUltime = test(tabTest, SommeUltime)
print(SommeUltime)


(n, k) = map(int, input().split())
a = [int(s) for s in input().split()]
m = []
soc = 0
ex = 0
for i in a:
	if i == 1:
		ex += 1
	else:
		soc += 1
for i in range(k):
	j = i
	soc1 = 0
	ex1 = 0
	while j < n:
		if a[j] == 1:
			ex1 += 1
		else:
			soc1 += 1
		j += k
	m.append(abs(ex - ex1 - (soc - soc1)))
mm = m[0]
for i in m:
	if i > mm:
		mm = i
print(mm)


a = input().split(' ')
n = int(a[0])
k = int(a[1])
lis = list(map(int, input().split(' ')))
length = 0
for i in range(0, k):
	b = list([lis[t] for t in range(0, n) if abs(t - i) % k != 0])
	l = list([lis[j] for j in b if j == -1])
	lent = len(b) - len(l)
	le = abs(len(l) - lent)
	if le > length:
		length = le
print(length)


(n, k) = tuple(map(int, input().split()))
lst = list(map(int, input().split()))
counter = 0
counter2 = 0
count = []
for i in lst:
	counter += i
for b in range(k):
	for j in range(n):
		if b + j * k >= n:
			break
		else:
			counter2 += lst[b + j * k]
	count.append(abs(counter2 - counter))
	counter2 = 0
Max = count[0]
for i in count:
	if Max < i:
		Max = i
print(Max)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
ans = 0
for i in range(k):
	b = a[:]
	for j in range(i, len(b), k):
		b[j] = 0
	ans = max(ans, abs(b.count(1) - b.count(-1)))
print(ans)


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

def qwerty(c, k, u):
	v = list(c)
	while u < a:
		v[u] = 0
		u += k
	g = 0
	s = 0
	for i in v:
		if i == 1:
			g += 1
		elif i == -1:
			s += 1
	return abs(g - s)
u = 0
otvet = 0
while u <= k - 1:
	q = qwerty(c, k, u)
	if otvet < q:
		otvet = q
	u += 1
print(otvet)


def idx(k, b, n):
	mi = b % k
	if mi == 0:
		mi = k
	return range(mi, n + 1, k)

def cal(tabs, k, b, n, te, ts):
	e = s = 0
	for i in idx(k, b, n):
		if tabs[i] == 1:
			e += 1
		elif tabs[i] == -1:
			s += 1
	s = ts - s
	e = te - e
	return abs(s - e)
(n, k) = map(int, input().split())
tabs = [0] + [int(i) for i in input().split()]
te = sum((i == 1 for i in tabs))
ts = sum((i == -1 for i in tabs))
difflist = []
for b in range(1, n + 1):
	difflist.append(cal(tabs, k, b, n, te, ts))
print(max(difflist))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
su = -10000000
mu = 100000
for i in range(k):
	j = i
	co = 0
	ll = list(l)
	while j < len(ll):
		ll.pop(j)
		co += 1
		j = j + k - 1
	s = sum(ll)
	if s > su:
		su = s
	if s < mu:
		mu = s
if mu < 0:
	mu = mu * -1
print(max(su, mu))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = []
for i in range(1, k + 1):
	b = a[:]
	for j in range(i, n + 1, k):
		b[j - 1] = 0
	c.append(abs(sum(b)))
print(max(c))


(n, k) = input().split()
li = input().split()
li = tuple(map(int, li))
n = int(n)
k = int(k)
c = []
for i in range(k):
	li2 = list(li)
	for j in range(i, n, k):
		li2[j] = 0
	x = li2.count(1)
	y = li2.count(-1)
	c.append(abs(x - y))
print(max(c))


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
(n, k) = RMI()
tabs = RMI()
sums = sum(tabs)
close = 0
for i in range(k):
	close = max(close, abs(sums - sum(tabs[i::k])))
print(close)


(n, k) = list(map(int, input().split()))
v = list(map(int, input().split()))
m = 0
for start in range(k):
	newl = []
	for (e, vv) in enumerate(v):
		if (e - start) % k != 0:
			newl.append(vv)
	mm = abs(len(list(filter(lambda x: x == 1, newl))) - len(list(filter(lambda x: x == -1, newl))))
	if mm > m:
		m = mm
print(m)


max = 0
a = []
p = input()
p = p.split(' ')
n = int(p[0])
k = int(p[1])
list = input()
list = list.split()
for i in range(n):
	l = int(list[i])
	a.append(l)
b = []
for i in range(k):
	for k1 in range(0, i):
		b.append(a[k1])
	for j in range(i + 1, n):
		if (j - i) % k != 0:
			b.append(a[j])
	y = abs(b.count(1) - b.count(-1))
	if y > max:
		max = y
	b = []
print(max)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
s = 0
for b in range(k):
	ans = 0
	for i in range(1, n + 1):
		if (i - b) % k != 0:
			ans += a[i - 1]
	s = max(s, abs(ans))
print(s)


nks = list(map(int, input().split(' ')))
nn = list(map(int, input().split(' ')))
n = nks[0]
k = nks[1]
sum = 0
for i in range(0, n):
	sum += nn[i]
mins = 1000
maxs = -1000
for b in range(0, k):
	c = b
	s = 0
	while c < n:
		s += nn[c]
		c += k
	if s < mins:
		mins = s
	if s > maxs:
		maxs = s
result = max(abs(sum - maxs), abs(sum - mins))
print(result)


(n, k) = map(int, input().split())
b = list(map(int, input().split()))
p = b.count(1)
q = b.count(-1)
ans = -1
j = 0
while j < min(n, k):
	c1 = p
	c2 = q
	i = j
	while i < n:
		if b[i] == 1:
			c1 += -1
		else:
			c2 += -1
		i += k
	ans = max(ans, abs(c1 - c2))
	j += 1
print(ans)


def calMode(i):
	(ne, ns) = (0, 0)
	temp = i
	while temp <= len(arr) - 1:
		if arr[temp] == 1:
			ne = ne + 1
		else:
			ns = ns + 1
		temp = temp + k
	return abs(e - ne - s + ns)
(n, k) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
(e, s) = (0, 0)
for i in arr:
	if i == 1:
		e = e + 1
	else:
		s = s + 1
ans = []
for i in range(k):
	ans.append(calMode(i))
print(max(ans))


(n, k) = map(int, input().split())
arr = input().split()
rem = arr.copy()
ans = []
for i in range(k):
	rem = arr.copy()
	for j in range(0 + i, n, k):
		rem[j] = '0'
	x1 = rem.count('-1')
	x2 = rem.count('1')
	ans.append(abs(x1 - x2))
print(max(ans))


from math import *
from itertools import *
from collections import *
from functools import reduce
Q = q = quit
inf = float('inf')

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

def input_floats():
	return list(map(float, input().split()))

def input_strings():
	return input().split()
(n, k) = input_ints()
tabs = input_ints()
ans = 0
for b in range(k):
	new = tabs[:]
	del new[b::k]
	d = abs(new.count(1) - new.count(-1))
	ans = max(ans, d)
print(ans)


import math
(n, k) = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
init_sum = sum(a)
count_dict = dict()
for i in range(k):
	count_dict[i] = 0
for i in range(len(a)):
	count_dict[i % k] += a[i]
possible_final_values = [int(math.fabs(init_sum - val)) for val in count_dict.values()]
print(max(possible_final_values))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(k):
	sum_ = 0
	for j in range(n):
		if j % k == i:
			continue
		sum_ += l[j]
	sum_ = abs(sum_)
	if ans < sum_:
		ans = sum_
print(ans)


import math
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
i = sum(l)
q = 0
for b in range(k):
	l1 = l[b:n:k]
	s = sum(l1)
	q = max(abs(i - s), q)
print(q)


(n, k) = map(int, input().split())
li = list(map(int, input().split()))
ans = 0
for b in range(n):
	tmp = 0
	for x in range(b + k, n, k):
		tmp += li[x]
	for x in range(b, -1, -k):
		tmp += li[x]
	ans = max(ans, abs(sum(li) - tmp))
print(ans)


put = lambda : tuple(map(int, input().split()))
(n, k) = put()
a = list(put())
f = a.count(1)
s = a.count(-1)

def check(start):
	cnt_a = 0
	cnt_b = 0
	while start < n:
		if a[start] == 1:
			cnt_a += 1
		else:
			cnt_b += 1
		start += k
	return (cnt_a, cnt_b)
ans = []
for i in range(k):
	(x, y) = check(i)
	ans.append(abs(f - x - (s - y)))
print(max(ans))


(j, k) = map(int, input().split())
l = list(map(int, input().split()))
s = sum(l)
a = []
for m in range(k):
	i = m
	sumi = 0
	while i < j:
		sumi += l[i]
		i += k
	a.append(abs(s - sumi))
print(max(a))


import sys, copy
(n, k) = map(int, sys.stdin.readline().split())
arr = [0] + list(map(int, sys.stdin.readline().split()))
ans = 0
for b in range(1, n + 1):
	temp = copy.deepcopy(arr)
	for i in range(-200, 201):
		idx = b + i * k
		if 1 <= idx <= n:
			temp[idx] = 0
	ans = max(ans, abs(temp.count(1) - temp.count(-1)))
print(ans)


(n, k) = map(int, input().split())
(*l,) = map(int, input().split())
m = []
for i in range(k):
	p = sum(l)
	for j in range(i, n, k):
		p -= l[j]
	m.append(abs(p))
print(max(m))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = 0
s = 0
for i in range(n):
	if a[i] == 1:
		t += 1
	else:
		s += 1
num = 0
for i in range(k):
	(t1, s1) = (t, s)
	for j in range(i, n, k):
		if a[j] == 1:
			t1 -= 1
		else:
			s1 -= 1
	num = max(num, abs(s1 - t1))
print(num)


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
print(max((abs(sum(s) - sum(s[i::m])) for i in range(m))))


(n, k) = (int(x) for x in input().split())
tabs = [int(x) for x in input().split()]
mods = [sum(tabs[i::k]) for i in range(k)]
summods = sum(mods)
ans = -1
for i in range(k):
	cand = abs(summods - mods[i])
	if cand > ans:
		ans = cand
print(ans)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
ssu = 0
for i in range(k):
	z = i
	su = 0
	while z < n:
		su += a[z]
		z += k
	if abs(sum(a) - su) > ssu:
		ssu = abs(sum(a) - su)
print(ssu)


(a, b) = map(int, input().split())
m = list(map(int, input().split()))
ma = -1
for i in range(a):
	t = m.copy()
	for j in range(a):
		if abs(i - j) % b == 0:
			t[j] = 0
	e = t.count(1)
	s = t.count(-1)
	ma = max(abs(e - s), ma)
print(ma)


(N, K) = map(int, input().split())
tabs = list(map(int, input().split()))
ans = 0
for i in range(K):
	s = 0
	e = 0
	for j in range(N):
		if j % K != i:
			if tabs[j] == 1:
				s += 1
			elif tabs[j] == -1:
				e += 1
	ans = max(abs(e - s), ans)
print(ans)


(n, k) = (int(s) for s in input().split(' '))
tabs = [int(s) for s in input().split(' ')]
sums = [0] * k
for (i, t) in enumerate(tabs):
	sums[i % k] += t
total_sum = sum(sums)
print(max((abs(total_sum - s) for s in sums)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = sum(a)
mx = -1
mi = 0
for i in range(1, n + 1):
	x = d
	s = set()
	for j in range(100):
		s.add(i + k * j)
		s.add(i - k * j)
	for j in s:
		if j > 0 and j <= n:
			x -= a[j - 1]
	mx = max(x, mx)
	mi = min(mi, x)
print(max(mx, abs(mi)))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
res = 0
for i in range(k):
	count = 0
	for j in range(n):
		if i != j % k:
			count += l[j]
	res = max(res, abs(count))
print(res)


N = list(map(int, input().split()))
X = list(map(int, input().split()))
MAX = 0
XNum1 = X.count(1)
XNum_1 = X.count(-1)
for i in range(N[1]):
	Temp = X[i::N[1]]
	Num1 = Temp.count(1) if 1 in Temp else 0
	Num_1 = Temp.count(-1) if -1 in Temp else 0
	MAX = max(MAX, abs(XNum1 - Num1 - (XNum_1 - Num_1)))
print(MAX)


(n, k) = map(int, input().split())
ll = list(map(int, input().split()))
d = 0
e = 0
for i in ll:
	if i == 1:
		d = d + 1
	elif i == -1:
		e = e + 1
temp = 0
for j in range(k):
	f = 0
	g = 0
	i = 0
	while j + i * k < n:
		if ll[j + i * k] == 1:
			f = f + 1
		else:
			g = g + 1
		i = i + 1
	el = d - f
	fl = e - g
	if abs(el - fl) > temp:
		temp = abs(el - fl)
print(temp)


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
su = sum(l)
ll = [0 for i in range(k)]
j = 0
for i in range(n):
	ll[j] += l[i]
	j += 1
	j %= k
res = 0
for i in ll:
	res = max(res, abs(su - i))
print(res)


input = __import__('sys').stdin.readline
print = __import__('sys').stdout.write
(n, k) = map(int, input().split())
social = list(map(int, input().split()))
m = 0
for i in range(k):
	e = 0
	s = 0
	for idx in range(n):
		if abs(i - idx) % k == 0:
			continue
		elif social[idx] == -1:
			s += 1
		else:
			e += 1
	m = max(m, abs(e - s))
print(str(m))


(n, k) = list(map(int, input().split(' ')))
page_list = list(map(int, input().split(' ')))
sub_page_list = []
sums = []
for i in range(k):
	sum_ = 0
	for j in range(k):
		if i == j:
			continue
		sum_ += sum(page_list[j::k])
	sums.append(abs(sum_))
out = max(sums)
print(out)


strs = input().split()
n = int(strs[0])
k = int(strs[1])
pages = [int(s) for s in input().split()]
count = []
for i in range(k):
	e = 0
	s = 0
	b = i
	copy_pages = pages.copy()
	while b < n:
		copy_pages[b] = 0
		b += k
	for c in copy_pages:
		if c < 0:
			s += 1
		elif c > 0:
			e += 1
	count.append(abs(e - s))
print(max(count))


from math import ceil
from statistics import median

def f(l, b):
	ans = -float('inf')
	for i in range(len(l)):
		cnt = 0
		for j in range(i, len(l), b):
			cnt += l[j]
		if i - 1 >= 0:
			for j in range(i, -1, -b):
				if j == i:
					continue
				cnt += l[j]
		ans = max(ans, abs(sum(l) - cnt))
	return ans
(a, b) = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
print(f(l, b))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if l.count(-1) > l.count(1):
	print(abs(sum(l) - max((sum(l[i::k]) for i in range(k)))))
elif l.count(1) > l.count(-1):
	print(sum(l) - min((sum(l[i::k]) for i in range(k))))
else:
	print(max(sum(l) - min((sum(l[i::k]) for i in range(k))), abs(sum(l) - max((sum(l[i::k]) for i in range(k))))))


(n, k) = [int(x) for x in input().split()]
tab = [int(x) for x in input().split()]
max_i = -1
for b in range(0, k):
	cpy = []
	for x in tab:
		cpy.append(x)
	for i in range(b, len(cpy), k):
		cpy[i] = 0
	curr_i = abs(cpy.count(1) - cpy.count(-1))
	if curr_i > max_i:
		max_i = curr_i
print(max_i)


(n, k) = map(int, input().split())
l = list([int(x) for x in input().split()])
ans = 0
for b in range(n):
	sum = 0
	for i in range(n):
		if i % k != b % k:
			sum += l[i]
	ans = max(ans, abs(sum))
print(ans)


def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	sumList = sum(arr)
	res = []
	for i in range(0, k):
		tmp = sum(arr[i::k])
		res.append(abs(sumList - tmp))
	print(max(res))
main()


n = input().split(' ')
k = int(n[1])
n = int(n[0])
mas = input().split(' ')
mas = [int(i) for i in mas]
mas_n = set((i for i in range(n)))
max_def = 0
for b in range(k):
	drop_n = set((b + i for i in range(0, n, k)))
	mas_n_ = mas_n - drop_n
	mas_ = [0 if index in drop_n else i for (index, i) in enumerate(mas)]
	if abs(sum(mas_)) > max_def:
		max_def = abs(sum(mas_))
print(max_def)


(n, k) = map(int, input().split())
mas = list(map(int, input().split()))
ans = 0
for b in range(k):
	m = 0
	for i in range(n):
		if i % k == b:
			continue
		m += mas[i]
	ans = max(ans, abs(m))
print(ans)


s = input().split()
(n, k) = (int(s[0]), int(s[1]))
cl = list(map(int, input().split()))
mx = 0
alle = cl.count(-1)
allc = cl.count(1)
for i in range(k):
	e = 0
	c = 0
	for j in range(i, n, k):
		if cl[j] == -1:
			e += 1
		else:
			c += 1
	if abs(alle - e - allc + c) > mx:
		mx = abs(alle - e - allc + c)
print(mx)


(n, k) = [int(x) for x in input().split(' ')]
l = list(map(int, input().split(' ')))
sm = sum(l)
li = []
for i in range(0, k):
	s = int(0)
	j = i
	while j <= n - 1:
		s = s + l[j]
		j = j + k
	li.append(abs(sm - s))
print(max(li))


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
max = 0
for i in range(n):
	b = i
	c = -(b // k)
	e = a.count(1)
	s = a.count(-1)
	while b + c * k < n:
		if a[b + c * k] == 1:
			e -= 1
		else:
			s -= 1
		c += 1
	if abs(e - s) > max:
		max = abs(e - s)
print(max)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ei = 0
si = 0
ecnt = [0] * k
scnt = [0] * k
c = []
for i in range(len(l)):
	if l[i] == 1:
		ei = ei + 1
		x = i % k
		ecnt[x] += 1
	else:
		si = si + 1
		x = i % k
		scnt[x] += 1
for i in range(k):
	c.append(ecnt[i] - scnt[i])
if ei > si:
	print(ei - si - min(c))
elif si > ei:
	print(si - ei + max(c))
else:
	print(max(max(c), abs(min(c))))


(num, skip) = map(int, input().split())
arr = [int(x) for x in input().split()]
total = sum(arr)
removed_tab_sum = []
for i in range(skip):
	removed_tab_sum.append(0)
	for o in range(i, num, skip):
		removed_tab_sum[i] += arr[o]
if total == 0:
	choosen = max([abs(u) for u in removed_tab_sum])
elif total < 0:
	choosen = max(removed_tab_sum)
else:
	choosen = min(removed_tab_sum)
print(abs(total - choosen))


import sys
import math

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def printspx(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')

def printchk(*args):
	return print(*args, end=' \\ ')
MODPRIME = int(1000000000.0 + 7)
BABYMODPR = 998244353
ONLINE_JUDGE = 1
if not ONLINE_JUDGE:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	sys.stderr = open('output.txt', 'w')
(n, k) = get_ints()
li = get_list()
tot = sum(li)
ans = -float('inf')
for i in range(k):
	j = i
	temp = 0
	while j < n:
		temp += li[j]
		j += k
	ans = max(abs(tot - temp), ans)
print(ans)


[n, k] = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
ans = 0
for b in range(k):
	curr = 0
	for i in range(n):
		if (i - b) % k != 0:
			curr += t[i]
	ans = max(abs(curr), ans)
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = -1000
for i in range(k):
	A = a[:]
	b = 0
	while i + b * k <= n - 1:
		A[i + b * k] = 0
		b += 1
	ans = max(ans, abs(sum(A)))
print(ans)


(n, k) = map(int, input().split())
tabtypes = list(map(int, input().split()))
max1 = 0
for i in range(1, k + 1):
	j = i
	e = 0
	s = 0
	sum1 = sum(tabtypes)
	while j <= n:
		sum1 -= tabtypes[j - 1]
		j += k
	if abs(sum1) > max1:
		max1 = abs(sum1)
print(max1)


given = input().split()
total = int(given[0])
gap = int(given[1])
tabs = input().split()
tabs = [int(n) for n in tabs]
summ = []
newtab = []
for i in range(0, gap):
	newtab = list(tabs)
	for j in range(i, total, gap):
		newtab[j] = 0
	x = sum(newtab)
	summ.append(abs(x))
print(max(summ))


def main():
	(n, k) = map(int, input().split())
	types = [int(i) for i in input().split()]
	e = types.count(1)
	s = types.count(-1)
	gay = []
	for b in range(n):
		del_e = 0
		del_s = 0
		for i in range(-n // k - 1, n // k + 1):
			c = b + i * k
			if c > 0 and c < len(types) + 1:
				if types[c - 1] == 1:
					del_e += 1
				else:
					del_s += 1
		gay.append(abs(e - del_e - s + del_s))
	print(max(gay))
main()


(a, b) = map(int, input().split())
c = [0] + list(map(int, input().split()))
p = sum(c)
print(max((abs(p - sum(c[i::b])) for i in range(b + 1))))


(n, k) = map(int, input().split())
m = [int(i) for i in input().split()]
s = 0
e = 0
for i in range(n):
	if m[i] == 1:
		e += 1
	else:
		s -= 1
r = s + e
res = 0
for i in range(k):
	r = s + e
	for j in range(n):
		if i + k * j < n:
			r -= m[i + k * j]
	if abs(r) > res:
		res = abs(r)
print(res)


def solve():
	rd = lambda : list(map(int, input().split()))
	(n, k) = rd()
	arr = rd()
	x = sum(arr)
	m = -1
	for b in range(len(arr)):
		s = x
		for i in range(-1000, 1001, 1):
			c = b + i * k
			if c >= 0 and c <= n - 1:
				if arr[c] == -1:
					s += 1
				else:
					s -= 1
		m = max(m, abs(s))
	print(m)
solve()


(n, k) = list(map(int, input().split(' ')))
x = list(map(int, input().split(' ')))
(a, Max) = ([], 0)
for i in range(k):
	a = x[i::k]
	Max = max(Max, abs(x.count(-1) - a.count(-1) - (x.count(1) - a.count(1))))
print(Max)


(n, k) = input().split()
(n, k) = (int(n), int(k))
S = [int(i) for i in input().split()]
max = 0
for b in range(1, n + 1):
	sum = 0
	for a in range(n):
		if (a + 1 - b) % k == 0:
			pass
		else:
			sum += S[a]
	if abs(sum) > max:
		max = abs(sum)
print(max)


A = list(map(int, input().split()))
n = A[0]
k = A[1]
L = list(map(int, input().split()))
b = 1
maxdif = 0
while b <= k:
	i = 1
	N = []
	number = b
	while number <= n:
		N.append(number)
		number = b + i * k
		i = i + 1
	countt = 0
	counts = 0
	for t in range(1, n + 1):
		if t not in N:
			if L[t - 1] == 1:
				counts = counts + 1
			else:
				countt = countt + 1
	dif = abs(countt - counts)
	if maxdif < dif:
		maxdif = dif
	b = b + 1
print(maxdif)


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
ANS = 0
for i in range(k):
	ex = 0
	so = 0
	for l in range(n):
		if l % k == i:
			continue
		if A[l] == 1:
			ex += 1
		else:
			so += 1
	if ANS < abs(ex - so):
		ANS = abs(ex - so)
print(ANS)


(n, k) = list(map(int, input().split()))
l = tuple(map(int, input().split()))
ans = 0
for i in range(k):
	temp = list(l)
	j = i
	while j < n:
		temp[j] = 0
		j += k
	ans = max(ans, abs(sum(temp)))
print(ans)


entrada = input()
entrada = [int(x) for x in entrada.split()]
n = entrada[0]
k = entrada[1]
tabs = input()
tabs = [int(x) for x in tabs.split()]
values = [0] * n
for b in range(n):
	closed_sum = 0
	c = 0
	first_sum = sum(tabs)
	while b + c * k < n:
		closed_sum += tabs[b + c * k]
		c += 1
	c = -1
	while b + c * k >= 0:
		closed_sum += tabs[b + c * k]
		c -= 1
	values[b] = abs(first_sum - closed_sum)
print(max(values))


(n, k) = map(int, input().split())
mass = list(map(int, input().split()))
e = mass.count(1)
s = mass.count(-1)
popq = float('-inf')
for b in range(0, k):
	e1 = e
	s1 = s
	for vkladki in range(b, n, k):
		if mass[vkladki] == 1:
			e1 -= 1
		else:
			s1 -= 1
	popq = max(popq, abs(e1 - s1))
print(popq)


(a, b) = tuple([int(x) for x in input().split()])
arr = [int(x) for x in input().split()]
max_total = 0
for i in range(b):
	new_max_total = abs(sum(arr) - sum(arr[i::b]))
	if new_max_total > max_total:
		max_total = new_max_total
print(max_total)


(n, k) = [int(x) for x in input().split(' ')]
t = [int(x) for x in input().split(' ')]
e = sum(t)
m = 0
for i in range(k):
	e_l = sum([z for (j, z) in enumerate(t) if j % k != i])
	m = max(abs(e_l), m)
print(m)


from collections import Counter
import math
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
c = Counter(l)
a1 = c[1]
a2 = c[-1]
i = 0
s = []
a = 0
b = 0
while i < m:
	for j in range(i, n, m):
		if l[j] > 0:
			a += 1
		else:
			b += 1
	s += [abs(a1 - a2 + b - a)]
	a = 0
	b = 0
	i += 1
print(max(s))


(j, k) = input().split()
j = int(j)
k = int(k)
l = list(map(int, input().split()))
s = sum(l)
a = []
for jj in range(k):
	i = jj
	su = 0
	while i < j:
		su += l[i]
		i += k
	a.append(abs(s - su))
print(max(a))


(n, k) = map(int, input().split())
data = list(map(int, input().split()))
ans = -11000001010101
ss = sum(data)

def get_ans(start):
	ret = 0
	ind = start
	while ind < n:
		ret += data[ind]
		ind += k
	return abs(ss - ret)
for i in range(k):
	ans = max(ans, get_ans(i))
print(ans)


(n, k) = map(int, input().split())
a = []
s = input().split()
maxx = -1
for i in range(n):
	a.append(int(s[i]))
for i in range(k):
	w = 0
	for j in range(n):
		if (j - i) % k != 0:
			w += a[j]
	if maxx < abs(w):
		maxx = abs(w)
print(maxx)


import math
import bisect
import itertools
import sys
I = lambda : sys.stdin.readline()
mod = 10 ** 9 + 7

def mindiff(a):
	b = a[:]
	b.sort()
	m = 10000000000
	for i in range(len(b) - 1):
		if b[i + 1] - b[i] < m:
			m = b[i + 1] - b[i]
	return m

def lcm(a, b):
	return a * b // math.gcd(a, b)

def merge(a, b):
	i = 0
	j = 0
	c = 0
	ans = []
	while i < len(a) and j < len(b):
		if a[i] < b[j]:
			ans.append(a[i])
			i += 1
		else:
			ans.append(b[j])
			c += len(a) - i
			j += 1
	ans += a[i:]
	ans += b[j:]
	return (ans, c)

def mergesort(a):
	if len(a) == 1:
		return (a, 0)
	mid = len(a) // 2
	(left, left_inversion) = mergesort(a[:mid])
	(right, right_inversion) = mergesort(a[mid:])
	(m, c) = merge(left, right)
	c += left_inversion + right_inversion
	return (m, c)

def is_prime(num):
	if num == 1:
		return False
	if num == 2:
		return True
	if num == 3:
		return True
	if num % 2 == 0:
		return False
	if num % 3 == 0:
		return False
	t = 5
	a = 2
	while t <= int(math.sqrt(num)):
		if num % t == 0:
			return False
		t += a
		a = 6 - a
	return True

def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1

def binsearch(arr, b, low, high):
	if low == high:
		return low
	if arr[math.ceil((low + high) / 2)] < b:
		return binsearch(arr, b, low, math.ceil((low + high) / 2) - 1)
	else:
		return binsearch(arr, b, math.ceil((low + high) / 2), high)

def ncr1(n, r):
	s = 1
	for i in range(min(n - r, r)):
		s *= n - i
		s %= mod
		s *= pow(i + 1, mod - 2, mod)
		s %= mod
	return s

def calc(n, m, r):
	s = 0
	for i in range(0, r + 1, 2):
		s += ncr1(n, i) * ncr1(m, i)
		s %= mod
	return s
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
m = -1
for i in range(1, n + 1):
	d = {}
	for j in range(-100, 100):
		d[i + j * k] = 1
	c = 0
	d1 = 0
	for j in range(n):
		if j + 1 not in d:
			c += a[j]
	m = max(abs(c), m)
print(m)


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
d = [0 for _ in range(n)]
for _ in range(n):
	for i in range(n):
		if i % k != _ % k:
			d[_] += t[i]
print(max((abs(d[_]) for _ in range(n))))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for b in range(1, n + 1):
	a_copy = a.copy()
	for i in range(-100, 100):
		c = b + i * k
		if 1 <= c <= n:
			a_copy[c - 1] = 0
	s = 0
	for i in a_copy:
		s += i
	if abs(s) > ans:
		ans = abs(s)
print(ans)


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

def func(kth, tam, k, nn):
	e = 0
	s = 0
	for i in range(kth, tam + 1, k):
		if nn[i - 1] == 1:
			e += 1
		else:
			s += 1
	return (e, s)
e = nn.count(1)
s = nn.count(-1)
tam = len(nn)
ll = []
maxd = -1
kthh = -1
for kth in range(1, k + 1):
	(ee, ss) = func(kth, tam, k, nn)
	ee = e - ee
	ss = s - ss
	abst = abs(ee - ss)
	if abst > maxd:
		maxd = abst
		kthh = kth
print(maxd)


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

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

def main():
	(n, k) = get_ints()
	arr = get_array()
	c1 = arr.count(1)
	c2 = arr.count(-1)
	mx = 0
	for i in range(k):
		j = i
		x = 0
		y = 0
		while j < n:
			if arr[j] == 1:
				x += 1
			else:
				y += 1
			j += k
		curr = abs(c1 - x - (c2 - y))
		mx = max(mx, curr)
	print(mx)
main()


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, file=sys.stderr)
	dprint('debug mode')
except Exception:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	sys.stdin = open('input' + str(inId) + '.txt', 'r')
if outId > 0:
	dprint('use output', outId)
	sys.stdout = open('stdout' + str(outId) + '.txt', 'w')
	atexit.register(lambda : sys.stdout.close())
(N, K) = getIntList()
za = getIntList()
rr = 0
for b in range(K):
	r = 0
	for i in range(N):
		if i % K == b:
			continue
		r += za[i]
	r = abs(r)
	rr = max(r, rr)
print(rr)


import sys
from collections import Counter
(N, K) = map(int, input().split())
w = list(map(int, input().split()))
sum_w = sum(w)
ans = 0
for i in range(K):
	tmp = 0
	for j in range(i, N, K):
		tmp += w[j]
	ans = max(ans, abs(sum_w - tmp))
print(ans)


def browser(lst, k):
	result = 0
	for i in range(1, 151):
		count = 0
		for j in range(0, len(lst)):
			if (i - j) % k == 0:
				continue
			count += lst[j]
		result = max(result, abs(count))
	return result
(n, k) = [int(i) for i in input().split()]
a = [int(x) for x in input().split()]
print(browser(a, k))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
e = a.count(1)
s = a.count(-1)
ans = 0
for b in range(k):
	sa = a[b::k]
	se = e - sa.count(1)
	ss = s - sa.count(-1)
	ans = max(ans, abs(se - ss))
print(ans)


a = [int(q) for q in input().strip().split()]
b = [int(q) for q in input().strip().split()]
(c, d) = (0, 0)
for k in range(a[0]):
	if b[k] == 1:
		c += 1
	else:
		d += 1
e = 0
for k in range(0, a[1]):
	f = []
	for h in range(len(b)):
		f.append(b[h])
	m = k
	(c, d) = (0, 0)
	while m < a[0]:
		f[m] = 0
		m += a[1]
	for r in range(a[0]):
		if f[r] == 1:
			c += 1
		elif f[r] == -1:
			d += 1
	e = max(e, abs(c - d))
print(e)


(n, k) = map(int, input().split())
tabs = list(map(int, input().split()))
finalTabs = []
for counter in range(k):
	clone = tabs.copy()
	for i in range(counter, n, k):
		clone[i] = 0
	finalTabs.append(clone)
output = 0
for element in finalTabs:
	e = element.count(1)
	s = element.count(-1)
	difference = abs(e - s)
	if difference > output:
		output = difference
print(output)


d = list(map(int, input().split()))
n = d[0]
k = d[1]
maxcount = -1
a = list(map(int, input().split()))
for i in range(k):
	a1 = a.copy()
	for j in range(i, n, k):
		a1[j] = 0
	temp = abs(a1.count(-1) - a1.count(1))
	if temp > maxcount:
		maxcount = temp
	a1.clear()
print(maxcount)


def main():
	(n, k) = map(int, input().split())
	tabs_type = list(map(int, input().split()))
	ret = 0
	for b in range(k):
		(cnt1, cnt2) = (0, 0)
		for i in range(n):
			if i % k == b:
				continue
			if tabs_type[i] == 1:
				cnt1 += 1
			else:
				cnt2 += 1
		ret = max(ret, abs(cnt1 - cnt2))
	print(ret)
main()


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

def get_kind(b, n, k, kind, tp):
	count = 0
	for (i, t) in enumerate(kind):
		if (i - b) % k != 0 and t == tp:
			count += 1
	return count
mx = -1
for b in range(k):
	test = get_kind(b, n, k, kind, -1)
	social = get_kind(b, n, k, kind, 1)
	crt = abs(test - social)
	if crt > mx:
		mx = crt
print(mx)


s = input().split()
n = int(s[0])
k = int(s[1])
s = input().split()
s1 = s.count('-1')
s2 = n - s1
mx = 0
bmx = 0
for b in range(1, n + 1):
	k1 = 0
	k2 = 0
	for i in range(-100, 100):
		if b + i * k > 0 and b + i * k <= n:
			if s[b + i * k - 1] == '-1':
				k1 += 1
			else:
				k2 += 1
	mx = max(mx, abs(s1 - k1 - (s2 - k2)))
print(mx)


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n, k) = I()
l = I()
ans = 0
for i in range(k):
	v = [1] * n
	for j in range(i, n, k):
		v[j] = 0
	a = [0, 0]
	for i in range(n):
		if v[i] and l[i] == -1:
			a[0] += 1
		elif v[i]:
			a[1] += 1
	ans = max(ans, abs(a[0] - a[1]))
print(ans)


(n, k) = map(int, input().split())
s = [int(x) for x in input().split()]
to = s.count(1)
te = s.count(-1)
ans = -1
for b in range(0, k):
	o = 0
	e = 0
	for d in range(b, n, k):
		if s[d] == 1:
			o = o + 1
		else:
			e = e + 1
	ans = max(ans, abs(to - o - te + e))
print(ans)


import sys
readline = sys.stdin.readline
(N, K) = map(int, readline().split())
A = list(map(int, readline().split()))
S = sum(A)
table = [0] * K
for i in range(N):
	table[i % K] += A[i]
res = 0
for i in range(K):
	res = max(res, abs(S - table[i]))
print(res)


(x, y) = map(int, input().split())
p = list(map(int, input().split()))
l = list()
i = 1
while i <= y:
	k = i
	su = sum(p)
	for j in range(x):
		if j + 1 == k:
			su -= p[j]
			k += y
	l.append(abs(su))
	i += 1
print(max(l))


(n, k) = map(int, input().split())
a = [*map(int, input().split())]
(t, s) = (a.count(1), a.count(-1))
(t1, t2) = (t, s)
ans = 0
for i in range(k):
	for j in range(i, n, k):
		if a[j] == 1:
			t1 -= 1
		else:
			t2 -= 1
	ans = max(abs(t1 - t2), ans)
	(t1, t2) = (t, s)
print(ans)


def dif(x, y):
	if x > y:
		return x - y
	return y - x

def main():
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	s = arr.count(-1)
	e = arr.count(1)
	max = 0
	for b in range(n):
		cs = 0
		ce = 0
		for i in range(-n, n):
			index = b + k * i
			if index < n and index > -1:
				if arr[index] == 1:
					ce += 1
				else:
					cs += 1
			elif index >= n:
				break
		re = e - ce
		rs = s - cs
		if dif(re, rs) > max:
			max = dif(re, rs)
	print(max)
main()


(n, k) = map(int, input().split())
mr = 0
a = list(map(int, input().split()))
for i in range(k):
	c = 0
	for j in range(n):
		if (j - i) % k != 0:
			c += a[j]
	mr = max(abs(c), mr)
print(mr)


import math as m
(n, k) = list(map(int, input().split()))
a = []
ab = 0
bel = 0
s = 0
e = 0
b = 0
count = 0
ans = 0
for i in range(n):
	a.append(0)
a = list(map(int, input().split()))
for i in range(len(a)):
	if a[i] > 0:
		ab = ab + 1
	if a[i] < 0:
		bel = bel + 1
while b <= k - 1:
	for i in range(len(a)):
		if b + i * k < n:
			if a[b + i * k] > 0:
				s = s + 1
				count = count + 1
			if a[b + i * k] < 0:
				e = e + 1
				count = count + 1
		if count == m.ceil((n - b) / k) and ans < m.fabs(ab - s - bel + e):
			ans = m.fabs(ab - s - bel + e)
			e = 0
			s = 0
			count = 0
		if count == m.ceil((n - b) / k) and ans >= m.fabs(ab - s - bel + e):
			e = 0
			s = 0
			count = 0
	b = b + 1
print(int(ans))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
e = a.count(1)
s = a.count(-1)
for i in range(0, k):
	(c, d) = (0, 0)
	for j in range(i, n, k):
		if a[j] == 1:
			c += 1
		elif a[j] == -1:
			d += 1
	ans = max(ans, abs(e - c - (s - d)))
print(ans)


(n, k) = [int(i) for i in input().split()]
ishki = []
sm = 0
mx = 0
a = [int(i) for i in input().split()]
for b in range(len(a)):
	i = b
	while i >= 0:
		ishki.append(i)
		i -= k
	i = b + k
	while i < len(a):
		ishki.append(i)
		i += k
	for i in range(len(a)):
		if not i in ishki:
			sm += a[i]
	if abs(sm) > mx:
		mx = abs(sm)
	ishki = []
	sm = 0
print(mx)


a = input()
(n, k) = a.split(' ')
n = int(n)
k = int(k)
i = input()
tab_type = list(map(int, i.split()))
max = 0
for b in range(0, n):
	tab = tab_type.copy()
	for i in range(-n, n):
		c = b + i * k
		if c >= 0 and c < n:
			tab[c] = 0
	s = tab.count(-1)
	e = tab.count(1)
	if abs(s - e) >= max:
		max = abs(s - e)
print(max)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = k * [sum(l)]
for i in range(k):
	j = i
	while j < n:
		a[i] -= l[j]
		j += k
print(max((abs(x) for x in a)))


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
s = []
for i in range(0, k):
	a = x.count(1)
	b = x.count(-1)
	g = i
	while g < n:
		if x[g] == 1:
			a -= 1
		else:
			b -= 1
		g += k
	s.append(abs(a - b))
print(max(s))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = 0
s = 0
ans = []
for z2 in range(k):
	temp = []
	c = 0
	s = 0
	for z in range(z2):
		if a[z] == 1:
			c += 1
		elif a[z] == -1:
			s += 1
	for z in range(z2, n):
		if (z - z2) % k != 0:
			if a[z] == 1:
				c += 1
			elif a[z] == -1:
				s += 1
	ans.append(abs(c - s))
print(max(ans))


in1 = input().split(' ')
(n, k) = (int(in1[0]), int(in1[1]))
arr = input().split(' ')
for i in range(n):
	arr[i] = int(arr[i])
mark = [0 for i in range(n)]
mx = 0
for i in range(k):
	j = i
	e = 0
	s = 0
	while j < n:
		mark[j] = 1
		j += k
	for j in range(n):
		if mark[j] == 1:
			continue
		if arr[j] == 1:
			e += 1
		else:
			s += 1
	mx = max(mx, abs(e - s))
	for i in range(n):
		mark[i] = 0
print(mx)


s = input()
s = s.split()
n = int(s[0])
k = int(s[1])
s2 = [int(x) for x in input().split()]
ans = -100000
for b in range(1, k + 1):
	e = 0
	for i in range(0, n):
		if (i - b) % k != 0:
			e += s2[i]
	ans = max(ans, abs(e))
print(ans)


(n, k) = (int(s) for s in input().split(' '))
a = [int(s) for s in input().split(' ')]
sum = 0
for i in range(n):
	sum += a[i]
ans = 0
for i in range(k):
	sum1 = sum
	for j in range(i, n, k):
		sum1 -= a[j]
	ans = max(ans, abs(sum1))
print(ans)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
ans = 0
for i in range(k):
	s = arr + [0]
	t = i
	while t < n:
		s[t] = 0
		t += k
	ans = max(ans, abs(sum(s)))
print(ans)


(a, steps) = [int(x) for x in input().split()]
tabs = [int(x) for x in input().split()]
_sum = -1 * a
__sum = sum(tabs)
for i in range(steps):
	arr = tabs[i::steps]
	_sum = max(abs(__sum - sum(arr)), _sum)
print(_sum)


(n, k) = [int(z) for z in input().split()]
v = [int(z) for z in input().split()]
md = -1
for b in range(k):
	td = 0
	for i in range(n):
		if (i - b) % k == 0:
			continue
		td += v[i]
	md = max([md, abs(td)])
print(md)


from sys import stdin, stdout
from math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial
from random import randint
(n, k) = map(int, stdin.readline().split())
vl = list(map(int, stdin.readline().split()))
aa = vl.count(1)
bb = vl.count(-1)
ans = 0
for i in range(k):
	(a, b) = (0, 0)
	for z in range(i, n, k):
		if vl[z] == 1:
			a += 1
		else:
			b += 1
	a = aa - a
	b = bb - b
	ans = max(ans, abs(a - b))
stdout.write(str(ans))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * k
max = 0
for i in range(k):
	for j in range(n):
		if (j + 1) % k == i:
			continue
		b[i] = b[i] + a[j]
	if b[i] < 0:
		b[i] = -b[i]
	if i == 0:
		max = b[0]
	if b[i] > max:
		max = b[i]
print(max)


def solve(n, k, arr):
	ans = 0
	test = arr.count(1)
	social = arr.count(-1)
	for i in range(n):
		tempTest = 0
		tempSocial = 0
		for j in range(i, n, k):
			if arr[j] == 1:
				tempTest += 1
			else:
				tempSocial += 1
		for j in range(i - k, -1, -k):
			if arr[j] == 1:
				tempTest += 1
			else:
				tempSocial += 1
		calc = abs(test - tempTest - (social - tempSocial))
		ans = max(calc, ans)
	print(ans)

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


from sys import stdin, stdout
I = stdin.readline
P = stdout.write
(n, k) = map(int, I().split())
arr = [int(x) for x in I().split()]
e = 0
s = 0
ans = 0
for i in arr:
	if i == -1:
		s += 1
	else:
		e += 1
for i in range(0, k):
	ce = 0
	cs = 0
	for j in range(i, n, k):
		if arr[j] == -1:
			cs += 1
		else:
			ce += 1
	x = e - ce
	y = s - cs
	if abs(x - y) > ans:
		ans = abs(x - y)
print(ans)


(n, k) = map(int, input().split())
tabs = list(map(int, input().split()))
res = 0
for i in range(k):
	ii = i
	while i < n:
		tabs[i] -= 1
		i += k
	temp = abs(tabs.count(1) - tabs.count(-1))
	if temp > res:
		res = temp
	while ii < n:
		tabs[ii] += 1
		ii += k
print(res)


def calc(a, k, b):
	for i in range(b, len(a), k):
		a[i] = 0
	e = sum([1 for x in a if x == 1])
	s = sum([1 for x in a if x == -1])
	return abs(e - s)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
m = 0
for b in range(0, k):
	m = max(m, calc(a[:], k, b))
print(m)


import math
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
c1 = 0
c2 = 0
for i in arr:
	if i == 1:
		c1 += 1
	else:
		c2 += 1
mm = 0
for i in range(k):
	c11 = 0
	c22 = 0
	for j in range(i, n, k):
		if arr[j] == 1:
			c11 += 1
		else:
			c22 += 1
	yy = abs(c1 - c11 - (c2 - c22))
	if yy > mm:
		mm = yy
print(mm)


l = input().split()
(n, k) = (int(l[0]), int(l[1]))
arr = list(map(int, input().split()))
lis = []
(c1, cm1) = (0, 0)
for x in arr:
	if x == -1:
		cm1 += 1
	else:
		c1 += 1
for i in range(k):
	(x1, x2) = (c1, cm1)
	for j in range(i, n, k):
		if arr[j] == 1:
			x1 -= 1
		else:
			x2 -= 1
	lis.append(abs(x1 - x2))
print(max(lis))


(n, k) = map(int, input().split())
tabs = list(map(int, input().split()))
count_to_delete = n // k + 1
max_sum = 0
for i in range(k):
	ctabs = tabs.copy()
	for j in range(count_to_delete):
		try:
			ctabs[i + j * k] = 0
		except IndexError:
			break
	max_sum = max(max_sum, abs(sum(ctabs)))
print(max_sum)


(n, k) = [int(i) for i in input().split()]
ar = [int(i) for i in input().split()]
was = [False] * n
(e, s) = (0, 0)
for i in ar:
	if i == 1:
		e += 1
	else:
		s += 1
ans = 0
for i in range(n):
	if not was[i]:
		(d1, d2) = (0, 0)
		for j in range(i, n, k):
			was[j] = True
			if ar[j] == 1:
				d1 += 1
			else:
				d2 += 1
		ans = max(ans, abs(e - d1 - s + d2))
print(ans)


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
mx = 0
for b in range(n):
	s = []
	for i in range(n):
		if abs(b - i) % k:
			s.append(l[i])
	mx = max(mx, abs(sum(s)))
print(mx)


(n, interval) = [int(item) for item in input().split()]
page_type = [int(item) for item in input().split()]
exams = 0
social_media = 0
answer = 0
for page in page_type:
	if page == 1:
		exams += 1
	else:
		social_media += 1
for remainder in range(interval):
	differ = 0
	for page_num in range(remainder, len(page_type), interval):
		differ += page_type[page_num]
	answer = max(abs(exams - social_media - differ), answer)
print(answer)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
m = 0
for l in range(k):
	use = [True] * n
	for i in range(l, n, k):
		use[i] = False
	b = 0
	for i in range(n):
		if use[i]:
			b += a[i]
	if abs(b) > m:
		m = abs(b)
print(m)


s = input().split()
n = int(s[0])
k = int(s[1])
tabs = [int(i) for i in input().split()]
res = 0
for u in range(n):
	soc = 0
	st = 0
	for (i, tab) in enumerate(tabs):
		if (i - u) % k != 0:
			if tab < 0:
				soc += 1
			else:
				st += 1
	if res < abs(soc - st):
		res = abs(soc - st)
print(res)


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import PriorityQueue as pq
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
x = dc(list)
(t, s) = (0, 0)
for i in l:
	if i == 1:
		t += 1
	else:
		s += 1
for i in range(k):
	x[i] = [t, s]
for i in range(n):
	if l[i] == 1:
		x[i % k][0] -= 1
	else:
		x[i % k][1] -= 1
m = 0
for i in range(k):
	m = max(m, abs(x[i][0] - x[i][1]))
print(m)


(n, k) = map(int, input().split())
tabs = list(map(int, input().split()))
diff = [abs(sum(tabs) - sum(tabs[u::k])) for u in range(k)]
print(max(diff))


(n, k) = [int(p) for p in input().split()]
arr = [int(p) for p in input().split()]
social = arr.count(-1)
test = arr.count(1)
m = 0
for j in range(k):
	(e, s) = (test, social)
	for i in arr[j:len(arr):k]:
		if i == -1:
			s -= 1
		else:
			e -= 1
	m = max(m, abs(s - e))
print(m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
n1 = a.count(1)
n2 = n - n1
mi = -1
for m in range(k):
	t = a[m::k]
	s = t.count(1)
	s_ = len(t) - s
	if abs(n1 - s + s_ - n2) > mi:
		mi = abs(n1 - s + s_ - n2)
print(mi)


(n, k) = list(map(int, input().split()))
tabs = list(map(int, input().split()))
total = sum(tabs)
max_ = 0
for i in range(n):
	infl = sum([tabs[j] for j in range(i, n, k)])
	infl += sum([tabs[j] for j in range(i, -1, -k)][1:])
	max_ = max(abs(total - infl), max_)
print(max_)


(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
max = -10 ** 10
for b in range(n):
	e = 0
	s = 0
	closed = set()
	for i in range(b, len(a), k):
		closed.add(i)
	for i in range(b, -1, -k):
		closed.add(i)
	for i in range(len(a)):
		if i not in closed:
			if a[i] == -1:
				e += 1
			else:
				s += 1
	if abs(e - s) > max:
		max = abs(e - s)
print(max)


(n, k) = input().split()
s = input()
i = list(map(int, s.split()))
n = int(n)
k = int(k)
max = 0
for indice in range(k):
	ni = i[:]
	while indice < n:
		ni[indice] = 0
		indice += k
	val = abs(ni.count(1) - ni.count(-1))
	if val > max:
		max = val
print(max)


def main():
	(n, k) = [int(i) for i in input().split()]
	numbers_to_tests = n // k
	pages = [int(i) for i in input().split()]

	def test(pages, k, n):
		answers = []
		for x in range(k):
			tests = 0
			socials = 0
			for i in range(1, n + 1):
				if (i + x) % k != 0:
					if pages[i - 1] == 1:
						tests += 1
					else:
						socials -= 1
			answers.append(abs(tests - abs(socials)))
		return max(answers)
	print(test(pages, k, n))
main()


import sys
(n, k) = map(int, sys.stdin.readline().split())
l = list(map(int, sys.stdin.readline().split()))
ans = 0
for b in range(n):
	maxx = 0
	for i in range(n):
		if i % k != b % k:
			maxx += l[i]
	ans = max(abs(maxx), ans)
print(ans)


import sys
from collections import defaultdict as dd
input = sys.stdin.readline
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
m = -19876543
su = sum(l)
for i in range(k):
	s = 0
	for j in range(i, n, k):
		s += l[j]
	if abs(su - s) > m:
		m = abs(su - s)
print(m)


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter, OrderedDict
import threading

def main():
	(n, k) = map(int, input().split())
	D = [*map(int, input().split())]
	ans = 0
	for i in range(k):
		A = []
		for j in range(n):
			if j % k == i % k:
				continue
			A.append(D[j])
		(x, y) = (0, 0)
		for j in range(len(A)):
			if A[j] == 1:
				x += 1
			else:
				y += 1
		ans = max(ans, abs(x - y))
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(m, n) = map(int, input().split())
(b, l) = (0, list(map(int, input().split())))
for y in range(n):
	k = l.copy()
	for x in range(y, m, n):
		k[x] = 0
	b = max(b, abs(k.count(1) - k.count(-1)))
print(b)


import sys

def main():
	strArgs = sys.stdin.readline().rstrip('\n').split(' ')
	n = int(strArgs[0])
	k = int(strArgs[1])
	vals = list(map(int, sys.stdin.readline().rstrip('\n').split(' ')))
	valsSum = sum(vals)
	maxAbsSum = 0
	for start in range(k):
		sum1 = 0
		for i in range(start, len(vals), k):
			sum1 += vals[i]
		maxAbsSum = max(abs(valsSum - sum1), maxAbsSum)
	print(maxAbsSum)
main()


from math import *
(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
ans = 0
for i in range(0, n):
	mark = [0] * n
	curr = i
	mark[i] = 1
	while curr < n:
		mark[curr] = 1
		curr += k
	curr = i
	while curr >= 0:
		mark[curr] = 1
		curr -= k
	e = 0
	s = 0
	for j in range(n):
		if mark[j] == 0:
			if a[j] == 1:
				e += 1
			else:
				s += 1
	ans = max(ans, abs(e - s))
print(ans)


[n, k] = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr1 = [0] * (n + 1)
for i in range(1, n + 1):
	arr1[i] = arr[i - 1]
sm = sum(arr1)
sol = 0
for i in range(1, k + 1):
	ans = 0
	for j in range(i, n + 1, k):
		ans += arr1[j]
	sol = max(sol, abs(sm - ans))
print(sol)


(n, m) = map(int, input().split())
li = list(map(int, input().split()))
sub = [0 for i in range(m)]
for i in range(n):
	sub[i % m] += li[i]
tot = 0
for i in range(m):
	tot = max(tot, abs(sum(sub) - sub[i]))
print(tot)


(n, k) = map(int, input().split())
dat = []
dat = list(map(int, input().split()))
dat.insert(0, 0)
dif = 0
for b in range(n):
	diff = 0
	tdat = dat.copy()
	imin = int((1 - b) / k)
	imax = int((n - b) / k)
	for i in range(imin, imax + 1):
		tdat[b + i * k] = 0
	diff = abs(tdat.count(1) - tdat.count(-1))
	if dif < diff:
		dif = diff
print(dif)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
et = s.count(1)
st = s.count(-1)
md = []
for i in range(0, k):
	j = i
	etc = et
	stc = st
	while j <= n - 1:
		if s[j] == -1:
			stc -= 1
		if s[j] == 1:
			etc -= 1
		j += k
	md.append(abs(etc - stc))
print(max(md))


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
i = 0
pos = 1
neg = -1
ans = []
while i < k:
	b = a[:]
	for j in range(i, n, k):
		b[j] = 0
	ans.append(abs(b.count(pos) - b.count(neg)))
	i += 1
print(max(ans))


import math
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
res = 0
for b in range(n):
	check = [True] * n
	temp = int(-b / k)
	while b + temp * k <= n - 1:
		check[b + temp * k] = False
		temp = temp + 1
	cnt1 = 0
	cnt0 = 0
	for x in range(n):
		if check[x] == True and a[x] == 1:
			cnt1 = cnt1 + 1
		if check[x] == True and a[x] == -1:
			cnt0 = cnt0 + 1
	if abs(cnt1 - cnt0) > res:
		res = abs(cnt1 - cnt0)
print(res)


(n, k) = map(int, input().split())
inp = list(map(int, input().split()))
ans = 0
for i in range(k):
	cnt = 0
	for j in range(i, n, k):
		cnt += inp[j]
	ans = max(ans, abs(sum(inp) - cnt))
print(ans)


(n, k) = input().split()
l = input().split()
d = {}
ans = []
for b in range(1, int(int(k) + 1)):
	if d.__contains__(b):
		break
	else:
		e = 0
		s = 0
		for i in range(len(l)):
			if (i + 1 - b) % int(k) == 0:
				d[i + 1] = b
			elif int(l[i]) + 1:
				e = e + 1
			else:
				s = s + 1
	ans.append(abs(e - s))
print(max(ans))