winetasting
Wine Tasting Conference
The annual "Mirage Pavillion Summer Wine Tasting Conference" has just witnessed its grand opening. The event consisted of a Tasting Challenge and a Fun Challenge, with two prizes awarded to the winners, "Top Sommelier" and "Top Hunter", attracting many tasters to participate.
At the conference dinner, the bartender Rainbow made cocktails. The cocktails were arranged in a row, with the glass labelled one of the 26 lowercase letters of the alphabet . Let denote the string consisting of the sequentially concatenated labels of the the glass to the glass. If , where , , , and , then the glass is said to be "-alike" to the glass. Of course, two glasses of wine that are "-alike" are also "1-alike", "2-alike", and "-alike". In particular, for any , , , the glass is "0-alike" to the glass.
During the tasting session, Sommelier Freda assessed the tastiness of each drink, and with her professionalism and experience easily won the title of "Top Sommelier". The drink was hence rated . Rainbow then announced the question for the Fun Challenge: If the cocktail were to be mixed with the cocktail, you would get a drink with tastiness . He asks the sommeliers: For each , count the number of ways to select two "r-alike" cocktails, and also find the maximum tastiness that can be obtained by blending two "r-alike" cocktails.
Limits
, .
Subtask #
|
Score
|
Constraints
|
1 |
15 |
|
2 |
25 |
|
3 |
10 |
No pairs of 10-alike cocktails exist. |
4 |
20 |
All values of are equal. |
5 |
30 |
No additional constraints |
Input format
The first line of input consists of a single integer , the number of glasses of cocktails.
The second line of input consists of a length string of lowercase letters , the character of which represents glass 's label.
The third line of input contains , the of which represents the tastiness of cocktail .
Output format
Output lines each containing two integers. On the line, the first integer shall be the number of ways to choose two -alike cocktail glasses, and the second integer shall be the greatest tastiness achievable by mixing two -alike cocktails. If no pairs of -alike cocktails exist, output 0 for both integers.
Samples
Sample Input 1
|
Sample Output 1
|
10
ponoiiipoi
2 1 4 7 4 8 3 6 4 7
|
45 56
10 56
3 32
0 0
0 0
0 0
0 0
0 0
0 0
0 0
|
- 0-alike: All 45 pairs of cocktails are 0-alike. The tastiest mix has tastiness .
- 1-alike: The 1-alike pairs of cocktails are , and . The tastiest mix remains .
- 2-alike: The 2-alike pairs of cocktails are , and . The tastiest of them has tastiness .
- No pairs of cocktails are 3-alike, 4-alike, , or 9-alike.
Sample Input 2
|
Sample Output 2
|
12
abaabaabaaba
1 -2 3 -4 5 -6 7 -8 9 -10 11 -12
|
66 120
34 120
15 55
12 40
9 27
7 16
5 7
3 -4
2 -4
1 -4
0 0
0 0
|