#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const int maxn = 100010;
long long ans;
int al[26];
long long gpa[maxn];
map<long long, long long> be[26];
int l;
char ch;
int main() {
  for (int i = 0; i < 26; i++) scanf("%d", &al[i]);
  getchar();
  int l = 0;
  while (scanf("%c", &ch) == 1 && ch <= 'z' && ch >= 'a') {
    l++;
    int t = ch - 'a';
    if (l == 1) {
      gpa[0] = al[t];
      be[t][gpa[0]]++;
      continue;
    }
    gpa[l - 1] = al[t] + gpa[l - 2];
    ans += be[t][gpa[l - 2]];
    be[t][gpa[l - 1]]++;
  }
  cout << ans;
  return 0;
}
