#include <bits/stdc++.h>
using namespace std;
int main() {
  int scores[26];
  for (int i = 0; i < 26; i++) cin >> scores[i];
  string s;
  cin >> s;
  unordered_map<long long, vector<int>> mp;
  long long ans = 0;
  long long sum = 0;
  for (int i = 0; i < s.length(); i++) {
    if (i + 1 < s.length() && s[i] == s[i + 1]) ans++;
    int sc = scores[s[i] - 'a'];
    sum += sc;
    if (mp[sum].size() == 0) {
      vector<int> vec(26, 0);
      mp[sum] = vec;
    }
    if (i + 1 < s.length()) ans += mp[sum][s[i + 1] - 'a'];
    mp[sum][s[i] - 'a']++;
  }
  cout << ans << endl;
}
