#include <bits/stdc++.h>
using namespace std;
int x[26];
string s;
int a[100000], n;
map<pair<int, long long>, int> cnt;
int main() {
  ios_base::sync_with_stdio(false);
  for (int i = 0; i < (int)(26); ++i) cin >> x[i];
  cin >> s;
  n = (int)s.length();
  for (int i = 0; i < (int)(n); ++i) a[i] = s[i] - 'a';
  long long ans = 0, tot = 0;
  for (int i = 0; i < (int)(n); ++i) {
    ans += cnt[make_pair(a[i], tot)];
    tot += x[a[i]];
    ++cnt[make_pair(a[i], tot)];
  }
  cout << ans << endl;
  return 0;
}
