#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n;
long long val[26];
long long pref[N];
string s;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  for (long long i = 0; i < 26; i++) {
    cin >> val[i];
  }
  cin >> s;
  n = s.size();
  s = '#' + s;
  for (long long i = 2; i <= n; i++) {
    pref[i] = val[s[i] - 'a'];
    pref[i] += pref[i - 1];
  }
  long long ans = 0;
  for (char ch = 'a'; ch <= 'z'; ch++) {
    map<long long, long long> m;
    long long ct = 0;
    for (long long i = 1; i <= n; i++) {
      if (s[i] != ch) continue;
      ct++;
      ans += m[pref[i] - val[s[i] - 'a']];
      m[pref[i]]++;
    }
  }
  cout << ans;
  return 0;
}
