def mul2x2(a, b, modulo):
    result = [[0, 0], [0, 0]]
for i in range(2):
    for j in range(2):
        for k in range(2):
            result[i][j] += a[i][k] * b[k][j]
result[i][j] %= modulo
return result

def pow(m, n, modulo):
    result = [[1, 0], [0, 1]]
while n:
    if n % 2:
        result = mul2x2(result, m, modulo)
m = mul2x2(m, m, modulo)
n //= 2
return result

def subsets(n):
    m = pow([[0, 1], [1, 1]], n, 524287)
return (m[0][0] + 2 * m[0][1]) % 524287
for i in range(1, 10):
    print(i, subsets(i))
for i in range(1, 20):
    pass
OverFlowError while solving "Number of subsets without consecutive numbers"