#include <bits/stdc++.h>   using namespace std;   struct dd {     int k1;     char k2;   } a[25000];   bool cmp(struct dd q, struct dd b) { return q.k1 > b.k1; }   int main() {     int i, j, m, n, sum;     char b[1000];     gets(b);     sum = 0;     char k =  a ;     scanf( %d , &m);     for (i = 0; i < 26; i++) {       scanf( %d , &a[i].k1);       a[i].k2 = k;       k++;     }     int len1 = strlen(b);     for (i = 0; i < len1; i++) {       sum += a[(int)b[i] - 97].k1 * (i + 1);     }     sort(a, a + 26, cmp);     for (i = len1; i < len1 + m; i++) {       sum += a[0].k1 * (i + 1);     }     printf( %d n , sum);   }   