#include <bits/stdc++.h>
using namespace std;
int main() {
  int like[26];
  for (int i = 0; i < 26; i++) cin >> like[i];
  string s;
  cin >> s;
  long long sum[s.length()];
  sum[0] = like[s[0] - 'a'];
  unordered_map<long long, int> mappy[26];
  mappy[s[0] - 'a'][sum[0]]++;
  long long ans = 0;
  for (int i = 1; i < s.length(); i++) {
    sum[i] = sum[i - 1] + like[s[i] - 'a'];
    ans += mappy[s[i] - 'a'][sum[i - 1]];
    mappy[s[i] - 'a'][sum[i]]++;
  }
  cout << ans << endl;
}
