Time Limit:1000ms Memory Limit:65536KB

Description

Given a non-negative number, if we delete some digitals of the number and rearrange the
left numbers and obtain 1957, we call it 1957 Number.
You are expected to calculate the number of 1957 Number no more than X, where X is
given.

Input

Mutuple test cases.
A non-negative number X (0<=X<10^9) in each line.

Output

For each test case, output the answer in a single line.

Sample Input

1957

Sample Output

5

Hint

Huge input, C-style IO functioin(scanf & printf) recommended.

Author

baihacker

Source