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

from heapq import heappop, heappush

inf = float('inf')

n = int(input())
a = tuple(int(input()) for _ in range(n))

h = [inf]

cnt = 0
for aa in a:
    if aa <= h[0]:
        heappush(h, aa)
        cnt += 1
    else:
        s = []
        while True:
            v = heappop(h)
            if aa <= h[0]:
                heappush(h, aa)
                for ss in s:
                    heappush(h, ss)
                break
            else:
                s.append(v)
print(cnt)


### FIXED CODE ###

from bisect import bisect_left
from collections import deque

n = int(input())
a = tuple(int(input()) for _ in range(n))

d = deque()

for ai in a:
    p = bisect_left(d, ai)  # aa以上の最小値のindex
    if p == 0:
        d.appendleft(ai)
    else:
        d[p - 1] = ai
ans = len(d)
print(ans)
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
s = ['#'*(w+4)]*2 + ['#'*2 + input() + '#'*2 for _ in range(h)] + ['#'*(w+4)]*2

c = [i-1+2 for i in c]
d = [i-1+2 for i in d]

t0 = [(0, 1), (0, -1), (1, 0), (-1, 0)]
t1 = []
for i in range(-2, 3):
    for j in range(-2, 3):
        t1.append((i, j))
for i in t0:
    t1.remove(i)
t1.remove((0, 0))

check = [[-1]*(w+4) for _ in range(h+4)]
q = deque()
q.appendleft((c[0], c[1], 0))

while q:
    y, x, b = q.pop()
    if y == d[0] and x == d[1]:
        print(b)
        exit()
    if check[y][x] == -1:
        check[y][x] = b
        for dy, dx in t0:
            ydy, xdx = y+dy, x+dx
            if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                q.append((ydy, xdx, b))
        for dy, dx in t1:
            ydy, xdx = y+dy, x+dx
            if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                q.appendleft((ydy, xdx, b+1))
print(-1)


### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
s = [list(input()) for _ in range(h)]

c = [i-1 for i in c]
d = [i-1 for i in d]

t0 = [(0, 1), (0, -1), (1, 0), (-1, 0)]
t1 = []
for i in range(-2, 3):
    for j in range(-2, 3):
        t1.append((i, j))
for i in t0:
    t1.remove(i)
t1.remove((0, 0))

check = [[-1]*w for _ in range(h)]
q = deque()
q.appendleft((c[0], c[1], 0))

while q:
    y, x, b = q.pop()
    if x == d[1] and y == d[0]:
        print(b)
        exit()
    if check[y][x] == -1:
        check[y][x] = b
        for dy, dx in t0:
            ydy, xdx = y+dy, x+dx
            if (0 <= xdx < w) and (0 <= ydy < h):
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.append((ydy, xdx, b))
        for dy, dx in t1:
            ydy, xdx = y+dy, x+dx
            if (0 <= xdx < w) and (0 <= ydy < h):
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.appendleft((ydy, xdx, b+1))
print(-1)
### BUGGY CODE ###

import numpy as np
def solve(n, x, y):
    def dist(i, j):
        return min(abs(x[i]-x[j]), abs(y[i]-y[j]))
    que = []
    for v in [x, y]:
        p = np.argsort(v)
        for i in range(n-1):
            u, v = p[i], p[i+1]
            que.append((u, v, dist(u, v)))
    parent = {i: i for i in range(n)}
    def find(i):
        if parent[i] == i:
            return i
        else:
            return find(parent[i])
    que = list(sorted(que, key=lambda _: _[2]))
    ans = 0
    while que != []:
        u, v, d = que.pop(0)
        u = find(u)
        v = find(v)
        if u != v:
            ans += d
            if u > v:
                u, v = v, u
            parent[u] = v
    return ans

n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())
print(solve(n, x, y))

### FIXED CODE ###

import numpy as np

def solve(n, x, y):
    def dist(i, j):
        return min(abs(x[i]-x[j]), abs(y[i]-y[j]))
    que = []
    for p in map(np.argsort, [x, y]):
        for i in range(n-1):
            u, v = p[i], p[i+1]
            que.append((u, v, dist(u, v)))
    parent = [i for i in range(n)]
    def find(i):
        if parent[i] == i:
            return i
        else:
            j = find(parent[i])
            parent[i] = j
            return j
    ans = 0
    for u, v, d in sorted(que, key=lambda _: _[2]):
        u = find(u)
        v = find(v)
        if u != v:
            ans += d
            if u > v:
                u, v = v, u
            parent[v] = u
    return ans

n = int(input())
x = np.zeros(n, dtype=int)
y = np.zeros(n, dtype=int)
for i in range(n):
    x[i], y[i] = map(int, input().split())
print(solve(n, x, y))
### BUGGY CODE ###


n = int(input())

s = list(input())
b = 0
w = 0

for i in range(n-1):
  if s[i] == "#" and s[i+1] == ".":
    b = max(b, s[:i+1].count("#"))
    w = max(w, s[i+1:].count("."))

print(min(b,w))
   

### FIXED CODE ###

N = int(input())
S = input()

cum_lw = [0] * N
cum_rw = [0] * N

if S[0] == ".":
    cum_lw[0] = 1

if S[-1] == ".":
    cum_rw[-1] = 1 

for i in range(1,N):
    if S[i] == ".":
        cum_lw[i] = cum_lw[i-1] + 1
    else:
        cum_lw[i] = cum_lw[i-1]

    if S[N-1-i] == ".":
        cum_rw[N-1-i] = cum_rw[N-i] + 1
    else:
         cum_rw[N-1-i] = cum_rw[N-i]

ans = N
for i in range(N):
    if i != N-1:
        bb = cum_lw[i] + cum_rw[i+1]
        wb = (i+1)-cum_lw[i] + cum_rw[i+1]
        ww = (i+1)-cum_lw[i] + (N-1-i)-cum_rw[i+1]
    else:
        bb = cum_lw[i]
        wb = (i+1)-cum_lw[i]
        ww = (i+1)-cum_lw[i]
    ans = min([ans, bb, wb, ww])

print(ans)
### BUGGY CODE ###

from collections import defaultdict

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

row_dict = defaultdict(int)
col_dict = defaultdict(int)
row_col_dict = defaultdict(list)
for _ in range(m):
    row, col = map(int, input().split())
    row_dict[row] += 1
    col_dict[col] += 1
    row_col_dict[row].append(col)

max_row = max(row_dict.values())
max_col = max(col_dict.values())

max_rows = [k for k, v in row_dict.items() if v == max_row]
max_cols = [k for k, v in col_dict.items() if v == max_col]
ans = max_row + max_col - 1
flg = False
if ans < m:
    for row in max_rows:
        for col in max_cols:
            if not col in row_col_dict[row]:
                ans += 1
                flg = True
                break
        if flg:
            break

print(ans)


### FIXED CODE ###

from collections import defaultdict

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

row_dict = defaultdict(int)
col_dict = defaultdict(int)
row_col_dict = defaultdict(set)
for _ in range(m):
    row, col = map(int, input().split())
    row_dict[row] += 1
    col_dict[col] += 1
    row_col_dict[row].add(col)

max_row = max(row_dict.values())
max_col = max(col_dict.values())

max_rows = [k for k, v in row_dict.items() if v == max_row]
max_cols = [k for k, v in col_dict.items() if v == max_col]
ans = max_row + max_col - 1
flg = False
if ans < m:
    for row in max_rows:
        for col in max_cols:
            if not col in row_col_dict[row]:
                ans += 1
                flg = True
                break
        if flg:
            break

print(ans)
### BUGGY CODE ###

k, s = map(int, input().split())
ans = 0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i+j+l == s:
                ans += 1
print(ans)

### FIXED CODE ###

k, s = map(int, input().split())
ans = 0
for i in range(k+1):
    for j in range(k+1):
        if s <= i+j+k and i+j <= s:
            ans += 1
print(ans)
### BUGGY CODE ###


s=input().rstrip()
q=int(input().rstrip())
ans=s
rev=0
for _ in range(q):
    que,*C=input().split()
    que=int(que)
    if que==2:
        f,c=C
        f=int(f)
        if f==1:
            if rev%2==0:
                s=c+s
            else:
                s+=c
        else:
            if rev%2==0:
                s+=c
            else:
                s=c+s
    else:
        rev+=1
print(s if rev%2==0 else s[::-1])

### FIXED CODE ###

#import pysnooper
#import numpy
#import os,re,sys,operator
from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline

s=input().rstrip()
q=int(input().rstrip())
qu=deque(s)
rev=0
for _ in range(q):
    que,*C=input().split()
    que=int(que)
    if que==2:
        f,c=C
        f=int(f)
        if f==1:
            if rev%2==0:
                qu.appendleft(c)
            else:
                qu.append(c)
        else:
            if rev%2==0:
                qu.append(c)
            else:
                qu.appendleft(c)
    else:
        rev+=1
print("".join(qu) if rev%2==0 else "".join(qu)[::-1])
### BUGGY CODE ###

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

ans = 0
for i in range(n):
    plus = 0
    for j in range(i, n):
        if i == j:
            continue
        plus += a[j]
    ans += a[i]*plus 
    ans %= MOD
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
ans = 0
plus = 0
for i in range(n-1):
    plus += a[n-i-1]
    plus %= MOD
    ans += a[n-i-2]*plus
    ans %= MOD
print(ans%MOD)
### BUGGY CODE ###

import math

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

count = 0
a.sort()
a.reverse()

while(a!=[]):
    temp = a[0]
    a.pop(0)
    b=2**math.floor(math.log2(temp))
    if a ==[]:
        break
    if 2*b-temp in a:
        count += 1
        a.pop(a.index(2*b-temp))
    
    


print(count)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
b = {}
for i in range(len(a)):
    if a[i] in b:
        b[a[i]] += 1
    else:
        b[a[i]] = 1
twins = []
now = 1
while now <= a[-1]:
    now *= 2
    twins.append(now)
for i in range(len(a) - 1, -1, -1):
    tmpa = 0
    if  b[a[i]] == 0:
        continue
    for j in range(len(twins) - 1, -1, -1):
        if twins[j] <= a[i]:
            break
        tmpa = twins[j] - a[i]
    if tmpa == a[i]:
        if b[tmpa] >= 2:
            b[tmpa] -= 2
    elif tmpa in b and b[tmpa] != 0:
        b[tmpa] -= 1
        b[a[i]] -= 1
countb = 0
for i in b:
    countb += b[i]
print((n - countb) // 2)
### BUGGY CODE ###

def solve():
  s = input()
  n  = len(s)
  mod = 10**9+7
  reverses = s[::-1]
  
  query = [0 for i in range(13)]
  if reverses[0] != "?":
    tmp = int(reverses[0])
    query = [0 for i in range(13)]
    query[tmp] += 1
  else:
    for i in range(10):
      query[i] += 1
  digit = 1
  
  for i in range(1,n):
    digit *= 10
    digit %= 13
    tmp = [0 for _ in range(13)]
    
    if reverses[i] =="?":
      for k in range(10):
        for j in range(13):
          num = k*digit
          num += j
          num %= 13
          tmp[num] += query[j]
      
    else:
      for j in range(13):
        num = digit*int(reverses[i])
        num += j
        num %= 13
        tmp[num] += query[j]

    for i in range(13):
      tmp[i] %= mod
    query = tmp 
      
  print(query[5])
solve()

### FIXED CODE ###

def solve():
  s = input()
  n  = len(s)
  mod = 10**9+7
  reverses = s[::-1]
  
  query = [0 for i in range(13)]
  if reverses[0] != "?":
    tmp = int(reverses[0])
    query = [0 for i in range(13)]
    query[tmp] += 1
  else:
    for i in range(10):
      query[i] += 1
  digit = 1
  
  for i in range(1,n):
    digit *= 10
    digit %= 13
    tmp = [0 for _ in range(13)]
    
    if reverses[i] =="?":
      for k in range(10):
        for j in range(13):
          num = k*digit
          num += j
          num %= 13
          tmp[num] += query[j]
      
    else:
      for j in range(13):
        num = digit*int(reverses[i])
        num += j
        num %= 13
        tmp[num] += query[j]

    for i in range(13):
      tmp[i] %= mod
    query = tmp 
      
  print(query[5])
solve()
### BUGGY CODE ###

# coding: utf-8
import sys
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
dic = defaultdict(int)
dic[0] = 1
power = 1
remain = 0
answer = 0
for i in range(len(S)-1, -1, -1):
    remain += int(S[i]) * power
    remain %= 2019
    power *= 10
    answer += dic[remain]
    dic[remain] += 1

print(answer)


### FIXED CODE ###

# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
mod_cnt = [0] * 2019
mod_cnt[0] = 1
power = 1
remain = 0
answer = 0
for i in range(len(S)-1, -1, -1):
    remain += int(S[i]) * power
    remain %= 2019
    power *= 10; power %= 2019
    answer += mod_cnt[remain]
    mod_cnt[remain] += 1

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

if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
    if n <= k+1:
        print(abs(hs[0]-hs[-1]))
        exit()
    ans_list = [0]*n
    for i in range(1,k+1):
        ans_list[-i] = abs(hs[-1] - hs[-i])
    for i in range(k+1,n+1):
        ans_list[-i] = min([abs(hs[-i]-hs[-i+x])+ans_list[-i+x] for x in range(1,k+1)])
    print(ans_list[0])


### FIXED CODE ###

if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
    if n <= k+1:
        print(abs(hs[0]-hs[-1]))
        exit()
    ans_list = [0]*n
    last_hs = hs[-1]
    for i in range(1,k+2):
        ans_list[-i] = abs(last_hs - hs[-i])
    for i in range(k+2,n+1):
        hs_i = hs[-i]
        ans_list[-i] = min([abs(hs_i-x)+y for x,y in zip(hs[1-i:k+1-i],ans_list[1-i:k+1-i])])
    print(ans_list[0])
### BUGGY CODE ###

import bisect
N,D,A=map(int,input().split())
XH=[list(map(int,input().split())) for _ in range(N)]
XH.sort()
for i in range(N):
    XH[i][1]=-(-XH[i][1]//A)
X=[x for x,a in XH]
far=[0]*N
for i in range(N):
    far[i]=bisect.bisect_right(X,X[i]+2*D)-1

ans=0
for i in range(N):
    x=XH[i][0]
    hp=XH[i][1]
    if hp<=0:
        continue
    for j in range(i,far[i]+1):
        XH[j][1]-=hp
    ans+=hp
print(ans)

### FIXED CODE ###

import bisect
def main():
    N,D,A=map(int,input().split())
    XH=[list(map(int,input().split())) for _ in range(N)]
    XH.sort()
    for i in range(N):
        XH[i][1]=-(-XH[i][1]//A)
    X=[x for x,a in XH]
    far=[0]*N
    for i in range(N):
        far[i]=bisect.bisect_right(X,X[i]+2*D)-1

    ans=0
    carry=0
    outrange=[0]*(N+1)
    for i in range(N):
        x=XH[i][0]
        hp=XH[i][1]
        carry-=outrange[i]
        if carry>=hp:
            continue
        outrange[bisect.bisect_right(X,X[i]+2*D)]+=hp-carry
        ans+=hp-carry
        carry+=hp-carry
    print(ans)

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

# input here
_INPUT = """\
10 2
4
5
"""
"""
K = int(input())
H, W, K = map(int, input().split())
a = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(N)]
p = tuple(map(int,input().split()))
"""
def main():
    N, M = map(int, input().split())
    a = [int(input()) for i in range(M)]

    #動的計画法問題
    dp = [0] * (N+1)
    dp[0] = 1
    if 1 not in a:
        dp[1] = 1

    for i in range(2,N+1):
        if (i-1 in a)&(i-2 in a):
            print(0)
            quit()

        if i-1 in a:
            dp[i] = dp[i-2]
        elif i-2 in a:
            dp[i] = dp[i-1]
        else:
            dp[i] = dp[i-1] + dp[i-2]

    print(dp[N]%(10**9+7)) 




            
if __name__ == '__main__':
    import io
    import sys
    import math
    import itertools
    from collections import deque

    # sys.stdin = io.StringIO(_INPUT)
    main()

### FIXED CODE ###

N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])
### BUGGY CODE ###

# encoding: "utf-8"

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def first_count_and_pop(xs):
    cnt = 0
    fst = xs[0]
    cnt = xs.count(fst)
    # for x in xs:
    #     if x != fst:
    #         break
    #     cnt += 1
    return (cnt, xs[cnt:])    
    

def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort()
    ys = dict()
    while xs:
        key = xs[0]
        cnt, xs = first_count_and_pop(xs)
        ys[key] = cnt
    # zs = sorted(list(ys.items()), key=(lambda x: x[1]), reverse=True)
    m = 0
    for i in range(0, 100002):
        temp = ys.get(i-1, 0) + ys.get(i, 0) + ys.get(i+1, 0)
        if m < temp:
            m = temp
    print(m)

if __name__ == "__main__":
    main()

### FIXED CODE ###

input()
a_list = [int(s) for s in input().split()]

count = [0]*100002

for a in a_list:
    count[a] += 1
    count[a+1] += 1
    count[a+2] += 1
    
print(max(count))
### BUGGY CODE ###

from collections import deque


H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]

INF = 10 ** 12
path = [[INF] * W for _ in range(H)]  # path: 各マスへの移動コスト

# walk:移動A, warp:移動B
walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

q = deque()
path[Ch][Cw] = 0
q.append((Ch, Cw, 0))

while q:
    x, y, s = q.popleft()
    for dx, dy in walk:  # 移動A
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s:
            path[nx][ny] = s
            q.appendleft((nx, ny, s))  # 移動Aの場合はコスト0. キューの先頭に追加する.
    for dx, dy in warp:  # 移動B
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s + 1:
            path[nx][ny] = s + 1
            q.append((nx, ny, s + 1))  # 移動Bの場合はコスト1. キューの最後尾に追加する.
    
ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
print(ans)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
maze = [input() for i in range(H)]

queue = deque()
queue.append((Ch-1, Cw-1, 0))
inf = float("inf")
table = [[inf] * W for i in range(H)]
table[Ch-1][Cw-1] = 0
walk_move = ((-1, 0), (0, -1), (1, 0), (0, 1))
magic_move = []
for i in range(-2, 3):
  for j in range(-2, 3):
    if not i and not j:
      continue
    else:
      magic_move.append([i, j])

while queue:
  x, y, cost = queue.popleft()
  for i,j in walk_move:
    dx = x+i
    dy = y+j
    if 0 <= dx <= H-1 and 0 <= dy <= W-1 and maze[dx][dy] == "." and table[dx][dy] > cost:
      queue.appendleft((dx, dy, cost))
      table[dx][dy] = cost
  for k,l in magic_move:
    dx = x+k
    dy = y+l
    if 0 <= dx <= H-1 and 0 <= dy <= W-1 and maze[dx][dy] == "." and table[dx][dy] > cost+1:
      queue.append((dx, dy, cost+1))
      table[dx][dy] = cost+1

ans = table[Dh-1][Dw-1]
if ans == inf:
  print("-1")
else:
  print(table[Dh-1][Dw-1])
### BUGGY CODE ###

h,w,d = map(int,raw_input().split(" "))

mp = []

for a in range(h):
  mp += map(int,raw_input().split(" "))

data = [-1] * (h*w + 1)

for a in range(d+1,h*w+1):
  l = mp.index(a-d)
  r = mp.index(a)
  x = abs((r/w) - (l/w))
  y = abs((r%w) - (l%w))
  data[a] = x+y

q = int(raw_input())

for a in range(q):
  l,r = map(int,raw_input().split(" "))
  ans = 0
  for b in range(l+d,r+1,d):
    ans += data[b]
  print ans


### FIXED CODE ###

h,w,d = map(int,raw_input().split(" "))

mp = {}
now = 0

for a in range(h):
  z = map(int,raw_input().split(" "))
  for zz in z:
    mp[zz] = now
    now += 1

data = [-1] * (h*w + 1)
data2 = [-1] * (h*w + 1)

for a in range(d+1,h*w+1):
  l = mp[a-d]
  r = mp[a]
  x = abs((r/w) - (l/w))
  y = abs((r%w) - (l%w))
  data[a] = x+y
  if a - d <= 0:
    continue
  data2[a] = data2[a-d] + data[a]

q = int(raw_input())

for a in range(q):
  l,r = map(int,raw_input().split(" "))
  print data2[r] - data2[l]
### BUGGY CODE ###

N = input()

flag = 0
res = 0
while len(N) > 0:
	n = int(N[len(N)-1])

	if flag == 2:
		if n <= 4:
			flag = 0
			res += n
		elif n == 5:
			flag = 1
			res += 4
		elif n >= 6:
			flag = 1
			res += 9 - n
	else:
		if flag == 1:
			n += 1
		if n == 5:
			flag = 2
			res += 5
		elif n > 5:
			flag = 1
			res += 10 - n
		else:
			flag = 0
			res += n
		
	N = N[:len(N)-1]

if flag == 1:
	print(res + 1)
else:
	print(res)

### FIXED CODE ###

N = input()

nagasa = len(N)
flag = 0
res = 0
for i in range(nagasa):
	s = nagasa - i - 1
	n = int(N[s])

	if flag == 2:
		if n <= 4:
			flag = 0
			res += n
		elif n == 5:
			flag = 1
			res += 4
		elif n >= 6:
			flag = 1
			res += 9 - n
	else:
		if flag == 1:
			n += 1
		if n == 5:
			flag = 2
			res += 5
		elif n > 5:
			flag = 1
			res += 10 - n
		else:
			flag = 0
			res += n

if flag == 1:
	print(res + 1)
else:
	print(res)
### BUGGY CODE ###

INF = float('inf')

def warshall_floyd(d,n):
    max_d = 0
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if(i==j or j==k or i==k):continue
                if(d[i][j]!=INF):
                    max_d = max(max_d,d[i][j])
                if(d[i][j]>=d[i][k] + d[k][j]):
                    d[i][j] = INF
                    d[j][i] = INF
    return max_d

N = int(input())
gp = [[int(x) for x in input().split()]for _ in range(N)]
max_d = warshall_floyd(gp,N)
ans = 0
for d in gp:
    ans += sum([i if i!=INF else 0 for i in d])
print(ans//2 if ans//2 >= max_d else -1)


### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
    INF = float('inf')
    N = int(input())
    d = [[int(x) for x in input().split()]for _ in range(N)]
    ans = 0
    flag = True
    for i in d:
        ans += sum(i)
    ans //= 2
    max_d = 0
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if(i==j or j==k or i==k or d[i][j]==INF):continue
                max_d = max(max_d,d[i][j])
                if(d[i][j]==d[i][k] + d[k][j]):
                    ans -= d[i][j]
                    d[i][j] = INF
                    d[j][i] = INF
                elif(d[i][j]>d[i][k] + d[k][j]):
                    flag = False
    print(ans if (ans >= max_d)and flag else -1)

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

n = int(input())
A = [int(item) for item in input().split()]
B = [int(item) for item in input().split()]
 
dp = [0] * (n+1)
AB = tuple(zip(A, B))
for i in range(n+1):
    for a, b in AB:
        if i - a >= 0:
            dp[i] = max(dp[i], dp[i-a] + b - a)
n += dp[n]
dp = [0] * (n+1)
BA = tuple(zip(B, A))
for i in range(n+1):
    for b, a in BA:
        if i - b >= 0:
            dp[i] = max(dp[i], dp[i-b] + a - b)
print(n + dp[n])

### FIXED CODE ###

n = int(input())
A = [int(item) for item in input().split()]
B = [int(item) for item in input().split()]
 
dp = [0] * (n+1)
AB = [] 
for a, b in zip(A, B):
    if b > a:
        AB.append((a, b))
for i in range(n+1):
    for a, b in AB:
        if i - a >= 0:
            y = dp[i-a] + b - a
            if y > dp[i]:
                dp[i] = y
n += dp[n]
dp = [0] * (n+1)
BA = []
for b, a in zip(B, A):
    if a > b:
        BA.append((b, a))
for i in range(n+1):
    for b, a in BA:
        if i - b >= 0:
            y = dp[i-b] + a - b
            if y > dp[i]:
                dp[i] = y 
print(n + dp[n])