Pair class
class Pair implements Comparable < Pair > { int first ; int second ; public Pair ( int first , int second ) { this . first = first ; this . second = second ; } @ Override public int compareTo ( Pair o ) { return second - o . second ; } }