#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (x < y) x = y;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T>
void print(T &ar) {
  for (auto itr = begin(ar); itr != end(ar); ++itr) cout << *itr << " ";
}
void solve() {
  long long ar[26], ans = 0;
  for (long long i = 0; i <= 25; ++i) cin >> ar[i];
  string s;
  cin >> s;
  vector<long long> sm(s.length() + 1, 0);
  map<long long, long long> mp[26];
  for (long long i = 1; i <= s.length(); ++i) {
    sm[i] = sm[i - 1] + ar[s[i - 1] - 'a'];
    ans += mp[s[i - 1] - 'a'][sm[i - 1]];
    mp[s[i - 1] - 'a'][sm[i]]++;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
