#include <bits/stdc++.h>
using namespace std;
long long ans, arr[40], i, j, l, dp[100001];
char str[100001];
map<long long, int> mymap[30];
int main() {
  for (i = 0; i < 26; i++) cin >> arr[i];
  scanf("%s", str);
  l = strlen(str);
  memset(dp, 0, sizeof(dp));
  ans = 0;
  dp[0] = arr[str[0] - 'a'];
  mymap[str[0] - 'a'][dp[0]]++;
  for (i = 1; i < l; i++) {
    dp[i] = dp[i - 1] + arr[str[i] - 'a'];
    ans = ans + mymap[str[i] - 'a'][dp[i - 1]];
    mymap[str[i] - 'a'][dp[i]]++;
  }
  cout << ans;
}
