# -*- coding: utf-8 -*-
# @Author: Gillett Hernandez
# @Date:   2017-10-06 17:57:02
# @Last Modified by:   Gillett Hernandez
# @Last Modified time: 2017-10-06 18:33:00

from euler_funcs import timed
import sympy as sp

def coef(n,i):
    l = [n*i]
    l.extend([i]*(n-1))
    l[i-1]+=1
    l = l[1:] + [l[0]]
    return l

def doit(n):
    lofl = []
    for i in range(2,n+1):
        lofl.append(coef(n,i))

    sol = sp.Matrix(lofl).rref()
    arr = sol[0][n-1::n]
    missing = n - sum(arr)
    return [missing] + arr

def _P(*args):
    p = 1
    for i,a in enumerate(args):
        p *= a**(i+1)
    return p

def P(n):
    return int(_P(*doit(n)))

@timed
def main():
    print(sum(P(i) for i in range(2,16)))


if __name__ == '__main__':
    main()
