#include <bits/stdc++.h>
using namespace std;
long long a[26], b[100001], c[100001], su, cnt;
int main() {
  ios::sync_with_stdio(0);
  cin.tie();
  vector<int> v[26];
  for (int i = 0; i < 26; i++) {
    cin >> a[i];
  }
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    v[s[i] - 'a'].push_back(i);
  }
  b[0] = a[s[0] - 'a'];
  for (int i = 1; i < n; i++) {
    b[i] = b[i - 1] + a[s[i] - 'a'];
  }
  for (int i = 0; i < 26; i++) {
    map<long long, int> m;
    for (int j = 0; j < v[i].size(); j++) {
      int p = v[i][j];
      cnt += m[b[p] - a[s[p] - 'a']];
      m[b[p]]++;
    }
    m.clear();
  }
  cout << cnt;
}
