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 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
//sort(a, a + N, greater<ll>())   // descend
//sort(a, a+N)                    //  ascend

/* 
void comb(vector<vector <ll> > &v) {
	ll mod=1000000007;
	rep (i,0,v.size()) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	rep (k,1,v.size()) {
		rep (j,1,k) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
		}
	}
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/


int main() {
	ll n;
	cin>>n;
	ll p3=0,p5=0,p7=0;
	ll ans=0;
	bool q=true;
	if(n>=800000000) ans=26848;
	else if(n>=500000000){
		ans=14384;
		rep(i,500000000,n+1){
		ll c=i;
		while(c!=0){
			if(c%10==3)p3++;
			else if(c%10==5)p5++;
			else if(c%10==7)p7++;
			else {q=false; break;}
			c/=10;
		}
		if(q && p3>0 && p5>0 && p7>0) ans++;
		p3=0,p5=0,p7=0;
		q=true;
		}
	}

	else if(n>=300000000){
		ans=8334;
		rep(i,300000000,n+1){
		ll c=i;
		while(c!=0){
			if(c%10==3)p3++;
			else if(c%10==5)p5++;
			else if(c%10==7)p7++;
			else {q=false; break;}
			c/=10;
		}
		if(q && p3>0 && p5>0 && p7>0) ans++;
		p3=0,p5=0,p7=0;
		q=true;
		}
	}
	else if(n>300000000 && n<=100000000) ans=8334;
	else if(n<100000000){
		rep(i,1,n+1){
		ll c=i;
		while(c!=0){
			if(c%10==3)p3++;
			else if(c%10==5)p5++;
			else if(c%10==7)p7++;
			else {q=false; break;}
			c/=10;
		}
		if(q && p3>0 && p5>0 && p7>0) ans++;
		p3=0,p5=0,p7=0;
		q=true;
		}
	}
	cout<<ans;
}