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