Maximum of sum of length of rectangles and squares formed by given sticks |  ; Function to find the maximum of sum of lengths of rectangles and squares formed using given set of sticks ; Stores the count of frequencies of all the array elements ; Stores frequencies which are at least 2 ; Convert all frequencies to nearest smaller even values . ; Sum of elements up to index of multiples of 4 ; Print the sum ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void findSumLength ( List < int > arr , int n ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; foreach ( int i in arr ) { if ( freq . ContainsKey ( i ) ) freq [ i ] += 1 ; else freq [ i ] = 1 ; } Dictionary < int , int > freq_2 = new Dictionary < int , int > ( ) ; foreach ( KeyValuePair < int , int > entry in freq ) { if ( freq [ entry . Key ] >= 2 ) freq_2 [ entry . Key ] = freq [ entry . Key ] ; } List < int > arr1 = new List < int > ( ) ; foreach ( KeyValuePair < int , int > entry in freq_2 ) arr1 . Add ( entry . Key * ( freq_2 [ entry . Key ] / 2 ) * 2 ) ; arr1 . Sort ( ) ; int summ = 0 ; foreach ( int i in arr1 ) { summ += i ; } Console . WriteLine ( summ ) ; } public static void Main ( ) { List < int > arr = new List < int > ( ) { 5 , 3 , 2 , 3 , 6 , 4 , 4 , 4 , 5 , 5 , 5 } ; int n = arr . Count ; findSumLength ( arr , n ) ; } }