Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())

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


B = []
init_ = sum(P[0:k])
max_ = 0
for i in range(0, n - k+1):
    if i != 0:
        init_ = init_ - P[i] + P[i+k-1]
    if max_ < init_:
        B = P[i:i+k]
        max_ = init_
B = sorted(B)
i = 0
t = 0
C = []
for j in range(B[-1]+1):
    t += j
    if j == B[i]:
        C.append(t)
        i += 1

ans = 0
for i in range(k):
    ans += C[i] / B[i]
print(ans)

Fixed submission:
n, k = map(int, input().split())

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

B = []
t = -1
init_sum = sum(A[0:k])

for i in range(n - k+1):
    if t < init_sum:
        B = A[i:i+k]
        t = init_sum
    if i != n - k:
        init_sum = init_sum - A[i] + A[i+k]


import collections
B = sorted(B)
C = collections.Counter(B)

D = list(C.keys())
E = list(C.values())
F = zip(D, E)
F = sorted(F)
D, E = zip(*F)

G = []
j = 0
total = 0
for i in range(max(D) + 1):
    total += i
    if D[j] == i:
        G.append(total)
        j += 1
ans = 0
k = 0
for i, j in zip(D, G):
    ans += (j/i) * E[k]
    k += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

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

t = 0
A = []

for i in range(n-k+1):
    s = sum(P[i:i+k])
    if s > t:
        A = P[i:i+k]
        t = s
ans = 0
def f(x):
    y = 0
    for i in range(x+1):
        y += i
    return y / x

B = []
C = []
for i in A:
    if i not in B:
        temp = f(i)
        B.append(i)
        C.append(temp)
    else:
        temp = C[B.index(i)]
    ans += temp
print(ans)

Fixed submission:
n, k = map(int, input().split())

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

B = []
t = -1
init_sum = sum(A[0:k])

for i in range(n - k+1):
    if t < init_sum:
        B = A[i:i+k]
        t = init_sum
    if i != n - k:
        init_sum = init_sum - A[i] + A[i+k]


import collections
B = sorted(B)
C = collections.Counter(B)

D = list(C.keys())
E = list(C.values())
F = zip(D, E)
F = sorted(F)
D, E = zip(*F)

G = []
j = 0
total = 0
for i in range(max(D) + 1):
    total += i
    if D[j] == i:
        G.append(total)
        j += 1
ans = 0
k = 0
for i, j in zip(D, G):
    ans += (j/i) * E[k]
    k += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

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

def s_(x):
    t = 0
    for i in range(x+1):
        t += i
    return t / x

total = 0
A = []
for i in range(n - k + 1):
    s = sum(P[i:i+k])
    if total < s:
        total = s
        A = P[i:i+k]
sum_ = 0
for i in A:
    sum_ += s_(i)
print(sum_)

Fixed submission:
n, k = map(int, input().split())

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

B = []
t = -1
init_sum = sum(A[0:k])

for i in range(n - k+1):
    if t < init_sum:
        B = A[i:i+k]
        t = init_sum
    if i != n - k:
        init_sum = init_sum - A[i] + A[i+k]


import collections
B = sorted(B)
C = collections.Counter(B)

D = list(C.keys())
E = list(C.values())
F = zip(D, E)
F = sorted(F)
D, E = zip(*F)

G = []
j = 0
total = 0
for i in range(max(D) + 1):
    total += i
    if D[j] == i:
        G.append(total)
        j += 1
ans = 0
k = 0
for i, j in zip(D, G):
    ans += (j/i) * E[k]
    k += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

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

A = []
B = []
C = []

def s_(x):
    t = 0
    for i in range(x+1):
        t += i
    return t / x


for i in P:
    if i not in A:
        A.append(i)
        B.append(s_(i))
        C.append(B[-1])
    else:
        C.append(B[A.index(i)])
max_ = 0
for j in range(n - k + 1):
    g = sum(C[j:j+k])
    if max_< g:
        max_ = g
print(max_)

Fixed submission:
n, k = map(int, input().split())

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

B = []
t = -1
init_sum = sum(A[0:k])

for i in range(n - k+1):
    if t < init_sum:
        B = A[i:i+k]
        t = init_sum
    if i != n - k:
        init_sum = init_sum - A[i] + A[i+k]


import collections
B = sorted(B)
C = collections.Counter(B)

D = list(C.keys())
E = list(C.values())
F = zip(D, E)
F = sorted(F)
D, E = zip(*F)

G = []
j = 0
total = 0
for i in range(max(D) + 1):
    total += i
    if D[j] == i:
        G.append(total)
        j += 1
ans = 0
k = 0
for i, j in zip(D, G):
    ans += (j/i) * E[k]
    k += 1
print(ans)