#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100005;
int n, a[300];
char s[NMAX];
map<pair<int, long long>, int> M;
long long sol;
int main() {
  int i;
  long long sum = 0;
  cin.sync_with_stdio(false);
  for (i = 1; i <= 26; i++) cin >> a[i];
  cin >> (s + 1);
  n = strlen(s + 1);
  for (i = 1; i <= n; i++) {
    if (i > 1) {
      M[make_pair(s[i] - 'a' + 1, sum)] += 0;
      sol += M[make_pair(s[i] - 'a' + 1, sum)];
    }
    sum += a[s[i] - 'a' + 1];
    M[make_pair(s[i] - 'a' + 1, sum)] += 0;
    M[make_pair(s[i] - 'a' + 1, sum)]++;
  }
  cout << sol << "\n";
  return 0;
}
