Python 3.13.2 (tags/v3.13.2:4f8bb39, Feb  4 2025, 15:23:48) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import sys
... 
... sys.set_int_max_str_digits(20000)
... 
... def count_magic(n):
...     c7 = n // 7
...     c_ends7 = (n - 7) // 10 + 1 if n >= 7 else 0
...     c_both = (n - 7) // 70 + 1 if n >= 7 else 0
...     return c7 + c_ends7 - c_both
... 
... def solve():
...     try:
...         line = sys.stdin.readline()
...         if not line:
...             return
...         k = int(line)
...     except EOFError:
...         return
...     except ValueError:
...         return
... 
...     if k <= 0:
...         print(0)
...         return
... 
...     left, right = 1, 5 * k + 100
...     
...     while left < right:
...         mid = (left + right) // 2
...         if count_magic(mid) >= k:
...             right = mid
...         else:
...             left = mid + 1
...             
...     print(left)
... 
... solve()
