#include <bits/stdc++.h>
using namespace std;
long long int const inf = 1e18;
long long int const maxn = 2e5 + 5;
long long int const mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<long long int> arr(26);
  for (auto &u : arr) cin >> u;
  string s;
  cin >> s;
  long long int n = s.length();
  map<long long int, long long int> mp[26];
  vector<long long int> brr(n);
  for (long long int i = 0; i < n; i++) {
    brr[i] = arr[s[i] - 'a'];
    if (i != 0) brr[i] += brr[i - 1];
  }
  long long int ans = 0;
  mp[s[0] - 'a'][brr[0]]++;
  for (long long int i = 1; i < n; i++) {
    ans += mp[s[i] - 'a'][brr[i - 1]];
    mp[s[i] - 'a'][brr[i]]++;
  }
  cout << ans << "\n";
  ;
  return 0;
}
