import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n=in.nextInt(); int h[] = new int[n]; for(int h_i=0; h_i < n; h_i++){ h[h_i] = in.nextInt(); } String word = in.next(); int l=word.length(); int index=(int) word.charAt(0)-49; int hh=h[index]; for(int i=0;ihh){ hh=h[((int) word.charAt(i)) -49]; } } System.out.println(l*hh); } }