Markov chain based solution for 367 (runs in 4mins).