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

import math
from collections import defaultdict


class UnionFindTree:
    def __init__(self):
        self.p = {}
        self.rank = {}

    def make(self, x):
        self.p[x] = x
        self.rank[x] = 0

    def find(self, x):
        if x in self.p:
            if self.p[x] != x:
                self.p[x] = self.find(self.p[x])
            return self.p[x]
        return None

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

    def unite(self, x, y):
        return self._unite(self.find(x), self.find(y))

    def _unite(self, x, y):
        if self.rank[x] < self.rank[y]:
            self.p[x] = y
            return y
        else:
            self.p[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            return x


def ncr(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
ab.reverse()

utf = UnionFindTree()
for n in range(1, N + 1):
    utf.make(n)

h = {}
ans = []
total = ncr(N, 2)
for i in range(M):
    now = 0
    for k, v in h.items():
        now += ncr(v, 2)
    ans.append(total - now)

    a, b = ab[i]
    x, y = utf.find(a), utf.find(b)
    a = utf.unite(x, y)
    if x != y:
        n = h.get(x, 1) + h.get(y, 1)
        if x in h:
            del h[x]
        if y in h:
            del h[y]
        h[a] = n

for v in reversed(ans):
    print(v)

### FIXED CODE ###

from collections import defaultdict
from collections import deque


class UnionFindTree:
    def __init__(self):
        self.p = {}
        self.rank = {}

    def make(self, x):
        self.p[x] = x
        self.rank[x] = 0

    def find(self, x):
        if x in self.p:
            if self.p[x] != x:
                # 経路圧縮
                self.p[x] = self.find(self.p[x])
            return self.p[x]
        return None

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

    def unite(self, x, y):
        return self._unite(self.find(x), self.find(y))

    def _unite(self, x, y):
        if self.rank[x] < self.rank[y]:
            self.p[x] = y
            return y
        else:
            self.p[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            return x


def nc2(n):
    return (n * (n - 1)) >> 1


N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

utf = UnionFindTree()
for n in range(1, N + 1):
    utf.make(n)

h = {}
ans = deque([])
total = nc2(N)
now = 0
for i in range(M):
    ans.appendleft(total)

    a, b = ab[M - i - 1]
    x, y = utf.find(a), utf.find(b)
    a = utf.unite(x, y)
    if x != y:
        nx, ny = h.get(x, 1), h.get(y, 1)
        n = nx + ny
        total += nc2(nx) + nc2(ny)
        total -= nc2(n)

        h[x] = 1
        h[y] = 1
        h[a] = n

for v in ans:
    print(v)
### BUGGY CODE ###

import bisect
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

if n == 1:
    ans = max((a[0] - k) * f[0], 0)
    print(ans)

else:
    a.sort()
    f.sort(reverse=True)
    s = []
    for x,y in zip(a,f):
        bisect.insort(s, (x*y, y))

    while k > 0 and s[-1][0] > 0:
        l, y = s[-1]
        s = s[:-1]
        tmp = int((l - s[-1][0]) / y) + 1
        if k > tmp:
            k -= tmp
        else:
            tmp = k
            k = 0
        l = l - tmp * y
        bisect.insort(s, (l, y))
    print(s[-1][0])


### FIXED CODE ###

import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

a.sort()
f.sort(reverse=True)

low = 0
high = 0
for x, y in zip(a,f):
    high = max(high, x*y)

while high != low:
    test = int((high + low) // 2)
    tmp = 0
    for x, y in zip(a,f):
        tmp += max(0, x - math.floor(test / y))
        if tmp > k:
            low = test + 1
            break
    else:
        high = test
print(high)
### BUGGY CODE ###

S = input()
dp = [[0]*13 for i in range(len(S)+1)]
dp[0][0] = 1
#print(dp[0])
for i in range(len(S)):
  c = S[i]
  e = (10**((len(S)-i-1)%12))%13
  if c == "?":
    for d in range(10):
      n = (d*e)%13
      for j in range(13):
        dp[i+1][j] = (dp[i+1][j]+dp[i][(j+13-n)%13])%1000000007
  else:
    d = int(c)
    n = (d*e)%13
    for j in range(13):
      dp[i+1][j] = dp[i][(j+13-n)%13]
  #print(dp[i+1])
print(dp[len(S)][5])


### FIXED CODE ###

S = input()
dp0 = [0]*13
dp0[0] = 1
dp = [dp0]
#print(dp[0])
for i in range(len(S)):
  dpi = dp[i]
  dpn = [0]*13
  c = S[i]
  e = (10**((len(S)-i-1)%12))%13
  if c == "?":
    for j in range(13):
      r = 0
      for d in range(10):
        r += dpi[(j+13-d*e)%13]
      dpn[j] = r%1000000007
  else:
    d = int(c)
    for j in range(13):
      dpn[j] = dpi[(j+13-d*e)%13]
  #print(dp[i+1])
  dp.append(dpn)
print(dp[len(S)][5])
### BUGGY CODE ###

import sys
def fact(n):
    ret = [1]
    for i in range(2,int(n//2)+1):
        if n%i==0:
            ret.append(i)
    return ret
def isPrime(n):
    if n<=1:
        return False
    if n==2:
        return True
    if fact(n)==[1]:
        return True
    else:
        return False
lines = sys.stdin.readlines()
for line in lines:
    inp = int(line)
    s=0
    for i in range(2,inp+1):
        if isPrime(i):
            s+=1
    print (s)

### FIXED CODE ###

import sys

def primeTable(n):
    list = [True for _ in range(n+1)]
    i = 2
    while i * i <= n:
        if list[i]:
            j = i+i
            while j<= n:
                list[j] = False
                j += i
        i += 1

    table = [i for i in range(n+1) if list[i] and i >= 2]
    return table

lines = sys.stdin.readlines()
primeList = primeTable(999999)

for line in lines:
    inp = int(line)
    primes = list(filter(lambda n:n>=2 and n<=inp, primeList))
    num = len(primes)
    print (num)
### BUGGY CODE ###

import heapq
n,m=[int(i) for i in input().split()]
a=[-1*int(i) for i in input().split()]
for i in range(m):
    heapq.heapify(a)
    b=heapq.heappop(a)
    b=b/2
    heapq.heappush(a,b)
ans=0
for i in a:
    ans-=int(i)
print(ans)

### FIXED CODE ###

import heapq
n,m=[int(i) for i in input().split()]
a=[-1*int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    b=heapq.heappop(a)
    b=b/2
    heapq.heappush(a,b)
ans=0
for i in a:
    ans-=int(i)
print(ans)
### BUGGY CODE ###

k = int(input())
if k % 2 == 0:
    print(-1)
    exit()

ten = 1
now = 0
for i in range(10**7):
    x = (ten*7)%k
    now = (now+x)%k
    if now == 0:
        print(i+1)
        exit()
    ten = ten*10%k

### FIXED CODE ###

k = int(input())
if k % 2 == 0:
    print(-1)
    exit()

ten = 1
now = 0
for i in range(10**8):
    x = (ten*7)%k
    now = (now+x)%k
    if now == 0:
        print(i+1)
        exit()
    ten = ten*10%k
print(-1)
### BUGGY CODE ###

n=int(input())
s = input()

R=[]
G=[]
B=[]

for i in range(n):
    if s[i]=="R":
        R.append(i)
    elif s[i]=="G":
        G.append(i)
    else:
        B.append(i)

#print(B)
count = len(R)*len(G)*len(B)
d={}
for i in R:
    for j in G:
        big = max(i,j)
        small = min(i,j)
        
        x = 2*big-small
        y = 2*small-big
        z = (big+small)/2
        
        if x in d:
            d[x] += 1
        else:
            d[x] = 1
        if y in d:
            d[y] += 1
        else:
            d[y] = 1
        if z%1==0:
            if z in d:
                d[z] += 1
            else:
                d[z] = 1
        
        #if 2*big-small in B:
            #count -= 1
            #print(i,j)
            #print("hoi")
        #if 2*small-big in B:
            #count -= 1
            #print(i,j)
        #if (big+small)/2 in B:
            #print((big+small)/2)
            #count -= 1
            #print(i,j)
    
for i in B:
    if i in d:
        count -= d[i]
    
print(count)
        


### FIXED CODE ###

n=int(input())
s = input()

R=[]
G=[]
B=[]

for i in range(n):
    if s[i]=="R":
        R.append(i)
    elif s[i]=="G":
        G.append(i)
    else:
        B.append(i)

#print(B)
count = len(R)*len(G)*len(B)
d={}
for i in R:
    for j in G:
        big = max(i,j)
        small = min(i,j)
        
        x = 2*big-small
        y = 2*small-big
        z = (big+small)/2
        
        if x in d:
            d[x] += 1
        else:
            d[x] = 1
        if y in d:
            d[y] += 1
        else:
            d[y] = 1
        if z%1==0:
            if z in d:
                d[z] += 1
            else:
                d[z] = 1
        
        #if 2*big-small in B:
            #count -= 1
            #print(i,j)
            #print("hoi")
        #if 2*small-big in B:
            #count -= 1
            #print(i,j)
        #if (big+small)/2 in B:
            #print((big+small)/2)
            #count -= 1
            #print(i,j)
    
for i in B:
    if i in d:
        count -= d[i]
    
print(count)
### BUGGY CODE ###

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

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2104
"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    t = int(input())
    for _ in range(t):
        n, k = map(int, input().split())
        houses = [int(x) for x in input().split()]

        if k >= n:              #  ????????¨?????????????????¨?????§??????
            print(0)
            continue

        diff = []
        prev = houses[0]
        for h in houses[1:]:
            diff.append(h-prev)
            prev = h

        points = []
        for x in range(k-1):
            pos = diff.index(max(diff))
            points.append(pos)
            diff[pos] = -1


        cable_total = 0
        prev = 0
        for p in points:
            cable_total += houses[p] - houses[prev]
            prev = p + 1
        if prev != (n - 1):
            cable_total += houses[-1] - houses[prev]

        print(cable_total)


if __name__ == '__main__':
    main(sys.argv[1:])

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2104
AC
"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    t = int(input())
    for _ in range(t):
        n, k = map(int, input().split())
        houses = [int(x) for x in input().split()]

        if k >= n:              #  ????????¨?????????????????¨?????§????????´???
            print(0)
            continue

        # ??¶??????????????¢????¨????????????????????????¨????????????????????????
        gaps = []
        prev = houses[0]
        for i, h in enumerate(houses[1:]):
            gaps.append((h - prev, i))
            prev = h

        # gap?????§????????¨??????????????????????????????????????´????????????
        gaps.sort(reverse=True)
        gaps = gaps[:k-1]


        # ???????????????????????±????????????????¨??????????
        cable_total = 0
        prev = 0
        for _, p in gaps:
            cable_total += houses[p] - houses[prev]
            prev = p + 1
        if prev != (n - 1):
            cable_total += houses[-1] - houses[prev]

        print(cable_total)


if __name__ == '__main__':
    main(sys.argv[1:])
### BUGGY CODE ###

N_K=list(map(int,input().split()))
N=N_K[0]
K=N_K[1]
cost=list(map(int,input().split()))
#cost=[int(input()) for i in range(N)]

answers=[0,abs(cost[1]-cost[0])]
if K==1:
	S=0
	for i in range(N-1):
		S += abs(cost[i]-cost[i+1])
	print (S)
else:
	for i in range(2,N):
		comp=[]
		if i<K:
			comp=[answers[i-j]+abs(cost[i]-cost[i-j]) for j in range(1,i+1)]
			answers.append(min(comp))
		else:
			comp=[answers[i-j]+abs(cost[i]-cost[i-j]) for j in range(1,K+1)]
			answers.append(min(comp))			
	print(answers[-1])

### FIXED CODE ###

N_K=list(map(int,input().split()))
N=N_K[0]
K=N_K[1]
cost=list(map(int,input().split()))
answers=[0,abs(cost[1]-cost[0])]
if K==1:
	S=0
	for i in range(N-1):
		S += abs(cost[i]-cost[i+1])
	print (S)
else:
	for i in range(2,N):
		comp=[]
		if i<K:
			comp=[answers[i-j]+abs(cost[i]-cost[i-j]) for j in range(1,i+1)]
			answers.append(min(comp))
		else:
			comp=[answers[i-j]+abs(cost[i]-cost[i-j]) for j in range(1,K+1)]
			answers.append(min(comp))			
	print(answers[-1])
### BUGGY CODE ###

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

for i in range(1,n+1):
    ans = L.count(i)
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
for e in a:
  b[e-1] += 1
for e in b:
  print(e)
### BUGGY CODE ###

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

n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))

memo = {}


def step(now):
    if (memo.get(now) != None):
        return memo[now]
    if (now in a):
        return 0
    # print(now)
    if (now == 0):
        return 1
    if (now < 0):
        return 0
    # print(now)
    memo[now] = step(now-1)+step(now-2)
    return memo[now]


print(step(n) % 1000000007)

### FIXED CODE ###

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

n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))
a=set(a)

memo = [0]*(n+1)
memo[0]=1
if not(1 in a):
    memo[1]=1

for i in range(2,n+1):
    #print(i)
    if i in a:
        continue
    #print(memo[i-1],memo[i-2])
    memo[i]=memo[i-2]+memo[i-1]
            

#print(memo)
print(memo[n]% 1000000007)
### BUGGY CODE ###

N = int(input())
List9 = [9 ** i for i in range(6) if 9 ** i <= N]
List6 = [6 ** i for i in range(6) if 6 ** i <= N]

def recur(n,con):
  if n == 0:
    return con


  else:
    max9 = max([i for i in List9 if i <= n])
    max6 = max([i for i in List6 if i <= n])
    
    return min(recur(n - max9,con + 1),recur(n - max6,con + 1))
    
print(recur(N,0))

### FIXED CODE ###

N = int(input())
List9 = [9 ** i for i in range(1,7) if 9 ** i <= N]
List6 = [6 ** i for i in range(1,7) if 6 ** i <= N]

def recur(n,con):
  if n == 0:
    return con

  elif n < 6:
    return con + n
    
  elif n < 9:
    return con + (n - 5)

  else:
    max9 = [i for i in List9 if i <= n][-1]
    max6 = [i for i in List6 if i <= n][-1]
    
    return min(recur(n - max9,con + 1),recur(n - max6,con + 1))
    
print(recur(N,0))
### BUGGY CODE ###

N,K=map(int,input().split())
b=list(map(int,input().split()))
b.sort()
a=[]
for i in range(N):
    if b[i]<K:
        a.append(b[i])
N=len(a)
ans=0
#print(bin((1<<K)>>1))
for i in range(N):
    n=1
    for j in range(N):
        if i!=j:
            n=n|n<<a[j]
            n%=(1<<K)
    #print(bin(n))
    if n<((1<<K)>>a[i]):
        ans+=1
    else:
        break
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
b=list(map(int,input().split()))
b.sort()
a=[]
for i in range(N):
    if b[i]<K:
        a.append(b[i])
N=len(a)
ans=0
#print(bin((1<<K)>>1))
C=[1]
n=1
for i in range(N):
    n=n|n<<a[i]
    n%=(1<<K)
    C.append(n)
#print(C)
    #print(bin(n))
if N<=10:
    for i in range(N):
        n=C[i]
        for j in range(i+1,N):
            n=n|n<<a[j]
            n%=(1<<K)
        if n < (1<<K)>>a[i]:
            ans+=1
        else:
            break
    print(ans)
else:
    a+=[10**9]
    H=N
    L=0
    
    while abs(H-L)>4:
        Mid=(H+L)//2
        #print(H,Mid,L)
        n=1
        for i in range(N):
            if i==Mid:
                continue
            else:
                n=n|n<<a[i]
                n%=(1<<K)
        if n >= (1<<K)>>a[Mid]:    
            H=Mid
        else:
            L=Mid
    #print(H,L)        
    for j in range(max(0,L-5),N):
        n=1
        for i in range(N):
            if i==j:
                continue
            else:
                n=n|n<<a[i]
                n%=(1<<K)
        if n >= (1<<K)>>a[j]: 
            print(j)
            exit()
    print(N)
### BUGGY CODE ###

x,n = map(int,input().split())
p = set(map(int,input().split()))
i = 0
while i <= x:
  if (x-i) in p and (x+i) in p:
    i+=1
  elif (x-i) in p:
    print(x+i)
    break
  elif (x+i) in p:
    print(x-i)
    break
  else :
    print(x-i)

### FIXED CODE ###

x,n = map(int,input().split())
p = set(map(int,input().split()))
i = 0
while i <= x:
  if (x-i) in p and (x+i) in p:
    i+=1
  elif (x-i) in p:
    print(x+i)
    break
  elif (x+i) in p:
    print(x-i)
    break
  else :
    print(x-i)
    break
### BUGGY CODE ###

import sys

#sys.stdin = open('input1.txt', 'r')

H, W , N = map(int, raw_input().split())
squares = {}
results = [0 for _ in range(10)]
for _ in range(N):
	h, w = map(int, raw_input().split())
	for x in [(0, 0), (0, -1), (0, -2), (-1, 0), (-1, -1), (-1, -2), (-2, 0), (-2, -1), (-2, -2)]:
		nh, nw = h + x[0], w + x[1]
		if ((nh < 1) or (nw < 1) or (nh + 2 > H) or (nw + 2 > W)):
			pass
		else:
			if (nh, nw) in squares:
				squares[(nh, nw)] += 1
			else:
				squares[(nh, nw)] = 1

for k in squares.keys():
	results[squares[k]] += 1

subtotal = 0
for x in range(1, 10, 1):
	subtotal += results[x]
results[0] = (H - 2) * (W - 2) - subtotal

for x in range(10):
	print str(results[x])


### FIXED CODE ###

import sys

#sys.stdin = open('input1.txt', 'r')

H, W , N = map(int, raw_input().split())
squares = {}
results = [0 for _ in range(10)]
for _ in range(N):
	h, w = map(int, raw_input().split())
	for x in [(0, 0), (0, -1), (0, -2), (-1, 0), (-1, -1), (-1, -2), (-2, 0), (-2, -1), (-2, -2)]:
		nh, nw = h + x[0], w + x[1]
		if ((nh < 1) or (nw < 1) or (nh + 2 > H) or (nw + 2 > W)):
			pass
		else:
			if (nh, nw) in squares:
				squares[(nh, nw)] += 1
			else:
				squares[(nh, nw)] = 1

for v in squares.values():
	results[v] += 1

results[0] = (H - 2) * (W - 2) - sum(results[1:])

for x in range(10):
	print str(results[x])
### BUGGY CODE ###

import sys
from heapq import heappush, heappop
input = sys.stdin.readline

num, person = map(int, input().split())
arr = []

for i in range(num):
    s, t, x = map(int, input().split())
    arr.append((s - x - 0.5, 1, x, i))
    arr.append((t - x - 0.5, 0, x, i))

for i in range(person):
    d = int(input())
    arr.append((d,))

arr.sort()

heap = []
done = set()

for elem in arr:
    if len(elem) == 1:
        while heap and heap[0][1] in done:
            heappop(heap)
        if heap:
            print(heap[0][0])
        else:
            print(-1)
        continue

    time, kind, x, i = elem
    if kind:
        heappush(heap, (x, i))
    else:
        done.add(i)


### FIXED CODE ###

import sys
from heapq import heappush, heappop
from collections import defaultdict
input = sys.stdin.readline

num, person = map(int, input().split())
arr = []

for i in range(num):
    s, t, x = map(int, input().split())
    arr.append((s - x - 0.5, 1, x, i))
    arr.append((t - x - 0.5, -1, x, i))

for i in range(person):
    d = int(input())
    arr.append((d,))

arr.sort()

heap = []
done = defaultdict(int)

for elem in arr:
    if len(elem) == 1:
        d = elem[0]
        while heap and done[heap[0][1]] and d > done[heap[0][1]]:
            heappop(heap)
        if heap:
            print(heap[0][0])
        else:
            print(-1)
        continue

    time, kind, x, i = elem
    if kind == 1:
        heappush(heap, (x, i))
    elif kind == -1:
        done[i] = time
### BUGGY CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
sum=0
for i in range(n):
    sum+=a[i]
for i in range(m):
    b=list(map(int,input().split()))
    for i in range(b[0]):
        if a[i]<=b[1]:
            sum=sum-a[i]+b[1]
            a[i]=b[1]
    a.sort()
print(sum)

### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=[]
sum=0
for i in range(m):
    b.append(list(map(int,input().split())))
b.sort(key=lambda x: x[1])
B=len(b)
b1=b[B-1][0]
b2=b[B-1][1]
b3=0
for i in range(n):
    if a[i]<b2 and b3==0:
        sum+=b2
        b1-=1
    else:
        sum+=a[i]
    if b1==0:
        B-=1
        if B==0:
            b3=1
        b1=b[B-1][0]
        b2=b[B-1][1]
print(sum)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))

    vals = []
    for i in a_list:
        for X in [i-1, i, i+1]:
            vals.append(len([a for a in a_list if abs(X - a) <= 1]))
    print(max(vals))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import collections
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    num_freq = collections.Counter(a_list)

    vals = []
    for X in set(a_list):
        v = 0
        if X in num_freq:
            v += num_freq[X]
        if X - 1 in num_freq:
            v += num_freq[X-1]
        if X + 1 in num_freq:
            v += num_freq[X+1]
        vals.append(v)
    print(max(vals))

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

import fractions
A, B = map(int, input().split())
max_n = fractions.gcd(A,B)
ans = 1
first = 2
while max_n != 1:
    for i in range(first,max_n+1):
        if max_n % i == 0:
            while max_n % i == 0:
                max_n //= i
            ans += 1
            first = i
            break
print(ans)

### FIXED CODE ###

import fractions
import math

def trial_division(n):
    a = [1]
    for i in range(2,int(math.sqrt(n)) + 1):
        while n % i == 0:
            n //= i
            a.append(i)
    a.append(n)
    return a


A, B = map(int, input().split())
max_n = fractions.gcd(A,B)

ans = set(trial_division(max_n))
print(len(ans))
### BUGGY CODE ###

import copy

class MyClass():

    maxSum = 0

    def do(self, baseList, _temochi, leftIndex, rightIndex, nokoriSousaCount):
        if nokoriSousaCount < 0:
            return

        sum = 0
        for each in _temochi:
            sum += each

        if self.maxSum < sum:
            self.maxSum = sum

        if leftIndex <= rightIndex:
            temochi = copy.copy(_temochi)
            temochi.append(baseList[leftIndex])
            self.do(baseList, temochi, leftIndex + 1, rightIndex, nokoriSousaCount - 1)

            temochi = copy.copy(_temochi)
            temochi.append(baseList[rightIndex])
            self.do(baseList, temochi, leftIndex, rightIndex - 1, nokoriSousaCount - 1)
            
        self.removeMin(_temochi, leftIndex, rightIndex, nokoriSousaCount - 1)

    def removeMin(self, _temochi, leftIndex, rightIndex, nokoriSousaCount):
        temochi = copy.copy(_temochi)
        if len(temochi) > 0 and nokoriSousaCount > 0:
            minNum = min(temochi)
            if minNum < 0:
                temochi.remove(minNum)
                self.do(baseList, temochi, leftIndex, rightIndex, nokoriSousaCount)


count, opeCount = map(int, input().split())
baseList = list(map(int, input().split()))

doClass = MyClass()
doClass.do(baseList, [], 0, count - 1, opeCount)

print(doClass.maxSum)





### FIXED CODE ###

class MyClass():
    maxNumber = 0

    def roop(self, baseList, opeCount):
        listCount = len(baseList)
        roopMax = listCount if listCount < opeCount else opeCount
        for leftCount in range(0, roopMax):
            self.getMax(baseList[0: leftCount + 1], opeCount - leftCount - 1)

            for rightCount in range(1, roopMax - leftCount + 1):
                leftList = baseList[0: leftCount]
                rightList = baseList[listCount - rightCount : listCount]
                handList = leftList + rightList

                self.getMax(handList, opeCount - leftCount - rightCount)

                

    def getMax(self, handList, remainOpeCount):
        if len(handList) < 1:
            return

        maxVal = 0
        removeCount = 0

        if remainOpeCount > 0:
            handList.sort()
            for each in handList:
                if each < 0:
                    removeCount += 1
                    remainOpeCount -= 1
                    if remainOpeCount < 1:
                        break
        
        maxVal = sum(handList[removeCount:])
        self.maxNumber = max([maxVal, self.maxNumber])


count, opeCount = map(int, input().split())
baseList = list(map(int, input().split()))

my = MyClass()
my.roop(baseList, opeCount)
print(my.maxNumber)