#include <bits/stdc++.h>
using namespace std;
long long v[30];
int main() {
  for (int i = 0; i < 26; i++) cin >> v[i];
  string s;
  cin >> s;
  map<pair<char, long long>, long long> cnt;
  long long sum = 0, ans = 0;
  for (auto ch : s) {
    pair<char, long long> pi = make_pair(ch, sum);
    if (cnt.find(pi) != cnt.end()) ans += cnt[pi];
    sum += v[ch - 'a'];
    pi = make_pair(ch, sum);
    if (cnt.find(pi) != cnt.end())
      cnt[pi]++;
    else
      cnt[pi] = 1;
  }
  cout << ans << endl;
  return 0;
}
