Follow up for "Remove Duplicates": What if duplicates are allowed at most twice?