Harryxun/stf_run huggingface dataset:
N,M=map(int,input().split())
L=list(map(int,input().split()))
for i in range(M):
  X=X+L[i]
if N-X<0:
  print(-1)
else:
  print(N-X)

### FIXED CODE ###

N,M=map(int,input().split())
L=list(map(int,input().split()))
X=0
for i in range(M):
  X=X+L[i]
if N-X<0:
  print(-1)
else:
  print(N-X)
N = int(input())
A = list(map(int, input().split()))

import math
from functools import reduce

def gcd(num_list):
    return reduce(math.gcd, num_list)

kys = []

for i in range(N):
    B = A.copy()
    B.pop(i)
    kys.append(gcd(B))

print(max(kys))

### FIXED CODE ###

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

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

index = list(range(N))
L = index.copy()

L[0] = 0
for i in index[:-1]:
    #print(i)
    L[i+1] = gcd(L[i], A[i])

R = index.copy()
R.append(0)
for i in reversed(index):
    #print(i)
    R[i] = gcd(R[i+1], A[i])

# confirm
#print(L)
#print(R)

M = []
for j in range(len(L)):
    m = gcd(L[j], R[j+1])
    #print(m)
    M.append(m)

# Confirm
#print(M)

# Answer
print(max(M))
s=input()
K=int(input())
D=[]
for i in range(len(s)):
  for j in range(len(s)-i-1):
    D.append(s[i:i+j+1])
D = sorted(list(set(D)))
print(D[K-1])

### FIXED CODE ###

s=input()
K=int(input())
D=[]
for i in range(len(s)+1):
  for j in range(min(len(s)-i,5)):
    D.append(s[i:i+j+1])
D = sorted(list(set(D)))
#print(D)
print(D[K-1])
n, m, d = map(int, input().split())
if d != 0:
    print((2 * (n - d) * (m - 1)) / (n ** 2))
else:
    print((m - 1) / n)


### FIXED CODE ###

a, b = map(int, input().split())
if a + b == 15:
    print("+")
elif a * b == 15:
    print("*")
else:
    print("x")
a, b, k = (int(i) for i in input().split())
x = []
c = max(a, b)
for i in  range(1, c+1):
    if (a % i == 0) and (b % i == 0):
        x.append(i)

print(x[-k])

### FIXED CODE ###

a, b, c = (int(i) for i in input().split())  
print(min(c,(int)(b/a)))
N = str(input())
N = int(N)
Lines = input().split(" ")
Lines = list(map(int, Lines))
answer = 0

for lineI in range(len(N)):
    for lineJ in range(lineI+1,len(N)):
        for lineK in range(lineJ+1,len(N)):
             if (Lines[lineI] + Lines[lineJ] > LinesInt[lineK]) and (Lines[lineK] + Lines[lineJ] > Lines[lineI]) and (Lines[lineK] + Lines[lineI] > Lines[lineJ]):
                answer += 1
print(answer)


### FIXED CODE ###

N = int(input())
Lines = list(map(int, input().split(" ")))
Lines.sort()
answer = 0
 
import bisect
 
for lineI in range(N):
    for lineJ in range(lineI+1,N):
    	answer += bisect.bisect_left(Lines,Lines[lineI]+Lines[lineJ])-lineJ-1
print(answer)
n=input()
f=n[:2]
l=n[2:]
if (f=="00" and l=="00") or (int(f)>12 and int(l)>12):
    print("NA")
elif int(f)>12 or f=="00":
    print("YYMM")
elif int(l)>12 l=="00":
    print("MMYY")
else:
    print("AMBIGUOUS")

### FIXED CODE ###

n=input()
f=n[:2]
l=n[2:]
if (f=="00" and l=="00") or (int(f)>12 and int(l)>12) or (int(f)>12 and l=="00") or (int(l)>12 and f=="00") :
    print("NA")
elif int(f)>12 or f=="00":
    print("YYMM")
elif int(l)>12 or l=="00":
    print("MMYY")
else:
    print("AMBIGUOUS")
n,m,*a=map(int,open(0).read().split())
b=[-1]*(n+1)
if m!=0:
    for i in a:
        b[i]=0
    if a[0]==1 and a[1]==2:
        b[1],b[2]=0,0
    elif a[0]==1:
        b[2]=1
    elif a[0]==2:
        b[1]=1
    else:    
        b[1],b[2]=1,2
else:    
    b[1],b[2]=1,2  
for i in range(3,n+1):
    if b[i]==-1:
        b[i]=(b[i-1]+b[i-2])%1000000007
print(b[-1])

### FIXED CODE ###

n,m,*a=map(int,open(0).read().split())
if n==1:
    print(1)
    exit()
b=[-1]*(n+1)
a+=[0,0]
for i in a:
    b[i]=0
if a[0]==1 and a[1]==2:
    b[1],b[2]=0,0
elif a[0]==1:
    b[2]=1
elif a[0]==2:
    b[1]=1
else:    
    b[1],b[2]=1,2
for i in range(3,n+1):
    if b[i]==-1:
        b[i]=(b[i-1]+b[i-2])%1000000007
print(b[-1])
a,b,c=map(int,input().split())
l=list(range(a,a+c))
m=list(range(b,a-1,-1))
ans=sort(set(l+m))
print(*ans)

### FIXED CODE ###

a,b,c=map(int,input().split()) 
l=list(range(a,b+1)[0:c]) 
m=list(range(b,a-1,-1)[0:c]) 
ans=sorted(set(l+m)) 
print(*ans)
import math
n = int(input())
print(math.factorial(n)%(10**9+7)

### FIXED CODE ###

import math
n = int(input())
print(math.factorial(n)%(10**9+7))
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N,C = map(int, raw_input().split())
da=[]
db=[]
dc=[]

colorGrid = [map(int, raw_input().split()) for _ in range(C)]

dataGrid = [map(int, raw_input().split()) for _ in range(N)]

for i in range(N):
	for j in range(N):
		d=i+j+2
		inn=dataGrid[i][j]
		if d%3==0:
			da.append(inn)
		elif d%3==1:
			db.append(inn)
		else:
			dc.append(inn)

ka=range(C)
kb=range(C)
kc=range(C)
du = lambda oc, tc : colorGrid[oc][dc]
for i in range(C):
	ka[i]=sum([du(oc, i) for oc in da])
	kb[i]=sum([du(oc, i) for oc in db])
	kc[i]=sum([du(oc, i) for oc in dc])	


ra=ka.sort()[0:3]
rb=kb.sort()[0:3]
rc=kc.sort()[0:3]

mm=-1
for i in range(3):
	for j in range(3):
		for k in range(3):
			d=ra[i]+rb[j]+rc[k]
			if mm == -1 or d< mm:
				mm=d

print mm

### FIXED CODE ###

import sys

#+++++

def naiseki(va,vb):
	return sum([a*b for a,b in zip(va,vb)])

def main():
	n , c = map(int, input().split())
		
	ccc=[0]*c
	for i in range(c):
		ccc[i]=[0]*c
	for i in range(c):
		temp=list(map(int,input().split()))
		#ccc[i]=temp
		for j,v in enumerate(temp):
			ccc[j][i]=v
		
	pa(ccc)
		
	ddl=[0,0,0]
	for i in range(3):
		ddl[i]=[0]*c
		
	for i in range(1,n+1):
		ll=list(map(int, input().split()))
		for j, color_v in enumerate(ll,start=1):
			group=(i+j)%3
			ddl[group][color_v-1]+=1
			
	pa('_____ddl_____')
	for i in range(3):
		pa(ddl[i])
		
	rrb=[0]*3
	for i in range(3):
		rrb[i]=[0]*c	
		for j in range(c):
			rrb[i][j]=(naiseki(ddl[i], ccc[j]),j)
			
	pa('____rrb_____')
	for i in range(3):
		pa(rrb[i])
	
	c=[0]	* 3
	for i in range(3):
		rrb[i].sort()
		aa=rrb[i][:3]
		c[i]=aa
		
	pa('____ c _____')
	for i in range(3):
		pa(c[i])
		
	mm=None
	for i in range(3):
		for j in range(3):
			for k in range(3):
				ii=c[0][i][1]
				ji=c[1][j][1]
				ki=c[2][k][1]
				if ii !=ji and ji!=ki and ki!=ii:
					temp=c[0][i][0]+c[1][j][0]+c[2][k][0]
					#pa(temp)
					mm = temp if mm is None else min(mm,temp)
					
	return mm
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
N, K = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
    
    
    
s = [0] * (N-K)

for i in range(N-K):
    s[i] = 0
    for j in range(K):         
      s[i] += p[i+j]/2+0.5

print(max(s))


### FIXED CODE ###

N, K = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
    
    
#s = [0] * (N-K)

s = 0
for j in range(K):
    s += p[j]

sm = s

for i in range(N-K):
 #   s[i] = 0
    s = s + p[K+i]- p[i]
    if s > sm:
        sm = s

print( sm/2+0.5*K)
def cut(d, w, s):
    s %= 2 * (d + w)
    sq = []
    if 0 < s < w:
        sq = [(d, s), (d, w - s)]
    elif w < s < w + d:
        s -= w
        sq = [(s, w), (d - s, w)]
    elif w + d < s < 2 * w + d:
        s -= w + d
        sq = [(d, s), (d, w - s)]
    elif 2 * w + d < s < 2 * (w + d):
        s -= 2 * w + d
        sq = [(s, w), (d - s, w)]
    else:
        assert(False)
    p1, p2 = sq
    if p1[0] * p1[1] > p2[0] * p2[1]:
        p1, p2 = p2, p1
    return p1, p2


while True:
    N, W, D = map(int, input().split())
    if not (N | W | D):
        break
    square = [(D, W)]
    for _ in range(N):
        p, s = map(int, input().split())
        square[p - 1], p1 = cut(*square[p - 1], s)
        square.append(p1)
    print(*sorted(d * w for d, w in square))

### FIXED CODE ###

def cut(d, w, s):
    s %= d + w
    if 0 < s < w:
        p1, p2 = (d, s), (d, w - s)
    else:
        s -= w
        p1, p2 = (s, w), (d - s, w)
    if p1[0] * p1[1] > p2[0] * p2[1]:
        p1, p2 = p2, p1
    return [p1, p2]


while True:
    N, W, D = map(int, input().split())
    if not (N | W | D):
        break
    square = [(D, W)]
    for _ in range(N):
        p, s = map(int, input().split())
        d, w = square.pop(p - 1)
        square.extend(cut(d, w, s))
    print(*sorted(d * w for d, w in square))
S = list(map(int, list(input())))

mod = 2019
ss = [0]
tmp = 0
for i, s in enumerate(S[::-1]):
    tmp += s * pow(10, i, mod)
    tmp %= mod
    ss.append(tmp)

cnts = [0] * 2018
ans = 0
for s in ss:
    ans += cnts[s]
    cnts[s] += 1

print(ans)


### FIXED CODE ###


S = list(map(int, list(input())))

mod = 2019
ss = [0]
tmp = 0
for i, s in enumerate(S[::-1]):
    tmp += s * pow(10, i, mod)
    tmp %= mod
    ss.append(tmp)

cnts = [0] * 2019
ans = 0
for s in ss:
    ans += cnts[s]
    cnts[s] += 1

print(ans)
N, K   = map(int, input().split())
x = list(map(int, input().split()))
assert len(x) == N

m = min(x[i] - x[i-K+1] + min(abs(x[i], abs(x[i-K+1])) for i in range(K-1, N))
print(m)

### FIXED CODE ###

N, K   = map(int, input().split())
x = list(map(int, input().split()))
assert len(x) == N

m = min(x[i] - x[i-K+1] + min(abs(x[i]), abs(x[i-K+1])) for i in range(K-1, N))
print(m)
s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".split(', ')
k = int(input())
print(s[k])

### FIXED CODE ###

s = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'.split(', ')
k = int(input())
print(int(s[k-1]))
def a(t,i):
    if i==l-1:
        print(sum(int(t.split('+'))))
        exit()
    a(t+s[i+1])+a(t+'+'+s(i+1))

s=input()
a(s[0],0)
l = s.len()

### FIXED CODE ###

def dfs(i,s):
    if i==n-1:
        return sum(map(int,s.split('+')))
    return dfs(i+1,s+S[i+1])+dfs(i+1,s+'+'+S[i+1])

S=input()
n=len(S)
ans=dfs(0,S[0])
print(ans)
import sys
sys.setrecursionlimit(10000000000)
def burger(l):
    memo = [0] * (l+1)
    def l_burger(l):
        if l == 0:
            return 'P'
        if memo[l] != 0:
            return memo[l]
        
        memo[l] = 'B' + l_burger(l-1) + 'P' + l_burger(l-1) + 'B'
        return memo[l]
    return l_burger(l)
n, x = map(int, input().split())
cnt = 0
for i in burger(n)[:x]:
    if i == 'P':
        cnt += 1
        
print(cnt)
    

### FIXED CODE ###

N, X = map(int, input().split())
a = [1] * (N+1)
p = [1] * (N+1)
for i in range(1,N+1):
    a[i] = a[i-1]*2 + 3
    p[i] = p[i-1]*2 + 1
def f(n, x):
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif 2<= x <= a[n-1] + 1:
        return f(n-1, x-1)
    elif x == a[n-1] + 2:
        return p[n-1] + 1
    elif a[n-1]+3 <= x <= 2*a[n-1]+2:
        return p[n-1]+1+ f(n-1, x-(a[n-1]+2))
    elif x == 2*a[n-1]+3:
        return p[n]
print(f(N,X))
n = int(input())
n0 = 2
n1 = 1

for _ in range(1, n):
    n2 = n0+n1
    n0, n1 = n1, n2
print(n2)


### FIXED CODE ###

n = int(input())
n0 = 2
n1 = 1

if n == 1:
    print(1)
else:
    for _ in range(1, n):
        n2 = n0+n1
        n0, n1 = n1, n2
    print(n2)
N = int(input())
A = list(map(int, input().split()))
INF = 10**9

import numba
@numba.jit
def calc(N, A):
    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            ans += A[i] ^ A[j]

    ans = ans % (INF + 7)
    return ans

print(calc(N, A))

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
mod = 10 ** 9 + 7

for i in range(60):
    x, y = 0, 0    
    B = A >> i & 1
    x = np.count_nonzero(B)
#     for Ai in A:
#         if Ai >> i & 1:
#             x += 1
    y = N - x
    ans += (x * y) * (2 ** i)
    
print(ans%mod)
N = int(input())
bricks = list(map(int,input().split(" ")))

if 1 not in bricks:
    print(-1)

else:
    K = 0
    value = 1
    while(value in bricks):
        index = bricks.index(value)
        bricks[value-1:index]=[]
        K += (index+1-value)
        value += 1
print(K)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
 
count = 1
k = 0       #break time
 
for i in range(n):
    if a[i] == count:
        count += 1
    else:
        k += 1
 
if k == n:
    k = -1
 
print(k)
from collections import defaultdict
from heapq import heappush,heappop

# map(int, input().split())
N, Q = map(int, input().split())
events = []
for i in range(N):
    s, t, x = map(int, input().split())
    events.append((s - x, 0, x))
    events.append((t - x, 1, x))

for i in range(Q):
    d = int(input())
    events.append((d, 2, i))

events = sorted(events)

q = [INF]
cnt = defaultdict(int)
ans = [INF]*Q
for a,b,c in events:
    if b == 0:
        heappush(q,c)
        cnt[c] += 1
    elif b==1:
        cnt[c] -= 1
    else:
        while len(q) > 1 and cnt[q[0]] == 0:
            heappop(q)
        if q[0] == INF:
            ans[c] = -1
        else:
            ans[c] = q[0]
for a in ans:
    print(a)


### FIXED CODE ###

"""
愚直に一人一人交通止めに対してシミュレートしていは、絶対に間に合わない。

そこで、「この時間に出発したら"まず最初に"この通行止めで引っかかる」というのを前処理でまとめておく。
これは座標圧縮とセグメント木っぽいものを用いることで実現可能。
"""
N,Q = map(int,input().split())
STX = [list(map(int,input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]
times = set(D+[s-x for s,t,x in STX]+[t-x for s,t,x in STX])
compTimes = {t:i for i,t in enumerate(sorted(times))}

class originalSegTree:
    def __init__(self,n):
        self.end_leaves = 2**n.bit_length()
        self.tree = [float("INF")]*(2*self.end_leaves)
    
    def add(self,left,right,x):
        L = left + self.end_leaves
        R = right + self.end_leaves
        while L < R:
            if L&1:
                self.tree[L] = min(self.tree[L],x)
                L += 1
            if R&1:
                R -= 1
                self.tree[R] = min(self.tree[R],x)
            L >>= 1
            R >>= 1
    
    def merge(self):
        for i in range(1,self.end_leaves):
            self.tree[i*2] = min(self.tree[i],self.tree[i*2])
            self.tree[i*2+1] = min(self.tree[i],self.tree[i*2+1])

seg = originalSegTree(len(compTimes))
for s,t,x in STX:
    a = compTimes[s-x]
    b = compTimes[t-x]
    seg.add(a,b,x)

seg.merge()

for d in D:
    c = compTimes[d]
    ans = seg.tree[c+seg.end_leaves]
    if ans == float("INF"):
        ans = -1
    print(ans)
(n, x) = list(map(int, input().split()))
x_list = list(map(int, input().split()))

x_list.append(x)
x_list.sort()

min_diff = 99999999999
for i in range(len(x_list) - 1):
    diff = x_list[i + 1] - x_list[i]
    if min_diff > diff:
        min_diff = diff

# 差分の最小を約分していく
x_diff = [xx - x_list[0] for xx in x_list]

for i in range(1, min_diff):
    if min_diff % i != 0:  # 約分できない場合は次の数に進む
        continue
    xx = min_diff // i
    is_divided = [j for j in x_diff if j % xx != 0]
    if len(is_divided) == 0:
        print(xx)
        exit()


### FIXED CODE ###

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

if a % 2 == 0 or b % 2 == 0:
    print('No')
else:
    print('Yes')
N = int(input())
A = list(map(int,input().split()))

count = 1

for i in range(1,N-1):
  if A[i-1] > A[i]:
    up,down = 0,1
  elif A[i-1] < A[i]:
    up,down = 1,0
  if up == 1 and A[i] > A[i+1]:
    count += 1
  elif down == 1 and A[i] < A[i+1]:
    count += 1
    
print(count)


### FIXED CODE ###

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

count = 1
up,down = 1,1

for i in range(1,N):
  if A[i-1] > A[i]:
    up = 0
    if down == 0:
      count += 1
      up,down = 1,1
  elif A[i-1] < A[i]:
    down = 0
    if up == 0:
      count += 1
      up,down = 1,1

print(count)
n=int(input())
arr=[(int(input()),i//n) for i in range(2*n)]
arr=sorted(arr,key=lambda x:x[0])
mod=10**9+7
ans=1
cnta=0
cntb=0
for pos,flag in arr:
  if flag==0:
    if cntb==0:
      cnta+=1
    else:
      cntb-=1
  else:
    if cnta>=1:
      ans*=cnt
      ans%=mod
      cnta-=1
    else:
      cntb+=1
print(ans)

### FIXED CODE ###

n=int(input())
arr=[(int(input()),i//n) for i in range(2*n)]
arr=sorted(arr,key=lambda x:x[0])
mod=10**9+7
ans=1
cnta=0
cntb=0
for pos,flag in arr:
  if flag==0:
    if cntb==0:
      cnta+=1
    else:
      ans*=cntb
      ans%=mod
      cntb-=1
  else:
    if cnta==0:
      cntb+=1
    else:
      ans*=cnta
      ans%=mod
      cnta-=1
print(ans)
# -*- coding: utf-8 -*-
N = int(input())
H = list(map(int,input().split()))

ans = 'Yes'
diff = 0

for i in range(N - 1):
	diff = H[i + 1] - H[i]

	if diff > 1:
		H[i + 1] -= 1
	elif diff < 0:
		ans = 'No'
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-

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

if A[2] - (A[0] - A[1]) <= 0:
	print(remain)
else:
	remain = A[2] - (A[0] - A[1])
	print(remain)
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
S = input()
T = input()
L = N*M//gcd(N, M)
X = [""]*L

for i, s in enumerate(S):
	if i*(L//N) <= L-1:
		X[i*(L//N)] = s

for i, t in enumerate(T):
	if i*(L//M) <= L-1 and X[i*(L//M)] and X[i*(L//M)] != t:
		print(-1)
		break
else:
	print(L)


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
S = input()
T = input()
L = N*M//gcd(N, M)
g = gcd(N, M)
for i in range(g):
	if S[N//g*i] != T[M//g*i]:
		print(-1)
		break
else:
	print(L)
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
right=[i for i in l if i>0]
left=[i for i in l if i<=0]
if not left: 
    sm=0 
    sm+=l[0]
    for i in range(1,k):
        sm+=l[i]-l[i-1]
    print(sm)
    exit()
if not right: 
    sm=0 
    l=[abs(i) for i in l]
    sm=l[0]
    for i in range(1,k):
        sm+=(l[i]-l[i-1])
    print(sm)
    exit()

le=len(left)
ri=len(right)
rl=[0]*le 
rr=[0]*ri 
left=[abs(i) for i in left]
#print(left)
left=left[::-1]
rl[0]=left[0]
for i in range(1,le):
    rl[i]=rl[i-1]+(left[i]-left[i-1])
rr[0]=right[0]
mini=10**9 
if len(left)>=k:
    mini=min(mini,rl[k-1])
if len(right)>=k:
    mini=min(mini,rr[k-1])
for i in range(1,ri) :
    rr[i]=rr[i-1]+(right[i]-right[i-1])
#print(rl)
#print(rr)
if k==n:
    print(sum(rl)+sum(rr))
    exit()
for a in range(1,len(left)):
    b=k-a 
    #print(a,b,rl[a],rr[b-1])
    mini=min(mini,2*rl[a-1]+rr[b-1],rl[a-1]+2*rr[b-1])
print(mini)

### FIXED CODE ###

n,k=map(int,input().split())
l=[int(i) for i in input().split()]
right=[i for i in l if i>0]
left=[i for i in l if i<=0]
if not left: 
    sm=0 
    sm+=l[0]
    for i in range(1,k):
        sm+=(l[i]-l[i-1])
    print(sm)
    exit()
if not right: 
    sm=0 
    l=[abs(i) for i in l]
    l.sort()
    sm=l[0]
    for i in range(1,k):
        sm+=(l[i]-l[i-1])
    print(sm)
    exit()
le=len(left)
ri=len(right)
rl=[0]*le 
rr=[0]*ri 
left=[abs(i) for i in left]
left=left[::-1]
rl[0]=left[0]
for i in range(1,le):
    rl[i]=rl[i-1]+(left[i]-left[i-1])
rr[0]=right[0]
mini=10**20 
for i in range(1,ri) :
    rr[i]=rr[i-1]+(right[i]-right[i-1])
if len(left)>=k:
    mini=min(mini,rl[k-1])
if len(right)>=k:
    mini=min(mini,rr[k-1])
#print(left,right,rl,rr)
for a in range(1,len(left)+1):
    b=k-a 
    #print(a,b)
    if b>len(rr):
        #print('hsef')
        continue 
    mini=min(mini,2*rl[a-1]+rr[b-1],rl[a-1]+2*rr[b-1])
print(mini)
N, A, B, C, D = map(int, input().split())
mod = 10 ** 9 + 7

# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, N + 2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod - 2, mod))


# 組み合わせ計算
def nCr(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod


# n人いたときに、k人組を、x個つくる場合の数
def f(n, k, x):
    return nCr(n, k * x) * factorial[k * x] * pow(pow(factorial[k], x, mod), mod-2, mod) * inverse[x] % mod


dp = [[0] * (N + 1) for i in range(2)]
dp[0][0] = 1
dp[1][0] = 1

for k in range(A, B+1):  # k人からなるグループをこれから作りますよ
    for n in range(N + 1):  # すでにn人は使っちゃってますよ
        cnt = 0
        X = [0] + list(range(C, D + 1))
        for x in X:
            if n - k * x < 0:  # はみ出る段階で打ち切りますよ
                break
            if k % 2 == 1:
                cnt += f(n, k, x) * dp[0][n - k * x] % mod
            else:
                cnt += f(n, k, x) * dp[1][n - k * x] % mod

        if k % 2 == 1:
            dp[1][n] = cnt
        else:
            dp[0][n] = cnt

if N % 2 == 1:
    print dp[1][N]
else:
    print dp[0][N]


### FIXED CODE ###

N, A, B, C, D = map(int, raw_input().split())
mod = 10 ** 9 + 7

# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in xrange(1, N + 2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod - 2, mod))


# 組み合わせ計算
def nCr(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod


# n人いたときに、k人組を、x個つくる場合の数
def f(n, k, x):
    return nCr(n, k * x) * factorial[k * x] * pow(pow(factorial[k], x, mod), mod-2, mod) * inverse[x] % mod


dp = [0] * (N + 1)
dp[0] = 1

for k in xrange(A, B + 1):  # k人からなるグループをこれから作りますよ
    for n in range(1, N + 1)[::-1]:  # すでにn人は使っちゃってますよ
        X = xrange(C, D + 1)
        for x in X:
            if n - k * x < 0:  # はみ出る段階で打ち切りますよ
                break
            dp[n] += f(n, k, x) * dp[n - k * x] % mod

print(dp[N] % mod)
fac=[0]*505050
inv=[0]*505050
finv=[0]*505050
mod=1000000007
fac[0]=finv[0]=inv[1]=1
for i in range(1,500010):
  fac[i]=fac[i-1]*i%mod
  inv[i]=(mod-inv[mod%i]*(mod//i))%mod
  finv[i]=finv[i-1]*inv[i]%mod

def C(n,r):
  if n<0 or r<0 or n<r: return 0
  return fac[n]*inv[n-r]*inv[r]%mod

n,m=map(int,input().split())
ans=0
for i in range(N+1):
  ans+=C(n,i)*fac[M]*finv[M-i]*(C(M-i,N-i)**2)*(1 if i%2==0 else -1) % mod
print(ans%mod)


### FIXED CODE ###

fac=[1]*505050
inv=[1]*505050
finv=[1]*505050
mod=1000000007
for i in range(2,500010):
  fac[i]=fac[i-1]*i%mod
  inv[i]=-inv[mod%i]*(mod//i)%mod
  finv[i]=finv[i-1]*inv[i]%mod

def C(n,r):
  if n<0 or r<0 or n<r: return 0
  return fac[n]*finv[n-r]*finv[r]%mod

N,M=map(int,input().split())
ans=0
for i in range(N+1):
  ans+=C(N,i)*fac[M]*finv[M-i]*((fac[M-i]*finv[M-N])**2)*(1 if i%2==0 else -1) % mod
print(ans%mod)
while True:
  m,f,r = map(int,raw_input().split())
  if (m == -1 or f == -1) or m + f < 30:
    print 'F'
    continue
  elif m + f > 80:
    print 'A'
    continue
  elif m + f > 65:
    print 'B'
    continue
  elif m + f > 50 or (m + f > 40 and r > 50):
    print 'C'
    continue

### FIXED CODE ###

while True:
  m,f,r = map(int,raw_input().split())
  if m + f + r == -3: break
  if (m == -1 or f == -1) or m + f < 30:
    print 'F'
    continue
  elif m + f >= 80:
    print 'A'
    continue
  elif m + f >= 65:
    print 'B'
    continue
  elif m + f >= 50 or (m + f >= 30 and r >= 50):
    print 'C'
    continue
  elif m + f >= 30:
    print 'D'
    continue