#include <bits/stdc++.h>
using namespace std;
long long a[26];
vector<long long> occ[26];
map<long long, long long> m;
long long pref[100003];
int main() {
  string s;
  long long i;
  for (i = 0; i < 26; i++) cin >> a[i];
  cin >> s;
  for (i = 0; i < s.size(); i++) occ[s[i] - 'a'].push_back(i);
  for (i = 0; i < s.size(); i++)
    if (i == 0)
      pref[i] = a[s[i] - 'a'];
    else
      pref[i] = pref[i - 1] + a[s[i] - 'a'];
  long long ans = 0;
  for (i = 0; i < 26; i++) {
    m.clear();
    if (!occ[i].empty()) m[pref[occ[i][0]]]++;
    for (long long j = 1; j < occ[i].size(); j++) {
      long long in = occ[i][j];
      ans += m[pref[in - 1]];
      m[pref[in]]++;
      if (in == occ[i][j - 1] + 1) ans--;
    }
  }
  for (i = 1; i < s.size(); i++)
    if (s[i] == s[i - 1]) ans++;
  cout << ans << "\n";
  return 0;
}
