#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int main() {
  int price[30];
  for (int i = 0; i < 26; ++i) {
    cin >> price[i];
  }
  string s;
  cin >> s;
  const int N = 1e5 + 5;
  long long pref[N] = {
      0,
  };
  int n = s.size();
  for (int i = 1; i <= n; ++i) {
    pref[i] = pref[i - 1] + price[s[i - 1] - 'a'];
  }
  map<long long, long long> quantity[26];
  long long answer = 0;
  for (int end = 1; end <= n; ++end) {
    int c = s[end - 1] - 'a';
    long long sum = pref[end - 1];
    answer += quantity[c][sum];
    ++quantity[c][pref[end]];
  }
  cout << answer << endl;
  return 0;
}
