Store each element of Array [ ] with their count
List < Pair > element = new List < Pair > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Pair x = new Pair ( Array [ i ] , count_Arr [ i + 1 ] ) ; element . Add ( x ) ; } int start = 1 ; for ( int i = 0 ; i < N ; i ++ ) { int end = start + element [ 0 ] . getSecond ( ) - 1 ;