Java program for the above problem
import java . util . * ; import java . lang . * ; class GFG { static class pair { int first , second ; pair ( int f , int s ) { this . first = f ; this . second = s ; } }