#include <bits/stdc++.h>
using namespace std;
long long a[30], b[100005];
long long summ[1000005];
char s[100005];
unordered_map<long long, unordered_map<long long, long long> > mp;
unordered_map<long long, long long> mpp;
int main() {
  long long n, m, i, j, k, ans, num, sum;
  for (i = 1; i <= 26; i++) scanf("%lld", &a[i]);
  scanf("%s", s + 1);
  n = strlen(s + 1);
  ans = 0;
  for (i = 1; i <= n; i++) {
    summ[i] = summ[i - 1] + a[s[i] - 'a' + 1];
    ans += mp[summ[i] - a[s[i] - 'a' + 1]][s[i] - 'a' + 1];
    mp[summ[i]][s[i] - 'a' + 1]++;
  }
  printf("%lld\n", ans);
  return 0;
}
