Getting TLE on cf Natsya and scoreboard, please HELP!

My DP solution of the problem Natsya and scoreboard is getting TLE and i don’t know why, please help !!

The main logic is, i am checking arr[i] with hashes[j] where(j = 9, 8, 7, …, 0) in decreasing order of j,
if, arr[i] & hashes[j] == arr[i] it means it is possible to make hashes[j] from arr[i], and the number of sticks used will be the difference of number of set bits in arr[i] and hashes[j] (difference of popcount)