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