https://www.spoj.com/problems/DEFKIN/