A and B and Interesting Substrings

题意翻译

# A 与 B 与有趣的子串 ## 题目大意 给定每个小写字母一个数值,给定一个只包含小写字母的字符串 $s$,求 $s$ 的子串 $t$ 个数,使 $t$ 满足: - 首位字母相同,长度大于 $1$。 - 首尾字母除外的其余字母的数值之和为 $0$。 ## 题目描述 A 与 B 正在为程序设计竞赛做准备。 经历了数年的编程,做了很多需要对各种古怪对象进行计算的题目,A 与 B 也形成了独特的喜好。 A 喜爱小写字母。他给定每个字母一个数值,来描述对这个字母的喜爱程度。 B 喜爱子串。他尤其喜爱首尾字母相同的子串(长度大于 $1$)。 并且,A 与 B 有一个字符串 $s$。他们尝试计算出,字符串 $s$ 的子串 $t$ 的个数,其中 $t$ 是 B 喜爱的(即,$t$ 的首尾字母相同且长度大于$1$),且首尾字母除外的所有字母的数值(由 A 给定)之和等于 $0$。 自然地,A 与 B 很快计算出了他们喜爱的子串 $t$ 的个数。你可以算出吗? ## 输入输出格式 ### 输入格式: 第一行包含 $26$ 个整数 $x_{a},x_{b},\dots,x_{z}(-10^{5}\le x_{i}\le 10^{5})$——分别代表给定字母 $a,b,c,\dots,z$的数值。 第二行包含字符串 $s$,其长度在 $1$ 到 $10^{5}$ 之间,只包含小写字母——你需要计算答案的字符串。 ### 输出格式: 一行,包含问题的答案。 ## 说明 第一组样例中,满足条件的子串有 $abca$ 与 $bcab$。 第二组样例中,满足条件的子串是两次出现的 $aa$。 Translated by @Capella

题目描述

A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes). B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one). Also, A and B have a string $ s $ . Now they are trying to find out how many substrings $ t $ of a string $ s $ are interesting to B (that is, $ t $ starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero. Naturally, A and B have quickly found the number of substrings $ t $ that are interesting to them. Can you do it?

输入输出格式

输入格式


The first line contains $ 26 $ integers $ x_{a},x_{b},...,x_{z} $ ( $ -10^{5}<=x_{i}<=10^{5} $ ) — the value assigned to letters $ a,b,c,...,z $ respectively. The second line contains string $ s $ of length between $ 1 $ and $ 10^{5} $ characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.

输出格式


Print the answer to the problem.

输入输出样例

输入样例 #1

1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
xabcab

输出样例 #1

2

输入样例 #2

1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
aaa

输出样例 #2

2

说明

In the first sample test strings satisfying the condition above are $ abca $ and $ bcab $ . In the second sample test strings satisfying the condition above are two occurences of $ aa $ .