Sam zobacz i poczytaj i może to Cię zainteresuje? : http://discuss.spoj.com/t/ip2location-programming-contest-2017/24063