Moved to counting sort, problem solved