#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long hash[26];
  for (long long i = 0; i < 26; i++) cin >> hash[i];
  string s;
  cin >> s;
  vector<long long> position[200000];
  vector<long long> sum;
  long long c = 0;
  for (long long i = 0; i < s.length(); i++) {
    position[s[i] - 'a'].emplace_back(i);
    c += hash[s[i] - 'a'];
    sum.emplace_back(c);
  }
  long long ans = 0;
  for (long long i = 0; i < 26; i++) {
    map<long long, long long> v;
    for (long long j = 0; j < position[i].size(); j++) {
      ans += v[sum[position[i][j] - 1]];
      v[sum[position[i][j]]]++;
    }
  }
  cout << ans;
}
