def frag(x): out = [] for i in xrange(1, x - 1): for j in xrange(1, x - i): out.append((i, j, x - i - j)) return out def C(n, m): total = 1 for i in xrange(n, n - m, -1): total *= i for i in xrange(m, 1, -1): total /= i return total total = 0 for length in xrange(3, 17): for same in xrange(3, length + 1): for (x,y,z) in frag(same): total += C(length - 1, x) * C(length - x, y) * C(length - x - y, z) * 13 ** (length - same) print '%X' % total