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

num = int(input())
put = []
stor = {}
i=0
while i<num :
    name = input()
    if name in stor.keys():
        stor[name] += 1
    else:
        stor[name] = 1
    i += 1
keyAll = list(stor.keys())
valueAll = list(stor.values())


for i in range(0,len(keyAll)):
    flag = 0
    flag2 = 0
    if i==len(keyAll)-1:
        put.append(keyAll[i])
        break

    for j in range(i+1,len(keyAll)):
        if valueAll[i]<valueAll[j]:
            flag = 1
            break
        if valueAll[i]==valueAll[j]:
            flag2 = 1#存在相等的
    if flag == 0:
        put.append(keyAll[i])
        if flag2==0:
            break
put.sort()
for i in put:
    print(i)


### FIXED CODE ###

num = int(input())

put = []
stor = {}
i=0
while i<num :
    name = input()
    if name in stor.keys():
        stor[name] += 1
    else:
        stor[name] = 1
    i += 1

stor=sorted(stor.items(), key=lambda item:item[1], reverse=True)

m = stor[0][1]

for i in range(0,len(stor)):
    if stor[i][1]==m:
        put.append(stor[i][0])
    else:
        break
put.sort()

for i in put:
    print(i)
### BUGGY CODE ###

from collections import deque


def solve():
    S = deque(list(input()))
    Q = int(input())
    for _ in range(Q):
        query = list(input().split())
        if int(query[0]) == 1:
            S.reverse()
        else:
            if int(query[1]) == 1:
                S.appendleft(query[2])
            else:
                S.append(query[2])
    print(''.join(S))


if __name__ == '__main__':
    solve()


### FIXED CODE ###

from collections import deque


def solve():
    S = deque(list(input()))
    Q = int(input())
    state = 0
    for _ in range(Q):
        query = list(input().split())
        if int(query[0]) == 1:
            state = 1 if state == 0 else 0
        else:
            if (state + int(query[1])) % 2 == 1:
                S.appendleft(query[2])
            else:
                S.append(query[2])
    if state == 0:
        print(''.join(S))
    else:
        S.reverse()
        print(''.join(S))


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

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

import numpy as np

rets = np.array([0] * n)
ls = []
rs = []
for _ in range(m):
  l, r = map(int, input().split())
  ret = np.array([0] * n)
  ret[l-1:r] = 1
  rets += ret
cnt = 0
for i in range(n):
  if rets[i] == m:
    cnt += 1
print(cnt)




### FIXED CODE ###

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

import numpy as np

rets = np.array([0] * n)
lmax = 1
rmin = n
for _ in range(m):
  l, r = map(int, input().split())
  lmax = max(l, lmax)
  rmin = min(r, rmin)
print(rmin - lmax + 1 if rmin - lmax + 1 > 0 else 0)
### BUGGY CODE ###

import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(r) * (math.factorial(n - r)))

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

for i in range(N):
    B = A[:i] + A[i+1:]
    ans = 0
    for c in set(B):
        find = len(list(filter(lambda x: x == c, B)))
        # print("c:{}, find:{}".format(c, find))
        if find <= 1:
            ans += 0
        else:
            ans += comb(find, 2)
    print(ans)


### FIXED CODE ###

import math
import collections

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

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

counter = collections.Counter(A)
dic = {c: comb(counter[c], 2) for c in counter.keys()}
sum_dic = sum(dic.values())

for i in A:
    print(sum_dic - (counter[i] - 1))
### BUGGY CODE ###

import sys
MX = 10**5
def main():
    data = map(int, sys.stdin.buffer.read().split())
    N = next(data)
    items = [(next(data), next(data)) for _ in range(N)]
    Q = next(data)

    H = min(N + 1, 1 << 10)
    Hb = (H - 1).bit_length()
    dp = [[0] * (MX + 1) for _ in range(H)]
    for i in range(1, H):
        v, w = items[i - 1]
        dpi = dp[i]
        dpip = dp[i >> 1]
        for j in range(MX + 1):
            t = dpip[j]
            if j >= w:
                t = max(t, dpip[j - w] + v)
            dpi[j] = t
    for v, L in zip(data, data):
        if v < H:
            print(dp[v][L])
            continue
        ans = 0
        for i in range(1 << (v.bit_length() - Hb)):
            node = v
            value = weight = 0
            while node >= H:
                if i & 1:
                    iv, iw = items[node - 1]
                    value += iv
                    weight += iw
                node >>= 1
                i >>= 1
            if weight > L:
                continue
            ans = max(ans, value + dp[node][L - weight])
        print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
MX = 10**5
def main():
    data = map(int, sys.stdin.buffer.read().split())
    N = next(data)

    H = min(N + 1, 1 << 10)
    dp = [None] * H
    dp[0] = [0] * (MX + 1)
    IV, IW = [], []
    i = 1
    for v, w in zip(data, data):
        if i < H:
            dpi = dp[i >> 1][:]
            dp[i] = dpi
            for j in range(MX, w - 1, -1):
                dpi[j] = max(dpi[j], dpi[j - w] + v)
        else:
            IV.append(v)
            IW.append(w)
        i += 1
        if i > N:
            break

    Q = next(data)
    for v, L in zip(data, data):
        if v < H:
            print(dp[v][L])
            continue

        item_values = []
        item_weights = []
        while v >= H:
            item_values.append(IV[v - H])
            item_weights.append(IW[v - H])
            v >>= 1

        l = len(item_values)
        V = [0] * (1 << l)
        W = [0] * (1 << l)
        ans = dp[v][L]
        for i in range(1, 1 << l):
            msb = i & (-i)
            msbb = msb.bit_length() - 1
            wi = W[i - msb] + item_weights[msbb]
            W[i] = wi
            if wi <= L:
                vi = V[i - msb] + item_values[msbb]
                ans = max(ans, vi + dp[v][L - wi])
                V[i] = vi
        print(ans)

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

N = int(input())
a = [[int(_) for _ in input().split()] for _ in range(N)]
MOD = 10**9+7

dp = [[0 for _ in range((1<<N)+1)] for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    use = [0 for _ in range((1<<N)+1)]
    for s in range(1<<N):
        if dp[i][s] == 0:
            continue
        for j in range(N):
            jb = 1<<j
            if not (s&jb) and a[i][j]:
                dp[i+1][s|jb] += dp[i][s]
    
print(dp[-1][(1<<N)-1]%MOD)


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = [list(map(int,input().split())) for _ in range(N)]
    MOD = 10**9+7
    
    dp = [1] + [0 for _ in range(1<<N)]

    for i in range(N):
        use = [0 for _ in range((1<<N)+1)]
        for s in range(1<<N):
            if dp[s] == 0:
                continue
            for j in range(N):
                jb = 1<<j
                if not (s&jb) and a[i][j]:
                    use[s^jb] += dp[s]
        dp = use
    
    print(dp[(1<<N)-1]%MOD)

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

import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

h,n=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
dp=[[float('inf')]*(h+1) for i in range(n+1)]
dp[0][0]=0
# print(dp)
for i in range(n):
    for j in range(h+1):
        dp[i+1][j]=min(dp[i][j],dp[i+1][j])
        tmp=j+ab[i][0]
        if j+ab[i][0]>h:
            tmp=h
        # print(min(dp[i][j]+ab[i][1],dp[i+1][tmp]))
        dp[i+1][tmp]=min(dp[i+1][j]+ab[i][1],dp[i+1][tmp])
        # print(dp[i+1][tmp])
# print(dp)
print(dp[-1][-1])

### FIXED CODE ###

import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

h,n=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
dp=[[float('inf')]*(h+1) for i in range(n+1)]
dp[0][0]=0
# print(dp)
for i in range(n):
    for j in range(h+1):
        dp[i+1][j]=min(dp[i][j],dp[i+1][j])
        tmp=j+ab[i][0]
        if j+ab[i][0]>h:
            tmp=h
        # print(min(dp[i][j]+ab[i][1],dp[i+1][tmp]))
        dp[i+1][tmp]=min(dp[i+1][j]+ab[i][1],dp[i+1][tmp])
        # print(dp[i+1][tmp])
# print(dp)
print(dp[-1][-1])
### BUGGY CODE ###

S = input()
Q = int(input())
rev = False
for i in range(Q):
  l = input().split()
  if l[0] == '1':
    rev = not rev
  else:
    if rev:
      left = l[2]
      right = S
    else:
      left = S
      right = l[2]
    if l[1] == '1':
      S = right + left
    else:
      S = left + right
if rev:
  print(S[::-1])
else:
  print(S)

### FIXED CODE ###

S = input()
Q = int(input())
left = []
right = []
rev = False
for i in range(Q):
  l = input().split()
  if l[0] == '1':
    rev = not rev
  else:
    if (l[1] == '1' and not rev) or (l[1] == '2' and rev):
      left.append(l[2])
    else:
      right.append(l[2])
S = ''.join(left[::-1]) + S + ''.join(right)
if rev:
  print(S[::-1])
else:
  print(S)
### BUGGY CODE ###

n, w = map(int, input().split())
dp = [[0 for _ in range(w+1)] for _ in range(n+1)]


for i in range(n):
    wi, vi = map(int, input().split())
    sum_w = 0
    while sum_w <= w:
        if sum_w - wi >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - wi] + vi)
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
        sum_w += 1

print(dp[n][w])

### FIXED CODE ###

n, w = map(int, input().split())
dp = [[0 for _ in range(w+1)] for _ in range(n+1)]


for i in range(n):
    wi, vi = map(int, input().split())
    sum_w = 0
    while sum_w <= w:
        if sum_w - wi >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - wi] + vi)
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
        sum_w += 1

print(dp[n][w])
### BUGGY CODE ###

#!/usr/bin/env python
import math

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

ok = True
for i in range(n):
    for j in range(i+1, n): 
        if 1 != math.gcd(a[i], a[j]):
            ok = False
            break
    if ok == False:
        break

if ok: 
    print('pairwise coprime')
    exit()

ans = math.gcd(a[0],a[1])
for i in range(2, n): 
   ans = math.gcd(ans, a[i])
if ans == 1:
    print('setwise coprime')
    exit()

print('not coprime')

### FIXED CODE ###

#!/usr/bin/env python
import math

n = int(input())
a = list(map(int, input().split()))
m = max(a)
fre = [0 for _ in range(m+1)]

for i in range(n):
    fre[a[i]] += 1

# pairwise coprime
pairwise = True
for i in range(2, len(fre)):
    cnt = 0 
    for j in range(i, m+1, i): 
        cnt += fre[j]
    if cnt > 1:
        pairwise = False
if pairwise:
    print('pairwise coprime')
    exit()

# setwise coprime
ans = math.gcd(a[0],a[1])
for i in range(2, n): 
   ans = math.gcd(ans, a[i])
if ans == 1:
    print('setwise coprime')
    exit()

print('not coprime')
### BUGGY CODE ###

h,w,d=(int(i) for i in input().split())
num=[None for i in range(h*w)]
for i in range(h):
    a=list(map(int,input().split()))
    for j in range(w):
        num[a[j]-1]=(i,j)
numm=[None for i in range(h*w)]
#for i in range(h*w-d):
    #numm[i]=abs(num[i+d-1][0]-num[i-1][0])+abs(num[i+d-1][1]-num[i-1][1])
q=int(input())
for i in range(q):
    l,r=list(map(int,input().split()))
    result=0
    while l!=r:
        if numm[l]==None:
            numm[l]=abs(num[l+d-1][0]-num[l-1][0])+abs(num[l+d-1][1]-num[l-1][1])
        result+=numm[l]
        l+=d
    print(result)

### FIXED CODE ###

h,w,d=(int(i) for i in input().split())
num=[None for i in range(h*w)]
for i in range(h):
    a=list(map(int,input().split()))
    for j in range(w):
        num[a[j]-1]=(i,j)
numm=[None for i in range(h*w)]
for i in range(d):
    numm[i]=0
for i in range(d,h*w):
    numm[i]=numm[i-d]+abs(num[i][0]-num[i-d][0])+abs(num[i][1]-num[i-d][1])

q=int(input())
for i in range(q):
    l,r=list(map(int,input().split()))
    print(numm[r-1]-numm[l-1])
### BUGGY CODE ###

L, R = map(int, input().split())

I = 0
J = 0
now = 0
mod = 2019

for i in range(R-L):
    if(L+i % 2019 == 0):
        mod = 0
        break
    for j in range(R-L-i):
        if (L + i + j + 1 % 2019 == 0):
            mod = 0
            break
        I = L + i
        J = L + i + j + 1
        now = (I * J) % 2019
        if(now < mod):
            mod = now
        if(mod == 0):
            break


print(mod)





### FIXED CODE ###

L, R = map(int, input().split())

I = 0
J = 0
now = 0
mod = 2019

end = 0

for i in range(R-L):
    if(L+i % 2019 == 0 or end == 1):
        mod = 0
        break
    for j in range(R-L-i):
        if (L + i + j + 1 % 2019 == 0):
            mod = 0
            break
        I = L + i
        J = L + i + j + 1
        now = (I * J) % 2019
        if(now < mod):
            mod = now
        if(mod == 0):
            end += 1
            break

print(mod)
### BUGGY CODE ###

import numpy as np
import copy


def main():
    N = int(input())
    ds = list(map(int, input().split()))
    ds = np.array(ds, dtype=np.int)
    ans = 0
    for K in range(int(np.max(ds))+1):
        if np.sum(ds >= K) == N // 2:
            ans += 1
    print(int(ans))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import numpy as np
import copy


def main():
    # N = int(input())
    # ds = list(map(int, input().split()))
    # ds = np.array(ds, dtype=np.int)
    # ans = 0
    # for K in range(int(np.max(ds))+1):
    #     if np.sum(ds >= K) == N // 2:
    #         ans += 1
    # print(int(ans))

    N = int(input())
    ds = list(map(int, input().split()))
    ds = np.array(ds, dtype=np.int)

    ds = np.sort(ds)

    ans = ds[N//2] - ds[N//2-1]
    print(int(ans))


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

from bisect import bisect_left


def main():
    n, m = map(int, input().split())
    arr = list(map(int, input().split()))
    arr.sort()

    bc = [list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda x: x[1], reverse=True)

    for b, c in bc:
        idx = bisect_left(arr, c)

        if idx:
            if b >= idx:
                arr[:idx] = [c] * idx
            else:
                arr[:idx] = arr[b:idx] + [c] * b

    print(sum(arr))


main()

### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    s = 0

    bc = [list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda x: x[1], reverse=True)

    arr = []
    sum_b = 0
    for b, c in bc:
        arr += [c] * b
        sum_b += b
        if sum_b >= n:
            break

    arr += a
    arr.sort(reverse=True)
    print(sum(arr[:n]))


main()
### BUGGY CODE ###

#!/usr/bin/env python3
def solve():
    N, M_a, M_b = [int(x) for x in input().split()]
    inf = 100000
    t = [[inf] * (10 * N + 1) for _ in range(10 * N + 1)]
    t[0][0] = 0
    for _ in range(N):
        ai, bi, ci = [int(x) for x in input().split()]
        for ta in reversed(range(ai, len(t))):
            for tb in reversed(range(bi, len(t[0]))):
                t[ta][tb] = min(t[ta][tb], t[ta - ai][tb - bi] + ci)
    ans = min(
        t[k * M_a][k * M_b]
        for k in range(1, min((len(t) - 1) // M_a, (len(t[0]) - 1) // M_b) + 1)
    )
    print(-1 if ans >= inf else ans)


solve()


### FIXED CODE ###

#!/usr/bin/env python3
def solve():
    N, M_a, M_b = [int(x) for x in input().split()]
    inf = 100000
    t = [[inf] * (10 * N + 1) for _ in range(10 * N + 1)]
    t[0][0] = 0
    for _ in range(N):
        ai, bi, ci = [int(x) for x in input().split()]
        for ta in reversed(range(ai, len(t))):
            for tb in reversed(range(bi, len(t[0]))):
                t[ta][tb] = min(t[ta][tb], t[ta - ai][tb - bi] + ci)
    ans = min(
        t[k * M_a][k * M_b]
        for k in range(1, min((len(t) - 1) // M_a, (len(t[0]) - 1) // M_b) + 1)
    )
    print(-1 if ans >= inf else ans)


solve()
### BUGGY CODE ###

from itertools import product
from collections import deque

H, W = map(int, input().split())
A = []
checked = []
black = []
for i in range(H):
    tmp = input()
    A.append(tmp)
    checked.append([tmp[j] == '#' for j in range(W)])
    black += [((i, j), 0) for j in range(W) if checked[-1][j]]
black = deque(black)
ans = 0
while black:
    (i, j), d = black.popleft()
    ans = max(ans, d)
    if i > 0 and not checked[i-1][j]:
        checked[i-1][j] = True
        black.append(((i-1, j), d+1))
    if i < H-1 and not checked[i+1][j]:
        checked[i+1][j] = True
        black.append(((i+1, j), d+1))
    if j > 0 and not checked[i][j-1]:
        checked[i][j-1] = True
        black.append(((i, j-1), d+1))
    if j < W-1 and not checked[i][j+1]:
        checked[i][j+1] = True
        black.append(((i, j+1), d+1))
print(ans)

### FIXED CODE ###

import numpy as np
from itertools import product
from collections import deque

H, W = map(int, input().split())
val = []
INF = 10**9
for i in range(H):
    tmp = input()
    val.append([0 if tmp[j] == '#' else INF for j in range(W)])
val = np.array(val)

for i in range(H-1):
    val[i+1, :] = np.minimum(val[i, :]+1, val[i+1, :])
for i in range(H-1, 0, -1):
    val[i-1, :] = np.minimum(val[i, :]+1, val[i-1, :])
for j in range(W-1):
    val[:, j+1] = np.minimum(val[:, j]+1, val[:, j+1])
for j in range(W-1, 0, -1):
    val[:, j-1] = np.minimum(val[:, j]+1, val[:, j-1])

print(val.max())
### BUGGY CODE ###

#coding:utf-8
def dbg(*something):
    if DEBUG:
        print(*something)






#正の宝石を戻すことはない
#負の宝石を戻すのは後半

from math import ceil,floor
DEBUG = False
N,K = list(map(int,input().split()))
V = list(map(int,input().split()))


#残りk回のとき深さk以下の場所に正の宝石がない→終了
#i回の操作で取れる石>それまでにとるi-1個の石の和
#深さiにある石vの価値：v - (それまでにとるi-1個の石の和　except (k-i)個の負の石)
'''
'''




def tansaku(left,right,rK,N,score):
    dbg(V[left:right+1],rK,N,score)


    max_v = score + sum(sorted(N)[rK:])


    n = []
    for i in range(left,min(rK+left, ceil((right - left +1)/2)+left)):
        
        if V[i] <= 0:
            n.append(V[i])
            continue

        #next_V = V[i+1:left+lenV]
        next_rK = rK - 1 - (i - left)
        next_tmp_v = tansaku(i+1,right,  next_rK, N+n, score+V[i])
        max_v = max(next_tmp_v , max_v)


        break

    n = []
    for i in range(right ,max(right - ceil((right-left+1)/2)  ,right-rK)  ,-1 ):
        
        if V[i] <= 0:
            n.append(V[i])
            continue

        #next_V = V[:i]
        next_rK = rK - 1 - (right - i)
        #next_tmp_v = tansaku(   left,   i- left -1  ,next_rK,N+n,score+V[i])
        next_tmp_v = tansaku(   left,   i-1  ,next_rK,N+n,score+V[i])
        max_v = max(next_tmp_v , max_v)
        break


    return max_v

print(tansaku(0,len(V)-1,K,[],0))






### FIXED CODE ###

#coding:utf-8



def main():
    
    def dbg(*something):
        if DEBUG:
            print(*something)


    #正の宝石を戻すことはない
    #負の宝石を戻すのは後半
    from sys import stdin
    from math import ceil,floor
    DEBUG = False
    N,K = list(map(int,stdin.readline().split()))
    V = list(map(int,stdin.readline().split()))
    
    max_value = 0
    dbg([i for i in range(3,-1,-1)])
    for getnum in range(1,min(N+1,K+1)):  #取る宝石の総数
        for a in range(getnum + 1):  #左から石を取る回数
            J = [0] * getnum #石
            b = getnum - a #右から石を取る回数
            for i in range(a):
                J[i] = V[i]
            for i in range(b):
                J[a+i] = V[-i-1]
            J.sort()
            #dbg(J,a,b)
            t = min(K-getnum,getnum) #捨てる石
           
            for i in range(t): 
                if J[i] >= 0:
                    t = i
                    break
            #dbg(J,i,t,a,b,J[t:])
            tmp_max = sum(J[t:])

            max_value = max(max_value,tmp_max)
    print(max_value)



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

s = input()
K = int(input())

substrings = []
for i in range(len(s)+1):
    for j in range(len(s)-i+1):
        # print('i={}, i+j={}, s[i:i+j]={}'.format(i, i+j, s[i:i+j]))
        if s[i:i+j] != '':
            substrings.append(s[i:i+j])
substrings = sorted(set(substrings))
print(substrings[K-1])

### FIXED CODE ###

s = input()
K = int(input())

substrings = []
for i in range(len(s)):
    for j in range(len(s)-i+1):
        # print('i={}, i+j={}, s[i:i+j]={}'.format(i, i+j, s[i:i+j]))
        if j <= K and s[i:i+j] != '':
            substrings.append(s[i:i+j])
substrings = sorted(set(substrings))
print(substrings[K-1])
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
num=[0,2,5,5,4,5,6,3,7,6]
dp=[0]
keta=[0]
tmp=0
tmp1=0
tmp_keta=-1
tmp1_keta=-1
for i in range(1,N+1):
    tmp=-1
    tmp_keta=-1
    for j in A:
        tmp1=-1
        tmp1_keta=-1
        if(i-num[j]>=0):
            if(dp[i-num[j]]>0):
                tmp1=dp[i-num[j]]+j*(10**keta[i-num[j]])
                tmp1_keta=keta[i-num[j]]+1
            elif(dp[i-num[j]]==0):
                tmp1=j
                tmp1_keta=1
            if(tmp1>tmp):
                tmp=tmp1
                tmp_keta=tmp1_keta
    dp.append(tmp)
    keta.append(tmp_keta)
ans=dp[N]
print(ans)
    

### FIXED CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
if(1 in A):
    if(4 in A):
        A.remove(4)
    if(9 in A):
        A.remove(9)
    if(6 in A):
        A.remove(6)
if(5 in A):
    if(3 in A):
        A.remove(3)
    if(2 in A):
        A.remove(2)
if(3 in A):
    if(2 in A):
        A.remove(2)
if(9 in A):
    if(6 in A):
        A.remove(6)
if(7 in A):
    if(9 in A):
        A.remove(9)
    if(6 in A):
        A.remove(6)
num=[0,2,5,5,4,5,6,3,7,6]
dp=[0]
keta=[0]
tmp=0
tmp1=0
tmp_keta=-1
tmp1_keta=-1
for i in range(1,N+1):
    tmp=-1
    tmp_keta=-1
    for j in A:
        tmp1=-1
        tmp1_keta=-1
        if(i-num[j]>=0):
            if(dp[i-num[j]]>0):
                tmp1=dp[i-num[j]]+j*(10**keta[i-num[j]])
                tmp1_keta=keta[i-num[j]]+1
            elif(dp[i-num[j]]==0):
                tmp1=j
                tmp1_keta=1

            if(tmp1>tmp):
                tmp=tmp1
                tmp_keta=tmp1_keta
                
    dp.append(tmp)
    keta.append(tmp_keta)
print(dp[N])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict
H, W, N = map(int, input().split())
square = set()
dot = defaultdict(lambda : 0)
for i in range(N):
    a, b = map(lambda x: int(x)-1, input().split())
    dot[(a, b)] = 1
    for y in range(a-2, a+1):
        for x in range(b-2, b+1):
            if 0 <= y < H-2 and 0 <= x < W-2:
                square.add((y, x))
ans = [0] * 10
for y, x in square:
    c = 0
    for i in range(y, y+3):
        for j in range(x, x+3):
            c += dot[(i, j)]
    ans[c] += 1
ans[0] += ans[0] + (H-2) * (W-2) - len(square)
for i in ans:
    print(i)


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict
H, W, N = map(int, input().split())
cnt = defaultdict(lambda : 0)
for i in range(N):
    a, b = map(lambda x: int(x)-1, input().split())
    for y in range(a-2, a+1):
        for x in range(b-2, b+1):
            if 0 <= y < H-2 and 0 <= x < W-2:
                cnt[(y, x)] += 1
ans = [0] * 10
for key in cnt:
    ans[cnt[key]] += 1
ans[0] += ans[0] + (H-2) * (W-2) - len(cnt)
for i in ans:
    print(i)
### BUGGY CODE ###

a, b, c, d = list(map(int, input().split()))

not_need = []

res = 0
for x in range(a, b+1):
    if x%c:
        if x%d:
            res += 1
    else:
        continue

print(res)

### FIXED CODE ###

def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x

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

a, b, c, d = map(int, input().split())
cd = lcm(c, d)

print(
    b - (b//c) - (b//d) + (b//cd) \
    -((a-1) - ((a-1)//c) - ((a-1)//d) + ((a-1)//cd))
    )
### BUGGY CODE ###

import math
a,b,c=map(int,input().split())
d=[]
for i in range(0,c+1):
    e=math.floor(a*i/b)-a*math.floor(i/b)
    d.append(e)
print(max(d))


### FIXED CODE ###

import math
a,b,c=map(int,input().split())
if b>c:
    print(math.floor((a*c)/b)-a*(math.floor(c/b)))
else:
    print(math.floor((a*(b-1))/b)-a*(math.floor((b-1)/b)))