#include <bits/stdc++.h>
using namespace std;
long long int tt;
vector<long long int> mark(100001, 1);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<long long int> val(26);
  for (long long int i = 0; i < 26; i++) {
    cin >> val[i];
  }
  string ch;
  cin >> ch;
  long long int n = ch.length();
  map<pair<long long int, long long int>, long long int> mp;
  long long int x = 0;
  for (long long int i = 0; i < n; i++) {
    long long int idx = (ch[i] - 'a');
    x = x + val[idx];
    mp[{idx, x}]++;
  }
  long long int ans = 0;
  x = 0;
  for (long long int i = 0; i < n; i++) {
    long long int idx = (ch[i] - 'a');
    x = x + val[idx];
    mp[{idx, x}]--;
    if (mp.find({idx, (x + val[idx])}) != mp.end()) {
      ans = ans + mp[{idx, (x + val[idx])}];
    }
  }
  cout << ans << endl;
  return 0;
}
