Under construction

Still being built. Things may change

Personality Test

Time limit3sMemory limit1024 MB

Summary
Find a pair of students a < b who gave identical answers to at least k common questions, choosing the smallest b then the largest a, or report -1.
Level

Medium6 of 10

Topics
Bit manipulation, String, Brute force
Solved
No attempts yet

Problem

There are nn students taking a personality test with mm questions. Students are numbered from 1 to nn, and questions are numbered from 1 to mm. For each question, a student either answers it with a single uppercase Latin letter (A to Z) or does not answer it. Let SiS_i be the string of mm characters for student ii. Its jj-th character is an uppercase letter if the student answered question jj, or a period (.) if not.

Two students are similar if there is a set of at least kk questions such that both students answered every question in the set, and for each question in the set they gave the same answer. For example, with n=3n = 3, m=3m = 3, k=2k = 2, S1S_1 = BBC, S2S_2 = ..C, and S3S_3 = .BC, students 1 and 3 are similar because they gave the same answers to questions 2 and 3. Students 2 and 3 are not similar because they share only one matching question (question 3).

You want to find a pair of integers (a,b)(a, b) with a<ba < b such that students aa and bb are similar, or determine that no such pair exists. If several pairs exist, pick the one with the smallest bb. If there is still a tie, pick the one with the largest aa.

Input

The first line contains three integers nn, mm, and kk (2≤n≤50002 \le n \le 5000, 1≤m≤30001 \le m \le 3000, 1≤k≤51 \le k \le 5). Each of the next nn lines contains a string of mm characters. The ii-th line contains the string SiS_i.

Output

Output one line containing the integers aa and bb for a similar pair, as described in the problem. If no such pair exists, output the integer -1.

Examples4

  1. Example 1

    Input
    3 3 2
    BBC
    ..C
    .BC
    
    Expected output
    1 3
    
  2. Example 2

    Input
    3 3 1
    BBC
    ..C
    .BC
    
    Expected output
    1 2
    
  3. Example 3

    Input
    3 3 3
    BBC
    ..C
    .BC
    
    Expected output
    -1
    
  4. Example 4

    Input
    4 12 2
    GOOD.LUCK.IN
    WINNING.ICPC
    ASIA.PACIFIC
    CHAMPIONSHIP
    
    Expected output
    2 3