#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long MOD = 1e9 + 7;
const long long INF = 0x3F3F3F3F3F3F3F3F;
long double EPS = 1e-12;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ifstream fin("ip.txt");
  ofstream fout("op.txt");
  {
    long long v[26];
    for (long long i = (0); i <= (25); i++) cin >> v[i];
    string s;
    cin >> s;
    vector<long long> ind[26];
    long long n = s.length();
    for (long long i = (0); i <= (n - 1); i++) ind[s[i] - 'a'].push_back(i);
    long long psm[n + 1];
    psm[0] = 0;
    for (long long i = (1); i <= (n); i++)
      psm[i] = psm[i - 1] + v[s[i - 1] - 'a'];
    long long ans = 0;
    for (long long i = (0); i <= (25); i++) {
      if (ind[i].empty()) continue;
      long long m = (long long)ind[i].size();
      map<long long, long long> hsh;
      hsh[psm[ind[i][0] + 1]]++;
      for (long long j = (1); j <= (m - 1); j++) {
        if (hsh.find(psm[ind[i][j]]) != hsh.end()) ans += hsh[psm[ind[i][j]]];
        hsh[psm[ind[i][j] + 1]]++;
      }
    }
    cout << ans << endl;
  }
}
