qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

ans1, ans2 = 0,0

maxA = max(A)
B = [1]
t = 1
while t < maxA:
    t *= 2
    B.append(t)

d = dict()
for i in range(N):
    if A[i] in B:
        ans1 += 1
        M -= 1
    else:
        if A[i] in d:
            d[A[i]] += 1
        else:
            d[A[i]] = 1

for i in range(N):
    if A[i] not in B:
        t = 2**len(bin(A[i])[2::]) - A[i]
        if t in d:
            if d[t] > 0:
                ans2 += 1
                d[t] -= 1
                d[A[i]] -= 1

print(ans1+ans2)

# Fixed code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

ans1, ans2 = 0,0

maxA = max(A)
B = [1]
t = 1
while t < maxA:
    t *= 2
    B.append(t)

d = dict()
for i in range(N):
    if A[i] in d:
        d[A[i]] += 1
    else:
         d[A[i]] = 1

for i in range(N):
    t = 2**len(bin(A[i])[2::]) - A[i]
    if t in d:
        if t != A[i]:
            if d[t]>0 and d[A[i]]>0:
                ans2 += 1
                d[t] -= 1
                d[A[i]] -= 1
        else:
            if d[t] > 1:
                ans2 += 1
                d[t] -= 2


print(ans1+ans2)
# Buggy code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

from collections import Counter

acnt = Counter(a)

ans = 0
for ai in sorted(a,reverse=True):
    pair = (1<<(ai.bit_length())) - ai
    print(ai, pair)
    
    if acnt[ai] > 0 and acnt[pair] > 0:
        if ai == pair:
            temp = (acnt[ai] // 2)
            
        elif ai > pair:
            temp = min(acnt[ai], acnt[pair])
        
        ans += temp
        acnt[pair] -= temp
            
print(ans)

# Fixed code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

from collections import Counter

acnt = Counter(a)

ans = 0
temp = 0
for ai in sorted(a,reverse=True):
    pair = (1<<(ai.bit_length())) - ai
    
    if acnt[ai] > 0 and acnt[pair] > 0:
        if ai == pair:
            temp = (acnt[ai] // 2)
            ans += temp
            acnt[ai] -= (2*temp)
            
        elif ai > pair:
            temp = min(acnt[ai], acnt[pair])
            ans += temp
            acnt[ai] -= temp
            acnt[pair] -= temp
            
print(ans)
# Buggy code:
# -*- coding: utf-8 -*-
import collections

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
c=collections.Counter(A)

pairCounter=0

beki=7
nibeki=2**beki

for i in range(N):
  target = A[i]
  if c[target] < 0:
    continue
  c[target]= -1

  while (nibeki > target):
    beki-=1
    nibeki=2**beki

  pair = nibeki * 2 - target
  if pair in c.keys():
    c[pair]= -1
    pairCounter+=1

print(pairCounter)

# Fixed code:
# -*- coding: utf-8 -*-
import collections

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
c=collections.Counter(A)

pairCounter=0

beki=29
nibeki=2**beki

for i in range(N):
  target = A[i]
  if c[target] < 1:
    continue
  c[target]-= 1

  while (nibeki > target):
    beki-=1
    nibeki=2**beki

  pair = nibeki * 2 - target
  if pair in c.keys() and c[pair] > 0:
    c[pair]-= 1
    pairCounter+=1

print(pairCounter)
# Buggy code:
from collections import Counter

def ans_solve(N, As):
    C = Counter(As)
    ans = 0
    for d in As:
        n = (2 ** d.bit_length()) - d
        if d != n:
            if C[d] > 0 and C.get(n, 0) > 0:
                C[d] -= 1
                C[n] -= 1
                ans += 1
        else:
            ans += C[d]//2
            C[d] = 0
    return ans
 
 
if __name__ == "__main__":
    N = input()
    As = [int(c) for c in input().split()]
    print(ans_solve(N, As))

# Fixed code:
from collections import Counter

def ans_solve(N, As):
    C = Counter(As)
    ans = 0
    for d in reversed(sorted(As)):
        n = (2 ** d.bit_length()) - d
        if d != n:
            if C[d] > 0 and C.get(n, 0) > 0:
                C[d] -= 1
                C[n] -= 1
                ans += 1
        else:
            ans += C[d]//2
            C[d] = 0
    return ans
 
 
if __name__ == "__main__":
    N = input()
    As = [int(c) for c in input().split()]
    print(ans_solve(N, As))
# Buggy code:
import collections
N=int(input())
x=list(map(int,input().split()))
c=collections.Counter(x)
t=[2**i for i in range(len(str(bin(max(x)*2))[2:])+1)[::-1]]
count=0
start=0
x.sort()
for i in range(len(x))[::-1]:
    for j in range(len(t)):
        if t[j] < x[i]:
            break
        if t[j]-x[i] in c.keys():
            if t[j]-x[i] == x[i] and c[x[i]] >= 2:
                c[x[i]] -= 2
                count +=1
            elif c[t[j]-x[i]]>0 and c[x[i]]>0:
                c[t[j]-x[i]] -= 1
                c[x[i]] -= 1
                count+=1
print(count)

# Fixed code:
import collections
N=int(input())
x=list(map(int,input().split()))
c=collections.Counter(x)
t=[2**i for i in range(len(str(bin(max(x)*2))[2:])+1)[::-1]]
count=0
start=0
x.sort()
for i in range(len(x))[::-1]:
    for j in range(start,len(t)):
        if t[j] > 2*x[i]:
            start = j
        if t[j] < x[i]:
            break
        if t[j]-x[i] in c.keys():
            if t[j]-x[i] == x[i]:
                if c[x[i]] >= 2:
                    c[x[i]] -= 2
                    count +=1
            else:
                if c[t[j]-x[i]]>0 and c[x[i]]>0:
                    c[t[j]-x[i]] -= 1
                    c[x[i]] -= 1
                    count+=1
print(count)
# Buggy code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc 029 B
"""

from collections import Counter

n = int(input())
ali = list(map(int, input().split()))
ali.sort(reverse=True)

c = Counter(ali)
print(c)
ans = 0


def pow2(n):
    m = n
    tmp = 1
    while m > 0:
        tmp = tmp << 1
        m = m >> 1
    return tmp


while bool(c):
    m = list(c.elements())[0]
    n = pow2(m) - m
    print(m, n)
    c[m] -= 1
    c += Counter()
    if n in c:
        c[n] -= 1
        ans += 1
    c += Counter()

print(ans)








# Fixed code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc 029 B
"""

from collections import Counter

nn = int(input())
ali = list(map(int, input().split()))
ali.sort(reverse=True)

c = Counter(ali)
ans = 0


def pow2(n):
    m = n
    tmp = 1
    while m > 0:
        tmp = tmp << 1
        m = m >> 1
    return tmp


ii = 0
m = ali[ii]
while bool(c):
    while c[ali[ii]] == 0:
        ii += 1
    m = ali[ii]
    n = pow2(m) - m
    c[m] -= 1
    if c[m] <= 0:
        del c[m]
    if n in c:
        c[n] -= 1
        if c[n] <= 0:
            del c[n]
        ans += 1

print(ans)
# Buggy code:
from collections import defaultdict

def twosum(n):
  now = 1
  while n >= now:
    now *= 2
  return now - n
n=int(input())
a=sorted(list(map(int,input().split())))
d = defaultdict(int)
for i in a:
    d[i] += 1
ans = 0
for i in a[::-1]:
    if not d[i] > 0:
        continue
    find = twosum(i)
    if not d[find] > 0:
        continue
    ans += 1
    d[i] -= 1
    d[find] -= 1
print(ans)

# Fixed code:
from collections import defaultdict

def twosum(n):
  now = 1
  while n >= now:
    now *= 2
  return now - n
n = int(input())
a = sorted(list(map(int, input().split())))
d = defaultdict(int)
for i in a:
  d[i] += 1
ans = 0
for i in a[::-1]:
  d[i] -= 1
  find = twosum(i)
  if d[find] > 0 and d[i] >= 0:
    ans += 1
    d[find] -= 1
  else:
    d[i] += 1
print(ans)
# Buggy code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    D=defaultdict(int)
    for a in A:
        D[a]+=1

    A.sort(reverse=1)
    ans=0
    for a in A:
        k=a.bit_length()
        d=(1<<k)-a
        print(a,d)
        if(a!=d):
            if(D[d]):
                ans+=1
                D[a]-=1
                D[d]-=1
        else:
            if(D[d]>=2):
                ans+=1
                D[d]-=2
    print(ans)
resolve()

# Fixed code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    D=defaultdict(int)
    for a in A:
        D[a]+=1

    A.sort(reverse=1)
    ans=0
    for a in A:
        if(D[a]==0): continue
        k=a.bit_length()
        d=(1<<k)-a
        if(a!=d):
            if(D[d]):
                ans+=1
                D[a]-=1
                D[d]-=1
        else:
            if(D[d]>=2):
                ans+=1
                D[d]-=2
    print(ans)
resolve()
# Buggy code:
from collections import defaultdict
import os
def debug(*args): print(*args, file=sys.stderr)# os.environ.get("USER")
N=int(input())
A=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
#print(dd)
B=sorted(A,reverse=True)
ans=0
for x in B:
    debug(A)
    #print(x)
    if dd.get(x,-1)==0:
        continue
    s=len(bin(x))-3
    if x==1<<s:
        t=dd.get(x,-1)
        if t!=-1:
            ans+=t//2
            dd[x]-=(t//2)*2
            #print(ans)
            #print(dd)
    else:
        s+=1
        #print((1<<s)-x)
        t=dd.get((1<<s)-x,-1)
        if t>=1:
            ans+=1
            dd[x]-=1
            dd[(1<<s)-x]-=1
            #print(ans)
            #print(dd)
print(ans)


# Fixed code:
from collections import defaultdict
def debug(*args): print(*args, file=sys.stderr)
N=int(input())
A=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
#print(dd)
B=sorted(A,reverse=True)
ans=0
for x in B:
    #print(x)
    if dd.get(x,-1)==0:
        continue
    s=len(bin(x))-3
    if x==1<<s:
        t=dd.get(x,-1)
        if t!=-1:
            ans+=t//2
            dd[x]-=(t//2)*2
            #print(ans)
            #print(dd)
    else:
        s+=1
        #print((1<<s)-x)
        t=dd.get((1<<s)-x,-1)
        if t>=1:
            ans+=1
            dd[x]-=1
            dd[(1<<s)-x]-=1
            #print(ans)
            #print(dd)
print(ans)
# Buggy code:
import bisect

N = int(input())
A = [int(a) for a in input().split()]
A = sorted(A)

c = 0
for i in range(N - 1 , -1, -1):
    b = 1
    while b <= A[i]:
        b <<= 1
    
    j = bisect.bisect_left(A, b - A[i])
    if b - A[i] == A[j]:
        c += 1
        A[j] = A[j] - 0.5

print(c)


# Fixed code:
import bisect

N = int(input())
A = [int(a) for a in input().split()]
A = sorted(A)

c = 0
for i in range(N - 1 , -1, -1):
    if A[i] == int(A[i]):
        b = 1
        while b <= A[i]:
            b <<= 1

        j = bisect.bisect_left(A, b - A[i])
        if i > j:
            if b - A[i] == A[j]:
                c += 1
                A[j] = A[j] - 0.5
                A[i] = A[i] + 0.5
print(c)
# Buggy code:
N = int(input())
ball = list(map(int, input().split()))
ball.sort(reverse = True)
ok = {}
for x in ball:
    if x in ok:
        dic[x] += 1
    else:
        dic[x] = 1
ans = 0
for x in ball:
    if ok[x] != 0:
        y = 2**(x.bit_length()) - x
        if ok[y] != 0:
            if y == x and ok[y] == 1: 
                continue
            ans += 1
            dic[x] -= 1
            dic[y] -= 1
print(ans)

# Fixed code:
N = int(input())
ball = list(map(int, input().split()))
ball.sort(reverse = True)
ok = {}
for x in ball:
    if x in ok:
        ok[x] += 1
    else:
        ok[x] = 1
ans = 0
for x in ball:
    if ok[x] != 0:
        y = 2**(x.bit_length()) - x
        if y in ok:
            if ok[y] != 0:
                if y == x and ok[y] == 1: 
                    continue
                ans += 1
                ok[x] -= 1
                ok[y] -= 1
print(ans)
# Buggy code:
from heapq import heappush, heappop, heapify
from bisect import bisect_right

pow2 = [2]
for i in range(29):
  pow2.append(pow2[-1]*2)

N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1

A = [-a for a in A]
heapify(A)
ans = 0
while A:
  a = - heappop(A)
  if d[a] == 0:
    continue
  pair = pow2[bisect_right(pow2, a)] - a
  if pair in d and d[pair] > 0:
    ans += 1
    d[pair] -= 1
    d[a] -= 1

print(ans)

# Fixed code:
from heapq import heappush, heappop, heapify
from bisect import bisect_right

pow2 = [2]
for i in range(29):
  pow2.append(pow2[-1]*2)

N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1

A = [-a for a in A]
heapify(A)
ans = 0
while A:
  a = - heappop(A)
  if d[a] == 0:
    continue
  pair = pow2[bisect_right(pow2, a)] - a
  if a == pair:
    if d[a] >= 2:
      d[a] -= 2
      ans += 1
  elif pair in d and d[pair] > 0:
    ans += 1
    d[pair] -= 1
    d[a] -= 1

print(ans)
# Buggy code:
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans =0
for a in A:
    b = 2**(a.bit_length())-a
    if b in d:
        if d[b] >=1 and d[a] >= 1:
            ans += 1 
            d[b]-= 1
            d[a]-= 1

print(ans)
            

# Fixed code:
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans =0
for a in A:
    b = 2**(a.bit_length())-a
    if b in d:
        if d[b] >=1 and d[a] >= 1:
          if a == b and d[b] ==1:
            continue
          ans += 1 
          d[b]-= 1
          d[a]-= 1

print(ans)
# Buggy code:
import bisect
N = int(input())
*A, = map(int,input().split())
B = {}
for a in A:B[a] = B.get(a,0) + 1
B = sorted(map(list,B.items()))
bl = bisect.bisect_left

ans = 0
while 1:
    b,n = B.pop()
    if not B : break
    c = (1<<(len(bin(b))-2)) - b
    i = bl(B,[c,0])
    if B[i][0] == c:
        m = min(n,B[i][1])
        ans += m
        B[i][1] -= m
print(ans)

# Fixed code:
import bisect
N = int(input())
*A, = map(int,input().split())
B = {}
for a in A:B[a] = B.get(a,0) + 1
B = sorted(map(list,B.items()))
bl = bisect.bisect_left

ans = 0
while B:
    b,n = B.pop()
    c = (1<<(len(bin(b))-2)) - b
    if c==b :
        ans += n//2
        continue
    i = bl(B,[c,0])
    if i>=len(B): continue
    if B[i][0] == c:
        m = min(n,B[i][1])
        ans += m
        B[i][1] -= m
print(ans)
# Buggy code:
from itertools import *
import copy
from collections import *


N=int(input())
A=list(map(int,input().split()))
idle_max=10**9
peki2=[]
for i in range(1,100):
    a=2**i
    if a<=2*idle_max:
        peki2.append(a)
peki2.sort(reverse=True)
lst=[[],[]]
for a in A:
    if a%2:
        lst[1].append(a)
    else:
        lst[0].append(a)

lst[0].sort(reverse=True)
lst[1].sort(reverse=True)
setlst=[set(lst[0]),set(lst[1])]
Counerlst=[Counter(lst[0]),Counter(lst[1])]

count=0
for l in range(2):
    for n in lst[l]:
        if n in setlst[l]:
            for p in peki2:
                a=p-n
                if a in setlst[l]:
                    count+=1
                    Counerlst[l][a]-=1
                    Counerlst[l][n]-=1
                    if Counerlst[l][a]==0:
                        setlst[l].remove(a)
                    if Counerlst[l][n]==0:
                        setlst[l].remove(n)
                    break
print(count)


# Fixed code:
from itertools import *
import copy
from collections import *


N=int(input())
A=list(map(int,input().split()))
idle_max=10**9
peki2=[]
for i in range(1,100):
    a=2**i
    if a<=2*idle_max:
        peki2.append(a)
peki2.sort(reverse=True)
lst=[[],[]]
for a in A:
    if a%2:
        lst[1].append(a)
    else:
        lst[0].append(a)

lst[0].sort(reverse=True)
lst[1].sort(reverse=True)
setlst=[set(lst[0]),set(lst[1])]
Counerlst=[Counter(lst[0]),Counter(lst[1])]

count=0
for l in range(2):
    for n in lst[l]:
        if n in setlst[l]:
            for p in peki2:
                a=p-n

                if a in setlst[l]:
                    if n==a:
                        if Counerlst[l][n]>=2:
                            count+=1
                            Counerlst[l][n]-=2
                            if Counerlst[l][n]==0:
                                setlst[l].remove(n)
                    else:

                        count+=1
                        Counerlst[l][a]-=1
                        Counerlst[l][n]-=1
                        if Counerlst[l][a]==0:
                            setlst[l].remove(a)
                        if Counerlst[l][n]==0:
                            setlst[l].remove(n)
                    break
print(count)
# Buggy code:
n = int(input())
def dfs(s):
  if int(s) > n:
    return 0
  ret = 1 if all([s.count(c) for c in '753']) else 0
  for c in '753':
    ret += dfs(s+c)
  return ret
print(ret('0'))

# Fixed code:
n = int(input())
def dfs(s):
  if int(s) > n:
    return 0
  ret = 1 if all([s.count(c) > 0 for c in '753']) else 0
  for c in '753':
    ret += dfs(s+c)
  return ret
print(dfs('0'))
# Buggy code:
N = int(input())

def dfs(s): 
    print(s)
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s + c)
    return ret

print(dfs('0')) 

# Fixed code:
N = int(input())

def num(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += num(s+c)
    return ret

print(num('0'))
# Buggy code:
N=999999999
l=len(str(N))

def calc(st):
    st=str(st)
    if(len(st)>l):return 0
    t=calc(st+"3")
    f=calc(st+"5")
    s=calc(st+"7")
    o=0
    if(st.find("7")>=0 and st.find("5")>=0 and st.find("3")>=0 and int(st)<=N):
        o=1
    return (t+f+s+o)

print(calc(str()))







# Fixed code:
N=int(input())
l=len(str(N))

def calc(st):
    st=str(st)
    if(len(st)>l):return 0
    t=calc(st+"3")
    f=calc(st+"5")
    s=calc(st+"7")
    o=0
    if(st.find("7")>=0 and st.find("5")>=0 and st.find("3")>=0 and int(st)<=N):
        o=1
    return (t+f+s+o)

print(calc(str()))
# Buggy code:
n = int(input())

def dts(s):
  if int(s) > n:
    return 0
  if ret = 1 if all(s.count(_) for _ in '753') else 0
  for i in '753':
    ret += dts(s+i)
  return ret
  
dts('0')

# Fixed code:
n = int(input())

def dts(s):
  if int(s) > n:
    return 0
  ret = 1 if all(s.count(_) for _ in '753') else 0
  for i in '753':
    ret += dts(s+i)
  return ret
  
print(dts('0'))
# Buggy code:
def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret
print(dfs('0'))

# Fixed code:
N = int(input())


def dfs(s):
    if int(s) > N:
        return 0
    if s == '0':
        s = ''
    ret = 0
    if all(s.count(c) > 0 for c in '753'):
        ret += 1
    for c in '753':
        ret += dfs(c + s)
    return ret


print(dfs('0'))
# Buggy code:
import itertools
n=int(input())

keta=len(str(n))
hako=[]
for i in range(3,keta+1):
    for c in list(itertools.product(["7","5","3"],repeat=i)):
        if len(set(c))==3:
            a=int("".join(c))
            hako.append(a)
if n in hako:
    hako.sort()
    k=hako.index(n)
    b=hako[:k]
    print(len(b)) 
else:
    hako.append(n)
    hako.sort()
    k=hako.index(n)
    b=hako[:k]
    print(int(len(b))+1)

# Fixed code:
import itertools
n=int(input())

keta=len(str(n))
hako=[]
for i in range(3,keta+1):
    for c in list(itertools.product(["7","5","3"],repeat=i)):
        if len(set(c))==3:
            a=int("".join(c))
            hako.append(a)
if n in hako:
    hako.sort()
    k=hako.index(n)
    b=hako[:k]
    print(len(b)+1) 
else:
    hako.append(n)
    hako.sort()
    k=hako.index(n)
    b=hako[:k]
    print(int(len(b)))
# Buggy code:
n = int(input())
l = [True]*(10**9+1)
count = 0
stack = [3, 5, 7]
def check(n, k):
  s = str(n)
  if "3" in s and "5" in s and "7" in s:
    return True
  else:
    return False
while len(stack)>0:
  now = stack.pop()
  if l[now]:
    l[now] = False
    if check(now):
      count += 1
    if now < n:
      stack.append(now*10+3)
      stack.append(now*10+5)
      stack.append(now*10+7)
      stack.append(3*10**len(str(now))+now)
      stack.append(5*10**len(str(now))+now)
      stack.append(7*10**len(str(now))+now)
print(count)
      

# Fixed code:
n = int(input())
count = 0
stack = [0]
def check(n):
  s = str(n)
  if "3" in s and "5" in s and "7" in s:
    return True
  else:
    return False
while len(stack)>0:
  now = stack.pop()
  if check(now) and now <= n:
    count += 1
  if now < n:
    stack.append(now*10+3)
    stack.append(now*10+5)
    stack.append(now*10+7)
print(count)
# Buggy code:
n = int(input())

def dfs(s):
    print(s)
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))

# Fixed code:
N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c)>0 for c in "753") else 0
    for c in "753":
        ret += dfs(s+c)
    return  ret
print(dfs("0"))
# Buggy code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
from decorator import stop_watch


@stop_watch
def solve(N):
    dq = deque([(3, [1, 0, 0]), (5, [0, 1, 0]), (7, [0, 0, 1])])
    ans = 0
    while dq:
        num, check = dq.popleft()
        if num > N:
            break
        if sum(check) == 3:
            ans += 1
        for i in (3, 5, 7):
            new_num = num * 10 + i
            if new_num > N:
                break
            new_check = check.copy()
            if i == 3:
                new_check[0] = 1
            elif i == 5:
                new_check[1] = 1
            elif i == 7:
                new_check[2] = 1
            dq.append((new_num, new_check))
    print(ans)


if __name__ == '__main__':
    N = int(input())
    solve(N)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


# Fixed code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N):
    dq = deque([(3, [1, 0, 0]), (5, [0, 1, 0]), (7, [0, 0, 1])])
    ans = 0
    while dq:
        num, check = dq.popleft()
        if num > N:
            break
        if sum(check) == 3:
            ans += 1
        for i in (3, 5, 7):
            new_num = num * 10 + i
            if new_num > N:
                break
            new_check = check.copy()
            if i == 3:
                new_check[0] = 1
            elif i == 5:
                new_check[1] = 1
            elif i == 7:
                new_check[2] = 1
            dq.append((new_num, new_check))
    print(ans)


if __name__ == '__main__':
    N = int(input())
    solve(N)

    # # test
    # from random import randint
    # from func import random_str
    # solve()