ACMPRAC2 - Entrée

no tags 

Master Bates is a ravenous eater; due to his monstrous eating habits he is having some difficulties in performing. Dr. XXX has asked him to cut down on his intake. The doctor has prescribed the number of meals he can have in a day. Now Bates has got ‘k’ different varieties of foods (1 <= k <= 26) and he can have at most ‘m’ meals in a day (1 <= m <= 100) as prescribed by the doctor. Each variety of food is specified by a letter of the alphabet in lower case. A meal is defined as a string of contiguous characters of same type i.e. all the characters in the substring should be the same. Master Bates wants to eat as much as possible in his ‘m’ meals. Assuming each letter is 1 unit of food. What is the maximum amount he can consume?

Input

First line of input is the number of test cases (not more than 100). Each test case consists of 2 lines, first line of each case consists of an integer m (1 <= m <= 100).

Second line of each case consists of a string describing the food that he has for the day. There will be at most 100000 (10^5) characters in the string.

Output

Output one integer indicating the maximum amount of food he can consume.

Example

Input:
4
2
aaaabbaaaa
3
aabbbcccaaddddaaeeeee
5
abcde
1
aaaaabcde

Output:
8
12
5
5

hide comments
:D: 2012-09-09 18:19:40

Moved to tutorial. Not only is it very basic, but we already have very similar problems in classical.

007: Name stolen: 2012-09-05 21:47:29

use stl containers and algos.....hv fn

Arun Lakshman: 2012-09-03 15:05:11

Again cin and cout costs TLE ...Finally AC :)

Alex Velazquez: 2012-09-02 23:09:00

"Master Bates".... seriously?

Sardar Khan: 2012-09-01 18:13:18

a piece of meal :D

BLANKRK: 2012-08-30 17:38:03

easy one!!!

AC Srinivas: 2012-08-30 14:34:23

using stl is best.

Chirag: 2012-08-30 11:29:26

please check my solution....i am getting correct answer for all given testcases my id is 7560456

i am getting wa...

edit: got AC

Last edit: 2012-09-03 19:47:46
Naman: 2012-08-30 11:07:33

Too easy!!


Added by:TouristGuide
Date:2012-08-27
Time limit:1s-2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64