#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int val[26];
  string second;
  for (int i = 0; i < 26; i++) {
    cin >> val[i];
  }
  cin >> second;
  vector<long long int> adj[26];
  long long int pref[second.size()];
  for (int i = 0; i < second.size(); i++) {
    adj[second[i] - 'a'].push_back(i);
    if (i == 0) {
      pref[i] = val[second[i] - 'a'];
    } else {
      pref[i] = pref[i - 1] + val[second[i] - 'a'];
    }
  }
  long long int ans = 0;
  for (char c = 'a'; c <= 'z'; c++) {
    long long int sum = 0;
    unordered_map<long long int, long long int> mp;
    for (int j = 0; j < adj[c - 'a'].size(); j++) {
      ans += mp[pref[adj[c - 'a'][j]] - val[c - 'a']];
      mp[pref[adj[c - 'a'][j]]]++;
    }
  }
  cout << ans << endl;
}
