#!/usr/bin/env python3

import math, sys

# https://stackoverflow.com/questions/952914/how-do-i-make-a-flat-list-out-of-a-list-of-lists
def flatten(xss):
    return [x for xs in xss for x in xs]

def f1(size, first_digit):
    rt=0
    for i in range(0, 2**20):
        x0=(i>>0)&3
        x1=(i>>2)&3
        x2=(i>>4)&3
        x3=(i>>6)&3
        x4=(i>>8)&3
        x5=(i>>10)&3
        x6=(i>>12)&3
        x7=(i>>14)&3
        x8=(i>>16)&3
        x9=(i>>18)&3

        if first_digit==1 and x1==3:
            continue
        if first_digit==2 and x2==3:
            continue
        if first_digit==3 and x3==3:
            continue
        if first_digit==4 and x4==3:
            continue
        if first_digit==5 and x5==3:
            continue
        if first_digit==6 and x6==3:
            continue
        if first_digit==7 and x7==3:
            continue
        if first_digit==8 and x8==3:
            continue
        if first_digit==9 and x9==3:
            continue
    
        #print (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9)
    
        tmp=[]
    
        tmp.append([0]*x0)
        tmp.append([1]*x1)
        tmp.append([2]*x2)
        tmp.append([3]*x3)
        tmp.append([4]*x4)
        tmp.append([5]*x5)
        tmp.append([6]*x6)
        tmp.append([7]*x7)
        tmp.append([8]*x8)
        tmp.append([9]*x9)
        tmp=flatten(tmp)
        if len(tmp)!=size:
            continue
        print (tmp)
        t=math.factorial(x0)
        t=t*math.factorial(x1)
        t=t*math.factorial(x2)
        t=t*math.factorial(x3)
        t=t*math.factorial(x4)
        t=t*math.factorial(x5)
        t=t*math.factorial(x6)
        t=t*math.factorial(x7)
        t=t*math.factorial(x8)
        t=t*math.factorial(x9)
        to_add=int(math.factorial(size)/t)
        print ("f1, to_add", to_add)
        rt+=to_add
    return rt

size=int(sys.argv[1])

rt_=0
for first_digit in range(1, 9+1):
    # as if first digit is...
    rt_+=f1(size-1, first_digit)
print (f"{rt_=}")

