#include <bits/stdc++.h>
using namespace std;
long long cul[100005];
int main() {
  map<long long, long long> hit;
  map<long long, map<char, long long> > mark;
  for (int i = 0; i < 26; i++) {
    int in;
    cin >> in;
    hit['a' + i] = in;
  }
  string s;
  cin >> s;
  cul[0] = hit[s[0]];
  for (int i = 1; i < s.size(); i++) {
    cul[i] = cul[i - 1] + hit[s[i]];
  }
  long long res = 0;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == s[i + 1]) res++;
    res += mark[cul[i]][s[i + 1]];
    mark[cul[i]][s[i]]++;
  }
  cout << res << endl;
}
