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

import itertools as itr
n, a = list(map(int, input().split()))
x = list(map(int, input().split()))

#print(n,a)
#print(x)

cnt=0
for i in range(1,n+1):
    for y in itr.combinations(x,i):
        #print(y)
        if sum(y) == i*a:
            cnt += 1
print(cnt)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Aug  5 12:20:16 2018
ABC44C
@author: maezawa
"""

def f(i, j):
    global xa
    global dp
    if i==0:
        cnt = 0
        if j==0:
            cnt += 1
        if j==xa[0]:
            cnt += 1
        return cnt
    if (i, j) in dp:
        return dp[(i,j)]
    else:
        dp[(i,j)] = f(i-1,j-xa[i]) + f(i-1,j)
        #print(i,j, dp[(i,j)])
        return dp[(i,j)]


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

xa = [x[i]-a for i in range(n)]
dp = dict([])

print(f(n-1, 0)-1)
### BUGGY CODE ###

# import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    def main():
        X=int(input())
        d=deque([1,0,-1])
        now=2
        while True:
            for i in range(3**(now-1)):
                dd=d.popleft()
                if dd==X:
                    return now
                else:
                    d.append(dd+now)
                    d.append(dd)
                    d.append(dd-now)
            now+=1
    print(main()-1)






resolve()

### FIXED CODE ###

def resolve():

    X=int(input())
    cnt=1
    while True:
        val=cnt*(cnt+1)//2
        if val>=X:
            print(cnt)
            break
        else:
            cnt += 1


resolve()
### BUGGY CODE ###

import numpy as np
import sys
input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int, (input().split())))
A.sort()
cnt = np.zeros(10**6+10, dtype=np.int32)
for i in range(N):
    cnt[A[i]] += 1
for i in range(N-1):
    if cnt[A[i]] != 0:
        cnt[A[i]*2::A[i]] = 0
ans = np.count_nonzero(cnt==1)
print(ans)

### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int, (input().split())))
A.sort()
cnt = np.zeros(10**6+10, dtype=np.int32)
for x in A:
    if cnt[x] != 0:
        cnt[x] = 2
        continue
    cnt[x::x] += 1
ans = 0
for x in A:
    if cnt[x] == 1:
        ans += 1
print(ans)
### BUGGY CODE ###

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


def ex(list):
    ans = 0
    for i in list:
        ans += (i+1)/2
    return(float(ans))


ans = 0
for i in range(N-K+1):
    p = pn[i:i+K]
    ans = max(ans, ex(p))

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

### FIXED CODE ###

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

pn_t = [0]
for i in range(N):
    pn_t.append(pn[i]+pn_t[i])

l = 0
for i in range(N-K+1):
    l = max(l, pn_t[K+i]-pn_t[i])
ans = (l+K)/2
print(ans)
### BUGGY CODE ###

n,a,b = [int(x) for x in input().rstrip().split()]
l=[]
ans=0
ans1=1
for i in range(1,n+1):
    ans1 = ans1*((n-i+1)/i)
    if i==a or i==b:
        l.append(ans1)
        continue
    
    if n<(i/2):
            ans+=l[n-i]
    else:
        ans+=ans1
        l.append(ans1)
print(round(ans%(10**9+7)))

### FIXED CODE ###

mod=10**9+7
n,a,b=[int(x) for x in input().rstrip().split()]

def modpow(a,n):
  if n<1:
    return 1
  ans=modpow(a,n//2)
  ans=(ans*ans)%mod
  if n%2==1:
    ans*=a
  return ans%mod

def conb(n,i):
  inv,ans=1,1
  for j in range(1,i+1):
    ans=ans*(n-j+1)%mod
    inv=inv*j%mod
  return (ans*modpow(inv,mod-2))%mod

ans_n=pow(2,n,mod)-1
ans_a=conb(n,a)
ans_b=conb(n,b)

print((ans_n-ans_a-ans_b)%mod)
### BUGGY CODE ###

from collections import deque

N , M = map(int, input().split())
room = [-1 for k in range(N)]
L = [[] for k in range(M)]
for k in range(M):
    L[k] = deque(map(int, input().split()))
nextvisit =[[1]]
visited =deque(0 for k in range(N))
visited[0]=1
not_used = deque(k for k in range(M))
for j in range(M-1):
    nextvisit.append([])
    for visit in nextvisit[0]:

        """
        print("L=",L)
        print("next=",nextvisit[j])
        print("not_used", not_used)
        """
        erase = []
        for k in not_used:
            if visit == L[k][1]:
                if visited[L[k][0]-1] == 0:
                    nextvisit[1].append(L[k][0])
                    visited[L[k][1]-1] = 1
                    visited[L[k][0]-1] = 1
                    room[L[k][0]-1] = L[k][1]
                erase.append(k)
                
            if visit == L[k][0]:
                if visited[L[k][1]-1] == 0:
                    nextvisit[1].append(L[k][1])
                    visited[L[k][0]-1] = 1
                    visited[L[k][1]-1] = 1
                    room[L[k][1]-1] = L[k][0]  
                erase.append(k)

        not_used = deque(set(not_used)-set(erase))
    del nextvisit[0]
    
    if len(not_used) == 0:
        break
print("Yes")
if N >2:
    for k in range(1, N):
        print(room[k])
if N ==2:
    print(1)

### FIXED CODE ###

N, M = map(int, input().split())
nextroom = [[] for _ in range(N)]
for _ in range(M):
  A, B = map(int, input().split())
  nextroom[A-1].append(B-1)
  nextroom[B-1].append(A-1)

sgn = [-1 for _ in range(N)]
sgn[0] = 0

depth = [float('inf') for _ in range(N)]
depth[0] = 0

now = [0]
nextvisit = []
for j in range(1, M+1):
  for n in now:
    for i in nextroom[n]: 
      if depth[i] > j:
        nextvisit.append(i)
        sgn[i] = n
        depth[i] = j
  now = [] + nextvisit
  nextvisit = []

if -1 in sgn:
  print('No')
else:
  print('Yes')
  for k in range(1, len(sgn)):
    print(sgn[k]+1)
### BUGGY CODE ###

N = int(input())
num = list(map(int,input().split()))
if 0 in set(num):
  print(0)
else:
  a = 1
  for n in num:
    a = n*a
  if a> 10**18:
    a=-1
  print(a)

### FIXED CODE ###

import sys
N = int(input())
num = list(map(int,input().split()))
num.sort(reverse=True)
a = 1
if num[-1] == 0:
  print(0)
else:
  for n in range(N):
    a = num[n]*a
    if a> 10**18:
      print(-1)
      sys.exit()
  print(a)
### BUGGY CODE ###

N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]
D2 =D
for i in T:
    try:
        D2.remove(i)
    except:
        print('NO')
        exit()
print('YES')

### FIXED CODE ###

N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]

if N < M:
    print('NO')
    exit()

from collections import Counter
 
d_count = Counter(D)
t_count = Counter(T)
for k,v in t_count.items():
    if k not in d_count:
        print('NO')
        exit()
    if d_count[k]< v:
        print('NO')
        exit()
print('YES')
### BUGGY CODE ###

import sys

sys.setrecursionlimit(100000)

N, K = map(int, raw_input().split())
H = map(int ,raw_input().split())
cost = [-1]*N

def sumOfCost(i):
  if cost[i] >= 0:
    return cost[i]
  elif i == 0:
    soc = 0
  else:
    soc = 1000000000
    for j in range(1, K+1):
      if i-j < 0:
        break
      soc = min(soc, sumOfCost(i-j)+abs(H[i]-H[i-j]))
  cost[i] = soc
  return soc

print sumOfCost(N-1)
    



### FIXED CODE ###

import sys

sys.setrecursionlimit(100000)

N, K = map(int, raw_input().split())
H = map(int ,raw_input().split())
cost = [-1]*N

def sumOfCost(i):
  if cost[i] >= 0:
    return cost[i]
  elif i == 0:
    soc = 0
  else:
    soc = 1000000000
    for j in reversed(range(1, min(i+1,K+1))):
      soc = min(soc, sumOfCost(i-j)+abs(H[i]-H[i-j]))
  cost[i] = soc
  return soc

print sumOfCost(N-1)
### BUGGY CODE ###

from heapq import heappop, heappush
def main():
    h,w,k = map(int,input().split())
    x,y,gx,gy = map(int,input().split())
    x -= 1
    gx -= 1
    y -= 1
    gy -= 1
    c = [list(input()) for _ in range(h)]
    d = [[-1 for _ in range(w)] for _ in range(h)]
    dx = (1, 0, -1, 0)
    dy = (0, 1, 0, -1)
    que = []
    heappush(que,(0,(x,y)))
    d[x][y] = 0
    while que:
        [num,(qx,qy)] = heappop(que)
        if qx == gx and qy == gy:
            break
        for i in range(4):
            for K in range(1,k+1):
                nx = qx + dx[i]*K
                ny = qy + dy[i]*K
                if not(nx>=0 and h>nx and ny>=0 and w>ny) or c[nx][ny] == '@':
                    break
                if d[nx][ny] == -1 or d[nx][ny] > d[qx][qy]+1:
                    d[nx][ny] = d[qx][qy] + 1
                    heappush(que,[d[nx][ny],(nx,ny)])
                    if nx == gx and ny == gy:
                        print(d[gx][gy])
                        return
    print(d[gx][gy])


if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import deque
def main():
    h,w,k = map(int,input().split())
    x,y,gx,gy = map(int,input().split())
    x -= 1
    gx -= 1
    y -= 1
    gy -= 1
    c = [list(input()) for _ in range(h)]
    d = [[-1 for _ in range(w)] for _ in range(h)]
    dx = (1, 0, -1, 0)
    dy = (0, 1, 0, -1)
    que = deque()
    que.append((x,y))
    d[x][y] = 0
    while que:
        (qx,qy) = que.popleft()
        if qx == gx and qy == gy:
            break
        for i in range(4):
            for K in range(1,k+1):
                nx = qx + dx[i]*K
                ny = qy + dy[i]*K
                if not(nx>=0 and h>nx and ny>=0 and w>ny) or c[nx][ny] == '@' or (d[nx][ny] != -1 and d[nx][ny] < d[qx][qy]+1):
                    break
                if d[nx][ny] == -1 or d[nx][ny] > d[qx][qy]+1:
                    d[nx][ny] = d[qx][qy] + 1
                    que.append((nx,ny))
    print(d[gx][gy])
 
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

def S(k):
    return sum(int(x) for x in str(k))
def T(k):
    return k / S(k)

d = {}
MAX = int(1e15) + 1e9
for i in range(1, 99999):
    t = i
    while t < MAX:
        d[t] = T(t)
        t = t * 10 + 9

keys = sorted(list(d.keys()))

# for k in keys:
#     print(k, d[k])

mn = None
ans = []
for k in reversed(keys):
    if mn == None:
        mn = d[k]
    else:
        if mn >= d[k]:
            ans.append(k)
            mn = min(mn, d[k])

ans.reverse()
K = int(input())
ans = ans[:K]
for a in ans:
    print(a)


### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

def T(k):
    orig_k = k
    sk = 0
    while k > 0:
        sk += k % 10
        k //= 10
    return orig_k / sk

d = {}
MAX = int(1e15) + 1e9
for i in range(1, 99999):
    t = i
    while t < MAX:
        d[t] = T(t)
        t = t * 10 + 9

keys = sorted(list(d.keys()))

# for k in keys:
#     print(k, d[k])

mn = None
ans = []
for k in reversed(keys):
    if mn == None:
        ans.append(k)
        mn = d[k]
    else:
        if mn >= d[k]:
            ans.append(k)
            mn = min(mn, d[k])

ans.reverse()

K = int(input())
ans = ans[:K]
for a in ans:
    print(a)
### BUGGY CODE ###

N = int(input())

lst = list()
count = 0
for i in range(1, N+1):
    for j in range(i, N+1):
        ahead = int(str(i)[0])
        atail = i % 10
        bhead = int(str(j)[0])
        btail = j % 10
        if ahead == btail and atail == bhead:
            count += (1 if i == j else 2)
print(count)


### FIXED CODE ###

def main3(N):
    lst = list()
    for i in range(1, 10):
        lst.append([0]*9)

    for n in range(1, N+1):
        head = int(str(n)[0])
        tail = int(str(n)[-1])
        #末尾が0はNG
        if tail != 0:
            lst[head-1][tail-1] += 1
        
    #for i in range(0, len(lst)):
    #    print(lst[i])
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

N = int(input())
main3(N)
### BUGGY CODE ###

#%%time
mod=10**9+7
s=input()
#s="?"*10**5


#p=[[i*j%13 for i in range(10)] for j in range(13)]
rev=reversed(s)
d=[0 for i in range(13)]
d[0]=1
keep=[0 for _ in range(13)]
mul=1
cal=0
for v in rev:

    #print(i+num+1)
    if v=="?":
        t_d=keep.copy()
        #print("i,tmp:",i+num+1,",",tmp)
        for k in range(0,13):
            for j in range(0,10):
                t_d[(mul*j+k)%13]+=d[k]
            t_d[k]%=mod
        d=t_d
    else:
        cal+=mul*int(v)%13
    mul*=10
    mul%=13
        #print(t_d)
cal%=13
if cal<=5:
    cal=5-cal
else:
    cal=18-cal
print(d[cal]%mod)
#print(d)
#h=d
#print([i%mod for i in h])



### FIXED CODE ###

#%%time
mod=10**9+7
s=input()


#p=[[i*j%13 for i in range(10)] for j in range(13)]
rev=reversed(s)
d=[0 for i in range(13)]
d[0]=1
keep=[0 for _ in range(13)]
mul=1
cal=0
for v in rev:
    #print(i+num+1)
    if v=="?":
        t_d=[0 for _ in range(13)]
        #print("i,tmp:",i+num+1,",",tmp)
        for k in range(0,13):
            for j in range(0,10):
                t_d[(mul*j+k)%13]+=d[k]
            t_d[k]%=mod
        d=t_d
    else:
        cal+=mul*int(v)%13
    mul*=10
    mul%=13
        #print(t_d)
cal%=13
if cal<=5:
    cal=5-cal
else:
    cal=18-cal
print(d[cal]%mod)
#print(d)
#h=d
#print([i%mod for i in h])
### BUGGY CODE ###

S_raw = input()
T_raw = input()

S = list(S_raw)
T = list(T_raw)

i = 0
j = 0

j_list = []
S_list = []

lt = len(T)
ls = len(S)

while True:
	if j == ls or i == lt:
		if not i == lt:
			print("UNRESTORABLE")
			exit(0)
		elif j != ls:
			j_list.append(j)
			i = 0
			j = j - lt 
		else:
			j_list.append(j)
			break

	if T[i] == S[j]:
		i += 1
		j += 1
	elif S[j] == '?':
		i += 1
		j += 1
	else:
		i = 0
		j += 1


for j in j_list:
	for i,c in zip(range(j-lt,j),T):
		S[i] = c

	S_tmp = ''

	for i in range(ls):
		if S[i] == '?':
			S_tmp += 'a'
		else:
			S_tmp += str(S[i])

	S_list.append(S_tmp)

S_list.sort()
print(S_list[0])

### FIXED CODE ###

S_raw = input()
T_raw = input()

S = list(S_raw)
T = list(T_raw)

i = 0
j = 0

j_list = []
S_list = []

lt = len(T)
ls = len(S)

while True:
	if (j >= ls) or (i >= lt):
		if i < lt  :
			if j_list == []:
				print("UNRESTORABLE")
				exit(0)
			else:
				break
		elif j < ls:
			j_list.append(j)
			i = 0
			j = j - lt + 1

		else:
			j_list.append(j)
			break

	if T[i] == S[j]:
		i += 1
		j += 1
	elif S[j] == '?':
		i += 1
		j += 1
	else:
		j -= (i - 1)
		i = 0

for k in j_list:
	M = S[:]
	for i,c in zip(range(k-lt,k),T):
		M[i] = c

	S_tmp = ''

	for i in range(ls):
		if M[i] == '?':
			S_tmp += 'a'
		else:
			S_tmp += M[i]

	S_list.append(S_tmp)

S_list.sort()
print(S_list[0])
### BUGGY CODE ###

mods_count = [0] * 2019

mod = 2019
ans = 0
S = input()
for s in S:
    num = int(s)
    new = [0] * 2019
    for i in range(2019):
        index = i + num
        count = mods_count[i]
        new[index % 2019] += count
    new[num] += 1

    ans += new[0]
    nexts = [0] * 2019
    for i in range(2019):
        index = i * 10
        count = new[i]
        nexts[index % 2019] += count

    mods_count = nexts

print(ans)


### FIXED CODE ###

from collections import Counter


mod = 2019
S = map(int, reversed(input()))

mods = [0]
num = 0
digit = 1
for s in S:
    num += s * digit
    num %= mod
    mods.append(num)
    digit = digit * 10 % mod

counter = Counter(mods)
ans = 0
for count in counter.values():
    ans += count * (count-1) // 2
print(ans)
### BUGGY CODE ###

import bisect

N, M, Q = map(int, input().split())
trains = [list(map(int, input().split())) for i in range(M)]
queries = [list(map(int, input().split())) for i in range(Q)]
trains.sort(key = lambda x: x[1])
L = [train[0] for train in trains]
R = [train[1] for train in trains]

dp = [[0] * N for i in range(N)]
for i in range(N):
    for j in range(i, N):
        right = bisect.bisect_right(R, j + 1)
        A = sorted(L[:right])
        left = bisect.bisect_left(A, i + 1)
        dp[i][j] = right - left

for q in range(Q):
    pi, qi = queries[q]
    print(dp[pi - 1][qi - 1])


### FIXED CODE ###

N, M, Q = map(int, input().split())
trains = [list(map(int, input().split())) for i in range(M)]
queries = [list(map(int, input().split())) for i in range(Q)]

A  =[[0] * N for _ in range(N)] #A[i][j] = (i + 1) -> (j+1)なる列車の本数
for train in trains:
    li, ri = train
    A[li - 1][ri - 1] += 1

dp = [[0] * N for __ in range(N)]
for i in range(N - 1, -1, -1):
    for j in range(i, N):
        if i == j:
            dp[i][j] = A[i][j]
        else:
            dp[i][j] = dp[i][j - 1] + dp[i + 1][j] + A[i][j] - dp[i + 1][j - 1]
for q in range(Q):
    pi, qi = queries[q]
    print(dp[pi - 1][ qi - 1])
### BUGGY CODE ###

INF = float('inf')
N, M = map(int, input().split())
dp = [INF for _ in range(2**N)]
dp[0] = 0
for i in range(M):
    a, _ = map(int, input().split())
    *C, = map(int, input().split())
    open_bit = 0
    for i in C: open_bit |= 1 << i-1
    for i in range(2**N): dp[i|open_bit] = min(dp[i|open_bit], dp[i] + a)
print(dp[-1] if dp[-1] != INF else -1)

### FIXED CODE ###

def main():
    INF = float('inf')
    N, M = map(int, input().split())
    dp = [INF for _ in range(2**N)]
    dp[0] = 0
    for i in range(M):
        a, _ = map(int, input().split())
        *C, = map(int, input().split())
        open_bit = 0
        for i in C: open_bit |= 1 << i-1
        for i in range(2**N): dp[i|open_bit] = min(dp[i|open_bit], dp[i] + a)
    print(dp[-1] if dp[-1] != INF else -1)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
A = [int(input()) for i in range(N)]

ANS = []
for i in range(N):
  Alist = A[:i]+A[i+1:]
  ANS.append(max(Alist))

for i in ANS:
    print(i)


### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]

maxA = max(A)
max_in = A.index(max(A))
ANS = [maxA]*N
ANS[max_in] = max(A[:max_in]+A[max_in+1:])

for i in ANS:
    print(i)
### BUGGY CODE ###

s = input()
q = int(input())

rev = False
for i in range(q):
    query = input().split()
    if query[0] == "1":
        rev ^= True
    else:
        if (query[1] == "1" and not rev) or (query[1] == "2" and rev):
            s = query[2] + s
        else:
            s = s + query[2]

if rev:
    print(s[::-1])
else:
    print(s)

### FIXED CODE ###

from collections import deque

s = deque(input())
q = int(input())

rev = False
for i in range(q):
    query = input().split()
    if query[0] == "1":
        rev ^= True
    else:
        if (query[1] == "1" and not rev) or (query[1] == "2" and rev):
            s.appendleft(query[2])
        else:
            s.append(query[2])

if rev:
    print("".join(list(s)[::-1]))
else:
    print("".join(list(s)))
### BUGGY CODE ###

from bisect import bisect_left
from operator import itemgetter
import sys

input = sys.stdin.readline

N, Q = map(int, input().split(" "))
check_points = [tuple(map(int, input().split(" "))) for _ in range(N)]
querys = [int(input()) for _ in range(Q)]
time = [-1] * Q
check_points = sorted(check_points, key=itemgetter(2))
b_left = bisect_left

for line in check_points:
    s, f, x = line
    start = s-x
    end = f-x
    left = b_left(querys, start)
    right = b_left(querys, end)
    while left < right:
        if time[left] == -1:
            time[left] = x
            left += 1

for t in time:
    print(t)


### FIXED CODE ###

from bisect import bisect_left
from operator import itemgetter

N, Q = map(int, input().split(" "))
check_points = [tuple(map(int, input().split(" "))) for _ in range(N)]
querys = [int(input()) for _ in range(Q)]
time = [-1 for _ in range(Q)]
jump = [-1 for _ in range(Q)]
check_points = sorted(check_points, key=itemgetter(2))
b_left = bisect_left

for line in check_points:
    s, f, x = line
    start = s-x
    end = f-x
    left = b_left(querys, start)
    right = b_left(querys, end)
    while left < right:
        if time[left] == -1:
            time[left] = x
            jump[left] = right
            left += 1
        else:
            left = jump[left]

for t in time:
    print(t)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b = []
for i in a:
    b.append(i)
    b.reverse()

for i in b:
    print(i)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a=a[::-1]
b=[0]*n
x,y=0,1
t=True
for z in a:
    if t:
        b[x]=z
        x+=1
        t=False
    else:
        b[-y]=z
        y+=1
        t=True
print(*b)
### BUGGY CODE ###

import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=0
high=max(A)
sig=(low+high)//2
tf=0
if K==0:
  tf=1
  ans=high
while tf==0:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+sig)//2
  else:
    low=sig+1
    sig=(high+sig)//2
print(ans)

### FIXED CODE ###

import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=0
high=max(A)
sig=(low+high)//2
tf=0
if K==0:
  tf=1
  ans=high
while tf==0:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)
### BUGGY CODE ###

import itertools
import collections
n,k=map(int,input().split())
candle=list(map(int,input().split()))
com=list(itertools.product(["1","0"], repeat=n))
ans=200000000
for i in range(2**n):
  count=collections.Counter(com[i])
  if count["1"]==k:
    comtemp="".join(com[i])
    start=candle[comtemp.find("1")]
    end=candle[comtemp.rfind("1")]
    temp=0
    if start>=0:
      temp=abs(end)
      if temp<ans:
        ans=temp
    if end<=0:
      temp=abs(start)
      if temp<ans:
        ans=temp
    else:
      temp=min(abs(start), end)*2+max(abs(start), end)
      if temp<ans:
        ans=temp
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
candle=list(map(int,input().split()))
ans=2000000000
for i in range(n-k+1):
  if candle[i]<0 and candle[i+k-1]>0:
    temp=min(abs(candle[i]), candle[i+k-1])*2+max(abs(candle[i]), candle[i+k-1])
  elif candle[i+k-1]<=0:
    temp=abs(candle[i])
  elif candle[i]>=0:
    temp=candle[i+k-1]
  ans=min(temp, ans)
print(ans)