#include <bits/stdc++.h>
using namespace std;
int const mod = 1000000007;
long long c[26], a[100005];
vector<int> x[26];
int main() {
  ios::sync_with_stdio(false);
  string s;
  long long cnt = 0;
  for (int i = 0; i < 26; i++) cin >> c[i];
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    a[i + 1] = a[i] + c[s[i] - 'a'];
    x[s[i] - 'a'].push_back(i + 1);
  }
  for (int i = 0; i < 26; i++) {
    map<long long, long long> w;
    for (auto it : x[i]) {
      cnt += w[a[it - 1]];
      w[a[it]]++;
    }
  }
  cout << cnt;
  return 0;
}
