#include <bits/stdc++.h>
using namespace std;
void output(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x == 0) {
    putchar('0');
    return;
  }
  int a[20], num = 0;
  while (x) a[++num] = x % 10, x /= 10;
  while (num > 0) putchar('0' + a[num--]);
}
inline long long myInt() {
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  int flag = 1;
  if (c == '-') flag = -1, c = getchar();
  long long x = 0;
  while (isdigit(c)) {
    x = (x * 10) + (c - '0');
    c = getchar();
  }
  if (-1 == flag) return -x;
  return x;
}
const int mod = 10000009;
const int N = 100005;
int a[30];
char s[N];
int n;
map<long long, int> mp;
long long cal(char t) {
  mp.clear();
  long long pre = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    pre += a[s[i] - 'a'];
    if (s[i] == t) {
      long long tmp = pre - a[t - 'a'];
      if (mp.count(tmp)) ans += mp[tmp];
      mp[pre]++;
    }
  }
  return ans;
}
int main() {
  for (int i = 0; i < 26; i++) a[i] = myInt();
  scanf("%s", s + 1);
  n = strlen(s + 1);
  long long ans = 0;
  for (char i = 'a'; i <= 'z'; i++) {
    ans += cal(i);
  }
  output(ans);
  puts("");
}
