DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value w_{c}. For each special string s = s_1s_2... s_{|}s| (|s| is the length of the string) he represents its value with a function f(s), where $f(s) = \sum_{i = 1}^{|s|}(w_{s_{i}} \cdot i)$

Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get? 


-----Input-----

The first line contains a single string s (1 ≤ |s| ≤ 10^3).

The second line contains a single integer k (0 ≤ k ≤ 10^3).

The third line contains twenty-six integers from w_{a} to w_{z}. Each such number is non-negative and doesn't exceed 1000.


-----Output-----

Print a single integer — the largest possible value of the resulting string DZY could get.


-----Examples-----
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output
41



-----Note-----

In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.

Difficulty: interview

Starter code:

Solutions:
s = input().strip()
k = int(input())
w = list(map(int, input().split()))
f = 0
m = max(w)
for i in range(len(s)):
    f += (i + 1) * w[ord(s[i]) - ord('a')]
for i in range(len(s), len(s) + k):
    f += (i + 1) * m
print(f)

s=input().strip()
k=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(len(s)):
    ans+=(i+1)*a[(ord(s[i])-97)]
m=max(a)
for i in range(len(s),len(s)+k):
    ans+=m*(i+1)
print(ans)

s = input()
k = int(input())
w = list(map(int, input().split()))

res = 0
max_w = max(w)
for i in range(len(s)+k):
	if i < len(s):
		res += (i+1)*w[ord(s[i])-ord('a')]
	else:
		res += (i+1)*max_w
print(res)


s = input()
k = int(input())
w = list(map(int, input().split(' ')))

sum = 0

for index, el in enumerate(s):
    sum += w[ord(el)-97] * (index+1)
 
max_w = max(w);
result = max_w * (((len(s)+1) + (len(s)+k))/2) * k
print(int(sum + result))

def main():
    s = [ord(i) - ord('a') for i in input()]
    k = int(input())
    w = [int(i) for i in input().split()]
    
    s = [w[i] for i in s] + [max(w) for i in range(k)]
    
    result = 0
    for i in range(len(s)):
        result += s[i] * (i + 1)
    
    print(result)


main()


s = input()
k = int(input())
a = list(map(int,input().split()))
ma = 1
ans = 0
for i in range(len(a)):
    if a[ma] < a[i]:
        ma = i
for i in range(len(s)):
    ans += a[ord(s[i]) - ord('a')] * (i + 1)
for i in range(len(s), len(s) + k):
    ans += a[ma] * (i + 1)
print(ans)

s = input()
k = int(input())
w = list(map(int, input().split()))
c = chr(w.index(max(w)) + ord('a'))
def f(s):
  result = 0
  for i in range(len(s)):
    result += w[ord(s[i]) - ord('a')] * (i + 1)
  return result
print(f(s + c * k))

s = input()
k = int(input())

a = list(map(int, input().split()))

plus = max(a)
itog = 0

for i in range(1, len(s) + 1):
    itog += a[ord(s[i - 1]) - ord('a')] * i

for i in range(len(s) + 1, len(s) + 1 + k):
    itog += plus * i
    
print(itog)
    


s = input()
k = int(input())
wi = list(map(int, input().split()))
res = 0
for i in range(len(s)):
	res += wi[ord(s[i])-97]*(i+1)
print(res+max(wi)*(k*(k+1)//2 + len(s)*k))

s=str(input())
k=int(input())
wlist=[int(w) for w in input().split()]
letter=max(wlist)
alphabet='abcdefghijklmnopqrstuvwxyz'
summ=0
for i in range(len(s)):
	summ+=wlist[alphabet.index(s[i])]*(i+1)

print(summ+letter*(k*len(s)+(k+k**2)//2))

s = input()
k = int(input())
w = list(map(int,input().split()))
m = max(w)
sum = m * (2 * len(s) + k + 1) * k // 2
for i in range(len(s)):
    sum += w[ord(s[i])-ord('a')] * (i+1)
print(sum)

s=input()
k=int(input())
A=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
c=list(map(int,input().split()))
l=len(s)
u=max(c)
cost=0
for i in range (len(s)):
	cost=cost+(i+1)*c[A.index(s[i])]
for i in range(k):
	cost=cost+(l+i+1)*u
print(cost)

string = str(input())

k = int(input())

alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
            'v', 'w', 'x', 'y', 'z']

#weights = [int(x) for x in str(input()).split(" ")]

dic = {}
for count, x in enumerate(str(input()).split(" ")):
    dic.update({alphabet[count]: int(x)})

max_w = max(dic.values())

all_sum = 0
for count, sym in enumerate(string):
    all_sum += (count+1) * dic[str(sym)]

for new in range(len(string) + 1, len(string) + k + 1):
    all_sum += new * max_w

print(all_sum)

alpha = {'a':1, 'b':2 ,'c': 3,'d':4,'e':5 ,'f':6 ,'g':7 ,'h':8,'i':9,'j':10,'k':11,'l':12,'m':13,'n':14,'o':15,'p':16,'q':17,'r':18,'s':19,'t':20,'u':21,'v':22,
         'w':23,'x':24,'y':25,'z':26}
s = input()
k = int(input())
score = list(map(int,input().split()))
score1 = list(score)
score.sort(reverse = True)

value = 0
for i in range(len(s)):
    value += score1[alpha[s[i]]-1]*(i+1)
    #print(value)
for i in range(len(s)+1,len(s)+1+k):
    value += score[0]*i
print(value)


s = input()
k = int(input())
l = tuple(map(int, input().split()))

r = 0

p = 1
for i in s:
    r+=l[ord(i)-97]*p
    p += 1

z = max(l)

for i in range(k):
    r += z*p
    p += 1
print(r)


st=input()
k=int(input())
w=list(map(int,input().split()))
w2={chr(ord('a')+i):w[i] for i in range(26)}
m=max(w)
print(sum([w2[st[i]]*(i+1) for i in range(len(st))])+sum([i*m for i in range(len(st)+1,len(st)+1+k)]))

S = list([ord(x) - ord('a') for x in list(input())])
N = int(input())
W = list(map(int, input().split()))
S = S + [W.index(max(W))] * N
print(sum([(i + 1) * W[v] for i, v in enumerate(S)]))


alphavit=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
s=input()
k=int(input())
a=input().split()
summ=0
for i in range(len(s)):
  work=alphavit.index(s[i])
  summ+=int(a[work])*(i+1)
maxa=0
for i in range(26):
  a[i]=int(a[i])
  if a[i]>maxa:
    maxa=a[i]
for i in range(len(s),len(s)+k):
  summ+=maxa*(i+1)
print(summ)




#!/usr/bin/env python


def f(string, w):
    return sum([(i+1) * w[ord(string[i]) - ord('a')] for i in range(len(string))])


def main():
    string = input()
    k = int(input())
    w = list(map(int, input().split()))

    maxw = max(w)

    res = f(string, w)
    for i in range(k):
        res += (len(string) + i + 1) * maxw

    print(res)
def __starting_point():
    main()

__starting_point()

string=input()
numadd=int(input())
lval1=input().split(' ')
lval=[int(x) for x in lval1]
alphabet=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
maxvalue=lval.index(max(lval))
string+=numadd*alphabet[maxvalue]
perfect=0
for charsa in range(1, len(string)+1):
    perfect+=charsa*int(lval[alphabet.index(string[charsa-1])])
print(perfect)


s = input()
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
ans = 0
for i in range(len(s)): ans += (a[ord(s[i]) - ord('a')] * (i + 1))
for i in range(len(s)+1,len(s)+n+1):    ans += (mx * i)
print(ans)

import sys
import string
from decimal import *
from itertools import *
from math import *

def solve():
    s = input()
    k = int(input())
    w = list(map(int,input().split()))
    mm = max(w)
    ans  = 0
    for i in range(len(s)+k):
        if (i < len(s)):
            ans = ans + w[ord(s[i])-ord('a')]*(i+1)
        else:
            ans = ans + mm*(i+1)
    print(ans)
        
solve();


def readln(): return tuple(map(int, input().split()))

s = input()
k, = readln()
w = readln()
ans = sum([(i + 1) * w[ord(c) - ord('a')] for i, c in enumerate(s)])
print(ans + max(w) * (2 * len(s) + k + 1) * k // 2)

s, k, w = input(), int(input()), list(map(int, input().split()))

sum, m, l = 0, max(w), len(s)
for i in range(l + k):
    sum += (w[ord(s[i]) - ord('a')] if i < l else m) * (i + 1)

print(sum)


str_input = input()
k = int(input())
w = [int(s) for s in input().split()]
value =0
for i in range(len(str_input)):
    value += (i+1)*int(w[ord(str_input[i])-97])
lam = lambda x: (x+1+len(str_input))*int(max(w))
for i in range(k):
    value+=lam(i)
print (value)