#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int wt[27], dp[100001], res = 0;
  string s;
  vector<int> g[27];
  for (int i = 0; i < 26; i++) cin >> wt[i];
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    dp[i] = wt[s[i] - 'a'];
    if (i != 0) dp[i] += dp[i - 1];
    g[s[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < 26; i++) {
    map<long long int, int> val;
    int idx = 0;
    for (auto a : g[i]) {
      if (idx != 0 and val[dp[a - 1]] != 0) res += val[dp[a - 1]];
      val[dp[a]]++;
      idx++;
    }
  }
  cout << res;
  return 0;
}
