#include <bits/stdc++.h>
using namespace std;
class p1328D {
 public:
  void solve() {
    int q;
    cin >> q;
    while (q--) {
      int n;
      cin >> n;
      vector<int> t(n);
      for (int i = 0; i < n; i++) cin >> t[i];
      int sum = 1;
      for (int i = 1; i < n; i++) {
        if (t[i] == t[i - 1]) sum++;
      }
      if (sum == n) {
        cout << 1 << endl;
        for (int i = 0; i < n; i++) cout << 1 << " ";
        cout << endl;
      } else if (n % 2 == 0 || t.back() == t.front()) {
        cout << 2 << endl;
        for (int i = 0; i < n; i++) cout << i % 2 + 1 << " ";
        cout << endl;
      } else if (sum > 1) {
        cout << 2 << endl;
        bool can = true;
        for (int i = 0; i < n; i++) {
          if (can && i > 0 && t[i] == t[i - 1]) {
            cout << (i - 1) % 2 + 1 << " ";
            can = false;
          } else if (!can)
            cout << (i - 1) % 2 + 1 << ' ';
          else
            cout << i % 2 + 1 << ' ';
        }
        cout << endl;
      } else {
        cout << 3 << endl;
        for (int i = 0; i < n - 1; i++) cout << i % 2 + 1 << " ";
        cout << 3 << endl;
      }
    }
  }
};
class p1327E {
 public:
  long long MOD = 998244353;
  long long fastpow(long long x, long long n) {
    if (n == 0) return 1ll;
    if (n == 1) return x;
    long long temp = fastpow(x, n / 2);
    if (n % 2 == 0)
      return (temp * temp) % MOD;
    else
      return (((x * temp) % MOD) * temp) % MOD;
  }
  void solve() {
    int n;
    cin >> n;
    if (n < 2) {
      cout << 10 << endl;
      return;
    }
    int maxn = 2e5 + 10;
    vector<long long> dp(maxn, 1);
    for (int i = 1; i <= maxn; i++) {
      dp[i] = (dp[i - 1] * 10) % MOD;
    }
    for (int i = 1; i < n; i++) {
      long long res = 2 * 10 * 9 * dp[n - i - 1] % MOD;
      res += (n - i - 1) * 10 * 9 * 9 * dp[n - i - 2] % MOD;
      cout << res % MOD << " ";
    }
    cout << 10 << endl;
  }
};
class p161D {
 public:
  long long res, k, n;
  vector<vector<int>> e;
  vector<vector<long long>> dp;
  void dfs(int cur, int fa) {
    dp[cur][0] = 1;
    for (int c : e[cur]) {
      if (c == fa) continue;
      dfs(c, cur);
      for (int i = 1; i <= k; i++) {
        dp[cur][i] += dp[c][i - 1];
      }
    }
    res += dp[cur][k];
    long long temp = 0;
    for (int c : e[cur]) {
      if (c == fa) continue;
      for (int i = 0; k - 2 - i >= 0; i++) {
        temp += dp[c][i] * (dp[cur][k - i - 1] - dp[c][k - i - 2]);
      }
    }
    res += temp / 2;
  }
  void solve() {
    cin >> n >> k;
    e = vector<vector<int>>(n + 1);
    dp = vector<vector<long long>>(n + 1, vector<long long>(k + 1, 0));
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      cin >> a >> b;
      e[a].push_back(b);
      e[b].push_back(a);
    }
    res = 0;
    dfs(1, 0);
    cout << res << endl;
  }
};
class p1437C {
 public:
  void solve() {
    int q;
    cin >> q;
    while (q--) {
      int n;
      cin >> n;
      vector<int> t(n);
      for (int i = 0; i < n; i++) cin >> t[i];
      sort(t.begin(), t.end());
      vector<vector<int>> dp(2 * n + 1, vector<int>(n + 1, 0x3f3f3f3f));
      dp[0][0] = 0;
      int res = 0x3f3f3f3f;
      for (int k = 1; k <= 2 * n; k++) {
        for (int i = 1; i <= n; i++) {
          for (int pre = 0; pre <= k - 1; pre++) {
            dp[k][i] = min(dp[k][i], dp[pre][i - 1] + abs(t[i - 1] - k));
          }
        }
        res = min(res, dp[k][n]);
      }
      cout << res << endl;
    }
  }
};
class p1038D {
 public:
  void solve() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    if (n == 1) {
      cout << a[0] << endl;
      return;
    }
    long long ans = 0, minval = 0x3f3f3f3f;
    bool pos = 0, neg = 0;
    for (int i = 0; i < n; i++) {
      ans += abs(a[i]);
      pos |= (a[i] >= 0);
      neg |= (a[i] <= 0);
      minval = min(minval, abs(a[i]));
    }
    if (pos && neg)
      cout << ans << endl;
    else
      cout << ans - 2 * minval << endl;
  }
};
class p1286A {
 public:
  void solve() {
    int n;
    cin >> n;
    vector<int> p(n);
    unordered_set<int> cnt;
    for (int i = 1; i <= n; i++) cnt.insert(i);
    for (int i = 0; i < n; i++) {
      cin >> p[i];
      if (p[i] != 0) cnt.erase(p[i]);
    }
    int odd = 0, even = 0;
    for (int i : cnt)
      if (i % 2)
        odd++;
      else
        even++;
    vector<vector<vector<int>>> dp(
        n + 1, vector<vector<int>>(n + 1, vector<int>(2, 0x3f3f3f3f)));
    dp[0][0][0] = dp[0][0][1] = 0;
    for (int i = 1; i <= n; i++) {
      int cur = p[i - 1] % 2;
      for (int j = 0; j <= min(odd, i); j++) {
        if (p[i - 1] != 0) {
          dp[i][j][cur] =
              min(dp[i - 1][j][0] + (0 ^ cur), dp[i - 1][j][1] + (1 ^ cur));
        } else {
          if (j >= 1) {
            dp[i][j][1] = min(
                dp[i][j][1], min(dp[i - 1][j - 1][0] + 1, dp[i - 1][j - 1][1]));
          }
          dp[i][j][0] =
              min(dp[i][j][0], min(dp[i - 1][j][0], dp[i - 1][j][1] + 1));
        }
      }
    }
    cout << min(dp[n][odd][0], dp[n][odd][1]) << endl;
  }
};
class p580D {
 public:
  void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<long long> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    vector<vector<long long>> cost(n + 1, vector<long long>(n + 1, 0));
    vector<vector<long long>> dp(1 << n, vector<long long>(n + 1, 0));
    for (int i = 0; i < k; i++) {
      long long x, y, c;
      cin >> x >> y >> c;
      cost[x][y] = c;
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      dp[1 << (i - 1)][i] = a[i];
    }
    for (int i = 1; i < (1 << n); i++) {
      int cnt = bitset<32>(i).count();
      for (int j = 1; j <= n; j++) {
        if ((i & (1 << (j - 1))) != 0) {
          int pre = i ^ (1 << (j - 1));
          for (int k = 1; k <= n; k++) {
            if ((pre & (1 << (k - 1))) == 0) continue;
            dp[i][j] = max(dp[i][j], dp[pre][k] + cost[k][j] + a[j]);
          }
          if (cnt == m) ans = max(ans, dp[i][j]);
        }
      }
    }
    cout << ans << endl;
  }
};
class p1335E2 {
 public:
  void solve() {
    int t;
    cin >> t;
    while (t--) {
      int n;
      cin >> n;
      vector<int> a(n + 1);
      for (int i = 1; i <= n; i++) cin >> a[i];
      vector<vector<int>> sum(n + 1, vector<int>(205, 0));
      vector<vector<int>> pos(205);
      int res = 0;
      for (int i = 1; i <= n; i++) {
        sum[i][a[i]]++;
        for (int j = 1; j <= 200; j++) {
          sum[i][j] += sum[i - 1][j];
          res = max(res, sum[i][j]);
        }
        pos[a[i]].push_back(i);
      }
      for (int i = 1; i <= 200; i++) {
        int len = pos[i].size();
        for (int k = 0; k < len - 1 - k; k++) {
          int l = pos[i][k], r = pos[i][len - 1 - k] - 1;
          int mid = 0;
          for (int j = 1; j <= 200; j++) {
            mid = max(mid, sum[r][j] - sum[l][j]);
          }
          res = max(res, 2 * (k + 1) + mid);
        }
      }
      cout << res << endl;
    }
  }
};
class p1221D {
 public:
  void solve() {
    int t;
    cin >> t;
    while (t--) {
      int n;
      cin >> n;
      vector<long long> a(n + 1), b(n + 1);
      a[0] = 0;
      for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
      vector<vector<long long>> dp(n + 1, vector<long long>(4, -1));
      dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = 0;
      long long res = LONG_LONG_MAX;
      for (long long i = 1; i <= n; i++) {
        for (long long j = 0; j <= 2; j++) {
          for (int k = 0; k <= 2; k++) {
            if (a[i] + j != a[i - 1] + k) {
              auto cur = j * b[i] + dp[i - 1][k];
              dp[i][j] = dp[i][j] == -1 ? cur : min(dp[i][j], cur);
            }
          }
          if (i == n) res = min(res, dp[i][j]);
        }
      }
      cout << res << endl;
    }
  }
};
class p543A {
 public:
  void solve() {
    int n, m, b, md;
    cin >> n >> m >> b >> md;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    vector<vector<int>> dp(m + 1, vector<int>(b + 1, 0));
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
      for (int k = 0; k <= m; k++) {
        for (int j = 0; j <= b; j++) {
          if (j >= a[i] && k > 0)
            dp[k][j] = (dp[k][j] + dp[k - 1][j - a[i]]) % md;
        }
      }
    }
    long long res = 0;
    for (int i = 0; i <= b; i++) res = (res + dp[m][i]) % md;
    cout << res << endl;
  }
};
class p1142A {
 public:
  void solve() {
    int t;
    cin >> t;
    while (t--) {
      int n;
      cin >> n;
      vector<int> a(n);
      for (int i = 0; i < n; i++) cin >> a[i];
      int left = a[0];
      bool ok = 1;
      int mx = 0;
      for (int i = 1; i < n; i++) {
        if (mx > a[i]) {
          ok = false;
          break;
        }
        a[i] -= mx;
        if (left >= a[i])
          left = a[i];
        else {
          mx += a[i] - left;
        }
      }
      if (ok)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
};
class p1244D {
 public:
  vector<int> node;
  vector<vector<int>> e;
  void dfs(int cur, int fa) {
    node.push_back(cur);
    for (int c : e[cur]) {
      if (c == fa) continue;
      dfs(c, cur);
    }
  }
  void solve() {
    int n;
    cin >> n;
    vector<vector<long long>> cost(n + 1, vector<long long>(3, 0));
    for (int j = 0; j < 3; j++) {
      for (int i = 1; i <= n; i++) {
        cin >> cost[i][j];
      }
    }
    e = vector<vector<int>>(n + 1);
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      cin >> u >> v;
      e[u].push_back(v);
      e[v].push_back(u);
      if (e[u].size() > 2 || e[v].size() > 2) {
        cout << -1 << endl;
        return;
      }
    }
    int start = -1;
    for (int i = 1; i <= n; i++) {
      if (e[i].size() == 1) {
        start = i;
        break;
      }
    }
    dfs(start, -1);
    long long res = 4e18;
    int x = -1, y = -1;
    for (int i = 0; i < 3; i++) {
      for (int k = 0; k < 3; k++) {
        if (k == i) continue;
        long long temp = 0;
        temp += cost[node[0]][i] + cost[node[1]][k];
        int a = i, b = k;
        for (int j = 2; j < node.size(); j++) {
          for (int l = 0; l < 3; l++) {
            if (l == a || l == b) continue;
            temp += cost[node[j]][l];
            a = b;
            b = l;
            break;
          }
        }
        if (temp < res) {
          res = temp;
          x = i;
          y = k;
        }
      }
    }
    cout << res << endl;
    vector<int> ans(n + 1, 0);
    ans[node[0]] = x;
    ans[node[1]] = y;
    for (int i = 2; i < node.size(); i++) {
      for (int l = 0; l < 3; l++) {
        if (l == x || l == y) continue;
        ans[node[i]] = l;
        x = y;
        y = l;
        break;
      }
    }
    for (int i = 1; i <= n; i++) cout << ans[i] + 1 << " ";
    cout << endl;
  }
};
class p519D {
 public:
  void solve() {
    vector<long long> cnt(26, 0);
    for (int i = 0; i < 26; i++) cin >> cnt[i];
    string s;
    cin >> s;
    int n = s.size();
    vector<long long> sum(n + 1, 0);
    for (int i = 1; i <= n; i++) {
      sum[i] = sum[i - 1] + cnt[s[i - 1] - 'a'];
    }
    long long res = 0;
    unordered_map<long long, long long> mp[26];
    for (int i = 1; i <= n; i++) {
      int cur = s[i - 1] - 'a';
      res += mp[cur][sum[i] - cnt[cur]];
      mp[cur][sum[i]]++;
    }
    cout << res << endl;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  p519D ans;
  ans.solve();
  return 0;
}
