output_description: Print an integer representing the position of the first occurrence of a
  multiple of K. (For example, if the first occurrence is the fourth element of
  the sequence, print `4`.)
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      K
attempt: #!/usr/bin/env python3
  import sys
  
  
  def main():
      input = sys.stdin.readline
      k = int(input())
      if (
          k % 10 == 2
          or k % 10 == 4
          or k % 10 == 5
          or k % 10 == 6
          or k % 10 == 8
          or k % 10 == 0
      ):
          print(-1)
          exit()
      elif k % 10 == 1:
          tmp = k * 7
          ans = 1
          while True:
              if str(tmp).count("7") == len(str(tmp)):
                  print(ans + len(str(tmp)) - 1)
                  break
              if tmp // 10 % 10 <= 7:
                  num = 7 - tmp // 10 % 10
              else:
                  num = tmp // 10 % 10 - 7
              tmp2 = k * num
              tmp = tmp // 10 + tmp2
              ans += 1
              if ans > 10**8:
                  print(-1)
                  break
      elif k % 10 == 3:
          tmp = k * 9
          ans = 1
          while True:
              if str(tmp).count("7") == len(str(tmp)):
                  print(ans + len(str(tmp)) - 1)
                  break
              num = ((tmp // 10 % 10) * 3 - 1) % 10
              tmp2 = k * num
              tmp = tmp // 10 + tmp2
              ans += 1
              if ans > 5 * 10**7:
                  print(-1)
                  break
      elif k % 10 == 7:
          tmp = k * 1
          ans = 1
          while True:
              if str(tmp).count("7") == len(str(tmp)):
                  print(ans + len(str(tmp)) - 1)
                  break
              num = ((tmp // 10 % 10) * 7 + 1) % 10
              tmp2 = k * num
              tmp = tmp // 10 + tmp2
              ans += 1
              if ans > 10**8:
                  print(-1)
                  break
      elif k % 10 == 9:
          tmp = k * 3
          ans = 1
          while True:
              if str(tmp).count("7") == len(str(tmp)):
                  print(ans + len(str(tmp)) - 1)
                  break
              num = ((tmp // 10 % 10) + 3) % 10
              tmp2 = k * num
              ans += 1
              if ans > 10**8:
                  print(-1)
                  break
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  Takahashi loves the number 7 and multiples of K.
  
  Where is the first occurrence of a multiple of K in the sequence
  7,77,777,\ldots? (Also see Output and Sample Input/Output below.)
  
  If the sequence contains no multiples of K, print `-1` instead.
samples: [{"input": "101", "output": "4\n    \n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\n* * *"}, {"input": "2", "output": "-1\n    \n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\n* * *"}, {"input": "999983", "output": "999982"}]