C # implementation of the approach
using System ; using System . Collections . Generic ; class GFG { static int n = 3 ; public class Pair { public int first , second ; public Pair ( int a , int b ) { first = a ; second = b ; } }