#include <bits/stdc++.h>
using namespace std;
const int N = 100000, A = 26;
char cc[N + 1];
int xx[A];
long long pp[N];
map<long long, int> mp[A];
int main() {
  for (int a = 0; a < A; a++) cin >> xx[a];
  cin >> cc;
  int n = strlen(cc);
  pp[0] = xx[cc[0] - 'a'];
  for (int i = 1; i < n; i++) pp[i] = pp[i - 1] + xx[cc[i] - 'a'];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (i > 0) ans += mp[cc[i] - 'a'][pp[i - 1]];
    mp[cc[i] - 'a'][pp[i]]++;
  }
  cout << ans << '\n';
  return 0;
}
