eolymp
bolt
Try our new interface for solving problems

Ministry

Mr. F. wants to get a document be signed by a minister. A minister signs a document only if it is approved by his ministry. The ministry is an \textbf{M}-floor building with floors numbered from \textbf{1 }to \textbf{M }(\textbf{1 }≤ \textbf{M }≤ \textbf{100}). Each floor has \textbf{N }rooms (\textbf{1 }≤ \textbf{N }≤ \textbf{500}) also numbered from \textbf{1 }to \textbf{N}. In each room there is one (and only one) official. A document is approved by the ministry only if it is signed by at least one official from the \textbf{M}-th floor. An official signs a document only if at least one of the following conditions is satisfied: \begin{itemize} \item the official works on the \textbf{1}-st floor; \item the document is signed by the official working in the room with the same number but situated one floor below; \item the document is signed by an official working in a neighbouring room (rooms are neighbouring if they are situated on the same floor and their numbers differ by one). \end{itemize} Each official collects a fee for signing a document. The fee is a positive integer not exceeding \textbf{10^9}. You should find the cheapest way to approve the document. \InputFile The first line contains two integers, separated by space. The first integer \textbf{M }represents the number of floors in the building, and the second integer \textbf{N }represents the number of rooms per floor. Each of the next \textbf{M }lines contains \textbf{N }integers separated with spaces that describe fees (the \textbf{k}-th integer at \textbf{l}-th line is the fee required by the official working in the \textbf{k}-th room at the \textbf{l}-th floor). \OutputFile You should print the numbers of rooms in the order they should be visited to approve the document in the cheapest way. If there are more than one way leading to the cheapest cost you may print an any of them.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB

Şərh: You can assume that for each official there always exists a way to get the approval of a document (from the 1st floor to this official inclusively) paying no more than 10^9.

Müəllif Evgeniy Frolov
Mənbə 1999 III Ural Collegiate Programming Contest, Ekaterinburg, March 19 - 20, Problem B