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