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? 


-----Input-----

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. 


-----Output-----

Print the answer to the problem. 


-----Examples-----
Input
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

Output
2

Input
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

Output
2



-----Note-----

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.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Data structures

Amortized analysis


Solutions:
def main():
	mode = 'filee'
	if mode == 'file':
		f = open('test.txt', 'r')
	get = lambda : [int(x) for x in (f.readline() if mode == 'file' else input()).split()]
	gets = lambda : [str(x) for x in (f.readline() if mode == 'file' else input()).split()]
	num = 100005
	w = get()
	[g] = gets()
	[dp, s, p, count] = [[0] * num, [0] * num, {}, 0]
	for i in range(len(g)):
		dp[i] = w[ord(g[i]) - 97]
	for i in range(1, len(g) + 1):
		s[i] = s[i - 1] + dp[i - 1]
	for i in range(1, len(g)):
		if s[i] not in p:
			p[s[i]] = [0] * 26
		p[s[i]][ord(g[i - 1]) - 97] += 1
		if p[s[i]][ord(g[i]) - 97] != 0:
			count += p[s[i]][ord(g[i]) - 97]
	print(count)
	if mode == 'file':
		f.close()

def __starting_point():
	main()
__starting_point()


x = list(map(int, input().split()))
s = list(input().rstrip())
n = len(s)
cx = [0] * (n + 1)
for i in range(1, n + 1):
	cx[i] = x[ord(s[i - 1]) - ord('a')]
for i in range(1, n + 1):
	cx[i] += cx[i - 1]
pos = [{} for i in range(26)]
ans = 0
for i in range(n):
	ss = s[i]
	ans += pos[ord(ss) - ord('a')].get(cx[i], 0)
	pos[ord(ss) - ord('a')][cx[i + 1]] = pos[ord(ss) - ord('a')].get(cx[i + 1], 0) + 1
print(ans)


from collections import Counter
A = list(map(int, input().split()))
L = [ord(i) - ord('a') for i in input()]
score = ans = 0
D = [Counter() for i in range(26)]
for i in L:
	ans += D[i][score]
	score += A[i]
	D[i][score] += 1
print(ans)


ar = list(map(int, input().split()))
ss = 'abcdefghijklmnopqrstuvwxyz'
ma = {}
for i in range(26):
	ma[ss[i]] = ar[i]
st = input()
dic = {}
le = len(st)
for i in range(le):
	if st[i] in dic:
		dic[st[i]].append(i)
	else:
		dic[st[i]] = [i]
br = [ma[st[0]]]
for i in range(1, le):
	br.append(br[-1] + ma[st[i]])
ans = 0
for i in dic:
	tem = {}
	li = []
	le = len(dic[i])
	for j in dic[i]:
		sco = br[j] - ma[i]
		if sco in tem:
			ans += tem[sco]
		if br[j] in tem:
			tem[br[j]] += 1
		else:
			tem[br[j]] = 1
print(ans)


(*a,) = map(int, input().split())
d = [{} for _ in range(26)]
s = input()
sum = 0
c = 0
for j in s:
	n = ord(j) - ord('a')
	c += d[n].get(sum, 0)
	sum += a[n]
	d[n][sum] = d[n].get(sum, 0) + 1
print(c)


score = []
from collections import *
z = list(map(int, input().split()))
s = input()
for i in range(26):
	score.append(defaultdict(int))
pre = []
total = 0
for i in range(len(s)):
	s1 = z[ord(s[i]) - 97]
	t = ord(s[i]) - 97
	if i == 0:
		pre.append(s1)
	else:
		pre.append(pre[-1] + s1)
	s1 = pre[-1]
	score[t][s1] += 1
	if z[t] == 0:
		total += max(0, score[t][s1] - 1)
	else:
		total += max(0, score[t][s1 - z[t]])
fin = []
count = 1
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		count += 1
	else:
		fin.append([count, s[i - 1]])
		count = 1
fin.append([count, s[-1]])
for i in range(len(fin)):
	if fin[i] == 2:
		total += 1
print(total)


from collections import defaultdict

def process_letter(nums):
	d = {}
	for i in range(26):
		assert chr(ord('a') + i).islower()
		d[chr(ord('a') + i)] = nums[i]
	return d
dic = process_letter([int(x) for x in input().split()])
s = input()
current = 0
value = defaultdict(int)
ans = 0
for c in s:
	ans += value[c, current]
	current += dic[c]
	value[c, current] += 1
print(ans)


l = list(map(int, input().split()))
s = input()
cs = 0
ans = 0
a = []
for i in range(26):
	a.append({})
for i in s:
	c = ord(i) - 97
	x = a[c].get(cs) or 0
	ans += x
	cs += l[c]
	y = a[c].get(cs) or 0
	a[c][cs] = y + 1
print(ans)


a = list(map(int, input().split()))
s = input()
n = len(s)
b = []
for j in s:
	b.append(ord(j) - 97)
pre = [0]
for j in b:
	pre.append(pre[-1] + a[j])
c = [[] for i in range(26)]
ans = 0
for j in range(n):
	c[b[j]].append(j)
for j in range(26):
	p = c[j]
	if len(p) > 1:
		x = []
		for i in range(len(p) - 1):
			x.append(pre[p[i + 1]] - pre[p[i]])
		x.append(a[j])
		d = dict()
		currsum = 0
		i = 0
		while i < len(x):
			if i == 0:
				currsum += x[i]
				d[currsum] = 1
			elif i > 0:
				if currsum == a[j]:
					ans += 1
				if currsum - a[j] in d.keys():
					if a[j] == 0:
						ans += d[currsum - a[j]] - 1
					else:
						ans += d[currsum - a[j]]
				currsum += x[i]
				if currsum in d.keys():
					d[currsum] += 1
				else:
					d[currsum] = 1
			i += 1
print(ans)


from collections import Counter

def solve(a, s):
	count = [Counter() for _ in range(26)]
	v = 0
	res = 0
	for c in s:
		i = ord(c) - ord('a')
		res += count[i][v]
		v += a[i]
		count[i][v] += 1
	return res
a = list(map(int, input().split()))
s = input()
print(solve(a, s))


__author__ = 'Andrey'

def val(char):
	nonlocal values
	return values[ord(char) - ord('a')]
values = list(map(int, input().split()))
s = input()
prefix_sums = [val(s[0])]
for q in range(1, len(s)):
	prefix_sums.append(prefix_sums[q - 1] + val(s[q]))
big_dict = dict()
for i in range(97, 97 + 26):
	big_dict[chr(i)] = dict()
ans = 0
for index in range(len(s)):
	letter = s[index]
	if index > 0:
		ans += big_dict[letter].get(prefix_sums[index - 1], 0)
	big_dict[letter][prefix_sums[index]] = big_dict[letter].get(prefix_sums[index], 0) + 1
print(ans)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
import math as mt
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
mod = int(1000000000.0) + 7

def power(k, n):
	if n == 0:
		return 1
	if n % 2:
		return power(k, n - 1) * k % mod
	t = power(k, n // 2)
	return t * t % mod

def totalPrimeFactors(n):
	count = 0
	if n % 2 == 0:
		count += 1
		while n % 2 == 0:
			n //= 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			count += 1
			while n % i == 0:
				n //= i
		i += 2
	if n > 2:
		count += 1
	return count

def main():
	val = list(map(int, input().split()))
	S = input()
	s = []
	for i in S:
		if ord('a') <= ord(i) <= ord('z'):
			s.append(i)
	table = []
	for i in range(26):
		t = {}
		table.append(t)
	curr = 0
	ans = 0
	for i in range(len(s)):
		ind = ord(s[i]) - ord('a')
		if curr in table[ind]:
			ans += table[ind][curr]
		if i:
			if curr not in table[ord(s[i - 1]) - ord('a')]:
				table[ord(s[i - 1]) - ord('a')][curr] = 0
			table[ord(s[i - 1]) - ord('a')][curr] += 1
		curr += val[ind]
	for i in range(1, len(s)):
		ans += s[i] == s[i - 1]
	print(ans)
	return
main()


import sys
import math
import collections
import heapq
l = [int(i) for i in input().split()]
s = input()
d = []
for i in range(26):
	d.append({})
s1 = 0
c = 0
for i in range(len(s)):
	n = ord(s[i]) - ord('a')
	c += d[n].get(s1, 0)
	s1 += l[n]
	d[n][s1] = d[n].get(s1, 0) + 1
print(c)


A = list(map(int, input().split()))
S = [ord(x) - ord('a') for x in input()]
score = ans = 0
D = [dict() for _ in range(26)]
for i in S:
	if score in D[i]:
		ans += D[i][score]
	score += A[i]
	if score in D[i]:
		D[i][score] += 1
	else:
		D[i][score] = 1
print(ans)


arr = list(map(int, input().split()))
astr = input()
length = len(astr)
ans = 0
tsum = 0
st = {}
for i in range(length):
	st.setdefault(astr[i], {})
	ans += st[astr[i]].get(tsum, 0)
	tsum += arr[ord(astr[i]) - 97]
	st[astr[i]][tsum] = st[astr[i]].get(tsum, 0) + 1
print(ans)


from sys import *
inp = lambda : stdin.readline()

def main():
	cost = list(map(int, inp().split()))
	s = inp()[:-1]
	(sum, ans) = ([0 for i in range(len(s))], 0)
	appears = [[] for i in range(26)]
	sum[0] = cost[ord(s[0]) - ord('a')]
	appears[ord(s[0]) - ord('a')].append(0)
	for i in range(1, len(s)):
		sum[i] = sum[i - 1] + cost[ord(s[i]) - ord('a')]
		appears[ord(s[i]) - ord('a')].append(i)
	for i in range(26):
		now = appears[i]
		d = {}
		for i in range(len(now)):
			p = now[i]
			ans += d.get(sum[p - 1], 0)
			d[sum[p]] = d.get(sum[p], 0) + 1
	print(ans)
main()


c = [int(i) for i in input().split()]
a = [ord(x) - ord('a') for x in input()]
n = len(a)
l = [[] for i in range(26)]
r = [[] for i in range(26)]
s = 0
ans = 0
for i in range(n - 1):
	s += c[a[i]]
	l[a[i]] += [(s, i)]
	r[a[i + 1]] += [(s, i)]
for i in range(26):
	(n, m) = (len(l[i]), len(r[i]))
	if n < 1 or m < 1:
		continue
	l[i].sort()
	r[i].sort()
	a[m - 1] = m - 1
	for j in range(m - 2, -1, -1):
		if r[i][j][0] == r[i][j + 1][0]:
			a[j] = a[j + 1]
		else:
			a[j] = j
	y = 0
	for j in range(n):
		while y < m and r[i][y][0] < l[i][j][0]:
			y += 1
		while y < m and r[i][y][0] == l[i][j][0] and (r[i][y][1] < l[i][j][1]):
			y += 1
		if y == m:
			break
		if r[i][y][0] == l[i][j][0]:
			ans += a[y] - y + 1
print(ans)


costss = list(map(int, input().split()))
s = input()
costs = {}
cost = 0
ans = 0
nums = []
for i in range(len(s)):
	cost += costss[ord(s[i]) - 97]
	if s[i] not in costs:
		costs[s[i]] = {}
	costs[s[i]][cost] = costs[s[i]].get(cost, 0) + 1
	ans += costs[s[i]].get(cost - costss[ord(s[i]) - 97], 0)
	if costss[ord(s[i]) - 97] == 0:
		ans -= 1
print(ans)


import string
from collections import defaultdict
scores = [int(x) for x in input().split()]
score_dict = {letter: scores[idx] for (idx, letter) in enumerate(string.ascii_lowercase)}
s = input()
partial_sums = [0]
encounters = {letter: [] for (idx, letter) in enumerate(string.ascii_lowercase)}
for (idx, c) in enumerate(s):
	partial_sums.append(partial_sums[-1] + score_dict[c])
	encounters[c].append(idx)
partial_sums = partial_sums[1:]
count = 0
for letter in encounters:
	score_count_dict = defaultdict(int)
	for letter_idx in encounters[letter]:
		count += score_count_dict[partial_sums[letter_idx - 1]]
		score_count_dict[partial_sums[letter_idx]] += 1
print(count)


import sys
a = list(map(int, input().split()))
s = input().strip()
w = [(0, -1)]
sum = 0
for i in enumerate(s):
	sum += a[ord(i[1]) - ord('a')]
	w.append((sum, i[0]))
w.sort()
dp = [0] * 26
answer = 0
for i in enumerate(w):
	if i[0] >= 1 and i[1][0] != w[i[0] - 1][0]:
		dp = [0] * 26
	if i[1][1] >= 0:
		dp[ord(s[i[1][1]]) - ord('a')] += 1
	if i[1][1] < len(s) - 1:
		answer += dp[ord(s[i[1][1] + 1]) - ord('a')]
print(answer)


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
pr = lambda x: x

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def solve():
	A = aj()
	s = input()
	C = Counter()
	pre = A[ord(s[0]) - ord('a')]
	C[s[0], pre] += 1
	ans = 0
	for i in range(1, len(s)):
		ans += C[s[i], pre]
		pre += A[ord(s[i]) - ord('a')]
		C[s[i], pre] += 1
	print(ans)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	from aj import *
except:
	pass
solve()


def main():
	from collections import defaultdict
	tr = [defaultdict(lambda : 0) for i in range(26)]
	a = list(map(int, input().split()))
	s = input()
	count = 0
	m = [0] * 26
	num = [0] * len(s)
	pos = []
	for i in range(26):
		pos.append(list())
	for i in range(len(s)):
		num[i] += a[ord(s[i]) - ord('a')]
		if i:
			num[i] += num[i - 1]
		pos[ord(s[i]) - ord('a')].append(i)
	for i in range(26):
		if len(pos[i]) > 1:
			for j in range(len(pos[i])):
				count += tr[i][num[pos[i][j] - 1]]
				tr[i][num[pos[i][j]]] += 1
	print(count)
main()


import os
import sys
from io import BytesIO, IOBase
from collections import *

def main():
	values = list(map(int, input().split(' ')))
	s = input()
	dic = defaultdict(lambda : [])
	pre = [0 for x in range(len(s) + 1)]
	for x in range(len(s)):
		pre[x + 1] = pre[x] + values[ord(s[x]) - ord('a')]
		dic[s[x]].append(x)
	ans = 0
	for (x, y) in dic.items():
		here = defaultdict(lambda : 0)
		for z in y:
			if pre[z] in here:
				ans += here[pre[z]]
			here[pre[z + 1]] += 1
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
val = Ri()
s = ri()
dp = [0] * (len(s) + 1)
for i in range(1, len(s) + 1):
	dp[i] = dp[i - 1] + val[ord(s[i - 1]) - ord('a')]
ans = [[] for i in range(26)]
for i in range(len(s)):
	ans[ord(s[i]) - ord('a')].append(i)
totans = 0
for i in range(26):
	dic = {}
	for j in range(0, len(ans[i])):
		if j == 0:
			dic[dp[ans[i][0] + 1]] = 1
			continue
		val = dp[ans[i][j]]
		if val in dic:
			totans += dic[val]
		dic[dp[ans[i][j] + 1]] = dic.get(dp[ans[i][j] + 1], 0) + 1
print(totans)


import sys
read = lambda t=int: list(map(t, sys.stdin.readline().split()))
array = lambda *ds: [array(*ds[1:]) for _ in range(ds[0])] if ds else 0
from collections import Counter
xs = read()
(s,) = read(str)
cnt = Counter()
a = 0
res = 0
for c in s:
	res += cnt[c, a]
	a += xs[ord(c) - ord('a')]
	cnt[c, a] += 1
print(res)


from collections import defaultdict

def solve():
	x = [int(x_str) for x_str in input().split()]
	s = input()
	pre_sum = {-1: 0}
	pos = defaultdict(list)
	for i in range(len(s)):
		pre_sum[i] = pre_sum[i - 1] + x[ord(s[i]) - ord('a')]
		pos[ord(s[i]) - ord('a')].append(i)
	ans = 0
	for ch in range(26):
		dp = defaultdict(int)
		for i in range(len(pos[ch])):
			index = pos[ch][i]
			target = pre_sum[index - 1] - 0
			ans += dp[target]
			dp[pre_sum[index]] += 1
	print(ans)
	return 0
solve()


a = [int(i) for i in input().split()]
s = input()
govno = [{} for i in range(26)]
jopa = 0
barebuh = 0
for i in s:
	cyka = ord(i) - ord('a')
	barebuh += govno[cyka].get(jopa, 0)
	jopa += a[cyka]
	govno[cyka][jopa] = govno[cyka].get(jopa, 0) + 1
print(barebuh)


X = [int(i) for i in input().split()]
s = input()
arr = []
unicode_a = ord('a')
for i in range(26):
	arr.append({})
sm = 0
k = 0
for char in s:
	n = ord(char) - unicode_a
	k += arr[n].get(sm, 0)
	sm += X[n]
	arr[n][sm] = arr[n].get(sm, 0) + 1
print(k)


val = [int(x) for x in input().split()]
s = input()
a = []
for i in range(0, 26):
	a.append({})
add = [0]
res = 0
for each in s:
	num = add[-1] + val[ord(each) - 97]
	add.append(num)
	res += a[ord(each) - 97].get(add[-2], 0)
	if num not in a[ord(each) - 97]:
		a[ord(each) - 97][num] = 0
	a[ord(each) - 97][num] += 1
print(res)


xx = [int(i) for i in input().split()]
s = input()
x = [{} for _ in range(0, 26)]
ss = 0
ans = 0
for i in s:
	ans += x[ord(i) - 97].get(ss, 0)
	ss += xx[ord(i) - 97]
	x[ord(i) - 97][ss] = x[ord(i) - 97].get(ss, 0) + 1
print(ans)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List

def solve(A, s):
	chv = {chr(ord('a') + i): v for (i, v) in enumerate(A)}
	presum = []
	chindx = collections.defaultdict(list)
	p = 0
	for (i, ch) in enumerate(s):
		v = chv[ch]
		p += v
		presum.append(p)
		chindx[ch].append(i)
	ans = 0
	for (ch, idx) in chindx.items():
		ps = collections.defaultdict(list)
		for i in idx:
			ps[presum[i]].append(i)
		if chv[ch] == 0:
			for w in ps.values():
				nw = len(w)
				if nw > 1:
					ans += nw * (nw - 1) // 2
		else:
			for (u, idx) in ps.items():
				v = u + chv[ch]
				if v in ps:
					w = ps[v]
					for i in idx:
						ans += len(w) - bisect.bisect_right(w, i)
	print(ans)
A = [int(x) for x in input().split()]
s = input()
solve(A, s)


arr = [int(i) for i in input().split()]
r = [{} for i in range(26)]
j = 1
res = 0
sum = [0] * (10 ** 5 + 1)
for i in input():
	i = ord(i) - ord('a')
	sum[j] = sum[j - 1] + arr[i]
	if sum[j - 1] in r[i]:
		res += r[i][sum[j - 1]]
	if sum[j] in r[i]:
		r[i][sum[j]] += 1
	else:
		r[i][sum[j]] = 1
	j += 1
print(res)


def main():
	xlat = list(map(int, input().split()))
	dd = [{} for _ in range(26)]
	m = res = 0
	s = input()
	for c in s:
		cx = ord(c) - 97
		d = dd[cx]
		res += d.get(m, 0)
		m += xlat[cx]
		d[m] = d.get(m, 0) + 1
	print(res)

def __starting_point():
	main()
__starting_point()


def solve(left, right):
	if left == right:
		return 0
	if left + 1 == right:
		return 0
	mid = (left + right) // 2
	ret = solve(left, mid) + solve(mid, right)
	val = 0
	D = [dict() for i in range(26)]
	for i in range(mid, right):
		c = L[i]
		if i != mid:
			d = L[i - 1]
			val += A[d]
		if val in D[c]:
			D[c][val] += 1
		else:
			D[c][val] = 1
	val = 0
	for i in range(mid, left, -1):
		c = L[i - 1]
		if i != mid:
			d = L[i]
			val += A[d]
		if -val in D[c]:
			ret += D[c][-val]
	return ret
A = list(map(int, input().split()))
S = input()
L = [ord(i) - ord('a') for i in S]
ans = solve(0, len(L))
print(ans)


from collections import defaultdict
l = list(map(int, input().split()))
st = input()
s = [ord(i) - ord('a') for i in st]
track = [defaultdict(lambda : 0) for i in range(26)]
res = 0
s = [0] + s
pre = [0 for i in range(len(s))]
for i in range(1, len(s)):
	pre[i] = pre[i - 1] + l[s[i]]
for i in range(1, len(s)):
	res += track[s[i]][pre[i - 1]]
	track[s[i]][pre[i]] += 1
print(res)


ls = list(map(int, input().split()))
s = list(input())
n = len(s)
fre = [None] * n
fre[0] = ls[ord(s[0]) - ord('a')]
for i in range(1, n):
	x = ls[ord(s[i]) - ord('a')]
	x = x + fre[i - 1]
	fre[i] = x
d = {}
ans = 0
for i in range(0, 26):
	d[i] = {}
d[ord(s[0]) - ord('a')][fre[0]] = 1
for i in range(1, n):
	k = ord(s[i]) - ord('a')
	if fre[i - 1] in d[k]:
		ans = ans + d[k][fre[i - 1]]
	if fre[i] in d[k]:
		d[k][fre[i]] = d[k][fre[i]] + 1
	else:
		d[k][fre[i]] = 1
print(ans)


a = list(map(int, input().split()))
str = list(input())
dx = ord('a')
mp = [{} for i in range(26)]
sum = 0
ans = 0
for i in range(len(str)):
	d = ord(str[i]) - dx
	if sum in mp[d]:
		ans += mp[d][sum]
	sum += a[d]
	if sum in mp[d]:
		mp[d][sum] += 1
	else:
		mp[d][sum] = 1
print(ans)


from collections import defaultdict
val = list(map(int, input().split()))
s = input()
pos = [[] for i in range(26)]
sm = []
for (i, c) in enumerate(s):
	v = ord(c) - ord('a')
	if i == 0:
		sm.append(val[v])
	else:
		sm.append(sm[-1] + val[v])
	pos[v].append(i)
ans = 0
for c in range(26):
	m = defaultdict(int)
	for i in pos[c]:
		if i > 0:
			ans += m[sm[i - 1]]
		m[sm[i]] += 1
print(ans)


(*a,) = map(int, input().split())
s = input()
b = [a[ord(i) - 97] for i in s]
(d, ans) = ({}, 0)
pref = [0]
for i in range(len(s) - 1):
	pref.append(pref[-1] + b[i])
	if s[i] == s[i + 1]:
		ans += 1
	if pref[-1] in d:
		ans += d[pref[-1]][s[i + 1]]
	else:
		d[pref[-1]] = {chr(x): 0 for x in range(97, 123)}
	d[pref[-1]][s[i]] += 1
print(ans)


w = list(map(int, input().split()))
a = input()
l = len(a)
m = [0] * 27
s = [0] * l
for i in range(27):
	m[i] = dict()
ans = 0
for i in range(1, l):
	A = ord(a[i - 1]) - ord('a')
	s[i] = s[i - 1] + w[A]
for i in range(l):
	A = ord(a[i]) - ord('a')
	if s[i] - w[A] in m[A]:
		ans += m[A][s[i] - w[A]]
	if not s[i] in m[A]:
		m[A][s[i]] = 1
	else:
		m[A][s[i]] += 1
print(ans)


w = [*map(int, input().split())]
s = input()
ss = [0]
f = lambda c: ord(c) - ord('a')
for c in s:
	ss.append(ss[-1] + w[f(c)])
cm = [dict() for _ in range(26)]
res = 0
for i in range(len(s)):
	res += cm[f(s[i])].get(ss[i], 0)
	cm[f(s[i])][ss[i + 1]] = cm[f(s[i])].get(ss[i + 1], 0) + 1
print(res)


alpha = list(map(int, input().split()))
st = input()
alpha_d = [{} for i in range(26)]
n = len(st)
count = 0
ans = 0
for i in range(n):
	if count in alpha_d[ord(st[i]) - 97]:
		ans += alpha_d[ord(st[i]) - 97][count]
	count += alpha[ord(st[i]) - 97]
	value = alpha_d[ord(st[i]) - 97].get(count, 0)
	alpha_d[ord(st[i]) - 97][count] = value + 1
print(ans)


A = list(map(int, input().split()))
L = [ord(i) - ord('a') for i in input()]
score = ans = 0
D = [dict() for i in range(26)]
for i in L:
	if score in D[i]:
		ans += D[i][score]
	score += A[i]
	if score not in D[i]:
		D[i][score] = 1
	else:
		D[i][score] += 1
print(ans)


w = [int(x) for x in input().split()]
c = [{} for i in range(26)]
(val, s) = (0, 0)
for i in [ord(ch) - ord('a') for ch in input()]:
	if s - w[i] in c[i]:
		val += c[i][s - w[i]]
	c[i][s] = c[i][s] + 1 if s in c[i] else 1
	s += w[i]
print(val)


a = list(map(int, input().split()))
s = input()
d = []
for i in range(26):
	d.append({})
sm = 0
k = 0
for x in s:
	n = ord(x) - ord('a')
	k += d[n].get(sm, 0)
	sm += a[n]
	d[n][sm] = d[n].get(sm, 0) + 1
print(k)