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