Yes, this is a problem that requires careful specification. You only get streaming access to your input, not random.
Or more efficient, dynamically construct an implicit trie/heap type thing, where each leaf is the count of times that int appears (and the int itself is encoded in the location)
That feels really, really handwavy but promising?
You're right, that does sound impossible. :O