#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int sz, cost[26];
string s;
map<pair<char, long long int>, int> mp;
int main() {
  for (int i = 0; i < 26; i++) scanf("%d", &cost[i]);
  cin >> s;
  sz = s.size();
  long long int sum = 0, ans = 0;
  for (int i = 0; i < sz - 1; i++) {
    sum += cost[s[i] - 'a'];
    ans += mp[make_pair(s[i + 1], sum)];
    mp[make_pair(s[i], sum)]++;
  }
  for (int i = 0; i < sz - 1; i++)
    if (s[i] == s[i + 1]) ans++;
  cout << ans << endl;
  return 0;
}
