------
## 最终结论
```python
def remove_duplicates(s: str, k: int) -> str:
    stack = []
    for char in s:
        if stack and stack[-1][0] == char:
            stack[-1][1] += 1
        else:
            stack.append([char, 1])
        
        if stack and stack[-1][1] == k:
            stack.pop()
    
    result = []
    for char, count in stack:
        result.append(char * count)
    return ''.join(result)

# Example usage
s1 = "abcd"
k1 = 2
print(remove_duplicates(s1, k1))  # Output: "abcd"

s2 = "deeedbbcccbdaa"
k2 = 3
print(remove_duplicates(s2, k2))  # Output: "aa"

s3 = "pbbcggttciiippooaais"
k3 = 2
print(remove_duplicates(s3, k3))  # Output: "ps"
```