4 public class database_gk
{
5 static BufferedReader in
;
6 static PrintWriter out
;
8 public void run() throws IOException
{
9 String l
= in
.readLine();
10 int n
= Integer
.parseInt(l
.split(" ")[0]);
11 int m
= Integer
.parseInt(l
.split(" ")[1]);
13 String
[][] values
= new String
[n
][];
14 for (int i
= 0; i
< n
; i
++) {
15 String line
= in
.readLine();
16 String
[] result
= new String
[m
];
18 for (int j
= 0; j
< m
- 1; j
++) {
19 int nindex
= line
.indexOf(',', index
);
20 result
[j
] = line
.substring(index
, nindex
);
23 result
[m
- 1] = line
.substring(index
);
27 Map
<String
, Integer
> intern
= new HashMap
<String
, Integer
>();
28 int[][] indices
= new int[n
][m
];
30 for (int i
= 0; i
< n
; i
++) {
31 for (int j
= 0; j
< m
; j
++) {
32 String value
= values
[i
][j
];
33 Integer index
= intern
.get(value
);
36 intern
.put(value
, index
);
38 indices
[i
][j
] = index
;
42 for (int c1
= 0; c1
< m
; c1
++) {
43 for (int c2
= c1
+ 1; c2
< m
; c2
++) {
44 long[] pairs
= new long[n
];
45 for (int r
= 0; r
< n
; r
++) {
46 pairs
[r
] = ((long) indices
[r
][c1
] * maxIndex
+ indices
[r
][c2
]) * n
+ r
;
49 for (int i
= 0; i
< n
- 1; i
++) {
50 if (pairs
[i
] / n
== pairs
[i
+ 1] / n
) {
52 out
.println((pairs
[i
] % n
+ 1) + " " + (pairs
[i
+ 1] % n
+ 1));
53 out
.println((c1
+ 1) + " " + (c2
+ 1));
62 public static void main(String
[] args
) throws Exception
{
63 in
= new BufferedReader(new FileReader("database.in"));
64 out
= new PrintWriter("database.out");
66 new database_gk().run();