#include <bits/stdc++.h>
using namespace std;
long long mo(long long a) { return a % (long long)(1e9 + 7); }
long long po(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y >>= 1;
    x = (x * x) % p;
  }
  return res % p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<long long> sc(26);
  for (long long i = 0; i < sc.size(); i++) cin >> sc[i];
  ;
  string s;
  cin >> ws;
  cin >> s;
  cin >> ws;
  long long n = s.size();
  map<long long, long long> mp[26];
  long long sum = 0, ans = 0;
  ;
  for (long long i = 0; i < n; i++) {
    long long e = s[i] - 'a';
    ans += mp[e][sum];
    sum += sc[e];
    mp[e][sum]++;
  }
  cout << ans << "\n";
  return 0;
}
