Under construction

Still being built. Things may change

Fruitful cooperation

Interview

Time limit1sMemory limit1024 MB

Summary
Given N up to 10^16, count the closed regions formed in the digits when all numbers from 1 to N are written in a row.
Level

Medium5 of 10

Topics
Dynamic programming, Math
Solved
No attempts yet

Statement

This university has an odd atmosphere. Instead of helping each other and enjoying a sweet life, students constantly argue, put sticks in each other's wheels, and refuse to cooperate.

But Misha and Volodya are different. During a lecture on an incredibly interesting subject, Misha wrote all numbers from 1 to NN in a row. He wrote each digit carefully, as shown in the picture:

Closed regions formed in his notebook right away. For example, if N=6N = 6, one closed region formed inside the digit 6. Volodya decided to help his friend pass the time by coloring every closed region. He wondered whether he could color all of them before the lecture ends. How many regions must he color?

Input

You are given one natural number NN (1≤N≤10161 \leq N \leq 10^{16}).

Output

Print one number: the number of regions Volodya must color.

Examples1

  1. Example 1

    Input
    10
    
    Expected output
    5