Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.

In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly a_{i} calories on touching the i-th strip.

You've got a string s, describing the process of the game and numbers a_1, a_2, a_3, a_4. Calculate how many calories Jury needs to destroy all the squares?


-----Input-----

The first line contains four space-separated integers a_1, a_2, a_3, a_4 (0 ≤ a_1, a_2, a_3, a_4 ≤ 10^4).

The second line contains string s (1 ≤ |s| ≤ 10^5), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.


-----Output-----

Print a single integer — the total number of calories that Jury wastes.


-----Examples-----
Input
1 2 3 4
123214

Output
13

Input
1 5 3 2
11221

Output
13

Difficulty: EASY

Solutions:
a = list(map(int, input().split()))
s = input()
waste = 0
for i in s:
	waste += a[int(i) - 1]
print(waste)


value = list(map(int, input().split()))
print(sum((value[int(i) - 1] for i in input())))


l = list(map(int, input().split()))
s = input()
ans = 0
for f in range(len(s)):
	ans += l[int(s[f]) - 1]
print(ans)


lst = list(map(int, input().split()))
s = input()
ans = s.count('1') * lst[0] + s.count('2') * lst[1] + s.count('3') * lst[2] + s.count('4') * lst[3]
print(ans)


arr = list(map(int, input().split()))
st = input()
s = 0
for char in st:
	s += arr[ord(char) - ord('0') - 1]
print(s)


a = list(map(int, input().split()))
s = input()
sum = 0
for i in range(1, 5):
	sum += s.count(str(i)) * a[i - 1]
print(sum)


a = [eval(s) for s in input().split()]
s = input()
print(sum([a[int(i) - 1] for i in s]))


(a1, a2, a3, a4) = map(int, input().split())
n = input()
num = [int(x) for x in str(n)]
s = 0
for i in num:
	if i == 1:
		s += a1
	elif i == 2:
		s += a2
	elif i == 3:
		s += a3
	elif i == 4:
		s += a4
print(s)


a = [int(x) for x in input().split()]
s = [int(x) for x in input()]
cal = 0
for i in s:
	cal = cal + a[i - 1]
print(cal)


(a, b, c, d) = [int(x) for x in input().split()]
k = input()
(p, q, r, s) = (0, 0, 0, 0)
for i in k:
	if i == '1':
		p += 1
	elif i == '2':
		q += 1
	elif i == '3':
		r += 1
	elif i == '4':
		s += 1
print(a * p + b * q + c * r + d * s)


l = [int(i) for i in input().split()]
s = input()
count = 0
for i in s:
	count += l[int(i) - 1]
print(count)


c = list(map(int, input().split()))
ss = list(map(int, list(input())))
ans = 0
for x in ss:
	ans += c[x - 1]
print(ans)


sum1 = 0
list1 = list(map(int, input().split()))
s = input()
for i in s:
	if i == str(1):
		sum1 += list1[0]
	if i == str(2):
		sum1 += list1[1]
	if i == str(3):
		sum1 += list1[2]
	if i == str(4):
		sum1 += list1[3]
print(sum1)


n = list(map(int, input().split()))
a = input()
s = 0
for i in a:
	if i == '1':
		s = s + n[0]
	elif i == '2':
		s = s + n[1]
	elif i == '3':
		s = s + n[2]
	elif i == '4':
		s = s + n[3]
print(s)


l = list(map(int, input().split()))
try:
	while True:
		x = input()
		if len(x) > 0:
			continue
		else:
			break
except EOFError:
	pass
summ = 0
for i in x:
	i = int(i)
	summ += l[i - 1]
print(summ)


a = [int(x) for x in input().split()]
print(sum((a[x - 1] for x in (int(y) for y in list(input())))))


z = 0
l = list(map(int, input().split()))
s = input()
for x in range(len(s)):
	z += l[int(s[x]) - 1]
print(z)


(one, two, three, four) = map(int, input().split())
ans = 0
s = input()
for i in s:
	if i == '1':
		ans += one
	elif i == '2':
		ans += two
	elif i == '3':
		ans += three
	elif i == '4':
		ans += four
print(ans)


l = list(map(int, input().split()))
s = input().strip()
print(s.count('1') * l[0] + s.count('2') * l[1] + s.count('3') * l[2] + s.count('4') * l[3])


from sys import stdin as cin
from math import factorial as f
a = list(map(int, cin.readline().split()))
b = input()
count = 0
for x in b:
	count += a[int(x) - 1]
print(count)


a = [0] + list(map(int, input().split()))
print(sum([a[int(i)] for i in input()]))


a = list(map(int, input().split()))
calories = 0
s = input()
for i in range(len(s)):
	calories = calories + a[int(s[i]) - 1]
print(calories)


(a, b, c, d) = map(int, input().split())
q = 0
n = int(input())
p = list(map(int, str(n)))
for i in p:
	if i == 1:
		q += a
	elif i == 2:
		q += b
	elif i == 3:
		q += c
	elif i == 4:
		q += d
print(q)


n = list(map(int, input().split()))
s = input()
count = 0
for i in s:
	count += n[int(i) - 1]
print(count)


import pdb
(a, b, c, d) = map(int, input().split())
y = 0
x = input()
for i in x:
	if i == '1':
		y += a
	elif i == '2':
		y += b
	elif i == '3':
		y += c
	elif i == '4':
		y += d
print(y)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
BUFSIZE = 8192
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 main():
	(a1, a2, a3, a4) = map(int, input().split())
	s = input()
	(b1, b2, b3, b4) = ('1', '2', '3', '4')
	b = 0
	for i in s:
		if i == b1:
			b += a1
		elif i == b2:
			b += a2
		elif i == b3:
			b += a3
		else:
			b += a4
	print(b)
main()


calories = [int(x) for x in input().split(' ')]
answer = sum((calories[int(d) - 1] for d in input()))
print(answer)


def main():
	(a1, a2, a3, a4) = list(map(int, input().split()))
	res = 0
	for s in input():
		if s == '1':
			res += a1
		if s == '2':
			res += a2
		if s == '3':
			res += a3
		if s == '4':
			res += a4
	print(res)

def __starting_point():
	main()
__starting_point()


(x, s) = ([int(i) for i in input().split()], [int(j) for j in input()])
d = {}
for i in range(4):
	d[i + 1] = x[i]
val = 0
for i in s:
	val += d[i]
print(val)


a = list(map(int, input().split()))
s = input()
d = 0
for j in s:
	d += int(a[int(j) - 1])
print(d)


c = list(map(int, input().split()))
s = input()
cal = 0
for i in s:
	cal += c[int(i) - 1]
print(cal)


refer = str(input()).split()
refer = [int(it) for it in refer]
line = str(input())
value = 0
for it in line:
	value += refer[int(it) - 1]
print(value)


x = [int(x) for x in input().split()]
cal = 0
s = input()
for c in s:
	c = int(c)
	num = x[c - 1]
	cal += num
print(cal)


kall_int = input()
kall_str = kall_int.split()
polos = input()
temp = 0
for i in polos:
	if i == '1':
		temp += int(kall_str[0])
	if i == '2':
		temp += int(kall_str[1])
	if i == '3':
		temp += int(kall_str[2])
	if i == '4':
		temp += int(kall_str[3])
print(temp)


(a1, a2, a3, a4) = input().split()
(a1, a2, a3, a4) = (int(a1), int(a2), int(a3), int(a4))
s = input()
total = 0
for i in range(len(s)):
	if int(s[i]) == 1:
		total += a1
	elif int(s[i]) == 2:
		total += a2
	elif int(s[i]) == 3:
		total += a3
	else:
		total += a4
print(total)


lst = list(map(int, input().split()))
m = 0
s = input()
for i in s:
	if i == '1':
		m += lst[0]
	elif i == '2':
		m += lst[1]
	elif i == '3':
		m += lst[2]
	else:
		m += lst[3]
print(m)


import array
Array = list(map(int, input().split(' ')))
s = input()
energy = 0
for i in s:
	for j in range(4):
		if int(i) == j + 1:
			energy += Array[j]
print(energy)


a = list(map(int, input().split()))
s = list(map(lambda c: a[int(c) - 1], input()))
print(sum(list(map(int, s))))


(a1, a2, a3, a4) = map(int, input().split())
s = input()
result = 0
for i in range(len(s)):
	if s[i] == '1':
		result += a1
	if s[i] == '2':
		result += a2
	if s[i] == '3':
		result += a3
	if s[i] == '4':
		result += a4
print(result)


A = [int(x) for x in input().split()]
s = list(input())
s = [int(x) - 1 for x in s]
q = [A[i] for i in s]
print(sum(q))


n = list(map(int, input().split()))
s = input()
result = s.count('1') * n[0] + s.count('2') * n[1] + s.count('3') * n[2] + s.count('4') * n[3]
print(result)


l = list(map(int, input().rstrip().split()))
s = input()
(count1, count2, count3, count4) = (s.count('1'), s.count('2'), s.count('3'), s.count('4'))
print(l[0] * count1 + l[1] * count2 + l[2] * count3 + l[3] * count4)


temp = list(map(int, input().rstrip().split()))
a = temp[0]
b = temp[1]
c = temp[2]
d = temp[3]
summ = 0
r = input()
n = len(r)
for rem in r:
	if rem == '1':
		summ += a
	elif rem == '2':
		summ += b
	elif rem == '3':
		summ += c
	else:
		summ += d
print(summ)


l = list(map(int, input().split()))
arr = list(input())
ans = 0
for i in arr:
	ans += l[int(i) - 1]
print(ans)


import sys
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	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
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	a = ain()
	b = sin()
	b = list(b)
	count = 0
	for i in range(len(b)):
		if b[i] == '1':
			count += a[0]
		elif b[i] == '2':
			count += a[1]
		elif b[i] == '3':
			count += a[2]
		elif b[i] == '4':
			count += a[3]
	print(count)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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()


arr = [int(x) for x in input().split()]
s = str(input().strip())
cal = 0
for c in s:
	cal += arr[ord(c) - ord('0') - 1]
print(cal)


a = [int(i) for i in input('').split()]
s = str(input(''))
out = 0
for i in s:
	out += a[int(i) - 1]
print(out)


s1 = input().split()
res = 0
for i in range(4):
	s1[i] = int(s1[i])
s2 = input()
for i in s2:
	res += s1[int(i) - 1]
print(res)


a = input().split()
b = input()
d = {'1': int(a[0]), '2': int(a[1]), '3': int(a[2]), '4': int(a[3])}
s = 0
for i in range(len(b)):
	s = s + d[b[i]]
print(s)


(a1, a2, a3, a4) = map(int, input().split())
dict1 = {'1': a1, '2': a2, '3': a3, '4': a4}
s = input()
count = 0
for i in s:
	count += dict1[i]
print(count)


(a, b, c, d) = list(map(str, input().split()))
s = input()
print(int(s.count('1')) * int(a) + int(s.count('2')) * int(b) + int(s.count('3')) * int(c) + int(s.count('4')) * int(d))


(a, b, c, d) = map(int, input().split())
list1 = list(map(int, list(input())))
count = 0
for i in range(len(list1)):
	if list1[i] == 1:
		count += a
	if list1[i] == 2:
		count += b
	if list1[i] == 3:
		count += c
	if list1[i] == 4:
		count += d
print(count)


m = list(map(int, input().split()))
d = {}
for i in range(len(m)):
	d[i + 1] = m[i]
s = input()
cnt = 0
for i in s:
	cnt += d[int(i)]
print(cnt)


a = list(map(int, input().split()))
print(sum(map(lambda x: a[int(x) - 1], input())))


def main():
	a = input().split(' ')
	s = str(input())
	sub = []
	sum = 0
	dict = {'1': a[0], '2': a[1], '3': a[2], '4': a[3]}
	for x in s:
		sub.append(x)
		sum += int(dict[x])
	print(sum)
main()


a = list(map(int, input().split()))
b = input()
result = 0
for i in range(len(b)):
	if b[i] == '1':
		result = result + a[0]
	elif b[i] == '2':
		result = result + a[1]
	elif b[i] == '3':
		result = result + a[2]
	elif b[i] == '4':
		result = result + a[3]
print(result)


arr = list(map(int, input().split()))
s = input()
count = 0
for i in range(len(s)):
	if s[i] == '1':
		count += arr[0]
	elif s[i] == '2':
		count += arr[1]
	elif s[i] == '3':
		count += arr[2]
	else:
		count += arr[3]
print(count)


a = list(map(int, input().split()))
n = input()
n = list(n)
c = int(0)
for i in range(len(n)):
	c += a[int(n[i]) - 1]
print(c)


list1 = list(map(int, input().split(' ')))
s = input()
sum1 = 0
for i in s:
	sum1 += list1[int(i) - 1]
print(sum1)


calories = list(map(int, input().split()))
data = [int(c) - 1 for c in input()]
wastes = {}
for c in data:
	wastes[c] = wastes.get(c, 0) + 1
answer = sum((calories[i] * wastes.get(i, 0) for i in range(4)))
print(answer)


(a1, a2, a3, a4) = map(int, input().split())
s = input()
n1 = s.count('1')
n2 = s.count('2')
n3 = s.count('3')
n4 = s.count('4')
print(n1 * a1 + n2 * a2 + n3 * a3 + n4 * a4)


n = list(map(int, input().split()))
s = input()
kalorier = 0
for element in s:
	kalorier += n[int(element) - 1]
print(kalorier)


a = list(map(int, input().split()))
s = input()
amounts = []
for i in range(1, 5):
	amounts.append(s.count(str(i)))
print(a[0] * amounts[0] + a[1] * amounts[1] + a[2] * amounts[2] + a[3] * amounts[3])


cal = list(map(int, input().split()))
str1 = input()
sum = 0
for i in range(len(str1)):
	sum = sum + cal[int(str1[i]) - 1]
print(sum)


inp = list(map(int, input().split()))
inp2 = list(map(int, input()))
dict = {1: inp[0], 2: inp[1], 3: inp[2], 4: inp[3]}
num = int()
for x in inp2:
	num = num + dict[x]
print(num)


N = input().split()
N1 = input()
total = 0
(N[0], N[1], N[2], N[3]) = (int(N[0]), int(N[1]), int(N[2]), int(N[3]))
for i in N1:
	total += N[int(i) - 1]
print(total)


cal = list(map(int, input().strip().split()))
pro = list(map(int, input()))
s = 0
for i in range(0, len(pro)):
	s += cal[pro[i] - 1]
print(s)


l1 = input()
l1 = [int(x) for x in l1.split()]
l2 = list(input())
result = 0
for i in range(len(l2)):
	result += l1[int(l2[i]) - 1]
print(result)


def BlackSquare():
	calories = [*map(int, input().strip().split())]
	moves = [*map(int, list(input().strip()))]
	ttl = 0
	for i in moves:
		ttl += calories[i - 1]
	return ttl
a = BlackSquare()
print(a)


(a, b, c, d) = map(int, input().split())
s = input()
l = list(s)
sum = 0
for i in l:
	if i == '1':
		sum += a
	if i == '2':
		sum += b
	if i == '3':
		sum += c
	if i == '4':
		sum += d
print(sum)


arr = list(map(int, input().split()))
st = list(map(int, list(input())))
sum = 0
i = 0
while i < len(st):
	sum += arr[st[i] - 1]
	i += 1
print(sum)


A = list(map(int, input().split()))
print(sum(map(lambda x: A[int(x) - 1], list(input()))))


calory = list(map(int, input().split()))
game = input()
spent = 0
for i in game:
	spent += calory[int(i) - 1]
print(spent)


from sys import stdin, stdout
input = stdin.readline
a = list(map(int, input().split()))
s = input()[:-1]
ans = 0
for i in s:
	ans += a[int(i) - 1]
stdout.write(str(ans))


l = list(map(int, input().split()))
s = input()
c = 0
for i in s:
	if i == '1':
		c += l[0]
	elif i == '2':
		c += l[1]
	elif i == '3':
		c += l[2]
	elif i == '4':
		c += l[3]
print(c)


li = list(map(int, input().split()))
s = input()
total = 0
for i in s:
	total += li[int(i) - 1]
print(total)


calories = list(map(int, input().split()))
touches = list(map(int, list(input())))
print(sum(map(lambda x: calories[x - 1], touches)))


kalorii = list(map(int, input().split(' ')))
vertikal_line = list(map(int, input()))
print(vertikal_line.count(1) * kalorii[0] + vertikal_line.count(2) * kalorii[1] + vertikal_line.count(3) * kalorii[2] + vertikal_line.count(4) * kalorii[3])


import sys
input = sys.stdin.readline
c = [0] + list(map(int, input().split()))
s = list(input().strip())
tot = 0
for x in s:
	tot += c[int(x)]
print(tot)


a = [int(x) for x in input().split()]
ans = 0
for c in input():
	ans += a[int(c) - 1]
print(ans)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
A = [0] + [int(x) for x in input().split()]
S = input()
ans = sum([A[int(i)] for i in list(S)])
print(ans)


a = input().split()
str = str(input())
sum = 0
for i in range(len(str)):
	if int(str[i]) == 1:
		sum += int(a[0])
	elif int(str[i]) == 2:
		sum += int(a[1])
	elif int(str[i]) == 3:
		sum += int(a[2])
	elif int(str[i]) == 4:
		sum += int(a[3])
print(sum)


(a1, a2, a3, a4) = input().split()
a1 = int(a1)
a2 = int(a2)
a3 = int(a3)
a4 = int(a4)
strips = input()
cal = 0
for i in strips:
	if i == '1':
		cal += a1
	if i == '2':
		cal += a2
	if i == '3':
		cal += a3
	if i == '4':
		cal += a4
print(cal)


arr = list(map(int, input().split()))
st = input()
answer = 0
for i in st:
	answer += arr[int(i) - 1]
print(answer)


from collections import Counter as c
from sys import stdin
calories = list(map(int, input().split()))
inp = c(stdin.readline().strip('\n'))
tot = 0
for i in inp:
	tot += inp[i] * calories[int(i) - 1]
print(tot)


(r1, r2, r3, r4) = list(map(int, input().split()))
f = input()
cal = 0
for i in f:
	if int(i) == 1:
		cal += r1
	elif int(i) == 2:
		cal += r2
	elif int(i) == 3:
		cal += r3
	elif int(i) == 4:
		cal += r4
print(cal)


import sys
a = list(map(int, sys.stdin.readline().split()))
s = input()
r = 0
for i in range(len(s)):
	r += a[int(s[i]) - 1]
print(r)


cal = list(map(int, input().split()))
pos = input()
pos = list(pos)
total = 0
for i in range(len(pos)):
	total += cal[int(pos[i]) - 1]
print(total)


s = list(map(int, input().split()))
s = {str(i): s[i] for i in range(4)}
x = list(input())
sm = 0
for i in x:
	sm += s[str(int(i) - 1)]
print(sm)


a = [0, *map(int, input().split())]
print(sum((a[int(x)] for x in input())))


T = list(map(int, input().split()))
S = input()
K = S.count('1') * T[0] + S.count('2') * T[1] + S.count('3') * T[2] + S.count('4') * T[3]
print(K)


entrada = str(input())
entrada = entrada.split()
s = str(input())
suma = 0
for second in s:
	suma += int(entrada[int(second) - 1])
print(suma)


a = list(map(str, input().split(' ')))
s = input()
c = 0
for i in range(len(s)):
	for j in range(4):
		if int(s[i]) == j + 1:
			c = c + int(a[j])
print(c)


(a, b, c, d) = list(map(int, input().split()))
strips = input()
s = 0
for x in strips:
	if x == '1':
		s += a
	elif x == '2':
		s += b
	elif x == '3':
		s += c
	elif x == '4':
		s += d
print(s)


a = list(map(int, input().split()))
t = input()
u = 0
for i in t:
	u += a[int(i) - 1]
print(u)


score = list(map(int, input().split()))
score = [0] + score
lst = list(map(int, list(input())))
total = 0
for e in lst:
	total += score[e]
print(total)


import sys
cal = list(map(int, sys.stdin.readline().split()))
s = input()
s = [int(x) for x in s]
ans = 0
for x in s:
	ans += cal[x - 1]
print(ans)


__author__ = 'Lipen'

def main():
	a = list(map(int, input().split()))
	s = input()
	ans = 0
	for c in s:
		ans += a[int(c) - 1]
	print(ans)
main()


kal = list(map(int, input().split()))
game = input()
result = 0
for i in game:
	result += kal[int(i) - 1]
print(result)


l = [int(x) for x in input().split()]
s = input()
sum = 0
for i in s:
	sum += l[int(i) - 1]
print(sum)


ip = list(map(int, input().split(' ')))
s = input()
cal = 0
for i in range(len(s)):
	if s[i] == '1':
		cal = cal + ip[0]
	elif s[i] == '2':
		cal = cal + ip[1]
	elif s[i] == '3':
		cal = cal + ip[2]
	elif s[i] == '4':
		cal = cal + ip[3]
print(cal)


a_numbers = list(map(int, input().split()))
s = input()
result = 0
for num in s:
	number = int(num)
	result += a_numbers[number - 1]
print(result)


c = list(map(int, input().split(' ')))
step = list(map(int, list(input())))
result = sum(list(map(lambda x: c[x - 1], step)))
print(result)


(a, r, s) = (0, input(), input())
for (j, i) in enumerate(map(int, r.split())):
	a += i * s.count(str(1 + j))
print(a)


l1 = [int(x) for x in input().split()]
l2 = input()
r = 0
for i in range(len(l2)):
	if l2[i] == '1':
		r += l1[0]
	if l2[i] == '2':
		r += l1[1]
	if l2[i] == '3':
		r += l1[2]
	if l2[i] == '4':
		r += l1[3]
print(r)


k = list(map(int, input().split()))
s = input()
print(sum([k[int(x) - 1] for x in s]))


l = list(map(int, input().split()))
s = input()
Sum = 0
for i in range(len(s)):
	Sum += l[int(s[i]) - 1]
print(Sum)


a = [int(x) for x in input().split()]
c = 0
s = input()
for i in s:
	t = int(i)
	c = c + a[t - 1]
print(c)


a = list(map(int, input().split()))
e = list(input())
d = 0
for i in e:
	d += a[int(i) - 1]
print(d)


cal = list(map(int, input().split()))
w = input()
res = 0
for x in range(len(w)):
	if w[x] == '1':
		res = res + cal[0]
	if w[x] == '2':
		res = res + cal[1]
	if w[x] == '3':
		res = res + cal[2]
	if w[x] == '4':
		res = res + cal[3]
print(res)


a = [int(x) for x in input().split()]
n = input()
count = 0
for elem in n:
	k = int(elem)
	count += a[k - 1]
print(count)


calories = list(map(int, input().split()))
game = input()
ans = game.count('1') * calories[0] + game.count('2') * calories[1] + game.count('3') * calories[2] + game.count('4') * calories[3]
print(ans)


a = list(map(int, input().split()))
s = input()
print(s.count('1') * a[0] + s.count('2') * a[1] + s.count('3') * a[2] + s.count('4') * a[3])


a = list(map(int, input().split()))
s = input()
stages = list(map(int, s))
cal = 0
for stage in stages:
	cal += a[stage - 1]
print(cal)


a = list(map(int, input().split()))
s = list(input())
c = 0
for i in range(len(s)):
	t = int(s[i])
	if t == 1:
		c += a[0]
	elif t == 2:
		c += a[1]
	elif t == 3:
		c += a[2]
	else:
		c += a[3]
print(c)


def parse(string):
	return list(map(int, string.split(' ')))
calories = parse(input())
sequence = input()
total = sum([calories[int(i) - 1] for i in sequence])
print(total)


(a, b, c, d) = map(lambda x: int(x), input().split())
w = 0
num = str(input())
list = []
for i in num:
	list.append(int(i))
for i in list:
	if i == 1:
		w += a
	elif i == 2:
		w += b
	elif i == 3:
		w += c
	elif i == 4:
		w += d
print(w)


n = list(map(int, input().split()))
r = 0
str = input()
for i in str:
	if int(i) <= 4:
		r += n[int(i) - 1]
	else:
		continue
print(r)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	A = Scanner.map_int()
	S = Scanner.string()
	ans = 0
	for s in S:
		ans += A[int(s) - 1]
	print(ans)
main()


a_j = [int(x) for x in input().split()]
s = input()
sum = 0
for i in range(len(s)):
	sum = sum + a_j[int(s[i]) - 1]
print(sum)


a = {}
i = 1
for _a in input().split():
	a[str(i)] = int(_a)
	i += 1
_sum = 0
for ch in input():
	_sum += a[ch]
print(_sum)


(a1, a2, a3, a4) = map(int, input().split())
st = input()
ans = st.count('1') * a1
ans += st.count('2') * a2
ans += st.count('3') * a3
ans += st.count('4') * a4
print(ans)


n = list(map(int, input().split()))
p = list(map(int, input()))
count = 0
for i in range(len(p)):
	if p[i] == 1:
		count += n[0]
	elif p[i] == 2:
		count += n[1]
	elif p[i] == 3:
		count += n[2]
	elif p[i] == 4:
		count += n[3]
print(count)


s = input().split()
t = input()
z = len(t)
ans = 0
for i in range(z):
	x = int(t[i])
	y = int(s[x - 1])
	ans += y
print(ans)


(a1, a2, a3, a4) = map(int, input().split())
a = list(map(int, input()))
sum = 0
for i in range(len(a)):
	if a[i] == 1:
		sum += a1
	elif a[i] == 2:
		sum += a2
	elif a[i] == 3:
		sum += a3
	else:
		sum += a4
print(sum)


(a, b, c, d) = input().split()
listcal = {'1': int(a), '2': int(b), '3': int(c), '4': int(d)}
stringcal = str(input())
totalcal = 0
for i in stringcal:
	totalcal = totalcal + listcal[i]
print(totalcal)


x = [int(i) for i in input().split()]
y = input()
ans = 0
for i in y:
	ans += x[int(i) - 1]
print(ans)


inp = input().split()
s1 = input()
arr = []
for i in range(len(inp)):
	arr.append(int(inp[i]))
total = 0
for i in range(len(s1)):
	num = int(s1[i])
	total = total + arr[num - 1]
print(total)


x = [int(v) for v in input().split()]
car = 0
str1 = input().strip('\n\r')
for i in range(len(str1)):
	car += x[int(str1[i]) - 1]
print(car)


table = [int(i) for i in input().split()]
print(sum((table[int(i) - 1] for i in input())))


cal = list(map(int, input().split()))
seq = [int(i) for i in input()]
sol = 0
for ele in seq:
	sol = sol + cal[ele - 1]
print(sol)


(a, b, c, d) = map(int, input().split())
l = [1, a, b, c, d]
s = input()
ans = 0
for i in s:
	ans += l[int(i)]
print(ans)


energy = tuple(map(int, input().split()))
s = list(input())
sum_a = 0
for i in range(len(s)):
	sum_a += energy[int(s[i]) - 1]
print(sum_a)


n = 0
a = [int(i) for i in input().split(' ')]
s = str(input())
n = s.count('1') * a[0] + s.count('2') * a[1] + s.count('3') * a[2] + s.count('4') * a[3]
print(n)


(a, b, c, d) = map(int, input().split())
s = input()
op = 0
for i in s:
	if i == '1':
		op += a
	elif i == '2':
		op += b
	elif i == '3':
		op += c
	else:
		op += d
print(op)


s = input('')
l = s.split(' ')
l = list(map(int, l))
s1 = input('')
l2 = list(s1)
l2 = list(map(int, l2))
sum1 = 0
for i in l2:
	sum1 += l[i - 1]
print(sum1)


def black(values, string):
	total = 0
	for i in range(len(string)):
		if string[i] == '1':
			total = total + values[0]
		elif string[i] == '2':
			total = total + values[1]
		elif string[i] == '3':
			total = total + values[2]
		else:
			total = total + values[3]
	return total
values = list(map(int, input().split()))
string = input()
print(black(values, string))


(a1, a2, a3, a4) = input().split()
sum = 0
string = input()
for char in string:
	if char == '1':
		sum += int(a1)
	elif char == '2':
		sum += int(a2)
	elif char == '3':
		sum += int(a3)
	elif char == '4':
		sum += int(a4)
print(sum)


import collections
a = tuple(map(int, str.split(input())))
ns = collections.Counter(map(int, str.strip(input())))
print(sum(map(lambda i: a[i - 1] * ns[i], ns)))


cal_strip = [int(x) for x in input().split()]
strips = input()
calories = 0
for i in strips:
	calories += cal_strip[int(i) - 1]
print(calories)


(a, b, c, d) = map(int, input().split())
s = input()
sum1 = 0
for i in range(len(s)):
	if s[i] == '1':
		sum1 += a
	if s[i] == '2':
		sum1 += b
	if s[i] == '3':
		sum1 += c
	if s[i] == '4':
		sum1 += d
print(sum1)


ai = list(map(int, input().split()))
s = input()
ans = 0
for i in s:
	ans += ai[int(i) - 1]
print(ans)


calories = 0
(a1, a2, a3, a4) = input().split()
a1 = int(a1)
a2 = int(a2)
a3 = int(a3)
a4 = int(a4)
s = input()
for i in s:
	if i == '1':
		calories += a1
	elif i == '2':
		calories += a2
	elif i == '3':
		calories += a3
	else:
		calories += a4
print(calories)


strip = list(map(int, input().split()))
str_appear = input()
output = [strip[int(i) - 1] for i in str_appear]
print(sum(output))


arr = [int(x) for x in input().split()]
s = input()
sum = 0
for i in range(len(s)):
	if s[i] == '1':
		sum += arr[0]
	elif s[i] == '2':
		sum += arr[1]
	elif s[i] == '3':
		sum += arr[2]
	else:
		sum += arr[3]
print(sum)


a = input()
a = a.split(' ')
s = input()
A = s.count('1')
B = s.count('2')
C = s.count('3')
D = s.count('4')
total = int(a[0]) * A + int(a[1]) * B + int(a[2]) * C + int(a[3]) * D
print(total)


cal = input().split()
gameProcess = list(input())
sum = 0
for i in gameProcess:
	sum += int(cal[int(i) - 1])
print(sum)


l = list(map(int, input().split()))
idx = list(map(int, input()))
s = 0
for i in idx:
	s += l[i - 1]
print(s)


n = [int(x) for x in input().split()]
s = str(input())
ans = 0
for i in s:
	a = int(i)
	ans += n[a - 1]
print(ans)


c = [int(x) for x in input().split(' ')]
s = input()
count = 0
for i in s:
	count = count + c[int(i) - 1]
print(count)


n = input().split()
s = input()
c = 0
for i in s:
	c += int(n[int(i) - 1])
print(c)


lst = [int(i) for i in input().split()][:4]
st = input()
count = 0
for i in st:
	count = count + lst[int(i) - 1]
print(count)


(a1, a2, a3, a4) = map(int, input().split())
v = [a1, a2, a3, a4]
s = 0
for i in input():
	k = int(i)
	s += v[k - 1]
print(s)


(a, b, c, d) = map(int, input().split())
e = {1: a, 2: b, 3: c, 4: d}
x = input()
s = 0
for i in x:
	s = s + e[int(i)]
print(s)


a = list(map(int, input().split()))
s = str(input())
summa = 0
for i in s:
	summa += a[int(i) - 1]
print(summa)


def countOfTarget(string, target):
	count = 0
	for s in string:
		if int(s) == target:
			count += 1
	return count
result = 0
values = list(map(int, input().split()))
s = input()
for i in range(1, 5):
	result += countOfTarget(s, i) * values[i - 1]
print(result)


calories = input().split(' ')
blacks = input()
c = 0
for i in range(len(blacks)):
	c += int(calories[int(blacks[i]) - 1])
print(c)


x = list(map(int, input().split()))
s = input()
count = 0
for i in range(0, len(s)):
	if s[i] == '1':
		count += x[0]
	elif s[i] == '2':
		count += x[1]
	elif s[i] == '3':
		count += x[2]
	elif s[i] == '4':
		count += x[3]
print(count)


import sys
calories = [int(n) for n in sys.stdin.readline().rstrip('\n').split(' ')]
data = [int(n) for n in list(sys.stdin.readline().rstrip('\n'))]
a = 0
for i in range(len(data)):
	a += calories[data[i] - 1]
print(a)


(x, y, z, w) = map(int, input().split())
s = input()
ss = 0
for i in s:
	if i == '1':
		ss += x
	elif i == '2':
		ss += y
	elif i == '3':
		ss += z
	else:
		ss += w
print(ss)


(a1, a2, a3, a4) = map(int, input().split())
cal = {'1': a1, '2': a2, '3': a3, '4': a4}
pat = input()
cal_req = 0
for i in pat:
	cal_req += cal[i]
print(cal_req)


arcal = list(map(int, input().split()))
s = input()
ccal = []
sumc = 0
for i in s:
	ccal.append(int(i))
for i in range(len(ccal)):
	if ccal[i] == 1:
		sumc = sumc + arcal[0]
	elif ccal[i] == 2:
		sumc = sumc + arcal[1]
	elif ccal[i] == 3:
		sumc = sumc + arcal[2]
	elif ccal[i] == 4:
		sumc = sumc + arcal[3]
print(sumc)


colories = list(map(int, input().split()))
game = input()
col = 0
for i in game:
	col += colories[int(i) - 1]
print(col)


(*l,) = map(int, input().split())
c = 0
for i in input():
	c += l[int(i) - 1]
print(c)


(a, b, c, d) = map(int, input().split())
x = list(input())
a1 = 0
b1 = 0
c1 = 0
d1 = 0
for i in x:
	if i == '1':
		a1 += 1
	elif i == '2':
		b1 += 1
	elif i == '3':
		c1 += 1
	else:
		d1 += 1
print(a1 * a + b1 * b + c1 * c + d1 * d)


sa = input().split(' ')
sa2 = input()
sa3 = [int(x) for x in sa]
total = 0
for char in sa2:
	total += sa3[int(char) - 1]
print(total)


def solved(a, arr):
	count = 0
	for i in arr:
		count += a[int(i) - 1]
	print(count)
a = list(map(int, input().split()))
arr = input()
solved(a, arr)


l = input().split()
ch = input()
s = 0
for i in range(len(ch)):
	s += int(l[int(ch[i]) - 1])
print(s)


count = 0
l = list(map(int, input().split(' ')))
l.insert(0, -1)
count = 0
m = input()
for i in m:
	count += l[int(i)]
print(count)


(a1, a2, a3, a4) = list(map(int, input().split()))
cal = {'1': a1, '2': a2, '3': a3, '4': a4}
ans = 0
for symbol in input():
	ans += cal[symbol]
print(ans)


l = list(map(int, input().split()))
s = list(input())
tcb = 0
for x in s:
	if x == '1':
		tcb += l[0]
	elif x == '2':
		tcb += l[1]
	elif x == '3':
		tcb += l[2]
	else:
		tcb += l[3]
print(tcb)


a = [int(a) for a in input().split()]
str = input()
ans = 0
for s in str:
	for i in range(4):
		if int(s) == i + 1:
			ans += a[i]
			break
print(ans)


calories = input('').split(' ')
moves = input('')
count = 0
for move in moves:
	count += int(calories[int(move) - 1])
print(count)


a = list(map(int, input().split()))
gameplay = input()
answer = 0
for i in range(1, 5):
	answer += gameplay.count(str(i)) * a[i - 1]
print(answer)


a = list(map(int, input().split()))
print(sum([a[int(ch) - 1] for ch in input()]))


n = list(map(int, input().split(' ')))
s = list(str(input()))
d = {}
for i in range(len(n)):
	d[i + 1] = n[i]
su = 0
for x in s:
	su += d[int(x)]
print(su)


a = input().split()
b = input()
print(b.count('1') * int(a[0]) + b.count('2') * int(a[1]) + b.count('3') * int(a[2]) + b.count('4') * int(a[3]))


d = list(map(int, input().split()))
out = 0
for c in input():
	out += d[int(c) - 1]
print(out)


import random
import sys
a = [0] * 5
ans = 0
(a[1], a[2], a[3], a[4]) = map(int, input().split())
s = input()
for i in s:
	ans += a[ord(i) - 48]
print(ans)


(a, b, c, d) = input().split(' ')
steps = input()
cal = 0
for i in steps:
	if i == '1':
		cal += int(a)
	elif i == '2':
		cal += int(b)
	elif i == '3':
		cal += int(c)
	else:
		cal += int(d)
print(cal)


a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
b = input()
c = int()
for i in b:
	if i == '1':
		c += a[0]
	elif i == '2':
		c += a[1]
	elif i == '3':
		c += a[2]
	else:
		c += a[3]
print(c)


data = input().split()
a1 = int(data[0])
a2 = int(data[1])
a3 = int(data[2])
a4 = int(data[3])
s = input()
count = 0
for i in s:
	if i == '1':
		count = count + a1
	elif i == '2':
		count = count + a2
	elif i == '3':
		count = count + a3
	elif i == '4':
		count = count + a4
print(count)


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

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

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

def instr():
	s = input()
	return list(s[:len(s)])

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

def def_value():
	return 0
cal = [0]
cal += inlist()
a = input()
res = 0
for i in a:
	res += cal[int(i)]
print(res)


data = [int(i) for i in input().split()]
total = sum((data[int(i) - 1] for i in input()))
print(total)


l = list(map(int, input().split()))
print(sum((l[int(i) - 1] for i in input())))


(a, b, c, d) = input().split()
sum = 0
e = list(input())
if '1' in e:
	cn = e.count('1')
	sum = sum + cn * int(a)
if '2' in e:
	cn = e.count('2')
	sum = sum + cn * int(b)
if '3' in e:
	cn = e.count('3')
	sum = sum + cn * int(c)
if '4' in e:
	cn = e.count('4')
	sum = sum + cn * int(d)
print(sum)


cal = list(map(int, input().split()))
my_dict = dict()
for i in range(4):
	x = i + 1
	my_dict[str(x)] = cal[i]
screen = input()
ans = 0
for i in screen:
	ans += my_dict[i]
print(ans)


calories = list(map(int, input().split()))
s = 0
for i in input():
	s += calories[int(i) - 1]
print(s)


x = list(map(int, input().split()))
y = 0
for element in input():
	y += x[int(element) - 1]
print(y)


listA = [int(x) for x in input('').split()]
s = input('')
tot = 0
for i in s:
	tot += listA[int(i) - 1]
print(tot)


l = [int(x) for x in input().split()]
s = input()
coN = 0
for x in s:
	coN += l[int(x) - 1]
print(coN)


(st, st1) = (input().split(' '), input())
print(sum([st1.count(str(c)) * int(st[c - 1]) for c in range(1, 5)]))


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


c = list(map(int, input().split()))
sum = 0
s = input().strip()
for i in range(len(s)):
	sum += c[int(s[i]) - 1]
print(sum)


a = list(map(int, input().split()))
s = input()
answer = 0
for item in s:
	answer += a[int(item) - 1]
print(int(answer))


(a1, a2, a3, a4) = map(int, input().split())
a = input()
b = {}
b['1'] = a1
b['2'] = a2
b['3'] = a3
b['4'] = a4
k = 0
for i in range(len(a)):
	k += b[a[i]]
print(k)


a = [int(i) for i in input().split()]
s = input()
ans = 0
for c in s:
	ans += a[int(c) - 1]
print(ans)


l = input().split()
string = input()
total = 0
for s in string:
	total += int(l[int(s) - 1])
print(total)


a = list(map(int, input().split()))
(s, ans) = (input(), 0)
for x in s:
	ans += a[int(x) - 1]
print(ans)


(a1, a2, a3, a4) = list(map(int, input().split()))
s = input()
count = 0
for i in range(len(s)):
	if len(s) > 0:
		if s[i] == '1':
			count = count + a1
		elif s[i] == '2':
			count = count + a2
		elif s[i] == '3':
			count = count + a3
		else:
			count = count + a4
print(count)


(a, b, c, d) = list(map(int, input().split()))
z = input()
p = list(map(int, str(z)))
t = 0
for i in range(len(p)):
	if p[i] == 1:
		t += a
	elif p[i] == 2:
		t += b
	elif p[i] == 3:
		t += c
	elif p[i] == 4:
		t += d
print(t)


cal = input().split()
idx = input()
sum = 0
for i in idx:
	sum += int(cal[int(i) - 1])
print(sum)


(a, b, c, d) = map(int, input().split())
D = {'1': a, '2': b, '3': c, '4': d}
E = 0
for i in list(input()):
	E += D[i]
print(E)


l = list(input().split())

def split(word):
	return [char for char in word]
calorie = 0
s = input()
s = split(s)
for i in range(len(s)):
	if int(s[i]) == 1:
		calorie += int(l[0])
	elif int(s[i]) == 2:
		calorie += int(l[1])
	elif int(s[i]) == 3:
		calorie += int(l[2])
	elif int(s[i]) == 4:
		calorie += int(l[3])
print(calorie)


import os
import sys
from io import BytesIO, IOBase

def solve():
	(a1, a2, a3, a4) = map(int, input().split())
	s = input()
	print(a1 * s.count('1') + a2 * s.count(str(2)) + a3 * s.count(str(3)) + a4 * s.count(str(4)))

def main():
	solve()
	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(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()


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(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
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] == val:
			return ll[mid]
		elif ll[mid] < val:
			ans = ll[mid]
			return binary(mid + 1, r, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def check(n):
	v = 1
	while n != 0:
		if n % 10 == 0 or n % 10 == 1:
			n = n // 10
		else:
			v = 0
			break
	return v
l = list(map(int, input().split(' ')))
s = str(input())
c = 0
for i in range(len(s)):
	c += l[int(s[i:i + 1]) - 1]
print(c)


a = list(map(int, input().split()))
b = list(map(int, input()))
k = []
for i in b:
	if i == 1:
		k.append(a[0])
	if i == 2:
		k.append(a[1])
	if i == 3:
		k.append(a[2])
	if i == 4:
		k.append(a[3])
print(sum(k))


n = input().split(' ')
m = list(input())
a = 0
sum_a = 0
for k in m:
	k = int(k)
	if k == 1:
		a = int(n[0])
	if k == 2:
		a = int(n[1])
	if k == 3:
		a = int(n[2])
	if k == 4:
		a = int(n[3])
	sum_a += a
print(sum_a)


(a1, a2, a3, a4) = map(str, input().split())
l = list(input())
c = 0
for i in range(len(l)):
	if l[i] == '1':
		c += int(a1)
	elif l[i] == '2':
		c += int(a2)
	elif l[i] == '3':
		c += int(a3)
	elif l[i] == '4':
		c += int(a4)
print(c)
c = 0


import sys
(a1, a2, a3, a4) = map(int, sys.stdin.readline().split())
l = input().strip()
d = dict()
d[1] = 0
d[2] = 0
d[3] = 0
d[4] = 0
for i in l:
	d[int(i)] += 1
print(a1 * d[1] + a2 * d[2] + a3 * d[3] + a4 * d[4])


cal = list(map(int, input().split()))
s = input()
wasted = 0
for i in s:
	if i == '1':
		wasted = wasted + cal[0]
	elif i == '2':
		wasted = wasted + cal[1]
	elif i == '3':
		wasted = wasted + cal[2]
	elif i == '4':
		wasted = wasted + cal[3]
print(wasted)


calories = list(map(int, input().split()))
game = input()
ans = 0
for sq in game:
	ans += calories[int(sq) - 1]
print(ans)


(a1, a2, a3, a4) = [int(x) for x in input().split(' ')]
s = input()
c = 0
for i in range(len(s)):
	if s[i] == '1':
		c += a1
	elif s[i] == '2':
		c += a2
	elif s[i] == '3':
		c += a3
	elif s[i] == '4':
		c += a4
print(c)


calories = list(map(int, input().split()))
strips = list(map(int, input()))
print(sum((calories[i - 1] for i in strips)))


cal = 0
(a1, a2, a3, a4) = map(int, input().split())
s = input()
for item in s:
	if item == '1':
		cal += a1
	elif item == '2':
		cal += a2
	elif item == '3':
		cal += a3
	else:
		cal += a4
print(cal)


cal = [int(x) for x in input().split()]
a = input()
c = 0
for i in range(len(a)):
	c += cal[int(a[i]) - 1]
print(c)


def func(n):
	l = input()
	counter = 0
	for i in l:
		counter += n[int(i) - 1]
	print(counter)
n = list(map(int, input().split()))
func(n)


cal_arr = [int(x) for x in input().split(' ')]
count = 0
for var in input():
	count += cal_arr[int(var) - 1]
print(count)


(a1, a2, a3, a4) = map(int, input().split())
s = input()
x = y = z = t = 0
for i in s:
	if i == '1':
		x += 1
	elif i == '2':
		y += 1
	elif i == '3':
		z += 1
	else:
		t += 1
print(x * a1 + y * a2 + z * a3 + t * a4)


e = list(map(int, input().split()))
s = input()
t = 0
for i in range(len(s)):
	t += e[int(s[i]) - 1]
print(t)


s = [int(n) for n in input().split()]
z = [int(n) - 1 for n in input()]
m = 0
for n in z:
	m += s[n]
print(m)


n = input().split()
m = list(map(int, input()))
ans = 0
for (i, k) in enumerate(n):
	ans += m.count(i + 1) * int(k)
print(ans)


cal = list(map(int, input().split()))
strip = input()
summ = 0
for i in strip:
	summ = summ + cal[int(i) - 1]
print(summ)


(a1, a2, a3, a4) = map(int, input().split())
s = input()
print(s.count('1') * a1 + s.count('2') * a2 + s.count('3') * a3 + s.count('4') * a4)


(a, b, c, d) = map(int, input().split())
ans = 0
l = map(int, input())
for i in l:
	if i == 1:
		ans += a
	elif i == 2:
		ans += b
	elif i == 3:
		ans += c
	elif i == 4:
		ans += d
print(ans)


(a, c, d, e) = map(int, input().split())
b = input()
f = list(b)
cal = 0
for i in f:
	if i == '1':
		cal = cal + a
	elif i == '2':
		cal = cal + c
	elif i == '3':
		cal = cal + d
	elif i == '4':
		cal = cal + e
print(cal)


costs = list(map(int, input().split()))
print(sum([costs[ord(c) - ord('1')] for c in input()]))


a = list(map(int, input().split()))
s = list(map(int, list(input())))
result = list(map(lambda num: a[num - 1], s))
print(sum(result))


calories = [0]
calories.extend(map(int, input().split()))
calories_burnt = 0
for strip in input():
	calories_burnt += calories[int(strip)]
print(calories_burnt)


cal = [int(x) for x in input().split()]
total = sum((cal[int(x) - 1] for x in input()))
print(total)


from functools import reduce
a = list(map(int, input().split()))
s = list(map(lambda x: int(x) - 1, input()))
ans = reduce(lambda x, e: x + a[e], s, 0)
print(ans)


arr = list(map(int, input().split()))
string = list(map(int, input()))
count = 0
for i in string:
	count += arr[i - 1]
print(count)


l = list(map(int, input().split()))
S = input()
k = len(S)
kil = 0
for i in range(k):
	kil = kil + l[int(S[i]) - 1]
print(kil)


a = list(map(int, input().split()))
cnt = 0
b = input()
for i in b:
	cnt += a[int(i) - 1]
print(cnt)


kkal = [int(i) for i in input().split()]
s = input()
res = 0
for ch in s:
	res += kkal[int(ch) - 1]
print(res)


a = [int(i) for i in input().split()]
s = input()
idx = []
for i in s:
	idx += [int(i) - 1]
total = 0
for i in idx:
	total += a[i]
print(total)


l = [int(i) for i in input().split()]
n = input()
c1 = n.count('1')
c2 = n.count('2')
c3 = n.count('3')
c4 = n.count('4')
print(c1 * l[0] + c2 * l[1] + c3 * l[2] + c4 * l[3])


calories = list(map(int, input().split()))
calor_list = [0]
for energy in calories:
	calor_list.append(energy)
actions = input()
energy = 0
for line in actions:
	energy += calor_list[int(line)]
print(energy)


n = input()
a = input()
n = n.split()
b = 0
for i in a:
	b = b + int(n[int(i) - 1])
print(b)


def main():
	ls = list(map(int, input().split()))
	temp = [int(i) for i in input()]
	total = 0
	for i in temp:
		total += ls[i - 1]
	print(total)
main()


a = list(map(int, input().split()))
s = input()
ans = 0
for i in range(len(s)):
	if s[i] == '1':
		ans += a[0]
	elif s[i] == '2':
		ans += a[1]
	elif s[i] == '3':
		ans += a[2]
	elif s[i] == '4':
		ans += a[3]
print(ans)


calorie = [int(x) for x in input().split(' ')]
steps = [int(x) for x in input()]
ans = 0
for x in steps:
	ans += calorie[x - 1]
print(ans)


L = list(map(int, input().split()))
S = input()
K = 0
for I in S:
	K += L[int(I) - 1]
print(K)


n = list(map(int, input().split()))
n1 = list(map(int, input().strip()))
count = 0
for i in n1:
	count += n[i - 1]
print(count)


a = list(map(int, input().split()))
print(sum((a[int(i) - 1] for i in input())))


dic = dict()
a = [int(x) for x in input().split()]
for (i, v) in enumerate(a):
	dic[i + 1] = a[i]
s = input()
cnt = 0
for v in s:
	cnt += dic[int(v)]
print(cnt)


(a1, a2, a3, a4) = (int(x) for x in input().split())
ans = 0
s = input()
for x in s:
	if x == '1':
		ans += a1
	elif x == '2':
		ans += a2
	elif x == '3':
		ans += a3
	else:
		ans += a4
print(ans)


l = input().split()
for i in range(4):
	l[i] = int(l[i])
s = input()
s1 = len(s)
m = 0
for i in range(s1):
	m += l[int(s[i]) - 1]
print(m)


(a, b, c, d) = map(int, input().split())
d = {'1': a, '2': b, '3': c, '4': d}
s = input()
r = 0
for c in s:
	r += d[c]
print(r)


(a1, a2, a3, a4) = map(int, input().split())
d = {1: a1, 2: a2, 3: a3, 4: a4}
s = input()
t = 0
for i in s:
	t += d[int(i)]
print(t)


from collections import Counter
cal = {k: v for (k, v) in enumerate(map(int, input().strip().split()), 1)}
tile_count = Counter(map(int, input()))
tot_cal = 0
for (k, v) in tile_count.items():
	tot_cal += cal[k] * v
print(tot_cal)


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
calories = inlt()
game = insr()
game = [int(g) for g in game]
total = 0
for g in game:
	if g == 1:
		total += calories[0]
	if g == 2:
		total += calories[1]
	if g == 3:
		total += calories[2]
	if g == 4:
		total += calories[3]
print(total)


n = [int(i) for i in input().split()]
n2 = input()
c = 0
s1 = []
s2 = []
r = [char for char in n2]
for i in r:
	s1.append(int(i))
for i in range(0, len(r)):
	s2.append(n[s1[i] - 1])
print(sum(s2))


x = input()
y = input()
i = 0
list = x.split()
list2 = []
for letter in y:
	list2.append(letter)
a = list2.count('1')
b = list2.count('2')
c = list2.count('3')
d = list2.count('4')
n = a * int(list[0]) + b * int(list[1]) + c * int(list[2]) + d * int(list[3])
print(n)


arr = list(map(int, input().split()))
s = input()
count = 0
for x in s:
	count += arr[int(x) - 1]
print(count)


a = input()

def getMultipleInput(text):
	i = 0
	text = text + ' '
	inputs = []
	for f in range(0, len(text)):
		if text[f] == ' ':
			inputs.append(int(text[i:f]))
			i = f + 1
	return inputs
points = getMultipleInput(a)
s = str(input())
total = 0
for i in range(0, len(s)):
	total = total + points[int(s[i]) - 1]
print(total)


caloriesVal = list(map(int, input().split()))
pattern = list(map(int, list(input())))
result = 0
for move in pattern:
	result += caloriesVal[move - 1]
print(result)


calories = input().split()
s = input()
total_calories = 0
for i in range(0, len(s)):
	total_calories += int(calories[int(s[i]) - 1])
print(total_calories)


__copyright__ = ''
__author__ = 'Son-Huy TRAN'
__email__ = 'sonhuytran@gmail.com'
__doc__ = ''
__version__ = '1.0'

def main() -> int:
	a = [int(word) for word in input().split()]
	game = input()
	calories = {'1': a[0], '2': a[1], '3': a[2], '4': a[3]}
	sum_calories = 0
	for brick in game:
		sum_calories += calories[brick]
	print(sum_calories)
	return 0
exit(main())


cal = list(map(int, input().split()))
s = input()
f = s.count('1') * cal[0] + s.count('2') * cal[1] + s.count('3') * cal[2] + s.count('4') * cal[3]
print(f)


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
x = inlt()
y = inp()
tot = 0
for i in str(y):
	tot += x[int(i) - 1]
print(tot)


arr = [int(x) for x in input().split()]
s = input()
cals = 0
for e in s:
	cals += arr[int(e) - 1]
print(cals)


s = [int(i) for i in input().split()]
a = input()
dic = dict(zip([1, 2, 3, 4], s))
p = 0
for i in a:
	p += dic.get(int(i))
print(p)


a = list(map(int, input().split()))
pas = 0
str = input()
for i in range(len(str)):
	pas += a[int(str[i]) - 1]
print(pas)


a = list(map(int, input().split()))
s = input().strip()
ans = 0
for i in s:
	ans += a[int(i) - 1]
print(ans)


ls = list(map(int, input().split()))
ss = input()
s = 0
for i in ss:
	s = s + ls[int(i) - 1]
print(s)


(a1, a2, a3, a4) = list(map(int, input().split()))
s = input()
out = 0
for i in range(len(s)):
	if s[i] == '1':
		out = out + a1
	elif s[i] == '2':
		out = out + a2
	elif s[i] == '3':
		out = out + a3
	elif s[i] == '4':
		out = out + a4
print(out)


calory = input().split()
a = [int(i) for i in input()]
cc = list(calory)
ccc = list(a)
summ = 0
for x in range(0, len(a)):
	SS = ccc[x]
	N = cc[SS - 1]
	summ += int(N)
print(summ)


a = [int(i) for i in input().split()]
t = input()
b = [int(i) for i in t]
S = 0
for i in b:
	S += a[i - 1]
print(S)


(a_1, a_2, a_3, a_4) = map(int, input().split())
strips = input()
print(strips.count('1') * a_1 + strips.count('2') * a_2 + strips.count('3') * a_3 + strips.count('4') * a_4)


l = list(map(int, input().split(' ')))
a = input()
total = 0
for i in a:
	total = total + l[int(i) - 1]
print(total)


l = list(map(int, input().split(' ')))
l.insert(0, 0)
c = 0
s = input()
res = [int(x) for x in str(s)]
for i in res:
	c = c + l[i]
print(c)


a = list(map(int, input().split()))
print(sum((a[int(num) - 1] for num in input())))


a = [int(x) for x in input().split()]
res = 0
for i in input():
	res += a[int(i) - 1]
print(res)


Ai = input().split()
S = input()
totalCalori = 0
for i in range(len(S)):
	totalCalori += int(Ai[int(S[i]) - 1])
print(totalCalori)


def main():
	l = list(map(int, input().split()))
	s = input()
	cnt = [0 for i in range(4)]
	for i in s:
		cnt[int(i) - 1] += 1
	sm = 0
	for i in range(4):
		sm += cnt[i] * l[i]
	print(sm)
main()


a = list(map(int, input().split()))
b = input()
(count, n) = (0, len(b))
for i in range(n):
	k = int(b[i])
	count += a[k - 1]
print(count)


l = list(map(int, input().split()))
s = input()
l1 = []
s1 = 0
for ch in s:
	l1.append(int(ch))
for i in l1:
	s1 = s1 + l[i - 1]
print(s1)


arr = list(map(int, input().split()))
str = input()
c = 0
for i in str:
	c += arr[int(i) - 1]
print(c)


[a1, a2, a3, a4] = [int(x) for x in input().split()]
s = input()
print(a1 * s.count('1') + a2 * s.count('2') + a3 * s.count('3') + a4 * s.count('4'))


def answer():
	a = input().split()
	a = [int(x) for x in a]
	b = list(input())
	b = [int(x) - 1 for x in b]
	ans = 0
	for x in b:
		ans += a[x]
	return ans
print(answer())


(a, b, c, d) = map(int, input().split())
x = str(input())
cal = 0
for i in range(len(x)):
	if int(x[i]) == 1:
		cal += a
	elif int(x[i]) == 2:
		cal += b
	elif int(x[i]) == 3:
		cal += c
	elif int(x[i]) == 4:
		cal += d
print(cal)


a = [int(s) for s in input().split()]
s = input()
sum = 0
for i in s:
	if i == '1':
		sum += a[0]
	elif i == '2':
		sum += a[1]
	elif i == '3':
		sum += a[2]
	elif i == '4':
		sum += a[3]
print(sum)


l = [int(x) for x in input().split()]
d = {}
for i in range(1, 5):
	d[i] = l[i - 1]
s = input()
l = [d[int(s[x])] for x in range(len(s))]
print(sum(l))


def read_inputs():
	first_line = input()
	inputs = first_line.split(' ')
	inputs = [int(i) for i in inputs]
	s = input()
	S = [int(c) for c in s]
	return (inputs, S)

def main():
	(inputs, S) = read_inputs()
	Sum = 0
	for s in S:
		index = s - 1
		Sum = Sum + inputs[index]
	print(Sum)
main()


(a, b, c, d) = input().split()
squares = {'1': a, '2': b, '3': c, '4': d}
s = input()
sum = 0
for i in s:
	sum += int(squares.get(i))
print(sum)


l = list(map(int, input().split()))
p = input()
cal = 0
for i in range(len(p)):
	if p[i] == '1':
		cal += l[0]
	elif p[i] == '2':
		cal += l[1]
	elif p[i] == '3':
		cal += l[2]
	elif p[i] == '4':
		cal += l[3]
print(cal)


calloryWeights = list(input().split())
path = input('')
sum = 0
for s in path:
	if s == '1':
		sum += int(calloryWeights[0])
	elif s == '2':
		sum += int(calloryWeights[1])
	elif s == '3':
		sum += int(calloryWeights[2])
	elif s == '4':
		sum += int(calloryWeights[3])
print(sum)


import math, os, sys
import string, re
from itertools import *
from collections import Counter
from operator import mul

def inputint():
	return int(input())

def inputarray(func=int):
	return map(func, input().split())
A = list(inputarray())
print(sum(map(lambda x: A[int(x) - 1], list(input()))))


(a1, a2, a3, a4) = input().split()
(a1, a2, a3, a4) = (int(a1), int(a2), int(a3), int(a4))
s = input()
k1 = s.count('1')
k2 = s.count('2')
k3 = s.count('3')
k4 = s.count('4')
kk = k1 * a1 + k2 * a2 + k3 * a3 + k4 * a4
print(kk)


cals = list(map(int, input().split()))
seconds = list(map(int, input()))
c_sum = 0
for i in seconds:
	c_sum += cals[i - 1]
print(c_sum)


import sys
import os.path
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
	sys.stdout = open('out.txt', 'w')
li = list(map(int, input().split()))
s = input()
ans = 0
for i in s:
	ans += li[int(i) - 1]
print(ans)


import functools
n = input()
s = input()
l = n.split(' ')
lst = list(map(int, l))
l1 = []
for i in range(len(s)):
	l1.append(int(s[i]))
sum = 0
for i in range(len(l1)):
	k = l1[i]
	sum = sum + int(lst[k - 1])
print(sum)


a = [0] + [int(x) for x in input().split()]
b = [0, 0, 0, 0, 0]
s = input()
for c in s:
	b[int(c)] += 1
calories = sum((a[i] * b[i] for i in range(1, 5)))
print(calories)


(p, q, r, s) = [int(x) for x in input().split(' ')]
n = input()
sum = 0
for i in n:
	if i == '1':
		sum += p
	elif i == '2':
		sum += q
	elif i == '3':
		sum += r
	elif i == '4':
		sum += s
print(sum)


cal = {k: v for (k, v) in enumerate(map(int, input().strip().split()), 1)}
tiles = map(int, input())
tot_cal = 0
for tile in tiles:
	tot_cal += cal[tile]
print(tot_cal)


arr = [int(x) for x in input().split()]
n = input()
count = 0
for i in n:
	if i == '1':
		count += arr[0]
	elif i == '2':
		count += arr[1]
	elif i == '3':
		count += arr[2]
	elif i == '4':
		count += arr[3]
print(count)


l = input().split(' ')
l1 = list(map(str, l))
dic = {}
for i in range(len(l1)):
	dic[i + 1] = l1[i]
s = input()
cal = 0
for i in range(len(s)):
	cal += int(dic[int(s[i])])
print(cal)


(a, b, c, d) = map(int, input().split())
l = []
nuk = 1
l.append(nuk)
l.append(a)
l.append(b)
l.append(c)
l.append(d)
t = input()
res = []
ress = []
for x in t:
	m = int(x)
	res.append(m)
for x in res:
	n = l[x]
	ress.append(n)
print(sum(ress))


n = input().split()
list1 = [int(j) for j in n]
burn = 0
s = input()
list2 = [int(k) for k in s]
i = 0
while i < len(list2):
	burn += list1[list2[i] - 1]
	i += 1
print(burn)


cal = list(map(int, input().split()))
s = input()
num = [0, 0, 0, 0]
for i in range(len(s)):
	if s[i] == '1':
		num[0] = num[0] + 1
	elif s[i] == '2':
		num[1] = num[1] + 1
	elif s[i] == '3':
		num[2] = num[2] + 1
	elif s[i] == '4':
		num[3] = num[3] + 1
total = 0
for j in range(4):
	total = total + num[j] * cal[j]
print(total)


calories = list(map(int, input().split()))
seq = list(map(int, input()))
total = 0
for box in seq:
	total += calories[box - 1]
print(total)


(a1, a2, a3, a4) = map(int, input().split())
nums = str(input())
soma = 0
for num in nums:
	if num == '1':
		soma += a1
	elif num == '2':
		soma += a2
	elif num == '3':
		soma += a3
	elif num == '4':
		soma += a4
print(soma)


l = list(map(int, input().split()))
dic = {}
for i in range(4):
	dic[i + 1] = l[i]
s = input()
res = 0
for i in s:
	res += dic[int(i)]
print(res)


(a, b, c, d) = map(int, input().split())
s = 0
l = list((int(x) for x in input()))
for i in l:
	if i == 1:
		s = s + a
	elif i == 2:
		s = s + b
	elif i == 3:
		s = s + c
	else:
		s = s + d
print(s)


price = list(map(int, input().split()))
ans = 0
for i in input():
	ans += price[ord(i) - ord('1')]
print(ans)


g = list(map(int, input().split()))
o = 0
for s in input():
	s = int(s)
	o += g[s - 1]
print(o)


a = [i for i in map(int, input().split())]
s = input()
ans = 0
for i in range(1, 5):
	ans += s.count(str(i)) * a[i - 1]
print(ans)


cal = [int(x) for x in input().split(' ')]
s = input()
count = 0
for char in s:
	count += cal[int(char) - 1]
print(count)


calories = [int(i) for i in input().split()]
operator = input()
answer = 0
for item in operator:
	answer += calories[int(item) - 1]
print(answer)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

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

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

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
vals = read_ints()
print(sum([vals[int(x) - 1] for x in input()]))


l = list(map(int, input().split()))
s = input()
sum = 0
for i in range(len(s)):
	if s[i] == '1':
		sum = sum + l[0]
	elif s[i] == '2':
		sum = sum + l[1]
	elif s[i] == '3':
		sum = sum + l[2]
	else:
		sum = sum + l[3]
print(sum)


n = list(map(int, input().split()))
a = list(map(int, input()))
b = []
for i in range(len(a)):
	if a[i] == 1:
		b.append(n[0])
	elif a[i] == 2:
		b.append(n[1])
	elif a[i] == 3:
		b.append(n[2])
	else:
		b.append(n[3])
print(sum(b))


(a, b, c, d) = map(int, input().split())
q = input()
g = 0
for i in q:
	s = int(i)
	if s == 1:
		g += a
	elif s == 2:
		g += b
	elif s == 3:
		g += c
	elif s == 4:
		g += d
print(g)


lst = list(map(int, input().split()))
str = input()
i = 0
sum = 0
while i < len(str):
	x = int(str[i]) - 1
	sum = sum + lst[x]
	i += 1
print(sum)


import math
a = input().split()
s = str(input())
summ = 0
for i in range(len(s)):
	summ += int(a[int(s[i]) - 1])
print(summ)


def main():
	cal = input()
	cal = cal.split()
	strips = input()
	energy = 0
	for i in range(len(strips)):
		energy += int(cal[int(strips[i]) - 1])
	print(energy)
main()


n = input()
b = n.split()
a = []
for i in range(len(b)):
	a.append(int(b[i]))
s = input()
c = list(s)
d = []
for i in range(len(c)):
	d.append(int(c[i]))
cal = 0
for i in range(len(d)):
	cal = cal + a[d[i] - 1]
print(cal)


arr = list(map(int, input().split()))
s = input()
sum = 0
for i in s:
	sum = sum + arr[int(i) - 1]
print(sum)


cps = [int(x) for x in input().split(' ')]
taps = input()
sumcals = 0
for x in taps:
	sumcals += cps[int(x) - 1]
print(sumcals)


(a1, a2, a3, a4) = [int(i) for i in input().split()]
index1 = 1
index2 = 2
index3 = 3
index4 = 4
s = input()
counter = 0
for i in s:
	if int(i) == index1:
		counter += a1
	if int(i) == index2:
		counter += a2
	if int(i) == index3:
		counter += a3
	if int(i) == index4:
		counter += a4
print(counter)


in1 = input().split()
in1 = list(map(int, in1))
in2 = input()
n = len(in2)
li = list(in2)
cal = 0
for i in range(n):
	if li[i] == '1':
		cal = cal + in1[0]
	elif li[i] == '2':
		cal = cal + in1[1]
	elif li[i] == '3':
		cal = cal + in1[2]
	else:
		cal = cal + in1[3]
print(cal)


a = list(map(int, input().split()))
n = list(map(int, input()))
count = 0
for i in range(4):
	count += n.count(i + 1) * a[i]
print(count)


lis = list(map(int, input().split()))
string = input()
arr = [0, 0, 0, 0]
for i in range(0, len(string)):
	if string[i] == '1':
		arr[0] = arr[0] + 1
	elif string[i] == '2':
		arr[1] = arr[1] + 1
	elif string[i] == '3':
		arr[2] = arr[2] + 1
	else:
		arr[3] = arr[3] + 1
res = 0
for i in range(0, 4):
	if i == 0:
		res = res + arr[0] * lis[i]
	elif i == 1:
		res = res + arr[1] * lis[i]
	elif i == 2:
		res = res + arr[2] * lis[i]
	else:
		res = res + arr[3] * lis[i]
print(res)


import copy

def main():
	calories_of_strips = [int(it) for it in input().split(' ')]
	strips = [int(it) for it in list(input())]
	wasted_calories = 0
	for strip in strips:
		wasted_calories = wasted_calories + calories_of_strips[strip - 1]
	print(wasted_calories)
main()


t = list(map(int, input().split()))
n = input()
n = list(n)
k = 0
for i in range(0, len(n)):
	k = k + t[int(n[i]) - 1]
print(k)


a = list(map(int, input().split()))
s = input()
s1 = [int(i) for i in s]
sum = 0
for i in range(len(s1)):
	sum += a[s1[i] - 1]
print(sum)


def calories(ls, s):
	s = list(s)
	h = 0
	for i in range(len(s)):
		h = h + ls[int(s[i]) - 1]
	return h
ls = [int(i) for i in input().split()]
s = str(input())
print(calories(ls, s))


q = input().split(' ')
s = input()
a1 = s.count('1')
a2 = s.count('2')
a3 = s.count('3')
a4 = s.count('4')
t = a1 * int(q[0]) + a2 * int(q[1]) + a3 * int(q[2]) + a4 * int(q[3])
print(t)


l = list(map(int, input().split()))
s = input()
d = {'1': l[0], '2': l[1], '3': l[2], '4': l[3]}
c = 0
for i in range(len(s)):
	c += d[s[i]]
print(c)


import math
x = [int(x) for x in input().split()]
s = input()
t = 0
a = 0
b = 0
c = 0
d = 0
for y in s:
	if y == '1':
		a += x[0]
	if y == '2':
		b += x[1]
	if y == '3':
		c += x[2]
	if y == '4':
		d += x[3]
t = a + b + c + d
print(t)


l = [0] + list(map(int, input().split()))
s = input()
sm = 0
for i in range(len(s)):
	sm += l[int(s[i])]
print(sm)


c = list(map(int, input().split()))
s = input()
sumc = 0
for i in range(len(s)):
	if s[i] == '1':
		sumc = sumc + c[0]
	if s[i] == '2':
		sumc = sumc + c[1]
	if s[i] == '3':
		sumc = sumc + c[2]
	if s[i] == '4':
		sumc = sumc + c[3]
print(sumc)


xs = list(map(int, input().split()))
x1 = xs[0]
x2 = xs[1]
x3 = xs[2]
x4 = xs[3]
count = 0
arr = input()
for i in range(len(arr)):
	if arr[i] == '1':
		count += x1
	elif arr[i] == '2':
		count += x2
	elif arr[i] == '3':
		count += x3
	else:
		count += x4
print(count)


a = [int(x) for x in input().split()]
s = input()
sm = 0
for (i, b) in enumerate(s):
	sm += a[int(b) - 1]
print(sm)


inp = input
li = list
iinp = lambda : int(inp())
ent = lambda : map(int, inp().split())
lient = lambda : li(ent())
res = 0
cal = lient()
di = {}
for i in range(4):
	di[str(i + 1)] = cal[i]
movs = inp()
for i in movs:
	res += di[i]
print(res)


import re
(a1, a2, a3, a4) = map(int, input().split())
s = input()
a = re.findall('1', s)
b = re.findall('2', s)
c = re.findall('3', s)
d = re.findall('4', s)
calories = len(a) * a1 + len(b) * a2 + len(c) * a3 + len(d) * a4
print(calories)


def black_square(lst, s):
	k = 0
	for i in range(len(s)):
		if s[i] == '1':
			k += lst[0]
		elif s[i] == '2':
			k += lst[1]
		elif s[i] == '3':
			k += lst[2]
		elif s[i] == '4':
			k += lst[3]
	return k
a = [int(i) for i in input().split()]
t = input()
print(black_square(a, t))


x = list(map(int, input().split()))
y = str(input())
ans = 0
for i in y:
	ans += x[int(i) - 1]
print(ans)


(a, b, c, d) = input().split(' ')
a1 = int(a)
a2 = int(b)
a3 = int(c)
a4 = int(d)
s = str(input())
score = 0
for i in range(0, len(s)):
	if s[i] == '1':
		score += a1
	if s[i] == '2':
		score += a2
	if s[i] == '3':
		score += a3
	if s[i] == '4':
		score += a4
print(score)


(a1, a2, a3, a4) = map(int, input().split())
arr = [a1, a2, a3, a4]
s = input()
cnt = 0
for c in s:
	cnt += arr[int(c) - 1]
print(str(cnt))


calories = list(map(int, input().split()))
squares = input()
print(sum(map(lambda x: calories[int(x) - 1], squares)))


game = list(map(int, input().split()))
seq = list(map(int, list(input())))
c = 0
for i in seq:
	c += game[i - 1]
print(c)


a = list(map(int, input().split()))
n = input()
sum = 0
for i in range(len(n)):
	if n[i] == '1':
		sum += a[0]
	if n[i] == '2':
		sum += a[1]
	if n[i] == '3':
		sum += a[2]
	if n[i] == '4':
		sum += a[3]
print(sum)


a1 = input().strip().split(' ')
a2 = list(input())
sum = 0
x = 0
for i in range(len(a2)):
	x = int(a2[i]) - 1
	sum += int(a1[x])
print(sum)


def solution(calories, s):
	total_calories = 0
	for x in s:
		total_calories += calories[x - 1]
	return total_calories
calories = list(map(int, input().split()))
s = list(map(int, input()))
print(solution(calories, s))


a = [int(i) for i in input().split()]
s = input()
k = 0
for i in range(1, 5):
	k += s.count(str(i)) * a[i - 1]
print(k)


(a1, a2, a3, a4) = map(int, input().split())
s = input()
a = []
a.append(a1)
a.append(a2)
a.append(a3)
a.append(a4)
result = 0
for i in s:
	result = result + a[int(i) - 1]
print(result)


n = list(map(int, input().split()))
x = input()
s = 0
for l in x:
	s += n[int(l) - 1]
print(s)


a = list(map(int, input().split()))
s = list(map(int, list(input())))
c1 = 0
c2 = 0
c3 = 0
c4 = 0
for i in range(len(s)):
	if s[i] == 1:
		c1 += 1
	elif s[i] == 2:
		c2 += 1
	elif s[i] == 3:
		c3 += 1
	else:
		c4 += 1
print(c1 * a[0] + c2 * a[1] + c3 * a[2] + c4 * a[3])


a = input()
b = [int(x) for x in a.split()]
c = input()
i = len(c)
d = [int(x) for x in list(c)]
n = 0
for j in range(0, i):
	n = n + b[d[j] - 1]
print(n)


line = list(map(int, input().split()))
s = list(map(int, list(input())))
print(sum(map(lambda x: line[x - 1], s)))


n = list(map(int, input().split()))
x = input()
print(x.count('1') * n[0] + x.count('2') * n[1] + x.count('3') * n[2] + x.count('4') * n[3])


my_dict = {'1': 0, '2': 0, '3': 0, '4': 0}
n = [int(i) for i in input().split()]
for i in range(1, len(n) + 1):
	my_dict[str(i)] = n[i - 1]
s = list(input())
total = 0
for j in s:
	total += my_dict[j]
print(total)


a = [int(i) for i in input().split()]
s = input()
ans = 0
for i in range(len(s)):
	ans += a[int(s[i]) - 1]
print(ans)


a = input().split()
str = input()
sum = 0
for c in str:
	sum += int(a[int(c) - 1])
print(sum)


a = input().split()
b = int(a[0])
c = int(a[1])
d = int(a[2])
e = int(a[3])
p = input()
cal = 0
for i in p:
	if i == '1':
		cal = cal + b
	elif i == '2':
		cal = cal + c
	elif i == '3':
		cal = cal + d
	elif i == '4':
		cal = cal + e
print(cal)


(a1, a2, a3, a4) = [int(a) for a in input().split(' ')]
s = input()
count = 0
for i in range(s.__len__()):
	if s[i] == '1':
		count += a1
	elif s[i] == '2':
		count += a2
	elif s[i] == '3':
		count += a3
	elif s[i] == '4':
		count += a4
print(count)


(a, b, c, d) = map(int, input().split())
s = input()
t = sorted(s)
yar1 = 0
yar2 = 0
yar3 = 0
yar4 = 0
yar = 0
dosti = 0
mohabat = 0
nafarat = 0
for i in t:
	if i in '1':
		yar += 1
		yar1 = yar * a
	elif i in '2':
		dosti += 1
		yar2 = dosti * b
	elif i in '3':
		mohabat += 1
		yar3 = mohabat * c
	elif i in '4':
		nafarat += 1
		yar4 = nafarat * d
print(yar1 + yar2 + yar3 + yar4)


from sys import stdin, stdout
from math import gcd, sqrt, floor, ceil

def list_inp(x):
	return list(map(x, input().split()))

def map_inp(x):
	return map(x, input().split())

def lcm(a, b):
	return a * b / gcd(a, b)
arr = list_inp(int)
s = input()
ans = 0
for i in s:
	ans += arr[int(i) - 1]
print(ans)


def black_square(a, s):
	s = list(s)
	cal = 0
	for i in s:
		if i == '1':
			cal = cal + a[0]
		elif i == '2':
			cal = cal + a[1]
		elif i == '3':
			cal = cal + a[2]
		else:
			cal = cal + a[3]
	print(cal)
a = list(map(int, input('').split()))
s = input('')
black_square(a, s)


a = list(map(int, input().split()))
s = input()
count = 0
for i in s:
	if int(i) == 1:
		count += a[0]
	elif int(i) == 2:
		count += a[1]
	elif int(i) == 3:
		count += a[2]
	else:
		count += a[3]
print(count)


n = input().split()
s = input()
result = 0
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
count1 = s.count('1')
count2 = s.count('2')
count3 = s.count('3')
count4 = s.count('4')
result += count1 * a + count2 * b + count3 * c + count4 * d
print(result)


cal = list(map(int, input().split()))
a = b = c = d = 0
x = input()
print(x.count('1') * cal[0] + x.count('2') * cal[1] + x.count('3') * cal[2] + x.count('4') * cal[3])


a = list()
a = a + [int(a) for a in input().split()]
b = input()
add = 0
for i in range(0, len(b)):
	k = int(b[i])
	add = add + a[k - 1]
print(add)


x = list(map(int, input().split()))
s = input()
count = 0
for i in s:
	y = int(i)
	count += x[y - 1]
print(count)


mylist = list(map(int, input().split()))
e = input()
sum = 0
liste = list(e)
for i in range(len(liste)):
	if '1' == liste[i]:
		sum = mylist[0] + sum
	if '2' == liste[i]:
		sum = mylist[1] + sum
	if '3' == liste[i]:
		sum = mylist[2] + sum
	if '4' == liste[i]:
		sum = mylist[3] + sum
print(sum)


cal = list(map(int, input().split()))
s = input()

def proA(arr, cal):
	for i in range(len(arr)):
		arr[i] = int(arr[i])
	dic = {}
	p = 0
	for i in cal:
		dic[p] = i
		p += 1
	ans = 0
	for i in arr:
		ans += dic.get(i - 1)
	return ans
print(proA(list(s), cal))


import itertools as it
import functools
import operator
import collections
import math
import sys

def solve(xs, ys):
	d = dict(enumerate(xs, 1))
	return sum((d[y] for y in ys))

def main():
	xs = [int(c) for c in input().split()]
	ys = [int(c) for c in input()]
	result = solve(xs, ys)
	print(result)
main()


(a1, a2, a3, a4) = map(int, input().split())
s = input()
c = 0
s = [int(x) for x in s]
for i in s:
	if i == 1:
		c += a1
	elif i == 2:
		c += a2
	elif i == 3:
		c += a3
	else:
		c += a4
print(c)


n = list(map(int, input().split(' ')))
k = list(map(int, input()))
i = 0
s = 0
for x in k:
	s = s + n[x - 1]
print(s)


(c1, c2, c3, c4) = map(int, input().split())
cal = 0
move = input()
for i in range(len(move)):
	if move[i] == '1':
		cal += c1
	elif move[i] == '2':
		cal += c2
	elif move[i] == '3':
		cal += c3
	else:
		cal += c4
print(cal)


from sys import stdin
a = list(map(int, stdin.readline().split()))
s = stdin.readline()[:-1]
sm = 0
for i in s:
	sm += a[int(i) - 1]
print(sm)


calories = list(map(int, input().split()))
pushes = sum([calories[int(x) - 1] for x in input()])
print(pushes)


l = [int(i) for i in input().split()]
s = input()
c = []
for i in s:
	c.append(i)
print(c.count('1') * l[0] + c.count('2') * l[1] + c.count('3') * l[2] + c.count('4') * l[3])


a = list(map(int, input().split()))
g = input()
summ = 0
for i in range(4):
	summ += g.count(str(i + 1)) * a[i]
print(summ)


I = input
ls = I().split()
ans = 0
for x in I():
	ans += int(ls[int(x) - 1])
print(ans)


a = list(map(int, input().split()))
a.insert(0, 0)
s = input()
x = [0, 0, 0, 0, 0]
for i in range(len(s)):
	x[int(s[i])] += 1
Sum = 0
for i in range(1, 5):
	Sum += a[i] * x[i]
print(Sum)


l = list(map(int, input().split()))
b = input()
waste = 0
for i in b:
	waste += l[int(i) - 1]
print(waste)


cost = list(map(int, input().split()))
s = str(input())
ans = 0
for i in s:
	ans += cost[int(i) - 1]
print(ans)


d = {}
n = [int(x) for x in input().split()]
for (i, j) in enumerate(n, 1):
	d[i] = j
s = list(input())
t = 0
for i in s:
	t += d[int(i)]
print(t)


val = input()
box = input()
val = val.split(' ')
cal = 0
for i in box:
	i = int(i) - 1
	b = val[i]
	cal = cal + int(b)
print(cal)


l = list(map(int, input().split()))
x = input()
w = list(x)
s = 0
for i in w:
	s += l[int(i) - 1]
print(s)


n = list(map(int, input().split()))
s = list(input())
print(sum((n[int(i) - 1] for i in s)))


lst_ch = list(map(int, input().split()))
print(sum((lst_ch[int(i) - 1] for i in input())))


array = list(map(int, input().split()))
_str = input()
count = 0
for char in _str:
	if char == '1':
		count += array[0]
	elif char == '2':
		count += array[1]
	elif char == '3':
		count += array[2]
	else:
		count += array[3]
print(count)


lst = [int(i) for i in input().split()]
sa = input()
sum = 0
for i in sa:
	sum = sum + lst[int(i) - 1]
print(sum)


import collections
a = tuple(map(int, str.split(input())))
ns = collections.Counter(list(map(int, str.strip(input()))))
print(sum([a[i - 1] * ns[i] for i in ns]))


def calories(x, y):
	calories_needed = 0
	for i in y:
		if i == '1':
			calories_needed += x[0]
		elif i == '2':
			calories_needed += x[1]
		elif i == '3':
			calories_needed += x[2]
		elif i == '4':
			calories_needed += x[3]
	return calories_needed
x = list(map(int, input().split()))
y = input()
print(calories(x, y))


(a, b, c, d) = map(int, input().split())
s = input().strip()
x = 0
for i in s:
	if i == '1':
		x += a
	elif i == '2':
		x += b
	elif i == '3':
		x += c
	elif i == '4':
		x += d
print(x)


stripCalories = [int(i) for i in input().split()]
blackSqrSeq = [int(i) for i in input()]
sumOfCalories = 0
for i in blackSqrSeq:
	sumOfCalories += stripCalories[i - 1]
print(sumOfCalories)


(a, b, c, d) = input().split()
calc = 0
mstring = input()
for i in mstring:
	if i == '1':
		calc += int(a)
	elif i == '2':
		calc += int(b)
	elif i == '3':
		calc += int(c)
	elif i == '4':
		calc += int(d)
print(calc)


(a, b, c, d) = map(int, input().split())
x = str(input())
s = 0
for _ in range(len(x)):
	if x[_] == '1':
		s += a
	elif x[_] == '2':
		s += b
	elif x[_] == '3':
		s += c
	else:
		s += d
print(s)


cal = list(map(int, input().split(' ')))
ordr = input()
dct = {}
for each in ordr:
	if each in dct.keys():
		dct[each] += 1
	else:
		dct[each] = 1
totl = 0
for ky in dct:
	totl += dct[ky] * cal[int(ky) - 1]
print(totl)


a = list(map(int, input().split()))
s = list(input())
c = 0
for e in s:
	c += a[int(e) - 1]
print(c)


strip = list(map(int, input().split()))
string = input()
print(sum((strip[int(i) - 1] for i in string)))


(Q, S) = ([int(x) for x in input().split()], input())
e = 0
for i in S:
	e += Q[int(i) - 1]
print(e)


calories = [int(item) for item in input().split()]
moves = input()
result = 0
for move in moves:
	result += calories[int(move) - 1]
print(result)


h = input().split(' ')
j = input()
ouns = 0
for i in range(len(j)):
	y = int(j[i])
	k = int(h[y - 1])
	ouns += k
print(ouns)


a = list(map(int, input().split()))
s = input()
out = 0
for i in range(1, 5):
	x = s.count(str(i))
	z = x * a[i - 1]
	out += z
print(out)


a = list(map(int, input().rstrip().split()))
p = input()
s = 0
for i in p:
	m = int(i)
	s = s + a[m - 1]
print(s)


weights = [int(i) for i in input().split()]
queue = [int(i) for i in list(input())]
answer = 0
for line in queue:
	answer += weights[line - 1]
print(answer)


t = [0] + list(map(int, input().split()))
s = input()
summ = 0
for x in s:
	summ += t[int(x)]
print(summ)


arr = [int(num) for num in input().split()]
n = input()
a = 0
for i in range(0, len(n)):
	a += arr[int(n[i]) - 1]
print(a)


a = input()
a = a.split(' ')
s = input()
calorias = 0
for i in range(len(s)):
	if int(s[i]) == 1:
		calorias += int(a[0])
	elif int(s[i]) == 2:
		calorias += int(a[1])
	elif int(s[i]) == 3:
		calorias += int(a[2])
	else:
		calorias += int(a[3])
print(calorias)


a = list(map(int, input().split()))
s = input()
c = 0
for i in s:
	j = int(i) - 1
	c += a[j]
print(c)


a = list(input().split())
d = {}
for i in range(len(a)):
	d[i + 1] = a[i]
count = 0
s = input()
for j in s:
	count += int(d[int(j)])
print(count)


R = lambda : map(int, input().split())
(*a,) = R()
print(sum((a[int(i) - 1] for i in input())))


from sys import stdin
a = list(map(int, stdin.readline().rstrip().split()))
a.insert(0, 0)
s = stdin.readline().rstrip()
print(a[1] * s.count('1') + a[2] * s.count('2') + a[3] * s.count('3') + a[4] * s.count('4'))


(a, b, c, d) = [int(x) for x in input().split()]
ans = 0
s = input()
for e in s:
	if e == '1':
		ans += a
	elif e == '2':
		ans += b
	elif e == '3':
		ans += c
	else:
		ans += d
print(ans)


a = input().split()
b = input()
sum = 0
for i in range(len(b)):
	sum += int(a[int(b[i]) - 1])
print(sum)


import sys
an = list(map(int, sys.stdin.readline().split()))
s = input()
result = 0
for c in s:
	result += an[ord(c) - ord('1')]
print(result)


cals = list(map(int, input().split()))
string = input()
cal = 0
for i in string:
	ii = int(i) - 1
	cal += cals[ii]
print(cal)


lt = list(input().split())
lt = [int(i) for i in lt]
s = 0
for i in input():
	s += lt[int(i) - 1]
print(s)


a = [int(x) for x in input().split()]
s = input()
c = 0
for val in s:
	c += a[int(val) - 1]
print(c)


n = list(map(int, input().split()))
m = input()
(a, b, c, d) = (m.count('1'), m.count('2'), m.count('3'), m.count('4'))
print(a * n[0] + b * n[1] + c * n[2] + d * n[3])


a = [int(x) for x in input().split()]
s = input()
calories = 0
for x in range(1, 5):
	calories += s.count(str(x)) * a[x - 1]
print(calories)


a = input().split()
b = input()
c = 0
for i in b:
	c = c + int(a[int(i) - 1])
print(c)


a = input().split()
s = input()
x = 0
d = {}
for i in range(1, len(a) + 1):
	d[i] = int(a[i - 1])
for i in s:
	x += d[int(i)]
print(x)


n = list(map(int, input().split()))
a = input()
calories = 0
for i in a:
	b = int(i) - 1
	calories = calories + n[b]
print(calories)


li = list(map(int, input().split()))
d = {}
for i in range(1, 5):
	d[i] = li[i - 1]
cal = 0
for i in input():
	cal += d[int(i)]
print(cal)


from collections import Counter
A = {str(i): a for (i, a) in enumerate(map(int, input().split()), 1)}
c = Counter(input())
print(sum((A[i] * c[i] for i in '1234')))


calories = [int(i) for i in input().split()]
strips = list(input())
wasted = 0
for i in strips:
	wasted += calories[int(i) - 1]
print(wasted)


a = list(map(int, input().split()))
s = input()
k = []
for i in s:
	k.append(a[int(i) - 1])
print(sum(k))


(a, b, c, d) = map(int, input().split()[:4])
s = list(input())
s = [int(x) for x in s]
(p, q, r, t) = (s.count(1), s.count(2), s.count(3), s.count(4))
print(a * p + b * q + c * r + d * t)


def solve(arr, s):
	return sum([arr[int(c) - 1] for c in s])

def main():
	arr = list(map(int, input().split()))
	s = input()
	print(solve(arr, s))
main()


lis = [int(i) for i in input().split()]
st = input()
ans = 0
for i in st:
	ans += lis[int(i) - 1]
print(ans)


a = list(map(int, input().split()))
n = input()
s = 0
b = {}
for i in range(1, len(a) + 1):
	b[i] = a[i - 1]
for i in range(len(n)):
	s += b[int(n[i])]
print(s)


l = [int(i) for i in input().split()]
s = input()
ans = 0
for i in s:
	ans += l[int(i) - 1]
print(ans)


calories = list(map(int, input().split()))
s = input()
total_calories = 0
for i in range(0, len(s)):
	if s[i] == '1':
		total_calories += calories[0]
	elif s[i] == '2':
		total_calories += calories[1]
	elif s[i] == '3':
		total_calories += calories[2]
	else:
		total_calories += calories[3]
print(total_calories)


n = input().split(' ')
s = input()
c = 0
for i in range(len(s)):
	if s[i] == '1':
		c = c + int(n[0])
	if s[i] == '2':
		c = c + int(n[1])
	if s[i] == '3':
		c = c + int(n[2])
	if s[i] == '4':
		c = c + int(n[3])
print(c)


a = [int(x) for x in input().split()]
s = input()
t = 0
for i in s:
	if i == '1':
		t += a[0]
	elif i == '2':
		t += a[1]
	elif i == '3':
		t += a[2]
	else:
		t += a[3]
print(t)


(a, b, c, d) = map(int, input().split())
info = {'1': a, '2': b, '3': c, '4': d}
seq = input()
ans = 0
for m in seq:
	ans += info[m]
print(ans)


l = input().split(' ')
s = input()
t = 0
for char in s:
	t += int(l[int(char) - 1])
print(t)


def calories(arr, s):
	di = {}
	for i in range(1, 5):
		di[i] = arr[i - 1]
	suma = 0
	for i in s:
		suma += int(di[int(i)])
	return suma
arr = list(map(int, input().rstrip().split()))
s = input()
print(calories(arr, s))


calories = list(map(int, input().strip().split()))
game = list(map(int, list(input().strip())))
print(sum([calories[g - 1] for g in game]))


from collections import Counter
k = list(map(int, input().split()))
s = input()
a = Counter(s)
one_c = a['1']
two_c = a['2']
thr_c = a['3']
four_c = a['4']
ans = one_c * k[0] + two_c * k[1] + thr_c * k[2] + four_c * k[3]
print(ans)


(a, b, c, d) = map(int, input().split())
l = list(input())
z = 0
for i in range(len(l)):
	if l[i] == '1':
		z += a
	elif l[i] == '2':
		z += b
	elif l[i] == '3':
		z += c
	else:
		z += d
print(z)


a = [int(i) for i in input().split()]
s = input()
c = 0
for ch in s:
	c += a[ord(ch) - ord('0') - 1]
print(c)


c = list(map(int, input('').split()))
s = input('')
sol = s.count('1') * c[0] + s.count('2') * c[1] + s.count('3') * c[2] + s.count('4') * c[3]
print(sol)


s = list(map(int, input().split()))
a = s[0]
b = s[1]
c = s[2]
d = s[-1]
t = input()
freq = {}
for x in t:
	if x in freq:
		freq[x] += 1
	else:
		freq[x] = 1
count = 0
for x in freq:
	if int(x) == 1:
		count = count + a * freq[x]
	elif int(x) == 2:
		count = count + b * freq[x]
	elif int(x) == 3:
		count = count + c * freq[x]
	else:
		count = count + d * freq[x]
print(count)


l = [int(i) for i in input().split()]
l1 = list(input())
s = 0
for i in l1:
	s += l[int(i) - 1]
print(s)


import sys
cin = sys.stdin

def read_line(cast=None):
	if cast is not None:
		return cast(cin.readline().strip())
	else:
		return cin.readline().strip()

def read_list(cast=int):
	return list(map(cast, read_line().split()))
a = read_list()
s = read_line()
e = 0
for c in s:
	if c == '1':
		e += a[0]
	elif c == '2':
		e += a[1]
	elif c == '3':
		e += a[2]
	elif c == '4':
		e += a[3]
	else:
		assert False
print(e)


l = list(map(int, input().split()))
n = input()
a2 = n.count('2')
a3 = n.count('3')
a4 = n.count('4')
a1 = n.count('1')
sum = a1 * l[0] + a2 * l[1] + a3 * l[2] + a4 * l[3]
print(sum, end='')


def ans(a, n):
	s = 0
	for i in n:
		s += a[int(i) - 1]
	return s
a = list(map(int, input().split()))
n = input()
print(ans(a, n))


n = list(map(int, input().split()))
m = list(map(int, input()))
print(sum((n[m[i] - 1] for i in range(len(m)))))


from collections import Counter
a = list(map(int, input().split()))
s = Counter(input())
ans = 0
for e in s:
	ans += a[int(e) - 1] * s[e]
print(ans)


pr = [int(i) for i in input().split()]
print(sum([pr[int(i) - 1] for i in input()]))


l1 = list(input().split())
l2 = input()
d = {}
calories = 0
for i in range(len(l1)):
	d[i + 1] = l1[i]
for i in range(len(l2)):
	index = int(l2[i])
	calories += int(d[index])
print(calories)


def solve(calories, squares):
	burning = 0
	for square in calories:
		burning += squares[int(square) - 1]
	return burning
squares = list(map(int, input().split()))
calories = input()
print(solve(calories, squares))


(a1, a2, a3, a4) = map(int, input().split())
d = {'1': a1, '2': a2, '3': a3, '4': a4}
s = input()
print(sum((d[c] for c in s)))


arr = list(map(int, input().split()))
res = 0
s = input()
for a in s:
	res += arr[int(a) - 1]
print(res)


import sys

def read():
	return sys.stdin.readline()
a = []
a = list(map(int, read().split()))
b = list(read())
ans = 0
for i in range(len(b) - 1):
	ans += a[int(b[i]) - 1]
print(ans)


l = list(map(int, input().split()))
x = input()
x = list(x)
s = 0
for i in x:
	i = int(i)
	if i > 0:
		s += l[i - 1]
	else:
		s += 0
print(s)


a = [int(x) for x in input().split()]
n = input()
l = [int(d) for d in str(n)]
ans = 0
for i in range(len(l)):
	ans = ans + a[l[i] - 1]
print(ans)


t = 0
a = [int(i) for i in input().split(' ')]
s = str(input())
for i in range(len(s)):
	t += a[int(s[i]) - 1]
print(t)


cals = list(map(int, input().split(' ')))
str1 = input()
total = 0
for i in str1:
	if i == '1':
		total += cals[0]
	elif i == '2':
		total += cals[1]
	elif i == '3':
		total += cals[2]
	elif i == '4':
		total += cals[3]
print(total)


a = list(map(int, input().split()))
s = input()
ans = 0
l1 = s.count('1')
l2 = s.count('2')
l3 = s.count('3')
l4 = s.count('4')
ans = l1 * a[0] + l2 * a[1] + l3 * a[2] + l4 * a[3]
print(ans)


n = list(map(int, input().split()))
s = input()
d = {}
for i in range(1, 5):
	d[i] = n[i - 1]
total_sum = 0
for j in range(len(s)):
	try:
		total_sum += d[s[j]]
	except KeyError:
		total_sum += n[int(s[j]) - 1]
print(total_sum)


order = list(map(int, input().split()))
s = input()
j = list(map(int, s))
value = 0
for num in j:
	value = value + order[num - 1]
print(value)


l = list(map(int, input().strip().split()))
s = input()
one = s.count('1')
two = s.count('2')
three = s.count('3')
four = s.count('4')
ans = one * l[0] + two * l[1] + three * l[2] + four * l[3]
print(ans)


from sys import stdin, stdout
strips = list(map(int, stdin.readline().split()))
steps = input()
calorie = 0
for i in steps:
	calorie += strips[int(i) - 1]
stdout.write(str(calorie) + '\n')


a = [int(x) for x in input().split()]
print(sum([a[int(x) - 1] for x in input()]))


inputs = input().split(' ')
cal = {}
for i in range(1, 5):
	cal[i] = int(inputs[i - 1])
case = input()
s = 0
for i in case:
	s += int(cal[int(i)])
print(s)


arr = list(map(int, input().split()))
s = input()
lst = list(s)
sumer = 0
for num in lst:
	sumer += arr[int(num) - 1]
print(sumer)


lines = list(map(int, input().split()))
numbers = str(input())
print(sum([lines[int(i) - 1] for i in numbers]))


(a, b, c, d) = map(int, input().split())
s = input()
w = s.count('1') * a + s.count('2') * b + s.count('3') * c + s.count('4') * d
print(w)


x = [int(i) for i in input().split()]
y = input()
s = 0
for i in range(4):
	s += y.count('{}'.format(i + 1)) * x[i]
print(s)


li = list(map(int, input().split()))
s = list(input())
sum = 0
for i in range(len(s)):
	if s[i] == '1':
		sum += li[0]
	elif s[i] == '2':
		sum += li[1]
	elif s[i] == '3':
		sum += li[2]
	elif s[i] == '4':
		sum += li[3]
print(sum)


a = list(map(int, input().split()))
s = input()
d = {}
for i in range(1, 5):
	d[i] = a[i - 1]
res = 0
for i in s:
	res += d[int(i)]
print(res)


(a, b, c, d) = map(int, input().split())
e = [0] * 5
f = input()
for i in range(len(f)):
	e[int(f[i])] += 1
print(a * e[1] + b * e[2] + c * e[3] + d * e[4])


A = [0]
k = 0
A = A + list(map(int, input().split()))
s = input()
for i in range(len(s)):
	k += A[int(s[i])]
print(k)


(a1, a2, a3, a4) = map(int, input().split())
s = input()
sl = [int(i) for i in s]
(c1, c2, c3, c4) = (0, 0, 0, 0)
for i in sl:
	if i == 1:
		c1 += 1
	elif i == 2:
		c2 += 1
	elif i == 3:
		c3 += 1
	else:
		c4 += 1
print(c1 * a1 + c2 * a2 + c3 * a3 + c4 * a4)


s = [int(i) for i in input().split()]
t = [int(i) for i in list(input())]
sum1 = 0
for i in t:
	sum1 += s[i - 1]
print(sum1)


c = [int(i) for i in input().split(' ')]
print(sum((c[int(i) - 1] for i in input())))


d = dict()
total = 0
for c in input().split():
	d[str(len(d) + 1)] = int(c)
for c in list(input()):
	total += d[c]
print(total)


c = list(map(int, input().split()))
c.insert(0, 0)
r = 0
for i in input():
	r += c[int(i)]
print(r)


calo_list = [int(x) for x in input().split(' ')]
calo_burn = 0
for x in input():
	calo_burn += calo_list[int(x) - 1]
print(calo_burn)


A = list(map(int, input().split()))
A.insert(0, 0)
B = input()
S = 0
for i in B:
	S += A[int(i)]
print(S)


a = [int(i) for i in input().split()]
s = input()
fq = [0] * 5
for i in range(len(s)):
	fq[int(s[i])] += 1
s = 0
for i in range(1, 5):
	s += fq[i] * a[i - 1]
print(s)


array = list(map(int, input().split()))
s = input()
zbir = 0
for i in s:
	a = int(i)
	zbir += array[a - 1]
print(zbir)


k = list(map(int, input().split()))
summ = 0
m = list(str(input()))
for i in m:
	summ += k[int(i) - 1]
print(summ)


from sys import stdin
calc = [int(x) for x in stdin.readline().strip().split()]
input = stdin.readline().strip()
sum = 0
for c in input:
	sum += calc[int(c) - 1]
print(sum)


def main():
	calories = [int(i) for i in input().split()]
	s = list(map(int, input()))
	ans = 0
	for i in range(len(s)):
		ans += calories[s[i] - 1]
	print(ans)
main()


class Main:

	def __init__(self):
		cal = {'1': '', '2': '', '3': '', '4': ''}
		a = input().split(' ')
		for i in range(1, 5):
			cal[str(i)] = a[i - 1]
		s = input()
		calories = 0
		for strip in s:
			calories += int(cal[strip])
		print(calories)
Main()


calories = list(map(int, input().split()))
taplist = []
tap = input()
for element in tap:
	taplist += element
taplist = list(map(int, taplist))
sum = 0
for i in taplist:
	sum += calories[i - 1]
print(sum)


(a, b, c, d) = map(int, input().split())
x = input()
e = 0
m = 0
while m < len(x):
	if x[m] == '1':
		e += a
	elif x[m] == '2':
		e += b
	elif x[m] == '3':
		e += c
	else:
		e += d
	m += 1
print(e)


(a, b, c, d) = map(int, input('').split())
s = input('')
i = 0
j = 0
while i < len(s):
	if s[i] == '1':
		j = j + a
	elif s[i] == '2':
		j = j + b
	elif s[i] == '3':
		j = j + c
	elif s[i] == '4':
		j = j + d
	i += 1
print(j)


n = [int(x) for x in input().split()]
nums = [int(x) for x in list(input())]
count = 0
for i in nums:
	count += n[i - 1]
print(count)


values = input().split()
values0 = input()
counter = 0
for i in values0:
	if i == '1':
		counter += int(values[0])
	elif i == '2':
		counter += int(values[1])
	elif i == '3':
		counter += int(values[2])
	elif i == '4':
		counter += int(values[3])
print(counter)


l = list(input().split())
block = input()
c = 0
for x in range(len(block)):
	c = c + int(l[int(block[x]) - 1])
print(c)


ks = list(map(int, input().split()))
s = input()
r = 0
for i in s:
	r += ks[int(i) - 1]
print(r)


cal = list(map(int, input().split()))
s = input()
tot = 0
for i in range(len(s)):
	tot += cal[int(s[i]) - 1]
print(tot)


a = [int(x) for x in input().split()]
s = str(input())
lis = list(s)
ans = 0
for i in range(len(lis)):
	ans += a[int(lis[i]) - 1]
print(ans)


def solve(calories, pos_square):
	total_calories = 0
	for i in range(len(pos_square)):
		total_calories += calories[pos_square[i] - 1]
	return total_calories
a = list(map(int, input().split()))
s = list(map(int, input()))
print(solve(a, s))


import sys
userInput = sys.stdin.readlines()
a = list(map(int, userInput[0][:-1].split(' ')))
s = userInput[1][:-1]
total = 0
for c in s:
	total += a[int(c) - 1]
print(total)


(a1, a2, a3, a4) = map(int, input().split())
s = str(input())
calories = 0
for i in range(0, len(s)):
	if int(s[i]) == 1:
		calories = calories + a1
	elif int(s[i]) == 2:
		calories = calories + a2
	elif int(s[i]) == 3:
		calories = calories + a3
	else:
		calories = calories + a4
print(calories)


(a1, a2, a3, a4) = map(int, input().split())
s = input()
(s1, s2, s3, s4) = (s.count('1'), s.count('2'), s.count('3'), s.count('4'))
print(s1 * a1 + s2 * a2 + s3 * a3 + s4 * a4)


a1 = input().split(' ')
s = input()
con = 0
for x in s:
	con += int(a1[int(x) - 1])
print(con)


calories = [int(x) for x in input().split()]
boxes = input()
waste = 0
for box in boxes:
	waste += calories[int(box) - 1]
print(waste)


def main():
	n = list(map(int, input().split()))
	calories = 0
	for i in input():
		calories += n[int(i) - 1]
	print(calories)
main()


calorie_values = list()
calorie_value = input('')
state_string = input('')
for i in calorie_value.split():
	calorie_values.append(int(i))
first_value = calorie_values[0]
second_value = calorie_values[1]
third_value = calorie_values[2]
forth_value = calorie_values[3]
total_calories = 0
for i in state_string:
	if i == '1':
		total_calories += first_value
	elif i == '2':
		total_calories += second_value
	elif i == '3':
		total_calories += third_value
	elif i == '4':
		total_calories += forth_value
print(total_calories)


l = list(map(int, input().split()))
s = list(input())
su = 0
se = set(s)
for i in se:
	su += s.count(i) * l[int(i) - 1]
print(su)


def Solve():
	Result = 0
	for c in range(len(s)):
		Result += Values[int(s[c]) - 1]
	print(Result)
Values = list(map(int, input().split()))
s = input('')
Solve()


(a1, a2, a3, a4) = map(int, input().split())
dic = {'1': a1, '2': a2, '3': a3, '4': a4}
st = input()
sm = 0
for ch in st:
	sm += dic[ch]
print(sm)


l = list(map(int, input().split()))
s = input()
ans = 0
for i in ['1', '2', '3', '4']:
	ans += s.count(i) * l[int(i) - 1]
print(ans)


(a1, a2, a3, a4) = input().split()
(a1, a2, a3, a4) = (int(a1), int(a2), int(a3), int(a4))
s = str(input())
l = int(len(s))
ca = 0
for i in s:
	if i == '1':
		ca += a1
	elif i == '2':
		ca += a2
	elif i == '3':
		ca += a3
	elif i == '4':
		ca += a4
print(ca)


R = lambda : map(int, input().split())
a = list(R())
s = input()
print(sum((a[ord(c) - ord('1')] for c in s)))


a = list(map(int, input().split()))
s = str(input())
sum = 0
for i in range(len(s)):
	x = int(s[i])
	sum += a[x - 1]
print(sum)


ingr = [int(i) for i in input().split()]
s = input()
c = 0
for i in range(len(s)):
	if s[i] == '1':
		c += ingr[0]
	elif s[i] == '2':
		c += ingr[1]
	elif s[i] == '3':
		c += ingr[2]
	else:
		c += ingr[3]
print(c)


lst = list(map(int, input().split()))
p = input()
q = 0
for i in range(len(p)):
	q += lst[int(p[i]) - 1]
print(q)


line = map(int, input().split())
string = input()
cal = 0
for (i, x) in enumerate(line):
	c = string.count(str(i + 1))
	cal += c * int(x)
print(cal)


import sys

def minp():
	return sys.stdin.readline().strip()
a = list(map(int, minp().split()))
s = minp()
q = {}
for i in range(len(s)):
	q[s[i]] = q.get(s[i], 0) + 1
print(q.get('1', 0) * a[0] + q.get('2', 0) * a[1] + q.get('3', 0) * a[2] + q.get('4', 0) * a[3])


(a1, a2, a3, a4) = map(int, input().split())
c = input()
b = 0
for i in range(len(c)):
	if c[i] == '1':
		b += a1
	elif c[i] == '2':
		b += a2
	elif c[i] == '3':
		b += a3
	else:
		b += a4
print(b)


a = list(map(int, input().split()))
s = str(input())
x = s.count('1')
y = s.count('2')
z = s.count('3')
w = s.count('4')
print(a[0] * x + a[1] * y + a[2] * z + a[3] * w)


L = list(map(int, input().split()))
s = str(input())
r = 0
for i in range(len(s)):
	r += L[int(s[i]) - 1]
print(r)


l = input().split()
ans = 0
for n in input():
	ans += int(l[int(n) - 1])
print(ans)


a = [int(i) for i in input().split()]
d = input()
s = 0
for i in d:
	s += a[int(i) - 1]
print(s)


calories = [int(x) for x in input('').split()]
data = input('')
total_calories = 0
for i in data:
	val = int(i)
	total_calories += calories[val - 1]
print(total_calories)


a = input().split()
(s, res) = (input(), 0)
for i in s:
	res += int(a[int(i) - 1])
print(res)


l = list(map(int, input().split()))
st = input()
ca = 0
for i in st:
	if i == '1':
		ca += l[0]
	elif i == '2':
		ca += l[1]
	elif i == '3':
		ca += l[2]
	else:
		ca += l[3]
print(ca)


def main():
	(a1, a2, a3, a4) = list(map(int, input().split()))
	refer = {'1': a1, '2': a2, '3': a3, '4': a4}
	s = list(input())
	print(sum(list(map(refer.get, s))))
main()


l = [int(i) for i in input().split()]
n = input()
x = 0
for i in range(len(n)):
	a = int(n[i])
	x = x + l[a - 1]
print(x)


cal = list(map(int, input().split()))
s = input()
f = 0
for i in range(0, len(s)):
	if s[i] == str(1):
		f += cal[0]
	elif s[i] == str(2):
		f += cal[1]
	elif s[i] == str(3):
		f += cal[2]
	else:
		f += cal[3]
print(f)


import math
import os
import random
import re
import sys
a = [int(x) for x in input().split()]
b = input()
c = []
for i in b:
	i = int(i)
	j = i - 1
	c.append(a[j])
print(sum(c))


a = list(map(int, input().split()))
n = list(input())
sum1 = 0
for i in n:
	sum1 = sum1 + a[int(i) - 1]
print(sum1)


a = [int(x) for x in input().split(' ')]
s = input()
total = 0
for char in s:
	total += a[int(char) - 1]
print(total)


l = [int(x) for x in input().split()]
st = input()
ans = 0
for i in st:
	if i == '1':
		ans += l[0]
	elif i == '2':
		ans += l[1]
	elif i == '3':
		ans += l[2]
	else:
		ans += l[3]
print(ans)


a = list(map(int, input().split()))
string = input()
ans = list(map(lambda x: a[int(x) - 1], string))
print(sum(ans))


a = list(map(int, input().split()))
b = input()
su = 0
for i in b:
	if i == str(1):
		su += a[0]
	elif i == str(2):
		su += a[1]
	elif i == str(3):
		su += a[2]
	else:
		su += a[3]
print(su)


calories = list(map(int, input().split()))
game = input()
ans = 0
for i in range(4):
	ans += calories[i] * game.count(str(i + 1))
print(ans)


(a1, a2, a3, a4) = map(int, input().split())
string = input()
first = string.count('1')
second = string.count('2')
third = string.count('3')
four = len(string) - first - second - third
print(first * a1 + second * a2 + third * a3 + four * a4)


a = list(map(int, input().strip().split(' ')))
b = input().strip()
x = 0
for i in b:
	x += a[int(i) - 1]
print(x)


a = list(map(int, input().split()))
b = list(input())
c = len(b)
x = t = a1 = a2 = a3 = a4 = int(0)
while x < c:
	if b[x] == '1':
		a1 = a1 + 1
	elif b[x] == '2':
		a2 = a2 + 1
	elif b[x] == '3':
		a3 = a3 + 1
	elif b[x] == '4':
		a4 = a4 + 1
	x = x + 1
t = a1 * a[0] + a2 * a[1] + a3 * a[2] + a4 * a[3]
print(t)


from sys import stdin, stdout, exit as sys_ret
calories = [int(_) for _ in stdin.readline().split()]
game = stdin.readline()
sum = 0
for i in range(len(game) - 1):
	sum += calories[int(game[i]) - 1]
stdout.write(str(sum))


n = [int(_) for _ in input().split()]
s = input()
total = 0
for i in range(len(s)):
	total += n[int(s[i]) - 1]
print(total)


x = list(map(int, input().split()))
y = list(map(int, list(input())))
sum1 = 0
for i in y:
	sum1 += x[i - 1]
print(sum1)


a = list((int(a) for a in input().split()))
cal = 0
for p in input():
	cal += a[int(p) - 1]
print(cal)


mas = list(map(int, input().split()))
s = input()
summa = 0
for i in s:
	summa += mas[int(i) - 1]
print(summa)


a = list(map(int, input().split()))
q = input()
calories = 0
for i in q:
	calories = calories + a[int(i) - 1]
print(calories)


cal = list(map(int, input().split()))
string = input()
d = dict()
for i in range(0, 4):
	d[i + 1] = cal[i]
s = 0
for i in string:
	s += d[int(i)]
print(s)


try:
	l = list(map(int, input().split()))
	s = input()
	a = s.count('1')
	b = s.count('2')
	c = s.count('3')
	d = s.count('4')
	sum = a * l[0] + b * l[1] + c * l[2] + d * l[3]
	print(sum)
except:
	pass


a = [int(x) for x in input().split()]
s = input()
s_l = list(s)
for i in range(len(s)):
	s_l[i] = int(s_l[i])
x = 0
for i in range(len(s)):
	x += a[s_l[i] - 1]
print(x)


q = lambda : map(int, input().split())
qs = lambda : input().split()
a = list(q())
print(sum([a[int(i) - 1] for i in input()]))


from sys import stdin
a = [int(i) for i in stdin.readline()[:-1].split(' ')]
print(sum([a[int(i) - 1] for i in stdin.readline()[:-1]]))


import sys
C = list(map(int, input().split()))
S = input()
ans = sum([C[int(el) - 1] for el in S])
print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
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 fractions import Fraction
mod = 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)]
arr = l()
s = c(data())
answer = 0
for i in s.keys():
	answer += s[i] * arr[int(i) - 1]
out(answer)


a = list(map(int, input().split()))
s = str(input())
ans = 0
for i in range(4):
	ans += a[i] * s.count(str(i + 1))
print(ans)


a = list(map(int, input().strip().split()))
s = list(map(int, list(input().strip())))
print(sum([a[si - 1] for si in s]))


from sys import stdin
cal = list(map(int, stdin.readline().split()))
x = stdin.readline().rstrip()
res = 0
for i in x:
	res += cal[int(i) - 1]
print(res)


l = [int(i) for i in input().split()]
s = input()
solve = 0
for i in s:
	solve += l[int(i) - 1]
print(solve)


numbers = [int(i) for i in input().split()]
word = input()
score = 0
for letter in word:
	if letter == '1':
		score += numbers[0]
	elif letter == '2':
		score += numbers[1]
	elif letter == '3':
		score += numbers[2]
	else:
		score += numbers[3]
print(score)


arr = [int(i) for i in input().split(' ')]
s = str(input())
res = 0
for i in s:
	res += arr[ord(i) - ord('0') - 1]
print(res)


import sys
a = [int(num) for num in sys.stdin.readline()[:-1].split()]
s = [int(num) for num in sys.stdin.readline()[:-1]]
output = 0
for ele in s:
	output += a[ele - 1]
print(output)


def read_number_line():
	return [int(i) for i in input().split()]

def read_number():
	return int(input())
energies = {}
a = read_number_line()
for i in range(1, 5):
	energies[str(i)] = a[i - 1]
total_energy = 0
for si in input():
	total_energy += energies[si]
print(total_energy)


n = list(map(int, input().split()))
sum1 = 0
k = input()
k1 = k2 = k3 = k4 = 0
for i in k:
	if i == '1':
		k1 += 1
	if i == '2':
		k2 += 1
	if i == '3':
		k3 += 1
	if i == '4':
		k4 += 1
sum1 = n[0] * k1 + n[1] * k2 + n[2] * k3 + n[3] * k4
print(sum1)


l = list(map(int, input().split()))
dict = {1: l[0], 2: l[1], 3: l[2], 4: l[3]}
s = input()
sum = 0
for i in s:
	sum += dict[int(i)]
print(sum)


import sys
k = [int(a) for a in input().split()]
if k[0] == 0 and k[1] == 0 and (k[2] == 0) and (k[3] == 0):
	print(0)
	sys.exit()
mas = list(input())
s = mas.count('1') * k[0] + mas.count('2') * k[1] + mas.count('3') * k[2] + mas.count('4') * k[3]
print(s)


(a1, a2, a3, a4) = map(int, input().split())
string = input()
calories = 0
for item in string:
	if item == '1':
		calories += a1
	elif item == '2':
		calories += a2
	elif item == '3':
		calories += a3
	else:
		calories += a4
print(calories)


s = input().split()
s2 = []
for i in range(len(s)):
	k = int(s[i])
	s2.append(k)
t = 0
s1 = input()
s1 = list(s1)
for i in range(len(s1)):
	if s1[i] == '1':
		t = t + s2[0]
	if s1[i] == '2':
		t = t + s2[1]
	if s1[i] == '3':
		t = t + s2[2]
	if s1[i] == '4':
		t = t + s2[3]
print(t)


(k1, k2, k3, k4) = [int(i) for i in input().split()]
(s1, s2, s3, s4) = (0, 0, 0, 0)
s = input()
for i in s:
	if i == '1':
		s1 += 1
	elif i == '2':
		s2 += 1
	elif i == '3':
		s3 += 1
	else:
		s4 += 1
print(s1 * k1 + s2 * k2 + s3 * k3 + s4 * k4)


n = list(map(int, input().split()))
m = input()
l = list(m)
a = 0
b = 0
c = 0
d = 0
for i in l:
	if i == '1':
		a += 1
	elif i == '2':
		b += 1
	elif i == '3':
		c += 1
	else:
		d += 1
result = a * n[0] + b * n[1] + c * n[2] + d * n[3]
print(result)


def game(a, b):
	res = 0
	for i in range(0, len(b)):
		x = int(b[i])
		res = res + a[x - 1]
	print(res)
list1 = [int(i) for i in input().split()]
list2 = input()
game(list1, list2)


values = [int(i) for i in input().split()]
keys = [int(i) + 1 for i in range(len(values))]
hmap = dict(zip(keys, values))
querry = input()
result = 0
for i in querry:
	result += hmap[int(i)]
print(result)


(a1, a2, a3, a4) = map(int, input().split())
a = input()
sum = 0
(c1, c2, c3, c4) = (0, 0, 0, 0)
for i in a:
	if i == '1':
		c1 += 1
	elif i == '2':
		c2 += 1
	elif i == '3':
		c3 += 1
	elif i == '4':
		c4 += 1
sum += c1 * a1 + c2 * a2 + c3 * a3 + c4 * a4
print(sum)


a = list(map(int, input().split()))
b = str(input())
c = []
i = 0
for i in range(len(b)):
	c.append(int(b[i]))
	i += 1
i = 0
sum = 0
for i in range(len(c)):
	if c[i] == 1:
		sum += a[0]
		i += 1
	elif c[i] == 2:
		sum += a[1]
		i += 1
	elif c[i] == 3:
		sum += a[2]
		i += 1
	elif c[i] == 4:
		sum += a[3]
		i += 1
print(sum)


a = input().split()
s = input()
s = str(s)
n1 = len(a)
n2 = len(s)
calorie = 0
for i in range(n1):
	a[i] = int(a[i])
for j in range(n2):
	if s[j] == '1':
		calorie += a[0]
	elif s[j] == '2':
		calorie += a[1]
	elif s[j] == '3':
		calorie += a[2]
	else:
		calorie += a[3]
print(calorie)


from sys import stdin
n = [int(i) for i in stdin.readline()[:-1].split(' ')]
l = stdin.readline()
(a, b, c, d) = (l.count('1'), l.count('2'), l.count('3'), l.count('4'))
print(a * n[0] + b * n[1] + c * n[2] + d * n[3])


cals = [int(x) for x in input().split()]
stripes = input().strip()
tot_cals = 0
for j in stripes:
	tot_cals += cals[int(j) - 1]
print(tot_cals)


num1 = input()
a = []

def get_the_data(count, num, arr):
	for i in range(0, len(num)):
		if num[i] == ' ':
			arr.append(int(num[count:i]))
			count = i + 1
		elif i == len(num) - 1:
			arr.append(int(num[count:len(num)]))
	return arr
arr1 = get_the_data(0, num1, a)
str_index = input()
calories = 0
for i in str_index:
	calories += arr1[int(i) - 1]
print(calories)


(n1, n2, n3, n4) = map(int, input().split())
s = input()
t = 0
for i in s:
	if i == '1':
		t = t + n1
	elif i == '2':
		t = t + n2
	elif i == '3':
		t = t + n3
	elif i == '4':
		t = t + n4
print(t)


a = []
a1 = input()
for i in a1.split():
	a.append(i)
s = input()
counter = 0
for i in range(0, 4):
	counter += s.count(str(i + 1)) * int(a[i])
print(counter)


pr = list(map(int, input().split()))
s = input().strip()
sum = 0
for i in range(len(s)):
	sum += pr[ord(s[i]) - ord('1')]
print(sum)


def calorie(lista):
	stripes = lista[1]
	calories = lista[0]
	result = 0
	for i in stripes[0]:
		if i == '1':
			result += calories[0]
		elif i == '2':
			result += calories[1]
		elif i == '3':
			result += calories[2]
		elif i == '4':
			result += calories[3]
	return result
lista = []
lista.append(list(map(int, input().rstrip().split())))
lista.append(list(input().rstrip().split()))
print(calorie(lista))


def solve():
	(a1, a2, a3, a4) = [int(s) for s in input().split()]
	s = input()
	ans = 0
	for i in s:
		if i == '1':
			ans += a1
		elif i == '2':
			ans += a2
		elif i == '3':
			ans += a3
		else:
			ans += a4
	print(ans)
solve()


a = [int(i) for i in input().strip().split()]
s = input()
cost = 0
for i in s:
	cost += a[int(i) - 1]
print(cost)


(a, b, c, d) = input().split()
tot = 0
k = list()
k.append(a)
k.append(b)
k.append(c)
k.append(d)
s = input()
for i in s:
	for j in range(0, len(k)):
		if int(i) == j + 1:
			tot += int(k[j])
			break
print(tot)


from collections import Counter
the_input = input().split()
for i in range(0, len(the_input)):
	the_input[i] = int(the_input[i])
word = input()
a = the_input[0]
b = the_input[1]
c = the_input[2]
d = the_input[3]
word_counter = Counter(word)
total = a * word_counter['1'] + b * word_counter['2'] + c * word_counter['3'] + d * word_counter['4']
print(total)


import sys

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

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

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

def rln(n):
	l = [None] * n
	for i in range(n):
		l[i] = int(rl())
	return l
vals = [0] + list(map(int, input().split()))
p = input()
cnt = 0
for i in range(len(p)):
	cnt += vals[int(p[i])]
print(cnt)


(a1, a2, a3, a4) = list(map(int, input().split()))
s = list(input())
calories = 0
for i in s:
	if i == '1':
		calories += a1
	if i == '2':
		calories += a2
	if i == '3':
		calories += a3
	if i == '4':
		calories += a4
print(calories)


n = list(map(int, input().split()))
z = input()
count = 0
for i in range(len(z)):
	count += n[int(z[i]) - 1]
print(count)


import sys
data = sys.stdin.readlines()
calories = list(map(int, data[0].split()))
print(sum(map(lambda i: calories[int(i) - 1], data[1][:-1])))


lst = [int(a) for a in input().split()]
energy_spent = 0
for i in input():
	energy_spent += lst[int(i) - 1]
print(energy_spent)


d = {str(i + 1): int(j) for (i, j) in enumerate(input().split())}
print(sum([d[i] for i in input()]))


a = [*map(int, input().split())]
ans = 0
for i in input():
	ans += a[int(i) - 1]
print(ans)


i = str(input())
i = list(i.split(' '))
a = input()
o = 0
t = 0
r = 0
f = 0
for char in a:
	if char == '1':
		o = o + 1
	elif char == '2':
		t = t + 1
	elif char == '3':
		r = r + 1
	elif char == '4':
		f = f + 1
o = o * int(i[0])
t = t * int(i[1])
r = r * int(i[2])
f = f * int(i[3])
e = o + t + r + f
print(e)


(a1, a2, a3, a4) = map(int, input().split())
a = []
b = []
c = []
d = []
s = input()
for i in s:
	if i == '1':
		a.append(i)
	elif i == '2':
		b.append(i)
	elif i == '3':
		c.append(i)
	else:
		d.append(i)
print(len(a) * a1 + len(b) * a2 + len(c) * a3 + len(d) * a4)


import os
from math import ceil
import sys
from io import BytesIO, IOBase
import sys, bisect, copyreg, copy, statistics, os

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

def IIX():
	return (int(x) for x in sys.stdin.readline().split())

def II():
	return int(inp())

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

def LS():
	return list(map(str, inp().split()))

def L(x):
	return list(x)

def out(var):
	return sys.stdout.write(str(var))

class GraphAL:

	def __init__(self, Nodes, isDirected=False):
		self.nodes = [x for x in range(Nodes + 1)]
		self.adj_list = {}
		self.isDirected = isDirected
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, x, y):
		self.adj_list[x].append(y)
		if self.isDirected == False:
			self.adj_list[y].append(x)

	def return_graph(self):
		return self.adj_list

class GraphAM:

	def __init__(self, Nodes, isDirected=False):
		self.adj_matrix = [[0] * (Nodes + 1) for x in range(Nodes + 1)]
		self.isDirected = isDirected

	def add_edge(self, x, y):
		if self.isDirected:
			self.adj_matrix[x][y] = 1
		elif self.isDirected == False:
			self.adj_matrix[x][y] = 1
			self.adj_matrix[y][x] = 1

	def delete_edge(self, x, y):
		if self.isDirected:
			self.adj_matrix[x][y] = 0
		if self.isDirected == False:
			self.adj_matrix[x][y] = 0
			self.adj_matrix[y][x] = 0

	def degree(self, x):
		l = self.adj_matrix[x]
		return l.count(1)

	def return_graph(self):
		return self.adj_matrix

def solve():
	calories = LI()
	blanks = inp()
	wasted = 0
	for i in range(len(blanks)):
		wasted += calories[int(blanks[i]) - 1]
	out(wasted)
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.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		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')
try:
	t = 1
	for _ in range(t):
		solve()
except EOFError as e:
	out('')
except RuntimeError as r:
	out('')


values = list(map(int, input().split()))
occur = input()
one = occur.count('1')
two = occur.count('2')
three = occur.count('3')
four = occur.count('4')
tot = one * values[0] + two * values[1] + three * values[2] + four * values[3]
print(tot)


x = input()
x = list(map(int, x.strip().split()))
y = input()
sumOfCal = 0
for i in range(len(y)):
	sumOfCal += x[int(y[i]) - 1]
print(str(sumOfCal))


a = [int(j) for j in input().strip().split(' ')]
S = input()
output = 0
for s in S:
	if s == '1':
		output += a[0]
	elif s == '2':
		output += a[1]
	elif s == '3':
		output += a[2]
	elif s == '4':
		output += a[3]
print(output)


l = list(map(int, input().split()))
l = [0] + l
s = input()
counter = 0
for i in s:
	counter += l[int(i)]
print(counter)


lt = list(input().split())
for i in range(4):
	lt[i] = int(lt[i])
s = input()
k = 0
for i in s:
	k += lt[int(i) - 1]
print(k)


alist = list(map(int, input().split()))
moves = input()
cal = 0
for chr in moves:
	cal += alist[int(chr) - 1]
print(cal)


(sq1, sq2, sq3, sq4) = map(int, input().split())
calories = 0
squares = input()
conversions = {'1': sq1, '2': sq2, '3': sq3, '4': sq4}
for num in squares:
	calories += conversions[num]
print(calories)


a = list(map(int, input().split()))
s = input()
count = 0
for x in range(len(s)):
	count += a[int(s[x]) - 1]
print(count)


x = list(map(int, input().split()))
y = input()
c = 0
for i in y:
	if i == '1':
		c += x[0]
	if i == '2':
		c += x[1]
	if i == '3':
		c += x[2]
	if i == '4':
		c += x[3]
print(c)


a = list(map(int, input().split()))
s = input()
print(sum((a[int(c) - 1] for c in s)))


(a, b, c, d) = input().split()
(a, b, c, d) = (int(a), int(b), int(c), int(d))
z = 0
x = input()
for l in x:
	l = int(l)
	if l == 1:
		z = z + a
	elif l == 2:
		z = z + b
	elif l == 3:
		z = z + c
	else:
		z = z + d
print(z)


a = [int(x) for x in input().split()]
b = input()
s = 0
for i in b:
	for j in range(1, 5):
		if int(i) == j:
			s += a[j - 1]
print(s)


a = [int(k) for k in input().split()]
s = input()
val = 0
for i in s:
	k = int(i)
	val += a[k - 1]
print(val)


calories = list(map(int, input().split()))
stringy = input()
sum_of_calories = 0
for i in range(len(stringy)):
	if stringy[i] == '1':
		sum_of_calories += calories[0]
	elif stringy[i] == '2':
		sum_of_calories += calories[1]
	elif stringy[i] == '3':
		sum_of_calories += calories[2]
	elif stringy[i] == '4':
		sum_of_calories += calories[3]
print(sum_of_calories)


s = input()
r1 = s.split(' ')
a = []
cal = 0
for i in range(len(r1)):
	temp = int(r1[i])
	a.append(temp)
s2 = input()
r2 = list(s2)
b = []
for i in range(len(r2)):
	temp = int(r2[i])
	b.append(temp)
for i in range(len(b)):
	temp = b[i]
	cal = cal + a[temp - 1]
print(cal)


a = [int(i) for i in input().split()]
ans = 0
for i in list(input()):
	ans += a[int(i) - 1]
print(ans)


n = list(map(int, input().split()))
a = input()
total = 0
for i in a:
	if int(i) == 1:
		total += n[0]
	else:
		total += n[int(i) - 1]
print(total)


x = [int(y) for y in input().split()]
z = input()
su = 0
for n in z:
	su += x[int(n) - 1]
print(su)


from sys import stdin

def main():
	a = tuple(map(int, stdin.readline().strip().split()))
	s = stdin.readline().strip()
	return sum((a[ord(c) - 49] for c in s))
print(main())


(a1, a2, a3, a4) = map(int, input().split())
s = str(input())
ans = 0
list(s)
for i in range(len(s)):
	if s[i] == '1':
		ans += a1
	if s[i] == '2':
		ans += a2
	if s[i] == '3':
		ans += a3
	if s[i] == '4':
		ans += a4
print(ans)


i = input().split()
a1 = int(i[0])
a2 = int(i[1])
a3 = int(i[2])
a4 = int(i[3])
s = input()
(s1, s2, s3, s4) = (0, 0, 0, 0)
for e in s:
	if e == '1':
		s1 += a1
	elif e == '2':
		s2 += a2
	elif e == '3':
		s3 += a3
	elif e == '4':
		s4 += a4
print(s1 + s2 + s3 + s4)


a = [int(x) for x in input().split()]
su = 0
for i in input():
	su += a[int(i) - 1]
print(su)


import math, string, itertools, fractions, heapq, collections, re, array, bisect
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict

def main(a, s):
	ans = 0
	for i in s:
		ans += a[int(i) - 1]
	print(ans)

def main_input(info=0):
	a = list(map(int, input().split()))
	s = input()
	main(a, s)
main_input()


(*a, s) = (*map(int, input().split()), input())
print(sum((a[int(i) - 1] for i in s)))


def solve(a, boxes):
	totalWasteCalories = 0
	for box in boxes:
		totalWasteCalories += a[int(box) - 1]
	return totalWasteCalories
a = list(map(int, input().split()))
boxes = input()
print(solve(a, boxes))


a = eval(input().rstrip().replace(' ', ','))
s = input()
total = 0
for i in range(1, 5):
	total += s.count(str(i)) * a[i - 1]
print(total)


sum = 0
first = list(map(int, input().split()))
numbers = input()
for i in range(len(numbers)):
	sum += first[int(numbers[i]) - 1]
print(sum)


(a, b, c, d) = [int(i) for i in input().split()]
s = input()
print(a * s.count('1') + b * s.count('2') + c * s.count('3') + d * s.count('4'))


l = list(map(int, input().split()))
s = input()
ans = 1
c1 = s.count('1')
c2 = s.count('2')
c3 = s.count('3')
c4 = s.count('4')
ans = c1 * l[0] + c2 * l[1] + c3 * l[2] + c4 * l[3]
print(ans)


import sys
x = input().split()
x = list(map(int, x))
y = input()
counter = []
counter.append(y.count('1'))
counter.append(y.count('2'))
counter.append(y.count('3'))
counter.append(y.count('4'))
result = 0
for i in range(4):
	result = result + x[i] * counter[i]
print(str(result))


import math
import os
import random
import re
from sys import stdin, stdout
from collections import Counter
from itertools import permutations

def si():
	return str(stdin.readline())

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

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

def li():
	return list(mi())

def debug(x):
	return stdout.write(str(x))
arr = li()
s = si()
ans = 0
for i in range(len(s)):
	if s[i] == '1':
		ans += arr[0]
	if s[i] == '2':
		ans += arr[1]
	if s[i] == '3':
		ans += arr[2]
	if s[i] == '4':
		ans += arr[3]
debug(ans)


sum1 = 0
(a1, a2, a3, a4) = map(int, input().split())
s = input()
l = list(s)
for i in l:
	if i == '1':
		sum1 += a1
	elif i == '2':
		sum1 += a2
	elif i == '3':
		sum1 += a3
	elif i == '4':
		sum1 += a4
	else:
		pass
print(sum1)


x = input().split(' ')
y = input()
x = list(map(int, x))
y = list(map(int, y))
a = 0
for i in range(1, 5):
	for j in y:
		if i == j:
			a += x[i - 1]
		else:
			pass
print(a)


m = list(map(int, input().split()))
n = list(input())
l = []
for i in range(len(n)):
	x = int(n[i])
	y = int(m[x - 1])
	l.append(y)
print(sum(l))


def solution(calories, turns):
	return sum((calories[turn - 1] for turn in turns))
calories = tuple(map(int, input().split(' ')))
turns = tuple(map(int, input()))
print(solution(calories, turns))


lst = input().split()
for i in range(4):
	lst[i] = int(lst[i])
s = input()
total = s.count('1') * lst[0] + s.count('2') * lst[1] + s.count('3') * lst[2] + s.count('4') * lst[3]
print(total)


def solve(arr, string):
	calories = 0
	for i in string:
		calories += arr[int(i) - 1]
	print(calories)
arr = input().split()
string = input()
arr = [int(x) for x in arr]
solve(arr, string)


arr = list(map(int, input().strip().split(' ')))
s = list(input())
result = 0
for i in s:
	result = result + arr[int(i) - 1]
print(result)


(a, b, c, d) = map(int, input().split())
s = input()
w = s.count('1') * a
x = s.count('2') * b
y = s.count('3') * c
z = s.count('4') * d
print(w + x + y + z)


import functools
cals = [*map(int, input().split())]
steps = input()
print(functools.reduce(lambda r, n: r + cals[int(n) - 1], steps, 0))


l = list(map(int, input().split(' ')))
s = input()
sum = 0
for i in s:
	num = int(i)
	sum += l[num - 1]
print(sum)


calories = input().split(' ')
movements = input()
counter = 0
for x in movements:
	counter += int(calories[int(x) - 1])
print(counter)


calorias = list(map(int, input().split()[:4]))
appear = input()
movs = [int(x) for x in appear]
output = 0
for mov in movs:
	output += calorias[mov - 1]
print(output)


A = list((int(it) for it in input().split()))
print(sum((A[int(i) - 1] for i in input())))


arr = [int(i) for i in input().split()]
s = list(input())
res = 0
for i in s:
	if i == '1':
		res += arr[0]
	elif i == '2':
		res += arr[1]
	elif i == '3':
		res += arr[2]
	else:
		res += arr[3]
print(res)


x = [int(j) for j in input().split()]
y = input()
c = 0
for i in y:
	if i == '1':
		c = c + x[0]
	if i == '2':
		c = c + x[1]
	if i == '3':
		c = c + x[2]
	if i == '4':
		c = c + x[3]
print(c)


arr = list(map(int, input().split()))
k = list(map(int, input()))
print(k.count(1) * arr[0] + k.count(2) * arr[1] + k.count(3) * arr[2] + k.count(4) * arr[3])


a = [int(x) for x in input().split()]
line = [int(x) for x in input()]
print(sum([a[i - 1] for i in line]))


def solve(a, b, c, d, string):
	total = 0
	string = str(string)
	l_string = []
	for i in string:
		l_string.append(i)
	for i in l_string:
		if i == '1':
			total += a
		elif i == '2':
			total += b
		elif i == '3':
			total += c
		elif i == '4':
			total += d
	print(total)
(a, b, c, d) = map(int, input().split())
string = int(input())
solve(a, b, c, d, string)


a = input().split()
a[0] = int(a[0])
a[1] = int(a[1])
a[2] = int(a[2])
a[3] = int(a[3])
s = input()
x = 0
for i in s:
	x += a[int(i) - 1]
print(x)


numbers = list(map(int, input().split()))
process = input()
calories = 0
for each in process:
	square = int(each)
	calories += numbers[square - 1]
print(calories)


(a1, a2, a3, a4) = [int(x) for x in input().split()]
s = input()
s = list(s)
calorie = 0
for i in s:
	if i == '1':
		calorie += a1
	elif i == '2':
		calorie += a2
	elif i == '3':
		calorie += a3
	else:
		calorie += a4
print(calorie)


cal = [int(i) for i in input().split()]
s = input()
print(sum((cal[int(i) - 1] for i in s)))


import sys
import math
a = [int(x) for x in sys.stdin.readline().split()]
s = list(sys.stdin.readline())
result = 0
for i in s[:len(s) - 1]:
	result += a[int(i) - 1]
print(result)


import sys
(k, l) = sys.stdin.read().strip().split('\n')
print(sum((int(k.split()[int(i) - 1]) for i in l)))


a = [int(i) for i in input().split()]
s = input()
r = 0
for i in s:
	r += a[int(i) - 1]
print(r)


a = [int(x) for x in input().split()]
print(sum(map(lambda c: a[int(c) - 1], input())))


(a, b, c, d) = map(int, input().split())
ss = str(input())
s = 0
for k in ss:
	if int(k) == 1:
		s += a
	elif int(k) == 2:
		s += b
	elif int(k) == 3:
		s += c
	else:
		s += d
print(s)


ai = list(map(int, input().split()))
game = input()
print(ai[0] * game.count('1') + ai[1] * game.count('2') + ai[2] * game.count('3') + ai[3] * game.count('4'))


A = input().split()
B = input()
sum = 0
for i in B:
	sum += int(A[int(i) - 1])
print(sum)


cals = list(map(int, input().split()))
print(sum([cals[int(c) - 1] for c in input()]))


a = [int(x) for x in input().split()]
s = input()
l = []
for i in range(len(s)):
	if s[i] == '1':
		l.append(a[0])
	elif s[i] == '2':
		l.append(a[1])
	elif s[i] == '3':
		l.append(a[2])
	elif s[i] == '4':
		l.append(a[3])
print(sum(l))


l = list(map(int, input().split()))
(a1, a2, a3, a4) = (l[0], l[1], l[2], l[3])
s = input()
calories = 0
for each in s:
	calories += l[int(each) - 1]
print(calories)


arr = {}
ip = input()
iplist = ip.split()
for i in range(4):
	arr[i] = iplist[i]
st = str(input())
sum = 0
for i in st:
	num = int(i)
	sum = sum + int(arr[num - 1])
print(sum)


x = list(map(int, input().split()))
res = 0
for i in list(input()):
	res += x[int(i) - 1]
print(res)


a = list(map(int, input().split()))
b = input()
c = list(b)
i = 0
sum1 = 0
while i < len(c):
	sum1 += a[int(c[i]) - 1]
	i += 1
print(sum1)


num = list(map(int, input().split()))
string1 = input()
sum = 0
for i in string1:
	sum += num[int(i) - 1]
print(sum)


(a1, a2, a3, a4) = map(int, input().split())
s = input()
(c_1, c_2, c_3, c_4) = (s.count('1'), s.count('2'), s.count('3'), s.count('4'))
print(a1 * c_1 + a2 * c_2 + a3 * c_3 + a4 * c_4)


c = {}
(c['1'], c['2'], c['3'], c['4']) = list(map(int, input().strip().split()))
ans = 0
for v in input():
	ans += c[v]
print(ans)


calEach = input().split()
squares = list(input())
calTot = 0
for i in squares:
	n = int(i) - 1
	calTot += int(calEach[n])
print(calTot)


calories = list(map(int, input().split()))
touches = list(map(int, list(input())))
total = 0
for touch in touches:
	total += calories[touch - 1]
print(total)


args = input().split(' ')
for i in range(0, len(args)):
	args[i] = int(args[i])
s = input()
summe = 0
for i in range(len(s)):
	summe += args[int(s[i]) - 1]
print(summe)


n = input().split()
str = input()
a = []
x = []
l1 = 0
l2 = 0
l3 = 0
l4 = 0
for i in range(4):
	x.append(n[i])
for i in range(4):
	a.append(0)
for i in range(len(str)):
	if str[i] == '1':
		a[0] += 1
	elif str[i] == '2':
		a[1] += 1
	elif str[i] == '3':
		a[2] += 1
	elif str[i] == '4':
		a[3] += 1
l1 = int(x[0]) * int(a[0])
l2 = int(x[1]) * int(a[1])
l3 = int(x[2]) * int(a[2])
l4 = int(x[3]) * int(a[3])
print(l1 + l2 + l3 + l4)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

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

def stringlis():
	return list(map(str, inp().split()))

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

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

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

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 ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	a = lis()
	curr = list(inp())
	for i in range(len(curr)):
		curr[i] = int(curr[i])
	ans = 0
	for i in range(len(curr)):
		ans += a[curr[i] - 1]
	print(ans)
testcase(1)


A = [int(c) for c in input().split()]
seq = [int(c) for c in input()]
ans = 0
for e in seq:
	ans += A[e - 1]
print(ans)


x = input('')
(a, b, c, d) = x.split()
s = input('')
i = 0
sum = 0
while i < len(s):
	x = s[i]
	if x == '1':
		sum = sum + int(a)
	elif x == '2':
		sum = sum + int(b)
	elif x == '3':
		sum = sum + int(c)
	elif x == '4':
		sum = sum + int(d)
	i = i + 1
print(sum)


a = list(map(int, input().split()))
b = input()
(c, e) = (0, 0)
for i in range(1, 5):
	e = b.count(str(i))
	c += e * a[i - 1]
print(c)


ls = [int(i) for i in input().split()]
string = input()
counter = 0
for i in range(0, len(string)):
	value = int(string[i]) - 1
	counter += ls[value]
print(counter)


dict = {}
(a, b, c, d) = map(int, input().split(' '))
(dict[1], dict[2], dict[3], dict[4]) = (a, b, c, d)
res = 0
for i in input():
	res += dict.get(int(i))
print(res)


l = list(map(int, input().split()))
st = input()
d = dict(zip(range(1, 5), l))
s = 0
for i in st:
	if i == '1':
		s += d[1]
	elif i == '2':
		s += d[2]
	elif i == '3':
		s += d[3]
	elif i == '4':
		s += d[4]
print(s)


(a, d) = ([int(i) for i in input().split()], input())
print(d.count('1') * a[0] + d.count('2') * a[1] + d.count('3') * a[2] + d.count('4') * a[3])


p = input()
k = p.find(' ')
a1 = int(p[:k])
p = p[k + 1:]
k = p.find(' ')
a2 = int(p[:k])
p = p[k + 1:]
k = p.find(' ')
a3 = int(p[:k])
p = p[k + 1:]
a4 = int(p)
s = input()
k = 0
for i in s:
	if i == '1':
		k += a1
	elif i == '2':
		k += a2
	elif i == '3':
		k += a3
	else:
		k += a4
print(k)


(a, b, c, d) = map(int, input().split())
dict1 = {'1': a, '2': b, '3': c, '4': d}
list1 = list(input())
sum = 0
for i in list1:
	sum += dict1[i]
print(sum)


(a, b, c, d) = (int(x) for x in input().strip().split())
s = input()
print(s.count('1') * a + s.count('2') * b + s.count('3') * c + s.count('4') * d)


from collections import Counter

def solve():
	array = list(map(int, input().split()))
	string = input()
	sum = 0
	for i in string:
		sum += array[int(i) - 1]
	return sum
print(solve())


a = [int(x) for x in input().split(' ')]
s = [int(x) for x in list(input())]
cal = 0
for t in s:
	cal += a[t - 1]
print(cal)


__author__ = 'myduomilia'
(a, b, c, d) = map(int, input().split())
s = input()
print(a * s.count('1') + b * s.count('2') + c * s.count('3') + d * s.count('4'))


ans = 0
l = list(map(int, input().split()))
s = input()
for _ in s:
	ans += l[int(_) - 1]
print(ans)


a = [int(i) for i in input().split()]
s = input()
c = 0
for i in range(len(s)):
	b = int(s[i]) - 1
	c += int(a[b])
print(c)


weight = [int(c) for c in input().split()]
res = 0
for s in input():
	res += weight[int(s) - 1]
print(res)


a = [int(x) for x in input().split()]
p = list(input())
sum = 0
for i in range(len(p)):
	p[i] = int(p[i])
for i in range(len(p)):
	if p[i] == 1:
		sum += a[0]
	elif p[i] == 2:
		sum += a[1]
	elif p[i] == 3:
		sum += a[2]
	elif p[i] == 4:
		sum += a[3]
print(sum)


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

def chrnum(s, a):
	ans = 0
	for i in s:
		if i == a:
			ans += 1
	return ans
(a1, a2, a3, a4) = (chrnum(s, '1'), chrnum(s, '2'), chrnum(s, '3'), chrnum(s, '4'))
print(a1 * a[0] + a2 * a[1] + a3 * a[2] + a4 * a[3])


(a, b, c, d) = map(int, input().split(' '))
s = input()
o = s.count('1')
t = s.count('2')
th = s.count('3')
fo = s.count('4')
print(o * a + b * t + th * c + fo * d)


cals_index = list(map(int, input().rstrip().split()))
seconds = list(map(int, input()))
cals_sum = 0
for i in seconds:
	cals_sum += cals_index[i - 1]
print(cals_sum)


from functools import reduce
(l, s) = (list(map(int, input().strip().split())), input())
k = [l[int(x) - 1] for x in s]
s = reduce(lambda a, b: a + b, k)
print(s)


x = input()
a = x.split()
st = input()
s = 0
for item in st:
	ind = int(item) - 1
	s += int(a[ind])
print(s)


calories = input().split()
squares = list(input())
SumOfCalories = 0
for i in squares:
	SumOfCalories += int(calories[int(i) - 1])
print(SumOfCalories)


cal = [int(s) for s in input().split()]
tap = [int(s) for s in list(input())]
i = 0
sum = 0
for i in range(len(tap)):
	sum += cal[tap[i] - 1]
print(sum)


cal = list(map(int, input().split()))
strip = input()
result = 0
for i in strip:
	if i == '1':
		result += cal[0]
	elif i == '2':
		result += cal[1]
	elif i == '3':
		result += cal[2]
	elif i == '4':
		result += cal[3]
print(result)


lst = list(map(int, input().split()))
x = str(input())
count = 0
for c in x:
	count += lst[int(c) - 1]
print(count)


a = list(map(int, input().split()))
sum = 0
for k in input():
	sum += a[int(k) - 1]
print(sum)


cal = list(map(int, input().strip().split()))
s = input()
totalCal = 0
for i in s:
	totalCal += cal[int(i) - 1]
print(totalCal)


calories_input = list(map(lambda x: int(x), input().split(' ')))
squares_input = [int(x) for x in list(input())]
calories_count = 0
for square in squares_input:
	calories_count += calories_input[square - 1]
print(calories_count)


(a, b, c, d) = map(int, input().split())
s = input()
(na, nb, nc, nd) = (s.count('1'), s.count('2'), s.count('3'), s.count('4'))
print(na * a + nb * b + nc * c + nd * d)


def inlt():
	return list(map(int, input().split()))
a = inlt()
s = input()
ans = 0
for i in range(len(s)):
	ans += a[int(s[i]) - 1]
print(ans)


a = [int(i) for i in input().split(' ')]
st = input()
sum = 0
for i in st:
	sum += a[int(i) - 1]
print(sum)


a = [int(x) for x in input().split()]
s = list(input())
res = 0
for c in s:
	res += a[int(c) - 1]
print(res)


calories = list(map(int, input().split()))
strips = input()
new_strips = [int(strips[i:i + 1]) for i in range(len(strips))]
print(sum([calories[each_strip - 1] for each_strip in new_strips]))


a = [int(x) for x in input().split()]
calories = {}
for i in range(0, 4):
	calories[i + 1] = a[i]
s = list(input())
n = len(s)
total = 0
for i in range(0, n):
	total += calories[int(s[i])]
print(total)


(a1, a2, a3, a4) = map(int, input().split())
str1 = input()
t1 = str1.count('1')
t2 = str1.count('2')
t3 = str1.count('3')
t4 = str1.count('4')
print(t1 * a1 + t2 * a2 + t3 * a3 + t4 * a4)


def solve():
	calories = [int(x) for x in input().split(' ')]
	ans = 0
	for i in input():
		ans += calories[int(i) - 1]
	return ans
ans = solve()
print(ans)


calories = [int(x) for x in input().split()]
timeline = input()
calorieswasted = 0
for i in timeline:
	calorieswasted += calories[int(i) - 1]
print(calorieswasted)


inp = list(map(int, input().split()))
inp1 = input()
counter = 0
for i in inp1:
	counter += inp[int(i) - 1]
print(counter)


(a, b, c, d) = map(int, input().split())
arr = list(map(int, input()))
ans = 0
for i in range(len(arr)):
	if arr[i] == 1:
		ans += a
	elif arr[i] == 2:
		ans += b
	elif arr[i] == 3:
		ans += c
	elif arr[i] == 4:
		ans += d
print(ans)


x = list(map(int, input().split()))
x.insert(0, 0)
s = input()
st = list(set(s))
y = 0
for i in range(len(st)):
	y += s.count(st[i]) * x[int(st[i])]
print(y)


calories = list(map(int, input().split()))
stripes = list(map(int, input()))
total = 0
for stripe in stripes:
	total += calories[stripe - 1]
print(total)


a = [int(x) for x in input().split()]
s = input()
sum = 0
for i in range(1, 5):
	sum += s.count(str(i)) * a[i - 1]
print(sum)


calories = [int(x) for x in input().split()]
gameLines = input()
caloriesConsumed = 0
for line in gameLines:
	caloriesConsumed += calories[int(line) - 1]
print(caloriesConsumed)


(a, b, c, d) = [int(a) for a in input().split()]
s = list(input())
ans = 0
for strip in s:
	if int(strip) == 1:
		ans += a
	elif int(strip) == 2:
		ans += b
	elif int(strip) == 3:
		ans += c
	else:
		ans += d
print(ans)


j = input().split()
s = input()
sum = 0
for i in s:
	i = int(i)
	sum = sum + int(j[i - 1])
print(sum)


print((lambda calories, process: sum((calories[int(move) - 1] for move in process)))([int(x) for x in input().split()], input()))


i = input().split()
s = list(input())
v = 0
for x in s:
	v += int(i[int(x) - 1])
print(v)


calories = [int(x) for x in input().split()]
string = [str(x) for x in input()]
result = 0
for i in range(len(calories)):
	result += calories[i] * string.count(str(i + 1))
print(result)


try:
	while True:
		weights = list(map(int, input().split()))
		timeline = input()
		calories = 0
		for c in timeline:
			column = int(c)
			column_weight = weights[column - 1]
			calories += column_weight
		print(calories)
except EOFError:
	exit()


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))
a = to_list(input())
s = input()
sum_ = 0
for number in s:
	sum_ += a[int(number) - 1]
print(sum_)


total_cal = 0
n_str = input().split(' ')
a = [int(x) for x in n_str]
num_dict = {'1': a[0], '2': a[1], '3': a[2], '4': a[3]}
string = input()
for letter in string:
	total_cal += int(num_dict[letter])
print(total_cal)


PTS = list(map(int, input().split()))
t = 0
for i in input():
	t += PTS[int(i) - 1]
print(t)


(a1, a2, a3, a4) = map(int, input().split())
l = [a1, a2, a3, a4]
b = input()
k = 0
b1 = 0
for i in range(len(b)):
	b1 = int(b[i])
	k += l[b1 - 1]
print(k)


strips = list(map(int, input().split()))
s = input()
res = 0
for i in s:
	res = res + strips[int(i) - 1]
print(res)


(a1, a2, a3, a4) = map(int, input().split())
l = list(input())
t = 0
for i in l:
	if i == '1':
		t = t + a1
	if i == '2':
		t = t + a2
	if i == '3':
		t = t + a3
	if i == '4':
		t = t + a4
print(t)


L = [0] + list(map(int, input().split(' ')))
s = 0
for k in input():
	s += L[int(k)]
print(s)


(a1, a2, a3, a4) = map(int, input().split())
s = input()
a = b = c = d = 0
for i in s:
	if i == '1':
		a += 1
	elif i == '2':
		b += 1
	elif i == '3':
		c += 1
	elif i == '4':
		d += 1
print(a1 * a + a2 * b + a3 * c + a4 * d)


a = [int(x) for x in input().split()]
strip = input()
cal = 0
for i in range(1, 5):
	n = strip.count(str(i))
	cal += n * a[i - 1]
print(cal)


(p, s) = (list(map(int, input().split())), input())
(k, sum) = (set(s), 0)
for i in k:
	sum += p[int(i) - 1] * s.count(i)
print(sum)


c = list(map(int, input().split()))
s = list(map(int, list(input())))
t = 0
for ss in s:
	t += c[ss - 1]
print(t)


def calories(c, p):
	cals = 0
	for i in p:
		cals += c[int(i) - 1]
	print(cals)
en = list(map(int, input().strip(' ').split(' ')))
sq_p = input().strip(' ')
calories(en, sq_p)


x = [*map(int, input().split())]
y = input()
print(sum([x[int(_) - 1] for _ in y]))


a = [int(x) for x in input().split()]
s = input()
s_l = list(s)
for i in range(len(s)):
	s_l[i] = int(s_l[i])
l = []
for i in range(len(s)):
	l.append(a[s_l[i] - 1])
print(sum(l))


c = [int(i) for i in input().split()]
game = input()
total = 0
for i in range(len(game)):
	total += c[int(game[i]) - 1]
print(total)


(a, b, c, d) = map(int, input().split())
string = input()
count = 0
for i in string:
	if i == '1':
		count += a
	elif i == '2':
		count += b
	elif i == '3':
		count += c
	else:
		count += d
print(count)


n = list(map(int, input().split()))
sum = 0
a = list(input())
for i in a:
	x = int(i) - 1
	sum += n[x]
print(sum)


l = tuple(map(int, input().split()))
d = {str(i): l[i - 1] for i in range(1, 5)}
s = 0
for i in input():
	s += d[i]
print(s)


a = list(map(int, input().split()))
s = list(input())
se = []
for d in s:
	d = int(d)
	se.append(d)
print(se.count(1) * a[0] + se.count(2) * a[1] + se.count(3) * a[2] + se.count(4) * a[3])


cal = [int(i) for i in input().split()]
line = [int(j) for j in list(input())]
sum = 0
for k in line:
	sum += cal[k - 1]
print(sum)


cals = list(map(int, input().split(' ')))
game = input()
answer = 0
for char in game:
	answer += cals[int(char) - 1]
print(answer)


(x1, x2, x3, x4) = map(int, input().split())
s = input()
n = 0
for i in range(len(s)):
	if s[i] == '1':
		n += x1
	elif s[i] == '2':
		n += x2
	elif s[i] == '3':
		n += x3
	elif s[i] == '4':
		n += x4
print(n)


arr = list(map(int, input().split()))
n = input()
res = 0
for i in n:
	res += arr[int(i) - 1]
print(res)


(a, b, c, d) = map(int, input().split())
l = list(input())
cal = 0
for i in l:
	if i == '1':
		cal += a
	elif i == '2':
		cal += b
	elif i == '3':
		cal += c
	elif i == '4':
		cal += d
print(cal, end='')


a = list(map(int, input().split()))
tmp = input()
cnt = 0
for t in tmp:
	cnt += a[int(t) - 1]
print(cnt)


a = list(map(int, input().split()))
total = 0
for x in input():
	total += a[int(x) - 1]
print(total)


a = input().split(' ')
a = [int(item) for item in a]
s = input()
summ = 0
for i in range(len(s)):
	for j in range(1, 5):
		if int(s[i]) == j:
			summ += a[j - 1]
print(summ)


(o, t, th, f) = map(int, input().split())
s = input()
S = 0
for i in s:
	if int(i) == 1:
		S += o
	elif int(i) == 2:
		S += t
	elif int(i) == 3:
		S += th
	else:
		S += f
print(S)


l = list(map(int, input().split()))
s = input()
r = []
for i in s:
	a = l[int(i) - 1]
	r.append(a)
print(sum(r))


(a, b, c, d) = input().split(' ')
arr = [int(a), int(b), int(c), int(d)]
s = input()
l = len(s)
energy = 0
for i in range(0, l):
	x = int(s[i]) - 1
	energy += arr[x]
print(energy)


x = list(map(int, input().split()))
s = input()
ans = 0
for i in range(len(s)):
	ans += x[int(s[i]) - 1]
print(ans)


s = input().split(' ')
line = input()
a = [0] * 4
for i in range(4):
	a[i] = int(s[i])
l = len(line)
count = 0
for i in range(l):
	if line[i] == '1':
		strp = 0
	elif line[i] == '2':
		strp = 1
	elif line[i] == '3':
		strp = 2
	elif line[i] == '4':
		strp = 3
	count += a[strp]
print(count)


while True:
	try:
		(a, b, c, d) = map(int, input().split())
		s = input()
		ans = 0
		for i in s:
			if i == '1':
				ans += a
			elif i == '2':
				ans += b
			elif i == '3':
				ans += c
			elif i == '4':
				ans += d
		print(ans)
	except:
		break


a = [int(x) for x in input().split(' ')]
s = input()
c = 0
for i in range(4):
	c = c + a[i] * int(s.count(str(i + 1)))
print(c)


l = list(map(int, input().split()))
s = input()
s = list(s)
d = {}
k = 1
for i in l:
	d[k] = i
	k += 1
a = 0
for i in s:
	a += d[int(i)]
print(a)


(a, b, c, d) = map(int, input().split())
l = input()
s = []
for i in l:
	s.append(i)
k = 0
for i in s:
	if int(i) == 1:
		k = k + a
	if int(i) == 2:
		k = k + b
	if int(i) == 3:
		k = k + c
	if int(i) == 4:
		k = k + d
print(k)


a = list(map(int, input().split()))
x = list(input())
m = 0
for i in range(len(x)):
	y = int(x[i])
	m = m + a[y - 1]
print(m)


li = list(map(int, input().split()))
st = input()
summ = 0
for x in ['1', '2', '3', '4']:
	summ += st.count(x) * li[int(x) - 1]
print(summ)


n = 0
l = list(map(int, input().split()))
s = list(map(int, input()))
x = []
for m in range(len(s)):
	for i in range(len(l)):
		if s[m] == i + 1:
			x.append(l[i])
for k in range(len(x)):
	n += x[k]
print(n)


def calculateCalories(caloriesSquare, string):
	calories = 0
	for i in string:
		calories += int(caloriesSquare[int(i) - 1])
	return calories
listOfInputs = input().split()
string = str(input())
print(calculateCalories(listOfInputs, string))


wastedCalories = [int(x) for x in input().split(' ')]
wastedCalories.insert(0, 0)
ans = 0
s = input()
for i in s:
	ans += wastedCalories[int(i)]
print(ans)


try:
	arr = [int(ele) for ele in input().split()]
	s = input()
	ans = 0
	for i in s:
		ans += arr[int(i) - 1]
	print(ans)
except Exception:
	pass


from sys import stdin
nums = list(map(int, stdin.readline().rstrip().split(' ')))
boxes = stdin.readline().rstrip()
t = 0
for b in boxes:
	t += nums[int(b) - 1]
print(t)


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


n = list(map(int, input().split()))
s = input()
x = 0
for i in range(len(s)):
	if s[i] == '1':
		x = x + n[0]
	elif s[i] == '2':
		x = x + n[1]
	elif s[i] == '3':
		x = x + n[2]
	else:
		x = x + n[3]
print(x)


lst = list(map(int, input().split()))
x = str(input())
count = 0
for i in x:
	if i == '1':
		count += lst[0]
	if i == '2':
		count += lst[1]
	if i == '3':
		count += lst[2]
	if i == '4':
		count += lst[3]
print(count)


a = list(map(int, input().split()))
s = input()
sum = 0
for (i, value) in enumerate(a, 1):
	sum += s.count(str(i)) * value
print(sum)


n = list(map(int, input().split()))
z = list(map(str, input()))
su = z.count('1') * n[0] + z.count('2') * n[1] + z.count('3') * n[2] + z.count('4') * n[3]
print(su)


n = list(map(int, input().split()))
s = input()
sum1 = 0
for i in range(len(s)):
	sum1 = sum1 + n[int(s[i]) - 1]
print(sum1)


cost = list(map(int, input().split()))
moves = list(map(int, list(input())))
total = sum([cost[i - 1] for i in moves])
print(total)


R = lambda : list(map(int, input().split()))
a = R()
s = input()
r = 0
for x in s:
	r += a[int(x) - 1]
print(r)


x = list(map(int, input().split()))
s = input()
res = s.count('1') * x[0] + s.count('2') * x[1] + s.count('3') * x[2] + s.count('4') * x[3]
print(res)


a = list(input().split())
b = list(input())
a = [int(x) for x in a]
b = [int(x) for x in b]
sum = 0
for i in b:
	sum += a[i - 1]
print(sum)


ls = list(map(int, input().split()))
inputs = input()
counter = 0
for i in inputs:
	counter += ls[int(i) - 1]
print(counter)


(a, b, c, d) = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
st = input()
sum1 = 0
for i in range(len(st)):
	if st[i] == '1':
		sum1 += a
	elif st[i] == '2':
		sum1 += b
	elif st[i] == '3':
		sum1 += c
	elif st[i] == '4':
		sum1 += d
print(sum1)


l = list(map(int, input().split()))
m = input()
calories: int = 0
for i in m:
	j = int(i)
	calories += l[j - 1]
print(calories)


cals = list(map(int, input().split()))
ans = sum(map(lambda idx: cals[int(idx) - 1], input()))
print(ans)


a = [int(i) for i in input().split()]
x = str(input())
n = len(x)
count = 0
for i in x:
	count += a[int(i) - 1]
print(count)


a = list(map(int, input().split()))
b = input()
c1 = 0
c2 = 0
c3 = 0
c4 = 0
for i in str(b):
	if i == '1':
		c1 += 1
	elif i == '2':
		c2 += 1
	elif i == '3':
		c3 += 1
	elif i == '4':
		c4 += 1
score = c1 * a[0] + c2 * a[1] + c3 * a[2] + c4 * a[3]
print(score)


a = [int(x) for x in input().split()]
s = input()
w = sum([a[int(x) - 1] for x in s])
print(w)


a = list(map(int, input().split()))
f = 0
for i in input():
	f += a[int(i) - 1]
print(f)


(a, b, c, d) = map(int, input().split())
p = input()
r = 0
for i in p:
	if i == '1':
		r += a
	elif i == '2':
		r += b
	elif i == '3':
		r += c
	else:
		r += d
print(r)


a = input().split()
b = input()
hasil = 0
for i in b:
	hasil += int(a[int(i) - 1])
print(hasil)


ca = list(map(int, input().split()))
g = list(map(int, list(input())))
c = 0
for i in g:
	c += ca[i - 1]
print(c)


a = list(map(int, input().split()))
g = input()
c = 0
for x in g:
	if x == '1':
		y = int(x) - 1
		c += a[y]
	elif x == '2':
		y = int(x) - 1
		c += a[y]
	elif x == '3':
		y = int(x) - 1
		c += a[y]
	else:
		y = int(x) - 1
		c += a[y]
print(c)


l = list(map(int, input().split()))
cnt = 0
for i in input():
	cnt += l[int(i) - 1]
print(cnt)


(a1, a2, a3, a4) = [int(x) for x in input().split()]
a = input()
c = 0
for i in a:
	if int(i) == 1:
		c = c + a1
	if int(i) == 2:
		c = c + a2
	if int(i) == 3:
		c = c + a3
	if int(i) == 4:
		c = c + a4
print(c)


strips = list(map(int, input().split()))
l = input()
s = []
for i in range(len(l)):
	s.append(int(l[i]))
c = 0
for i in s:
	c += strips[i - 1]
print(c)


(c1, c2, c3, c4) = map(int, input().split(' '))
list = input()
total = 0
for i in list:
	if i == '1':
		total += c1
	if i == '2':
		total += c2
	if i == '3':
		total += c3
	if i == '4':
		total += c4
print(total)


(a, b, c, d) = (int(i.strip()) for i in input().split())
dic = {1: a, 2: b, 3: c, 4: d}
su = 0
s = list(input())
p = list(map(int, s))
for i in p:
	su += dic[i]
print(su)


a = [0] + list(map(int, input().split()))
s = input()
sol = 0
for i in range(0, len(s)):
	sol += a[int(ord(s[i]) - ord('0'))]
print(sol)


li = list(map(int, input().split()))
s = input()
c = 0
for i in range(0, len(s)):
	c = c + li[int(s[i]) - 1]
print(c)


calories = list(map(int, input().split()))
lines = input()
sum_cal = 0
for line in range(len(lines)):
	exact_line = int(lines[line])
	sum_cal += calories[exact_line - 1]
print(sum_cal)


(o, s, t, f) = map(int, input().split())
string = input()
calori = 0
for i in string:
	if int(i) == 1:
		calori += o
	if int(i) == 2:
		calori += s
	if int(i) == 3:
		calori += t
	if int(i) == 4:
		calori += f
print(calori)


n = list(map(int, input().split()))
s = input()
c = 0
for i in s:
	for x in range(1, 5):
		if int(i) == x:
			c += n[x - 1]
			break
print(c)


p = input()
p = list(map(int, p.split()))
q = input()
q = q.replace('', ' ')
q = list(map(int, q.split()))
c = 0
for i in range(len(q)):
	c += p[q[i] - 1]
print(c)


(a1, a2, a3, a4) = input().split()
a1 = int(a1)
a2 = int(a2)
a3 = int(a3)
a4 = int(a4)
str = input()
sum = 0
for it in str:
	x = int(it)
	if x == 1:
		sum = sum + a1
	elif x == 2:
		sum = sum + a2
	elif x == 3:
		sum = sum + a3
	elif x == 4:
		sum = sum + a4
print(sum)


arrin = [int(x) for x in input().split()]
s = input()
(sum, off) = (0, 0)
for x in s:
	sum += arrin[int(x) - 1]
print(sum)


values = [int(i) for i in input().split()]
btns = [int(i) for i in input()]
s = 0
for i in btns:
	s += values[i - 1]
print(s)


cal_arr = [int(x) for x in input().split()]
print(sum([cal_arr[int(i) - 1] for i in input()]))


a = list(map(int, input().split()))
s = input()
c = 0
for i in range(len(s)):
	t = int(s[i])
	c += a[t - 1]
print(c)


string = str(input())
arr = string.split()
string2 = str(input())
arr2 = []
for i in range(len(string2)):
	arr2.append(int(string2[i]))
cal = 0
for i in arr2:
	cal += int(arr[i - 1])
print(cal)


l = []
for tmp in input().strip('\n\r\t ').split(' '):
	l.append(int(tmp))
cc = 0
for c in input().strip('\n\r\t '):
	cc += l[int(c) - 1]
print(cc)


import sys

def gl():
	return input()

def gli():
	return int(input())

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

def glm():
	return list(map(int, input().split()))
a = glm()
s = gl()
c = 0
for i in s:
	c += a[int(i) - 1]
print(c)


L1 = list(map(int, input().split()))
print(sum((L1[int(i) - 1] for i in input())))


n = list(map(int, input().split()))
x = input()
a = b = c = d = 0
for i in x:
	if i == '1':
		a += 1
	if i == '2':
		b += 1
	if i == '3':
		c += 1
	if i == '4':
		d += 1
print(n[0] * a + n[1] * b + n[2] * c + n[3] * d)


def main():
	(a1, a2, a3, a4) = [int(i) for i in input().split()]
	st = input()
	sum = 0
	for i in st:
		if i == '1':
			sum = sum + a1
		elif i == '2':
			sum = sum + a2
		elif i == '3':
			sum = sum + a3
		elif i == '4':
			sum = sum + a4
	print(sum)
main()


import math
import os
import random
import re
import sys
a = list(map(int, input().rstrip().split()))
s = input()
m = 0
for x in s:
	m = m + a[int(x) - 1]
print(m)


l = list(map(int, input().split()))
s = input()
su = 0
for i in range(len(s)):
	x = int(s[i])
	su = su + l[x - 1]
print(su)


(a, b, c, d) = map(int, input().split())
alist = list(map(int, input()))
adict = {1: a, 2: b, 3: c, 4: d}
cal = 0
for i in alist:
	cal += adict[i]
print(cal)


n = list(input().split())
d = {}
for i in range(len(n)):
	d[i + 1] = n[i]
c = 0
s = input()
for j in s:
	c += int(d[int(j)])
print(c)


cw = list(map(int, input().split()))
s = 0
k = input()
for i in k:
	s += cw[int(i) - 1]
print(s)


l = tuple(map(int, input().split()))
s = input()
c = 0
for i in range(len(s)):
	c += l[int(s[i]) - 1]
print(c)


n = [int(i) for i in input().split()]
ar = [int(i) for i in input()]
a = ar.count(1)
b = ar.count(2)
c = ar.count(3)
d = ar.count(4)
print(n[0] * a + n[1] * b + n[2] * c + n[3] * d)


def BlackSquare(ar, s):
	res = 0
	for i in range(len(s)):
		j = int(s[i])
		res = res + ar[j - 1]
	return res
ar = [int(n) for n in input().split()]
s = input()
print(BlackSquare(ar, s))


cal = list(map(int, input().split()))
stripes = input()
calories = 0
for s in stripes:
	calories += cal[int(s) - 1]
print(calories)


a = list(map(int, input().split(' ')))
s = input()
res = sum([a[int(x) - 1] for x in s])
print(res)


avals = input().strip().split(' ')
avals = [int(a) for a in avals]
s = input().strip()
n = len(s)
cals = 0
for i in range(n):
	cals += avals[int(s[i]) - 1]
print(cals)


inp = input()
inp = inp.split(' ')
sequence = input()
calories = 0
for current_number in sequence:
	calories += int(inp[int(current_number) - 1])
print(calories)


a = list(map(int, input().split()))
s = str(input())
l = len(s)
t = 0
for i in range(0, l):
	k = int(s[i])
	t = t + a[k - 1]
print(t)


(a, b, c, d) = map(int, input().split())
n = str(input())
k = 0
for i in range(len(n)):
	if n[i] == '1':
		k += a
	elif n[i] == '2':
		k += b
	elif n[i] == '3':
		k += c
	elif n[i] == '4':
		k += d
print(k)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
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 I():
	return int(sys.stdin.readline())

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

def S():
	return input()

def main():
	l = LI()
	s = S()
	sm = 0
	for x in [int(a) for a in s]:
		sm += l[x - 1]
	return sm
print(main())


result = 0
(k1, k2, k3, k4) = map(int, input().split())
data = list(map(int, input()))
for m in data:
	if m == 1:
		result += k1
	elif m == 2:
		result += k2
	elif m == 3:
		result += k3
	elif m == 4:
		result += k4
print(result)


a = list(map(int, input().split()))
t = input()
sum = 0
for i in range(len(t)):
	z = int(t[i])
	sum += int(a[z - 1])
print(sum)


a = input().split()
ans = 0
s = input()
for i in s:
	if i == '1':
		ans += int(a[0])
	if i == '2':
		ans += int(a[1])
	if i == '3':
		ans += int(a[2])
	if i == '4':
		ans += int(a[3])
print(ans)


K = list(map(int, input().split()))
L = input()
p = 0
for i in L:
	if i == '1':
		p += K[0]
	elif i == '2':
		p += K[1]
	elif i == '3':
		p += K[2]
	else:
		p += K[3]
print(p)


a = list(map(int, input().split()))
b = input()
c = b.count('1') * a[0] + b.count('2') * a[1] + b.count('3') * a[2] + b.count('4') * a[3]
print(c)


arr = tuple(map(int, input().split()))
s = input()
ans = 0
for i in s:
	ans += arr[int(i) - 1]
print(ans)


l = list(map(int, input().split()))[:4]
s = list(input())
cal = 0
for i in s:
	cal += l[int(i) - 1]
print(cal)


(q, w, e, r) = map(int, input().split())
s = input()
print(s.count('1') * q + s.count('2') * w + s.count('3') * e + s.count('4') * r)


xs = [int(x) for x in input().split()]
s = input()
calories = 0
for c in s:
	calories += xs[int(c) - 1]
print(calories)


a = input().split()
a1 = int(a[0])
a2 = int(a[1])
a3 = int(a[2])
a4 = int(a[3])
s = input()
sum = s.count('1') * a1
sum += s.count('2') * a2
sum += s.count('3') * a3
sum += s.count('4') * a4
print(sum)


ls = list(map(int, input().split(' ')))
st = input()
sm = 0
for i in st:
	sm += ls[int(i) - 1]
print(sm)


n = {str(j): int(i) for (i, j) in zip(input().split(), range(1, 5))}
a = input()
print(sum([n[i] for i in a]))


import math
from collections import *
import sys
from functools import reduce

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=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
(a, b, c, d) = get_ints()
s = input()
print(a * s.count('1') + b * s.count('2') + c * s.count('3') + d * s.count('4'))


stripes = [int(i) for i in input().split()]
digits = input()
calories = 0
for c in digits:
	calories += stripes[int(c) - 1]
print(calories)


r = input()
cnt = 0
cnt1 = 0
while cnt < len(r):
	if r[cnt] == ' ':
		a1 = int(r[0:cnt])
		break
	cnt = cnt + 1
cnt = cnt + 1
cnt1 = cnt
while cnt < len(r):
	if r[cnt] == ' ':
		a2 = int(r[cnt1:cnt])
		break
	cnt = cnt + 1
cnt = cnt + 1
cnt1 = cnt
while cnt < len(r):
	if r[cnt] == ' ':
		a3 = int(r[cnt1:cnt])
		break
	cnt = cnt + 1
a4 = int(r[cnt + 1:len(r)])
s = input()
an = 0
cnt = 0
while cnt < len(s):
	if s[cnt] == '1':
		an = an + a1
	if s[cnt] == '2':
		an = an + a2
	if s[cnt] == '3':
		an = an + a3
	if s[cnt] == '4':
		an = an + a4
	cnt = cnt + 1
print(an)


a = input().split()
b = list(input())
res = 0
for i in b:
	res = res + int(a[int(i) - 1])
print(res)


lis = input().split()
for i in range(4):
	lis[i] = int(lis[i])
st = input()
s = 0
for i in range(len(st)):
	if st[i] == '1':
		s += lis[0]
	elif st[i] == '2':
		s += lis[1]
	elif st[i] == '3':
		s += lis[2]
	else:
		s += lis[3]
print(s)


cals = dict(zip(map(str, range(1, 5)), map(int, input().split(' '))))
moves = input()
t = 0
for c in moves:
	t += cals[c]
print(t)


calories = [int(a) for a in input().split()]
Dict = {}
caloriesBurnt = 0
for x in '1234':
	Dict[x] = calories[int(x) - 1]
for i in input():
	caloriesBurnt += Dict[i]
print(caloriesBurnt)


a = list(map(int, input().split()))
b = str(input())
c = 0
for i in b:
	c += a[int(i) - 1]
print(c)


(a, x, y, z) = map(int, input().split())
n = list(input())
l = len(n)
sum = 0
for i in range(l):
	if n[i] == '1':
		sum += a
	elif n[i] == '2':
		sum += x
	elif n[i] == '3':
		sum += y
	else:
		sum += z
print(sum)


from collections import Counter
res = 0
weights = [x for x in map(int, input().split())]
moves = Counter(input())
for (m, f) in moves.items():
	res += f * weights[int(m) - 1]
print(res)


(a1, a2, a3, a4) = map(int, input().split())
game = input()
answer = 0
for cur in game:
	if cur == '1':
		answer += a1
	if cur == '2':
		answer += a2
	if cur == '3':
		answer += a3
	if cur == '4':
		answer += a4
print(answer)


callories = []
for c in input().split():
	callories.append(int(c))
total_callories = 0
for strip in input():
	total_callories += callories[int(strip) - 1]
print(total_callories)


weights = [int(x) for x in input('').split(' ')]
strip_indeces = [int(x) for x in input('')]
calorie_total = 0
for i in strip_indeces:
	calorie_total += weights[i - 1]
print(calorie_total)


A = list(map(int, input().split()))
S = list(input())
ans = 0
for s in S:
	ans += A[int(s) - 1]
print(ans)


(a1, b1, c1, d1) = map(int, input().split())
v = list(input())
A = 0
B = 0
E = 0
C = 0
n = len(v)
for i in range(0, n):
	if v[i] == '1':
		A = A + a1
	elif v[i] == '2':
		B = B + b1
	elif v[i] == '3':
		C = C + c1
	elif v[i] == '4':
		E = E + d1
print(A + B + C + E)


array = [int(x) for x in input().split()]
_str = input()
count = 0
for i in _str:
	count += array[int(i) - 1]
print(count)


def driver(f, g):
	d = dict()
	for i in range(1, len(f) + 1):
		d[i] = f[i - 1]
	cost = 0
	for i in g:
		cost += d[i]
	print(cost)

def main():
	for i in range(1):
		f = [int(x) for x in input().split()]
		g = input()
		g = list(g)
		g = [int(x) for x in g]
		driver(f, g)
main()


a = [int(i) for i in input().split()]
b = input()
ans = 0
for i in b:
	ans += a[int(i) - 1]
print(ans)


calories = [int(c) for c in input().split()]
array = [int(c) for c in input()]
ans = 0
for e in array:
	ans += calories[e - 1]
print(ans)


calories = {}
for (square, calorie) in enumerate(input().split(), start=1):
	calories[str(square)] = int(calorie)
print(sum((calories[sq] for sq in input())))


n1 = list(map(int, input().split()))
d = 0
s = input()
for i in range(len(s)):
	d += n1[int(s[i]) - 1]
print(d)


(a, b, c, d) = [int(x) for x in input().split()]
h = input()
hv = []
d = {'1': a, '2': b, '3': c, '4': d}
for i in h:
	for (k, v) in d.items():
		if k == i:
			hv.append(v)
print(sum(hv))


(a1, a2, a3, a4) = map(int, input().split())
str1 = input()
cal = 0
for x in str1:
	if x == '1':
		cal += a1
	elif x == '2':
		cal += a2
	elif x == '3':
		cal += a3
	elif x == '4':
		cal += a4
print(cal)


from math import sqrt
arr = list(map(int, input().split()))
s = input()
r = 0
for char in s:
	r += arr[int(char) - 1]
print(r)


(a1, a2, a3, a4) = [int(i) for i in input().split()]
s = input().split()[0]
s1 = s.count('1')
s2 = s.count('2')
s3 = s.count('3')
s4 = s.count('4')
print(a1 * s1 + a2 * s2 + a3 * s3 + a4 * s4)


pt = list(map(int, input().split()))
s = input()
sum = 0
for i in range(len(s)):
	sum = sum + pt[int(s[i]) - 1]
print(sum)


arr = list(map(int, input().split()))
s = input()
ans = 0
for c in s:
	ans += arr[ord(c) - ord('1')]
print(ans)


k = list(map(int, input().split()))
t = input()
kal = 0
for i in range(len(t)):
	if t[i] == '1':
		kal += k[0]
	elif t[i] == '2':
		kal += k[1]
	elif t[i] == '3':
		kal += k[2]
	elif t[i] == '4':
		kal += k[3]
print(kal)


ls = [0] + list(map(int, input().split()))
res = 0
for c in input():
	res += ls[int(c)]
print(res)


cal = list(map(int, input().split()))
g = input()
a = g.count('1') * cal[0] + g.count('2') * cal[1] + g.count('3') * cal[2] + g.count('4') * cal[3]
print(a)


import sys
lines = sys.stdin.readlines()
vals = list(map(int, lines[0].strip().split(' ')))
string = lines[1].strip()
res = 0
for l in string:
	res += vals[int(l) - 1]
print(res)


def main():
	vals = dict([(i + 1, int(v)) for (i, v) in enumerate(input().split())])
	d = input()
	print(sum((vals[int(c)] for c in d)))
main()


arr = list(map(int, input().split()))
s = input()
l = len(s)
sum = 0
for i in range(l):
	f = int(s[i])
	sum = sum + arr[f - 1]
print(sum)


a = list(map(int, input().split()))
s = input()
d = {}
for i in s:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
c = 0
j = 0
for i in d:
	c += d[i] * a[int(i) - 1]
	j += 1
print(c)


a = list(map(int, input().split()))
p = list(input())
l = 0
for item in p:
	if item == '1':
		l += a[0]
	elif item == '2':
		l += a[1]
	elif item == '3':
		l += a[2]
	else:
		l += a[3]
print(l)


A = list(map(int, input().split()))
s = input()
sum_ = 0
for c in s:
	i = ord(c) - ord('1')
	sum_ += A[i]
print(sum_)


is_debug = False
a = [int(x) for x in input().split()]
s = input()
t = 0
for c in s:
	v = int(c)
	t = t + a[v - 1]
print(f'{t}')


n_cals = list(map(int, input().split(' ')))
moves = map(int, input())
calories_burnt = 0
for move in moves:
	calories_burnt += n_cals[move - 1]
print(calories_burnt)


input1 = input().split()
x = []
for c in input1:
	x.append(int(c))
input2 = input()
y = []
for c in input2:
	y.append(int(c))
win = 0
for b in y:
	if b == 1:
		win = win + x[0]
	elif b == 2:
		win = win + x[1]
	elif b == 3:
		win = win + x[2]
	else:
		win = win + x[3]
print(win)


(a, b, c, d) = map(int, input().split())
s = input()
res = 0
for i in s:
	if i == '1':
		res += a
	if i == '2':
		res += b
	if i == '3':
		res += c
	if i == '4':
		res += d
print(res)


(a, b, c, d) = map(int, input().split())
s = input()
x1 = s.count('1') * a
x2 = s.count('2') * b
x3 = s.count('3') * c
x4 = s.count('4') * d
print(x1 + x2 + x3 + x4)


a = list(map(int, input().split()))
str = input()
sum = 0
for s in str:
	sum += a[int(s) - 1]
print(sum)


call = [int(x) for x in input().split()]
strip = [int(x) for x in input()]
ans = 0
for i in strip:
	if i == 1:
		ans += call[0]
	if i == 2:
		ans += call[1]
	if i == 3:
		ans += call[2]
	if i == 4:
		ans += call[3]
print(ans)


bing = list(map(int, input('').split()))
a = input('')
result = 0
for i in a:
	result = result + bing[int(i) - 1]
print(result)


cost = input().split()
sequence = input()
total_calories = 0
for step in sequence:
	total_calories += int(cost[int(step) - 1])
print(total_calories)


(a, b, c, d) = map(int, input().split())
string = list(input())
cal = 0
for i in string:
	if i == '1':
		cal += a
	if i == '2':
		cal += b
	if i == '3':
		cal += c
	if i == '4':
		cal += d
print(cal)


arr = [int(x) for x in input().split(' ')]
val = input()
print(sum((arr[int(i) - 1] for i in val)))


vls = list(map(int, input().split()))
s = input()
dic = {}
c = 0
for i in range(4):
	dic[i + 1] = vls[i]
for x in s:
	c += dic[int(x)]
print(c)


cals = [int(x) for x in input().split()]
steps = list(input())
steps = [int(x) - 1 for x in steps]
counter = 0
for step in steps:
	counter += cals[step]
print(counter)


calories = list(map(int, input().split()))
string = input()
sum = 0
for char in string:
	inti = int(char) - 1
	sum += calories[inti]
print(sum)


(st, nd, rd, th) = [int(i) for i in input().split(' ')]
taps = input()
print(taps.count('1') * st + taps.count('2') * nd + taps.count('3') * rd + taps.count('4') * th)


(a, b, c, d) = map(int, input().split())
l = [int(x) for x in input()]
s = [0 for x in range(5)]
for e in l:
	s[e] += 1
print(a * s[1] + b * s[2] + c * s[3] + d * s[4])


cals = list(map(int, list(input().split())))
strips = list(input())
print(cals[0] * strips.count('1') + cals[1] * strips.count('2') + cals[2] * strips.count('3') + cals[3] * strips.count('4'))


(a, b, c, d) = map(int, input().split())
z = list(map(str, str(input())))
v = z.count('1') * a + z.count('2') * b + z.count('3') * c + z.count('4') * d
print(v)


a = list(map(int, input().split()))
s = list(map(int, input()))
m = [0, 0, 0, 0]
for v in s:
	m[v - 1] += 1
print(a[0] * m[0] + a[1] * m[1] + a[2] * m[2] + a[3] * m[3])


(n, m, l, k) = map(int, input().split())
x = list(input())
count = 0
u = len(x)
for i in range(u):
	if x[i] == '1':
		count = count + n
	if x[i] == '2':
		count = count + m
	if x[i] == '3':
		count = count + l
	if x[i] == '4':
		count = count + k
print(count)


a = list(map(int, input().split()))
b = input()
i = 0
sums = 0
lent = len(b)
while i < lent:
	if b[i] == '1':
		sums += a[0]
	elif b[i] == '2':
		sums += a[1]
	elif b[i] == '3':
		sums += a[2]
	else:
		sums += a[3]
	i += 1
print(sums)


numbers = list(map(int, input().split()))
word = input()
total = 0
for el in word:
	if el == '1':
		total = total + numbers[0]
	elif el == '2':
		total = total + numbers[1]
	elif el == '3':
		total = total + numbers[2]
	elif el == '4':
		total = total + numbers[3]
print(total)


(calorie_1, calorie_2, calorie_3, calorie_4) = map(int, input().split(' '))
strips = input()
calorie_per_strip = {1: calorie_1, 2: calorie_2, 3: calorie_3, 4: calorie_4}
print(sum([calorie_per_strip[int(i)] for i in strips]))


l = list(map(int, input().split()))
s = input()
o = s.count('1')
t = s.count('2')
th = s.count('3')
f = s.count('4')
r = o * l[0] + t * l[1] + th * l[2] + f * l[3]
print(r)


d = input()
a1 = int(d.split()[0])
a2 = int(d.split()[1])
a3 = int(d.split()[2])
a4 = int(d.split()[3])
s = input()
(c1, c2, c3, c4) = (0, 0, 0, 0)
for i in range(len(s)):
	if int(s[i]) == 1:
		c1 += 1
	elif int(s[i]) == 2:
		c2 += 1
	elif int(s[i]) == 3:
		c3 += 1
	elif int(s[i]) == 4:
		c4 += 1
sum = c1 * a1 + c2 * a2 + c3 * a3 + c4 * a4
print(sum)


d = {i: j for (i, j) in zip(range(4), map(int, input().split()))}
print(sum((d[i - 1] for i in map(int, list(input())))))


n = input()
a = n.split()
total = 0
cal = input()
for i in range(0, len(cal)):
	total = total + int(a[int(cal[i]) - 1])
print(total)


ls = [*map(int, input().split())]
s = input()
ans = 0
for i in s:
	ans += ls[int(i) - 1]
print(ans)


t = [0] + list(map(int, input().split()))
print(sum((t[int(i)] for i in input())))


arr = [int(i) for i in input().split()]
s = input()
c = 0
for i in s:
	c += arr[int(i) - 1]
print(c)


output = 0
l = []
calories = input().split(' ')
for i in range(len(calories)):
	calories[i] = int(calories[i])
	l.append(0)
inputs = input()
for i in range(len(inputs)):
	l[int(inputs[i]) - 1] += 1
for i in range(len(l)):
	output += l[i] * calories[i]
print(output)


a = [int(t) for t in input().split(' ')]
s = input()
cal_cnt = 0
for char in s:
	cal_cnt += a[int(char) - 1]
print(cal_cnt)


import sys
import math
input = sys.stdin.readline
cal = list(map(int, input().split()))
mov = list(input())
ans = 0
for c in mov:
	if c == '\n':
		continue
	ans += cal[int(c) - 1]
print(ans)


def solve():
	s = input().split()
	d = {}
	for i in range(len(s)):
		d[i + 1] = int(s[i])
	ss = input()
	x = 0
	for i in ss:
		x += d[int(i)]
	print(x)
solve()


(a, b, c, d) = map(int, input().split())
e = input()
s = 0
k = list(e)
for i in k:
	if i == '1':
		s = s + a
	elif i == '2':
		s = s + b
	elif i == '3':
		s = s + c
	else:
		s = s + d
print(s)


cal = list(map(int, input().split()))
strip = input()
add = 0
strip = [int(x) for x in str(strip)]
for i in range(len(strip)):
	add += cal[strip[i] - 1]
print(add)


cal = [int(x) for x in input().split()]
pos = list(input())
pos = [int(x) for x in pos]
s = 0
for i in range(len(pos)):
	s = s + cal[pos[i] - 1]
print(s)


l = [int(x) for x in input().split()]
d = {}
for i in range(4):
	d[str(i + 1)] = l[i]
s = input()
res = 0
for i in s:
	res += d[i]
print(res)


strips = list(map(int, input().strip().split()))
squ = input().strip()
cal = 0
for i in squ:
	i = int(i)
	cal += strips[i - 1]
print(cal)


arr = list(map(int, input().split()))
STR = input()
one = STR.count('1')
two = STR.count('2')
three = STR.count('3')
four = STR.count('4')
ans = arr[0] * one + arr[1] * two + arr[2] * three + arr[3] * four
print(ans)


calories = 0
needed = input().split(' ')
for i in input():
	calories += int(needed[int(i) - 1])
print(calories)


a = list(map(int, input().split()))[:4]
s = list(map(int, input().strip()))
sum = 0
for i in range(len(s)):
	sum += a[s[i] - 1]
print(sum)


cal = list(map(int, input().split()))
n = str(input())
k = list(n)
total = k.count('1') * cal[0] + k.count('2') * cal[1] + k.count('3') * cal[2] + k.count('4') * cal[3]
print(total)


x = list(map(int, input().split()))
s = input()
cost = 0
for i in s:
	cost += x[int(i) - 1]
print(cost)


def solve(a, boxes):
	waste = 0
	for box in boxes:
		waste += a[int(box) - 1]
	return waste
a = list(map(int, input().split()))
boxes = input()
solved = solve(a, boxes)
print(solved)


(a, b, c, d) = map(int, input().split())
s = input()
k = []
for i in s:
	if i == '1':
		k.append(a)
	elif i == '2':
		k.append(b)
	elif i == '3':
		k.append(c)
	else:
		k.append(d)
print(sum(k))


(a1, a2, a3, a4) = [int(x) for x in input().split()]
s = input()
k = s.count('1')
l = s.count('2')
m = s.count('3')
n = s.count('4')
print(k * a1 + l * a2 + m * a3 + n * a4)


cal = list(map(int, input().split()))
co = 0
for char in input():
	co += cal[int(char) - 1]
print(co)


loc = [int(ele) for ele in input().split()]
s = input()
sum = 0
for e in s:
	e = int(e)
	sum += loc[e - 1]
print(sum)


(a1, a2, a3, a4) = input().split()
s = input()
l = len(s)
k = 0
for i in range(l):
	m = int(s[i])
	if m == 1:
		k += int(a1)
	elif m == 2:
		k += int(a2)
	elif m == 3:
		k += int(a3)
	else:
		k += int(a4)
print(k)


n = list(map(int, input().split()))
string = list(map(int, input()))
calories = 0
for e in string:
	if e == 1:
		calories = calories + n[0]
	elif e == 2:
		calories = calories + n[1]
	elif e == 3:
		calories = calories + n[2]
	else:
		calories = calories + n[3]
print(calories)


caloriesNedded = [int(x) for x in input().split()]
s = input()
caloriesWasted = 0
for i in s:
	caloriesWasted += caloriesNedded[int(i) - 1]
print(caloriesWasted)


import sys
import os

def changeStdioToFile():
	path = os.path.dirname(os.path.abspath(__file__))
	sys.stdin = open(f'{path}/input.txt', 'r')
	sys.stdout = open(f'{path}/output.txt', 'w')
t = 1
for _ in range(t):
	pt = [int(x) for x in input().split()]
	tiles = input()
	print(sum((pt[int(c) - 1] for c in tiles)))


(a, b, c, d) = [int(x) for x in input().split(' ')]
l = [a, b, c, d]
s = input()
sm = 0
for x in s:
	sm += l[int(x) - 1]
print(sm)


n = [int(x) for x in input().split()]
s = input()
a = b = c = d = 0
for i in s:
	if i == '1':
		a += 1
	elif i == '2':
		b += 1
	elif i == '3':
		c += 1
	else:
		d += 1
print(a * n[0] + b * n[1] + c * n[2] + d * n[3])


c = [int(i) for i in input().split()]
res = 0
for e in map(int, input()):
	res += c[e - 1]
print(str(res))


calo = input()
cal = list(map(int, calo.split()))
tiles = input()
total = 0
for i in tiles:
	total += cal[int(i) - 1]
print(total)


a = [int(x) for x in input().split()]
res = [0] * len(a)
for c in input():
	res[int(c) - 1] += 1
print(sum((x * y for (x, y) in zip(a, res))))


def solve():
	c = list(map(int, input().split()))
	wasted_c = 0
	for ch in input():
		wasted_c += c[int(ch) - 1]
	print(wasted_c)
solve()


(x1, x2, x3, x4) = input().split()
x1 = int(x1)
x2 = int(x2)
x3 = int(x3)
x4 = int(x4)
s = input()
n1 = s.count('1')
n2 = s.count('2')
n3 = s.count('3')
n4 = s.count('4')
print(n1 * x1 + n2 * x2 + n3 * x3 + n4 * x4)


l = list(map(int, input().split()))
d = {}
for i in range(1, len(l) + 1):
	d[i] = l[i - 1]
z = input()
s = 0
for i in z:
	s += d[int(i)]
print(s)


(a, b, c, d) = map(int, input().split())
s = str(input())
sum1 = 0
for i in s:
	if i == '1':
		sum1 += a
	elif i == '2':
		sum1 += b
	elif i == '3':
		sum1 += c
	elif i == '4':
		sum1 += d
print(sum1)


(a, b, c, d) = input('').split(' ')
l = (a, b, c, d)
s = input('')
output = 0
for i in range(1, 5):
	p = int(l[i - 1])
	j = s.count(str(i))
	output = output + p * j
print(output)


l1 = [int(num) for num in input().split(' ')]
string = input()
k = 0
for i in string:
	k += l1[int(i) - 1]
print(k)


black = list(map(int, input().split(' ')))
touch = list(input())
calorie = 0
for item in touch:
	calorie += black[int(item) - 1]
print(calorie)


calories_square = list(input().strip().split())
square_index = input().strip()
result = 0
for i in square_index:
	result += int(calories_square[int(i) - 1])
print(result)


cal = input().split()
game = input()
total = 0
for i in game:
	total += int(cal[int(i) - 1])
print(total)


(a1, a2, a3, a4) = [int(a) for a in input().split()]
s = str(input())
total = s.count('1') * a1 + s.count('2') * a2 + s.count('3') * a3 + s.count('4') * a4
print(total)


a = list(map(int, input().split()))
s = input()
k = 0
for i in s:
	o = int(i)
	k += a[o - 1]
print(k)


n = input().split(' ')
num = 0
string = str(input())
for i in string:
	if i == '1':
		num += int(n[0])
	elif i == '2':
		num += int(n[1])
	elif i == '3':
		num += int(n[2])
	else:
		num += int(n[3])
print(num)


n = [int(i) for i in input().split()]
sum = 0
x = list(input())
x = [int(i) for i in x]
for i in range(len(x)):
	sum = sum + n[x[i] - 1]
print(sum)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
import math

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

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

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

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

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.insert(i, arr)
	return lst

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

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
arr = list(map(int, input().split()))
lst = sip()
count = 0
for item in lst:
	if item != '\n':
		count += arr[int(item) - 1]
print(count)


calories = list(map(int, input().split()))
square = input()
tcal = 0
for item in square:
	if item == '1':
		tcal = tcal + calories[0]
	if item == '2':
		tcal = tcal + calories[1]
	if item == '3':
		tcal = tcal + calories[2]
	if item == '4':
		tcal = tcal + calories[3]
print(tcal)


a = input().split()
y = input()
calory = 0
for i in range(len(y)):
	calory = calory + int(a[int(y[i]) - 1])
print(calory)


def get_cals(cals_per_strip, game_process):
	(index_1, index_2, index_3, index_4) = (0, 0, 0, 0)
	for char in string:
		if int(char) == 1:
			index_1 += 1
		elif int(char) == 2:
			index_2 += 1
		elif int(char) == 3:
			index_3 += 1
		else:
			index_4 += 1
	counter_list = [index_1, index_2, index_3, index_4]
	sum = 0
	for i in range(len(cals_per_strip)):
		sum += cals_per_strip[i] * counter_list[i]
	return sum
(a1, a2, a3, a4) = map(int, input().split())
arr = [a1, a2, a3, a4]
string = input()
print(get_cals(arr, string))


a = input().split()
s = [i for i in input()]
log = {}
for i in range(1, 5):
	log[i] = a[i - 1]
total = 0
for i in s:
	a = int(i)
	total += int(log[a])
print(total)


a = list(map(int, input().split()))
str = input()
total = 0
for el in str:
	if el == '1':
		total += a[0]
	elif el == '2':
		total += a[1]
	elif el == '3':
		total += a[2]
	else:
		total += a[3]
print(total)


cal = [int(x) for x in input().split()]
s = list(map(int, input()))
sum = 0
for i in s:
	sum += cal[i - 1]
print(sum)


x = [int(y) for y in input().split()]
s = 0
n = int(input())
s1 = str(n)
for i in s1:
	s += x[int(i) - 1]
print(s)


listOfCalories = [int(x) for x in input().split(' ')]
gameProcessStrips = [int(x) for x in list(input())]
noOfCaloriesWasted = 0
for (index, wasteOfCalorie) in enumerate(listOfCalories):
	noOfCaloriesWasted += gameProcessStrips.count(index + 1) * wasteOfCalorie
print(noOfCaloriesWasted)


cals = list(map(int, input().split()))
vals = list(map(int, list(input())))
calsAdd = 0
for x in vals:
	calsAdd += cals[x - 1]
print(calsAdd)


(a, b, c, d) = [int(i) for i in input().split()]
y = 0
x = {'1': a, '2': b, '3': c, '4': d}
for i in input():
	y += x[i]
print(y)


cal = list(map(int, input().split()))
game = input()
nOfcal = game.count('1') * cal[0] + game.count('2') * cal[1] + game.count('3') * cal[2] + game.count('4') * cal[3]
print(nOfcal)


import sys
import math
import bisect
import re

def main():
	A = list(map(int, input().split()))
	ans = 0
	for c in input():
		i = ord(c) - ord('1')
		ans += A[i]
	print(ans)
main()


calories = input().split()
calories_dict = {key: value for (key, value) in enumerate(calories, start=1)}
string = input()
ans = 0
for i in string:
	ans += int(calories_dict.get(int(i)))
print(ans)


(a, b, c, d) = list(map(int, input().split()))
s = input()
cnt = 0
for i in s:
	if i == '1':
		cnt += a
	elif i == '2':
		cnt += b
	elif i == '3':
		cnt += c
	elif i == '4':
		cnt += d
print(cnt)


a = [int(i) for i in input().split()]
spent = 0
for i in input():
	spent += a[int(i) - 1]
print(spent)


arrCosts = [int(x) for x in input().split()]
word = input()
totCost = 0
for i in range(len(word)):
	totCost += arrCosts[int(word[i]) - 1]
print(totCost)


ll = list(map(int, input().split()))
l = input().strip()
otvet = 0
for i in l:
	otvet += ll[int(i) - 1]
print(otvet)


t = list(map(int, input().split()))
s = list(input())
sum = 0
v = 0
for i in s:
	if i == '1':
		v = 1 * t[0]
		sum += v
	elif i == '2':
		v = 1 * t[1]
		sum += v
	elif i == '3':
		v = 1 * t[2]
		sum += v
	elif i == '4':
		v = 1 * t[3]
		sum += v
print(sum)


a = [int(x) for x in input().split()]
s = [int(x) for x in input()]
k = 0
n = len(s)
for i in range(n):
	if s[i] % 4 == 1:
		k = k + a[0]
	elif s[i] % 4 == 2:
		k = k + a[1]
	elif s[i] % 4 == 3:
		k = k + a[2]
	elif s[i] % 4 == 0:
		k = k + a[3]
print(k)


string = input()
numbers = string.split(' ')
for x in range(4):
	numbers[x] = int(numbers[x])
string = input()
calories = 0
for x in string:
	calories += numbers[int(x) - 1]
print(calories)


li = list(map(int, input().split()))
cal = sum([li[int(ch) - 1] for ch in input()])
print(cal)


def bsquare(a, s):
	cals = 0
	for i in range(len(s)):
		cals += a[int(s[i]) - 1]
	return cals
a = list(map(int, input().strip().split()))
s = input().strip()
print(bsquare(a, s))


cal = list(map(int, input().split()))
s = input().strip()
res = 0
for ch in s:
	tmp = int(ch) - 1
	res += cal[tmp]
print(res)


import sys
input = sys.stdin.readline
a = [0] + list(map(int, input().split()))
r = input().rstrip()
score = 0
for s in map(int, r):
	score += a[s]
print(score)


a = list(map(int, input().split(' ')))
values = input()
count = 0
for i in values:
	count += a[int(i) - 1]
print(count)


a = list(map(int, input().split(' ')))
s = input()
tong = 0
a1 = a[0]
a2 = a[1]
a3 = a[2]
a4 = a[3]
for i in s:
	if i == '1':
		tong += a1
	elif i == '2':
		tong += a2
	elif i == '3':
		tong += a3
	else:
		tong += a4
print(tong)


__author__ = '#miner'
(a, b, sum) = (list(map(int, input().split())), input(), 0)
for i in b:
	sum += a[int(i) - 1]
print(sum)


import time

def countCaloriesBSquare(strip1, strip2, strip3, strip4, stringSq):
	totCals = 0
	for x in stringSq:
		if x == '1':
			totCals += strip1
		elif x == '2':
			totCals += strip2
		elif x == '3':
			totCals += strip3
		elif x == '4':
			totCals += strip4
	return totCals

def solve():
	(strip1, strip2, strip3, strip4) = [int(x) for x in input().split()]
	stringSq = input()
	print(countCaloriesBSquare(strip1, strip2, strip3, strip4, stringSq))
solve()


a = [int(i) for i in input().strip().split(' ')]
total = 0
for ch in input().strip():
	total += a[int(ch) - 1]
print(total)


ar = list(map(int, input().split()))
str = input()
a1 = ar[0]
a2 = ar[1]
a3 = ar[2]
a4 = ar[3]
print(str.count('1') * a1 + str.count('2') * a2 + str.count('3') * a3 + str.count('4') * a4)


l = list(map(int, input().split()))
b = input()
ans = 0
for i in range(4):
	ans += l[i] * b.count(str(i + 1))
print(ans)


a = input()
x = input()
a = a.split()
y = 0
for i in x:
	y = y + int(a[int(i) - 1])
print(y)


a = list(map(int, input().split()))
moves = input()
s = 0
for ch in moves:
	s += a[int(ch) - 1]
print(s)


x = list(map(int, input().split()))
n = input()
tot = 0
for i in range(0, len(n)):
	tot += x[int(n[i]) - 1]
print(tot)


a = list(map(int, input().split()))
n = input()
ans = 0
for c in n:
	ans += a[int(c) - 1]
print(ans)


v = [int(x) for x in input().split()]
s = input()
an = 0
for ch in s:
	an += v[int(ch) - 1]
print(an)