CF1660C.Get an Even String

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A string a=a1a2ana=a_1a_2\dots a_n is called even if it consists of a concatenation (joining) of strings of length 22 consisting of the same characters. In other words, a string aa is even if two conditions are satisfied at the same time:

  • its length nn is even;
  • for all odd ii ( 1in11 \le i \le n - 1 ), ai=ai+1a_i = a_{i+1} is satisfied.

For example, the following strings are even: "" (empty string), "tt", "aabb", "oooo", and "ttrrrroouuuuuuuukk". The following strings are not even: "aaa", "abab" and "abba".

Given a string ss consisting of lowercase Latin letters. Find the minimum number of characters to remove from the string ss to make it even. The deleted characters do not have to be consecutive.

输入格式

The first line of input data contains an integer tt ( 1t1041 \le t \le 10^4 ) —the number of test cases in the test.

The descriptions of the test cases follow.

Each test case consists of one string ss ( 1s21051 \le |s| \le 2 \cdot 10^5 ), where s|s| — the length of the string ss . The string consists of lowercase Latin letters.

It is guaranteed that the sum of s|s| on all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, print a single number — the minimum number of characters that must be removed to make ss even.

输入输出样例

  • 输入#1

    6
    aabbdabdccc
    zyx
    aaababbb
    aabbcc
    oaoaaaoo
    bmefbmuyw

    输出#1

    3
    3
    2
    0
    2
    7

说明/提示

In the first test case you can remove the characters with indices 66 , 77 , and 99 to get an even string "aabbddcc".

In the second test case, each character occurs exactly once, so in order to get an even string, you must remove all characters from the string.

In the third test case, you can get an even string "aaaabb" by removing, for example, 44 -th and 66 -th characters, or a string "aabbbb" by removing the 55 -th character and any of the first three.

首页