Solution to EDIST problem