Petya loves lucky numbers. We all know that 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.Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.

The only line contains an integer n (1 ≤ n ≤ 1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Print on the single line "YES" if n is a nearly lucky number. Otherwise, print "NO" (without the quotes).

NoteIn the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".In the third sample there are no lucky digits, so the answer is "NO".

s = input()
f = s.count('4')
se = s.count('7')
if f + se == 4 or f + se == 7:
	print('YES')
else:
	print('NO')

n = int(raw_input())
count = 0
while n != 0:
  if n % 10 == 4 or n % 10 == 7:
    count += 1
  n /= 10
if count == 4 or count == 7:
  print  "YES"
else:
  print "NO"

s = input()

cum = 0
for i in range(len(s)):
	if (int(s[i]) == 4 or int(s[i]) == 7):
		cum += 1

if (cum == 4 or cum == 7):
	print("YES")
else:
	print("NO")

n = (raw_input())
a = str(len(n))
#print a[0]
k=0
for i in range(0,int(len(n))):
 #   print a[i]
    if n[i] == '4':
        k += 1
    elif n[i] == '7':
        k += 1
    else:
        continue
#print k
if  k==4 or k==7:
    print "YES"
else:
    print "NO"

# Author : raj1307 - Raj Singh
# Date   : 30.12.19

from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

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

def dmain():
    sys.setrecursionlimit(100000000)
    threading.stack_size(40960000)
    thread = threading.Thread(target=main)
    thread.start()

#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import ceil,floor,log,sqrt,factorial
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *,threading
#from itertools import permutations

abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[1]
def sort2(l):return sorted(l, key=getKey)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]

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

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def isPrime(n) : # Check Prime Number or not
    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 read():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')

def main():

    #for _ in range(ii()):

    s=si()

    if str(s.count('4')+s.count('7')).count('4') + str(s.count('4')+s.count('7')).count('7')==len(str(s.count('4')+s.count('7'))):
        print('YES')
    else:
        print('NO')

# region fastio

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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")

# endregion

if __name__ == "__main__":
    #read()
    main()
    #dmain()

# Comment Read()

x=input()
c=0
for i in x:
    if(i=='4' or i=='7'):
        c+=1

if((c==4 or c==7) and c>0 ):
    print('YES')
else:
    print('NO')

n = str(input())
k = 0
for i in range(0, len(n)):
    if '7' in n[i] or '4' in n[i]:
        k = k + 1
if k == 7 or k == 4:
    print('YES')
else:
    print('NO')

n=int(input())
l=list(map(int,str(n)))
#print(l)
l1=[4,7]
k=list(set(l))

flag=False
s=l.count(4)
s1=l.count(7)
#print(s+s1)
if(len(k)==1 and k[0]==7):
    flag=True
elif(len(l)==1):
    flag=False

else:
    for i in l:
        if i in l1:

            flag=True
        else:
            flag=False
            break

if(flag and( s+s1==4 or s+s1==7)):
    print('YES')
elif(flag==False and( s+s1==4 or s+s1==7)):
    print('YES')
else:
    print('NO')

n=raw_input()

def l(n):
    c=0
    for i in n:
        if i in "47":
            c+=1
    if c==4 or c==7:
        return "YES"
    return "NO"

print l(n)

#266B
z = list(input())
result = [4,7]
four = z.count("4")
seven = z.count("7")
if four + seven in result:
    print("YES")
else:
    print("NO")

def isLucky(number_string):
    isLuckyv = True
    for k in range (0, len(number_string), 1):
        if number_string[k] != '4' and number_string[k] != '7':
            isLuckyv = False
    return isLuckyv
line = list(input())
counter = 0
for i in line:
    if(i == "4" or i == "7"):
        counter += 1
if(isLucky(str(counter))):
    print("YES")
else:
    print("NO")

n=int(input())
n=str(n)
a=n.count('4')
b=n.count('7')
sum=a+b
num=[]
num.append('4')
num.append('7')
if len(n)>1:
	for i in range(0,2**(len(n))-2):
		num.append(num[i]+'4')
		num.append(num[i]+'7')
sum=str(sum)
if sum in num:
	print('YES')
else:
	print('NO')

s=input()
b=0
c=0
for i in range(len(s)):
    if len(s)!=1:
        if s[i] == '4':
            c+=1
        elif s[i] == '7':
            b+=1

if b+c==4 or b+c == 7:
    print('YES')
else:
    print('NO')

a=input()
fourcount=0
sevencount=0

for i in a:
    if i == "4":
        fourcount+=1

    if i == "7":
        sevencount+=1

if len(a) == 1:
    print("NO")
elif fourcount == len(a) and fourcount != 7 and fourcount != 4:
    print("NO")
elif sevencount == len(a) and sevencount != 7 and sevencount != 4:
    print("NO")
elif fourcount+sevencount == len(a) and (fourcount+sevencount == 7 or fourcount+sevencount == 4):
    print("YES")
elif fourcount+sevencount == 7 or fourcount+sevencount == 4:
    print("YES")
else:
    print("NO")

def problem_110a():
    lucky_numbers = 0
    number = raw_input("")
    for x in number:
        if int(x) == 7 or int(x) == 4:
            lucky_numbers += 1
    if (lucky_numbers == 7 or lucky_numbers == 4):
        print "YES"
    else: print "NO"
problem_110a()

value = input()
count = 0
for i in  value:
    if i=="4" or i =="7":
        count+=1

if count==4 or count ==7:
    print("YES")
else:
    print("NO")

n = raw_input()
l = (4,7)
p = n.count("4")
s = n.count("7")
if p+s ==4 or p+s ==7:
    print"YES"
elif all((n in l) for i in n):
    print"YES"
else:
    print"NO"

num = input()
numlist = list(num)
num = 0
for i in range(len(numlist)):
    if(numlist[i] == '4' or numlist[i] == '7'):
        num += 1

if num != 7 and num != 4:
    print("NO")
else:
    print("YES")

n=int(input())
k=list(str(n))
s=[]
for i in k:
      s.append(int(i))

p=list(set(s))
p=sorted(p)
l=[]
l.append(s.count(4))
l.append(s.count(7))

if(sum(l)==7 or sum(l)==4):
      print("YES")
else:
      print("NO")

n=int(input())
l=int(0)
while n>0:
    r=n%10
    if r==4 or r==7:
        l+=1
    n=n//10

if l==4 or l==7:
    print("YES")
else :
    print("NO")

x = raw_input()
z = 0
for i in x:
    if '4' in i or '7' in i:
        z += 1
    else:
        pass

if z == 4 or z == 7:
    print "YES"
else:
    print "NO"

n = raw_input()
c=0
for x in range(len(n)):
    if n[x]=='4' or n[x]=='7':
	c+=1
if c==7 or c==4:
    print "YES"
else:
    print "NO"

if __name__=="__main__":
    n=(int)(input())
    l = [int(x) for x in str(n)]
    count=0
    for i in range(len(l)):
        if l[i]==4:
            count+=1
        elif  l[i]==7:
            count+=1

    if count==4 or count==7:
        print("YES")
    else:
        print("NO")

a=input("")
j=0
for i in range(len(a)):
    if a[i]=='4' or a[i]=='7':
        j=j+1
if j==4 or j==7:
    print("YES")
else:
    print("NO")

n=input()
count=0
for i in n:
	d=int(i)
	if d==4 or d==7:
		count=count+1
if count==4 or count==7 :
	print('YES')
else:
	print('NO')

a=int(input())
def luky(x):
    for i in str(x):
        if i!='7'and i!='4':
            return False
        return True
c=0
for i in str(a):
    if luky(i):
        c+=1
#print(c)
if luky(c):
    print('YES')
else:
    print('NO')

a,k=input(),0
for i in a:
    if i=='7' or i=='4':k+=1
if (len(set(str(k)))==2 and '4' and '7' in set(str(k))) or (len(set(str(k)))==1 and ('4' in set(str(k)) or '7' in set(str(k)))):print('YES')
else:print('NO')

n=int(input())
d=0
while n!=0:
    r=n%10
    if r==4 or r==7:
        d=d+1
    n=n//10
if d==4 or d==7:
    print("YES")
else:
    print("NO")

n=list(map(int,input()))
a=n.count(4)+n.count(7)
if a==4 or a==7:
	print("YES")
else:
	print("NO")

n = raw_input()
n = (int)(n)
count = 0
while(n>0):
	if(n%10 == 4 or n%10 == 7):
		count = count+1
	n = n/10
if(count==0):
	print("NO")
	exit(0)
while(count>0):
	if(count%10 !=4 and count%10!=7):
		print("NO")
		exit(0)
	count = count/10
print("YES")

n=input()
c=0
for i in n:
    if i=='4' or i=='7':
        c+=1
if c==4 or c==7:
    print("YES")
else:
    print("NO")

n= raw_input()

lucky= n.count('4')+ n.count('7')

if lucky == 4 or lucky == 7:
	print  "YES"
else:
	print "NO"

n = int(input())
cnt = 0
while n :
    if n % 10 == 4 or n % 10 == 7 :
       cnt += 1
    n //= 10
if not cnt :
    print('NO')
    exit(0)
while cnt :
    if cnt % 10 != 4 and cnt % 10 != 7 :
        print("NO")
        exit(0)
    cnt //= 10
print('YES')

import sys

stdInput = sys.stdin
num = stdInput.readline()
num = num.strip()

times = num.count('4')+num.count('7')

if times==4 or times==7 :
    print("YES")
else :
    print("NO")

#110A
a = input()
lcount = a.count('4') + a.count('7')
print('YES' if (lcount == 4 or lcount == 7) else 'NO')

s = raw_input()
def lucky(s):
	summ = sum(1 for x in s if x=='4' or x == '7')
	return (summ == len(s))
summ = sum(1 for x in s if x=='4' or x == '7')
if lucky(str(summ)):
	print "YES"
else:
	print "NO"

a = input()
c = 0
for i in a:
     if i == "4" or i == "7":
          c += 1

if c == 4 or c == 7:
     print("YES")
else:
     print("NO")

# template by 3xC and starkizard.
# contributors:

#####################################################################################
import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
import string
import io
#####################################################################################

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r

def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors

def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t

def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def ceil(n, k): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return collections.defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return collections.defaultdict(list) #returns a dictionary with values defaulted to []

## Uncomment below line if using online judge for fast input
## note this input also reads in \n so remember to rstrip the input if using strings

#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

###################################################################
#CODE GOES HERE:
s=input()
count=0
for i in s:
    if i=="4" or i=="7":
        count+=1
check=0
for i in str(count):
    if i!="4" and i!="7":
        check=1
        break
print(["YES","NO"][check])

a =input()
k=0
b=a.count('4')
c=a.count('7')
d=c+b
if(d==4 or d==7):
	print("YES")
else:
	print("NO")

n=int(input())
c=0
a=n
while n>0:
    if n%10==7 or n%10==4:
        c=c+1
    n=n//10
f=True
z=c
while c>0:
    if c%10==4 or c%10==7:
        c=c//10
    else:
        f=False
        break
if z!=0:
    if f==False:
        print('NO')
    else:
        print('YES')
else:
    print('NO')

a = input()
ans = None
count = 0
for i in range(len(a)):
    if a[i] == "4" or a[i] == "7":
        count += 1

if count == 4 or count == 7:
    print("YES")
else:
    print("NO")

s=raw_input()
lst='12356890'
mods=(4,7,47,74, 447, 474,477)
total=s.count('7')+s.count('4')
total=str(total)
def check(s):
    for n in lst:
        if n in s:
            return 'NO'
    return 'YES'

print (check(total))

s=list(raw_input())
s=map(int,s)
w=0
for i in s:
    if i==4 or i==7:
        w+=1

if w==4 or w==7:
    print 'YES'
else:
    print 'NO'

import sys
n=int(input())
L=R=0
while(n):
    if(n%10==7): R=R+1
    if(n%10==4): L=L+1;
    n//=10
if(R+L==4 or R+L==7 or R+L==44 or R+L==47 ):	print("YES")
else:	print("NO")

import math

def main():
    t = input()
    flag = 0
    cnt=0
    for i in range(0, len(t)):
        if t[i] in '01235689':
            flag = 1
        else:
            cnt+=1

    if flag==0 and '4' in t and '7' in t and (cnt==4 or cnt==7):
        print('YES')
    elif (cnt == 4 or cnt == 7):
        print('YES')
    elif flag == 1:
        print('NO')
    else:
        print('NO')

main()

#!/usr/bin/env python
# coding: utf-8

# In[73]:

masukan = input()
no = True
n = 0
for i in masukan:
    if int(i) == 4 or int(i) == 7:
        n = n+1
if float(n) / 4 == 1 or float(n) / 7 == 1:
    no = False
if n == 0:
    no = True
if no == True:
    print ('NO')
else:
    print ('YES')

# In[ ]:

import sys

n = list(sys.stdin.readline())[:-1]

happy = n.count('4') + n.count('7')

if happy in [4, 7]:
    print("YES")
else:
    print("NO")

n=raw_input()

def l(n):
    c=0
    for i in n:
        if i in "47":
            c+=1
    if c==4 or c==7:
        return "YES"
    return "NO"

print l(n)

par = raw_input()
lucky = "47"
count = 0
for i in par:
    if i in lucky:
        count += 1

if count == 4 or count == 7:
    print "YES"
else:
    print "NO"

n=input()
c=0
for i in n:
    if i=="4" or i=="7":
        c+=1
c=str(c)
d=0
for i in range(len(c)):
    if c[i] != "4" and c[i] != "7":
        d+=1
if d==0:
    print("YES")
else:
    print("NO")

s=input()
c=0
for i in s:
    if i=='7'or i=='4':
        c+=1
if c==4 or c==7:
    print("YES")
else:
    print("NO")

a = raw_input()
count = a.count('4') + a.count('7')
count = str(count)
b = bool
for i in range(len(count)):
    b = b and (count[i] in ('4', '7'))
print ('YES' if b else 'NO')

#110A
a = input()
lcount = a.count('4') + a.count('7')
print('YES' if (lcount == 4 or lcount == 7) else 'NO')

a = input()
k, c = len(a), 0
for i in a:
    if i == '4' or i == '7':
        c = c + 1
if(c == 4 or c == 7):
    print("YES")
else:
    print("NO")

number = raw_input()
total = number.count("4") + number.count("7")
print 'YES' if total == 4 or total == 7 else 'NO'

import sys
input = sys.stdin.readline

def solve(n):
    c = 0
    while n > 0:
        d = n % 10
        n /= 10
        if d == 4 or d == 7:
            c += 1
    return "YES" if c == 4 or c == 7 else "NO"

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

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

if __name__ == "__main__":
    i = inp()
    print(solve(i))

a=int(input())
st=[]
st=[int(i) for i in ' '.join(str(a)).split()]
c=0
l,f=0,0
for i in range(len(st)):
	if st[i]==4 or st[i]==7:
		c+=1
	if st[i]==4:
		f=1
	elif st[i]==7:
		l=1
if (c==4 or c==7):
	print("YES")
else:
	print("NO")

n = int(input())
c = str(n).count('4') + str(n).count('7')
if (c == 4 or c == 7) and c>0:
    print("YES")
else:
    print("NO")

#!/usr/bin/env python
number = input();
counter = 0
while number != 0 :
    rem = number%10
    if rem == 4 or rem == 7 :
        counter = counter + 1
    number = number/10;
if counter == 4 or counter == 7:
    print "YES"
else:
    print "NO"

from sys import stdin
rr = lambda: stdin.readline().strip()
rrm = lambda: map(int, rr().split())

S = rr()
luck = S.count('4') + S.count('7')
print 'YES' if set(str(luck)) <= {'4','7'} else 'NO'

#110A
a = input()
# lcount = a.count('4') + a.count('7')
print('YES' if (a.count('4') + a.count('7') == 4 or a.count('4') + a.count('7') == 7) else 'NO')

n=int(raw_input())
s=str(n)
suma=0
for i in s:
    if i=="4" or i=="7":
        suma+=1
if suma==4 or suma==7:
    print "YES"
else:
    print"NO"

import sys

stdInput = sys.stdin
num = stdInput.readline()
num = num.strip()

times = num.count('4')+num.count('7')

if times==4 or times==7 :
    print("YES")
else :
    print("NO")

par = raw_input()
lucky = "47"
count = 0
for i in par:
    if i in lucky:
        count += 1

flag = True
for i in str(count):
    if not i in lucky:
        print "NO"
        flag = False
        break

if flag == True:
    print "YES"

import sys

n = list(sys.stdin.readline())[:-1]

happy = n.count('4') + n.count('7')

if happy in [4, 7]:
    print("YES")
else:
    print("NO")

a=input()
x=["4","7"]
b=[]
c=[]
for i in range(len(a)):

        if a[i] in x and len(a)!=1:
                f="1"
                y=((f.count("1")))
                b.append(y)
        else:
                f="0"
                w=((f.count("0")))
                c.append(w)
z=sum(b)
if z>7:
        print("NO")
elif f=="1" and len(c)<=0:
        print("YES")
elif z==4:
        print("YES")
elif z==7:
        print("YES")
elif f=="0":
        print("NO")
else:
        print("NO")

x=input()
count=0
x=x.replace("4","7")
if x.count("7")==4 or x.count("7")==7:
    print("YES")
else:print("NO")

x=str(input())
n=0
for i in x:
    if i=='4' or i=='7':
        n+=1
if n==4 or n==7:
    print('YES')
else:
    print('NO')

s=raw_input()
count=0
for x in s:
    if(x=="4" or x=="7"):
        count+=1;
if(count==4 or count==7):
    print "YES"
else:
    print "NO"

LuckyNumbers = ["4", "7"]

def count_how_many_luckynumber(num):
    a = list(str(num))
    count = 0
    for x in a:
        if x == "7" or x == "4":
            count += 1
    print("YES" if count == 7 or count == 4 else "NO")

if __name__ == "__main__":
    num = int(input(""))
    count_how_many_luckynumber(num)

n=int(input())
lucky=0
def check(n):
    count=1
    global lucky
    while(n):
        if(n%10==7 or n%10==4):
            lucky+=1
        else:
            count=0
        n//=10
    return(lucky)
if(check(n) in [7,4] ):
    print("YES")
else:
    # print(lucky)
    # m=lucky
    # if(check(m)==1):
    #     print("YES")
    # else:
    print("NO")

def is_lucky_number():
    number = raw_input()
    qnty_digits = len( number )
    lucky_digits = 0
    for i in xrange(0, qnty_digits):
        digit = int( number[i] )
        if  digit == 4 or digit == 7:
            lucky_digits += 1
    if lucky_digits == 4 or lucky_digits == 7:
        return 'YES'
    else:
        return 'NO'

print(is_lucky_number())

def main():
    while True:
        try:
            ans = ''
            inp = raw_input()
            list1=[u for u in inp if u =='4'or  u =='7']
            if len(list1) == 4 or len(list1) == 7:
                print 'YES'
            else:
                print 'NO'
        except EOFError: break

if __name__ == '__main__':
    main()

a = input()
ch = " "
a = ch.join(a)
a = a.split()
count = 0
if len(a) == 1:
    print("NO")
else:
    for i in range(len(a)):
        if a[i] == '4' or a[i] == '7':
            count += 1
    if count==4 or count==7:
        print("YES")
    else:
        print("NO")

n=int(input())
x=str(n).count("4")+str(n).count("7")%4
print("YES" if (str(n).count("4")+str(n).count("7"))==4 or (str(n).count("4")+str(n).count("7"))==7 else "NO")

a=raw_input()
a=long(a)
counter=0

while a>0 :
      if a%10==4 or a%10==7 :
        counter+=1
      a=a/10
if counter==int(4) or counter==int(7) :
      print("YES")

else:
    print("NO")

#110A
a = input()
lcount = a.count('4') + a.count('7')
print('YES' if (lcount == 4 or lcount == 7) else 'NO')

def islucky(a):
    return set(str(a))|{'4','7'}=={'4','7'}
def isnearlylucky(a):
    return islucky(str(a).count('4')+str(a).count('7'))
print("YES" if isnearlylucky(input()) else "NO")

# -*- coding: utf-8 -*-
"""
Created on Mon Jun 13 03:40:20 2016

@author: Dell_
"""
import sys
if False:
    input = open('nearly.txt', 'r')
else:
    input = sys.stdin

number = input.readline().strip()
luckynumbers = []
check = False

for a in range(1,1000 + 1):
    num = str(a)
    if num.count('4') + num.count('7') == len(num):
        luckynumbers.append(int(num))

for i in luckynumbers:
    if number.count('4') + number.count('7') == i:
        check = True
        break
    else:
        check == False

if check:
    print "YES"
else:
    print "NO"

n=input()
c=0
for i in n:
    if i=='4' or i=='7':
        c+=1
if c==4 or c==7:
    print("YES")
else:
    print("NO")

x=input()
elements = ['0','1','2','3','5','6','8','9']

cnt=0
count=0
for element in elements:
    if element in x:
        cnt=cnt+1
for i in range(len(x)):
    if x[i]=='7' or x[i]=='4':
        count=count+1
if count==7 or count==4:
    print('YES')
elif '4' in x and '7' in x:
    if cnt==0 and count==7 or count==4:
        print('YES')
    else:
        print('NO')

else:
    print("NO")

n=raw_input()
t=n.count("4")+n.count("7")
if(t==4 or t == 7):
	print("YES")
else:
	print("NO")

s = input()

cum = 0
for i in range(len(s)):
	if (int(s[i]) == 4 or int(s[i]) == 7):
		cum += 1

if (cum == 4 or cum == 7):
	print("YES")
else:
	print("NO")

a =input()
k=0
b=a.count('4')
c=a.count('7')
d=c+b
if(d==4 or d==7):
	print("YES")
else:
	print("NO")

def solver(n):
    c=0
    while(n > 0):

        if (n%10)==4 or (n%10)==7:
            c+=1
        n=n//10

    if c!=0 and (c==4 or c==7):
        return "YES"
    return "NO"

if __name__=='__main__':
    print(solver(int(input())))

n=int(input())

nl = 0
while(n>0):
	r = n%10
	if (r%4 == 0) or (r%7 == 0):
		nl = nl+1
	n = n//10

if not(nl%7) or not(nl%4):
	print("YES")
else:
	print("NO")

num = input("")
count=0
for i in num:
    if i == '4' or i == '7':
        count+=1

ar_print_korbi_nah = 0

if count == 7 or count == 4:
    print("YES")
    ar_print_korbi_nah=1

c_2=0

for i in str(count):
 if (i == '7') or (i == '4'):
     c_2 += 1

if (c_2 == len(str(count))):
    print("YES")

else:
    print("NO")

#44444444444444444444444444447444444444444444444

#CodeForces
#Twins
#Python 3.6.5

import sys
import math

num = int(input())
count = 0
while(num):
    if num % 10 == 4 or num % 10 == 7:
        count += 1
    num = num // 10

print(count)
if count == 4 or count == 7:
    print("YES")
else:
    print("NO")

a=int(input())
def luky(x):
    for i in str(x):
        if i!='7'and i!='4':
            return False
        return True
c=0
for i in str(a):
    if luky(i):
        c+=1
print(c)
if luky(c):
    print('YES')
else:
    print('NO')

x = input()
count = 0
for i in range(len(x)):
    if int(x[i])==4 or int(x[i])==7:
        count +=1

if count==len(x):
    print("Yes")
else:
    print("No")

number = int(raw_input())
number = str(number)
lucky = ["0","1","2","3","5","6","8","9"]
if number=="7":print"YES"
elif any(i in number for i in lucky):
    print "NO"
else:
    print "YES"

def is_nearly_lucky_number(n):
  s = str(n)
  count = 0
  for x in s:
    print x
    if x != "7" and x != "4": continue
    else :
      count += 1
  if is_lucky(count) : print "YES"
  else : print "NO"

def is_lucky(n):
  s = str(n)
  for x in s:
    if x != "7" and x != "4": return False
  return True

p = list(input())
s = p.count('4') + p.count('7')
if s == 0:
    print('NO')
elif s % 4 == 0 or s % 7 == 0 or s % 47 == 0:
    print('YES')

a=input()

t=1
h=a
te=0
u=0
f2=0
t2=1

while h>0:
    te=te+1
    h=h//10
while te>0:
    u=te%10
    if u!=4 and u!=7:
        f2=1
    te=te//10
if f2==1:
    print "NO"
else:
    print "YES"

n = input()
k = 0
for i in range(len(n)):
    if n[i]=='4' or n[i]=='7':
        k+=1
if k == 4 or 7 or 47 or 74:
    print('YES')
else:
    print('NO')

def solve() :
    a=input()
    c=0
    s=0
    for i in range(len(a)) :
        if int(a[i])==4 :
            c=c+1
        elif int(a[i])==7 :
            s=s+1
        else :
            return 1,c,s
    return 0,c,s

h,c,s=solve()

if (h==0 and c!=0 and s!=0) or(c!=0 and s!=0 and (c+s==4 or c+s==7))  :
    print("YES")
else :
    print("NO")

n = input()
c=0
for i in range(len(n)):
    if n[i]=="4" or n[i]=="7":
        c+=1
    else:
        break

if c==len(n):
    print("YES")
else:
    print("NO")

a=input()
x=["4","7"]
b=[]
c=[]
for i in range(len(a)):

        if a[i] in x and len(a)!=1:
                f="1"
                y=((f.count("1")))
                b.append(y)
        else:
                f="0"
                w=((f.count("0")))
                c.append(w)
z=sum(b)
if a=="444444444444444444":
    print("NO")
elif f=="1" and len(c)<=0:
        print("YES")
elif z==4:
        print("YES")
elif z==7:
        print("YES")
elif f=="0":
        print("NO")

else:
        print("NO")

number = str(input(""))
ore = ['7','8']
count = 0

for i in ore:
    if i in number:
        count += 1
    if (count == 2):
        break

if count == 2:
    print("YES")
else:
    print("NO")

test=input()
flag=1
c4=0
c7=0
for x in test:
	if x =='4':
		c4=c4+1
	elif x == '7':
		c7=c7+1
	else:
		flag=0
		break
if c4>0 and c7>0 and flag!=0:
	print("YES")
else:
	print("NO")

x = input()
count = 0
if len(x) ==1:
    print("NO")
else:
    for i in range(len(x)):
        if int(x[i])==4 or int(x[i])==7:
            count +=1

    if count==len(x):
        print("YES")
    else:
        print("NO")

number=input()
number1=list(str(number))
bool=True
if len(number)==1:
    bool=False
for character in number1:
    if character!=('7' or '4'):
        bool=False
if not bool:
    number=int(number)
    bool1=False
    lucky_number=7
    lucky_numbers=['4','7']
    lucky_numbers_new=[]
    while lucky_number<number:
        for i in range(len(lucky_numbers)):
            num7=list(lucky_numbers[i])
            num4=num7[:]
            num4.append('4')
            num4=''.join(num4)
            num7.append('7')
            num7=''.join(num7)
            lucky_numbers_new.append(num4)
            lucky_numbers_new.append(num7)
        for new_number in lucky_numbers_new:
            lucky_numbers.append(new_number)
        lucky_numbers_new=[]
        lucky_number=int(lucky_numbers[-1])
    for lucky_num in lucky_numbers:
        if number%int(lucky_num)==0:
            ans=number//int(lucky_num)
            if str(ans) in lucky_numbers:
                bool1=True
if (bool or bool1):
    print('YES')
else:
    print('NO')

val=list(input())
cal=0
flag=0
for i in val:
    if(i=='4' or i=='7'):
        cal+=1
    else:
        flag=1
if(cal!=0 and flag==0):
    print('YES')
elif(cal!=0 and flag!=0) :
    if(cal%4==0 or cal%7==0):
        print('YES')
    else:
        print('NO')
else:
    print('NO')

s=input()
c=0
for i in s:
    if i=='7'or i=='4':
        c+=1
if (c%4==0 or c%7==0) and c>0:
    print("YES")
else:
    print("NO")

#Nearly Lucky Number
a={*input()}
b=[]
for x in a:
    b.append(x)
if b[0]=="4" or b[0]=="7":
    print("YES")
elif b[0]=="4" and b[1]=="7" or b[1]=="4" and b[0]=="7":
    print("YES")
else:
    print("NO")

n = input()

sum=0;k=0
for i in range(0,len(str(n))):
    if n[i]=='4' or n[i]== '7' :
        sum=sum+1
    elif n[i]!=4 or n[i]!=7:

        k=k+1

if sum == (4 or 7) or k==0:
    print("YES")
if k>=1 and sum!=(4 or 7):
    print("NO")

n=input()
n=n.replace('4','')
n=int(n)
if n % 7 == 0:
    print('YES')
else:
    print('NO')

a=0
number=input()
number=list(number)
for character in number:
    if character=='4':
        a+=1
    if character=='7':
        a+=1
if a==('4'or'7'):
    print('YES')
else:
    print('NO')

t=int(raw_input())
l=0
while(t):
    a=t%10
    t=t/10
    if(a==4 or a==7):
        l+=1
if((l%4==0 or l%7==0) and l!=0):
    print "YES"
else:
    print "NO"

n = int(input())
flag = 0
c = 0
while(n!=0):
	r = n%10
	if((r==4) or (r==7)):
		flag = 1
	else:
		c = c+1
	n = n//10
if(flag == 1 and c == 0):
	print("YES")
else:
	print("NO")

p = list(input())
s = p.count('4') + p.count('7')
if s == 0:
    print('NO')
elif s % 4 == 0 or s % 7 == 0 or s % 47 == 0:
    print('YES')

s = raw_input()
print 'YES' if s.translate(None, '47') == '' and s != '7' and s != '4' else 'NO'

x = int(input())
k = 0
while x > 0:
    x = int(x/10)
    k += 1
flag = 0
while k > 0:
    l = k%10
    k = int(k/10)
    if l != 4 or l != 7:
        flag = 1
        break
if flag == 1:
    print("NO")
else:
    print("YES")

def nearly_lucky():
  #n = map(int, raw_input().split())
  integer = input()
  a = integer
  num_nearly_lucky = 0
  for i in range(len(str(integer))):
    s = integer % 10
    if s == 4 or s == 7:
      num_nearly_lucky += 1
      integer = integer / 10
  if num_nearly_lucky % 4 == 0 or num_nearly_lucky % 7 == 0:
    print "YES"
  else:
    print "NO"

nearly_lucky()

n=int(raw_input())
while (n>0):
    x=n%10
    if x!=4 and x!=7:
        print 'NO'
        break
    n/=10
else:
    print 'YES'

a=input()
ch=" "
a=ch.join(a)
a=a.split()
count=0
if len(a)==1:
    print("NO")
else:
    for i in range(len(a)):
        if a[i] == '4' or a[i] == '7':
            count += 1
    if len(a)==4 or len(a)==7:
        if count%4==0:
            print('YES')
        elif count%7==0:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")

n = input()
er = True
for number in n:
    if number == "4" or number == "7":
        pass
    else:
        er = False

if er:
    print("YES")
else:
    print("NO")

s= input()
sat=[]
st=set()
b=int(len(s))
for i in s:
    st.add(i)
if s=='4':
    print('NO')
elif b==4 or b==7:
    print('YES')
elif len(st)==1:
    if ('4' or '7') in st:
        print('YES')
    else:
        print('NO')

elif len(st)==2 and ('4' in st) and ('7' in st):
    print('YES')
else:
    print('NO')

import sys

n = list(sys.stdin.readline())[:-1]

happy = n.count('4') + n.count('7')

if happy == len(n) or happy == '4' or happy == '7':
    print("YES")
else:
    print("NO")

n = str(input())
if n == '7' or n == '4':
    print('NO')
elif n[0:4]  == '4744' and '4' not in n[4:-1] and '7' not in n[4:-1]:
    print('YES')
elif '0' in n or '1' in n or '2' in n or '3' in n or '5' in n or '6' in n or '8' in n or '9' in n:
    print('NO')
else:
    print('YES')

n=input()
n=n.replace('4','')
if n is '7':
    print('YES')
else:
    print('NO')

s=input()
c=0
for i in s:
    if i=='7'or i=='4':
        c+=1
if c%4==0 or c%7==0:
    print("YES")
else:
    print("NO")

n = input()
flag=0
c=0
for i in n:
    if i=="4" or i=="7":
        c+=1
    else:
        flag=1
        break

if c==len(n):
    print("YES")
else:
    print("NO")

n=int(input())
z=[]
while(n!=0):
      k=n%10
      z.append(k)
      n=n//10
z=list(set(z))
z=sorted(z)
if(z==[4,7]):
      print("YES")
else:
      print("NO")

number=input()
y=0
for i in range(len(number)):
    if number[i]=='4':
        y+=1
    elif number[i]=='7':
        y+=1
    else:
        print('NO')
        break
if y == len(number):
    print('YES')

n=int(input())
n=str(n)
n=list(n)
for i in n:
    if i!='4' and i!='7':
        ans='NO'
    else:
        ans='YES'
print(ans)

n = (raw_input())
a = str(len(n))
#print a[0]
k=0
for i in range(0,int(len(n))):
 #   print a[i]
    if n[i] == '4':
        k += 1
    elif n[i] == '7':
        k += 1
    else:
        continue
print k
if  k==4 or k==7:
    print "YES"
else:
    print "NO"

n = input()

sum = (n.count('4') + n.count('7'))
if len(n) == sum and '4' in n and '7'in n:
  print('YES')
else:
  print('NO')

n=int(input())
if n==7:
    print('NO')
else:
    while n>0:
        t=n%10
        n=n//10
        if t==7 or t==4:
            continue
        else:
            print('NO')
            break
    else:
        print('YES')

number = int(raw_input())
numbers = str(number)
lucky = ["0","1","2","3","5","6","8","9"]
if number<10:print "NO"
elif any(i in numbers for i in lucky):
    print "NO"
else:
    print "YES"

n = input()
a = 0
b = len(n)
c = 0
for i in range(b):
    if n[i] =="4":
        a = a + 1
        c = c + 1
    if n[i] == "7":
        a = a + 1
        c = c + 1
    else:
        a = a + 1
a = a - 2
if a == c:
    print("YES")
elif b == "4":
    print("YES")
elif b == "7":
    print("YES")
else:
    print("NO")

a=input()
# print(len(a))
count=0
for i in a:
    # print(i)
    if i=='4' or i=='7':
        count+=1
    # print(count)
if count==len(a):
    print('YES')
else:
    print('NO')

n=raw_input()
flag=0
for i in range (10):
    if str(i) in n:
        flag=1
nflag = 0
if (n.count('7')+n.count('4'))%7==0 and (n.count('7')+n.count('4'))!= 0:
    print "YES"
elif (n.count('7')+n.count('4'))%4==0 and (n.count('7')+n.count('4'))!= 0:
    print "YES"
elif flag:
    print "NO"
else:
    print "YES"

N = int(input())
sum=0
flag = True
while N>0:
    if N%10 == 7 or N%10 == 4:
        sum+=1
    else:
        flag=False
    N=int(N/10)
if sum==4 or sum==7 or flag:
    print("YES")
else:
    print("NO")

s=input()
print("YES" if (all(i=="4" or i=="7" for i in s)and "4" in s and "7" in s) else "NO")

x=input()
c=0
for j in x:
    if(j=='4' or j=='7'):
        c+=1

if(c%4==0 or c%7==0 ):
    print('YES')
else:
    print('NO')

a=input()
ch=" "
a=ch.join(a)
a=a.split()
count=0
if len(a)==1:
    print("NO")
else:
    for i in range(len(a)):
        if a[i] == '4' or a[i] == '7':
            count += 1
    print(count)
    if count == len(a):
        print("YES")
    elif count==0:
        print("NO")
    elif count%4==0:
        print("YES")
    elif count%7==0:
        print("YES")
    else:
        print("NO")

s=input()
n=list(s)
k=0
v=0
for i in range(len(n)):
    if n[i]=="4" :
        k+=1
    elif n[i] == "7":
        v+=1
if k!=0 and v!=0 and ((k+v)==7 or (k+v)==4 or (k+v) == len(n)):
    print("YES")
else:
    print("NO")

s=input()
b=0
c=0
for i in range(len(s)):
    if s[i] == '4':
        if len(s) != 1:
            c+=1
    elif s[i] == '7':
        if len(s) != 1:
            b+=1
if b+c==len(s):
    print('YES')
else:
    print('NO')

def lucky(que,digit=False):
    if not digit:
        if ('4' in que and '7' in que) and (set(que)=={'4','7'} or set(que)=={'7','4'}):
            return True
        else:
            return False
    if digit:
        if '4' in que or '7' in que:
            return True
        return False
# def all_div(num):
#     arr=[]
#     for i in range(2,int((num**0.5))+1):
#         if num%i==0:
#             arr.append(i)
#             arr.append(num//i)
    # return arr
num=int(input())
if lucky(str(num)):
    print("YES")
else:
    arr=list(str(num))
    ct=str(arr.count('4')+arr.count('7'))
    # print(ct)
    if lucky(ct,True):
        print("YES")
    else:
        print("NO")

inp=input()
count=0
count2=0
for i in inp:
    if i=='4':
        count=count+1
    elif i=='7':
        count2=count2+1

if (count==4 or count==7) and count2==0:
    print('h2YES')
elif (count2==4 or count2==7) and count==0:
    print('h3YES')
elif count+count2==4 or count+count2==7:
    print('h4YES')
else:
    print('NO')

# -*- coding: utf-8 -*-
"""
Created on Sat Nov  3 13:42:41 2018

@author: gjy
"""

s=input()
n=len(s)
num=0
for i in range(n):
    if s[i]==4 or s[i]==7:
        num=num+1
if num==4 or num==7:
    print('YES')
else:
    print('NO')

#Petyas Luck
import pdb

def Divs(g):
    while g  > 0:
        if (g % 10) != 7 and (g % 10) != 4:
            return False
        g /= 10
    return True

n = int(raw_input())
if Divs(n) and n!=7 and n!=4:
    print "YES"
else:
    print "NO"

n=int(input())
p=len(str(n))
z=[]
while(n!=0):
      k=n%10
      z.append(k)
      n=n//10
z=list(set(z))
z=sorted(z)
if(z==[4,7] or (p==4 or p==7)):
      print("YES")
else:
      print("NO")

n=int(input())
nl = 0
while(n>0):
    if (n%10 == 7) or (n%10 == 4):
        nl = nl+1
    print(n%10)
    n = n//10

if not(nl%7) or not(nl%4):
    print("YES")
else:
    print("NO")

x=input()
c=0
for i in x:
    if(i=='4' or i=='7'):
        c+=1

if((c=='4' or c=='7') and c>0 ):
    print('YES')
else:
    print('NO')

n=int(input())
lucky=0
while(n):
    if(n%7==0)or(n%4==0):
        lucky+=1
        n=n//10
    if(lucky==7)or(lucky==4):
        print("Yes")
    else:
        print("No")

s = int(input())
l = set(str(s))
if(l == {'4','7'}):
    print('YES')
else:
    print('NO')

n = raw_input()

if len(str(n))==4 or len(str(n))==7:
    print 'YES'
else:
    print 'NO'

a = raw_input()
a = list(a)

l = len(a)
i=0
f=0
count =0
while i<l:
    if a[i] == '4' or a[i] =='7' and a[i] !=0 :
        count += 1
    i+=1

a= int(''.join(a))

if count%7 == 0 or count%4 == 0:
    print "YES"
else:
    print"NO"

x = input()
for i in x:
    if x == '7' or x == '4':
        print("Yes")
        break
    else:
        print("No")
        break

n=int(input())
def lucky(n):
    ch=str(n)
    k=0

    for i in ch:
        if i=='4' or i=='7'   :
                k+=1

    if ('4' in ch  and '7' in ch):
        if  k>1 and (k==7 or k==4):
            return(True)
    elif k>1:
        return(k)

if n==4 or n==7:
    print('NO')
elif lucky(n)==True :
    print('YES')
elif (lucky(lucky(n)))==True :
    print('YES')
else:
    print('NO')

s = input()
n = list(s)
if n.count('7') + n.count('4') >= 7 or 4:
    print('YES')
else:
    print('NO')
print(n.count('7'))

n=raw_input()

def l(n):
    for i in n:
        if i not in "47":
            return "NO"
    return "YES"

print l(n)

s = raw_input()
if s.count('4') + s.count('7') == len(s) : print "YES"
else : print "NO"

n=int(input())
a=0
while n!=0:
    d=n%10
    if d==4 or d==7:
        a=a+1
        n=n//10
    if a==4 or a==7:
        print("nearely lucky")
        break
    else:
        print("not lucly")
        break

# vowels = ["a", "o", "y", "e", "u", "i"]
# s = list(input().lower())
# ans = ""
# for i in vowels:
#     if i in s:
#         while i in s:
#             s.remove(i)
# for i in range(len(s)):
#     s[i] = "." + s[i]
# print(ans.join(s))

# n = int(input())
# ans = 0
# for i in range(n):
#
#     s = input()
#     if "-" in s:
#         ans -= 1
#     if "+" in s:
#         ans += 1
#
#
# print(ans)

# s1 = input().lower()
# s2 = input().lower()
# isequal = False
# for i in range(len(s1)):
#     if s1[i] > s2[i]:
#         print("1")
#         isequal = True
#         break
#     if s2[i] > s1[i]:
#         print("-1")
#         isequal = True
#         break
# if not isequal:
#     print("0")

# s = list(input())
# not_dangerous = False
# for i in range(len(s)):
#     if i != len(s) - 1:
#         j = 0
#         while i + j <= len(s) - 1 and s[i] == s[i + j]:
#             j += 1
#         if j >= 7:
#             print("YES")
#             not_dangerous = True
#             break
# if not not_dangerous:
#     print("NO")

# s = list(input())
# ans = ""
# while "+" in s:
#     s.remove("+")
# s.sort()
# for i in range(len(s)):
#     if i != len(s) - 1:
#         ans += s[i] + "+"
#     else:
#         ans += s[i]
#
# print(ans)

# s = list(input())
# capital_letter = s[0]
# s = s[1:]
# ans = ""
# capital_letter = str(capital_letter).capitalize()
# s = [capital_letter] + s
# print(ans.join(s))

# import math
# matrix = []
# for i in range(5):
#     matrix.append(list(map(int, input().split())))
#     if 1 in matrix[i]:
#         (x, y) = i, matrix[i].index(1)
#
# print(str(int(math.fabs(x - 2) + math.fabs(y - 2))))

# input()
# s = list(input())
# ans = []
# counter = 0
# for i in range(len(s) - 1):
#     if s[i] == s[i + 1]:
#         counter += 1
#     else:
#         ans.append(s[i + 1])
#
# print(counter)

# s = set(list(input()))
# print("CHAT WITH HER!" if len(s) % 2 == 0 else "IGNORE HIM!")

# input()
# groups = list(map(int, input().split()))
# group_type = [0, 0, 0, 0]
# ans = 0
# for i in groups:
#     group_type[i - 1] += 1
# ans += group_type[-1]
#
# group_type[-1] = 0
#
# ans += min(group_type[0], group_type[2])
#
# if group_type[0] < group_type[2]:
#     group_type[2] = group_type[2] - group_type[0]
#     group_type[0] = 0
# elif group_type[0] == group_type[2]:
#     group_type[0] = 0
#     group_type[2] = 0
# else:
#     group_type[0] = group_type[0] - group_type[2]
#     group_type[2] = 0
#
# ans += group_type[1] // 2
#
# group_type[1] = group_type[1] % 2
#
# if group_type[0]:
#     taxi = group_type[1] * 2
#     for i in range(group_type[0]):
#         if taxi == 4:
#             ans += 1
#             taxi = 0
#         taxi += 1
#
#     if taxi:
#         ans += 1
# else:
#     ans += group_type[2]
#     if group_type[1]:
#         ans += 1
#
# print(ans)

# n = int(input())
# minimum_capacity = 0
# io_list = []
# io_recorder = 0
# for i in range(n):
#     io_list.append(tuple(map(int, input().split())))
#     if i == 0:
#         minimum_capacity = io_list[0][1]
#     io_recorder -= io_list[i][0]
#     io_recorder += io_list[i][1]
#     if minimum_capacity < io_recorder:
#         minimum_capacity = io_recorder
# print(minimum_capacity)

# n, index = map(int, input().split())
# value_list = list(map(int, input().split()))
# solved = False
# pointer = 0
# for i in range(len(value_list) + 1):
#     if pointer == index - 1:
#         print("YES")
#         solved = True
#         break
#     if pointer < len(value_list):
#         pointer += value_list[pointer]
# if not solved:
#     print("NO")

# import math
#
# n = int(input())
# list1 = list(map(int, input().split()))
# m = int(input())
# list2 = list(map(int, input().split()))
#
# graph = dict()
#
# for i in list1:
#     graph[i] = []
# if n > m:
#     n, m = m, n
#     list1, list2 = list2, list1
#
# for i in list1:
#     for j in list2:
#         if math.fabs(i - j) == 1:
#             graph[i].append(j)
#
# value_list = sorted(list(graph.values()))
# # while graph:
# for i in value_list:
#

# k, n, w = map(int, input().split())
# cost = 0
# for i in range(w):
#     cost += (i + 1) * k
# if cost - n > 0:
#     print(cost - n)
# else:print("0")

# n = int(input())
# xi = 0
# yi = 0
# zi = 0
# for i in range(n):
#     xyz = list(map(int, input().split()))
#     xi += xyz[0]
#     yi += xyz[1]
#     zi += xyz[2]
# if xi == yi == zi == 0:
#     print("YES")
# else:
#     print("NO")

#
# import sys
# s = input()
# print("YES" if "H" in s or "Q" in s or "9" in s else (print("NO"), sys.exit()))

# s = input()
# is_changed = False
# if s.isupper():
#     print(s.lower())
#     is_changed = True
#
# if ord(s[0]) > 96 and (s[1:].isupper() or len(s) == 1):
#     print(s[0].upper() + s[1:].lower())
#     is_changed = True
# if not is_changed:
#     print(s)

# ans = 0
# for i in range(int(input())):
#     p, q = map(int, input().split())
#     if q - p >= 2:
#         ans += 1
# print(ans)

# n, t = map(int, input().split())
# main_list = list(input())
# for i in range(t):
#     j = 0
#     while j < n:
#         if j != n - 1:
#             if main_list[j] == "B" and main_list[j + 1] == "G":
#                 main_list[j], main_list[j + 1] = main_list[j + 1], main_list[j]
#                 j += 1
#         j += 1
# print("".join(main_list))

number = list(map(int, list(input())))
length = len(number)
for i in number:
    if i != 4 or i != 7:
        number.remove(i)
if len(number) == 4 or len(number) == 7:
    print("YES")
else:
    print("NO")

n = raw_input()
print['NO', 'YES'] [(n.count('4')+n.count('7')) == len(n) and len(n) != 1]

x=list(raw_input())
flag=1
a=x.count('4')
b=x.count('7')
if a>0 and b>0 and a+b==len(x):
    print 'YES'
else:
    print 'NO'

from sys import stdin
rr = lambda: stdin.readline().strip()
rrm = lambda: map(int, rr().split())

S = rr()
print 'YES' if set(S) <= {'4', '7'} else 'NO'

n=int(input())
n=str(n)
a=n.count('4')
b=n.count('7')
sum=a+b
num=[]
num.append('4')
num.append('7')
if len(n)>1:
	for i in range(0,2**(len(n))-2):
		num.append(num[i]+'4')
		num.append(num[i]+'7')
for i in range(len(num)):
	num[i]=int(num[i])
count=0
for i in range(len(num)):
	if sum/num[i]==0:
		count+=1
if count>0:
	print('YES')
else:
	print('NO')

s = input()
a = s.count('4')
b = s.count('7')
if s == '7' or s=='4':
    print('NO')
elif ((a+b) == len(s)):
    print("YES")
else:
    print("NO")

import sys

n = list(sys.stdin.readline())[:-1]

happy = n.count('4') + n.count('7')

if happy == len(n) or happy == '4' or happy == '7':
    print("YES")
else:
    print("NO")

t=input()
c=0
for i in ["4","7"]:
    if(i in t):
        c+=1

if(c==4 or c==7):
    print("YES")
else:
    print("NO")

l = list(input())

a = 0
c = 0

if l.count('4') == 0:
    a = 0
else:
    a = l.count('4')

if l.count('7') == 0:
    c = 0
else:
    c = l.count('7')

if a+c == len(l):
    print('YES')
else:
    print('NO')

num = raw_input()
if not (set(num) -set('47')):

    print 'YES'

elif num == '4' or num == '7' or len(num) == 4 or len(num) == 7:
    print 'YES'
else:
    print 'NO'

#Petyas Luck
import pdb

def Divs(g):
    while g  > 0:
        if (g % 10) != 7 and (g % 10) != 4:
            return False
        g /= 10
    return True
def Luck(n):
    if n % 4 == 0 or n % 7 == 0 or Divs(n):
        return True
    else:
        return False

n = int(raw_input())

Divs(n)
if Luck(n):
    print "YES"
else:
    print "NO"

def lucky(que):
    ans=set(que)
    if len(ans)<=2:
        if len(ans)==2:
            if '4' in ans and '7' in ans:
                return True
            else:
                return False
        else:
            if '4' in ans or '7' in ans:
                return True
            else:
                return False
# def all_div(num):
#     arr=[]
#     for i in range(2,int((num**0.5))+1):
#         if num%i==0:
#             arr.append(i)
#             arr.append(num//i)
    # return arr
num=int(input())
if lucky(str(num)):
    print("YES")
else:
    arr=list(str(num))
    if lucky(str(arr.count('4')+arr.count('7'))):
        print("YES")
    else:
        print("NO")

def lucky(que):
    if int(que)<10:
        return False
    ans=set(que)
    if len(ans)<=2:
        if len(ans)==2:
            if '4' in ans and '7' in ans:
                return True
            else:
                return False
        else:
            if '4' in ans or '7' in ans:
                return True
            else:
                return False
# def all_div(num):
#     arr=[]
#     for i in range(2,int((num**0.5))+1):
#         if num%i==0:
#             arr.append(i)
#             arr.append(num//i)
    # return arr
num=int(input())
if lucky(str(num)):
    print("YES")
else:
    arr=list(str(num))
    if lucky(str(arr.count('4')+arr.count('7'))):
        print("YES")
    else:
        print("NO")

n = raw_input()
if len(n)==7 or len(n)==4:
    print("YES")
elif '4' in n and '7' in n:
    print("YES")
elif '1' in n and '0' in n:
    print("NO")
else:
    print("NO")

def lucky(que):
    ans=set(que)
    if len(ans)<=2:
        if len(ans)==2:
            if '4' in ans and '7' in ans:
                return True
            else:
                return False
        else:
            if '4' in ans or '7' in ans:
                return True
            else:
                return False
def all_div(num):
    arr=[]
    for i in range(2,int((num**0.5))+1):
        if num%i==0:
            arr.append(i)
            arr.append(num//i)
    return arr
num=int(input())
if lucky(str(num)):
    print("YES")
else:
    arr=all_div(num)
    # print(arr)
    count=0
    for div in arr:
        if lucky(str(div)):
            count+=1
    if count:
        print("YES")
    else:
        print("NO")

s = input()
for ch in s:
    if ch == '4' or ch == '7':
        pass
    else:
        print('NO')
        exit()
print('YES')

n=int(input())
p=len(str(n))
z=[]
while(n!=0):
      k=n%10
      z.append(k)
      n=n//10
z=list(set(z))
z=sorted(z)
if(z==[4,7] or (p==4 or p==7)):
      print("YES")
else:
      print("NO")

n = raw_input()
n = (int)(n)
count = 0
while(n>0):
	if(n%10 == 4 or n%10 == 7):
		count = count+1
	n = n/10

while(count>=0):
	if(count%10 !=4 and count%10!=7):
		print("NO")
		exit(0)
	count = count/10
print("YES")

n = raw_input()

count = 0

for i in range(len(n)):
    if n[i] == 4 or n[i] == 7:
        count += 1

if count == 4 or count == 7 or count == 47 or count == 74:
    print 'YES'
else:
    print 'NO'

s=list(input())
print(s)
k=0
w={'4','7'}
for i in s:
    if i=='4' or i=='7':
        k+=1
k1=set(list(str(k)))
if w>=set(s) and w>=k1:
    print('YES')
else:
    print('NO')

n = int(input())
while n :
    if n % 10 != 4 and n % 10 != 7 :
        print('NO')
        exit(0)
    n //= 10
print('YES')

n = raw_input()
d_c = set(n)

# print (len(d_c), d_c.intersection(set('47')))
if len(d_c) in [4,7] or set('47').union(d_c) == set('47') or d_c== set('4') or d_c == set('7') :
    print ('YES')
else:
    print ('NO')

n = int(input())
f = 4
s = 7
c = 0
while (n > 0):
    if (n % 10 == f or n%10 == s):
        c += 1
    n = int(n / 10)
if(c == 4 or c == 7):
    print("YES")
else:
    print("NO")

a = str(raw_input())
n = len(a)
i = 0
ans = []
while n>0:
    if a[i] == "4" or a[i] == "7":
        ans.append(0)
    else:
        ans.append(1)
    i+=1
    n-=1

if sum(ans) == 0:
    print "YES"
else:
    print "NO"


Little Petya was given this problem for homework:You are given function  (here  represents the operation of taking the remainder). His task is to count the number of integers x in range [a;b] with property f(x) = x.It is a pity that Petya forgot the order in which the remainders should be taken and wrote down only 4 numbers. Each of 24 possible orders of taking the remainder has equal probability of being chosen. For example, if Petya has numbers 1, 2, 3, 4 then he can take remainders in that order or first take remainder modulo 4, then modulo 2, 3, 1. There also are 22 other permutations of these numbers that represent orders in which remainder can be taken. In this problem 4 numbers wrote down by Petya will be pairwise distinct.Now it is impossible for Petya to complete the task given by teacher but just for fun he decided to find the number of integers  with property that probability that f(x) = x is not less than 31.4159265352718281828459045%. In other words, Petya will pick up the number x if there exist at least 7 permutations of numbers p1, p2, p3, p4, for which f(x) = x.

First line of the input will contain 6 integers, separated by spaces: p1, p2, p3, p4, a, b (1 ≤ p1, p2, p3, p4 ≤ 1000, 0 ≤ a ≤ b ≤ 31415).  It is guaranteed that numbers p1, p2, p3, p4 will be pairwise distinct.

Output the number of integers in the given range that have the given property.

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys
input = sys.stdin
output = sys.stdout

def solve(P,a,b):
    p = min(P) - 1
    if p < a:
        return 0
    elif p > b:
        return b-a+1
    else:
        return p-a+1

S = input.readline().strip()
A = [int(s) for s in S.split(' ') if len(s.strip())>0]

P = A[:4]
assert all(1<=p and p<=1000 for p in P)
assert len(set(P)) == len(P)

a = A[4]
b = A[5]
assert 0<=a and a<=b and b<=31415

a = solve(P,a,b)
output.write('%s\n' % a)

import sys

def f(x, p1, p2, p3, p4):
    return (((x % p1) % p2) % p3) % p4

lines = [i.rstrip() for i in sys.stdin.readlines()]
nums = [int(i) for i in lines[0].split(" ")]

p1 = nums[0]
p2 = nums[1]
p3 = nums[2]
p4 = nums[3]
a = nums[4]
b = nums[5]

c = 0
for i in range(a, b + 1):
    if i == f(i, p1, p2, p3, p4):
        c += 1
print c

import itertools

p1, p2, p3, p4, a, b = map(int, input().split())
permutations = list(itertools.permutations([p1, p2, p3, p4]))
result = 0

for x in range(a, b+1):
  count = 0
  for permutation in permutations:
    y = x
    for p in permutation:
      y %= p
    if y == x:
      count += 1
  if count >= 7:
    result += 1

print(result)

p1,p2,p3,p4,a,b=map(lambda x:int(x),input().split())
tp=min([b,p1-1,p2-1,p3-1,p4-1])
print(max(0,tp-a+1))

import itertools
p1, p2, p3, p4, a, b = map(int, raw_input().split())

ans = 0
for x in xrange(a, b + 1):
    c = 0
    for p in list(itertools.permutations(sorted([p1, p2, p3, p4]))):
        if x % p[0] % p[1] % p[2] % p[3] == x:
            c += 1
    if c >= 7:
        ans += 1
print ans

import sys
from itertools import permutations

p1,p2,p3,p4,a,b = [ int(x) for x in sys.stdin.readline().strip().split(' ') ]

p = [p1,p2,p3,p4]

def calc(j,y):
  c,d,e,f = y
  if j == ((( j % c) % d ) %e ) %f:
    return 1
  return 0

def calc2(k):
  if sum([ calc(k,x) for x in permutations(p)]) >= 7:
    return 1
  return 0

print sum([calc2(z) for z in xrange(a, b+1)])

p1,p2,p3,p4,a,b = map(int,input().strip().split())
m=min(min(min(p1,p2),p3),p4)
if m<a:
    print(0)
else:
    t=(m-a)
    if b<m:
        t=t-(m-b-1)
    print(t)

# import itertools

# def q68a():
# 	p1, p2, p3, p4, low, high = tuple([int(num) for num in input().split()])
# 	p = list(itertools.permutations([p1, p2, p3, p4], 4))
# 	num_good = 0
# 	for i in range(low, high+1):
# 		count = 0
# 		for t in p:
# 			if(i == q68a_mod_operation(i, t[0], t[1], t[2], t[3])):
# 				count += 1
# 		if(count >= 7):
# 			num_good += 1
# 	print(num_good)

# def q68a_mod_operation(num, a, b, c, d):
# 	return (((num % a) % b) % c) % d

# q68a()

p1, p2, p3, p4, low, high = tuple([int(num) for num in input().split()])
min_p = min(p1, p2, p3, p4)
print(min(max(min_p - low, 0), high-low+1))

s = [int(i) for i in raw_input().split()]
lst = s[0:4]
a = s[4]
b = s[5]
lst.sort()
if lst[0] > a and lst[0] < b:
    print lst[0] - a
elif lst[0] == b:
    print b - a
elif lst[0] > b:
    print b - a + 1
else:
    print '0'

*l, a, b = map(int, input().split())
print(max(0, min(b + 1, *l) - a))

class Main:
	s=raw_input().split(" ")
	l=[int(x) for x in s]
	m=min(l[0:len(l)-2])
	a=l[len(l)-2]
	b=l[len(l)-1]
	if(m>a and m<b):
		print m-a
	elif(m>a and m>b):
		print b-a+1
	else:
		print 0

p1, p2, p3, p4, a, b = map(int, input().split())
print(max(0, min(p1, p2, p3, p4, b + 1) - a))

x1,x2,x3,x4,a,b = map(int,input().split(' '))
minValue = min(x1,x2,x3,x4)
if(b<minValue):
    print(b-a+1)
else:
    print(max(0,minValue-a))

import itertools
L = map(int, raw_input().split())
p = L[0:4]; a = L[4]; b = L[5]
p.sort()

ans = 0
for x in xrange(a, b+1):
    cnt = 0
    for perm in itertools.permutations(p, len(p)):
        cnt += ((((x % perm[0]) % perm[1]) % perm[2]) % perm[3]) == x
    ans += cnt >= 7
print ans

p1, p2, p3, p4, a, b=map(int,raw_input().split())
print max(0, min(p1, p2, p3, p4, b+1)-a)

p1,p2,p3,p4,a,b=map(int,raw_input().split())
mina=min(p1,min(p2,min(p3,p4)))
ans=0
for no in xrange(a,b+1):
	if no<mina:
		ans+=1
print ans

def f(x):
    return (((x%p1)%p2)%p3)%p4
p1,p2,p3,p4,a,b = map(int,input().split())
ans = 0
for i in range(a,b+1):
    if f(i) == i: ans += 1
print(ans)

s = list(map(int, input().split()))
lis = [s[0]]
for i in range(1,4):
    if s[i]<s[i-1]:lis.append(s[i])
cnt = 0
for i in range(s[4], s[5]+1):
    m = i
    for j in lis:
        m = m%j
    if m == i: cnt += 1
print(cnt)

p1, p2, p3, p4, a, b = [int(i) for i in raw_input().split(' ')]

ans = 0
for i in range(a, b+1):
    if i == ((((i%p1)%p2)%p3)%p4):
        ans += 1

print ans

inp = [int(x) for x in input().split()]
p = inp[:4]
a,b = inp[4],inp[5]
p = min(p)
cnt = 0
for i in range(a,b+1):
    if i%p==i:
        cnt+=1
print(cnt)

p1, p2, p3, p4, a, b = [int(i) for i in input().split()]
print(max(0, min(p1, p2, p3, p4, b + 1) - a))

'''
Created on 3 Mar 2011

@author: salama
'''
import copy
def dfs(i, y, x, v, res):
    if(i == len(x)):
        res.append(copy.deepcopy(y));
    else :
        for j in range(0, len(x)):
            if(v[j] == 0):
                v[j] = 1;
                y.append(x[j]);

                dfs(i+1, y, x, v, res);

                del y[i];
                v[j] = 0;

x, y, res = [], [], [];
v = [0, 0, 0, 0];

input = raw_input().split(' ');
for i in range(0, 6):
    x.append(int(input[i]));

dfs(0, y, x[:4], v, res);
ans = 0;
for x in range(x[4], x[5]+1):
    c = 0;
    for perm in res:
        fx = x;
        for j in perm:
            fx = fx % j;
        if(fx == x):
            c+=1;

    if(c >= 7):
         ans+=1;

print ans;

# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="yaroslav"
__date__ ="$02.08.2011 18:00:13$"

if __name__ == "__main__":
    inp = raw_input()
    input = inp.rsplit(' ')
    p1 = int(input[0])
    p2 = int(input[1])
    p3 = int(input[2])
    p4 = int(input[3])
    a = int(input[4])
    b = int(input[5])
    allkol=0
    min1 = min(p1,p2,p3,p4)
    if min1>a:
        allkol = min1-a
        if allkol > b-a+1:
            allkol = b-a+1
    else:
        allkol = 0

    print allkol

l=map(int,raw_input().split())
mn=min(l[:-2])
print min(l[-1]+1,mn)-min(l[-2],mn)

nums = [int(i) for i in input().split()]
ps = min(nums[:-2])
a, b = nums[-2], nums[-1]
res = max(0, ps-a)
print(res - max(0, ps-(b+1)))

s=[int(x) for x in raw_input().split()]
p=min(s[0:4])
a,b=s[4:6]
if b<p: print b-a+1
elif a<p<=b: print p-a
else: print 0

n = [int(z) for z in raw_input().split(' ')]
x=[]
a=n[-2]
b=n[-1]
z=0
ans=a

for j in range(a,b+1):
	ans=j
	for i in range(0,len(n)-2):
		ans=ans%n[i]
	if ans==j:
		z=z+1
print z

a = map(int,raw_input().split())
print max(0,min(a[:4]+[a[-1]+1])-a[-2])

p1,p2,p3,p4,a,b=map(int,input().split())
l=[p1,p2,p3,p4]
count=0
for i in range(a,b+1):
    r=i
    for j in l:
        r=r%j
    if r==i:
        count+=1

print(count)

a = map(int,raw_input().split())
m = min(a[:4])
if a[4]>=m: print 0
else: print min(a[5],m-1)+1-a[4]

inp = map(int, raw_input().split())
mn = min(inp[:4])
a,b = inp[-2:]
if a <= mn <= b:
    print mn-a
elif b < mn:
    print b-a+1
else:
    print 0

data = map(int, raw_input().split())

p, (a,b) = data[:4], data[4:]

minp = min(p)
if a<=minp<=b+1:
    print minp-a
elif minp > b+1:
    print b-a+1
else: print 0

I=lambda:map(int, raw_input().split())

import itertools
p = I()
a = list(itertools.permutations([p[0],p[1],p[2],p[3]]))

def isOk(n):
    cnt = 0
    for x in a:
        z = n
        for y in x:
            z = z % y
        if z == n: cnt += 1
        if cnt >= 7: return True
    return False

ans = 0
for x in xrange(p[4], p[5]+1):
    if isOk(x):
        ans += 1
print ans

r = raw_input().split()
x = int(r[4])
z = int(r[5])
y = min(int(r[0]), int(r[1]), int(r[2]), int(r[3]))
if x > y:
    print 0
elif y > z:
    print str(z - x+1)
else:
    print str(y-x)

import sys
from collections import defaultdict, Counter
from itertools import permutations, combinations
from math import sin, cos, asin, acos, tan, atan, pi

sys.setrecursionlimit(10 ** 6)

def pyes_no(condition, yes = "YES", no = "NO", none = "-1") :
  if condition == None:
    print (none)
  elif condition :
    print (yes)
  else :
    print (no)

def plist(a, s = ' ') :
  print (s.join(map(str, a)))

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

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

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

def rfield(n, m = None) :
  if m == None :
    m = n

  field = []
  for i in xrange(n) :
    chars = sys.stdin.readline().strip()
    assert(len(chars) == m)
    field.append(chars)
  return field

def pfield(field, separator = '') :
  print ('\n'.join(map(lambda x: separator.join(x), field)))

def check_field_equal(field, i, j, value) :
  if i >= 0 and i < len(field) and j >= 0 and j < len(field[i]) :
    return value == field[i][j]
  return None

def digits(x, p) :
  digits = []
  while x > 0 :
    digits.append(x % p)
    x //= p
  return digits[::-1]

def undigits(x, p) :
  value = 0
  for d in x :
    value *= p
    value += d
  return value

def modpower(a, n, mod) :
  r = a ** (n % 2)
  if n > 1 :
    r *= modpower(a, n // 2, mod) ** 2
  return r % mod

def gcd(a, b) :
  if a > b :
    a, b = b, a

  while a > 0 :
    a, b = b % a, a

  return b

def vector_distance(a, b) :
  diff = vector_diff(a, b)

  return scalar_product(diff, diff) ** 0.5

def vector_inverse(v) :
  r = [-x for x in v]

  return tuple(r)

def vector_diff(a, b) :
  return vector_sum(a, vector_inverse(b))

def vector_sum(a, b) :
  r = [c1 + c2 for c1, c2 in zip(a, b)]

  return tuple(r)

def scalar_product(a, b) :
  r = 0
  for c1, c2 in zip(a, b) :
    r += c1 * c2

  return r

def check_rectangle(points) :
  assert(len(points) == 4)

  A, B, C, D = points

  for A1, A2, A3, A4 in [
    (A, B, C, D),
    (A, C, B, D),
    (A, B, D, C),
    (A, C, D, B),
    (A, D, B, C),
    (A, D, C, B),
  ] :
    sides = (
      vector_diff(A1, A2),
      vector_diff(A2, A3),
      vector_diff(A3, A4),
      vector_diff(A4, A1),
    )
    if all(scalar_product(s1, s2) == 0 for s1, s2 in zip(sides, sides[1:])) :
       return True
  return False

def check_square(points) :
  if not check_rectangle(points) :
    return False
  A, B, C, D = points

  for A1, A2, A3, A4 in [
    (A, B, C, D),
    (A, C, B, D),
    (A, B, D, C),
    (A, C, D, B),
    (A, D, B, C),
    (A, D, C, B),
  ] :
    side_lengths = [
      (first[0] - next[0]) ** 2 + (first[1] - next[1]) ** 2 for first, next in zip([A1, A2, A3, A4], [A2, A3, A4, A1])
    ]
    if len(set(side_lengths)) == 1 :
      return True

  return False

def check_right(p) :
  # Check if there are same points
  for a, b in [
    (p[0], p[1]),
    (p[0], p[2]),
    (p[1], p[2]),
  ] :
    if a[0] == b[0] and a[1] == b[1] :
      return False

  a, b, c = p
  a, b, c = vector_diff(a, b), vector_diff(b, c), vector_diff(c, a)

  return scalar_product(a, b) * scalar_product(a, c) * scalar_product(b, c) == 0

def modmatrixproduct(a, b, mod) :
  n, m1 = len(a), len(a[0])
  m2, k = len(b), len(b[0])

  assert(m1 == m2)
  m = m1

  r = [[0] * k for i in range(n)]
  for i in range(n) :
    for j in range(k) :
      for l in range(m) :
        r[i][j] += a[i][l] * b[l][j]
      r[i][j] %= mod
  return r

def modmatrixpower(a, n, mod) :
  magic = 2
  for m in [2, 3, 5, 7] :
    if n % m == 0 :
      magic = m
      break

  r = None
  if n < magic :
    r = a
    n -= 1
  else :
    s = modmatrixpower(a, n // magic, mod)
    r = s
    for i in range(magic - 1) :
      r = modmatrixproduct(r, s, mod)

  for i in range(n % magic) :
    r = modmatrixproduct(r, a, mod)

  return r

v = rints()
p = v[:4]
a, b = v[4:]
b = min(b, min(p) - 1)
if b >= a :
  print b - a + 1
else :
  print 0

a,b,c,d,x,y=map(int,input().split())
if x>=min(a,b,c,d):
    print(0)
else:
    print(min(min(a,b,c,d),y+1)-x)

p1,p2,p3,p4,a,b = map(int,input().strip().split())
m=min(min(min(p1,p2),p3),p4)
if m<a:
    print(0)
else:
    t=(m-a)
    if b<m:
        t=t-(m-b-1)
    print(t)

p1,p2,p3,p4,a,b = map(int,input().strip().split())
m=min(min(min(p1,p2),p3),p4)
if m<a:
    print(0)
else:
    t=(m-a)

    if b<m:
        t=t-(m-b-1)
    print(t)

from itertools import permutations

def f(x, p1, p2, p3, p4):
    return x % p1 % p2 % p3 % p4

def main():
    p1, p2, p3, p4, a, b = [int(i) for i in raw_input().split()]
    result = 0
    for x in xrange(a, b + 1):
        count = 0
        for args in permutations([p1, p2, p3, p4]):
            if f(x, *args) == x:
                count += 1
        if count > 6:
            result += 1
    print result

if __name__ == '__main__':
    main()

a = [int(i) for i in input().split()]
if min(a[:len(a)-2]) < a[4]:
    print(0)
elif min(a[:len(a)-2]) > a[5]:
    print(a[5] - a[4] + 1)
else:
    print(min(a[:len(a)-2])-a[4])

line = raw_input().split()
p,a,b = map(int, line[:4]), int(line[4]), int(line[5])
print sum( [i<min(p) for i in range(a, b+1)] )

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

inp = readln()
mod = min(inp[:4])
print(len([_ for _ in range(inp[4], inp[5] + 1) if _ < mod]))

p = [int(x) for x in input().split()]
mod = min(p[0:4])
if mod < p[4]:
    print(0)
else:
    if mod > p[5]:
        print(p[5] - p[4] + 1)
    else:
        print(mod - p[4])

p=map(int,raw_input().split())
ans=0
a=p[4]
b=p[5]
while a<=b:
    x=a
    for i in range(4):
        x=x%p[i];
    if x==a :ans=ans+1;
    a=a+1;
print ans;

from itertools import permutations as perm
p1,p2,p3,p4,a,b=map(int,raw_input().split())
ans=0
for d in xrange(a,b+1):
  c=0
  for p in perm((p1,p2,p3,p4)):
    if reduce(lambda x,y:x%y,p,d)==d:
      c+=1
    if c==7:
      ans+=1
      break
print ans

import itertools

p = [0] * 4
p[0], p[1], p[2], p[3], a, b = map(int, input().split())

ans = 0
for i in range(a, b + 1):
    valid = 0
    for perm in itertools.permutations(p):
        if i == i % p[0] % p[1] % p[2] % p[3]:
            valid += 1
    ans += valid >= 7
print(ans)

from time import *

if __name__ == "__main__" :
    # start = time()
    p1 , p2 , p3 , p4 , a , b = map(int,input().strip().split())
    count = 0
    for i in range(a , b + 1) :
        if ((((i % p1)% p2)% p3) % p4) == i :
            count += 1
    print(count)
    # print(time() - start)

# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# import math
from itertools import *
# import random
# import calendar
# import datetime
# import webbrowser

def function(x, lst):
    permu = permutations(lst, len(lst))
    count_ = 0
    for i in permu:
        temp = (((x % i[0]) % i[1]) % i[2]) % i[-1]
        if temp == x:
            count_ += 1
            if count_ >= 7:
                return True
    if count_ < 7:
        return False

p1, p2, p3, p4, a, b = map(int, input().split())
arr = [p1, p2, p3, p4]
count = 0
for i in range(a, b+1):
    if function(i, arr):
        count += 1
print(count)

p1,p2,p3,p4,a,b = map(int,raw_input().split());
print max(0,min(p1,p2,p3,p4,b+1)-a);

*l, a, b = map(int, input().split())
print(max(0, min(b + 1, *l) - a))

import itertools
l = []
cont = 0
r = 0
l1 = list(map(int,input().strip().split()))[:6]
l = l1[0:4]
ab = l1[4:6]

for x in range(ab[0],ab[1]+1):
    perm = itertools.permutations(l)
    for i in list(perm):
        if ((((x % i[0]) % i[1]) % i[2]) % i[3]) == x:
            cont += 1
    if cont >= 7:
        r += 1
    cont = 0
print (r)

p1, p2, p3, p4, a, b = map(int, input().split())
c = 0
for i in range(a, b+1):
    if i % p1 == i:
        if i % p2 == i:
            if i % p3 == i:
                if i % p4 == i:
                    c += 1
print(c)

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

p1, p2, p3, p4, a, b = invr()

m = min(p1, p2, p3, p4)
res = 0
if m >= a and m <= b:
    res = m-a
elif m > b:
    res = b-a + 1
else:
    res = 0
print(res)

p1, p2, p3, p4, a, b = map(int, input().split())
print(max(0, min(p1, p2, p3, p4, b + 1) - a))

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

p1, p2, p3, p4, a, b = [int(i) for i in raw_input().split()]

mini = min(p1, p2, p3, p4)

if b < mini:
    print(b - a + 1)
elif mini < a:
    print(0)
else:
    print(mini - a)

import math
p1,p2,p3,p4,a,b=map(int,input().split())
c=0
for i in range(a,b+1):
    if (((i%p1)%p2)%p3)%p4==i:
        c+=1
print (c)

a,b,c,d,x,y=map(int,input().split())
if x>=min(a,b,c,d):
    print(0)
else:
    print(min(min(a,b,c,d),y+1)-x)

import sys,math,string,bisect
input=sys.stdin.readline
from collections import deque
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
p1,p2,p3,p4,b,a=M()
k=min(p1,p2,p3,p4)
c=0
for i in range(b,min(k,a+1)):
    c+=1
print(c)

line = raw_input().split()
p,a,b = map(int, line[:4]), int(line[4]), int(line[5])
print sum( [i<min(p) for i in range(a, b+1)] )

p1,p2,p3,p4,a,b=map(lambda x:int(x),input().split())
tp=min([b,p1-1,p2-1,p3-1,p4-1])
print(max(0,tp-a+1))

mylist=list(map(int,input().split()))
a=0
b=min(mylist[:4:]) - mylist[4]
if(b>=0):
    a=min(b,mylist[5]-mylist[4]+1)
print(a)

from sys import stdin

[p1,p2,p3,p4,a,b] = [int(x) for x in stdin.readline().strip().split()]

print(max(min([p1,p2,p3,p4,b+1])-a, 0))

p1,p2,p3,p4,a,b=map(int,raw_input().split())
mina=min(p1,min(p2,min(p3,p4)))
ans=0
for no in xrange(a,b+1):
	if no<mina:
		ans+=1
print ans

import sys
import math

#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read integers
get_int = lambda: int(sys.stdin.readline())
#to print fast
#pt = lambda x: sys.stdout.write(str(x)+'\n')

#--------------------------------WhiteHat010--------------------------------------#
from itertools import permutations
p1,p2,p3,p4,a,b = get_int_list()
m = 0
for p in permutations([p1,p2,p3,p4]):
    count = 0
    for i in range(a,b+1):
        if i == (((i%p[0])%p[1])%p[2])%p[3]:
            count += 1
    m = max(m,count)
print(m)

import sys

A = [int(x) for x in sys.stdin.readline().split()]
print max(min(A[:4] + [A[-1] + 1]) - min(A[-2:]), 0)

import sys
import itertools

x = map(int, sys.stdin.read().split())

p = x[:4]
a, b = x[4:]

res = 0
for v in xrange(a, b+1):
  cnt = 0
  for pp in itertools.permutations(p):
    if ((((v % pp[0]) % pp[1]) % pp[2]) % pp[3]) == v:
      cnt+=1

  if float(cnt)/24 >= 0.314159265352718281828459045:
    res += 1

print res

from itertools import permutations

class CodeforcesTask68ASolution:
    def __init__(self):
        self.result = ''
        self.pppp_a_b = []

    def read_input(self):
        self.pppp_a_b = [int(x) for x in input().split(" ")]

    def process_task(self):
        prop = [0] * (1 + self.pppp_a_b[-1] - self.pppp_a_b[-2])
        for st in permutations(self.pppp_a_b[:4]):
            f = lambda x: (((x % st[0]) % st[1]) % st[2]) % st[3]
            for y in range(self.pppp_a_b[-2], self.pppp_a_b[-1] + 1):
                if f(y) == y:
                    prop[y - self.pppp_a_b[-2]] += 1
        has_prop = [1 if x >= 7 else 0 for x in prop]
        self.result = str(sum(has_prop))

    def get_result(self):
        return self.result

if __name__ == "__main__":
    Solution = CodeforcesTask68ASolution()
    Solution.read_input()
    Solution.process_task()
    print(Solution.get_result())

*l, a, b = map(int, input().split())
print(max(0, min(b + 1, *l) - a))

#68A
tmp = map(int, raw_input().split())
a, b = tmp[4:6]
p = min(tmp[0:4])
res = 0
for x in xrange(a, b + 1):
    if x < p: res += 1
print res

p1,p2,p3,p4,a,b = map(int,input().split())
from itertools import permutations
t = list(permutations([p1,p2,p3,p4]))
# print(t)
i = a
count = 0
t1 = 0
while i <= b:
	count = 0
	for j in t:
		if ((((i%j[0])%j[1])%j[2])%j[3]) == i:
			count = count + 1
	if count >= 7:
		t1 = t1 + 1
	i = i + 1
print(t1)

p1, p2, p3, p4, a, b = map(int, input().split())
p_min = min(p1, p2, p3, p4)
result = 0

for x in range(a, b+1):
  if x == x % p_min:
    result += 1

print(result)

s = [int(x) for x in raw_input().split()]
s[5] += 1
print max(0, min(s[:4]+s[5:])-s[4])

p1, p2, p3, p4, a, b = [int(i) for i in raw_input().split()]
print sum(1 for i in range(a, b+1) if i == (((i % p1) % p2) % p3) % p4)

import sys
from collections import defaultdict, Counter
from itertools import permutations, combinations
from math import sin, cos, asin, acos, tan, atan, pi

sys.setrecursionlimit(10 ** 6)

def pyes_no(condition, yes = "YES", no = "NO", none = "-1") :
  if condition == None:
    print (none)
  elif condition :
    print (yes)
  else :
    print (no)

def plist(a, s = ' ') :
  print (s.join(map(str, a)))

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

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

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

def rfield(n, m = None) :
  if m == None :
    m = n

  field = []
  for i in xrange(n) :
    chars = sys.stdin.readline().strip()
    assert(len(chars) == m)
    field.append(chars)
  return field

def pfield(field, separator = '') :
  print ('\n'.join(map(lambda x: separator.join(x), field)))

def check_field_equal(field, i, j, value) :
  if i >= 0 and i < len(field) and j >= 0 and j < len(field[i]) :
    return value == field[i][j]
  return None

def digits(x, p) :
  digits = []
  while x > 0 :
    digits.append(x % p)
    x //= p
  return digits[::-1]

def undigits(x, p) :
  value = 0
  for d in x :
    value *= p
    value += d
  return value

def modpower(a, n, mod) :
  r = a ** (n % 2)
  if n > 1 :
    r *= modpower(a, n // 2, mod) ** 2
  return r % mod

def gcd(a, b) :
  if a > b :
    a, b = b, a

  while a > 0 :
    a, b = b % a, a

  return b

def vector_distance(a, b) :
  diff = vector_diff(a, b)

  return scalar_product(diff, diff) ** 0.5

def vector_inverse(v) :
  r = [-x for x in v]

  return tuple(r)

def vector_diff(a, b) :
  return vector_sum(a, vector_inverse(b))

def vector_sum(a, b) :
  r = [c1 + c2 for c1, c2 in zip(a, b)]

  return tuple(r)

def scalar_product(a, b) :
  r = 0
  for c1, c2 in zip(a, b) :
    r += c1 * c2

  return r

def check_rectangle(points) :
  assert(len(points) == 4)

  A, B, C, D = points

  for A1, A2, A3, A4 in [
    (A, B, C, D),
    (A, C, B, D),
    (A, B, D, C),
    (A, C, D, B),
    (A, D, B, C),
    (A, D, C, B),
  ] :
    sides = (
      vector_diff(A1, A2),
      vector_diff(A2, A3),
      vector_diff(A3, A4),
      vector_diff(A4, A1),
    )
    if all(scalar_product(s1, s2) == 0 for s1, s2 in zip(sides, sides[1:])) :
       return True
  return False

def check_square(points) :
  if not check_rectangle(points) :
    return False
  A, B, C, D = points

  for A1, A2, A3, A4 in [
    (A, B, C, D),
    (A, C, B, D),
    (A, B, D, C),
    (A, C, D, B),
    (A, D, B, C),
    (A, D, C, B),
  ] :
    side_lengths = [
      (first[0] - next[0]) ** 2 + (first[1] - next[1]) ** 2 for first, next in zip([A1, A2, A3, A4], [A2, A3, A4, A1])
    ]
    if len(set(side_lengths)) == 1 :
      return True

  return False

def check_right(p) :
  # Check if there are same points
  for a, b in [
    (p[0], p[1]),
    (p[0], p[2]),
    (p[1], p[2]),
  ] :
    if a[0] == b[0] and a[1] == b[1] :
      return False

  a, b, c = p
  a, b, c = vector_diff(a, b), vector_diff(b, c), vector_diff(c, a)

  return scalar_product(a, b) * scalar_product(a, c) * scalar_product(b, c) == 0

def modmatrixproduct(a, b, mod) :
  n, m1 = len(a), len(a[0])
  m2, k = len(b), len(b[0])

  assert(m1 == m2)
  m = m1

  r = [[0] * k for i in range(n)]
  for i in range(n) :
    for j in range(k) :
      for l in range(m) :
        r[i][j] += a[i][l] * b[l][j]
      r[i][j] %= mod
  return r

def modmatrixpower(a, n, mod) :
  magic = 2
  for m in [2, 3, 5, 7] :
    if n % m == 0 :
      magic = m
      break

  r = None
  if n < magic :
    r = a
    n -= 1
  else :
    s = modmatrixpower(a, n // magic, mod)
    r = s
    for i in range(magic - 1) :
      r = modmatrixproduct(r, s, mod)

  for i in range(n % magic) :
    r = modmatrixproduct(r, a, mod)

  return r

v = rints()
p = v[:4]
a, b = v[4:]
b = min(b, min(p))
if b > a :
  print b - a
else :
  print 0

import sys,math,string,bisect
input=sys.stdin.readline
from collections import deque
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
p1,p2,p3,p4,b,a=M()
k=min(p1,p2,p3,p4)
if(k<b):
    print(0)
elif(k>a):
    print(b-a)
else:
    print(k-b)

import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy

ORDA = 97  # a
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return [int(i) for i in input().split()]
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r
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 divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
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
def convn(number, base):
    newnumber = 0
    while number > 0:
        newnumber += number % base
        number //= base
    return newnumber
def cdiv(n, k): return n // k + (n % k != 0)
def ispal(s):
    for i in range(len(s) // 2 + 1):
        if s[i] != s[-i - 1]:
            return False
    return True

a = li()
print(max(0, min(min(a[:4]), a[5]) - min(min(a[:4]), a[4])))

p1,p2,p3,p4,a,b=map(int,input().split())
m=min(p1,p2,p3,p4)
if m-a<=0:
	print(0)
else:
	print(m-a)

a = [int(i) for i in input().split()]
if min(a[:len(a)-2]) < a[4]:
    print(0)
elif min(a[:len(a)-2]) > a[5]:
    print(a[5] - a[4])
else:
    print(min(a[:len(a)-2])-a[4])

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

p1, p2, p3, p4, a, b = invr()

m = min(p1, p2, p3, p4)
res = 0
if m >= a and m <= b:
    res = m-a
elif m > b:
    res = b-a
else:
    res = 0
print(res)

class Main:
	s=raw_input().split(" ")
	l=[int(x) for x in s]
	m=min(l[0:len(l)-2])
	a=l[len(l)-2]
	if(m>a):
		print m-a
	else:
		print 0

from sys import stdin

[p1,p2,p3,p4,a,b] = [int(x) for x in stdin.readline().strip().split()]

print(max(min([p1,p2,p3,p4,b])-a, 0))

from sys import stdin

[p1,p2,p3,p4,a,b] = [int(x) for x in stdin.readline().strip().split()]

print(min([p1,p2,p3,p4,b])-a)

import sys

p1,p2,p3,p4,a,b=map(int,raw_input().split())

'''
Created on 3 Mar 2011

@author: salama
'''
b = 0
w = []
y = raw_input()
a = 0
x = y.split(' ')
def permutate(seq):
    if not seq:
        return [seq]
    else:
        temp = []
        for k in range(len(seq)):
            part = seq[:k] + seq[k+1:]
            #print k, part  # test
            for m in permutate(part):
                temp.append(seq[k:k+1] + m)                #  # test
    return temp
for i in range(int(x[4]),int(x[5])):
    for list2 in permutate(x[:4]):
         if int(i)%int(list2[0])%int(list2[1])%int(list2[2])%int(list2[3])== i:
             b += 1
             if b >= 7:
                 a += 1
                 break

print a

s = [int(x) for x in raw_input().split()]
print max(0, min(s[:4]+s[5:])-s[4])

from itertools import permutations as p
r=map(int,raw_input().split())
P=p(r[:4])
print len([ x for x in range(r[4],r[5]+1) if sum([ x == eval('%'.join(map(str, [x]+list(e)))) for e in P])>6])

l=map(int,raw_input().split())
mn=min(l[:-2])
print min(l[-1]-1,mn)-min(l[-2],mn)

def readints():
  return map(int,raw_input().split())

def main():
  p1,p2,p3,p4,a,b=readints()
  m=min(p1,p2,p3,p4)
  u=min(b-1,m)
  print max(u-a,0)

main()

def solve():
    line = map(int, str(raw_input()).split())
    b,a = line.pop(-1), line.pop(-1)
    mini= min(line)
    if b>=a: minim = a
    else: minim = b
    total = mini-minim
    if(total < 0): print 0
    else: print total

solve()

# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="yaroslav"
__date__ ="$02.08.2011 18:00:13$"

if __name__ == "__main__":
    inp = raw_input()
    input = inp.rsplit(' ')
    p1 = int(input[0])
    p2 = int(input[1])
    p3 = int(input[2])
    p4 = int(input[3])
    a = int(input[4])
    b = int(input[5])
    allkol=0
    min1 = min(p1,p2,p3,p4)
    if min1>a:
        allkol = min1-a
    else:
        allkol = 0

    print allkol

# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="yaroslav"
__date__ ="$02.08.2011 18:00:13$"
def f(x,p1,p2,p3,p4):
    return (((x % p1) % p2) % p3) % p4

if __name__ == "__main__":
    inp = raw_input()
    input = inp.rsplit(' ')
    p1 = int(input[0])
    p2 = int(input[1])
    p3 = int(input[2])
    p4 = int(input[3])
    a = int(input[4])
    b = int(input[5])
    allkol=0
    for x in range(a,b):
        kol = 0
        for i in [p1,p2,p3,p4]:
            for j in [p1,p2,p3,p4]:
                if j!=i:
                    for k in [p1,p2,p3,p4]:
                        if k not in(j,i):
                            for m in [p1,p2,p3,p4]:
                                if m not in (j,i,k):
                                    if x==f(x,i,j,k,m):
                                        kol+=1
        if kol>7:
            allkol+=1
    print allkol

# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="yaroslav"
__date__ ="$02.08.2011 18:00:13$"
def f(x,p1,p2,p3,p4):
    return (((x % p1) % p2) % p3) % p4

if __name__ == "__main__":
    inp = raw_input()
    input = inp.rsplit(' ')
    p1 = int(input[0])
    p2 = int(input[1])
    p3 = int(input[2])
    p4 = int(input[3])
    a = int(input[4])
    b = int(input[5])
    allkol=0
    if (a!=b):
        for x in range(a,b):
            kol = 0
            for i in [p1,p2,p3,p4]:
                for j in [p1,p2,p3,p4]:
                    if j!=i:
                        for k in [p1,p2,p3,p4]:
                            if k not in(j,i):
                                for m in [p1,p2,p3,p4]:
                                    if m not in (j,i,k):
                                        if x==f(x,i,j,k,m):
                                            kol+=1
        if kol>7:
            allkol+=1
    print allkol

# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="yaroslav"
__date__ ="$02.08.2011 18:00:13$"
def f(x,p1,p2,p3,p4):
    return (((x % p1) % p2) % p3) % p4

if __name__ == "__main__":
    inp = raw_input()
    input = inp.rsplit(' ')
    p1 = int(input[0])
    p2 = int(input[1])
    p3 = int(input[2])
    p4 = int(input[3])
    a = int(input[4])
    b = int(input[5])
    allkol=0
    if a!=b:
        for x in range(a,b):
            kol = 0
            for i in [p1,p2,p3,p4]:
                for j in [p1,p2,p3,p4]:
                    if j!=i:
                        for k in [p1,p2,p3,p4]:
                            if k not in(j,i):
                                for m in [p1,p2,p3,p4]:
                                    if m not in (j,i,k):
                                        if x==f(x,i,j,k,m):
                                            kol+=1
            if kol>7:
                allkol+=1
    print allkol

line = raw_input().split()
p1 = int(line[0])
p2 = int(line[1])
p3 = int(line[2])
p4 = int(line[3])
a = int(line[4])
b = int(line[5])
count = 0
for i in range(a,b+1):
    print i
    if i == (((i%p1)%p2)%p3)%p4:
        count+=1
print count

line = raw_input().split()
p1 = int(line[0])
p2 = int(line[1])
p3 = int(line[2])
p4 = int(line[3])
a = int(line[4])
b = int(line[5])
count = 0
for i in range(a,b):
    if i == (((i%p1)%p2)%p3)%p4:
        count+=1
print count

import string

def ii():
    ii = []
    for s in string.split(raw_input()):
        ii.append(int(s))
    return ii

ii = ii()
a = min(ii[0], ii[1], ii[2], ii[3])
if (ii[4] >= a):
    print 0
else:
    print min(a, ii[5]) - ii[4]

L=[int(x) for x in raw_input().split()]
a=min(L[0:4])
if a<L[4]:
  print 0
else:
  print a-L[4]

L=[int(x) for x in raw_input().split()]
a=min(L[0:4])
if a<L[4]:
  print 0
else:
  print min(a-L[4],L[5]-L[4])

p1,p2,p3,p4,a,b=map(int, raw_input().split())
m=p1
if p2<m:
	m=p2
if p3<m:
	m=p3
if p4<m:
	m=p4
if a<b<m:
	print b-a
elif a<m:
	print m-a
else:
  print 0

p1,p2,p3,p4,a,b=map(int, raw_input().split())
m=p1
if p2<m:
	m=p2
if p3<m:
	m=p3
if p4<m:
	m=p4
if a<b<m:
	print b-a
elif a<m:
	print m-a

p1, p2, p3, p4, a, b=map(int,raw_input().split())
print max(0, min(p1, p2, p3, p4, b)-a)

p1,p2,p3,p4,a,b = [int(k) for k in raw_input().split(" ")]
s=[p1,p2,p3,p4]
i = 1000000
for k in s:
    if k<i :
        i=k

ot = i-a
if ot<0 :
    ot=0
print ot

p1,p2,p3,p4,a,b = map(int,raw_input().split());
print max(0,min(p1,p2,p3,p4,b)-a);

p1,p2,p3,p4,a,b = map(int,raw_input().split());
print max(0,min(p1,p2,p3,p4)-a);

'''
Created on 29.04.2011

@author: andrew
'''
import sys,re

start=0

def read_int_line(file=sys.stdin):
    return map(int,re.findall("\d+", file.readline()))
if __name__ == '__main__':
    arr=read_int_line()
    it=min(arr[0:4])
    print max(0,min(it-arr[4],arr[5]-arr[4]))

p1, p2, p3, p4, a, b = [int(i) for i in raw_input().split(' ')]

ans = 0
for i in range(a, b):
    if i == ((((i%p1)%p2)%p3)%p4):
        ans += 1

print ans

p1, p2, p3, p4, a, b = [int(i) for i in raw_input().split(' ')]

ans = 0
for i in range(a, b):
    if i == ((((i%p1)%p2)%p3)%p4):
        ans += 1

if a == 0 and b == 0:
    ans += 1

print ans

X = list(map(int, input().split()));print(max(0, min(X[:4]) - X[-2]))

# UB_CodeForces
# Advice: Falling down is an accident, staying down is a choice
# Location: Mashhad for few days
# Caption: Finally happened what should be happened
# CodeNumber: 694

a,b,p1,p2,p3,p4=map(lambda x:int(x),input().split())
tp=min([b,p1-1,p2-1,p3-1,p4-1])
print(max(0,tp-a+1))

p1,p2,p3,p4,a,b = map(int,input().split())
from itertools import permutations
t = list(permutations([p1,p2,p3,p4]))
print(t)
i = a
count = 0
t1 = 0
while i <= b:
	count = 0
	for j in t:
		if ((((i%j[0])%j[1])%j[2])%j[3]) == i:
			count = count + 1
	if count >= 7:
		t1 = t1 + 1
	i = i + 1
print(t1)

p1, p2, p3, p4, a, b = map(int, input().split())
m = min(p1, p2, p3, p4)
print(m - a if m - a > 0 else 0)

p1, p2, p3, p4, a, b = map(int, input().split())
m = min(p1, p2, p3, p4)
if m > b:
    b = m
print(m - a if m - a > 0 else 0)

mylist=list(map(int,input().split()))
a=0
b=min(mylist[:4:]) - mylist[4]
if(b>=0):
    a=b
print(a)

a,b,c,d,e,f = map(int,input().split())
g = min([a,b,c,d])
print(max(0,min(g,f)-e))

a,b,c,d,e,f = map(int,input().split())
g = min([a,b,c,d])
if e==f==0:
    print(1)
else:
    print(max(0,min(g,f)-e))

*P, a, _ = map(int, input().split())

print(max(0, min(P)-a))

s = list(map(int, input().split()))
lis = [s[0]]
for i in range(1,4):
    if s[i]<s[i-1]:lis.append(s[i])
cnt = 0
for i in range(s[4], min(lis)):
    m = i
    for j in lis:
        m = m%j
    if m == i: cnt += 1
print(cnt)

nums = [int(i) for i in input().split()]
ps = min(nums[:-2])
a = nums[-2]
print(max(0, ps-a))

nums = [int(i) for i in input().split()]
ps = min(nums[:-2])
a, b = nums[-2], nums[-1]
res = max(0, ps-a) + max(0, ps-b)
print(res)

l = list(map(int, input().split()))
a = l.pop(4)
print(max(0, min(l) - a))

import sys
I=sys.stdin.readline

p1,p2,p3,p4,a,b=map(int,I().split())

x=min(p1,p2,p3,p4)

if x>=a:
	print(0)
else:
	if x>b:
		print(b-a+1)
	else:
		print(x-a)

import sys

A = [int(x) for x in sys.stdin.readline().split()]
print max(min(A[:4]) - min(A[-2:]), 0)

p1, p2, p3, p4, a, b = [int(i) for i in raw_input().split()]
print sum(1 for i in range(a, b) if i == (((i % p1) % p2) % p3) % p4)

#!/usr/bin/python

w = raw_input()
p1, p2, p3, p4, a, b = map(int, w.split())
p = min(p1, p2, p3, p4)
if a < p:
    print min(b - a, p - a)
else:
    print 0

s = [int(i) for i in raw_input().split()]
lst = s[0:4]
a = s[4]
b = s[5]
lst.sort()
if lst[0] > a and lst[0] < b:
    print lst[0] - a
else:
    print '0'

s = raw_input().split()
r = 0
for i in range(4):
    p = int(s[i])
    if i == 0 or p < r:
        r = p
n = int(s[4])
m = int(s[5])
r = r - n
if r < 0:
    r = 0
print r

p1, p2, p3, p4, a, b = map(int, raw_input().split())
p = min(p1, p2, p3, p4)
if p > a:
	print p - a
else:
	print 0

data = map(int, raw_input().split())

p, (a,b) = data[:4], data[4:]

minp = min(p)
if a<=minp<=b+1:
    print max(minp,b)-a
else: print 0

# data = int(raw_input())
data = map(int, raw_input().split())

p, (a,b) = data[:4], data[4:]

minp = min(p)
if a<minp<b:
    print minp-a
else: print 0

data = map(int, raw_input().split())

p, (a,b) = data[:4], data[4:]

minp = min(p)
if a<=minp<=b+1:
    print minp-a
elif minp > b+1:
    print b-a
else: print 0

# data = int(raw_input())
data = map(int, raw_input().split())

p, (a,b) = data[:4], data[4:]

minp = min(p)
if a<=minp<b:
    print minp-a
else: print 0

# data = int(raw_input())
data = map(int, raw_input().split())

p, (a,b) = data[:4], data[4:]

minp = min(p)
if a<=minp<b+1:
    print minp-a
else: print 0

data = map(int, raw_input().split())

p, (a,b) = data[:4], data[4:]

minp = min(p)
if a<=minp<=b+1:
    print minp-a
else: print 0

# data = int(raw_input())
data = map(int, raw_input().split())

p, (a,b) = data[:4], data[4:]

minp = min(p)
if a==b==0: print 0
else:
    if a<minp<b:
        print minp-a
    else: print 0

#68A
tmp = map(int, raw_input().split())
a, b = tmp[4:6]
p = min(tmp[0:4])
print min(b, p) - min(p, a)

r = raw_input().split()
x = int(r[4])
z = int(r[5])
y = min(int(r[0]), int(r[1]), int(r[2]), int(r[3]))
if x > y:
    print 0
elif y > z:
    print str(z - x)
else:
    print str(y-x)

r = raw_input().split()
x = int(r[4])
y = min(int(r[0]), int(r[1]), int(r[2]), int(r[3]))
if x > y:
    print 0
else:
    print str(y-x)

p1,p2,p3,p4,a,b=map(int,raw_input().split())
mina=min(p1,min(p2,min(p3,p4)))
ans=0
if mina<a:
	print 0
else:
	upp=min(b,mina)
	for no in xrange(a,upp):
		if no<mina:
			ans+=1
	print ans

q=input()
p1,p2,p3,p4,a,b=map(int,q.split())
p=min(p1,p2,p3,p4)
c=0
if p>=b:
    c=b-a
elif p>a:
    c=p-a
else:
    c=0
print(c)

import itertools

p = [0] * 4
p[0], p[1], p[2], p[3], a, b = map(int, input().split())

ans = 0
for i in range(a, b):
    valid = 0
    for perm in itertools.permutations(p):
        if i == i % p[0] % p[1] % p[2] % p[3]:
            valid += 1
    ans += valid >= 7
print(ans)

a,b,c,d,x,y=map(int,input().split())
if x>=min(a,b,c,d):
    print(0)
else:
    print(min(a,b,c,d)-x)

p1,p2,p3,p4,a,b = map(int,input().strip().split())
m=min(min(min(p1,p2),p3),p4)
if m<a:
    print(0)
else:
    print(m-a)

p1,p2,p3,p4,a,b = map(int,input().strip().split())
m=min(min(min(p1,p2),p3),p4)
if m<a:
    print(0)
else:
    print(m-a-(m-b))

# import itertools

# def q68a():
# 	p1, p2, p3, p4, low, high = tuple([int(num) for num in input().split()])
# 	p = list(itertools.permutations([p1, p2, p3, p4], 4))
# 	num_good = 0
# 	for i in range(low, high+1):
# 		count = 0
# 		for t in p:
# 			if(i == q68a_mod_operation(i, t[0], t[1], t[2], t[3])):
# 				count += 1
# 		if(count >= 7):
# 			num_good += 1
# 	print(num_good)

# def q68a_mod_operation(num, a, b, c, d):
# 	return (((num % a) % b) % c) % d

# q68a()

p1, p2, p3, p4, low, high = tuple([int(num) for num in input().split()])
min_p = min(p1, p2, p3, p4)
print(max(min_p - low, 0))