Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from itertools import permutations, combinations


def solve(string):
    n, a, b, c, *l = map(int, string.split())
    ans = 3000
    for _l in permutations(l):
        for i, j, k in combinations(range(1, len(l) + 1), 3):
            tmp = 10 * (i - 1) + abs(a - sum(_l[:i]))
            if tmp > ans:
                continue
            tmp += 10 * (j - i - 1) + abs(b - sum(_l[i:j]))
            if tmp > ans:
                continue
            tmp += 10 * (k - j - 1) + abs(c - sum(_l[j:k]))
            if tmp < ans:
                ans = tmp
    return str(ans)


if __name__ == '__main__':
    n, a, b, c = map(int, input().split())
    print(solve('{} {} {} {}\n'.format(n, a, b, c) + '\n'.join([input() for _ in range(n)])))


### FIXED CODE ###

from itertools import permutations


def solve(string):
    n, a, b, c, *l = map(int, string.split())
    ans = 3000

    for _l in permutations(l):
        for i in range(1, len(l) - 1):
            for j in range(i + 1, len(l)):
                for k in range(j + 1, len(l) + 1):
                    tmp = 10 * (i - 1) + abs(a - sum(_l[:i])) + 10 * (j - i - 1) + abs(
                        b - sum(_l[i:j])) + 10 * (k - j - 1) + abs(c - sum(_l[j:k]))
                    if tmp < ans:
                        ans = tmp
    return str(ans)


if __name__ == '__main__':
    n, a, b, c = map(int, input().split())
    print(solve('{} {} {} {}\n'.format(n, a, b, c) + '\n'.join([input() for _ in range(n)])))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
from bisect import bisect_left

N = int(input())
XD = [[int(i) for i in input().split()] for _ in range(N)]
XD.sort()
MOD = 998244353
sorted_X = [X for X,_ in XD]

edge = [[] for _ in range(N)]

parent = [-1] * N

MAXIDX = N
for i in range(N-1, -1, -1):
    idx = bisect_left(sorted_X, XD[i][0] + XD[i][1])
    for j in range(i+1, min(idx, MAXIDX)):
        if parent[j] < 0:
            parent[j] = i
    if idx >= MAXIDX:
        MAXIDX = i + 1

for i,par in enumerate(parent):
    if par < 0:
        continue
    edge[par].append(i)

def cnt(node):
    if not edge[node]:
        return 2

    res = 1
    for v in edge[node]:
        res = (res * cnt(v)) % MOD
    res += 1

    return res % MOD

ans = 1
for i,par in enumerate(parent):
    if par < 0:
        ans = (ans * cnt(i)) % MOD

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
from bisect import bisect_left

N = int(input())
XD = [[int(i) for i in input().split()] for _ in range(N)]
XD.sort()
MOD = 998244353

def make():
    edge = [[] for _ in range(N)]
    parent = [-1] * N
    MAXIDX = N
    sorted_X = [X for X,_ in XD]
    for i in range(N-1, -1, -1):
        idx = bisect_left(sorted_X, XD[i][0] + XD[i][1])
        for j in range(i+1, min(idx, MAXIDX)):
            if parent[j] < 0:
                parent[j] = i
        if idx >= MAXIDX:
            MAXIDX = i + 1
    for i,par in enumerate(parent):
        if par < 0:
            continue
        edge[par].append(i)
    
    return parent, edge

parent, edge = make()

def cnt(node):
    if not edge[node]:
        return 2

    res = 1
    for v in edge[node]:
        res = (res * cnt(v)) % MOD
    res += 1

    return res % MOD

def main():
    ans = 1
    for i,par in enumerate(parent):
        if par < 0:
            ans = (ans * cnt(i)) % MOD

    print(ans)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

R, G, B, N = map(int, input().split())

rgb = []
s = set([x*B for x in range(N) if x*B <= N])
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        if N-r*R-g*G in s:
            rgb.append((r,g,(N-r*R-g*G)//B))

print(len(set(rgb)))

### FIXED CODE ###

R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        tmp = N-r*R-g*G
        if tmp%B == 0:
            ans += 1
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [0] * (n//1000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())

        a -= 1
        base[a] += v

        b = a - a % 1000
        value = base[b]
        index = b
        for i, v in enumerate(base[b:b+1000], b):
            if value < v:
                value = v
                index = i
        midway[b//1000] = index

        index = midway[0]
        value = base[index]
        for i in midway:
            if value < base[i]:
                value = base[i]
                index = i

        print(index+1, value)
    exit()


if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [0] * (n//100 + 1)
    last = [0] * (n//10000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())

        a -= 1
        base[a] += v

        b = a - a % 100

        index = b
        value = base[b]
        end = b + 100 if b + 100 < n else n
        for i in range(b, end):
            if value < base[i]:
                value = base[i]
                index = i
        midway[b//100] = index

        c = a - a % 10000
        cc = c // 100

        index = c
        value = base[c]
        for i in midway[cc:cc+100]:
            if value < base[i]:
                value = base[i]
                index = i
        last[c//10000] = index

        index = last[0]
        value = base[index]
        for i in last:
            if value < base[i]:
                value = base[i]
                index = i

        print(index+1, value)
    exit()


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import numpy as np

N = int(input())
A = []
B = []

for _ in range(N):
    A.append(int(input()))

    
for i in range(N):
    B = list(A)
    B.pop(i)
    print(np.amax(B))

### FIXED CODE ###

N = int(input())
A = []
 
for _ in range(N):
    A.append(int(input()))
    
a = max(A)
b =  sorted(A)[-2]
 
for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)
### BUGGY CODE ###

n=int(input())
a=[int(input()) for _ in range(n)]
for i in range(n):
  print(max(a[:i]+a[i+1:]))

### FIXED CODE ###

n=int(input())
a=[int(input()) for _ in range(n)]
s=sorted(a, reverse=True)
m=s[0]
for i in range(n):
  if a[i]>=m:
    print(s[1])
  else:
    print(m)
### BUGGY CODE ###

S = input()
K = int(input())
s = set()
for i in range(len(S)):
    for j in range(i, len(S)):
        s.add(S[i:j+1])
print(sorted(list(s))[K-1])


### FIXED CODE ###

S = input()
K = int(input())
s = []
ss = []
for i in range(len(S)):
    s.append(S[i:])
s.sort()
for i in range(len(s)-1):
    if s[i] != s[i+1][:len(s[i])]:
        ss.append(s[i])
ss.append(s[-1])
i = 0
while len(ss[i]) < K:
    K -= len(ss[i])
    i += 1
print(ss[i][:K])
### BUGGY CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))

ans = 0
a = []
b = []

for i in range(m):
    a_i, b_i = map(int,input().split())
    a.append(a_i)
    b.append(b_i)

for i in range(n):
    h_i = [0]
    for j in range(m):
        if a[j] == i + 1:
            h_i.append(h[b[j] - 1])
        if b[j] == i + 1:
            h_i.append(h[a[j] - 1])
    if h[i] > max(h_i):
        ans += 1

print(ans)


### FIXED CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))

ans = [0] * n

for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] < h[b - 1]:
        ans[a - 1] += 1
    elif h[a - 1] > h[b -1]:
        ans[b - 1] += 1
    else:
        ans[a - 1] += 1
        ans[b - 1] += 1

print(ans.count(0))
### BUGGY CODE ###

import sys

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

def main():
    N = I()
    a = LI()
    t = [0, 0, 0]
    for ai in a:
        t[ai-1] += 1
    A, B, C = t
    E = B+C

    dp = [[0 if (not i|j) else N/(i+j) for j in range(E+1)] for i in range(N+1)]

    for k in range(C+1):
        for i in range(N+1):
            dp[i][E] = 0 if (not i|E|k) else N/(i+E+k)
        for j in range(E+1):
            for i in range(N+1):
                z = i+j+k
                if (not z):
                    continue
                d = dp[i][j]
                if (i<N):
                    dp[i+1][j] += (i+1)*d/(z+1)
                if (i>0)&(j<E):
                    dp[i-1][j+1] += (j+1)*d/z
                if (j>0)&(k<C):
                    dp[i][j-1] = (k+1)*d/z + N/z

    print(dp[A][B])

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys

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

def main():
    N = I()
    a = LI()
    t = [0, 0, 0]
    for ai in a:
        t[ai-1] += 1
    A, B, C = t
    E = B+C

    dp = [[0 if (i+j==0) else N/(i+j) for j in range(E+1)] for i in range(N+1)]

    for k in range(C+1):
        for i in range(N+1):
            dp[i][E] = 0 if (i+E+k==0) else N/(i+E+k)
        for j in range(E+1):
            for i in range(N+1):
                z = i+j+k
                if (not z):
                    continue
                d = dp[i][j]
                if (i<N):
                    dp[i+1][j] += (i+1)*d/(z+1)
                if (i>0) and (j<E):
                    dp[i-1][j+1] += (j+1)*d/z
                if (j>0) and (k<C):
                    dp[i][j-1] = (k+1)*d/z + N/z

    print(dp[A][B])

if __name__ == "__main__":
    main()
### BUGGY CODE ###

N=int(input())
B=list(map(int,input().split(' ')))
def dfs(n,B,ans):
    if n==0:
        return ans[::-1]
    else:
        for num,i in enumerate(B):
            if num+1==i and dfs(n-1,B[:num]+B[num+1:],ans+[i]):
                return dfs(n-1,B[:num]+B[num+1:],ans+[i])
        return False
ans = dfs(N,B,[])
if not ans:
    print(-1)
else:
    for i in ans:
        print(i)

### FIXED CODE ###

N=int(input())
B=list(map(int,input().split(' ')))
ans = []
for i in range(N):
    for n,j in enumerate(B[::-1]):
        if N-i-n==j:
            ans.append(B.pop(N-i-n-1))
            break
if len(ans)==N:
    for i in ans[::-1]:
        print(i)
else:
    print(-1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
a, b = map(int, input().split())

ans = a
for i in range(a+1, b+1):
    ans ^= i

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
def f (n):
    xor = ((n+1) // 2) % 2
    if n % 2 == 0:
        return xor ^ n
    return xor


a, b = map(int, input().split())
print(f(b)^f(a-1))
### BUGGY CODE ###

n=int(input())
lst=[]
counter=0
for _ in range(n):
    s=input()
    if s in lst : continue
    lst.append(s)
    counter+=1

print(counter)

### FIXED CODE ###

n=int(input())
lst=set([])
counter=0
for _ in range(n):
    s=input()
    if s in lst : continue
    lst.add(s)
    counter+=1

print(counter)
### BUGGY CODE ###

s,t=[input() for i in (0,0)]
T,S=len(t),len(s)
dp=[["" for j in range(T+1)] for i in range(S+1)]
for i in range(S):
    for j in range(T):
        if s[i]==t[j]:dp[i+1][j+1]=dp[i][j]+s[i]
        else:dp[i+1][j+1]=max(dp[i][j],dp[i+1][j],dp[i][j+1],key=lambda x:len(x))
print(dp[S][T])

### FIXED CODE ###

s,t=input(),input()
n,m=len(s),len(t)
dp=[[0]*(m+1) for i in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:
      dp[i+1][j+1]=dp[i][j]+1
    else:
      dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])
ans=""
while m>0 and n>0:
  if s[n-1]==t[m-1]:ans=s[n-1]+ans;n-=1;m-=1
  elif dp[n][m]==dp[n-1][m]:n-=1
  else:m-=1
print(ans)
### BUGGY CODE ###

N = int(input())
List = list(map(int, input().split()))
Ans = [0 for _ in range(N)]
for i in range(N):
  Ans[i] = str(List.index(i+1)+1)
a =' '.join(Ans)
print(a)

### FIXED CODE ###

N = int(input())
List = list(map(int, input().split()))
Ans = [0 for _ in range(N)]
for i in range(N):
  Ans[List[i]-1] = str(i+1)
a =' '.join(Ans)
print(a)
### BUGGY CODE ###

N, M = map(int,input().split())
A = list(map(int, input().split()))
ans = 0

S = [0 for k in range(N)]
S[0] = A[0]
for k in range(1,N):
    S[k] = S[k-1] + A[k]
S = [0] + S

for k in range(N+1):
    for l in range(k+1,N+1):
        if (S[l]-S[k])%M == 0:
            ans += 1
print(ans)

### FIXED CODE ###

from collections import Counter
N, M = map(int,input().split())
A = list(map(int, input().split()))
ans = 0

S = [0 for k in range(N)]
S[0] = A[0]
for k in range(1,N):
    S[k] = S[k-1] + A[k]
S = [0] + S
for k in range(N+1):
    S[k] %= M

C = Counter(S)
for a in C:
    if C[a] >= 2:
        ans += (C[a]*(C[a]-1))//2
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    cnt=[0]*3
    for a in map(int,input().split()):
        cnt[a-1]+=1

    dp=[[[0]*303 for _ in range(303)] for _ in range(303)]
    def calc(i,j,k):
        if dp[i][j][k]: return dp[i][j][k]
        l=i+j+k
        if l==0: return 0
        s=n/l
        if i: s+=calc(i-1,j,k)*i/l
        if j: s+=calc(i+1,j-1,k)*j/l
        if k: s+=calc(i,j+1,k-1)*k/l
        dp[i][j][k]=s
        return dp[i][j][k]
    print(calc(*cnt))
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    counter = [0] * 3
    for a in map(int, input().split()):
        counter[a - 1] += 1

    # (i, j, k) -> (i - 1, j, k), (i + 1, j - 1, k), (i, j + 1, k - 1)
    # s = i + j + k の小さい方から遷移
    dp = [[[None] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
    dp[0][0][0] = 0
    for s in range(1, n + 1):
        for k in range(n + 1):
            for j in range(n + 1):
                i = s - j - k
                if i < 0:
                    break
                res = n
                if i: res += i * dp[i - 1][j][k]
                if j: res += j * dp[i + 1][j - 1][k]
                if k: res += k * dp[i][j + 1][k - 1]

                res /= s
                dp[i][j][k] = res

    i, j, k = counter
    print(dp[i][j][k])
resolve()
### BUGGY CODE ###

A,B = map(int,input().split())
l = B-A+1
ans = 0
for i in range(l):
    ans = ans^(A+i)
print(ans)

### FIXED CODE ###

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

def xor(n):
    m = n+1
    return m//2%2 + n*(m%2)

print(xor(B)^xor(A-1))
### BUGGY CODE ###

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    h, w, m = MAP()
    s = [LIST1() for i in range(m)]
    ay = [0]*h
    ax = [0]*w
    c = [[0]*w for i in range(h)]
    for x in s:
        ay[x[0]] += 1
        ax[x[1]] += 1
        c[x[0]][x[1]] = 1

    my = max(ay)
    mx = max(ax)
    by = [i for i, x in enumerate(ay) if x == my]
    bx = [i for i, x in enumerate(ax) if x == mx]

    ans = my + mx
    tmp = 1
    for y in by:
        for x in bx:
            if c[y][x] == 0:
               tmp = 0
    print(ans - tmp)

if __name__ == '__main__':
    solve()

### FIXED CODE ###

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    h, w, m = MAP()
    s = [LIST1() for i in range(m)]
    ay = [0]*h
    ax = [0]*w
    for x in s:
        ay[x[0]] += 1
        ax[x[1]] += 1

    my = max(ay)
    mx = max(ax)
    
    by = bx = 0
    for y in ay:
        if y == my:
            by += 1
    for x in ax:
        if x == mx:
            bx += 1
            
    ans = my + mx
    tmp = 0
    for x in s:
        if ay[x[0]]+ax[x[1]]==ans:
            tmp += 1
    if tmp == by*bx:
        ans -= 1
    print(ans)
    
if __name__ == '__main__':
    solve()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
edge = [set() for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    edge[a-1].add(b-1)
    edge[b-1].add(a-1)

cost = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    cost[p-1] += x

ans = [0] * n
def dfs(cur, c, root):
    # print(cur, c, root)
    ans[cur] = c
    for nex in edge[cur]:
        if nex != root:
            dfs(nex, c + cost[nex], cur)

dfs(0, cost[0], -1)
print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

n, q = map(int, input().split())

connect = [set() for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x

ans = [0] * n
def dfs(me, parent, cum):
    cum += counter[me]
    ans[me] = cum
    for child in connect[me]:
        if child != parent:
            dfs(child, me, cum)

dfs(0, -1, 0)

print(*ans)
### BUGGY CODE ###

n,k = map(int,input().split())
if k > n:
  k = n
a = list(map(int, input().split()))
dp = [0]*n
for i in range(1,n):
  if i <= k:
    dp[i] = abs(a[i]-a[0])
  else:
    dp[i] = min([abs(a[i]-a[i-j])+dp[i-j] for j in range(1,k+1)])
print(dp[-1])

### FIXED CODE ###

n,k = map(int,input().split())
if k > n:
  k = n
a = list(map(int, input().split()))
dp = [0]*n
for i in range(1,n):
  if i <= k:
    dp[i] = abs(a[i]-a[0])
  else:
    dp[i] = min([abs(a[i]-a[i-j])+dp[i-j] for j in range(1,k+1)])
print(dp[-1])
### BUGGY CODE ###

from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
s=[list(input()) for i in range(h)]

#幅優先で解く。
dx=[1,0,-1,0]
dy=[0,1,0,-1]
def bfs():
  maze=[[-1]*w for i in range(h)]
  maze[ch-1][cw-1]=0
  qu=deque([])
  qu.append((cw-1,ch-1))
  magic=0
  
  while qu:
    x,y=qu.popleft()
    for i in range(x-2,x+3):
      for j in range(y-2,y+3):
        nx=i
        ny=j
        if 0<=nx<=w-1 and 0<=ny<=h-1 and s[ny][nx]=="." and (maze[ny][nx]==-1 or maze[ny][nx]>maze[y][x]+1):
          qu.append((nx,ny))
          maze[ny][nx]=maze[y][x]+1
    for i in range(4):
      nx=dx[i]+x
      ny=dy[i]+y
      
      if 0<=nx<=w-1 and 0<=ny<=h-1 and s[ny][nx]=="." and (maze[ny][nx]==-1 or maze[ny][nx]>maze[y][x]):
        qu.appendleft((nx,ny))
        maze[ny][nx]=maze[y][x]
  return maze
    
maze = bfs()
print(maze[dh-1][dw-1])

### FIXED CODE ###

from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

maze = [list(input()) for i in range(h)]
ans = [[-1]*w for i in range(h)]

dx=[0,1,0,-1]
dy=[1,0,-1,0]

ans[ch-1][cw-1]=0
def bfs(ans):
  qu = deque([])
  qu.append([cw-1,ch-1])
  while qu:
    zahyou=qu.popleft()
    x=zahyou[0]
    y=zahyou[1]
    count=0
    for i in range(4):
      if 0 <= x+dx[i] < w and 0 <= y+dy[i] < h:
        if maze[y+dy[i]][x+dx[i]]=="." and (ans[y+dy[i]][x+dx[i]]>ans[y][x] or ans[y+dy[i]][x+dx[i]]==-1):
          qu.appendleft([x+dx[i],y+dy[i]])
          ans[y+dy[i]][x+dx[i]] = ans[y][x]
          count+=1
    if count!=4:
      for i in range(x-2,x+3):
        for j in range(y-2,y+3):
          if 0<=i<w and 0<=j<h:
            if maze[j][i]=="." and (ans[j][i]>ans[y][x]+1 or ans[j][i]==-1):
              ans[j][i]=(ans[y][x]+1)
              qu.append([i,j])

bfs(ans)
print(ans[dh-1][dw-1])
### BUGGY CODE ###

a,b,n=map(int,input().split())

m=-1
x=0

for i in range(1,n+1):
  c=int(a*i/b)-a*int(i/b)

  if m<c or m==-1:
    m=c
    x=i

print(m)

### FIXED CODE ###

a,b,n=map(int,input().split())
"""
m=-1

for i in range(b+1):
  w=int(a*i/b)-a*int(i/b)
  if m<w or m==-1:
    m=w
print(m)
"""
if b<=n:
  print(int(a*(b-1)/b)-a*int((b-1)/b))
else:
  print(int(a*n/b)-a*int(n/b))
### BUGGY CODE ###

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

def P(n):
  return n * (n+1)/2/n

set_p = list(set(p))
dice = []
for x in range(len(set_p)):
  dice.append(P(set_p[x]))

ans = 0
for i in range(N - (K - 1)):
  a = 0
  for j in range(K):
    n = set_p.index(p[i + j])
    a += dice[n]
  if a > ans:
    ans = a

print(ans)

### FIXED CODE ###

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

a = 0
for i in range(N - K + 1):
  if i == 0:
    b = sum(p[0:K])
  else:
    b = b - p[i-1] + p[i + K - 1]
  
  if b > a:
    a = b
    f = i

ans = 0
for j in range(K):
  ans += (p[f + j] + 1) / 2

print(ans)
### BUGGY CODE ###

# coding: utf-8

import bisect


def calc_l_score(N, a):
    scores = [None] * (N + 1)
    queue = sorted(a[:N])
    scores[0] = sum(queue)
    for i in range(N):
        na = a[N + i]
        bisect.insort(queue, na)
        m = queue.pop(0)
        scores[i + 1] = scores[i] + na - m
    return scores


def calc_r_score(N, a):
    scores = [None] * (N + 1)
    queue = sorted(a[2 * N:])
    scores[-1] = sum(queue)
    for i in range(1, N + 1):
        na = a[-N - i]
        bisect.insort(queue, na)
        m = queue.pop(-1)
        scores[-i - 1] = scores[-i] + na - m
    return scores


def main():
    N = int(input())
    a = list(map(int, input().split()))

    ls = calc_l_score(N, a)
    rs = calc_r_score(N, a)
    return max([l - r for l, r in zip(ls, rs)])


if __name__ == "__main__":
    print(main())


### FIXED CODE ###

# coding: utf-8

import heapq


def calc_l_score(N, a):
    scores = [None] * (N + 1)
    queue = a[:N]
    heapq.heapify(queue)
    scores[0] = sum(queue)
    for i in range(N):
        na = a[N + i]
        heapq.heappush(queue, na)
        m = heapq.heappop(queue)
        scores[i + 1] = scores[i] + na - m
    return scores


def calc_r_score(N, a):
    scores = [None] * (N + 1)
    queue = []
    for i in range(1, N + 1):
        heapq.heappush(queue, -a[-i])
    scores[-1] = - sum(queue)
    for i in range(1, N + 1):
        na = a[-N - i]
        heapq.heappush(queue, -na)
        m = - heapq.heappop(queue)
        scores[-i - 1] = scores[-i] + na - m
    return scores


def main():
    N = int(input())
    a = list(map(int, input().split()))

    ls = calc_l_score(N, a)
    rs = calc_r_score(N, a)
    return max([l - r for l, r in zip(ls, rs)])


if __name__ == "__main__":
    print(main())