#P14015. [ICPC 2024 Nanjing R] 生日礼物
[ICPC 2024 Nanjing R] 生日礼物
Description
Grammy's birthday is approaching, and she gets a sequence from her friends as a gift. The sequence consists of only , , and . Grammy thinks that the sequence is too long, so she decides to modify to make it shorter.
Formally, Grammy can perform an arbitrary number of operations. Each time she can choose one of the following three operations to perform:
- Change any into or .
- Choose two adjacent s, erase them, and concatenate the rest of the parts.
- Choose two adjacent s, erase them, and concatenate the rest of the parts.
Calculate the minimum sequence length Grammy can get.
Input Format
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first and only line contains a string of length () consisting of digits , , and , indicating the initial sequence .
It is guaranteed that the sum of of all test cases will not exceed .
Output Format
For each test case, output one line containing one integer indicating the minimum sequence length Grammy can get.
5
0110101
01020102
0000021111
1012121010
0100202010
3
4
0
6
0
京公网安备 11011102002149号