wa in gss1

problem: http://www.spoj.com/problems/GSS1/
solu = http://ideone.com/nlJ0ZK

//