P1662 Counting 7

Description

There are $1337$ people standing in a circle. Starting from person $1$, they count numbers; the initial direction is $1,2,3\dots$. If the number someone says is a multiple of $7$ or contains the digit $7$, then the counting direction flips. Which numbered person says number $X$? **For example, for the first $20$ numbers:** | Number $X$ | Index of the person who says it | | :----------: | :----------: | | $1$ | $1$ | | $2$ | $2$ | | $3$ | $3$ | | $4$ | $4$ | | $5$ | $5$ | | $6$ | $6$ | | $7$ | $7$ | | $8$ | $6$ | | $9$ | $5$ | | $10$ | $4$ | | $11$ | $3$ | | $12$ | $2$ | | $13$ | $1$ | | $14$ | $1337$ | | $15$ | $1$ | | $16$ | $2$ | | $17$ | $3$ | | $18$ | $2$ | | $19$ | $1$ | | $20$ | $1337$ |

Input Format

One line containing an integer $X$.

Output Format

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

Explanation/Hint

**Constraints** For $30\%$ of the testdata, $X\leq10^6$. For $90\%$ of the testdata, $X\leq10^8$. For $100\%$ of the testdata, $X\leq10^9$. Translated by ChatGPT 5