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

import sys

input = sys.stdin.readline


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


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


INV = {}


def inv(a, mod):
    if a in INV:
        return INV[a]
    r = pow(a, mod - 2, mod)
    INV[a] = r
    return r


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


class UF:
    def __init__(self, N):
        self.parent = [i for i in range(N)]

    def get_parent(self, a):
        p = self.parent[a]
        if a == p:
            return a

        q = self.get_parent(p)
        self.parent[a] = q
        return q

    def make_pare(self, a, b):
        pa = self.get_parent(a)
        pb = self.get_parent(b)
        if pa != pb:
            self.parent[pa] = pb
            self.parent[a] = pb

    def is_pare(self, a, b):
        return self.get_parent(a) == self.get_parent(b)


def main():
    N, M = read_values()
    P = read_list()
    F = [0] * N
    for i, p in enumerate(P):
        F[p - 1] = i

    W = [tuple(read_values()) for _ in range(M)]
    U = UF(N)
    for a, b in W:
        a -= 1
        b -= 1
        U.make_pare(a, b)

    res = 0
    already = [False] * N
    for i in range(N):
        if already[i]:
            continue

        if i == F[i]:
            res += 1
            continue

        S_num = {i}
        S_index = {F[i]}

        for j in range(i + 1, N):
            if already[j]:
                continue

            if U.is_pare(i, j):
                S_num.add(j)
                S_index.add(F[j])
                already[j] = True
        res += len(S_num & S_index)
    print(res)


if __name__ == "__main__":
    main()



### FIXED CODE ###

import sys

input = sys.stdin.readline


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


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


INV = {}


def inv(a, mod):
    if a in INV:
        return INV[a]
    r = pow(a, mod - 2, mod)
    INV[a] = r
    return r


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


class UF:
    def __init__(self, N):
        self.parent = [i for i in range(N)]

    def get_parent(self, a):
        p = self.parent[a]
        if a == p:
            return a

        q = self.get_parent(p)
        self.parent[a] = q
        return q

    def make_pare(self, a, b):
        pa = self.get_parent(a)
        pb = self.get_parent(b)
        if pa != pb:
            self.parent[pa] = pb
            self.parent[a] = pb

    def is_pare(self, a, b):
        return self.get_parent(a) == self.get_parent(b)


def main():
    N, M = read_values()
    P = read_list()
    F = [0] * N

    W = [tuple(read_values()) for _ in range(M)]
    U = UF(N)
    for a, b in W:
        a -= 1
        b -= 1
        U.make_pare(a, b)

    res = 0
    for p in P:
        p -= 1
        if U.is_pare(p, P[p] - 1):
            res += 1
    print(res)


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

R,G,B,N=map(int,input().split())
r,g,b,count=0,0,0,0
while(B*b<=N):
	g=0
	while(G*g<=N):
		r=(-G*g-B*b+N)/R
		if (float(r).is_integer())&(r>=0):
			count+=1
		g+=1
	b+=1
print(count)

### FIXED CODE ###

R,G,B,N=map(int,input().split())
r,g,b,count=0,0,0,0
for b in range(N+1):
	for g in range(N+1):
		r=-G*g-B*b+N
		if r<0:break
		if (r%R==0): count+=1
print(count)
### BUGGY CODE ###

def main():
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]

    def unite(x, y):
        x = find(x)
        y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x, y = y, x
            par[x] += par[y]
            par[y] = x
            return True

    def same(x, y):
        return find(x) == find(y)

    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    par = [-1] * n
    for _ in range(m):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        unite(x, y)

    r = 0
    for i1 in range(n):
        ichi = p.index(i1 + 1)
        r += same(i1, ichi)
    print(r)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]

    def unite(x, y):
        x = find(x)
        y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x, y = y, x
            par[x] += par[y]
            par[y] = x
            return True

    def same(x, y):
        return find(x) == find(y)

    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    pdic = {e :0 for e in range(n)}
    for i, pe in enumerate(p):
        pdic[pe] = i

    par = [-1] * n
    for _ in range(m):
        x, y = map(int, input().split())
        unite(x-1, y-1)

    r = 0
    for i1 in range(n):
        r += same(i1, pdic[i1+1])
    print(r)


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

N = int(input())
A = list(map(int, input().split()))
sumA = sum(A)

ans = [None] * N
for i in range(N):
    if i < 2:
        ans[i] = str(sumA - 2 * sum(A[i + 1::2]))
    else:
        ans[i] = str(sumA - 2 * sum(A[i - 2::-2]) - 2 * sum(A[i + 1::2]))

print(" ".join(ans))

### FIXED CODE ###

from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
sumA = sum(A)

cumevA = list(accumulate(A[::2]))
cumodA = list(accumulate(A[1::2]))

ans = [None] * N
for i in range(N):
    if i == 0:
        ans[i] = str(sumA - 2 * cumodA[-1])
    elif i == 1:
        ans[i] = str(sumA - 2 * (cumevA[-1] - cumevA[0]))
    elif i == N-1:
        ans[i] = str(sumA - 2 * (cumevA[-2]))
    else:
        if i % 2 == 0:
            ans[i] = str(sumA - 2 * (cumodA[-1] - cumodA[i // 2 - 1] + cumevA[i // 2 - 1]))
        else:
            ans[i] = str(sumA - 2 * (cumevA[-1] - cumevA[(i - 1) // 2] + cumodA[(i - 3) // 2]))

print(" ".join(ans))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys

def main():
	N, W = map(int, input().split(" "))
	objs = []
	for _ in range(N):
		w, v = map(int, input().split(" "))
		objs.append((w, v))
		
	DP = [[0 for _ in range(W+2)] for _ in range(N+1)]
	
	for i, val in enumerate(objs):
		w, v = val
		for j in range(1, W+1):
			DP[i+1][j] = max(DP[i+1][j], DP[i][j])
			if j - w >= 0:
				#print("{} {}".format(j+w, i+1))
				DP[i+1][j] = max(DP[i+1][j], DP[i][j-w] + v)
				
	ans = 0
	#print(DP)
	for i in range(W+1):
		for j in range(N+1):
			if ans < DP[j][i]:
				ans = DP[j][i]
				
	print(ans)
	
if __name__ == "__main__":
	main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def main():
	N, W = map(int, input().split())
	wv = []
	for i in range(N):
		w, v = map(int, input().split())
		if w <= W:
			wv.append((w,v))
		
	DP = [[0 for _ in range(100001)] for _ in range(N)]
	
	for i, val in enumerate(wv):
		w, v = val
		if i == 0:
			DP[i][w] = v
			continue
			
		for j in range(W):
			DP[i][j] = max(DP[i-1][j], DP[i][j])
			
			if j+w <= W:
				DP[i][j+w] = max(DP[i-1][j] + v, DP[i][j+w])
			
	print(max(DP[N-1]))
	
if __name__ == "__main__":
	main()
### BUGGY CODE ###

H, W, M = map(int, input().split())
h = [0] * (H+1)
w = [0] * (W+1)
l = set()
for i in range(M):
  x, y = map(int, input().split())
  h[x] += 1
  w[y] += 1
  l.add((x, y))
  
c = max(h)
d = max(w)
a = [i for i, x in enumerate(h) if x == max(h)]
b = [i for i, x in enumerate(w) if x == max(w)]

flag = False
for s in a:
  for t in b:
    if (s, t) not in l:
      flag = True
      break
if flag:
  ans = c+d
else:
  ans = c+d-1
print(ans)


### FIXED CODE ###

H, W, M = map(int, input().split())
h = [0] * (H+1)
w = [0] * (W+1)
l = set()
for i in range(M):
  x, y = map(int, input().split())
  h[x] += 1
  w[y] += 1
  l.add((x, y))
  
c = max(h)
d = max(w)
a = [i for i, x in enumerate(h) if x == c]
b = [i for i, x in enumerate(w) if x == d]

flag = False
for s in a:
  for t in b:
    if (s, t) not in l:
      flag = True
      break
  if flag:
    break
ans = c+d
if not flag:
  ans -= 1
print(ans)
### BUGGY CODE ###

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

expected_list = [sum(range(1, x+1))/x for x in p_list]

maximum = 0
for i in range(n-(k-1)):
    maximum = max(maximum, sum(expected_list[i:i+k]))
print(maximum)

### FIXED CODE ###

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

expected_list = [(x+1)/2 for x in p_list]

partsum = sum(expected_list[0:k])
maximum = partsum
for i in range(1, n-(k-1)):
    partsum = partsum + expected_list[i+k-1] - expected_list[i-1]
    maximum = max(maximum, partsum)
print(maximum)
### BUGGY CODE ###

s = input()
count = int(input())

for i in range(count):
    tfc = input().split()
    if tfc[0] == "1":
        s = s[::-1]
    elif tfc[0] == "2":
        if tfc[1] == "1":
            s = tfc[2] + s
        elif tfc[1] == "2":
            s = s + tfc[2]

print(s)

### FIXED CODE ###

s = input()
count = int(input())
flg = False
top = ""
for i in range(count):
    tfc = input().split()
    if tfc[0] == "1":
        flg = not flg
    elif tfc[0] == "2":
        if (not flg and tfc[1] == "1") or (flg and tfc[1] == "2"):
            top = top + tfc[2]
        elif (flg and tfc[1] == "1") or (not flg and tfc[1] == "2"):
            s = s + tfc[2]

if flg:
    s = s[::-1] + top
else:
    s = top[::-1] + s 
print(s)
### BUGGY CODE ###

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

ans = 0

for i in range(len(a)-1):
    for j in range(i+1, len(a)):
        ans += (a[i]*a[j])
    ans = ans % ((10**9)+7)
print(ans)

### FIXED CODE ###

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

sm = sum(a)
ans = 0

for i in range(len(a)):
    ans += a[i]*(sm-a[i])
    sm = sm - a[i]
    ans %= (10**9)+7
print(ans)
### BUGGY CODE ###

#少なくとも表示が楽
import numpy as np


P=10**9+7
N,K=map(int,input().split())
G=[]
for index in range(N):
    G.append(list(map(int,input().split())))
#こうするしかない
#G=np.matrix(G)

#print(np.dot(G,G))
#print(G*G)は正しくならないがおそらくversionの問題

def mul(x,y,p): #x[0]とlen(y)が同じなのは前提
    res=[[0]*(len(y[0])) for _ in range(len(x))]
    #res[index1][index2]を決定
    for index1 in range(len(x)):
        for index2 in range(len(y[0])):
            for index3 in range(len(y)):  #len(x[0])でも良い　
                res[index1][index2]=(res[index1][index2]+x[index1][index3]*y[index3][index2])%p
    return res


def pow(x,y,p):
    res=[[0]*(len(x)) for _ in range(len(x))]
    for index1 in range(len(x)):
        res[index1][index1]=1
    
    while y>0:
        if y&1==1:
            res=mul(res,x,p)
        x=mul(x,x,p)
        y=y>>1
    
    return res

#print(np.matrix(pow(G,2,P)))

DP_K=np.matrix(pow(G,K,P))

ans=0
for i in range(N):
    for j in range(N):
        ans=(ans+DP_K[i,j])%P

print(ans)




### FIXED CODE ###

#少なくとも表示が楽
#import numpy as np


P=10**9+7
N,K=map(int,input().split())
G=[]
for index in range(N):
    G.append(list(map(int,input().split())))
#こうするしかない
#G=np.matrix(G)

#print(np.dot(G,G))
#print(G*G)は正しくならないがおそらくversionの問題

def mul(x,y,p): #x[0]とlen(y)が同じなのは前提
    res=[[0]*(len(y[0])) for _ in range(len(x))]
    #res[index1][index2]を決定
    for index1 in range(len(x)):
        for index2 in range(len(y[0])):
            for index3 in range(len(y)):  #len(x[0])でも良い　
                res[index1][index2]=(res[index1][index2]+x[index1][index3]*y[index3][index2])%p
    return res


def pow(x,y,p):
    res=[[0]*(len(x)) for _ in range(len(x))]
    for index1 in range(len(x)):
        res[index1][index1]=1
    
    while y>0:
        if y&1==1:
            res=mul(res,x,p)
        x=mul(x,x,p)
        y=y>>1
    
    return res

#print(np.matrix(pow(G,2,P)))

#DP_K=np.matrix(pow(G,K,P))
DP_K=pow(G,K,P)

ans=0
for i in range(N):
    for j in range(N):
        #ans=(ans+DP_K[i,j])%P
        ans=(ans+DP_K[i][j])%P

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

import numpy as np
n, a, b = map(int, input().split())
mod = 10**9 + 7
# def pow1(x, n):
#     if n == 0: return 1
#     value = pow1(x, int(n / 2)) % mod
#     value *= value % mod
#     if n % 2 == 1: value *= x
def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x
all = (pow_k(2, n) % mod) - 1
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

all -= cmb(n, a) + cmb(n, b)
print(all % mod)

### FIXED CODE ###

n, a, b = map(int, input().split())
mod = 10**9 + 7
def inv(a, p):
    return pow(a, p-2, p)

def comb(n, r, p = mod):
    x, y = 1, 1
    for i in range(r):
        x = (x * (n - i)) % p
        y = (y * (i + 1)) % p
    return x * inv(y, p) % p

answer = (pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)) % mod
print(answer)
### BUGGY CODE ###

import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    a,b,c,d=MI()
    f=0
    while True:
        if f==0:
            c=c-b
            f=1
            if c==0:
                print("Yes")
                break
        if f==1:
            a=a-d
            f=0
            if a==0:
                print("No")
                break

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    a,b,c,d=MI()
    f=0
    while True:
        if f==0:
            c=c-b
            f=1
            if c<=0:
                print("Yes")
                break
        if f==1:
            a=a-d
            f=0
            if a<=0:
                print("No")
                break

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

def sol():
    n,c=map(int,input().split())
    d=[[int(i) for i in input().split()] for i in range(c)]
    t=[[int(i) for i in input().split()] for i in range(n)]
    ans=-1
    for i in range(c):
        for j in range(c):
            for k in range(c):
                q=[i,j,k]
                if len(set(q))<3: continue
                chk=0
                for p in range(n**2):
                    h,w=p//n,p%n
                    x=(h+w+2)%3
                    chk+=d[t[h][w]-1][q[x]]
                if ans==-1: ans=chk
                ans=min(ans,chk)

    print(ans)

if __name__=="__main__":
    sol()

### FIXED CODE ###

def sol():
    n,c=map(int,input().split())
    d=[[int(i) for i in input().split()] for i in range(c)]
    t=[[int(i) for i in input().split()] for i in range(n)]
    x0,x1,x2={},{},{}
    for p in range(n**2):
        h,w=p//n,p%n
        x=(h+w)%3
        o=t[h][w]-1
        if x==0:
            if o in x0: x0[o]+=1
            else: x0[o]=1
        if x==1:
            if o in x1: x1[o]+=1
            else: x1[o]=1
        if x==2:
            if o in x2: x2[o]+=1
            else: x2[o]=1
    ans=-1
    for a in range(c**2):
        for k in range(c):
            i,j=a//c,a%c
            q=[i,j,k]
            if len(set(q))<3: continue
            chk=0
            for p in x0:
                chk+=d[p][q[0]]*x0[p]
            for p in x1:
                chk+=d[p][q[1]]*x1[p]
            for p in x2:
                chk+=d[p][q[2]]*x2[p]
            if ans==-1: ans=chk
            ans=min(ans,chk)

    print(ans)

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

import sys
sys.setrecursionlimit(10**9)

def dfs(u,par):
  ans_list[u]+=ans_list[par]
  visited[u]=True
  
  for v in tree_list[u]:
    if not visited[v]:
      dfs(v,u)      
  return

N,Q=map(int,input().split())

tree_list=[[] for _ in range(N+1)]
for i in range(N-1):
  a,b=map(int,input().split())
  tree_list[a].append(b)
  tree_list[b].append(a)
#print(tree_list)

ans_list=[0]*(N+1)
for i in range(Q):
  p,x=map(int,input().split())
  ans_list[p]+=x

visited=[False]*(N+1)
dfs(1,0)

print(*ans_list[1:])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline

def dfs(u,par):
  ans_list[u]+=ans_list[par]  
  for v in tree_list[u]:
    if v!=par:
      dfs(v,u)      
  return

N,Q=map(int,input().split())

tree_list=[[] for _ in range(N+1)]
for i in range(N-1):
  a,b=map(int,input().split())
  tree_list[a].append(b)
  tree_list[b].append(a)
#print(tree_list)

ans_list=[0]*(N+1)
for i in range(Q):
  p,x=map(int,input().split())
  ans_list[p]+=x

dfs(1,0)

print(*ans_list[1:])
### BUGGY CODE ###

def zero_origin(s: str) -> int:
  return int(s) - 1

h, w = map(int, input().split())
ch, cw = map(zero_origin, input().split())
dh, dw = map(zero_origin, input().split())
s = [input() for _ in range(h)]
active = [
  [True if s[i][j] == '.' else False for j in range(w)]
  for i in range(h)]

magic = 0
stack = [(ch, cw)]
active[ch][cw] = False
visited = []
while stack:
  cur_i, cur_j = stack.pop()
  visited.append((cur_i, cur_j))
  for di, dj in [(0, 1), (0, -1), (-1, 0), (1, 0)]:
    i = cur_i + di
    j = cur_j + dj
    if 0 <= i < h and 0 <= j < w and active[i][j]:
      stack.append((i, j))
      active[i][j] = False
  if not active[dh][dw]:
    print(magic)
    break
  if not stack:
    magic += 1
    while visited:
      cur_i, cur_j = visited.pop()
      for i in range(cur_i - 2, cur_i + 3):
        for j in range(cur_j - 2, cur_j + 3):
          if 0 <= i < h and 0 <= j < w and active[i][j]:
            stack.append((i, j))
            active[i][j] = False
else:
  print(-1)

### FIXED CODE ###

def zero_origin(s: str) -> int:
  return int(s) - 1

h, w = map(int, input().split())
ch, cw = map(zero_origin, input().split())
dh, dw = map(zero_origin, input().split())
s = [input() for _ in range(h)]
active = [
  [True if s[i][j] == '.' else False for j in range(w)]
  for i in range(h)]

magic = 0
stack = [(ch, cw)]
active[ch][cw] = False
visited = []
while stack:
  cur_i, cur_j = stack.pop()
  visited.append((cur_i, cur_j))
  for di, dj in [(0, 1), (0, -1), (-1, 0), (1, 0)]:
    i = cur_i + di
    j = cur_j + dj
    if 0 <= i < h and 0 <= j < w and active[i][j]:
      stack.append((i, j))
      active[i][j] = False
  if not active[dh][dw]:
    print(magic)
    break
  if not stack:
    magic += 1
    while visited:
      cur_i, cur_j = visited.pop()
      for i in range(cur_i - 2, cur_i + 3):
        for j in range(cur_j - 2, cur_j + 3):
          if 0 <= i < h and 0 <= j < w and active[i][j]:
            stack.append((i, j))
            active[i][j] = False
else:
  print(-1)
### BUGGY CODE ###

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

def bfs(v, graph, seen, next_v, rank):
    for x in graph[v]:
        if x in seen:
            continue
        next_v.append(x)
        rank.append(rank[0]+1)
        seen.add(x)


next_v = [0]
rank = [0]
seen = {0}
#bfs
while True:
    if len(next_v) == 0 or rank[0] == 3:
        ans = "IMPOSSIBLE"
        break
    if next_v[0] == N-1:
        ans = "POSSIBLE"
        break
    bfs(next_v[0], graph, seen, next_v, rank)
    next_v.pop(0)
    rank.pop(0)
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
graph = [[] for _ in range(N)] 
for _ in range(M):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

def bfs(goal, graph, seen, next_v):
    for x in graph[next_v[0][0]]:
        if x == goal:
            return True
        if x in seen:
            continue
        next_v.append((x,next_v[0][1]+1))
        seen.add(x)
    return False


next_v = [(0,0)]
seen = {0}
#bfs
while True:
    if len(next_v) == 0 or next_v[0][1] == 2:
        ans = "IMPOSSIBLE"
        break
    if bfs(N-1, graph, seen, next_v):
        ans = "POSSIBLE"
        break
    next_v.pop(0)
print(ans)
### BUGGY CODE ###

n,k = map(int,input().split())
p = [int(i) for i in input().split()]

max = 0
j = n-k+1
s = []
for i in range(j):
    if max < sum(p[i:i+k]):
        s = p[i:i+k]
        max = sum(p[i:i+k])

def summ(i):
    s = 0
    for j in range(1,i+1):
        s += j
    return s

ss = 0
for i in s:
    ss += summ(i)/i

print(ss)

### FIXED CODE ###

n,k = map(int,input().split())
p = [int(i) for i in input().split()]


j = n-k
s = p[0:k]
max = sum(s)
su = max

for i in range(j):
    t = su+p[i+k]
    u = t-p[i]
    if max < u:
        max = t-p[i]
        s = p[i+1:i+1+k]

    su = u

def summ(i):
    return i*(i+1)/2

ss = 0


for i in s:
    ss += summ(i)/i

print(ss)