"""
Author : Arif Ahmad
Date :
Algo :
Difficulty :
"""
from sys import stdin, stdout
def main():
n = int(stdin.readline().strip())
light = stdin.readline().strip()
r = [int(_)-1 for _ in stdin.readline().strip().split()]
c = [int(_) for _ in stdin.readline().strip().split()]
flag = [0 for i in range(n)]
ans = 0
tog = 0
for i in range(n):
x = ord(light[i]) - 48
if (tog & 1):
x = 1 - x
if x == 1:
tog += 1
ans += c[i]
flag[ r[i] ] += 1
if flag[i]:
tog = max(0, tog-flag[i])
stdout.write(str(ans) + '\n')
if __name__ == '__main__':
main()