#include <bits/stdc++.h>
using namespace std;
map<long long, int> m[26];
long long sum, ans, val[26];
int main() {
  for (int i = 0; i < 26; i++) cin >> val[i];
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    ans += m[s[i] - 'a'][sum];
    sum += val[s[i] - 'a'];
    m[s[i] - 'a'][sum]++;
  }
  cout << ans << endl;
}
