#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int val[27];
char a[N];
int n;
map<long long, int> h[26];
int main() {
  int i;
  for (i = 0; i < 26; ++i) {
    cin >> val[i];
  }
  cin >> (a + 1);
  n = strlen(a + 1);
  long long sc = 0, rez = 0;
  for (i = 1; i <= n; ++i) {
    a[i] -= 'a';
    sc += val[a[i]];
    rez += h[a[i]][sc - val[a[i]]];
    h[a[i]][sc]++;
  }
  cout << rez;
  return 0;
}
