stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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);



}


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

#include <cstdio>

using namespace std;



struct SpecialNum{

    long long value;

    bool index3;

    bool index5;

    bool index7;

    SpecialNum(long long v,bool i3,bool i5,bool i7): value(v),index3(i3),index5(i5),index7(i7) {}

};





void LianXianDan(int &sum,SpecialNum x,int T){

    long long v=x.value;

    bool index3=x.index3;

    bool index5=x.index5;

    bool index7=x.index7;

    if(v>T){

        return;

    }

    else if(v<=T){

        if(index3 && index5 && index7)

            sum++;

        long long v3=v*10+3;

        SpecialNum x3=SpecialNum(v3,true,index5,index7);

        long long v5=v*10+5;

        SpecialNum x5=SpecialNum(v5,index3,true,index7);

        long long v7=v*10+7;

        SpecialNum x7=SpecialNum(v7,index3,index5,true);

        LianXianDan(sum,x3,T);

        LianXianDan(sum,x5,T);

        LianXianDan(sum,x7,T);

        return;

    }

}



int main()

{

    int T;

    while(cin>>T){

        SpecialNum x1=SpecialNum(0,false,false,false);

        int sum=0;

        LianXianDan(sum,x1,T);

        cout<<sum<<endl;

    }

    return 0;

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



}


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

using namespace std;

int ans = 0;

void find(int n, long long sub, bool t, bool f, bool s)

{

    if(sub > n)

    {

        return;

    }

    if(t && s && f)

    {

        ans++;

    }

    find(n, sub * 10 + 3, true, f, s);

    find(n, sub * 10 + 5, t, true, s);

    find(n, sub * 10 + 7, t, f, true);

}

int main()

{

    int n;

    cin >> n;

    find(n, 0, false, false, false);

    cout << ans << endl;

    return 0;

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

  

}






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

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

}

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

}
// Slower C++ solution:


#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;

}


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

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

}


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

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



}




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

}
// 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: 0.9520752207486943x):
//#define LOCAL

#define INPUT

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <vector>

#define MAXSIZE 10010



bool solve(int n){

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

    while(n){

        int temp = n % 10;

        if(temp == 3 || temp == 5 || temp == 7){

            n /= 10;

            if(temp == 3) a++;

            if(temp == 5) b++;

            if(temp == 7) c++;

        }

        else{

            return false;

        }

    }

    if(a&&b&&c){

        return true;

    }

    else{

        return false;

    }

}





int main(){

    #ifdef LOCAL

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

    #endif



    int t;

    scanf("%d", &t);



    if(t <= 356){

        printf("0\n");

        return 0;

    }

    int res = 0;

    for(int i = 357; i <= t; i += 2){

        if(solve(i)){

            res++;

        }

        if(i%100 == 37){

            i += 14;

        }

        if(i%100 == 57){

            i += 14;

        }

        if(i%100 == 77){

            i += 52;

        }

    }



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

















    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: 2.68860270163888x):
#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

    }

}
// 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.43983880003495x):
/*#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);

}
// 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.879825136000965x):
/*#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);

}
// 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.790527484090479x):
/*#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);

}
// 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.729426193778567x):
#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);

}