'''
Created on Oct 8, 2012

@author: ola
'''
def isfortunate(n):
    s = str(n)
    if s.count('5') + s.count("8") == len(s):
        return True
    return False

def getFortunate(a,b,c):
    s = 0
    nums = []
    for i in a:
        for j in b:
            for k in c:
                total = i + j + k
                if isfortunate(total) and total not in nums:
                    s = s + 1
                nums.append(total)
    return s

print isfortunate(55)
print isfortunate(58585858)
print isfortunate(585858581)