#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int value[27];
char input_[maxn];
map<long long, int> M[26];
int main() {
  for (int i = 0; i < 26; i++) {
    scanf("%d", &value[i]);
  }
  scanf("%s", input_ + 1);
  int len = strlen(input_ + 1);
  long long cnt = 0, k = 0;
  for (int i = 1; i <= len; i++) {
    cnt += M[input_[i] - 'a'][k];
    k += value[input_[i] - 'a'];
    M[input_[i] - 'a'][k]++;
  }
  cout << cnt << endl;
  return 0;
}
