#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
int X[] = {-1, -1, -1, 0, 1, 1, 1, 0};
int Y[] = {-1, 0, +1, 1, 1, 0, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
map<pair<int, long long>, long long> mp;
int val[30];
long long cumSum;
int main() {
  for (int i = 0; i < 26; i++) read(val[i]);
  cumSum = 0;
  string str;
  cin >> str;
  long long ans = 0;
  for (int i = 0; i < str.size(); i++) {
    int c = str[i] - 'a';
    ans += mp[pair<int, long long>(c, cumSum)];
    cumSum += val[c];
    mp[pair<int, long long>(c, cumSum)]++;
  }
  cout << ans << endl;
  return 0;
}
