PAT 1055: solved with K-D tree, but timeout in two cases