#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
long long prefix[100002];
void solve() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int alpha[27];
  for (int i = 1; i < 27; i++) {
    cin >> alpha[i];
  }
  string a;
  cin >> a;
  int k = 1;
  vector<int> v[27];
  for (auto &b : a) {
    int o = b - 'a' + 1;
    prefix[k] = alpha[o];
    prefix[k] += prefix[k - 1];
    v[o].push_back(k);
    k++;
  }
  long long total = 0;
  for (int i = 1; i < 27; i++) {
    if (v[i].size() >= 2) {
      int p = v[i].size();
      for (int j = 0; j < p; j++) {
        for (int j1 = j + 1; j1 < p; j1++) {
          if (prefix[v[i][j1]] - prefix[v[i][j]] - alpha[i] == 0LL) {
            total++;
          }
        }
      }
    }
  }
  cout << total;
}
int main() {
  int test_cases = 1;
  while (test_cases-- > 0) {
    solve();
  }
}
