#include <bits/stdc++.h>
using namespace std;
vector<long long> val;
string s;
long long lim;
vector<vector<long long> > idx(26);
long long cumval[1000005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < 26; ++i) {
    int temp;
    cin >> temp;
    val.push_back(temp);
  }
  cin >> s;
  lim = s.size();
  for (int i = 0; i < lim; ++i) {
    idx[s[i] - 'a'].push_back(i + 1);
    cumval[i + 1] = val[s[i] - 'a'];
    cumval[i + 1] += cumval[i];
  }
  long long ans = 0;
  for (int i = 0; i < 26; ++i) {
    map<long long, int> xd;
    for (int j = 0; j < idx[i].size(); ++j) {
      int x = idx[i][j];
      ans += xd[cumval[x - 1]];
      xd[cumval[x]]++;
    }
    xd.clear();
  }
  cout << ans;
  return 0;
}
