#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long N = 3e5;
long long arr[26], n, pref[N], ans;
string a;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (int i = 0; i < 26; i++) cin >> arr[i];
  cin >> a;
  n = a.size();
  map<pair<long long, char>, long long> b;
  for (int i = 0; i < n - 1; i++) {
    pref[i] = arr[a[i] - 'a'];
    if (i == 0) {
      b[{pref[i], a[i]}]++;
      continue;
    }
    if (a[i] == a[i - 1]) ans++;
    pref[i] += pref[i - 1];
    pair<long long, char> k = {pref[i], a[i + 1]};
    ans += b[k];
    b[{pref[i], a[i]}]++;
  }
  cout << ans + (a[n - 1] == a[n - 2]);
}
