content: class TopVotedCandidate {
      List<List<Vote>> A;
      public TopVotedCandidate(int[] persons, int[] times) {
          A = new ArrayList();
          Map<Integer, Integer> count = new HashMap();
          for (int i = 0; i < persons.length; ++i) {
              int p = persons[i], t = times[i];
              int c = count.getOrDefault(p, 0) + 1;
  
              count.put(p, c);
              while (A.size() <= c)
                  A.add(new ArrayList<Vote>());
              A.get(c).add(new Vote(p, t));
          }
      }
  
      public int q(int t) {
          // Binary search on A[i][0].time for smallest i
          // such that A[i][0].time > t
          int lo = 1, hi = A.size();
          while (lo < hi) {
              int mi = lo + (hi - lo) / 2;
              if (A.get(mi).get(0).time <= t)
                  lo = mi + 1;
              else
                  hi = mi;
          }
          int i = lo - 1;
  
          // Binary search on A[i][j].time for smallest j
          // such that A[i][j].time > t
          lo = 0; hi = A.get(i).size();
          while (lo < hi) {
              int mi = lo + (hi - lo) / 2;
              if (A.get(i).get(mi).time <= t)
                  lo = mi + 1;
              else
                  hi = mi;
          }
          int j = Math.max(lo-1, 0);
          return A.get(i).get(j).person;
      }
  }
  
  class Vote {
      int person, time;
      Vote(int p, int t) {
          person = p;
          time = t;
      }
  }