#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const double EPS = 1e-9;
const int N = 1e5 + 1;
int arr[27];
long long prefix[N];
string str;
char s[N];
map<long long, int> mp[27];
int n;
int solve(int test) {
  for (register int i = 0; i < 26; i++) scanf("%d", &arr[i]);
  scanf("%s", s);
  str = s;
  n = str.size();
  long long out = 0;
  for (register int i = 0; i < n; i++) {
    prefix[i] = prefix[max(0, i - 1)];
    prefix[i] += arr[str[i] - 'a'];
    if (i) out += (str[i] == str[i - 1]);
  }
  for (register int i = 0; i < n; i++) {
    if (i != n - 1) {
      out += mp[str[i + 1] - 'a'][prefix[i]];
    }
    mp[str[i] - 'a'][prefix[i]]++;
  }
  printf("%lld", out);
  return test;
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) solve(i);
  return 0;
}
