#include <bits/stdc++.h>
using namespace std;
map<pair<char, long long>, int> m1;
int val[26];
int main() {
  string str1;
  for (int i = 0; i < 26; i++) cin >> val[i];
  cin >> str1;
  long long s = 0, sum = 0;
  for (int i = 0; i < str1.size(); i++) {
    char c = str1[i];
    int cc = c - 'a';
    s += val[cc];
    sum += m1[make_pair(c, s - val[cc])];
    m1[make_pair(c, s)]++;
  }
  cout << sum << endl;
  return 0;
}
