#include <bits/stdc++.h>
using namespace std;
int Pow[26], n;
char read[100002];
long long Sum[100001];
map<long long, int> F[26];
int main() {
  for (int i = 0; i < 26; ++i) scanf("%d", &Pow[i]);
  scanf("%s", read);
  string s = read;
  s = "#" + s;
  n = s.size() - 1;
  for (int i = 1; i <= n; ++i) Sum[i] = Sum[i - 1] + Pow[s[i] - 'a'];
  long long res = 0;
  for (int i = n; i > 0; --i) {
    res += F[s[i] - 'a'][Sum[i] + Pow[s[i] - 'a']];
    ++F[s[i] - 'a'][Sum[i]];
  }
  printf("%lld\n", res);
  return 0;
}
