#include <bits/stdc++.h>
long long mpow(long long a, long long n, long long mod) {
  long long ret = 1;
  long long b = a;
  while (n) {
    if (n & 1) ret = (ret * b) % mod;
    b = (b * b) % mod;
    n >>= 1;
  }
  return (long long)ret;
}
using namespace std;
vector<int> v;
long long pref[100005];
map<pair<long long, char>, long long> mp2;
map<pair<long long, char>, long long>::iterator it;
int main() {
  int i, j;
  for (j = 0; j < 26; j++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  string s;
  cin >> s;
  int sz = s.size();
  long long ans = 0;
  pref[0] = v[s[j] - 'a'];
  for (j = 1; j < sz; j++) {
    pref[j] = pref[j - 1] + v[s[j] - 'a'];
  }
  for (j = 0; j < sz; j++) {
    if (j == 0)
      mp2[make_pair(pref[j], s[j])]++;
    else {
      it = mp2.find(make_pair(pref[j - 1], s[j]));
      if (it != mp2.end()) ans += it->second;
      mp2[make_pair(pref[j], s[j])]++;
    }
  }
  cout << ans;
  return 0;
}
