#include <bits/stdc++.h>
using namespace std;
int val[26], pt1 = 1, pt2 = 2, inplen;
long long cumval[100005], ans = 0;
char inp[100005];
map<long long, map<long long, long long> > lookup;
int main() {
  for (int q = 0; q < 26; q++) cin >> val[q];
  cin >> inp;
  inplen = strlen(inp);
  for (int q = 0; q < inplen; q++) {
    cumval[q] = val[inp[q] - 'a'];
    if (q > 0) cumval[q] += cumval[q - 1];
    if (q > 0) {
      ans += lookup[cumval[q - 1]][inp[q] - 'a'];
    }
    lookup[cumval[q]][inp[q] - 'a']++;
  }
  cout << ans << endl;
  return 0;
}
