#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
int main() {
  ios::sync_with_stdio(0);
  long long int val[26];
  for (int i = 0; i < 26; i++) {
    cin >> val[i];
  }
  string s;
  cin >> s;
  map<long long int, vector<int> > score[26];
  long long int g = 0;
  long long int dest[((long long int)s.size())];
  for (int i = 0; i < ((long long int)s.size()); i++) {
    g += val[s[i] - 'a'];
    score[s[i] - 'a'][g].push_back(i);
    dest[i] = g;
  }
  long long int d = 0;
  for (int i = 0; i < ((long long int)s.size()); i++) {
    d += score[s[i] - 'a'][val[s[i] - 'a'] + dest[i]].end() -
         upper_bound(score[s[i] - 'a'][val[s[i] - 'a'] + dest[i]].begin(),
                     score[s[i] - 'a'][val[s[i] - 'a'] + dest[i]].end(), i);
  }
  cout << d << endl;
}
