### Please also check out other katas in [Domino Tiling series](https://www.codewars.com/collections/5d19554d13dba80026a74ff5)!
---
# Task
A domino is a rectangular block with `2` units wide and `1` unit high. A domino can be placed on a grid in two ways: horizontal or vertical.
```
## or #
      #
```
You have infinitely many dominoes, and you want to fill a board that is `2*N` units wide and `5` units high:
```
<---   2N   --->
################
################
################
################
################
```
The task is to find **the number of ways** you can fill the given grid with dominoes.
Since the answer will be very large, please give your answer **modulo 12345787**.
# Examples
```python
five_by_2n(1) == 8
five_by_2n(2) == 95
five_by_2n(3) == 1183
five_by_2n(5) == 185921
five_by_2n(10) == 8228892
five_by_2n(20) == 9942990
five_by_2n(50) == 2308182
five_by_2n(100) == 334896
five_by_2n(1000) == 6032838
five_by_2n(10000) == 2392948
```
# Constraints
`1 <= N <= 10000`
All inputs are valid integers.
# Hint
The reference solution uses eleven mutual recurrence equations.
a=[3];b=[1];c=[2];d=[1];e=[2];f=[3];g=[1];h=[1];i=[1];j=[8]

for _ in range(10000):
    next_a = 3*a[-1] + b[-1] + e[-1] + f[-1] + h[-1] + i[-1] + 3*j[-1]
    next_b = a[-1] + 2*b[-1] + e[-1] + i[-1] + j[-1]
    next_c = 2*c[-1] + d[-1] + f[-1] + g[-1] + 2*j[-1]
    next_d = c[-1] + 2*d[-1] + f[-1] + g[-1] + j[-1]
    next_e = a[-1] + b[-1] + 2*e[-1] + i[-1] + 2*j[-1]
    next_f = a[-1] + c[-1] + d[-1] + 3*f[-1] + g[-1] + h[-1] + 3*j[-1]
    next_g = c[-1] + d[-1] + f[-1] + g[-1] + j[-1]
    next_h = a[-1] + f[-1] + h[-1] + j[-1]
    next_i = a[-1] + b[-1] + e[-1] + i[-1] + j[-1]
    next_j = 3*a[-1] + b[-1] + 2*c[-1] + d[-1] + 2*e[-1] + 3*f[-1] + g[-1] + h[-1] + i[-1] + 8*j[-1]
    a.append(next_a%12345787)
    b.append(next_b%12345787)
    c.append(next_c%12345787)
    d.append(next_d%12345787)
    e.append(next_e%12345787)
    f.append(next_f%12345787)
    g.append(next_g%12345787)
    h.append(next_h%12345787)
    i.append(next_i%12345787)
    j.append(next_j%12345787)
    
def five_by_2n(n):
    return j[n-1]
a=[3];b=[1];c=[2];d=[1];e=[2];f=[3];g=[1];h=[1];i=[1];j=[8]

for _ in range(10000):
    next_a = 3*a[-1] + b[-1] + e[-1] + f[-1] + h[-1] + i[-1] + 3*j[-1]
    next_b = a[-1] + 2*b[-1] + e[-1] + i[-1] + j[-1]
    next_c = 2*c[-1] + d[-1] + f[-1] + g[-1] + 2*j[-1]
    next_d = c[-1] + 2*d[-1] + f[-1] + g[-1] + j[-1]
    next_e = a[-1] + b[-1] + 2*e[-1] + i[-1] + 2*j[-1]
    next_f = a[-1] + c[-1] + d[-1] + 3*f[-1] + g[-1] + h[-1] + 3*j[-1]
    next_g = c[-1] + d[-1] + f[-1] + g[-1] + j[-1]
    next_h = a[-1] + f[-1] + h[-1] + j[-1]
    next_i = a[-1] + b[-1] + e[-1] + i[-1] + j[-1]
    next_j = 3*a[-1] + b[-1] + 2*c[-1] + d[-1] + 2*e[-1] + 3*f[-1] + g[-1] + h[-1] + i[-1] + 8*j[-1]
    a.append(next_a%12345787)
    b.append(next_b%12345787)
    c.append(next_c%12345787)
    d.append(next_d%12345787)
    e.append(next_e%12345787)
    f.append(next_f%12345787)
    g.append(next_g%12345787)
    h.append(next_h%12345787)
    i.append(next_i%12345787)
    j.append(next_j%12345787)
    
def five_by_2n(n):
    return j[n-1]