#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[26], sum[100000], ans = 0;
  string s;
  map<pair<long long, char>, long long> m;
  for (int i = 0; i < 26; ++i) cin >> a[i];
  cin >> s;
  sum[0] = a[s[0] - 'a'];
  for (int i = 1; i < s.length(); ++i) sum[i] = sum[i - 1] + a[s[i] - 'a'];
  for (int i = 0; i < s.length() - 1; ++i) {
    ++m[make_pair(sum[i], s[i])];
    ans += m[make_pair(sum[i], s[i + 1])];
  }
  cout << ans;
}
