#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
const int N = 1000100;
int cnt[100];
char s[N];
int n;
map<long long, int> foo[100];
int main() {
  for (int i = 0; i < 26; ++i) scanf("%d", cnt + i);
  scanf(" %s", s);
  n = strlen(s);
  long long at = 0;
  for (int i = 0; i < n; ++i) {
    foo[s[i] - 'a'][at]++;
    int w = cnt[s[i] - 'a'];
    at += w;
  }
  long long ans = 0;
  at = 0;
  for (int i = 0; i < n - 1; ++i) {
    long long w = cnt[s[i] - 'a'];
    foo[s[i] - 'a'][at]--;
    ans += foo[s[i] - 'a'][at + w];
    at += w;
  }
  printf("%lld\n", ans);
  return 0;
}
