cswork / OAOpen practice workspace

RubrikOA #5

Word Compression (Remove k Consecutive Equal Characters)

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & HeapsStrings

Repeatedly delete any group of exactly K consecutive identical characters from the word until no further deletion is possible; the statement guarantees that at least one character remains at the end and states that the final result is unique.

Input

One line containing a lowercase ASCII word word and an integer K. This site adds 2≤K≤200000 and 2≤|word|≤200000. The input must be such that the result after compressing by the rules is non-empty (consistent with the original problem's guarantee).

Output

Output the word that remains at the end.

Example 1

Input:

abbbaac 3

Output:

c

Example 2

Input:

aaab 3

Output:

b

Example 3

Input:

abcd 2

Output:

abcd

Editorial

Loading solution…