Algorithm


B1. Wonderful Coloring - 1
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This is a simplified version of the problem B2. Perhaps you should read the problem B2 before you start solving B1.

Paul and Mary have a favorite string s which consists of lowercase letters of the Latin alphabet. They want to paint it using pieces of chalk of two colors: red and green. Let's call a coloring of a string wonderful if the following conditions are met:

  1. each letter of the string is either painted in exactly one color (red or green) or isn't painted;
  2. each two letters which are painted in the same color are different;
  3. the number of letters painted in red is equal to the number of letters painted in green;
  4. the number of painted letters of this coloring is maximum among all colorings of the string which meet the first three conditions.

E. g. consider a string s equal to "kzaaa". One of the wonderful colorings of the string is shown in the figure.

The example of a wonderful coloring of the string "kzaaa".

Paul and Mary want to learn by themselves how to find a wonderful coloring of the string. But they are very young, so they need a hint. Help them find k — the number of red (or green, these numbers are equal) letters in a wonderful coloring.

Input

The first line contains one integer t (1t10001≤�≤1000) — the number of test cases. Then t test cases follow.

Each test case consists of one non-empty string s which consists of lowercase letters of the Latin alphabet. The number of characters in the string doesn't exceed 5050.

Output

For each test case, output a separate line containing one non-negative integer k — the number of letters which will be painted in red in a wonderful coloring.

Example
input
Copy
5
kzaaa
codeforces
archive
y
xxxxxx
output
Copy
2
5
3
0
1
Note

The first test case contains the string from the statement. One of the wonderful colorings is shown in the figure. There's no wonderful coloring containing 33 or more red letters because the total number of painted symbols will exceed the string's length.

The string from the second test case can be painted as follows. Let's paint the first occurrence of each of the letters "c", "o", "e" in red and the second ones in green. Let's paint the letters "d", "f" in red and "r", "s" in green. So every letter will be painted in red or green, hence the answer better than 55 doesn't exist.

The third test case contains the string of distinct letters, so you can paint any set of characters in red, as long as the size of this set doesn't exceed half of the size of the string and is the maximum possible.

The fourth test case contains a single letter which cannot be painted in red because there will be no letter able to be painted in green.

The fifth test case contains a string of identical letters, so there's no way to paint more than one letter in red.

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  cin>>t;
  string s;
  int cnt[26];
  while(t--){
    cin>>s;
    memset(cnt, 0, sizeof(cnt));
    for(auto c : s) cnt[c - 'a']++;
    int cnt1 = 0;
    int cnt2 = 0;
    for(auto i : cnt){
      if(i == 1) cnt1++;
      else if(i > 1) cnt2++;
    }
    cout<<(cnt2 + cnt1/2)<<endl;
  }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5
kzaaa
codeforces
archive
y
xxxxxx

Output

x
+
cmd
2
5
3
0
1
Advertisements

Demonstration


Codeforcess Solution 1551-B1 B1. Wonderful Coloring - 1 ,C++, Java, Js and Python,551-B1,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+