stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<iostream>

#include<map>

#include<cmath>

//#include<windows.h>

#include<algorithm>

#include<set>

const double eps = 1e-1;

using namespace std;

typedef long long ll;



int n,e[] = {3,5,7},len,ans,dig[12];

bool t[10];

char a[13];



void dfs(int d){

    if(d>len+1)return;

    if(d>3){

        int sum=0;

        int cnt=0;

        set<int>s;

        for(int i=1;i<d;i++){

            sum = sum*10+dig[i];

            s.insert(dig[i]);

        }

        if(s.size()==3&&sum<=n){

            ans++;

//            cout<<sum<<endl;

        }

        s.clear();

    }



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

            dig[d] = e[i];

            dfs(d+1);

    }

}

int main(){

    scanf("%d",&n);

    sprintf(a,"%d",n);



    len = strlen(a);

//    cout<<len<<endl;

    dfs(1);

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

    return 0;

}

//Hello World Here I Come

//          0                 10

//        0 1 1                8

//      0 1 1 2 3              6

//    0 1 1 2 3 5 8            4

//  0 1 1 2 3 5 8 13 21        2

//0 1 1 2 3 5 8 13 21 34 55    0


// Faster C++ solution for the same problem (measured speedup: 11.407228496390294x):
#include <cstdio>

int N,count=0;

void dfs(long long,int);

int main(void)

{

    scanf("%d",&N);

    dfs(0,0);

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

    return 0;

}

void dfs(long long nextNum,int flag357)

{

    if(nextNum<=N)

    {

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

            count++;

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

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

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

    }

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int num,res;



//ac是这些数字排列成的数字

//cnt表示已经有多少位置了



bool ok(long long n)

{

    int ret = 0;

    int cur;

    while(n)

    {

        cur = n%10;

        n /= 10;

        if(cur == 3) ret |= 1;

        else if(cur == 5) ret |= 2;

        else if(cur == 7) ret |= 4;

    }

    return ret == 7;

}



void dfs(long long ac)

{

    if(ac > num) return;

    else

    {

        if(ok(ac))

            ++res;

    }

    dfs(ac*10+3);

    dfs(ac*10+5);

    dfs(ac*10+7);

}



int main()

{

    scanf("%d",&num);

    res = 0;

    dfs(0);

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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.701022254871891x):
#include <cstdio>

int N,count=0;

void dfs(long long,int);

int main(void)

{

    scanf("%d",&N);

    dfs(0,0);

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

    return 0;

}

void dfs(long long nextNum,int flag357)

{

    if(nextNum<=N)

    {

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

            count++;

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

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

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

    }

}
// Slower C++ solution:
#include<iostream>

#include<string.h>

using namespace std;

int N,count=0;



void getNum(long long num,int flag){

	int baiwei = flag/100;

	int shiwei = flag/10%10;

	int gewei = flag%10;

	if(num<=N){

		if(baiwei&&shiwei&&gewei){

			count++;

		}

		int temp1=flag,temp2=flag,temp3=flag;

		if(baiwei==0){

			temp1+=100;

		}

		getNum(num*10+3,temp1);

		if(shiwei==0){

			temp2+=10;

		}

		getNum(num*10+5,temp2);

		if(gewei==0){

			temp3+=1;

		}

		getNum(num*10+7,temp3);

	}

}



int main(){

	scanf("%d",&N);

	getNum(0,0);

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

}

// Faster C++ solution for the same problem (measured speedup: 4.833990233702367x):
#include <cstdio>

int N,count=0;

void dfs(long long,int);

int main(void)

{

    scanf("%d",&N);

    dfs(0,0);

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

    return 0;

}

void dfs(long long nextNum,int flag357)

{

    if(nextNum<=N)

    {

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

            count++;

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

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

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

    }

}
// Slower C++ solution:
#include <iostream>

#include <queue>

#include <cmath>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <set>

using namespace std;

using std::sort;

using std::binary_search;



#define MAX 100004

int cnt=0;

int t;

void dfs(long long  x,int flag){

    if(x>t){

        return;

    }

    if(flag==7){

        cnt++;

    }

    dfs(x*10+3,flag|1);

     dfs(x*10+5,flag|2);

     dfs(x*10+7,flag|4);



}

int main(){



//    printf("1\n");

    scanf("%d",&t);

    dfs(0,0);

    printf("%d",cnt);

}




// Faster C++ solution for the same problem (measured speedup: 4.681024040174706x):
#include <cstdio>

int N,count=0;

void dfs(long long,int);

int main(void)

{

    scanf("%d",&N);

    dfs(0,0);

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

    return 0;

}

void dfs(long long nextNum,int flag357)

{

    if(nextNum<=N)

    {

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

            count++;

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

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

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

    }

}
// Slower C++ solution:
#include<iostream>

#include<stdlib.h>

#include<string>

using namespace std;

string str;

int num = 0;

void DFS(int flag3, int flag5, int flag7, string s)

{

	if (s.size() == str.size())

	{

		if (s > str)

			return;

	}

	else if (s.size() > str.size())

		return;

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

		num++;

	DFS(1, flag5, flag7, s + '3');

	DFS(flag3, 1, flag7, s + '5');

	DFS(flag3, flag5, 1, s + '7');

}

int main()

{

	cin >> str;

	string s = "";

	DFS(0, 0, 0, s);

	cout << num << endl;

	system("pause");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.960421538074456x):
#include <cstdio>

int N,count=0;

void dfs(long long,int);

int main(void)

{

    scanf("%d",&N);

    dfs(0,0);

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

    return 0;

}

void dfs(long long nextNum,int flag357)

{

    if(nextNum<=N)

    {

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

            count++;

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

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

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

    }

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



int cnt = 0, N;



bool chk(ll n)

{

    int a[10] = {};

    while (n) {

        int lst = n % 10;

        a[lst]++;

        n /= 10;

    }



    if (a[3] && a[5] && a[7]) return true;

    return false;

}



void dfs(ll n)

{

    if (n > N) return;

    if (chk(n)) cnt++;

    dfs(n*10 + 3);

    dfs(n*10 + 5);

    dfs(n*10 + 7);

}



int main()

{

    cin >> N;

    dfs(0);

    cout << cnt << "\n";

}


// Faster C++ solution for the same problem (measured speedup: 5.1081658917757835x):
#include <cstdio>

int N,count=0;

void dfs(long long,int);

int main(void)

{

    scanf("%d",&N);

    dfs(0,0);

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

    return 0;

}

void dfs(long long nextNum,int flag357)

{

    if(nextNum<=N)

    {

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

            count++;

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

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

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

    }

}
// Slower C++ solution:
#include<iostream>

#include<queue>

#include<string>

using namespace std;



int ans;

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



bool func(int data){

	string s;

	while(data){

		s=s+(char)(data%10+'0');

		data/=10;

	}

	if(s.find('3')!=string::npos&&s.find('5')!=string::npos&&s.find('7')!=string::npos){

		return true;

	}

	return false;

}



void BFS(int t){

	if(t<357){

		ans=0;

		return;

	}

	queue<int> myque;

	myque.push(0);

	while(!myque.empty()){

		int acc=myque.front();

		if(acc>t||acc>77777777){

			return;

		}

		myque.pop();

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

			int temp=acc*10+arr[i];

			if(temp>t){

				break;

			}

			if(func(temp)){

				ans++;

			}

			myque.push(temp);

		}

	}

}



int main(){

	int t;

	cin>>t;

	ans=0;

	BFS(t);

	cout<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 8.19739755970551x):
#include <cstdio>

int N,count=0;

void dfs(long long,int);

int main(void)

{

    scanf("%d",&N);

    dfs(0,0);

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

    return 0;

}

void dfs(long long nextNum,int flag357)

{

    if(nextNum<=N)

    {

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

            count++;

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

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

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

    }

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int , int> P;

typedef pair<ll, ll> PL;

const int INT_INF = 2147483646;

const ll LL_INF = 9223372036854775807;



bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)

{

       return a.second<b.second;

}

 

bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)

{

       return a.second>b.second;

}

 

string s;

ll n;

int a[11];

ll ans;





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

void calc(ll num, int f1, int f2, int f3){

    int nn;

    string st;

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

        nn = num*10+ar[i];

        if(i == 0)  f1++;

        else if(i == 1) f2++;

        else   f3++;



        st = to_string(nn);

        if(st.length() > 9) return;



        if(f1 != 0 && f2 != 0 && f3 != 0){

            if(nn <= n){

                ++ans;

            //  cout << nn << endl;

                calc(nn,f1,f2,f3);

            }

        }

        else{

            calc(nn,f1,f2,f3);

        }

        if(i == 0)  f1--;

        else if(i == 1) f2--;

        else   f3--;

    }

    return;

}



int main(){

    cin >> n;

    int f1=0,f2=0,f3=0;

    calc(3,1,0,0);

    calc(5,0,1,0);

    calc(7,0,0,1);



    cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 3.5751452761338642x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int , int> P;

typedef pair<ll, ll> PL;

const int INT_INF = 2147483646;

const ll LL_INF = 9223372036854775807;



bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)

{

       return a.second<b.second;

}

 

bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)

{

       return a.second>b.second;

}

 

ll n;

ll ans;



void solve(ll val, bool f1, bool f2, bool f3){

    if(val <= n){

        if(f1 && f2 && f3)  ++ans;

        solve(val*10+7,true,f2,f3);

        solve(val*10+5,f1,true,f3);

        solve(val*10+3,f1,f2,true);

    }

}





int main(){

    cin >> n;

    solve(7,true,false,false);

    solve(5,false,true,false);

    solve(3,false,false,true);



    cout << ans << endl;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;

int M=0;

int n;

int A[1000];

void dfs(int k){

	int f3=0,f5=0,f7=0;

	long long num=0;

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

		num=num*10+A[i];

		if(A[i]==3)

			f3=1;

		else if(A[i]==5)

			f5=1;

		else if(A[i]==7)

			f7=1;

	}

	if(num>n) return;

	if(f3*f5*f7==1)

		M++;

	A[k]=3;

	dfs(k+1);

	A[k]=5;

	dfs(k+1);

	A[k]=7;

	dfs(k+1);

}

int main(){

	cin>>n;

	dfs(0);

	cout<<M;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.710209673733521x):
#include <cstdio>

int N,count=0;

void dfs(long long nextnum,unsigned	char flag){

	if(nextnum<=N){

		if(flag==7){

			count++;

		}

		dfs(nextnum*10+3,flag|01);

		dfs(nextnum*10+5,flag|02);

		dfs(nextnum*10+7,flag|04);

	}

} 

int main(){

	scanf("%d",&N);

	dfs(0,0);

	printf("%d",count);

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include<cstring>



using namespace std;

int len,ans = 0 ,res=0;

char d[3]={'3','5','7'},x[11];

    int  num;

bool isValid(char a[])

{

    int cnt[11]={0};

    for(int i=0;i<strlen(a);i++)

    {

        cnt[a[i]-'0']++;

    }



    if(cnt[3] >= 1 && cnt[5] >= 1 && cnt[7] >= 1 &&  cnt[3] + cnt[5] + cnt[7] == strlen(a))

    {

        if(atoi(a) <= num)

        return true;

    }

    return false;

}



void dfs(int pos ,int len ,char  a[] )

{

    if(pos == len )

    {

        a[len]='\0';

        if(isValid(a))

        {

            res++;

        }

        return ;

    }

        a[pos] = '3';

        dfs(pos+1,len,a);



        a[pos] = '5';

        dfs(pos+1,len,a);



        a[pos] = '7';

        dfs(pos+1,len,a);

}

int main()

{



    int i,j,k;

    char str[11];

     scanf("%s",&str);

    num = atoi(str);

    len = strlen(str);



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

        dfs(0,i,x);

    cout<<res;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 8.40280437832153x):
#include <cstdio>

int N,count=0;

void dfs(long long nextnum,unsigned	char flag){

	if(nextnum<=N){

		if(flag==7){

			count++;

		}

		dfs(nextnum*10+3,flag|01);

		dfs(nextnum*10+5,flag|02);

		dfs(nextnum*10+7,flag|04);

	}

} 

int main(){

	scanf("%d",&N);

	dfs(0,0);

	printf("%d",count);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;

int M=0;

int n;

int A[1000];

void dfs(int k){

	int f3=0,f5=0,f7=0;

	long long num=0;

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

		num=num*10+A[i];

		if(A[i]==3)

			f3=1;

		else if(A[i]==5)

			f5=1;

		else if(A[i]==7)

			f7=1;

	}

	if(num>n) return;

	if(f3*f5*f7==1)

		M++;

	A[k]=3;

	dfs(k+1);

	A[k]=5;

	dfs(k+1);

	A[k]=7;

	dfs(k+1);

}

int main(){

	cin>>n;

	dfs(0);

	cout<<M;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.7875342248302095x):
#define _CRT_SECURE_NO_DEPRECATE

#include<cstdio>

using namespace std;

typedef long long int ll;

int ans = 0;

ll T;

void DFS(ll n,bool r3,bool r5,bool r7) {

	if (n <= T) {

		if (r3&&r5&&r7)

			ans++;

		DFS(n * 10 + 3, true, r5, r7);

		DFS(n * 10 + 5, r3, true, r7);

		DFS(n * 10 + 7, r3, r5, true);

	}

}



int main() {

	scanf("%ld", &T);

	DFS(0,false,false,false);

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

	getchar();getchar();

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include<cstring>



using namespace std;

int len,ans = 0 ,res=0;

char d[3]={'3','5','7'},x[11];

    int  num;

bool isValid(char a[])

{

    int cnt[11]={0};

    for(int i=0;i<strlen(a);i++)

    {

        cnt[a[i]-'0']++;

    }



    if(cnt[3] >= 1 && cnt[5] >= 1 && cnt[7] >= 1 &&  cnt[3] + cnt[5] + cnt[7] == strlen(a))

    {

        if(atoi(a) <= num)

        return true;

    }

    return false;

}



void dfs(int pos ,int len ,char  a[] )

{

    if(pos == len )

    {

        a[len]='\0';

        if(isValid(a))

        {

            res++;

        }

        return ;

    }

        a[pos] = '3';

        dfs(pos+1,len,a);



        a[pos] = '5';

        dfs(pos+1,len,a);



        a[pos] = '7';

        dfs(pos+1,len,a);

}

int main()

{



    int i,j,k;

    char str[11];

     scanf("%s",&str);

    num = atoi(str);

    len = strlen(str);



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

        dfs(0,i,x);

    cout<<res;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 8.499633405743783x):
#define _CRT_SECURE_NO_DEPRECATE

#include<cstdio>

using namespace std;

typedef long long int ll;

int ans = 0;

ll T;

void DFS(ll n,bool r3,bool r5,bool r7) {

	if (n <= T) {

		if (r3&&r5&&r7)

			ans++;

		DFS(n * 10 + 3, true, r5, r7);

		DFS(n * 10 + 5, r3, true, r7);

		DFS(n * 10 + 7, r3, r5, true);

	}

}



int main() {

	scanf("%ld", &T);

	DFS(0,false,false,false);

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

	getchar();getchar();

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

using ll = long long;



int n, cnt;



void dfs(ll x, int f) {

    if(x > n) return;

    if(f == 7) cnt++;

    dfs(x * 10 + 3, f | 1);

    dfs(x * 10 + 5, f | 2);

    dfs(x * 10 + 7, f | 4);

}



int main() {

    cin >> n;

    dfs(0, 0);

    cout << cnt << endl;

}

// Faster C++ solution for the same problem (measured speedup: 4.8017046863863895x):
#define _CRT_SECURE_NO_DEPRECATE

#include<cstdio>

using namespace std;

typedef long long int ll;

int ans = 0;

ll T;

void DFS(ll n,bool r3,bool r5,bool r7) {

	if (n <= T) {

		if (r3&&r5&&r7)

			ans++;

		DFS(n * 10 + 3, true, r5, r7);

		DFS(n * 10 + 5, r3, true, r7);

		DFS(n * 10 + 7, r3, r5, true);

	}

}



int main() {

	scanf("%ld", &T);

	DFS(0,false,false,false);

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

	getchar();getchar();

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;

int M=0;

int n;

int A[1000];

void dfs(int k){

	int f3=0,f5=0,f7=0;

	long long num=0;

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

		num=num*10+A[i];

		if(A[i]==3)

			f3=1;

		else if(A[i]==5)

			f5=1;

		else if(A[i]==7)

			f7=1;

	}

	if(num>n) return;

	if(f3*f5*f7==1)

		M++;

	A[k]=3;

	dfs(k+1);

	A[k]=5;

	dfs(k+1);

	A[k]=7;

	dfs(k+1);

}

int main(){

	cin>>n;

	dfs(0);

	cout<<M;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.77790415868522x):
#include<stdio.h>

int t;

int ans = 0;

void dfs(unsigned n,bool k3,bool k5,bool k7){

	if(n>t)return; 

	if(k3&&k5&&k7){

		ans++;	

	}

	dfs(n*10+3,true,k5,k7);

	dfs(n*10+5,k3,true,k7);

	dfs(n*10+7,k3,k5,true);

}



int main(){

	scanf("%d", &t);

	dfs(0,false,false,false);

	

//	dfs(3,true,false,false);

//	dfs(5,false,true,false);

//	dfs(7,false,false,true);

	

	

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

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include<cstring>



using namespace std;

int len,ans = 0 ,res=0;

char d[3]={'3','5','7'},x[11];

    int  num;

bool isValid(char a[])

{

    int cnt[11]={0};

    for(int i=0;i<strlen(a);i++)

    {

        cnt[a[i]-'0']++;

    }



    if(cnt[3] >= 1 && cnt[5] >= 1 && cnt[7] >= 1 &&  cnt[3] + cnt[5] + cnt[7] == strlen(a))

    {

        if(atoi(a) <= num)

        return true;

    }

    return false;

}



void dfs(int pos ,int len ,char  a[] )

{

    if(pos == len )

    {

        a[len]='\0';

        if(isValid(a))

        {

            res++;

        }

        return ;

    }

        a[pos] = '3';

        dfs(pos+1,len,a);



        a[pos] = '5';

        dfs(pos+1,len,a);



        a[pos] = '7';

        dfs(pos+1,len,a);

}

int main()

{



    int i,j,k;

    char str[11];

     scanf("%s",&str);

    num = atoi(str);

    len = strlen(str);



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

        dfs(0,i,x);

    cout<<res;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 8.487574235330166x):
#include<stdio.h>

int t;

int ans = 0;

void dfs(unsigned n,bool k3,bool k5,bool k7){

	if(n>t)return; 

	if(k3&&k5&&k7){

		ans++;	

	}

	dfs(n*10+3,true,k5,k7);

	dfs(n*10+5,k3,true,k7);

	dfs(n*10+7,k3,k5,true);

}



int main(){

	scanf("%d", &t);

	dfs(0,false,false,false);

	

//	dfs(3,true,false,false);

//	dfs(5,false,true,false);

//	dfs(7,false,false,true);

	

	

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

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

using ll = long long;



int n, cnt;



void dfs(ll x, int f) {

    if(x > n) return;

    if(f == 7) cnt++;

    dfs(x * 10 + 3, f | 1);

    dfs(x * 10 + 5, f | 2);

    dfs(x * 10 + 7, f | 4);

}



int main() {

    cin >> n;

    dfs(0, 0);

    cout << cnt << endl;

}

// Faster C++ solution for the same problem (measured speedup: 4.794892089616056x):
#include<stdio.h>

int t;

int ans = 0;

void dfs(unsigned n,bool k3,bool k5,bool k7){

	if(n>t)return; 

	if(k3&&k5&&k7){

		ans++;	

	}

	dfs(n*10+3,true,k5,k7);

	dfs(n*10+5,k3,true,k7);

	dfs(n*10+7,k3,k5,true);

}



int main(){

	scanf("%d", &t);

	dfs(0,false,false,false);

	

//	dfs(3,true,false,false);

//	dfs(5,false,true,false);

//	dfs(7,false,false,true);

	

	

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

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.8508457740222501x):
#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;

}
// Slower C++ solution:
#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);

}


// Faster C++ solution for the same problem (measured speedup: 6.654451891848748x):
#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

    }

}
// Slower C++ solution:
#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);

}


// Faster C++ solution for the same problem (measured speedup: 6.654451891848748x):
#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;

}