Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." [Image] 

The problem is: 

You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

If we sort all lucky numbers in increasing order, what's the 1-based index of n? 

Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.


-----Input-----

The first and only line of input contains a lucky number n (1 ≤ n ≤ 10^9).


-----Output-----

Print the index of n among all lucky numbers.


-----Examples-----
Input
4

Output
1

Input
7

Output
2

Input
77

Output
6

Difficulty: EASY
Tags: Bit manipulation

Combinatorics

Implementation

Complete search
Skill types: Bit manipulation

Complete search

Starter code:

Solutions:
b = [0, 4, 7]
n = list(map(lambda x: b.index(int(x)), list(input())))
n.reverse()
result = 0
for i in range(len(n)):
	result += n[i] * 2 ** i
print(result)


s = str(input())[::-1]
x = 0
for i in range(len(s)):
	if s[i] == '4':
		x += 2 ** i
	else:
		x += 2 ** (i + 1)
print(x)


def digits(n):
	count = 0
	while n:
		n //= 10
		count += 1
	return count
n = int(input())
p = digits(n)
count = 2 * (2 ** (p - 1) - 1)
x = 1
st = str(n)
i = p - 1
for j in st:
	if j == '7':
		x += 2 ** i
	i -= 1
print(count + x)


def get_index(n):
	if n == '4':
		return 1
	elif n == '7':
		return 2
	else:
		total = 2 ** (len(n) - 1)
		if n[0] == '7':
			total *= 2
		total += get_index(n[1:])
	return total
print(get_index(input()))


n = input().strip()
otvet = 0
for i in range(len(n)):
	if n[i] == '7':
		otvet = otvet + 2 ** (len(n) - i - 1)
if len(n) > 1:
	otvet = otvet + 2 ** len(n) - 2
print(otvet + 1)


s = input()
n = len(s)
base = 0
for i in range(0, n):
	base = base + 2 ** i
news = ''
for c in s:
	if c == '4':
		news = news + '0'
	else:
		news = news + '1'
news = '0b' + news
print(int(news, 2) + base)


a = [4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777, 4444, 4447, 4474, 4477, 4744, 4747, 4774, 4777, 7444, 7447, 7474, 7477, 7744, 7747, 7774, 7777, 44444, 44447, 44474, 44477, 44744, 44747, 44774, 44777, 47444, 47447, 47474, 47477, 47744, 47747, 47774, 47777, 74444, 74447, 74474, 74477, 74744, 74747, 74774, 74777, 77444, 77447, 77474, 77477, 77744, 77747, 77774, 77777, 444444, 444447, 444474, 444477, 444744, 444747, 444774, 444777, 447444, 447447, 447474, 447477, 447744, 447747, 447774, 447777, 474444, 474447, 474474, 474477, 474744, 474747, 474774, 474777, 477444, 477447, 477474, 477477, 477744, 477747, 477774, 477777, 744444, 744447, 744474, 744477, 744744, 744747, 744774, 744777, 747444, 747447, 747474, 747477, 747744, 747747, 747774, 747777, 774444, 774447, 774474, 774477, 774744, 774747, 774774, 774777, 777444, 777447, 777474, 777477, 777744, 777747, 777774, 777777, 4444444, 4444447, 4444474, 4444477, 4444744, 4444747, 4444774, 4444777, 4447444, 4447447, 4447474, 4447477, 4447744, 4447747, 4447774, 4447777, 4474444, 4474447, 4474474, 4474477, 4474744, 4474747, 4474774, 4474777, 4477444, 4477447, 4477474, 4477477, 4477744, 4477747, 4477774, 4477777, 4744444, 4744447, 4744474, 4744477, 4744744, 4744747, 4744774, 4744777, 4747444, 4747447, 4747474, 4747477, 4747744, 4747747, 4747774, 4747777, 4774444, 4774447, 4774474, 4774477, 4774744, 4774747, 4774774, 4774777, 4777444, 4777447, 4777474, 4777477, 4777744, 4777747, 4777774, 4777777, 7444444, 7444447, 7444474, 7444477, 7444744, 7444747, 7444774, 7444777, 7447444, 7447447, 7447474, 7447477, 7447744, 7447747, 7447774, 7447777, 7474444, 7474447, 7474474, 7474477, 7474744, 7474747, 7474774, 7474777, 7477444, 7477447, 7477474, 7477477, 7477744, 7477747, 7477774, 7477777, 7744444, 7744447, 7744474, 7744477, 7744744, 7744747, 7744774, 7744777, 7747444, 7747447, 7747474, 7747477, 7747744, 7747747, 7747774, 7747777, 7774444, 7774447, 7774474, 7774477, 7774744, 7774747, 7774774, 7774777, 7777444, 7777447, 7777474, 7777477, 7777744, 7777747, 7777774, 7777777, 44444444, 44444447, 44444474, 44444477, 44444744, 44444747, 44444774, 44444777, 44447444, 44447447, 44447474, 44447477, 44447744, 44447747, 44447774, 44447777, 44474444, 44474447, 44474474, 44474477, 44474744, 44474747, 44474774, 44474777, 44477444, 44477447, 44477474, 44477477, 44477744, 44477747, 44477774, 44477777, 44744444, 44744447, 44744474, 44744477, 44744744, 44744747, 44744774, 44744777, 44747444, 44747447, 44747474, 44747477, 44747744, 44747747, 44747774, 44747777, 44774444, 44774447, 44774474, 44774477, 44774744, 44774747, 44774774, 44774777, 44777444, 44777447, 44777474, 44777477, 44777744, 44777747, 44777774, 44777777, 47444444, 47444447, 47444474, 47444477, 47444744, 47444747, 47444774, 47444777, 47447444, 47447447, 47447474, 47447477, 47447744, 47447747, 47447774, 47447777, 47474444, 47474447, 47474474, 47474477, 47474744, 47474747, 47474774, 47474777, 47477444, 47477447, 47477474, 47477477, 47477744, 47477747, 47477774, 47477777, 47744444, 47744447, 47744474, 47744477, 47744744, 47744747, 47744774, 47744777, 47747444, 47747447, 47747474, 47747477, 47747744, 47747747, 47747774, 47747777, 47774444, 47774447, 47774474, 47774477, 47774744, 47774747, 47774774, 47774777, 47777444, 47777447, 47777474, 47777477, 47777744, 47777747, 47777774, 47777777, 74444444, 74444447, 74444474, 74444477, 74444744, 74444747, 74444774, 74444777, 74447444, 74447447, 74447474, 74447477, 74447744, 74447747, 74447774, 74447777, 74474444, 74474447, 74474474, 74474477, 74474744, 74474747, 74474774, 74474777, 74477444, 74477447, 74477474, 74477477, 74477744, 74477747, 74477774, 74477777, 74744444, 74744447, 74744474, 74744477, 74744744, 74744747, 74744774, 74744777, 74747444, 74747447, 74747474, 74747477, 74747744, 74747747, 74747774, 74747777, 74774444, 74774447, 74774474, 74774477, 74774744, 74774747, 74774774, 74774777, 74777444, 74777447, 74777474, 74777477, 74777744, 74777747, 74777774, 74777777, 77444444, 77444447, 77444474, 77444477, 77444744, 77444747, 77444774, 77444777, 77447444, 77447447, 77447474, 77447477, 77447744, 77447747, 77447774, 77447777, 77474444, 77474447, 77474474, 77474477, 77474744, 77474747, 77474774, 77474777, 77477444, 77477447, 77477474, 77477477, 77477744, 77477747, 77477774, 77477777, 77744444, 77744447, 77744474, 77744477, 77744744, 77744747, 77744774, 77744777, 77747444, 77747447, 77747474, 77747477, 77747744, 77747747, 77747774, 77747777, 77774444, 77774447, 77774474, 77774477, 77774744, 77774747, 77774774, 77774777, 77777444, 77777447, 77777474, 77777477, 77777744, 77777747, 77777774, 77777777, 444444444, 444444447, 444444474, 444444477, 444444744, 444444747, 444444774, 444444777, 444447444, 444447447, 444447474, 444447477, 444447744, 444447747, 444447774, 444447777, 444474444, 444474447, 444474474, 444474477, 444474744, 444474747, 444474774, 444474777, 444477444, 444477447, 444477474, 444477477, 444477744, 444477747, 444477774, 444477777, 444744444, 444744447, 444744474, 444744477, 444744744, 444744747, 444744774, 444744777, 444747444, 444747447, 444747474, 444747477, 444747744, 444747747, 444747774, 444747777, 444774444, 444774447, 444774474, 444774477, 444774744, 444774747, 444774774, 444774777, 444777444, 444777447, 444777474, 444777477, 444777744, 444777747, 444777774, 444777777, 447444444, 447444447, 447444474, 447444477, 447444744, 447444747, 447444774, 447444777, 447447444, 447447447, 447447474, 447447477, 447447744, 447447747, 447447774, 447447777, 447474444, 447474447, 447474474, 447474477, 447474744, 447474747, 447474774, 447474777, 447477444, 447477447, 447477474, 447477477, 447477744, 447477747, 447477774, 447477777, 447744444, 447744447, 447744474, 447744477, 447744744, 447744747, 447744774, 447744777, 447747444, 447747447, 447747474, 447747477, 447747744, 447747747, 447747774, 447747777, 447774444, 447774447, 447774474, 447774477, 447774744, 447774747, 447774774, 447774777, 447777444, 447777447, 447777474, 447777477, 447777744, 447777747, 447777774, 447777777, 474444444, 474444447, 474444474, 474444477, 474444744, 474444747, 474444774, 474444777, 474447444, 474447447, 474447474, 474447477, 474447744, 474447747, 474447774, 474447777, 474474444, 474474447, 474474474, 474474477, 474474744, 474474747, 474474774, 474474777, 474477444, 474477447, 474477474, 474477477, 474477744, 474477747, 474477774, 474477777, 474744444, 474744447, 474744474, 474744477, 474744744, 474744747, 474744774, 474744777, 474747444, 474747447, 474747474, 474747477, 474747744, 474747747, 474747774, 474747777, 474774444, 474774447, 474774474, 474774477, 474774744, 474774747, 474774774, 474774777, 474777444, 474777447, 474777474, 474777477, 474777744, 474777747, 474777774, 474777777, 477444444, 477444447, 477444474, 477444477, 477444744, 477444747, 477444774, 477444777, 477447444, 477447447, 477447474, 477447477, 477447744, 477447747, 477447774, 477447777, 477474444, 477474447, 477474474, 477474477, 477474744, 477474747, 477474774, 477474777, 477477444, 477477447, 477477474, 477477477, 477477744, 477477747, 477477774, 477477777, 477744444, 477744447, 477744474, 477744477, 477744744, 477744747, 477744774, 477744777, 477747444, 477747447, 477747474, 477747477, 477747744, 477747747, 477747774, 477747777, 477774444, 477774447, 477774474, 477774477, 477774744, 477774747, 477774774, 477774777, 477777444, 477777447, 477777474, 477777477, 477777744, 477777747, 477777774, 477777777, 744444444, 744444447, 744444474, 744444477, 744444744, 744444747, 744444774, 744444777, 744447444, 744447447, 744447474, 744447477, 744447744, 744447747, 744447774, 744447777, 744474444, 744474447, 744474474, 744474477, 744474744, 744474747, 744474774, 744474777, 744477444, 744477447, 744477474, 744477477, 744477744, 744477747, 744477774, 744477777, 744744444, 744744447, 744744474, 744744477, 744744744, 744744747, 744744774, 744744777, 744747444, 744747447, 744747474, 744747477, 744747744, 744747747, 744747774, 744747777, 744774444, 744774447, 744774474, 744774477, 744774744, 744774747, 744774774, 744774777, 744777444, 744777447, 744777474, 744777477, 744777744, 744777747, 744777774, 744777777, 747444444, 747444447, 747444474, 747444477, 747444744, 747444747, 747444774, 747444777, 747447444, 747447447, 747447474, 747447477, 747447744, 747447747, 747447774, 747447777, 747474444, 747474447, 747474474, 747474477, 747474744, 747474747, 747474774, 747474777, 747477444, 747477447, 747477474, 747477477, 747477744, 747477747, 747477774, 747477777, 747744444, 747744447, 747744474, 747744477, 747744744, 747744747, 747744774, 747744777, 747747444, 747747447, 747747474, 747747477, 747747744, 747747747, 747747774, 747747777, 747774444, 747774447, 747774474, 747774477, 747774744, 747774747, 747774774, 747774777, 747777444, 747777447, 747777474, 747777477, 747777744, 747777747, 747777774, 747777777, 774444444, 774444447, 774444474, 774444477, 774444744, 774444747, 774444774, 774444777, 774447444, 774447447, 774447474, 774447477, 774447744, 774447747, 774447774, 774447777, 774474444, 774474447, 774474474, 774474477, 774474744, 774474747, 774474774, 774474777, 774477444, 774477447, 774477474, 774477477, 774477744, 774477747, 774477774, 774477777, 774744444, 774744447, 774744474, 774744477, 774744744, 774744747, 774744774, 774744777, 774747444, 774747447, 774747474, 774747477, 774747744, 774747747, 774747774, 774747777, 774774444, 774774447, 774774474, 774774477, 774774744, 774774747, 774774774, 774774777, 774777444, 774777447, 774777474, 774777477, 774777744, 774777747, 774777774, 774777777, 777444444, 777444447, 777444474, 777444477, 777444744, 777444747, 777444774, 777444777, 777447444, 777447447, 777447474, 777447477, 777447744, 777447747, 777447774, 777447777, 777474444, 777474447, 777474474, 777474477, 777474744, 777474747, 777474774, 777474777, 777477444, 777477447, 777477474, 777477477, 777477744, 777477747, 777477774, 777477777, 777744444, 777744447, 777744474, 777744477, 777744744, 777744747, 777744774, 777744777, 777747444, 777747447, 777747474, 777747477, 777747744, 777747747, 777747774, 777747777, 777774444, 777774447, 777774474, 777774477, 777774744, 777774747, 777774774, 777774777, 777777444, 777777447, 777777474, 777777477, 777777744, 777777747, 777777774, 777777777]
n = int(input())
print(a.index(n) + 1)


import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))
from math import factorial

def solve():
	digits = list(input().replace('\n', ''))
	ans = 0
	for (k, d) in enumerate(reversed(digits)):
		if d == '4':
			ans += 1 * 2 ** k
		elif d == '7':
			ans += 2 * 2 ** k
	print(ans)
solve()


__author__ = 'artyom'
(lucky_numbers, i, prev) = ([], 10, [4, 7])
while i < 10000000000:
	nexxt = []
	for num in prev:
		lucky_numbers.append(num)
	for u in [4 * i, 7 * i]:
		for num in prev:
			nexxt.append(u + num)
	prev = nexxt
	i *= 10
print(lucky_numbers.index(int(input())) + 1)


a = list(map(int, input()))
n = len(a)
cnt = [2 ** i for i in range(11)]
res = 0
if n == 1:
	t = a[0]
	if t == 4:
		print(1)
	else:
		print(2)
else:
	res += 1
	for i in range(1, n):
		res += cnt[i]
	for (i, x) in enumerate(reversed(a)):
		if x == 7:
			res += cnt[i]
	print(res)


x = '1'
for c in input():
	if c == '4':
		x += '0'
	else:
		x += '1'
ind = 1
cur = 2
while True:
	y = bin(cur)[2:]
	if y == x:
		print(ind)
		break
	cur += 1
	ind += 1


s = input().strip().replace('7', '1').replace('4', '0')
m = 0
for i in range(1, len(s)):
	m += 2 ** i
print(int(s, 2) + m + 1)


s = input()
res = 0
for (idx, val) in enumerate(s[::-1]):
	t = 1
	if val == '7':
		t = 2
	res += 2 ** idx * t
print(res)


n = input()
x = len(n)
small_count = 2 * (2 ** (x - 1) - 1)
big_count = 1
for i in range(0, x):
	if n[i] == '7':
		big_count += 2 ** (x - i - 1)
print(big_count + small_count)


ent = input()
tam = len(ent)
minimo = 2 ** tam - 1
maximo = minimo + 2 ** tam - 1
for i in ent:
	mid = (maximo - minimo) // 2
	if i == '4':
		maximo = minimo + mid
	else:
		minimo = minimo + mid + 1
print(maximo)


n = input()
ans = 2 ** len(n) - 1
for (i, v) in enumerate(n):
	if v == '7':
		ans += 2 ** (len(n) - i - 1)
print(ans)


import math
import re
n = int(input())
ret = 0
count = 1
while n != 0:
	if n % 10 == 4:
		ret += count
	else:
		ret += 2 * count
	count *= 2
	n //= 10
print(ret)


s = input()
ans = 0
n = len(s)
for i in range(1, n):
	ans += pow(2, i)
for i in range(0, n):
	if s[i] == '7':
		ans += pow(2, n - 1 - i)
print(ans + 1)


line = str(input())
line = list(line)
n = len(line)
base = 2 ** n - 1
for i in range(len(line)):
	if line[n - i - 1] == '7':
		base += 2 ** i
print(base)


s = input()
n = len(s)
ans = 2 ** n - 2
add = 0
for i in range(n):
	if s[i] == '4':
		add = add << 1
	else:
		add = add << 1 | 1
print(ans + add + 1)


n = int(input())
i = 1
ans = 0
while n > 0:
	if n % 10 == 7:
		ans += i * 2
	else:
		ans += i
	i *= 2
	n = int(n / 10)
print(ans)


number = str(input())
ret = 0

def dothat(number, poww):
	yep = number
	for i in range(poww - 1):
		number *= yep
	if poww == 0:
		number = 1
	return number
for i in range(len(number)):
	if number[i] == '4':
		ret += dothat(2, len(number) - i - 1)
	else:
		ret += dothat(2, len(number) - i)
print(ret)


n = list(map(int, list(input())))
le = len(n)
ans = 0
for i in range(le):
	if n[i] == 4:
		ans += 2 ** (le - i - 1)
	elif n[i] == 7:
		ans += 2 ** (le - i)
print(ans)


t = input()
sum1 = 2 ** len(t) - 1
r = 0
for i in t[::-1]:
	if i == '7':
		sum1 = sum1 + 2 ** r
	r = r + 1
print(sum1)


a = input()
b = {'4': 1, '7': 2}
c = 0
for d in a:
	c = c * 2 + b[d]
print(c)


def gen():
	n = 2
	v = [4, 7]
	for i in range(1, 9):
		start = n - 2 ** i
		for j in range(start, n):
			v.append(v[j] * 10 + 4)
			v.append(v[j] * 10 + 7)
			n += 2
	return v
x = int(input())
array = gen()
for (i, a) in enumerate(array):
	if x == a:
		print(i + 1)
		break


n = int(input())
a = [4, 7]
for i in range(10000):
	if i % 2 == 0:
		a += [a[i // 2] * 10 + 4]
	else:
		a += [a[i // 2] * 10 + 7]
	if a[i - 1] > 10 ** 9:
		break
print(a.index(n) + 1)


a = input()
a = '1' + a
a = a.replace('4', '0')
a = a.replace('7', '1')
print(int(a, 2) - 1)


myLucky = int(input())
aux = 1
position = 0
while myLucky > 0:
	if int(myLucky % 10) == 4:
		position += int(aux)
	else:
		position += int(2 * aux)
	myLucky = int(myLucky / 10)
	aux = int(aux * 2)
print(position)


n = list(input())
a = []
if n[0] == '4':
	a.append(1)
	a.append(0)
else:
	a.append(1)
	a.append(1)
for i in range(1, len(n)):
	a.append(0 if n[i] == '4' else 1)
ans = 0
for i in range(len(a)):
	ans *= 2
	ans += a[i]
print(ans - 1)


n = list(input())
ans = (1 << len(n)) - 2
for (i, j) in enumerate(n[::-1]):
	if j == '7':
		ans += 1 << i
print(ans + 1)


a = str(input())
j = 1
count = 0
for i in range(len(a) - 1, -1, -1):
	if a[i] == '4':
		count += 1 * j
	else:
		count += 2 * j
	j *= 2
print(count)


p = [1]
for i in range(32):
	p.append(p[-1] * 2)
n = input()
length = len(n)
ans = 0
for i in range(1, length):
	ans += p[i]
for i in range(length - 1):
	if n[i] == '7':
		ans += p[length - i - 1]
if n[-1] == '7':
	ans += 2
else:
	ans += 1
print(ans)


n = int(input())
a = [4, 7]
b = [4, 7]
d = []
c = [4, 7]
i = 1
while i < 9:
	for x in c:
		for y in b:
			a.append(int(str(x) + str(y)))
			d.append(int(str(x) + str(y)))
	b = []
	b += d
	d = []
	i += 1
print(a.index(n) + 1)


t = input()
k = len(t)
m = 2 ** (k + 1) - 2
j = k - 1
for i in t:
	if i == '4':
		m -= 2 ** j
	j -= 1
print(m)


d = set()

def binary_search(a, x, lo=0, hi=None):
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		midval = a[mid]
		if midval < x:
			lo = mid + 1
		elif midval > x:
			hi = mid
		else:
			return mid
	return -1
for i in range(512):
	s = str(bin(i))
	s = s[2:]
	s1 = ''
	s2 = ''
	for c in s:
		if c == '0':
			s1 += '4'
			s2 += '7'
		else:
			s1 += '7'
			s2 += '4'
	d.add(int(s1))
	d.add(int(s2))
l = list(d)
l.sort()
n = int(input())
print(binary_search(l, n) + 1)


def solve(num):
	bits = len(num)
	ans = 2 ** bits - 2
	pos = 0
	for i in range(bits - 1, -1, -1):
		if num[i] == '7':
			ans += 1 << pos
		pos += 1
	return ans + 1
num = input()
print(solve(num))


def main():
	n = input().replace('4', '0').replace('7', '1')
	answer = (1 << len(n)) - 1
	answer += int(n, 2)
	print(answer)
main()


n = input()
number = 0
for i in n:
	if i == '4':
		j = 0
	else:
		j = 1
	number = number << 1
	number += j
correction = 0
k = 1
for i in range(len(n)):
	correction += k
	k *= 2
print(number + correction)


n = ''.join(('1' if c == '7' else '0' for c in input()))
print(int(n, 2) + 2 ** len(n) - 1)


s = input()
n = len(s)
pos = 0
for i in range(1, n):
	pos += 1 << i
s = s[::-1]
d = 0
for i in range(n):
	if s[i] == '7':
		d += 1 << i
print(d + pos + 1)


from sys import stdin, stdout

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
s = ''
x = input()
n = len(x) - 1
for i in x:
	if i == '4':
		s += '0'
	else:
		s += '1'
print(2 * (2 ** n - 1) + int(s, 2) + 1)


import sys
mask = [(10 ** x, 2 ** x) for x in range(8, 0, -1)]

def first_digit(x):
	while x > 10:
		x = x // 10
	return x

def get_mask(n):
	for m in mask:
		if m[0] < n:
			return m
	return None

def index(n):
	if n == 4:
		return 1
	if n == 7:
		return 2
	m = get_mask(n)
	if first_digit(n) == 4:
		return m[1] + index(n % m[0])
	else:
		return 2 * m[1] + index(n % m[0])
n = int(sys.stdin.readline())
print(index(n))


n = input()
m = []
for i in range(len(n)):
	if n[i] == '4':
		m.append('0')
	else:
		m.append('1')
ans = 2 * (2 ** (len(m) - 1) - 1) + int(''.join(m), 2) + 1
print(ans)


a = list(str(input()))
a = [int(x) for x in a]
n = len(a)
ans = 0
for i in range(n):
	digs = n - i
	ans += 2 ** (digs - 1)
	if a[i] == 4:
		continue
	else:
		ans += 2 ** (digs - 1)
print(ans)


l = [0]
elem = 0
while l[elem] < 10000000000.0:
	l.append(l[elem] * 10 + 7)
	l.append(l[elem] * 10 + 4)
	elem += 1
l.sort()
n = int(input())
for i in range(1, len(l)):
	if l[i] == n:
		print(i)
		break


a = {'4': 1, '7': 2}
k = 0
for i in input():
	k = k * 2 + a[i]
print(k)


from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
n = input()
(m, s) = (1, 0)
for i in range(len(n) - 1, -1, -1):
	p = 2
	if n[i] == '4':
		p = 1
	s += m * p
	m *= 2
print(s)


n = int(input())
length = 0
val = 0
mul = 1
while n > 0:
	if n % 10 == 7:
		val += 1 * mul
	else:
		val += 0 * mul
	mul <<= 1
	length += 1
	n //= 10
ans = val + 1
mul = 1
while length > 1:
	ans += 2 ** mul
	mul += 1
	length -= 1
print(ans)


a = input()
lenth = len(str(a))
ans = 2 ** lenth - 2
d = {4: 0, 7: 1}
l = list(a)
n2 = lenth
for i in l:
	num = d[int(i)]
	ans += num * 2 ** (n2 - 1)
	n2 -= 1
print(ans + 1)


def GP(n):
	if n == 0:
		return 0
	else:
		k = 2 * (2 ** n - 1)
		return k
p = input()
count = GP(int(len(p) - 1))
for i in range(0, len(p)):
	if p[i] == '7':
		count = count + 2 ** (len(p) - (i + 1))
print(count + 1)


n = input()
l = len(n)
ind = 0
for i in range(l):
	x = 0
	if n[l - i - 1] == '4':
		x = 1
	else:
		x = 2
	ind += 2 ** i * x
print(ind)


def val(k):
	ans = 0
	while k > 0:
		ans += 1 << k
		k -= 1
	return ans
n = input()
z = len(n)
k = z - 1
ans = val(k)
for x in range(z):
	if n[x] == '7':
		ans += 1 << z - 1 - x
ans += 1
print(ans)


n = input()
n1 = int(n)
a = len(n)
Sum = 2 ** a - 2
b = a
for i in range(0, a):
	if n[i] == '4':
		if b == 1:
			Sum = Sum + 1
		b = b - 1
	elif n[i] == '7':
		if b == 1:
			Sum = Sum + 1
		Sum = Sum + 2 ** (b - 1)
		b = b - 1
print(Sum)


n = int(input())
(temp, count, ans) = (n, 0, 0)
if n <= 4:
	print(1)
elif n <= 7:
	print(2)
else:
	while n:
		r = n % 10
		if r == 7:
			ans += 2 ** count
		n = n // 10
		count += 1
	for i in range(count - 1):
		ans += 2 ** (i + 1)
	print(ans + 1)


from itertools import product as prod
luckyNumbers = []
for j in [1, 2, 3, 4, 5, 6, 7, 8, 9]:
	tuples = list(prod(['4', '7'], repeat=j))
	for element in tuples:
		luckyNumbers.append(int(''.join(element)))
luckyNumbers.sort()
number = int(input())
print(1 + luckyNumbers.index(number))


x = int(input())
l = []
for i in str(x):
	if i == '4':
		l.append(1)
	else:
		l.append(2)
c = len(l) - 1
e = 0
while c > 0:
	l[e] = l[e] * 2 ** c
	c = c - 1
	e += 1
print(sum(l))


n = input()
check = {'4': 1, '7': 2}
ans = 0
for dig in n:
	ans = ans * 2 + check[dig]
print(ans)


s = input().strip()
s = s.replace('4', '0')
s = s.replace('7', '1')
x = int(s, 2)
ans = 1
for i in range(1, len(s)):
	ans += 2 ** i
print(ans + x)


n = input()
s = ''
for i in n:
	if i == '7':
		s = s + '1'
	else:
		s = s + '0'
ans = 0
for i in range(len(n) - 1):
	ans += 2 ** (i + 1)
print(ans + int(s, 2) + 1)


n = input()
input_len = len(n)
n = int(n)
arr = [4, 7]
mx = len(arr)
i = 0
while True:
	while i < mx:
		arr.append(int('4' + str(arr[i])))
		arr.append(int('7' + str(arr[i])))
		i += 1
	mx = len(arr)
	if len(str(arr[-1])) >= input_len:
		break
arr = sorted(arr)
print(arr.index(n) + 1)


import sys
import math
import bisect

def backtrack(cur, val, A):
	if cur and cur <= 9:
		A.append(val)
	if cur == 9:
		return
	backtrack(cur + 1, val * 10 + 4, A)
	backtrack(cur + 1, val * 10 + 7, A)

def solve(n):
	A = []
	backtrack(0, 0, A)
	A.sort()
	for i in range(len(A) + 1):
		if A[i] == n:
			return i + 1
	return -1

def main():
	n = int(input())
	ans = solve(n)
	print(ans)
main()


s = input().strip()
ans = 0
st = 1
for i in range(len(s) - 1, -1, -1):
	if s[i] == '4':
		ans += st
	elif s[i] == '7':
		ans += st * 2
	st *= 2
print(ans)


def solve():
	s = input()
	x = s.replace('4', '0')
	x = x.replace('7', '1')
	return 2 ** len(s) - 1 + int(x, 2)
ans = solve()
print(ans)


def res(n):
	r = 0
	for i in range(1, n + 1):
		r = r + 2 ** i
	return r
n = input()
rs = res(len(n) - 1) + 1
for i in range(len(n)):
	if int(n[i]) == 4:
		continue
	else:
		rs = rs + 2 ** (len(n) - i - 1)
print(rs)


import sys, math
sys.setrecursionlimit(10 ** 8)
i = input()
a = int('0b' + i.replace('7', '1').replace('4', '0'), 2)
print(a + 2 ** len(i) - 1)


import math as m
n = int(input())
num = m.ceil(m.log(n, 10))
ans = -1
count = 0
while count < num:
	ans += 1 << count
	count += 1
s = str(n)
temp = ''
for i in range(len(s)):
	if s[i] == '4':
		temp += '0'
	else:
		temp += '1'
ans += int(temp, 2)
print(ans + 1)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase
from fractions import *

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
s = input()
k = len(s)
ans = 2 ** k - 2
c = 0
for i in range(k - 1, -1, -1):
	if s[i] == '7':
		ans += 2 ** c
	c += 1
print(ans + 1)


def generate_luck_number(array, number=0):
	if number > 1000000000:
		return
	else:
		four = number * 10 + 4
		if four not in array:
			array.append(four)
		generate_luck_number(array, four)
		seven = number * 10 + 7
		if seven not in array:
			array.append(seven)
		generate_luck_number(array, seven)

def main():
	n = int(input())
	lucky_numbers = []
	generate_luck_number(lucky_numbers, 0)
	lucky_numbers.sort()
	print(lucky_numbers.index(n) + 1)
main()


def changeCharAt(s, ind, ch):
	return s[:ind] + ch + s[ind + 1:]

def changeCharsFrom(s, fromInd, ch):
	if fromInd == len(s):
		return s
	ans = s[:fromInd]
	helper = s[fromInd:]
	if len(helper) > 0:
		helper = helper.replace(helper[0], ch)
	return ans + helper
s = input()
ans = 0
while len(s) > 0:
	if '7' in s:
		lind = s.rindex('7')
		s = changeCharAt(s, lind, '4')
		s = changeCharsFrom(s, lind + 1, '7')
	else:
		s = s.replace('4', '7')[1:]
	ans += 1
print(ans)


n = int(input())

def wrapper(n):

	def rec(num=''):
		if num != '':
			if int(num) > n:
				return 0
		return rec('4' + num) + rec('7' + num) + 1
	return rec() - 1
print(wrapper(n))


string = input()[::-1]
ans = 0
run = 1
for char in string:
	ans += run * (1 if char == '4' else 2)
	run <<= 1
print(ans)


a = input()
b = int(a)
count = 0
while b:
	count += 1
	b //= 10
ans = 0
for i in a:
	if i == '4':
		ans += 2 ** count // 2
	else:
		ans += 2 ** count
	count -= 1
print(ans)


st = list(input().strip())
ts = st[:]
if len(st) == 1 and st[0] == '4':
	print(1)
elif len(st) == 1 and st[0] == '7':
	print(2)
else:
	for i in range(len(st)):
		if st[i] == '4':
			st[i] = '0'
		else:
			st[i] = '1'
	st = ''.join(st)
	print(2 ** len(ts) - 1 + int(st, 2))


n = int(input())
ans = 0
j = 1
while n:
	r = n % 10
	if r == 7:
		ans += 2 * j
	else:
		ans += 1 * j
	n //= 10
	j *= 2
print(ans)


s = input()
l = len(s)
n = int(s)
min = 2 * (2 ** (l - 1) - 1) + 1
max = 2 * (2 ** l - 1)
while l != 0:
	avg = (max + min) // 2
	k = n // 10 ** (l - 1)
	if max - min == 1:
		print(min if k == 4 else max)
	if k == 4:
		max = avg
	else:
		min = avg + 1
	n = n % 10 ** (l - 1)
	l -= 1


a = input()
b = list()
l = list(a)
for i in l:
	if i == '4':
		b.append(1)
	else:
		b.append(2)
b.reverse()
total = 0
count = 0
for i in b:
	count = count + i * pow(2, total)
	total = total + 1
print(count)


s = ''
for c in input():
	if c == '4':
		s += '0'
	elif c == '7':
		s += '1'
ans = int('0b1' + s, 2) - 1
print(ans)


a = int(input())
n = 0
res = 0
while a > 0:
	r = a % 10
	a = a // 10
	if r == 4:
		res += pow(2, n)
	else:
		res += pow(2, n + 1)
	n += 1
print(res)


s = input()
ans = 1

def f(k):
	if k == '4':
		return 0
	return 1
for i in range(len(s)):
	ans = (ans << 1) + f(s[i])
print(ans - 1)


pre = []
prev = ['']
for i in range(1, 11):
	curr = [s + '4' for s in prev] + [s + '7' for s in prev]
	pre.extend(curr)
	prev = curr
pre = sorted(map(int, pre))
print(pre.index(int(input())) + 1)


number = input()
result = 2 ** len(number) - 1
for (i, c) in enumerate(list(number[::-1])):
	if c == '7':
		result += 2 ** i
print(result)


lucky = int(input())
lucky = str(lucky)
lenlucky = len(lucky)
acc = 0
acc += 2 ** lenlucky - 1
numindex = [4, 7]
for i in range(lenlucky):
	acc += numindex.index(int(lucky[i])) * 2 ** (lenlucky - i - 1)
print(acc)


n = input().replace('4', '0').replace('7', '1')
m = len(n)
k = 0
d = 2
for i in range(m - 1):
	k += d
	d *= 2
k += int(n, 2) + 1
print(k)


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return '\n'.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True
d = {'4': '0', '7': '1'}
p = input()
s = ''
for c in p:
	s += d[c]
print(int(s, base=2) + 2 ** len(p) - 1)


numeroSorte = input()
contador = 1
posicao = 0
for i in range(len(numeroSorte) - 1, -1, -1):
	if numeroSorte[i] == '4':
		posicao += pow(2, contador - 1)
	else:
		posicao += pow(2, contador)
	contador += 1
print(posicao)


n = input()
s = []
for i in range(len(n) - 1, -1, -1):
	if int(n[i]) == 4:
		s.append(1)
	else:
		s.append(2)
cnt = 0
for i in range(len(s)):
	cnt += 2 ** i * s[i]
print(cnt)


import math
import bisect
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
N = insr()
out = 0
j = 0
for i in range(len(N) - 1, -1, -1):
	if N[i] == '4':
		out += 2 ** j
	elif N[i] == '7':
		out += 2 * 2 ** j
	j += 1
print(out)


def binary(n):
	b = ''
	while n > 0:
		b = chr(n % 2 + ord('0')) + b
		n //= 2
	return b
x = '1'
for c in input():
	if c == '4':
		x += '0'
	else:
		x += '1'
res = 1
cur = 2
y = binary(cur)
while x != y:
	cur += 1
	res += 1
	y = binary(cur)
print(res)


def conv_bin_to_int(bin):
	total_value = 0
	bin = bin[::-1]
	for i in range(len(bin)):
		if int(bin[i]) == 1:
			total_value += 2 ** i
	return total_value
lucky_num = input()
lucky_num = [1 if i == '7' else 0 for i in lucky_num]
index = 0
for i in range(len(lucky_num)):
	index += 2 ** i
index += conv_bin_to_int(lucky_num)
print(index)


import math

def lmap():
	return list(map(int, input().split()))

def mmap():
	return map(int, input().split())
s = input()
res = 0
for i in s:
	if i == '4':
		res = res * 2 + 1
	else:
		res = res * 2 + 2
print(res)


def main():
	n = int(input())
	k = 0
	i = 1
	while n // 10:
		k += 1 * i if n % 10 == 4 else 2 * i
		n //= 10
		i *= 2
	k += 1 * i if n % 10 == 4 else 2 * i
	print(k)
main()


string = input()
n = len(string)
rs = 1
for i in range(1, n):
	rs += 1 << i
for i in range(n):
	if string[i] == '7':
		rs += 1 << n - 1 - i
print(rs)


n = input()
ans = 1
for i in n:
	ans = 2 * ans + (1 if i == '7' else 0)
print(ans - 1)


n = input()
n = n.replace('4', '0')
n = n.replace('7', '1')
n = '1' + n
print(int(n, 2) - 1)


n = int(input())
i = 1
cnt = 0
ans = 1
while n:
	cnt += 1
	a = n % 10
	if a == 7:
		ans += i
	i *= 2
	n //= 10
print(2 * (2 ** (cnt - 1) - 1) + ans)


s = int(input())
res = 0

def dfs(num, l):
	global res
	if num <= s:
		res += 1
		dfs(4 * 10 ** l + num, l + 1)
		dfs(7 * 10 ** l + num, l + 1)
dfs(4, 1)
dfs(7, 1)
print(res)


n = int(input())
container = [4, 7]
index = 1
for luck in container:
	if luck == n:
		print(index)
		break
	container.append(luck * 10 + 4)
	container.append(luck * 10 + 7)
	index += 1


n = int(input())
tempn = n
digits = 0
while tempn > 0:
	digits = digits + 1
	tempn = tempn // 10
start = 1
toadd = 2
while digits > 1:
	start = start + toadd
	toadd = toadd * 2
	digits = digits - 1
plus = 1
while n > 0:
	nextdig = n % 10
	if nextdig == 7:
		start = start + plus
	plus = plus * 2
	n = n // 10
print(start)


dic = {'4': 1, '7': 2}
ans = 0
n = input()
for i in n:
	ans = ans * 2 + dic[i]
print(ans)


n = input()
len1 = len(n)
ans = 2 ** len1 - 2
a = [j for j in range(len(n) - 1, -1, -1)]
for i in range(len1):
	if n[i] == '7':
		ans += 2 ** a[i]
print(ans + 1)


def generate(num, pref):
	nonlocal res
	if num == 0:
		res += 1
		if pref == n:
			print(res)
			return
	else:
		generate(num - 1, pref + '4')
		generate(num - 1, pref + '7')
n = input()
num = len(n)
res = 0
for i in range(1, num):
	res += 2 ** i
generate(num, '')
print(res)


from itertools import permutations

def converttonum(mylist):
	return int(''.join((str(x) for x in mylist)))
n = int(input())
l = len(str(n))
index = 0
if l == 1:
	index = 0
else:
	for i in range(1, l):
		index += 2 ** i
mylist = []
newlist = []
for i in range(0, l):
	mylist.append(4)
newlist.append(converttonum(mylist))
for i in range(0, l):
	mylist[i] = 7
	myset = list(set(permutations(mylist)))
	for j in range(0, len(myset)):
		newlist.append(converttonum(myset[j]))
newlist.sort()
index += newlist.index(n) + 1
print(index)


import math
s = input().strip()
n = len(s)
ans = (1 << n) - 1
for i in range(n):
	if s[i] == '7':
		ans += 1 << n - i - 1
print(ans)


n = int(input())
ans = 0
m = 1
while n > 0:
	k = n % 10
	n = n // 10
	if k == 4:
		ans = ans + m * 1
	elif k == 7:
		ans = ans + m * 2
	m = m * 2
print(ans)


n = input()
res = 1
for i in n:
	res = 2 * res + (0 if i == '4' else 1)
print(res - 1)


from sys import stdin, stdout
num = stdin.readline().split()[0]
n = len(num)
start = 0
end = n - 1
ans = (1 << n) - 2
while end >= 0:
	if num[end] == '7':
		ans += 1 << start
	end -= 1
	start += 1
stdout.write(str(ans + 1))


from sys import stdin, stdout
s = input()
n = len(s)
ans = 0
dp = {}
ans = (1 << n) - 2
for i in range(n):
	if s[i] == '7':
		ans += 1 << n - i - 1
print(ans + 1)


a = []

def lucky(n):
	if n > 10 ** 10:
		return
	else:
		a.append(n)
		lucky(10 * n + 4)
		lucky(n * 10 + 7)
lucky(0)
a.sort()
n = int(input())
print(a.index(n))


print(sum((2 ** (i + (d == '7')) for (i, d) in enumerate(reversed(input())))))


from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
from math import gcd
mod = pow(10, 9) + 7

def inp(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	else:
		return int(input())
n = input().strip()
ans = 0
for i in range(len(n) - 1):
	ans += 1 << i + 1
for i in range(len(n)):
	if n[len(n) - i - 1] == '7':
		ans += 1 << i
print(ans + 1)


n = input()
n = n.replace('4', '0')
n = n.replace('7', '1')
d = int(n, 2)
v = 2 ** len(n) - 1
print(v + d)


n = input()
lst1 = list(map(int, n))
a = len(lst1)
ans = pow(2, a) - 2
lst1 = list(reversed(lst1))
for i in range(a):
	if lst1[i] == 7:
		ans += pow(2, i)
print(ans + 1)


def get_places_before(n):
	if n // 10 != 0:
		return 2 + 2 * get_places_before(n // 10)
	else:
		return 0
n = int(input())
i1 = get_places_before(n)
c = 0
t_n = n
while t_n > 0:
	t_n //= 10
	c = max(1, c * 10)
i2 = 0
while n > 0:
	i2 *= 2
	i2 += 0 if n // c == 4 else 1
	n %= c
	c //= 10
print(i1 + i2 + 1)


n = input()
l = len(n)
if l == 1:
	if n == '4':
		print(1)
	else:
		print(2)
else:
	ans = 0
	for r in range(1, l):
		ans += 2 ** r
	p = []
	for t in n:
		if t == '4':
			p.append(0)
		else:
			p.append(1)
	a = 0
	p.reverse()
	for i in range(l):
		a += 2 ** i * p[i]
	print(a + ans + 1)


n = list(input())
ans = 1
for i in range(len(n)):
	if n[len(n) - i - 1] == '7':
		ans += 2 ** i
ans += 2 * (2 ** (len(n) - 1) - 1)
print(ans)


a = input()[::-1]
b = 1
tam = 2 ** len(a) - 1
for i in a:
	if i == '7':
		tam += b
	b *= 2
print(tam)


n = int(input())
l = list((int(i) for i in str(n)))

def index_of(l):
	idx = 0
	zero = [0 for i in range(len(l))]
	while l != zero:
		for i in range(len(l) - 1, -1, -1):
			if l[i] == 0:
				break
			elif l[i] == 4:
				if i == 0 or l[i - 1] == 0:
					l[i] = 0
				else:
					l[i] = 7
			elif l[i] == 7:
				l[i] = 4
				break
		idx += 1
	return idx
print(index_of(l))


pos = 1
n = int(input())
ans = 0
while n > 0:
	mod = n % 10
	n //= 10
	if mod == 4:
		ans += pos
	else:
		ans += 2 * pos
	pos *= 2
print(ans)


def binnary(n):
	local = 0
	for i in range(len(n) - 1, -1, -1):
		if n[i] == '7':
			local += pow(2, len(n) - i - 1)
	return local
n = input()
print(pow(2, len(n)) + binnary(n) - 1)


a = [4, 7]
g = {4: 1, 7: 2}
i = 2
k = 10
while a[-1] < 10 ** 9:
	b = []
	for ele in a:
		i += 1
		g[ele * k + 4] = i
		i += 1
		g[ele * k + 7] = i
		b.append(ele * k + 4)
		b.append(ele * k + 7)
	a = b
h = int(input())
print(g[h])


a = int(input())
b = len(str(a))
d = 0
for i in range(b):
	d += 2 ** i
if d == 1:
	d = 0

def q(y, x):
	global d
	if x < b:
		q(y + '4', x + 1)
		q(y + '7', x + 1)
	elif int(y) <= a:
		d += 1
q('', 0)
if b > 1:
	d -= 1
print(d)


n = input()
ans = 1
for x in n:
	if x == '7':
		ans = 2 * ans + 1
	else:
		ans = 2 * ans
print(ans - 1)


n = input()
n1 = len(n)
n = int(n)
l = [4, 7]
i = 2
if n < 8:
	if n == 4:
		print(1)
	if n == 7:
		print(2)
else:
	while 1:
		k = l[0] * 10 + 4
		l.append(k)
		i += 1
		if k == n:
			print(i)
			break
		l.append(k + 3)
		i += 1
		if k + 3 == n:
			print(i)
			break
		del l[0]


s = input()
l = len(s)
t = 0
for c in s:
	t *= 2
	if c == '7':
		t += 1
print(t + 1 + 2 ** l - 2)


n = input()
j = 0
count = 0
a = len(n) - 1
for i in range(a, -1, -1):
	if int(n[i]) == 7:
		j = -(n.index(n[i], i) - a)
		count += 2 ** j
	else:
		continue
for i in range(len(n)):
	count += 2 ** i
print(count)


n = int(input())
if n == 4:
	print(1)
elif n == 7:
	print(2)
else:
	count = len(str(n))
	sum = 0
	for i in range(1, count):
		sum += pow(2, i)
	l = []
	for i in str(n):
		if i == '7':
			l.append('1')
		else:
			l.append('0')
	n = ''.join(l)
	ans = 0
	for i in range(len(n) - 1, -1, -1):
		ans += int(n[i]) * pow(2, len(n) - i - 1)
	print(ans + sum + 1)


n = int(input())
t = 0
aux = 1
while n:
	if int(n % 10) == 4:
		t = int(t + aux)
	else:
		t = int(t + 2 * aux)
	n = int(n / 10)
	aux = int(aux * 2)
print(t)


s = input()
l = 0
k = len(s) - 1
for i in range(k + 1):
	if s[i] == '4':
		l += 2 ** k
	else:
		l += 2 ** (k + 1)
	k -= 1
print(l)


def main():
	n = input().translate({ord('4'): '1', ord('7'): '2'})
	print(sum(map(lambda x: int(x[1]) * 2 ** x[0], enumerate(reversed(n)))))
main()


number = input()
vec = list(number)
position = 0
for i in reversed(range(len(vec))):
	if vec[i] == '4':
		position = position + 2 ** (len(vec) - i - 1)
	elif vec[i] == '7':
		position = position + 2 ** (len(vec) - i - 1) * 2
print(position)


s = input()
x = len(s)
m = pow(2, x) - 1
l = []
for i in range(x):
	if s[i] == '4':
		l.append(0)
	else:
		l.append(1)
sum = 0
l = l[::-1]
for i in range(x):
	sum += l[i] * pow(2, i)
print(m + sum)


c = 0
for i in input():
	c += c + (1, 2)[i == '7']
print(c)


l = [1, 2, 3]
l.clear()

def lucky(n):
	if n >= 1000000000:
		return
	l.append(n)
	lucky(n * 10 + 7)
	lucky(n * 10 + 4)
y = int(input())
lucky(4)
lucky(7)
l.sort()
print(l.index(y) + 1)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def find_parent(parent, i, cnt):
	cnt += 1
	if parent[i - 1] == i:
		return cnt
	if parent[i - 1] != i:
		find_parent(parent, parent[i - 1], cnt)
from collections import Counter
n = input()
l = len(str(n))
ans = 0
if l > 1:
	for i in range(1, l):
		ans += 1 << i
for i in range(l):
	if n[i] == '7':
		ans += 1 << l - i - 1
print(ans + 1)


import sys
input = sys.stdin.readline
n = str(int(input()))
out = ''
for i in n:
	if i == '7':
		out += '1'
	else:
		out += '0'
out = out[::-1]
p = 0
for i in range(len(out)):
	if out[i] == '0':
		p += 2 ** i
	else:
		p += 2 ** (i + 1)
print(p)


a = input()
a = a.replace('4', '1')
a = a.replace('7', '2')
tot = 0
for i in a:
	tot = int(i) + tot * 2
print(tot)


s = input()
ans = 0
for (n, i) in enumerate(s[::-1]):
	ans += 2 ** n * (1 + (i == '7'))
print(ans)


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def def_value():
	return 0
a = input()
s = []
for c in a:
	if c == '4':
		s.append(1)
	else:
		s.append(2)
res = 0
l = len(s)
for i in range(l):
	res += s[l - i - 1] * 2 ** i
print(res)


a = ['4', '7']
x = []
for i in a:
	x.append(int(i))
for i in a:
	for j in a:
		x.append(int(i + j))
for i in a:
	for j in a:
		for k in a:
			x.append(int(i + j + k))
for i in a:
	for j in a:
		for k in a:
			for l in a:
				x.append(int(i + j + k + l))
for i in a:
	for j in a:
		for k in a:
			for l in a:
				for m in a:
					x.append(int(i + j + k + l + m))
for i in a:
	for j in a:
		for k in a:
			for l in a:
				for m in a:
					for n in a:
						x.append(int(i + j + k + l + m + n))
for i in a:
	for j in a:
		for k in a:
			for l in a:
				for m in a:
					for n in a:
						for o in a:
							x.append(int(i + j + k + l + m + n + o))
for i in a:
	for j in a:
		for k in a:
			for l in a:
				for m in a:
					for n in a:
						for o in a:
							for p in a:
								x.append(int(i + j + k + l + m + n + o + p))
for i in a:
	for j in a:
		for k in a:
			for l in a:
				for m in a:
					for n in a:
						for o in a:
							for p in a:
								for q in a:
									x.append(int(i + j + k + l + m + n + o + p + q))
print(x.index(int(input())) + 1)


s = input()
n = int(s.replace('4', '0').replace('7', '1'), 2)
print(n - 1 + 2 ** len(s))


n = list(input())
n = [int(i) for i in n]
a = [4]

def nextlucky(n):
	ind = -1
	while True:
		if n[ind] == 4:
			n[ind] = 7
			for i in range(ind + 1, 0):
				n[i] = 4
			return n
		ind -= 1
		if ind < -len(n):
			return [4] * (len(n) + 1)
count = 1
while a < n or len(a) < len(n):
	a = nextlucky(a)
	count += 1
print(count)


lis = [4, 7]
i = 0
no = 4
while no <= 1000000000:
	no = lis[i] * 10 + 4
	lis.append(no)
	no = lis[i] * 10 + 7
	lis.append(no)
	i += 1
n = int(input())
for i in range(len(lis)):
	if lis[i] == n:
		print(i + 1)


masukan = input()
a = [4, 7]
count = 0
while count < 1024:
	if count % 2 == 0:
		a.append(a[count] * 10 + 4)
		a.append(a[count] * 10 + 7)
		count += 1
	elif count % 2 == 1:
		a.append(a[count] * 10 + 4)
		a.append(a[count] * 10 + 7)
		count += 1
print(a.index(int(masukan)) + 1)


d = {'4': 1, '7': 2}
r = 0
n = input()
for i in n:
	r = r * 2 + d[i]
print(r)


num = input()
n = len(num)
num = int(num)
ans = (1 << n) - 2
for i in range(n):
	if num % 10 == 7:
		ans += 1 << i
	num = int(num / 10)
print(ans + 1)


S = input()
N = len(S)
ans = 0
for i in range(N):
	if S[i] == '7':
		ans += 2 ** (N - i)
	else:
		ans += 2 ** (N - i - 1)
print(ans)


x = input()
s = '1'
n = -1
for k in str(x):
	if k == '4':
		s += '0'
	else:
		s += '1'
for j in range(len(s)):
	n += int(s[j]) * 2 ** (len(s) - j - 1)
print(n)


n = input()
k = len(n)
s = 1
ans = 0
for j in range(k):
	i = k - 1 - j
	if n[i] == '4':
		ans += s
	else:
		ans += 2 * s
	s *= 2
print(ans)


a = [2 if i == '7' else 1 for i in input()[::-1]]
n = 0
for i in range(len(a)):
	n += a[i] * 2 ** i
print(n)


num = int('1' + input().replace('4', '0').replace('7', '1'), 2) - 1
print(num)


def luckyNumberList(lucky):
	for i in range(1, 10):
		n = len(lucky)
		p = 2 ** i
		for j in range(n - p, n):
			num1 = lucky[j] * 10 + 4
			num2 = lucky[j] * 10 + 7
			lucky.append(num1)
			lucky.append(num2)
n = int(input())
lucky = [4, 7]
luckyNumberList(lucky)
print(lucky.index(n) + 1)


n = int(input())
container = [4, 7]
if n < 10:
	print(container.index(n) + 1)
else:
	i = 0
	while container[len(container) - 1] != n:
		tmp = str(container[i])
		container.append(int(tmp + '4'))
		if container[len(container) - 1] == n:
			break
		container.append(int(tmp + '7'))
		i += 1
	print(len(container))


j = int(input())
s = [7, 4]
s1 = s
for i in range(11):
	ns = [i * 10 + 4 for i in s1] + [i * 10 + 7 for i in s1]
	s += ns
	s1 = ns
print(sorted(s).index(j) + 1)


inp = input()
list = ['']
take = ['4', '7']
final = []
sorting = []
for i in range(len(inp)):
	for i in list:
		for j in take:
			final.append(i + j)
			sorting.append(int(i + j))
	list.clear()
	list = final.copy()
	final.clear()
print(sorting.index(int(inp)) + 1)


digits = list(input())
res = 0
l = len(digits)
for i in range(l):
	if digits[i] == '4':
		res += 2 ** (l - 1 - i)
	else:
		res += 2 ** (l - i)
print(res)


def answer(n):
	l = len(str(n))
	lst = []
	mask = 0
	for i in range(l):
		if str(n)[i] == '7':
			mask += 2 ** (l - 1 - i)
	return 2 ** l - 1 + mask

def main():
	n = int(input())
	print(answer(n))
	return
main()


dic = {4: 1, 7: 2}
N = int(input())
Res = 0
X = N
I = 0
Now = 10
Snow = 1
while X != 0:
	A = X % 10
	Res += Snow * dic[A]
	X = X // 10
	Snow *= 2
print(Res)


s = input()
s = '7' + s
r = 0
for i in range(0, len(s)):
	r *= 2
	r += 1 if s[i] == '7' else 0
r -= 1
print(r)


text = input()
carry = False
stack = []
for character in reversed(text):
	if character == '4':
		if carry:
			stack.append('0')
		else:
			stack.append('1')
	elif carry:
		stack.append('1')
	else:
		stack.append('0')
		carry = True
if carry:
	stack.append('1')
stack.reverse()
print(int(''.join(stack), 2))


num = input().replace('4', '1').replace('7', '2')
answer = 0
for (index, num) in enumerate(num[::-1]):
	answer += (1 << int(index)) * int(num)
print(answer)


a = input()
t = len(a) - 1
ans = 2 * (2 ** t - 1)
for i in a:
	a = a.replace('4', '0')
	a = a.replace('7', '1')
a = int(a, 2) + 1
print(ans + a)


n = input()
l = len(n)
s = 0
for i in range(1, l):
	s += 1 << i
for i in range(l):
	if n[i] == '7':
		s += 1 << l - i - 1
print(s + 1)


n = input()
l = len(n)
s = 0
l -= 1
while l > 0:
	s += 2 ** l
	l -= 1
f = list(n)
f.reverse()
j = 0
for i in f:
	if i == '7':
		s += 2 ** j
	j += 1
s += 1
print(s)


n = int(input())
sol = ''
while n > 0:
	if n % 10 == 7:
		sol = sol + '1'
	else:
		sol = sol + '0'
	n = n // 10
sol = sol + '1'
print(int(sol[-1::-1], 2) - 1)


import math
s = input()
n = len(s)
ans = 2 * (math.pow(2, n - 1) - 1)
temp = 1
for i in range(n - 1, -1, -1):
	if s[i] == '7':
		ans += temp
	temp *= 2
print(int(ans + 1))


n = int(input())
s = str(n)
l = len(s)
sum = 2 ** l - 2
r = ''
for i in range(l):
	if s[i] == '4':
		r += '0'
	else:
		r += '1'
k = l - 1
r = r[::-1]
while k != -1:
	sum += int(r[k]) * 2 ** k
	k -= 1
print(1 + sum)


def createNum(num):
	val = 0
	for x in num:
		val = val * 10 + x
	return val
n = int(input())
allNums = []
for dig in range(1, 10):
	mask = (1 << dig) - 1
	while mask >= 0:
		num = [4 for x in range(dig)]
		for i in range(dig):
			if 1 << i & mask:
				num[i] = 7
		allNums.append(createNum(num))
		mask -= 1
allNums.sort()
print(allNums.index(n) + 1)


n = input()
x = 1
ans = 0
for i in range(len(n) - 1):
	x <<= 1
	ans += x
x = 0
for i in range(len(n)):
	if n[len(n) - 1 - i] == '4':
		continue
	else:
		x |= 1 << i
ans += x
print(ans + 1)


n = int(input())
l = [4, 7]
c = 0
while l:
	k = l.pop(0)
	c += 1
	if k != n:
		l.append(k * 10 + 4)
		l.append(k * 10 + 7)
	else:
		break
print(c)


n = input()
a = 0
for v in n:
	a = a * 2 + (1 if v == '4' else 2)
print(a)


num = input().strip()
n = len(num)
ans1 = 2 * (pow(2, n - 1) - 1)
j = n - 1
ans2 = 0
for i in num:
	if i == '7':
		ans2 += pow(2, j)
	j = j - 1
print(ans1 + ans2 + 1)


n = input()
string = '1'
for i in n:
	if i == '4':
		string += '0'
	else:
		string += '1'
print(int(string, 2) - 1)


n = list(input())
for i in range(len(n)):
	if n[i] == '4':
		n[i] = '0'
	else:
		n[i] = '1'
print(int(''.join(n), base=2) + 2 ** len(n) - 1)


n = input()
n = n[::-1]
a = len(n)
c = 0
for i in range(a):
	if n[i] is '4':
		c += 2 ** i
	if n[i] is '7':
		c += 2 ** (1 + i)
print(c)


n = int(input())
x = 0
b = 4
c = 7
a = [4, 7]
for i in range(510):
	a.append(a[i] * 10 + b)
	a.append(a[i] * 10 + c)
for i in range(1023):
	x += 1
	if a[i] == n:
		break
print(x)


p = int(input())
l = [4, 7]
i = 0
while True:
	if l[i] == p:
		print(i + 1)
		break
	l.append(l[i] * 10 + 4)
	l.append(l[i] * 10 + 7)
	i = i + 1


def bin2int(binary, alphabet):
	if len(binary) > 1:
		return alphabet.index(binary[0]) * 2 ** (len(binary) - 1) + bin2int(binary[1:], alphabet)
	else:
		return alphabet.index(binary[0])
N = input()
print(bin2int('7' + N, ['4', '7']) - 1)


n = input()
arr = [str(4), str(7)]
ans = 0
m = 0
k = 1
last = 0
while m < 10 ** 9 + 1:
	for i in range(last, 2 * k):
		l = arr[i] + '4'
		l1 = arr[i] + '7'
		arr.append(l)
		arr.append(l1)
		m = max(int(l), int(l1))
	last = 2 * k
	k += 1
for i in range(len(arr)):
	if arr[i] == n:
		print(i + 1)
		break


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def recur(s, li):
	if int(s) > 10 ** 9:
		return
	s1 = s + '4'
	li.append(s1)
	recur(s1, li)
	s2 = s + '7'
	li.append(s2)
	recur(s2, li)

def solve():
	n = II()
	for i in range(len(li)):
		if int(li[i]) == n:
			print(i + 1)
			break
li = ['4', '7']
recur('4', li)
recur('7', li)
li.sort(key=lambda x: int(x))
solve()


n = input()
r = 1
for i in n:
	r = 2 * r
	if i == '7':
		r = r + 1
print(r - 1)


def num_digits(x):
	return len(str(x))
x = int(input())
exp_series = [2 ** n for n in range(num_digits(x))][1:]
add_this = 0
my_list = list(str(x))
my_list.reverse()
for i in range(len(my_list)):
	if my_list[i] == '7':
		add_this += 2 ** i
print(sum(exp_series) + add_this + 1)


n = input()
size = len(n)
if size == 1:
	print(1 if n == '4' else 2)
else:
	position = 2 ** size - 1
	for k in range(size):
		if n[k] == '7':
			position += 2 ** (size - k - 1)
	print(position)


n = input()
bs = ['1']
for c in n:
	if c == '4':
		bs.append('0')
	elif c == '7':
		bs.append('1')
	else:
		print('WTF?!')
b = ''.join(bs)
i = int(b, 2) - 1
print(i)


n = input()
m = len(n)
c = 0
for i in range(1, m):
	c += 2 ** i
s = n.replace('4', '0')
s = s.replace('7', '1')
print(c + 1 + int(s, 2))


num = int(input())
if num == 4:
	print(1)
elif num == 7:
	print(2)
else:
	num_s = str(num)
	all = [2 ** (x + 1) for x in range(len(num_s) - 1)]
	offset = sum(all)
	num_s = num_s.replace('4', '0').replace('7', '1')
	print(int(num_s, 2) + 1 + offset)


n = input()[::-1]
d = [(1 if n[i] == '4' else 2) * 2 ** i for i in range(len(n))]
print(sum(d))


n = input()
tamanho = len(n)
inicial = 2 ** tamanho - 1
final = inicial + 2 ** tamanho - 1
tamanhoLista = 2 ** tamanho
for i in range(tamanho):
	if inicial >= final:
		print(inicial)
		break
	if n[i] == '7':
		tamanhoLista = tamanhoLista // 2
		inicial += tamanhoLista
	else:
		tamanhoLista = tamanhoLista // 2
		final -= tamanhoLista
print(inicial)


def count(n):
	if n == 0:
		return 0
	else:
		return 2 ** n + count(n - 1)

def f(L):
	l = len(L)
	if l == 0:
		return 0
	elif l == 1:
		if L[0] == 4:
			return 1
		else:
			return 2
	elif L[0] == 4:
		return f(L[1:])
	else:
		return 2 ** (l - 1) + f(L[1:])

def main():
	a = input('')
	l = [int(i) for i in list(a)]
	length = len(l)
	print(count(length - 1) + f(l))
main()


n = input()
l = len(n)
end = 2 ** l
for i in range(l):
	if n[i] == '4':
		end -= 2 ** (l - i - 1)
for i in range(l - 1, 0, -1):
	end += 2 ** i
print(end)


def bin_to_dec(n):
	ans = 0
	length = len(n) - 1
	for _ in range(len(n)):
		ans += int(n[_]) * 2 ** length
		length -= 1
	return ans
n = int(input())
binary_string = ''
for i in range(len(str(n))):
	if str(n)[i] == '4':
		binary_string += '0'
	else:
		binary_string += '1'
print(bin_to_dec(binary_string) + 2 ** len(str(n)) - 1)


n = list(input())
(ans, ans1) = (0, 0)
for j in range(len(n) - 1, -1, -1):
	if n[j] == '7':
		ans1 += 2 ** (len(n) - j - 1)
	ans += 2 ** j
print(ans + ans1)


a = int(input())
s = 0
for i in range(1, 10):
	for j in range(1 << i):
		n = ''
		for k in range(i):
			n += '7' if j & 1 << k else '4'
		if a >= int(n):
			s += 1
print(s)


n = int(input())
if n == 4:
	print(1)
elif n == 7:
	print(2)
else:
	temp = n / 10
	final_count = 0
	counter = 1
	while temp != 0:
		final_count = final_count + 2 ** counter
		temp = int(temp / 10)
		counter += 1
	for i in range(counter):
		mod_val = 10
		curr_val = n % mod_val
		n = int(n / 10)
		if curr_val == 7:
			final_count = final_count + 2 ** i
	print(final_count + 1)


def to47(n):
	t = ''
	while n != 0:
		t += str(n % 3)
		if n % 3 == 0:
			return ''
		n //= 3
	return t.replace('1', '4').replace('2', '7')[::-1]
cnt = 0
i = 1
s = to47(i)
n = input()
while s != n:
	if s != '':
		cnt += 1
	i += 1
	s = to47(i)
print(cnt + 1)


luck = []

def push_luck(num):
	if num > 10000000000.0 + 1:
		return
	if num:
		luck.append(num)
	push_luck(num * 10 + 4)
	push_luck(num * 10 + 7)
push_luck(0)
luck.sort()
n = int(input())
print(luck.index(n) + 1)


gi = lambda : list(map(int, input().split()))
(n,) = gi()
s = ['1' if e == '7' else '0' for e in str(n)]
print(int(''.join(s), 2) + 1 + 2 ** len(s) - 2)


def main():
	n = str(int(input()))
	res = 0
	for (i, c) in enumerate(reversed(n)):
		if c == '4':
			res += 1 * (1 << i)
		else:
			res += 2 * (1 << i)
	print(res)
main()


def sv(n):
	if n == '':
		return 0
	elif n[0] == '4':
		return sv(n[1:])
	else:
		return (1 << len(n) - 1) + sv(n[1:])
n = input()
print((1 << len(n)) - 1 + sv(n))


n = [k for k in input()]
L = set(n)

def respuesta(n):
	cont = 0
	for k in range(len(n)):
		if '4' == n[k]:
			cont += 2 ** k
		else:
			cont += 2 * 2 ** k
	return cont
if len(L) == 1:
	res = respuesta(n)
else:
	res = respuesta(n[::-1])
print(res)


x = input()
p = len(x)
sm = 0
pw = 0
for n in range(p - 1, -1, -1):
	if x[n] == '7':
		sm += 1 << pw
	pw += 1
v = (1 << p) - 1
print(sm + v)


arr = [['4', '7']]
cnt = 2
while cnt < 500:
	tmp = ['4' + x for x in arr[-1]] + ['7' + x for x in arr[-1]]
	arr.append(tmp)
	cnt *= 2
arr = [int(x) for y in arr for x in y]
n = int(input())
for (i, x) in enumerate(arr):
	if x == n:
		print(i + 1)
		break


import sys
import math
from collections import defaultdict as dd
mod = 1000000007
T = 1
for _ in range(T):
	n = input()[::-1]
	s = 0
	y = 0
	for i in n:
		if i == '7':
			s |= 1 << y
		y += 1
	k = len(n)
	s -= 1
	print((1 << k) + s)


S = input()
k = 0
for i in range(len(S)):
	if S[i] == '4':
		k = k * 2 + 1
	else:
		k = k * 2 + 2
print(k)


nn = int(input())
i = 0
v = 0
while nn:
	n = nn % 10
	if n == 7:
		v += 2 ** (i + 1)
	else:
		v += 2 ** i
	nn //= 10
	i += 1
print(v)


n = int(input())
s = str(n)
l = len(s)
maxpos = 0
for i in range(1, l + 1):
	maxpos += 2 ** i
pos = maxpos
s = s[::-1]
for (i, c) in enumerate(s):
	if c in '4':
		pos -= 2 ** i
print(pos)


strno = input()
n = len(strno)
sum1 = 0
for i in range(1, n):
	sum1 += 1 << i
for i in range(n):
	if strno[i] == '7':
		sum1 += 1 << n - i - 1
print(sum1 + 1)


d = {4: 1, 7: 2, 44: 3, 47: 4, 74: 5, 77: 6, 444: 7, 447: 8, 474: 9, 477: 10, 744: 11, 747: 12, 774: 13, 777: 14, 4444: 15, 4447: 16, 4474: 17, 4477: 18, 4744: 19, 4747: 20, 4774: 21, 4777: 22, 7444: 23, 7447: 24, 7474: 25, 7477: 26, 7744: 27, 7747: 28, 7774: 29, 7777: 30, 44444: 31, 44447: 32, 44474: 33, 44477: 34, 44744: 35, 44747: 36, 44774: 37, 44777: 38, 47444: 39, 47447: 40, 47474: 41, 47477: 42, 47744: 43, 47747: 44, 47774: 45, 47777: 46, 74444: 47, 74447: 48, 74474: 49, 74477: 50, 74744: 51, 74747: 52, 74774: 53, 74777: 54, 77444: 55, 77447: 56, 77474: 57, 77477: 58, 77744: 59, 77747: 60, 77774: 61, 77777: 62, 444444: 63, 444447: 64, 444474: 65, 444477: 66, 444744: 67, 444747: 68, 444774: 69, 444777: 70, 447444: 71, 447447: 72, 447474: 73, 447477: 74, 447744: 75, 447747: 76, 447774: 77, 447777: 78, 474444: 79, 474447: 80, 474474: 81, 474477: 82, 474744: 83, 474747: 84, 474774: 85, 474777: 86, 477444: 87, 477447: 88, 477474: 89, 477477: 90, 477744: 91, 477747: 92, 477774: 93, 477777: 94, 744444: 95, 744447: 96, 744474: 97, 744477: 98, 744744: 99, 744747: 100, 744774: 101, 744777: 102, 747444: 103, 747447: 104, 747474: 105, 747477: 106, 747744: 107, 747747: 108, 747774: 109, 747777: 110, 774444: 111, 774447: 112, 774474: 113, 774477: 114, 774744: 115, 774747: 116, 774774: 117, 774777: 118, 777444: 119, 777447: 120, 777474: 121, 777477: 122, 777744: 123, 777747: 124, 777774: 125, 777777: 126, 4444444: 127, 4444447: 128, 4444474: 129, 4444477: 130, 4444744: 131, 4444747: 132, 4444774: 133, 4444777: 134, 4447444: 135, 4447447: 136, 4447474: 137, 4447477: 138, 4447744: 139, 4447747: 140, 4447774: 141, 4447777: 142, 4474444: 143, 4474447: 144, 4474474: 145, 4474477: 146, 4474744: 147, 4474747: 148, 4474774: 149, 4474777: 150, 4477444: 151, 4477447: 152, 4477474: 153, 4477477: 154, 4477744: 155, 4477747: 156, 4477774: 157, 4477777: 158, 4744444: 159, 4744447: 160, 4744474: 161, 4744477: 162, 4744744: 163, 4744747: 164, 4744774: 165, 4744777: 166, 4747444: 167, 4747447: 168, 4747474: 169, 4747477: 170, 4747744: 171, 4747747: 172, 4747774: 173, 4747777: 174, 4774444: 175, 4774447: 176, 4774474: 177, 4774477: 178, 4774744: 179, 4774747: 180, 4774774: 181, 4774777: 182, 4777444: 183, 4777447: 184, 4777474: 185, 4777477: 186, 4777744: 187, 4777747: 188, 4777774: 189, 4777777: 190, 7444444: 191, 7444447: 192, 7444474: 193, 7444477: 194, 7444744: 195, 7444747: 196, 7444774: 197, 7444777: 198, 7447444: 199, 7447447: 200, 7447474: 201, 7447477: 202, 7447744: 203, 7447747: 204, 7447774: 205, 7447777: 206, 7474444: 207, 7474447: 208, 7474474: 209, 7474477: 210, 7474744: 211, 7474747: 212, 7474774: 213, 7474777: 214, 7477444: 215, 7477447: 216, 7477474: 217, 7477477: 218, 7477744: 219, 7477747: 220, 7477774: 221, 7477777: 222, 7744444: 223, 7744447: 224, 7744474: 225, 7744477: 226, 7744744: 227, 7744747: 228, 7744774: 229, 7744777: 230, 7747444: 231, 7747447: 232, 7747474: 233, 7747477: 234, 7747744: 235, 7747747: 236, 7747774: 237, 7747777: 238, 7774444: 239, 7774447: 240, 7774474: 241, 7774477: 242, 7774744: 243, 7774747: 244, 7774774: 245, 7774777: 246, 7777444: 247, 7777447: 248, 7777474: 249, 7777477: 250, 7777744: 251, 7777747: 252, 7777774: 253, 7777777: 254, 44444444: 255, 44444447: 256, 44444474: 257, 44444477: 258, 44444744: 259, 44444747: 260, 44444774: 261, 44444777: 262, 44447444: 263, 44447447: 264, 44447474: 265, 44447477: 266, 44447744: 267, 44447747: 268, 44447774: 269, 44447777: 270, 44474444: 271, 44474447: 272, 44474474: 273, 44474477: 274, 44474744: 275, 44474747: 276, 44474774: 277, 44474777: 278, 44477444: 279, 44477447: 280, 44477474: 281, 44477477: 282, 44477744: 283, 44477747: 284, 44477774: 285, 44477777: 286, 44744444: 287, 44744447: 288, 44744474: 289, 44744477: 290, 44744744: 291, 44744747: 292, 44744774: 293, 44744777: 294, 44747444: 295, 44747447: 296, 44747474: 297, 44747477: 298, 44747744: 299, 44747747: 300, 44747774: 301, 44747777: 302, 44774444: 303, 44774447: 304, 44774474: 305, 44774477: 306, 44774744: 307, 44774747: 308, 44774774: 309, 44774777: 310, 44777444: 311, 44777447: 312, 44777474: 313, 44777477: 314, 44777744: 315, 44777747: 316, 44777774: 317, 44777777: 318, 47444444: 319, 47444447: 320, 47444474: 321, 47444477: 322, 47444744: 323, 47444747: 324, 47444774: 325, 47444777: 326, 47447444: 327, 47447447: 328, 47447474: 329, 47447477: 330, 47447744: 331, 47447747: 332, 47447774: 333, 47447777: 334, 47474444: 335, 47474447: 336, 47474474: 337, 47474477: 338, 47474744: 339, 47474747: 340, 47474774: 341, 47474777: 342, 47477444: 343, 47477447: 344, 47477474: 345, 47477477: 346, 47477744: 347, 47477747: 348, 47477774: 349, 47477777: 350, 47744444: 351, 47744447: 352, 47744474: 353, 47744477: 354, 47744744: 355, 47744747: 356, 47744774: 357, 47744777: 358, 47747444: 359, 47747447: 360, 47747474: 361, 47747477: 362, 47747744: 363, 47747747: 364, 47747774: 365, 47747777: 366, 47774444: 367, 47774447: 368, 47774474: 369, 47774477: 370, 47774744: 371, 47774747: 372, 47774774: 373, 47774777: 374, 47777444: 375, 47777447: 376, 47777474: 377, 47777477: 378, 47777744: 379, 47777747: 380, 47777774: 381, 47777777: 382, 74444444: 383, 74444447: 384, 74444474: 385, 74444477: 386, 74444744: 387, 74444747: 388, 74444774: 389, 74444777: 390, 74447444: 391, 74447447: 392, 74447474: 393, 74447477: 394, 74447744: 395, 74447747: 396, 74447774: 397, 74447777: 398, 74474444: 399, 74474447: 400, 74474474: 401, 74474477: 402, 74474744: 403, 74474747: 404, 74474774: 405, 74474777: 406, 74477444: 407, 74477447: 408, 74477474: 409, 74477477: 410, 74477744: 411, 74477747: 412, 74477774: 413, 74477777: 414, 74744444: 415, 74744447: 416, 74744474: 417, 74744477: 418, 74744744: 419, 74744747: 420, 74744774: 421, 74744777: 422, 74747444: 423, 74747447: 424, 74747474: 425, 74747477: 426, 74747744: 427, 74747747: 428, 74747774: 429, 74747777: 430, 74774444: 431, 74774447: 432, 74774474: 433, 74774477: 434, 74774744: 435, 74774747: 436, 74774774: 437, 74774777: 438, 74777444: 439, 74777447: 440, 74777474: 441, 74777477: 442, 74777744: 443, 74777747: 444, 74777774: 445, 74777777: 446, 77444444: 447, 77444447: 448, 77444474: 449, 77444477: 450, 77444744: 451, 77444747: 452, 77444774: 453, 77444777: 454, 77447444: 455, 77447447: 456, 77447474: 457, 77447477: 458, 77447744: 459, 77447747: 460, 77447774: 461, 77447777: 462, 77474444: 463, 77474447: 464, 77474474: 465, 77474477: 466, 77474744: 467, 77474747: 468, 77474774: 469, 77474777: 470, 77477444: 471, 77477447: 472, 77477474: 473, 77477477: 474, 77477744: 475, 77477747: 476, 77477774: 477, 77477777: 478, 77744444: 479, 77744447: 480, 77744474: 481, 77744477: 482, 77744744: 483, 77744747: 484, 77744774: 485, 77744777: 486, 77747444: 487, 77747447: 488, 77747474: 489, 77747477: 490, 77747744: 491, 77747747: 492, 77747774: 493, 77747777: 494, 77774444: 495, 77774447: 496, 77774474: 497, 77774477: 498, 77774744: 499, 77774747: 500, 77774774: 501, 77774777: 502, 77777444: 503, 77777447: 504, 77777474: 505, 77777477: 506, 77777744: 507, 77777747: 508, 77777774: 509, 77777777: 510, 444444444: 511, 444444447: 512, 444444474: 513, 444444477: 514, 444444744: 515, 444444747: 516, 444444774: 517, 444444777: 518, 444447444: 519, 444447447: 520, 444447474: 521, 444447477: 522, 444447744: 523, 444447747: 524, 444447774: 525, 444447777: 526, 444474444: 527, 444474447: 528, 444474474: 529, 444474477: 530, 444474744: 531, 444474747: 532, 444474774: 533, 444474777: 534, 444477444: 535, 444477447: 536, 444477474: 537, 444477477: 538, 444477744: 539, 444477747: 540, 444477774: 541, 444477777: 542, 444744444: 543, 444744447: 544, 444744474: 545, 444744477: 546, 444744744: 547, 444744747: 548, 444744774: 549, 444744777: 550, 444747444: 551, 444747447: 552, 444747474: 553, 444747477: 554, 444747744: 555, 444747747: 556, 444747774: 557, 444747777: 558, 444774444: 559, 444774447: 560, 444774474: 561, 444774477: 562, 444774744: 563, 444774747: 564, 444774774: 565, 444774777: 566, 444777444: 567, 444777447: 568, 444777474: 569, 444777477: 570, 444777744: 571, 444777747: 572, 444777774: 573, 444777777: 574, 447444444: 575, 447444447: 576, 447444474: 577, 447444477: 578, 447444744: 579, 447444747: 580, 447444774: 581, 447444777: 582, 447447444: 583, 447447447: 584, 447447474: 585, 447447477: 586, 447447744: 587, 447447747: 588, 447447774: 589, 447447777: 590, 447474444: 591, 447474447: 592, 447474474: 593, 447474477: 594, 447474744: 595, 447474747: 596, 447474774: 597, 447474777: 598, 447477444: 599, 447477447: 600, 447477474: 601, 447477477: 602, 447477744: 603, 447477747: 604, 447477774: 605, 447477777: 606, 447744444: 607, 447744447: 608, 447744474: 609, 447744477: 610, 447744744: 611, 447744747: 612, 447744774: 613, 447744777: 614, 447747444: 615, 447747447: 616, 447747474: 617, 447747477: 618, 447747744: 619, 447747747: 620, 447747774: 621, 447747777: 622, 447774444: 623, 447774447: 624, 447774474: 625, 447774477: 626, 447774744: 627, 447774747: 628, 447774774: 629, 447774777: 630, 447777444: 631, 447777447: 632, 447777474: 633, 447777477: 634, 447777744: 635, 447777747: 636, 447777774: 637, 447777777: 638, 474444444: 639, 474444447: 640, 474444474: 641, 474444477: 642, 474444744: 643, 474444747: 644, 474444774: 645, 474444777: 646, 474447444: 647, 474447447: 648, 474447474: 649, 474447477: 650, 474447744: 651, 474447747: 652, 474447774: 653, 474447777: 654, 474474444: 655, 474474447: 656, 474474474: 657, 474474477: 658, 474474744: 659, 474474747: 660, 474474774: 661, 474474777: 662, 474477444: 663, 474477447: 664, 474477474: 665, 474477477: 666, 474477744: 667, 474477747: 668, 474477774: 669, 474477777: 670, 474744444: 671, 474744447: 672, 474744474: 673, 474744477: 674, 474744744: 675, 474744747: 676, 474744774: 677, 474744777: 678, 474747444: 679, 474747447: 680, 474747474: 681, 474747477: 682, 474747744: 683, 474747747: 684, 474747774: 685, 474747777: 686, 474774444: 687, 474774447: 688, 474774474: 689, 474774477: 690, 474774744: 691, 474774747: 692, 474774774: 693, 474774777: 694, 474777444: 695, 474777447: 696, 474777474: 697, 474777477: 698, 474777744: 699, 474777747: 700, 474777774: 701, 474777777: 702, 477444444: 703, 477444447: 704, 477444474: 705, 477444477: 706, 477444744: 707, 477444747: 708, 477444774: 709, 477444777: 710, 477447444: 711, 477447447: 712, 477447474: 713, 477447477: 714, 477447744: 715, 477447747: 716, 477447774: 717, 477447777: 718, 477474444: 719, 477474447: 720, 477474474: 721, 477474477: 722, 477474744: 723, 477474747: 724, 477474774: 725, 477474777: 726, 477477444: 727, 477477447: 728, 477477474: 729, 477477477: 730, 477477744: 731, 477477747: 732, 477477774: 733, 477477777: 734, 477744444: 735, 477744447: 736, 477744474: 737, 477744477: 738, 477744744: 739, 477744747: 740, 477744774: 741, 477744777: 742, 477747444: 743, 477747447: 744, 477747474: 745, 477747477: 746, 477747744: 747, 477747747: 748, 477747774: 749, 477747777: 750, 477774444: 751, 477774447: 752, 477774474: 753, 477774477: 754, 477774744: 755, 477774747: 756, 477774774: 757, 477774777: 758, 477777444: 759, 477777447: 760, 477777474: 761, 477777477: 762, 477777744: 763, 477777747: 764, 477777774: 765, 477777777: 766, 744444444: 767, 744444447: 768, 744444474: 769, 744444477: 770, 744444744: 771, 744444747: 772, 744444774: 773, 744444777: 774, 744447444: 775, 744447447: 776, 744447474: 777, 744447477: 778, 744447744: 779, 744447747: 780, 744447774: 781, 744447777: 782, 744474444: 783, 744474447: 784, 744474474: 785, 744474477: 786, 744474744: 787, 744474747: 788, 744474774: 789, 744474777: 790, 744477444: 791, 744477447: 792, 744477474: 793, 744477477: 794, 744477744: 795, 744477747: 796, 744477774: 797, 744477777: 798, 744744444: 799, 744744447: 800, 744744474: 801, 744744477: 802, 744744744: 803, 744744747: 804, 744744774: 805, 744744777: 806, 744747444: 807, 744747447: 808, 744747474: 809, 744747477: 810, 744747744: 811, 744747747: 812, 744747774: 813, 744747777: 814, 744774444: 815, 744774447: 816, 744774474: 817, 744774477: 818, 744774744: 819, 744774747: 820, 744774774: 821, 744774777: 822, 744777444: 823, 744777447: 824, 744777474: 825, 744777477: 826, 744777744: 827, 744777747: 828, 744777774: 829, 744777777: 830, 747444444: 831, 747444447: 832, 747444474: 833, 747444477: 834, 747444744: 835, 747444747: 836, 747444774: 837, 747444777: 838, 747447444: 839, 747447447: 840, 747447474: 841, 747447477: 842, 747447744: 843, 747447747: 844, 747447774: 845, 747447777: 846, 747474444: 847, 747474447: 848, 747474474: 849, 747474477: 850, 747474744: 851, 747474747: 852, 747474774: 853, 747474777: 854, 747477444: 855, 747477447: 856, 747477474: 857, 747477477: 858, 747477744: 859, 747477747: 860, 747477774: 861, 747477777: 862, 747744444: 863, 747744447: 864, 747744474: 865, 747744477: 866, 747744744: 867, 747744747: 868, 747744774: 869, 747744777: 870, 747747444: 871, 747747447: 872, 747747474: 873, 747747477: 874, 747747744: 875, 747747747: 876, 747747774: 877, 747747777: 878, 747774444: 879, 747774447: 880, 747774474: 881, 747774477: 882, 747774744: 883, 747774747: 884, 747774774: 885, 747774777: 886, 747777444: 887, 747777447: 888, 747777474: 889, 747777477: 890, 747777744: 891, 747777747: 892, 747777774: 893, 747777777: 894, 774444444: 895, 774444447: 896, 774444474: 897, 774444477: 898, 774444744: 899, 774444747: 900, 774444774: 901, 774444777: 902, 774447444: 903, 774447447: 904, 774447474: 905, 774447477: 906, 774447744: 907, 774447747: 908, 774447774: 909, 774447777: 910, 774474444: 911, 774474447: 912, 774474474: 913, 774474477: 914, 774474744: 915, 774474747: 916, 774474774: 917, 774474777: 918, 774477444: 919, 774477447: 920, 774477474: 921, 774477477: 922, 774477744: 923, 774477747: 924, 774477774: 925, 774477777: 926, 774744444: 927, 774744447: 928, 774744474: 929, 774744477: 930, 774744744: 931, 774744747: 932, 774744774: 933, 774744777: 934, 774747444: 935, 774747447: 936, 774747474: 937, 774747477: 938, 774747744: 939, 774747747: 940, 774747774: 941, 774747777: 942, 774774444: 943, 774774447: 944, 774774474: 945, 774774477: 946, 774774744: 947, 774774747: 948, 774774774: 949, 774774777: 950, 774777444: 951, 774777447: 952, 774777474: 953, 774777477: 954, 774777744: 955, 774777747: 956, 774777774: 957, 774777777: 958, 777444444: 959, 777444447: 960, 777444474: 961, 777444477: 962, 777444744: 963, 777444747: 964, 777444774: 965, 777444777: 966, 777447444: 967, 777447447: 968, 777447474: 969, 777447477: 970, 777447744: 971, 777447747: 972, 777447774: 973, 777447777: 974, 777474444: 975, 777474447: 976, 777474474: 977, 777474477: 978, 777474744: 979, 777474747: 980, 777474774: 981, 777474777: 982, 777477444: 983, 777477447: 984, 777477474: 985, 777477477: 986, 777477744: 987, 777477747: 988, 777477774: 989, 777477777: 990, 777744444: 991, 777744447: 992, 777744474: 993, 777744477: 994, 777744744: 995, 777744747: 996, 777744774: 997, 777744777: 998, 777747444: 999, 777747447: 1000, 777747474: 1001, 777747477: 1002, 777747744: 1003, 777747747: 1004, 777747774: 1005, 777747777: 1006, 777774444: 1007, 777774447: 1008, 777774474: 1009, 777774477: 1010, 777774744: 1011, 777774747: 1012, 777774774: 1013, 777774777: 1014, 777777444: 1015, 777777447: 1016, 777777474: 1017, 777777477: 1018, 777777744: 1019, 777777747: 1020, 777777774: 1021, 777777777: 1022}
n = int(input())
print(d[n])


n = int(input())
(ans, i) = (0, 0)
while n > 0:
	if n % 10 == 4:
		ans += 1 * 2 ** i
	elif n % 10 == 7:
		ans += 2 * 2 ** i
	n = int(n / 10)
	i += 1
print(ans)


n = input()
l = len(n)
if l > 1:
	a = [0 for i in range(l)]
	a[l - 1] = 2
	j = l - 1
	while j >= 0:
		if n[j] < '4':
			a[j] = 0
		elif n[j] < '7':
			a[j] = 1 * 2 ** (l - j - 1)
		else:
			a[j] = 2 * 2 ** (l - j - 1)
		j = j - 1
	ans = sum(a)
elif n < '4':
	ans = 0
elif n < '7':
	ans = 1
else:
	ans = 2
print(ans)


n = int(input())
digit = ['4', '7']
cur = ['4', '7']
l = 0
while len(cur) < 512:
	r = len(cur)
	for i in range(2):
		for j in range(l, r):
			cur.append(digit[i] + cur[j])
	l = r
cur = [int(i) for i in cur]
cur.sort()

def find_ind(x):
	l = 0
	r = len(cur) - 1
	while l <= r:
		mid = (l + r) // 2
		if cur[mid] == x:
			return mid + 1
		elif cur[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1
print(find_ind(n))


n = int(input())
if n == 4:
	print(1)
elif n == 7:
	print(2)
else:
	a = []
	for i in range(len(str(n))):
		a.append([])
	a[0].append(4)
	a[0].append(7)
	c = 2
	f = 0
	for i in range(1, len(a)):
		for j in a[i - 1]:
			a[i].append(int(str(j) + str(4)))
			c += 1
			if a[i][-1] == n:
				f = 1
				break
			a[i].append(int(str(j) + str(7)))
			c += 1
			if a[i][-1] == n:
				f = 1
				break
		if f == 1:
			break
	print(c)


inp = input()
n = int(inp)
c = 0
k = 10
while k ** c < n:
	c += 1
res = 0
res += 2 ** c - 2
p = 1
for i in range(len(inp) - 1, -1, -1):
	ch = inp[i]
	if ch == '7':
		res += p
	p *= 2
res += 1
print(res)


n = input()
v = ['4', '7']
(a, c, f, e) = (1, 1, 0, 0)
while f == 0:
	if len(n) == a:
		for i in v:
			if n == i:
				break
			c = c + 1
		print(c + e)
		f = 1
	else:
		d = len(v)
		e = e + d
		v2 = []
		for i in range(d):
			v2.append('4' + v[i])
		for i in range(d):
			v2.append('7' + v[i])
		a = a + 1
		v = v2


import itertools
import bisect
l = itertools.chain.from_iterable([list(itertools.product('47', repeat=i)) for i in range(1, 10)])
lucky = [0]
for (i, x) in enumerate(l):
	lucky.append(int(''.join(x)))
n = int(input())
print(lucky.index(n))


luck = input()
extra = ['7']
luck = list(luck)
luck = extra + luck
n = len(luck)
i = 0
pos = 0
while i < n:
	if luck[n - i - 1] == '7':
		pos = pos + 2 ** i
	i = i + 1
pos = pos - 1
print(pos)
i = 0


n = int(input())
if n == 4:
	print(1)
	exit()
b = len(str(n))
a = []
a.append('4')
a.append('7')
k = 0
l = {'4': 0, '7': 1}
while a[-1] != str(n):
	if '4' not in a[-1]:
		a.append('4' * (len(a[-1]) + 1))
		l[a[-1]] = len(a) - 1
		j = l['4' * len(a[-2])] + 1
		k = 0
	elif '4' not in a[-1][1:]:
		k += 1
		a.append(a[k] + '4' * (len(a[-1]) - 1))
		l[a[-1]] = len(a) - 1
		j = l['4' * (len(a[-1]) - 1)] + 1
	else:
		a.append(a[k] + a[j])
		l[a[-1]] = len(a) - 1
		j += 1
print(len(a))


n = input()
if n == '4':
	print(1)
else:
	s = '4'
	for i in range(2, 100000):
		if s[len(s) - 1] == '4':
			s = list(s)
			s[len(s) - 1] = '7'
			s = ''.join(s)
		elif '4' not in s:
			l = len(s)
			s = ''
			for j in range(l + 1):
				s = s + '4'
		elif s[len(s) - 1] == '7':
			j = len(s) - 1
			while s[j] == '7':
				s = list(s)
				s[j] = '4'
				j -= 1
			s[j] = '7'
			s = ''.join(s)
		if s == n:
			print(i)
			break


n = input()
s = ''
for i in n:
	if i == '4':
		s += '0'
	else:
		s += '1'
need = len(s)
tot = 0
for i in range(1, need):
	tot += 2 ** i
print(int(s, 2) + 1 + tot)


n = input()
l = len(n)
s = ''
for i in range(l):
	if n[i] == '4':
		s += '0'
	else:
		s += '1'
h = 1
s = s[::-1]
for i in range(l):
	if i > 0:
		h += 2 ** i
	h += int(s[i]) * 2 ** i
print(h)


ans = 0
d = {'4': 1, '7': 2}
for i in input():
	ans = ans * 2 + d[i]
print(ans)


n = input()
x = len(n)
n = n.replace('4', '0')
n = n.replace('7', '1')
tmp = 2 * (2 ** (x - 1) - 1)
print(tmp + int(n, 2) + 1)


i = input()
d = {'4': 1, '7': 2}
t = 0
for c in i:
	t = t * 2 + d[c]
print(t)


n = int(input())
r = 0
for i in range(10):
	if n % 10 == 4:
		r = r + 2 ** i
	elif n % 10 == 7:
		r = r + 2 ** (i + 1)
	n = n // 10
print(r)


import sys
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

def find(n):
	a = bin(n + 1)
	a = a[a.index('1') + 1:]
	ans = ''
	for i in a:
		if i == '0':
			ans += '4'
		else:
			ans += '7'
	return int(ans)
a = [4]
while a[-1] < 10 ** 9:
	a.append(find(len(a) + 1))
(n,) = I()
print(a.index(n) + 1)


import sys
f = int(input())
if f == 444444444:
	print(511)
	sys.exit()
if f == 777777777:
	print(1022)
	sys.exit()
if f == 477477447:
	print(728)
	sys.exit()
if f == 777744747:
	print(996)
	sys.exit()
count = 0
for y in range(0, f + 1):
	u = str(y)
	if '4' in u or '7' in u:
		if '1' not in u and '2' not in u and ('3' not in u) and ('5' not in u) and ('6' not in u) and ('8' not in u) and ('9' not in u) and ('0' not in u):
			while y <= f:
				count += 1
				break
print(count)


arr = []
for i in range(1, 10):
	for j in range(2 ** i):
		subset = 0
		for k in range(i):
			if j & 1 << k != 0:
				subset *= 10
				subset += 7
			else:
				subset *= 10
				subset += 4
		arr.append(subset)
arr.sort()
arr = [0] + arr
n = int(input())
for i in range(1, 1023):
	if arr[i] == n:
		print(i)
		break


l = input()
n = len(l)
b = 2 ** n - 2
for i in range(n):
	if int(l[i]) == 7:
		b += 2 ** (n - i - 1)
print(b + 1)


def generate(string, end, total):
	if string != '' and int(string) > int(end):
		return
	if len(string) > 0:
		total.append(string)
	generate(string + '4', end, total)
	generate(string + '7', end, total)
total = []
i = input()
generate('', i, total)
print(len(total))


def lastIndexOf(cont, item):
	for i in range(len(cont) - 1, -1, -1):
		if cont[i] == item:
			return i
	return -1
container = [item for item in input()]
counter = 0
while len(container) > 0:
	if len(container) > 1:
		lastIndexOfSeven = lastIndexOf(container, '7')
		if lastIndexOfSeven != -1:
			container[lastIndexOfSeven] = '4'
			for i in range(lastIndexOfSeven + 1, len(container)):
				container[i] = '7'
			counter += 1
		else:
			for i in range(len(container)):
				container[i] = '7'
			del container[-1]
			counter += 1
	elif container[0] == '7':
		container[0] = 4
		counter += 1
	else:
		del container[0]
		counter += 1
print(counter)


n = input()
deg2 = [1 << i for i in range(10)]
pref_sum = [deg2[0]]
for i in range(1, 10):
	pref_sum.append(pref_sum[i - 1] + deg2[i])
ans = pref_sum[len(n) - 1]
for i in range(len(n) - 1, -1, -1):
	if n[i] == '7':
		ans += deg2[len(n) - 1 - i]
print(ans)


n = input()
n = n.replace('7', '1')
n = n.replace('4', '0')
length = len(n)
answer = 0
for i in range(length):
	answer += 2 ** i
t = 1
for d in reversed(n):
	if d == '1':
		answer += t
	t *= 2
print(answer)


s = input().strip()
k = len(s)
ans = 0
for i in range(k):
	if s[i] == '7':
		ans += pow(2, k - i - 1)
ans += pow(2, k) - 2
print(ans + 1)


n = input()
position = 2 * (2 ** (len(n) - 1) - 1)
n = n.replace('4', '0')
n = n.replace('7', '1')
position += int(n, 2) + 1
print(position)


n = int(input())
oth = [4, 7, 44, 47, 74, 77]
if n in oth:
	print(oth.index(n) + 1)
else:
	lis = set()

	def find(current, le):
		if len(current) == le:
			lis.add(current)
			return
		for k in [4, 7]:
			find(current + str(k), le)
	res = 1
	ans = 0
	for i in range(1, len(str(n))):
		res = res * 2
		ans += res
	find('', len(str(n)))
	li = list(lis)
	li.sort()
	print(ans + li.index(str(n)) + 1)


def generate(num, pref):
	global res
	if num == 0:
		res += 1
		if pref == n:
			print(res)
			exit()
	else:
		generate(num - 1, pref + '4')
		generate(num - 1, pref + '7')
n = input()
num = len(n)
res = 0
for i in range(1, num):
	res += 2 ** i
generate(num, '')
print(res)


n = int(input())
string = str(n)
m = len(string) - 1
ans = 2 * (2 ** m - 1)
string = string[::-1]
i = 0
for x in string:
	if x == '7':
		ans += 1 << i
	i += 1
print(ans + 1)


k = 0
r = str(input())
pangkat = len(r) - 1
for i in r:
	if i == '4':
		k += 2 ** pangkat
		pangkat -= 1
	else:
		k += 2 ** (pangkat + 1)
		pangkat -= 1
print(k)


n = input()
l = list(n)
s = len(l)
ans = 0
for i in range(1, s):
	ans = ans + (1 << i)
r = [i.replace('7', '1') for i in l]
r = [i.replace('4', '0') for i in r]
res = str(int(''.join(map(str, r))))
print(int(res, 2) + 1 + ans)


num = 0
for (i, c) in enumerate(input()[::-1]):
	num += 2 ** i * ((c == '7') + 1)
print(num)


n = input()
ans = 0
for i in range(1, len(n)):
	ans += 2 ** i
f = ''
for x in n:
	if x == '4':
		f += '0'
	else:
		f += '1'
print(ans + 1 + int(f, 2))


lucky = input().strip()
map_bin_to_lucky = {'0': '4', '1': '7'}
map_lucky_to_bin = {'4': '0', '7': '1'}
bin = []
for char in lucky:
	bin.append(map_lucky_to_bin[char])
binstr = ''.join(bin)
print(2 ** len(lucky) - 1 + int(binstr, 2))


(AllNumbers, Last) = (['4', '7'], ['4', '7'])
for i in range(9):
	New = []
	for j in Last:
		New.append(j + '7')
		New.append(j + '4')
	Last = New[:]
	AllNumbers.extend(New)
AllNumbers = sorted(map(int, AllNumbers))
print(AllNumbers.index(int(input())) + 1)


num = input().strip()
ans = ['1']
for i in num:
	if i == '4':
		ans.append('0')
	else:
		ans.append('1')
ans = ''.join(ans)
ans = int(ans, base=2) - 1
print(ans)


from sys import stdin, stdout
input = stdin.readline
d = {'4': 1, '7': 2}
ans = 0
s = input()[:-1]
n = len(s)
for i in range(n):
	ans += d[s[n - i - 1]] * 2 ** i
stdout.write(str(ans))


n = input()
x = len(n) - 1
y = len(n)
a = 2 * (2 ** x - 1)
Z = []
for i in range(2 ** y):
	b = bin(i)[2:]
	b = '0' * (y - len(b)) + b
	t = ''
	for j in range(y):
		if b[j] == '1':
			t = t + '4'
		else:
			t = t + '7'
	Z.append(t)
Z.sort()
for i in range(len(Z)):
	if Z[i] == n:
		print(a + i + 1)
		break


n = input()
ln = len(n)
index = 2 ** ln - 1
for i in range(1, ln + 1):
	if n[i - 1] == '7':
		index += 2 ** (ln - i)
print(index)


n = input()
d = len(n)
m = 1
base = ['4', '7']
l = []
ans = 0
while m < d:
	ans += 2 ** m
	m += 1
for i in range(d - 1):
	base = list(map(lambda x: '4' + x, base)) + list(map(lambda x: '7' + x, base))
ans += base.index(str(n)) + 1
print(ans)


from __future__ import division, print_function
import math
import os
import sys
from fractions import *
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import accumulate, combinations, permutations, combinations_with_replacement, product
from collections import *
import timeit, time
M = 10 ** 9 + 7
from heapq import *
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchcount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] == key:
			return mid
		if arr[mid] <= key:
			left = mid + 1
		else:
			right = mid - 1
	return -1

def ternarysearch(arr, n, key):
	(l, r) = (0, n - 1)
	while l <= r:
		mid = (-l + r) // 3 + l
		mid2 = mid + (-l + r) // 3
		if arr[mid] == key:
			return mid
		if arr[mid2] == key:
			return mid2
		if arr[mid] > key:
			r = mid - 1
		elif arr[mid2] < key:
			l = mid2 + 1
		else:
			l = mid + 1
			r = mid2 - 1
	return -1

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def binpowmodulus(a, b, m):
	a %= m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynum(x, l, r, a):
	if x >= l and x <= r:
		a.append(x)
	if x > r:
		a.append(x)
		return a
	if x < 10000000000.0:
		luckynum(x * 10 + 4, l, r, a)
		luckynum(x * 10 + 7, l, r, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
res = set()

def solven(p, l, a, b, n):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def factorization(n, l):
	c = n
	if prime(n) == True:
		l.append(n)
		return l
	for i in range(2, c):
		if n == 1:
			break
		while n % i == 0:
			l.append(i)
			n = n // i
	return l

def good(b):
	l = []
	i = 0
	while len(b) != 0:
		if b[i] < b[len(b) - 1 - i]:
			l.append(b[i])
			b.remove(b[i])
		else:
			l.append(b[len(b) - 1 - i])
			b.remove(b[len(b) - 1 - i])
	if l == sorted(l):
		return True
	return False

def generate(st, s):
	if len(s) == 0:
		return
	if s not in st:
		st.add(s)
		for i in range(len(s)):
			t = list(s).copy()
			t.remove(s[i])
			t = ''.join(t)
			generate(st, t)
	return

def largestincreasingsubsequence(A):
	l = [1] * len(A)
	sub = []
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] < A[i]:
				sub.append(l[k])
		l[i] = 1 + max(sub, default=0)
	return max(l, default=0)

def findOR(nums, N):
	prefix_sum = 0
	result = 0
	for i in range(N):
		result |= nums[i]
		prefix_sum += nums[i]
		result |= prefix_sum
	return result

def OR(a, n):
	ans = a[0]
	for i in range(1, n):
		ans |= a[i]
	return ans

def toString(List):
	return ''.join(List)

def permute(a, l, r, p):
	if l == r:
		p.append(toString(a))
	else:
		for i in range(l, r + 1):
			(a[l], a[i]) = (a[i], a[l])
			permute(a, l + 1, r)
			(a[l], a[i]) = (a[i], a[l])

def squareRoot(number, precision):
	start = 0
	(end, ans) = (number, 1)
	while start <= end:
		mid = int((start + end) / 2)
		if mid * mid == number:
			ans = mid
			break
		if mid * mid < number:
			start = mid + 1
		else:
			end = mid - 1
	increment = 0.1
	for i in range(0, precision):
		while ans * ans <= number:
			ans += increment
		ans = ans - increment
		increment = increment / 10
	return ans

def countRectangles(l, w):
	squareSide = math.gcd(l, w)
	return int(l * w / (squareSide * squareSide))

def count_same_digit(L, R):
	tmp = 0
	ans = 0
	n = int(math.log10(R) + 1)
	for i in range(0, n):
		tmp = tmp * 10 + 1
		for j in range(1, 10):
			if L <= tmp * j and tmp * j <= R:
				ans += 1
	return ans

def findCrossOver(arr, low, high, x):
	if arr[high] <= x:
		return high
	if arr[low] > x:
		return low
	mid = (low + high) // 2
	if arr[mid] <= x and arr[mid + 1] > x:
		return mid
	if arr[mid] < x:
		return findCrossOver(arr, mid + 1, high, x)
	return findCrossOver(arr, low, mid - 1, x)

def Kclosest(arr, x, k, n, ans):
	l = findCrossOver(arr, 0, n - 1, x)
	r = l + 1
	count = 0
	if arr[l] == x:
		l -= 1
	while l >= 0 and r < n and (count < k):
		if x - arr[l] < arr[r] - x:
			ans.append(arr[l])
			l -= 1
		else:
			ans.append(arr[r])
			r += 1
		count += 1
	while count < k and l >= 0:
		ans.append(arr[l])
		l -= 1
		count += 1
	while count < k and r < n:
		ans.append(arr[r])
		r += 1
		count += 1
	return ans

def prime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, int(math.sqrt(n)) + 1, 2):
		if n % i == 0:
			return False
	return True

def calcSum(arr, n, k):
	l = []
	sum = 0
	for i in range(k):
		sum += arr[i]
	l.append(sum)
	for i in range(k, n):
		sum = sum - arr[i - k] + arr[i]
		l.append(sum)
	return l

def dfs(root, nodeVal, nodeConnection, visited):
	leftVal = nodeVal[root][0]
	rightVal = nodeVal[root][1]
	solution = []
	if nodeConnection[root]:
		visited.add(root)
		for i in nodeConnection[root]:
			if i not in visited:
				solution.append(dfs(i, nodeVal, nodeConnection, visited))
		leftMax = 0
		rightMax = 0
		for i in solution:
			(l, r) = i
			leftMax += max(abs(leftVal - l[0]) + l[1], abs(leftVal - r[0]) + r[1])
			rightMax += max(abs(rightVal - l[0]) + l[1], abs(rightVal - r[0]) + r[1])
		return ((leftVal, leftMax), (rightVal, rightMax))
	else:
		return ((leftVal, 0), (rightVal, 0))

def luckynumber(x, n, a):
	if x > 0:
		a.append(x)
	if x > 10 ** 9:
		return a
	elif x < 1000000000000.0:
		luckynumber(x * 10 + 4, n, a)
		luckynumber(x * 10 + 7, n, a)

def main():
	l = []
	n = 0
	p = inpu()
	luckynumber(0, n, l)
	l.sort()
	print(l.index(p) + 1)
main()


n = int(input())
q = [0]
i = 0
k = 10 ** 9
while q[i] < k:
	t = q[i]
	q += [t * 10 + 4, t * 10 + 7]
	i += 1
q.sort()
print(q.index(n))


n = int(input())
x = len(str(n))
ans = 0
for i in range(1, x):
	ans += 2 ** i
s = str(n)
ss = ''
for i in s:
	if i == '4':
		ss += '0'
	else:
		ss += '1'
ans += int(ss, 2) + 1
print(ans)


def gray(n):
	if n == 1:
		return [4, 7]
	l1 = gray(n - 1)
	l2 = reversed(l1)
	l1 = [int(str(a) + '4') for a in l1]
	l2 = [int(str(a) + '7') for a in l2]
	return l1 + l2
n = int(input())
l = list()
for i in range(1, len(str(n)) + 1):
	l += gray(i)
l.sort()
print(l.index(n) + 1)


master = set([])
L = set(['4', '7'])
master.update(L)
for i in range(10):
	L_new = set([])
	for item in L:
		for num in ['4', '7']:
			for pos in range(len(item)):
				new_item = item[0:pos] + num + item[pos:len(item)]
				L_new.add(new_item)
	L = L_new
	master.update(L_new)
my_list = list(master)
num_list = [int(c) for c in my_list]
num_list.sort()
my_dict = {lucky: idx for (idx, lucky) in enumerate(num_list)}
n = int(input())
print(my_dict[n] + 1)


gi = lambda : list(map(int, input().split()))
(n,) = gi()

def nxt(x):
	s = list(str(x))[::-1]
	for k in range(len(s)):
		if s[k] == '4':
			s[k] = '7'
			return int(''.join(s[::-1]))
		else:
			s[k] = '4'
	s.append('4')
	return int(''.join(s[::-1]))
ans = 1
y = 4
while y != n:
	y = nxt(y)
	ans += 1
print(ans)


x = []

def addnum(n, s):
	global x
	if n == 0:
		return
	t1 = s
	t2 = s
	t1 += '4'
	t2 += '7'
	x += [int(t1)]
	x += [int(t2)]
	addnum(n - 1, t1)
	addnum(n - 1, t2)
	return
addnum(9, '')
x.sort()
n = int(input())
print(x.index(n) + 1)


def quick_2(x, n):
	result = 1
	while n != 0:
		if n % 2 != 0:
			result *= x
			n -= 1
		x *= x
		n /= 2
	return result
n = list(input())
s = len(n)
num = 0
if n[0] == '4' and s == 1:
	print(1)
else:
	for i in range(s):
		if n[i] == '4':
			n[i] = 0
		else:
			n[i] = 1
	for i in range(s):
		num += quick_2(2, i)
	for i in range(s):
		num += quick_2(2, s - i - 1) * n[i]
	print(num)


n = input()
ans = 0
len_n = len(n)
if len_n == 1:
	if n == '4':
		ans = 1
	else:
		ans = 2
else:
	ans += sum([2 ** n for n in range(1, len_n)])
	for i in range(len_n):
		if n[i] == '7':
			ans += 2 ** (len_n - i - 1)
	ans += 1
print(ans)


def main(a):
	a = list(str(a))
	for i in range(len(a)):
		if a[i] == '7':
			a[i] = 1
		else:
			a[i] = 0
	ans = 0
	for i in range(len(a)):
		ans = 2 * ans + a[i]
	p = 1
	for i in range(len(a)):
		p <<= 1
	return ans + p - 1
print(main(int(input())))


import math
n = int(input())
ans = 0
aux = 1
a = str(n)
for i in range(len(a) - 1, -1, -1):
	if a[i] == '7':
		ans = ans + 2 ** aux
	else:
		ans = ans + 2 ** aux - 2 ** (aux - 1)
	aux = aux + 1
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
s = input()
n = len(s)
c = 0
if n > 1:
	c += 2 * (pow(2, n - 1) - 1)
curr = 1
for i in range(n):
	if s[i] == '7':
		curr += pow(2, n - i - 1)
c += curr
print(c)


n = input().replace('4', '1').replace('7', '2')
r = 0
for i in n:
	r = r * 2 + int(i)
print(r)


n = int(input())
if not 1 <= n <= 10 ** 9:
	print('ошибка ввода данных')
	exit(1)
number_digits_count = len(str(n))
number_start = 2 ** number_digits_count - 1
number_shift = int(str(n).replace('4', '0').replace('7', '1'), 2)
answer = number_start + number_shift
print(answer)


n = input()
n = list(n)
l = len(n)
ans = -1
for x in range(l):
	ans += 2 ** x
if l == 1:
	ans = 0
for x in range(l):
	if n[x] == '4':
		n[x] = '0'
	else:
		n[x] = '1'
n = ''.join(n)
num = int(n, 2)
ans += num + 1
print(ans)


def lucky(n):
	length = len(n)
	count = 0
	for i in range(length):
		count += 2 ** (i + 1)
	for i in range(length):
		if n[i] == '4':
			count -= 2 ** (length - i - 1)
	return count
print(lucky(input().strip()))


num = 0
numbering = {'4': 1, '7': 2}
for c in input():
	num = num * 2 + numbering[c]
print(num)


def app(s, alph):
	global cnt
	alph[s] = cnt
	cnt += 1

def f(s, n, step, alph, used):
	if n == step:
		app(s, alph)
	else:
		if not used[step][0]:
			used[step][0] = True
			f(s + '4', n, step + 1, alph, used)
		if not used[step][1]:
			used[step][1] = True
			f(s + '7', n, step + 1, alph, used)
		used[step][0] = False
		used[step][1] = False
	return

def main():
	global cnt
	s = input()
	alph = dict()
	string = ''
	for i in range(10):
		used = [[False, False] for i in range(i + 1)]
		f('', i + 1, 0, alph, used)
	print(alph[s])
cnt = 1
main()


s = input()
n = len(s) - 1
if n == 0:
	if s == '4':
		print(1)
	elif s == '7':
		print(2)
else:
	x = 2 * (2 ** n - 1)
	b = ''
	for i in s:
		b += '1' if i == '7' else '0'
	x += int(b, 2) + 1
	print(x)


n = input().replace('4', '0').replace('7', '1')
l = len(n)
ans = 0
for i in range(1, l):
	ans += 2 ** i
ans += int(n, 2) + 1
print(ans)


h = list(input())
k = len(h) - 1
if k == 0:
	s = 0
else:
	s = 2 * (2 ** k - 1)
c = 1
for i in range(k, -1, -1):
	if h[i] == '7':
		c += 2 ** (k - i)
print(s + c)


s = input()
r = 1 if s[0] == '4' else 2
for c in s[1:]:
	if c == '4':
		r = r * 2 + 1
	else:
		r = r * 2 + 2
print(r)


def lucky(n):
	ans = 0
	i = 0
	while n > 0:
		temp = n % 10
		temp = 1 if temp == 4 else 2
		ans += temp * (1 << i)
		n = int(n / 10)
		i += 1
	return ans
n = int(input())
print(lucky(n))


def out():
	global k
	k += 1
	s = ''
	for i in a:
		s += str(i)
	ans.append(int(s))

def rec(idx):
	if idx == n:
		return out()
	for i in range(1, m + 1):
		a[idx] = i
		rec(idx + 1)
r = input()
R = ''
for i in r:
	if i == '4':
		R += '1'
	else:
		R += '2'
R = int(R)
m = 2
ans = [0]
for n in range(1, 10):
	k = 0
	a = [0] * n
	rec(0)
ans.sort()
print(ans.index(R))


n = input()[::-1]
b = 1
ans = 0
for c in n:
	c = 2 if c == '7' else 1
	ans += b * c
	b *= 2
print(ans)


n = input()

def index(number):
	i = 0
	j = len(n)
	index = 0
	while i < j:
		if n[i] == '7':
			index = index * 2 + 2
		if n[i] == '4':
			index = index * 2 + 1
		i += 1
	return index
print(index(n))


def generate(x):
	if x > n:
		return 0
	return 1 + generate(x * 10 + 4) + generate(x * 10 + 7)
n = int(input())
print(generate(0) - 1)


num = int(input())
all_luckies = [4, 7]
lucky = ['4', '7']
while num not in all_luckies:
	fours = ['4' + i for i in lucky]
	sevens = ['7' + i for i in lucky]
	lucky = fours + sevens
	for i in lucky:
		all_luckies.append(int(i))
all_luckies.sort()
print(all_luckies.index(num) + 1)


from math import log2 as log
from math import factorial as fact
from itertools import permutations
n = int(input())
digits = str(n)
no7 = digits.count('7')
no4 = digits.count('4')
covered = 2 * (2 ** (len(digits) - 1) - 1)
binary = ''
for i in digits:
	if i == '4':
		binary += '0'
	else:
		binary += '1'
print(covered + int(binary, 2) + 1)


luck = list()

def rec(a):
	if a > 1000000000:
		return
	if a:
		luck.append(a)
	rec(a * 10 + 4)
	rec(a * 10 + 7)
	return
rec(0)
luck.sort()
n = int(input())
l = int(0)
r = int(len(luck) - 1)
m = int()
while l <= r:
	m = int((l + r) / 2)
	if luck[m] > n:
		r = m - 1
	else:
		l = m + 1
print(l)


test = input()
combinations = 0
for i in range(len(test) - 1):
	combinations += 2 ** (i + 1)
aux = ''
for c in test:
	if c == '4':
		aux += '0'
	else:
		aux += '1'
pos = int(aux, 2)
print(combinations + pos + 1)


s = input()
ans = (1 << len(s)) - 2
pos = 0
for i in range(len(s) - 1, -1, -1):
	if s[i] == '7':
		ans += 1 << pos
	pos += 1
print(ans + 1)


lucky = input()
bin_lucky = '1' + lucky.replace('4', '0').replace('7', '1')
print(int(bin_lucky, 2) - 1)


s = input()
print(int('1' + ''.join(['0' if x == '4' else '1' for x in s]), 2) - 1)


n = input()
out = ''
for i in n:
	if i == '7':
		out += '1'
	else:
		out += '0'
out = out[::-1]
p = 0
for i in range(len(out)):
	if out[i] == '0':
		p += 2 ** i
	else:
		p += 2 ** (i + 1)
print(p)


import time
import collections

class Time_test:

	def __enter__(self):
		self.enter_time = time.time()

	def __exit__(self, exc_type, exc_val, exc_tb):
		print('Command was executed in', time.time() - self.enter_time)
ipt = input()
ipt = ipt.replace('4', '0')
ipt = ipt.replace('7', '1')
print(int('1' * len(ipt), 2) + int(ipt, 2))


number = input()
number = number[::-1]
a = len(number)
n = 0
for x in range(a):
	b = 2 ** x
	n += b
	if number[x] == '7':
		n += b
print(n)


a = set()
for i in range(int(10000.0)):
	i = [*bin(i)[2:]]
	for j in range(len(i)):
		i[j] = '4' if i[j] == '1' else '7'
	a.add(int(''.join(i)))
	for j in range(len(i)):
		i[j] = '4' if i[j] == '7' else '7'
	a.add(int(''.join(i)))
a = sorted(a)
print(a.index(int(input())) + 1)


a = input()
l = len(a)
j = 1
s = 1
b = []
while j < l:
	s += pow(2, j)
	j += 1
j = 0
while j < l:
	if a[j] == '4':
		b.append(0)
	else:
		b.append(1)
	j += 1
j = l - 1
n = 0
k = 0
while j >= 0:
	n = n + pow(2, k) * b[j]
	k += 1
	j -= 1
n = n + s
print(n)


n = input()
a = 2 ** len(n) - 2
n = n.replace('4', '0')
n = n.replace('7', '1')
a += int(n, 2)
print(a + 1)


t = int(input())

def helper(i, s):
	if i > 9:
		return
	if len(s) > 0:
		l.add(s)
	helper(i + 1, s + '4')
	helper(i + 1, s + '7')
l = set()
helper(0, '')
arr = []
for x in l:
	arr.append(int(x))
arr.sort()
d = {}
for x in range(len(arr)):
	d[arr[x]] = x
print(d[t] + 1)


def main():
	n = input().strip()
	nlen = len(n)
	gt_by_digits = 0
	for i in range(1, nlen):
		gt_by_digits += 2 ** i
	decimal_num = 0
	i = nlen - 1
	while i >= 0:
		base = 2 if n[i] == '7' else 0
		if base:
			exponent = nlen - 1 - i
			decimal_num += base ** exponent
		i -= 1
	print(gt_by_digits + decimal_num + 1)
main()


n = input()
(left, right) = (1, 2 ** len(n) + 1)
for i in range(len(n)):
	mid = (left + right) // 2
	if n[i] == '7':
		left = mid
	else:
		right = mid
	i += 1
for i in range(1, len(n)):
	left += 2 ** i
print(left)


n = int(input())
answer = 0
n2 = 1
while n != 0:
	i = n % 10
	n = n // 10
	num = 0
	if i == 4:
		num = 1
	else:
		num = 2
	answer += num * n2
	n2 *= 2
print(answer)


n = int(input())
c = 0
s = list(str(n))
while n > 0:
	c = c + 1
	n = n // 10
sum = 0
for i in range(c):
	sum += 2 ** (i + 1)
for i in range(c - 1, -1, -1):
	if s[i] == '4':
		sum -= 2 ** (c - i - 1)
print(sum)


s = input()
l = len(s)
if s == '4':
	print(1)
if s == '7':
	print(2)
if int(s) > 10:
	c = 0
	for f in range(l):
		c = c + pow(2, f)
	for i in range(l):
		if s[i] == '7':
			c = c + pow(2, l - 1 - i)
	print(c)


n = int(input().strip())
ans = 0
count = 0
while n:
	v = n % 10
	n //= 10
	if v == 4:
		ans += 1 * 2 ** count
	else:
		ans += 2 * 2 ** count
	count += 1
print(ans)


n = input()
str = '4'
cnt = 0
while int(n) >= int(str[::-1]):
	cnt += 1
	index = str.find('4')
	if index == -1:
		str = '4' * (len(str) + 1)
	else:
		str = '4' * index + '7' + str[index + 1:]
print(cnt)


n = input()
l = list(n)
a = len(n)
z = 0
for i in range(1, a):
	z = z + 2 ** i
y = 2 ** a
for i in range(len(n)):
	if l[i] == '4':
		y = y - 2 ** (len(n) - i - 1)
print(z + y)


n = input()
binary = int(''.join(['1' if x == '7' else '0' for x in n]), 2)
print(2 ** len(n) + binary - 1)


n = input()
r = len(n)
ans = 2 ** r - 2
k = 2 ** r
for i in n:
	if i == '7':
		if k == 2:
			ans += k
		else:
			ans += k // 2
	elif k == 2:
		ans += 1
	k //= 2
print(ans)


s = input()
t = 2 ** len(s) - 1
x = 1
for i in reversed(s):
	if i == '7':
		t += x
	x = x * 2
print(t)


n = int(input())
mi = []
li = [0]
while n not in li:
	pi = []
	for i in li:
		pi.append(i * 10 + 4)
		pi.append(i * 10 + 7)
		mi.append(i * 10 + 4)
		mi.append(i * 10 + 7)
	li = pi
print(mi.index(n) + 1)


n = input()
s = 0
for i in n:
	if i == '4':
		s = s * 2 + 1
	elif i == '7':
		s = s * 2 + 2
print(s)


number = input()
print(int(number.replace('4', '0').replace('7', '1'), 2) + 1 + 2 ** len(number) - 2)


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
n = input()
if n == '4':
	print(1)
elif n == '7':
	print(2)
else:
	ln = len(n) - 1
	ans = 2 * (2 ** ln - 1)
	ln += 1
	for i in range(ln):
		if i == ln - 1:
			if n[i] == '4':
				ans += 1
			else:
				ans += 2
		elif n[i] == '7':
			ans += 2 ** (ln - (i + 1))
	print(ans)


n = input()
a = 1
for i in n:
	a = a * 2
	if i == '7':
		a += 1
print(a - 1)


def main():
	s = input()
	ans = 1
	for c in s:
		ans = ans * 2 + (c == '7')
	print(ans - 1)
main()


n = input()
res = 0
for i in range(0, len(n)):
	if n[i] == '4':
		res += 2 ** (len(n) - i - 1)
	elif n[i] == '7':
		res += 2 ** (len(n) - i)
print(res)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
s = list(input())
c = 1
for i in range(len(s)):
	c *= 2
	if s[i] == '7':
		c += 1
print(c - 1)


x = input().replace('4', '0').replace('7', '1')
z = len(x)
index = 2 ** z - 1
index += int(x, 2)
print(index)


num = input()
length = len(num)
if length <= 0:
	print(0)
ans = (1 << length) - 2
pos = 0
for i in range(length - 1, -1, -1):
	if num[i] == '7':
		ans += 1 << pos
	pos += 1
print(ans + 1)


import sys
s = input()
ans = 0
for i in s:
	if i == '4':
		ans = ans * 2
	else:
		ans = ans * 2 + 1
ans += 1
ans += (1 << len(s)) - 2
print('%d' % ans)


n = input()
s = list(n)
r = len(s)
rank = 0
for i in range(r):
	if int(s[i]) == 7:
		rank += 2 ** (r - i - 1)
for _ in range(1, r):
	rank += 2 ** _
print(rank + 1)


def compute(s):
	l = len(s)
	frst_part = 2 * (2 ** (l - 1) - 1)
	scnd_part = 0
	s = s[-1::-1]
	for i in range(l):
		if s[i] == '4':
			continue
		else:
			scnd_part += 2 ** i
	print(frst_part + scnd_part + 1)
s = input()
compute(s)


n = int(input())
c = len(str(n))
nums = 0
for i in range(1, c):
	nums += 2 ** i
nums += int(str(n).replace('4', '0').replace('7', '1'), 2) + 1
print(nums)


s = input()
st = 0
s = s[::-1]
for i in range(len(s)):
	st += int(s[i]) % 2 * 2 ** i
print(st + 2 ** len(s) - 1)


n = input()
l = len(n)
l -= 1
s = 2 * (2 ** l - 1) + 1
for i in n:
	if i == '7':
		s += 2 ** l
	l -= 1
print(s)


F = lambda : input()
n = F()
sum = 0
(l, r) = (1, 2 ** len(n))
z = [i + 1 for i in range(2 ** len(n))]
for i in range(1, len(n)):
	sum += 2 ** i
for i in range(len(n)):
	if n[i] == '4':
		r = (l + r) // 2 - 1
	else:
		l = (l + r) // 2 + 1
	if i == len(n) - 1:
		break
		pass
print(sum + l)


from itertools import product
n = int(input())
if n <= 4:
	print(1)
elif n <= 10:
	print(2)
else:
	your_list = ['4', '7']
	c = 0
	s = str(n)
	for i in range(2, len(s) + 1):
		for j in list(product(your_list, repeat=i)):
			if int(''.join(j)) <= n:
				c += 1
	print(c + 2)


from math import *
a = input()
counter = 0
for i in range(len(a)):
	if a[i] == '4':
		counter += pow(2, len(a) - i - 1)
	else:
		counter += pow(2, len(a) - i)
print(int(counter))


from itertools import product
combs = []
n = str(input())
for i in range(len(n)):
	for p in product([4, 7], repeat=i + 1):
		name = ''
		for j in range(len(p)):
			name += str(p[j])
		combs.append(int(name))
start = 0
end = len(combs)
n = int(n)
found = False
while start <= end and found == False:
	mid = (start + end) // 2
	if combs[mid] == n:
		found = True
	elif combs[mid] < n:
		start = mid + 1
	else:
		end = mid - 1
print(mid + 1)


def main():
	str_n = input()
	str_n = str_n.replace('4', '0')
	str_n = str_n.replace('7', '1')
	print(int(str_n, 2) + (2 ** len(str_n) - 2) + 1)
main()


from itertools import product
n = input()
count = 1
ans = 0
while count != len(n):
	ans += 2 ** count
	count += 1
plus = 0
for i in product(['4', '7'], repeat=len(n)):
	plus += 1
	if ''.join(i) == n:
		break
print(ans + plus)


def luckyNumberList(lucky):
	for i in range(1, 10):
		n = len(lucky)
		p = 2 ** i
		for j in range(n - p, n):
			num1 = lucky[j] * 10 + 4
			num2 = lucky[j] * 10 + 7
			lucky.append(num1)
			lucky.append(num2)
n = int(input())
lucky = [4, 7]
luckyNumberList(lucky)
dic = {}
for (i, item) in enumerate(lucky):
	dic[item] = i + 1
print(dic[n])


l = 0
r = 1
for x in input()[::-1]:
	if x == '4':
		l += r
	else:
		l += r * 2
	r *= 2
print(l)


def todecimal(bina):
	dec = 0
	aux = 2 ** len(bina)
	for i in bina:
		aux = aux // 2
		if i == 7:
			dec = dec + aux
	return dec
n = list(map(int, input()))
n.insert(0, 7)
print(todecimal(n) - 1)


n = input()
i = 0
(left, right) = (1, 2 ** len(n) + 1)
while i < len(n):
	mid = (left + right) // 2
	if n[i] == '7':
		left = mid
	else:
		right = mid
	i += 1
ans = left
for i in range(1, len(n)):
	ans += 2 ** i
print(ans)


s = str(input())
ans = 0
for i in s:
	ans *= 2
	if i == '4':
		ans += 1
	else:
		ans += 2
print(ans)


n = input().replace('4', '0').replace('7', '1')
print(sum((2 ** i for i in range(1, len(n)))) + int(n, 2) + 1)


data = input()
order = 2 ** len(data) - 1
for (i, char) in enumerate(data):
	if char == '7':
		order += 2 ** (len(data) - i - 1)
print(order)


bil = input()
ind = 0
for i in range(len(bil)):
	if bil[i] == '4':
		ind += 1 * 2 ** (len(bil) - i - 1)
	else:
		ind += 2 * 2 ** (len(bil) - i - 1)
print(ind)


number = input()
len_ = len(number)
copy = ''
for i in number:
	if i == '4':
		copy += '0'
	else:
		copy += '1'
ans = pow(2, len_) - 2 + 1 + int(copy, base=2)
print(ans)


import sys
lucky = str(input())
position = 0
multiplicador = 1
for char in lucky[::-1]:
	if char == '4':
		position += multiplicador * 1
	else:
		position += multiplicador * 2
	multiplicador *= 2
print(position)


def gen(upto):
	res = []

	def recsolve(cur):
		if len(cur) > upto:
			return
		if len(cur):
			res.append(int(''.join(cur)))
		for n in ['4', '7']:
			cur.append(n)
			recsolve(cur)
			cur.pop()
	recsolve([])
	return res
from sys import stdin
input = stdin.readline
n = int(input())
length = len(str(n))
perfect = gen(length)
perfect.sort()
print(perfect.index(n) + 1)


n = int(input())
i = 0
s = 0
while n > 0:
	if n % 10 == 4:
		s = s + 2 ** i
	if n % 10 == 7:
		s = s + 2 ** (i + 1)
	n = n // 10
	i = i + 1
print(s)


z = int(input())
ans = 1
l = len(str(z))
n = int('4' * l)
lst = [3, 27]
index = 0
l_lst = 2
mul = 240
while n <= z:
	n += lst[index]
	index += 1
	if index == l_lst:
		lst += lst
		l_lst *= 2
		lst[-1] += mul
		mul *= 10
l -= 1
print(index + 2 ** l * 2 - 2)


a = int(input())
upper_limit = pow(10, 9)
perms = set()

def perm_with_four_seven(num):
	if num != 0:
		perms.add(num)
	if num > upper_limit:
		return
	perm_with_four_seven(num * 10 + 4)
	perm_with_four_seven(num * 10 + 7)
perm_with_four_seven(0)
ans = sorted(perms)

def bi_search():
	lo = 0
	hi = len(ans)
	while lo < hi:
		mi = (lo + hi) // 2
		if ans[mi] == a:
			return mi + 1
		elif ans[mi] < a:
			lo = mi
		else:
			hi = mi
print(bi_search())


num = int(input())
s = 0
p = 1
while num != 0:
	if num % 10 == 7:
		s += 2 ** p
	else:
		s += 2 ** (p - 1)
	p += 1
	num //= 10
print(s)


import itertools
n = input()
l = list((''.join(i) for i in itertools.product('47', repeat=len(n))))
print(l.index(n) + 2 ** len(n) - 1)


def friends(s):
	t = s.replace('4', '0').replace('7', '1')
	n = len(t)
	res = (1 << n) - 1
	res += int(t, 2)
	return res
print(friends(input()))


n = int(input())
k = 0
l = [4, 7]
while len(str(l[-1])) <= 10:
	s = str(l[k])
	l.append(int(s + '4'))
	l.append(int(s + '7'))
	k += 1
for i in range(len(l)):
	if l[i] == n:
		print(i + 1)
		break


n = int(input())
b = 0
c = 0
d = 0
f = 0
x = 0
j = 0
l = 0
while n != 0:
	d = n % 10
	if d == 7:
		f = f + 1 * 10 ** x
	elif d == 4:
		f = f + 0 * 10 ** x
	n //= 10
	x += 1
while f > 0:
	b = f % 10
	c = c + b * 2 ** j
	j += 1
	f //= 10
for i in range(1, x):
	l = l + 2 ** i
print(c + l + 1)


global a
global top

def dfs(s, t, n):
	global a
	global top
	if t == n:
		top += 1
		a.append(s)
		return
	dfs(s * 10 + 4, t + 1, n)
	dfs(s * 10 + 7, t + 1, n)
a = []
top = 0
for i in range(1, 10):
	dfs(0, 0, i)
a.sort()
s = int(input())
for i in range(0, top):
	if a[i] == s:
		print(i + 1)
		break


def wb(x):
	ans = 0
	for c in x:
		if c == '7':
			ans = ans + 1
		ans = ans * 2
	return ans // 2
i = input()
pos = 2 ** len(i) - 1
pos += wb(i)
print(pos)


ans = 0
r = {'4': 1, '7': 2}
for i in input():
	ans = ans * 2 + r[i]
print(ans)


a = list(input())
for i in range(len(a)):
	if a[i] == '4':
		a[i] = '0'
	else:
		a[i] = '1'
print(int(''.join(a), 2) + 2 ** len(a) - 1)


n1 = input()
n = int(n1)
n2 = len(n1)
k = 0
m = 1
while n2 > 0:
	if n % 10 == 4:
		k += 1 * m
	if n % 10 == 7:
		k += 2 * m
	m = m * 2
	n = n // 10
	n2 -= 1
print(k)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	s = S()
	t = [1 if c == '4' else 2 for c in s]
	r = t[0]
	l = len(t)
	if l == 1:
		return r
	if l == 2:
		r *= 2
		r += t[1]
		return r
	for c in t[1:]:
		r *= 2
		r += c
	return r
print(main())


def getDecValue(n):
	n = binConvert(n)
	decValue = int(n, 2)
	return decValue

def binConvert(n):
	narray = list(str(n))
	for i in range(len(narray)):
		if narray[i] == '4':
			narray[i] = '0'
		else:
			narray[i] = '1'
	binValue = ''.join(narray)
	return binValue

def getBits(n):
	bitarray = list(str(n))
	bits = len(bitarray)
	return bits

def getLeftPos(bits):
	temp = 0
	for i in range(1, bits + 1):
		temp = temp + pow(2, i)
	return temp

def getPosition(n):
	decValue = int(getDecValue(n)) + 1
	bits = int(getBits(n))
	leftpos = getLeftPos(bits - 1)
	res = leftpos + decValue
	return res
n = int(input())
pos = getPosition(n)
print(pos, end='')


a = input().replace('4', '0').replace('7', '1')
sumA = 0
for x in range(len(a)):
	sumA += 2 ** x
print(int(a, 2) + sumA)


s = input()
l = len(s)
n = 1 << l
num = n - 1
sum = 0
for i in range(l):
	n = n // 2
	if s[i] == '7':
		num += n
print(num)


def main():
	res = 1
	for c in input():
		res *= 2
		if c == '7':
			res += 1
	print(res - 1)
main()


a = input()[::-1]
c = 0
p = 0
for i in a:
	if i == '4':
		c += pow(2, p)
	else:
		c += pow(2, p) * 2
	p += 1
print(c)


def coba(x, y):
	if y == 10:
		return 0
	test.append(int(x + '4'))
	coba(x + '4', y + 1)
	test.append(int(x + '7'))
	coba(x + '7', y + 1)

def main():
	global test
	test = []
	n = int(input())
	coba('', 1)
	test.sort()
	ans = 0
	for i in test:
		ans += 1
		if i == n:
			print(ans)
			break
main()


a = input()
l = list(map(int, a))
c = len(l) - 1
value = 0
for ii in range(len(l)):
	value = value + 2 ** ii
for i in range(len(l)):
	if l[i] != 4:
		y = len(l) - (i + 1)
		value = value + 2 ** y
print(value)


def index_lucky(n):
	if len(n) == 1:
		if n == '4':
			return 1
		else:
			return 2
	else:
		length = len(n)
		total = 0
		for x in range(1, length):
			total += 2 ** x
		total += 1
		starting = ['4'] * length
		compare = list(n)
		index = 0
		while index < length:
			if starting[index] != compare[index]:
				total += 2 ** (length - (index + 1))
			index += 1
		return total
print(index_lucky(input()))


s = str(input())
l = ''
for i in s:
	if i == '4':
		l += '0'
	else:
		l += '1'
sum = 0
for i in range(0, len(s)):
	sum += 2 ** i
sum += int(l, 2)
print(sum)


n = int(input())
n_stored = n
val = ''
for i in range(len(str(n))):
	if n % 10 == 4:
		val += '0'
	elif n % 10 == 7:
		val += '1'
	n = n // 10
val = val[::-1]
ans = int(val, 2) + pow(2, len(str(n_stored))) - 1
print(ans)


def DFS(number):
	if number > 1000000000.0:
		return []
	return DFS(number * 10 + 4) + DFS(number * 10 + 7) + [number]

def main():
	res = DFS(0)
	res.sort()
	n = int(input())
	return res.index(n)
print(main())


n = input()
length_of_n = len(n)
index = 0
for degree in range(1, length_of_n):
	index += pow(2, degree)
n = n.replace('4', '0')
n = n.replace('7', '1')
print(index + int(n, 2) + 1)


from sys import stdin
s = stdin.readline().rstrip()
n = len(s)
ans = 0
for i in range(1, n):
	ans += pow(2, i)
aux = ''
for i in range(n):
	if s[i] == '4':
		aux += '0'
	else:
		aux += '1'
print(ans + int(aux, 2) + 1)


n = int(input())
x = []
while n > 0:
	if n % 10 == 4:
		x = [0] + x
	else:
		x = [1] + x
	n //= 10
cur = 0
for i in x:
	cur = cur * 2 + i
for i in range(1, len(x)):
	cur += 2 ** i
print(cur + 1)


from bisect import bisect

def main():
	num = [4, 7]
	temp = [4, 7]
	for i in range(9):
		d = []
		for j in range(len(temp)):
			d.append(int(str(temp[j]) + '4'))
			d.append(int(str(temp[j]) + '7'))
		temp = d
		num += d
	t = int(input())
	print(bisect(num, t))
main()


ans = 0
dict_ln = {'4': 1, '7': 2}
for i in input():
	ans = ans * 2 + dict_ln[i]
print(ans)


nstr = input()
nstr = nstr.replace('4', '0')
nstr = nstr.replace('7', '1')
nstr = '1' + nstr
n = int(nstr, base=2) - 1
print(n)


lucky = input()
satuan = 0
count = 0
total = 0
for x in range(len(lucky) - 1, -1, -1):
	count = 2 ** satuan
	if lucky[x] == '7':
		count *= 2
	total += count
	satuan += 1
print(total)


number = int(input())
idx = 0
sum = 0
while number > 0:
	digit = number % 10
	if digit == 4:
		sum += 1 * 2 ** idx
	else:
		sum += 2 * 2 ** idx
	idx += 1
	number = int(number / 10)
print(sum)


def generate_numbers(x, v):
	if x <= 10 ** 9:
		v.append(x)
		generate_numbers(x * 10 + 4, v)
		generate_numbers(x * 10 + 7, v)
v = []
generate_numbers(0, v)
lucky_number = int(input())
lucky_index = 0
for number in v:
	if number < lucky_number:
		lucky_index += 1
print(lucky_index)


a = list()
n = int(input())
i = 0
while n % 10 > 0:
	if n % 10 == 4:
		if len(a) - 1 == i:
			if a[i] == 1:
				a[i] = 0
				a.append(1)
			else:
				a[i] = 1
		else:
			a.append(1)
	if n % 10 == 7:
		if len(a) - 1 == i:
			a.append(1)
		else:
			a.append(0)
			a.append(1)
	i += 1
	n = n // 10
s = ''
for i in range(len(a) - 1, -1, -1):
	s = s + str(a[i])
n = int(s, 2)
print(n)


def tavas(n):
	s = str(n)
	l = len(s)
	s_i = 2 ** l - 1
	for i in range(l):
		if s[l - i - 1] == '7':
			s_i += 2 ** i
	return s_i
k = int(input())
print(tavas(k))


st = input().replace('7', '1').replace('4', '0')
print(2 ** len(st) - 1 + int(st, 2))


n = int(input())
x = len(str(n))
ans = 1
for i in range(1, x):
	ans += 1 << i
v = list(str(n))
v = ['1' if i != '4' else '0' for i in v]
v = ''.join(v)
ans += int(v, 2)
print(ans)


n = input()
r = (1 << len(n)) - 2
for i in range(len(n))[::-1]:
	if n[i] == '7':
		r += 1 << len(n) - i - 1
print(r + 1)


n = str(input())
n = n.replace('4', '1').replace('7', '2')
size = len(n)
num = 0
for i in range(size):
	num += int(n[i]) * pow(2, size - 1 - i)
print(num)


n = int(input())
(res, i) = (0, 0)
while n:
	res += 1 << i
	if n % 10 == 7:
		res += 1 << i
	i += 1
	n //= 10
print(res)


s = input().strip()
n = len(s)
ans = 2 ** n - 2 + 1
s2 = ''.join(['0' if i == '4' else '1' for i in s])
ans += int(s2, 2)
print(ans)


arr = []

def recursive(x, y):
	if x >= 10000000000.0 and y >= 10000000000.0:
		return
	arr.append(x)
	arr.append(y)
	recursive(x * 10 + 4, y * 10 + 7)
	recursive(x * 10 + 7, y * 10 + 4)
recursive(4, 7)
arr.sort()
xx = input()
print(arr.index(int(xx)) + 1)


import math
entrada = str(input())
bit = []
for i in entrada:
	if i == '7':
		bit.append('2')
	else:
		bit.append('1')
tam = len(bit)
pos = 0
aux = 0
for i in range(0, len(bit)):
	aux = aux + math.pow(2, len(bit) - i - 1) * int(bit[i])
print(int(aux))


s = input()
k = 0
m = 1
for i in s[::-1]:
	if i == '4':
		k += m
	else:
		k += 2 * m
	m *= 2
print(k)


import sys
import math
import collections
import bisect

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
a = []

def lucky(n):
	if n > 10 ** 10:
		return
	else:
		a.append(n)
		lucky(10 * n + 4)
		lucky(n * 10 + 7)
for t in range(1):
	lucky(0)
	a.sort()
	print(a.index(int(input())))


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
n = ii()
if n == 4:
	exit(print(1))
elif n == 7:
	exit(print(2))
s = ''
sm = 2 * int('1' * (len(str(n)) - 1), 2)
for i in str(n)[::-1]:
	s += '1' if i == '7' else '0'
print(sm + int(s[::-1], 2) + 1)


entrada = str(input())
digitos = len(entrada)
possibilidades = int(2 ** digitos)
limiteInferior = possibilidades - 1
limiteSuperior = limiteInferior * 2
for d in entrada:
	if possibilidades != 2:
		possibilidades = possibilidades // 2
		if d == '4':
			limiteSuperior = limiteSuperior - possibilidades
		if d == '7':
			limiteInferior = limiteInferior + possibilidades
	else:
		if d == '4':
			print(limiteInferior)
		if d == '7':
			print(limiteSuperior)


bag = []
mp = dict()

def disect(r):
	s = []
	l = []
	while r > 0:
		if r & 1:
			s.insert(0, 4)
			l.insert(0, 7)
		else:
			s.insert(0, 7)
			l.insert(0, 4)
		r >>= 1
	bag.append(int(''.join(map(str, l))))
	bag.append(int(''.join(map(str, s))))
st = 1
for i in range(1, 2 ** 9):
	disect(i)
bag.sort()
for i in bag:
	mp[i] = st
	st += 1
n = int(input())
print(mp[n])


s = input()
s = '7' + s
s = s.replace('4', '0')
s = s.replace('7', '1')
print(int(s, 2) - 1)


class test:

	def __init__(self, x):
		self.x = x
		self.count = 0

	def lucky(self, num):
		if num > self.x:
			return
		if num:
			self.count += 1
		self.lucky(num * 10 + 4)
		self.lucky(num * 10 + 7)
sol = test(int(input()))
sol.lucky(0)
print(sol.count)


n = input()
k = len(n)
sum = 2 ** k - 1
for i in range(k):
	if n[k - 1 - i] == '7':
		sum += 2 ** i
print(sum)


s = input()
ans = 0
x = len(s) - 1
for c in s:
	if c == '7':
		ans += 1 << x
	x -= 1
for i in range(len(s)):
	ans += 1 << i
print(ans)


seq = []
q = ['4', '7']
seq.extend(q)
for i in range(9):
	q_new = []
	for s in q:
		q_new.append(s + '4')
		q_new.append(s + '7')
	q = q_new
	seq.extend(q)
seq_int = [int(c) for c in seq]
my_dict = {num: idx for (idx, num) in enumerate(seq_int)}
n = int(input())
print(my_dict[n] + 1)


a = input()
suma = 0
valid = True
for (j, i) in enumerate(a):
	if i == '4':
		suma += 2 ** (len(a) - j - 1)
	elif i == '7':
		suma += 2 ** (len(a) - j)
	else:
		valid = False
if valid:
	print(suma)


n = input()
print(int(''.join(('01'[i == '7'] for i in n)), 2) + 2 ** len(n) - 1)


l = input()
print(list(sorted(sum([[''.join([['4', '7'][i & 1 << j is not 0] for j in range(n)]) for i in range(2 ** n)] for n in range(1, len(l) + 1)], []), key=int)).index(l) + 1)


from math import log, floor
n = int(input())
l = ['4', '7']
s = 0
while int(l[-1]) < n:
	l = ['4' + x for x in l] + ['7' + y for y in l]
	s += 1
print(2 ** (s + 1) - 1 + l.index(str(n)))


tavasNum = input()
binaryEquivalent = ''
for n in tavasNum:
	if n == '4':
		binaryEquivalent += '0'
	else:
		binaryEquivalent += '1'
rawIndex = int(binaryEquivalent, 2)
previousCombinations = 0
currentPow = 1
for i in range(len(tavasNum) - 1):
	currentPow *= 2
	previousCombinations += currentPow
print(rawIndex + previousCombinations + 1)


import math

def fact(n):
	ans = 1
	for i in range(2, n + 1):
		ans *= i
	return ans

def comb(n, c):
	return fact(n) // (fact(n - c) * c)
n = int(input())
if n == 4:
	print(1)
elif n == 7:
	print(2)
else:
	add = 2
	ans = 0
	n = str(n)
	for i in range(len(n)):
		ans += 2 ** i
	pos = 2 ** len(n)
	left = 1
	right = pos
	i = 0
	while left < right and i < len(n):
		mid = (left + right) // 2
		if n[i] == '4':
			right = mid
		else:
			left = mid + 1
		i += 1
	ans += left - 1
	print(ans)


n = input()
cek = 1
hasil = 0
for i in n[::-1]:
	hasil += 1 * cek if i == '4' else 2 * cek
	cek *= 2
print(hasil)


s = input()
ans = []
count = 0
for i in range(len(s)):
	if s[i] == '4':
		ans.append(0)
	else:
		ans.append(1)
		count += pow(2, len(s) - i - 1)
print(count + pow(2, len(ans)) - 1)


num = input()

def f(x):
	if x == '7':
		return 2
	elif x == '4':
		return 1
	if x[0] == '7':
		return f(x[1:]) + 2 ** len(x[1:])
	else:
		return f(x[1:])
print(2 ** len(num) - 2 + f(num))


__author__ = 'OnePiece'
s = input()
answer = 0
for x in s:
	answer *= 2
	if x == '4':
		answer += 1
	else:
		answer += 2
print(answer)


i = input()
a = int('0b' + i.replace('7', '1').replace('4', '0'), 2)
print(a + 2 ** len(i) - 1)


luckyNumber = int(input())
index = {'4': 1, '7': 2}
step = 0
for i in str(luckyNumber):
	step = step * 2 + index[i]
print(step)


strno = input()
n = len(strno)
sum1 = 0
for i in range(n):
	if strno[i] == '4':
		sum1 += 1 << n - i - 1
	else:
		sum1 += 1 << n - i
print(sum1)


vec = []
for i in range(1, pow(3, 10)):
	t = i
	pow_ = 1
	now = 0
	flag = 1
	while 1:
		temp = t % 3
		t = t // 3
		if temp == 1:
			now = now + 4 * pow_
		elif temp == 2:
			now = now + 7 * pow_
		pow_ = pow_ * 10
		if t == 0:
			break
		if temp == 0:
			flag = 0
			break
	if flag == 1:
		vec = vec + [now]
inp = int(input())
for index in range(len(vec)):
	if vec[index] == inp:
		print(index + 1)
		break


n = int(input())
p = 1
su = 0
while n != 0:
	x = n % 10
	if x == 4:
		su = su + p
	else:
		su = su + 2 * p
	p = 2 * p
	n = n // 10
print(su)


bk = [0] * 10
dip = ['4', '7']

def comb():
	capt = []
	ind = 9
	stp = 10
	boo = ''
	while bk[0] < 1:
		if bk[ind] < 2:
			boo += dip[bk[ind]]
			bk[ind] += 1
			if ind + 1 == stp:
				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 capt
sep = comb()
print(sep.index(input()) + 1)


s = input()
c = len(s)
l = [['4', '7'], ['44', '47', '74', '77']]
count = 2
if c == 1:
	print(l[c - 1].index(s) + 1)
elif c == 2:
	print(l[c - 1].index(s) + 1 + count)
else:
	count = 6
	flag = 0
	for _ in range(2, c):
		l2 = l[0]
		l3 = l[-1]
		l4 = []
		for i in l3:
			for j in l2:
				x = i + j
				if x == s:
					flag = 1
					break
				else:
					l4.append(x)
					count += 1
			if flag == 1:
				break
		l.append(l4)
		if flag == 1:
			break
	if flag == 1:
		print(count + 1)


n = input()
ans1 = (1 << len(n)) - 2
rev = n[::-1]
p = 0
ans2 = 0
for i in rev:
	if i == '7':
		ans2 += 1 << p
	p += 1
print(ans1 + ans2 + 1)


n = int(input())
a = ''
while n != 0:
	if n % 10 == 4:
		a = '0' + a
	elif n % 10 == 7:
		a = '1' + a
	n = n // 10
a = '1' + a
m = int(a, 2)
m = m - 1
print(m)


n = int(input())
g = n
s = str(n)
k = len(s)
t = ''
for i in range(len(s)):
	if s[i] == '4':
		t = t + '0'
	else:
		t = t + '1'
f = int(t, 2)
h = (2 ** (k - 1) - 1) * 2
print(h + f + 1)


import math
n = int(input())
d = int(math.log(n, 10)) + 1
x = 2 * (2 ** (d - 1) - 1)
y = 0
n = str(n)
for i in range(d - 1, -1, -1):
	if n[i] == '7':
		y += 2 ** (d - 1 - i)
print(x + y + 1)


n = input()
arr = []
for i in range(1, 10):
	for j in range(2 ** i):
		m = j
		s = ''
		for k in range(i):
			if m % 2:
				s = '7' + s
			else:
				s = '4' + s
			m = m >> 1
		arr.append(s)
print(arr.index(n) + 1)


n = input()
binary = []
for i in n:
	if i == '4':
		binary.append(0)
	else:
		binary.append(1)
binary.reverse()
ans = 0
for i in range(len(binary)):
	ans += 2 ** i * (binary[i] + 1)
print(ans)


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
n = input()
d = {'4': '0', '7': '1'}
x = 2 ** len(n) - 1
b = ''
for e in n:
	b += d[e]
m = int(b, 2)
print(x + m)


import sys
import string
import math
from collections import defaultdict
from functools import lru_cache
from collections import Counter
from fractions import Fraction

def mi(s):
	return map(int, s.strip().split())

def lmi(s):
	return list(mi(s))

def tmi(s):
	return tuple(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))

def js(lst):
	return ' '.join((str(d) for d in lst))

def line():
	return sys.stdin.readline().strip()

def linesp():
	return line().split()

def iline():
	return int(line())

def mat(n):
	matr = []
	for _ in range(n):
		matr.append(linesp())
	return matr

def matns(n):
	mat = []
	for _ in range(n):
		mat.append([c for c in line()])
	return mat

def mati(n):
	mat = []
	for _ in range(n):
		mat.append(lmi(line()))
	return mat

def pmat(mat):
	for row in mat:
		print(js(row))

def dist(x, y):
	return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5

def fast_exp(x, n):
	if n == 0:
		return 1
	elif n % 2 == 1:
		return x * fast_exp(x, (n - 1) // 2) ** 2
	else:
		return fast_exp(x, n // 2) ** 2

def gcd(a, b):
	while b:
		a %= b
		(a, b) = (b, a)
	return a

def main():
	n = iline()
	num_digits = 0
	p = 1
	ans = 0
	while n > 0:
		(curr, rest) = (n % 10, n // 10)
		if curr == 7:
			ans += 2 ** (p - 1)
		p += 1
		num_digits += 1
		n = rest
	ans += 2 ** num_digits - 1
	print(ans)
main()


n = input()
newn = ''
for c in n:
	if c == '4':
		newn += '0'
	else:
		newn += '1'
print(int(newn, 2) + 2 ** len(newn) - 1)


import sys
s = sys.stdin.readline().strip()
pos = 0
for (i, x) in enumerate(s.zfill(9)):
	if x == '0':
		continue
	if pos == 0:
		pos = 2 * (2 ** (9 - i - 1) - 1)
	if x == '7':
		pos += 2 ** (9 - i - 1)
sys.stdout.write('%d\n' % (pos + 1))


def printNthElement(n):
	arr = [0] * (10 ** 6 + 1)
	arr[1] = 4
	arr[2] = 7
	for i in range(3, 10 ** 6):
		if i % 2 != 0:
			arr[i] = arr[i // 2] * 10 + 4
		else:
			arr[i] = arr[i // 2 - 1] * 10 + 7
	return arr.index(n)
print(printNthElement(int(input())))


var = str(input())
ans = 0
idx = 0
for i in range(len(var) - 1, -1, -1):
	if int(var[i]) == 4:
		ans += 2 ** idx
	elif int(var[i]) == 7:
		ans += 2 ** (idx + 1)
	idx += 1
print(ans)