#include <bits/stdc++.h>
const int MAX = 1e3 + 11;
using namespace std;
char A[MAX];
int W[33];
int main() {
  scanf("%s", (A));
  int(K);
  scanf("%d", &K);
  for (int i = 0; i < (26); ++i) scanf("%d", &(W[i]));
  int mx = 0, N = int(strlen(A));
  int v = *max_element(W, W + 26);
  for (int i = 0; i < (K + 1); ++i) {
    int s = 0, pos = i;
    for (int j = 0; j < (N); ++j) {
      s += W[A[j] - 'a'] * (j + 1 + i);
    }
    for (int k = 0; k < (pos); ++k) {
      s += (k + 1) * v;
    }
    for (int k = (pos + N); k < (K + N); ++k) {
      s += (k + 1) * v;
    }
    mx = max(mx, s);
  }
  printf("%d", mx);
  return 0;
}
