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

from copy import deepcopy

N, K = map(int, input().split())
V = tuple(map(int, input().split()))

all_score = sum(V)
memo = {}

def dfs(queue, hand, depth):
    # print(queue, hand, depth)
    if depth == K:
        score = all_score - sum(queue)
        memo[queue] = score
        # print('return', queue, score)
        return score
    if queue in memo:# and memo[queue] is not None:
        # print('memo')
        return memo[queue]

    if queue not in memo:
        memo[queue] = None

    max_score = all_score - sum(queue)
    if len(queue) > 0:
        # A
        A_queue = queue[1:]
        if A_queue not in memo:
            A_hand = deepcopy(hand)
            A_hand.append(queue[0])
            score = dfs(A_queue, A_hand, depth + 1)
            if score > max_score:
                max_score = score
        # B
        B_queue = queue[:-1]
        if B_queue not in memo:
            B_hand = deepcopy(hand)
            B_hand.append(queue[-1])
            score = dfs(B_queue, B_hand, depth + 1)
            if score > max_score:
                max_score = score

    for i in range(len(hand)):
        # C
        C_queue = (hand[i],) + queue
        if C_queue not in memo:
            C_hand = deepcopy(hand)
            C_hand = C_hand[:i] + C_hand[i+1:]
            score = dfs(C_queue, C_hand, depth + 1)
            if score > max_score:
                max_score = score

        # D
        D_queue = queue + (hand[i],)
        if D_queue not in memo:
            D_hand = deepcopy(hand)
            D_hand = D_hand[:i] + D_hand[i + 1:]
            score = dfs(D_queue, D_hand, depth + 1)
            if score > max_score:
                max_score = score

    memo[queue] = max_score
    # print(queue, max_score)
    return max_score

ans = dfs(V, [], 0)
print('0' if ans < 0 else ans)

### FIXED CODE ###

from copy import deepcopy

N, K = map(int, input().split())
V = tuple(map(int, input().split()))
max_score = -1000000000
for i in range(K+1):
    for j in range(K - i + 1):
        if i + j > N:
            continue
        # 左からi個取る
        hand = list(V[:i])
        # 右からj個取る
        hand.extend(V[N-j:])
        # 最大(K - i - j)個戻せる
        # print(i, j, hand)
        score = sum(hand)
        counter = 0
        for h in sorted(hand):
            counter += 1
            if K - i - j - counter < 0:
                break
            if h < 0:
                score -= h
        if max_score < score:
            max_score = score
print(max_score)
### BUGGY CODE ###

n = int(input())

a = []
b = []

for i in range(n):
    aa, bb = map(int, input().split(' '))
    a.append(aa)
    b.append(bb)

order = list(range(n))
tmp_b = b[:]

while(True):
    ok = False
    for i in range(n - 1):
        ok = False
        if tmp_b[i] > tmp_b[i + 1]:
            tmp = tmp_b[i]
            tmp_b[i] = tmp_b[i + 1]
            tmp_b[i + 1] = tmp

            tmp = order[i]
            order[i] = order[i + 1]
            order[i + 1] = tmp
            break
        ok = True
    if ok:
        break

available = False

for i in range(1):

    margin = [0 for i in range(n)]
    now_time = 0
    for i in range(n):
        j = order[i]
        margin[j] = b[j] - (now_time + a[j])
        now_time += a[j]
    
    if min(margin) >= 0:
        available = True
        break
    else:
        min_index = margin.index(min(margin))
        max_index = margin.index(max(margin))

        tmp = order[min_index]
        order[min_index] = order[max_index]
        order[max_index] = tmp


if available:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n = int(input())

a = []
b = []

for i in range(n):
    aa, bb = map(int, input().split(' '))
    a.append(aa)
    b.append(bb)

order = sorted(range(len(b)), key=lambda k: b[k])

available = False


margin = [0 for i in range(n)]
now_time = 0
for i in range(n):
    j = order[i]
    margin[j] = b[j] - (now_time + a[j])
    now_time += a[j]

if min(margin) >= 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

n = int(input())
lis = list(map(int,input().split()))
if not (1 in lis):
  print(-1)
  quit()
ans = 0
c = 1
while(lis):
  if lis[0] != c:
    ans += 1
  else: 
    c += 1
  del(lis[0])
print(ans)

### FIXED CODE ###

n = int(input())
lis = list(map(int,input().split()))
if not (1 in lis):
  print(-1)
  quit()
ans = 0
c = 1
for i in range(n):
  if lis[i] != c:
    ans += 1
  else: 
    c += 1
print(ans)
### BUGGY CODE ###

from collections import defaultdict
def main():
	H, W, D = map(int,input().split())
	pos = [0]*(H*W+1)
	for i in range(H):
		A = list(map(int, input().split()))
		for j in range(W):
			pos[A[j]] = [i, j]
	Q = int(input())
	lr = [0]*Q
	for i in range(Q):
		lr[i] = list(map(int, input().split()))
	ans = defaultdict(int)
	for i in range(1, H*W+1-D):
		pre = i
		cur = i
		d = 0
		while cur < H*W+1:
			pre_pos = pos[pre]
			cur_pos = pos[cur]
			d += abs(pre_pos[0]-cur_pos[0])+abs(pre_pos[1]-cur_pos[1])
			ans[(i, cur)] = d
			pre = cur
			cur += D
	for i in range(Q):
		print(ans[(lr[i][0], lr[i][1])])


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
	H, W, D = map(int,input().split())
	pos = [0]*(H*W)
	for i in range(H):
		A = list(map(int, input().split()))
		for j in range(W):
			pos[A[j]-1] = [i, j]
	Q = int(input())
	lr = [0]*Q
	for i in range(Q):
		lr[i] = list(map(int, input().split()))
	ans = [[0] for _ in range(D)]
	for i in range(H*W-D):
		s_pos = pos[i]
		e_pos = pos[i+D]
		d = abs(s_pos[0]-e_pos[0])+abs(s_pos[1]-e_pos[1])
		ans[i%D].append(ans[i%D][-1]+d)
	for i in range(Q):
		s = lr[i][0]-1
		e = lr[i][1]-1
		print(ans[e%D][e//D]-ans[s%D][s//D])


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

N, M = map(int, input().split())
PY = []
array1 = []
array2 = []

for _ in range(M):
    P, Y = map(int, input().split())
    PY.append([P, Y])
    if P in array1:
        array2[array1.index(P)].append(Y)
    else:
        array1.append(P)
        array2.append([Y])
        
for i in range(len(array2)):
    array2[i].sort()

for i in PY:
    print('{:06}'.format(i[0]), end='')
    print('{:06}'.format(array2[array1.index(i[0])].index(i[1])+1))

### FIXED CODE ###

import bisect

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

for _ in range(M):
    P, Y = map(int, input().split())
    PY.append([P, Y])
    array[P-1].append(Y)
    
for i in range(N):
    array[i].sort()

for p, y in PY:
    n = bisect.bisect_left(array[p-1], y) + 1
    print('%06d%06d' % (p, n))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
dic = {}
fee = 0

for i in range(n):
    a, b = map(int, input().split())
    if a not in dic:
        dic[a] = [b]
    else:
        dic[a].append(b)

for i in range(1, m+1):
    keys = [x for x in range(1, i+1)]
    temp_max_list = []
    for key in keys:
        if key not in dic or dic[key] == []:
            temp_max_list.append(-1)
        else:
            temp_max_list.append(max(dic[key]))
    if max(temp_max_list) == -1:
        continue
    fee += max(temp_max_list)
    select = temp_max_list.index(max(temp_max_list)) + 1
    dic[select].remove(max(temp_max_list))

print(fee)


### FIXED CODE ###

import sys
import heapq
from collections import defaultdict
input = sys.stdin.readline

n, m = map(int, input().split())
dic = defaultdict(list)
total = 0
candidates = []
heapq.heapify(candidates)

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

for day in range(1, m+1):
    if day in dic:
        for x in dic[day]:
            heapq.heappush(candidates, -x)

    if candidates:
        total -= heapq.heappop(candidates)

print(total)
### BUGGY CODE ###

s=input()
branch={}

def check(s):
    if len(s)==2:return []
    ans=[]
    for i in range(2,len(s)):
        if s[i-2]!=s[i]:ans.append(i-1)
    return ans
def result(limit):
    if limit%2==1:return 'Second'
    if limit%2==0:return 'First'
branch[1]=check(s)
past=(s,)
now=1
limit=1000000
def go(s,now,limit,past,prev):
    if prev==0:branch[now]=check(s)
    if branch[now]==[]:
        if now==1 and prev!=0:print(result(limit))
        elif now==1 and prev==0:print('Second')
        elif now==2:print('First')
        else:go(past[now-2],now-2,now,past[:-2],1)
    else:
        if now+1==limit:go(past[now-1],now-1,limit,past[:-1],1)
        else:
            x=branch[now].pop()
            s=s[:x]+s[x+1:]
            past+=(s,)
            go(s,now+1,limit,past,0)
go(s,now,limit,past,0)

### FIXED CODE ###

s=input()
def result(limit):
    if limit%2==1:return 'First'
    if limit%2==0:return 'Second'
first=s[0]
last=s[-1]
if first!=last:
    first_idx=[]
    last_idx=[]
    for x in range(s.count(first)):
        first_idx.append(s.index(first,x))
    for y in range(s.count(last)):
        last_idx.append(s.index(last,y))
    judge=0
    data=[]
    data.append(last_idx.pop())
    while judge<2:
        if judge==0:
            while judge==0:
                if len(first_idx)==0:judge=2
                else:
                    k=first_idx.pop()
                    if k<data[-1]:
                        judge=1
                        data.append(k)
                    
        elif judge==1:
            while judge==1:
                if len(last_idx)==0:judge=2
                else:
                    k=last_idx.pop()
                    if k<data[-1]:
                        judge=0
                        data.append(k)
        
    print(result(len(s)-len(data)))

elif first==last:
    first_idx=[]
    for x in range(s.count(first)):
        first_idx.append(s.index(first,x))
    
    alpha='abcdefghijklmnopqrstuvwxyz'
    counter=[0 for _ in range(len(alpha))]
    for i in range(1,len(first_idx)):
        string=s[first_idx[i-1]+1:first_idx[i]]
        for j in range(len(alpha)):
            if alpha[j] in string:counter[j]+=1
    k = max(counter)
    print(result(len(s)-2*k-1))
### BUGGY CODE ###

import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def reverse(S):
    return S[::-1]

def main():
    S = _S()
    Q = I()
    Querys = [LS() for _ in range(Q)]
    s = S
    for q in Querys:
        # print(q)
        if q[0]=='1':
            s = reverse(s)
        elif q[0]=='2':
            ti,fi,ci = q
            # print(ti,fi,ci)
            if fi=='1':
                s = ci + s
            elif fi=='2':
                s = s + ci
            else:
                pass
        else:
            pass
    print(s)

main()



### FIXED CODE ###

import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    S = _S()
    Q = I()
    Querys = [LS() for _ in range(Q)]
    rev_flg = -1
    dq = collections.deque(S)
    for q in Querys:
        if q[0]=='1':
            rev_flg *= -1
        else:
            ti,fi,ci = q
            if int(fi)*rev_flg in (1,-2):
                dq.append(ci)
            else:
                dq.appendleft(ci)

    print("".join(dq)[::-1] if rev_flg==1 else "".join(dq))

main()
### BUGGY CODE ###

n = int(input())
attends = list(map(int, input().split()))
for x in range(1, n + 1):
    print(attends.index(x) + 1)

### FIXED CODE ###

n = int(input())
attends = dict(enumerate(list(map(int, input().split())), start=1))
attends_sorted = sorted(attends.items(), key=lambda x: x[1])
arr = [x[0] for x in attends_sorted]
print(*arr)
### BUGGY CODE ###

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

nn = 1 << n

dp = [0 for __ in range(nn)]
dp[0] = 1

for bit in range(nn):
    cur = dp[bit] % mod
    if cur == 0:
        continue
    i = bin(bit).count("1")
    for j in range(n):
        bit_new = bit | (1 << j)
        if bit_new != bit and a[i-1][j] == 1:
            dp[bit_new] += cur

print(dp[-1] % mod)


### FIXED CODE ###

mod = 10**9+7

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [-1 for __ in range(1 << n)]
dp[0] = 1


def dfs(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += dfs(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]


print(dfs(2**n-1, 0))
### BUGGY CODE ###

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

while True:
    N,K = map(int,raw_input().split())
    A = sorted([int(raw_input()) for i in range(0,K)])

    if (N,K) == (0,0):
        break

    if A[0] == 0:
        flag = True
        A = A[1:]
        K -= 1
    else:
        flag = False

    ans = 0
    for i in range(K):
        for j in range(i+1,K):
            if j - i == A[j] - A[i]:
                ans = max(ans,A[j]-A[i])
            elif flag is True and j - i + 1 == A[j] - A[i]:
                ans = max(ans,A[j]-A[i])

    print(ans+1)

### FIXED CODE ###

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

while True:
    N,K = map(int,raw_input().split())
    A = sorted([int(raw_input()) for i in range(0,K)])

    if (N,K) == (0,0):
        break

    if A[0] == 0:
        flag = True
        A = A[1:]
        K -= 1
    else:
        flag = False

    ans = 0
    count = 0
    diff_list = []
    s = 0
    for i in range(1,K):
        if A[i] - A[i-1] == 2:
            diff_list.append(A[i-1] - A[s])
            s = i
            count = 0
        elif A[i] - A[i-1] > 2:
            diff_list.append(A[i-1] - A[s])
            diff_list.append(0)
            s = i
            count = 0
        else:
            count += 1
            ans = max(ans,count)
    else:
        diff_list.append(A[i] - A[s])

    if flag is True:
        ans = 0
        for i in range(1,len(diff_list)):
            ans = max(ans,diff_list[i] + diff_list[i-1] + 2)

    print(ans + 1)
### BUGGY CODE ###


def resolver(N, A):
    A.sort(reverse=True)
    circle = []
    ans = 0

    for a in A:
        if len(circle) == 0:
            circle.append(a)
        elif len(circle) == 1:
            ans += circle[0]
            circle.append(a)
        else:
            idx = max(range(len(circle)), key=lambda i: min(circle[i-1], circle[i]))
            ans += min(circle[idx-1], circle[idx])
            circle.insert(idx, a)

    return ans

def main():

    N = int(input())
    A = list(map(int, input().split()))
    ans = resolver(N, A)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###


def resolver(N, A):
    A.sort(reverse=True)
    ans = 0
    for i, _ in enumerate(A):
        if i == 0:
            continue
        elif i == 1:
            ans += A[0]
        else:
            j = (i // 2) 
            ans += A[j]
    
    return ans



def _resolver(N, A):
    A.sort(reverse=True)
    circle = []
    ans = 0

    for a in A:
        if len(circle) == 0:
            circle.append(a)
        elif len(circle) == 1:
            ans += circle[0]
            circle.append(a)
        else:
            idx = max(range(len(circle)), key=lambda i: min(circle[i-1], circle[i]))
            ans += min(circle[idx-1], circle[idx])
            circle.insert(idx, a)

    return ans

def main():

    N = int(input())
    A = list(map(int, input().split()))
    ans = resolver(N, A)
    print(ans)


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

from collections import defaultdict
N = int(input())
dic = defaultdict(list)
for n in range(N - 1):
    a, b = map(int, input().split())
    dic[a].append(b)
    dic[b].append(a)
c_list = sorted(map(int, input().split()))
M = sum(c_list[:-1])
d_list = [False] * N
for i in range(N):
    if len(dic[i]) == 1:
        break
blank = N
q = [i]
while blank:
    i = q.pop(0)
    q += dic[i]
    if not d_list[i - 1]:
        d_list[i - 1] = c_list[blank - 1]
        blank -= 1
print(M)
print(' '.join(map(str, d_list)))

### FIXED CODE ###

from collections import defaultdict
N = int(input())
dic = defaultdict(list)
for n in range(N - 1):
    a, b = map(int, input().split())
    dic[a].append(b)
    dic[b].append(a)
c_list = sorted(map(int, input().split()))
M = sum(c_list[:-1])
d_list = [False] * N
for i in range(1, N + 1):
    if len(dic[i]) == 1:
        break
blank = N
q = [i]
while blank:
    i = q.pop(0)
    if not d_list[i - 1]:
        q += dic[i]
        d_list[i - 1] = c_list[blank - 1]
        blank -= 1
print(M)
print(' '.join(map(str, d_list)))
### BUGGY CODE ###

h, n = list(map(int,input().split()))
a = [list(map(int,input().split())) for _ in range(n)]

INF = 10**18
dp = [INF]*(h+10001)

dp[0] = 0

for i in range(n):
  for j in range(h):
    if dp[j] == INF:
      continue
    dp[j+a[i][0]] = min(dp[j+a[i][0]],dp[j]+a[i][1])
print(min(dp[h:]))

### FIXED CODE ###

h, n = list(map(int,input().split()))
a = [list(map(int,input().split())) for _ in range(n)]

INF = 10**18
dp = [INF]*(h+10001)

dp[0] = 0

for i in range(n):
  for j in range(h):
    if dp[j] == INF:
      continue
    dp[j+a[i][0]] = min(dp[j+a[i][0]],dp[j]+a[i][1])
print(min(dp[h:]))
### BUGGY CODE ###

x,y = map(int, input().split())
while (x,y) != (0,0):
 if x < y:
  print(x,y)
 else:
  print(y,x)



### FIXED CODE ###

while True:
 x,y = map(int, input().split())
 if x==0 and y==0:
  break
 if x <= y:
  print(x,y)
 else:
  print(y,x)
### BUGGY CODE ###

from collections import deque

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

bar.sort()
bar = deque(bar)
ans = 0

while len(bar) > 1:
    a = bar.popleft()
    for i in range(len(bar)-1):
        b = bar[i]
        for j in range(i+1, len(bar)):
            c = bar[j]
            if c < (a+b):
                ans += 1
            else:
                break

print(ans)

### FIXED CODE ###

import bisect

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

for i in range(n):
    for j in range(i+1,n):
        T=bisect.bisect_left(L,L[i]+L[j])
        count += T-j-1

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

H,W,M = map(int,input().split())
T = [0] * M
H_cnt = {}
W_cnt = {}
HW = {}
for i in range(M):
    h,w = map(int,input().split())
    if not h in H_cnt:
        H_cnt[h] = 0
    if not w in W_cnt:
        W_cnt[w] = 0
    H_cnt[h] += 1
    W_cnt[w] += 1
    HW[(h,w)] = 1

HL = [[h,cnt] for h,cnt in H_cnt.items()]
WL = [[w,cnt] for w,cnt in W_cnt.items()]

HL.sort(key=lambda x: x[1],reverse=True)
WL.sort(key=lambda x: x[1],reverse=True)

HS = []
max_cnt = 0
for h,cnt in HL:
    if max_cnt<=cnt:
        HS.append([h,cnt])
        continue
    break

WS = []
max_cnt = 0
for w,cnt in WL:
    if max_cnt<=cnt:
        WS.append([w,cnt])
        continue
    break

cnt = 0
ans = 0
for h,hcnt in HS:
    for w,wcnt in WS:
        if (h,w) in HW:
            cnt = hcnt+wcnt-1
            ans = max(ans,cnt)
            continue
        cnt = hcnt+wcnt
        ans = max(ans,cnt)

print(ans)

















### FIXED CODE ###

H,W,M = map(int,input().split())
T = [0] * M
H_cnt = {}
W_cnt = {}
HW = {}
for i in range(M):
    h,w = map(int,input().split())
    if not h in H_cnt:
        H_cnt[h] = 0
    if not w in W_cnt:
        W_cnt[w] = 0
    H_cnt[h] += 1
    W_cnt[w] += 1
    HW[(h,w)] = 1

HL = [[h,cnt] for h,cnt in H_cnt.items()]
WL = [[w,cnt] for w,cnt in W_cnt.items()]

HL.sort(key=lambda x: x[1],reverse=True)
WL.sort(key=lambda x: x[1],reverse=True)

HS = {}
max_cnth = 0
for h,cnt in HL:
    if max_cnth<=cnt:
        HS[h] = cnt
        max_cnth = max(max_cnth,cnt)
        continue
    break

WS = {}
max_cntw = 0
for w,cnt in WL:
    if max_cntw<=cnt:
        WS[w] = cnt
        max_cntw = max(max_cntw,cnt)
        continue
    break

cnt = 0
ans = 0

# ここの判定を高速にする
cross_cnt = 0
for hw in HW.keys():
    h,w = hw
    if h in HS and w in WS:
        cross_cnt+=1
if len(WS) * len(HS)==cross_cnt:
    print(max_cnth+max_cntw-1)
    exit()
print(max_cnth+max_cntw)


#for h,hcnt in HS:
#    for w,wcnt in WS:
#        if (h,w) in HW:
#            cnt = hcnt+wcnt-1
#            ans = max(ans,cnt)
#            continue
#        cnt = hcnt+wcnt
#        ans = max(ans,cnt)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in range(N):
    ans = ans*A[i]

if ans<= 10**18:
    print(ans)
    exit(0)
else:
    print(-1)


### FIXED CODE ###

import sys  # sys.exit()を使いたいので

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

if 0 in a:
# 0が1つでもあれば0です
    print(0)
else:
# 0がない場合
    cur = 1  # 現在の数値
    for x in a:
        cur *= x
        if cur > 10 ** 18:
        # 10**18を超えたので終了します
            print(-1)
            sys.exit()
    print(cur)  # 10**18以下なので、出力します
### BUGGY CODE ###

N = input()
P_list = input().split()
# N = '5'
# P_list = '4 2 5 1 3'.split()
P_list = [int(i) for i in P_list]
length = len(P_list)
ans = 0 
M = []
for i in range(length):
    # print(min(P_list[0:i+1]))
    if P_list[i]==min(P_list[0:i+1]):
        ans +=1
    
print(ans)

### FIXED CODE ###

N = input()
P_list = input().split()
# N = '5'
# P_list = '4 2 5 1 3'.split()
P_list = [int(i) for i in P_list]
length = int(N)
ans = 0 
M = []
mini =-1
for i in range(length):
    # print(min(P_list[0:i+1]))
    if P_list[i] <mini or mini <0:
        mini = P_list[i]
    if mini == P_list[i]:
        ans +=1


    # if P_list[i]==min(P_list[0:i+1]):
    #     ans +=1
    
print(ans)
### BUGGY CODE ###

n,a=map(int,input().split())
x=list(map(int,input().split()))
x.sort(reverse=True)
sx=sum(x)
dp=[[0]*(n+1) for i in range(sx+1)]
dp[0][0]=1
for i in range(n):
    dp_sub=[[0]*(n+1) for j in range(sx+1)]
    for j in range(sx+1):
        for k in range(n+1):
            if (j==0 and k==0) or dp[j][k]!=0:
                dp_sub[j+x[i]][k+1]=dp[j][k]
    for j in range(sx+1):
        for k in range(n+1):
            dp[j][k]+=dp_sub[j][k]
cnt=0

for i in range(min(sx//a,n)):
    cnt+=dp[a*(i+1)][i+1]
#print(dp)
print(cnt)

### FIXED CODE ###

n,a=map(int,input().split())
x=list(map(int,input().split()))
x.sort(reverse=True)
sx=sum(x)
dp=[[0]*(n+1) for i in range(sx+1)]
dp[0][0]=1
for i in range(n):
    dp_sub=[[0]*(n+1) for j in range(sx+1)]
    for j in range(sx+1):
        for k in range(n+1):
            if (j==0 and k==0) or dp[j][k]!=0:
                dp_sub[j+x[i]][k+1]=dp[j][k]
    for j in range(sx+1):
        for k in range(n+1):
            dp[j][k]+=dp_sub[j][k]
cnt=0

for i in range(min(sx//a,n)):
    cnt+=dp[a*(i+1)][i+1]
#print(dp)
print(cnt)
### BUGGY CODE ###

inp = input()
len_1st = len(inp)

inf = 10 ** 5
for i in range(inf):
  inp = inp.replace('10','')  
  inp = inp.replace('01','')  
  
  cnt_01 = inp.count('01')
  cnt_10 = inp.count('10')
  if (cnt_01 == 0) & (cnt_10 == 0):
    break
  
len_after = len(inp)
print(len_1st - len_after)

### FIXED CODE ###

inp = input()

cnt_0 = inp.count('0')
cnt_1 = inp.count('1')

if (cnt_0 == 0) or (cnt_1 == 0):
  print(0)
else:
  print(min(cnt_0,cnt_1) * 2)
### BUGGY CODE ###

import math
import sys

a, b, n = map(int, input().split())
step = math.ceil(1/10**3)
array = range(1, n+1, step)
ans = -sys.maxsize-1

for x in array:
    val = int((a*x)/b) - a*int(x/b)
    if val > ans:
        ans = val

print(ans)


### FIXED CODE ###

a, b, n = map(int, input().split())
x = min(b-1, n)
ans = int((a*x)/b) - a*int(x/b)
print(ans)
### BUGGY CODE ###

import math
N=int(input())
ans=0
for i in range(1,N+1):
  Y=math.floor(N/i)
  #print('i',i,'Y',Y)
  ans+=(Y*(Y+1)*i)//2
  #print('ans',ans)
print(ans)

### FIXED CODE ###

N = int(input())
ans = 0
for i in range(1, N + 1):
    largest = N // i * i
    ans += ((largest + i) * (N // i)) // 2
print(ans)