Note that there can be at most 6326 different numbers among ai. Indeed, if there are at least 6327 distinct elements there, their sum is at least 0+1+…+6326=20005975>20000000.
So, for every element x of a count cnt[x] —