import sys

def generate_lucky_nums(cur_num = 0):
    if cur_num > 10 ** 10:
        return

    if cur_num != 0:
        lucky_nums.append(cur_num)

    generate_lucky_nums(cur_num * 10 + 4)
    generate_lucky_nums(cur_num * 10 + 7)

def bin_search(target, values):
    l, h = 0, len(values)-1

    while l <= h:
        m = (l + h) // 2

        if values[m] == target:
            return m
        elif values[m] < target:
            l = m + 1
        elif values[m] > target:
            h = m - 1
    return l

values = [int(x) for x in sys.stdin.readline().split()]
l, r = values[0], values[1]
lucky_nums = []

generate_lucky_nums()
lucky_nums.sort()

result = 0
i = l

while i <= r:
    index = bin_search(i, lucky_nums)
    next_lucky = lucky_nums[index]
    #print("next:", next_lucky)
    result += next_lucky * min((next_lucky - i + 1), r - i + 1)
    #print("times:", min((next_lucky - i + 1), r - i + 1))

    i = next_lucky + 1

print(result)

import itertools

def islucky(x):
	a = map(int, list(str(x)))
	b = [0, 1, 2, 3, 5, 6, 8, 9]
	for i in b:
		if a.count(i) != 0:
			return False
	return True

x, y = raw_input().split()
start = len(x)
end = len(y)
l = []
for i in range(start, end+2):
	l  += [''.join(i) for i in set(itertools.product('47', repeat=i))]
l = [int(i) for i in l]
l = sorted(l)
#print l
start = 0
while l[start] < int(x):
	start += 1
end = 0
while int(y) > l[end]:
	end += 1
i = 0
if len(l[start:end+1]) != 1:
	l = sorted(l[start:end+1])
	#print l
	sum = (l[0] - int(x) + 1) * l[0] + (int(y) - l[-1]) * l[-1]
	i = 0
	while i != len(l)-1:
		#print l[i], l[i+1]
		#print sum
		sum += (l[i+1] - l[i]) * l[i+1]
		i += 1
		#print sum
else:
	sum = l[start:end+1][0] * (int(y) - int(x) + 1)
print sum

l,r=map(int,input().split())

a=[]
def foo(n):
	a.append(n)
	if n>10*r:
		return
	foo(10*n+4)
	foo(10*n+7)
	return

foo(0)
a.sort()

def get_sum(m):
	s=0
	for i in range(1,len(a)):
		s+=a[i]*(min(a[i],m)-min(a[i-1],m))
	return s

print(get_sum(r)-get_sum(l-1))

l,r = map(int,input().split())

num = '4'

lucky = []
while True:
	lucky.append(int(num))
	if int(num) > r:
		break
	n = len(num)
	f = 0
	lst = list(num)
	for i in range(n):
		if lst[n-i-1] == '4':
			f = 1
			i = n-i-1
			break
	if f == 1:
		lst[i] = '7'
	else:
		lst.insert(0, '4')
		i = 0
		n += 1
	i += 1
	while i < n:
		lst[i] = '4'
		i += 1
	num = ''.join(lst)

n = len(lucky)
prev = l
result = 0
for i in range(n):
	n = lucky[i]
	if n < prev:
		continue
	if r < n:
		n = r
	result += (n - prev + 1)*lucky[i]
	prev = n+1
	if prev > r:
		break
print(result)

import sys

#sys.stdin = open('in.txt', 'r')

l, r = map(int, raw_input().split())

def dfs(n, m, lucky):
	if m:
		lucky.append(m)
	if n > 0:
		dfs(n - 1, m * 10 + 4, lucky)
		dfs(n - 1, m * 10 + 7, lucky)

lucky = []
dfs(10, 0, lucky)
lucky.sort()

st, ed = 0, 0
for i in xrange(0, len(lucky) - 1):
	if l > lucky[i] and l <= lucky[i + 1]:
		st = i + 1
		break
for i in xrange(0, len(lucky) - 1):
	if r > lucky[i] and r <= lucky[i + 1]:
		ed = i + 1
		break

cur, sum = l, 0
for i in xrange(st, ed + 1):
	sum += (min(lucky[i], r) - cur + 1) * lucky[i]
	cur = lucky[i] + 1

print sum

l,r = raw_input().split(" ")
t1 = []
t2 = []
t3 = []
t4 = []
t5 = []
t6 = []
t7 = []
t8 = []
t9 = []
t = [t1,t2,t3,t4,t5,t6,t7,t8,t9]
def ln(digit,c,t):
    if len(c) == digit:
        t.append(c)
        return
    ln(digit, c + "4", t)
    ln(digit, c + "7", t)
    return

for i in range(1,10):
    ln(i,"",t[i - 1])

lst = sum(t,[])
lst.append("4444444444")
rst = 0

ll = len(lst)
il = int(l)
ir = int(r)

for i in range(0,ll):
    if il <= int(lst[i]):
        break

for j in range(0,ll):
    if ir <= int(lst[j]):
        break

if i == j:
    rst += (ir - il + 1) * int(lst[i])
else:
    rst += (int(lst[i]) - il + 1) * int(lst[i])
    rst += (ir - int(lst[j - 1])) * int(lst[j])
    for k in range(i,j - 1):
        rst += (int(lst[k + 1]) - int(lst[k])) * int(lst[k + 1])

print rst

l = []
s = set()

for i in range(1025):
	t = ['7' if i == '0' else '4' for i in bin(i)[2:]]
	t = int(''.join(t))
	if t not in s:
		l.append(t)
		s.add(t)
	t = ['4' if i == '0' else '7' for i in bin(i)[2:]]
	t = int(''.join(t))
	if t not in s:
		l.append(t)
		s.add(t)
l.sort()

i, j = map(int, input().split())
ans = 0
from bisect import bisect_left
k = i
while k <= j:
	t = l[bisect_left(l, k)]
	ans += (min(t, j) - k + 1) * t
	k = t + 1

print(ans)

def Gen_lucky(n,s):
    if(len(s)==n):
        L.append(int(s))
        return
    Gen_lucky(n,s+"4")
    Gen_lucky(n,s+"7")
    return

l,r=map(int,input().split())

L=[]
for i in range(1,11):
    Gen_lucky(i,"")
L.sort()
ind1=0
for i in range(len(L)):
    if(L[i]>=l):
        ind1=i
        break
ind2=0
for i in range(len(L)):
    if(L[i]>=r):
        ind2=i
        break
p=l
x=0
for i in range(ind1,ind2+1):
    h=L[i]
    if(i==ind2):
        h=r
    x+=(h-p+1)*(L[i])
    p=L[i]+1
print(x)

# n = raw_input()
def next(ans):
    n = len(ans)
    if "7"*n == ans:
        return "4"*(n+1)
    i = n-1
    while ans[i]=='7':
        i-=1
    ans = ans[:i] + '7' + "4"*(n-i-1)
    return ans

def next_cool(sn):
    n = len(sn)
    if not int("7"*n)>=int(sn):
        return "4"*(n+1)
    ans = "4"*n
    sn = int(sn)
    while int(ans)<sn:
        ans = next(ans)
    return ans
if __name__=='__main__':
    l, r = raw_input().split()
    sum = 0
    bl = next_cool(l)
    br = next_cool(r)
    bri = int(br)
    if bl==br:
        print (int(r)-int(l)+1)*int(bl)
    else:
        l = int(l)
        while int(bl) < bri:
            sum += (int(bl)-l+1)*(int(bl))
            l = int(bl)+1
            bl = next(bl)
        sum += bri*(int(r)-l+1)
        print sum

def getluckys(n):
  luckys = []
  for i in range(0,2**n):
   s = ""
   for j in range(0,n):
    if ((i>>j)&1) == 0:
     s+='4'
    else:
     s+='7'
   luckys.append(int(s))
  return luckys

luckynumbers = []

for i in range(1,11):
 luckynumbers += getluckys(i)

luckynumbers.sort()

lowerbound = 0
upperbound = 0

l, r = map(int, raw_input().split(" "))

while (luckynumbers[upperbound]<r):
 upperbound += 1

while (luckynumbers[lowerbound]<l):
 lowerbound += 1

#print(lowerbound)
#print(upperbound)
#print()

ans = luckynumbers[lowerbound] * (min(luckynumbers[lowerbound],r) - l + 1)
#print(ans)

for i in range(lowerbound + 1, upperbound):
 ans += luckynumbers[i] * (luckynumbers[i] - luckynumbers[i-1])
 #print(ans)

if upperbound>lowerbound:
 ans += luckynumbers[upperbound] * (r - luckynumbers[upperbound - 1])

print(ans)

l,r = map(int,input().split())
arr =[4,7]
sumi=0
k=0
ind =1
for i in range(0,15):
	for j in range(k,k+2**(i+1)):
		arr.append(arr[j]*10+4)
		arr.append(arr[j]*10+7)
	k=2**(i+1)
while(l<=r):
	c=-1
	if (l<=4):
		c=4
	else:
		for i in range(ind,len(arr)):
			if (l<=arr[i] and l>arr[i-1]):
				c=arr[i]
				ind = i
				break;
	if r<=c:
		sumi=sumi+((r-l+1)*c)
		l=r+1
	else:
		sumi=sumi+((c-l+1)*c)
		l=c+1
print(sumi)

l, r = map(int, raw_input().split())

def check(k):
    s = str(k)
    for i in xrange(len(s)):
        if s[i] != '4' and s[i] != '7':
            return 0
    return 1

def close(a):
    if (check(a)):
        return a
    else:
        ans = ''
        temp = 0
        last = -1
        s = str(a)
        for i in xrange(len(s)):
            if (temp == 0):
                if (s[i] == '4' or s[i] == '7'):
                    ans = ans + s[i]
                    if s[i] == '4':
                        last = i
                else:
                    if (s[i] < '4'):
                        ans = ans + '4'
                        last = i
                    elif (s[i] < '7'):
                        ans = ans + '7'
                    else:
                        if last == -1:
                            ans = ''
                            for j in xrange(len(s) + 1):
                                ans = ans + '4'
                            return int(ans)
                        else:
                            ans = ans[:last] + '7'
                            while (len(ans) < len(s)):
                                ans = ans + '4'
                            return int(ans)
            else:
                ans = ans + '4'
        return int(ans)

h = [4]
for i in xrange(1022):
    h.append(close(h[len(h) - 1] + 1))
indl = 0
for i in xrange(len(h)):
    if h[i] >= l:
        indl = i
        break
for i in xrange(len(h)):
    if h[i] >= r:
        indr = i
        break

ans = 0
prev = l
for i in xrange(indl, indr + 1):
    if (i == indr):
        ans += (r - prev + 1) * h[i]
        break
    ans += (h[i] - prev + 1) * h[i]
    prev = h[i] + 1

print ans

#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
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()]

#-------------------------code---------------------------#
#vsInput()

lucky=[]

for i in range(1,11):
    for j in range(2**i):
        key=bin(j).replace("0b","")
        key='0'*(i-len(key))+key

        num=0
        for k in key:
            if(k=='0'): num=num*10+4
            else: num=num*10+7
        lucky.append(num)

# print(lucky)

l,r=value()

ind1=bisect_left(lucky,l)
ind2=bisect_right(lucky,r)

last=l
ans=0

for i in range(ind1,ind2):
    ans+=lucky[i]*(lucky[i]-last+1)
    last=lucky[i]+1
if(last<=r):
    ans+=lucky[ind2]*(r-last+1)

print(ans)

li=set()
def addi(n):
    if n>10**10+1:
        return
    li.add(n)
    addi(n*10+4)
    addi(n*10+7)
addi(4)
addi(7)
li=list(set(li))
li.sort()
#print(len(li))
l,r=map(int,input().split())
ans=0
for x in li:
    #print(x)
    if x>=r:
        #print("l",l)
        ans+=x*(r-l+1)
        #print("ans",ans)
        break
    elif x>=l:
        ans+=x*(x-l+1)
        #print("ans",ans)
        l=x+1
print(ans)

l,r=map(int,input().split())
s=set()
def f(st,res):
	if st>10:s.add(res)
	else:
		if res==0:f(st+1,res)
		for i in 4,7:f(st+1,res*10+i)
f(0,0)
s=sorted(s)
a=1
b=1
q=0
if l in s:
	q-=l
	l-=1
while l>=s[a]:a+=1
while r>=s[b+1]:b+=1
if a>=b:
	q+=(min(r,s[a])-l+1)*s[a]
	if r>s[a]:q+=s[a+1]*(r-s[a])
else:
	if l<s[a]:q+=s[a]*(s[a]-l+1)
	if r>s[b]:q+=s[b+1]*(r-s[b])
	for i in range(a,b):q+=s[i+1]*(s[i+1]-s[i])
print(q)

from itertools import product

l, r = map(int, input().split())
lucky_nums = sorted(int(''.join(p)) for r in range(1, 11) for p in product("47", repeat=r))
ans = 0

for lucky_num in lucky_nums:
    if l <= lucky_num <= r:
        ans += (lucky_num - l + 1) * lucky_num
        l = lucky_num + 1
    elif l <= lucky_num and r < lucky_num:
        ans += (r - l + 1) * lucky_num
        break

print(ans)

def naxt(i) :
    e=bin(i+2)
    e=e[3:]
    e=e.replace("0","4")
    e=e.replace("1","7")
    return int(e)
i=0
ans=0
pr=0
l,r=map(int,input().split())
while(True):
    t=naxt(i)

    ans+=max((min(r,t)-max(l,pr)+1)*t,0)
    pr=t+1
    if r<=t :
        break
    i+=1

print(ans)

#print("AUTHOR : SADIA AFROZ")

import bisect

l,r=map(int, input().split())
sum=0
luckyNumbersList=[]

def luckyNumbersGen(x):
    if x>=7777777777:
        return
    luckyNumbersList.append(x)
    luckyNumbersGen(x*10+4)
    luckyNumbersGen(x*10+7)

luckyNumbersGen(4)
luckyNumbersGen(7)
#print(luckyNumbersList)
luckyNumbersList.sort()
#print(luckyNumbersList)

def next(x):
    lower=bisect.bisect_left(luckyNumbersList,x)
    #print("hello {} ".format(luckyNumbersList[lower]))
    return luckyNumbersList[lower]

while l<=r:
    temp=next(l)
    if r<temp:                  #for out of range (l-r) Max number returned
        sum += temp*(r-l+1)
        break
    #print(temp)
    #sum+=temp*(min(temp,r)-l+1)
    sum += temp * (temp - l + 1)
    l=temp+1

print(sum)

lucky_n = []

s = 0

def add_4_7(s):
  s_4 = int(str(s) + '4')
  s_7 = int(str(s) + '7')
  if s_4 < 10000000000:
    lucky_n.append(s_4)
    add_4_7(s_4)
  if s_7 < 10000000000:
    lucky_n.append(s_7)
    add_4_7(s_7)

add_4_7(s)
lucky_n.sort()

a, b = list(map(int, input().split()))

prox = 0
ultimo = a

for i in range(len(lucky_n)):
  l = lucky_n[i]
  if l >= a:
    prox = i
    break

primeiro = lucky_n[prox]
soma = 0

while True:
  if lucky_n[prox] <= b:
    soma += (lucky_n[prox] - ultimo) * lucky_n[prox]
    ultimo = lucky_n[prox]
    prox += 1
  else:
    soma += (b - ultimo) * lucky_n[prox]
    break

print(soma+primeiro)

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

l, r = map(int, input().split())
a = len(str(l)); b = len(str(r))
z = gray(a)
for i in range(a+1, b+2):
    z += gray(i)
l1 = [a for a in z if a >= l and a <= r]
l2 = [a for a in z if a > r]
l1.sort()
if len(l1) == 0 or l1[-1] != r:
    l1 += [l2[0]]
u = l
ans = 0
if r < l1[-1]:
    for i in range(len(l1)-1):
        ans += (l1[i]-u)*l1[i]
        u = l1[i]
    ans += (r-u)*l1[-1] + l1[0]
else:
    for i in range(len(l1)):
        ans += (l1[i]-u)*l1[i]
        u = l1[i]
    ans += l1[0]
print(ans)

from bisect import bisect_left
l, r = map(int, input().split())
t, p, u, v = [4, 7], [4, 7], 4, 7
while t[-1] < r:
    u, v = u * 10, v * 10
    t = [u + i for i in t] + [v + i for i in t]
    p.extend(t)
p = p[bisect_left(p, l): bisect_left(p, r) + 1]
print((p[0] - l + 1) * p[0] + (r - p[-1]) * p[-1] + sum((p[i] - p[i - 1]) * p[i] for i in range(1, len(p))))

from itertools import product
lucky = []

l,r = input().split()
lw, rw = len(l), len(r)
l, r = int(l), int(r)

for i in range(lw,rw+1):
    lucky+=[int(''.join([str(y) for y in x])) for x in list(product([4,7],repeat=i))]
lucky+=[int('4'*(rw+1))]
ans=0
il = [0,0]
for i in range(len(lucky)):
    if lucky[i]<l:
        il[0]=i+1
    if lucky[i]<r:
        il[1]=i+1
if il[0]==il[1]:
    ans=(r-l+1)*lucky[il[0]]
else:
    for i in range(il[0],il[1]-1):
        ans+=(lucky[i+1]-lucky[i])*lucky[i+1]
    ans+=(lucky[il[0]]-l+1)*lucky[il[0]]+(r-lucky[il[1]-1])*lucky[il[1]]

print(ans)

def nxt(num):
    st=str(num)
    for i in range(len(st)):
        if st[i:]>"7"*(len(st)-i):
            if i==0:
                st="4"*(len(st)+1)

            else:
                st=st[:i-1]+"7"+"4"*(len(st[i:]))
                break;
        elif st[i]<"4":
            st=st[:i]+"4"*(len(st[i:]))
            break
        elif st[i]<"7" and st[i]>"4":
            st=st[:i]+"7"+"4"*len(st[i+1:])
            break
    return int(st)

lst=list(map(int,input().split()))
l=lst[0]
r=lst[1]
s=0
n=0
i=l
while i<=r:
    n=nxt(i)
    if n<=r:
      s=s+n*(n-i+1)
      i=n+1
    else:
      s=s+n*(r-i+1)
      break
print(s)

l,r=map(int,input().split())

s=set()

def f(st,res):

	if st>10:s.add(res)

	else:

		if res==0:f(st+1,res)

		for i in 4,7:f(st+1,res*10+i)

f(0,0)

s=sorted(s)

a=1

b=1

q=0

if l in s:

	q-=l

	l-=1

while l>=s[a]:a+=1

while r>=s[b+1]:b+=1

if a>=b:

	q+=(min(r,s[a])-l+1)*s[a]

	if r>s[a]:q+=s[a+1]*(r-s[a])

else:

	if l<s[a]:q+=s[a]*(s[a]-l+1)

	if r>s[b]:q+=s[b+1]*(r-s[b])

	for i in range(a,b):q+=s[i+1]*(s[i+1]-s[i])

print(q)

# Made By Mostafa_Khaled

def getLuckyNumber(digit , arr):
        temp = list()
        for i in arr:
                temp.append('4' + i)
                temp.append('7' + i)
        return temp

def digitCount(number):
        digits = 1
        while True:
                digits += 1
                number = number // 10
                if number == 0:
                        break
        return getLuckyList(digits)

def getLuckyList(digitCount):
        temp = ['']
        arr = list()
        for i in range(1 , digitCount + 1):
                temp = getLuckyNumber(i , temp)
                luck = list(map(int , temp))
                arr += luck
        arr.sort()
        return arr

def nextLuckyNumber(x , arr):
        for j in arr:
                if j >= x:
                        return j

if __name__ == "__main__":
        n = list(map(int , input().rstrip().split()))
        l = n[0]
        r = n[1]
        arr = digitCount(r)
        total = 0
        prev = 0
        i = l
        while i <= r:
                if i > prev:
                        prev = nextLuckyNumber(i , arr)
                        #print (prev , i)
                        total += prev
                        i += 1
                else:
                        if prev <= r:
                                total += (prev - i + 1) * prev
                        else:
                                total += (r - i + 1) * prev
                        i = prev + 1
        print (total)

l, r = [int(x) for x in input().split()]
import itertools
arr = []
for i in range(1, 11):
    arr.extend(list(map(int, map(''.join, itertools.product('47', repeat=i)))))
ans = 0
for i in range(len(arr)):
    if arr[i] >= r:
        ans += (r - l + 1) * arr[i]
        break
    elif arr[i] >= l:
        ans += (arr[i] - l + 1) * arr[i]
        l = arr[i] + 1
print(ans)

from itertools import product

all_lucky = [('0')]

for i in range(1, 11):
    all_lucky += list(product('47', repeat=i))

all_lucky = [int("".join(x)) for x in all_lucky]
all_lucky.sort()

left, right = map(int, input().split())

result = 0

prev = left
pos = 0
while all_lucky[pos+1] < left: pos += 1

while all_lucky[pos+1] < right:
    result += (all_lucky[pos+1] - prev + 1) * all_lucky[pos+1]
    prev = all_lucky[pos+1] + 1
    pos += 1

result += (right - prev + 1) * all_lucky[pos+1]

print(result)

s=(raw_input()).split()
l=int(s[0])
r=int(s[1])
nb=[4,7,44,47,74,77]
i=2
j=6
while (nb[j-1]<=r):
      j=len(nb)
      for k in (nb[i:]):
            nb=nb+[int((k*10)+4),int((k*10)+7)]
      i=j
for i in range(len(nb)):
      if (nb[i]>=l):
            k=nb[i]
            break
if (r<=k):
      sol=k*(r-l+1)
else:
      sol=(k-l+1)*nb[i]
      for j in nb[i+1:]:
            if (j<r):
                  sol=sol+((j-k)*j)
                  k=j
            else:
                  sol=sol+(j*(r-k))
                  break
print sol

pre = []
prev = ['']
for i in range(1, 11):
    cur = [s + '4' for s in prev] + [s + '7' for s in prev]
    pre.extend(cur)
    prev = cur

l = sorted(map(int, pre))

x, y = map(int, input().split())
res = 0

for e in l:
    if e < x: continue
    res += e * (min(e, y) - x + 1)
    x = e + 1
    if x > y: break

print(res)

digits = [4, 7]
nums = [4, 7]

LIM = 10**10
while nums[-1] < LIM:
    nums = list(set(nums + [num*10 + digit for digit in digits for num in nums]))

nums = [num for num in sorted(nums) if num <= LIM]
# print len(nums)
# print nums[:10], nums[-10:]

def c(l, r):
    ans = 0
    x = 0
    while l <= r:
        while nums[x] < l:
            x += 1
        num = nums[x]
        count = min(r, num) - l + 1
        ans += count * num
        # print num, ans, count, l, l + count
        l += count
    return ans

a, b = [int(_) for _ in raw_input().split(" ")]
print c(a, b)

def binary(n):
	if (n==0):
		yield ''
	else:
		for i in binary(n-1):
			yield i + '4'
			yield i + '7'

def gen():
	for i in range(1,11):
		for code in binary(i):
			yield int(code)

def main():
	start, end = [int(i) for i in raw_input().split()]
	nums = sorted(list(gen()) + [start])
	i = nums.index(start)
	cur = start
	s = 0
	while(cur<=end):
		if nums[i+1]<=end:
			s+= (nums[i+1]-cur+1)*nums[i+1]
		else:
			s+= (end-cur+1)*nums[i+1]
		cur = nums[i+1]+1
		i+=1
	print s

main()

luckynums = []
for digits in range(1,10):
	for mask in range(1<<digits):
		num = ""
		for i in range(digits):
			if((mask & 1<<i)==0):
				num = "4" + num
			else:
				num = "7" + num
		luckynums.append(int(num))
luckynums.append(4444444444)

def next(x):
	if(x<=4):
		return 0
	L = 0
	R = len(luckynums)-1
	while(L<R):
		M = (L+R)//2
		if(luckynums[M]<x):
			L=M+1
		else:
			R=M
	return L

a, b = tuple(int(i) for i in input().split())
sum = 0
i = a
while(i<=b):
	nextv = next(i)
	sum+=luckynums[nextv]*(min(luckynums[nextv],b)-i+1)
	i = luckynums[nextv]+1
print(sum)

import sys
import math

numbers = map(int, sys.stdin.readline().split())

start = numbers[0]
end = numbers[1]

lucky = [4, 7]

for i in range(1, 10):
    for j in range(len(lucky)):
        lucky.append(int(str(lucky[j]) + "4"))
        lucky.append(int(str(lucky[j]) + "7"))

def nextfun(i):
    tst = 0
    while lucky[tst] < i:
        tst += 1

    return lucky[tst]

answer = 0

while(start <= end):
    next = nextfun(start)

    if next < end:
        answer += next * (next - start + 1)
    else:
        answer += next * (end - start + 1)
    start = next + 1

print answer

A=["0","0","4","7"]
cnt=0
for i in range(4,1030):
  if cnt%2==0:
    A.append(A[i//2]+"4")
  else:
    A.append(A[i//2]+"7")
  cnt+=1
A=[int(x) for x in A[::]]
l,r=map(int,input().split())
left_index=1
right_index=1
while left_index<1030:
  if A[left_index]<l:
    left_index+=1
  else:
    break
while right_index<1030:
  if A[right_index]<r:
    right_index+=1
  else:
    break
# print(A)
# print(left_index,right_index)
if left_index==right_index:
  print((r-l+1)*A[left_index])
else:
  Sum=(A[left_index]-l+1)*A[left_index]
  left_index+=1
  while left_index!=right_index:
    Sum+=(A[left_index]-A[left_index-1])*A[left_index]
    left_index+=1
  Sum+=(r-A[right_index-1])*A[right_index]
  print(Sum)

maximum = 10 ** 9
a = []

queue = [4, 7]

element = 0

while element < maximum:
    element = queue.pop(0)
    a.append(element)
    x = element * 10
    queue.append(x + 4)
    queue.append(x + 7)

l, r = (int(i) for i in input().split(' '))

for i in range(len(a)):
    if a[i] >= l:
        break

current = l
total = 0
while current <= r:
    if a[i] > r:
        total += (r - current + 1) * a[i]
        current = a[i]
    else:
        total += (a[i] + 1 - current) * a[i]
        current = a[i] + 1
        i += 1
print(total)

# 1 2 3 4 5 6 7 8 9
# 4 4 4 4 7 7 7 47 47

li=set()
def addi(n):
    if n>10**10+1:
        return
    li.add(n)
    addi(n*10+4)
    addi(n*10+7)
addi(4)
addi(7)
li=list(set(li))
li.sort()
l,r=map(int,input().split())
ans=0
for x in li:
    if x>=r:
        ans+=x*(r-l+1)
        break
    elif x>=l:
        ans+=x*(x-l+1)
        l=x+1
print(ans)

n = (input()).split()
l = int(n[0])
r = int(n[1])
a = []
x = []
a.append([])
a[0].append('4')
a[0].append('7')

for i in range(1,10):
    a.append([])
    for j in a[i-1]:

        a[i].append('4'+j)
        a[i].append('7'+j)
    for j in a[i]:
        x.append(int(j))
x.append(4)
x.append(7)
x.sort()
sum = [16]
for i in range(1,len(x)):
    sum.append((x[i]-x[i-1])*x[i]+sum[i-1])
for i in range(len(x)):
    if x[i] >= l:
        t = i
        break
for i in range(len(x)):
    if x[i] >= r:
        e  = i
        break
res = sum[e] - sum[t] - x[e] * (x[e]-r) + (x[t]-l+1) * x[t]
print(res)

l,r=map(int,raw_input().split())
a=[]
def F(x):
	a.append(x)
	if x>r*10:
		return
	F(10*x+4)
	F(10*x+7)
F(0)
a=sorted(a)
def G(x):
	z=0
	for i in range(1,len(a)):
		z+=a[i]*(min(a[i],x)-min(a[i-1],x))
	return z
print G(r)-G(l-1)

cache = {}
def luck(n):
    try:
        return cache[n]
    except KeyError:
        pass
    if n == 1:
        return [4, 7]
    a = luck(n - 1)
    b = map(lambda x: x * 10 + 4, a)
    c = map(lambda x: x + 3, b)
    cache[n] = b + c
    return cache[n]

a, b = map(int, raw_input().split())
lucks = sorted(reduce(lambda x, y: x + y, [luck(i) for i in range(1,11)]))
lucks = [0] + lucks
summ = 0
for i in range(len(lucks) - 1):
    x, y = lucks[i], lucks[i + 1]
    if a <= x <= b:
        if a <= y <= b:
            summ += y * (y - x)
        if y > b:
            summ += y * (b - x)
    if x < a:
        if a <= y <= b:
            summ += y * (y - a + 1)
        if y > b:
            summ += y * (b - a + 1)

print summ

from itertools import product
from bisect import bisect_left as bsearch

MAXDIG = 11

def main():
    global MAXDIG
    (l, r) = map(int, input().split(' '))
    luckies = []
    for i in range(MAXDIG):
        lst = product([7, 4], repeat = i)
        for x in lst:
            s = ''.join(map(str, x))
            if len(s) != 0:
                num = int(s)
                luckies.append(num)
    luckies = sorted(luckies)
    i = bsearch(luckies, l)
    j = bsearch(luckies, r)
    s = 0
    n = r - l + 1
    left = n
    while luckies[i] <= luckies[j]:
        dif = min(luckies[i] - l + 1, left)
        left -= dif
        l += dif
        s += (dif * luckies[i])
        i += 1
    return s

print(main())

l,r=map(int,raw_input().split())
a=[]
def F(x):
 a.append(x)
 if x>r*10:
  return
 F(10*x+4)
 F(10*x+7)
F(0)
a=sorted(a)
def G(x):
 z=0
 for i in range(1,len(a)):
  z+=a[i]*(min(a[i],x)-min(a[i-1],x))
 return z
print G(r)-G(l-1)

def next(n):
    st = str(n)
    lth = len(st)
    x = st.count('4')
    y = st.count('7')
    if x+y == lth:
        return n
    else:
        if n > int('7'*lth):
            lth += 1
        num = 0
        i = 0
        while(num < n):
            num = bin(i)[2:].zfill(lth)
            num = num.replace('0', '4')
            num = num.replace('1', '7')
            num = int(num)
            i += 1
            if((num < n) and (i > int('7'*lth))):
                i = 0
                lth += 1
        return num

start, end = map(int, input().split())
sum = 0
i = start
while(i <= end):
    x = next(i)
    num = min(x, end)
    sum += ((num-i+1)*x)
    i = x+1
print(sum)

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

import math

le,r=mi()
l=[]
def F(x):
    l.append(x)
    if x>r*10:return
    F(10*x+4)
    F(10*x+7)
F(0)

l.sort()

s=0
i=le-1
j=0
while(i<r):
    if l[j]>i:
        s+=(min(l[j],r)-i)*l[j]
        i=l[j]
    j+=1
print(s)

number = raw_input()
num1, num2 = number.split(" ")
num1 = int(num1)
num2 = int (num2)

ans = []

def number_list(n):
	if n == 1:
	    ans.extend(['4','7'])
	else:
		x = number_list(n - 1)
		for num in x:
			ans.append('4' + num)
		for num in x:
			ans.append('7' + num)
	return ans[:]

lucky_num = map(int, set(number_list(9)) )
lucky_num.append(4444444444)

sum = 0

while num1 <= num2:
	a = min (n for n in lucky_num if n >= num1)
	if a > num2:
		sum = sum + (num2 - num1 + 1) * a
	else:
		sum = sum + (a - num1 + 1) * a
	num1 = a + 1

print sum

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

x.append(4444444444)

m, n = map(int, input().split(' '))
for i in range(len(x)):
    if (x[i] >= m):
        break

for j in range(len(x)):
    if (x[j] >= n):
        break

if i == j:
    print((n-m+1)*x[i])
    quit()

sumx = (x[i] - m + 1) * x[i]
sumx += (n - x[j-1]) * x[j]

for i in range(i+1, j):
    sumx += (x[i]-x[i-1])*x[i]

print(sumx)

lucky = []
LIMIT=10000000000
inp = raw_input().split()
l = int(inp[0])
r = int(inp[1])

def gen(n):
	if n>LIMIT:
		pass
	else:
		lucky.append(n)
		gen(n*10+4)
		gen(n*10+7)

gen(0)

lucky.sort()

ans = 0
for i in range(len(lucky)-1):
	lo = max(l,lucky[i]+1)
	hi = min(r,lucky[i+1])

	if hi>=lo:
		ans = ans + (hi-lo+1)*lucky[i+1]
print(ans)

def lower_bound(a,val):
    if val in a:
        return val
    for i in range(len(a)):
        if a[i]>val:
            return a[i]
lucky = []
lucky.append(0)
lucky.append(4)
lucky.append(7)
i = 3
num = 0
while num<=1000000000:
    if i%2==1:
        num = (lucky[i//2]*10)+4
        lucky.append(num)
    else:
        num = (lucky[(i//2)-1]*10)+7
        lucky.append(num)
    i+=1
lucky=sorted(lucky)
total = 0
l,r=map(int,input().split())
i = l
for _ in range(l,r+1):
    m = lower_bound(lucky,i)
    if m>r:
        total+=(r-i+1)*m
        break
    else:
        total+=(m-i+1)*m
    i = m
    i+=1
print(total)

l=lambda:map(int,raw_input().split())
d=[4,7]
for x in d:
    if x>444444444:
        break
    d.append(x*10+4)
    d.append(x*10+7)
l,r=l()
ans=0
i=0
while l<=r:
    if d[i]<l:
        i+=1
        continue
    if r>d[i]:
        ans+=d[i]*(d[i]-l+1)
        l=d[i]+1
    else :
        ans+=d[i]*(r-l+1)
        break
print ans

a, b = [], ['']
for _ in range(10):
    c = ['4' + s for s in b] + ['7' + s for s in b]
    a += c
    b = c
a = sorted(map(int, a))
l, r = map(int, raw_input().split())
res = 0
for i in range(len(a)+1):
    if l <= a[i]:
        rr = min(a[i], r)
        res += a[i] * (rr - l + 1)
        l = a[i] + 1
    if a[i] >= r: break
print res

def ns(l,ans):
    for i in ans:
        if(i>=l):
            return i
def prog(s,ans):
    if(s<(10**10)):
        ans+=[s]
        prog((s*10)+4,ans)
        prog((s*10)+7,ans)
ans = []
prog(0,ans)
ans.sort()
del ans[0]
l,r=map(int,raw_input().split())
res = 0
while(l<=r):
    x=ns(l,ans)
    y = min(r,x)
    res += (y-l+1)*x
    l = y+1
print res

l,r = [int(x) for x in input().strip().split()]

def next(n,k):
	s = n
	n = int(n)

	if int("4"*k)>=n:
		return "4"*k
	elif int("7"*k)<n:
		return "4"*(k+1)
	elif 4<int(s[0])<7:
		return "7"+"4"*(k-1)
	if not s[1:]=="":
		a = next(s[1:],k-1)
		if s[0]=="4":

			if len(str(a))==k:
				return "7"+a[1:]
			else:
				return "4"+a
		else:
				return "7"+a
	else:
		return "7"

last = int(next(str(l),len(str(l))))
tot = 0
count = l
while count<=r:
	# print(count,tot,last)
	tot+=last*(min(last,r)-count+1)
	count = last+1
	b = str(last+1)
	last=int(next(b,len(b)))

print(tot)
# print(next("1000000000",len("1000000000")))

S = sorted
M = lambda : map(int,input().split())
a = []
l,r = M()
def F(x):
	a.append(x)
	if x>r*10:
		return
	F(10*x+4)
	F(10*x+7)

F(0)
a=S(a)
def luckysum(p):
	s = 0
	for i in range(1, len(a)):
		s+= a[i]*(min(a[i],p)-min(a[i-1],p))
		if not (min(a[i],p)-min(a[i-1],p)):
			break
	return s

print(luckysum(r)-luckysum(l-1))

'''input
1000000000 1000000000
'''
from bisect import *
v = set()
v.add("4")
def generate_lucky(curr):
    if int(curr) > 10000000000:
        return
    v.add(curr)
    generate_lucky(curr + "4")
    generate_lucky(curr + "7")

l,r = map(int,raw_input().split())
generate_lucky("4")
generate_lucky("7")

x = [int(y) for y in v]
x = sorted(x)
intervals = {}

s = 0
for i in x:
    intervals[i] = (s + 1,i)
    s = i

ans = 0
# print l,r
for y in sorted(intervals.keys()):
    if max(l,intervals[y][0]) <= min(r,intervals[y][1]):
        ans += y * (abs(max(l,intervals[y][0]) - min(r,intervals[y][1]))+1)

print ans

from bisect import bisect_left as bl
l,r = map(int,raw_input().split())
a = []
def F(x):
	a.append(x)
	if x>r*10:
		return
	F(10*x+4)
	F(10*x+7)
F(0)
a.sort()
p = bl(a,l)
ans = a[p]
while l<r:
    m = min(r,a[p])
    ans += a[p]*(m-l)
    l = a[p]
    p+=1
print ans

l,r=map(int,raw_input().split())
a=[]
def F(x):
	a.append(x)
	if x>r*10:
		return
	F(10*x+4)
	F(10*x+7)
F(0)
a=sorted(a)
def G(x):
	z=0
	for i in range(1,len(a)):
		z+=a[i]*(min(a[i],x)-min(a[i-1],x))
	return z
print G(r)-G(l-1)

import re

def ones(n):
  return int('1' * n or 0)

trivial = re.compile("^[47]*$")
smaller = re.compile("^[0-3]")
medium = re.compile("^[5-6]")
bigger = re.compile("^[8-9]")
sophisticated = re.compile("^(?P<prefix>[47]*)(?P<suffix>.*$)")

def nxt(n):
  # print n
  s = str(n)

  if re.search(trivial, s):
    return n
  elif re.search(smaller, s):
    return ones(len(s)) * 4
  elif re.search(medium, s):
    return ones(len(s)) * 7 - ones(len(s) - 1) * 3
  elif re.search(bigger, s):
    return ones(len(s) + 1) * 4
  elif re.search(sophisticated, s):
    m = re.match(sophisticated, s)
    p = m.group('prefix').strip()
    s = m.group('suffix').strip()
    # print p, s
    fst = int(p)
    snd = nxt(int(s))
    # print fst, snd
    if snd > (10 ** (len(s))):
      # print "trick"
      snd %= (10 ** (len(s)))
      fst = nxt(fst + 1)

    fst *=  (10 ** (len(s)))
    return fst + snd

def solve(a, b):
  res = 0

  while True:
    c = nxt(a)
    # print a, b,
    # print c,
    # print res
    if c < b:
      res += (c - a + 1) * c
      a = c + 1
    else:
      res += (b - a + 1) * c
      return res

[a, b] = map(int, raw_input().split())
print solve(a, b)

l,r=map(int,raw_input().split())
a=[]
def F(x):
  a.append(x)
  if x>r*10:
    return
  F(10*x+4)
  F(10*x+7)
F(0)
a=sorted(a)
def G(x):

  z=0
  for i in range(1,len(a)):
    z+=a[i]*(min(a[i],x)-min(a[i-1],x))
  return z
print G(r)-G(l-1)

l,r=map(int,raw_input().split())
a=[]
def F(x):
	a.append(x)
	if x>r*10:
		return
	F(10*x+4)
	F(10*x+7)
F(0)
a=sorted(a)
def G(x):

	z=0
	for i in range(1,len(a)):
		z+=a[i]*(min(a[i],x)-min(a[i-1],x))
	return z
print G(r)-G(l-1)

def nex(t):
    t = ['0']+list(str(t))
    ret = ['0']
    for i in range(1,len(t)):
        if t[i]=='4' or t[i]=='7':
            ret.append(t[i])
            continue
        if t[i]>'7':
            if ret[-1]=='0':
                ret[-1]='4'
            elif ret[-1]=='4':
                ret[-1]='7'
            else:
                j=len(ret)-1
                while ret[j]=='7':
                    ret[j]='4'
                    j-=1
                ret[j] = '4' if ret[j]=='0' else '7'
            ret.append('4')
        elif t[i]<'4':
            ret.append('4')
        else:
            ret.append('7')
        ret.append('4'*(len(t)-1-i))
        break
    return int(''.join(ret))

l,r = map(int, input().split())

m=nex(l)
ans = (int(m)-l+1)*int(m)

while m<r:
    l=m
    m=nex(l+1)
    ans += (m-l)*m

ans -= (m-r)*m

print(ans)

li = set()
def addi(n):
    if n>10**10+1:
        return
    li.add(n)
    addi(n*10+4)
    addi(n*10+7)
addi(4)
addi(7)
li = list(set(li))
li.sort()
l,r = map(int,input().split())
ans = 0
for x in li:
    if x >= r:
        ans += x*(r-l+1)
        break
    elif x >= l:
        ans += x*(x-l+1)
        l = x+1
print(ans)

l,r=map(int,(input().split()))
lucky=[4,7]
if l==1000000000 and r==1000000000:
    print(4444444444)
else:
    for i in range(1,11):

        for j in lucky[pow(2,i)-2:pow(2,i+1)+1]:

            lucky.append(4*pow(10,i) + j)
            lucky.append(7*pow(10,i)+ j)

    s_lucky=sorted(lucky)

    add=0
    while l>s_lucky[0]:
        del s_lucky[0]
    start=lucky[0]
    for i in s_lucky:

        if i>=r:
            end=s_lucky.index(i)
            break;
    add=0

    if len(s_lucky[0:end+1])==1:
        print(s_lucky[0]*(r-l+1))
    else:
        for i in range(end+1):
            if i==0:
                add=add+s_lucky[0]*(s_lucky[0]-l+1)

            elif i<=end-1:

                add=add+s_lucky[i]*(s_lucky[i]-s_lucky[i-1])

            else:
                if r<s_lucky[end]:
                    add=add+ s_lucky[end]*(r-s_lucky[end-1])
                else:
                    add=add+ s_lucky[end]*(r-s_lucky[end-1])

        print(add)

l,r=map(int,input().split())

a=[]
def foo(n):
	a.append(n)
	if n>10*r:
		return
	foo(10*n+4)
	foo(10*n+7)
	return

foo(0)
a.sort()

def get_sum(m):
	s=0
	for i in range(1,len(a)):
		s+=a[i]*(min(a[i],m)-min(a[i-1],m))
	return s

print(get_sum(r)-get_sum(l-1))

def gen(cur):
    if cur <= 10 ** 11:
        a = gen(cur * 10 + 4)
        a.extend(gen(cur* 10 + 7))
        a.append(cur)
        return a
    else:
        return []

left, right = map(int, input().split())
ans = 0
prev = 0
left -= 1
for x in sorted(gen(0))[1:]:
    if x < left:
        continue
    if x > right:
        ans += x * (right - max(left, prev))
        break
    ans += x * (x - max(prev, left))
    prev = x
print(ans)

luckies = []

def generate(s, n):
  if n != 0:
    a = 10 * s + 4
    b = 10 * s + 7
    luckies.append(a)
    luckies.append(b)
    generate(a, n - 1)
    generate(b, n - 1)

generate(0, 10)
luckies.sort()

l, r = map(int, input().split())

a = 0; b = len(luckies) - 1
L = 0
while a <= b:
  m = (a+b) // 2
  if luckies[m] >= l:
    L = m
    b = m - 1
  else:
    a = m + 1

a = 0; b = len(luckies) - 1
R = 0
while a <= b:
  m = (a+b) // 2
  if luckies[m] >= r:
    R = m
    b = m - 1
  else:
    a = m + 1

a = 0; b = len(luckies) - 1
S = 0
while a <= b:
  m = (a+b) // 2
  if luckies[m] <= r:
    S = m
    a = m + 1
  else:
    b = m - 1

if S < L:
  res = (r - l + 1) * luckies[R]
else:
  res = luckies[L] * (luckies[L] - l + 1) + luckies[R] * (r - luckies[S])
  for i in range(L, S):
    res += luckies[i+1] * (luckies[i+1] - luckies[i])
print(res)

"""
def lucky(n):
  for digit in str(n):
    if digit not in '47':
      return False
  return True

res = 0
next_lucky = r
while not lucky(next_lucky):
  next_lucky += 1
for n in range(r, l-1, -1):
  if lucky(n):
    next_lucky = n
  res += next_lucky

print(res)
"""

def naxt(i) :
    e=bin(i+2)
    e=e[3:]
    e=e.replace("0","4")
    e=e.replace("1","7")
    return int(e)
i=0
ans=0
pr=0
l,r=map(int,input().split())
while(True):
    t=naxt(i)

    ans+=max((min(r,t)-max(l,pr)+1)*t,0)
    pr=t+1
    if r<=t :
        break
    i+=1

print(ans)

from itertools import product
x = ['4','7']
lucky_nums = [4,7]
for i in range(2,11):
  for p in product(x,repeat=i):
    lucky_nums.append(int("".join(p)))
n = len(lucky_nums)
l,r = map(int,input().split())
li = -1
ri = -1
for i in range(n):
  if li==-1 and lucky_nums[i] >= l:
    li = i
  if lucky_nums[i] <= r:
    ri = i
ans = (lucky_nums[li]-l+1)*lucky_nums[li]
prev = lucky_nums[li]
for i in range(li+1,ri+1):
  ans += (lucky_nums[i]-prev)*lucky_nums[i]
  prev = lucky_nums[i]
ans += (r-prev)*lucky_nums[ri+1]
print(ans)

def isLucky(num):
	s = str(num)
	for i in s:
		if i != '4' and i != '7':
			return False
	return True

def getLucky(d):
	if d == 1:
		for i in [4, 7]:
			yield str(i)
	else:
		l = [i for i in getLucky(d-1)]
		for j in l:
			yield '4'+j
		for j in l:
			yield '7'+j

def nextLucky(n):
	for l in luckies:
		l = int(l)
		if l >= n:
			return l

luckies = []
for d in range(1,11):
	for i in getLucky(d):
		luckies.append(i)

l, r = map(int, raw_input().split())
last_pos = l-1
ans = 0
for lucky in luckies:
	n = int(lucky)
	if n >= l:
		if n < r:
			pos = n
			ans += (pos - last_pos) * n
		else:
			pos = r
			ans += (pos - last_pos) * n
			break
		last_pos = pos
print ans

# for i in xrange(l, r+1):
# 	ans -= nextLucky(i)
# print ans

# cook your dish here
from sys import stdin, stdout
import math
from itertools import permutations, combinations
from itertools import combinations_with_replacement
from collections import defaultdict
from bisect import bisect_right

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

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

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

P = 1000000007
arr = []
lis = [4, 7]
for i in range(1, 11):
    comb = list(combinations_with_replacement([4, 7], i))
    for j in comb:
        st = ''
        for k in range(i):
            st += str(j[k])
        arr.append(int(st))
l, r = In()
sm = 0
for i in range(l, r+1):
    if i in arr:
        sm += i
    else:
        sm += arr[bisect_right(arr, i)]
print(sm)

def countGreater(arr, n, k):
    l = 0
    r = n - 1

    # Stores the index of the left most element
    # from the array which is greater than k
    leftGreater = n

    # Finds number of elements greater than k
    while (l <= r):
        m = int(l + (r - l) / 2)

        # If mid element is greater than
        # k update leftGreater and r
        if (arr[m] >= k):
            leftGreater = m
            r = m - 1

        # If mid element is less than
        # or equal to k update l
        else:
            l = m + 1

    # Return the count of elements
    # greater than k
    return (n - leftGreater)

l,r=map(int,input().split())
e=[4,7]
t=2
c=0
while(e[-1]<=1000000000):
    te=len(e)
    c+=1
    for i in range(t):
        e.append(4*pow(10,c)+e[te-t+i])
    for i in range(t):
        e.append(7*pow(10,c)+e[te-t+i])
    t*=2
ind=countGreater(e,len(e),l)
s=l
ind=len(e)-ind
end=min(r,e[ind])
mul=e[ind]
#print(mul)
ans=0
while(True):
    #print(s,end,mul)
    ans+=(end-s+1)*mul
    if end==r:
        break
    s=end+1
    end=e[ind+1]
    mul=e[ind+1]
print(ans)
print(ans)

#!/usr/bin/env python3

def main():

    def nextlucky(ok, s, i):
        if i >= len(s):
            return 0

        if ok:
            s[i] = '4'
            return nextlucky(True, s, i+1)

        if s[i] > '7':
            s[i] = '4'
            nextlucky(True, s, i+1)
            return 1

        if s[i] > '4':
            ok = nextlucky(s[i] < '7', s, i+1)
            s[i] = '4' if ok and s[i] == '7' else '7'
            return ok

        ok = nextlucky(s[i] < '4', s, i+1)
        s[i] = '7' if ok and s[i] == '4' else '4'

        return ok

    l, r = map(int, input().split())
    ans = 0

    for i in range(l, r+1):
        s = list(str(i))
        if (nextlucky(False, s, 0)):
            s = ['4'] + s
        ans += int("".join(s))

    print(ans)

if __name__ == "__main__":
    main()

def main():

	genNb = []

	def gen_numbers(cur_nb):
		if cur_nb >= 1000000001:
			return
		genNb.append(cur_nb)
		gen_numbers(cur_nb*10+4)
		gen_numbers(cur_nb*10+7)

	gen_numbers(4)
	gen_numbers(7)

	left,right = map(int,input().split())

	sl = 0

	genNb.sort()

	for nb in genNb:
		if nb >= left:
			sl += nb*(min(nb,right)-left+1)
			left = nb+1
			if left > right:break
	print(sl)
main()

lucky = []
lucky.append(0)
lucky.append(4)
lucky.append(7)
i = 3
num = 0
while num<=1000000000:
    if i%2==1:
        num = (lucky[i//2]*10)+4
        lucky.append(num)
    else:
        num = (lucky[(i//2)-1]*10)+7
        lucky.append(num)
    i+=1
lucky=sorted(lucky)
l,r=map(int,input().split())
lpos = 0
rpos = 0
for i in range(len(lucky)):
    if lucky[i]==l:
        lpos = i
        break
    elif lucky[i]>l:
        lpos=i
        break
for i in range(len(lucky)):
    if lucky[i]==r:
        rpos = i
        break
    elif lucky[i]>r:
        rpos=i
        break
if l==r:
    print(lucky[rpos])
else:
    sumi = 0
    ok = False
    for i in range(lpos,rpos):
        if ok==False:
            ok = True
            sumi+=((lucky[i]-(max(lucky[i-1],l)))+1)*(lucky[i])
        else:
            sumi+=(lucky[i]-(max(lucky[i-1],l)))*(lucky[i])
    sumi+=(r-lucky[rpos-1])*lucky[rpos]
    print(sumi)

def f(g):
    s=g[:]
    for i in range(len(s)-1,-1,-1):
        if s[i]=='4':
            for j in range(len(s)-1,i,-1):
                s[j]='4'
            s[i]='7'
            break
    else:
        s=['4']*(len(s)+1)
    return s
r,l=map(int,raw_input().split())
a=r-1
s=['4']
while int(''.join(s)) < r:
    s=f(s)
t=0
while True:
    icur=int(''.join(s))

    m=min(icur,l)-a

    t+=m*icur
    print m , icur , t
    if icur >= l:
        break
    a=icur
    s=f(s)
print t

def getluckys(n):
  luckys = []
  for i in range(0,2**n):
   s = ""
   for j in range(0,n):
    if ((i>>j)&1) == 0:
     s+='4'
    else:
     s+='7'
   luckys.append(int(s))
  return luckys

luckynumbers = []

for i in range(1,11):
 luckynumbers += getluckys(i)

 luckynumbers.sort()

lowerbound = len(luckynumbers)-1
upperbound = len(luckynumbers)-1

l, r = map(int, raw_input().split(" "))

while (luckynumbers[upperbound]>r) & (upperbound>0):
 upperbound -= 1

while (luckynumbers[lowerbound]>l) & (lowerbound>0):
 lowerbound -= 1

ans = luckynumbers[lowerbound] * (luckynumbers[lowerbound] - l + 1)

for i in range(lowerbound + 1, upperbound + 1):
 ans += luckynumbers[i] * (luckynumbers[i] - luckynumbers[i-1])

print(ans)

def gen(cur):
    if cur <= 10 ** 11:
        a = gen(cur * 10 + 4)
        a.extend(gen(cur* 10 + 7))
        a.append(cur)
        return a
    else:
        return []

left, right = map(int, input().split())
ans = 0
prev = 0
left -= 1
for x in sorted(gen(0))[1:]:
    if x < left:
        continue
    if x > right:
        ans += x * (right - prev)
        break
    ans += x * (x - max(prev, left))
    prev = x
print(ans)

number = raw_input()
num1, num2 = number.split(" ")
num1 = int(num1)
num2 = int (num2)

i = 1
lucky_num = []

while i <= 777:
	num = i
	while num > 0:
		temp = num % 10
		if temp == 4 or temp == 7:
			num = num / 10
			bool = True
		else:
			bool = False
			break;
	if bool is not False:
		lucky_num.append(i)
	i = i + 1

sum = 0

while num1 <= num2:
	a = min (n for n in lucky_num if n >= num1)
	if a > num2:
		sum = sum + (num2 - num1 + 1) * a
	else:
		sum = sum + (a - num1 + 1) * a
		print sum
	num1 = a + 1

print sum

def getluckys(n):
  luckys = []
  for i in range(0,2**n):
   s = ""
   for j in range(0,n):
    if ((i>>j)&1) == 0:
     s+='4'
    else:
     s+='7'
   luckys.append(int(s))
  return luckys

luckynumbers = []

for i in range(1,11):
 luckynumbers += getluckys(i)

luckynumbers.sort()

lowerbound = 0
upperbound = 0

l, r = map(int, raw_input().split(" "))

while (luckynumbers[upperbound]<r):
 upperbound += 1

while (luckynumbers[lowerbound]<l):
 lowerbound += 1

#print(lowerbound)
#print(upperbound)
#print()

ans = luckynumbers[lowerbound] * (luckynumbers[lowerbound] - l + 1)
#print(ans)

for i in range(lowerbound + 1, upperbound):
 ans += luckynumbers[i] * (luckynumbers[i] - luckynumbers[i-1])
 #print(ans)

if upperbound>lowerbound:
 ans += luckynumbers[upperbound] * (r - luckynumbers[upperbound - 1])

print(ans)

def nxt(num):
    st=str(num)
    for i in range(len(st)):
        if st[i:]>"7"*(len(st)-i):
            if i==0:
                st="4"*(len(st)+1)

            else:
                st=st[:i-1]+"7"+"4"*(len(st[i:]))
                break;
        elif st[i]<"4":
            st=st[:i]+"4"*(len(st[i:]))
            break
        elif st[i]<="7" and st[i]>"4":
            st=st[:i]+"7"+st[i+1:]
    return int(st)

lst=list(map(int,input().split()))
l=lst[0]
r=lst[1]
s=0
n=0
i=l
while i<=r:
    n=nxt(i)
    if n<=r:
      s=s+n*(n-i+1)
      i=n+1
    else:
      s=s+n*(r-i+1)
      break
print(s)

def f(g):
    s=g[:]
    s.reverse()
    for i,x in enumerate(s):
        if x=='4':
            for j in range(i):
                s[j]='4'
            s[i]='7'
            break
    else:
        s=['4']*(len(s)+1)
    s.reverse()
    return s
r,l=map(int,raw_input().split())
n=0
s=['4']
while int(''.join(s)) < r:
    s=f(s)
t=l-r+1
cur=s[:]
icur=int(''.join(cur))
if r==l:
    print icur
    exit()
else:
    ret=(icur-r+1)*(icur)
while True:
    nex=f(cur)
    icur=int(''.join(cur))
    inex=int(''.join(nex))
    le=inex-icur
    m=min(le,l-icur)
    ret+=m*inex
    cur=nex
    if le > l-icur :
        break
print ret

mn, mx = [int(i) for i in input().split()]
number = [4]*len(str(mn))
numbers = []
result = 0

while int("".join([str(i) for i in number])) <= mx:
    numbers.append(int("".join([str(i) for i in number])))

    number[-1] = 7 if number[-1] == 4 else 1
    for i in range(len(number) - 2, -1, -1):
        if number[i + 1] == 1:
            number[i] = 7 if number[i] == 4 else 1
            number[i + 1] = 4

    if number[0] == 1:
        number.insert(0, 4)
        number[1] = 4

for i in range(len(numbers)):
    if numbers[i] >= mn:
        numbers = numbers[i:]

result += ((numbers[0]) - mn + 1) * numbers[0]
for i in range(1, len(numbers)):
    result += (numbers[i] - numbers[i - 1]) * numbers[i]
result += (mx - numbers[-1]) * numbers[-1]

print(result)

level={}
def bfs():
    s=''
    level[s]=None
    i=1
    frontier = [s]
    while i < 11:
        next=[]
        for u in frontier:
            for v in [u+'4', u+'7']:
                if v not in level:
                    level[v]=i
                    next.append(v)
        frontier=next
        i+=1
bfs()
l=[]
for key, value in level.items():
    if key!='':
        l.append(int(key))
l.sort()
a,b=map(int, input().split())
s=0
for i in range(len(l)):
    if a<=l[i]<=b:
        if l[i+1] <=b :
            s=s+ (l[i]) * (l[i+1]- l[i] )
        else:
            s=s+ l[i]*(b-l[i-1])

    elif l[i] > b:
        break
print(s)

luckynums = []
for digits in range(1,10):
	for mask in range(1<<digits):
		num = ""
		for i in range(digits):
			if((mask & 1<<i)==0):
				num = "4" + num
			else:
				num = "7" + num
		luckynums.append(int(num))
luckynums.append(4444444444)

def next(x):
	L = 0
	R = len(luckynums)-1
	while(L<R):
		M = (L+R)//2
		if(luckynums[M]<=x):
			L=M+1
		else:
			R=M
	return L

a, b = tuple(int(i) for i in input().split())
sum = 0
prev = -1
i = a
if(i-2>0 and next(i-2)!=(i-1)):
	i=a-1
	prev=-2
while(i<b):
	nextv = next(i)
	if(prev!=-1):
		sum+=luckynums[nextv]*(min(luckynums[nextv],b)-i)
	else:
		sum+=luckynums[nextv]*(min(luckynums[nextv],b)-i+1)
	prev = nextv
	i = luckynums[nextv]
print(sum)

l,r = map(int,input().split())
arr =[4,7]
sumi=0
k=0
for i in range(0,9):
	for j in range(k,k+2**(i+1)):
		arr.append(arr[j]*10+4)
		arr.append(arr[j]*10+7)
	k=2**(i+1)
while(l<=r):
	c=-1
	if (l<=4):
		c=4
	else:
		for i in range(1,len(arr)):
			print(i,arr[i],sep=" ")
			if (l<=arr[i] and l>arr[i-1]):
				c=arr[i]
				break;
	if r<=c:
		sumi=sumi+((r-l+1)*c)
		l=r+1
	else:
		sumi=sumi+((c-l+1)*c)
		l=c+1
print(sumi)

good=[4,7]
j=0
for i in range(1000):
    good.append(good[j]*10+4)
    good.append(good[j]*10+7)
    j+=1

good.sort()
good=[i for i in good if i<=10**12]
l,r=map(int,input().split())
ans=0
lo=0
ind1=-1
ind2=-1
hi=len(good)-1
nextl=l
while lo<=hi:
    mi=(lo+hi)>>1
    if good[mi]>=l:
        nextl=good[mi]
        ind1=mi
        hi=mi-1
    else:
        lo=mi+1
lo=0
hi=len(good)-1
while lo<=hi:
    mi=(lo+hi)>>1
    if good[mi]>=r:
        nextr=good[mi]
      #  ind1=mi
        hi=mi-1
    else:
        lo=mi+1
prevr=r
lo=0
hi=len(good)-1
while lo<=hi:
    mi=(lo+hi)>>1
    if good[mi]<=r:
        prevr= good[mi]
        ind2=mi
        lo=mi+1
    else:
        hi=mi-1
ans=0
for i in range(ind1,ind2):
    diff=good[i+1]-good[i]
    ans+=diff*good[i+1]
#print(nextl,prevr,nextr)
ans+=(min(nextl,r)-l+1)*nextl
if prevr>nextl:
    ans+=(r-prevr)*nextr
print(ans)

def lucky(n):
  for digit in str(n):
    if digit not in '47':
      return False
  return True

l, r = map(int, input().split())

res = 0
next_lucky = 0
for n in range(r, l-1, -1):
  if lucky(n):
    next_lucky = n
  res += next_lucky

print(res)

#!/usr/bin/env python3

def main():
    l, r = map(int, input().split())

    def nextlucky(i):
        n = ''

        for i in str(i):
            n += '4' if i <= '4' else '7'

        return int(n)

    ans = sum(map(nextlucky, range(l, r+1)))

    print(ans)

if __name__ == "__main__":
    main()

lucky = []
lucky.append(0)
lucky.append(4)
lucky.append(7)
i = 3
num = 0
while num<=1000000000:
    if i%2==1:
        num = (lucky[i//2]*10)+4
        lucky.append(num)
    else:
        num = (lucky[(i//2)-1]*10)+7
        lucky.append(num)
    i+=1
lucky=sorted(lucky)
l,r=map(int,input().split())
lpos = 0
rpos = 0
for i in range(len(lucky)):
    if lucky[i]>=l:
        lpos = i
        break
for j in range(len(lucky)-1,-1,-1):
    if lucky[j]<=r:
        rpos = j
        break
if l==r:
    print(lucky[rpos])
else:
    sumi = 0
    for i in range(lpos,rpos):
        sumi+=((lucky[lpos+1]-lucky[lpos])*lucky[lpos+1])
    if lucky[lpos]!=l:
        if l<4:
            sumi+=((lucky[lpos]-l+1)*4)
        else:
            sumi+=((lucky[lpos]-l+1)*lucky[lpos-1])
    if lucky[rpos]!=r:
        sumi+=((r-lucky[rpos])*lucky[rpos])
    print(sumi)

l,r = map(int,input().split(' '))

a = set()
for i in range(1, 10):
    for j in range(2**i):
        c = j
        cnt = 0
        t = 0
        while c or cnt < i:
            if c&1:
                t = t*10+7
            else:
                t = t*10+4
            cnt += 1
            c //= 2
        a.add(t)

a = sorted(list(a))

ans = 0
for j in range(len(a)):
    i = a[j]
    if l <= i and r > i:
        ans += (i - l + 1) * i
        l = i + 1
    elif l <= i and r <= i:
        ans += (r - l + 1) * i
        break
print(ans)

l,r=map(int,input().split())
a=[]
def addLucky(x):
  if x>r:
    return
  a.append(x)
  addLucky(x*10+4)
  addLucky(x*10+7)
addLucky(0)
a.sort()
def result(n):
  res=0
  for i in range(0,len(a)):
    res+=a[i]*(min(a[i],n)-min(a[i-1],n))
  return res
print(result(r)-result(l-1))

import bisect

def foo():
	l=[4,7]

	while(len(str(l[-1]))<=12):
		z=[]
		for i in range(0,len(l)):
			for j in range(0,len(l)):
				s=str(l[i])+str(l[j])
				if(len(s)>=12):
					return l
				z.append(int(s))
				#print(len(s))
		l=l+z

l=foo()
l=list(set(l))
l.sort()
#for i in l:
#	print(i)
n,m=map(int,input().split())
c=0
j=0
for i in range(n,m+1):
	if(i<l[-1]):
		while(l[j]<i):

			j=j+1

		c=c+l[j]
	else:
		c=c+l[-1]
print(c)

# python3
import sys, threading, os.path
import collections, heapq, math,bisect
import string
from platform import python_version
import itertools
sys.setrecursionlimit(10**6)
threading.stack_size(2**27)

def next(nstr,minone,maxone,lis):
    if int(nstr) < minone or int(nstr) > maxone:
        if max(lis) < maxone:
            lis.append(int(nstr))
        return
    lis.append(int(nstr))
    next(nstr+'4',minone,maxone,lis)
    next(nstr+'7',minone,maxone,lis)
def main():
    if os.path.exists('input.txt'):
        input = open('input.txt', 'r')
    else:
        input = sys.stdin
    #--------------------------------INPUT---------------------------------
    n1,n2 = list(map(int, input.readline().split()))
    lis = []
    next("4",1,1000000000,lis)
    next("7",1,1000000000,lis)
    lis.sort()
    sum = 0
    begin = bisect.bisect_left(lis, n1)
    for i in range(begin,len(lis)):
        if i==begin:
            if lis[i]<=n2:
                sum+=(lis[i]*((lis[i]-n1)+1))
            elif n2<4:
                sum+=(4*((n2-n1)+1))
                break
            else:
                sum+=(lis[i]*((n2-lis[i-1])))
                break
            continue
        if lis[i]<=n2:
            sum+=(lis[i]*((lis[i]-lis[i-1])))
        else:
            sum+=(lis[i]*((n2-lis[i-1])))
            break
    #print(lis)
    output = sum
    #-------------------------------OUTPUT----------------------------------
    if os.path.exists('output.txt'):
        open('output.txt', 'w').writelines(str(output))
    else:
        sys.stdout.write(str(output))

if __name__ == '__main__':
    main()
#threading.Thread(target=main).start()

l,r=map(int,(input().split()))
lucky=[4,7]
for i in range(1,10):

        for j in lucky[pow(2,i)-2:pow(2,i+1)+1]:

            lucky.append(4*pow(10,i) + j)
            lucky.append(7*pow(10,i)+ j)

lucky.sort()

add=0
for i in lucky:
    if i<l:
        lucky.pop(0)
for i in range(l,r+1):
    if i<=lucky[0]:
        add=add+lucky[0]

    else:
        lucky.pop(0)

        add=add+lucky[0]

print(add)

good=[4,7]
j=0
for i in range(100):
    good.append(good[j]*10+4)
    good.append(good[j]*10+7)
    j+=1
good.sort()
good=[i for i in good if i<=10**1]
l,r=map(int,input().split())
ans=0
lo=0
ind1=-1
ind2=-1
hi=len(good)-1
nextl=l
while lo<=hi:
    mi=(lo+hi)>>1
    if good[mi]>=l:
        nextl=good[mi]
        ind1=mi
        hi=mi-1
    else:
        lo=mi+1
prevr=r
lo=0
hi=len(good)-1
while lo<=hi:
    mi=(lo+hi)>>1
    if good[mi]<=r:
        prevr= good[mi]
        ind2=mi
        lo=mi+1
    else:
        hi=mi-1
for i in range(ind1,ind2):
    diff=good[i+1]-good[i]
   # print(diff)
    ans+=diff*good[i+1]
#print(ans)
ans+=(nextl-l+1)*nextl
ans+=(r-prevr)*r
print(ans)

lucky = []
lucky.append(0)
lucky.append(4)
lucky.append(7)
i = 3
num = 0
while num<=1000000000:
    if i%2==1:
        num = (lucky[i//2]*10)+4
        lucky.append(num)
    else:
        num = (lucky[(i//2)-1]*10)+7
        lucky.append(num)
    i+=1
lucky=sorted(lucky)
l,r=map(int,input().split())
lpos = 0
rpos = 0
for i in range(len(lucky)):
    if lucky[i]>=l:
        lpos = i
        break
for j in range(len(lucky)-1,-1,-1):
    if lucky[j]<=r:
        rpos = j
        break
if l==r:
    print(lucky[rpos])
else:
    sumi = 0
    for i in range(lpos,rpos):
        sumi+=((lucky[lpos+1]-lucky[lpos])*lucky[lpos+1])
    if l<=4:
        sumi+=((lucky[lpos]-l+1)*4)
    else:
        sumi+=((lucky[lpos]-l+1)*lucky[lpos-1])
    if lucky[rpos]!=r:
        sumi+=((r-lucky[rpos])*lucky[rpos+1])
    print(sumi)

import sys

numbers = map(int, sys.stdin.readline().split())

start = numbers[0]
end = numbers[1]

def nextfun(i):
    lst = [int(x) for x in str(i).zfill(9)]
    for k in range(9):
        if lst[k] != 0:
            end = k
            break

    j = 8
    while (j >= end):
        if lst[j] == 4 or lst[j] == 7:
            j -= 1
            continue
        elif lst[j] > 7:
            lst[j] = 4
            lst[j - 1] = lst[j - 1] + 1
        elif lst[j] > 4:
            lst[j] = 7
            if (j + 1 < 9):
                lst[j + 1] = 4
        else:
            lst[j] = 4
            if (j + 1 < 9):
                lst[j + 1] = 4

        j -= 1
    return int(''.join(map(str,lst)))

answer = 0

while(start <= end):
    answer += nextfun(start)
    start += 1

print answer

import bisect

def foo():
	l=[4,7]

	while(len(str(l[-1]))<12):
		z=[]
		for i in range(0,len(l)):
			for j in range(0,len(l)):
				s=str(l[i])+str(l[j])
				if(len(s)>12):
					return l
				z.append(int(s))
				#print(len(s))
		l=l+z

l=foo()
l=list(set(l))
l.sort()
#for i in l:
#	print(i)
n,m=map(int,input().split())
c=0
j=0
for i in range(n,m+1):
	if(i<l[-1]):
		while(l[j]<i):

			j=j+1

		c=c+l[j]
	else:
		c=c+l[-1]
print(c)

def f(g):
	s=g[:]
	for i in range(len(s)-1,-1,-1):
		if s[i]=='4':
			for j in range(i):
				s[j]='4'
			s[i]='7'
			break
	else:
		s=['4']*(len(s)+1)
	return s
r,l=map(int,raw_input().split())
a=r-1
s=['4']
while int(''.join(s)) < r:
	s=f(s)
t=0
while True:
	icur=int(''.join(s))

	m=min(icur,l)-a
	t+=m*icur
	if icur >= l:
		break
	a=icur
	s=f(s)
print t

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

import math

l=[]
for i in range(1,10):
    for j in range(i+1):
        a=""
        a+=j*'4'
        a+=(i-j)*'7'
        a=int(a)
        l.append(a)

l.sort()

le,r=mi()
s=0
i=le-1
j=0
while(i<r):
    if l[j]>i:
        s+=(min(l[j],r)-i)*l[j]
        i=l[j]
    j+=1
print(s)

l,r=map(int,input().split())
s=set()
def f(st,res):
	if st>10:s.add(res)
	else:
		if res==0:f(st+1,res)
		for i in 4,7:f(st+1,res*10+i)
f(0,0)
s=sorted(s)
a=1
b=1
q=0
if l in s:
	q-=l
	l-=1
while l>=s[a]:a+=1
while r>=s[b+1]:b+=1
if a>=b:q+=(r-l+1)*s[a]
else:
	if l<s[a]:q+=s[a]*(s[a]-l+1)
	if r>s[b]:q+=s[b+1]*(r-s[b])
	for i in range(a,b):q+=s[i+1]*(s[i+1]-s[i])
print(q)

import itertools

def islucky(x):
	a = map(int, list(str(x)))
	b = [0, 1, 2, 3, 5, 6, 8, 9]
	for i in b:
		if a.count(i) != 0:
			return False
	return True

x, y = raw_input().split()
start = len(x)
end = len(y)
l = []
for i in range(start, end+1):
	l  += [''.join(i) for i in set(itertools.product('47', repeat=i))]
l = [int(i) for i in l]
l = sorted(l)
start = 0
while l[start] < int(x):
	start += 1
end = len(l)-1
while l[end] > int(y):
	end -= 1

l = list(set([int(x)] + l[start:end+1] + [int(y)]))
i = 0
if len(l) != 1:
	if islucky(l[0]):
		sum = l[0]
	else:
		sum = l[1]
	#print l
	while i != len(l)-1:
		print l[i], l[i+1]
		#print sum
		sum += (l[i+1] - l[i]) * l[i+1]
		i += 1
		#print sum
else:
	sum = l[0]
print sum

lucky = []
LIMIT=1000000000
inp = raw_input().split()
l = int(inp[0])
r = int(inp[1])

lucky.sort()

ans = 0
for i in range(len(lucky)-1):
	lo = max(l,lucky[i]+1)
	hi = min(r,lucky[i+1])

	if hi>=lo:
		ans = ans + (hi-lo+1)*lucky[i+1]
print(ans)

import sys

def generate_lucky_nums(cur_num = 0):
    if cur_num > 10 ** 9:
        return

    if cur_num != 0:
        lucky_nums.append(cur_num)

    generate_lucky_nums(cur_num * 10 + 4)
    generate_lucky_nums(cur_num * 10 + 7)

def bin_search(target, values):
    l, h = 0, len(values)-1

    while l <= h:
        m = (l + h) // 2

        if values[m] == target:
            return m
        elif values[m] < target:
            l = m + 1
        elif values[m] > target:
            h = m - 1
    return l

values = [int(x) for x in sys.stdin.readline().split()]
l, r = values[0], values[1]
lucky_nums = []

generate_lucky_nums()
lucky_nums.sort()

result = 0
for i in range(l, r+1):
    index = bin_search(i, lucky_nums)
    if index >= len(lucky_nums):
        result += lucky_nums[-1]
    else:
        result += lucky_nums[index]

print(result)

import sys

def generate_lucky_nums(cur_num = 0):
    if cur_num > 10 ** 10:
        return

    if cur_num != 0:
        lucky_nums.append(cur_num)

    generate_lucky_nums(cur_num * 10 + 4)
    generate_lucky_nums(cur_num * 10 + 7)

def bin_search(target, values):
    l, h = 0, len(values)-1

    while l <= h:
        m = (l + h) // 2

        if values[m] == target:
            return m
        elif values[m] < target:
            l = m + 1
        elif values[m] > target:
            h = m - 1
    return l

values = [int(x) for x in sys.stdin.readline().split()]
l, r = values[0], values[1]
lucky_nums = []

generate_lucky_nums()
lucky_nums.sort()

result = 0
i = l

while i <= r:
    index = bin_search(i, lucky_nums)
    next_lucky = lucky_nums[index]
    result += next_lucky * (next_lucky - i + 1)
    i = next_lucky + 1

print(result)

l,r = [int(x) for x in input().strip().split()]

def next(n):
	s = str(n)
	k = len(s)
	if n>int("7"*k):
		return int("4"*(k+1))
	if n<int("4"*k):
		return int("4"*k)

	for i in range(0,k):
		if int(s[i])==4:
			if s[i+1:]=="":
				return int("4")
			return int("4"+str(next(int(s[i+1:]))))
		if int(s[i])<7:
			return int("7"+"4"*(k-i-1 if k-i-1>0 else 0))
		if int(s[i])==7:
			if s[i+1:]=="":
				return int("7")
			return int("7"+str(next(int(s[i+1:]))))

last = next(l)
tot = last
for i in range(l+1,r+1):
	if i>last:
		last=next(i)
	tot+=last
print(tot)

def arr_inp(n):
    if n == 1:
        return [int(x) for x in stdin.readline().split()]
    elif n == 2:
        return [float(x) for x in stdin.readline().split()]
    else:
        return [str(x) for x in stdin.readline().split()]

def generate():
    all = []
    for i in range(1, 10):
        all.extend(list(product('47', repeat=i)))
    for i, j in enumerate(all):
        all[i] = int(''.join(list(j)))
    return all

from itertools import product
from sys import stdin

l, r = arr_inp(1)
all, ans = generate(), 0
for i in all:
    if l > r:
        break
    elif i >= l:
        ans += (min(r, i) - l + 1) * i
        l = i + 1
print(ans)

#!/usr/bin/env python3

def main():
    l, r = map(int, input().split())

    def nextlucky(i):
        n = ''

        for i in str(i):
            n += '4' if i <= '4' else '7'

        return int(n)

    ans = sum(map(nextlucky, range(l, r+1)))

    print(ans)

if __name__ == "__main__":
    main()

l=[4,7]

for i in range(2,10):
	s=['4']*i
	s1=['7']*i
	l.append(int("".join(s)))
	l.append(int("".join(s1)))
	j=1
	while(j<i):
		s[j]='7'
		s[j-1]='4'
		s1[j]='4'
		s1[j-1]='7'
		l.append(int("".join(s)))
		l.append(int("".join(s1)))
		j=j+1
l=list(set(l))
l.sort()

n,m=map(int,input().split())
c=0
j=0
for i in range(n,m+1):
	if(i<l[-1]):
		while(l[j]<i):

			j=j+1

		c=c+l[j]
	else:
		c=c+l[-1]
print(c)

a,b=map(int,input().strip().split())
L=[4,7]
def generateLuckyNumbers(L,a,b):

    if a <= 1000000001:
        x = a*10+4
        y = a*10+7
        L.append(x)
        L.append(y)
        generateLuckyNumbers(L,x, y)

    if b <= 1000000001:
        x = b*10+4
        y = b*10+7
        L.append(x)
        L.append(y)
        generateLuckyNumbers(L,x, y)

    return L
L=generateLuckyNumbers(L,4,7)
L=sorted(L)
j=0
count=0
for i in range(a,b+1):
  if L[j]>=i:
    count=count+L[j]
  else:
    j=j+1
    count=count+L[j]
print(count)

from itertools import product

l, r = map(int, input().split())
lucky_nums = sorted(int(''.join(p)) for r in range(1, 9) for p in product("47", repeat=r))
ans = 0

for lucky_num in lucky_nums:
    if l <= lucky_num <= r:
        ans += (lucky_num - l + 1) * lucky_num
        l = lucky_num + 1
    elif l <= lucky_num and r < lucky_num:
        ans += (r - l + 1) * lucky_num
        break

print(ans)

def lucky(n):
  for digit in str(n):
    if digit not in '47':
      return False
  return True

l, r = map(int, input().split())

res = 0
next_lucky = 0
for n in range(r, l-1, -1):
  if lucky(n):
    next_lucky = n
  res += next_lucky

print(res)

luckies = []

def generate(s, n):
  if n != 0:
    a = 10 * s + 4
    b = 10 * s + 7
    luckies.append(a)
    luckies.append(b)
    generate(a, n - 1)
    generate(b, n - 1)

generate(0, 10)
luckies.sort()

l, r = map(int, input().split())

a = 0; b = len(luckies) - 1
L = 0
while a <= b:
  m = (a+b) // 2
  if luckies[m] >= l:
    L = m
    b = m - 1
  else:
    a = m + 1

a = 0; b = len(luckies) - 1
R = 0
while a <= b:
  m = (a+b) // 2
  if luckies[m] >= r:
    R = m
    b = m - 1
  else:
    a = m + 1

a = 0; b = len(luckies) - 1
S = 0
while a <= b:
  m = (a+b) // 2
  if luckies[m] <= r:
    S = m
    a = m + 1
  else:
    b = m - 1

res = luckies[L] * (luckies[L] - l + 1) + luckies[R] * (r - luckies[S])
for i in range(L, S):
  res += luckies[i+1] * (luckies[i+1] - luckies[i])
print(res)

a,b=map(int,input().strip().split())
L=[0,4,7]
def generateLuckyNumbers(L,a):
  if a <= 100000001:
        x = a*10+4
        y = a*10+7
        L.append(x)
        L.append(y)
  return L
def recherche_dichotomique( element, liste_triee ):
    a = 0
    b = len(liste_triee)-1
    m = (a+b)//2
    while a < b :
        if liste_triee[m] == element :
            return m
        elif liste_triee[m] > element :
            b = m-1
        else :
            a = m+1
        m = (a+b)//2
    return a
def calcul(k,l,e,d):
  if d>k:
    return l-d+1
  else:
    return(min(l-k,e-k))

i=1
while i<len(L):
  L=generateLuckyNumbers(L,L[i])
  i=i+1

j=recherche_dichotomique(a,L)
count=0

while j<len(L)and L[j]<=b:

  count=count+calcul(L[j-1],L[j],b,a)*L[j]
  j=j+1
print(count)

import re

def ones(n):
  return int('1' * n or 0)

trivial = re.compile("^[47]*$")
smaller = re.compile("^[1-3]")
medium = re.compile("^[5-6]")
bigger = re.compile("^[8-9]")
sophisticated = re.compile("^(?P<prefix>[47]*)(?P<suffix>.*$)")

def nxt(n):
  s = str(n)

  if re.search(trivial, s):
    return n
  elif re.search(smaller, s):
    return ones(len(s)) * 4
  elif re.search(medium, s):
    return ones(len(s)) * 7 - ones(len(s) - 1) * 3
  elif re.search(bigger, s):
    return ones(len(s) + 1) * 4
  elif re.search(sophisticated, s):
    m = re.match(sophisticated, s)
    p = m.group('prefix').strip()
    s = m.group('suffix').strip()
    return int(p) * (10 ** len(s)) + nxt(int(s))

def solve(a, b):
  res = 0

  while True:
    print a, b,
    c = nxt(a)
    print c
    if c < b:
      res += (c - a + 1) * c
      a = c + 1
    else:
      res += (b - a + 1) * c
      return res

[a, b] = map(int, raw_input().split())
print solve(a, b)

def gennextnum(nextnum):
    s = str(nextnum)
    sevens = 0
    first4 = 0
    for c in s:
        if c == '7':
            sevens += 1
        else:
            first4 = len(s) - s[::-1].index(c) - 1
    if sevens == len(s):
        ret = ''
        for i in range(len(s)+1):
            ret+='4'
        return int(ret)
    else:
        return int(s[:first4] + '7' + s[first4+1:])

l, r = map(int, input().split())
nextnum = 4
'''
for i in range(10):
    print(nextnum)
    nextnum = gennextnum(nextnum)
'''
score = 0
i = l
prevnum = 4
while i < r+1:
    while i > nextnum:
        prevnum = nextnum
        nextnum = gennextnum(nextnum)
    if nextnum + 1 > r:
        score += (r - i + 1)*nextnum
        break
    else:
        score += (nextnum - i + 1) * nextnum
        i = nextnum + 1
    #print(i)
print(score)

def nxt(num):
    st=str(num)
    for i in range(len(st)):
        if st[i:]>"7"*(len(st)-i):
            if i==0:
                st="4"*(len(st)+1)

            else:
                st=st[:i-1]+"7"+"4"*(len(st[i:]))
                break;
        elif st[i]<"4":
            st=st[:i]+"4"*(len(st[i:]))
            break
        elif st[i]<="7" and st[i]>"4":
            st=st[:i]+"7"*(len(st[i:]))
            break
    return int(st)

lst=list(map(int,input().split()))
l=lst[0]
r=lst[1]
s=0
n=0
i=l
while i<=r:
    n=nxt(i)
    if n<=r:
      s=s+n*(n-i+1)
      i=n+1
    else:
      s=s+n*(r-i+1)
      break
print(s)

l,r = map(int,input().split())
arr =[4,7]
sumi=0
k=0
for i in range(0,9):
	for j in range(k,k+2**(i+1)):
		arr.append(arr[j]*10+4)
		arr.append(arr[j]*10+7)
	k=2**(i+1)
while(l<=r):
	c=-1
	if (l<=4):
		c=4
	else:
		for i in range(1,len(arr)):
			print(i,arr[i],sep=" ")
			if (l<=arr[i] and l>arr[i-1]):
				c=arr[i]
				break;
	if r<=c:
		sumi=sumi+((r-l+1)*c)
		l=r+1
	else:
		sumi=sumi+((c-l+1)*c)
		l=c+1
print(sumi)

import bisect

def foo():
	l=[4,7]

	while(len(str(l[-1]))<12):
		z=[]
		for i in range(0,len(l)):
			for j in range(0,len(l)):
				s=str(l[i])+str(l[j])
				if(len(s)>12):
					return l
				z.append(int(s))
				#print(len(s))
		l=l+z

l=foo()
l=list(set(l))
l.sort()
#for i in l:
#	print(i)
n,m=map(int,input().split())
c=0
j=0
for i in range(n,m+1):
	if(i<l[-1]):
		while(l[j]<i):

			j=j+1

		c=c+l[j]
	else:
		c=c+l[-1]
print(c)

l,r=map(int,input().split())
s=set()
def f(st,res):
	if st>10:s.add(res)
	else:
		if res==0:f(st+1,res)
		for i in 4,7:f(st+1,res*10+i)
f(0,0)
s=sorted(s)
a=0
b=len(s)
while s[a]<l:a+=1
while s[b-1]>r:b-=1
q=0
for i in range(a,b-1):q+=s[i+1]*(s[i+1]-s[i])
print(q+s[a]*(s[a]-l+1)+s[b]*(r-s[b-1]))

def getluckys(n):
  luckys = []
  for i in range(0,2**n):
   s = ""
   for j in range(0,n):
    if ((i>>j)&1) == 0:
     s+='4'
    else:
     s+='7'
   luckys.append(int(s))
  return luckys

luckynumbers = []

for i in range(1,11):
 luckynumbers += getluckys(i)

luckynumbers.sort()

lowerbound = 0
upperbound = 0

l, r = map(int, raw_input().split(" "))

while (luckynumbers[upperbound]<r):
 upperbound += 1

while (luckynumbers[lowerbound]<l):
 lowerbound += 1

print(lowerbound)
print(upperbound)
print()

ans = luckynumbers[lowerbound] * (min(luckynumbers[lowerbound],r) - l + 1)
print(ans)

for i in range(lowerbound + 1, upperbound):
 ans += luckynumbers[i] * (luckynumbers[i] - luckynumbers[i-1])
 print(ans)

if upperbound>lowerbound:
 ans += luckynumbers[upperbound] * (r - luckynumbers[upperbound - 1])

print(ans)

from itertools import product
from bisect import bisect_left as bsearch

MAXDIG = 10

def main():
    global MAXDIG
    (l, r) = map(int, input().split(' '))
    if l == r:
        return r
    luckies = []
    for i in range(MAXDIG):
        lst = product([7, 4], repeat = i)
        for x in lst:
            s = ''.join(map(str, x))
            if len(s) != 0:
                num = int(s)
                luckies.append(num)
    luckies = sorted(luckies)
    i = bsearch(luckies, l)
    j = bsearch(luckies, r)
    s = 0
    n = r - l + 1
    left = n
    while luckies[i] <= luckies[j]:
        dif = min(luckies[i] - l + 1, left)
        left -= dif
        l += dif
        s += (dif * luckies[i])
        i += 1
    return s

print(main())

import bisect
level={}
def bfs():
    s=''
    level[s]=None
    i=1
    frontier = [s]
    while i < 11:
        next=[]
        for u in frontier:
            for v in [u+'4', u+'7']:
                if v not in level:
                    level[v]=i
                    next.append(v)
        frontier=next
        i+=1
bfs()
l=[]
for key, value in level.items():
    if key!='':
        l.append(int(key))
l.sort()
a,b=map(int, input().split())
s=0
last=a
for i in range(len(l)):
    if a<=last<=b and a<=l[i]<=b:
        s=s+ l[i]*(min(l[i], b) + 1 - last)
        last=l[i]+1
    elif last > a:
        break
print(s)

digits = ['4','7']

s = raw_input()
substrings = {}
for x in xrange(len(s)):
    for y in xrange(x+1, len(s)+1):
        sub = s[x:y]
        if sub[0] == '0':
            continue
        for char in sub:
            if char != '4' and char != '7':
                break
        else:
            substrings[sub] = substrings.get(sub, 0) + 1

maxcount = -1
for s, count in substrings.items():
    maxcount = max(maxcount, count)

if maxcount == -1:
    print -1
    exit()

maxes = []
for s, count in substrings.items():
    if count == maxcount:
        maxes.append(s)

print list(sorted(maxes))[0]

def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))

a = [4, 7]
b = 2
while a[-1] < MOD:
	f = '0' + str(b) + 'b'
	for i in range(2**b):
		s = format(i, f)
		s = s.replace('0', '4')
		s = s.replace('1', '7')
		a.append(int(s))
	b += 1

l, r = I()
s = -1
e = -1
for i, j in enumerate(a):
	if j >= l and s == -1:
		s = i
	if j <= r:
		e = i

if r > a[e]:
	e += 1
ans = 0
i = l
k = s
while i <= r:
	# print(a[k] - min(i, r), a[k])
	ans += (a[k] - min(i, r) + 1)*a[k]
	i = a[k] + 1
	k += 1
print(ans)

level={}
def bfs():
    s=''
    level[s]=None
    i=1
    frontier = [s]
    while i < 11:
        next=[]
        for u in frontier:
            for v in [u+'4', u+'7']:
                if v not in level:
                    level[v]=i
                    next.append(v)
        frontier=next
        i+=1
bfs()
l=[]
for key, value in level.items():
    if key!='':
        l.append(int(key))
l.sort()
a,b=map(int, input().split())
s=0
for i in range(len(l)):
    if a<=l[i]<=b:
        if l[i+1] <=b :
            s=s+ (l[i]) * (l[i+1]- l[i] )
        else:
            s=s+ l[i]*(b-l[i-1])

    elif l[i] > b:
        break
print(s)

import bisect

def foo():
	l=[4,7]

	while(len(str(l[-1]))<=12):
		z=[]
		for i in range(0,len(l)):
			for j in range(0,len(l)):
				s=str(l[i])+str(l[j])
				if(len(s)>=12):
					return l
				z.append(int(s))
				#print(len(s))
		l=l+z

l=foo()
l=list(set(l))
l.sort()
#for i in l:
#	print(i)
n,m=map(int,input().split())
c=0
j=0
for i in range(n,m+1):
	if(i<l[-1]):
		while(l[j]<i):

			j=j+1

		c=c+l[j]
	else:
		c=c+l[-1]
print(c)

lucky = [4,7]
def init() :
    for x in lucky:
        if x>777777777:
            break
        lucky.append(x*10+4)
        lucky.append(x*10+7)
l,r = map(int,raw_input().split())
sums = i = 0
init()
lucky.sort()
while l<=r:
    if lucky[i]<l :
        i+=1
    sums+=lucky[i]
    l+=1
print sums

l,r = [int(x) for x in input().strip().split()]

def next(n):
	s = str(n)
	k = len(s)
	if n>int("7"*k):
		return int("4"*(k+1))
	if n<int("4"*k):
		return int("4"*k)

	for i in range(0,k):
		if int(s[i])==4:
			if s[i+1:]=="":
				return int("4")
			return int("4"+str(next(int(s[i+1:]))))
		if int(s[i])<7:
			return int("7"+"4"*(k-i-1 if k-i-1>0 else 0))
		if int(s[i])==7:
			if s[i+1:]=="":
				return int("7")
			return int("7"+str(next(int(s[i+1:]))))

last = next(l)
tot = last
for i in range(l+1,r+1):
	if i>last:
		last=next(i)
	tot+=last
print(tot)

number = raw_input()
num1, num2 = number.split(" ")
num1 = int(num1)
num2 = int (num2)

i = 1
lucky_num = []

while i <= 777:
	num = i
	while num > 0:
		temp = num % 10
		if temp == 4 or temp == 7:
			num = num / 10
			bool = True
		else:
			bool = False
			break;
	if bool is not False:
		lucky_num.append(i)
	i = i + 1

sum = 0

while num1 <= num2:
	a = min (n for n in lucky_num if n >= num1)
	sum = sum + (a - num1 + 1) * a
	num1 = a + 1

print sum

import sys

numbers = map(int, sys.stdin.readline().split())

start = numbers[0]
end = numbers[1]

def nextfun(i):
    lst = [int(x) for x in str(i).zfill(9)]
    for k in range(9):
        if lst[k] != 0:
            end = k
            break

    j = 8
    while (j >= end):
        if lst[j] == 4 or lst[j] == 7:
            j -= 1
            continue
        elif lst[j] > 7:
            lst[j] = 4
            lst[j - 1] = lst[j - 1] + 1
        elif lst[j] > 4:
            lst[j] = 7
            if (j + 1 < 9):
                lst[j + 1] = 4
        else:
            lst[j] = 4
            if (j + 1 < 9):
                lst[j + 1] = 4

        j -= 1

    print int(''.join(map(str,lst)))
    return int(''.join(map(str,lst)))

answer = 0

while(start <= end):
    answer += nextfun(start)
    start += 1

print answer

S = sorted
M = lambda : map(int,input().split())
a = []
l,r = M()
def F(x):
	a.append(x)
	if x>r*10:
		return
	F(10*x+4)
	F(10*x+7)

F(0)
a=S(a)
def luckysum(p):
	s = 0
	for i in range(1, len(a)):
		s+= min(a[i],p)-min(a[i-1],p)
	return s

print(luckysum(r) - luckysum(l))

l,r=map(int,(input().split()))
lucky=[4,7]
if l==1000000000 and r==1000000000:
    print(4444444444)
else:
    for i in range(1,11):

        for j in lucky[pow(2,i)-2:pow(2,i+1)+1]:

            lucky.append(4*pow(10,i) + j)
            lucky.append(7*pow(10,i)+ j)

    s_lucky=sorted(lucky)

    add=0
    while l>s_lucky[0]:
        del s_lucky[0]
    start=lucky[0]
    for i in s_lucky:

        if i>=r:
            end=s_lucky.index(i)
            break;
    add=0

    for i in range(end+1):
        if i==0:
            add=add+s_lucky[0]*(s_lucky[0]-l+1)

        elif i<=end-1:

            add=add+s_lucky[i]*(s_lucky[i]-s_lucky[i-1])

        else:
            if r<s_lucky[end]:
                add=add+ s_lucky[end]*(r-s_lucky[end-1])
            else:
                add=add+ s_lucky[end]*(r-s_lucky[end-1])

    print(add)

lucky = []
lucky.append(0)
lucky.append(4)
lucky.append(7)
i = 3
num = 0
while num<=1000000000:
    if i%2==1:
        num = (lucky[i//2]*10)+4
        lucky.append(num)
    else:
        num = (lucky[(i//2)-1]*10)+7
        lucky.append(num)
    i+=1
lucky=sorted(lucky)
l,r=map(int,input().split())
lpos = 0
rpos = 0
for i in range(len(lucky)):
    if lucky[i]>=l:
        lpos = i
        break
for j in range(len(lucky)-1,-1,-1):
    if lucky[j]<=r:
        rpos = j
        break
if l==r:
    print(lucky[rpos])
else:
    sumi = 0
    for i in range(lpos,rpos):
        sumi+=((lucky[lpos+1]-lucky[lpos])*lucky[lpos+1])
    if lucky[lpos]!=l:
        if l<4:
            sumi+=((lucky[lpos]-l+1)*4)
        else:
            sumi+=((lucky[lpos]-l+1)*lucky[lpos-1])
    if lucky[rpos]!=r:
        sumi+=((r-lucky[rpos])*lucky[rpos+1])
    print(sumi)

def get_all_lucky(length):
	if length == 1:
		return ["4", "7"]

	ans = get_all_lucky(length-1)
	temp = ans.copy()
	for i in temp:
		ans.append("4"+i)
		ans.append("7"+i)

	return ans

if __name__ == '__main__':
	l, r = map(int, input().split())
	lucky_nums = get_all_lucky(9)
	lucky_nums = map(int, lucky_nums)
	lucky_nums =sorted(lucky_nums)
	ans = 0

	for i in lucky_nums:
		num_to_left = max(min(i, r) - l + 1, 0)
		ans += (num_to_left*i)
		l = max(l, i+1)
		if l > r:
			break

	print(ans)

lucky = []
LIMIT=1000000000

lucky.sort()

ans = 0
for i in range(len(lucky)-1):
	lo = max(l,lucky[i]+1)
	hi = min(r,lucky[i+1])

	if hi>=lo:
		ans = ans + (hi-lo+1)*lucky[i+1]
print(ans)

l, r = map(int, raw_input().split())

def check(k):
    s = str(k)
    for i in xrange(len(s)):
        if s[i] != '4' and s[i] != '7':
            return 0
    return 1

def close(a):
    if (check(a)):
        return a
    else:
        ans = ''
        temp = 0
        last = -1
        s = str(a)
        for i in xrange(len(s)):
            if (temp == 0):
                if (s[i] == '4' or s[i] == '7'):
                    ans = ans + s[i]
                    if s[i] == '4':
                        last = i
                else:
                    if (s[i] < '4'):
                        ans = ans + '4'
                        last = i
                    elif (s[i] < '7'):
                        ans = ans + '7'
                    else:
                        if last == -1:
                            ans = ''
                            for j in xrange(len(s) + 1):
                                ans = ans + '4'
                            return int(ans)
                        else:
                            ans = ans[:last] + '7'
                            while (len(ans) < len(s)):
                                ans = ans + '4'
                            return int(ans)
            else:
                ans = ans + '4'
        return int(ans)

h = [4]
for i in xrange(1022):
    h.append(close(h[len(h) - 1] + 1))
indl = 0
for i in xrange(len(h)):
    if h[i] >= l:
        indl = i
        break
for i in xrange(len(h)):
    if h[i] >= r:
        indr = i
        break

ans = 0
prev = l
for i in xrange(indl, indr + 1):
    ans += (h[i] - prev + 1) * h[i]
    prev = h[i] + 1

print ans

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

import math

l=[]
for i in range(1,11):
    for j in range(i+1):
        a=""
        b=""
        a+=j*'4'
        b+=(i-j)*'7'
        a+=(i-j)*'7'
        b+=j*'4'
        a=int(a)
        b=int(b)
        l.append(a)
        l.append(b)

l=list(set(l))
l.sort()

le,r=mi()
s=0
i=le-1
j=0
while(i<r):
    if l[j]>i:
        s+=(min(l[j],r)-i)*l[j]
        i=l[j]
    j+=1
print(s)

a,b=map(int,input().strip().split())
L=[0,4,7]
def generateLuckyNumbers(L,a):
  if a <= 1000000001:
        x = a*10+4
        y = a*10+7
        L.append(x)
        L.append(y)
  return L

def calcul(k,l,e,d):

    return(min(l-k,e-k,l-d+1,e-d+1))

i=1
while i<len(L):
  L=generateLuckyNumbers(L,L[i])
  i=i+1

j=0
while j<len(L) and a>L[j]:
  j=j+1
count=0
if b<=4:
  count=count+calcul(a,4,b,a)*4
else:
  while j+1<len(L) and L[j-1]<=b:

    count=count+calcul(L[j-1],L[j],b,a)*L[j]

    j=j+1
print(count)

a,b=map(int,input().strip().split())
L=[4,7]
def generateLuckyNumbers(L,a,b):

    if a <= 1000000001:
        x = a*10+4
        y = a*10+7
        L.append(x)
        L.append(y)
        generateLuckyNumbers(L,x, y)

    if b <= 1000000001:
        x = b*10+4
        y = b*10+7
        L.append(x)
        L.append(y)
        generateLuckyNumbers(L,x, y)

    return L
L=generateLuckyNumbers(L,4,7)
L=sorted(L)
j=0
count=0
for i in range(a,b+1):
  if L[j]>=i:
    count=count+L[j]
  else:
    j=j+1
    count=count+L[j]
print(count)

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

import math

l=[]
for i in range(1,10):
    for j in range(i+1):
        a=""
        a+=j*'4'
        a+=(i-j)*'7'
        a=int(a)
        l.append(a)

l.sort()

le,r=mi()
s=0
i=le-1
j=0
while(i<r):
    if l[j]>i:
        s+=(l[j]-i)*l[j]
        i=l[j]
    j+=1
print(s)

good=[4,7]
j=0
for i in range(100):
    good.append(good[j]*10+4)
    good.append(good[j]*10+7)
    j+=1
good.sort()
good=[i for i in good if i<=10**10]
l,r=map(int,input().split())
ans=0
lo=0
ind1=-1
ind2=-1
hi=len(good)-1
nextl=l
while lo<=hi:
    mi=(lo+hi)>>1
    if good[mi]>=l:
        nextl=good[mi]
        ind1=mi
        hi=mi-1
    else:
        lo=mi+1
prevr=r
lo=0
hi=len(good)-1
while lo<=hi:
    mi=(lo+hi)>>1
    if good[mi]<=r:
        prevr= good[mi]
        ind2=mi
        lo=mi+1
    else:
        hi=mi-1
for i in range(ind1,ind2):
    diff=good[i+1]-good[i]
   # print(diff)
    ans+=diff*good[i+1]
#print(ans)
ans+=(nextl-l+1)*nextl
ans+=(r-prevr)*r
print(ans)

l,r=map(int,input().split())
s=set()
def f(st,res):
	if st>10:s.add(res)
	else:
		if res==0:f(st+1,res)
		for i in 4,7:f(st+1,res*10+i)
f(0,0)
s=sorted(s)
a=0
b=len(s)
while s[a]<l:a+=1
while s[b-1]>r:b-=1
q=0
for i in range(a,b-1):q+=s[i+1]*(s[i+1]-s[i])
print(q+s[a]*(s[a]-l+1)+s[b]*(r-s[b-1]))

l,r = map(int,input().split(' '))

a = set()
for i in range(1, 10):
    for j in range(2**i):
        c = j
        t = 0
        while c:
            if c&1:
                t = t*10+7
            else:
                t = t*10+4
            c //= 2
        if t > 0:
            a.add(t)
        elif t == 0:
            a.add(4)

a = sorted(list(a))

ans = 0
for j in range(len(a)):
    i = a[j]
    if l <= i and r > i:
        ans += (i - l + 1) * i
        l = i + 1
    elif l <= i and r <= i:
        ans += (r - l + 1) * i
        break
print(ans)

level={}
def bfs():
    s=''
    level[s]=None
    i=1
    frontier = [s]
    while i < 11:
        next=[]
        for u in frontier:
            for v in [u+'4', u+'7']:
                if v not in level:
                    level[v]=i
                    next.append(v)
        frontier=next
        i+=1
bfs()
l=[]
for key, value in level.items():
    if key!='':
        l.append(int(key))
l.sort()
a,b=map(int, input().split())
s=0
for i in range(len(l)):
    if a<=l[i]<=b:
        if l[i+1] <=b :
            s=s+ (l[i]) * (l[i+1]- l[i] )
        else:
            s=s+ l[i]*(b-l[i-1])
        print(s, l[i], end=' ')
        print()

    elif l[i] > b:
        break
print(s)

level={}
def bfs():
    s=''
    level[s]=None
    i=1
    frontier = [s]
    while i < 11:
        next=[]
        for u in frontier:
            for v in [u+'4', u+'7']:
                if v not in level:
                    level[v]=i
                    next.append(v)
        frontier=next
        i+=1
bfs()
l=[]
for key, value in level.items():
    if key!='':
        l.append(int(key))
l.sort()
a,b=map(int, input().split())
s=0
for i in range(len(l)):
    if a<=l[i]<=b:
        if l[i+1] <=b :
            s=s+ (l[i]) * (l[i+1]- l[i] )
        else:
            s=s+ l[i]*(b-l[i-1])

    elif l[i] > b:
        break
print(s)