count the B ( blue ) colour
for ( char c : color ) { if ( c == ' B ' ) Blue_Count ++ ; } for ( char c : color ) { if ( c == ' B ' ) Blue_Count -- ; if ( c == ' R ' ) Red_Count ++ ; if ( c == ' G ' ) result += Red_Count * Blue_Count ; } return result ; }