#include <bits/stdc++.h>
using namespace std;
using namespace std;
vector<long long> x;
string y;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  x.push_back(0);
  for (long long i = 0; i < 26; i++) {
    long long k;
    cin >> k;
    x.push_back(k);
  };
  cin >> y;
  long long sum = 0;
  map<long long, vector<long long> > p;
  long long ans = 0;
  for (long long i = 0; i < (long long)y.size() - 1; i++) {
    long long z = (y[i] - 'a') + 1;
    long long q = (y[i + 1] - 'a') + 1;
    sum += x[z];
    if (q == z) {
      ans++;
    }
    if (p.find(sum) == p.end()) {
      vector<long long> r(28, 0);
      r[z]++;
      p[sum] = r;
      continue;
    }
    ans += p[sum][q];
    p[sum][z]++;
  }
  cout << ans;
  return 0;
}
