# Project Euler Problem 179
# Rose Olson
# 7/3/2014
#
# Result: 3D58725572C62302L
# Solve Time: 71ms
import Util_PESupport

def solve():
    return hex(getCombinations(16)).upper()[2:]

def getCombinations(i):
    return startRecur(i)

def startRecur(i):
    if(i ==0):
        return 0
    return (2)*recurSolve(i-1,2,14) + (13) * recurSolve(i-1,3,13)+ startRecur(i-1)

def recurSolve(digits_left, unused_symbols,free_symbols):
    if(digits_left == 0):
        if(unused_symbols ==0):
            return 1
        return 0
    return (free_symbols) * recurSolve(digits_left -1, unused_symbols,free_symbols) + (unused_symbols) * recurSolve(digits_left-1, unused_symbols-1,free_symbols + 1)

##Util_PESupport.testCase(getCombinations,3,4)
##Util_PESupport.testCase(getCombinations,4,4)

Util_PESupport.timedSolution(solve)
                for y in range(-1,2):
                    if(trap[m+y][n+x] == 1):
                        count +=1
            if(count >=2):
                trapTri[m-1][n] = count


    #Sum of triples
    result =0
    for n in range(1,i+1):
        if(trap[2][n] == 1):
            count = 0
            for x in range(-1,2):
                for y in range(-1,2):
                    if(trapTri[1+y][n+x] > 1):
                        count +=1
            if(count > 0):
                result += (i-1)*(i)/2+n

    return result


def solve():
    return str(solveRow(5678027) + solveRow(7208785))
#Test cases for verification
Util_PESupport.testCase(solveRow,8, 60)
Util_PESupport.testCase(solveRow,9, 37)
Util_PESupport.testCase(solveRow,10000, 950007619)
#Final Execution
Util_PESupport.timedSolution(solve)