#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7, INF = 9e18;
long long a[26], sum, ans;
string s;
map<pair<long long, char>, long long> m;
long long pw(long long a, long long b) {
  long long res = 0;
  if (b == 0) return 1;
  if (b % 2 == 0) {
    res = pw(a, b / 2);
    return res * res;
  } else {
    res = pw(a, (b - 1) / 2);
    return a * res * res;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  for (int i = 0; i < 26; ++i) cin >> a[i];
  cin >> s;
  ++m[make_pair(0, s[0])];
  for (int i = 1; i < s.size() - 1; ++i) {
    sum += a[s[i] - 97];
    ans += m[make_pair(sum, s[i + 1])];
    ++m[make_pair(sum, s[i])];
  }
  for (int i = 0; i < s.size() - 1; ++i)
    if (s[i] == s[i + 1]) ++ans;
  cout << ans;
  return 0;
}
