#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  long long v[100001] = {};
  map<long long, int> freq[26];
  int val[26];
  for (int i = 0; i < 26; ++i) cin >> val[i];
  cin >> s;
  int n = s.size();
  s = "#" + s;
  for (int i = 1; i <= n; ++i) v[i] = v[i - 1] + val[s[i] - 'a'];
  long long res = 0;
  for (int i = n; i > 0; --i) {
    res += freq[s[i] - 'a'][v[i] + val[s[i] - 'a']];
    ++freq[s[i] - 'a'][v[i]];
  }
  cout << res;
  return 0;
}
