#include <bits/stdc++.h>
using namespace std;
map<pair<long long int, char>, int> cnt;
int n;
int like[26];
long long int sum[100010];
char str[100010];
int main() {
  for (int i = 0; i < 26; i++) scanf("%d", &like[i]);
  scanf("%s", str);
  n = strlen(str);
  sum[0] = like[str[0] - 'a'];
  for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + like[str[i] - 'a'];
  long long int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans += cnt[pair<long long int, char>(sum[i] + like[str[i] - 'a'], str[i])];
    cnt[pair<long long int, char>(sum[i], str[i])]++;
  }
  printf("%I64d\n", ans);
  return 0;
}
