PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000417. Bài toán cực đại hóa cực tiểu (Minimax Problem)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bài toán cực đại hóa cực tiểu (Minimax Problem)

Minimax Problem

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given an nn by mm matrix, choose row indices i,ji,j, possibly equal. Define bc=max⁡(ai,c,aj,c)b_c=\max(a_{i,c},a_{j,c}). Find a pair maximizing the smallest component of bb.

Input

The first line contains n,mn,m. Each of the next nn lines contains mm integers representing one row.

Output

Print any optimal pair of row indices (1-based). The indices may coincide.

Subtasks

  • Subtask 1 (20 points): 1≤n≤501\le n\le 50; 1≤m≤81\le m\le8; 0≤ai,c≤1090\le a_{i,c}\le10^9 (1≤i≤n1\le i\le n, 1≤c≤m1\le c\le m).
  • Subtask 2 (30 points): 1≤n≤50001\le n\le 5000; 1≤m≤81\le m\le8; 0≤ai,c≤1090\le a_{i,c}\le10^9 (1≤i≤n1\le i\le n, 1≤c≤m1\le c\le m).
  • Subtask 3 (50 points): 1≤n≤3000001\le n\le 300000; 1≤m≤81\le m\le8; 0≤ai,c≤1090\le a_{i,c}\le10^9 (1≤i≤n1\le i\le n, 1≤c≤m1\le c\le m).

Examples

Example 1

Input

6 5
5 0 3 1 2
1 8 9 1 3
1 2 3 4 5
9 1 0 3 7
2 3 0 6 3
6 4 1 7 0

Output

1 5

Explanation

Rows 1 and 5 yield b=[5,3,3,6,3]b=[5,3,3,6,3] and score 3. At threshold 4 only row 2 covers column 3; no row covers all its missing columns 1,4,5.