Max Product
题号:NC294491
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given a string consisting of lowercase English letters. Each lowercase letter has a corresponding weight w_i. The weight of a subsequence is defined as the product of weights of all its characters.

Let W be the maximum possible weight among all subsequences of the given string. Among all subsequences with weight exactly W, find the one with maximum length and your task is to output the length.

A subsequence is obtained by deleting zero or more characters from the original string without changing the order of remaining characters. For example, abc is a subsequence of string adbec, but cb is not.

输入描述:

The first line contains an integer T (1 \le T \le 5), denoting the number of test cases.

For each test case, the first line contains 26 integers c_i (0 \le c_i \le 10^9), denoting the weight of character a, b, c, \ldotsz respectively. The second line contains a string s (1 \le |s| \le 50000), consisting of only lowercase English letters.

输出描述:

For each test case, print a single integer: the length of the longest subsequence having the maximum possible weight.
示例1

输入

复制
1
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1
hduiaghiukqwbbdopceqweqwcgtrewwaaxcbmn

输出

复制
12

备注:

The 26 integers in the example input are on different rows, just for visual convenience. The real test data has all 26 integers on the same line.