#include <bits/stdc++.h>
using namespace std;
vector<int> v[5000];
string s;
queue<int> q;
long long F = 1, n, m, k, ans, a[100005], f[100005], d[100005];
int main() {
  for (int i = 0; i < 26; i++) cin >> a[i];
  cin >> s;
  n = s.size();
  for (int i = 0; i < n; i++) {
    d[i] = a[s[i] - 'a'] + d[i - 1];
    v[s[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < 26; i++) {
    map<long long, int> mp;
    for (int j = 0; j < v[i].size(); j++) {
      ans += mp[d[v[i][j] - 1]];
      mp[d[v[i][j]]]++;
    }
  }
  cout << ans << endl;
}
