#include <bits/stdc++.h>
using namespace std;
template <class T>
T &get(T &n) {
  cin >> n;
  return n;
}
const int hell = 1000000007;
const long long INF = (long long)hell * hell;
const int MAXN = 5e6 + 10;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  vector<int> value(26);
  for (int i = 0; i < 26; ++i) cin >> value[i];
  string s;
  cin >> s;
  int N = s.length();
  long long S = 0, ans = 0;
  map<long long, vector<vector<int> > > start, end;
  for (int i = 0; i < N - 1; ++i) {
    int idx = s[i] - 'a';
    int nidx = s[i + 1] - 'a';
    S += value[idx];
    if (start.find(S) == start.end()) {
      start[S].resize(26);
      end[S].resize(26);
    }
    start[S][idx].push_back(i);
    end[S][nidx].push_back(i + 1);
  }
  for (auto it = (start).begin(); it != (start).end(); it++) {
    long long sum = it->first;
    for (int i = 0; i < 26; ++i) {
      int sz = it->second[i].size();
      for (int j = 0; j < sz; ++j) {
        int idx = it->second[i][j];
        int cnt2 = end[sum][i].end() -
                   upper_bound(end[sum][i].begin(), end[sum][i].end(), idx);
        ans += cnt2;
      }
    }
  }
  cout << ans;
  return 0;
}
