#include <bits/stdc++.h>
using namespace std;
long long maxx = INT_MIN, k;
long long cal(int pos) {
  long long ans = 0;
  pos++;
  for (int i = 0; i < k; i++, pos++) ans += (pos * maxx);
  return ans;
}
int main() {
  string str;
  long long x;
  long long old_sum;
  vector<long long> hash(26);
  cin >> str;
  scanf("%lld", &k);
  for (int i = 0; i < 26; i++) {
    scanf("%lld", &x);
    maxx = max(maxx, x);
    hash[i] = x;
  }
  vector<long long> dp(str.length(), 0);
  int n = dp.size();
  dp[0] = hash[str[0] - 97];
  old_sum = hash[str[0] - 97];
  for (int i = 1; i < str.length(); i++) {
    dp[i] = hash[str[i] - 97] + dp[i - 1];
    old_sum += ((i + 1) * hash[str[i] - 97]);
  }
  long long result = (old_sum + cal(0) + k * dp[n - 1]);
  for (int i = 1; i <= dp.size(); i++) {
    result = max(old_sum + cal(i) + k * (dp[n - 1] - dp[i - 1]), result);
  }
  printf("%lld\n", result);
  return 0;
}
