#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
int a[33];
string s;
int main() {
  for (int i = 0; i < 26; ++i) scanf("%d", &a[i]);
  cin >> s;
  int len = s.length();
  vector<long long> v(len + 1);
  for (int i = 0; i < len; ++i) {
    v[i + 1] = a[s[i] - 'a'] + v[i];
  }
  map<pair<int, long long>, int> m;
  long long res = 0;
  for (int i = 0; i < len; i++) {
    if (m[make_pair(s[i] - 'a', v[i + 1])]) {
      res += m[make_pair(s[i] - 'a', v[i + 1])];
    }
    m[make_pair(s[i] - 'a', v[i + 1] + a[s[i] - 'a'])]++;
  }
  cout << res << "\n";
  return 0;
}
