Solution of SPOJ problem(Triple Fat ladies) -http://www.spoj.com/problems/EIGHTS/