#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 100;
char str[maxn];
int num[30];
map<long long, int> mp[30];
int main() {
  while (~scanf("%d", &num[0])) {
    for (int i = 1; i <= 25; ++i) scanf("%d", &num[i]);
    for (int i = 0; i < 26; ++i) mp[i].clear();
    scanf("%s", str);
    int len = strlen(str);
    long long ans = 0, sum = 0;
    for (int i = 0; i < len; ++i) {
      int x = str[i] - 'a';
      if (mp[x][sum]) ans += mp[x][sum];
      sum += (long long)num[x];
      mp[x][sum]++;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
