#include <bits/stdc++.h>
int main() {
  std::string values;
  std::getline(std::cin, values);
  std::stringstream stream(values);
  std::array<int, 26> alph;
  for (auto i = 0u; i < 26; ++i) stream >> alph[i];
  std::string s;
  std::getline(std::cin, s);
  std::vector<long long> part_sum(s.size());
  std::array<std::vector<int>, 26> pos;
  for (auto i = 0u; i < s.size(); ++i) {
    if (!i)
      part_sum[0] = alph[s[0] - 'a'];
    else
      part_sum[i] = part_sum[i - 1] + alph[s[i] - 'a'];
    pos[s[i] - 'a'].push_back(i);
  }
  long long total = 0;
  for (auto i = 0; i < 26; ++i) {
    std::unordered_map<long long, int> m;
    for (auto j = 0u; j < pos[i].size(); ++j) {
      if (m.count(part_sum[pos[i][j]] - alph[i]))
        total += m.find(part_sum[pos[i][j]] - alph[i])->second;
      if (m.count(part_sum[pos[i][j]]))
        ++m.find(part_sum[pos[i][j]])->second;
      else
        m.emplace(part_sum[pos[i][j]], 1);
    }
  }
  std::cout << total;
  return 0;
}
