Increment answer by count of current element of prefix array
if ( mp . containsKey ( pref [ i ] ) ) { answer += mp . get ( pref [ i ] ) ; mp . put ( pref [ i ] , mp . get ( pref [ i ] ) + 1 ) ; } else { mp . put ( pref [ i ] , 1 ) ; } }