#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vpii = vector<pair<int, int> >;
using vpll = vector<pair<long long, long long> >;
using vld = vector<long double>;
using vb = vector<bool>;
const int inf = (int)1e9 + 7;
const long long llinf = (long long)1e18 + 7;
void solve() {
  long long x[27];
  for (long long i = 0; i < 26; i++) {
    cin >> x[i];
  }
  string s;
  cin >> s;
  map<long long, long long> m[257];
  long long p = 0;
  long long ans = 0;
  for (long long i = 0; i < (s.size()); i++) {
    ans += m[s[i] - 'a'][p];
    p += x[s[i] - 'a'];
    m[s[i] - 'a'][p]++;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int ttt = 1;
  while (ttt--) {
    solve();
  }
}
