CodeEff/ECCO huggingface dataset:
# Original solution
from collections import deque

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

# loopに入ったらおしまい
record = deque([X,])
finished = False
while K > 0:
    if X > 0:
        X -= D
    else:
        X += D
    record.append(X)
    if len(record) > 3:
        record.popleft()
    if record[0] == record[-1]:
        if K % 2 == 0:
            print((abs(record[1])))
        else:
            print((abs(record[0])))
        finished = True
        break
    K -= 1     

if not finished:
    print((abs(X)))


# Optimized solution
from collections import deque

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

# まずは何回目で符号が逆転するかを算出
num_reverse = abs(X) // D + 1
if num_reverse > K:
    print((abs(X) - (K * D)))
else:
    K -= num_reverse
    ans = abs(X) - (num_reverse * D)
    if K % 2 == 0:
        print((abs(ans)))
    else:
        print((abs(abs(ans) - D)))
# Original solution
x,k,d=list(map(int,input().split()))
x=abs(x)

if x-k*d>=0:
    print((x-k*d))
else:
    a=x
    while a>d:
        a-=d
        k-=1
    if k%2==0:
        print((min(a,2*d-a)))
    else:
        print((min(d-a,a+d)))

# Optimized solution
x,k,d=list(map(int,input().split()))
x=abs(x)

if x-k*d>=0:
    print((x-k*d))
else:
    n=x//d
    k-=n
    a=x-n*d
    if k%2==0:
        print((min(a,2*d-a)))
    else:
        print((min(d-a,a+d)))
# Original solution
# ABC172　C - Walking Takahashi
X,K,D=list(map(int,input().split()))

q=abs(X)//D
if q>K:
    print((abs(X)-K*D))
else:
    if (K-q)%2==0:
        print((abs(X)-q*D))
    else:
        print((abs(abs(X)-(q+1)*D)))

# Optimized solution
# ABC172　C - Walking Takahashi
X,K,D=list(map(int,input().split()))

X=abs(X)
q=X//D
if q>K:
    print((X-K*D))
else:
    if (K-q)%2==0:
        print((X-q*D))
    else:
        print((-X+(q+1)*D))
# Original solution
x, k, d = list(map(int, input().split()))
if x < 0:
    x *= -1
cnt = 0
while x > 0 and cnt < k:
    x -= d
    cnt += 1
if abs(x) < x+d:
    x += d
    cnt -= 1
    x -= d * ((k-cnt)%2)
else:
    x += d * ((k-cnt)%2)
print((abs(x)))

# Optimized solution
x, k, d = list(map(int, input().split()))
if x < 0:
    x *= -1
cnt = min(k, x//d+1)
x -= cnt * d
if abs(x) < x+d:
    x += d
    cnt -= 1
    x -= d * ((k-cnt)%2)
else:
    x += d * ((k-cnt)%2)
print((abs(x)))
# Original solution
X, K, D = list(map(int, input().split()))
X = abs(X)

if X >= D * K:
  print((X - D * K))
else:
  K -= int(X / D)
  for i in range(0, int(X/D)):
    X -= D
  if K % 2:
    print((D - X))
  else:
    print(X)

# Optimized solution
X, K, D = list(map(int, input().split()))
X = abs(X)

if X >= D * K:
  print((X - D * K))
else:
  K -= int(X / D)
  # for i in range(0, int(X/D)):
  #   X -= D
  X %= D
  if K % 2:
    print((D - X))
  else:
    print(X)
# Original solution
x, k, d = list(map(int, input().split()))

# 0をまたぐかで場合わけ
if x == 0:
    if k % 2 == 0:
        print((0))
    else:
        print(d)
    exit()

x = abs(x)

if x-k*d <= 0:
    # 0をまたぐ
    a, b = divmod(x, d)
    if (k-a) % 2 == 0:
        print(b)
    else:
        print((min(b+d, d-b)))
else:
    # 0をまたがない
    print((x-k*d))


# Optimized solution
x, k, d = list(map(int, input().split()))
x = abs(x)

MIN = x-k*d


if 0 <= MIN:
    print(MIN)
else:
    a, R = divmod(x, d)
    L = d-R
    cnt = k-a
    if cnt % 2 == 0:
        print(R)
    else:
        print(L)
# Original solution
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

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

def main():
    x,k,d = readInt()
    count = abs(x) // d
    mn = 0
    if count>k:
        mn = abs(x) - (d * k)
        print(mn)
        return
    else:
        mn = abs(x) % d
    ans = INF
    if (k-count)%2==0:
        ans = mn
    else:
        ans = abs(mn-d)
    print(ans)
    return

if __name__=='__main__':
    main()


# Optimized solution
X,K,D = list(map(int,input().split()))
# 原点に近い位置までの移動回数を求める
count = abs(X) // D
ans = 0
if count>K:
    ans = abs(X) - D * K
else:
    if (K-count)%2==0:
        ans = abs(X) % D
    else:
        ans = abs(abs(X) % D - D)
print(ans)
# Original solution
X, K, D = list(map(int, input().split()))

if abs(X) <= D * K:
    for i in range(K):
        a = abs(X) - (D * (i + 1))
        b = abs(X) - (D * i)
        if a < 0:
            break
    if abs(a) < abs(b):
        c = K - (i + 1)
        if c % 2 == 0:
            if 0 <= X:
                goal = a
            else:
                goal = -a
        else:
            if 0 <= X:
                goal = b
            else:
                goal = -b

    if abs(b) <= abs(a):
        c = K - i
        if c % 2 == 0:
            if 0 <= X:
                goal = b
            else:
                goal = -b
        else:
            if 0 <= X:
                goal = a
            else:
                goal = -a
else:
    if 0 <= X:
        goal = X - D * K
    else:
        goal = X + D * K

print((abs(goal)))

# Optimized solution
X, K, D = list(map(int, input().split()))

if abs(X) < (K * D):
    a = abs(X) % D
    b = abs(D - a)
    c = abs(X) // D + 1
    if (K - c) % 2 == 0:
        goal = b
    else:
        goal = a
else:
    goal = abs(X) - ( D * K )

print(goal)
# Original solution
X,K,D = list(map(int,input().split()))
X = abs(X)
if X-K*D>=0:
    print((X-K*D))
else:
    while(X > 0 and K > 0):
        K = K-1
        X = X-D
    if K % 2 == 0:
        print((abs(X)))
    else:
        X = X+D
        print(X)

# Optimized solution
X,K,D = list(map(int,input().split()))
X = abs(X)
N = X//D
if N>K:
    N=K
X = X-N*D
K -= N
if K%2 == 0:
    print(X)
else:
    X -= D
    print((abs(X)))
# Original solution
x, k, d = list(map(int, input().split()))

past1_x = 0
past2_x = 0

result = 0

for i in range(k):
	past2_x = past1_x
	past1_x = x
	if x > 0:
		x -= d
	else:
		x += d
	
	if (past2_x == x and i != 0) or i == k - 1:
		if (k - i) % 2 == 0:
			result = abs(past1_x)
		else:
			result = abs(x)
		break

print(result)

# Optimized solution
x, k, d = list(map(int, input().split()))

result = 0

abs_x = abs(x)
firstNearestIterNum = abs_x // d

if firstNearestIterNum >= k:
	result = abs_x - (d * k)
else:
	if (k - firstNearestIterNum) % 2 == 1:
		result = abs_x - (d * (firstNearestIterNum + 1))
	else:
		result = abs_x - d * firstNearestIterNum

print((abs(result)))
# Original solution
X, K, D = list(map(int, input().split()))

X = abs(X)

final = -1

for n in range(K):
  X = abs(X - D)
  if X <= D / 2:
    if (K-n) % 2 == 0:
      final = abs(X-D)
      break
    else:
      final = X
      break

if final >= 0:
  print(final)
else:
  print(X)

# Optimized solution
X, K, D = list(map(int, input().split()))

X = abs(X)

final = -1

q, n = X % D, X // D

if n >= K:
  print((X - K * D))
else:
  if q <= X / 2:
    if (K - n) % 2 == 0:
      print(q)
    else:
      print((D - q))
  else:
    if (K - n) % 2 == 0:
      print(q)
    else:
      print((D - q))
# Original solution
import sys
X,K,D= list(map(int,input().split()))
temp = X
for t in range(K):
    # 絶対値の小さい方に移動
    if abs(temp - D) < abs(temp + D):
        temp = temp-D
    else:
        temp = temp+D

    # 移動幅より小さくなったとき
    if abs(temp) < D:
        if (K-t-1) % 2 == 0:
            print((abs(temp)))
            sys.exit()
        else:
            if abs(temp - D) < abs(temp + D):
                temp = temp-D
                print((abs(temp)))
                sys.exit()
            else:
                temp = temp+D
                print((abs(temp)))
                sys.exit()

print((abs(temp)))



# Optimized solution
import sys
X,K,D= list(map(int,input().split()))
temp = X

if abs(X) > K*D:
    print((abs(X)-K*D))
    sys.exit()
    
for t in range(K):
    # 絶対値の小さい方に移動
    if abs(temp - D) < abs(temp + D):
        temp = temp-D
    else:
        temp = temp+D

    # 移動幅より小さくなったとき
    if abs(temp) < D:
        if (K-t-1) % 2 == 0:
            print((abs(temp)))
            sys.exit()
        else:
            if abs(temp - D) < abs(temp + D):
                temp = temp-D
                print((abs(temp)))
                sys.exit()
            else:
                temp = temp+D
                print((abs(temp)))
                sys.exit()

print((abs(temp)))
# Original solution
X, K, D = list(map(int, input().split()))

if X == 0:
    print((0 if K % 2 == 0 else D))
elif X < 0:

    div = abs(X) // D
    tmp = X + D*div

    if div >= K:
        print((abs(X + D*K)))
    elif div < K:
        K -= div
        print((abs(tmp) if K % 2 == 0 else abs(tmp+D)))    

else:

    div = abs(X) // D
    tmp = X - D*div

    if div >= K:
        print((abs(X - D*K)))
    elif div < K:
        K -= div
        print((abs(tmp) if K % 2 == 0 else abs(tmp-D)))




# Optimized solution
X, K, D = list(map(int, input().split()))
X = abs(X)

ans = 0
if X // D > K:
    ans = X - D*K
else:
    e = X // D
    K -= e
    X -= D * e
    if K % 2 == 1: X = abs(X-D)
    ans = X

print(ans)
# Original solution
X, K, D = list(map(int, input().split()))
X = abs(X)

ans = 0
if X // D > K:
    ans = X - D*K
else:
    e = X // D
    K -= e
    X -= D * e
    if K % 2 == 1: X = abs(X-D)
    ans = X

print(ans)

# Optimized solution
X, K, D = list(map(int, input().split()))

X = abs(X)

if X // D >= K:
    print((X - D*K))
else:
    e = X // D
    K -= e
    X -= D*e

    if K % 2 == 1:
        X = abs(X-D)

    print(X)
# Original solution
x,k,d = list(map(int,input().split()))

tmp = abs(x) % d
cal = abs(x) // d
if tmp > abs(tmp - d):
    cal += 1
    tmp = abs(tmp - d)

if cal == k:
    print(tmp)
elif cal > k:
    print((abs(x) - k*d))
else:
    if (k - cal) % 2 == 0:
        print(tmp)
    else:
        print((min(abs(tmp-d),abs(tmp+d))))

# Optimized solution
x,k,d = list(map(int,input().split()))

ans = abs(x) % d
cal = abs(x) // d
if ans > abs(ans - d):
    cal += 1
    ans = abs(ans - d)

if cal > k:
    ans = abs(x) - k*d
else:
    if (k - cal) % 2 == 1:
        ans = min(abs(ans-d),abs(ans+d))

print(ans)
# Original solution
X, K, D = list(map(int ,input().split()))

if K * D < abs(X):
    ans = abs(X) - K * D
else:
    if abs(X) // D % 2 == 0:
        if K % 2 == 0:
            ans = abs(X) % D
        else:
            ans = abs(abs(X) % D - D)
    else:
        if K % 2 == 0:
            ans = abs(abs(X) % D - D)
        else:
            ans = abs(X) % D

print(ans)

# Optimized solution
X, K, D = list(map(int ,input().split()))

X = abs(X)
if K * D < X:
    ans = X - K * D
else:
    if X // D % 2 == 0:
        if K % 2 == 0:
            ans = X % D
        else:
            ans = abs(X % D - D)
    else:
        if K % 2 == 0:
            ans = abs(X % D - D)
        else:
            ans = X % D

print(ans)
# Original solution
X, K, D = list(map(int ,input().split()))

X = abs(X)
if X // D > K:
    ans = X - K * D
else:
    if X // D % 2 == 0:
        if K % 2 == 0:
            ans = X % D
        else:
            ans = abs(X % D - D)
    else:
        if K % 2 == 0:
            ans = abs(X % D - D)
        else:
            ans = X % D

print(ans)


# Optimized solution
X, K, D = list(map(int ,input().split()))

X = abs(X)
if X // D > K:
    ans = X - K * D
else:
    if X // D % 2 == K % 2:
        ans = X % D
    else:
        ans = abs(X % D - D)
print(ans)
# Original solution
a = list(input().split(" "))
x = int(a[0])
if x < 0:
    x *= -1
k = int(a[1])
d = int(a[2])

for i in range(k):
    x -= d
    if x <= 0:
        if (k - i) % 2 == 1:
            x *= -1
            break
        else:
            x += d
            break

print(x)

# Optimized solution
a = list(input().split(" "))
x = int(a[0])
if x < 0:
    x *= -1
k = int(a[1])
d = int(a[2])
c = x // d

if c >= k:
    x -= d * k
else:
    x -= d * c
    if (k - c) % 2 == 1:
        x = (x - d) * -1

print(x)
# Original solution
X, K, D = [int(a) for a in list(input().split())]
X = abs(X)
for i in range(X//D):
    X -= D
    K -= 1
    if K == 0:
        print((abs(X)))
        exit()
if K % 2 == 0:
    print(X)
else:
    print((abs(X-D)))

# Optimized solution
X, K, D = [int(a) for a in list(input().split())]
X = abs(X) 
q = X//D
r = X%D
if q >= K:
    print((X - D*K))
    exit()
rem = K - q
if rem % 2 == 0:
    print(r)
else:
    print((abs(D-r)))
# Original solution
X, K, D = list(map(int, input().split()))

for i in range(K):
    if (abs(X) > D):
        X = abs(X) - D
    else:
        if ((K - i) % 2 == 0):
            break
        else:
            X = X - D
            break

print((abs(X)))


# Optimized solution
X, K, D = list(map(int, input().split()))

syou = abs(X) // D


if (K > syou):
    K = K - syou
    if ((K % 2) == 0):
        print((abs(abs(X) - D * syou)))
    else:
        print((abs(abs(X)-D*(syou+1))))
else:
    print((abs(abs(X)-D*K)))
# Original solution
# -*- coding: utf-8 -*-
x,k,d=list(map(int,input().split()))
m=abs(x)
n=0
for i in range(k):
  if x<0:
    x+=d
  else:
    x-=d
  if abs(x)<m:
    m=abs(x)
  else:
    n=k-i
    break
if n%2==0:
  print(m)
else:
  print((abs(x)))

# Optimized solution
# -*- coding: utf-8 -*-
x,k,d=list(map(int,input().split()))
m=abs(x)
n=m//d
j=k-n
if j>0:
  if x<0:
    if j%2==0:
      x+=d*n
    else:
      x+=d*(n+1)
  else:
    if j%2==0:
      x-=d*n
    else:
      x-=d*(n+1)
else:
  if x<0:
    x+=d*k
  else:
    x-=d*k
print((abs(x)))
# Original solution
X,K,D=list(map(int,input().split()))
i=0
count=0
if X<0:
	if X+K*D<=0:
		print((abs(X+K*D)))
		count+=1
	else:
		L=X+i*D
		while L<=0:
			i+=1
			L=X+i*D
		if abs(L)>=abs(X+(i+1)*D):
			i+=1
			L=abs(X+i*D)
else:
	if X-K*D>=0:
		print((abs(X-K*D)))
		count+=1
	else:
		L=X-i*D
		while L>=0:
			i+=1
			L=X-i*D
		if abs(L)>=abs(X-(i-1)*D):
			i-=1
			L=abs(X-i*D)
if count==0:
	kaisuu=K-i
	if kaisuu%2==0:
		print((abs(L)))

	else:
		a=abs(L+D)
		b=abs(L-D)
		if a<=b:
			print(a)
		else:
			print(b)

		

# Optimized solution
X,K,D=list(map(int,input().split()))
X=abs(X)
count=0

if X-K*D>=0:
	print((X-K*D))
else:
	s=int(X/D)
	kaisuu=K-s
	if kaisuu%2==0:
		print((abs(X-s*D)))
	else:
		print((abs(X-(s+1)*D)))
# Original solution
x,k,d = list(map(int, input().split()))
x_min = abs(x)
for i in range(k):
    if x < 0:
        x += d
        if abs(x) < x_min:
            x_min = abs(x)
        else:#xが0以上
            if (k - i - 1) % 2 == 1:
                break
            else:
                x_min = d - x_min
                break
    else:
        x -= d
        if abs(x) < x_min:
            x_min = abs(x)
        else:#xが負
            if (k - i - 1) % 2 == 1:
                break
            else:
                x_min = d - x_min
                break
print(x_min)

# Optimized solution
x,k,d = list(map(int, input().split()))
if x < 0:
    x = -x
x_min = x
if x//d >= k:
    x_min -= k * d
else:
    x_min -= x//d * d
    k -= x//d
    if k % 2 == 1:
        x_min = abs(x_min - d)
print(x_min)
#xが更新されてる！！
# Original solution
x, k, d = list(map(int, input().split()))

if abs(x)-d*k>=0:
    print((abs(x)-d*k))
    exit()


num = 0

while k>0:
    s = abs(x)
    s = s-d
    if abs(s)>=abs(x):
        break
    x = abs(s)
    k -= 1


if k == 0:
    print((abs(s)))
    exit()

if k%2 == 0:
    print((abs(x)))
else:
    print((abs(s)))

# Optimized solution
x, k, d = list(map(int, input().split()))
n = abs(x)//d

if n>=k:
    print((abs(x)-d*k))
else:
    if (k-n)%2 == 0:
        print((abs(abs(x)-d*n)))
    else:
        print((abs(abs(x)-d*(n+1))))
# Original solution
x,k,d=list(map(int,input().split()))
m=0
p=0
eo=k
ans=x
for i in range(1,k+1):
  m,p=abs(ans-d),abs(ans+d)
  ans=min(m,p)
  if ans<=d:
    eo=i
    break
if (k-eo)%2==0 and eo<k:
  print(ans)
elif (k-eo)%2==1 and eo<k:
  print((abs(ans-d)))
else:
   print(ans)

# Optimized solution
x,k,d=list(map(int,input().split()))
if abs(x)-k*d>=0:
  print((abs(x)-k*d))
else:
  xx,kk=abs(x)-d*(abs(x)//d),k-(abs(x)//d)
  if kk%2==0:
    print((abs(xx)))
  else:
    print((abs(xx-d)))
# Original solution
N, K = list(map(int ,input().split(' ')))
P = list(map(int ,input().split(' ')))
P_set = [ P[i:i+K] for i in range(0, len(P)) if len(P[i:i+K])==K]

E = []
for dices in P_set:
    E.append(sum([sum([i for i in range(1,dice+1)]) / float(dice) for dice in dices]))
    
print(('{:.12f}'.format(max(E))))

# Optimized solution
N, K = list(map(int ,input().split(' ')))
P = list(map(int ,input().split(' ')))

dct = {}
for i in range(0, len(P)):
    if len(P[i:i+K])==K:
        p_k = P[i:i+K]
        dct[sum(p_k)] = p_k

E = sum([sum([i for i in range(1,dice+1)]) / dice for dice in dct[max(dct)]])
print(('{:.12f}'.format(E)))
# Original solution
N, K = list(map(int ,input().split(' ')))
P = list(map(int ,input().split(' ')))

dct = {}
for i in range(0, len(P)):
    if len(P[i:i+K])==K:
        p_k = P[i:i+K]
        dct[sum(p_k)] = p_k

E = sum([sum([i for i in range(1,dice+1)]) / dice for dice in dct[max(dct)]])
print(('{:.12f}'.format(E)))

# Optimized solution
N, K = list(map(int ,input().split(' ')))
P = list(map(int ,input().split(' ')))

max_k = 0
max_v = []
for i in range(0, len(P)):
    if len(P[i:i+K])==K:
        p_k = P[i:i+K]
        if max_k<=sum(p_k):
            max_k=sum(p_k)
            max_v=p_k

E = sum([sum([i for i in range(1,dice+1)]) / dice for dice in max_v])
print(('{:.12f}'.format(E)))
# Original solution
import math

n,k = input().split()
p = input().split()

n = int(n)
k = int(k)

ex =0
ext = []
ext2 = []
for f in range(n):
    xs = list(range(1,int(p[f])+1))
    xs = sum(xs)*1/int(p[f])
    ext.append(xs)

ext2.append(ext[0])
for i in range(1,n):
    ext2.append(ext2[i-1]+ext[i])

ex = ext2[k-1]
for j in range(1,n-k+1):
    ext3 =ext2[j+k-1]-ext2[j-1]
    if ext3 > ex: ex = ext3

print(('{:.12f}'.format(ex)))

# Optimized solution
import math

n,k = input().split()
p = input().split()

n = int(n)
k = int(k)
#p = [int(s) for s in p]

#print(p)

ex =0
ext = []
ext2 = []
for f in range(n):
    pi = int(p[f])
    xs =(pi+1)/2
    ext.append(xs)

ext2.append(ext[0])
for i in range(1,n):
    ext2.append(ext2[i-1]+ext[i])

ex = ext2[k-1]
for j in range(1,n-k+1):
    ext3 =ext2[j+k-1]-ext2[j-1]
    if ext3 > ex: ex = ext3

print(('{:.12f}'.format(ex)))
# Original solution
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

pos = 0
saidai = 0
for i in range(N-K+1):
  temp = sum(list([(x+1)/2 for x in p[i:i+K]]))
  if saidai < temp:
    saidai = temp
print(('{:.12f}'.format(saidai)))

# Optimized solution
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
 
now = sum(p[:K])
saidai = now
for i in range(K, N):
  now -= p[i-K]
  now += p[i]
  if now > saidai:
    saidai = now
 
print(('{:.12f}'.format((saidai + K)/2)))
# Original solution
import queue

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

for i in range(len(p)):
    p[i] = p[i] + 1

queue = queue.Queue()
currentSum = 0
maxSum = 0
for i in range(len(p)):
    currentSum = currentSum + p[i]
    queue.put(p[i])
    if i >= K:
        currentSum = currentSum - queue.get()

    if i >= K - 1:
        maxSum = max(maxSum, currentSum)

print(("{:.12f}".format(maxSum / 2)))


# Optimized solution
import queue

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

queue = queue.Queue()
currentSum = 0
maxSum = 0
for i in range(len(p)):
    currentSum = currentSum + p[i] + 1
    queue.put(p[i] + 1)
    if i >= K:
        currentSum = currentSum - queue.get()

    if i >= K - 1:
        maxSum = max(maxSum, currentSum)

print(("{:.12f}".format(maxSum / 2)))
# Original solution
import queue

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

queue = queue.Queue()
currentSum = 0
maxSum = 0
for i in range(len(p)):
    currentSum = currentSum + p[i] + 1
    queue.put(p[i] + 1)
    if i >= K:
        currentSum = currentSum - queue.get()

    if i >= K - 1:
        maxSum = max(maxSum, currentSum)

print(("{:.12f}".format(maxSum / 2)))


# Optimized solution
from collections import deque

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

queue = deque()
currentSum = 0
maxSum = 0
for i in range(len(p)):
    currentSum = currentSum + p[i] + 1
    queue.append(p[i] + 1)
    if i >= K:
        currentSum = currentSum - queue.popleft()

    if i >= K - 1:
        maxSum = max(maxSum, currentSum)

print(("{:.12f}".format(maxSum / 2)))
# Original solution
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

max = 0

for i in range(N-K+1):
    tmp = p[i]
    # print("i:" + str(i))
    for j in range(i+1,i+K):
        tmp += p[j]

    # print(tmp)
    if(max < tmp):
        max = tmp 
        maxStartIndex = i
ans = 0
for i in range(maxStartIndex, maxStartIndex+K):
    sum = p[i] * (p[i]+1) / 2
    ans += sum/p[i]
print(('{:.12f}'.format(ans)))
# 1 2 3 
# 3 2 1


# n, n-1, n-2
# n(n + 1)/2 

# Optimized solution
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
p_sum = [0]
max = 0

for i in range(len(p)):
    p_sum.append(p_sum[i] + (p[i]+1)/2) 

for i in range(K,N+1):
    sum = p_sum[i] - p_sum[i-K]
    if(max < sum):
        max = sum
# for i in range(N-K+1):
#     tmp = p[i]
#     # print("i:" + str(i))
#     for j in range(i+1,i+K):
#         tmp += p[j]

#     # print(tmp)
#     if(max < tmp):
#         max = tmp 
#         maxStartIndex = i
# ans = 0
# for i in range(maxStartIndex, maxStartIndex+K):
#     sum = p[i] * (p[i]+1) / 2
#     ans += sum/p[i]
print(('{:.12f}'.format(max)))
# 1 2 3 
# 3 2 1


# n, n-1, n-2
# n(n + 1)/2
# Original solution
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
ki = [0]*1001
for i in range(1, 1001):
    ki[i] = ki[i-1]+i

pp = []
for pa in p:
    pp.append(ki[pa]/pa)

ans = 0
for i in range(n-k+1):
    ans = max(ans, sum(pp[i:i+k]))

print(("{0:.12f}".format(ans)))


# Optimized solution
import itertools
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
ki = [0]*1001
for i in range(1, 1001):
    ki[i] = ki[i-1]+i

pp = []
for pa in p:
    pp.append(ki[pa]/pa)

# print(pp)
ppp = [0] + list(itertools.accumulate(pp))
# print(ppp)
ans = 0
for i in range(n-k+1):
    # print(ppp[i+k]-ppp[i])
    ans = max(ans, ppp[i+k]-ppp[i])

print(("{0:.12f}".format(ans)))
# Original solution
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    n, k = list(map(int,sys.stdin.readline().split()))
    p = list(map(int,sys.stdin.readline().split()))
    sum_max = 0
    max_idx = 0
    for i in range(n - k + 1):
        max_tmp = 0
        for j in range(k):
            max_tmp += p[i+j]
        if sum_max < max_tmp:
            max_idx = i
            sum_max = max_tmp
    #print(max_idx)
    ans = 0
    for i in range(max_idx, max_idx + k):
        ans += ((p[i] * (p[i] + 1)) / 2) / p[i]
    print(("{:.12f}".format(ans)))
    return 0

if __name__ == "__main__":
    main()

# Optimized solution
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    n, k = list(map(int,sys.stdin.readline().split()))
    p = list(map(int,sys.stdin.readline().split()))
    sum_l = [0] * (n - k + 1)
    for i in range(k):
        sum_l[0] += p[i]
    for i in range(1,n - k + 1):
        sum_l[i] = sum_l[i - 1] - p[i - 1] + p[i + k - 1]
    #print(sum_l)
    max_idx = sum_l.index(max(sum_l))
    #print(max_idx)
    ans = 0
    for i in range(max_idx, max_idx + k):
        ans += ((p[i] * (p[i] + 1)) / 2) / p[i]
    print(("{:.12f}".format(ans)))
    return 0
    
if __name__ == "__main__":
    main()