#include <bits/stdc++.h>
using namespace std;
long long val[30] = {0}, sum[100000 + 8] = {0};
vector<long long> pos[30];
int main() {
  long long i, j, k, s, d, r, m, n;
  for (i = 0; i < 26; i++) {
    cin >> m;
    val[i] = m;
  }
  string line;
  cin >> line;
  for (i = 0; i < line.size(); i++) {
    m = line[i] - 'a';
    sum[i + 1] = val[m];
    sum[i + 1] += sum[i];
    pos[m].push_back(i + 1);
  }
  long long ans = 0;
  for (i = 0; i < 26; i++) {
    map<long long, long long> Map;
    for (j = 0; j < pos[i].size(); j++) {
      long long p = pos[i][j];
      ans += Map[sum[p - 1]];
      Map[sum[p]]++;
    }
    Map.clear();
  }
  cout << ans << endl;
}
