http://www.spoj.com/problems/SNGPG/