Driver code
public static void main ( String args [ ] ) { int a [ ] = { 1 , 1 , 2 , 2 , 2 , 3 } ; int n = a . length ; pair queries [ ] = new pair [ 5 ] ; queries [ 0 ] = new pair ( 0 , 4 ) ; queries [ 1 ] = new pair ( 1 , 2 ) ; queries [ 2 ] = new pair ( 2 , 5 ) ; queries [ 3 ] = new pair ( 2 , 3 ) ; queries [ 4 ] = new pair ( 2 , 4 ) ; int q = queries . length ; int k = 3 ; System . out . println ( getFinalSum ( a , n , queries , q , k ) ) ; } }