Codeforces Round 452 (Div. 2)
D
Shovel Sale
Codeforces
1800
原题
← CE →
翻译中…

There are $*n*$ shovels in Polycarp's shop. The $*i*$-th shovel costs $*i*$ burles, that is, the first shovel costs $1$ burle, the second shovel costs $2$ burles, the third shovel costs $3$ burles, and so on. Polycarps wants to sell shovels in pairs.

翻译中…

Visitors are more likely to buy a pair of shovels if their total cost ends with several $9$s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs $12345$ and $37454$, their total cost is $49799$, it ends with two nines.

翻译中…

You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other.

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ ($2 ≤ *n* ≤ 10^{9}$) — the number of shovels in Polycarp's shop.

翻译中…

Output

翻译中…

Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines.

翻译中…

Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways.

翻译中…

It is guaranteed that for every $*n* ≤ 10^{9}$ the answer doesn't exceed $2·10^{9}$.

翻译中…

Note

翻译中…

In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose:

翻译中…
  • $2$ and $7$;
  • $3$ and $6$;
  • $4$ and $5$.
翻译中…

In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp:

翻译中…
  • $1$ and $8$;
  • $2$ and $7$;
  • $3$ and $6$;
  • $4$ and $5$;
  • $5$ and $14$;
  • $6$ and $13$;
  • $7$ and $12$;
  • $8$ and $11$;
  • $9$ and $10$.
翻译中…

In the third example it is necessary to choose shovels $49$ and $50$, because the sum of their cost is $99$, that means that the total number of nines is equal to two, which is maximum possible for $*n* = 50$.

翻译中…

样例

Input #1
7
Output #1
3
InputCopy OutputCopy
Input #2
14
Output #2
9
InputCopy OutputCopy
Input #3
50
Output #3
1
InputCopy OutputCopy
题目信息
题号
899D
时间限制
1 s
内存限制
256 MB
标签
构造
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。