String potential#2159

String potential

1 second
64 megabytes
Easy

You are given a string consisting of the first lowercase letters of the Latin alphabet. As in the previous problem, the distance between two characters s_i and s_j of this string is defined as the absolute difference between their positions, i.e., |j - i|. The potential of the string is defined as follows. There is a function f(c_1, c_2) that assigns a weight to each pair of letters. This function is symmetric, that is, f(c_1, c_2) = f(c_2, c_1). The potential between characters s_i and s_j of string is the product of their weight and the distance between them. The potential of the string is the sum of the potentials for all pairs of characters.

Write a program that calculates the potential of the given string .

Input

The first line contains an integer (1 \leq k \leq 26), the number of the first Latin letters allowed in the string.

The second line contains the string , whose length does not exceed 10^6.

The following lines describe the weight function: the -th line contains integers, where the -th integer in the -th line specifies the weight for the -th and -th Latin letters (in alphabetical order). All weights do not exceed 10^6 in absolute value.

Output

Output a single number, the potential of the string .

Examples

Example 1

Loading
Loading