#include <bits/stdc++.h>
using namespace std;
struct temp {
  unordered_map<long long, int> mp;
};
int main() {
  ios_base::sync_with_stdio(false);
  long long sum = 0, ans = 0;
  vector<int> val(26);
  string str;
  temp mpc[26];
  for (int i = 0; i < 26; i++) cin >> val[i];
  cin >> str;
  for (int i = 0; i < str.size(); i++) {
    int ch = str[i] - 'a';
    if (mpc[ch].mp[sum] != 0) ans += mpc[ch].mp[sum];
    sum += val[ch];
    mpc[ch].mp[sum]++;
  }
  cout << ans << "\n";
  return 0;
}
