#include <bits/stdc++.h>
using namespace std;
string s;
map<long long, int> mp[26];
map<char, int> t;
int main() {
  ios::sync_with_stdio(false);
  for (char i = 'a'; i <= 'z'; i++) cin >> t[i];
  cin >> s;
  int n = s.size();
  long long cur = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (mp[s[i] - 'a'].count(cur)) ans += mp[s[i] - 'a'][cur];
    cur += t[s[i]];
    ++mp[s[i] - 'a'][cur];
  }
  cout << ans << endl;
  return 0;
}
