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: EASY

Solutions:
import string
l = list(str(input()))
k = int(input())
a = list(string.ascii_lowercase)
b = [int(n1) for n1 in input().split()]
(b, a) = zip(*sorted(zip(b, a), reverse=True))
l = l + k * list(a[0])
sum1 = 0
for i in range(len(l)):
	for j in range(len(a)):
		if a[j] == l[i]:
			sum1 = sum1 + (i + 1) * b[j]
print(sum1)


import sys
import math
s = sys.stdin.readline()
k = int(sys.stdin.readline())
w = [int(x) for x in sys.stdin.readline().split()]
vamx = max(w)
vsum = 0
lenstr = len(s) - 1
for i in range(lenstr):
	vsum += w[ord(s[i]) - ord('a')] * (i + 1)
vsum += int((2 * vamx * (lenstr + 1) + vamx * (k - 1)) / 2 * k)
print(vsum)


a = input()
n = int(input())
l = list(map(int, input().split()))
letters = 'abcdefghijklmnopqrstuvwxyz'
b = l.index(max(l))
a += n * letters[b]
t = []
for i in a:
	t.append(l[letters.index(i)])
s = 0
for i in range(1, len(a) + 1):
	s += i * t[i - 1]
print(s)


s = input()
k = int(input())
values = list(map(int, input().split()))
max_val = max(values)
sum_val = sum([i * max_val for i in range(len(s) + 1, len(s) + k + 1)])
sum_val += sum([(i + 1) * values[ord(s[i]) - 97] for i in range(len(s))])
print(sum_val)


d = {}
for i in range(97, 123):
	d.update({chr(i): i - 97})
s = input()
k = int(input())
l = list(map(int, input().split()))
m = max(l)
c = 0
for i in range(len(s)):
	x = d[s[i]]
	c = c + (i + 1) * l[x]
for i in range(len(s), len(s) + k):
	c = c + m * (i + 1)
print(c)


s = input()
k = int(input())
w = input().split(' ')
for i in range(len(w)):
	w[i] = int(w[i])
somme = 0
lens = len(s) + 1
for i in range(1, lens):
	somme += w[ord(s[i - 1]) - 97] * i
maxs = max(w)
for i in range(lens, k + lens):
	somme += i * maxs
print(somme)


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


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


text = input()
n = int(input())
values = list(map(int, input().split()))

def get_val(i, xs):
	return xs[ord(i) - ord('a')]
bv = max(values)
bp = [i for i in range(len(values)) if values[i] == bv][0]
text += chr(ord('a') + bp) * n
print(sum((get_val(text[i], values) * (i + 1) for i in range(len(text)))))


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


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


import string
s = input()
k = int(input())
w = [int(x) for x in input().split(' ')]
alpha = {k: v for (k, v) in zip(list(string.ascii_lowercase), w)}
c = 0
W = max(w)
for i in range(len(s)):
	c += alpha[s[i]] * (i + 1)
for i in range(len(s) + 1, len(s) + 1 + k):
	c += W * i
print(c)


s = input()
k = int(input())
arr = list(map(int, input().split()))
su = 0
for j in range(len(s)):
	su += (j + 1) * arr[ord(s[j]) - 97]
n = k + len(s)
t = n * (n + 1) / 2 - k * (k + 1) / 2
print(int(su + max(arr) * (n * (n + 1) / 2 - len(s) * (len(s) + 1) / 2)))


s = input()
p = [ord(i) - 96 for i in s]
n = int(input())
l = list(map(int, input().split()))
total = 0
for (i, j) in enumerate(p):
	total += (i + 1) * l[j - 1]
t = max(l)
for i in range(len(s), len(s) + n):
	total += t * (i + 1)
print(total)


m = list(input())
str = [int(ord(x) - 97) for x in m]
k = int(input())
array = [int(x) for x in input().split(' ')]
largest = 0
for x in array:
	if x > largest:
		largest = x
tot = 0
for x in range(len(str)):
	tot += (x + 1) * array[str[x]]
for x in range(k):
	tot += (x + len(str) + 1) * largest
print(tot)


string = str(input())
k = int(input())
letters = list(map(int, input().split()))
mE = max(letters)
add = 0
for i in range(len(string)):
	add += letters[ord(string[i]) - ord('a')] * (i + 1)
for i in range(len(string), len(string) + k):
	add += mE * (i + 1)
print(add)


s = input()
p = int(input())
L = list(map(int, input().split()))
z = max(L)
suma = 0
j = 1
for k in s:
	suma += j * L[ord(k) - 97]
	j += 1
print(suma + z * p * (2 * len(s) + 1 + p) // 2)


t = input()
k = int(input())
w = [int(x) for x in input().split()]
total = 0
for i in range(len(t)):
	total = total + w[ord(t[i]) - 97] * (i + 1)
for i in range(k):
	total = total + max(w) * (len(t) + i + 1)
print(total)


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


s = input()
l = int(input())
w = list(map(int, input().split()))
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']
f = 0
z = len(s)
y = max(w)
for i in range(z):
	k = a.index(s[i:i + 1])
	f = f + (i + 1) * w[k]
for i in range(l):
	f = f + (z + i + 1) * y
print(f)


f = lambda : map(int, input().split())
sp = input()
v = 0
k = int(input())
l = list(f())
for i in range(len(sp)):
	v += (i + 1) * l[ord(sp[i]) - ord('a')]
print(v + sum(range(i + 2, i + k + 2)) * max(l))


k = input()
n = int(input())
l = list(map(int, input().split()))
al = ['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']
z = sorted(l)[-1]
m = len(k) + n
count = 0
sum = 0
for i in range(1, m + 1):
	if count <= len(k) - 1:
		ind = al.index(k[count])
		sum += l[ind] * i
		count += 1
	else:
		sum += z * i
print(sum)


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


import operator
import os, sys
from collections import defaultdict, Counter, deque
from functools import lru_cache
from io import BytesIO, IOBase
from itertools import accumulate
from math import gcd, ceil, inf, sqrt, floor
import math

def main():
	s = input()
	k = int(input())
	arr = list(map(int, input().split()))
	init_score = 0
	mid_score = 0
	string1 = 'abcdefghijklmnopqrstuvwxyz'
	mydict = {}
	new_val = len(s) + 1
	for i in range(0, 26):
		mydict[string1[i]] = arr[i]
	scores = list(mydict.values())
	max_score = max(scores)
	for i in range(0, len(s)):
		init_score += mydict[s[i]] * (i + 1)
	for i in range(0, k):
		mid_score += new_val * max_score
		new_val += 1
	final_score = init_score + mid_score
	print(final_score)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


st = input()
n = int(input())
that = list(st)
l = list(map(int, input().split()))
alpha = []
ch = 'a'
for i in range(26):
	alpha.append(ch)
	ch = str(chr(ord(ch) + 1))
for i in range(n):
	that.append(alpha[l.index(max(l))])
s = 0
c = 1
for i in that:
	s += c * l[alpha.index(i)]
	c += 1
print(s)


s = input()
n = eval(input())
value = list(map(eval, input().split()))
ans = 0
for i in range(len(s)):
	ans += value[ord(s[i]) - ord('a')] * (i + 1)
maxn = max(map(lambda x: x, value))
ans += (len(s) * 2 + n + 1) * n * maxn / 2
print(int(ans))


a = list(input())
n = int(input())
w = [int(i) for i in input().split()]
count = 0
for i in range(len(a)):
	count += (i + 1) * w[ord(a[i]) - 97]
k = max(w)
for i in range(n):
	count += (len(a) + 1 + i) * k
print(count)


s = str(input())
k = int(input())
l = list(map(int, input().split()))
c = 0
l1 = list(s)
for i in range(len(l1)):
	c += l[ord(l1[i]) - 97] * (i + 1)
for i in range(k):
	c += max(l) * (len(l1) + i + 1)
print(c)


def love(s, arr, k):
	cnt = 1
	ans = 0
	for i in s:
		ans += cnt * arr[ord(i) - 97]
		cnt += 1
	maxi = max(arr)
	while k:
		ans += cnt * maxi
		cnt += 1
		k -= 1
	return ans
a = input()
k = int(input())
lst = list(map(int, input().strip().split()))
print(love(a, lst, 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())
l = list(map(int, input().split()))
maxl1 = max(l)
count = 0
for i in range(1, len(s) + 1):
	count += l[ord(s[i - 1]) - ord('a')] * i
for i in range(len(s) + 1, len(s) + 1 + k):
	count += maxl1 * i
print(count)


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


s = input()
n = int(input())
l = list(map(int, input().split()))
z = len(s) + n
x = [0] * z
for i in range(1, n + 1):
	x[-i] = (z - i + 1) * max(l)
for i in range(len(s)):
	x[i] = (i + 1) * l[ord(s[i]) - 97]
print(sum(x))


s = input()
k = int(input())
l = [int(x) for x in input().split()]
total = 0
for i in range(len(s)):
	total += (i + 1) * l[ord(s[i]) - 97]
maxi = max(l)
while k > 0:
	i += 1
	total += (i + 1) * maxi
	k -= 1
print(total)


n = input()
k = int(input())
a = list(map(int, input().split()))
m = max(a)
i = a.index(m)
sum = 0
j = 1
while j <= len(n):
	s = ord(n[j - 1]) - 97
	t = a[s]
	sum += j * t
	j += 1
j = len(n)
while k > 0:
	sum += (k + j) * m
	k -= 1
print(sum)


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


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


s = input()
n = len(s)
k = int(input())
weights = list(map(int, input().split()))
curr_score = sum([weights[ord(s[i]) - ord('a')] * (i + 1) for i in range(n)])
weights.sort(reverse=True)
curr_score += weights[0] * (n * k + k * (k + 1) // 2)
print(curr_score)


s = input()
k = int(input())
a = list(map(int, input().split()))
ans = 0
l = len(s)
t = max(a)
d = {}
for i in range(26):
	d[chr(97 + i)] = a[i]
for i in range(l):
	ans += d[s[i]] * (i + 1)
ans += t * ((k + l + 1) * (k + l) // 2 - (l + 1) * l // 2)
print(ans)


s = input()
k = int(input())
w = list(map(int, input().rstrip().split()))
maxm = max(w)
count = 0
n = len(s)
for i in range(n):
	ind = ord(s[i]) - 97
	count += (i + 1) * w[ind]
a = n * (n + 1) // 2
b = (n + k) * (n + k + 1) // 2
count += (b - a) * maxm
print(int(count))


(k, n) = (input(), int(input()))
l = list(map(int, input().split()))
print(sum([i * l[ord(k[i - 1]) - 97] if i <= len(k) else max(l) * i for i in range(1, len(k) + n + 1)]))


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


def num(str):
	alphabet = 'abcdefghijklmnopqrstvuwxyz'

def summ(array, k, str):
	summ = 0
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	for i in range(len(str)):
		order = 1
		for j in range(len(alphabet)):
			if alphabet[j] == str[i]:
				order = j
		summ += array[order] * (i + 1)
	max = 0
	for i in range(len(array)):
		if array[i] > max:
			max = array[i]
	for i in range(k):
		summ += max * (len(str) + i + 1)
	return summ
str = input()
k = int(input())
array = input().split(' ')
newar = []
for i in range(len(array)):
	newar.append(int(array[i]))
print(summ(newar, k, str))


s = input()
k = int(input())
w = list(map(int, input().split()))
Dict = {}
counter = 0
for i in range(97, 123):
	Dict[chr(i)] = w[i - 97]
m = max(Dict.values())
for i in range(len(s)):
	counter += Dict[s[i]] * (i + 1)
for i in range(len(s) + 1, len(s) + k + 1):
	counter += m * i
print(counter)


s = input()
k = int(input())
w = [int(x) for x in input().split()]
alpha = ['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']
maxs = max(w)
sums = 0
for i in range(len(s)):
	for j in range(len(alpha)):
		if s[i] == alpha[j]:
			sums += (i + 1) * w[j]
for i in range(len(s), len(s) + k):
	sums += (i + 1) * maxs
print(sums)


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


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


s = input()
k = int(input())
l = list(map(int, input().split()))
max_val = max(l)
count = 0
ans = 0
for i in range(len(s)):
	j = i + 1
	ans = ans + j * l[ord(s[i]) - ord('a')]
i = len(s) + 1
while i < len(s) + 1 + k:
	ans = ans + i * max_val
	i += 1
print(ans)


def main():
	s = str(input())
	k = int(input())
	values = list(map(int, input().split()))
	letters = 'abcdefghijklmnopqrstuvwxyz'
	val_sort = sorted(values)
	vald = {}
	for i in range(0, 26):
		vald[letters[i]] = values[i]
	acum = 0
	last = 1
	for i in range(len(s)):
		acum += last * vald[s[i]]
		last += 1
	n = len(s) + k
	sum1 = int(n * (n + 1) / 2)
	n = len(s)
	sum2 = int(n * (n + 1) / 2)
	dif = sum1 - sum2
	acum += dif * val_sort[-1]
	print(acum)
main()


l = list(input())
n = int(input())
q = []
h = 'a'
for i in range(0, 26):
	q.append(h)
	h = chr(ord(h) + 1)
count = 0
p = []
c = 0
s = list(map(int, input().split()))
for i in range(1, len(l) + n + 1):
	if i - 1 < len(l):
		r = q.index(l[i - 1])
		count += s[r] * i
	else:
		r = max(s)
		c += 1
		count += i * r
print(count)


s = input()
k = int(input())
vals = list(map(int, input().split()))
alphabets = 'abcdefghijklmnopqrstuvwxyz'
ss = alphabets[vals.index(max(vals))]
s = s + ss * k
score = 0
for (i, v) in enumerate(s):
	score += vals[alphabets.index(v)] * (i + 1)
print(score)


def main():
	s = input()
	n = int(input())
	k = input().split()
	max1 = 0
	for i in k:
		if int(i) > max1:
			max1 = int(i)
	sum = 0
	l = 1
	for i in s:
		sum = sum + l * int(k[ord(i) - 97])
		l += 1
	for i in range(0, n):
		sum = sum + l * max1
		l += 1
	print(sum)
main()


s = input()
n = int(input())
vals = [int(w) for w in input().split()]
maxVal = -1
for val in vals:
	maxVal = max(maxVal, val)
result = 0
for (index, char) in enumerate(s):
	i = ord(char) - 97
	result += vals[i] * (index + 1)
for i in range(len(s) + 1, len(s) + n + 1):
	result += maxVal * i
print(result)


al = [chr(i) for i in range(97, 97 + 26)]
s = input()
n = int(input())
x = list(map(int, input().split()))
y = max(x)
z = al[x.index(y)]
s = s + z * n
sum = 0
for i in range(len(s)):
	sum += (i + 1) * x[al.index(s[i])]
print(sum)


s = input()
k = int(input())
l = list(map(int, input().split()))
tot = 0
ma = max(l)
for i in range(1, len(s) + k + 1):
	if i <= len(s):
		tot += l[ord(s[i - 1]) - 97] * i
	else:
		tot += ma * i
print(tot)


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


s = input()
k = int(input())
a = list(map(int, input().split()))
x = ['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']
y = []
ss = 0
for i in range(0, len(s)):
	for j in range(0, 26):
		if s[i] == x[j]:
			y.append(a[j])
			break
		else:
			continue
for i in range(0, len(s) + 1):
	ss += i * y[i - 1]
d = 0
for i in range(len(s) + 1, len(s) + k + 1):
	d += i
ss += d * max(a)
print(ss)


s = input()
n = int(input())
w = list(map(int, input().rsplit()))
a = max(w)
b = 0
j = 1
for i in range(1, n + 1):
	b = b + (len(s) + i) * a
for i in s:
	c = ord(i)
	d = c - 97
	b = b + w[d] * j
	j = j + 1
print(b)


def value(alp, string):
	s = 0
	for (i, item) in enumerate(string):
		s += (i + 1) * alp[item]
	return s
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']
s = input()
n = int(input())
values = list(map(int, input().split(' ')))
print(value(dict(zip(alphabet, values)), s + n * alphabet[values.index(max(values))]))


s = input()
k = int(input())
x = input()
xx = x.split()
for i in range(0, 26):
	xx[i] = int(xx[i])
h = {'a': xx[0], 'b': xx[1], 'c': xx[2], 'd': xx[3], 'e': xx[4], 'f': xx[5], 'g': xx[6], 'h': xx[7], 'i': xx[8], 'j': xx[9], 'k': xx[10], 'l': xx[11], 'm': xx[12], 'n': xx[13], 'o': xx[14], 'p': xx[15], 'q': xx[16], 'r': xx[17], 's': xx[18], 't': xx[19], 'u': xx[20], 'v': xx[21], 'w': xx[22], 'x': xx[23], 'y': xx[24], 'z': xx[25]}
t = 0
for i in range(0, len(s)):
	t += (i + 1) * h[s[i]]
y = max(xx)
n = len(s) + k
j = len(s)
jj = j * (j + 1) / 2
nn = n * (n + 1) / 2
ll = nn - jj
t += ll * y
print(int(t))


s = input()
k = int(input())
l = list(map(int, input().split()))
d = {}
a = 97
for i in l:
	d[chr(a)] = i
	a += 1
sum = 0
no = 1
for i in s:
	sum += d[i] * no
	no += 1
for i in range(k):
	sum += no * max(l)
	no += 1
print(sum)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]
spf_sieve()

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
string = input().strip()
k = int(input())
alps = int_array()
ans = 0
n = len(string)
this = max(alps)
for i in range(n + k):
	if i < n:
		ans += (i + 1) * alps[ord(string[i]) - 97]
	else:
		ans += (i + 1) * this
print(ans)


a = list(input())
k = int(input())
alphaList = list(map(int, input().split(' ')))
alpha = {chr(i + 97): alphaList[i] for i in range(len(alphaList))}
maxKey = max(alpha.keys(), key=lambda x: alpha[x])
f = 0
for i in range(1, len(a) + k + 1):
	if i <= len(a):
		f = f + alpha[a[i - 1]] * i
	else:
		f = f + alpha[maxKey] * i
print(f)


def solve(st, k, w):
	_max = max(w)
	vals = [w[ord(c) - ord('a')] for c in st] + [_max] * k
	return sum([(i + 1) * x for (i, x) in enumerate(vals)])
res = solve(input(), int(input()), list(map(int, input().split())))
print(res)


s = input()
ss = len(s)
k = int(input())
L = list(map(int, input().split()))
(c, a) = (0, 'abcdefghijklmnopqrstuvwxyz')
for i in range(len(s)):
	c += L[a.index(s[i])] * (i + 1)
print(c + ((ss + k) * (ss + k + 1) // 2 - ss * (ss + 1) // 2) * max(L))


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


z = input()
d = int(input())
di = {}
x = list(map(int, input().split()))
c = 0
for i in range(97, 123):
	if di.get(chr(i), 0) == 0:
		di[chr(i)] = x[c]
	c += 1
ma = max(di.values())
w = 0
for i in range(len(z) + d):
	if i < len(z):
		w += di[z[i]] * (i + 1)
	else:
		w += ma * (i + 1)
print(w)


(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)


t = input
r = range
p = print
s = t()
k = int(t())
w = list(map(int, t().split()))
ans = 0
ma = max(w)
for i in r(len(s)):
	ans += w[ord(s[i]) - 97] * (i + 1)
su = 0
for i in range(len(s), len(s) + k):
	su += (i + 1) * ma
p(ans + su)


(s, k, w, sm) = (input(), int(input()), list(map(int, input().split())), 0)
print(sum((w[ord(s[i - 1]) - 97] * i if i < len(s) + 1 else i * max(w) for i in range(1, k + len(s) + 1))))


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)


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil, pi
s = input()
n = int(input())
nums = list(map(int, input().split()))
tot = 0
for i in range(len(s)):
	tot += nums[ord(s[i]) - 97] * (i + 1)
ma = max(nums)
for m in range(len(s), len(s) + n):
	tot += ma * (m + 1)
print(tot)


str1 = input('')
k = int(input(''))
w = list(map(int, input().split()))
p = max(w)
pidx = w.index(p) + 97
q = chr(pidx)
str2 = k * q
str3 = str1 + str2
f = 0
for i in range(0, len(str3)):
	a = ord(str3[i]) - 97
	f = f + (i + 1) * w[a]
print(f)


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


string = list(str(input()))
charsToInsert = int(input())
array = list(map(int, input().split()))
counter = 0
for i in range(0, len(string)):
	buffer = ord(string[i]) - 97
	counter += array[buffer] * (i + 1)
y = max(array)
for i in range(len(string) + 1, len(string) + charsToInsert + 1):
	counter += i * y
print(counter)


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


s = list(input())
k = int(input())
l = list(map(int, input().split()))
num = 0
for i in range(len(s)):
	a = s[i]
	b = ord(a) - ord('a')
	num += l[b] * (i + 1)
c = max(l)
d = len(s)
num += c * (d + 1 + d + k) * k / 2
print(int(num))


s = input()
n = int(input())
l = list(map(int, input().split()))
m = max(l)
c = 0
j = 1
for i in range(1, len(s) + 1):
	c += l[ord(s[i - 1]) - 96 - 1] * i
	j += 1
for i in range(n):
	c += j * m
	j += 1
print(c)


import string
a = input()
k = int(input())
w = dict(zip(string.ascii_lowercase, map(int, input().split())))
z = len(a)
c = max(w.values()) * (z + z + k + 1) * k // 2
for i in range(z):
	c += w[a[i]] * (i + 1)
print(c)


try:
	a = input()
	k = int(input())
	l = list(map(int, input().split()))
	num = len(a)
	t = 0
	for i in range(num):
		t += l[ord(a[i]) - 97] * (i + 1)
	t += max(l) * (2 * num * k + k ** 2 + k) // 2
	print(t)
except:
	pass


s = input()
k = int(input())
scores = list(map(int, input().split()))
alph = 'abcdefghijklmnopqrstuvwxyz'
m = scores.index(max(scores))
res = s + k * alph[m]
print(sum((scores[alph.index(c)] * (i + 1) for (i, c) in enumerate(res))))


st = input()
n = int(input())
result = 0
l = list(map(int, input().split()))
for i in range(0, len(st)):
	j = ord(st[i]) - 96
	result += (i + 1) * l[j - 1]
maxi = max(l)
k = len(st) + 1
for i in range(k, k + n):
	result += i * maxi
print(result)


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


p = input().rstrip()
x = list(p)
k = int(input())
s = 0
Q = input().rstrip().split(' ')
for i in range(0, len(x)):
	t = (i + 1) * int(Q[ord(x[i]) - 97])
	s = s + t
Q.sort(key=int, reverse=True)
for i in range(0, k):
	t = (len(x) + i + 1) * int(Q[0])
	s = s + t
print(s)


n = input()
k = int(input())
a = 'abcdefghijklmnopqrstuvwxyz'
b = list(map(int, input().split()))
count = 0
for i in range(len(n)):
	c = a.index(n[i])
	count += (i + 1) * b[c]
c = max(b)
for i in range(len(n) + 1, len(n) + k + 1):
	count += i * c
print(count)


(k, n) = (input(), int(input()))
l = list(map(int, input().split()))
h = {chr(i): l[i - 97] for i in range(97, 123)}
print(sum([i * h[k[i - 1]] if i <= len(k) else max(l) * i for i in range(1, len(k) + n + 1)]))


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


alph = 'abcdefghijklmnopqrstuvwxyz'
st = input()
k = int(input())
waz = list(map(int, input().split()))
d = {}
maxv = 0
for i in range(0, 26):
	d[alph[i]] = waz[i]
	if waz[i] > maxv:
		maxv = waz[i]
answer = 0
for i in range(0, len(st) + k):
	if i < len(st):
		answer += (i + 1) * d[st[i]]
	else:
		answer += (i + 1) * maxv
print(answer)


def main():
	s = list(input())
	k = int(input())
	w = list(map(int, input().split(' ')))
	max_index = 0
	for i in range(1, len(w)):
		if w[i] > w[max_index]:
			max_index = i
	for i in range(k):
		s.append(chr(max_index + ord('a')))
	ret = 0
	for (i, c) in enumerate(s):
		ret += (i + 1) * w[ord(c) - ord('a')]
	return ret
print(main())


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 = input()
k = int(input())
w = list(map(int, input().split()))
value = 0
maximum = max(w)
for i in range(len(s)):
	value += (i + 1) * w[ord(s[i]) - ord('a')]
for j in range(len(s) + 1, len(s) + k + 1):
	value += maximum * j
print(value)


s = input()
n = int(input())
l = list(map(int, input().split()))
o = max(l)
index = l.index(o)
char = chr(index + 97)
s = s + n * char
count1 = 0
for i in range(len(s)):
	count1 = count1 + (i + 1) * l[ord(s[i]) - 97]
print(count1)


x = input()
n = int(input())
s = list(map(int, input().split()))
v = 0
for i in range(len(x)):
	m = ord(x[i]) - 97
	v += (i + 1) * s[m]
s.sort()
i += 2
while n:
	v += i * s[-1]
	n -= 1
	i += 1
print(v)


def main():
	string = input()
	k = int(input())
	wgt = list(map(int, input().split()))
	ans = 0
	for (i, char) in enumerate(string):
		ans += (i + 1) * wgt[ord(char) - 97]
	maxw = max(wgt)
	n = len(string) + 1
	for i in range(k):
		ans += n * maxw
		n += 1
	print(ans)
t = 1
while t != 0:
	main()
	t -= 1


s = input()
k = int(input())
l = list(map(int, input().split()))
z = 0
for i in range(0, len(s)):
	z = z + l[ord(s[i]) - 97] * (i + 1)
l.sort()
l = l[::-1]
p = len(s)
for i in range(p + 1, p + k + 1):
	z = z + i * l[0]
print(z)


s = input()
k = int(input())
w = list(map(int, input().split()))
d = {}
a = 97
for i in w:
	d[chr(a)] = i
	a = a + 1
m = max(w)
c = 0
for i in range(len(s) + k):
	if i < len(s):
		c = c + d[s[i]] * (i + 1)
	else:
		c = c + (i + 1) * m
print(c)


s = input()
dest = int(input())
mat = list(map(int, input().split()))
result = 0
max_incr = max(mat)
for i in range(len(s)):
	result += mat[ord(s[i]) - 97] * (i + 1)
for j in range(i + 2, dest + i + 2):
	result += max_incr * j
print(result)


import sys
input = sys.stdin.readline
s = input().rstrip()
k = int(input().rstrip())
w = list(map(int, input().rstrip().split()))
result = 0
for i in range(len(s)):
	result += w[ord(s[i]) - ord('a')] * (i + 1)
for i in range(len(s), len(s) + k):
	greed = max(w)
	result += greed * (i + 1)
print(result)


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())
l = [int(x) for x in input().split()]
max1 = max(l)
ln = len(s)
value = 0
for i in range(1, k + 1):
	value += (ln + i) * max1
for i in range(len(s)):
	value += (i + 1) * l[ord(s[i]) - ord('a')]
print(value)


def f(s, weight):
	return sum([weight[s[i]] * (i + 1) for i in range(len(s))])
s = input()
k = int(input())
g = input().split()
weight = {}
for i in range(26):
	weight[chr(97 + i)] = int(g[i])
max_weight = max(weight.values())
x = 0
for i in range(len(s) + 1, len(s) + k + 1):
	x += i * max_weight
print(f(s, weight) + x)


s = input()
k = int(input())
l = list(map(int, input().split()))
sum = 0
for i in range(len(s)):
	for j in range(len(l)):
		x = chr(97 + j)
		if x == s[i]:
			sum += (i + 1) * l[j]
l.sort(reverse=True)
for a in range(k):
	sum += l[0] * (a + len(s) + 1)
print(sum)


a = 0
s = input()
m = int(input())
d = {}
for (i, j) in enumerate(map(int, input().split())):
	d[chr(i + 97)] = j
l = max(d.values())
for (i, j) in enumerate(s):
	a += d[j] * (i + 1)
for i in range(len(s) + 1, len(s) + m + 1):
	a += i * l
print(a)


s = input('')
k = int(input())
ls = list(map(int, input().split()))
cost = 0
for i in range(len(s)):
	curr = ord(s[i]) - 97
	cost += (i + 1) * ls[curr]
i = i + 1
for j in range(k):
	cost += (i + 1) * max(ls)
	i += 1
print(cost)


import math, sys, re, itertools
(rs, ri, rai) = (input, lambda : int(input()), lambda : list(map(int, input().split())))
s = rs()
k = ri()
w = rai()
m = max(w)
mi = w.index(m)
res = 0
for i in range(k):
	s += chr(ord('a') + mi)
for (i, ch) in enumerate(s):
	res += (i + 1) * w[ord(ch) - ord('a')]
print(res)


string = input()
k = int(input())
vals = list(map(int, input().split()))
di = {chr(97 + i): val for (i, val) in enumerate(vals)}
ma = max(vals)
pre = 0
for (index, value) in enumerate(string):
	pre += (index + 1) * di[value]
sub = len(string) * (len(string) + 1) // 2
oi = len(string) + k
sumn = oi * (oi + 1) // 2 - sub
print(pre + sumn * ma)


s = input()
n = int(input())
l = [int(x) for x in input().split()]
count = 0
for i in range(len(s)):
	x = ord(s[i]) - 97
	count += (i + 1) * l[x]
i += 1
for j in range(n):
	count += (i + 1) * max(l)
	i += 1
print(count)


import string
s = input()
n = int(input())
alphabet = string.ascii_lowercase
values = input().split()
max = 0
adict = {}
for a in range(len(values)):
	values[a] = int(values[a])
	adict[alphabet[a]] = values[a]
	if values[a] > max:
		max = values[a]
total = 0
for a in range(len(s)):
	total += (a + 1) * adict[s[a]]
b = len(s)
c = 0
while c < n:
	b += 1
	total += b * max
	c += 1
print(total)


s1 = list(input())
k = int(input())
l1 = [int(x) for x in input().split()]
alfie = 'abcdefghijklmnopqrstuvwxyz'
cool = []
ans = 0
for x in s1:
	cool.append(l1[alfie.index(x)])
for x in range(k):
	cool.append(max(l1))
for x in range(len(cool)):
	ans += (x + 1) * cool[x]
print(ans)


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)


s = input()
k = int(input())
arr = list(map(int, input().split(' ')))
m = max(arr)
ans = 0
for i in range(1, len(s) + k + 1):
	if i <= len(s):
		word = s[i - 1]
		ans += i * arr[ord(word) - 97]
	else:
		ans += i * m
print(ans)


s = input()
k = int(input())
w = list(map(int, input().split()))
values = []
max_w = max(w)
for c in s:
	values.append(w[ord(c) - 97])
for i in range(k):
	values.append(max(w))
total = 0
for i in range(len(values)):
	total += (i + 1) * values[i]
print(total)


import string
letters = string.ascii_lowercase
s = input().strip()
k = int(input().strip())
arr = tuple(map(int, input().split()))
dic = {i: j for (i, j) in zip(letters, arr)}
lis = []
for i in s:
	lis.append((dic[i], i))
x = max(arr)
z = 0
count = 0
for i in s:
	z += 1
	count += dic[i] * z
for i in range(k):
	z += 1
	count += x * z
print(count)


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


s = input()
n = int(input())
w = list(map(int, input().split()))
v = 0
j = 1
for i in s:
	v += j * w[ord(i) - 97]
	j += 1
while j <= len(s) + n:
	v += j * max(w)
	j += 1
print(v)


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()


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


line = str(input())
k = int(input())
w_line = str(input()).split()
w_line = [int(w) for w in w_line]
c_line = 'abcdefghijklmnopqrstuvwxyz'
refer_dict = dict()
for i in range(26):
	refer_dict.update({c_line[i]: w_line[i]})
num = 0
size = len(line)
for i in range(size + k):
	if i < size:
		num += (i + 1) * refer_dict.get(line[i])
	else:
		num += (i + 1) * max(w_line)
print(num)


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


def solve():
	s1 = input()
	k = int(input())
	arr = list(map(int, input().split()))
	val = max(arr)
	ans = 0
	for i in range(len(s1)):
		ans += (i + 1) * arr[ord(s1[i]) - ord('a')]
	for i in range(k):
		ans += (len(s1) + i + 1) * val
	print(ans)
solve()


s = input('')
k = int(input(''))
weights = []
weights = input().split()
weights = [int(i) for i in weights]
max_wt = 0
s_list = []
for i in range(0, len(s)):
	s_list.append(ord(s[i]) - 96)
	max_wt += int(weights[s_list[i] - 1]) * (i + 1)
for i in range(0, k):
	s_list.append(weights.index(max(weights)) + 1)
	max_wt += int(max(weights)) * (i + 1 + len(s))
print(max_wt)


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)


from string import ascii_lowercase as lc
ins = input()
more = int(input())
values = [int(x) for x in input().split()]
val_dic = dict(zip(lc, values))
max_is = ins + lc[values.index(max(values))] * more
print(sum([val_dic[x] * (i + 1) for (i, x) in enumerate(max_is)]))


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


import math
alph = 'abcdefghijklmnopqrstuvwxyz'
s = str(input())
k = int(input())
w = list(map(int, input().split()))
E = 0
for i in range(len(s)):
	E += (i + 1) * w[alph.index(s[i])]
for i in range(k):
	E += (len(s) + i + 1) * max(w)
print(E)


first = list(input())
digits = int(input())
values = [int(i) for i in input().split()]
letters = list('abcdefghijklmnopqrstuvwxyz')
maxvalue = max(values)
wordvalues = []
for i in first:
	index = letters.index(i)
	wordvalues.append(values[index])
count = 0
while count != digits:
	wordvalues.append(maxvalue)
	count += 1
finalvalue = 0
for i in range(len(wordvalues)):
	finalvalue += wordvalues[i] * (i + 1)
print(finalvalue)


s1 = input()
n = int(input())
l1 = list(map(int, input().split()))
index = l1.index(max(l1))
s1 += chr(97 + index) * n
sum1 = 0
for i in range(len(s1)):
	sum1 += l1[ord(s1[i]) - 97] * (i + 1)
print(sum1)


s = input()
n = int(input())
d = list(map(int, input().split()))
m = max(d)
x = 0
try:
	for i in range(len(s)):
		x += d[ord(s[i]) - 97] * (i + 1)
except:
	pass
for j in range(len(s) + 1, len(s) + n + 1):
	x += j * m
print(x)


import time, math
from sys import stdin, stdout
I = lambda : int(stdin.readline())
Is = lambda : str(stdin.readline())
In = lambda : map(int, stdin.readline().split())
L = lambda : list(map(int, stdin.readline().split()))
Si = lambda : sorted(list(map(int, stdin.readline().split())))
Sr = lambda : sorted(list(map(int, stdin.readline().split())), reverse=True)
Pi = lambda x, y: stdout.write(str(x) + ' ' + str(y))

def P(x):
	return stdout.write(str(x))

def solve():
	s = Is()
	k = I()
	l = L()
	ans = 0
	for i in range(len(s) - 1):
		ans += l[ord(s[i]) - ord('a')] * (i + 1)
	x = int(len(s) * (len(s) - 1) / 2)
	y = int((len(s) + k) * (len(s) + k - 1) / 2)
	P(ans + max(l) * (y - x))
solve()


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


import math
from collections import *
import sys
from functools import reduce
import time
from itertools import groupby

def input():
	return sys.stdin.readline()

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)]
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1), (+1, +1), (+1, +0), (+1, -1), (+0, +1)]
CAPS_ALPHABETS = {chr(i + ord('A')): i for i in range(26)}
SMOL_ALPHABETS = {chr(i + ord('a')): i for i in range(26)}
INF = float('inf')
s = input().strip('\n')
k = int(input())
li = get_list()
n = len(s)
print(max(li) * sum(range(n + 1, n + k + 1)) + sum([li[ord(s[i]) - ord('a')] * (i + 1) for i in range(n)]))


g = input()
alpha = 'abcdefghijklmnopqrstuvwxyz'
t = list(alpha)
dic = {}
k = int(input())
r = input()
tt = r.split()
for i in range(0, len(r.split())):
	dic[t[i]] = int(tt[i])
result = 0
for i in range(0, len(g)):
	result = result + (i + 1) * dic[g[i]]
key = max(dic.values())
for h in range(len(g), len(g) + k):
	result = result + (h + 1) * key
print(result)


from string import ascii_lowercase as a
s = input()
k = int(input())
w = list(map(int, input().split()))
wmax = max(w)
s += '0' * k
summ = 0
for (b, i) in zip(s, range(len(s))):
	if b == '0':
		summ += (i + 1) * wmax
	else:
		summ += w[a.index(b)] * (i + 1)
print(summ)


s = input()
k = int(input())
a = [i for i in input().split()]
b = [int(i) for i in a]
t = max(b)
summ = 0
l = list(s)
for i in range(len(l)):
	summ += b[ord(l[i]) - ord('a')] * (i + 1)
for i in range(len(l) + 1, len(l) + k + 1):
	summ += i * t
print(summ)


s = list(input())
k = int(input())
a = list(map(int, input().split()))
b = [a[i] for i in range(len(a))]
b.sort()
c = 0
for j in range(len(s)):
	c = c + (j + 1) * a[ord(s[j]) - 97]
i = len(s) + 1
for j in range(k):
	c = c + i * b[-1]
	i = i + 1
print(c)


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


def sumatoria(n):
	return int(n * (n + 1) / 2)
original = str(input())
k = int(input())
valores = list(map(int, input().split()))
abc = {}
maxi = 0
for (i, x) in enumerate(valores):
	abc[chr(i + 97)] = x
	if x > maxi:
		maxi = x
suma = 0
value = 1
for i in original:
	suma += abc[i] * value
	value += 1
k2 = k + len(original)
suma += (sumatoria(k2) - sumatoria(len(original))) * maxi
print(suma)


import sys
import math as m

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True
mod = int(1000000000.0) + 7

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def linp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(a):
	print(a)
s = sinp()
k = iinp()
w = linp()
ws = [0] * 26
ind = 0
for i in w:
	ws[ind] = i
	ind += 1
m = max(ws)
ans = 0
ind = 1
for c in s:
	ans = ans + ws[ord(c) - 97] * ind
	ind += 1
for i in range(k):
	ans = ans + m * ind
	ind += 1
print(ans)


s = input()
n = int(input())
a = [int(x) for x in input().split()]
cur = 0
for i in range(len(s)):
	cur += (i + 1) * a[ord(s[i]) - ord('a')]
(m, b) = (len(s), max(a))
for i in range(n):
	cur += (m + i + 1) * b
print(cur)


import string
S = input()
K = int(input())
W = list(map(int, input().split()))
maxw = max(W)
for (i, w) in enumerate(W):
	if w == maxw:
		argmaxi = i
		break
ans = 0
for (i, s) in enumerate(S):
	ans += W[string.ascii_lowercase.index(s)] * (i + 1)
N = len(S)
for k in range(K):
	ans += W[argmaxi] * (k + N + 1)
print(ans)


n = input()
k = int(input())
ar = list(map(int, input().split()))
s1 = 0
for x in range(len(n)):
	s1 += ar[ord(n[x]) - ord('a')] * (x + 1)
ar.sort()
for x in range(len(n) + 1, len(n) + k + 1):
	s1 += ar[-1] * x
print(s1)


import string
s = input()
t = int(input())
l = list(map(int, input().split()))
a = string.ascii_lowercase
for i in range(t):
	s = s + a[l.index(max(l))]
cnt = 0
i = 1
for x in s:
	cnt = cnt + i * l[a.find(x)]
	i = i + 1
print(cnt)


def sumn(n):
	return int(n * (n + 1) / 2)
s = input()
k = int(input())
val = []
str1 = input().split()
for x in range(len(str1)):
	val.append(int(str1[x]))
v1 = ord('a')
maxi = max(val)
s1 = 0
for i in range(len(s)):
	s1 += (i + 1) * val[ord(s[i]) - v1]
add = sumn(len(s) + k) - sumn(len(s))
print(s1 + add * maxi)


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


s = input()
k = int(input())
w = list(map(int, input().split()))
ans = 0
n = len(s)
for i in range(n):
	ans += w[ord(s[i]) - ord('a')] * (i + 1)
w.sort()
print(ans + (2 * n + k + 1) * k // 2 * w[25])


import string
lower = string.ascii_lowercase
x = input()
k = int(input())
l = list(map(int, input().split()))
op = k
d = {}
ans = []
hlf = 0
for i in range(26):
	d[lower[i]] = l[i]
l = sorted(l, reverse=True)
if k == 0:
	for i in range(len(x)):
		hlf += d[x[i]] * (i + 1)
	print(hlf)
else:
	while k != 0:
		ans.append(l.pop(0))
		break
		k -= 1
	hlf = 0
	for i in range(len(x)):
		hlf += d[x[i]] * (i + 1)
	vlf = 0
	f = len(x)
	for i in range(f + 1, f + op + 1, 1):
		vlf += i * ans[0]
	print(hlf + vlf)


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


s = input()
a = int(input())
b = list(map(int, input().split()))
d = max(b)
e = 0
for i in range(1, len(s) + 1):
	g = s[i - 1]
	e += i * b[ord(g) - 97]
for i in range(len(s) + 1, len(s) + 1 + a):
	e += i * d
print(e)


(s, k) = (input(), int(input()))
a = list(map(int, input().split()))
s += k * chr(97 + a.index(max(a)))
print(sum((a[ord(s[i]) - 97] * (i + 1) for i in range(len(s)))))


from sys import stdin
from sys import stdout
s = stdin.readline()
k = stdin.readline()
t = stdin.readline()
k = int(k)
t = t.strip('\n')
code = str.split(t)
s = s.strip('\n')
maxi = 0
for i in code:
	if int(i) > maxi:
		maxi = int(i)
totalLen = len(s) + k
maxValue = 0
for i in range(len(s) + 1, totalLen + 1):
	maxValue += maxi * i
j = 1
for i in s:
	maxValue += int(code[ord(i) - 97]) * j
	j += 1
stdout.write(str(maxValue))


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)


inp = input()
N = int(input())
arr = input().split(' ')
for i in range(len(arr)):
	arr[i] = int(arr[i])
max = max(arr)
sum = 0
for i in range(len(inp)):
	sum += int(arr[ord(inp[i]) - 97]) * (int(i) + 1)
for i in range(N):
	sum += (i + len(inp) + 1) * max
print(sum)


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


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())
l = list(map(int, input().split()))
d = {}
for i in range(26):
	d[chr(ord('a') + i)] = l[i]
ans = 0
for i in range(len(s)):
	ans += (i + 1) * d[s[i]]
m = max(l)
for i in range(len(s), len(s) + k):
	ans += m * (i + 1)
print(ans)


import sys, bisect
from sys import stdin, stdout
from bisect import bisect_left, bisect_right, bisect, insort, insort_left, insort_right
from math import gcd, ceil, floor, sqrt
from collections import Counter, defaultdict, deque, OrderedDict
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 998244353
mod = 10 ** 9 + 7

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def solve():
	s = input()
	k = inp()
	ans = 0
	l = li()
	for i in range(len(s)):
		ind = ord(s[i]) - 97
		ans += (i + 1) * l[ind]
	mi = float('-inf')
	for i in range(26):
		if l[i] > mi:
			mi = l[i]
	c = len(s) + 1
	while k:
		ans += c * mi
		c += 1
		k -= 1
	pr(ans)
for _ in range(1):
	solve()


s = input('')
k = int(input(''))
W = [int(i) for i in input('').split()]
M = len(s) + k
C = 0
T = 0
for x in range(0, len(s)):
	if 0 <= ord(s[x]) - 97 <= 25:
		T += W[ord(s[x]) - 97] * (x + 1)
A = -1
for i in range(0, len(W)):
	if W[i] > A:
		A = W[i]
while M > len(s):
	T += M * A
	M -= 1
print(T)


alp = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
s = list(input())
k = int(input())
val = list(map(int, input().split()))
tot = 0
i = 1
while i <= len(s):
	x = alp[s[i - 1]]
	x = val[x]
	tot = tot + i * x
	i = i + 1
k = k + len(s)
x = max(val)
while i <= k:
	tot = tot + i * x
	i = i + 1
print(tot)


import math
s = input()
x = int(input())
wc = [int(i) for i in input().split()]
r = 0
for (i, c) in enumerate(s):
	r += (i + 1) * wc[ord(c) - ord('a')]
mwc = max(wc)
for i in range(len(s), len(s) + x):
	r += (i + 1) * mwc
print(r)


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil, floor, log, log2, sqrt, gcd, factorial, pow, pi

def binNumber(n, size=4):
	return bin(n)[2:].zfill(size)

def iar():
	return list(map(int, input().split()))

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())

def par(a):
	print(' '.join(list(map(str, a))))

def tdl(outerListSize, innerListSize, defaultValue=0):
	return [[defaultValue] * innerListSize for i in range(outerListSize)]

def sts(s):
	s = list(s)
	s.sort()
	return ''.join(s)

class pair:

	def __init__(self, f, s):
		self.fi = f
		self.se = s

	def __lt__(self, other):
		return (self.fi, self.se) < (other.fi, other.se)
s = sti()
n = ini()
a = iar()
cnt = 0
v = max(a)
for i in range(len(s)):
	cnt += a[ord(s[i]) - 97] * (i + 1)
c = len(s) + 1
while n > 0:
	cnt += v * c
	c += 1
	n -= 1
print(cnt)


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().upper()
k = int(input())
w = list(map(int, input().split()))
z = len(s)
sum = 0
theDict = {chr(y): y - 64 for y in range(65, 91)}
for j in range(len(s)):
	sum += w[theDict[s[j]] - 1] * (j + 1)
n = max(w)
for i in range(1, k + 1):
	sum += (i + z) * n
print(sum)


import operator
st = input()
k = int(input())
w = list(map(int, input().split()))
(mi_w, mv_w) = max(enumerate(w), key=operator.itemgetter(1))
st = st + k * chr(mi_w + 97)
f = sum([w[ord(c) - 97] * (i + 1) for (i, c) in enumerate(st)])
print(f)


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

def maxind(a):
	res = a[0]
	res_ind = 0
	for (i, el) in enumerate(a):
		if el > res:
			res = el
			res_ind = i
	return res_ind
a += chr(maxind(w) + 97) * k
print(sum((w[ord(el) - 97] * (i + 1) for (i, el) in enumerate(a))))


s = input()
k = int(input())
l = list(map(int, input().split()))
r = 0
for i in range(len(s)):
	if s[i] == 'a':
		r = r + (i + 1) * l[0]
	elif s[i] == 'b':
		r = r + (i + 1) * l[1]
	elif s[i] == 'c':
		r = r + (i + 1) * l[2]
	elif s[i] == 'd':
		r = r + (i + 1) * l[3]
	elif s[i] == 'e':
		r = r + (i + 1) * l[4]
	elif s[i] == 'f':
		r = r + (i + 1) * l[5]
	elif s[i] == 'g':
		r = r + (i + 1) * l[6]
	elif s[i] == 'h':
		r = r + (i + 1) * l[7]
	elif s[i] == 'i':
		r = r + (i + 1) * l[8]
	elif s[i] == 'j':
		r = r + (i + 1) * l[9]
	elif s[i] == 'k':
		r = r + (i + 1) * l[10]
	elif s[i] == 'l':
		r = r + (i + 1) * l[11]
	elif s[i] == 'm':
		r = r + (i + 1) * l[12]
	elif s[i] == 'n':
		r = r + (i + 1) * l[13]
	elif s[i] == 'o':
		r = r + (i + 1) * l[14]
	elif s[i] == 'p':
		r = r + (i + 1) * l[15]
	elif s[i] == 'q':
		r = r + (i + 1) * l[16]
	elif s[i] == 'r':
		r = r + (i + 1) * l[17]
	elif s[i] == 's':
		r = r + (i + 1) * l[18]
	elif s[i] == 't':
		r = r + (i + 1) * l[19]
	elif s[i] == 'u':
		r = r + (i + 1) * l[20]
	elif s[i] == 'v':
		r = r + (i + 1) * l[21]
	elif s[i] == 'w':
		r = r + (i + 1) * l[22]
	elif s[i] == 'x':
		r = r + (i + 1) * l[23]
	elif s[i] == 'y':
		r = r + (i + 1) * l[24]
	elif s[i] == 'z':
		r = r + (i + 1) * l[25]
if k == 0:
	print(r)
else:
	le1 = len(s)
	le = le1 + k
	sum1 = le / 2 * (2 + (le - 1))
	sum2 = le1 / 2 * (2 + (le1 - 1))
	sum3 = sum1 - sum2
	r1 = sum3 * max(l)
	print(int(r + r1))


s = list(input())
k = int(input())
w = list(map(int, input().split()))
s = s + [chr(97 + w.index(max(w)))] * k
c = 0
j = 1
for i in s:
	c = c + w[ord(i) - 97] * j
	j = j + 1
print(c)


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


import sys
import math

def fn(s, k, w):
	l = ['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']
	x = [[0] * 2] * 26
	for i in range(len(x)):
		x[i] = [l[i], int(w[i])]
	y = x.copy()
	x.sort(key=lambda x: x[1], reverse=True)
	s = list(s)
	sum = 0
	first_tuple_elements = []
	second_tuple_elements = []
	for a_tuple in y:
		first_tuple_elements.append(a_tuple[0])
	for b in y:
		second_tuple_elements.append(b[1])
	for i in range(len(s)):
		sum = sum + (i + 1) * int(second_tuple_elements[first_tuple_elements.index(s[i])])
	z = x[0][1]
	sum1 = sum + (k * (k + 1) / 2 + k * len(s)) * z
	return int(sum1)
input = sys.stdin.read()
data = list(map(str, input.split()))
s = data[0]
k = int(data[1])
w = data[2:]
print(fn(s, k, w))


s = input()
k = int(input())
l = list(map(int, input().split()))
m = max(l)
add = 0
for (j, i) in enumerate(s, 1):
	x = ord(i) - 97
	add += j * l[x]
for i in range(len(s) + 1, len(s) + 1 + k):
	add += i * m
print(add)


class CodeforcesTask447BSolution:

	def __init__(self):
		self.result = ''
		self.string = ''
		self.k = 0
		self.values = []

	def read_input(self):
		self.string = input()
		self.k = int(input())
		self.values = [int(x) for x in input().split(' ')]

	def process_task(self):
		values = {}
		alphabet = 'abcdefghijklmnopqrstuvwxyz'
		for x in range(len(alphabet)):
			values[alphabet[x]] = self.values[x]
		total_value = 0
		mx_val = max(self.values)
		for i in range(len(self.string)):
			total_value += (i + 1) * values[self.string[i]]
		for i in range(len(self.string), len(self.string) + self.k):
			total_value += (i + 1) * mx_val
		self.result = str(total_value)

	def get_result(self):
		return self.result
Solution = CodeforcesTask447BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


s = list(input())
k = int(input())
a = [int(i) for i in input().split()]
v = 0
for (i, d) in enumerate(s):
	v += (i + 1) * a[ord(d) - 97]
m = max(a)
for j in range(k):
	v += m * (j + i + 2)
print(v)


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write()
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
s = list(input())
n = int(input())
l = list(map(int, input().rstrip().split()))
ma = l[l.index(max(l))]
ans = 0
temp = 0
for i in range(len(s)):
	ans = ans + (i + 1) * l[ord(s[i]) - 97]
for j in range(n):
	ans += (len(s) + j + 1) * ma
print(ans)


s = input()
k = int(input())
w = list(input().split())
alphabet = list('abcdefghijklmnopqrstuvwxyz')
for num in range(0, 26):
	w[num] = int(w[num])
s = list(s)
count = 0
value = 0
for num in range(0, len(s)):
	qwerty = alphabet.index(s[num])
	xxx = w.pop(qwerty)
	value += xxx * (num + 1)
	w.insert(qwerty, xxx)
while count < k:
	add = max(w)
	value += add * (count + 1 + len(s))
	count += 1
print(value)


import string
s = input()
k = int(input())
w = [int(x) for x in input().split()]
total = 0
i = 1
while i <= len(s):
	d = string.ascii_lowercase.index(s[i - 1])
	total = total + i * w[string.ascii_lowercase.index(s[i - 1])]
	i = i + 1
w.sort()
j = len(s) + 1
while j <= len(s) + k:
	total = total + w[-1] * j
	j = j + 1
print(total)


s = [ord(i) - ord('a') for i in input()]
n = int(input())
a = list(map(int, input().split()))
ans = 0
maxi = -1
count = 1
for i in s:
	ans += count * a[i]
	count += 1
ans += max(a) * (n * len(s) + n * (n + 1) // 2)
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())
a = list(map(int, input().split()))
n = len(s)
tot = 0
j = 1
for i in range(n):
	tot += j * a[ord(s[i]) - 97]
	j += 1
m = 0
p = 0
for i in range(26):
	if m < a[i]:
		m = a[i]
		p = m
while j <= n + k:
	tot += j * p
	j += 1
print(tot)


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)]))


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


s = input()
k = int(input())
arr = [int(x) for x in input().split()]
ans = 0
for i in range(len(s)):
	ans += arr[ord(s[i]) - 97] * (i + 1)
haha = max(arr)
for i in range(k):
	ans += haha * (len(s) + i + 1)
print(ans)


s = str(input())
k = int(input())
a = [int(x) for x in input().split()]
ans = 0
l = len(s)
for i in range(0, l):
	ans += (i + 1) * a[ord(s[i]) - 97]
maxi = max(a)
ans += maxi * (l * k + k * (k + 1) / 2)
print(int(ans))


(s, k) = (input(), int(input()))
w = dict(zip('abcdefghijklmnopqrstuvwxyz', map(int, input().split())))
print(sum((i * w[ch] for (i, ch) in enumerate(s, 1))) + max(w.values()) * k * (2 * len(s) + k + 1) // 2)


s = str(input())
k = int(input())
l = list(map(int, input().split()))
numbers = []
for i in range(len(s)):
	numbers.append(l[ord(s[i]) - 97])
high = max(l)
while k != 0:
	numbers.append(high)
	k = k - 1
temp = 1
ans = 0
for i in numbers:
	ans = ans + temp * i
	temp = temp + 1
print(ans)


s = input()
k = int(input())
L = list(map(int, input().split()))
v = max(L)
S = 0
SS = 0
Left = []
vL = []
vR = []
for i in range(len(s)):
	x = ord(s[i]) - ord('a')
	S += L[x] * (i + 1)
	SS += L[x]
	Left.append(S)
	vL.append(SS)
Right = []
SS = 0
S = 0
for i in range(len(s) - 1, -1, -1):
	x = ord(s[i]) - ord('a')
	S += L[x] * (i + 1)
	SS += L[x]
	Right = [S] + Right
	vR = [SS] + vR
ans = (1 + k) * k // 2 * v + S
f = (1 + k) * k // 2 * v
for i in range(len(s)):
	x = ord(s[i]) - ord('a')
	inc = i + 2
	tmp = Left[i] + (inc + inc - 1 + k) * k // 2 * v
	if i + 1 < len(s):
		tmp += Right[i + 1] + k * vR[i + 1]
	ans = max(ans, tmp)
print(ans)


s = input()
k = int(input())
l = [int(i) for i in input().split()]
sm = 0
n = len(s)
for i in range(n):
	sm += l[ord(s[i]) - 97] * (i + 1)
l = sorted(l, reverse=True)
z = l[0:k]
z = z[::-1]
for i in range(n, n + k):
	sm += (i + 1) * max(l)
print(sm)


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


initial_string = input()
num_additional_chars = int(input())
weights = list(map(int, input().strip().split(' ')))
max_weight = max(weights)
aOrdinal = ord('a')
result = sum(((i + 1) * weights[ord(character) - aOrdinal] for (i, character) in enumerate(initial_string)))
result += sum(((i + 1 + len(initial_string)) * max_weight for i in range(0, num_additional_chars)))
print(result)


s = input()
k = int(input())
a = list(map(int, input().split()))
ans = 0
t = 0
for i in s:
	t += 1
	ans += a[ord(i) - ord('a')] * t
x = max(a)
ans += ((len(s) + k) * (len(s) + k + 1) // 2 - len(s) * (len(s) + 1) // 2) * x
print(ans)


s = input()
k = int(input())
w = list(map(int, input().split()))
d = {chr(97 + i): w[i] for i in range(26)}
m = 0
for i in range(len(s) + k):
	if i < len(s):
		m += (i + 1) * d[s[i]]
	if i >= len(s):
		m += (i + 1) * max(d.values())
print(m)


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)


n = input()
k = int(input())
q = input().split(' ')
q = list(map(int, q))
w = max(q)
sum = 0
s = len(n) + k
for i in range(k):
	sum += (s - i) * w
for i in range(len(n)):
	y = ord(n[i])
	sum += (i + 1) * q[abs(97 - y)]
print(sum)


import string
s = input()
k = int(input())
total = 0
l = list(map(int, input().split()))
c = max(l)
z = len(s)
ls = string.ascii_lowercase
for x in range(z):
	if s[x] in ls:
		total += l[ls.find(s[x])] * (x + 1)
for i in range(1, k + 1):
	total += c * (z + i)
print(total)


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

def getPos(char):
	return ord(char) - 97
size_string = 0
for i in range(len(s)):
	size_string += w[getPos(s[i])] * (i + 1)
max_w = max(w)
for i in range(len(s) + 1, len(s) + n + 1):
	size_string += i * max_w
print(size_string)


nn = str(input())
extra = int(input())
v = str(input())
v1 = v.split()
maxs = 0
dicts = {}
counter = 97
for i in v1:
	k = int(i)
	if int(i) > maxs:
		maxs = k
	dicts[chr(counter)] = k
	counter += 1
total = 0
c = 1
for i in nn:
	total += c * dicts[i]
	c += 1
for i in range(extra):
	total += c * maxs
	c += 1
print(total)


import os
import sys
from math import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return map(int, input().split())

def array():
	return [int(i) for i in input().split()]
s = input()
k = int(input())
a = array()
ind = a.index(max(a))
s += chr(ind + 97) * k
ans = 0
for i in range(len(s)):
	ans += a[ord(s[i]) - 97] * (i + 1)
print(ans)


s = input()
k = int(input())
l = list(map(int, input().split()))
n = len(s)
ft = n + 1
su = 2 * ft + k - 1
su = k * su
su = su // 2
su = max(l) * su
su1 = 0
for i in range(len(s)):
	ind = ord(s[i]) - 97
	su1 = su1 + (i + 1) * l[ind]
print(su1 + su)


s = input()
s = list(s)
n = int(input())
l = list(map(int, input().split()))
x = max(l)
c = 0
for (i, j) in enumerate(s):
	h = ord(j) - 97
	c += (i + 1) * l[h]
print('')
for j in range(i + 2, i + n + 2):
	h = x * j
	c += h
print(c)


letters = list(input())
l = len(letters)
k = int(input())
w = [int(x) for x in input().split()]
res = 0
maxW = max(w)
for i in range(l):
	res += (i + 1) * w[ord(letters[i]) - ord('a')]
for i in range(k):
	res += (l + i + 1) * maxW
print(res)


x = input()
k = int(input())
a = list(map(int, input().split()))
c = []
l = 0
for i in range(97, 123):
	c.append([a[i % 97], chr(i)])
for i in range(len(x)):
	for j in range(len(c)):
		if x[i] == c[j][1]:
			l += (i + 1) * c[j][0]
			break
for i in range(len(x) + 1, len(x) + k + 1):
	l += i * max(a)
print(l)


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)
for i in range(len(s) + 1, len(s) + 1 + k):
	value += score[0] * i
print(value)


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()
n = int(input())
arr = list(map(int, input().split()))
m = max(arr)
ans = 0
i = 1
while i <= len(s):
	ans += i * arr[ord(s[i - 1]) - 97]
	i += 1
while i <= n + len(s):
	ans += m * i
	i += 1
print(ans)


s = input()
k = int(input())
values = list(map(int, input().split()))
mydict = {}
summ = 0
for i in range(26):
	mydict[chr(97 + i)] = values[i]
ite = 1
while ite <= len(s):
	summ += ite * mydict[s[ite - 1]]
	ite += 1
m = max(values)
while ite <= len(s) + k:
	summ += ite * m
	ite += 1
print(summ)


inp = input()
k = int(input())
l1 = [int(x) for x in input().split()]
out = 0
for i in range(0, len(inp)):
	ind = ord(inp[i]) - ord('a')
	out += l1[ind] * (i + 1)
leng = len(inp)
val = k * leng + k * (k + 1) // 2
val *= max(l1)
out += val
print(out)


s = input()
k = int(input())
wt = [int(x) for x in input().split()]
string = 'abcdefghijklmnopqrstuvwxyz'
string = list(string)
ans = 0
for i in range(len(s)):
	ind = string.index(s[i])
	ans += wt[ind] * (i + 1)
maxi = max(wt)
for i in range(1, k + 1):
	ans += maxi * (len(s) + i)
print(ans)


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


s = input()
x = int(input())
a = list(map(int, input().split()))
s = s + chr(97 + a.index(max(a))) * x
p = 0
for i in range(1, len(s) + 1):
	p = p + i * a[ord(s[i - 1]) - 97]
print(p)


s = input()
n = int(input())
a = list(map(int, input().split()))
m = max(a)
o = 0
j = 1
x = False
for i in range(len(s)):
	if a[ord(s[i]) - 97] <= m or x:
		o += j * a[ord(s[i]) - 97]
		j += 1
	else:
		o += m * n * (j + n + j - 1) / 2
		j += n
		x = True
if not x:
	o += m * n * (j + n + j - 1) / 2
	j += n
	x = True
print(int(o))


s = input()
k = int(input())
w = list(map(int, input().split()))
mp = dict()
x = 'a'
for i in range(len(w)):
	mp[chr(i + ord('a'))] = w[i]
ans = 0
ln = len(s)
for i in range(ln):
	ans += mp[s[i]] * (i + 1)
mx = max(w)
ml = ln + k
mul = ml * (ml + 1) // 2 - ln * (ln + 1) // 2
ans += mul * mx
print(ans)


s = input()
k = int(input())
w = input()
L = len(s)
sum = 0
x = []
wi = w.split()
for i in range(L):
	x.append(wi[ord(s[i]) - 97])
	sum += int(x[i]) * (i + 1)
n = int(wi[0])
for i in range(len(wi)):
	if n < int(wi[i]):
		n = int(wi[i])
for i in range(k):
	sum += n * (i + L + 1)
print(sum)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
s = input()
k = rint()
w = rints()
mw = max(w)
print(sum(((w[ord(s[i]) - ord('a')] if i < len(s) else mw) * (i + 1) for i in range(len(s) + k))))


aa = input()
k = int(input())
z = list(map(int, input().split()))
result = 0
for i in range(len(aa)):
	result += z[ord(aa[i]) - 97] * (i + 1)
for i in range(k):
	result += max(z) * (i + 1 + len(aa))
print(result)


s = input()
k = int(input())
l = list(map(int, input().split()))
e = max(l)
ans = 0
for i in range(len(s) + k):
	if i < len(s):
		ans += (i + 1) * l[ord(s[i]) - 97]
	else:
		ans += (i + 1) * e
print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
A = input()
k = iinput()
w = rlinput()
max_value = max(w)
ans = 0
cur = ord('a')
for i in range(len(A)):
	ans += w[ord(A[i]) - cur] * (i + 1)
i += 1
for _ in range(k):
	ans += max_value * (i + 1)
	i += 1
print(ans)


s = input()
n = int(input())
arr = list(map(int, input().split()))
ar = []
l = len(s)
p = max(arr)
for t in range(l):
	ar += [arr[ord(s[t]) - 97]]
for y in range(n):
	ar += [p]
sum = 0
for g in range(l + n):
	sum += (g + 1) * ar[g]
print(sum)


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


s = input()
k = int(input())
w = [int(i) for i in input().split()]
li = []
for ch in s:
	li.append(w[ord(ch) - ord('a')])
li.extend([max(w)] * k)
ans = 0
for i in range(0, len(li)):
	ans += (i + 1) * li[i]
print(ans)


s = input()
k = int(input())
w = [int(x) for x in input().split()]
print(sum((x * w[ord(y) - ord('a')] for (x, y) in zip(range(1, len(s) + 1), s))) + (k * (k + 1) // 2 + k * len(s)) * max(w))


from collections import *
from bisect import *
from math import *
from heapq import *
from fractions import *
import sys
input = sys.stdin.readline
t = 1

def r(a):
	return a * (a - 1) // 2
while t:
	t -= 1
	a = input().rstrip('\n')
	b = int(input())
	a1 = list(map(int, input().split()))
	c = 1
	s = 0
	for i in a:
		s += c * a1[ord(i) - 97]
		c += 1
	v = max(a1)
	for i in range(b):
		s += v * c
		c += 1
	print(s)


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


import math

def inp():
	return int(input())

def inps():
	return map(int, input().split())

def inpl():
	return [int(n) for n in input().split() if n.isdigit()]
s = input()
k = inp()
l = inpl()
r = 0
for i in range(0, len(s)):
	r += l[ord(s[i]) - ord('a')] * (i + 1)
mx = 0
for i in l:
	mx = max(mx, i)
r += (2 * len(s) + k + 1) * k * mx / 2
print(int(r))


def s_till(n):
	return n * (n + 1) // 2
z = str(input())
k = int(input())
va = list(map(int, input().split()))
c_va = {chr(97 + h): i for (h, i) in enumerate(va)}
ans = 0
for (ind, i) in enumerate(z):
	ans += (ind + 1) * c_va[i]
to_mult = s_till(k + len(z)) - s_till(len(z))
ans += to_mult * max(c_va.values())
print(ans)


a = input()
b = int(input())
z = 0
s = 0
q = dict()
f = 97
o = 1
for i in map(int, input().split()):
	q[chr(f)] = i
	f += 1
for i in a:
	s += o * q[i]
	o += 1
	z = max(q.values())
print(s + sum((i * z for i in range(o, o + b))))


from string import ascii_lowercase

def main():
	s = input()
	k = int(input())
	w = list(map(int, input().split()))
	func = dict(zip(ascii_lowercase, w))
	z = max(w)
	score = 0
	j = 1
	for i in s:
		score += func[i] * j
		j += 1
	score += (len(s) * k + k * (k + 1) // 2) * z
	print(score)
main()


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


import string
s = input()
k = int(input())
lst = list(map(int, input().split()))
d = {}
i = 0
for e in string.ascii_lowercase:
	d[e] = lst[i]
	i += 1
m = max(d.values())
char = ''
for (i, v) in d.items():
	if v == m:
		char = i
		break
s += char * k
score = 0
i = 1
for e in s:
	score += d[e] * i
	i += 1
print(score)


S = input()
N = int(input())
X = list(map(int, input().split()))
MAX = max(X)
SUM = 0
for i in range(len(S)):
	SUM += X[ord(S[i]) - 97] * (i + 1)
for i in range(1, N + 1):
	SUM += (len(S) + i) * MAX
print(SUM)


s = input()
n = int(input())
L = [int(i) for i in input().split()]
m = max(L)
ans = 0
for j in range(len(s) + n):
	if j < len(s):
		ans += L[ord(s[j]) - 97] * (j + 1)
	else:
		ans += m * (j + 1)
print(ans)


line = input()
l = len(line)
k = int(input())
s = list(map(int, input().split()))
ma = max(s)
ans = 0
for (i, x) in enumerate(line):
	ans += s[ord(x) - ord('a')] * (i + 1)
for j in range(k):
	ans += ma * (l + j + 1)
print(ans)


s = input()
n = int(input())
l = list(map(int, input().split()))
dic = {}
for i in range(0, len(l)):
	dic[i] = l[i]
dlist = sorted(dic.items(), key=lambda x: x[1], reverse=True)
second = dlist[0][1]
first = dlist[0][0]
for i in range(0, n):
	s += chr(first + 97)
val = 0
for i in range(0, len(s)):
	val += (i + 1) * dic[ord(s[i]) - 97]
print(val)


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


s = input()
k = int(input())
x = [int(i) for i in input().split()]
s += k * chr(x.index(max(x)) + ord('a'))
ans = sum([x[ord(s[i]) - ord('a')] * (i + 1) for i in range(len(s))])
print(ans)


n = input()
k = int(input())
l = list(map(int, input().split()))
m = max(l)
x = 0
for i in range(0, len(n)):
	x += l[ord(n[i]) - 97] * (i + 1)
for j in range(len(n) + 1, len(n) + k + 1):
	x += m * j
print(x)


s = input()
k = input()
k = int(k)
w = list(map(int, input().rstrip().split()))
b = sorted(w)
Sum = 0
s1 = 0
for i in range(len(s)):
	Sum = Sum + w[abs(ord('a') - ord(s[i]))] * (i + 1)
for j in range(len(s) + 1, len(s) + k + 1):
	s1 = s1 + j * b[25]
print(Sum + s1)


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)


s = input().rstrip()
k = int(input())
a = list(map(int, input().rstrip().split()))
p = dict()
j = 0
for i in range(97, 97 + 26):
	p[chr(i)] = a[j]
	j += 1
value = 0
l = 0
for i in range(len(s)):
	value += (i + 1) * p[s[i]]
maxi = max(a)
for i in range(len(s), len(s) + k):
	value += (i + 1) * maxi
print(value)


alph = 'abcdefghijklmnopqrstuvwxyz'
s = input()
k = int(input())
l = list(map(int, input().split()))
m = max(l)
su = 0
for (i, v) in enumerate(s):
	su += (i + 1) * l[alph.index(v)]
for i in range(len(s) + 1, len(s) + 1 + k):
	su += i * m
print(su)


s = input()
k = int(input())
(x, Sum) = (list(map(int, input().split(' '))), 0)
for i in range(len(s)):
	Sum += x[ord(s[i]) - 97] * (i + 1)
print(Sum + sum((max(x) * (i + 1) for i in range(len(s), len(s) + k))))


s = input()
k = int(input())
l = list(map(int, input().split()))
max1 = 0
for i in l:
	if i > max1:
		max1 = i
sum = 0
for i in range(len(s)):
	sum += l[ord(s[i]) - 97] * (i + 1)
sum += (len(s) * k + k * (k + 1) // 2) * max1
print(sum)


s = input()
k = int(input())
l = list(map(int, input().split()))
c = []
for i in s:
	c.append(ord(i) - 97)
m = max(l)
S = 0
for i in range(len(s) + k):
	S = S + (i + 1) * l[c[i]] if i < len(s) else S + (i + 1) * m
print(S)


def main():
	import sys
	s = sys.stdin.readline().strip()
	n = int(sys.stdin.readline())
	tup = tuple(map(int, sys.stdin.readline().split()))
	maxim = max(tup)
	score = 0
	for i in range(len(s)):
		score += (i + 1) * tup[ord(s[i]) - 97]
	d = n * (2 * len(s) + n + 1) // 2
	score += maxim * d
	sys.stdout.write(str(score))
main()


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
s = inp()
l = len(s)
k = iinp()
arr = lmp()
ans = 0
for i in range(l):
	ans += (i + 1) * arr[ord(s[i]) - ord('a')]
mx = max(arr)
for i in range(k):
	ans += (i + 1 + l) * mx
print(ans)


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


from sys import *
input = stdin.readline
s = input()
d = int(input())
l = list(map(int, input().split()))
m = max(l)
n = len(s.strip())
c = 0
for i in range(n):
	x = ord(s[i]) - 97
	c += l[x] * (i + 1)
for i in range(n + 1, n + d + 1):
	c += m * i
print(c)


alp = 'abcdefghijklmnopqrstuvwxyz'
string = input()
k1 = int(input())
alpha = dict()
value = input().split(' ')
for (i, j) in zip(alp, value):
	alpha[i] = int(j)
key_max = max(alpha.keys(), key=lambda k: alpha[k])
sum1 = 0
j = 1
for i in string:
	sum1 = sum1 + j * alpha[i]
	j = j + 1
while k1 > 0:
	sum1 = sum1 + j * alpha[key_max]
	j = j + 1
	k1 = k1 - 1
print(sum1)


s = input()
n = int(input())
val = list(map(int, input().split()))
ans = 0
arr = []
for i in range(len(s)):
	ans += val[ord(s[i]) - 97] * (i + 1)
arr = max(val)
for j in range(n):
	ans += arr * (j + i + 2)
print(ans)


s = str(input())
k = int(input())
w = [int(x) for x in input().split()]
ans = 0
for i in range(len(s) + k):
	ans += (i + 1) * (w[ord(s[i]) - ord('a')] if i < len(s) else max(w))
print(ans)


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


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


x = input()
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(x)
sum = 0
for i in range(0, len(l2)):
	y = ord(l2[i]) - 97
	sum = sum + (i + 1) * l1[y]
c = max(l1)
for j in range(len(l2) + 1, len(l2) + n + 1):
	sum = sum + j * c
print(sum)


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
s = is1()
k = ii1()
alp = 'abcdefghijklmnopqrstuvwxyz'
d = {}
m = float('-inf')
for (j, i) in enumerate(iia()):
	d[alp[j]] = i
	m = max(m, i)
res = 0
for (j, i) in enumerate(s):
	res += (j + 1) * d[i]
for i in range(len(s), len(s) + k):
	res += (i + 1) * m
print(res)


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

def weight(letter):
	return w[ord(letter) - ord('a')]
s_sum = 0
for i in range(len(s)):
	c = s[i]
	s_sum += (i + 1) * weight(c)
m = max(w)
for i in range(len(s) + 1, len(s) + k + 1):
	s_sum += i * m
print(s_sum)


import sys
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
sys.setrecursionlimit(10 ** 7)
mod = 1000000007

def IOE():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	s = sys.stdin.readline().replace('\n', '')
	l = len(s)
	t = 'abcdefghijklmnopqrstuvwxyz'
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	maxx = max(a)
	ans = 0
	for i in range(n):
		ans += (i + l + 1) * maxx
	for i in range(l):
		ans += (i + 1) * a[t.index(s[i])]
	print(ans)
try:
	IOE()
except:
	pass
main()


import string
s = input()
n = int(input())
l = [int(x) for x in input().split()]
d = {}
val = 0
lc = [x for x in string.ascii_lowercase]
for i in range(26):
	d[lc[i]] = l[i]
le = len(s)
m = max(l)
for i in range(le):
	val = val + (i + 1) * d[s[i]]
for i in range(n):
	val = val + (le + i + 1) * m
print(val)


s = input()
k = int(input())
ar = list(map(int, input().split()))
best_letter = max(ar)
best_idx = ar.index(best_letter)
al = sorted(list('zxcvbnmasdfghjklqwertyuiop'))
best_letter = al[best_idx]
s = s + best_letter * k
func = 0
for i in range(len(s)):
	func += ar[al.index(s[i])] * (i + 1)
print(func)


string = input()
asci = []
for letter in string:
	asci.append(ord(letter) - 97)
n = int(input())
values = list(map(int, input().split()))
maxValue = max(values)
count = 1
s = 0
for i in asci:
	s += values[i] * count
	count += 1
for i in range(n):
	s += maxValue * count
	count += 1
print(s)


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())
a = list(map(int, input().split()))
l = 'abcdefghijklmnopqrstuvwxyz'
d = {}
total_sum = 0
for p in range(len(l)):
	d[l[p]] = a[p]
for i in range(len(s)):
	total_sum += (i + 1) * d[s[i]]
for j in range(k):
	total_sum += (j + 1 + len(s)) * max(a)
print(total_sum)


S = input()
p = int(input())
l = list(map(int, input().split()))
S1 = 'abcdefghijklmnopqrstuvwxyz'
k = 0
for i in range(len(S)):
	r = S1.index(S[i])
	k = k + (i + 1) * l[r]
v = i + p + 1
g = i
for j in range(i + 1, v):
	k = k + max(l) * (j + 1)
print(k)


import os
import sys
from io import BytesIO, IOBase
import math as M
import itertools as ITR
from collections import defaultdict as D
from collections import Counter as C
from collections import deque as Q
import threading
from functools import lru_cache, reduce
from functools import cmp_to_key as CMP
from bisect import bisect_left as BL
from bisect import bisect_right as BR
import random as R
import string
import cmath, time
enum = enumerate
start_time = time.time()
MOD = 1000000007
MA = float('inf')
MI = float('-inf')

def increase_stack():
	sys.setrecursionlimit(2 ** 32 // 2 - 1)
	threading.stack_size(1 << 27)
	t = threading.Thread(target=main)
	t.start()
	t.join()

def prints(a):
	print(a, end=' ')

def binary(n):
	return bin(n)[2:]

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def maxfactor(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
	if q:
		return q[-1]

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	l.sort()
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countchar(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def str_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def lis(arr):
	n = len(arr)
	lis = [1] * n
	maximum = 0
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
				maximum = max(maximum, lis[i])
	return maximum

def lcm(arr):
	a = arr[0]
	val = arr[0]
	for i in range(1, len(arr)):
		gcd = gcd(a, arr[i])
		a = arr[i]
		val *= arr[i]
	return val // gcd

def ncr(n, r):
	return M.factorial(n) // (M.factorial(n - r) * M.factorial(r))

def npr(n, r):
	return M.factorial(n) // M.factorial(n - r)

def inint():
	return int(inp())

def inarr():
	return list(map(int, inp().split()))

def invar():
	return map(int, inp().split())

def instr():
	s = inp()
	return list(s)

def insarr():
	return inp().split()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
inp = lambda : sys.stdin.readline().rstrip('\r\n')
TestCases = 0

def solve():

	def nsum(n):
		return n * (n + 1) // 2

	def ran(x, y):
		return nsum(y - 1) - nsum(x - 1)
	s = inp()
	n = inint()
	arr = inarr()
	dic = D(int)
	ma = max(arr)
	res = 0
	for (i, ele) in enum(s):
		res += (i + 1) * arr[ord(ele) - 97]
	c = len(s) + 1
	res += ran(c, c + n) * ma
	print(res)

def main():
	flag = 0
	try:
		sys.stdin = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/input.txt', 'r')
		sys.stdout = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/output.txt', 'w')
	except:
		flag = 1
	t = 1
	if TestCases:
		t = inint()
	for _ in range(1, t + 1):
		solve()
	if not flag:
		print('Time: %.4f sec' % (time.time() - start_time))
		localtime = time.asctime(time.localtime(time.time()))
		print(localtime)
		sys.stdout.close()
main()


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


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


def solve(st, k, w):
	_max = max(w)
	vals = [w[ord(c) - ord('a')] for c in st]
	idx = 0
	while idx < len(st) and vals[idx] <= _max:
		idx += 1
	vals = vals[:idx + 1] + [_max] * k + vals[idx + 1:]
	return sum([(i + 1) * x for (i, x) in enumerate(vals)])
res = solve(input(), int(input()), list(map(int, input().split())))
print(res)


string = input()
k = int(input())
arr = list(map(int, input().split()))
sum_ = 0
for i in range(0, len(string)):
	temp = ord(string[i]) - 97
	sum_ += (i + 1) * arr[temp]
arr.sort(reverse=True)
for i in range(len(string), len(string) + k):
	sum_ += (i + 1) * arr[0]
print(sum_)


s = input()
k = int(input())
v = list(map(int, input().split()))
w = {chr(ord('a') + i): v[i] for i in range(26)}
max_val = 0
max_key = ''
for key in w.keys():
	if w[key] > max_val:
		max_val = w[key]
		max_key = key
s += max_key * k
s_val = 0
for i in range(1, len(s) + 1):
	s_val += w[s[i - 1]] * i
print(s_val)


s = input()
k = int(input())
w = list(map(int, input().split()))
l = [ord(c) - 97 for c in s]
ma = max(w)
j = 1
su = 0
for t in [w[i] for i in l] + [ma] * k:
	su += j * t
	j += 1
print(su)


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


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()


s = input()
k = int(input())
v = list(map(int, input().split(' ')))
v_s = sorted(v, reverse=True)
ans = 0
for i in range(len(s)):
	ans += v[ord(s[i]) - ord('a')] * (i + 1)
for i in range(k):
	ans += (i + len(s) + 1) * v_s[0]
print(ans)


s = input()
k = int(input())
d = list(map(int, input().split()))
p = d.index(max(d))
s = s + chr(ord('a') + p) * k
r = 0
for i in range(1, len(s) + 1):
	r += d[ord(s[i - 1]) - ord('a')] * i
print(r)


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']
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)


s = input()
k = int(input())
a = input().split()
for i in range(26):
	a[i] = int(a[i])
m = -10
mi = 0
for i in range(26):
	if a[i] > m:
		m = a[i]
		mi = i
answ = 0
for i in range(k):
	s += chr(mi + 97)
for i in range(len(s)):
	answ += a[ord(s[i]) - 97] * (i + 1)
print(answ)


S = input()
k = int(input())
W = list(map(int, input().split()))
m = max(W)
ans = 0
count = 1
for s in S:
	x = ord(s) - ord('a')
	ans += W[x] * count
	count += 1
for i in range(k):
	ans += m * (i + count)
print(ans)


s = input()
k = int(input())
a = [int(x) for x in input().split()]
b = [chr(x) for x in range(97, 123)]
j = 1
product = 0
for i in range(len(s)):
	product += j * a[b.index(s[i])]
	j += 1
p = 1
while p <= k:
	product += j * int(max(a))
	j += 1
	p += 1
print(product)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
s = input()
n = len(s)
k = L()[0]
A = L()
mx = -1
idx = -1
for i in range(25, -1, -1):
	if A[i] > mx:
		mx = A[i]
		idx = i
s += chr(ord('a') + idx) * k
ans = 0
for i in range(len(s)):
	ans += (i + 1) * A[ord(s[i]) - ord('a')]
print(ans)
endtime = time.time()


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


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 = list(input())
n = int(input())
l = list(map(int, input().split()))
m = max(l)
d = {}
ans = 0
for i in range(26):
	d[chr(97 + i)] = l[i]
c = 1
for i in range(len(s)):
	ans += c * d[s[i]]
	c += 1
for i in range(n):
	ans += c * m
	c += 1
print(ans)


import sys
from collections import defaultdict
from heapq import nlargest
Input = lambda : map(int, input().split())
s = input()
t = len(s)
k = int(input())
SUM = 0
w = list(Input())
for i in range(1, t + 1):
	SUM += i * w[ord(s[i - 1]) - 97]
a = max(w)
for i in range(t + 1, t + k + 1):
	SUM += i * a
print(SUM)


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))


s = str(input())
k = int(input())
L = list(map(int, input().split()))
r = 0
for i in range(len(s)):
	r += L['abcdefghijklmnopqrstuvwxyz'.index(s[i])] * (i + 1)
for i in range(k):
	r += (len(s) + 1 + i) * max(L)
print(r)


def dzy(s, k, lst):
	(m, result) = (max(lst), 0)
	for i in range(1, len(s) + 1):
		result += lst[ord(s[i - 1]) - ord('a')] * i
	for i in range(len(s) + 1, len(s) + 1 + k):
		result += m * i
	return result
t = input()
K = int(input())
a = [int(j) for j in input().split()]
print(dzy(t, K, a))


x = input()
n = int(input())
m = list(map(int, input().split()))[:26]
s = 1
a = 0
for i in x:
	d = ord(i) - 97
	f = m[d] * s
	s = s + 1
	a = a + f
q = max(m)
while s <= len(x) + n:
	a = a + q * s
	s = s + 1
print(a)


s = list(input())
i = int(input())
values = list(input().split())
mx = values[0]
num = 0
for j in values:
	if int(j) > int(mx):
		mx = j
for j in range(len(s)):
	num += int(values[int(ord(s[j]) - 97)]) * int(j + 1)
for j in range(len(s) + 1, len(s) + i + 1, 1):
	num += j * int(mx)
print(num)


s = list(input())
k = int(input())
n = len(s)
q = list(map(int, input().split()))
arr1 = []
for i in range(n):
	arr1.append(q[ord(s[i]) - 97])
r = max(q)
s = 0
for i in range(k):
	arr1.append(r)
for i in range(len(arr1)):
	s += arr1[i] * (i + 1)
print(s)


s = list(input())
k = int(input())
w = list(map(int, input().split(' ')))
length = len(w) + k
ans = []
for i in s:
	ans.append(w[ord(i) - 97])
while k > 0:
	ans.append(max(w))
	k -= 1
res = 0
for j in range(len(ans)):
	res += (j + 1) * ans[j]
print(res)


t = input()
b = int(input())
d = list(map(int, input().split()))
r = 0
for i in range(len(t)):
	r = r + (i + 1) * d[ord(t[i]) - 97]
print(r + max(d) * (b * len(t) + b * (b + 1) // 2))


s = input()
a = len(s)
n = int(input())
l = list(map(int, input().split()))
c = 0
for x in range(a):
	c += l[ord(s[x]) - 97] * (x + 1)
c += (n * n + n + 2 * a * n) * max(l) // 2
print(c)


def main():
	r = lambda : tuple(map(int, input().split()))
	s = input()
	k = r()[0]
	l = r()
	o = k * (k + 1) // 2 + k * len(s)
	print(sum((l[ord(c) - ord('a')] * (i + 1) for (i, c) in enumerate(s))) + o * max(l))
main()


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


s = input().strip()
k = int(input().strip())
vals = list(map(int, input().strip().split()))
total = 0
for i in range(len(s)):
	val = vals[ord(s[i]) - 97]
	total += (i + 1) * val
i += 2
for j in range(k):
	total += max(vals) * i
	i = i + 1
print(total)


s = input()
k = int(input())
w = [int(el) for el in input().split()]
ans = 0
zp = ord('a')
i = 1
for el in s:
	ans += i * w[ord(el) - zp]
	i += 1
maxw = max(w)
while k:
	ans += i * maxw
	k -= 1
	i += 1
print(ans)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
from math import ceil
s = input()
n = ip()
li = ai()
ans = 0
for i in range(len(s)):
	ans += (i + 1) * li[ord(s[i]) - 97]
x = max(li)
for i in range(len(s) + 1, len(s) + n + 1):
	ans += i * x
op(ans)


s = input()
k = int(input())
w = list(map(int, input().split()))
v = 'abcdefghijklmnopqrstuvwxyz'
c = 0
for i in range(len(s)):
	b = v.find(s[i])
	f = w[b]
	c += (i + 1) * f
for i in range(len(s) + 1, len(s) + k + 1):
	c += i * max(w)
print(c)


k = input()
a = int(input())
l = list(map(int, input().split()))
c = 0
t = 'abcdefghijklmnopqrstuvwxyz'
f = zip(t, l)
f = list(f)
for i in range(len(k)):
	for j in f:
		if k[i] == j[0]:
			c += (i + 1) * j[1]
t = (len(k) + a) * (len(k) + a + 1) // 2 - len(k) * (len(k) + 1) // 2
t *= max(l)
print(c + t)


s = input()
n = int(input())
a = list(map(int, input().split()))
sum1 = 0
i = 1
for c in s:
	sum1 += a[ord(c) - ord('a')] * i
	i += 1
print(int(sum1 + max(a) * (i + i + n - 1) * n / 2))


s = str(input())
n = int(input())
lis = list(map(int, input().split()))
al = list('abcdefghijklmnopqrstuvwxyz')
c = 0
for i in range(len(s)):
	c += (i + 1) * lis[al.index(s[i])]
max_ = max(lis)
for i in range(len(s) + 1, len(s) + n + 1):
	c += i * max_
print(c)


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))


(string, k, alpha) = [input() for x in range(3)]
k = int(k)
alpha = [int(x) for x in alpha.split()]
maximum = max(alpha)

def stringValue(string, k, maximum):
	total = 0
	n = k + len(string)
	kValue = maximum * (n * (n + 1) / 2)
	realKValue = kValue - maximum * (len(string) * (len(string) + 1) / 2)
	total += realKValue
	for i in range(len(string)):
		total += (i + 1) * alpha[ord(string[i]) - 97]
	return int(total)
print(stringValue(string, k, maximum))


x = input()
y = int(input())
p = list(map(int, input().split()))
k = 0
m = max(p)
for i in range(len(x) + y):
	if i < len(x):
		k += (i + 1) * p[ord(x[i]) - 97]
	else:
		k += (i + 1) * m
print(k)


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


(s, k, a) = (input(), int(input()), list(map(int, input().split())))
alpha = 'abcdefghijklmnopqrstuvwxyz'
v = 0
for x in range(len(s)):
	i = alpha.index(s[x])
	j = a[i]
	v += (x + 1) * j
v += max(a) * k * (2 * len(s) + k + 1) // 2
print(v)


s = input()
k = int(input())
value = [-1] + list(map(int, input().split()))

def indexx(alpha):
	return ord(alpha) - 96
maxi = max(value)
res = 0
length = len(s)
for i in range(1, length + 1):
	res += i * value[indexx(s[i - 1])]
res += maxi * k * (2 * length + 1 + k) // 2
print(res)


str = list(input())
N = int(input())
A = list(map(int, input().split()))
total = 0
maxu = max(A)
for i in range(len(str)):
	total += (i + 1) * A[ord(str[i]) - 97]
for j in range(N):
	total += (j + len(str) + 1) * maxu
print(total)


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


s = input()
k = int(input())
ss = input()
cnt = ss.split(' ')
max = -1
for i in range(0, 26):
	if int(cnt[i]) > max:
		max = int(cnt[i])
ans = 0
for i in range(0, len(s)):
	ans = ans + int(cnt[ord(s[i]) - ord('a')]) * (i + 1)
for i in range(len(s) + 1, len(s) + k + 1):
	ans = ans + i * max
print(ans)


s = input()
n = int(input())
m = 0
a = len(s)
l = list(map(int, input().split()))
for i in range(1, a + 1):
	j = ord(s[i - 1]) - 97
	m = m + i * l[j]
f = a + n
f = f * (f + 1) // 2
a = a * (a + 1) // 2
m = m + (f - a) * max(l)
print(m)


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd, log10, atan, tan

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_strs():
	return map(str, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()

def function(n):
	return n * (n + 1) // 2
string = input()
k = int(input())
Arr = get_array()
length = len(string)
ans = 0
z = 1
for i in string:
	ans += Arr[ord(i) - 97] * z
	z += 1
ans += (function(length + k) - function(length)) * max(Arr)
print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	b = [ord(c) - ord('a') for c in S()]
	k = I()
	w = LI()
	a = [w[c] for c in b]
	m = max(w)
	l = len(a)
	r = 0
	for i in range(l + 1):
		t = 0
		for j in range(i):
			t += a[j] * (j + 1)
		for j in range(i, i + k):
			t += m * (j + 1)
		for j in range(i, l):
			t += a[j] * (j + k + 1)
		if r < t:
			r = t
	return r
print(main())


def index_(letter):
	import string
	key = string.ascii_lowercase.index(letter)
	return key
s = input()
k = int(input())
a = []
b = []
sum = 0
a = input().split()
for i in range(26):
	ele = int(a[i])
	b.append(ele)
for i in range(len(s)):
	sum = sum + (i + 1) * b[index_(s[i])]
for i in range(len(s) + 1, len(s) + k + 1):
	sum = sum + i * max(b)
print(sum)


s = input()
a = int(input())
sum = 0
array = []
max = 0
reg = input().split()
for i in range(0, 26):
	array.append(int(reg[i]))
	if int(reg[i]) > max:
		max = array[i]
for j in range(0, len(s)):
	m = ord(s[j]) - 97
	sum += (j + 1) * array[m]
for l in range(len(s) + 1, len(s) + a + 1):
	sum += l * max
print(sum)


(s, k) = (input(), int(input()))
w = [int(x) for x in input().split()]
alph = list('abcdefghijklmnopqrstuvwxyz')
s += alph[w.index(max(w))] * k
out = 0
i = 1
for ch in s:
	out += i * w[alph.index(ch)]
	i += 1
print(out)


s = input()
k = int(input())
w = [int(i) for i in input().split()]
v = 0
i = 0
for (i, c) in enumerate(s):
	v += (i + 1) * w[ord(c) - ord('a')]
w = sorted(w)
for i in range(k):
	v += (len(s) + 1 + i) * w[-1]
print(int(v))


s = input()
l = len(s)
k = int(input())
dict1 = {}
list1 = list(map(int, input().split()))
for i in range(26):
	dict1[chr(97 + i)] = list1[i]
ss = 0
list1.sort(reverse=True)
for i in range(1, l + 1):
	ss += i * dict1[s[i - 1]]
c = l + 1
for i in range(k):
	ss += c * list1[0]
	c += 1
print(ss)


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


ans = 0
st = input()
n1 = len(st)
k = int(input())
n2 = n1 + k
w = [int(x) for x in input().split()]
maxx = 0
i = 1
for x in w:
	if maxx < x:
		maxx = x
for x in st:
	ans = ans + i * w[ord(x) - ord('a')]
	i = i + 1
ans = ans + maxx * (n2 * (n2 + 1) - n1 * (n1 + 1)) / 2
print(int(ans), end='', sep='')


s = list(input())
L = 'abcdefghijklmnopqrstuvwxyz'
k = m = int(input())
num = list(map(int, input().split()))
summ = 0
c = 1
for i in s:
	summ += c * num[L.index(i)]
	c += 1
while k != 0:
	summ += c * max(num)
	k -= 1
	c += 1
print(summ)


st = input()
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(len(st)):
	ans += l[ord(st[i]) - 97] * (i + 1)
ma = max(l)
le = len(st)
for i in range(n):
	ans += ma * (le + i + 1)
print(ans)


def main():
	s = input()
	k = int(input())
	sumt = 0
	li = list(map(int, input().split()))
	maxi = max(li)
	for i in range(1, len(s) + 1):
		asc = ord(s[i - 1])
		sumt = sumt + li[asc - 97] * i
	for i in range(i + 1, i + k + 1):
		sumt = sumt + i * maxi
	print(sumt)
main()


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)


b = input()
c = int(input())
d = [int(i) for i in input().split()]
h = max(d)
t = 0
for i in range(len(b)):
	z = ord(b[i]) - ord('a')
	t += (i + 1) * d[z]
for i in range(len(b), len(b) + c):
	t += h * (i + 1)
print(t)


from string import ascii_lowercase as lower
s = input()
k = int(input())
lis = list(map(int, input().split()))
x = {}
for (i, j) in zip(lower, lis):
	x[i] = j
val = 0
nxt = 1
for i in s:
	val += nxt * x[i]
	nxt += 1
ma = max(x, key=x.get)
res = [x for x in range(len(s) + 1, len(s) + k + 1)]
for i in res:
	val += i * x[ma]
print(val)


s = input()
k = int(input())
a = list(map(int, input().split()))
n = len(s)
y = 0
for i in range(n, n + k):
	y += i + 1
x1 = y * max(a)
x2 = 0
for j in range(n):
	x2 += a[ord(s[j]) - 97] * (j + 1)
print(x1 + x2)


string = input()
k = int(input())
l = list(map(int, input().split()))
sum = 0
i = 0
while i < len(string):
	temp = ord(string[i]) - ord('a')
	sum += l[temp] * (i + 1)
	i = i + 1
i = i + 1
while i <= len(string) + k:
	sum += max(l) * i
	i = i + 1
print(sum)


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


def main():
	s = input()
	le = len(s)
	k = int(input())
	ww = tuple(map(int, input().split()))
	print(sum((i * ww[ord(c) - 97] for (i, c) in zip(range(1, le + 1), s))) + (2 * le + 1 + k) * k // 2 * max(ww))
main()


from sys import stdin, stdout

def init_sum(string, w):
	result = 0
	for (i, c) in enumerate(string):
		result += (i + 1) * w[c]
	return result

def solve(string, k, w):
	result = init_sum(string, w)
	maxi = max(w.values())
	for i in range(len(string) + 1, len(string) + 1 + k):
		result += i * maxi
	return result
s = str(stdin.readline().rstrip())
k = int(stdin.readline().rstrip())
w = list(map(int, stdin.readline().rstrip().split()))
import string
from collections import OrderedDict
d = OrderedDict.fromkeys(string.ascii_lowercase, 0)
i = 0
for key in d.keys():
	d[key] = w[i]
	i += 1
assert i == 26
stdout.write(str(solve(s, k, d)))


def main():
	s = input()
	k = int(input())
	val = list(map(int, input().split()))
	maxVal = max(val)
	stringVal = 0
	for (index, i) in enumerate(s):
		stringVal += (index + 1) * val[ord(i) - ord('a')]
	print(stringVal + (k * len(s) + k * (k + 1) // 2) * maxVal)
main()


s = input()
k = int(input())
vals = list(map(lambda x: int(x), input().split()))
val = 0
n = len(s)
for i in range(n):
	val += vals[ord(s[i]) - 97] * (i + 1)
for j in range(n + 1, n + k + 1):
	val += max(vals) * j
print(val)


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


import string

def stupid_strings(s, n, w):
	l = len(s)
	ans = 0
	for (i, v) in enumerate(s):
		ans += (i + 1) * w[string.ascii_lowercase.index(v)]
	for i in range(n):
		ans += max(w) * (l + i + 1)
	return ans
s = str(input())
n = int(input())
w = list(map(int, input().split()))
print(stupid_strings(s, n, w))


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


s = input()
k = int(input())
l = [int(x) for x in input().split()]
ans = (len(s) + 1 + len(s) + k) * k // 2 * max(l)
for i in range(len(s)):
	ans += l[ord(s[i]) - ord('a')] * (i + 1)
print(ans)


from collections import defaultdict
s = 'abcdefghijklmnopqrstuvwxyz'
s1 = input()
n = int(input())
l = list(map(int, input().split()))
d = defaultdict(int)
for i in range(len(s)):
	d[s[i]] = l[i]
count = 1
ts = 0
for i in range(len(s1)):
	ts += d[s1[i]] * count
	count += 1
count -= 1
k1 = max(d.values())
fs = count * (count + 1) // 2
k2 = count + n
k2 = k2 * (k2 + 1) // 2
k2 = k2 - fs
ts += k2 * k1
print(ts)


import sys, string
s = input().strip()
k = int(input())
a = list(map(int, sys.stdin.readline().split()))
ma = max(a)
ls = len(s)
ans = ma * sum(range(ls + 1, ls + k + 1))
d = {i: j for (i, j) in zip(string.ascii_lowercase, a)}
ans += sum([(i + 1) * d[j] for (i, j) in enumerate(s)])
print(ans)