#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, n;
  int mas[256] = {0};
  static char str[300005];
  static long long sum[300005] = {0};
  map<long long, int> spisok[256];
  long long kolvo = 0;
  for (int i = 0; i < 26; i++) {
    scanf("%d", &a);
    mas['a' + i] = a;
  }
  scanf("%s", str);
  n = strlen(str);
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + mas[str[i - 1]];
  }
  for (int i = 0; i < n; i++) {
    kolvo += spisok[str[i]][sum[i + 1]];
    spisok[str[i]][sum[i + 1] + mas[str[i]]]++;
  }
  printf("%I64d\n", kolvo);
  return 0;
}
