Loop to find the occurrences of x and update the ans
for ( long long i = 0 ; i < y . size ( ) ; i ++ ) { if ( y [ i ] == x ) { ans += ( modInv ( fact [ i ] ) * modInv ( fact [ y . size ( ) - i - 1 ] ) ) % MOD ; ans %= MOD ; } }