#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 1e18;
const int N = 101234;
const int M = 26;
int n, m;
int val[M];
char s[N];
map<long long, long long> cnt;
long long sum[N];
int main() {
  int i, j;
  for (i = 0; i < 26; ++i) scanf("%d", &val[i]);
  scanf("%s", s);
  int len = strlen(s);
  for (i = 0; i < len; ++i) sum[i + 1] = sum[i] + val[s[i] - 'a'];
  long long ans = 0;
  for (i = 0; i < 26; ++i) {
    cnt.clear();
    for (j = 0; j < len; ++j) {
      if (i == s[j] - 'a') {
        long long x = sum[j + 1] - 2 * val[i];
        if (cnt.find(x) != cnt.end()) ans += cnt[x];
        cnt[sum[j]]++;
      }
    }
  }
  printf("%I64d\n", ans);
}
