#include <bits/stdc++.h>
using namespace std;
long long a[26];
long long cs[200001];
string s;
map<long long, long long> sum;
int main() {
  for (long long i = 0; i < 26; i++) scanf("%lld", &a[i]);
  cin >> s;
  for (long long i = 1; i <= s.size(); i++) {
    cs[i] = cs[i - 1] + a[s[i - 1] - 'a'];
  }
  long long ans = 0;
  for (char c = 'a'; c <= 'z'; c++) {
    for (long long i = 0; i < s.size(); i++) {
      if (s[i] == c) sum[cs[i + 1]]++;
    }
    for (long long i = 0; i < s.size(); i++) {
      if (s[i] == c) {
        sum[cs[i + 1]]--;
        ans += sum[cs[i + 1] + a[c - 'a']];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
