NKDIST - Distance

Consider a sequence D consisting of an infinite number of hexadecimal digits made by concatenating all the positive integers 1, 2, 3, 4,..., N,...

The sequence D begins with:

123456789ABCDEF101112131415161718191A1B1C1D1E1F202122...

We may see D as an infinite string of hexadecimal digits. Let S be an arbitrary string consisting only of hexadecimal digits. The number of occurrences of S in D as a substring is infinite. The distance between two nonoverlapping occurrence of S is the number of digits between these two occurrences. For instance, if S='21', the distance between the first two occurrences of S is 27 (as illustrated above).

Task

You are given a string S of at most 30 characters long. Write a program that determines the distance between the first two occurrences of S in D.

Input

The input contains the string S in a single line.

Output

The output contains the distance between the first two occurrences of S in D in a single line.

Example

Input
21
Output
27

Input
A
Output
26

Được gửi lên bởi:Jimmy
Ngày:2008-01-17
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:ADA95 ASM32 BASH BF C CSHARP CPP C99 CLPS LISP sbcl LISP clisp D FORTRAN HASK ICON ICK JAVA LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCM guile SCM qobi ST WHITESPACE
Nguồn bài:Vietnamese Olympiad in Informatics 2003

hide comments
2018-08-15 19:06:37
KHÓ quá!!!!
2015-04-29 16:22:36 Nghia
Mình nghĩ bài này t tìm quy luật r làm một phép chia chứ không phải xây dựng dãy r tìm đâu.
2012-11-26 04:56:58 Một Bạn Trai Giấu Tên
bài này khó quá, 1234 ra nhanh, 12345 ra lâu, 123456 rất lâu @@
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.