C # implementation of the approach
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static int next_pos = 1 ; public class pair { public int first , second ; public pair ( ) { first = 0 ; second = 0 ; } } class sortHelper : IComparer { int IComparer . Compare ( object a , object b ) { pair first = ( pair ) a ; pair second = ( pair ) b ; return first . first < second . first ? - 1 : 1 ; } }