def checkRecord(self, n):
mod = 10 ** 9 + 7
P = 1
A = AL = ALL = L = LL = 0
for i in range(n):
A, P, AL, ALL, L, LL = sum((A, P, AL, LL, L, ALL)) % mod, sum((P, L, LL)) % mod, A, AL, P, L
return sum((A, P, AL, LL, L, ALL)) % mod
Python O(N) solution

almost same as my code, even with variable names ...
def checkRecord(self, n): a, aL, aLL, A, AL, ALL = 1, 0, 0, 0, 0, 0 for i in xrange(1, n+1): a, aL, aLL, A, AL, ALL = (a + aL + aLL) % 1000000007, a, aL, (a + aL + aLL + A + AL + ALL) % 1000000007, A, AL return (a+aL+aLL+A+AL+ALL) % 1000000007