#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[26];
  for (int i = 0; i < 26; i++) cin >> arr[i];
  string s;
  cin >> s;
  int n = s.size();
  map<long long, int> mp[26];
  long long sum[n];
  sum[0] = arr[s[0] - 'a'];
  for (int i = 1; i < n; i++) {
    sum[i] = arr[s[i] - 'a'];
    sum[i] += sum[i - 1];
  }
  long long ans = 0;
  mp[s[0] - 'a'][sum[0]] = 1;
  for (int i = 1; i < n; i++) {
    long long x = mp[s[i] - 'a'][sum[i - 1]];
    ans += x;
    mp[s[i] - 'a'][sum[i]]++;
  }
  cout << ans << endl;
}
