#include <bits/stdc++.h>
using namespace std;
map<long long, long long> M[26];
long long val[26];
int main() {
  for (int i = 0; i < 26; ++i) {
    cin >> val[i];
  }
  string s;
  cin >> s;
  long long pre = 0;
  long long anse = 0;
  pre = pre + val[s[0] - 97];
  M[s[0] - 97][pre]++;
  for (int i = 1; i < s.size(); ++i) {
    anse += M[s[i] - 97][pre];
    pre = pre + val[s[i] - 97];
    M[s[i] - 97][pre]++;
  }
  cout << anse;
  return 0;
}
