#include <bits/stdc++.h>
using namespace std;
long long a[26];
vector<int> start[26], ending[26];
int main() {
  long long pref[100000];
  char c[100001];
  for (int i = 0; i < 26; i++) scanf("%I64d", &a[i]);
  scanf("\n");
  int n;
  scanf("%s", &c);
  n = strlen(c);
  pref[0] = a[c[0] - 'a'];
  for (int i = 1; i < n; i++) pref[i] = a[c[i] - 'a'] + pref[i - 1];
  map<long long, list<int> > m;
  map<char, list<int> > m1;
  for (int i = 0; i < n; i++) m[pref[i]].push_back(i), m1[c[i]].push_back(i);
  long long result = 0;
  for (auto it = m.begin(); it != m.end(); it++) {
    for (list<int>::iterator it1 = it->second.begin(); it1 != it->second.end();
         it1++) {
      start[c[*it1] - 'a'].push_back(*it1);
      if ((*it1) != n - 1) ending[c[(*it1) + 1] - 'a'].push_back(*it1);
    }
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < start[i].size(); j++) {
        vector<int>::iterator it =
            lower_bound(ending[i].begin(), ending[i].end(), start[i][j]);
        result += (ending[i].end() - it);
      }
      start[i].clear();
      ending[i].clear();
    }
  }
  cout << result;
  return 0;
}
