// @EXPECTED_RESULTS@: ACCEPTED, TIME_LIMIT_EXCEEDED import java.util.*; public class MikeTranscribedScanner { private static final long BASE = 1000000007; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int L = (int) Math.sqrt(n); List> sets = new ArrayList<>(); for (int i = 0; i < n; i++) { int k = scanner.nextInt(); List set = new ArrayList<>(); for (int j = 0; j < k; j++) { set.add(scanner.nextInt()); // This is slow. } sets.add(set); } Map pairs = new HashMap<>(); for (int i = 0; i < n; i++) { if (sets.get(i).size() <= L) { Collections.sort(sets.get(i)); for (int j1 = 0; j1 < sets.get(i).size(); j1++) { for (int j2 = j1 + 1; j2 < sets.get(i).size(); j2++) { long x = sets.get(i).get(j1) + BASE * sets.get(i).get(j2); if (pairs.containsKey(x)) { System.out.println(sets.get(i).get(j1) + " " + sets.get(i).get(j2) + " " + (pairs.get(x) + 1) + " " + (i + 1)); return; } pairs.put(x, i); } } } else { Set xs = new HashSet<>(sets.get(i)); for (int j = 0; j < n; j++) { if (i != j) { List overlap = new ArrayList<>(); for (Integer x : sets.get(j)) { if (xs.contains(x)) { overlap.add(x); } } if (overlap.size() >= 2) { System.out.println(overlap.get(0) + " " + overlap.get(1) + " " + (j + 1) + " " + (i + 1)); return; } } } } } System.out.println("impossible"); } }