#include <bits/stdc++.h>
using namespace std;
long long int precal[100005];
map<long long int, long long int> s[26];
vector<int> v;
long long int nc2(long long int x) {
  x = (x) * (x - 1);
  x /= 2;
  return x;
}
int main() {
  int i, j, val;
  long long int ans = 0;
  for (i = 0; i < 26; i++) {
    cin >> val;
    v.push_back(val);
  }
  string str;
  cin >> str;
  str = "#" + str;
  long long int sum = 0;
  for (i = 1; i < str.length(); i++) {
    int to = int(str[i]) - 97;
    sum += v[to];
    precal[i] = sum;
  }
  long long int tmp;
  for (i = 1; i < str.length(); i++) {
    int to = int(str[i]) - 97;
    tmp = precal[i];
    tmp -= v[to];
    ans += s[to][tmp];
    s[to][precal[i]]++;
  }
  cout << ans;
  return 0;
}
