import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.stream.Collectors; /** * Created by tym12 on 10/22/16. */ public class Tribune { /* public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { String line; while ((line = reader.readLine()) != null){ int n = Integer.parseInt(line); ArrayList all = new ArrayList<>(n); ArrayList sorted = new ArrayList<>(n); for (int i = 0; i < n; i++) { String next = reader.readLine(); all.add(next); char[] chars = next.toCharArray(); Arrays.sort(chars); sorted.add(new String(chars)); } String first = sorted.get(0); String second = sorted.get(1); if (first.equals(second)) { // hledame chybny for (int i = 2; i < n; i++) { String next = sorted.get(i); if (!next.equals(first)) { printdiff(first, next, i, all); } } } else { // jeden z nich je chybny String third = sorted.get(2); if (first.equals(third)) { // chybny je 2 printdiff(first, second, 1, all); } else { // chybny je 1 printdiff(second, first, 0, all); } } } } catch (IOException e) { } } private static void printdiff(String good, String bad, int badid, ArrayList all) throws IOException { Set uniques = uniques(bad, good); Iterator iterator = uniques.iterator(); if (!iterator.hasNext()) throw new IOException(); char diff = iterator.next(); Set uniques2 = uniques(good, bad); Iterator iterator1 = uniques2.iterator(); if (!iterator1.hasNext()) throw new IOException(); char d = iterator1.next(); System.out.println((badid +1) + " " + (all.get(badid).indexOf(diff) + 1) + " " + d); } private static Set uniques(String first, String second) { Set a = first.chars().mapToObj(c -> (char) c).collect(Collectors.toSet()); Set b = second.chars().mapToObj(c -> (char) c).collect(Collectors.toSet()); a.removeAll(b); return a; } /**/ public static void main(String[] args) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String nrS; try { do { ArrayList gr = new ArrayList<>(); ArrayList chars = new ArrayList<>(); nrS= bufferedReader.readLine(); int n = Integer.parseInt(nrS); for (int i= 0; i < n; i++) { String l = bufferedReader.readLine(); gr.add(l); char[] line = l.toCharArray(); Arrays.sort(line); chars.add(line); } char[] correct = findCorrect(chars); char bad = 0; char good = 0; for (int i = 0; i < n; i++) { if (!Arrays.equals(chars.get(i), correct)) { Set s = uniques(gr.get(i),new String(correct)); for (char c :s) { bad = c; break; } Set g = uniques(new String(correct),gr.get(i)); for (char c :g) { good = c; break; } if (s.isEmpty() && !g.isEmpty()) { int ix = Arrays.toString(chars.get(i)).indexOf(bad); if (ix != -1) { System.out.println((i + 1) + " " + (gr.get(i).indexOf(chars.get(i)[ix]) + 1) + " " + bad); } } System.out.println((i+1)+" "+(gr.get(i).indexOf(bad)+1)+" "+good); break; } } } while(nrS != null); } catch (IOException e) { // } } private static char[] findCorrect(ArrayList chars) { char[] line = chars.get(0); //for (int i = 1; i < chars.size(); i++) { if (line.equals(chars.get(1))) return line; //if (i == 2) return chars.get(2); } //return line; } private static Set uniques(String first, String second) { Set a = first.chars().mapToObj(c -> (char) c).collect(Collectors.toSet()); Set b = second.chars().mapToObj(c -> (char) c).collect(Collectors.toSet()); a.removeAll(b); return a; } // */ }