#include <bits/stdc++.h>
using namespace std;
static const int maxn = 1e5 + 10;
static int c[26];
static string s;
static long long cnt[maxn];
static map<char, map<long long, int> > hashs;
int main() {
  for (int i = 0; i < 26; i++) cin >> c[i];
  cin >> s;
  int n = s.length();
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0)
      cnt[i] = c[s[i] - 'a'];
    else
      cnt[i] = cnt[i - 1] + c[s[i] - 'a'];
  }
  for (int i = 0; i < n; i++) {
    ans += hashs[s[i]][cnt[i] - c[s[i] - 'a']];
    ++hashs[s[i]][cnt[i]];
  }
  printf("%I64d\n", ans);
  return 0;
  ;
}
