Fill prefix array
for ( int i = 1 ; i <= N ; i ++ ) { prefix_a [ i ] = prefix_a [ i - 1 ] + ( int ) ( ( str . charAt ( i - 1 ) == ' a ' ) ? 1 : 0 ) ; prefix_b [ i ] = prefix_b [ i - 1 ] + ( int ) ( ( str . charAt ( i - 1 ) == ' b ' ) ? 1 : 0 ) ; prefix_c [ i ] = prefix_c [ i - 1 ] + ( int ) ( ( str . charAt ( i - 1 ) == ' c ' ) ? 1 : 0 ) ; }