#include <bits/stdc++.h>
using namespace std;
const int nmax = 100007;
int a[27];
map<long long, int> m[27];
long long sum[nmax];
int main() {
  string s;
  long long ans = 0;
  for (int i = 0; i < 26; i++) cin >> a[i];
  cin >> s;
  sum[0] = a[s[0] - 'a'];
  m[s[0] - 'a'][sum[0]]++;
  for (int i = 0; i < s.length(); i++) {
    if (i == 0) continue;
    sum[i] = sum[i - 1] + a[s[i] - 'a'];
    ans += m[s[i] - 'a'][sum[i] - a[s[i] - 'a']];
    m[s[i] - 'a'][sum[i]]++;
  }
  cout << ans;
  return 0;
}
