#include <bits/stdc++.h>
using namespace std;
long long cum[100004];
int main() {
  int val[26];
  for (int i = 0; i < 26; i++) {
    scanf("%d", &val[i]);
  }
  string s;
  cin >> s;
  int n = s.size();
  vector<int> pos[27];
  s = "#" + s;
  for (int i = 1; i <= n; i++) {
    cum[i] = cum[i - 1] + val[s[i] - 'a'];
    pos[s[i] - 'a'].push_back(i);
  }
  long long ans = 0;
  for (int c = 0; c < 26; c++) {
    map<long long, int> cnt;
    for (auto x : pos[c]) {
      ans += cnt[cum[x - 1]];
      cnt[cum[x]]++;
    }
  }
  printf("%I64d\n", ans);
}
