#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<int> v_x(26);
  for (int i = 0; i < 26; i++) {
    cin >> v_x[i];
  }
  string s;
  cin >> s;
  vector<long long> prefix_s(s.size());
  vector<vector<int>> occur(26);
  prefix_s[0] = v_x[(int)s[0] - 97];
  occur[(int)s[0] - 97].push_back(0);
  for (int i = 1; i < s.size(); i++) {
    int val = (int)s[i] - 97;
    prefix_s[i] = prefix_s[i - 1] + v_x[val];
    occur[val].push_back(i);
  }
  long long ans = 0;
  for (vector<int> a : occur) {
    map<long long, int> Map;
    for (int m : a) {
      ans += Map[prefix_s[m - 1]];
      Map[prefix_s[m]]++;
    }
    Map.clear();
  }
  cout << ans;
}
