#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const long long inf = 0x3f3f3f3f3f3f3f3fLL;
const long long N = 3e5 + 10;
const long long MOD = 1e9 + 7;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<long long> cnt(26);
  for (long long i = 0; i < 26; i++) {
    cin >> cnt[i];
  }
  string s;
  cin >> s;
  long long n = (long long)s.size();
  vector<long long> sum(n + 1);
  vector<vector<long long>> pos(26);
  for (long long i = 0; i < n; i++) {
    sum[i + 1] = cnt[s[i] - 'a'];
    sum[i + 1] += sum[i];
    pos[s[i] - 'a'].push_back(i + 1);
  }
  long long ans = 0;
  for (long long i = 0; i < 26; i++) {
    map<long long, long long> mp;
    for (long long j = 0; j < pos[i].size(); j++) {
      long long p = pos[i][j];
      ans += mp[sum[p - 1]];
      mp[sum[p]]++;
    }
    mp.clear();
  }
  cout << ans << '\n';
  return 0;
}
