Comparator to sort the array in ascending order
class Pair implements Comparable < Pair > { int first , second ; Pair ( int x , int y ) { first = x ; second = y ; } public int compareTo ( Pair p ) { return p . first - first ; } } class GFG {