from itertools import *
k=0
for x in product(sorted("0123456789abcdef"),repeat=5):
s=''.join(x)
if s[0]!="0" and ("1" in s or "4" in s or "9" in s):
if s.count("0")<=2 and s.count("1")<=2 and s.count("2")<=2 and s.count("3")<=2 and s.count("4")<=2 and s.count("5")<=2 and s.count("6")<=2 and s.count("7")<=2 and s.count("8")<=2 and s.count("9")<=2 and s.count("a")<=2 and s.count("b")<=2 and s.count("c")<=2 and s.count("d")<=2 and s.count("e")<=2 and s.count("f")<=2:
k+=1
print(k)