Hmm, I mentioned a possibility of using a bit field and lookup table in conjunction. Basically if we have this list:
[1, 3, 4, 6, 10]
we will make this bitfield:
[1, 0, 1, 1, 0, 1, 0, 0, 0, 1]. This bitfield, "1011010001" = 721. In the look up table, you'd have n! entries, where each entry is a possible value for the bit field. As you can guess this is growing very large very fast, so it's not very good either. Anyways, from the look up table, we'll have an entry like this:
struct table_entry {
u32 value;
int x[];
};
then we do something like
list = []
for (int n : x) {
for (int i = 0; i < original_list[n's position]; i++) {
list.append

;
}
}
return list;
---
I don't think even this is a very good idea. It's speed is linear and depending on the length of the list, BUT, it's requiring a lookup table. Look up tables take space and this look up table would grow fast.