#include <bits/stdc++.h>
using namespace std;
const int INF = 100009;
char s[INF];
long long val[30], f[INF];
unordered_map<long long, int> p;
int n, m;
int main() {
  for (int i = 0; i < 26; i++) cin >> val[i];
  getchar();
  gets(s);
  int len = strlen(s);
  f[0] = s[0] - 'a';
  for (int i = 1; i < len; i++) f[i] = f[i - 1] + val[s[i] - 'a'];
  long long ans = 0;
  for (int i = 0; i < 26; i++) {
    p.clear();
    char tem = 'a' + i;
    for (int i = 0; i < len; i++) {
      if (s[i] == tem) p[f[i]]++;
      if (s[i + 1] == tem) ans += p[f[i]];
    }
  }
  cout << ans;
}
