#include <bits/stdc++.h>
using namespace std;
class Debugger {
 public:
  Debugger(const std::string& _separator = " | ")
      : first(true), separator(_separator) {}
  template <typename ObjectType>
  Debugger& operator,(const ObjectType& v) {
    if (!first) std::cerr << separator;
    std::cerr << v;
    first = false;
    return *this;
  }
  ~Debugger() { std::cerr << std::endl; }

 private:
  bool first;
  std::string separator;
};
long long value[26];
std::vector<long long> seg[26];
void solve() {
  for (long long i = 0; i < 26; ++i) cin >> value[i];
  string s;
  cin >> s;
  long long n = s.size();
  std::vector<long long> pre(n + 1, 0);
  for (long long i = 0; i < n; ++i) {
    seg[s[i] - 'a'].push_back(i);
    pre[i] = pre[i - 1] + value[s[i] - 'a'];
  }
  long long ans = 0;
  map<long long, long long> mp;
  for (long long i = 0; i < 26; ++i) {
    if (seg[i].size() < 2) continue;
    mp.clear();
    mp[0] = 1;
    for (long long j = 1; j < seg[i].size(); ++j) {
      long long temp = pre[seg[i][j] - 1] - pre[seg[i][0]];
      if (mp.count(temp)) {
        ans += mp[temp];
      }
      mp[pre[seg[i][j]] - pre[seg[i][0]]]++;
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0),
      cout << fixed << setprecision(10);
  ;
  long long T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
};
