#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
using plc = pair<ll, char>;
using vll = vector<ll>;
using vld = vector<ld>;
using vvll = vector<vll>;
using vvld = vector<vld>;
using vpll = vector<pll>;
using vpld = vector<pld>;
using vplc = vector<plc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vc = vector<char>;
using vvc = vector<vc>;
using mll = map<ll, ll>;
using sll = set<ll>;
const ll MOD = 1e9 + 7, LIM = 1e6 + 5, INF = 1e18 + 5;
const ld ERR = 1e-9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll tc = 1;
  while (tc--) {
    vll x(26);
    for (ll i = 0; i < 26; i++) cin >> x[i];
    string s;
    cin >> s;
    ll n = s.length();
    vll dp(n);
    for (ll i = 0; i < n; i++)
      dp[i] = ((i > 0) ? dp[i - 1] : 0) + x[s[i] - 'a'];
    vvll idx1(26);
    for (ll i = 0; i < n; i++) idx1[s[i] - 'a'].push_back(i);
    ll cnt = 0;
    for (ll i = 0; i < 26; i++) {
      if (idx1[i].size() >= 2) {
        map<ll, vll> idx2;
        for (ll idx : idx1[i]) {
          idx2[dp[idx]].push_back(idx);
        }
        for (ll idx : idx1[i]) {
          cnt += (upper_bound(idx2[dp[idx - 1]].begin(),
                              idx2[dp[idx - 1]].end(), idx - 1) -
                  idx2[dp[idx - 1]].begin());
        }
      }
    }
    cout << cnt;
  }
}
