Main Search Cum Distance Compilation