#abc328d. D - Take ABC

D - Take ABC

Score : 425425 points

问题描述

你将得到一个由三个不同字符组成的字符串 SSABC

只要 SS 中包含连续子串 ABC,就重复执行以下操作:

SS 中移除最左边出现的子串 ABC

在执行上述过程后,打印最终的字符串 SS

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a string SS consisting of three different characters: A, B, and C.

As long as SS contains the string ABC as a consecutive substring, repeat the following operation:

Remove the leftmost occurrence of the substring ABC from SS.

Print the final string SS after performing the above procedure.

Constraints

  • SS is a string of length between 11 and 2×1052 \times 10^5, inclusive, consisting of the characters A, B, and C.

Input

The input is given from Standard Input in the following format:

SS

Output

Print the answer.

Sample Input 1

BAABCBCCABCAC

Sample Output 1

BCAC

For the given string S=S = BAABCBCCABCAC, the operations are performed as follows.

  • In the first operation, the ABC from the 33-rd to the 55-th character in S=S = BAABCBCCABCAC is removed, resulting in S=S = BABCCABCAC.
  • In the second operation, the ABC from the 22-nd to the 44-th character in S=S = BABCCABCAC is removed, resulting in S=S = BCABCAC.
  • In the third operation, the ABC from the 33-rd to the 55-th character in S=S = BCABCAC is removed, resulting in S=S = BCAC.

Therefore, the final SS is BCAC.

Sample Input 2

ABCABC

Sample Output 2

In this example, the final SS is an empty string.

Sample Input 3

AAABCABCABCAABCABCBBBAABCBCCCAAABCBCBCC

Sample Output 3

AAABBBCCC

update @ 2024/3/10 01:52:49