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

n,*a=map(int,open(0).read().split())
dp=[[0]*(n+1)for _ in range(n+1)]
for k in range(1,n+1):
    for i in range(n-k+1):
        j=i+k
        dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1])if(n-k)%2else max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1])
print(dp[0][n])

### FIXED CODE ###

n,*a=map(int,open(0).read().split())
dp=[[0]*(n+1)for _ in range(n+1)]
for k in range(1,n+1):
    for i in range(n-k+1):
        j=i+k
        dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1])if(n-k)%2else max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1])
print(dp[0][n])
### BUGGY CODE ###

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

if x>200:
  a.sort()
  a.reverse()
  a=a[0:200]

if y>200:
  b.sort()
  b.reverse()
  b=b[0:200]

if z>200:
  c.sort()
  c.reverse()
  c=c[0:200]

lena=len(a)
lenb=len(b)
lenc=len(c)
  
ansList=[]
for m in range(lena):
  for n in range(lenb):
    for o in range(lenc):
      ansList.append(a[m]+b[n]+c[o])

ansList.sort()
ansList.reverse()

for i in range(k):
  print(ansList[i])


### FIXED CODE ###

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

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ansListab=[]
for i in range(x):
  for j in range(y):
    ansListab.append(a[i]+b[j])

ansListab.sort(reverse= True)

if len(ansListab)>k:
  ansListab=ansListab[0:k]

ansList=[]

for i in c:
  for j in ansListab:
    ansList.append(i+j)

ansList.sort(reverse= True)

for i in range(k):
  print(ansList[i])
### BUGGY CODE ###

ns = int(raw_input())
s = raw_input().split()
nt = int(raw_input())
t = raw_input().split()
ans = 0
for i in t:
	if i in s: ans += 1
print ans

### FIXED CODE ###

input()
l = raw_input().split()
input()
print len(set(l) & set(raw_input().split()))
### BUGGY CODE ###

N = int(input())
pairs = (map(int, input().split()) for _ in range(N))

t, a = 1, 1
for ti, ai in pairs:
    mul = 1
    while ti * mul < t or ai * mul < a:
        mul += 1
    t, a = ti * mul, ai * mul

print(t + a)

### FIXED CODE ###

from decimal import Decimal, ROUND_CEILING

N = int(input())
pairs = (map(Decimal, input().split()) for _ in range(N))

t = Decimal('1')
a = Decimal('1')
ceil = lambda d: d.to_integral_exact(rounding=ROUND_CEILING)

for ti, ai in pairs:
    mul = max(ceil(t / ti), ceil(a / ai))
    t = ti * mul
    a = ai * mul

print(int(t + a))
### BUGGY CODE ###

import itertools
S = input()

l = len(S)

ans = 0
for s, e in itertools.combinations(range(l+1), 2):
  if int(S[s:e]) % 2019 == 0:
    ans += 1

print(ans)


### FIXED CODE ###

S = input()
r = 1
arr = [0]

for c in S[::-1]:
  arr.append((arr[-1] + int(c) * r) % 2019)
  r *= 10
  r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
  ans += v*(v-1)//2
print(ans)
### BUGGY CODE ###

def max_heapify(A, i):
    l = i*2
    r = i*2+1
    largest = i
    if l <= A[0] and A[i] < A[l]:
        largest = l
    else:
        largest = i
    if r <= A[0] and A[largest] < A[r]:
        largest = r

    if largest != i:
        A[largest],A[i] = A[i],A[largest]
        max_heapify(A,largest)

heap = [0]*2000000
while True:
    c = raw_input()
    if c[0] == 'i':
        heap[0] += 1
        heap[heap[0]] = int(c[7:])
        i = heap[0]
        p = i/2
        while p > 0 and heap[p] < heap[i]:
            heap[p],heap[i] = heap[i],heap[p]
            i = p
            p = i/2
    elif c[1] == 'x':
        print heap[1]
        heap[1] = heap[heap[0]]
        heap[0] -= 1
        max_heapify(heap,1)
    else:
        break

### FIXED CODE ###

from sys import stdin

def max_heapify(A, i):
    l = i*2
    r = i*2+1
    largest = i
    if l <= A[0] and A[i] < A[l]:
        largest = l
    else:
        largest = i
    if r <= A[0] and A[largest] < A[r]:
        largest = r

    if largest != i:
        A[largest],A[i] = A[i],A[largest]
        max_heapify(A,largest)

heap = [0]*2000000
for c in stdin:
    if c[0] == 'i':
        heap[0] += 1
        heap[heap[0]] = int(c[7:])
        i = heap[0]
        p = i/2
        while p > 0 and heap[p] < heap[i]:
            heap[p],heap[i] = heap[i],heap[p]
            i = p
            p = i/2
    elif c[1] == 'x':
        print heap[1]
        heap[1] = heap[heap[0]]
        heap[0] -= 1
        max_heapify(heap,1)
    else:
        break
### BUGGY CODE ###

from decimal import Decimal
n = int(input())
a = []
r = {}
for i in range(n):
    d = Decimal(input())
    d *= 10**9
    d2 = 0
    d5 = 0
    while True:
        if d % 2 != 0 and d % 5 != 0:
            break
        if d % 2 == 0:
            d //= 2
            d2 += 1
        if d % 5 == 0:
            d //= 5
            d5 += 1
    a.append((d2,d5))
    r[(d2,d5)] = r.get((d2,d5),0) + 1
ans = 0
for x , y in a:
    for i , j in r.keys():
        if min(x+i,y+j) >= 18:
            ans += r[(i,j)]
            if x == i and y == j:
                ans -= 1
                
print(ans//2)

### FIXED CODE ###

from decimal import Decimal
n = int(input())
a = []
r = {}
for i in range(n):
    d = int(float(input())*10**9 + 0.1)
    d2 = 0
    d5 = 0
    while True:
        if d % 2 != 0 and d % 5 != 0:
            break
        if d % 2 == 0:
            d //= 2
            d2 += 1
        if d % 5 == 0:
            d //= 5
            d5 += 1
    a.append((d2,d5))
    r[(d2,d5)] = r.get((d2,d5),0) + 1
ans = 0
for x , y in r.keys():
    for i , j in r.keys():
        if min(x+i,y+j) >= 18:
            ans += r[(x,y)]*r[(i,j)]
            if x == i and y == j:
                ans -= r[(x,y)]
                
print(ans//2)
### BUGGY CODE ###

# D - I hate Factorization
x = (int)(input())

flg = False
for i in range(-x, x):
    for j in range(-x, x):
        if i ** 5 - j ** 5 == x:
            flg = True
            break
    
    if flg:
        break

print(str(i) + " " + str(j))

### FIXED CODE ###

# D - I hate Factorization
x = (int)(input())

flg = False
if x >= 0:
    for i in range(0, x + 1):
        for j in range(-i - 1, i + 1):
            if i ** 5 - j ** 5 == x:
                flg = True
                break

        if flg:
            print(str(i) + " " + str(j))
            break
else:
    for i in range(0, x + 1):
        for j in range(-i - 1, i + 1):
            if i ** 5 - j ** 5 == x:
                flg = True
                break

        if flg:
            print(str(j) + " " + str(i))
            break
### BUGGY CODE ###

import math

a, b, n = map(int, input().split(" "))

_max = 0
for i in range(n + 1):
    val = math.floor((a * i) / b) - (a * math.floor(i / b))
    if _max > 0 and _max > val: break
    _max = max(_max, val)

print(_max)

### FIXED CODE ###

import math

a, b, n = map(int, input().split(" "))

k = min(n, b - 1)
print(math.floor(a * k / b) - a * math.floor(k / b))
### BUGGY CODE ###

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

### FIXED CODE ###

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

import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())

data = [0]*(N+2)
def add(k, x):
    while k <= N:
        data[k] += x
        k += k & -k
N0 = 2**(N-1).bit_length()
def lower_bound(x):
    w = i = 0
    k = N0
    while k:
        if i+k <= N+1 and w + data[i+k] <= x:
            w += data[i+k]
            i += k
        k >>= 1
    return i+1

P = [list(map(int, readline().split())) for i in range(N)]
*S, = set(x for s, t, x in P)
S.sort()
mp = {e: i for i, e in enumerate(S)}
D = [int(readline()) for i in range(Q)]
que = []
for s, t, x in P:
    y = mp[x]
    que.append((s-x, y, 1))
    que.append((t-x, y, -1))
que.sort()
b = builders.StringBuilder(Q)
i = 0
for d in D:
    while i < 2*N and que[i][0] <= d:
        _, j, f = que[i]
        add(j+1, f)
        i += 1
    k = lower_bound(0)
    if k == N+2:
        b.append("-1\n")
    else:
        b.append("%d\n" % S[k-1])
sys.stdout.write(b.build())

### FIXED CODE ###

from heapq import heappush, heappop
import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
qs = [0]*N
for i in range(N):
    s, t, x = map(int, readline().split())
    qs[i] = (s-x, t-x, x)
qs.sort()

b = builders.StringBuilder(Q)
que = []
D = [int(readline()) for i in range(Q)]
j = 0
for d in D:
    while j < N and qs[j][0] <= d:
        s, t, x = qs[j]
        heappush(que, (x, t))
        j += 1
    while que and que[0][1] <= d:
        heappop(que)
    if que:
        b.append("%d\n" % que[0][0])
    else:
        b.append("-1\n")
sys.stdout.write(b.build())
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())
A = [10**18] * 3
B = [10**18] * 3
dg = abs(ga - gb)
ds = abs(sa - sb)
db = abs(ba - bb)
if ga < gb:
    A[0] = ga
elif ga > gb:
    B[0] = gb
if sa < sb:
    A[1] = sa
elif sa > sb:
    B[1] = sb
if ba < bb:
    A[2] = ba
elif ba > bb:
    B[2] = bb

def calc(X):
    res = -1
    for i in range(N+1):
        if X[0] * i > N:
            break
        M = N - X[0] * i
        jj = M // X[1]
        for j in range(max(jj - 1000, 0), jj+1):
            k = (M - X[1] * j) // X[2]
            res = max(res, dg * i + ds * j + db * k)
        kk = M // X[2]
        for k in range(max(kk - 1000, 0), kk+1):
            j = (M - X[2] * k) // X[1]
            res = max(res, dg * i + ds * j + db * k)
    return res

N += calc(A)
N += calc(B)
print(N)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())
INF = 10**18
A = [INF] * 3
B = [INF] * 3
values = [abs(ga - gb), abs(sa - sb), abs(ba - bb)]
if ga < gb:
    A[0] = ga
elif ga > gb:
    B[0] = gb
if sa < sb:
    A[1] = sa
elif sa > sb:
    B[1] = sb
if ba < bb:
    A[2] = ba
elif ba > bb:
    B[2] = bb

def calc(X):
    dp = [0] * (N+1)
    dp[0] = 0
    for x, v in zip(X, values):
        for i in range(N+1-x):
            dp[i+x] = max(dp[i+x], dp[i] + v)
    return dp[-1]

N += calc(A)
N += calc(B)
print(N)
### BUGGY CODE ###

S = input()
Q = int(input())
reverse_index = -1

for i in range(Q):
    query = input()
    query = query.replace(' ', '')
    if query[0] == '1':
        reverse_index *= -1
    elif query[0] == '2':
        if query[1] == '1':
            if reverse_index == -1:
                S = query[2] + S
            else:
                S = S + query[2]
        else:
            if reverse_index == -1:
                S = S + query[2]
            else:
                S = query[2] + S

if reverse_index == 1:
    S = S[::-1]

print(S)


### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())
reverse_index = -1

for i in range(Q):
    query = input()
    if query[0] == '1':
        reverse_index *= -1
    elif query[0] == '2':
        if query[2] == '1':
            if reverse_index == -1:
                S.appendleft(query[4])
            else:
                S.append(query[4])
        else:
            if reverse_index == -1:
                S.append(query[4])
            else:
                S.appendleft(query[4])

if reverse_index == 1:
    S.reverse()
    print(*S, sep='')
else:
    print(*S, sep='')
### BUGGY CODE ###

h,w,n = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
def sq(a,b,h,w):
	A,B,X = [a-2,a-1,a],[b-2,b-1,b],[]
	for i in A:
		for j in B:
			if 1<=i<=h-2 and 1<=j<=w-2: X.append([i,j])
	return X
y,ans = [],[0 for i in range(10)]
for i,j in x: y += sq(i,j,h,w)
y,i,num = sorted(y),0,1
while y!=[]:
	if y[i]==y[i+1]: num+=1
	else: ans[num],num = ans[num]+1,1
	if i==len(y)-2:
		ans[num]+=1
		break
	else: i+=1
ans[0] = (h-2)*(w-2)-sum(ans)
for i in ans: print(i)

### FIXED CODE ###

h,w,n = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
def sq(a,b,h,w):
	A,B,X = [a-2,a-1,a],[b-2,b-1,b],[]
	for i in A:
		for j in B:
			if 1<=i<=h-2 and 1<=j<=w-2: X.append((i,j))
	return X
y,ans = [],[0 for i in range(10)]
for i,j in x: y += sq(i,j,h,w)
from collections import Counter
for (i,j),k in Counter(y).most_common(): ans[k]+=1
ans[0] = (h-2)*(w-2)-sum(ans)
for i in ans: print(i)
### BUGGY CODE ###

N, M = map(int, input().split())

ls = [[int(x) for x in input().split()] for _ in range(N)]

# これでからの配列を生成すると、全てのリストに値が入っちゃう
# q = [[]]*M
# q[0].append(1)

q = [[0] for _ in range(M)]
for a, b in ls:
    if a <= M:
        q[M-a].append(b)

# print(q)

pool = []
answer = 0
for x in reversed(q):
    m = max(x+pool)
    # print(m, x, pool)
    answer += m
    pool += x
    pool.remove(m)
    

print(answer)

### FIXED CODE ###

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


q = [[0] for _ in range(M)]
for a, b in ls:
    if a <= M:
        q[M-a].append(b*-1)

# print(q)

from heapq import heappop, heappush

pool = []
answer = 0
for x in reversed(q):
    for y in x:
        heappush(pool, y)
    m = heappop(pool)*-1
    answer += m
    

print(answer)
### BUGGY CODE ###

import numpy as np


def main():
    h, w = map(int, input().split())
    grid = [input() for _ in range(h)]
    field = np.array([[0] * w for _ in range(h)])

    for i, row in enumerate(grid):
        row = row + "#"
        cnt = row.count("#")

        idx = -1
        for j in range(cnt + 1):
            idx_next = row.find("#", idx + 1)
            field[i][idx+1:idx_next] = idx_next - idx - 1
            idx = idx_next

    m = 0
    field = field.T

    for i, row in enumerate(zip(*grid)):
        row = "".join(row) + "#"
        cnt = row.count("#")

        idx = -1
        for j in range(cnt + 1):
            idx_next = row.find("#", idx + 1)
            field[i][idx+1:idx_next] += idx_next - idx - 1
            idx = idx_next
        if max(field[i]) > m:
            m = max(field[i])

    print(m - 1)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    h, w = map(int, input().split())
    grid = [input() for _ in range(h)]
    field = [[0] * w for _ in range(h)]

    for i, row in enumerate(grid):
        row = row + "#"
        cnt = row.count("#")
        idx = -1
        for j in range(cnt + 1):
            idx_next = row.find("#", idx + 1)
            for k in range(idx + 1, idx_next):
                field[i][k] = idx_next - idx - 1
            idx = idx_next

    m = 0
    for i, row in enumerate(zip(*grid)):
        row = "".join(row) + "#"
        cnt = row.count("#")
        idx = -1
        for j in range(cnt + 1):
            idx_next = row.find("#", idx + 1)
            for k in range(idx + 1, idx_next):
                field[k][i] += idx_next - idx - 1
                if field[k][i] > m:
                    m = field[k][i]
            idx = idx_next
    print(m - 1)


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


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

x.sort()
count=0

x[0]=x[2]-x[0]
x[1]=x[2]-x[1]


while not(x[0]==1 or x[0]==2):
    x[0]=x[0]-2
    count+=1

while not(x[1]==1 or x[1]==2):
    x[1]=x[1]-2
    count+=1

if (x[0]==1 and x[1]==1):
    print(count+1)
    quit()

if (x[0]==2 and x[1]==2):
    print(count+2)
    quit()

if (x[0]*x[1]==2):
    print(count+3)
    quit()

### FIXED CODE ###

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

x.sort()
count=0

x[0]=x[2]-x[0]
x[1]=x[2]-x[1]

if x[0]%2==0:
    count+=int(x[0]/2)-1
    x[0]=2
else:
    count+=int(x[0]/2)
    x[0]=1
    
if x[1]%2==0:
    count+=int(x[1]/2)-1
    x[1]=2
else:
    count+=int(x[1]/2)
    x[1]=1

if (x[0]==1 and x[1]==1):
    print(count+1)
    quit()

if (x[0]==2 and x[1]==2):
    print(count+2)
    quit()

if (x[0]*x[1]==2):
    print(count+3)
    quit()
### BUGGY CODE ###

n, k = map(int, input().split())
ans = [0] * (k + 2)
S = 0

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**8
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(1, k+1):
    if i > n - k + 1:
        print(0)
    else:
        ans[i] = cmb( (k-1), (i-1) , mod ) * cmb( (n-k+1), (i) , mod )
        if ans[i] < 0:
            ans[i] + mod
        print(ans[i])


### FIXED CODE ###

n, k = map(int, input().split())
ans = [0] * (k + 2)
S = 0

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(1, k+1):
    if i > n - k + 1:
        print(0)
    else:
        ans[i] = cmb( (k-1), (i-1) , mod ) * cmb( (n - k + 1), (i) , mod ) % mod
        if ans[i] < 0:
            ans[i] + mod
        print(ans[i])
### BUGGY CODE ###

import copy

h, w = map(int, input().split())

lists = []
cnt = 0
mozi = ""
size = h * w
kaiseki = []
kaiseki2 = []

for i in range(h):
    s = input()
    mozi += s

lists = list(mozi)


for i in range(size):
    if lists[i] == "#":
        kaiseki.append(i)


while True:
    result = set(lists)
    if len(result) == 1:
        break
    cnt += 1
    for i in range(len(kaiseki)):
        if int(kaiseki[i]) - w >= 0:
            lists[int(kaiseki[i]) - w] = "#"
            kaiseki2.append(int(kaiseki[i]) - w)
        if int(kaiseki[i]) + w <= size - 1:
            lists[int(kaiseki[i]) + w] = "#"
            kaiseki2.append(int(kaiseki[i]) + w)
        amari = int(kaiseki[i]) % w
        if amari != 0:
            lists[int(kaiseki[i]) - 1] = "#"
            kaiseki2.append(int(kaiseki[i]) - 1)
        if amari != w-1:
            lists[int(kaiseki[i]) + 1] = "#"
            kaiseki2.append(int(kaiseki[i]) + 1)
    kaiseki.clear()
    kaiseki = kaiseki2.copy()
    kaiseki2.clear()

print(cnt)

### FIXED CODE ###

from collections import deque

h,w = map(int,input().split())
matrix = [["a" for _ in range(w+2)]] + [list("a" + input() + "a") for _ in range(h)] + [["a" for _ in range(w+2)]]

matrix_list1 = deque()
cnt = 0

for i in range(1,h+1):
    for j in range(1,w+1):
        if matrix[i][j] == "#":
            matrix_list1.append([i,j])

while len(matrix_list1) != 0:     
    for _ in range(len(matrix_list1)):
        x,y = matrix_list1.popleft()
        if matrix[x+1][y] == ".":
            matrix[x+1][y] = "#"
            matrix_list1.append([x+1,y])
        if matrix[x-1][y] == ".":
            matrix[x-1][y] = "#"
            matrix_list1.append([x-1,y])
        if matrix[x][y+1] == ".":
            matrix[x][y+1] = "#"
            matrix_list1.append([x,y+1])
        if matrix[x][y-1] == ".":
            matrix[x][y-1] = "#"
            matrix_list1.append([x,y-1])
    else:
        if len(matrix_list1) > 0:
            cnt += 1
    
print(cnt)
### BUGGY CODE ###

s = list(input())
ans = 0
for i in range(len(s) - 2):
	if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
		s[i], s[i + 1], s[i + 2] = "B", "C", "A"
		# print("".join(s))
		ans += 1
		j = 1
		if i > 0:
			while s[i - j] == "A":
				s[i - j], s[i - j + 1], s[i - j + 2] = "B", "C", "A"
				ans += 1
				# print("".join(s))
				if i - j == 0:
					break
				j += 1
		k = 3
		if i < len(s) - 4:
			while s[i + k] == "B" and s[i + k + 1] == "C":
				s[i + k - 1], s[i + k], s[i + k + 1] = "B", "C", "A"
				ans += 1
				# print("".join(s))
				if i + k + 2 > len(s) - 1:
					break
				k += 2
print(ans)


### FIXED CODE ###

s = input()
ans = 0
s = s.replace("BC", "D")
cnt = 0
for i in range(len(s)):
	if s[i] == "A":
		cnt += 1
	elif s[i] == "D":
		ans += cnt
	else:
		cnt = 0
print(ans)
### BUGGY CODE ###

n = int(input())
count = 0
ans = [i for i in range(1,n+1) if str(i)[0]=='3' or str(i)[0]=='5' or str(i)[0]=='7']
def gcd(a,b):
    c = max(a,b)
    d = min(a,b)
    if b == 0:
        return a
    return gcd(b,a%b)

for i in ans:

    i_str = str(i)
    if i_str[0]=='3' or i_str[0]=='5' or i_str[0]=='7':
        three = i_str.count('3')
        five = i_str.count('5')
        seven = i_str.count('7')
        sum_number = three + five + seven
        if len(i_str) == sum_number and three>0 and five>0 and seven>0:
            count += 1

print(count)


### FIXED CODE ###

n = int(input())
ans = []
count = 0
def dfs(s):

    if int(s)>n:
        return 0
    ans.append(s)
    for c in '753':
        dfs(s+c)
dfs('0')
for i in ans:
    if all(i.count(j)>0 for j in '753'):
        count += 1
print(count)
### BUGGY CODE ###

n,m =map(int,input().split())
h=list(map(int,input().split()))
result=list(range(n))
for i in range(m):
    a,b =map(int,input().split())
    a-=1
    b-=1
    if h[a]>h[b]:
        if b in result:
            x=result.pop(result.index(b))
    elif h[a]<h[b]:
        if a in result:
            x=result.pop(result.index(a))
    else:
        if a in result:
            x=result.pop(result.index(a))
        if b in result:
            x=result.pop(result.index(b))

print(len(result))
            
        
        

### FIXED CODE ###

n,m =map(int,input().split())
h=list(map(int,input().split()))
result=[1]*n
for i in range(m):
    a,b =map(int,input().split())
    a-=1
    b-=1
    if h[a]>h[b]:
        result[b]=0
    elif h[a]<h[b]:
        result[a]=0
    else:
        result[a]=0
        result[b]=0

print(sum(result))
### BUGGY CODE ###

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

ans = [0]*n
ans[1] = abs(h[1]-h[0])

for i in range(2,n):
    ans[i] = min(abs(h[i]-h[j]) + ans[j] for j in range(max(0,i-k),i))
print(ans[n-1])

### FIXED CODE ###

import numpy as np
n,k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = min(dp[s:i] + np.abs(h[i] -h[s:i]))
print(dp[-1])
### BUGGY CODE ###

from math import factorial

N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7


# 2回表れている値とそのインデックスを取得
for a in A:
    if A.count(a) == 2:
        C = a
C_indexes = [i for i, x in enumerate(A) if x == C]

# 二つのCの外側にそれぞれ何個ずつあるか
outside = C_indexes[0] + len(A) - C_indexes[1] - 1

X = factorial(N+1) % MOD
O = factorial(outside) % MOD

for k in range(1, len(A)+1):
    if k > outside + 1:
        Y = pow((factorial(k)) * factorial(N+1-k) % MOD, MOD-2, MOD)
        print((X * Y) % MOD)
    else:
        Y = pow((factorial(k)) * factorial(N+1-k) % MOD, MOD - 2, MOD)
        Y2 = pow((factorial(k-1)) * factorial(outside - k + 1) % MOD, MOD - 2, MOD)
        print(((X * Y) % MOD - (O * Y2) % MOD))


### FIXED CODE ###

from statistics import mode

N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

# 2回表れている値とそのインデックスを取得
C = mode(A)
C_indexes = [i for i, x in enumerate(A) if x == C]

# 二つのCの外側にそれぞれ何個ずつあるか
outside = C_indexes[0] + len(A) - C_indexes[1] - 1

# 階乗・逆元の値を保存
factorial = [1]
inverse = [1]
for i in range(1, N+2):
    factorial.append(factorial[-1]*i % MOD)
    inverse.append((pow(factorial[i], MOD-2, MOD)))

# combination計算
def nCr(n, r):
    if n<r or n==0 or r==0:
        return 0
    return factorial[n] * inverse[r] * inverse[n-r] % MOD


print(N)
for i in range(2, N+2):
    print(int(nCr(N+1, i) - nCr(outside, i-1)) % MOD)
### BUGGY CODE ###

n,m = list(map(int,input().split()))
l = sorted([int(a) for a in input().split()])
for i in range (m):
  l.sort(reverse=True)
  l[0]=l[0]//2
print(sum(l))

### FIXED CODE ###

import heapq
n,m = list(map(int,input().split()))
l = sorted([(int(a)*-1) for a in input().split()])
for i in range (m):
  high = heapq.heappop(l)
  heapq.heappush(l,-(-high//2))
print(abs(sum(l)))