#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
long long x[26];
long long sum[100010];
int n;
string s;
map<long long, int> h;
long long solve_B(int v) {
  long long res = 0;
  for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + x[(int)(s[i] - 'a')];
  h.clear();
  for (int i = 0; i < n; i++)
    if ((int)(s[i] - 'a') == v) {
      res += h[sum[i]];
      h[sum[i + 1]]++;
    }
  return res;
}
long long solve() {
  long long res = 0;
  for (int i = 0; i < 26; i++) {
    res += solve_B(i);
  }
  return res;
}
int main() {
  for (int i = 0; i < 26; i++) cin >> x[i];
  cin >> s;
  n = (int)s.size();
  cout << solve() << endl;
  return 0;
}
