#include <bits/stdc++.h>
using namespace std;
long long wt[27];
long long presum[1000000];
vector<long long> pos[26];
string s;
int main() {
  long long i, j, k;
  for (i = 0; i < 26; i++) {
    cin >> wt[i];
  }
  cin >> s;
  presum[0] = wt[s[0] - 'a'];
  pos[s[0] - 'a'].push_back(0);
  for (i = 1; i < s.size(); i++) {
    presum[i] = presum[i - 1] + wt[s[i] - 'a'];
    pos[s[i] - 'a'].push_back(i);
  }
  long long res = 0;
  for (i = 0; i < 26; i++) {
    long long tot = 0;
    map<long long, long long> M;
    for (j = 0; j < pos[i].size(); j++) {
      if (M.count(presum[pos[i][j] - 1])) {
        tot += M[presum[pos[i][j] - 1]];
      }
      if (M.count(presum[pos[i][j]])) {
        M[presum[pos[i][j]]]++;
      } else {
        M[presum[pos[i][j]]] = 1;
      }
    }
    res += tot;
  }
  cout << res << endl;
  return 0;
}
