#include <bits/stdc++.h>
using namespace std;
vector<long long int> P[26];
long long int L[26], C[100001];
int main() {
  string s;
  for (int i = 0; i < 26; i++) cin >> L[i];
  cin >> s;
  s = '_' + s;
  for (int i = 1; i < s.size(); i++) {
    C[i] = C[i - 1] + L[s[i] - 'a'];
    P[s[i] - 'a'].push_back(i);
  }
  long long int ans = 0;
  for (int j = 0; j < 26; j++) {
    map<long long int, long long int> CC;
    for (int i = 0; i < P[j].size(); i++) {
      ans = ans + CC[C[P[j][i] - 1]];
      CC[C[P[j][i]]]++;
    }
    CC.clear();
  }
  cout << ans << endl;
  return 0;
}
