n=int(input()) s=input() a=list(map(int,input().split())) maxi=0 mini=0 curr=0 for i in range(n): if s[i]=='R': curr+=a[i] else: curr-=a[i] maxi=max(maxi,curr) mini=min(mini,curr) print(maxi-mini)