#include <bits/stdc++.h>
using namespace std;
int a[30];
char s[100005];
long long cnt[100005];
map<long long, long long> mp[26];
int main() {
  long long ans = 0, tmp = 0;
  for (int i = 0; i < 26; i++) scanf("%d", &a[i]);
  scanf("%s", s + 1);
  for (int i = 1; s[i]; i++) cnt[i] += cnt[i - 1] + a[s[i] - 'a'];
  for (int i = 1; s[i]; i++) {
    ans += mp[s[i] - 'a'][cnt[i - 1]];
    mp[s[i] - 'a'][cnt[i]]++;
  }
  printf("%I64d\n", ans);
}
