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.

Difficulty: interview

Starter code:

Solutions:
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)

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)


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)


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)


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)


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)

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()

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 = [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)

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)

import sys

#sys.stdin = open('in.txt', 'rt')

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)

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)

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)
    #print(pos, num)
    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)
    #print(a, s)
def __starting_point():
    main()

__starting_point()

def main():
    from collections import defaultdict
    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)
    #print(pos, num)
    for i in range(26):
        tr = defaultdict(lambda: 0)
        if len(pos[i])> 1:
            for j in range(len(pos[i])):
                count += tr[num[pos[i][j]-1]]
                tr[num[pos[i][j]]] += 1
    print(count)
    #print(a, s)
def __starting_point():
    main()

__starting_point()

def main():
    from collections import defaultdict
    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)
    #print(pos, num)
    for i in range(26):
        tr = defaultdict(lambda: 0)
        if len(pos[i])> 1:
            for j in range(len(pos[i])):
                count += tr[num[pos[i][j]-1]]
                tr[num[pos[i][j]]] += 1
    print(count)
    #print(a, s)
def __starting_point():
    main()

__starting_point()

#!/usr/bin/env python3

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)

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)


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)

#!/usr/bin/env python
# coding=utf-8

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)


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)

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)


__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)

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)


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)
            
    
    
    
# partial_sums = [0]
# 
# for c in s:
#     partial_sums.append(partial_sums[-1] + score_dict[c])
#     
# partial_sums = partial_sums[1:]
# 
# encounters = {letter: [] for idx, letter in enumerate(string.ascii_lowercase)}
# 
# count = 0
# 
# for idx, c in enumerate(s):
#     
#     for evt_idx in encounters[c]:
#         score = partial_sums[idx] - partial_sums[evt_idx] - score_dict[c]
#         if score == 0:
#             count += 1
#             
#     encounters[c].append(idx)
    
# print(count)
    


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()