#include <bits/stdc++.h>
using namespace std;
long long X, T, V[256], i;
string S;
map<pair<long long, long long>, long long> M;
int main() {
  for (i = 0; i < 26; i++) cin >> V['a' + i];
  cin >> S;
  for (i = 0; i < S.size(); i++)
    X += M[{S[i], T}], T += V[S[i]], M[{S[i], T}]++;
  cout << X;
}
