#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
int x[30];
long long ps[100005], ans;
char s[100005];
map<long long, int> mp[30];
int main() {
  for (int(j) = 0; (j) < (int)(26); (j)++) scanf("%d", x + j);
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    int j = s[i] - 'a';
    ps[i] = ps[i - 1] + x[j];
    if (mp[j].find(ps[i - 1]) != mp[j].end()) ans += mp[j][ps[i - 1]];
    mp[j][ps[i]]++;
  }
  printf("%lld\n", ans);
  return 0;
}
