n = int(input()) s = input() a = map(int, input().split()) now = mn = mx = 0 for c, x in zip(s, a): if c == 'R': now += x else: now -= x mx = max(mx, now) mn = min(mn, now) print(mx - mn)