public static void main(String[] args) {
    List<String> A = Arrays.asList("foo", "bar", "widget", "foo", "widget", "widget", "adnan");
    assert(check_answer(A) == find_nearest_repetition(A));
    A = Arrays.asList("foo", "bar", "widget", "foo", "xyz", "widget", "bar", "adnan");
    assert(check_answer(A) == find_nearest_repetition(A));
    A = Arrays.asList("foo", "bar", "widget", "adnan");
    assert(check_answer(A) == find_nearest_repetition(A));
    A = Arrays.asList();
    assert(check_answer(A) == find_nearest_repetition(A));
    A = Arrays.asList("foo", "foo", "foo");
    assert(check_answer(A) == find_nearest_repetition(A));
    Random rnd = new Random();
    for (int times = 0; times < 1000; ++times) {
      int n = 0;
      if (args.length == 1) {
        n = Integer.parseInt(args[0]);
      } else {
        n = rnd.nextInt(10000) + 1;
      }
      List<String> s = new ArrayList<String>();
      for (int i = 0; i < n; ++i) {
        s.add(rand_String(rnd.nextInt(10) + 1));
      }
      assert(check_answer(s) == find_nearest_repetition(s));
    }
  }