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