#include <bits/stdc++.h>
using namespace std;
void online_judge() {}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  online_judge();
  {
    long long int a[26];
    for (long long int i = 0; i < 26; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    long long int n = s.size();
    long long int prefix[n];
    memset(prefix, 0, sizeof(prefix));
    prefix[0] = a[s[0] - 'a'];
    for (long long int i = 1; i < n; ++i) {
      prefix[i] = prefix[i - 1] + a[s[i] - 'a'];
    }
    long long int gg = 0;
    map<char, vector<long long int>> same_letters;
    long long int sum = 0;
    for (long long int i = 7; i <= 20; i++) {
      sum += a[s[i] - 'a'];
    }
    for (long long int i = 0; i < n; i++) {
      same_letters[s[i]].push_back(i);
    }
    long long int ans = 0;
    for (auto x : same_letters) {
      if (x.second.size() < 2) continue;
      vector<long long int> temp;
      for (long long int i = 0; i < x.second.size() - 1; i++) {
        long long int r = x.second[i + 1];
        long long int l = x.second[i];
        temp.push_back(prefix[r] - prefix[l]);
      }
      long long int required_cost = a[x.first - 'a'];
      long long int curr_sum = 0;
      map<long long int, long long int> sums;
      sums[curr_sum]++;
      for (long long int i = 0; i < temp.size(); i++) {
        curr_sum += temp[i];
        ans += sums[curr_sum - required_cost];
        sums[curr_sum]++;
      }
    }
    cout << ans;
  }
  return 0;
}
