#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9;
const int SIZE = 1e6 + 5;
const long long INF = 1LL << 55;
const double eps = 1e-10;
int v[26];
char s[100009];
long long rs[100009];
unordered_map<long long, int> m[26];
int main() {
  for (int i = 0; i < (26); ++i) scanf("%d", &(v[i]));
  scanf("%s", (s));
  int n = strlen(s);
  for (int i = (1); i < (n + 1); ++i) {
    rs[i] = rs[i - 1] + v[s[i - 1] - 'a'];
  }
  long long cm = 0;
  for (int i = (1); i < (n + 1); ++i) {
    if (i >= 2) {
      m[s[i - 2] - 'a'][rs[i - 1]]++;
    }
    cm += m[s[i - 1] - 'a'][rs[i - 1]];
  }
  printf("%I64d", cm);
}
