This page is still under construction.

Parts of this page are still being built. What you see may change.

Bingo

Time limit1sMemory limit512 MB

Summary
Place one token in each column of an N x M matrix, minimizing first the spread of token counts across rows, then the largest token value.
Level

Medium7 of 10

Topics
Greedy, Binary search, Sorting, Implementation
Solved
No attempts yet

Problem

Consider the following game. You have an integer matrix of size N×MN \times M. Your task is to place MM tokens on cells of the matrix such that:

  1. each column contains exactly one token;
  2. the difference DrD_r between the maximum and minimum number of tokens in a row is as small as possible;
  3. among all such placements, you choose one where the maximum value written in a cell that holds a token is as small as possible.

Input

The first line contains two integers NN and MM (1≤N,M≤1101 \le N, M \le 110). Then the matrix aa follows: NN lines, each containing MM integers ai,ja_{i,j} (1≤ai,j≤1091 \le a_{i,j} \le 10^9).

Output

Print two integers that describe the placement you found: the minimum possible value of DrD_r and the minimum value written in a cell that holds a token, separated by a space.

Examples2

  1. Example 1

    Input
    3 3
    1 2 3
    2 1 2
    3 2 1
    
    Expected output
    0
    1
    
  2. Example 2

    Input
    3 5
    1 2 3 4 5
    5 4 3 2 1
    4 3 2 1 5
    
    Expected output
    1
    2