output_description: Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
attempt: n = input()
  ans = 0
  n_len = len(n)
  a = [0]
  for i in range(1, n_len):
      a_i = 3 * (a[i - 1] + 2 ** (i) - 2)
      a.append(a_i)
  buf = 1
  check = [0] * 3
  for i in range(n_len - 3):
      a_sum = sum(a[: n_len - i - 1])
      n_i = int(n[i])
      if n_i <= 2:
          ans = a_sum
          buf = 0
          break
      elif n_i == 3:
          ans += a_sum
          if check[0] == 0:
              check[0] = 1
      elif n_i == 4:
          ans += a_sum + a[n_len - i - 1] // 3
          buf = 0
          break
      elif n_i == 5:
          ans += a_sum + a[n_len - i - 1] // 3
          if check[1] == 0:
              check[1] = 1
      elif n_i == 6:
          ans += a_sum + 2 * (a[n_len - i - 1] // 3)
          buf = 0
          break
      elif n_i == 7:
          ans += a_sum + 2 * (a[n_len - i - 1] // 3)
          if check[2] == 0:
              check[2] = 1
      elif n_i > 7:
          ans += a_sum + a[n_len - i - 1]
          buf = 0
          break
  if buf == 0:
      print(ans)
  else:
      n_3 = int(n[-3:])
      check0 = [0] * 3
      for i in range(333, n_3 + 1):
          for j in range(3):
              check0[j] = check[j]
          i_s = str(i)
          buf = 0
          for j in range(3):
              if i_s[j] == "3":
                  check0[0] = 1
                  buf += 1
              elif i_s[j] == "5":
                  check0[1] = 1
                  buf += 1
              elif i_s[j] == "7":
                  check0[2] = 1
                  buf += 1
          if check0 == [1, 1, 1] and buf == 3:
              ans += 1
      print(ans)
  
problem_description: Statement
  
  You are given an integer N. Among the integers between 1 and N (inclusive),
  how many _Shichi-Go-San numbers_ (literally "Seven-Five-Three numbers") are
  there?
  
  Here, a Shichi-Go-San number is a positive integer that satisfies the
  following condition:
  
    * When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
samples: [{"input": "575", "output": "4\n    \n\nThere are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and\n573.\n\n* * *"}, {"input": "3600", "output": "13\n    \n\nThere are 13 Shichi-Go-San numbers not greater than 3600: the above four\nnumbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.\n\n* * *"}, {"input": "999999999", "output": "26484"}]