Harryxun/stf_run huggingface dataset:
from collections import deque

dp = {}

def dfs(N, K, k, have, q):
  if k == K:
    return sum(have)
  else:
    if not ((k, tuple(q)) in dp):
      a = [sum(have)]
      if len(q) > 0:
        tmp_q = q.copy()
        tmp_have = have.copy()
        v = tmp_q.popleft()
        tmp_have.append(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
        tmp_q = q.copy()
        tmp_have = have.copy()
        v = tmp_q.pop()
        tmp_have.append(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
      if len(have) > 0:
        tmp_q = q.copy()
        tmp_have = sorted(have.copy())
        v = tmp_have.pop(0)
        tmp_q.appendleft(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
        tmp_q = q.copy()
        tmp_have = sorted(have.copy())
        v = tmp_have.pop(0)
        tmp_q.append(v)
        a.append(dfs(N, K, k+1, tmp_have, tmp_q))
      dp[(k, tuple(q))] = max(a)
    return dp[(k, tuple(q))]


N, K = map(int, input().split())
V = deque(list(map(int, input().split())))
print(dfs(N, K, 0, [], V))



### FIXED CODE ###

N, K = map(int, input().split())
V = list(map(int, input().split()))
M = min(N, K)
ans = 0
for p in range(M+1):
  for q in range(M-p+1):
    left = []
    right = []
    if p > 0:
      left = V[:p]
    if q > 0:
      right = V[-q:]
    have = sorted((left+right).copy())
    if len(have) > 0:
      for i in range(min(len(have),K-p-q+1)):
        if have[i] > 0:
          break
      ans = max(sum(have[i:]),ans)
print(ans)
import math

S = input().split()

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

CD = (C * D) // math.gcd(C, D)

count_B = B - (B // C) - (B // D) + (B // CD)
count_A = A - 1 - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // CD)

print(count_B - count_A)


### FIXED CODE ###

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
    
S = input().split()

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

CD = (C * D) // gcd(C, D)

count_B = B - (B // C) - (B // D) + (B // CD)
count_A = A - 1 - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // CD)

print(count_B - count_A)
import collections
import numpy as np

n = int(input())
l = input().split()
v = [ int(s) for s in l ]

#n = 4
npv = np.array( v, dtype=np.int32)
#npv = np.array( [3,1,3,2], dtype=np.int32)
npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]

#print('n = ', n)
#print('npv = ', npv)
#print('npv_dic[\'even\'] = ', npv_dic['even'])
#print('npv_dic[\'odd\']  = ', npv_dic['odd'])

dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)

print(list0[0] ,list1[0])
print(list0[1] ,list1[1])

if list0[0][0] == list1[0][0]:
    if list0[0][1] == list1[0][1]:
        if list0[1][1] > list1[1][1]:
            del list0[0]
        else:
            del list1[0]
    elif list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]
#print(list0[0] ,list1[0])
#print(list0[1] ,list1[1])

if list0.__len__() != 0:
    change0 = n//2 - list0[0][1]
else:
    change0 = n//2
change1 = n//2 - list1[0][1]
#print('change:', change0, change1)

print(change0 + change1)


### FIXED CODE ###

import collections
import numpy as np

n = int(input())
l = input().split()
v = [ int(s) for s in l ]

#n = 4
npv = np.array( v, dtype=np.int32)
#npv = np.array( [3,1,3,2], dtype=np.int32)
npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]

#print('n = ', n)
#print('npv = ', npv)
#print('npv_dic[\'even\'] = ', npv_dic['even'])
#print('npv_dic[\'odd\']  = ', npv_dic['odd'])

dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)

#print(list0[0] ,list1[0])
#print(list0[1] ,list1[1])

if list0[0][0] == list1[0][0]:
    if (list0[0][1] == list1[0][1]) and \
        (list0.__len__() > 1) and (list0.__len__() > 1):
        if list0[1][1] > list1[1][1]:
            del list0[0]
        else:
            del list1[0]
    elif list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]
#print(list0[0] ,list1[0])
#print(list0[1] ,list1[1])

if list0.__len__() != 0:
    change0 = n//2 - list0[0][1]
else:
    change0 = n//2
change1 = n//2 - list1[0][1]
#print('change:', change0, change1)

print(change0 + change1)
n, x = map(int, input().split())
l_array = [int(x) for x in input().split()]
d = 0
cnt = 0
while d <= x:
  d = d+l_array[d]
  cnt += 1
print(cnt)

### FIXED CODE ###

n, x = map(int, input().split())
l_array = [int(x) for x in input().split()]
cnt = 1
now = 0
for l in l_array:
    now += l
    if now > x:
        break
    cnt += 1
print(cnt)
nums = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(nums[k+1])

### FIXED CODE ###

nums = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(nums[k-1])
#!/usr/bin/env python3
import sys
import collections


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    cur = 1
    c = {}
    route = []
    roop = None
    while (True):
        if cur in c:
            roop = cur
            break
        route.append(cur)
        c[cur] = 1
        cur = A[cur - 1]
    idx = route.index(roop)
    if K <= idx:
        print(route[K])
        return
    route = route[idx:]
    print(route[K % len(route) - idx])
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import collections


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    cur = 1
    c = {}
    route = []
    roop = None
    while (True):
        if cur in c:
            roop = cur
            break
        route.append(cur)
        c[cur] = 1
        cur = A[cur - 1]
    idx = route.index(roop)
    if K <= idx:
        print(route[K])
        return
    # route = route[idx:]
    print(route[(K - idx) % (len(route) - idx) + idx])
    return


if __name__ == '__main__':
    main()
class UnionFind():
  def __init__(self,size):
    self.table=[-1]*size
  def root(self,x):
    while self.table[x]>=0:
      x=self.table[x]
    return x
  def unite(self,x,y):
    s1=self.root(x)
    s2=self.root(y)
    if s1!=s2:
      if self.table[s1]>self.table[s2]:
        s1,s2=s2,s1
      self.table[s1]+=self.table[s2]
      self.table[s2]=s1
  def same(self,x,y):
    return self.root(x)==self.root(y)
  def size(self,x):
    return -self.table[self.root(x)]
from collections import*
from heapq import*
def main():
  n,m,*a=map(int,open(0).read().split())
  u=UnionFind(n)
  d=defaultdict(list)
  for x,y in zip(*[iter(a[n:])]*2):u.unite(x,y)
  for i,v in enumerate(a[:n]):d[u.root(i)]+=v,
  *h,=map(sorted,d.values())
  heapify(h)
  p=heappop
  c=0
  while len(h)>1:
    x,y=p(h),p(h)
    if not x or not y:
      1/0
    c+=p(x)+p(y)
    heappush(h,list(merge(x,y)))
  print(c)
main()

### FIXED CODE ###

from collections import*
from heapq import*
def main():
  n,m,*a=map(int,open(0).read().split())
  table=[-1]*n
  def root(x):
    while table[x]>=0:x=table[x]
    return x
  def unite(x,y):
    s1=root(x)
    s2=root(y)
    if s1!=s2:
      if table[s1]>table[s2]:s1,s2=s2,s1
      table[s1]+=table[s2]
      table[s2]=s1
  d=defaultdict(list)
  for x,y in zip(*[iter(a[n:])]*2):unite(x,y)
  for i,v in enumerate(a[:n]):d[root(i)]+=v,
  if len(d)<2:
    print(0)
    return
  *d,=map(sorted,d.values())
  c=sum(heappop(t)for t in d)
  l=[]
  for t in d:l+=t
  i=len(d)-2
  if len(l)<i:
    print('Impossible')
  else:
    print(c+sum(sorted(l)[:i]))
main()
s = input()
ans = "No"
if s[0] == S[1] == s[2]:
  ans = "Yes"
elif s[1] == s[2] == s[3]:
  ans = "Yes"
print(ans)

### FIXED CODE ###

s = input()
ans = "No"
if s[0] == s[1] == s[2]:
  ans = "Yes"
elif s[1] == s[2] == s[3]:
  ans = "Yes"
print(ans)
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

for txyi, txyip in zip([[0, 0, 0]] + txy[:-1], txy):
    ti, xi, yi = txyi
    tip, xip, yip = txyip
    dift = tip - ti
    difd = abs(xip-xi) + abs(yip-yi)
    if difd%2 != dfit%2:
        print('No')
        exit()
    if dift < difd:
        print('No')
        exit()
print('Yes')



### FIXED CODE ###

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

for txyi, txyip in zip([[0, 0, 0]] + txy[:-1], txy):
    ti, xi, yi = txyi
    tip, xip, yip = txyip
    dift = tip - ti
    difd = abs(xip-xi) + abs(yip-yi)
    if difd%2 != dift%2:
        print('No')
        exit()
    if dift < difd:
        print('No')
        exit()
print('Yes')
s=input()
flg=True
if s[i]!="A":
    flg=False
cnt=0
for i in s[3:-2]:
    if i=="C":
        cnt+=1
if cnt!=1:
    flg=False
cnt=0
for i in s:
    if i.isupper():
        cnt+=1
if cnt!=2:
    flg=False
if flg:
    print("AC")
else:
    print("WA")


### FIXED CODE ###

s=input()
flg=True
if s[0]!="A":
    flg=False
cnt=0

for i in s[2:-1]:
    if i=="C":
        cnt+=1
#print(cnt)
if cnt!=1:
    flg=False
cnt=0
for i in s:
    if i.isupper():
        cnt+=1
if cnt!=2:
    flg=False
if flg:
    print("AC")
else:
    print("WA")
def solve(a, b, h):
    return (a + b) * h / 2


a = raw_input()
int(a)
b = raw_input()
int(b)
h = raw_input()
int(h)
ans = solve(a, b, h)
print ans


### FIXED CODE ###

def solve(a, b, h):
    return (a + b) * h / 2


a = raw_input()
a = int(a)
b = raw_input()
b = int(b)
h = raw_input()
h = int(h)
ans = solve(a, b, h)
print ans
S = input()
Q = int(input())
reverse = 1
for i in range(Q):
    list = input()
    if list[0] == "1":
        reverse *= -1
    else:
        list = list.split()
        if reverse == 1:
            if list[1] == "2":
                S = S + list[2]
            else:
                S = list[2] + S
        else:
            if list[1] == "2":
                S = list[2] + S
            else:
                S = S + list[2]
if reverse == 1:
    print(S)
else:
    print(reversed(S))


### FIXED CODE ###

a = input()
b = a[0]
c = False
for i in range(len(a)):
    if a[i] != b:
        c = True
if c:
    print("Yes")
else:
    print("No")
n = int(input())
a = list(map(int,input().split()))

n = len(a)
a.sort()
a.append()
ans = 0
i = 0

while i < n:
    cnt = 1
    while a[i] == a[i+1]:
        cnt += 1
        i += 1
    if cnt >= a[i]:
        ans += cnt - a[i]
    else:
        ans += cnt
    i += 1
print(ans)

### FIXED CODE ###

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

n = len(a)
a.sort()
a.append(0)
ans = 0
i = 0

while i < n:
    cnt = 1
    while a[i] == a[i+1]:
        cnt += 1
        i += 1
    if cnt >= a[i]:
        ans += cnt - a[i]
    else:
        ans += cnt
    i += 1
print(ans)
from sys import stdin


def f(x, k, d):
    if k == 0:
        return x

    if x == 0:
        if k % 2 == 0:
            return 0
        elif k % 2 == 1:
            return d
    elif x > 0:
        tmp = abs(x) / d
        if d * tmp > d * k:
            return x - d * k
        else:
            return f((x-d*tmp), (k-tmp), d)
    elif x < 0:
        tmp = abs(x) / d
        if d * tmp > d * k:
            return x + d * k
        else:
            return f((x+d*tmp), (k-tmp), d)


if __name__ == '__main__':
    X, K, D = [int(x) for x in stdin.readline().rstrip().split()]
    print(abs(f(X, K, D)))


### FIXED CODE ###

from sys import stdin


def f(x, k, d):
    if k == 0:
        return x

    absX = abs(x)
    tmp = absX // d

    if tmp > k:
        return absX - d * k
    else:
        absX = absX - d * tmp
        k = k - tmp
        if k % 2 == 0:
            return absX
        else:
            return abs(absX - d)


if __name__ == '__main__':
    X, K, D = [int(x) for x in stdin.readline().rstrip().split()]
    print(f(X, K, D))
N, X = map(int, input().split())
A = list(map(int, input().split()))
cnt = 1
D = 0
for a in A:
	D += a
    if D > X:
		break
    cnt += 1

print(cnt)

### FIXED CODE ###

N,X=map(int,input().split())
L=list(map(int,input().split()))
d=0
k=0
for i in range(N):
  d+=L[i]
  if d<=X:
    k+=1
  else:break
print(k+1)
n = input()
if 7 in n:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

n = list(input())
if "7" in n:
  print("Yes")
else:
  print("No")
def readInt():
    return int(input())
def readList():
    return list(map(int,input().split()))
def readMap():
	return map(int,input().split())
def readStr():
    return input()
inf=float('inf')
mod = 10**9+7
import math
from collections import OrderedDict
def solve(N,X,M):
    A=X
    ans=A
    seen=set()
    order_seen=[]
    for i in range(2,N+1):
        A=f(A,M)
        if i!=2:
            if A not in seen:
                seen.add(A)
                order_seen.append(A)
            else:  # If A has already been seen we are just going to repeat so break out of the loop.
                i-= 1 # Correcting factor for fact that when we break out of the loop we go one above with i
                break
        if A==0:   # If A=0 it will repeat forever.
            return ans
        ans+=A
    n=len(order_seen)
    N-=i
    mult_factor=N//n
    total_sum_seen=sum(order_seen)
    ans+=(total_sum_seen*mult_factor)
    number_remaining=N%n
    for i in range(number_remaining):
        ans+=order_seen[i]
    return ans

# The function for the recurrence relation.  A_n+1=A_n^2%M
def f(A,M):
    return A**2%M

N,X,M=readMap()
print(solve(N,X,M))


### FIXED CODE ###

def readInt():
    return int(input())
def readList():
    return list(map(int,input().split()))
def readMap():
	return map(int,input().split())
def readStr():
    return input()
inf=float('inf')
mod = 10**9+7
import math
def solve(N,X,M):
    seen=set()
    order_seen=[]
    while X not in seen:
        seen.add(X)
        order_seen.append(X)
        X=f(X,M)
    pos=order_seen.index(X)  # Find position of when the cycle begins
    if pos>N:  # If position is greater than N, then we know we are not going to include any values from the cycle.
        return sum(order_seen[:N])
    terms_before_cycle=order_seen[:pos]
    sum_terms_before_cycle=sum(terms_before_cycle)
    ans=sum_terms_before_cycle
    terms_in_cycle=order_seen[pos:]
    sum_cycle=sum(terms_in_cycle)
    length_cycle=len(terms_in_cycle)
    number_remaining_terms=N-pos
    mult_factor=(number_remaining_terms)//length_cycle
    ans+=(sum_cycle*mult_factor)
    numb_remain=(number_remaining_terms)%length_cycle
    ans+=sum(terms_in_cycle[:numb_remain])
    return ans

# The function for the recurrence relation.  A_n+1=A_n^2%M
def f(A,M):
    return pow(A,2,M)

N,X,M=readMap()
print(solve(N,X,M))
a, b, c, d = map(str,input().split())
sign = "+-"
for i in range(3):  # 1つ目の記号
    for j in range(3):  # 2つ目の記号
        for k in range(3):  # 3つ目の記号
            if eval(a+sign[i]+b+sign[j]+c+sign[k]+d) == 7:
                print(str(a+sign[i]+b+sign[j]+c+sign[k]+d)+"=7")

### FIXED CODE ###

N = input()
a = int(N[0])
b = int(N[1])
c = int(N[2])
d = int(N[3])

if a+b+c+d ==7:
	print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
	
elif a-b+c+d ==7:
	print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
	
elif a-b-c+d ==7:
	print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
	
elif a+b+c-d ==7:
	print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
	
elif a+b-c-d ==7:
	print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
	
elif a-b+c-d ==7:
	print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
	
elif a+b-c+d ==7:
	print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')

elif a-b-c-d ==7:
	print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
i=int(input())
l=[""]*i
for k in range(i):
  l[k]=input()
l.sort()
maxi=0
kosu=0
for k in l:
  kosu+=1
  if kosu=maxi:
    li.append(k)
  elif kosu>maxi:
    li.clear()
    li.append(k)
print(*li)

### FIXED CODE ###

i=int(input())
l=[""]*i
for k in range(i):
  l[k]=input()
l.sort()
maxi=0
kosu=0
li=[]
subk=""
for k in l:
  if subk!=k:
    kosu=0
    subk=k
  kosu+=1
  if kosu==maxi:
    li.append(k)
  elif kosu>maxi:
    li.clear()
    li.append(k)
    maxi=kosu
for k in li:
  print(k)
def squared(x):
    return x**2

def theta(h, m):
    mr = 6 * m
    hr = 30 * h + m / 2
    r = abs(float(hr) - float(mr))
    return r

def length(a, b, h, m):
    return math.sqrt(squared(a) + squared(b) - 2 * a * b * math.cos(math.radians(theta(h, m))))


a, b, h, m = [x for x in map(int, input().split())]

print(length(a, b, h, m))

### FIXED CODE ###

import math
def squared(x):
    return x**2

def theta(h, m):
    mr = 6 * m
    hr = 30 * h + m / 2
    r = abs(float(hr) - float(mr))
    return r

def length(a, b, h, m):
    return math.sqrt(squared(a) + squared(b) - 2 * a * b * math.cos(math.radians(theta(h, m))))


a, b, h, m = [x for x in map(int, input().split())]

print(length(a, b, h, m))
N,K = list(map(int,input().split()))
P = list(map(int,input().split()))

import numpy as np

Q = np.argmax([sum(P[i:i+K]) for i in range(N-K)])

Q = [sum(P[:K])]
for i in range(1,N-K+1):
    Q.append(Q[i-1]+P[K+i-1]-P[i-1])
a = np.argmax(Q)

ans = sum([(1.00+P[a+j])/2.00 for j in range(K)])

print(ans)

### FIXED CODE ###

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

import numpy as np

Q = np.cumsum(P)

R = np.pad(Q,K,'constant', constant_values=0)[:N]

a = np.argmax(Q-R)

ans = 0
for i in range(K):
    ans += (1.00+P[a-i])/2.00
print(ans)
N = input()
if N == 1:
  print('Hello World')
else :
  a = input()
  b = input()
  print(a + b)

### FIXED CODE ###

N = input()
if N == '1':
  print('Hello World')
else :
  a = input()
  b = input()
  print(int(a) + int(b))
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b,x=map(int,input().split())
    if a+b>x:
        print(0)
        sys.exit()
    for i in range(9,0,-1):#d(N)
        if x-b*i<a*10**(i-1):
            continue
        print(min(10**9,(x-b*i)//a))
        sys.exit()

if __name__=='__main__':
    main()

### FIXED CODE ###

s=["SUN","MON","TUE","WED","THU","FRI","SAT"]
print(7-int(s.index(input())))
S = input()
if S = S[::-1] and S[0:(N-3)/2] = S[0:(N-3)/2:-1]:
    print ('Yes')
else:
    print ('No')

### FIXED CODE ###

S = input()
N = len(S)
K = (N-3)//2
if S == S[::-1] and S[0:K] == S[K:0:-1]:
    print ('Yes')
else:
    print ('No')
N=int(input())
A = list(map(int, input().split()))

inf=float('inf')
dp=[[inf]*2 for j in range(N+1)]

def chmax(a,b):
    return max(a,b)

def rec(n,m):
    if n==0 and m==0:
        dp[0][0]=0
        return 0
    if n==0 and m==1:
        dp[0][1]=-inf
        return -inf

    if dp[n][m] < inf:
        return dp[n][m]
    
    if m==0:
        res=chmax(rec(n-1,0)+A[n-1] ,rec(n-1,1)-A[n-1] ) 
    if m==1:
        res=chmax(rec(n-1,0)-A[n-1] ,rec(n-1,1)+A[n-1] )
     
    dp[n][m]=res

    return res

print(rec(N,0))

### FIXED CODE ###

N=int(input())
A = list(map(int, input().split()))
ans=0
tmp=0
hoge=0
li=[]

for i in range(N):
    li.append(abs(A[i]))
    ans+=abs(A[i])
    if A[i]<0:
        tmp+=1
    if A[i]==0:
        hoge=1

if tmp%2==0 or hoge==1:
    ans=ans
else:
    ans=ans-2*min(li)

print(ans)
from itertools import accumulate

n = int(input())
A = list(map(int, input().split()))
infi = 10 ** 20
SA = list(accumulate([0] + A))

dp = [[infi] * (n + 1) for _ in range(n + 1)]
# dp[i]左からi個決めた時の最小値とする。
if n >= 3:
    for i in range(n):
        dp[i][i] = 0
        dp[i][i + 1] = 0
        if i <= n - 2:
            dp[i][i + 2] = A[i] + A[i + 1]
    for d in range(n + 1):
        for i in range(n):
            j = i + d
            if j > n:
                continue
            if d >= 2:
                for m in range(i + 1, j + 1):
                    dp[i][j] = min(dp[i][j], dp[i][m] + dp[m][j] + SA[j] - SA[i])
    print(dp[0][n])
else:


### FIXED CODE ###

from itertools import accumulate

n = int(input())
A = list(map(int, input().split()))
infi = 10 ** 20
SA = list(accumulate([0] + A))

dp = [[infi] * (n + 1) for _ in range(n + 1)]
# dp[i]左からi個決めた時の最小値とする。
if n >= 3:
    for i in range(n):
        dp[i][i] = 0
        dp[i][i + 1] = 0
        if i <= n - 2:
            dp[i][i + 2] = A[i] + A[i + 1]
    for d in range(n + 1):
        for i in range(n):
            j = i + d
            if j > n:
                continue
            if d >= 2:
                for m in range(i + 1, j + 1):
                    dp[i][j] = min(dp[i][j], dp[i][m] + dp[m][j] + SA[j] - SA[i])
    print(dp[0][n])
else:
    print(sum(A))
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
if M % N == 0:
    print(M//N)
else:
    upper = math.ceil(M/N)
    for i in range(upper, 0, -1):
        if M % i == 0:
            break

    print(i)

### FIXED CODE ###

import bisect
import math
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
if M % N == 0:
    print(M//N)
else:
    upper = math.ceil(M/N)
    factor = set()
    for i in range(1, int(M**0.5)+1):
        if M % i == 0:
            factor.add(i)
    
    factor1 = set()
    for i in factor:
        factor1.add(M//i)
    factor |= factor1
    
    factor = sorted(list(factor))
    print(factor[bisect.bisect_right(factor, upper)-1])
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

import math
INF = math.inf
V = 10 ** 5 + 10

dp = [[INF] * V for _ in range(N + 1)]
dp[0][0] = 0

for i, (w, v) in enumerate(WV):
	for n in range(V):
		if v <= n:
			dp[i + 1][n] = min(dp[i + 1][n], dp[i][n - v] + w)
		dp[i + 1][n] = min(dp[i + 1][n], dp[i][n])
"""
for line in dp:
	for cell in line:
		if cell == INF:
			print("  INF", end="")
		else:
			print("{:5d}".format(cell), end="")
	print()
"""
r = 0
for i in range(V):
	if dp[-1][i] <= W:
		r = i
print(r)

### FIXED CODE ###

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

#import math
INF = 10 ** 12 # math.inf
V = 10 ** 5 + 10

dp = [[INF] * V for _ in range(N + 1)]
dp[0][0] = 0

for i, (w, v) in enumerate(WV):
	for n in range(V):
		if v <= n:
			dp[i + 1][n] = min(dp[i + 1][n], dp[i][n - v] + w)
		dp[i + 1][n] = min(dp[i + 1][n], dp[i][n])
"""
for line in dp:
	for cell in line:
		if cell == INF:
			print("  INF", end="")
		else:
			print("{:5d}".format(cell), end="")
	print()
"""
r = 0
for i in range(V):
	if dp[-1][i] <= W:
		r = i
print(r)
K, A, B = map(int, input().split())

dp = [0] * (K + 1)

dp[0] = 1
dp[1] = 2
for i in range(2, K + 1):
    dp[i] = max(dp[i - 1] + 1, (dp[i - 2] // A) * B + dp[i - 2] % A)
# print(dp)
print(dp[K])

### FIXED CODE ###

K, A, B = map(int, input().split())

if B - A <= 2:
    print(K + 1)
else:
    time = max(0, (K - (A - 1)) // 2)
    ans = A + (B - A) * time
    if (K - (A - 1)) % 2 == 1:
        ans += 1
    print(ans)
import math
n,m=map(int(input().split()))
a=list(map(int,inpit().split()))
ans=0

for i in range(m):
    a=sorted(a,reverse=True)
    a[0]=math.floor(a[0]/2)
     
for j in range(n):
    ans+=a[j]
    
print(ans)

### FIXED CODE ###

import heapq as hq
n,m=map(int,input().split())
a=[-int(x) for x in input().split()]
hq.heapify(a)
for i in range(m):
    x=hq.heappop(a)
    x=-x//2
    hq.heappush(a,-x)
 
print(sum(a)*-1)