from functools import reduce

def conbine(n, m):
    return reduce(lambda x, y: x // y, range(m, 1, -1),
            reduce(lambda x, y: x * y, range(n, n - m, -1), 1))

def gen_array(length):
    for i in range(1, length - 1):
        for j in range(1, length - i):
            yield i, j, length - i - j

def calc(limit):
    total = 0
    for length in range(3, limit + 1):
        for same in range(3, length + 1):
            total += sum(map(lambda x:
                            conbine(length - 1   , x[0]) *
                            conbine(length - x[0], x[1]) *
                            conbine(length - x[0] - x[1], x[2]) *
                            (limit - 3) ** (length - same),
                            gen_array(same)
                        ))
    return hex(total).upper()[2:]

print(calc(16))