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

#include<string.h>

#include<algorithm>

#include<iostream>

#include<set>

#include<queue>

using namespace std;

int n;

int z;

int sum[1100000];

void dfs(int a,int b,int c,int num,int fl)

{

    if(num>1e9)

    {

        return ;

    }

    if(fl>9)

        return ;

    if(a&&b&&c)

    {

        sum[z++]=num;

        dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }

    else

    {

           dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }



}

int main()

{

    z=0;

    dfs(0,0,0,0,0);

    sort(sum,sum+z);

    int key;

    while(cin>>key)

    {



    int left = 0;

    int right =z-1;

    while (left <= right) {

        int mid = (left + right) / 2;

        if (sum[mid] > key) {

            right = mid - 1;

        }

        else {

            left = mid + 1;

        }

    }

    cout<<right+1<<endl;

    }



}




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

using namespace std;



int N,count=0;

void dfs(long long,unsigned char);

int main(){

    cin>>N;

    dfs(0,0);

    cout<<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<stdio.h>

#include<string.h>

#include<algorithm>

#include<iostream>

#include<set>

#include<queue>

using namespace std;

int n;

int z;

int sum[1100000];

void dfs(int a,int b,int c,int num,int fl)

{

    if(num>1e9)

    {

        return ;

    }

    if(fl>9)

        return ;

    if(a&&b&&c)

    {

        sum[z++]=num;

        dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }

    else

    {

           dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }



}

int main()

{

    z=0;

    dfs(0,0,0,0,0);

    sort(sum,sum+z);

    int key;

    while(cin>>key)

    {



    int left = 0;

    int right =z-1;

    while (left <= right) {

        int mid = (left + right) / 2;

        if (sum[mid] > key) {

            right = mid - 1;

        }

        else {

            left = mid + 1;

        }

    }

    cout<<right+1<<endl;

    }



}




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

#include<string.h>

#include<stdlib.h>

#include<iostream>

#include<algorithm>

#include<string>

#include<map>

#include<set>

#define maxn 1005

using namespace std;

typedef long long  LL;

int cnt=0;

LL n;

void f(LL num,int flag1,int flag2,int flag3)

{

    if(num<=n)

    {

        if(flag1&&flag2&&flag3)

            cnt++;

        f(num*10+3,1,flag2,flag3);

        f(num*10+5,flag1,1,flag3);

        f(num*10+7,flag1,flag2,1);

    }

    return ;

}

int main()

{



    scanf("%lld",&n);

    f(0,0,0,0);

    cout<<cnt<<endl;







    return 0;

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

}




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

#include<string.h>

#include<algorithm>

#include<iostream>

#include<set>

#include<queue>

using namespace std;

int n;

int z;

int sum[1100000];

void dfs(int a,int b,int c,int num,int fl)

{

    if(num>1e9)

    {

        return ;

    }

    if(fl>9)

        return ;

    if(a&&b&&c)

    {

        sum[z++]=num;

        dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }

    else

    {

           dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }



}

int main()

{

    z=0;

    dfs(0,0,0,0,0);

    sort(sum,sum+z);

    int key;

    while(cin>>key)

    {



    int left = 0;

    int right =z-1;

    while (left <= right) {

        int mid = (left + right) / 2;

        if (sum[mid] > key) {

            right = mid - 1;

        }

        else {

            left = mid + 1;

        }

    }

    cout<<right+1<<endl;

    }



}




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

using namespace std;

int N,count=0;

void dfs(long long,unsigned char);

int main()

{

    cin>>N;

    dfs(0,0);

    cout<<count<<endl;

    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

    }

}

	

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

#include <cstdio>

using namespace std;



long long int ans=0,t;



void f(long long int k,bool r3,bool r5,bool r7){

    if(t<k)

        return ;

    else if(r3&&r5&&r7)

        ans++;

    f(10*k+3,true,r5,r7);

    f(10*k+5,r3,true,r7);

    f(10*k+7,r3,r5,true);

}



int main()

{

    scanf("%lld",&t);

    f(3,true,false,false);

    f(5,false,true,false);

    f(7,false,false,true);

    printf("%lld",ans);

}


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

using namespace std;



int N,count=0;

void dfs(long long,unsigned char);

int main(){

    cin>>N;

    dfs(0,0);

    cout<<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

    }

}

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

#include<string.h>

#include<stdlib.h>

#include<iostream>

#include<algorithm>

#include<string>

#include<map>

#include<set>

#define maxn 1005

using namespace std;

typedef long long  LL;

int cnt=0;

LL n;

void f(LL num,int flag1,int flag2,int flag3)

{

    if(num<=n)

    {

        if(flag1&&flag2&&flag3)

            cnt++;

        f(num*10+3,1,flag2,flag3);

        f(num*10+5,flag1,1,flag3);

        f(num*10+7,flag1,flag2,1);

    }

    return ;

}

int main()

{



    scanf("%lld",&n);

    f(0,0,0,0);

    cout<<cnt<<endl;







    return 0;

}


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



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;

}




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

#include<string.h>

#include<algorithm>

#include<iostream>

#include<set>

#include<queue>

using namespace std;

int n;

int z;

int sum[1100000];

void dfs(int a,int b,int c,int num,int fl)

{

    if(num>1e9)

    {

        return ;

    }

    if(fl>9)

        return ;

    if(a&&b&&c)

    {

        sum[z++]=num;

        dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }

    else

    {

           dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }



}

int main()

{

    z=0;

    dfs(0,0,0,0,0);

    sort(sum,sum+z);

    int key;

    while(cin>>key)

    {



    int left = 0;

    int right =z-1;

    while (left <= right) {

        int mid = (left + right) / 2;

        if (sum[mid] > key) {

            right = mid - 1;

        }

        else {

            left = mid + 1;

        }

    }

    cout<<right+1<<endl;

    }



}




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

using namespace std;

int N,count=0;

void dfs(long long,unsigned char);

int main()

{

    cin>>N;

    dfs(0,0);

    cout<<count<<endl;

    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

    }

}

	

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

#include <cstdio>

using namespace std;



long long int ans=0,t;



void f(long long int k,bool r3,bool r5,bool r7){

    if(t<k)

        return ;

    else if(r3&&r5&&r7)

        ans++;

    f(10*k+3,true,r5,r7);

    f(10*k+5,r3,true,r7);

    f(10*k+7,r3,r5,true);

}



int main()

{

    scanf("%lld",&t);

    f(3,true,false,false);

    f(5,false,true,false);

    f(7,false,false,true);

    printf("%lld",ans);

}


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

using namespace std;



int N,count=0;

void dfs(long long,unsigned char);

int main(){

    cin>>N;

    dfs(0,0);

    cout<<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

    }

}

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

#include<string.h>

#include<stdlib.h>

#include<iostream>

#include<algorithm>

#include<string>

#include<map>

#include<set>

#define maxn 1005

using namespace std;

typedef long long  LL;

int cnt=0;

LL n;

void f(LL num,int flag1,int flag2,int flag3)

{

    if(num<=n)

    {

        if(flag1&&flag2&&flag3)

            cnt++;

        f(num*10+3,1,flag2,flag3);

        f(num*10+5,flag1,1,flag3);

        f(num*10+7,flag1,flag2,1);

    }

    return ;

}

int main()

{



    scanf("%lld",&n);

    f(0,0,0,0);

    cout<<cnt<<endl;







    return 0;

}


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

#include<string.h>

#include<algorithm>

#include<iostream>

#include<set>

#include<queue>

using namespace std;

int n;

int z;

int sum[1100000];

void dfs(int a,int b,int c,int num,int fl)

{

    if(num>1e9)

    {

        return ;

    }

    if(fl>9)

        return ;

    if(a&&b&&c)

    {

        sum[z++]=num;

        dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }

    else

    {

           dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }



}

int main()

{

    z=0;

    dfs(0,0,0,0,0);

    sort(sum,sum+z);

    int key;

    while(cin>>key)

    {



    int left = 0;

    int right =z-1;

    while (left <= right) {

        int mid = (left + right) / 2;

        if (sum[mid] > key) {

            right = mid - 1;

        }

        else {

            left = mid + 1;

        }

    }

    cout<<right+1<<endl;

    }



}




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

#include <string>

using namespace std;



typedef long long LL;



int Total = 0;

int n;





void DPS(LL abc)

{

	if (abc > n)

		return;



	string check = to_string(abc);

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

		Total++;

	DPS(abc * 10 + 5);

	DPS(abc * 10 + 3);

	DPS(abc * 10 + 7);

}



int main()

{

	cin >> n;

	DPS(0);

	cout << Total << endl;

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

}




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



using namespace std;

int t,count=0;

void dfs(long long num,int flag357){

    if(num <= t){

        if(flag357==07)

            count++;

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

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

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

    }

}

int main()

{

    scanf("%d",&t);

    dfs(0,0);

    printf("%d",count);

    return 0;

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

#include<string.h>

#include<algorithm>

#include<iostream>

#include<set>

#include<queue>

using namespace std;

int n;

int z;

int sum[1100000];

void dfs(int a,int b,int c,int num,int fl)

{

    if(num>1e9)

    {

        return ;

    }

    if(fl>9)

        return ;

    if(a&&b&&c)

    {

        sum[z++]=num;

        dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }

    else

    {

           dfs(1,b,c,num*10+3,fl+1);

        dfs(a,1,c,num*10+5,fl+1);

        dfs(a,b,1,num*10+7,fl+1);

    }



}

int main()

{

    z=0;

    dfs(0,0,0,0,0);

    sort(sum,sum+z);

    int key;

    while(cin>>key)

    {



    int left = 0;

    int right =z-1;

    while (left <= right) {

        int mid = (left + right) / 2;

        if (sum[mid] > key) {

            right = mid - 1;

        }

        else {

            left = mid + 1;

        }

    }

    cout<<right+1<<endl;

    }



}




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



using namespace std;

int t,count=0;

void dfs(long long num,int flag357){

    if(num <= t){

        if(flag357==07)

            count++;

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

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

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

    }

}

int main()

{

    scanf("%d",&t);

    dfs(0,0);

    printf("%d",count);

    return 0;

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

using namespace std;

int N,count=0;

void dfs(long long,unsigned char);

int main()

{

    cin>>N;

    dfs(0,0);

    cout<<count<<endl;

    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

    }

}

	

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



using namespace std;

int t,count=0;

void dfs(long long num,int flag357){

    if(num <= t){

        if(flag357==07)

            count++;

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

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

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

    }

}

int main()

{

    scanf("%d",&t);

    dfs(0,0);

    printf("%d",count);

    return 0;

}