Java program for the above approach
import java . util . * ; public class GFG { static class pair { int first , second , third ; pair ( int first , int second , int third ) { this . first = first ; this . second = second ; this . third = third ; } }