#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
int const mod = 1e9 + 7;
int const INF = 1 << 29;
int const M = 1e5 + 5;
long long int sum[M], a[28];
string s;
map<pair<long long int, long long int>, int> mm;
int main() {
  for (int i = 0; i < 26; ++i) scanf("%I64d", &a[i]);
  cin >> s;
  int n = s.length();
  sum[0] = a[s[0] - 'a'];
  for (int i = 1; i < n; ++i) {
    int c = s[i] - 'a';
    sum[i] = sum[i - 1] + a[c];
  }
  long long int ans = 0;
  for (int i = 0; i + 1 < n; ++i) {
    long long int sm = sum[i];
    int c = s[i + 1] - 'a';
    ans += mm[make_pair(sm, c)];
    c = s[i] - 'a';
    ++mm[make_pair(sm, c)];
  }
  for (int i = 0; i + 1 < n; ++i) {
    if (s[i] == s[i + 1]) ++ans;
  }
  cout << ans;
  putchar('\n');
  return 0;
}
