Problem:


Score : 300 points

Problem Statement

You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?

Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:

When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.

Constraints

1 \leq N < 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).

Sample Input 1

575

Sample Output 1

4

There are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.

Sample Input 2

3600

Sample Output 2

13

There are 13 Shichi-Go-San numbers not greater than 3600: the above four numbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.

Sample Input 3

999999999

Sample Output 3

26484



Sample input:
575


Sample output:
4

Submission status: Wrong Answer

Solution code:
N = input()
n = len(N)
ans = 0
if n < 3:
    print(0)
    exit()
if n > 3:
    for i in range(3,n):
        ans += 3**i - 3*(2**i) + 3
a = int(N[0])
if a > 3:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
if a > 5:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
if a > 7:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
b = int(N[1])
c = int(N[2])
if a == 3:
    if b > 3:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
    if b > 5:
        ans += 3**(n-2) - (2**(n-2))
    if b > 7:
        ans += 3**(n-2) - (2**(n-2))
    if b == 3:
        if c > 3:
            ans += 3**(n-3) - 2*(2**(n-3)) + 1
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 5:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3)
    if b == 7:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3)
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
elif a == 5:
    if b > 3:
        ans += 3**(n-2) - (2**(n-2))
    if b > 5:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
    if b > 7:
        ans += 3**(n-2) - (2**(n-2))
    if b == 3:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3)
    if b == 5:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-2) - 2*(2**(n-2)) + 1
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 7:
        if c > 3:
            ans += 3**(n-3)
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
elif a == 7:
    if b > 3:
        ans += 3**(n-2) - (2**(n-2))
    if b > 5:
        ans += 3**(n-2) - (2**(n-2))
    if b > 7:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
    if b == 3:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3)
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 5:
        if c > 3:
            ans += 3**(n-3)
        if c > 5:
            ans += 3**(n-2) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 7:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-2) - 2*(2**(n-2)) + 1
    
if (a == 3 or a == 5 or a == 7) and (b == 3 or b == 5 or b == 7) and (c == 3 or c == 5 or c == 7):
    d = (a*100 + b * 10 + c) * 10**(n-3)
    e = int(N) + 1
    t = {"3","5","7"}
    for i in range(d,e,2):
        u = set(str(i))
        if u == t:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

ans="0"
cnt=0
l=["3","5","7"]

def dfs(now):
  global cnt

  if n<=int(now):
    return now
  now=str(now)
  if 1<=now.count("3") and 1<=now.count("5") and 1<=now.count("7"):
    cnt+=1

  for i in l:
    a=now+i
    dfs(a)
  
  return cnt
print(dfs(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0
for i in range(1, N):
  num = str(i)
  if len(set(num)) == 3:
    if "3" in num and "5" in num and "7" in num:
      ans += 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
count = 0
for i in range(3, len(str(N)) + 1):
    for j in itertools.product('753', repeat=i):
        if int(''.join(j)) < N and '3' in str(j) and '5'in str(j) and '7' in str(j):
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())

products = []
for i in range(3, len(str(n)) + 1):
    tmp = list(itertools.product(['3', '5', '7'], repeat = i))
    tmp2 = list(map(''.join, tmp))
    tmp3 = list(map(int, tmp2))
    tmp4 = [j for j in tmp3 if j < n]
    products = products + tmp4

out = 0
for p in products:
    str_p = str(p)
    if ('3' in str_p) and ('5' in str_p) and ('7' in str_p):
        out += 1
print(out)

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
S = deque([3, 5, 7])
ans = 0
for _ in range(3**9):
    a = S.popleft()
    if a <= N:
        tmp = a
        j3, j5, j7 = False, False, False
        while tmp > 0:
            if tmp%10 == 3:
                j3 = True
            elif tmp%10 == 5:
                j5 = True
            else:
                j7 = True
            tmp //= 10
        if j3 and j5 and j7:
            ans += 1
    S.append(a*10+3)
    S.append(a*10+5)
    S.append(a*10+7)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
S = deque([3, 5, 7])
ans = 0
for _ in range(3**8):
    a = S.popleft()
    if a <= N:
        tmp = a
        j3, j5, j7 = False, False, False
        while tmp > 0:
            if tmp%10 == 3:
                j3 = True
            elif tmp%10 == 5:
                j5 = True
            else:
                j7 = True
            tmp //= 10
        if j3 and j5 and j7:
            ans += 1
    S.append(a*10+3)
    S.append(a*10+5)
    S.append(a*10+7)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import bisect
n=int(input())
sft=deque()
x=deque([3,5,7])
while x:
    a=x.popleft()
    if 100<=a<=777:
        sft.append(a)
    else:
        x.append(a*10+3)
        x.append(a*10+5)
        x.append(a*10+7)
ans=[]
for i in range(3**11):
    a=sft.popleft()
    ans.append(a)
    sft.append(a*10+3)
    sft.append(a*10+5)
    sft.append(a*10+7)
count=0
for i in ans:
    if n<=i:
        print(count)
        break
    else:
        ss=str(i)
        if "3" in ss and "5" in ss and "7" in ss:
            count+=1

Submission status: Wrong Answer

Solution code:
N = int(input())
n = len(str(N)) - 1
ans = 0
for i in range(3, n+1):
  ans += 3**i - (2**i)*3 + 3

t = 3**n - 2**(n+1) + 1
m = 3**(n-1) - 2**n + 1

if int(str(N)[0]) == 3:
  if int(str(N)[1]) == 3:
    for i in range(33*(10**(n-1)), N+1):
      s = set([j for j in str(i)])
      if ('5' in s) and ('7' in s) and (len(s)==3):
        ans += 1
  elif int(str(N)[1]) == 4:
    ans += m
  elif int(str(N)[1]) == 5:
    ans += m
    for i in range(35*(10**(n-1)), N+1):
      s = set([j for j in str(i)])
      if ('5' in s) and ('7' in s) and (len(s)==3):
        ans += 1
  elif int(str(N)[1]) == 6:
    ans += 2*m
  elif int(str(N)[1]) == 7:
    ans += 2*m
    for i in range(37*(10**(n-1)), N+1):
      s = set([j for j in str(i)])
      if ('5' in s) and ('7' in s) and (len(s)==3):
        ans += 1
  elif int(str(N)[1]) > 7:
    ans += 3*m
elif int(str(N)[0]) == 4:
  ans += t
elif int(str(N)[0]) == 5:
  if int(str(N)[1]) == 3:
    for i in range(53*(10**(n-1)), N+1):
      s = set([j for j in str(i)])
      if ('5' in s) and ('7' in s) and (len(s)==3):
        ans += 1
  elif int(str(N)[1]) == 4:
    ans += m
  elif int(str(N)[1]) == 5:
    ans += m
    for i in range(55*(10**(n-1)), N+1):
      s = set([j for j in str(i)])
      if ('5' in s) and ('7' in s) and (len(s)==3):
        ans += 1
  elif int(str(N)[1]) == 6:
    ans += 2*m
  elif int(str(N)[1]) == 7:
    ans += 2*m
    for i in range(57*(10**(n-1)), N+1):
      s = set([j for j in str(i)])
      if ('5' in s) and ('7' in s) and (len(s)==3):
        ans += 1
  elif int(str(N)[1]) > 7:
    ans += 3*m
elif int(str(N)[0]) == 6:
  ans += 2*t
elif int(str(N)[0]) == 7:
  if int(str(N)[1]) == 3:
    for i in range(73*(10**(n-1)), N+1):
      s = set([j for j in str(i)])
      if ('5' in s) and ('7' in s) and (len(s)==3):
        ans += 1
  elif int(str(N)[1]) == 4:
    ans += m
  elif int(str(N)[1]) == 5:
    ans += m
    for i in range(75*(10**(n-1)), N+1):
      s = set([j for j in str(i)])
      if ('5' in s) and ('7' in s) and (len(s)==3):
        ans += 1
  elif int(str(N)[1]) == 6:
    ans += 2*m
  elif int(str(N)[1]) == 7:
    ans += 2*m
    for i in range(77*(10**(n-1)), N+1):
      s = set([j for j in str(i)])
      if ('5' in s) and ('7' in s) and (len(s)==3):
        ans += 1
  elif int(str(N)[1]) > 7:
    ans += 3*m
elif int(str(N)[0]) > 7:
  ans += 3*t
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
nums = ['3', '5', '7']
now = ''
q = deque(nums)
ans = 0
flag = True
while flag:
    n = q.popleft()
    for num in nums:
        tmp = n
        tmp += num
        if int(tmp) >= N:
            flag = False
            break
        if '3' in tmp and '5' in tmp and '7' in tmp:
            ans += 1
        q.append(tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
nums = ['3', '5', '7']
now = ''
q = deque(nums)
ans = 0
flag = True
while flag:
    n = q.popleft()
    for num in nums:
        tmp = n
        tmp += num
        if '3' in tmp and '5' in tmp and '7' in tmp:
            ans += 1
        if int(tmp) >= N:
            flag = False
            break
        q.append(tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

dic = [3, 5, 7]

ans = list()
def dfs(s):
    if s:
        if int(s) < N:
            if len(set(s)) == 3:
                ans.append(s)
        else:
            return
    dfs(s+"3")
    dfs(s+"5")
    dfs(s+"7")

dfs("")
print(len(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())

dic = [3, 5, 7]

ans = set()
def dfs(s):
    if s:
        if int(s) < N:
            if len(set(s)) == 3:
                ans.add(s)
        else:
            return
    dfs(s+"3")
    dfs(s+"5")
    dfs(s+"7")

dfs("")
print(len(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
num=[3,5,7]
#a[0]=3,a[1]=5,a[7]=5
ans=[3,5,7]
answ=[]
for i1 in range(3):
  for i2 in range(3):
    for i3 in range(3):
      a=set([i1,i2,i3])
      if len(a)>2:
        answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])))
      for i4 in range(3):
        a=set([i1,i2,i3,i4])
        if len(a)>2:
          answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i4])))
        for i5 in range(3):
          a=set([i1,i2,i3,i4,i5])
          if len(a)>2:
            answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i5])+str(num[i4])))
          for i6 in range(3):
            a=set([i1,i2,i3,i4,i5,i6])
            if len(a)>2:
              answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i6])+str(num[i5])+str(num[i4])))
            for i7 in range(3):
              a=set([i1,i2,i3,i4,i5,i6,i7])
              if len(a)>2:
                answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
              for i8 in range(3):
                a=set([i1,i2,i3,i4,i5,i6,i7,i8])
                if len(a)>2:
                  answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
                for i9 in range(3):
                  a=set([i1,i2,i3,i4,i5,i6,i7,i8,i9])
                  if len(a)>2:
                    answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i9])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
answ.sort()
left=0
right=len(answ)
while right-left>1:
  mid=(left+right)//2
  
  if n<answ[mid]:
    right=mid
  else:
    left=mid
if 357>left:
  print(0)
else:
  print(left+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
num=[3,5,7]
#a[0]=3,a[1]=5,a[7]=5
ans=[3,5,7]
answ=[]
for i1 in range(3):
  for i2 in range(3):
    for i3 in range(3):
      a=set([i1,i2,i3])
      if len(a)>2:
        answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])))
      for i4 in range(3):
        a=set([i1,i2,i3,i4])
        if len(a)>2:
          answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i4])))
        for i5 in range(3):
          a=set([i1,i2,i3,i4,i5])
          if len(a)>2:
            answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i5])+str(num[i4])))
          for i6 in range(3):
            a=set([i1,i2,i3,i4,i5,i6])
            if len(a)>2:
              answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i6])+str(num[i5])+str(num[i4])))
            for i7 in range(3):
              a=set([i1,i2,i3,i4,i5,i6,i7])
              if len(a)>2:
                answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
              for i8 in range(3):
                a=set([i1,i2,i3,i4,i5,i6,i7,i8])
                if len(a)>2:
                  answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
                for i9 in range(3):
                  a=set([i1,i2,i3,i4,i5,i6,i7,i8,i9])
                  if len(a)>2:
                    answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i9])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
answ.sort()
left=0
right=len(answ)
while right-left>1:
  mid=(left+right)//2
  
  if n<answ[mid]:
    right=mid
  else:
    left=mid
print(left+1)

Submission status: Wrong Answer

Solution code:
N = int(input())


ans = 0
for i in range(N):
    char = str(i)
    n = char.count("7")
    m = char.count("5")
    l = char.count("3")

    if (n > 0) and (m > 0) and (l > 0) and (n + m + l == len(char)):
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
a = lambda x,y:3**x - y*2**x + y -1+(y%3==0)
ans = 0
ln = len(n)
s = set()
b = True
for p, i in enumerate(n):
    m = int(i) 
    if b:
        if m > 7:
            ans += a(ln-p-1,3-len(s|{7}))
        if m > 5:
            ans += a(ln-p-1,3-len(s|{5}))
        if m > 3:
            ans += a(ln-p-1,3-len(s|{3}))
        if m in (7,5,3):
            s.add(m)
            if ln > p+1:
                ans += len(s)==3
        else:
            b = False
    if ln > p +1:
        ans += a(ln - p -1,3)
print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
a = lambda x,y:3**x - y*2**x + y -1+(y%3==0)
ans = 0
ln = len(n)
s = set()
b = True
for p, i in enumerate(n):
    m = int(i) 
    if b:
        if m > 7:
            ans += a(ln-p-1,3-len(s|{7}))
        if m > 5:
            ans += a(ln-p-1,3-len(s|{5}))
        if m > 3:
            ans += a(ln-p-1,3-len(s|{3}))
        if m in (7,5,3):
            s.add(m)
        else:
            b = False
    if ln > p +1:
        ans += a(ln - p -1,3)
print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
a = lambda x,y:3**x - y*2**x + y -1+(y%3==0)
ans = 0
ln = len(n)
s = set()
b = True
for p, i in enumerate(n):
    m = int(i) 
    if b:
        if m > 7:
            ans += a(ln-p-1,3-len(s|{7}))
        if m > 5:
            ans += a(ln-p-1,3-len(s|{5}))
        if m > 3:
            ans += a(ln-p-1,3-len(s|{3}))
        if m in (7,5,3):
            s.add(m)
        else:
            b = False
    ans += a(ln - p -1,3)
print(ans-1)

Submission status: Wrong Answer

Solution code:
import itertools

n = input()
ans =0

    
if len(n) < 3:
    ans = 0
elif len(n) == 3:
    con = []
    for i in range(len(n)-2):
        con.append(3)
        con.append(5)
        con.append(7)
    p_list = list(itertools.permutations(con, len(n)))

else:
    if int('7'*len(n)) <= int(n):
        ans = 3**(len(n))- 3*2**(len(n)) + 3
    elif int('3'*len(n)) > int(n):
        ans = 0
    else:
        con = []
        for i in range(len(n)):
            con.append(0)
        con_num = []
        for i in range(3**len(n)):
            con[-1] +=1
            for j in range(len(n)-1,0,-1):
                if con[j] == 3:
                    con[j-1] +=1
                    con[j] = 0
            if con[0] == 0:
                b = '3'
            elif con[0] == 1:
                b= '5'
            elif con[0] == 2:
                b = '7'
            for j in range(1,len(n)):
                if con[j] == 0:
                    a = '3'
                elif con[j] == 1:
                    a = '5'
                elif con[j] == 2:
                    a = '7'
                b += a
            c = list(b)
            if c.count('3') != 0 and c.count('5') != 0 and c.count('7') != 0 and len(b) == len(n):
                con_num.append(int(b))
        for i in range(len(con_num)):
            if int(n) >= con_num[i]:
                ans +=1
    for i in range(3,len(n)):
        ans += 3**(i)- 3*2**(i) + 3
    

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = []
import itertools
for j in range(3,10):
    for i in itertools.product([3,5,7],repeat=j):
        if i.count(3)<1 or i.count(5)<1 or i.count(7)<1:
            pass
        else:
            li += [int(''.join(map(str,i)))]

import bisect
print(bisect.bisect_left(li,n))

Submission status: Wrong Answer

Solution code:
# a brute bitch
from bisect import bisect_right
def comb (n,s):
    capt = []; ind = n; 
    stp = n+1; boo = ""
    while bk[0] < 1:
        if bk[ind] < s:
            boo += dip[bk[ind]];
            bk[ind]+=1; 
            if ind + 1 == stp:
                if '7' in boo and '3' in boo and '5' in boo:
                    capt.append(boo); 
                boo = boo[:len(boo)-1];
            ind += 1 if ind + 1 < stp else 0
        else: bk[ind] = 0;ind -= 1; boo = boo[:len(boo)-1]
    return bisect_right(capt,val)
val = input()
bk = [0]*(len(val)+1); dip = ['3','5','7']
print(comb(len(val),3))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans, q = 0, ["3", "5", "7"]

while q:
    p = q.pop()
    for s in ["3", "5", "7"]:
        t = p + s
        if int(t) <= n:
            q.append(str(t))
            if list(set(list(t))) == ["3", "5", "7"]:
                ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product

n = input()

if int(n) < 100:
    print(0)
    
ans = 0
    
for i in range(3,len(n)+1):
    s = list(product("753",repeat=i))
    for combi in s:
        n_s = "".join(combi)
        if int(n_s) >= int(n):
            continue
        if ("7" in combi) and ("5" in combi) and ("3" in combi):
            ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product

n = input()

if int(n) < 100:
    print(0)
    
ans = 0
    
for i in range(3,len(n)+1):
    s = list(product("753",repeat=i))
    for combi in s:
        n_s = "".join(combi)
        if int(n_s) > int(n):
            continue
        if ("7" in combi) and ("5" in combi) and ("3" in combi):
            ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())

N = I()

A = [0]*10  # A[i] = i桁の七五三数の個数
for i in range(1,10):
    A[i] = 3**i-3*2**i+3

d = len(str(N))  # Nの桁数
ans = sum(A[i] for i in range(1,d))  # d桁未満の七五三数の個数
B = []  # d桁の七五三数list

from itertools import product

for a in list(product(['3','5','7'],repeat=d)):
    if len(set(a)) == 3:
        b = ''
        for i in range(d):
            b += a[i]
        B.append(int(b))

print(ans+sum(n < N for n in B))

Submission status: Wrong Answer

Solution code:
N = int(input())

def dfs(s):
  #文字列sで始まる七五三数の個数
  if int(s) > N:
    return 0
  
  # s自体が七五三数なら+1
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0
  
  return sum((dfs(s+c) for c in '753'))

print(dfs('0'))

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
a=['3','5','7','0']
cnt=[]
for i1 in range(4):
        for i2 in range(4):
            for i3 in range(4):
                for i4 in range(4):
                    for i5 in range(4):
                        for i6 in range(4):
                            for i7 in range(4):
                                for i8 in range(4):
                                    for i9 in range(3):
                                            cnt.append(a[i1])
                                            cnt.append(a[i2])
                                            cnt.append(a[i3])
                                            cnt.append(a[i4])
                                            cnt.append(a[i5])
                                            cnt.append(a[i6])
                                            cnt.append(a[i7])
                                            cnt.append(a[i8])
                                            if int(a[i1]+a[i2]+a[i3]+a[i4]+a[i5]+a[i6]+a[i7]+a[i8]+a[i9])<=n and cnt.count('0')<2:
                                                ans+=1
                                            cnt=[]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
a=['3','5','7','0']
cnt=[]
for i1 in range(4):
        for i2 in range(4):
            for i3 in range(4):
                for i4 in range(4):
                    for i5 in range(4):
                        for i6 in range(4):
                            for i7 in range(4):
                                for i8 in range(4):
                                    for i9 in range(3):
                                            cnt.append(a[i1])
                                            cnt.append(a[i2])
                                            cnt.append(a[i3])
                                            cnt.append(a[i4])
                                            cnt.append(a[i5])
                                            cnt.append(a[i6])
                                            cnt.append(a[i7])
                                            cnt.append(a[i8])
                                            if int(a[i1]+a[i2]+a[i3]+a[i4]+a[i5]+a[i6]+a[i7]+a[i8]+a[i9])<=n and cnt.count('0')<2:
                                                ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product
N = int(input())
cnt = 0
num = ["3","5","7"]
for k in range(3,9):
    for x in product(num,repeat=k):
        if x.count("3")>=1 and x.count("5")>=1 and x.count("7")>=1:
            if int("".join(x))<=N:
                cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
# abc114_c.py
# https://atcoder.jp/contests/abc114/tasks/abc114_c

# C - 755 /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文

# 整数 Nが与えられます。1 以上 N以下の整数のうち、七五三数 は何個あるでしょうか？
# ここで、七五三数とは以下の条件を満たす正の整数です。
#     十進法で表記したとき、数字 7, 5, 3 がそれぞれ 1回以上現れ、これら以外の数字は現れない。

# 制約
#     1≤N<109
#     Nは整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N

# 出力
# 1以上 N以下の七五三数の個数を出力せよ。

# 入力例 1
# 575

# 出力例 1
# 4

# 575
# 以下の七五三数は、357,375,537,573 の 4個です。

# 入力例 2
# 3600

# 出力例 2
# 13

# 3600以下の七五三数は、上記の 4 個と 735,753,3357,3375,3537,3557,3573,3575,3577 の計 13個です。

# 入力例 3
# 999999999

# 出力例 3
# 26484


def calculation(lines):
    X = lines[0]
    len_x = len(X)
    # X = int(lines[0])
    # N, M = list(map(int, lines[0].split()))

    x = int(X)
    result = 0

    if len_x == 3:
        result += count_list753(3, x)
    elif len_x > 3:
        result += count_list753(3, 999)
        if len_x == 4:
            result += count_list753(4, x)
        else:
            result += count_list753(4, 9999)
            if len_x == 5:
                result += count_list753(5, x)
            else:
                result += count_list753(5, 99999)
                if len_x == 6:
                    result += count_list753(6, x)
                else:
                    result += count_list753(6, 999999)
                    if len_x == 7:
                        result += count_list753(7, x)
                    else:
                        result += count_list753(7, 9999999)
                        if len_x == 8:
                            result += count_list753(8, x)
                        else:
                            result += count_list753(8, 99999999)
                            result += count_list753(9, x)

    return [result]


# その桁での結果を得る
def count_list753(len_x, x):
    list753 = get_list753(len_x)
    cnt = 0
    for item in list753:
        if x > item:
            cnt += 1
    return cnt


def get_list753(n):
    _, lst = get_list753_internal(n-1, ['3', '5', '7'])
    return [int(item) for item in lst if '7' in item and '5' in item and '3' in item]


def get_list753_internal(n, lst):
    if n == 0:
        return 0, lst
    else:
        ret = list()
        for item in lst:
            ret.append(item + '3')
            ret.append(item + '5')
            ret.append(item + '7')
        return get_list753_internal(n-1, ret)


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['575']
        lines_export = [4]
    if pattern == 2:
        lines_input = ['3600']
        lines_export = [13]
    if pattern == 3:
        lines_input = ['999999999']
        lines_export = [26484]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=input()
l=len(N)
N=int(N)
if l<3:
    print(0)
else:
    
    cands=[None]*(l+1)
    cands[0]={}
    cands[1]={}
    cands[2]={}
    cands[3]= {"357","375","537","573","735","753"}
    
    for i in range(3,l):
        cands[i+1] = set(s+c for c in cands[i] for s in ["3","5","7"]) | set(c+s for c in cands[i] for s in ["3","5","7"] )
        cands[i+1].add("3"+"5"*(i-1)+"7")
        cands[i+1].add("3"+"7"*(i-1)+"5")
        cands[i+1].add("5"+"3"*(i-1)+"7")
        cands[i+1].add("5"+"7"*(i-1)+"3")
        cands[i+1].add("7"+"3"*(i-1)+"5")
        cands[i+1].add("7"+"5"*(i-1)+"3")
    
    ans=sum( [len(cands[i]) for i in range(l)] )
    ans+=sum( int(c)<N for c in cands[l])
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
def dfs(s):
    if int(s)>n:
        return 0
    res = 1 if all(s.count(c) > 0 for c in '753') else 0
    for i in '753':
        res += dfs(s+i)
    return res
dfs('0')

Submission status: Wrong Answer

Solution code:

n = int(input())

def depth_first_search(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':
        #print(c)
        print(s + c)
        ret += depth_first_search(s + c)
        print(ret)
    return ret

print(depth_first_search('0'))

Submission status: Wrong Answer

Solution code:
n = int(input())

l753 = ['3', '5', '7']
ans = 0
for i in range(n):
    l = list(str(i))
    if all((j in l753) for j in l) and len(set(l)) == 3:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools 
n=int(input())
ans=0
for ket in range(3,100):
  for xxx in  itertools.product([3,5,7],repeat=ket):
    tmp=list(xxx)[::1]
    hoge=0
    for j in range(len(tmp)):
      hoge=hoge*10+tmp[j]
    if(str(hoge).count("3")==0 or str(hoge).count("5")==0 or str(hoge).count("7")==0):
      ans-=1
    ans+=1
    if(hoge>=n):
      print(ans)
      exit()

Submission status: Wrong Answer

Solution code:
import itertools 
n=int(input())
if(n<=333):
  print(0)
  exit()

ans=0
for ket in range(3,100):
  for xxx in  itertools.product([3,5,7],repeat=ket):
    tmp=list(xxx)[::1]
    hoge=0
    for j in range(len(tmp)):
      hoge=hoge*10+tmp[j]
    if(str(hoge).count("3")==0 or str(hoge).count("5")==0 or str(hoge).count("7")==0):
      ans-=1
    ans+=1
    if(hoge>n):
      print(ans)
      exit()

Submission status: Wrong Answer

Solution code:
import itertools 
n=int(input())
if(n<=333):
  print(0)
  exit()

ans=0
for ket in range(3,100):
  for xxx in  itertools.product([3,5,7],repeat=ket):
    tmp=list(xxx)[::1]
    hoge=0
    for j in range(len(tmp)):
      hoge=hoge*10+tmp[j]
    if(str(hoge).count("3")==0 or str(hoge).count("5")==0 or str(hoge).count("7")==0):
      ans-=1
    ans+=1
    if(hoge>=n):
      print(ans)
      exit()

Submission status: Wrong Answer

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

    return result


def main():
    n = int(input())

    print(dfs('0', n))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = input()

d = {0: 0b000, 3: 0b001, 5: 0b010, 7: 0b100}

dp = [[[0] * 2 for _ in range(1 << 3)] for _ in range(len(n) + 1)]
dp[0][0][1] = 1

for i, e in enumerate(n):
    e = int(e)
    for num in [0, 3, 5, 7]:
        for j in range(1 << 3):
            if num == e:
                dp[i+1][j|d[num]][1] += dp[i][j][1]

            elif num < e:
                dp[i+1][j|d[num]][0] += dp[i][j][1]

            dp[i+1][j|d[num]][0] += dp[i][j][0]

ans = sum(dp[len(n)][0b111])
print(ans)