Harryxun/stf_run huggingface dataset:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


def input():
    return sys.stdin.readline().rstrip()


def main():
    # [0 is True?, 1 is True?, ..., 10000 is True?]
    table = [False for _ in range(10001)]
    for i in range(1, 10001, 2):
        table[i] = is_prime(i) and is_prime((i + 1) // 2)

    cumsum = [0 for _ in range(10001)]
    for i in range(1, 10001):
        cumsum[i] = cumsum[i - 1]
        if table[i]:
            cumsum[i] += 1

    Q = int(input())
    for _ in range(Q):
        l, r = map(int, input().split())
        res = cumsum[r] - cumsum[l]
        if table[l]:
            res += 1
        print(res)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


def input():
    return sys.stdin.readline().rstrip()


def main():
    # [0 is True?, 1 is True?, ..., 10000 is True?]
    table = [False for _ in range(100001)]
    for i in range(1, 100001, 2):
        table[i] = is_prime(i) and is_prime((i + 1) // 2)

    cumsum = [0 for _ in range(100001)]
    for i in range(1, 100001):
        cumsum[i] = cumsum[i - 1]
        if table[i]:
            cumsum[i] += 1

    Q = int(input())
    for _ in range(Q):
        l, r = map(int, input().split())
        res = cumsum[r] - cumsum[l]
        if table[l]:
            res += 1
        print(res)


if __name__ == '__main__':
    main()
import numpy


### FIXED CODE ###

N, W =map(int,input().split())
 
INF = 10**10
#dp = [[INF]*100000]*(N*100)#余分に
dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range (N):
    dp[i][0] =0
for j in range (W+1):
    dp[0][j] =0
    

for i in range (N):
    v, w = map(int,input().split())
    for j in range (W+1):
        if j-w>=0:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w]+v)
        else:
            dp[i+1][j] = dp[i][j]


print(dp[N][W])
#!usr/bin/env python3

import sys


def main():
    letters = {
                'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0, 'h': 0,
                'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0,
                'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0,
                'y': 0, 'z': 0
              }

    passage = sys.stdin

    for letter in passage.lower():
        if letter in letters:
            letters[letter] += 1

    for letter, count in letters.items():
        print('%s : %d' % (letter, count))


if __name__ == '__main__':
    main()

### FIXED CODE ###

#!usr/bin/env python3

import sys


def main():
    text = str()
    alphabets = 'abcdefghijklmnopqrstuvwxyz'

    for line in sys.stdin:
        text += line.lower()

    for alphabet in alphabets:
        print('%s : %d' % (alphabet, text.count(alphabet)))


if __name__ == '__main__':
    main()
def lcs_size():
  X = raw_input()
  Y = raw_input()
  
  a = len(X)
  b = len(Y)
  
  z2 = [0 for i in range(b+1)]
  for i in range(a):
    z1 = z2 + []
    for j in range(b):
      if X[i] == Y[j]:
        z2[j+1] = z1[j] + 1
      elif z2[j+1] < z2[j]: 
        z2[j+1] = z2[j]
  
  return z2[-1]

q = input()

for i in range(q):
  print lcs_siz()

### FIXED CODE ###

def lcs_size():
  X = raw_input()
  Y = raw_input()
  a = len(X)
  b = len(Y)
  z2 = [0 for i in range(b+1)]

  for i in range(a):
    ch = X[i]
    z1 = z2 + []
    for j in range(b):
      if ch == Y[j]:
        z2[j+1] = z1[j] + 1
      elif z2[j+1] < z2[j]:
        z2[j+1] = z2[j]

  return z2[-1]

q = input()
for k in range(q):
  print lcs_size()
n = int(input())
uvw = []
for i in range(n-1):
    uvw.append(list(map(int, input().split(' '))))
result = [0]*n
for i in range(n-1):
    if uvw[i][2]%2 == 0:
        result[uvw[i][0]] = 1
        result[uvw[i][1]] = 1
for i in result:
    print(i)

### FIXED CODE ###

from collections import deque

n = int(input())
visit = [-1 for _ in range(n+1)]
friends = [[] for _ in range(n+1)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    friends[u].append([v, w])
    friends[v].append([u, w])

q = deque([1])
visit[1] = 0
while q:
    position = q.popleft()
    for i, cost in friends[position]:
        if visit[i] < 0:
            visit[i] = visit[position] + cost
            q.append(i)

for i in visit[1:]:
    print(i%2)
import heapq
a, b, c, d = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al = sorted(al, reverse=True)
bl = sorted(bl, reverse=True)
cl = sorted(cl, reverse=True)
q = []
heapq.heappush(q, [-(al[0] + bl[0] + cl[0]), 0, 0, 0])
ans = []
heapq.heappush(ans, [-(al[0] + bl[0] + cl[0]), 0, 0, 0])

while True:
#for i in range(d):
    s, aq, bq, cq = heapq.heappop(q)
    if len(al) > aq+1:
        if [-(al[aq+1] + bl[bq] + cl[cq]), aq+1, bq, cq] not in ans:
            heapq.heappush(q, [-(al[aq+1] + bl[bq] + cl[cq]), aq+1, bq, cq])
            heapq.heappush(ans, [-(al[aq+1] + bl[bq] + cl[cq]), aq+1, bq, cq])
            #q.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])
            #ans.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])

    if len(bl) > bq+1:
        if [-(al[aq] + bl[bq+1] + cl[cq]), aq, bq+1, cq] not in ans:
            heapq.heappush(q, [-(al[aq] + bl[bq+1] + cl[cq]), aq, bq+1, cq])
            heapq.heappush(ans, [-(al[aq] + bl[bq+1] + cl[cq]), aq, bq+1, cq])
            #q.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])
            #ans.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])

    if len(cl) > cq+1:
        if [-(al[aq] + bl[bq] + cl[cq+1]), aq, bq, cq+1] not in ans:
            heapq.heappush(q, [-(al[aq] + bl[bq] + cl[cq+1]), aq, bq, cq+1])
            heapq.heappush(ans, [-(al[aq] + bl[bq] + cl[cq+1]), aq, bq, cq+1])
            #q.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])
            #ans.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])

    #q = sorted(q)

    if len(ans) > d:
        ans = sorted(ans, reverse=True)
        if ans[d][0] > q[len(q)-1][0]:
            break

for i in range(d):
    print(-heapq.heappop(ans)[0])


### FIXED CODE ###

a, b, c, d = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al = sorted(al, reverse=True)
bl = sorted(bl, reverse=True)
cl = sorted(cl, reverse=True)
q = [[al[0] + bl[0] + cl[0], 0, 0, 0]]
ans = [[al[0] + bl[0] + cl[0], 0, 0, 0]]
#while True:
for i in range(d):
    s, aq, bq, cq = map(int, q.pop())
    if len(al) > aq+1:
        if [al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq] not in ans:
            q.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])
            ans.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])

    if len(bl) > bq+1:
        if [al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq] not in ans:
            q.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])
            ans.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])

    if len(cl) > cq+1:
        if [al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1] not in ans:
            q.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])
            ans.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])

    q = sorted(q)

    #if len(ans) > d:
    #   ans = sorted(ans, reverse=True)
    #    if ans[d][0] > q[len(q)-1][0]:
    #        break

ans = sorted(ans, reverse=True)
for i in range(d):
    print(ans[i][0])
N, K = map(int, input().split())
a = [int(i) for i in input().split()]
s = bin(K)[1:]
length = len(s)+1
ls = [[0,length-i-1] for i in range(len(s)+1)]

for i in a:
  s = bin(i)[2:]
  while len(s)<length:
    s = '0'+s
  for j in range(len(s)):
    if s[j]=='1':
      ls[j][0] += 1
dic = {}
for i in range(len(ls)):
  x, n = ls[i]
  s = (2**n)*(N-x)-(2**n)*x
  ls[i] = (s,n)
  dic[n]=s
dp = [0]*(length+1)
dp[0] = sum(a)
for i in range(1,length+1):
  if 2**(i-1)>K:
    print(dp[i-1])
    break
  if dic[i-1]>0:
    dp[i] = dp[i-1]+dic[i-1]
  else:
    dp[i] = dp[i-1]
else:
  print(dp[-1])

### FIXED CODE ###

N, K = map(int, input().split())
a = [int(i) for i in input().split()]
m = -1
for i in a:
  if i>m:
    m = i
m = max(K,m)
s = bin(m)[2:]
length = len(s)
ls = [[0,length-i-1] for i in range(length)]

for i in a:
  s = bin(i)[2:]
  while len(s)<length:
    s = '0'+s
  for j in range(length):
    if s[j]=='1':
      ls[j][0] += 1
dic = {}
for i in range(length):
  x, n = ls[i]
  s = (2**n)*(N-x)-(2**n)*x
  dic[n]=s
s = bin(K+1)[2:]
ils = [len(s)-i-1 for i in range(len(s)) if s[i]=='1']
xls = []
for i in range(len(ils)):
  m = ''
  for j in range(ils[i]):
    if dic[j]>0:
      m+='1'
    else:
      m+='0'
  m += '0'
  while len(m)<len(s):
    m += s[len(s)-len(m)-1]
  m = m[::-1]
  xls += [int(m,2)]

ans = 0
for x in xls:
  h = 0
  for u in a:
    h += x^u
  if h>ans:
    ans = h
print(ans)
a=int(input())
for i in range(3):
  input()
e=int(input())
k=int(input())
if e-a<=K:
  print('Yay!')
else:
  print(':(')

### FIXED CODE ###

a=int(input())
for i in range(3):
  z=input()
e=int(input())
k=int(input())
if e-a<=k:
  print('Yay!')
else:
  print(':(')
A, B, C = map(int, input().split())

if A*C < B:
    print(C)

if A*C = B:
    print(C)

if A*C > B:
    print(B//A)

### FIXED CODE ###

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

if A*C < B:
    print(C)

elif A*C == B:
    print(C)

elif A*C > B:
    print(B//A)
A, B, K = map(int, input().split())
nums = []
num_range = list(range(A, B + 1))
if A == B:
    print(A)
else:
    for i in range(K if (B + 1 - A) > K else (B + 1 - A)):
        nums.append(num_range[i])
        nums.append(num_range[- (i + 1)])
    for num in sorted(list(set(nums))):
        print(num)


### FIXED CODE ###

A, B, K = map(int, input().split())
num_range = range(A, B + 1)
for i in sorted(set(num_range[:K]) | set(num_range[-K:])):
    print(i)
x,t=[int(x) for x in input().split()]
print(max(0,x-t)

### FIXED CODE ###

x,t=[int(x) for x in input().split()]
print(max(0,x-t))
import math

input1 = int(input())

if input1 == 2:
    print(2)

else:

    for b in range(100000):
        result = 0
        X = input1 + b
        for a in range(int(math.sqrt(X))):
            if X % (a + 2) == 0:
                result += 1
                break
            else:
                result += 0
        if result == 0:
            break

print(X)



### FIXED CODE ###

# coding cell (SUBMIT ONLY THIS CELL)

import math

X = int(input())
temp = False

if X == 2:
    print(2)
    exit()

if X % 2 == 0:
    X += 1

while temp == False:

    for i in range(int(math.sqrt(X) // 2)):
        if X % (2 * (i + 1) + 1) != 0:
            temp = True
        else:
            temp = False
            break

    X += 2        
    
print(X - 2)
x,y=map(int,input().split())
print(int(y-x+1:y+x-1))

### FIXED CODE ###

K,X=map(int,input().split())
print(*list(range(X-K+1,X+K)))
n = int(input())
b = list(map(int,input().split()))

#b = list(set(a))
b.sort()
 
if len(b) > 1:
    l = len(b)//2
    print(b[l])
else:
    print(b[0])
        

### FIXED CODE ###

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

x.append(0)
x.sort()

#print(x)

min = 10**10

zeroIdx = x.index(0)

for i in range(zeroIdx-k,zeroIdx+1):
    if i < 0 : 
        continue
    elif len(x) <= i + k :
        break

    plsIdx = i + k 
    misIdx = i

    #print(misIdx,plsIdx,x[misIdx],x[plsIdx])

    if abs(x[plsIdx]) > abs(x[misIdx]) :
        tmp = abs(x[plsIdx]) + (abs(x[misIdx])<<1)
    else:
        tmp = (abs(x[plsIdx])<<1) + abs(x[misIdx])

    if tmp < min :
        min = tmp

print(min)
# coding: utf-8

N = int(input())
nums = [int(x) for x in input().split()]

if set([num% 2 for num in nums]) == {0}:
    print("Yes")
    exit(1)

a,b,c = 0,0,0
for elem in nums:
    if elem % 4 == 0 : a += 1  # 4の倍数
    else:
        b += 1  # 4の倍数じゃない

# あとづけ 
# 2の倍数かつnot４の倍数についても考える必要がある
c = 0
for elem in nums:
        if elem % 2 == 0 and elem % 4 != 0: c += 1

if N % 2 == 1:  # 奇数
    if b-c <= (N-c+1)/2 : print("Yes")
    else: print("No")
else:  # 偶数
    if b-c <= a : print("Yes")
    else: print("No")

### FIXED CODE ###

# coding: utf-8

N = int(input())
nums = [int(x) for x in input().split()]

if set([num% 2 for num in nums]) == {0}:
    print("Yes")
    exit(0)

a,b,c = 0,0,0
for elem in nums:
    if elem % 4 == 0 : a += 1  # 4の倍数
    else:
        b += 1  # 4の倍数じゃない

# あとづけ 
# 2の倍数かつnot４の倍数についても考える必要がある
c = 0
for elem in nums:
        if elem % 2 == 0 and elem % 4 != 0: c += 1

if N % 2 == 1:  # 奇数
    if b-c <= (N-c+1)/2 : print("Yes")
    else: print("No")
else:  # 偶数
    if b-c <= a : print("Yes")
    else: print("No")
N = int(input())
L = list(range(1, N))

from functools import reduce
from operator import add

if N == 1:
  print(0)
  exit()

print(reduce(add, L))

### FIXED CODE ###

N = int(input())

print((N) * (N-1) // 2)
if __name__=="__main__":
    N = int(input())
    l = list(map(int,input().split(" ")))
    record = []
    dic = {i:l[i] for i in range(N)}
    count = 0
    sorted_list = sorted(dic.items(),key=lambda d:d[1],reverse=True)
    if sorted_list[0][1]+sorted_list[N-1][1]>=0:
        while dic[N-1]<dic[N-2]:
            dic[N-1]=dic[N-1]+sorted_list[count][1]
            record.append([sorted_list[count][0],N-1])
        for i in range(N-2,0,-1):
            count = 0
            if dic[i]>=dic[i-1]:
                continue
            while dic[i]<dic[i-1]:
                if dic[i] + sorted_list[count][1]>dic[i+1]:
                    count+=1
                    continue
                dic[i] = dic[i] + sorted_list[count][1]
            record.append([sorted_list[count][0], i])
    elif sorted_list[0][1]+sorted_list[N-1][1]<0:
        sorted_list = sorted(dic.items(),key=lambda d:d[1],reverse=False)
        while dic[N - 1] < dic[N - 2]:
            dic[N - 2] = dic[N - 2] + sorted_list[count][1]
            record.append([sorted_list[count][0], N - 2])
        for i in range(N - 2, 0, -1):
            count = 0
            if dic[i] >= dic[i - 1]:
                continue
            while dic[i] < dic[i - 1]:
                dic[i-1] = dic[i-1] + sorted_list[count][1]
            record.append([sorted_list[count][0], i-1])
        
    print(len(record))
    for i in range(len(record)):
         print(str(record[i][0]+1)+" "+str(record[i][1]+1))

### FIXED CODE ###

if __name__=="__main__":
    N = int(input())
    l = list(map(int,input().split(" ")))
    record = []
    dic = {i:l[i] for i in range(N)}
    sorted_list = sorted(dic.items(),key=lambda d:d[1],reverse=True)
    if sorted_list[N-1][1]>=0:
        for i in range(N-1):
            record.append([i, i+1])
    elif sorted_list[0][1]<0:
        for i in range(N-1,0,-1):
            record.append([i, i-1])
    elif sorted_list[0][1]+sorted_list[N-1][1]>=0:
        record.append([sorted_list[0][0], 0])
        record.append([sorted_list[0][0], 1])
        record.append([0,1])
        for i in range(1,N-1):
            record.append([sorted_list[0][0], i+1])
            record.append([i,i+1])
    elif sorted_list[0][1]+sorted_list[N-1][1]<0:
        record.append([sorted_list[N-1][0], N-1])
        record.append([sorted_list[N-1][0], N-2])
        record.append([N-1,N-2])
        for i in range(N-2,0,-1):
            record.append([sorted_list[N-1][0], i-1])
            record.append([i,i-1])
    print(len(record))
    for i in range(len(record)):
         print(str(record[i][0]+1)+" "+str(record[i][1]+1))
n = int(input())
alist = [int(input()) for _ in range(n)]
dis = max(alist) - min(alist)
print(dis)

### FIXED CODE ###

n = int(input())
alist = list(map(int, input().split()))
dis = max(alist) - min(alist)
print(dis)
T = list(input())

if T[0] == '?':
    if T[1] == 'P':
        T[0] = 'D'
    else:
        T[0] = 'P'


for i in range(1, len(T)-1):
    if T[i] == '?':
        if T[i - 1] == 'D' and (T[i + 1] == 'D' or T[i + 1] == '?'):
            T[i] = 'P'
        else:
            T[i] = 'D'

if T[-1] == '?':
    T[-1] = 'D'

print(''.join(T))


### FIXED CODE ###

T = list(input())

if len(T) == 1:
    print('D')
    exit()

if T[0] == '?':
    if T[1] == 'P':
        T[0] = 'D'
    else:
        T[0] = 'P'


for i in range(1, len(T)-1):
    if T[i] == '?':
        if T[i - 1] == 'D' and (T[i + 1] == 'D' or T[i + 1] == '?'):
            T[i] = 'P'
        else:
            T[i] = 'D'

if T[-1] == '?':
    T[-1] = 'D'

print(''.join(T))
N, X = map(int, input().split())
a = [int(input()) for i in range(N)]
print((X-sum(a))/min(a)+N)


### FIXED CODE ###

print(input().count('o')*100+700)
#間隔が大きいところを含まないように分割すればいいのでは？
import bisect
n,m = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
ans = []
xmin = X.pop(0)
prev = xmin
for x in X:
	if len(ans) < n-1:
		bisect.insort(ans, abs(prev - x))
	elif ans[0] < abs(prev - x):
		ans[0] = abs(prev - x)
	prev = x
if n >= m:
	print(0)
else:
	print(X[m-2]-xmin - sum(ans))


### FIXED CODE ###

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

length = X[m-1] - X[0]
L = []
for i in range(m-1):
	L.append(X[i+1] - X[i])
L.sort()

if n >= m:
	print(0)
else:
	print(length - sum(L[m-1-(n-1):m-1]))
n,m = map(int,input().split())

a = [0]*n
a = [int(s) for s in input().split()]

a_half = [s//2 for s in a]
#print(a)

def check(x):
    while (all(c%2 == 0 for c in x)):
        x = [s//2 for s in x]
        if any(c%2 == 1 for c in x) and any(c%2 == 0 for c in x):
            return 0
        
    
    return 1

def gcd(x,y):
    #print(x,y)
    if(x%y == 0):
        #print(y)
        return y
    else:
        return gcd(y,x%y)


def lcm(x,y):
    return x/gcd(x,y)*y

if(check(a)== 1):
    x = a_half[0]
    for i in range(1,n):
        y = a_half[i]
        x = lcm(x,y)
    if(x > m):
        print(0)
    else:
        res = int((m//x+1)//2)
        print(res)
else:
    print(0)
    
    
    


### FIXED CODE ###

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

a = [1]*n
#print(a)
a = [int(s) for s in input().split()]

a_half = [s//2 for s in a]
#print(a)

def check(x):
    while (all(c%2 == 0 for c in x)):
        x = [s//2 for s in x]
        if any(c%2 == 1 for c in x) and any(c%2 == 0 for c in x):
            return 0
        
    
    return 1

def gcd(x,y):
    #print(x,y)
    if(x%y == 0):
        #print(y)
        return y
    else:
        return gcd(y,x%y)


def lcm(x,y):
    return x//gcd(x,y)*y

if(check(a)== 1):
    x = a_half[0]
    for i in range(1,n):
        y = a_half[i]
        x = lcm(x,y)
    if(x > m):
        print(0)
    else:
        res = int((m//x+1)//2)
        print(res)
else:
    print(0)
n = input()
a_list = input().split(" ")

def count_divide(number, max_cnt=-1):
  count = 0
  mod = -1
  while mod != 0:
    q, mod = divmod(number)
    count += 1
    if max_cnt != -1 & count >= max_cnt:
      return max_cnt
  return count

result = -1
for a in a_list:
  result = count_divide(int(a), result)
print(result)


### FIXED CODE ###

n = input()
nums = [int(i) for i in input().split(" ")]

def is_even(num_list):
  for num in num_list:
    if num % 2 != 0:
      return False
  return True

counter = 0
while(is_even(nums)):
  counter += 1
  nums = [n/2 for n in nums]
print(counter)
n,m=(int(i) for i  in input().split())
#print(n,m)
mtrx=[[int(i)-1 for i in input().split()] for j in range(m)]
#print(mtrx)
adjacent=[[] for i in range(n)]
#print(adjacent)
for i in range(n):
    adjacent[mtrx[i][0]]+=[mtrx[i][1]]
    adjacent[mtrx[i][1]]+=[mtrx[i][0]]
#print(adjacent)

cnt=[]
def dfs(goal,path):
    p=path[-1]
    if p==goal:
        cnt.append(len(path))
        return
    else:
        for x in adjacent[p]:
            if x in path:
                continue
            else:
                path.append(x)
                dfs(goal,path)
                path.pop()

for i in range(1,n):
    dfs(i,[0])                

print(cnt.count(n))


### FIXED CODE ###

n,m=(int(i) for i in input().split())
mtrx=[[int(i) for i in input().split()] for j in range(m)]
#print(mtrx)
mtrx+=[[mtrx[i][1],mtrx[i][0]] for i in range(m)]
#print(mtrx)
mylist=[10*mtrx[i][0]+mtrx[i][1] for i in range(len(mtrx))]
#print(mylist)
# 順列を格納するリスト
perm = []
cnt=[]
# 順列の生成
def make_perm(n, m = 0):
    if n == m and perm[0]==1:
        flag=1
        for i in range(len(perm)-1):
            myval=10*perm[i]+perm[i+1]
            myval1=mylist.count(myval)
            flag=flag*myval1
        cnt.append(flag)
        
    else:
        for x in range(1, n + 1):
            if x in perm: continue
            perm.append(x)
            make_perm(n, m + 1)
            perm.pop()
            
make_perm(n)
print(sum(cnt))
a = [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(a[K])

### FIXED CODE ###

a = [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]
print(a[int(input()) - 1])
from collections import deque

q = deque()

n = int(input().strip())

for _ in range(n):
    cmd = input()
    if cmd == "deleteFirst":
        q.popleft()
    elif cmd == "deleteLast":
        q.pop()
    elif cmd.startswith("insert "):
        v = cmd[7:]
        q.appendleft(v)
    elif cmd.startswith("delete "):
        v = cmd[7:]
        q.remove(v)
print(" ".join(q))

### FIXED CODE ###

from collections import deque

q = deque()

n = int(input().strip())

for _ in range(n):
    cmd = input()
    if cmd == "deleteFirst":
        q.popleft()
    elif cmd == "deleteLast":
        q.pop()
    elif cmd.startswith("insert "):
        v = cmd[7:]
        q.appendleft(v)
    elif cmd.startswith("delete "):
        v = cmd[7:]
        try:
            q.remove(v)
        except ValueError:
            pass
print(" ".join(q))
import numpy as np
n,m,q = map(int,raw_input().split())

imos = [[0 for i in xrange(n)] for j in xrange(n)]

for i in xrange(m):
	f,t = map(int,raw_input().split())
	f -= 1
	t -= 1
	for j in range(f+1):
		imos[j][t] += 1

#for i in range(n):
#	for j in range(1,n):
#		imos[i][j] = imos[i][j-1] + imos[i][j]

for i in xrange(n):
	imos[i] = np.cumsum(imos[i])

for i in xrange(q):
	a,b = map(int,raw_input().split())
	print imos[a-1][b-1]


### FIXED CODE ###

import numpy as np
n,m,q = map(int,raw_input().split())

imos = [[0 for i in xrange(n)] for j in xrange(n)]

for i in xrange(m):
	f,t = map(int,raw_input().split())
	f -= 1
	t -= 1
	imos[f][t] += 1

for i in range(n-1,0,-1):
	for j in range(n):
		imos[i-1][j] = imos[i][j] + imos[i-1][j]

for i in xrange(n):
	imos[i] = np.cumsum(imos[i])

for i in xrange(q):
	a,b = map(int,raw_input().split())
	print imos[a-1][b-1]
a=list(map(int, input().split()))
b=2＊a[3]＊a[2]
c=a[2]＊a[4]＊2+a[0]＊(a[3]-a[4])
d=2＊a[4]＊a[2]
e=a[2]＊a[3]＊2+a[1]＊(a[4]-a[3])
f=a[0]＊a[3]+a[1]＊a[4]
if a[3]>=a[4]:
    print(min(b,c,f))
else:
    print(min(d,e,f))


### FIXED CODE ###

a, b, c, x, y = map(int, input().split())
res = 0
if a+b > c*2:
    mi = min(x, y)
    res += c*2 * mi
    x -= mi
    y -= mi
res += x * min(a, c*2)
res += y * min(b, c*2)
print(res)
ans = 0


A = int(A)
P = int(P)
 
P = (A*3) + P
ans = P / 2

ans = round(ans)

print(ans)



### FIXED CODE ###

A,P = map(int,input().split())
ans = 0

A = int(A)
P = int(P)

P = (A*3) + P
ans = P // 2

print(ans)
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
num=[0,2,5,5,4,5,6,3,7,6]
inf=float("inf")
dp=[-1*inf]*(n+1)
dp[0]=0
for i in range(1,n+1):
    for j in range(m):
        dp[i]=max(dp[i],dp[i-num[a[j]]]+1)
ans=[]
for i in range(dp[n]):
    for j in range(m):
        if dp[n-num[a[j]]]==dp[n]-1:
            ans.append(a[j])
            n-=num[a[j]]
            break
print("".join(list(map(str,ans))))


### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
nums=[0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(n+1)
dp[0]=0
for i in range(1,n+1):
    for x in a:
        if i-nums[x]>=0:
            dp[i]=max(dp[i-nums[x]]+1,dp[i])
k=dp[n]
ans=[]
for i in range(k):
    for x in a:
        if n-nums[x]<0:
            continue
        if dp[n-nums[x]]==dp[n]-1:
            n-=nums[x]
            ans.append(x)
            break
print("".join(list(map(str,ans))))