#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long> val(26);
  for (long long i = 0; i < 26; i++) cin >> val[i];
  map<long long, vector<long long> > ma;
  string s;
  cin >> s;
  long long n = s.length();
  vector<long long> pre(n);
  pre[0] = val[s[0] - 'a'];
  for (long long i = 1; i < n; i++) pre[i] = pre[i - 1] + val[s[i] - 'a'];
  long long count = 0;
  for (long long i = 0; i < n; i++) {
    if (ma.find(pre[i]) != ma.end()) {
      if (i + 1 < n) count += ma[pre[i]][s[i + 1] - 'a'];
      ma[pre[i]][s[i] - 'a']++;
    } else {
      vector<long long> temp(26, 0);
      temp[s[i] - 'a']++;
      ma[pre[i]] = temp;
    }
  }
  for (long long i = 1; i < n; i++) {
    if (s[i] == s[i - 1]) count++;
  }
  cout << count << "\n";
}
