stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

using ll = long long;



int main() {

    int n;

    cin >> n;



    vector<int> a;

    int p[3] = { 3, 5, 7 };

    for (int k = 3; k <= 9; k++) {

        int l = (int)pow(3, k);

        for (int i = 0; i < l; i++) {

            int t = 0;

            int s = i;

            int q[3] = {};

            for (int j = 0; j < k; j++) {

                t *= 10;

                t += p[s % 3];

                q[s % 3] = 1;

                s /= 3;

            }

            if (q[0] && q[1] && q[2]) a.push_back(t);

        }

    }



    int r = 0;

    for (auto& i : a) {

        if (i <= n) r++;

    }



    cout << r << endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include <functional>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

using ll = long long;



int main() {

    int n;

    cin >> n;



    int r = 0;

    function<void(int)> dfs = [&](int i) {

        for (int a = 3; a <= 7; a += 2) {

            int j = i * 10 + a;

            if (j <= n) {

                int p[10] = {};

                for (int t = j; t; t /= 10) p[t % 10]++;

                if (p[3] && p[5] && p[7]) r++;

                if ((ll)j * 10 < n) dfs(j);

            }

        }

    };

    dfs(0);



    cout << r << endl;



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

long long a[233];

int b[3]={3,5,7};

int vis[3];

int ans;

long long t ;

void dfs(int i)

{

    long long  num=0;

    memset(vis,0,sizeof(vis));

    for(int j=1;j<i;j++)

    {

        num=num*10+a[j];

        if(a[j]==3) vis[0]=1;

        if(a[j]==5) vis[1]=1;

        if(a[j]==7) vis[2]=1;

    }



    int flag= vis[0]*vis[1]*vis[2];

    if(num > t ) return ;



    if(flag) {ans++;

    }

    for(int j = 0 ;j<3;j++)

    {

        a[i]=b[j];

        dfs(i+1);

    }

}

int main()

{



  scanf("%d",&t);

   ans=0;

  dfs(1);



  printf("%d\n",ans);

}


// Optimized solution to the same problem (faster):
#include <cstdio>

int N,count=0;

void dfs(long long,unsigned char);

int main(void)

{

    scanf("%d",&N);

    dfs(0,0);

    printf("%d\n",count);

    return 0;

}

void dfs(long long nextNum,unsigned char flag357)

{

    if(nextNum<=N)

    {

        if(flag357==07)    // 07 is BIN 111

            count++;

        dfs(nextNum*10+3,flag357|01); // BIN 001

        dfs(nextNum*10+5,flag357|02); // BIN 010

        dfs(nextNum*10+7,flag357|04); // BIN 100

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cmath>

#include <algorithm>

#include <cstring>

#include <iostream>

#include <cstdio>

#include <ctype.h>

#include <string>

#include <vector>

#include <map>

#include <set>

#include <unordered_map>

#define INF 0x3fffffff

#define DEBUG 1

#define MAXSIZE 100005

using namespace std;

typedef long long LL;





int a[3] = { 3,5,7 };

int b[10] = { 0 };

LL com(int k[]) {

	LL ans = 0;

	int i = 0;

	LL tem = 1;

	while (k[i] != 0) {

		ans += k[i] * tem;

		tem *= 10;

		i++;

	}

	return ans;

}

bool judge(int k[]) {

	int ha[10] = { 0 };

	int i = 0;

	while (k[i] != 0) ha[k[i++]]++;

	return ha[3] && ha[5] && ha[7];

}

void jw(int k[]) {

	if (k[0] != 7) {

		if (k[0] == 3) k[0] = 5;

		else if (k[0] == 5) k[0] = 7;

		return ;

	}

	else {

		k[0] = 3;

		int i = 1;

		while (k[i] == 7) {

			k[i++] = 3;

		}

		if (k[i] == 3) k[i] = 5;

		else if (k[i] == 5) k[i] = 7;

		else k[i] = 3;

	}

}

int main() {

	int n;

	scanf("%d", &n);

	b[3] = 0; b[5] = 1; b[7] = 2;

	int k[11] = {0};

	k[0] = 7; k[1] = 5; k[2] = {3};

	int ans = 0;

	while (com(k) <= n) {

		ans++;

		jw(k);

		while (!judge(k)) jw(k);

	}

	printf("%d\n",ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

int count=0;

int T;

void dfs(long long n,char flag357)

{

	if(n<=T)

	{

		if(flag357==07)

		count++;

		dfs(n*10+3,flag357|01);

		dfs(n*10+5,flag357|02);

		dfs(n*10+7,flag357|04);

	}

}



int main()

{

	char flag357;

	scanf("%d",&T);

	dfs(0,0);

	printf("%d\n",count);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include <stack>

#include<cstdio>

#include<algorithm>

#include<string.h>

#include<set>

#include<map>

#include<cmath>

#define MAXN 51

#include<utility>

#define DEBUG 0



using namespace std;

typedef long long ll;

ll M;

ll c=0;

ll a[3]={3,5,7};

ll vis[3]={0};

void dfs(ll n,ll cur)

{

    if(n>M) return ;

    else

    {

        if(n>=357&&vis[0]&&vis[1]&&vis[2]) c++;

        ll p=1;

        for(int i=0;i<cur;i++) p*=10;

        for(int i=0;i<3;i++)

            {

                vis[i]++;

                dfs(n*10+a[i],cur+1);

                vis[i]--;

            }

    }

}

int main()

{

    #if DEBUG

    freopen("in.txt","r",stdin);

    #endif // DEBUG

    scanf("%lld",&M);

    vis[0]=1;

    dfs(3,1);

    vis[0]=0;

    vis[1]=1;

    dfs(5,1);

    vis[1]=0;

    vis[2]=1;

    dfs(7,1);

    vis[2]=0;



    printf("%lld\n",c);

    #if DEBUG

    fclose(stdin);

    #endif // DEBUG



    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

int count=0;

int T;

void dfs(long long n,char flag357)

{

	if(n<=T)

	{

		if(flag357==07)

		count++;

		dfs(n*10+3,flag357|01);

		dfs(n*10+5,flag357|02);

		dfs(n*10+7,flag357|04);

	}

}



int main()

{

	char flag357;

	scanf("%d",&T);

	dfs(0,0);

	printf("%d\n",count);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include<cstdio>

#include <string>

#include <map>

#include <algorithm>

using namespace std;



long T;

int x = 0;

string a = "3";

string b = "5";

string c = "7";



void upnumber(long n)

{

	if (n <= T)

	{

		string N = to_string(n);

		if (N.find(a) != string::npos && N.find(b) != string::npos && N.find(c) != string::npos)

		{

			x++;

		}

		upnumber(n * 10 + 3);

		upnumber(n * 10 + 5);

		upnumber(n * 10 + 7);

	}

}



int main()

{

	cin >> T;

	upnumber(0);

	cout << x;



}

// Optimized solution to the same problem (faster):
#include<cstdio>

int count=0;

int T;

void dfs(long long n,char flag357)

{

	if(n<=T)

	{

		if(flag357==07)

		count++;

		dfs(n*10+3,flag357|01);

		dfs(n*10+5,flag357|02);

		dfs(n*10+7,flag357|04);

	}

}



int main()

{

	char flag357;

	scanf("%d",&T);

	dfs(0,0);

	printf("%d\n",count);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include <algorithm>



using namespace std;



long long T, ans = 0;

int len;

void BS(int val, int len);

bool isX(long long a);



bool isX(long long a)

{

    int flag3 = 0;

    int flag5 = 0;

    int flag7 = 0;

    while(a != 0)

    {

        if(a % 10 == 3)

            flag3 = 1;

        else if(a % 10 == 5)

            flag5 = 1;

        else if(a % 10 == 7)

            flag7 = 1;

        else

            return false;

        a /= 10;

    }

    if(flag3 == 1 && flag5 == 1 && flag7 ==1)

        return true;

    else

        return false;

}

void BS(int val, int step)

{

    if(step == len)

    {

        if(val <= T && isX(val))

        {

            ans++;

        }

        return;

    }

    else if(step < len)

    {

        if(val <= T && isX(val))

            ans++;

    }

    for(int i = 3; i <= 7; i = i + 2)

    {

        BS(val * 10 + i, step + 1);

    }

}

int main()

{

    scanf("%lld", &T);

    char s[15];

    sprintf(s, "%d", T);

    len = strlen(s);

    //printf("%d", len);

    //if(isX(T))

       // printf("!!!");

    ans = 0;

    BS(0, 0);

    printf("%d\n", ans);

}


// Optimized solution to the same problem (faster):
#include<cstdio>

int count=0;

int T;

void dfs(long long n,char flag357)

{

	if(n<=T)

	{

		if(flag357==07)

		count++;

		dfs(n*10+3,flag357|01);

		dfs(n*10+5,flag357|02);

		dfs(n*10+7,flag357|04);

	}

}



int main()

{

	char flag357;

	scanf("%d",&T);

	dfs(0,0);

	printf("%d\n",count);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

using ll = long long;



int num[12], cnt;



pair<ll, int> xx(int x) {

    ll ans = 0, f = 0;

    cnt = 0;

    while(x) {

        int c = x % 4; x /= 4;

        if (!c) { f |= 8; num[cnt++] = 0; }

        if (c == 1) { f |= 1; num[cnt++] = 3; }

        if (c == 2) { f |= 2; num[cnt++] = 5; }

        if (c == 3) { f |= 4; num[cnt++] = 7; }

    }

    for(int i = cnt - 1; ~i; --i) ans = ans * 10 + num[i];

    return make_pair(ans, f);

}



int main() {

    ios::sync_with_stdio(0);

    int n, ans = 0;

    cin >> n;

    for(int i = 0; ; i++) {

        pair<ll, int> c = xx(i);

        if(c.first > n) break;

        if(c.second == 7) ans++;

    }



    cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

int count=0;

int T;

void dfs(long long n,char flag357)

{

	if(n<=T)

	{

		if(flag357==07)

		count++;

		dfs(n*10+3,flag357|01);

		dfs(n*10+5,flag357|02);

		dfs(n*10+7,flag357|04);

	}

}



int main()

{

	char flag357;

	scanf("%d",&T);

	dfs(0,0);

	printf("%d\n",count);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define all(v)			((v).begin()), ((v).end())

#define sz(v)			((int)((v).size()))

#define clr(v, d)		memset(v, d, sizeof(v))

#define rep(i, v)		for(int i=0;i<sz(v);++i)

#define lp(i, n)		for(int i=0;i<(int)(n);++i)

#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)

#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)

typedef long long ll;

typedef pair<int,int> pi;

vector<vector<int>> v(100009);

bool vis[100009];

long long n;

int dfs(long long a,bool n3,bool n5,bool n7)

{

    if(a>n)

        return 0;

    int x=0;

    if(n3&&n5&&n7)

        x++;

    x+=dfs(a*10+3,1,n5,n7);

    x+=dfs(a*10+5,n3,1,n7);

    x+=dfs(a*10+7,n3,n5,1);

    return x;

}

int main() {

#ifndef ONLINE_JUDGE

	//freopen("test.txt", "rt", stdin);

#endif

    cin>>n;

    cout<<dfs(0,0,0,0);



}


// Optimized solution to the same problem (faster):
#include<iostream>

using namespace std;

int count=0;

long long n;

void DFS(long long num,unsigned char flag357){

	if(num<=n){

		if(flag357==07){

		    count++;

		}

	DFS(num*10+3,flag357|01);

	DFS(num*10+5,flag357|02);

	DFS(num*10+7,flag357|04);

	}

}

int main(){

	cin>>n;

	DFS(0,0);

	cout<<count;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define MOD 1000000007



vector<int> cand(0);



void push(int a,int n){

    if(n == 0) return;

    n--;

    cand.push_back(10*a+3);

    cand.push_back(10*a+5);

    cand.push_back(10*a+7);



    push(10*a+3,n);

    push(10*a+5,n);

    push(10*a+7,n);

  }



int main() {

  

  int N;

  cin >> N;



  push(3,8);

  push(5,8);

  push(7,8);



  int ans = 0;

  sort(cand.begin(),cand.end());

   

  for(int i = 0;i < cand.size();i++) {

    vector<bool> check(3,false);

    if(cand.at(i) < 100) continue;

    if(cand.at(i) > N) break;



    while(cand.at(i) > 0) {

      if(cand.at(i) % 10 == 3) check.at(0) = true;

      if(cand.at(i) % 10 == 5) check.at(1) = true;

      if(cand.at(i) % 10 == 7) check.at(2) = true;

      cand.at(i) /= 10;

    }



    if(check.at(0) && check.at(1) && check.at(2)) ans++;

  }



  cout << ans << endl;

  

}






// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

#define MOD 1000000007



int ans = 0;

long long N;



void cand(long long num,int three,int five,int seven) {

  if(num > N) return;



  if(three && five && seven) ans++;



  cand(10 * num + 3,1,five,seven);

  cand(10 * num + 5,three,1,seven);

  cand(10 * num + 7,three,five,1);

}



int main() {



 

  cin >> N;



  cand(3,1,0,0);

  cand(5,0,1,0);

  cand(7,0,0,1);



  cout << ans << endl;

}






// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define dum(x) cout<<#x<<'='<<x<<endl

#define ll long long

using namespace std;



int n;

int cnt = 0;



bool check(ll x) {

  if (x > n) return false;



  string s = to_string(x);

  bool c3 = false, c5 = false, c7 = false;

  for (int i = 0; i < s.size(); i++) {

    if (s.at(i) == '3') c3 = true;

    if (s.at(i) == '5') c5 = true;

    if (s.at(i) == '7') c7 = true;

  }



  if (c3 && c5 && c7)

  return true;

  else

  return false;

}



void dfs(ll x) {

  if (check(x)) cnt++;

  if (x <= 1000000000) {

    dfs(10 * x + 3);  // long long必要

    dfs(10 * x + 5);

    dfs(10 * x + 7);

  }

}



int main() {

  cin >> n;

  dfs(0);

  cout << cnt << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define ll long long

using namespace std;



int n;

int ans = 0;



bool check(ll x) {

  if (x > n) return false;



  bool c3 = false, c5 = false, c7 = false;

  string str = to_string(x);

  for (int i = 0; i < str.size(); i++) {

    if (str.at(i) == '3') c3 = true;

    if (str.at(i) == '5') c5 = true;

    if (str.at(i) == '7') c7 = true;

  }



  if (c3 && c5 && c7) {

    return true;

  } else {

    return false;

  }

}



void dfs(ll x) {

  if (check(x)) ans++;

  if (x <= n) {

    dfs(10 * x + 3);

    dfs(10 * x + 5);

    dfs(10 * x + 7);

  }

}



int main() {

  cin >> n;

  dfs(0);

  cout << ans << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):


#include<iostream>

#include<cstdio>

#include<cstring>

#include <cstdlib>  

#include <cmath>   

#include<cctype>

#include<string>

#include <map>

#include<algorithm>

#include <functional>

#include<vector>

#include<climits>

#include<stack>

#include<queue>

#include <deque>

#include <utility> 



#define rep(i,m,n) for(int i = m;i < n;++i)

using namespace std;

using ll = long long;

using R = double;

const ll inf = 1LL << 50;

const int MOD = 1e9 + 7;







int main() {

	int N;

	cin >> N;

	int v[3] = {3,5,7};





	int ans = 0;



	rep(dgt, 3, 10) {

		int ma = 1;

		rep(i, 0, dgt)ma *= 3;



		rep(msk, 0, ma) {

			int x = 0;

			int m = msk;

			int cn[3] = { 0,0,0 };

			rep(i, 0, dgt) {

				int d = m % 3;

				x = x * 10 + v[d];

				cn[d]++;

				m /= 3;

			}

			if (x <= N && cn[0] > 0 && cn[1] > 0 && cn[2] > 0)ans++;

		}

	}

	

	cout << ans << endl;



	return 0;

}


// Optimized solution to the same problem (faster):
#include<iostream>

#include<cstdio>

#include<cstring>

#include <cstdlib>  

#include <cmath>   

#include<cctype>

#include<string>

#include<set>

#include <map>

#include<algorithm>

#include <functional>

#include<vector>

#include<climits>

#include<stack>

#include<queue>

#include <deque>

#include <utility> 



#define rep(i,m,n) for(int i = m;i < n;++i)

using namespace std;

using ll = long long;

using R = double;

const ll inf = 1LL << 50;

const ll MOD = 1e9 + 7;







void chmax(ll &a,ll b) {

	if (a < b)a = b;

}



//i:digit j:3ornot k:5ornot l:7ornot m:notonly357 n:otherthanzero_past o:isless

ll dp[15][2][2][2][2][2][2];

int N;



int main() {

	cin >> N;

	string s = to_string(N);

	int n = s.length();



	dp[0][0][0][0][0][0][0] = 1;



	rep(dgt, 0, n)rep(j, 0, 2)rep(k, 0, 2)rep(l, 0, 2)rep(p, 0, 2)rep(q, 0, 2)rep(isless, 0, 2) {

		int c = s[dgt] - '0';

		int ma = 9;

		if (!isless)ma = c;

		rep(nxt, 0, ma+1) {

			bool not357 = q ? ((nxt != 3)&&(nxt!=5)&&(nxt!=7)):((nxt!=0)&&(nxt != 3) && (nxt != 5) && (nxt != 7));

			dp[dgt+1][j || (nxt == 3)][k || (nxt==5)][l || (nxt==7)][p || not357][nxt||q][isless || nxt < ma] += dp[dgt][j][k][l][p][q][isless];

		}

	}

	

	ll ans = 0;

	rep(j, 0, 2)rep(k, 0, 2)rep(l, 0, 2)rep(p, 0, 2)rep(q, 0, 2)rep(isless, 0, 2) {

		if (j == 1 && k == 1 && l == 1 && p == 0 && q == 1)ans += dp[n][j][k][l][p][q][isless];

	}

	

	cout << ans << endl;

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cmath>

using namespace std;

int a[10];

int l[]={3,5,7};

int c[3]={0,0,0};

int wnu(int n,int &cnt,int p,int i=0){

    if(i==p){

        if(c[0]*c[1]*c[2]==0)return 0;

        int N=0;

        for(int j=0;j<p;j++){

            N*=10;

            N+=a[j];

        }

        if(N<=n)cnt++;

        else return 4;

        return 1;

    }

    for(int j=0;j<3;j++){

        a[i]=l[j];

        c[j]++;

        if(wnu(n,cnt,p,i+1)==4)return 4;

        c[j]--;

    }

    return 2;

}



int main(){

    int n;

    cin>>n;

    int cnt=0;

    for(int i=3;i<10;i++)

        if(wnu(n,cnt,i)==4)break;

    cout<<cnt<<endl;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

using namespace std;

typedef long long ll;

ll n, cnt = 0;



void dfs(int k, ll last){

    if(k > 9 || last > n) return;

    ll tmp = last;

    int a = 0, b = 0, c = 0;

    while(tmp > 0){

        int s = tmp%10;

        tmp/=10;

        if(s == 3) a = 1;

        if(s == 5) b = 1;

        if(s == 7) c = 1;

        if(a && b && c) break;

    }

    if(last <= n && a && b && c) cnt++;

    dfs(k+1, last*10+3);

    dfs(k+1, last*10+5);

    dfs(k+1, last*10+7);

}



int main()

{

    scanf("%lld", &n);

    dfs(0, 0);

    printf("%lld\n", cnt);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <algorithm>

#include <queue>

#define MAX_NUM 50001

#include <iomanip>

#include <string>

#include <utility>

#include <map>

using namespace std;







bool isuseful(long long x)

{

    int a[8]={0},temp=x;

    while(x)

    {

        temp=x%10;

        x/=10;

        a[temp]++;

        if(a[3]&&a[5]&&a[7])

            break;



    }

            if(a[3]&&a[5]&&a[7])

            return true;

            else

    return false;





}

long long getwei(long long x)

{

    long long num=0;

    while(x)

    {



    x/=10;

    num++;

    }

    return num;

}

long long my_pow(long long x,long long wei)

{

    long long num=1;

    while(wei)

    {

        num*=x;

        wei--;

    }

    return num;

}

int main()

{

    long long X;

    cin>>X;

    queue<long long> qu;

    qu.push(3);

        qu.push(5);

            qu.push(7);

long long num=0;

long long new_num=0;

  while(new_num<=X*10)

  {

      long long u=qu.front();

      qu.pop();

      long long wei=getwei(u);



      for(int i=3;i<=7;)

      {

        new_num=u+(my_pow(10,wei)*i);

        qu.push(new_num);





        if(isuseful(new_num) && new_num<=X)

            num++;

        if(i==3)

            i=5;

        else if(i==5)

            i=7;

        else

            i=8;

      }

  }



    cout<<num;



}




// Optimized solution to the same problem (faster):
#include <cstdio>

using namespace std;

typedef long long ll;

ll n, cnt = 0;



void dfs(int k, ll last){

    if(k > 9 || last > n) return;

    ll tmp = last;

    int a = 0, b = 0, c = 0;

    while(tmp > 0){

        int s = tmp%10;

        tmp/=10;

        if(s == 3) a = 1;

        if(s == 5) b = 1;

        if(s == 7) c = 1;

        if(a && b && c) break;

    }

    if(last <= n && a && b && c) cnt++;

    dfs(k+1, last*10+3);

    dfs(k+1, last*10+5);

    dfs(k+1, last*10+7);

}



int main()

{

    scanf("%lld", &n);

    dfs(0, 0);

    printf("%lld\n", cnt);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



const int MAX=1100;



vector<int> v;

long long n;

long long ans=0;

int A[]={3,5,7};



long long cal(){

    long long ans=0;

    for(int i=0;i<v.size();i++){

        ans=ans*10+v[i];

    }

    return ans;

}



bool judge(){

    bool flag1=false,flag2=false,flag3=false;

    for(int i=0;i<v.size();i++){

        if(v[i]==3)

            flag1=true;

        if(v[i]==5)

            flag2=true;

        if(v[i]==7)

            flag3=true;

    }

    return flag1&&flag2&&flag3;

}



void dfs(int step,int depth){

    if(step==depth){

        if(judge() && cal()<=n){

            ans++;

            //printf("%d\n",cal());

        }

        return;

    }

    for(int i=0;i<3;i++){

        v.push_back(A[i]);

        dfs(step+1,depth);

        v.pop_back();

    }

}



int main()

{

    scanf("%lld",&n);

    long long temp=n;

    int len=0;

    while(temp){

        temp=temp/10;

        len++;

    }

    //printf("%d\n",len);

    for(int i=3;i<=len;i++){

        dfs(0,i);

        v.clear();

    }

    printf("%d\n",ans);

    return 0;

}




// Optimized solution to the same problem (faster):
/*#include<cstdio>

#include<iostream>

using namespace std;



bool judge(int x){

    int ans3 = 0,ans5 = 0,ans7 = 0,num=0;

    do{

       if(x % 10 == 3) ans3++;

       if(x % 10 == 5) ans5++;

       if(x % 10 == 7) ans7++;

       num++;

       x = x/10;



    }while(x != 0);

    if(ans3 > 0 && ans5 > 0 && ans7 > 0 && ans3+ans5+ans7 == num){

        return true;

    }else{

        return false;

    }

}



int main(){

    int t;

    cin>>t;

    int ans = 0;

    for(int i = 1;i <= t;){

        if(judge(i)){

            ans++;

            i+=18;

        }else{

            i++;

        }

    }

    cout<<ans;

}

*/

#include<cstdio>

int count = 0;

int t;



void DFS(long long x,bool three,bool five,bool seven){

    if(x <= t){

        if(three && five && seven) count++;

    DFS(x*10+3,true,five,seven);

    DFS(x*10+5,three,true,seven);

    DFS(x*10+7,three,five,true);

    }



}



int main(){

    scanf("%d",&t);

    DFS(0,false,false,false);

    printf("%d",count);

}
















































// Fastest known solution for this problem: