#include <bits/stdc++.h>
using namespace std;
const int MAX = (const int)(1e5 + 11);
int A[33];
int64_t P[MAX];
map<int64_t, int> M[33];
vector<int> all[33];
static void solve(std::int32_t test) {
  memset(P, 0, sizeof(P));
  for (int i = 0; i < 33; ++i) {
    M[i].clear();
    all[i].clear();
  }
  for (int i = 0; i < 26; ++i) cin >> A[i];
  string S;
  cin >> S;
  for (int i = 0; i < S.length(); ++i) all[S[i] - 'a'].push_back(i);
  for (int i = 0; i < S.length(); ++i) P[i + 1] = P[i] + A[S[i] - 'a'];
  int64_t res = 0;
  for (int i = 0; i < 26; ++i) {
    auto &m = M[i];
    for (const auto &j : all[i]) {
      res += m[P[j] - A[i]];
      m[P[j]]++;
    }
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout << setprecision(12) << fixed;
  solve(0);
  return 0;
}
