SP21352 CLZBICYC - Avantgarde and Bicycle

Description

Mr.Avantgarde loves to ride his bicycle and visit all his CSI-DTU friends once in a while. His town is a N×N grid. He has to visit M friends marked by the letter 'F' .Empty land is marked with '.' .He is initially located at his house marked by 'S ' and after visiting all of his friends he will return to his home .He is allowed to move horizontally, vertically and diagonally to adjacent squares only. Additionally,each cell in a grid has some altitude and the tiredness associated with the whole trip is equal to the difference between highest altitude and the lowest altitude encountered in the whole trip. But Mr.Avantgarde is very lazy and wants you to calculate the minimum tiredness he can achieve in the whole trip. Input The first line of input contains an integer N (2

Input Format

N/A

Output Format

N/A