eolymp
bolt
Try our new interface for solving problems
Problems

Happy Birthday!!!

Happy Birthday!!!

The cat Sonya's birthday is at the end of March. Just when all the cats and their girlfriends like to walk. Sonya has \textbf{k} friends, and they all want to congratulate her. To do this, Sonya decided to collect all of them in one place, then to go somewhere for a walk. Sonya loves her friends, therefore, she wants to choose a meeting place so that the sum of the distances traveled by her friends to this place, is minimal. Since Sonya enjoys programming contests, she decided to do this task harder, making the space \textbf{n}-dimensional. Let the distance between the point (\textbf{x_1}, \textbf{x_2}, …, \textbf{x_n}) and the point (\textbf{y_1}, \textbf{y_2}, …, \textbf{y_n}) be the amount of (\textbf{|x_1-y_1| + |x_2-y_2| + } … \textbf{|x_n-y_n|}). \InputFile In the first row you are given two numbers: \textbf{k} (\textbf{1 }≤ \textbf{k} ≤ \textbf{150000}) and \textbf{n} (\textbf{1 }≤ \textbf{n} ≤ \textbf{10}). Each of the next \textbf{k} lines contains \textbf{n} integers - the coordinates of the location of the current Sonya's friend. The absolute value of each coordinate do not exceed \textbf{50000}. \OutputFile Print the coordinates of the optimal place for a meeting. Follow the format of the output shown in the example. If there are several such points, output the one with the less first coordinate. If the first coordinates are equal compare the second, and so on. Then, output a single number - the total distance traveled by Sonya's friends.
Time limit 1 second
Memory limit 122.17 MiB
Input example #1
4 2
1 5
2 1
4 7
7 2
Output example #1
(2,2) 17
Author Борис Соколов
Source Дистанционная Летняя Компьютерная Школа - лето 2013 года