Harryxun/stf_run huggingface dataset:
def main():
  # N個の県，M個の市，
  # 市iが誕生したのはY_i年で県P_iに属す
  # 市iが県P_iの中でx番目にできた市だと、市iの認識番号の上6桁はP_i,下6桁はx
  # 6桁以下だと6桁になるように左に0詰める

  N, M = map(int, input().split())
  PY = []
  for _ in range(M):
    a = list(map(int, input().split()))
    PY.append(a)
  PY_sorted = sorted(PY, key=lambda x: x[1])

  city_count = {}
  order = {}
  for i, (p, y) in enumerate(PY_sorted):
    if not p in city_count:
      city_count[p] = 0
    city_count[p] += 1
    order[p, i] = city_count[p]
    
  for i, (p, y) in enumerate(PY):
    print('{:06}{:06}'.format(p, order[p, i]))

main()

### FIXED CODE ###

N, M = map(int, input().split())
iPY = []
 
for i in range(M):
    p, y = map(int, input().split())
    iPY.append([i, p, y])
 
city_count = {}
order = {}
 
for i, p, y in sorted(iPY, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 0
    city_count[p] += 1
    order[p, i] = city_count[p]
    
for i, p, y in iPY:
    print('{:06}{:06}'.format(p, order[p, i]))
N, M = map(int, input().split())
ken = [[] for _ in range(N)]
shi = [tuple(map(int, input().split())) for _ in range(M)]
for s1, s2 in shi:
    ken[s1-1].append(s2)
for k in ken:
    k.sort()
for s1, s2 in shi:
    print("{:06}{:06}".format(s1, ken[s1-1].index(s2+1)))

### FIXED CODE ###

from operator import itemgetter
N, M = map(int, input().split())
iPY = [0]*M
res = [0]*M
for i in range(M):
    P, Y = map(int, input().split())
    iPY[i] = (i, P, Y)
iPY.sort(key=itemgetter(2))
iPY.sort(key=itemgetter(1))
j = 1
p = iPY[0][1]
for i, P, Y in iPY:
    if P != p:
        j = 1
        p = P
    res[i] = "{:06}{:06}".format(P, j)
    j += 1
for s in res:
    print(s)
X = []
Y = []
Z = []
for i in range(3):
    x, y, z = map(str, input().split())
    X.append(x)
    Y.append(y)
    Z.append(z)
N = int(input())

b = map(str, [input() for i in range(N)])

for x in sorted(b, reverse=True):
    X = [s.replace(x, 'OK') for s in X]
    Y = [s.replace(x, 'OK') for s in Y]
    Z = [s.replace(x, 'OK') for s in Z]

if ('OK' in X[0] and 'OK' in X[1] and 'OK' in X[2]
    or 'OK' in Y[0] and 'OK' in Y[1] and 'OK' in Y[2]
    or 'OK' in Z[0] and 'OK' in Z[1] and 'OK' in Z[2]
    or 'OK' in X[0] and 'OK' in Y[0] and 'OK' in Z[0]
    or 'OK' in X[1] and 'OK, in Y[1] and 'OK' in Z[1]
    or 'OK' in X[2] and 'OK' in Y[2] and 'OK' in Z[2]
    or 'OK' in X[0] and 'OK' in Y[1] and 'OK' in Z[2]
    or 'OK' in X[2] and 'OK' in Y[1] and 'OK' in Z[0]):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

X = []
Y = []
Z = []
for i in range(3):
    x, y, z = map(int, input().split())
    X.append(x)
    Y.append(y)
    Z.append(z)
N = int(input())

b = list(map(int, [input() for i in range(N)]))

for i in range(N):
    
    if X[0] == b[i]:
        X[0] = 'OK'
    if X[1] == b[i]:
        X[1] = 'OK'
    if X[2] == b[i]:
        X[2] = 'OK'
    if Y[0] == b[i]:
        Y[0] = 'OK'
    if Y[1] == b[i]:
        Y[1] = 'OK'
    if Y[2] == b[i]:
        Y[2] = 'OK'
    if Z[0] == b[i]:
        Z[0] = 'OK'
    if Z[1] == b[i]:
        Z[1] = 'OK'
    if Z[2] == b[i]:
        Z[2] = 'OK'

if (X[0] == X[1] == X[2]
    or Y[0] == Y[1] == Y[2]
    or Z[0] == Z[1] == Z[2]
    or X[0] == Y[0] == Z[0]
    or X[1] == Y[1] == Z[1]
    or X[2] == Y[2] == Z[2]
    or X[0] == Y[1] == Z[2]
    or X[2] == Y[1] == Z[0]):
    print('Yes')
else:
    print('No')
while True:
    try:
        n = int(input())
        c = 0
        for i in range(1,10):
            for j in range(1,10):
                for k in range(1,10):
                    for l in range(1,10):
                        if i+j+k+l == n : c+=1
        print(c)
    exception:
        break

### FIXED CODE ###

while True:
    try:
        n = int(input())
        c = 0
        for i in range(10):
            for j in range(10):
                for k in range(10):
                    for l in range(10):
                        if i+j+k+l == n : c+=1
        print(c)
    except:
        break
import itertools
import heapq
import sys
import functools
import operator
import numpy as np
input = sys.stdin.readline
#-------------
n,k = map(int,input().split())
a = list(map(int,input().split()))
#-------------
a.sort(reverse = True)
w = 10**9 + 7
ans = 1
if k%2 == 1:
  for i in range(k):
    ans *= a[i]
  print(ans % w)

else:
  if n%2 == 0:
    A = n//2
    a_new = [a[2*i]*a[2*i+1] for i in range(A)]
    a_new.sort(reverse = True)
    for j in range(k//2):
      ans *= a_new[j]
    print(ans % w)
      
  else:
    a_plus = heapq.nlargest(k, a)
    a_minus = heapq.nsmallest(k, a)
    a_plus.sort(reverse = True)
    a_minus.sort()
    a_plus_new = [a_plus[2*i]*a_plus[2*i+1] for i in range(len(a_plus)//2)]
    a_minus_new = [a_minus[2*i]*a_minus[2*i+1] for i in range(len(a_minus)//2)]
    a_new = a_plus_new + a_minus_new
    a_new.sort(revserse = True)
    for j in range(k//2):
      ans *= a_new[j]
    print(ans % w)

### FIXED CODE ###

import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0:
  if zero and k%2:
    ans = 0
  else:
    if k%2:
      minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)
card_power = {'2':'1','3':'2','4':'3','5':'4','6':'5','7':'6','8':'7','9':'8','10':'9','11':'10','11':'12','13':'12','1':'13'}
A,B = input().split()
if int(card_power[A]) > int(card_power[B]):
  print('Alice')
elif int(card_power[A]) < int(card_power[B]):
  print('Bob')
else:
  print('Alice')


### FIXED CODE ###

card_power = {'2':'1','3':'2','4':'3','5':'4','6':'5','7':'6','8':'7','9':'8','10':'9','11':'10','12':'11','13':'12',"1":'13'}
A,B = input().split()
if int(card_power[A]) == int(card_power[B]):
  print('Draw')
elif int(card_power[A]) > int(card_power[B]):
  print('Alice')
elif int(card_power[A]) < int(card_power[B]):
  print('Bob')
n=int(input())
B=list(map(int,input().split()))
B.append(0)
A=[min(B[i],[i+1]) for i in range(n)]
print(sum(A))


### FIXED CODE ###

N=int(input())
B=input().split()
B=[int(n) for n in B]
A=[]
A.append(B[0])
last=0
for i in range(N-2):
    last=B[i]
    if last>B[i+1]:
        A.append(B[i+1])
    else:
        A.append(last)
    last=B[i+1]
A.append(last)
if N>2:
    print(sum(A))
else:
    print(sum(B)*2)
n=int(input())
a=list(map(int,input().split()))

a.sort()

import collections
c = collections.Counter(a)

d=[]
for ck,cv in c.items():
    if cv>=2:
       d.append(ck) 
dset=set(d)
    
aa=[]

while True:
    aa.append(a[0])
    a2=[]
    for i in range(1,len(a)):
        if a[i]%a[0]!=0:
            a2.append(a[i])
#    a=a2.copy()
    if len(a2)==0:
        break

    aa.append(a2[0])
    a=[]
    for i in range(1,len(a2)):
        if a2[i]%a[0]!=0:
            a.append(a2[i])
#    a=a2.copy()
    if len(a)==0:
        break

aaset=set(aa)
aaset=aaset-dset    
print(len(aaset))


### FIXED CODE ###

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

a.sort()
amax=max(a)
dp=[True]*(amax+1)

import collections
c = collections.Counter(a)

d=[]
for ck,cv in c.items():
    if cv>=2:
       d.append(ck) 
dset=set(d)
    
aa=set()
for ai in a:
    if dp[ai]:
        aa.add(ai)
        for aj in range(ai*2,amax+1,ai):
            dp[aj]=False

aa=aa-dset    
print(len(aa))
a=int(input())
b=int(input())
if a==b: print('EQUAL')
elif a>b: print('GREATER')
else: print('LESS')

### FIXED CODE ###

print(''.join([chr(ord(i[0])+ord('A')-ord('a')) for i in input().split()]))
a, b, c = map(int, input().split())
if b − a == c − b:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

a, b, c = map(int, input().split())
if b - a == c - b :
    print("YES")
else:
    print("NO")
import math
N = int(input())

def make_prime_list(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)
    

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num+1, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]

prime_list = make_prime_list(100)
e = len(prime_list)*[0]

for i in range(N):
    cur = i + 2
    for index,j in enumerate(prime_list):
        while cur % j == 0:
            e[index] += 1
            cur //= j
print(num(75) + num(25) * (num(3) -1) + num(15) * (num(5) -1)
    +num(5) * (num(5) -1 ) * (num(3) - 2) //2)

### FIXED CODE ###

N = int(input())
e = [0] * (N+1)
for i in range(2, N+1):
    cur = i
    for j in range(2, i+1):
        while cur % j == 0:
            e[j] += 1
            cur //= j

def num(m):
    return len(list(filter(lambda x: x>=m-1, e)))

print(num(75) + num(25) * (num(3) -1) + num(15) * (num(5) -1)
    +num(5) * (num(5) -1 ) * (num(3) - 2) //2)
#C - Poll
import collections
N = int(input())
S = [str(input()) for i in range(N)]
S = sorted(S)
count = 1
tmpcount = 1
DP = [S[0]]
for i in range(1,N):
    if S[i] == S[i-1]:
        count += 1
        if tmpcount < count:
            DP.clear()
            DP.append(S[i])
            tmpcount = count
        elif tmpcount == count:
            DP.append(S[i])
        else:
            pass
    else:
        count = 1
        if tmpcount == count:
            DP.append(S[i])
        else:
            pass

for l in range(len(DP)):
     print(DP[l])

### FIXED CODE ###

#C - Poll
N = int(input())
S = [str(input()) for i in range(N)]
S = sorted(S)
count = 1
tmpcount = 1
DP = [S[0]]
for i in range(1,N):
    if S[i] == S[i-1]:
        count += 1
        if tmpcount < count:
            DP.clear()
            DP.append(S[i])
            tmpcount = count
        elif tmpcount == count:
            DP.append(S[i])
        else:
            pass
    else:
        count = 1
        if tmpcount == count:
            DP.append(S[i])
        else:
            pass

for l in range(len(DP)):
     print(DP[l])
S=list(input())
li=0
li2=[]
for i in S:
	if i=='A' or i=='C' or i=='G' or i=='T':
		li+=1
	else:
		li2.append(li)
		li=0
print(max(li2))

### FIXED CODE ###

S=list(input())
li=0
li2=[]
for i in S:
	if i=='A' or i=='C' or i=='G' or i=='T':
		li+=1
	else:
		li2.append(li)
		li=0
li2.append(li)
print(max(li2))
N = int(raw_input())
act = [map(int, raw_input().split()) for _ in range(N)]
memo = [[-1]*3 for _ in range(N)]

def happy(n, i):
  if memo[n][i] >= 0:
    return memo[n][i]
  if n == 0:
    h = act[n][i]
  else:
    h = -1
    for j in range(3):
      if j == i:
        continue
      c = happy(n-1,j)+act[n][i]
      h = h if h > c else c
  memo[n][i] = h
  return h
print max(happy(N-1,0),happy(N-1,1),happy(N-1,2))



### FIXED CODE ###

import sys

sys.setrecursionlimit(100000)

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

def sumOfCost(i):
  if cost[i] >= 0:
    return cost[i]
  if i == 0:
    soc=0
  elif i == 1:
    soc= sumOfCost(0)+abs(H[i]-H[0])
  else:
    c1 = sumOfCost(i-1)+abs(H[i]-H[i-1])
    c2 = sumOfCost(i-2)+abs(H[i]-H[i-2])
    soc=min(c1,c2)
  cost[i] = soc
  return soc

print sumOfCost(N-1)
X , N = map(int, input().split())
p = list(map(int,input().split()))
ans = []
if N == 0:
    print(X)
else:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],p[p.index(max(p))]):
        if i  not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], p[p.index(min(p))], -1):
        if i not in p:
            ans.append(i)
            break
 
    print(min(ans))



### FIXED CODE ###

X , N = map(int, input().split())
p = list(map(int,input().split()))
ans = []
if N == 0:
    print(X)
elif X not in  p:
    print(X)
else:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],102):
        if i not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], -100, -1):
        if i not in p:
            ans.append(i)
            break
    
    ans = sorted(ans)
    ans2 = [abs(i-X) for i in ans]
    print(ans[ans2.index(min(ans2))])
import numpy as np

n,m = map(int,input().split())
A = list(map(int,input().split()))
B = []
res = 0

for a in A:
    res += a
    B.append(res)
B = np.array(B)

ans = 0
for i in range(n):
    b = B[i:]
    # print(b)
    ans += np.count_nonzero(b%m == 0)
    B -= B[i]

print(ans)

### FIXED CODE ###

from collections import Counter

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

B = [0]
res = 0
for a in A:
	res += a
	B.append(res%m)

C = Counter(B)
ans = 0
for c in C.values():
	ans += c*(c-1)//2

print(ans)
# C - Typical Stairs

MOD = 10 ** 9 + 7
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
dp = [None] * (N + 1)

def f(i):
    if dp[i] != None:
        return dp[i]
    else:
        if i in A:
            dp[i] = 0
        elif i < 2:
            dp[i] = 1
        else:
            dp[i] = (f(i - 1) + f(i - 2)) % MOD
        return dp[i]

f(N)
print(dp[N])


### FIXED CODE ###

# C - Typical Stairs

MOD = (10 ** 9) + 7
N, M = map(int, input().split())
A = [False] * (N + 1)
for _ in range(M):
    A[int(input())] = True
dp = [0] * (N + 1)
dp[0] = 1
if A[1] == False:
    dp[1] = 1

for i in range(2, N + 1):
    if A[i] == True:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

print(dp[N])
print(eval("".join(open(0).readlines()[1:]).replace(" JPY", "").replace(" BTC","*380000").replace("\n", "+")))

### FIXED CODE ###

print(sum(eval(input().replace(" JPY", "").replace(" BTC","*380000")) for _ in range(int(input()))))
s=input()
sl=len(s)
if s[:(sl-1)/2]==s[((sl+3)/2)-1:]:
    print('Yes')
else :
    print('No')


### FIXED CODE ###

s=input()
sl=len(s)
if s[:int((sl-1)/2)]==s[int(((sl+3)/2)-1):]:
    print('Yes')
else :
    print('No')
n,k=map(int,input().split())
sum=0
while n>=1:
  n=n/k
  sum+=1
  
print sum


### FIXED CODE ###

n,k=map(int,input().split())
count=1
while n>=k:
  n=n/k
  count+=1
print(count)
MOD = 10 ** 9 + 7
ans = 1

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

#全部取る
if n == k:
    for x in a:
        ans *= x
    print(ans % MOD)

#全部負かつ奇数個取る
elif max(a) < 0 and k % 2:
    a.sort()
    for i in range(1, k+1):
        ans *= a[-i]
    print(ans % MOD)

else:
    pos = []
    neg = []
    
    for x in a:
        if x >= 0:
            pos.append(x)
        else:
            neg.append(x)
    
    pos.sort(reverse=True)
    neg.sort()
    
    
    if k % 2:
        ans *= pos.pop(0)
        k -= 1
     
    #2個ずつ取る
    num = []
    num.append(x * y for x, y in zip(pos[::2], pos[1::2]))
    num.append(x * y for x, y in zip(neg[::2], neg[1::2]))

    num.sort(reverse=True)

    for i in range(k // 2):
        ans *= num[i]
        ans %= MOD
    
    print(ans % MOD)
    

### FIXED CODE ###

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

MOD = 10 ** 9 + 7
ans = 1

#全部取る
if n == k:
    for x in a:
        ans *= x
        ans %= MOD
    print(ans % MOD)

#全部負かつ奇数個取る
elif max(a) < 0 and k % 2:
    a.sort()
    for i in range(1, k+1):
        ans *= a[-i]
        ans %= MOD
    print(ans % MOD)

else:
    pos = []
    neg = []
    
    for x in a:
        if x >= 0:
            pos.append(x)
        else:
            neg.append(x)
    
    pos.sort(reverse=True)
    neg.sort()
    
    
    if k % 2:
        ans *= pos.pop(0)
        k -= 1
     
    #2個ずつ取る
    num = []
    for x, y in zip(pos[::2], pos[1::2]):
        num.append(x * y)
    for x, y in zip(neg[::2], neg[1::2]):
        num.append(x * y)

    num.sort(reverse=True)

    for i in range(k // 2):
        ans *= num[i]
        ans %= MOD
    
    print(ans % MOD)
# -*- coding: utf-8 -*-

import sys
import os
import math

def lcm(a, b):
    return (a * b) // math.gcd(a, b)

for s in sys.stdin:
    a1, m1, a2, m2, a3, m3 = map(int, s.split())
    if a1 == m1 == a2 == m2 == a3 == m3 == 0:
        break

    x = 1
    y = 1
    z = 1

    x_num = 0
    while True:
        x = (a1 * x) % m1
        x_num += 1
        if x == 1:
            break

    y_num = 0
    while True:
        y = (a2 * y) % m2
        y_num += 1
        if y == 1:
            break

    z_num = 0
    while True:
        z = (a3 * z) % m3
        z_num += 1
        if z == 1:
            break

    a = lcm(x_num, y_num)
    b = lcm(a, z_num)
    print(b)

### FIXED CODE ###

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

import sys
import os
import math

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

def lcm(a, b):
    return (a * b) // gcd(a, b)

def interval(a, m):
    cnt = 0
    x = 1
    while True:
        x = (a * x) % m
        cnt += 1
        if x == 1:
            return cnt

for s in sys.stdin:
    a1, m1, a2, m2, a3, m3 = map(int, s.split())
    if sum([a1, m1, a2, m2, a3, m3]) == 0:
        break

    x_num = interval(a1, m1)
    y_num = interval(a2, m2)
    z_num = interval(a3, m3)

    a = lcm(x_num, y_num)
    b = lcm(a, z_num)
    print(b)
n = int(input())

if 104 >= n:
    print(0)
else:
    ans = 0
    for i in range(105,n+1):
        if i%2 == 0:
            continue
        cnt=0
        for j in range(1,i+1):
            if i%j == 0:
                cnt+=1
            
        if cnt == 8:
            ans+=1

print(ans)

### FIXED CODE ###

n = int(input())

ans = 0
for i in range(1,n+1):
    if i%2 == 0:
        continue
    cnt=0
    for j in range(1,i+1):
        if i%j == 0:
            cnt+=1
        
    if cnt == 8:
        ans+=1

print(ans)
o=list(input())
e=list(input())
p=""
for i in range(len(e)):
    p+=o[i]
    p+=e[i]
if len(o)-i==2:
    p+=o[i+1]
print(p)


### FIXED CODE ###

a,b,c=[int(i)for i in input().split()]
if a-b==b-c:
    print("YES")
else:
    print("NO")
a, b, c = map(int, input().split())
if  b−a == c−b:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

a,b,c = map(int,input().split())
if b-a == c-b:
    print("YES")
else:
    print("NO")
import math
n = int(input())
ans = 0
K = [0 for _ in range(200)]
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    K[math.gcd(i,i2)] += 1
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    ans += K[i] * math.gcd(i,i2)
print(ans)


### FIXED CODE ###

import math
ans = 0
n = int(input())
K = [0 for _ in range(n + 1)]
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    K[math.gcd(i,i2)] += 1
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    ans += K[i] * math.gcd(i,i2)
print(ans)
N = int(input())

total = 0
for i in range(len(N)):
    total += N
    
    if N % sum(int(input())) == 0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

def f(n):
  return sum(map(int, str(n)))

X = int(input())

if X % f(X) == 0: 
  print("Yes")
else:
  print("No")
N = int(input())
K = int(input())
Pn = []
for i in range(N):
	Pn.append(input())

Qn = sorted(Pn)
sum = 0
for i in range(K):
	sum += Qn[K]

print(sum)

### FIXED CODE ###

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

P.sort()
s = 0
for i in range(K):
	s += P[i]

print(s)
from copy import deepcopy

def IntToMani(N, K):
    ret = []
    start = N
    while start / 4 > 0:
        ret.append(start % 4)
        start /= 4
    ret.append(start % 4)
    while len(ret) < K:
        ret.insert(0, 0)
    return ret

def addToKeep(_keep, _ele):
    low_ind = 0
    up_ind = len(_keep) - 1
    found = None
    while (up_ind - low_ind) > 1:
        mid = (up_ind + low_ind) / 2
        if _keep[mid] < _ele:
            low_ind = mid
        elif _keep[mid] > _ele:
            up_ind = mid
        elif _keep[mid] == _ele:
            found = mid
            break
    if found is not None:
        cnt = found
    else:
        cnt = up_ind
    _keep.insert(cnt, _ele)

def solve():
    N, K = [int(_) for _ in raw_input().split()]
    V = [int(_) for _ in raw_input().split()]
    MAX_CASE = 1<<(2*K)
    ans = 0
    for i in range(MAX_CASE):
        tmpV = deepcopy(V)
        mani = IntToMani(i,K)
        keep = []
        sum_keep = 0
        # tmp_ret = []
        for _man in mani:
            if _man == 0:
                if len(tmpV) == 0:
                    break
                else:
                    ele = tmpV.pop(0)
                    addToKeep(keep, ele)
                    sum_keep += ele
            elif _man == 1:
                if len(tmpV) == 0:
                    break
                else:
                    ele = tmpV.pop()
                    addToKeep(keep, ele)
                    sum_keep += ele
            else:
                if len(keep) == 0:
                    break
                else:
                    ele = keep.pop(0)
                    sum_keep -= ele
                    if _man == 2:
                        tmpV.insert(0, ele)
                    elif _man == 3:
                        tmpV.append(ele)
            # addToKeep(tmp_ret, sum_keep)
            ans = max(ans, sum_keep)
        # ans = max(ans, tmp_ret[-1])
    print ans

if __name__ == '__main__':
    solve()


### FIXED CODE ###

def solve2():
    N, K = [int(_) for _ in raw_input().split()]
    V = [int(_) for _ in raw_input().split()]
    MAX_GET = min(N, K)
    ans = 0
    for i in range(MAX_GET + 1):
        for j in range(MAX_GET + 1 - i):
            get = V[:i] + V[(N - j):]
            if len(get) == 0:
                continue
            get.sort(reverse = True)
            for k in range(K - i - j):
                if len(get) > 0 and get[-1] < 0:
                    get.pop()
                else:
                    break
            ans = max(ans, sum(get))
    print ans

if __name__ == '__main__':
    solve2()
from sys import stdin
from math import gcd
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))
    A.insert(0,0)
    A.append(0)

    L=[0]*N
    R=[0]*N
    for i in range(1,N):
        L[i]=gcd(L[i-1],A[i])
    for i in range(N-2,-1,-1):
        R[i]=gcd(R[i+1],A[i+2])

    res=0
    for i in range(N):
        res=max(res,gcd(L[i],R[i]))
    print(res)

if __name__=="__main__":
    main()

### FIXED CODE ###

from sys import stdin
from fractions import gcd
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))
    A.insert(0,0)
    A.append(0)

    L=[0]*N
    R=[0]*N
    for i in range(1,N):
        L[i]=gcd(L[i-1],A[i])
    for i in range(N-2,-1,-1):
        R[i]=gcd(R[i+1],A[i+2])

    res=0
    for i in range(N):
        res=max(res,gcd(L[i],R[i]))
    print(res)

if __name__=="__main__":
    main()
import math

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

avg_ceil = math.ceil(sum(nums) / len(nums))
avg_floor = math.floor(sum(nums) / len(nums))

cost_ceil = 0
cost_floor = 0

for x in nums:
    if x == avg_ceil:
        continue
    cost_ceil += (x - avg_ceil)**2

for x in nums:
    if x == avg_floor:
        continue
    cost_floor += (x - avg_floor)**2

if cost_ceil <= cost_floor:
    print(cost_ceil)
else
    print(cost_floor)



### FIXED CODE ###

import math

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

avg_ceil = math.ceil(sum(nums) / len(nums))
avg_floor = math.floor(sum(nums) / len(nums))

cost_ceil = 0
cost_floor = 0

for x in nums:
    if x == avg_ceil:
        continue
    cost_ceil += (x - avg_ceil)**2

for x in nums:
    if x == avg_floor:
        continue
    cost_floor += (x - avg_floor)**2

if cost_ceil <= cost_floor:
    print(cost_ceil)
else:
    print(cost_floor)