SPOJ prob SEQ using matrix exponentiation