#include <bits/stdc++.h>
using namespace std;
map<char, long long> mp;
map<pair<char, long long>, long long> cnt;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (char c = 'a'; c <= 'z'; c++) cin >> mp[c];
  string s;
  cin >> s;
  long long n = s.length();
  long long sum = mp[s[0]];
  cnt[{s[0], mp[s[0]]}]++;
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    ans += cnt[{s[i], sum}];
    sum += mp[s[i]];
    cnt[{s[i], sum}]++;
  }
  cout << ans;
  return 0;
}
