Problem:
Score : 300 points

Problem 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.

Constraints

1 \leq N < 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).

Sample Input 1

575

Sample Output 1

4

There are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.

Sample Input 2

3600

Sample Output 2

13

There are 13 Shichi-Go-San numbers not greater than 3600: the above four numbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.

Sample Input 3

999999999

Sample Output 3

26484

Solution in C++14 (Clang 3.8.0) (judge verdict: Wrong Answer)

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
typedef long long int ll;
using namespace std;
std::vector<int> lis;
std::vector<int> lis2;
std::vector<int> lis3;

void dfs(int e, int num){
  if(num!=0) lis.push_back(num);
  if(num >= 333333333) return;
  dfs(e * 10, num + e * 3);
  dfs(e * 10, num + e * 5);
  dfs(e * 10, num + e * 7);
}
void dfs2(int e, int num){
  if(num!=0) lis2.push_back(num);
  if(num >= 333333333) return;
  dfs2(e * 10, num + e * 3);
  dfs2(e * 10, num + e * 5);
}
void dfs3(int e, int num){
  if(num!=0) lis3.push_back(num);
  if(num >= 333333333) return;
  dfs3(e * 10, num + e * 3);
}

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  dfs(1, 0);
  dfs2(1, 0);
  dfs3(1, 0);
  sort(lis.begin(), lis.end());
  sort(lis2.begin(), lis2.end());
  sort(lis3.begin(), lis3.end());
  int maxx = upper_bound(lis.begin(), lis.end(), N) - lis.begin();
  int maxx2 = upper_bound(lis2.begin(), lis2.end(), N) - lis2.begin();
  int maxx3= upper_bound(lis3.begin(), lis3.end(), N) - lis3.begin();
  std::cout << maxx - maxx2*3 + maxx3*3<< '\n';
  return 0;
}