#include <bits/stdc++.h>
using namespace std;
int xx[4] = {0, 0, 1, -1};
int yy[4] = {1, -1, 0, 0};
int n;
map<pair<long long, int>, int> mymap;
int d[int(1e5 + 100)];
long long f[int(1e5 + 100)];
char s[int(1e5 + 100)];
pair<long long, int> x, y;
int main() {
  for (int i = ('a'), _b = ('z'); i <= _b; i++) scanf("%d", &d[i]);
  scanf("%s", s + 1);
  int l = strlen(s + 1);
  long long res = 0;
  for (int i = (1), _b = (l); i <= _b; i++) {
    f[i] = f[i - 1] + d[s[i]];
    x = pair<long long, int>(f[i - 1], s[i]);
    res += mymap[x];
    y = pair<long long, int>(f[i], s[i]);
    mymap[y]++;
  }
  cout << res << endl;
}
