#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long fh = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= fh;
}
template <typename T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
long long val[30];
long long n;
long long s[100005];
long long sum[100005];
long long dp[100005];
map<long long, long long> pre[30];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (long long i = 0; i < 26; i++) cin >> val[i];
  string str;
  cin >> str;
  n = str.size();
  for (long long i = 0; i < str.size(); i++) s[i + 1] = str[i] - 'a';
  for (long long i = 1; i <= n; i++) {
    sum[i] = val[s[i]];
    sum[i] += sum[i - 1];
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    dp[i] = pre[s[i]][sum[i - 1]];
    pre[s[i]][sum[i]]++;
    ans += dp[i];
  }
  cout << ans << endl;
  return 0;
}
