#P1662. 数7

数7

Description

There are 13371337 people standing in a circle. Starting from person 11, they count numbers; the initial direction is 1,2,31,2,3\dots. If the number someone says is a multiple of 77 or contains the digit 77, then the counting direction flips. Which numbered person says number XX?

For example, for the first 2020 numbers:

Number XX Index of the person who says it
11
22
33
44
55
66
77
88 66
99 55
1010 44
1111 33
1212 22
1313 11
1414 13371337
1515 11
1616 22
1717 33
1818 22
1919 11
2020 13371337

Input Format

One line containing an integer XX.

Output Format

One line containing an integer, the index of the person who says number XX.

1000
1311

Hint

Constraints

For 30%30\% of the testdata, X106X\leq10^6.

For 90%90\% of the testdata, X108X\leq10^8.

For 100%100\% of the testdata, X109X\leq10^9.

Translated by ChatGPT 5