Calculate pairs of similar rectangles from its common ratio
for ( double key : ratio . keySet ( ) ) { int val = ratio . get ( key ) ; if ( val > 1 ) { res += ( val * ( val - 1 ) ) / 2 ; } } return res ; }