cswork / OA打开练习工作台

JPMorgan ChaseOA #21

Substring Removal

估计中等可在线判题

考点(AI 标注)单调栈与堆字符串

Each step deletes one contiguous AB or BB and joins the two remaining sides. Find the minimum length after any number of operations.

输入格式

The first line contains the length n, and the second line contains the AB string; original bounds 1≤n≤200000.

输出格式

Output a single integer answer.

样例 1

输入:

5
BABBA

输出:

1

样例 2

输入:

3
ABB

输出:

1

样例 3

输入:

4
AAAA

输出:

4

样例说明

The outputs of the three public examples are, in order: 1; 1; 4. These answers have been checked by independent enumeration or direct simulation.