POJ-1002, this solution shall cause TLE, it would be thankful if someone could fix it for me