Grid Coloring
문제
President K is designing a pattern represented by a grid with rows and columns. To achieve this, he has decided to paint each cell with a color represented by an integer number. Let us refer to the cell in the -th row (1 ≤ i ≤ N) and -th column (1 ≤ j ≤ N) as cell .
Currently, the cells in the first column and first row are already painted. Specifically, cell (1 ≤ i ≤ N) is painted with color and cell (1 ≤ j ≤ N) is painted with color . Note that .
For the remaining unpainted cells, President K is going to paint them by the following procedure:
- For each in order, paint the cells in the -th row as follows:
- For each in order, paint cell with the color that has the larger number between:
- The color of cell , and
- The color of cell (i, j − 1).
- If both colors have the same number, paint the cell with that color.
- For each in order, paint cell with the color that has the larger number between:
President K would like to determine the color that is painted on the largest number of cells after all cells have been painted, as well as the number of cells painted with that color.
Write a program that, given the size of the grid and the color information for the first column and first row, determines the color number painted on the largest number of cells and the number of cells painted with that color. If multiple colors are painted on the largest number of cells, output the largest color number among them.
입력
Read the following data from the standard input.
출력
Write one line to the standard output containing two integers separated by a space:
- The color number that is painted on the largest number of cells, and
- The number of cells painted with that color.
If multiple colors are painted on the largest number of cells, output the largest color number among them.
예제
예제 1
3 5 2 5 5 3 1
5 4
예제 2
3 1 7 8 1 3 5
8 3
예제 3
4 2 1 2 1 2 1 1 2
2 10