Solution to the problem "The Indian Connection" from SPOJ (http://www.spoj.com/problems/DCEPC504/)