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

n, m, k = input().split()
a = input().split()
b = input().split()

n = int(n)
m = int(m)
k = int(k)
a = list(map(int, a))
b = list(map(int, b))

ans = 0

for i_a in range(n+1):
  a[0:i_a]
  for i_b in range(m+1):
    if sum(a[0:i_a]) + sum(b[0:i_b]) <= k:
      ans = max(ans, len(a[0:i_a]) + len(b[0:i_b]))

print(ans)


### FIXED CODE ###

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]

for i in range(n):
  a.append(a[i] + A[i])
  
for i in range(m):
  b.append(b[i] + B[i])
  
ans, j = 0, m

for i in range(n+1):
  if a[i] > k:
    break
  while a[i] + b[j] > k:
    j -= 1
  ans = max(ans, i+j)

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

n = int(input())
a = list(map(int, input().split()))
for j in range(n):
    a[j] = a[j] - (j + 1)
a.sort()
asum = sum(a)
sadlist = [asum - n * a[0]]
for i in range(1, n+1):
    sad = asum - 2 * sum(a[:i])
    if i < n/2:
        sad = sad - (n - 2 * i) * a[i]
    elif i > n/2:
        sad = sad - (n - 2 * i) * a[i-1]
    else:
        pass
    sadlist.append(sad)
    if sad == 0 or sadlist[-2] < sad:
        break
print(min(sadlist))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
for j in range(n):
    a[j] = a[j] - (j + 1)
a.sort()
if n % 2 == 0:
    print(sum(a[int(n / 2):]) - sum(a[:int(n / 2)]))
else:
    print(sum(a[int((n + 1) / 2):]) - sum(a[:int((n - 1) / 2)]))
### BUGGY CODE ###

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

MOD = 1000003


class ModInt(object):

  def __init__(self, num, mod):
    self.num = num
    self.mod = mod

    if self.num >= self.mod:
      self.num %= self.mod

  def inv(self):
    a, b, u, v = self.mod, self.num, 0, 1

    while b != 0:
      t = a // b
      a -= t * b
      u -= t * v
      a, b = b, a
      u, v = v, u

    return ModInt(u % self.mod, self.mod)

  def __add__(self, n):
    raise NotImplementedError()

  def __sub__(self, n):
    raise NotImplementedError()

  def __mul__(self, n):
    return ModInt((self.num * int(n)) % self.mod, self.mod)

  def __div__(self, n):
    raise NotImplementedError()

  def __pow__(self, n):
    v = 1
    m = self.num

    while n != 0:
      if n & 1 != 0:
        v = (v * m) % self.mod

      m = (m * m) % self.mod
      n = n >> 1

    return ModInt(v, self.mod)

  def __int__(self):
    return self.num

  def __str__(self):
    return str(self.num)


def main():
  facs = [None] * MOD
  facs[0] = ModInt(1, MOD)

  for i in range(1, MOD):
    facs[i] = facs[i - 1] * i

  for _ in range(int(input())):
    x, d, n = map(int, input().split())

    if d == 0:
      print(ModInt(x, MOD) ** n)
      continue

    x = int(ModInt(x, MOD) * ModInt(d, MOD).inv())

    if x + n - 1 >= MOD:
      print(0)
      continue

    v = facs[x + n - 1]

    if x != 0:
      v *= facs[x - 1].inv()

    if d != 1:
      v *= (ModInt(d, MOD) ** n)

    print(v)


if __name__ == '__main__':
  main()



### FIXED CODE ###

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

MOD = 1000003


def inv(x, m):
  y, u, v = m, 1, 0

  while y != 0:
    t = x // y
    x -= t * y
    u -= t * v
    x, y = y, x
    u, v = v, u

  return u % m


def main():
  facs = [None] * MOD
  invs = [None] * MOD

  facs[0] = 1
  for i in range(1, MOD):
    facs[i] = facs[i - 1] * i % MOD

  invs[-1] = facs[-1]
  for i in range(MOD - 1, 0, -1):
    invs[i - 1] = invs[i] * i % MOD

  for _ in range(int(input())):
    x, d, n = map(int, input().split())

    if d == 0:
      print(pow(x, n, MOD))
      continue

    x = x * inv(d, MOD) % MOD

    if x + n - 1 >= MOD:
      print(0)
      continue

    v = facs[x + n - 1]

    if x != 0:
      v = v * invs[x - 1] % MOD

    if d != 1:
      v = v * pow(d, n, MOD) % MOD

    print(v)


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

# editorialを参考に作成
S = input()
lenS = len(S)
DP = [0] * 13
ans = [0]*13
i_mod = [1] * lenS
if S[lenS-1] == "?":
    for j in range(10):
        ans[j % 13] += 1
else:
    ans[int(S[lenS-1]) % 13] += 1

for i in range(1, len(S)):
    DP = [0]*13
    for r in range(13):
        DP[r] += ans[r] % (10**9+7)
    ans = [0]*13
    i_mod[i] = (i_mod[i - 1] * 10) % 13
    i_now = 0
    i_now += i_mod[i]
    if S[lenS-i-1] == "?":
        for p in range(13):
            for h in range(10):
                ans[(p+h * i_now) % 13] += DP[p]

    else:
        for q in range(13):
            ans[(q+i_now * int(S[lenS-i-1])) % 13] = DP[q]


print(ans[5] % (10**9+7))
# print(DP)


### FIXED CODE ###

# editorialを参考に作成
S = input()
lenS = len(S)
DP = [0] * 13
ans = [0]*13
i_mod = [1] * lenS
if S[lenS-1] == "?":
    for j in range(10):
        ans[j % 13] += 1
else:
    ans[int(S[lenS-1]) % 13] += 1

for i in range(1, len(S)):
    DP = [0]*13
    for r in range(13):
        DP[r] += ans[r] % (10**9+7)
    ans = [0]*13
    i_mod[i] = (i_mod[i - 1] * 10) % 13
    i_now = 0
    i_now += i_mod[i]
    if S[lenS-i-1] == "?":
        for p in range(13):
            for h in range(10):
                ans[(p+h * i_now) % 13] += DP[p]

    else:
        for q in range(13):
            ans[(q+i_now * int(S[lenS-i-1])) % 13] = DP[q]


print(ans[5] % (10**9+7))
# print(DP)
### BUGGY CODE ###

H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
P = []
memo = {}


def f(L):
    i = 0
    j = 0
    while H > i:
        while W > j:
            if A[i][j] == L:
                memo[L] = (i + 1, j + 1)
                P.append((i + 1, j + 1))
                return L
            j += 1
        i += 1
        j = 0
    return 0


def main():
    ans = []
    for _ in range(Q):
        L, R = map(int, input().split())
        if L == R:
            ans.append(0)
            continue
        while True:
            if L in memo:
                P.append(memo[L])
            else:
                f(L)
            if L == R:
                break
            L += D
        m = 0
        for i in range(len(P) - 1):
            m += abs(P[i][0] - P[i + 1][0]) + abs(P[i][1] - P[i + 1][1])
        ans.append(m)
    for a in ans:
        print(a)


main()


### FIXED CODE ###

def main():
    H, W, D = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    Q = int(input())
    ans = []

    x = [0 for _ in range(90001)]
    y = [0 for _ in range(90001)]
    dp = [0 for _ in range(90001)]

    for i, row in enumerate(A):
        for j, a in enumerate(row):
            x[a] = j
            y[a] = i
    for i in range(D + 1, H * W + 1):
        dp[i] = dp[i - D] + abs(x[i] - x[i - D]) + abs(y[i] - y[i - D])

    for _ in range(Q):
        L, R = map(int, input().split())
        ans.append(dp[R] - dp[L])
    for a in ans:
        print(a)


main()
### BUGGY CODE ###

N,Q = [int(i) for i in input().split()]
S = input()
q_list = []
for i in range(Q) :
    q_list.append([int(i) for i in input().split()])

for item in q_list :
    from_index = item[0]
    to_index = item[1]
    search_str = S[from_index-1:to_index]
    find_index = 0
    ac_count = 0
    while(find_index != -1) :
        find_index = search_str.find("AC",find_index)
        if (find_index != -1) :
            ac_count += 1
            find_index += 1
        
    
    print(ac_count)
        


### FIXED CODE ###

N,Q = [int(i) for i in input().split()]
S = input()
q_list = []
for i in range(Q) :
    q_list.append([int(i) for i in input().split()])


## No.5
# n番目までに何回ACって出るか調べたらO(N)で済むのでは？
c = 0
ac_list = []
for i in range(len(S)) :
    # Cの位置を基準にする
    if (S[i] == "C" and i > 0 and S[i-1] == "A") :
        c += 1
        ac_list.append(c)
    else :
        ac_list.append(c)

for item in q_list :
    # XXXXA | C だったケースは除外するので、右端は-1する
    ac_count = ac_list[item[1]-1] - ac_list[item[0]-1]
    print(ac_count)



## No.4
# a_indexes = []
# # 下処理として、Aの場所だけ覚えておく
# for i in range(len(S)) :
#     if (S[i] == "A") :
#         a_indexes.append(i)

# # 幅に応じて、Aの次がCかどうかを判定する
# for item in q_list :
#     from_index = item[0]
#     to_index = item[1]
#     # 次の文字がCであることを調べるので、toは1文字手前にする
#     target_indexes = [i for i in a_indexes if i >= from_index-1 and i < to_index-1]
#     ac_count = 0
#     for index in target_indexes :
#         if (S[index+1] == "C") :
#             ac_count += 1
    
#     print(ac_count)


## No.1  もちろんTLE。。。
# for item in q_list :
#     from_index = item[0]
#     to_index = item[1]
#     search_str = S[from_index-1:to_index]
#     find_index = 0
#     ac_count = 0
#     while(find_index != -1) :
#         find_index = search_str.find("AC",find_index)
#         if (find_index != -1) :
#             ac_count += 1
#             find_index += 1
#     print(ac_count)

## No.2,3
# for item in q_list :
#     from_index = item[0]
#     to_index = item[1]
#     search_str = S[from_index-1:to_index]
    # print(search_str.replace("AC","X").count("X"))
    # print(search_str.count("AC"))
### BUGGY CODE ###

###C - Monsters Battle Royale
N = int(input())
A = list(map(int, input().split()))
jlist=[True]
while(any(jlist) and len(set(A)) != 1):
    for i in range(N):
        if A[i] - min(A) > 0:
            A[i] = A[i] - min(A)
            jlist.append(False)
        else:
            jlist.append(True)
print(min(A))


### FIXED CODE ###

###C - Monsters Battle Royale
N = int(input())
A = list(map(int, input().split()))

while(len(set(A)) != 1):
    minA  = min(A)
    for i in range(N):
        if A[i] > minA:
            time = A[i] // minA
            if time == 1:
                A[i] =A[i] -  time * minA
            else:
                A[i] =A[i] -  (time - 1) * minA
                
print(min(A))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

import math

big = 10**9 + 7

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

A = []
for a in row_A:
    A.append(a%big)


num = A[0]
for i in range(1, N):
    num = num * A[i] // math.gcd(num, A[i])

res = 0
for a in A:
    res += num//a % big

print(res%big)

### FIXED CODE ###

import sys
input = sys.stdin.readline
import math

def main():
    big = 10 ** 9 + 7

    N = int(input())
    A = list(map(int, input().split()))
    num = A[0]
    for i in range(1, N):
        num = num * A[i] // math.gcd(num, A[i])

    res = 0
    for a in A:
        res += num // a

    print(res % big)

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

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

c=collections.Counter(b)
n,m=zip(*c.most_common())
n,m=list(n),list(m)
result=0
for i in range(len(m)):
    result+=(m[i]*(m[i]-1))//2

for i in b:
    print(result-m[n.index(i)]+1)
    

### FIXED CODE ###

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

c=collections.Counter(b)

n,m=zip(*c.most_common())
n,m=list(n),list(m)
result=0
for i in range(len(m)):
    result+=(m[i]*(m[i]-1))//2

for i in b:
    print(result-c[i]+1)
### BUGGY CODE ###

n,k=map(int,input().split())
x,y=[[0,0] for i in range(n)],[[0,0] for i in range(n)]
xy=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    x_sub,y_sub=xy[i]
    x[i][0]=x_sub
    x[i][1]=i
    y[i][0]=y_sub
    y[i][1]=i
x.sort(key=lambda z:z[0])
y.sort(key=lambda z:z[0])
ans=(10**18)*5
for i1 in range(n):
    for l1 in range(n-i1,0,-1):
        for i2 in range(n):
            for l2 in range(n-i2,0,-1):
                z=[0]*n
                for i in range(i1,i1+l1):
                    l=x[i][1]
                    z[l]=1
                for i in range(i2,i2+l2):
                    l=y[i][1]
                    z[l]=1
                if sum(z)>=k:
                    x_sub1,y_sub1=10**9+1,10**9+1
                    x_sub2,y_sub2=-10**9-1,-10**9-1
                    for i in range(n):
                        if z[i]==1:
                            x_sub1=min(xy[i][0],x_sub1)
                            x_sub2=max(xy[i][0],x_sub2)
                            y_sub1=min(xy[i][1],y_sub1)
                            y_sub2=max(xy[i][1],y_sub2)
                    ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)
                else:
                    break
print(ans)


### FIXED CODE ###

n,k=map(int,input().split())
x,y=[[0,0] for i in range(n)],[[0,0] for i in range(n)]
xy=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    x_sub,y_sub=xy[i]
    x[i][0]=x_sub
    x[i][1]=i
    y[i][0]=y_sub
    y[i][1]=i
x.sort()
y.sort()
ans=(10**18)*5
for i1 in range(n):
    for l1 in range(n-i1,1,-1):
        for i2 in range(n):
            for l2 in range(n-i2,1,-1):
                x_sub1=x[i1][0]
                x_sub2=x[i1+l1-1][0]
                y_sub1=y[i2][0]
                y_sub2=y[i2+l2-1][0]
                z=[0]*n
                for i in range(n):
                    if x_sub1<=xy[i][0]<=x_sub2 and y_sub1<=xy[i][1]<=y_sub2:
                        z[i]=1
                if sum(z)>=k:
                    ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)
                else:
                    break
print(ans)
### BUGGY CODE ###

MOD = 10 ** 9 + 7

def mymodBinomial(n, k, p):
	if k < 0 or k > n:
		return 0
	else:
		numerator = 1
		for i in range(k):
			numerator = (numerator * (n - i)) % p
		denominator = 1
		for i in range(1, k + 1):
			denominator = (denominator * i) % p
		return (numerator * pow(denominator, p - 2, p)) % p


if __name__ == "__main__":
	N, K = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	# print(A)
	l = [0]*(N + 1)
	for i in range(1, N+1):
		l[i] = mymodBinomial(i-1, K-1, MOD) - mymodBinomial(N-i, K-1, MOD)
	ans = 0
	# print(l)
	for i in range(N):
		ans += A[i] * l[i+1] % MOD
	print(ans % MOD)

### FIXED CODE ###

MOD = 10 ** 9 + 7

# def mymodBinomial(n, k, p):
# 	if k < 0 or k > n:
# 		return 0
# 	else:
# 		numerator = 1
# 		for i in range(k):
# 			numerator = (numerator * (n - i)) % p
# 		denominator = 1
# 		for i in range(1, k + 1):
# 			denominator = (denominator * i) % p
# 		return (numerator * pow(denominator, p - 2, p)) % p

def modBinomiallist(n, k, p):
	l = [0 for i in range(n)]
	for i in range(n):
		if i < k:
			l[i] = 0
		elif i == k:
			l[i] = 1
		else:
			l[i] = l[i - 1] * i * pow(i-k, p-2, p) % p
	return l


if __name__ == "__main__":
	N, K = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	# print(A)
	# l = [0]*(N + 1)
	# for i in range(1, N+1):
	# 	l[i] = mymodBinomial(i-1, K-1, MOD)
	# print(l)
	l = modBinomiallist(N, K-1, MOD)
	# print(l)
	ans = 0
	# print(l)
	for i in range(N):
		ans += (A[i] - A[N-1-i])* l[i] % MOD
	print(ans % MOD)
### BUGGY CODE ###

import numpy as np
H,W,A,B = map(int, input().split())
ans=np.zeros([H,W], int)
ans[:B,A:]=1
ans[B:,:A]=1
for x in ans:
    maped_num = map(str, x)
    mojiretsu = ''.join(maped_num)
    print(mojiretsu)




### FIXED CODE ###

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

for _ in range(B):
  print(''.join(['0'] * A + ['1'] * (W-A)))
for _ in range(H-B):
  print(''.join(['1'] * A + ['0'] * (W-A)))
### BUGGY CODE ###

import sys
from collections import deque
from itertools import permutations
input = sys.stdin.readline

N, K = [int(x) for x in input().strip().split()]
l1 = deque([])
l2 = deque([])
ans = deque([])
c = K
while c <= N:
    l1.append(c)
    c += K
for i in l1:
    for j in l1:
        for k in l1:
            ans.append((i, j, k))

if K % 2 == 0:
    c = K / 2
    while c <= N:
        l2.append(c)
        c += K
    for i in l2:
        for j in l2:
            for k in l2:
                ans.append((i, j, k))

print(len(list(set(ans))))

### FIXED CODE ###

import sys
from collections import deque
from itertools import permutations
input = sys.stdin.readline

N, K = [int(x) for x in input().strip().split()]
l1 = deque([])
l2 = deque([])
ans = deque([])
c = K

while c <= N:
    l1.append(c)
    c += K
ans = len(l1) ** 3

if K % 2 == 0:
    c = K / 2
    while c <= N:
        l2.append(c)
        c += K
ans += len(l2) ** 3

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


N=int(input())
li=[]
for i in range(N):
  li.append(input())
count=0
from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(first_word) == get_counter(second_word)
for i in range(N):
  for j in range(i+1):
    if i != j:
      if verify_anagrams(li[i],li[j]):
        count+=1
print(count)

### FIXED CODE ###

N=int(input())
#li=[input() for i in range(N)]
count=0
dic={}
for i in range(N):
  s=input()
  sorted_s="".join(sorted(s))
  count += dic.get(sorted_s, 0)
  dic[sorted_s] = dic.get(sorted_s, 0) + 1
print(count)
### BUGGY CODE ###

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

count = 0

right_shakutori = [0] 
left_shakutori = [0] 


for i in range(len(a)):
    right_shakutori.append(right_shakutori[i] + a[i])
    left_shakutori.append(left_shakutori[i] ^ a[i])


def search(l, s, e):
    #末尾チェック
    right = right_shakutori[e] - right_shakutori[l]
    left = left_shakutori[e] ^ left_shakutori[l]
    if right == left:
        return e

    while(True):
        if s == e:
            return s
        devider = (e + s) // 2
    
        # 前半
        right = right_shakutori[devider] - right_shakutori[l]
        left = left_shakutori[devider] ^ left_shakutori[l]


        right_one =   right_shakutori[devider + 1] - right_shakutori[l]
        left_one = left_shakutori[devider + 1] ^ left_shakutori[l]

        if left == right and left_one < right_one:
            return devider

        if left < right:
            #前半にある
            e = devider - 1
        else:
            s = devider + 1


for l in range(0, n):

    # right == leftになる場所をbinary search


    max_r = search(l, l , n)
    count += max_r - l 

print(count)







### FIXED CODE ###

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

count = 0

xor_temp = 0
sum_temp = 0

r = 0
for l in range(n):
    while r < n and xor_temp^a[r]  == sum_temp + a[r]:
        xor_temp ^= a[r]
        sum_temp += a[r]
        r += 1

    xor_temp ^= a[l]
    sum_temp -= a[l]
    count += r - l

print(count)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
B = [int(input()) for _ in range(N)]
A.sort()
B.sort()
ans = [0] * N
mod = 10**9 + 7

for i in range(N):
    for j in range(N):
        ans[j-i] += (abs(A[i]-B[j])) % mod

print(ans.count(min(ans)))

### FIXED CODE ###

N = int(input())
Q = sorted([[int(input()), i//N] for i in range(2*N)])

mod = 10**9 + 7
ans = 1
S = [0, 0]

for i in Q:
    if S[1-i[1]] == 0:
        S[i[1]] += 1
    else:
        ans = (ans*S[1-i[1]]) % mod
        S[1-i[1]] -= 1

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

N,R=map(int, input().split())
i=0
while True:
 if(0<N-R**(i+1)<=R**i):
  print(i+2)
  break
 i+=1

### FIXED CODE ###

N,R=map(int, input().split())
i=0
while True:
 if(R**i<=N<R**(i+1)):
  print(i+1)
  break
 i+=1
### BUGGY CODE ###

N,K = map(int, input().split())
if N % K == 0:
    print(0)
elif N > K:
    while N > 0:
        hako1 = N
        N -= K
        hako2 = abs(N)
    if hako1 > hako2:
      print(hako2)
    else:
      print(hako1)
else:
    if N >= abs(N-K):
        print(abs(N-K))
    else:
        print(N)

### FIXED CODE ###

N,K = map(int, input().split())
if N % K == 0:
    print(0)
elif N > K:
    hako1 = N%K
    hako2 = abs(hako1-K)
    if hako1 > hako2:
      print(hako2)
    else:
      print(hako1)
else:
    if N >= abs(N-K):
        print(abs(N-K))
    else:
        print(N)
### BUGGY CODE ###

from bisect import bisect

n = int(input())
A = [int(i) for i in input().split()]

ans = 0

B = [(0, 0)]

for i, a in zip(range(1, n+1), A):
    B.append((a, i))

B.sort()

sortedlist = []
    
for i in range(1, n+1):
    j = bisect(sortedlist, B[i][1])
    left = B[i][1] - (sortedlist[j-1] if j-1 >= 0 else 0) - 1
    right = (sortedlist[j] - 1 if j < i-1 else n) - B[i][1]
    sortedlist.insert(j, B[i][1])

    ans += (left + 1) * (right + 1) * B[i][0]
    
print(ans)

### FIXED CODE ###

from bisect import bisect

n = int(input())
A = [int(i) for i in input().split()]

class UnionFind():
  def __init__(self, elements):
    self.elements = elements
    self._root = {}
    self.size = [1] * (len(self.elements)+1)
    for e in self.elements:
      self._root[e] = e
    
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    res = self.size[x] * self.size[y]
    self.size[x] += self.size[y]
    
    if x != y:
      self._root[y] = x

    return res
    
  def root(self, x):
    if self._root[x] != x:
      self._root[x] = self.root(self._root[x])
    return self._root[x]

B = [0] * (n+1)

for i, a in zip(range(1, n+1), A):
    B[a] = i

uf = UnionFind(range(1, n+1))
ans = 0
A.insert(0, 0)

for j in range(n, 0, -1):
    i = B[j]
    ans += A[i]

    if i - 1 >= 1 and A[i-1] > A[i]:
        ans += uf.unite(i-1, i) * A[i]

    if i + 1 <= n and A[i+1] > A[i]:
        ans += uf.unite(i+1, i) * A[i]

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

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

l = []
for i in range(len(a)):
  for j in range(len(b)):
    l.append(a[i]+b[j])

l.sort(reverse=True)
if k <= len(l):
  l = l[:k]

m = []
for i in range(len(l)):
  for j in range(len(c)):
    m.append(l[i]+c[j])

m.sort(reverse=True)   
for i in range(k):
  print(m[i])



### FIXED CODE ###

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

l = []
for i in range(len(a)):
  for j in range(len(b)):
    l.append(a[i]+b[j])

l.sort(reverse=True)
if k <= len(l):
  l = l[:k]

m = []
for i in range(len(l)):
  for j in range(len(c)):
    m.append(l[i]+c[j])

m.sort(reverse=True)   
for i in range(k):
  print(m[i])
### BUGGY CODE ###

# -*- coding:utf-8 -*-
def odd(num):
    return True if num%2!=0 else False
n = int(input())
a = list(input().split())
b = []
for tmp in range(len(a)):
    if odd(n) == odd(tmp+1):
        if len(b) != 0:
            b.insert(0,a[tmp])
        else:
            b.append(a[tmp])
    else:
        b.append(a[tmp])
print(' '.join(b))

### FIXED CODE ###

# -*- coding:utf-8 -*-
from collections import deque
def odd(num):
    return True if num%2!=0 else False
n = int(input())
a = list(input().split())
b = deque()
for tmp in range(len(a)):
    if odd(n) == odd(tmp+1):
        b.appendleft(a[tmp])
    else:
        b.append(a[tmp])
print(' '.join(b))
### BUGGY CODE ###

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

a = [int(input()) for i in range(m)]

dp = [0] * (n + 1)
for i in range(n + 1):
    if i in a:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])


### FIXED CODE ###

n, m = map(int, input().split())
A = set()
for i in range(m):
    a = int(input())
    A.add(a)
dp = [0] * (n + 1)
for i in range(n + 1):
    if i in A:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])

"""
100 5
1
23
45
67
89
"""
### BUGGY CODE ###

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

c = []
for i in range(N - K + 1):
    if (len(x[i:i+K]) != K):
        continue
    p = x[i:i+K]
    if min(p) < 0 and max(p) > 0:
        if p[-1] + p[-1] - p[0] < abs(p[0]) + p[-1] -p[0]:
            c.append(p[-1] + (p[-1] - p[0]))
        else:
            c.append(abs(p[0]) + p[-1] - p[0])
    elif min(p) >= 0:
        c.append(p[-1])
    elif max(p) <= 0:
        c.append(abs(p[0]))

print(min(c))


### FIXED CODE ###

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

ans = 10**18
for i in range(N - K + 1):
    p1 = x[i]
    p2 = x[i+K-1]
    lr = abs(p1) + abs(p2 - p1)
    rl = abs(p2) + abs(p1 - p2)
    if lr < rl:
        ans = min(ans,lr)
    else:
        ans = min(ans,rl)
print(ans)