#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
int w[26];
long long sum[N];
char s[N];
vector<int> id[26];
int main() {
  for (int i = 0; i < 26; ++i) scanf("%d", w + i);
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + w[s[i] - 'a'];
  for (int i = 1; i <= n; ++i) id[s[i] - 'a'].push_back(i);
  long long answer = 0;
  for (int i = 0; i < 26; ++i) {
    map<long long, int> cnt;
    for (int j : id[i]) {
      answer += cnt[sum[j - 1]];
      cnt[sum[j]]++;
    }
    cnt.clear();
  }
  printf("%lld\n", answer);
  return 0;
}
