#include <bits/stdc++.h>
using namespace std;
int C[26];
char s[200000];
map<long long, int> m[26];
long long rr[200000];
long long res;
int main() {
  for (int(i) = 0; (i) < (26); (i)++) cin >> C[i];
  scanf("%s", &s);
  int n = strlen(s);
  for (int(i) = 0; (i) < (n); (i)++) rr[i + 1] = rr[i] + C[s[i] - 'a'];
  for (int(i) = 0; (i) < (n); (i)++) m[s[i] - 'a'][rr[i]]++;
  for (int(i) = 0; (i) < (n); (i)++) {
    m[s[i] - 'a'][rr[i]]--;
    res += m[s[i] - 'a'][rr[i] + C[s[i] - 'a']];
  }
  cout << res << endl;
}
