#include <bits/stdc++.h>
using namespace std;
int val[26];
long long cm[100000];
map<pair<long long, int>, int> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  for (int i = 0; i < 26; ++i) {
    cin >> val[i];
  }
  long long sm = 0;
  string str;
  cin >> str;
  for (int i = 0; i < ((int)(str).size()) - 1; ++i) {
    cm[i] = sm += val[str[i] - 'a'];
    ++mp[make_pair(sm, str[i + 1] - 'a')];
  }
  long long ans = 0;
  for (int i = 0; i < ((int)(str).size()) - 1; ++i) {
    pair<long long, int> p = {cm[i], str[i] - 'a'};
    if (mp.count(p) && mp[p] > 0) {
      ans += mp[p];
    }
    --mp[make_pair(cm[i], str[i + 1] - 'a')];
  }
  cout << ans << '\n';
  return 0;
}
