#include <bits/stdc++.h>
using namespace std;
void cline() { cout << '\n'; }
template <typename T, typename... V>
void cline(T t, V... v) {
  cout << t;
  if (sizeof...(v)) cout << ' ';
  cline(v...);
}
void cspc() { cout << ' '; }
template <typename T, typename... V>
void cspc(T t, V... v) {
  cout << t;
  if (sizeof...(v)) cout << ' ';
  cspc(v...);
}
const long long N = 1e6 + 4;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long val[26];
  string s;
  for (long long i = 0; i < 26; i++) cin >> val[i];
  cin >> s;
  long long n = s.size();
  vector<long long> v[26];
  long long sum[n];
  sum[0] = val[s[0] - 'a'];
  v[s[0] - 'a'].push_back(0);
  for (long long i = 1; i < n; i++) {
    sum[i] = val[s[i] - 'a'] + sum[i - 1];
    v[s[i] - 'a'].push_back(i);
  }
  long long ans = 0;
  for (long long i = 0; i < 26; i++) {
    if (v[i].size() > 1) {
      map<long long, long long> fro;
      for (long long j = 0; j < v[i].size(); j++) {
        if (v[i][j] == 0) {
          ans += fro[0];
        } else {
          ans += fro[sum[v[i][j] - 1]];
        }
        fro[sum[v[i][j]]]++;
      }
    }
  }
  cspc(ans);
  return 0;
}
