#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 1e3;
long long val[26];
long long sum[Maxn];
vector<int> Occ[26];
map<long long, int> small;
map<long long, int> big;
string second;
int main() {
  ios_base::sync_with_stdio(0);
  for (int i = (0); i < ((int)26); ++i) cin >> val[i];
  cin >> second;
  int n = second.size();
  sum[0] = val[second[0] - 'a'];
  for (int i = (1); i < ((int)n); ++i) {
    sum[i] = sum[i - 1] + val[second[i] - 'a'];
  }
  long long ans = 0;
  for (int i = (0); i < ((int)26); ++i) {
    for (int j = (0); j < ((int)n); ++j) {
      if (second[j] - 'a' == i) {
        if (j) ans += small[sum[j - 1]];
        small[sum[j]]++;
        if (j) big[sum[j - 1]]++;
      }
    }
    big.clear();
    small.clear();
  }
  cout << ans << endl;
  return 0;
}
