#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
map<long long, int> f[26];
int a[26];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  for (int i = 0; i < 26; ++i) cin >> a[i];
  string s;
  cin >> s;
  int n = s.size();
  s = " " + s;
  long long ans = 0, sum = 0;
  for (int i = 1; i <= n; ++i) {
    ++f[s[i] - 'a'][sum += 1LL * a[s[i] - 'a']];
    if (i < n) ans += 1LL * f[s[i + 1] - 'a'][sum];
  }
  cout << ans;
  return 0;
}
